[empathy] Make the #defines an static array



commit f9716e53331ccbd0725a14089ad30e9d6c84a463
Author: Emilio Pozuelo Monfort <emilio pozuelo collabora co uk>
Date:   Thu Aug 4 09:53:25 2011 +0100

    Make the #defines an static array

 src/Makefile.am           |    2 ++
 src/empathy-call-window.c |    8 ++++++--
 src/empathy-preferences.c |   40 ++++++++++++++++++++++++++--------------
 src/empathy-preferences.h |   12 ++++--------
 4 files changed, 38 insertions(+), 24 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 40adee6..b2222c2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -169,6 +169,8 @@ empathy_call_SOURCES = \
        empathy-video-src.h \
        empathy-video-widget.c \
        empathy-video-widget.h \
+       empathy-preferences.c \
+       empathy-preferences.h \
        ev-sidebar.c \
        ev-sidebar.h \
        empathy-mic-menu.c \
diff --git a/src/empathy-call-window.c b/src/empathy-call-window.c
index 215bb5c..3ce138f 100644
--- a/src/empathy-call-window.c
+++ b/src/empathy-call-window.c
@@ -735,8 +735,12 @@ static void
 empathy_call_window_settings_cb (GtkAction *action,
     EmpathyCallWindow *self)
 {
-  empathy_launch_program (BIN_DIR, "empathy",
-      "-p " EMPATHY_PREFERENCES_STR_TAB_CALLS);
+  gchar *args = g_strdup_printf ("-p %s",
+      empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
+
+  empathy_launch_program (BIN_DIR, "empathy", args);
+
+  g_free (args);
 }
 
 static void
diff --git a/src/empathy-preferences.c b/src/empathy-preferences.c
index 4b3e076..e593c6f 100644
--- a/src/empathy-preferences.c
+++ b/src/empathy-preferences.c
@@ -55,6 +55,17 @@ G_DEFINE_TYPE (EmpathyPreferences, empathy_preferences, GTK_TYPE_DIALOG);
 
 #define GET_PRIV(self) ((EmpathyPreferencesPriv *)((EmpathyPreferences *) self)->priv)
 
+static const gchar * empathy_preferences_tabs[] =
+{
+  "general",
+  "notifications",
+  "sounds",
+  "calls",
+  "location",
+  "spell",
+  "themes",
+};
+
 struct _EmpathyPreferencesPriv {
 	GtkWidget *notebook;
 
@@ -1241,25 +1252,26 @@ empathy_preferences_init (EmpathyPreferences *preferences)
 static EmpathyPreferencesTab
 empathy_preferences_tab_from_string (const gchar *str)
 {
-  if (!tp_strdiff (str, EMPATHY_PREFERENCES_STR_TAB_GENERAL))
-    return EMPATHY_PREFERENCES_TAB_GENERAL;
-  else if (!tp_strdiff (str, EMPATHY_PREFERENCES_STR_TAB_NOTIFICATIONS))
-    return EMPATHY_PREFERENCES_TAB_NOTIFICATIONS;
-  else if (!tp_strdiff (str, EMPATHY_PREFERENCES_STR_TAB_SOUNDS))
-    return EMPATHY_PREFERENCES_TAB_SOUNDS;
-  else if (!tp_strdiff (str, EMPATHY_PREFERENCES_STR_TAB_CALLS))
-    return EMPATHY_PREFERENCES_TAB_CALLS;
-  else if (!tp_strdiff (str, EMPATHY_PREFERENCES_STR_TAB_LOCATION))
-    return EMPATHY_PREFERENCES_TAB_LOCATION;
-  else if (!tp_strdiff (str, EMPATHY_PREFERENCES_STR_TAB_SPELL))
-    return EMPATHY_PREFERENCES_TAB_SPELL;
-  else if (!tp_strdiff (str, EMPATHY_PREFERENCES_STR_TAB_THEMES))
-    return EMPATHY_PREFERENCES_TAB_THEMES;
+  guint i;
+
+  for (i = 0; i < G_N_ELEMENTS (empathy_preferences_tabs); i++)
+    {
+      if (!tp_strdiff (str, empathy_preferences_tabs[i]))
+        return i;
+    }
 
   g_warn_if_reached ();
   return -1;
 }
 
+const gchar *
+empathy_preferences_tab_to_string (EmpathyPreferencesTab tab)
+{
+  g_return_val_if_fail (tab < G_N_ELEMENTS (empathy_preferences_tabs), NULL);
+
+  return empathy_preferences_tabs[tab];
+}
+
 GtkWidget *
 empathy_preferences_new (GtkWindow *parent)
 {
diff --git a/src/empathy-preferences.h b/src/empathy-preferences.h
index daaaecc..fef0646 100644
--- a/src/empathy-preferences.h
+++ b/src/empathy-preferences.h
@@ -50,6 +50,7 @@ struct _EmpathyPreferencesClass {
 	GtkDialogClass parent_class;
 };
 
+/* Keep this enum and the array in empathy-preferences.c in sync */
 typedef enum
 {
   EMPATHY_PREFERENCES_TAB_GENERAL,
@@ -61,14 +62,6 @@ typedef enum
   EMPATHY_PREFERENCES_TAB_THEMES,
 } EmpathyPreferencesTab;
 
-#define EMPATHY_PREFERENCES_STR_TAB_GENERAL "general"
-#define EMPATHY_PREFERENCES_STR_TAB_NOTIFICATIONS "notifications"
-#define EMPATHY_PREFERENCES_STR_TAB_SOUNDS "sounds"
-#define EMPATHY_PREFERENCES_STR_TAB_CALLS "calls"
-#define EMPATHY_PREFERENCES_STR_TAB_LOCATION "location"
-#define EMPATHY_PREFERENCES_STR_TAB_SPELL "spell"
-#define EMPATHY_PREFERENCES_STR_TAB_THEMES "themes"
-
 GType empathy_preferences_get_type (void);
 
 GtkWidget *empathy_preferences_new (GtkWindow *parent);
@@ -76,6 +69,9 @@ GtkWidget *empathy_preferences_new (GtkWindow *parent);
 void empathy_preferences_show_tab (EmpathyPreferences *self,
     const gchar *tab);
 
+const gchar *
+empathy_preferences_tab_to_string (EmpathyPreferencesTab tab);
+
 G_END_DECLS
 
 #endif /* __EMPATHY_PREFERENCES_H__ */



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