soylent r42 - trunk/src



Author: treitter
Date: Tue Jan  8 05:30:56 2008
New Revision: 42
URL: http://svn.gnome.org/viewvc/soylent?rev=42&view=rev

Log:
continue fortifying functions (part-way done with soylent-browser.c)

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

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  8 05:30:56 2008
@@ -2115,9 +2115,10 @@
 
       context_str = CONTEXT_STRS[context];
 
-      frame_mail_cur = GTK_FRAME (soylent_browser_get_widget (wtree, "frame",
+      frame_mail_cur = GTK_FRAME (soylent_browser_get_widget (browser, "frame",
                                                               "mail",
-                                                              context_str));
+                                                              context_str,
+                                                              NULL));
 
       widget_str = g_strdup_printf ("tv_person_mail_%s_street",
                                     CONTEXT_STRS[context]);
@@ -2126,35 +2127,23 @@
       g_free (widget_str);
 
       /* FIXME: factor out the commonality */
-      entry_po = GTK_ENTRY (soylent_browser_get_widget_subcontext (wtree,
-                                                                   "entry",
-                                                                   "mail",
-                                                                   context_str,
-                                                                   "po"));
-
-      entry_locality = GTK_ENTRY (soylent_browser_get_widget_subcontext (wtree,
-                                                                        "entry",
-                                                                        "mail",
-                                                                    context_str,
-                                                                  "locality"));
-
-      entry_code = GTK_ENTRY (soylent_browser_get_widget_subcontext (wtree,
-                                                                     "entry",
-                                                                     "mail",
-                                                                    context_str,
-                                                                     "code"));
-
-      entry_region = GTK_ENTRY (soylent_browser_get_widget_subcontext (wtree,
-                                                                       "entry",
-                                                                       "mail",
-                                                                    context_str,
-                                                                    "region"));
-     
-      entry_country = GTK_ENTRY (soylent_browser_get_widget_subcontext (wtree,
-                                                                        "entry",
-                                                                        "mail",
-                                                                    context_str,
-                                                                    "country"));
+      entry_po = GTK_ENTRY (soylent_browser_get_widget (browser, "entry",
+                                                        "mail", context_str,
+                                                        "po"));
+      entry_locality = GTK_ENTRY (soylent_browser_get_widget (browser, "entry",
+                                                              "mail",
+                                                              context_str,
+                                                              "locality"));
+      entry_code = GTK_ENTRY (soylent_browser_get_widget (browser, "entry",
+                                                          "mail", context_str,
+                                                          "code"));
+      entry_region = GTK_ENTRY (soylent_browser_get_widget (browser, "entry",
+                                                            "mail", context_str,
+                                                            "region"));
+      entry_country = GTK_ENTRY (soylent_browser_get_widget (browser, "entry",
+                                                             "mail",
+                                                             context_str,
+                                                             "country"));
 
       /* FIXME - this should use e_contact_get_const */
       addr = e_contact_get (e_contact, context + E_CONTACT_FIRST_ADDRESS_ID);

Modified: trunk/src/soylent-browser.c
==============================================================================
--- trunk/src/soylent-browser.c	(original)
+++ trunk/src/soylent-browser.c	Tue Jan  8 05:30:56 2008
@@ -31,6 +31,10 @@
 #include "soylent-person.h"
 #include "soylent-utils.h"
 
+#define SOYLENT_GLADE_FILE_UNINSTALLED \
+                                    SOYLENT_GLADEDIR_UNINSTALLED"/soylent.glade"
+#define SOYLENT_GLADE_FILE SOYLENT_GLADEDIR"/soylent.glade"
+
 /* TODO: make this a full-fledged GObject */
 struct SoylentBrowser_tag
 { 
@@ -64,8 +68,8 @@
                                                         SoylentPerson *person,
                                               EmpathyContact *empathy_contact);
 
-static void soylent_browser_widget_setup (SoylentBrowser *browser);
-static void soylent_browser_ebook_setup (SoylentBrowser *browser);
+static gboolean soylent_browser_widget_setup (SoylentBrowser *browser);
+static gboolean soylent_browser_ebook_setup (SoylentBrowser *browser);
 static void soylent_browser_dialog_signals_setup (SoylentBrowser *browser);
 static void soylent_browser_person_actions_signals_setup
                                                       (SoylentBrowser *browser);
@@ -88,75 +92,142 @@
 static void soylent_browser_person_detail_add_signals_setup
                                                       (SoylentBrowser *browser);
 static void soylent_browser_presence_signals_setup (SoylentBrowser *browser);
-static void soylent_browser_signals_setup (SoylentBrowser *browser);
+static gboolean soylent_browser_signals_setup (SoylentBrowser *browser);
 
 /* Instantiate the main SoylentBrowser */
 SoylentBrowser*
 soylent_browser_new (void)
 {
+  SoylentBrowser *retval = NULL;
   SoylentBrowser *browser = NULL;
   soylent_browser_people_view_mode view_mode;
 
   browser = g_new0 (SoylentBrowser, 1);
-  view_mode = SB_PEOPLE_VIEW_MODE_BROWSE;
-
-  /* FIXME: should really only do this if in maintainer mode */
-  browser->main_window = glade_xml_new
-                                  (SOYLENT_GLADEDIR_UNINSTALLED"/soylent.glade",
-                                   NULL, NULL);
-  if (!browser->main_window)
+  if (browser)
     {
-      browser->main_window = glade_xml_new (SOYLENT_GLADEDIR"/soylent.glade",
-                                            NULL, NULL);
-    }
-
-  g_assert (browser->main_window);
+      view_mode = SB_PEOPLE_VIEW_MODE_BROWSE;
 
-  browser->live_manager = NULL;
-  browser->live_contacts_pending = NULL;
+      /* In development builds, try to load the local glade file first */
+      if (BUILD_DEV)
+        {
+          browser->main_window = glade_xml_new (SOYLENT_GLADE_FILE_UNINSTALLED,
+                                                NULL, NULL);
+        }
 
-  browser->icon_width_max  = ICON_MAX_WIDTH;
-  browser->icon_height_max = ICON_MAX_HEIGHT;
+      if (!browser->main_window)
+        {
+          browser->main_window = glade_xml_new (SOYLENT_GLADE_FILE, NULL, NULL);
+        }
 
-  /* 
-   * FIXME: we need to listen for theme updates, and refresh this when they
-   * happen. See the docs for this function. The updating callback also needs to
-   * g_object_unref() the current pixbuf.
-   *
-   * Is there a better way to do this?
-   */
-  browser->icon_stock_person = gtk_icon_theme_load_icon
-                                                (gtk_icon_theme_get_default (),
-                                                 "stock_person",
-                                                 browser->icon_width_max, 0,
-                                                 NULL);
-
-  /* 
-   * we need to free these eventually - just not during the main lifetime of the
-   * app
-   */
-  browser->pending_edits = g_hash_table_new (g_str_hash, g_str_equal);
+      if (browser->main_window)
+        {
+          GtkIconTheme *gtk_icon_theme = NULL;
+          browser->live_manager = NULL;
+          browser->live_contacts_pending = NULL;
+          browser->icon_width_max  = ICON_MAX_WIDTH;
+          browser->icon_height_max = ICON_MAX_HEIGHT;
 
-  browser->live_idle = empathy_idle_new ();
-  if (browser->live_idle)
-    {
-      /* XXX: some of these should be user-configurable */
-      empathy_idle_set_auto_away       (browser->live_idle, TRUE);
-      empathy_idle_set_auto_disconnect (browser->live_idle, FALSE);
-      empathy_idle_set_presence        (browser->live_idle,
-                                        MC_PRESENCE_AVAILABLE, "");
+          gtk_icon_theme = gtk_icon_theme_get_default ();
+          if (gtk_icon_theme)
+            {
+              /* 
+               * FIXME: we need to listen for theme updates, and refresh this
+               * when they happen. See the docs for this function. The updating
+               * callback also needs to g_object_unref() the current pixbuf.
+               *
+               * Is there a better way to do this?
+               */
+              browser->icon_stock_person = gtk_icon_theme_load_icon
+                                                       (gtk_icon_theme,
+                                                        "stock_person",
+                                                        browser->icon_width_max,
+                                                        0, NULL);
+
+              /* 
+              * we need to free these eventually - just not during the main
+              * lifetime of the app
+              */
+              browser->pending_edits = g_hash_table_new (g_str_hash,
+                                                         g_str_equal);
+              if (browser->pending_edits)
+                {
+                  gboolean signal_setup_retval = FALSE;
+
+                  browser->live_idle = empathy_idle_new ();
+                  if (browser->live_idle)
+                    {
+                      /* XXX: some of these should be user-configurable */
+                      empathy_idle_set_auto_away (browser->live_idle, TRUE);
+                      empathy_idle_set_auto_disconnect (browser->live_idle,
+                                                        FALSE);
+                      empathy_idle_set_presence (browser->live_idle,
+                                                MC_PRESENCE_AVAILABLE, "");
+                    }
+                  else
+                    {
+                      /* non-fatal */
+                      g_warning ("unable to initialize Empathy presence "
+                                 "handler");
+                    }
+
+                  soylent_browser_view_set_mode (browser, view_mode);
+
+                  signal_setup_retval = soylent_browser_signals_setup (browser);
+                  if (signal_setup_retval)
+                    {
+                      gboolean widget_setup_retval = FALSE;
+
+                      widget_setup_retval = soylent_browser_widget_setup
+                                                                      (browser);
+                      if (widget_setup_retval)
+                        {
+                          gboolean ebook_setup_retval = FALSE;
+
+                          ebook_setup_retval = soylent_browser_ebook_setup
+                                                                      (browser);
+                          if (ebook_setup_retval)
+                            {
+                              /* success */
+                              retval = browser;
+                            }
+                          else
+                            {
+                              g_warning ("failed to set up EBook (address "
+                                         "book)");
+                            }
+                        }
+                      else
+                        {
+                          g_warning ("failed to set up major widgets");
+                        }
+                    }
+                  else
+                    {
+                      g_warning ("failed to set up major GObject signals");
+                    }
+                }
+              else
+                {
+                  g_warning ("failed to allocate pending edits hash table");
+                }
+            }
+          else
+            {
+              g_warning ("unable to get default GTK theme");
+            }
+        }
+      else
+        {
+          g_warning ("unable to load glade file");
+        }
     }
-  else
+
+  if (!retval)
     {
-      g_warning ("unable to initialize Empathy presence handler");
+      soylent_browser_destroy (browser);
     }
 
-  soylent_browser_view_set_mode (browser, view_mode);
-  soylent_browser_signals_setup (browser);
-  soylent_browser_widget_setup (browser);
-  soylent_browser_ebook_setup (browser);
-
-  return browser;
+  return retval;
 }
 
 /* Free the contents of the given SoylentBrowser */
@@ -187,6 +258,9 @@
 soylent_browser_get_e_book (SoylentBrowser *browser)
 {
   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);
+   */
 
   return browser->book;
 }
@@ -195,6 +269,9 @@
 soylent_browser_get_e_book_view (SoylentBrowser *browser)
 {
   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);
+   */
 
   return browser->book_view;
 }
@@ -203,6 +280,9 @@
 soylent_browser_get_edits_pending (SoylentBrowser *browser)
 {
   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);
+   */
 
   return browser->pending_edits;
 }
@@ -211,6 +291,9 @@
 soylent_browser_get_icon_height_max (SoylentBrowser *browser)
 {
   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);
+   */
 
   return browser->icon_height_max;
 }
@@ -219,6 +302,9 @@
 soylent_browser_get_icon_width_max (SoylentBrowser *browser)
 {
   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);
+   */
 
   return browser->icon_width_max;
 }
@@ -227,6 +313,9 @@
 soylent_browser_get_live_manager (SoylentBrowser *browser)
 {
   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);
+   */
 
   return browser->live_manager;
 }
@@ -235,6 +324,9 @@
 soylent_browser_get_people (SoylentBrowser *browser)
 {
   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);
+   */
 
   return browser->people;
 }
@@ -243,49 +335,65 @@
 soylent_browser_get_widget_tree (SoylentBrowser *browser)
 {
   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);
+   */
 
   return browser->main_window;
 }
 
-/* Get a GtkWidget* for a widget based on its widget type, data type,
- * and context.
+/* Return a GtkWidget* for a widget based on its widget type abbreviation,
+ * data type, context, and subcontext (optionally NULL).
  *
- * Eg, "entry", "email", "home" */
+ * Eg, "entry", "email", "home", "1" */
 GtkWidget*
-soylent_browser_get_widget (GladeXML *wtree, const gchar *type_widget,
-               const gchar *type_data, const gchar *context)
+soylent_browser_get_widget (SoylentBrowser *browser, const gchar *type_widget,
+                            const gchar *type_data, const gchar *context,
+                            const gchar *subcontext)
 {
-  GtkWidget *widget = NULL;
+  GtkWidget *retval = NULL;
+  GladeXML *wtree = NULL;
   gchar *widget_str = NULL;
 
-  widget_str = g_strdup_printf ("%s_person_%s_%s", type_widget, type_data,
-                                context);
-  widget = glade_xml_get_widget (wtree, widget_str);
-  g_free (widget_str);
+  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 (type_widget != NULL, retval);
+  g_return_val_if_fail (type_data != NULL, retval);
+  g_return_val_if_fail (context != NULL, retval);
 
-  return widget;
-}
+  wtree = soylent_browser_get_widget_tree (browser);
+  if (wtree && GLADE_IS_XML (wtree))
+    {
+      if (subcontext)
+        {
+          widget_str = g_strdup_printf ("%s_person_%s_%s_%s", type_widget,
+                                        type_data, context, subcontext);
+        }
+      else
+        {
+          widget_str = g_strdup_printf ("%s_person_%s_%s", type_widget,
+                                        type_data, context);
+        }
 
-/* Get a GtkWidget* for a widget based on its widget type abbreviation,
- * data type, context, and subcontext.
- *
- * Eg, "entry", "email", "home", "1" */
-GtkWidget*
-soylent_browser_get_widget_subcontext (GladeXML *wtree,
-                                       const gchar *type_widget,
-                                       const gchar *type_data,
-                                       const gchar *context,
-                                       const gchar *subcontext)
-{
-  GtkWidget *widget = NULL;
-  gchar *widget_str = NULL;
+      if (widget_str)
+        {
+          retval = glade_xml_get_widget (wtree, widget_str);
 
-  widget_str = g_strdup_printf ("%s_person_%s_%s_%s", type_widget, type_data,
-                                context, subcontext);
-  widget = glade_xml_get_widget (wtree, widget_str);
-  g_free (widget_str);
+          g_free (widget_str);
+        }
+      else
+        {
+          g_warning ("failed to allocate a widget string");
+        }
+    }
+  else
+    {
+      g_warning ("failed to get SoylentBrowser's widget tree ");
+    }
 
-  return widget;
+  return retval;
 }
 
 /* Look up the SoylentPerson for the given EContact ID */
@@ -293,15 +401,21 @@
 soylent_browser_get_person_from_e_uid (SoylentBrowser *browser,
                                        const gchar *e_uid)
 {
-  SoylentPerson *person = NULL;
+  SoylentPerson *retval = NULL;
 
-  person = g_hash_table_lookup (browser->people, e_uid);
-  if (!person)
+  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_uid != NULL, retval);
+
+  retval = g_hash_table_lookup (browser->people, e_uid);
+  if (!retval)
     {
       g_warning ("invalid UID: '%s'", e_uid);
     }
 
-  return person;
+  return retval;
 }
 
 /* Look up the SoylentPerson for the given EContact ID */
@@ -309,13 +423,27 @@
 soylent_browser_get_person_from_e_contact (SoylentBrowser *browser,
                                            EContact *e_contact)
 {
+  SoylentPerson *retval = NULL;
   const gchar *e_uid = NULL;
-  SoylentPerson *person = 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);
   
   e_uid = e_contact_get_const (e_contact, E_CONTACT_UID);
-  person = soylent_browser_get_person_from_e_uid (browser, e_uid);
+  if (e_uid)
+    {
+      retval = soylent_browser_get_person_from_e_uid (browser, e_uid);
+    }
+  else
+    {
+      g_warning ("failed to find UID for given EContact");
+    }
 
-  return person;
+  return retval;
 }
 
 /* Get a GList* of the currently-selected people. Kinda hacky. */
@@ -1103,10 +1231,13 @@
   return retval;
 }
 
-/* Any widget setup that Glade won't do/doesn't do properly */
-static void
+/* Any widget setup that Glade won't do/doesn't do properly.
+ *
+ * Return TRUE for complete success, FALSE otherwise. */
+static gboolean
 soylent_browser_widget_setup (SoylentBrowser *browser)
 {
+  gboolean retval = FALSE;
   GladeXML *wtree = NULL;
   GtkIconView *iconview = NULL;
   GtkListStore *liststore = NULL;
@@ -1133,13 +1264,21 @@
   gtk_combo_box_set_active (cbox, 0);
 
   cbox_detail_add_setup (browser);
+
+  /* FIXME: only set this if everything above succeeds */
+  retval = TRUE;
+
+  return retval;
 }
 
 /* Instantiate an EBook addressbook and create the SoylentBrowser's contact
- * lookup table */
-static void
+ * lookup table
+ *
+ * Return TRUE for complete success, FALSE otherwise. */
+static gboolean
 soylent_browser_ebook_setup (SoylentBrowser *browser)
 {
+  gboolean retval = FALSE;
   GError *error = NULL;
 
   browser->book = e_book_new_system_addressbook (&error);
@@ -1154,6 +1293,11 @@
                                             soylent_person_free);
 
   g_idle_add (open_book, browser);
+
+  /* FIXME: only set this if everything above succeeds */
+  retval = TRUE;
+
+  return retval;
 }
 
 /* Hook up the dialog box button handlers */
@@ -1551,10 +1695,13 @@
   soylent_browser_person_info_mail_signals_setup   (browser);
 }
 
-/* Hook up handlers for all the people-related widgets (overview) */
-static void
+/* Hook up handlers for all the people-related widgets (overview)
+ *
+ * Return TRUE for complete success, FALSE otherwise. */
+static gboolean
 soylent_browser_signals_setup (SoylentBrowser *browser)
 {
+  gboolean retval = FALSE;
   GladeXML *wtree = NULL;
   GtkWidget *widget = NULL;
 
@@ -1575,4 +1722,9 @@
   widget = glade_xml_get_widget (wtree, "window_main");
   g_signal_connect (G_OBJECT (widget), "delete_event",
                     G_CALLBACK (soylent_browser_delete_cb), browser);
+
+  /* FIXME: only set this if everything above succeeds */
+  retval = TRUE;
+
+  return retval;
 }

Modified: trunk/src/soylent-browser.h
==============================================================================
--- trunk/src/soylent-browser.h	(original)
+++ trunk/src/soylent-browser.h	Tue Jan  8 05:30:56 2008
@@ -98,15 +98,11 @@
 EmpathyContactManager* soylent_browser_get_live_manager
                                                       (SoylentBrowser *browser);
 
-GtkWidget* soylent_browser_get_widget (GladeXML *wtree,
+GtkWidget* soylent_browser_get_widget (SoylentBrowser *browser,
                                        const gchar *type_widget,
                                        const gchar *type_data,
-                                       const gchar *context);
-GtkWidget* soylent_browser_get_widget_subcontext (GladeXML *wtree,
-                                                  const gchar *type_widget,
-                                                  const gchar *type_data,
-                                                  const gchar *context,
-                                                  const gchar *subcontext);
+                                       const gchar *context,
+                                       const gchar *subcontext);
 
 SoylentPerson* soylent_browser_get_person_from_e_uid (SoylentBrowser *browser,
                                                       const gchar *e_uid);



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