malcontent-control: Add a --user command line argument

This is handled on the primary instance, and causes the tab to be
switched to show the given username (if possible).

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #19
This commit is contained in:
Philip Withnall 2020-10-19 17:55:47 +01:00
parent 5efc773bda
commit db54baf9d6
1 changed files with 36 additions and 0 deletions

View File

@ -94,9 +94,25 @@ static void
mct_application_constructed (GObject *object) mct_application_constructed (GObject *object)
{ {
GApplication *application = G_APPLICATION (object); GApplication *application = G_APPLICATION (object);
const GOptionEntry options[] =
{
{ "user", 'u', G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, NULL,
/* Translators: This documents the --user command line option to malcontent-control: */
N_("User to select in the UI"),
/* Translators: This is a placeholder for a command line argument value: */
N_("USERNAME") },
};
g_application_set_application_id (application, "org.freedesktop.MalcontentControl"); g_application_set_application_id (application, "org.freedesktop.MalcontentControl");
g_application_add_main_option_entries (application, options);
g_application_set_flags (application, g_application_get_flags (application) | G_APPLICATION_HANDLES_COMMAND_LINE);
/* Translators: This is a summary of what the application does, displayed when
* its run with --help: */
g_application_set_option_context_parameter_string (application,
N_("— view and edit parental controls"));
/* Localisation */ /* Localisation */
bindtextdomain ("malcontent", PACKAGE_LOCALE_DIR); bindtextdomain ("malcontent", PACKAGE_LOCALE_DIR);
bind_textdomain_codeset ("malcontent", "UTF-8"); bind_textdomain_codeset ("malcontent", "UTF-8");
@ -240,6 +256,25 @@ mct_application_startup (GApplication *application)
"app.quit", (const gchar * const[]) { "<Primary>q", "<Primary>w", NULL }); "app.quit", (const gchar * const[]) { "<Primary>q", "<Primary>w", NULL });
} }
static gint
mct_application_command_line (GApplication *application,
GApplicationCommandLine *command_line)
{
MctApplication *self = MCT_APPLICATION (application);
GVariantDict *options = g_application_command_line_get_options_dict (command_line);
const gchar *username;
/* Show the application. */
g_application_activate (application);
/* Select a user if requested. */
if (g_variant_dict_lookup (options, "user", "&s", &username) &&
!mct_user_selector_select_user_by_username (self->user_selector, username))
g_warning ("Failed to select user %s", username);
return 0; /* exit status */
}
static void static void
mct_application_class_init (MctApplicationClass *klass) mct_application_class_init (MctApplicationClass *klass)
{ {
@ -251,6 +286,7 @@ mct_application_class_init (MctApplicationClass *klass)
application_class->activate = mct_application_activate; application_class->activate = mct_application_activate;
application_class->startup = mct_application_startup; application_class->startup = mct_application_startup;
application_class->command_line = mct_application_command_line;
} }
static void static void