soylent r43 - trunk/src



Author: treitter
Date: Sat Jan 12 19:43:28 2008
New Revision: 43
URL: http://svn.gnome.org/viewvc/soylent?rev=43&view=rev

Log:
Check more return values in a few more functions

Modified:
   trunk/src/soylent-browser.c
   trunk/src/soylent-browser.h

Modified: trunk/src/soylent-browser.c
==============================================================================
--- trunk/src/soylent-browser.c	(original)
+++ trunk/src/soylent-browser.c	Sat Jan 12 19:43:28 2008
@@ -450,45 +450,51 @@
 GList*
 soylent_browser_get_selected_people_e_contact (SoylentBrowser *browser)
 {
+  GList *retval = NULL;
   GList *selected_people_e_uids = NULL;
   GList *l = NULL;
-  GList *selected_people_e_contacts = NULL;
-  SoylentPerson *person = NULL;
-  gchar *e_uid = NULL;
   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), NULL);
+   */
+
   selected_people_e_uids = soylent_browser_get_selected_people_e_uid (browser);
 
   /* TODO: use gtk_icon_view_selected_foreach () */
 
   for (i = 0, l = selected_people_e_uids; l != NULL; l = g_list_next (l))
     {
-      e_uid = (gchar*) l->data;
+      gchar *e_uid = NULL;
 
-      if (!e_uid)
+      e_uid = (gchar*) l->data;
+      if (e_uid)
         {
-          g_warning ("list of selected people contains NULL UID\n");
-          continue;
-        }
+          SoylentPerson *person = NULL;
 
-      person = g_hash_table_lookup (browser->people, e_uid);
-
-      if (person)
-        {
-          EContact *e_contact = NULL;
-          
-          e_contact = soylent_person_get_e_contact (person);
-          if (e_contact && E_IS_CONTACT (e_contact))
+          person = g_hash_table_lookup (browser->people, e_uid);
+          if (person)
+            {
+              EContact *e_contact = NULL;
+              
+              e_contact = soylent_person_get_e_contact (person);
+              if (e_contact && E_IS_CONTACT (e_contact))
+                {
+                  retval = g_list_prepend (retval, e_contact);
+                }
+            }
+          else
             {
-              selected_people_e_contacts = g_list_prepend
-                                                    (selected_people_e_contacts,
-                                                     e_contact);
+              g_warning ("invalid UID: '%s'\n", e_uid);
             }
+
+          g_free (e_uid);
         }
       else
-        g_warning ("invalid UID: '%s'\n", e_uid);
-
-      g_free (e_uid);
+        {
+          g_warning ("list of selected people contains NULL UID\n");
+        }
     }
 
   if (selected_people_e_uids)
@@ -496,42 +502,61 @@
       g_list_free (selected_people_e_uids);
     }
 
-  return selected_people_e_contacts;
+  return retval;
 }
 
 /* Get the EContact IDs of the currently-selected people. Kinda hacky. */
 GList*
 soylent_browser_get_selected_people_e_uid (SoylentBrowser *browser)
 {
+  GList *retval = NULL;
   GladeXML *wtree = NULL;
   GtkIconView *iconview = NULL;
   GList *selected_people = NULL;
   GList *l = NULL;
-  GList *selected_e_uids = NULL;
   guint i = 0;
 
-  wtree = browser->main_window;
-  iconview = GTK_ICON_VIEW (glade_xml_get_widget (wtree, "iv_people"));
-  selected_people = gtk_icon_view_get_selected_items (iconview);
+  g_return_val_if_fail (browser != NULL, retval);
+  /* FIXME: uncomment once SoylentBrowser is a GObject:
+  g_return_val_if_fail (SOYLENT_IS_BROWSER (browser), NULL);
+   */
 
-  /* TODO: use gtk_icon_view_selected_foreach () */
-  for (i = 0, l = selected_people; l != NULL; l = g_list_next (l))
+  wtree = browser->main_window;
+  if (wtree && GLADE_IS_XML (wtree))
     {
-      GtkTreePath *path = NULL;
-      GtkTreeModel *model = NULL;
-      GtkTreeIter iter;
-      gchar *e_uid = NULL;
+      iconview = GTK_ICON_VIEW (glade_xml_get_widget (wtree, "iv_people"));
+      if (iconview)
+        {
+          selected_people = gtk_icon_view_get_selected_items (iconview);
+
+          /* TODO: use gtk_icon_view_selected_foreach () */
+          for (i = 0, l = selected_people; l != NULL; l = g_list_next (l))
+            {
+              GtkTreePath *path = NULL;
+              GtkTreeModel *model = NULL;
+              GtkTreeIter iter;
+              gchar *e_uid = NULL;
 
-      path = (GtkTreePath *) l->data;
-      model = gtk_icon_view_get_model(iconview);
+              path = (GtkTreePath *) l->data;
+              model = gtk_icon_view_get_model(iconview);
 
-      gtk_tree_model_get_iter (model, &iter, path);
-      gtk_tree_model_get (model, &iter, PEOPLE_COL_UID, &e_uid, -1);
+              gtk_tree_model_get_iter (model, &iter, path);
+              gtk_tree_model_get (model, &iter, PEOPLE_COL_UID, &e_uid, -1);
 
-      selected_e_uids = g_list_prepend (selected_e_uids, g_strdup (e_uid));
+              retval = g_list_prepend (retval, g_strdup (e_uid));
+            }
+        }
+      else
+        {
+          g_warning ("failed to get main icon view widget");
+        }
     }
- 
-  return selected_e_uids;
+  else
+    {
+      g_warning ("SoylentBrowser's widget tree is invalid");
+    }
+
+  return retval;
 }
 
 /* Get the SoylentPerson* of the currently-selected user (or first-selected, if
@@ -540,23 +565,30 @@
 soylent_browser_get_selected_person (SoylentBrowser *browser)
 {
   gchar *e_uid = NULL;
-  SoylentPerson *person = NULL;
+  SoylentPerson *retval = NULL;
+
+  g_return_val_if_fail (browser != NULL, retval);
+  /* FIXME: uncomment once SoylentBrowser is a GObject:
+  g_return_val_if_fail (SOYLENT_IS_BROWSER (browser), NULL);
+   */
   
   e_uid = soylent_browser_get_selected_person_e_uid (browser);
-  if (!e_uid)
+  if (e_uid)
     {
-      return NULL;
-    }
+      retval = g_hash_table_lookup (browser->people, e_uid);
+      if (!retval)
+        {
+          g_warning ("invalid UID: '%s'\n", e_uid);
+        }
 
-  person = g_hash_table_lookup (browser->people, e_uid);
-  if (!person)
+      g_free (e_uid);
+    }
+  else
     {
-      g_warning ("invalid UID: '%s'\n", e_uid);
+      /* nobody is selected */
     }
 
-  g_free (e_uid);
-
-  return person;  
+  return retval;  
 }
 
 /* Get the EContact* of the currently-selected user (or first-selected, if a
@@ -587,29 +619,73 @@
 gchar*
 soylent_browser_get_selected_person_e_uid (SoylentBrowser *browser)
 {
+  gchar *retval = NULL;
   GladeXML *wtree = NULL;
-  GtkIconView *iconview = NULL;
-  GList *selected_people = NULL;
-  GtkTreePath *path = NULL;
-  GtkTreeModel *model = NULL;
   GtkTreeIter iter;
   gchar *e_uid = NULL;
 
+  g_return_val_if_fail (browser != NULL, NULL);
+  /* FIXME: uncomment once SoylentBrowser is a GObject:
+  g_return_val_if_fail (SOYLENT_IS_BROWSER (browser), NULL);
+   */
+
   wtree = browser->main_window;
-  iconview = GTK_ICON_VIEW (glade_xml_get_widget (wtree, "iv_people"));
-  selected_people = gtk_icon_view_get_selected_items (iconview);
+  if (wtree && GLADE_IS_XML (wtree))
+    {
+      GtkIconView *iconview = NULL;
+
+      iconview = GTK_ICON_VIEW (glade_xml_get_widget (wtree, "iv_people"));
+      if (iconview && GTK_IS_ICON_VIEW (iconview))
+        {
+          GList *selected_people = NULL;
 
-  if (selected_people == NULL)
+          selected_people = gtk_icon_view_get_selected_items (iconview);
+          if (selected_people)
+            {
+              GtkTreePath *path = NULL;
+
+              path = (GtkTreePath*) selected_people->data;
+              if (path)
+                {
+                  GtkTreeModel *model = NULL;
+
+                  model = gtk_icon_view_get_model (iconview);
+                  if (model)
+                    {
+                      gtk_tree_model_get_iter (model, &iter, path);
+                      gtk_tree_model_get (model, &iter, PEOPLE_COL_UID, &e_uid,
+                                          -1);
+
+                      /* FIXME: this doesn't distinguish between memory
+                       * allocation failure and the "nobody is selected" case */
+                      retval = g_strdup (e_uid);
+                      if (!retval)
+                        {
+                          g_warning ("failed to duplicate person's e-d-s UID");
+                        }
+                    }
+                }
+              else
+                {
+                  g_warning ("selected people have a NULL GtkTreePath");
+                }
+            }
+          else
+            {
+              /* nobody is selected */
+            }
+        }
+      else
+        {
+          g_warning ("main icon view widget is invalid");
+        }
+    }
+  else
     {
-      return NULL;
+      g_warning ("SoylentBrowser's widget tree is invalid");
     }
-
-  path = (GtkTreePath*) selected_people->data;
-  model = gtk_icon_view_get_model (iconview);
-  gtk_tree_model_get_iter (model, &iter, path);
-  gtk_tree_model_get (model, &iter, PEOPLE_COL_UID, &e_uid, -1);
  
-  return g_strdup (e_uid);
+  return retval;
 }
 
 /* Find the given EmpathyContact among the SoylentBrowser's IM contacts */
@@ -617,77 +693,135 @@
 soylent_browser_live_contact_find_owner_person (SoylentBrowser *browser,
                                                 EmpathyContact *empathy_contact)
 {
-  EBookQuery *query = NULL;
-  GError *error = NULL;
+  SoylentPerson *retval = NULL;
   const gchar *live_name = NULL;
-  McAccount *account = NULL;
-  McProfile *profile = NULL;
-  const gchar *proto = NULL;
-  GList *e_contacts = NULL;
-  GList *l = NULL;
-  EContact *match = NULL;
-  SoylentPerson *person = NULL;
-  gchar *e_contact_field_id_name = NULL;
-  EContactField proto_e_contact_field = 0;
 
-  live_name = empathy_contact_get_id (empathy_contact);
-  account = empathy_contact_get_account (empathy_contact);
-  profile = mc_account_get_profile (account);
-  proto = mc_profile_get_protocol_name (profile);
-
-  /* XXX: we should maybe do this directly in the hash... though it'd probably
-   * be a lot slower. */
-
-  e_contact_field_id_name = g_strdup_printf ("im_%s", proto);
-  proto_e_contact_field = e_contact_field_id (e_contact_field_id_name);
-  g_free (e_contact_field_id_name);
+  g_return_val_if_fail (browser != NULL, retval);
+  /* FIXME: uncomment once SoylentBrowser is a GObject:
+  g_return_val_if_fail (SOYLENT_IS_BROWSER (browser), NULL);
+   */
+  g_return_val_if_fail (empathy_contact != NULL, retval);
+  g_return_val_if_fail (EMPATHY_IS_CONTACT (empathy_contact), retval);
 
-  if (proto_e_contact_field <= 0)
+  live_name = empathy_contact_get_id (empathy_contact);
+  if (live_name)
     {
-      return NULL;
-    }
-
-  query = e_book_query_field_test (proto_e_contact_field, E_BOOK_QUERY_IS,
-                                   live_name);
+      McAccount *account = NULL;
 
-  if (!e_book_get_contacts (browser->book, query, &e_contacts, &error))
-    {
-      g_warning ("Unable to query addressbook for username '%s': %s",
-                live_name, error->message);
-      g_error_free (error);
-    }
-    
-  for (l = e_contacts; l; l = g_list_next (l))
-    {
-      /* Just match the first one, for now */
-      if (!match)
+      account = empathy_contact_get_account (empathy_contact);
+      if (account)
         {
-          match = E_CONTACT (l->data);
+          McProfile *profile = NULL;
+
+          profile = mc_account_get_profile (account);
+          if (profile)
+            {
+              const gchar *proto = NULL;
+
+              proto = mc_profile_get_protocol_name (profile);
+              if (proto)
+                {
+                  gchar *e_contact_field_id_name = NULL;
+                  EContactField proto_e_contact_field = 0;
+
+                  /* XXX: we should maybe do this directly in the hash... though
+                   * it'd probably be a lot slower. */
+                  e_contact_field_id_name = g_strdup_printf ("im_%s", proto);
+                  proto_e_contact_field = e_contact_field_id
+                                                      (e_contact_field_id_name);
+                  g_free (e_contact_field_id_name);
+
+                  if (proto_e_contact_field > 0)
+                    {
+                      gboolean get_contacts_retval = FALSE;
+                      EBookQuery *query = NULL;
+                      GList *e_contacts = NULL;
+                      GError *error = NULL;
+
+                      query = e_book_query_field_test (proto_e_contact_field,
+                                                       E_BOOK_QUERY_IS,
+                                                       live_name);
+
+                      get_contacts_retval = e_book_get_contacts (browser->book,
+                                                                 query,
+                                                                 &e_contacts,
+                                                                 &error);
+                      if (get_contacts_retval)
+                        {
+                          EContact *match = NULL;
+                          GList *l = NULL;
+
+                          for (l = e_contacts; l; l = g_list_next (l))
+                            {
+                              /* Just match the first one, for now */
+                              if (!match)
+                                {
+                                  match = E_CONTACT (l->data);
+                                }
+                              else if (l->data)
+                                {
+                                  g_object_unref (l->data);
+                                }
+                            }
+                              
+                          e_book_query_unref (query);
+                          g_list_free (e_contacts);
+
+                          if (match)
+                            {
+                              retval = soylent_browser_get_person_from_e_contact
+                                                                      (browser,
+                                                                       match);
+                            }
+                        }
+                      else
+                        {
+                          g_warning ("query to addressbook for username "
+                                    "'%s' failed: %s", live_name,
+                                    error->message);
+                          g_error_free (error);
+                        }
+                    }
+                }
+              else
+                {
+                  g_warning ("failed to get protocol name for McProfile");
+                }
+            }
+          else
+            {
+              g_warning ("failed to get McProfile for McAccount");
+            }
         }
-      else if (l->data)
+      else
         {
-          g_object_unref (l->data);
+          g_warning ("failed to get McAccount for EmpathyContact");
         }
     }
-      
-  e_book_query_unref (query);
-  g_list_free (e_contacts);
-
-  if (match)
+  else
     {
-      person = soylent_browser_get_person_from_e_contact (browser, match);
+      g_warning ("failed to get username for EmpathyContact");
     }
 
-  return person;
+  return retval;
 }
 
-/* Set our IM presence for all of our accounts */
-void
+/* Set our IM presence for all of our accounts.
+ *
+ * Return TRUE for success, FALSE for any amount of failure. */
+gboolean
 soylent_browser_presence_set_cb (GtkWidget *widget, gpointer user_data)
 {
+  gboolean retval = FALSE;
   SoylentBrowser *browser = NULL;
 
+  g_return_val_if_fail (widget != NULL, retval);
+  g_return_val_if_fail (GTK_IS_COMBO_BOX (widget), retval);
+  g_return_val_if_fail (user_data != NULL, retval);
+
   browser = (SoylentBrowser*) user_data;
+  /* TODO: also check that the browser is a SoylentBrowser GObject, once
+   * SoylentBrowser is a GObject */
   if (browser->live_idle)
     {
       GtkComboBox *cbox = NULL;
@@ -722,20 +856,35 @@
 
       if (presence_new != MC_PRESENCE_UNSET)
         {
+          /* XXX: would check this value, but this function is void */
           empathy_idle_set_presence (browser->live_idle, presence_new,
                                      active_text);
+          retval = TRUE;
         }
     }
   else
     {
       g_warning ("Empathy idle handler is NULL");
     }
+
+  return retval;
 }
 
-/* Distribute known, online EmpathyContacts to their matching SoylentPersons */
-void
+/* Distribute known, online EmpathyContacts to their matching SoylentPersons.
+ *
+ * Return TRUE for success, FALSE for any amount of failure. */
+gboolean
 soylent_browser_live_setup_finish (SoylentBrowser *browser)
 {
+  gboolean retval = FALSE;
+
+  g_return_val_if_fail (browser != NULL, retval);
+  /* FIXME: uncomment once SoylentBrowser is a GObject:
+  g_return_val_if_fail (SOYLENT_IS_BROWSER (browser), NULL);
+   */
+
+  /* XXX: would check return value, but this function is void */
+  /* Set up contact list */
   empathy_status_presets_get_all ();
 
   browser->live_manager = empathy_contact_manager_new ();
@@ -770,10 +919,10 @@
            * SoylentPeople changes to the EmpathyContact affect, to perform
            * reactions quickly */
 
-          soylent_browser_live_members_changed_cb (EMPATHY_CONTACT_LIST
-                                                        (browser->live_manager),
-                                                   empathy_contact, NULL, 0,
-                                                   NULL, TRUE, browser);
+          retval = soylent_browser_live_members_changed_cb
+                                  (EMPATHY_CONTACT_LIST (browser->live_manager),
+                                   empathy_contact, NULL, 0, NULL, TRUE,
+                                   browser);
 
           g_object_unref (empathy_contact);
         }
@@ -784,6 +933,8 @@
     {
       g_warning ("unable to initialize Connection Manager");
     }
+
+  return retval;
 }
 
 
@@ -1031,8 +1182,10 @@
   gtk_main_quit();
 }
 
-/* Handle additions and removals of contacts to the given IM account's roster */
-void
+/* Handle additions and removals of contacts to the given IM account's roster
+ *
+ * Return TRUE for success, FALSE for any amount of failure */
+gboolean
 soylent_browser_live_members_changed_cb (EmpathyContactList *list_iface,
                                          EmpathyContact *empathy_contact,
                                          EmpathyContact *actor,
@@ -1040,6 +1193,7 @@
                                          gboolean is_member,
                                          SoylentBrowser *browser)
 {
+  gboolean retval = FALSE;
   SoylentPerson *person;
 
   person = soylent_browser_live_contact_find_owner_person (browser,
@@ -1094,6 +1248,11 @@
                              (gpointer) person);
         }
     }
+
+  /* FIXME: actually set this above */
+  retval = TRUE;
+
+  return retval;
 }
 
 /* Compare the display names of two people in the main icon view; used to sort

Modified: trunk/src/soylent-browser.h
==============================================================================
--- trunk/src/soylent-browser.h	(original)
+++ trunk/src/soylent-browser.h	Sat Jan 12 19:43:28 2008
@@ -119,7 +119,7 @@
 gchar*         soylent_browser_get_selected_person_e_uid
                                                       (SoylentBrowser *browser);
 
-void soylent_browser_live_setup_finish (SoylentBrowser *browser);
+gboolean soylent_browser_live_setup_finish (SoylentBrowser *browser);
 
 SoylentBrowser* soylent_browser_new (void);
 void soylent_browser_destroy (SoylentBrowser *browser);
@@ -136,13 +136,14 @@
 
 void soylent_browser_delete_cb (GtkWidget *widget, GdkEvent *event,
                                 gpointer user_data);
-void soylent_browser_live_members_changed_cb (EmpathyContactList *list_iface,
-                                              EmpathyContact *empathy_contact,
-                                              EmpathyContact *actor,
-                                              guint reason,
-                                              gchar *message,
-                                              gboolean is_member,
-                                              SoylentBrowser *browser);
-void soylent_browser_presence_set_cb (GtkWidget *widget, gpointer user_data);
+gboolean soylent_browser_live_members_changed_cb
+                                              (EmpathyContactList *list_iface,
+                                               EmpathyContact *empathy_contact,
+                                               EmpathyContact *actor,
+                                               guint reason, gchar *message,
+                                               gboolean is_member,
+                                               SoylentBrowser *browser);
+gboolean soylent_browser_presence_set_cb (GtkWidget *widget,
+                                          gpointer user_data);
 
 #endif /* _SOYLENT_BROWSER_H_ */



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