Merge branch '19-select-user' into 'master'
Resolve "Add command line option to malcontent-control to pre-select a user" Closes #19 See merge request pwithnall/malcontent!95
This commit is contained in:
commit
540c337ae1
|
@ -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
|
||||||
|
* it’s 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
|
||||||
|
|
|
@ -506,3 +506,38 @@ mct_user_selector_get_user (MctUserSelector *self)
|
||||||
|
|
||||||
return self->user;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -34,4 +34,7 @@ MctUserSelector *mct_user_selector_new (ActUserManager *user_manager);
|
||||||
|
|
||||||
ActUser *mct_user_selector_get_user (MctUserSelector *self);
|
ActUser *mct_user_selector_get_user (MctUserSelector *self);
|
||||||
|
|
||||||
|
gboolean mct_user_selector_select_user_by_username (MctUserSelector *self,
|
||||||
|
const gchar *username);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
project('malcontent', 'c',
|
project('malcontent', 'c',
|
||||||
version : '0.9.0',
|
version : '0.10.0',
|
||||||
meson_version : '>= 0.50.0',
|
meson_version : '>= 0.50.0',
|
||||||
license: ['LGPL-2.1-or-later', 'GPL-2.0-or-later'],
|
license: ['LGPL-2.1-or-later', 'GPL-2.0-or-later'],
|
||||||
default_options : [
|
default_options : [
|
||||||
|
|
Loading…
Reference in New Issue