soylent r50 - trunk/src



Author: treitter
Date: Wed Jan 16 07:32:20 2008
New Revision: 50
URL: http://svn.gnome.org/viewvc/soylent?rev=50&view=rev

Log:
check the return values of cleaned up soylent-browser.c functions throughout; fix an editting logic inversion

Modified:
   trunk/src/eds-callbacks.c
   trunk/src/soylent-browser-person-view.c
   trunk/src/soylent-browser.c
   trunk/src/soylent-person.c
   trunk/src/soylent-person.h

Modified: trunk/src/eds-callbacks.c
==============================================================================
--- trunk/src/eds-callbacks.c	(original)
+++ trunk/src/eds-callbacks.c	Wed Jan 16 07:32:20 2008
@@ -129,9 +129,22 @@
                   value = soylent_person_new (browser, e_contact);
                   if (value)
                     {
+                      gboolean update_icon_retval = FALSE;
+
                       g_hash_table_insert (people, (gchar*) e_uid, value);
-                      soylent_browser_update_person_icon (browser, value);
-                      update_groups (browser, e_contact);
+                      update_icon_retval = soylent_browser_update_person_icon
+                                                                      (browser,
+                                                                       value);
+                      if (update_icon_retval)
+                        {
+                          update_groups (browser, e_contact);
+                        }
+                      else
+                        {
+                          g_warning ("failed to update the avatar for a "
+                                     "person");
+                          retval = FALSE;
+                        }
                     }
                   else
                     {
@@ -200,16 +213,37 @@
           value = g_hash_table_lookup (people, e_uid);
           if (value)
             {
-              /* Replace contact */
-              soylent_person_set_e_contact (value, e_contact);
+              gboolean set_e_contact_retval = FALSE;
 
-              g_hash_table_steal (people, e_uid);
-              g_hash_table_insert (people, (gchar*) e_uid, value);
+              /* Replace contact */
+              set_e_contact_retval = soylent_person_set_e_contact (value,
+                                                                   e_contact);
+              if (set_e_contact_retval)
+                {
+                  gboolean update_icon_retval = FALSE;
 
-              /* Update list with possibly new name, photo */
-              soylent_browser_update_person_icon (browser, value);
+                  g_hash_table_steal (people, e_uid);
+                  g_hash_table_insert (people, (gchar*) e_uid, value);
 
-              update_groups (browser, e_contact);
+                  /* Update list with possibly new name, photo */
+                  update_icon_retval = soylent_browser_update_person_icon
+                                                                      (browser,
+                                                                       value);
+                  if (update_icon_retval)
+                    {
+                      update_groups (browser, e_contact);
+                    }
+                  else
+                    {
+                      g_warning ("failed to update the avatar for a person");
+                      retval = FALSE;
+                    }
+                }
+              else
+                {
+                  g_warning ("failed to set the EContact for a person");
+                  retval = FALSE;
+                }
             }
           else
             {
@@ -276,15 +310,21 @@
                                SoylentBrowser *browser)
 {
   gboolean retval = FALSE;
+  gboolean live_setup_retval = FALSE;
 
   g_return_val_if_fail (browser != NULL, retval);
   /* FIXME: uncomment this once SoylentBrowser is a real GObject
   g_return_val_if_fail (SOYLENT_IS_BROWSER (browser), retval);
   */
 
-  /* FIXME: make this function return success/failure, and check it */
-  soylent_browser_live_setup_finish (browser);
+  live_setup_retval = soylent_browser_live_setup_finish (browser);
+  if (!live_setup_retval)
+    {
+      /* non-fatal */
+      g_warning ("failed to set up instant messaging integration");
+    }
 
   retval = TRUE;
+
   return retval;
 }

Modified: trunk/src/soylent-browser-person-view.c
==============================================================================
--- trunk/src/soylent-browser-person-view.c	(original)
+++ trunk/src/soylent-browser-person-view.c	Wed Jan 16 07:32:20 2008
@@ -365,8 +365,16 @@
       }
 #else
       {
+        gboolean set_mode_retval = FALSE;
+
         soylent_browser_person_view_update (browser, person);
-        soylent_browser_view_set_mode (browser, SB_PEOPLE_VIEW_MODE_EDIT);
+
+        set_mode_retval = soylent_browser_view_set_mode
+                                                    (browser,
+                                                     SB_PEOPLE_VIEW_MODE_EDIT);
+
+        /* FIXME: ugly work-around until this function returns gboolean */
+        retval = (set_mode_retval == TRUE) ? 0 : -1;
       }
 #endif /* HAVE_CONTACTS_APP */
     }
@@ -1282,8 +1290,12 @@
   e_contact = pre_person_to_match->e_contact;
   if (browser && e_contact && E_IS_CONTACT (e_contact))
     {
+      gboolean person_select_retval = FALSE;
+
       person = soylent_browser_get_person_from_e_contact (browser, e_contact);
-      if (!soylent_browser_person_select (browser, person, TRUE))
+      person_select_retval = soylent_browser_person_select (browser, person,
+                                                            TRUE);
+      if (person_select_retval)
         {
           if (e_contacts)
             {
@@ -1304,11 +1316,16 @@
                   /* If we've found our match */
                   if (g_str_equal (e_uid, e_uid_cur))
                     {
+                      gboolean set_mode_retval = FALSE;
+
                       soylent_browser_person_view_update (browser, person);
-                      soylent_browser_view_set_mode (browser,
+                      set_mode_retval = soylent_browser_view_set_mode
+                                                    (browser,
                                                      SB_PEOPLE_VIEW_MODE_EDIT);
-
-                      retval = 0;
+                      if (set_mode_retval)
+                        {
+                          retval = 0;
+                        }
                       break;
                     }
                 }

Modified: trunk/src/soylent-browser.c
==============================================================================
--- trunk/src/soylent-browser.c	(original)
+++ trunk/src/soylent-browser.c	Wed Jan 16 07:32:20 2008
@@ -153,7 +153,7 @@
                                                          g_str_equal);
               if (browser->pending_edits)
                 {
-                  gboolean signal_setup_retval = FALSE;
+                  gboolean set_mode_retval = FALSE;
 
                   browser->live_idle = empathy_idle_new ();
                   if (browser->live_idle)
@@ -172,40 +172,50 @@
                                  "handler");
                     }
 
-                  soylent_browser_view_set_mode (browser, view_mode);
-
-                  signal_setup_retval = soylent_browser_signals_setup (browser);
-                  if (signal_setup_retval)
+                  set_mode_retval = soylent_browser_view_set_mode (browser,
+                                                                   view_mode);
+                  if (set_mode_retval)
                     {
-                      gboolean widget_setup_retval = FALSE;
+                      gboolean signal_setup_retval = FALSE;
 
-                      widget_setup_retval = soylent_browser_widget_setup
+                      signal_setup_retval = soylent_browser_signals_setup
                                                                       (browser);
-                      if (widget_setup_retval)
+                      if (signal_setup_retval)
                         {
-                          gboolean ebook_setup_retval = FALSE;
+                          gboolean widget_setup_retval = FALSE;
 
-                          ebook_setup_retval = soylent_browser_ebook_setup
+                          widget_setup_retval = soylent_browser_widget_setup
                                                                       (browser);
-                          if (ebook_setup_retval)
+                          if (widget_setup_retval)
                             {
-                              /* success */
-                              retval = browser;
+                              gboolean ebook_setup_retval = FALSE;
+
+                              ebook_setup_retval = soylent_browser_ebook_setup
+                                                                      (browser);
+                              if (ebook_setup_retval)
+                                {
+                                  /* success */
+                                  retval = browser;
+                                }
+                              else
+                                {
+                                  g_critical ("failed to set up EBook (address "
+                                              "book)");
+                                }
                             }
                           else
                             {
-                              g_critical ("failed to set up EBook (address "
-                                          "book)");
+                              g_critical ("failed to set up major widgets");
                             }
                         }
                       else
                         {
-                          g_critical ("failed to set up major widgets");
+                          g_critical ("failed to set up major GObject signals");
                         }
                     }
                   else
                     {
-                      g_critical ("failed to set up major GObject signals");
+                      g_critical ("failed to set the browser view mode");
                     }
                 }
               else
@@ -895,14 +905,10 @@
       GList *live_contacts = NULL;
       GList *l = NULL;
 
-      /* Set up the callback to handle changes in Empathy IM rosters. */
-      g_signal_connect (G_OBJECT (browser->live_manager), "members-changed",
-                        G_CALLBACK (soylent_browser_live_members_changed_cb),
-                        browser);
-
-      /* FIXME: add "groups-changed" */
-
-      /* Add contacts already created. */
+      /* Manually call the "members-changed" callback to ensure we initialize
+       * our associations for each EmpathyContact (in case we missed the only
+       * "members-changed" signal instance we will get for some people for a
+       * while) */
       live_contacts = empathy_contact_list_get_members
                                 (EMPATHY_CONTACT_LIST (browser->live_manager));
       for (l = live_contacts;
@@ -925,10 +931,25 @@
                                   (EMPATHY_CONTACT_LIST (browser->live_manager),
                                    empathy_contact, NULL, 0, NULL, TRUE,
                                    browser);
-
           g_object_unref (empathy_contact);
         }
 
+      /* XXX: is there any way to clean this up? Can we eliminate the manual
+       * invocation above and rely on the callback to handle this stuff? */
+      /* Consider this function successful if we handled an empty roster (which
+       * can happen if Empathy hasn't populated it by this point) */
+      if (!live_contacts)
+        {
+          retval = TRUE;
+        }
+
+      /* FIXME: add "groups-changed" */
+
+      /* Set up the callback to handle changes in Empathy IM rosters. */
+      g_signal_connect (G_OBJECT (browser->live_manager), "members-changed",
+                        G_CALLBACK (soylent_browser_live_members_changed_cb),
+                        browser);
+
       g_list_free (live_contacts);
     }
   else
@@ -1094,7 +1115,9 @@
 }
 
 /* Update the visual representation of the given SoylentPerson in the given
- * SoylentBrowser */
+ * SoylentBrowser
+ *
+ * Return TRUE for success, FALSE for any failure */
 gboolean
 soylent_browser_update_person_icon (SoylentBrowser *browser,
                                     SoylentPerson *person)
@@ -1489,12 +1512,19 @@
       set_success = soylent_person_set_live_contacts (person, live_contacts);
       if (set_success)
         {
-          /* FIXME: check these return values */
-          soylent_person_live_presence_updated_cb (empathy_contact, NULL,
-                                                   person);
-          soylent_browser_update_person_icon (browser, person);
+          gboolean update_presence_retval = FALSE;
 
-          retval = TRUE;
+          update_presence_retval = soylent_person_live_presence_updated_cb
+                                                              (empathy_contact,
+                                                               NULL, person);
+          if (update_presence_retval)
+            {
+              retval = TRUE;
+            }
+          else
+            {
+              g_warning ("failed to update the online presence of a person");
+            }
         }
     }
   else

Modified: trunk/src/soylent-person.c
==============================================================================
--- trunk/src/soylent-person.c	(original)
+++ trunk/src/soylent-person.c	Wed Jan 16 07:32:20 2008
@@ -428,49 +428,57 @@
 }
 
 /* Propagate IM contacts' presence changes to our internal state, updating
- * the SoylentPerson's representation and other widgets accordingly. */
-void
+ * the SoylentPerson's representation and other widgets accordingly.
+ *
+ * Return TRUE for success, FALSE for any failure
+ */
+gboolean
 soylent_person_live_presence_updated_cb (EmpathyContact *empathy_contact,
                                          GParamSpec *param,
                                          SoylentPerson *person)
 {
+  gboolean retval = FALSE;
   SoylentPresence soylent_person_presence_effective = SP_PRESENCE_OFFLINE;
+  GList *l = NULL;
 
-  if (person)
-    {
-      GList *l = NULL;
-
-      l = person->live_contacts;
-      for (; l && l->data && EMPATHY_IS_CONTACT (l->data); l = g_list_next (l))
+  g_return_val_if_fail (empathy_contact != NULL, retval);
+  g_return_val_if_fail (EMPATHY_IS_CONTACT (empathy_contact), retval);
+  g_return_val_if_fail (person != NULL, retval);
+  /* FIXME: uncomment once SoylentPerson is a GObject:
+  g_return_val_if_fail (SOYLENT_IS_PERSON (person), retval);
+   */
+
+  for (l = person->live_contacts;
+       l && l->data && EMPATHY_IS_CONTACT (l->data);
+       l = g_list_next (l))
+    {
+      EmpathyContact  *empathy_contact_cur = NULL;
+      EmpathyPresence *empathy_presence_cur = NULL;
+      SoylentPresence soylent_presence_cur = SP_PRESENCE_UNSET;
+      
+      empathy_contact_cur = EMPATHY_CONTACT (l->data);
+      empathy_presence_cur = empathy_contact_get_presence
+                                                      (empathy_contact_cur);
+      soylent_presence_cur = soylent_person_presence_from_empathy_presence
+                                                    (empathy_presence_cur);
+      
+      if (SP_PRESENCE_IS_VALID (soylent_presence_cur))
         {
-          EmpathyContact  *empathy_contact_cur = NULL;
-          EmpathyPresence *empathy_presence_cur = NULL;
-          SoylentPresence soylent_presence_cur = SP_PRESENCE_UNSET;
-          
-          empathy_contact_cur = EMPATHY_CONTACT (l->data);
-          empathy_presence_cur = empathy_contact_get_presence
-                                                          (empathy_contact_cur);
-          soylent_presence_cur = soylent_person_presence_from_empathy_presence
-                                                        (empathy_presence_cur);
-          
-          if (SP_PRESENCE_IS_VALID (soylent_presence_cur))
+          if ((soylent_person_live_presence_compare
+                                            (soylent_presence_cur,
+                                             soylent_person_presence_effective))
+              > 0)
             {
-              if ((soylent_person_live_presence_compare (soylent_presence_cur,
-                                            soylent_person_presence_effective))
-                  > 0)
-                {
-                  soylent_person_presence_effective = soylent_presence_cur;
-                }
+              soylent_person_presence_effective = soylent_presence_cur;
             }
         }
-
-      person->presence = soylent_person_presence_effective;
-      soylent_browser_update_person_icon (person->browser, person);
-    }
-  else
-    {
-      g_warning ("%s:%d: person is NULL", __FILE__, __LINE__);
     }
+
+  person->presence = soylent_person_presence_effective;
+
+  retval = soylent_browser_update_person_icon (person->browser, person);
+
+  return retval;
 }
 
 /* Propagate IM contacts' IM name changes to our internal state (most likely
@@ -483,13 +491,23 @@
                  "soylent_person_live_name_updated_cb");
 }
 
+/* FIXME: what's up with all this commented code? */
 /* Propagate IM contacts' avatar changes to our internal state (possibly
- * updating their presented and stored representations) */
-void
+ * updating their presented and stored representations)
+ *
+ * Return TRUE for success, FALSE for any failure */
+gboolean
 soylent_person_live_avatar_updated_cb (EmpathyContact *empathy_contact,
                                        GParamSpec *param, SoylentPerson *person)
 {
+  gboolean retval = FALSE;
   SoylentBrowser *browser = NULL;
+
+  g_return_val_if_fail (person != NULL, retval);
+  /* FIXME: uncomment once SoylentPerson is a GObject:
+  g_return_val_if_fail (SOYLENT_IS_PERSON (person), retval);
+   * */
+
 #if 0
   GdkPixbuf *pixbuf = NULL;
 #endif
@@ -520,7 +538,9 @@
     }
 #endif
 
-  soylent_browser_update_person_icon (browser, person);
+  retval = soylent_browser_update_person_icon (browser, person);
+
+  return retval;
 }
 
 /* ??? */

Modified: trunk/src/soylent-person.h
==============================================================================
--- trunk/src/soylent-person.h	(original)
+++ trunk/src/soylent-person.h	Wed Jan 16 07:32:20 2008
@@ -80,15 +80,16 @@
 void soylent_person_live_groups_updated_cb (EmpathyContact *empathy_contact,
                                             GParamSpec *param,
                                             SoylentPerson *person);
-void soylent_person_live_presence_updated_cb (EmpathyContact *empathy_contact,
-                                              GParamSpec *param,
-                                              SoylentPerson *person);
+gboolean soylent_person_live_presence_updated_cb
+                                              (EmpathyContact *empathy_contact,
+                                               GParamSpec *param,
+                                               SoylentPerson *person);
 void soylent_person_live_name_updated_cb (EmpathyContact *empathy_contact,
                                           GParamSpec *param,
                                           SoylentPerson *person);
-void soylent_person_live_avatar_updated_cb (EmpathyContact *empathy_contact,
-                                            GParamSpec *param,
-                                            SoylentPerson *person);
+gboolean soylent_person_live_avatar_updated_cb (EmpathyContact *empathy_contact,
+                                                GParamSpec *param,
+                                                SoylentPerson *person);
 void soylent_person_live_type_updated_cb (EmpathyContact *empathy_contact,
                                           GParamSpec *param,
                                           SoylentPerson *person);



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