soylent r59 - trunk/src



Author: treitter
Date: Wed Jan 30 08:01:33 2008
New Revision: 59
URL: http://svn.gnome.org/viewvc/soylent?rev=59&view=rev

Log:
pull out common widget signal handler setup code in soylent_browser_dialog_signals_setup(); will expand this to all similar handlers

Modified:
   trunk/src/Makefile.am
   trunk/src/soylent-browser.c
   trunk/src/soylent-utils.h

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Wed Jan 30 08:01:33 2008
@@ -15,6 +15,7 @@
 	soylent-person.h \
 	soylent.c \
 	soylent.h \
+	soylent-utils.c \
 	soylent-utils.h
 
 soylent_CFLAGS = \

Modified: trunk/src/soylent-browser.c
==============================================================================
--- trunk/src/soylent-browser.c	(original)
+++ trunk/src/soylent-browser.c	Wed Jan 30 08:01:33 2008
@@ -75,7 +75,7 @@
                                                EmpathyContact *empathy_contact);
 
 static gboolean soylent_browser_widget_setup (SoylentBrowser *browser);
-static void soylent_browser_dialog_signals_setup (SoylentBrowser *browser);
+static gboolean soylent_browser_dialog_signals_setup (SoylentBrowser *browser);
 static void soylent_browser_person_actions_signals_setup
                                                       (SoylentBrowser *browser);
 static void soylent_browser_person_icons_signals_setup
@@ -1629,37 +1629,56 @@
   return retval;
 }
 
-/* Hook up the dialog box button handlers */
-static void
+/* Hook up the dialog box button handlers
+ *
+ * Return TRUE for success, for FALSE for any failure */
+static gboolean
 soylent_browser_dialog_signals_setup (SoylentBrowser *browser)
 {
+  widget_signal_args_t signal_handlers[] =
+    {
+      {"btn_delete_person_cancel", "clicked", 
+       soylent_browser_person_action_delete_selected_hide_dialog_cb, browser,},
+
+      {"btn_delete_person_confirm", "clicked", 
+       soylent_browser_person_action_delete_selected_finalize_cb, browser},
+
+      {"dia_delete_person_confirm", "delete-event", gtk_widget_hide_on_delete,
+       browser},
+    };
+
+  gboolean retval = FALSE;
   GladeXML *wtree = NULL;
-  GtkDialog *dia_delete_person_confirm = NULL;
-  GtkButton *btn_delete_person_cancel = NULL;
-  GtkButton *btn_delete_person_confirm = NULL;
+  const guint signals_num = WIDGET_SIGNAL_ARGS_LEN (signal_handlers);
+  guint i = -1;
 
+  g_return_val_if_fail (browser != NULL, retval);
+  /* FIXME: uncomment once SoylentBrowser is a GObject:
+  g_return_val_if_fail (SOYLENT_IS_BROWSER (browser), retval);
+   */
 
-  wtree = browser->main_window;
-  dia_delete_person_confirm = GTK_DIALOG (glade_xml_get_widget (wtree,
-                                                  "dia_delete_person_confirm"));
-  btn_delete_person_cancel  = GTK_BUTTON (glade_xml_get_widget (wtree,
-                                                  "btn_delete_person_cancel"));
-  btn_delete_person_confirm = GTK_BUTTON (glade_xml_get_widget (wtree,
-                                                  "btn_delete_person_confirm"));
+  /* invert usual logic to simplify the loop below */
+  retval = TRUE;
 
-  g_signal_connect
-    (G_OBJECT (btn_delete_person_cancel), "clicked",
-     G_CALLBACK (soylent_browser_person_action_delete_selected_hide_dialog_cb),
-     browser);
+  wtree = browser->main_window;
+  for (i = 0; i < signals_num; i++)
+    {
+      gboolean connect_retval = FALSE;
+      widget_signal_args_t cur_args = signal_handlers[i];
 
-  g_signal_connect
-    (G_OBJECT (btn_delete_person_confirm), "clicked",
-     G_CALLBACK (soylent_browser_person_action_delete_selected_finalize_cb),
-     browser);
+      connect_retval = widget_signal_connect (wtree, cur_args.widget_name,
+                                              cur_args.signal_name,
+                                              cur_args.callback,
+                                              cur_args.user_data);
+      if (!connect_retval)
+        {
+          g_critical ("failed to set up signal handler for widget %s::%s\n",
+                      cur_args.widget_name, cur_args.signal_name);
+          retval = FALSE;
+        }
+    }
 
-  g_signal_connect
-    (G_OBJECT (dia_delete_person_confirm), "delete-event",
-     G_CALLBACK (gtk_widget_hide_on_delete), browser);
+  return retval;
 }
 
 /* Hook up handlers for actions related to setting our own presence */
@@ -2031,12 +2050,13 @@
 soylent_browser_signals_setup (SoylentBrowser *browser)
 {
   gboolean retval = FALSE;
+  gboolean dialog_signals_retval = FALSE;
   GladeXML *wtree = NULL;
   GtkWidget *widget = NULL;
 
   wtree = browser->main_window;
 
-  soylent_browser_dialog_signals_setup            (browser);
+  dialog_signals_retval = soylent_browser_dialog_signals_setup (browser);
   soylent_browser_person_actions_signals_setup    (browser);
   soylent_browser_person_icons_signals_setup      (browser);
   soylent_browser_person_info_signals_setup       (browser);

Modified: trunk/src/soylent-utils.h
==============================================================================
--- trunk/src/soylent-utils.h	(original)
+++ trunk/src/soylent-utils.h	Wed Jan 30 08:01:33 2008
@@ -30,4 +30,19 @@
 
 #define STRING_NULL_OR_EMPTY(x) ((!(x)) || (g_str_equal ((x), "")))
 
+#define WIDGET_SIGNAL_ARGS_LEN(x) ((sizeof (x)) / sizeof (widget_signal_args_t))
+
+typedef struct widget_signal_args_tag widget_signal_args_t;
+struct widget_signal_args_tag
+{
+  gchar *widget_name;
+  gchar *signal_name;
+  gpointer callback;
+  gpointer user_data;
+};
+
+gboolean
+widget_signal_connect (GladeXML *wtree, gchar *widget_name, gchar *signal,
+                       gpointer callback, gpointer user_data);
+
 #endif /* _SOYLENT_UTILS_H_ */



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