soylent r68 - trunk/src



Author: treitter
Date: Mon Feb 11 00:21:35 2008
New Revision: 68
URL: http://svn.gnome.org/viewvc/soylent?rev=68&view=rev

Log:
Simplify the phone-number-editing signal setup function

Modified:
   trunk/src/soylent-browser.c

Modified: trunk/src/soylent-browser.c
==============================================================================
--- trunk/src/soylent-browser.c	(original)
+++ trunk/src/soylent-browser.c	Mon Feb 11 00:21:35 2008
@@ -80,7 +80,7 @@
                                                       (SoylentBrowser *browser);
 static gboolean soylent_browser_person_info_email_signals_setup
                                                       (SoylentBrowser *browser);
-static void soylent_browser_person_info_phone_signals_setup
+static gboolean soylent_browser_person_info_phone_signals_setup
                                                       (SoylentBrowser *browser);
 static void soylent_browser_person_info_im_signals_setup
                                                       (SoylentBrowser *browser);
@@ -1770,42 +1770,72 @@
 }
 
 /* Hook up handlers for edits to peoples' existing phone numbers */
-static void
+static gboolean
 soylent_browser_person_info_phone_signals_setup (SoylentBrowser *browser)
 {
-  const guint NUM_CONTEXT = 3;
   const guint CONTEXT_POS_WORK = 0;
-  const gchar *context_list[] = {"work", "home", "cell",};
-  const guint e_contact_fields[] = {E_CONTACT_PHONE_BUSINESS,
-                                    E_CONTACT_PHONE_HOME,
-                                    E_CONTACT_PHONE_MOBILE,};
+  const guint NUM_CONTEXT = 3;
+  gboolean retval = FALSE;
   GladeXML *wtree = NULL;
-  guint context = CONTEXT_POS_WORK;
+  guint i = 0;
+
+  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;
 
-  for (context = CONTEXT_POS_WORK; context < NUM_CONTEXT; context++)
+  /* invert usual logic to simplify the loop below */
+  retval = TRUE;
+
+  for (i = CONTEXT_POS_WORK; i < NUM_CONTEXT; i++)
     {
-      gchar *widget_str = NULL;
-      GtkEntry *entry_phone = NULL;
+      /* TODO: factor this out somewhere else, if possible */
+      const gchar *context_list[] = {"work", "home", "cell",};
+      const guint e_contact_fields[] = {E_CONTACT_PHONE_BUSINESS,
+                                        E_CONTACT_PHONE_HOME,
+                                        E_CONTACT_PHONE_MOBILE,};
+      const gchar *signal_name = "changed";
+      const GCallback callback = G_CALLBACK (entry_changed_e_contact);
+      gboolean connect_retval = FALSE;
+      gchar *widget_name = NULL;
       cb_entry_changed_e_contact *cb_data = NULL;
 
-      widget_str = g_strdup_printf ("entry_person_phone_%s",
-                                    context_list[context]);
-      entry_phone = GTK_ENTRY (glade_xml_get_widget (wtree, widget_str));
+      widget_name = g_strdup_printf ("entry_person_phone_%s",
+                                     context_list[i]);
 
       cb_data = g_new0 (cb_entry_changed_e_contact, 1);
       cb_data->browser = browser;
-      cb_data->widget_name = g_strdup (widget_str);
-      g_free (widget_str);
+      cb_data->widget_name = g_strdup (widget_name);
       cb_data->field = g_new0 (EContactField, 1);
-      *(cb_data->field) = e_contact_fields[context];
+      *(cb_data->field) = e_contact_fields[i];
 
-      /* FIXME - use g_signal_connect_data so we can eventually free
-       * each instance of cb_data */
-      g_signal_connect (G_OBJECT (entry_phone), "changed",
-                        G_CALLBACK (entry_changed_e_contact), cb_data);
+      if (cb_data)
+        {
+          /* FIXME - use a version which uses g_signal_connect_data so we can
+           * eventually free each instance of cb_data */
+          connect_retval = widget_signal_connect (wtree, widget_name,
+                                                  signal_name, callback,
+                                                  cb_data);
+
+          if (!connect_retval)
+            {
+              g_critical ("failed to set up signal handler for widget %s::%s\n",
+                          widget_name, signal_name);
+              retval = FALSE;
+            }
+        }
+      else
+        {
+          g_critical ("failed to set up callback data for widget %s::%s\n",
+                      widget_name, signal_name);
+        }
+
+      g_free (widget_name);
     }
+
+  return retval;
 }
 
 /* Hook up handlers for edits to peoples' existing IM names */



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