From 5efc773bda6f019dc6438ce582370a27bbdd3eb5 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 19 Oct 2020 17:54:37 +0100 Subject: [PATCH 1/3] malcontent-control: Add API to select users by username Signed-off-by: Philip Withnall --- malcontent-control/user-selector.c | 35 ++++++++++++++++++++++++++++++ malcontent-control/user-selector.h | 3 +++ 2 files changed, 38 insertions(+) diff --git a/malcontent-control/user-selector.c b/malcontent-control/user-selector.c index 7f4ce03..67d0a45 100644 --- a/malcontent-control/user-selector.c +++ b/malcontent-control/user-selector.c @@ -506,3 +506,38 @@ mct_user_selector_get_user (MctUserSelector *self) return self->user; } + +/** + * mct_user_selector_select_user_by_username: + * @self: an #MctUserSelector + * @username: username of the user to select + * + * Selects the given @username in the widget. This might fail if @username isn’t + * a valid user, or if they aren’t listed in the selector due to being an + * administrator (see #MctUserSelector:show-administrators). + * + * Returns: %TRUE if the user was successfully selected, %FALSE otherwise + * Since: 0.10.0 + */ +gboolean +mct_user_selector_select_user_by_username (MctUserSelector *self, + const gchar *username) +{ + MctCarouselItem *item = NULL; + ActUser *user = NULL; + + g_return_val_if_fail (MCT_IS_USER_SELECTOR (self), FALSE); + g_return_val_if_fail (username != NULL && *username != '\0', FALSE); + + user = act_user_manager_get_user (self->user_manager, username); + if (user == NULL) + return FALSE; + + item = mct_carousel_find_item (self->carousel, user, user_compare); + if (item == NULL) + return FALSE; + + mct_carousel_select_item (self->carousel, item); + + return TRUE; +} diff --git a/malcontent-control/user-selector.h b/malcontent-control/user-selector.h index ec30929..1b02c21 100644 --- a/malcontent-control/user-selector.h +++ b/malcontent-control/user-selector.h @@ -34,4 +34,7 @@ MctUserSelector *mct_user_selector_new (ActUserManager *user_manager); ActUser *mct_user_selector_get_user (MctUserSelector *self); +gboolean mct_user_selector_select_user_by_username (MctUserSelector *self, + const gchar *username); + G_END_DECLS From db54baf9d6327dbae714a052758cdad847a2c030 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 19 Oct 2020 17:55:47 +0100 Subject: [PATCH 2/3] 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 Fixes: #19 --- malcontent-control/application.c | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/malcontent-control/application.c b/malcontent-control/application.c index e88f943..d9aee5d 100644 --- a/malcontent-control/application.c +++ b/malcontent-control/application.c @@ -94,9 +94,25 @@ static void mct_application_constructed (GObject *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_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 + * it’s run with --help: */ + g_application_set_option_context_parameter_string (application, + N_("— view and edit parental controls")); + /* Localisation */ bindtextdomain ("malcontent", PACKAGE_LOCALE_DIR); bind_textdomain_codeset ("malcontent", "UTF-8"); @@ -240,6 +256,25 @@ mct_application_startup (GApplication *application) "app.quit", (const gchar * const[]) { "q", "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 mct_application_class_init (MctApplicationClass *klass) { @@ -251,6 +286,7 @@ mct_application_class_init (MctApplicationClass *klass) application_class->activate = mct_application_activate; application_class->startup = mct_application_startup; + application_class->command_line = mct_application_command_line; } static void From 60754b6745ac6e4239738da52b7173cbcf0303b2 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 20 Oct 2020 12:41:05 +0100 Subject: [PATCH 3/3] build: Bump version for new release series This will allow g-c-c to check for version 0.10 at compile time. Signed-off-by: Philip Withnall --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 8500d6b..8a3c8cf 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('malcontent', 'c', - version : '0.9.0', + version : '0.10.0', meson_version : '>= 0.50.0', license: ['LGPL-2.1-or-later', 'GPL-2.0-or-later'], default_options : [