[gnome-control-center] shell: Add -o parameter to show the overview



commit fbbb9c35a925010af25e428ece6a16ea22d667db
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Dec 2 19:17:38 2010 +0000

    shell: Add -o parameter to show the overview
    
    Instead of just presenting the main window.

 shell/control-center.c       |   63 +++++++++++++++++++++++++++++++++++++----
 shell/gnome-control-center.c |    6 ++++
 shell/gnome-control-center.h |    2 +
 3 files changed, 64 insertions(+), 7 deletions(-)
---
diff --git a/shell/control-center.c b/shell/control-center.c
index ae9a12b..684fc37 100644
--- a/shell/control-center.c
+++ b/shell/control-center.c
@@ -22,31 +22,73 @@
 #include "config.h"
 
 #include <glib/gi18n.h>
+#include <stdlib.h>
 
 #include "gnome-control-center.h"
 
 #include <gtk/gtk.h>
 #include <string.h>
 
+G_GNUC_NORETURN static gboolean
+option_version_cb (const gchar *option_name,
+                   const gchar *value,
+                   gpointer     data,
+                   GError     **error)
+{
+  g_print ("%s %s\n", PACKAGE, VERSION);
+  exit (0);
+}
+
+static char **start_panels = NULL;
+static gboolean show_overview = FALSE;
+
+const GOptionEntry all_options[] = {
+  { "version", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_version_cb, NULL, NULL },
+  { "overview", 'o', G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &show_overview, N_("Show the overview"), NULL },
+  { G_OPTION_REMAINING, '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_FILENAME_ARRAY, &start_panels, N_("Panel to display"), NULL },
+  { NULL } /* end the list */
+};
 
 static int
 application_command_line_cb (GApplication  *application,
-			     GApplicationCommandLine  *command_line,
-			     GnomeControlCenter      *shell)
+                             GApplicationCommandLine  *command_line,
+                             GnomeControlCenter      *shell)
 {
   int argc;
   char **argv;
   int retval = 0;
+  GOptionContext *context;
+  GError *error = NULL;
+
+  argv = g_application_command_line_get_arguments (command_line, &argc);
+
+  context = g_option_context_new (N_("- System Settings"));
+  g_option_context_add_main_entries (context, all_options, GETTEXT_PACKAGE);
+  g_option_context_set_translation_domain(context, GETTEXT_PACKAGE);
+  g_option_context_add_group (context, gtk_get_option_group (TRUE));
+
+  if (g_option_context_parse (context, &argc, &argv, &error) == FALSE)
+    {
+      g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
+               error->message, argv[0]);
+      g_error_free (error);
+      g_option_context_free (context);
+      exit (1);
+    }
+  g_option_context_free (context);
 
   gnome_control_center_show (shell, GTK_APPLICATION (application));
 
-  argv = g_application_command_line_get_arguments (command_line, &argc);
-  if (argc == 2)
+  if (show_overview)
+    {
+      gnome_control_center_set_overview_page (shell);
+    }
+  else if (start_panels != NULL && start_panels[0] != NULL)
     {
-      gchar *start_id;
+      const char *start_id;
       GError *err = NULL;
 
-      start_id = argv[1];
+      start_id = start_panels[0];
 
       if (!cc_shell_set_active_panel_from_id (CC_SHELL (shell), start_id, &err))
         {
@@ -64,12 +106,19 @@ application_command_line_cb (GApplication  *application,
   gnome_control_center_present (shell);
 
   g_strfreev (argv);
+  if (start_panels != NULL)
+    {
+      g_strfreev (start_panels);
+      start_panels = NULL;
+    }
+  show_overview = FALSE;
+
   return retval;
 }
 
 static void
 application_startup_cb (GApplication       *application,
-			GnomeControlCenter *shell)
+                        GnomeControlCenter *shell)
 {
   /* nothing to do here, we don't want to show a window before
    * we've looked at the commandline
diff --git a/shell/gnome-control-center.c b/shell/gnome-control-center.c
index 466387a..4f639f3 100644
--- a/shell/gnome-control-center.c
+++ b/shell/gnome-control-center.c
@@ -222,6 +222,12 @@ shell_show_overview_page (GnomeControlCenterPrivate *priv)
                             priv->default_window_icon);
 }
 
+void
+gnome_control_center_set_overview_page (GnomeControlCenter *center)
+{
+  shell_show_overview_page (center->priv);
+}
+
 static void
 item_activated_cb (CcShellCategoryView *view,
                    gchar               *name,
diff --git a/shell/gnome-control-center.h b/shell/gnome-control-center.h
index 10a4c35..50fe5af 100644
--- a/shell/gnome-control-center.h
+++ b/shell/gnome-control-center.h
@@ -72,6 +72,8 @@ void gnome_control_center_present (GnomeControlCenter *center);
 
 void gnome_control_center_show (GnomeControlCenter *center, GtkApplication *app);
 
+void gnome_control_center_set_overview_page (GnomeControlCenter *center);
+
 G_END_DECLS
 
 #endif /* _GNOME_CONTROL_CENTER_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]