soylent r57 - trunk/src



Author: treitter
Date: Tue Jan 29 05:48:23 2008
New Revision: 57
URL: http://svn.gnome.org/viewvc/soylent?rev=57&view=rev

Log:
clean up more soylent-browser.c functions

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

Modified: trunk/src/soylent-browser-person-view.c
==============================================================================
--- trunk/src/soylent-browser-person-view.c	(original)
+++ trunk/src/soylent-browser-person-view.c	Tue Jan 29 05:48:23 2008
@@ -187,13 +187,13 @@
                     }
                   else
                     {
-                      g_warning ("failed to get the EBookView for the "
-                                 "SoylentBrowser");
+                      g_critical ("failed to get the EBookView for the "
+                                  "SoylentBrowser");
                     }
                 }
               else
                 {
-                  g_warning ("failed to get EBook for the SoylentBrowser");
+                  g_critical ("failed to get EBook for the SoylentBrowser");
                 }
             }
           else
@@ -203,12 +203,12 @@
         }
       else
         {
-          g_warning ("failed to get the browser's pending edits hash");
+          g_critical ("failed to get the browser's pending edits hash");
         }
     }
   else
     {
-      g_warning ("SoylentBrowser's widget tree is invalid");
+      g_critical ("SoylentBrowser's widget tree is invalid");
     }
 
   soylent_browser_person_view_editor_hide (browser);
@@ -845,26 +845,54 @@
   g_free (domain);
 }
 
-/* Hook up signal handlers for the Detail Add UI section widgets */
-void
+/* Hook up signal handlers for the Detail Add UI section widgets
+ *
+ * Return TRUE for success, FALSE for any failure */
+gboolean
 cbox_detail_add_setup (SoylentBrowser *browser)
 {
+  gboolean retval = FALSE;
   GladeXML *wtree = NULL;
-  GtkComboBox *cbox = 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), retval);
+   */
+
+  /* invert usual logic to simplify the code below */
+  retval = TRUE;
 
   wtree = soylent_browser_get_widget_tree (browser);
+  if (wtree && GLADE_IS_XML (wtree))
+    {
+      const gchar *cbox_names[] = {"cbox_detail_domain", "cbox_detail_proto",
+                                   "cbox_detail_type", "cbox_detail_type_phone",
+                                   "cbox_detail_type_web",};
+      GtkComboBox *cbox_cur = NULL;
+      guint i = 0;
+
+      /*  Glade lets us set these values, but they aren't honored */
+      for (i = 0; i < (sizeof (cbox_names) / sizeof (const gchar*)); i++)
+        {
+          cbox_cur = GTK_COMBO_BOX (glade_xml_get_widget (wtree,
+                                                          cbox_names[i]));
+          if (cbox_cur && GTK_IS_COMBO_BOX (cbox_cur))
+            {
+              gtk_combo_box_set_active(cbox_cur, 0);
+            }
+          else
+            {
+              g_critical ("failed to get combo box widget: %s", cbox_names[i]);
+              retval = FALSE;
+            }
+        }
+    }
+  else
+    {
+      g_critical ("SoylentBrowser's widget tree is invalid");
+    }
 
-  /*  Glade lets us set these values, but they aren't honored */
-  cbox = GTK_COMBO_BOX (glade_xml_get_widget (wtree, "cbox_detail_domain"));
-  gtk_combo_box_set_active(cbox, 0);
-  cbox = GTK_COMBO_BOX (glade_xml_get_widget (wtree, "cbox_detail_proto"));
-  gtk_combo_box_set_active(cbox, 0);
-  cbox = GTK_COMBO_BOX (glade_xml_get_widget (wtree, "cbox_detail_type"));
-  gtk_combo_box_set_active(cbox, 0);      
-  cbox = GTK_COMBO_BOX (glade_xml_get_widget (wtree, "cbox_detail_type_phone"));
-  gtk_combo_box_set_active(cbox, 0);
-  cbox = GTK_COMBO_BOX (glade_xml_get_widget (wtree, "cbox_detail_type_web"));
-  gtk_combo_box_set_active(cbox, 0);
+  return retval;
 }
 
 /* Update the visibility of the Detail Add UI section "Type" combo boxes, based

Modified: trunk/src/soylent-browser-person-view.h
==============================================================================
--- trunk/src/soylent-browser-person-view.h	(original)
+++ trunk/src/soylent-browser-person-view.h	Tue Jan 29 05:48:23 2008
@@ -75,8 +75,8 @@
 void commit_detail_add        (GtkWidget *widget, gpointer user_data);
 
 /* Setup/update sections of the person view UI with latest data from e-d-s */
-void btn_detail_add_update    (GtkWidget *widget, gpointer user_data);
-void cbox_detail_add_setup    (SoylentBrowser *browser);
-void cbox_detail_type_update  (GtkWidget *widget, gpointer user_data);
+void btn_detail_add_update (GtkWidget *widget, gpointer user_data);
+gboolean cbox_detail_add_setup (SoylentBrowser *browser);
+void cbox_detail_type_update (GtkWidget *widget, gpointer user_data);
 
 #endif /* _SOYLENT_BROWSER_PERSON_VIEW_H_ */

Modified: trunk/src/soylent-browser.c
==============================================================================
--- trunk/src/soylent-browser.c	(original)
+++ trunk/src/soylent-browser.c	Tue Jan 29 05:48:23 2008
@@ -65,11 +65,11 @@
 static SoylentPerson* soylent_browser_live_contact_find_owner_person 
                                              (SoylentBrowser *browser,
                                               EmpathyContact *empathy_contact);
-static gboolean soylent_browser_associate_live_contact
+static gboolean soylent_browser_person_associate_live_contact
                                             (SoylentBrowser *browser,
                                              SoylentPerson *person,
                                              EmpathyContact *empathy_contact);
-static gboolean soylent_browser_dissociate_live_contact
+static gboolean soylent_browser_person_dissociate_live_contact
                                               (SoylentBrowser *browser,
                                                SoylentPerson *person,
                                                EmpathyContact *empathy_contact);
@@ -308,7 +308,7 @@
 {
   g_return_val_if_fail (browser != NULL, 0);
   /* FIXME: uncomment once SoylentBrowser is a GObject:
-  g_return_val_if_fail (SOYLENT_IS_BROWSER (browser), NULL);
+  g_return_val_if_fail (SOYLENT_IS_BROWSER (browser), 0);
    */
 
   return browser->icon_height_max;
@@ -319,7 +319,7 @@
 {
   g_return_val_if_fail (browser != NULL, 0);
   /* FIXME: uncomment once SoylentBrowser is a GObject:
-  g_return_val_if_fail (SOYLENT_IS_BROWSER (browser), NULL);
+  g_return_val_if_fail (SOYLENT_IS_BROWSER (browser), 0);
    */
 
   return browser->icon_width_max;
@@ -373,7 +373,7 @@
 
   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 (SOYLENT_IS_BROWSER (browser), retval);
    */
   g_return_val_if_fail (type_widget != NULL, retval);
   g_return_val_if_fail (type_data != NULL, retval);
@@ -421,7 +421,7 @@
 
   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 (SOYLENT_IS_BROWSER (browser), retval);
    */
   g_return_val_if_fail (e_uid != NULL, retval);
 
@@ -444,7 +444,7 @@
 
   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 (SOYLENT_IS_BROWSER (browser), retval);
    */
   g_return_val_if_fail (e_contact != NULL, retval);
   g_return_val_if_fail (E_IS_CONTACT (e_contact), retval);
@@ -473,7 +473,7 @@
 
   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 (SOYLENT_IS_BROWSER (browser), retval);
    */
 
   selected_people_e_uids = soylent_browser_get_selected_people_e_uid (browser);
@@ -534,7 +534,7 @@
 
   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 (SOYLENT_IS_BROWSER (browser), retval);
    */
 
   wtree = browser->main_window;
@@ -585,7 +585,7 @@
 
   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 (SOYLENT_IS_BROWSER (browser), retval);
    */
   
   e_uid = soylent_browser_get_selected_person_e_uid (browser);
@@ -615,9 +615,9 @@
   EContact *retval = NULL;
   SoylentPerson *person = NULL;
 
-  g_return_val_if_fail (browser != NULL, 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);
+  g_return_val_if_fail (SOYLENT_IS_BROWSER (browser), retval);
    */
 
   person = soylent_browser_get_selected_person (browser);
@@ -640,9 +640,9 @@
   GtkTreeIter iter;
   gchar *e_uid = NULL;
 
-  g_return_val_if_fail (browser != NULL, 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);
+  g_return_val_if_fail (SOYLENT_IS_BROWSER (browser), retval);
    */
 
   wtree = browser->main_window;
@@ -714,7 +714,7 @@
 
   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 (SOYLENT_IS_BROWSER (browser), retval);
    */
   g_return_val_if_fail (empathy_contact != NULL, retval);
   g_return_val_if_fail (EMPATHY_IS_CONTACT (empathy_contact), retval);
@@ -953,7 +953,7 @@
 
   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 (SOYLENT_IS_BROWSER (browser), retval);
    */
 
   /* XXX: would check return value, but this function is void */
@@ -1043,7 +1043,7 @@
 
   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 (SOYLENT_IS_BROWSER (browser), retval);
    */
   g_return_val_if_fail (SOYLENT_BROWSER_PEOPLE_VIEW_MODE_IS_VALID (mode),
                         retval);
@@ -1111,11 +1111,11 @@
 
   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 (SOYLENT_IS_BROWSER (browser), 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), NULL);
+  g_return_val_if_fail (SOYLENT_IS_PERSON (person), retval);
    */
 
   wtree = browser->main_window;
@@ -1188,11 +1188,11 @@
 
   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 (SOYLENT_IS_BROWSER (browser), 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), NULL);
+  g_return_val_if_fail (SOYLENT_IS_PERSON (person), retval);
    */
 
   icon_view = GTK_ICON_VIEW (glade_xml_get_widget (browser->main_window,
@@ -1388,8 +1388,8 @@
 
       /* this handles NULL person pointers (adds the contact to a browser-wide
        * pool) */
-      retval = soylent_browser_associate_live_contact (browser, person,
-                                                       empathy_contact);
+      retval = soylent_browser_person_associate_live_contact (browser, person,
+                                                              empathy_contact);
     }
   /* Otherwise, this EmpathyContact was removed from our roster; drop them from
    * our own structures */
@@ -1418,8 +1418,8 @@
 
       /* this handles NULL person pointers (adds the contact to a browser-wide
        * pool) */
-      retval = soylent_browser_dissociate_live_contact (browser, person,
-                                                        empathy_contact);
+      retval = soylent_browser_person_dissociate_live_contact (browser, person,
+                                                               empathy_contact);
     }
 
   return retval;
@@ -1488,12 +1488,19 @@
  *
  * Return TRUE for success, FALSE for any failure. */
 static gboolean
-soylent_browser_associate_live_contact (SoylentBrowser *browser,
-                                        SoylentPerson *person,
-                                        EmpathyContact *empathy_contact)
+soylent_browser_person_associate_live_contact (SoylentBrowser *browser,
+                                               SoylentPerson *person,
+                                               EmpathyContact *empathy_contact)
 {
   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), retval);
+   */
+  g_return_val_if_fail (empathy_contact != NULL, retval);
+  g_return_val_if_fail (EMPATHY_IS_CONTACT (empathy_contact), retval);
+
   /* FIXME: once SoylentPerson is a GObject, check SOYLENT_IS_PERSON */
   if (person)
     {
@@ -1515,12 +1522,19 @@
  *
  * Return TRUE for success, FALSE for any failure. */
 static gboolean
-soylent_browser_dissociate_live_contact (SoylentBrowser *browser,
-                                         SoylentPerson *person,
-                                         EmpathyContact *empathy_contact)
+soylent_browser_person_dissociate_live_contact (SoylentBrowser *browser,
+                                                SoylentPerson *person,
+                                                EmpathyContact *empathy_contact)
 {
   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), retval);
+   */
+  g_return_val_if_fail (empathy_contact != NULL, retval);
+  g_return_val_if_fail (EMPATHY_IS_CONTACT (empathy_contact), retval);
+
   /* FIXME: once SoylentPerson is a GObject, check SOYLENT_IS_PERSON */
   if (person)
     {
@@ -1546,34 +1560,71 @@
 {
   gboolean retval = FALSE;
   GladeXML *wtree = NULL;
-  GtkIconView *icon_view = NULL;
-  GtkListStore *list_store = NULL;
-  GtkComboBox *cbox = 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), retval);
+   */
 
   wtree = browser->main_window;
+  if (wtree && GLADE_IS_XML (wtree))
+    {
+      GtkIconView *icon_view = NULL;
 
-  icon_view = GTK_ICON_VIEW (glade_xml_get_widget (wtree, "iv_people"));
-  list_store = gtk_list_store_new (NUM_PEOPLE_COLS, G_TYPE_STRING,
-                                   G_TYPE_STRING, GDK_TYPE_PIXBUF);
-  gtk_icon_view_set_model (icon_view, GTK_TREE_MODEL (list_store));
-  gtk_icon_view_set_text_column (icon_view, PEOPLE_COL_NAME);
-  gtk_icon_view_set_pixbuf_column (icon_view, PEOPLE_COL_PHOTO);
-  gtk_tree_sortable_set_sort_column_id ((GtkTreeSortable*) list_store,
-                                        PEOPLE_COL_NAME, GTK_SORT_ASCENDING);
-  gtk_tree_sortable_set_sort_func ((GtkTreeSortable*) list_store,
+      icon_view = GTK_ICON_VIEW (glade_xml_get_widget (wtree, "iv_people"));
+      if (icon_view && GTK_IS_ICON_VIEW (icon_view))
+        {
+          GtkListStore *list_store = NULL;
+
+          list_store = gtk_list_store_new (NUM_PEOPLE_COLS, G_TYPE_STRING,
+                                          G_TYPE_STRING, GDK_TYPE_PIXBUF);
+          if (list_store && GTK_IS_LIST_STORE (list_store))
+            {
+              GtkComboBox *cbox_presence = NULL;
+
+              /* Configure the main icon view */
+              gtk_icon_view_set_model (icon_view, GTK_TREE_MODEL (list_store));
+              gtk_icon_view_set_text_column (icon_view, PEOPLE_COL_NAME);
+              gtk_icon_view_set_pixbuf_column (icon_view, PEOPLE_COL_PHOTO);
+              gtk_tree_sortable_set_sort_column_id
+                                                ((GtkTreeSortable*) list_store,
+                                                 PEOPLE_COL_NAME,
+                                                 GTK_SORT_ASCENDING);
+              gtk_tree_sortable_set_sort_func
+                                  ((GtkTreeSortable*) list_store,
                                    PEOPLE_COL_NAME,
-                                   (GtkTreeIterCompareFunc)
-                                    soylent_browser_compare_people_by_icon_iter,
+                                   soylent_browser_compare_people_by_icon_iter,
                                    NULL, NULL);
- 
-  /* XXX - Glade lets us set these values, but they aren't honored */
-  cbox = GTK_COMBO_BOX (glade_xml_get_widget (wtree,"cbox_presence"));
-  gtk_combo_box_set_active (cbox, 0);
-
-  cbox_detail_add_setup (browser);
+            
+              /* XXX - Glade lets us set these values, but they aren't honored
+               * */
+              cbox_presence = GTK_COMBO_BOX (glade_xml_get_widget
+                                                      (wtree, "cbox_presence"));
+              if (cbox_presence && GTK_IS_COMBO_BOX (cbox_presence))
+                {
+                  gtk_combo_box_set_active (cbox_presence, 0);
 
-  /* FIXME: only set this if everything above succeeds */
-  retval = TRUE;
+                  retval = cbox_detail_add_setup (browser);
+                }
+              else
+                {
+                  g_critical ("failed to get presence combo box");
+                }
+            }
+          else
+            {
+              g_critical ("failed to allocate memory");
+            }
+        }
+      else
+        {
+          g_critical ("failed to get main icon view widget");
+        }
+    }
+  else
+    {
+      g_critical ("SoylentBrowser's widget tree is invalid");
+    }
 
   return retval;
 }



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