soylent r48 - trunk/src



Author: treitter
Date: Sun Jan 13 04:33:06 2008
New Revision: 48
URL: http://svn.gnome.org/viewvc/soylent?rev=48&view=rev

Log:
Clean up a couple more soylent-browser.c functions and start cleaning up the callers of those functions

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

Modified: trunk/src/eds-callbacks.c
==============================================================================
--- trunk/src/eds-callbacks.c	(original)
+++ trunk/src/eds-callbacks.c	Sun Jan 13 04:33:06 2008
@@ -42,19 +42,35 @@
   GList *e_contact_groups = 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 (e_contact != NULL, retval);
+  g_return_val_if_fail (E_IS_CONTACT (e_contact), retval);
+
+  /* inverting standard reval logic so we can easily set it FALSE for one or
+   * more errors */
+  retval = TRUE;
 
   e_contact_groups = e_contact_get (e_contact, E_CONTACT_CATEGORY_LIST);
   if (e_contact_groups)
     {
-      GList *group;
+      GList *group = NULL;
+
       for (group = e_contact_groups; group; group = g_list_next (group))
         {
-          soylent_browser_check_add_group (browser, group->data);
+          gboolean add_group_retval = FALSE;
+
+          add_group_retval = soylent_browser_check_add_group (browser,
+                                                              group->data);
+
+          if (add_group_retval == FALSE)
+            {
+              retval = FALSE;
+            }
         }
-      g_list_free (e_contact_groups);
 
-      retval = TRUE;
+      g_list_free (e_contact_groups);
     }
 
   return retval;
@@ -136,9 +152,6 @@
               retval = FALSE;
             }
         }
-
-      /* Update view */
-      soylent_browser_update_view (browser);
     }
   else
     {
@@ -205,9 +218,6 @@
               retval = FALSE;
             }
         }
-
-      /* Update view */
-      soylent_browser_update_view (browser);
     }
   else
     {
@@ -246,8 +256,6 @@
           g_hash_table_remove (people, e_uid);
         }
 
-      /* Update view */
-      soylent_browser_update_view (browser);
       retval = TRUE;
     }
   else

Modified: trunk/src/soylent-browser-person-view.c
==============================================================================
--- trunk/src/soylent-browser-person-view.c	(original)
+++ trunk/src/soylent-browser-person-view.c	Sun Jan 13 04:33:06 2008
@@ -29,6 +29,8 @@
 
 const gchar *CONTEXT_STRS[] = {"home", "work", "other",};
 
+static gboolean soylent_browser_person_view_editor_hide
+                                                      (SoylentBrowser *browser);
 static void soylent_browser_person_view_save_changes (GtkWidget *widget,
                                                       gpointer user_data);
 static gboolean soylent_browser_person_edit_save_scroll_cb
@@ -105,59 +107,108 @@
                                               GdkEvent *event,
                                               gpointer user_data)
 {
+  gboolean retval = FALSE;
   SoylentBrowser *browser = NULL;
   GladeXML *wtree = NULL;
-  GHashTable *edits_pending = NULL;
-  EContact *e_contact = NULL;
-  SoylentPerson *person = NULL;
-  GError *error = NULL;
-  GtkWidget *window_person_view = NULL;
 
-  /* FIXME: check these return values for sanity */
-  browser = (SoylentBrowser *) user_data;
-  wtree = soylent_browser_get_widget_tree (browser);
-  edits_pending = soylent_browser_get_edits_pending (browser);
-  window_person_view = (glade_xml_get_widget (wtree, "window_person_view")); 
+  g_return_val_if_fail (user_data != NULL, retval);
 
-  g_hash_table_foreach_remove (edits_pending,
-                               (GHRFunc) person_apply_edits_from_widgets_switch,
-                               browser);
+  /* FIXME: check these return values for sanity */
+  /* FIXME: when SoylentBrowser is a GObject, check SOYLENT_IS_BROWSER (browser)
+   * */
+  browser = (SoylentBrowser*) user_data;
 
-  e_contact = soylent_browser_get_selected_person_e_contact (browser);
-  if (e_contact)
+  wtree = soylent_browser_get_widget_tree (browser);
+  if (wtree && GLADE_IS_XML (wtree))
     {
-      EBook     *e_book = NULL;
-      EBookView *e_book_view = NULL;
+      GHashTable *edits_pending = NULL;
 
-      e_book      = soylent_browser_get_e_book (browser);
-      e_book_view = soylent_browser_get_e_book_view (browser);
-      person = soylent_browser_get_person_from_e_contact (browser, e_contact);
-#if 0
-      if (person)
+      edits_pending = soylent_browser_get_edits_pending (browser);
+      if (edits_pending)
         {
-          /* Just for the scrolling;
-           * XXX: maybe that should be a separate function */
-          soylent_browser_person_select (browser, person, TRUE);
-        }
-#endif
+          EContact *e_contact = NULL;
+
+          g_hash_table_foreach_remove
+                            (edits_pending,
+                             (GHRFunc) person_apply_edits_from_widgets_switch,
+                             browser);
+
+          e_contact = soylent_browser_get_selected_person_e_contact (browser);
+          if (e_contact)
+            {
+              EBook *e_book = NULL;
+
+              e_book = soylent_browser_get_e_book (browser);
+              if (e_book)
+                {
+                  EBookView *e_book_view = NULL;
 
-      /* Disconnected in callback */
-      g_signal_connect_after
-                      (e_book_view, "contacts_changed",
-                       G_CALLBACK (soylent_browser_person_edit_save_scroll_cb),
-                       person);
+                  e_book_view = soylent_browser_get_e_book_view (browser);
+                  if (e_book_view)
+                    {
+                      SoylentPerson *person = NULL;
 
-      if (e_book_commit_contact (e_book, e_contact, &error) == FALSE)
+                      person = soylent_browser_get_person_from_e_contact
+                                                                    (browser,
+                                                                     e_contact);
+                      if (person)
+                        {
+                          gboolean commit_retval = FALSE;
+                          GError *error = NULL;
+
+                          /* Disconnected in callback */
+                          g_signal_connect_after
+                              (e_book_view, "contacts_changed",
+                        G_CALLBACK (soylent_browser_person_edit_save_scroll_cb),
+                               person);
+
+                          commit_retval = e_book_commit_contact (e_book,
+                                                                 e_contact,
+                                                                 &error);
+                          if (commit_retval)
+                            {
+                              retval = TRUE;
+                            }
+                          else
+                            {
+                              g_warning ("Could not commit changes to address book: %s",
+                                        error ? error->message : "no error given");
+                              g_clear_error (&error);
+                            }
+                        }
+                      else
+                        {
+                          g_warning ("failed to get SoylentPerson from EContact");
+                        }
+                    }
+                  else
+                    {
+                      g_warning ("failed to get the EBookView for the SoylentBrowser");
+                    }
+                }
+              else
+                {
+                  g_warning ("failed to get EBook for the SoylentBrowser");
+                }
+            }
+          else
+            {
+              g_warning ("failed to get EContact for the person");
+            }
+        }
+      else
         {
-          g_warning ("Could not commit changes to address book, %s", 
-                      error ? error->message : "no error given");
-          g_clear_error (&error);
+          g_warning ("failed to get the browser's pending edits hash");
         }
     }
+  else
+    {
+      g_warning ("SoylentBrowser's widget tree is invalid");
+    }
 
-  gtk_widget_hide (window_person_view);
+  soylent_browser_person_view_editor_hide (browser);
 
-  return TRUE;
+  return retval;
 }
 
 /* Save unsaved changes to the person's details and return to Browse Mode */
@@ -858,6 +909,35 @@
     }
 }
 
+/* Hide the Person editor window
+ *
+ * Return TRUE for success, FALSE for any failure */
+static gboolean
+soylent_browser_person_view_editor_hide (SoylentBrowser *browser)
+{
+  gboolean retval = FALSE;
+  GladeXML *wtree = NULL;
+  GtkWidget *window_person_view = 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);
+   */
+
+  wtree = soylent_browser_get_widget_tree (browser);
+  if (wtree && GLADE_IS_XML (wtree))
+    {
+      window_person_view = (glade_xml_get_widget (wtree, "window_person_view")); 
+      if (window_person_view && GTK_IS_WIDGET (window_person_view))
+        {
+          gtk_widget_hide (window_person_view);
+          retval = TRUE;
+        }
+    }
+
+  return retval;
+}
+
 /* Save unsaved changes to the person's details */
 static void
 soylent_browser_person_view_save_changes (GtkWidget *widget, gpointer user_data)

Modified: trunk/src/soylent-browser.c
==============================================================================
--- trunk/src/soylent-browser.c	(original)
+++ trunk/src/soylent-browser.c	Sun Jan 13 04:33:06 2008
@@ -392,7 +392,7 @@
     }
   else
     {
-      g_warning ("failed to get SoylentBrowser's widget tree ");
+      g_warning ("SoylentBrowser's widget tree is invalid");
     }
 
   return retval;
@@ -967,7 +967,7 @@
                         retval);
 
   wtree = browser->main_window;
-  if (wtree)
+  if (wtree && GLADE_IS_XML (wtree))
     {
       sw_people = glade_xml_get_widget (wtree, "sw_people");
       window_person_view = glade_xml_get_widget (wtree, "window_person_view");
@@ -1037,7 +1037,7 @@
    */
 
   wtree = browser->main_window;
-  if (wtree)
+  if (wtree && GLADE_IS_XML (wtree))
     {
       GtkIconView *iv_people = NULL;
 
@@ -1218,17 +1218,19 @@
   return retval;
 }
 
-/* Union the given group with the SoylentBrowser's current set of groups */
-void
+/* Union the given group with the SoylentBrowser's current set of groups 
+ *
+ * Return TRUE for success, FALSE for any failure */
+gboolean
 soylent_browser_check_add_group (SoylentBrowser *browser, const gchar *group)
 {
- /*TODO*/}
+  gboolean retval = FALSE;
 
-/* XXX: this seems unnecessary... */
-void
-soylent_browser_update_view (SoylentBrowser *browser)
-{
- /*TODO*/}
+ /*TODO*/
+  retval = TRUE;
+
+  return retval;
+}
 
 void
 soylent_browser_delete_cb (GtkWidget *widget, GdkEvent *event,

Modified: trunk/src/soylent-browser.h
==============================================================================
--- trunk/src/soylent-browser.h	(original)
+++ trunk/src/soylent-browser.h	Sun Jan 13 04:33:06 2008
@@ -134,9 +134,8 @@
 
 SoylentBrowser* soylent_browser_new (void);
 void soylent_browser_destroy (SoylentBrowser *browser);
-void soylent_browser_check_add_group (SoylentBrowser *browser,
-                                      const gchar *group);
-void soylent_browser_update_view (SoylentBrowser *browser);
+gboolean soylent_browser_check_add_group (SoylentBrowser *browser,
+                                          const gchar *group);
 gboolean soylent_browser_view_set_mode (SoylentBrowser *browser,
                                         soylent_browser_people_view_mode mode);
 gboolean soylent_browser_person_select (SoylentBrowser *browser,

Modified: trunk/src/soylent.c
==============================================================================
--- trunk/src/soylent.c	(original)
+++ trunk/src/soylent.c	Sun Jan 13 04:33:06 2008
@@ -29,6 +29,7 @@
 int
 main (int argc, char *argv[])
 {
+  int retval = -1;
   GOptionContext *context = NULL;
   SoylentBrowser *browser = NULL;
 
@@ -48,10 +49,19 @@
                       GNOME_PARAM_NONE);
 
   browser = soylent_browser_new ();
+  if (browser)
+    {
+      /* start the event loop */
+      gtk_main ();
+
+      soylent_browser_destroy (browser);
+
+      retval = 0;
+    }
+  else
+    {
+      g_critical ("failed to create the SoylentBrowser");
+    }
 
-  /* start the event loop */
-  gtk_main ();
-
-  soylent_browser_destroy (browser);
-  return 0;
+  return retval;
 }



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