[empathy] Allow to specify the tab to open in the preferences



commit 0ea5743214b87e35e92b867485d9c5a0f8b5e272
Author: Emilio Pozuelo Monfort <emilio pozuelo collabora co uk>
Date:   Wed Aug 3 15:48:18 2011 +0100

    Allow to specify the tab to open in the preferences
    
    https://bugzilla.gnome.org/show_bug.cgi?id=655884

 src/empathy-main-window.c |    9 +++++++--
 src/empathy-main-window.h |    3 ++-
 src/empathy.c             |   34 +++++++++++++++++++++++++++++-----
 3 files changed, 38 insertions(+), 8 deletions(-)
---
diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c
index cbe44d6..3d09e52 100644
--- a/src/empathy-main-window.c
+++ b/src/empathy-main-window.c
@@ -1876,7 +1876,8 @@ main_window_edit_blocked_contacts_cb (GtkAction         *action,
 }
 
 void
-empathy_main_window_show_preferences (EmpathyMainWindow *window)
+empathy_main_window_show_preferences (EmpathyMainWindow *window,
+    gint tab)
 {
 	EmpathyMainWindowPriv *priv = GET_PRIV (window);
 
@@ -1889,13 +1890,17 @@ empathy_main_window_show_preferences (EmpathyMainWindow *window)
 	} else {
 		gtk_window_present (GTK_WINDOW (priv->preferences));
 	}
+
+	if (tab != -1)
+		empathy_preferences_show_tab (
+			EMPATHY_PREFERENCES (priv->preferences), tab);
 }
 
 static void
 main_window_edit_preferences_cb (GtkAction         *action,
 				 EmpathyMainWindow *window)
 {
-	empathy_main_window_show_preferences (window);
+	empathy_main_window_show_preferences (window, -1);
 }
 
 static void
diff --git a/src/empathy-main-window.h b/src/empathy-main-window.h
index 064086a..4392e73 100644
--- a/src/empathy-main-window.h
+++ b/src/empathy-main-window.h
@@ -53,7 +53,8 @@ GType empathy_main_window_get_type (void);
 
 GtkWidget *empathy_main_window_dup (void);
 
-void empathy_main_window_show_preferences (EmpathyMainWindow *window);
+void empathy_main_window_show_preferences (EmpathyMainWindow *window,
+    gint tab);
 
 G_END_DECLS
 
diff --git a/src/empathy.c b/src/empathy.c
index 8ac944d..66b3877 100644
--- a/src/empathy.c
+++ b/src/empathy.c
@@ -107,6 +107,7 @@ struct _EmpathyApp
   gboolean no_connect;
   gboolean start_hidden;
   gboolean show_preferences;
+  gint preferences_tab;
 
   gboolean activated;
 
@@ -295,7 +296,8 @@ empathy_app_command_line (GApplication *app,
     }
 
   if (self->show_preferences)
-    empathy_main_window_show_preferences (EMPATHY_MAIN_WINDOW (self->window));
+    empathy_main_window_show_preferences (EMPATHY_MAIN_WINDOW (self->window),
+        self->preferences_tab);
 
   if (!self->start_hidden)
     empathy_window_present (GTK_WINDOW (self->window));
@@ -308,6 +310,24 @@ empathy_app_command_line (GApplication *app,
 }
 
 static gboolean
+preferences_cb (const char *option_name,
+    const char *value,
+    gpointer data,
+    GError **error)
+{
+  EmpathyApp *self = data;
+
+  self->show_preferences = TRUE;
+
+  self->preferences_tab = -1;
+
+  if (value != NULL)
+    self->preferences_tab = atoi (value);
+
+  return TRUE;
+}
+
+static gboolean
 show_version_cb (const char *option_name,
     const char *value,
     gpointer data,
@@ -325,9 +345,9 @@ empathy_app_local_command_line (GApplication *app,
   gboolean retval = FALSE;
   GError *error = NULL;
   gboolean no_connect = FALSE, start_hidden = FALSE;
-  gboolean show_preferences = FALSE;
 
   GOptionContext *optcontext;
+  GOptionGroup *group;
   GOptionEntry options[] = {
       { "no-connect", 'n',
         0, G_OPTION_ARG_NONE, &no_connect,
@@ -338,7 +358,7 @@ empathy_app_local_command_line (GApplication *app,
         N_("Don't display the contact list or any other dialogs on startup"),
         NULL },
       { "show-preferences", 'p',
-        0, G_OPTION_ARG_NONE, &show_preferences,
+        G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, &preferences_cb,
         NULL, NULL },
       { "version", 'v',
         G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version_cb,
@@ -346,9 +366,14 @@ empathy_app_local_command_line (GApplication *app,
       { NULL }
   };
 
+  /* We create a group so that GOptionArgFuncs get the user data */
+  group = g_option_group_new ("empathy", NULL, NULL, app, NULL);
+  g_option_group_add_entries (group, options);
+
   optcontext = g_option_context_new (N_("- Empathy IM Client"));
   g_option_context_add_group (optcontext, gtk_get_option_group (TRUE));
-  g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE);
+  g_option_context_set_main_group (optcontext, group);
+  g_option_context_set_translation_domain (optcontext, GETTEXT_PACKAGE);
 
   argc = g_strv_length (*arguments);
 
@@ -376,7 +401,6 @@ empathy_app_local_command_line (GApplication *app,
 
   self->no_connect = no_connect;
   self->start_hidden = start_hidden;
-  self->show_preferences = show_preferences;
 
   return retval;
 }



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