[gnome-software] Redo commandline handling
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Redo commandline handling
- Date: Fri, 18 Oct 2013 03:28:56 +0000 (UTC)
commit 110a9a03628d4e3da6ddb4f647f3d15b628ea9ce
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Sep 15 20:07:12 2013 -0400
Redo commandline handling
Move all commandline handling to the launcher and convert
the --mode argument into a set-mode action.
src/gs-application.c | 104 ++++++++++++--------------------------------------
src/gs-launcher.c | 65 ++++++++++++++++++++++++++++++-
2 files changed, 88 insertions(+), 81 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 3a578c1..2580751 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -107,9 +107,32 @@ quit_activated (GSimpleAction *action,
g_application_quit (G_APPLICATION (app));
}
+static void
+set_mode_activated (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer data)
+{
+ GsApplication *app = GS_APPLICATION (data);
+ const gchar *mode;
+
+ mode = g_variant_get_string (parameter, NULL);
+ if (g_strcmp0 (mode, "updates") == 0) {
+ gs_shell_set_mode (app->shell, GS_SHELL_MODE_UPDATES);
+ } else if (g_strcmp0 (mode, "installed") == 0) {
+ gs_shell_set_mode (app->shell, GS_SHELL_MODE_INSTALLED);
+ } else if (g_strcmp0 (mode, "overview") == 0) {
+ gs_shell_set_mode (app->shell, GS_SHELL_MODE_OVERVIEW);
+ } else if (g_strcmp0 (mode, "updated") == 0) {
+ gs_shell_set_mode (app->shell, GS_SHELL_MODE_UPDATED);
+ } else {
+ g_warning ("Mode '%s' not recognised", mode);
+ }
+}
+
static GActionEntry actions[] = {
{ "about", about_activated, NULL, NULL, NULL },
- { "quit", quit_activated, NULL, NULL, NULL }
+ { "quit", quit_activated, NULL, NULL, NULL },
+ { "set-mode", set_mode_activated, "s", NULL, NULL }
};
static void
@@ -183,82 +206,6 @@ gs_application_activate (GApplication *application)
gs_shell_activate (GS_APPLICATION (application)->shell);
}
-static int
-gs_application_command_line (GApplication *application,
- GApplicationCommandLine *cmdline)
-{
- GsApplication *app = GS_APPLICATION (application);
- GOptionContext *context;
- gchar *mode = NULL;
- gboolean help = FALSE;
- gboolean verbose = FALSE;
- const GOptionEntry options[] = {
- { "mode", '\0', 0, G_OPTION_ARG_STRING, &mode,
- /* TRANSLATORS: this is a command line option, please don't
- * translate the option names between ‘’ */
- _("Start up mode: either ‘updates’, ‘updated’, ‘search’, ‘installed’ or ‘overview’"),
_("MODE") },
- { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, NULL, NULL },
- { "help", '?', 0, G_OPTION_ARG_NONE, &help, NULL, NULL },
-
- { NULL}
- };
- gchar **args, **argv;
- gint argc;
- gint i;
- GError *error = NULL;
-
- args = g_application_command_line_get_arguments (cmdline, &argc);
- /* We have to make an extra copy of the array, since g_option_context_parse()
- * assumes that it can remove strings from the array without freeing them.
- */
- argv = g_new (gchar*, argc + 1);
- for (i = 0; i <= argc; i++)
- argv[i] = args[i];
-
- context = g_option_context_new ("");
- g_option_context_set_help_enabled (context, FALSE);
- g_option_context_add_main_entries (context, options, NULL);
- if (!g_option_context_parse (context, &argc, &argv, &error)) {
- g_application_command_line_printerr (cmdline, "%s\n", error->message);
- g_error_free (error);
- g_application_command_line_set_exit_status (cmdline, 1);
- g_application_quit (application);
- }
- else if (help) {
- gchar *text;
- text = g_option_context_get_help (context, FALSE, NULL);
- g_application_command_line_print (cmdline, "%s", text);
- g_application_quit (application);
- g_free (text);
- }
- if (verbose)
- g_setenv ("G_MESSAGES_DEBUG", "all", FALSE);
- if (mode) {
- if (g_strcmp0 (mode, "updates") == 0) {
- gs_shell_set_mode (app->shell, GS_SHELL_MODE_UPDATES);
- } else if (g_strcmp0 (mode, "installed") == 0) {
- gs_shell_set_mode (app->shell, GS_SHELL_MODE_INSTALLED);
- } else if (g_strcmp0 (mode, "overview") == 0) {
- gs_shell_set_mode (app->shell, GS_SHELL_MODE_OVERVIEW);
- } else if (g_strcmp0 (mode, "updated") == 0) {
- gs_shell_set_mode (app->shell, GS_SHELL_MODE_UPDATED);
- } else {
- g_warning ("Mode '%s' not recognised", mode);
- }
- } else {
- /* this is the default */
- gs_shell_set_mode (app->shell, GS_SHELL_MODE_OVERVIEW);
- }
-
- g_free (search_value);
- g_free (argv);
- g_strfreev (args);
-
- g_option_context_free (context);
-
- return 0;
-}
-
static void
gs_application_finalize (GObject *object)
{
@@ -277,7 +224,6 @@ gs_application_class_init (GsApplicationClass *class)
G_OBJECT_CLASS (class)->finalize = gs_application_finalize;
G_APPLICATION_CLASS (class)->startup = gs_application_startup;
G_APPLICATION_CLASS (class)->activate = gs_application_activate;
- G_APPLICATION_CLASS (class)->command_line = gs_application_command_line;
}
GsApplication *
@@ -285,7 +231,7 @@ gs_application_new (void)
{
return g_object_new (GS_APPLICATION_TYPE,
"application-id", "org.gnome.Software",
- "flags", G_APPLICATION_HANDLES_COMMAND_LINE | G_APPLICATION_IS_SERVICE,
+ "flags", G_APPLICATION_IS_SERVICE,
NULL);
}
diff --git a/src/gs-launcher.c b/src/gs-launcher.c
index 4cf9db3..b0b6ee7 100644
--- a/src/gs-launcher.c
+++ b/src/gs-launcher.c
@@ -43,17 +43,78 @@ gs_launcher_init (GsLauncher *launcher)
{
}
+static gboolean
+gs_launcher_local_command_line (GApplication *app, gchar ***args, gint *status)
+{
+ GOptionContext *context;
+ gchar *mode = NULL;
+ gboolean version = FALSE;
+ gint argc;
+ const GOptionEntry options[] = {
+ { "mode", '\0', 0, G_OPTION_ARG_STRING, &mode,
+ /* TRANSLATORS: this is a command line option */
+ _("Start up mode: either ‘updates’, ‘updated’, ‘installed’ or ‘overview’"), _("MODE") },
+ { "version", 0, 0, G_OPTION_ARG_NONE, &version, NULL, NULL },
+
+ { NULL}
+ };
+ GError *error = NULL;
+
+ context = g_option_context_new ("");
+ g_option_context_add_main_entries (context, options, NULL);
+
+ argc = g_strv_length (*args);
+ if (!g_option_context_parse (context, &argc, args, &error)) {
+ g_printerr ("%s\n", error->message);
+ g_error_free (error);
+ *status = 1;
+ goto out;
+ }
+
+ if (version) {
+ g_print ("gnome-software " VERSION "\n");
+ *status = 0;
+ goto out;
+ }
+
+ if (!g_application_register (app, NULL, &error)) {
+ g_printerr ("%s\n", error->message);
+ g_error_free (error);
+ *status = 1;
+ goto out;
+ }
+
+ if (mode != NULL) {
+ g_action_group_activate_action (G_ACTION_GROUP (app),
+ "set-mode",
+ g_variant_new_string (mode));
+ } else {
+ g_application_activate (app);
+ }
+
+ *status = 0;
+
+out:
+ g_option_context_free (context);
+
+ return TRUE;
+}
+
static void
gs_launcher_class_init (GsLauncherClass *class)
{
+ GApplicationClass *application_class = G_APPLICATION_CLASS (class);
+
+ application_class->local_command_line = gs_launcher_local_command_line;
}
-GsLauncher *
+static GsLauncher *
gs_launcher_new (void)
{
return g_object_new (gs_launcher_get_type (),
"application-id", "org.gnome.Software",
- "flags", G_APPLICATION_IS_LAUNCHER,
+ "flags", G_APPLICATION_IS_LAUNCHER |
+ G_APPLICATION_SEND_ENVIRONMENT,
NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]