soylent r304 - trunk/src



Author: treitter
Date: Sun Oct 12 22:52:07 2008
New Revision: 304
URL: http://svn.gnome.org/viewvc/soylent?rev=304&view=rev

Log:
Cut out extra-paranoid (and completely useless) return value checking to improve readability.


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

Modified: trunk/src/soylent-browser-person-view.c
==============================================================================
--- trunk/src/soylent-browser-person-view.c	(original)
+++ trunk/src/soylent-browser-person-view.c	Sun Oct 12 22:52:07 2008
@@ -338,27 +338,20 @@
             GError *error = NULL;
             
             command_line = g_strdup_printf ("contacts --edit-uid=%s", e_uid);
-            if (command_line)
-              {
-                g_spawn_command_line_async (command_line, &error);
-
-                if (error)
-                  {
-                    g_warning ("Failed to launch Contacts to edit this person: "
-                               "%s", error->message);
-                    g_clear_error (&error);
-                  }
-                else
-                  {
-                    retval = TRUE;
-                  }
+            g_spawn_command_line_async (command_line, &error);
 
-                g_free (command_line);
+            if (error)
+              {
+                g_warning ("Failed to launch Contacts to edit this person: %s",
+                           error->message);
+                g_clear_error (&error);
               }
             else
               {
-                g_critical ("failed to allocate memory");
+                retval = TRUE;
               }
+
+            g_free (command_line);
           }
         else
           {
@@ -1501,31 +1494,23 @@
           if (email_addr)
             {
               gchar *mailto = NULL;
+              gboolean url_show_retval = FALSE;
+              GError *error = NULL;
 
               mailto = g_strdup_printf ("mailto:%s";, email_addr);
-              if (mailto)
+              url_show_retval = gnome_url_show (mailto, &error);
+              if (url_show_retval)
                 {
-                  gboolean url_show_retval = FALSE;
-                  GError *error = NULL;
-
-                  url_show_retval = gnome_url_show (mailto, &error);
-                  if (url_show_retval)
-                    {
-                      retval = TRUE;
-                    }
-                  else
-                    {
-                      g_warning ("Failed to open email window to %s: %s",
-                                email_addr, error->message);
-                      g_clear_error (&error);
-                    }
-
-                  g_free (mailto);
+                  retval = TRUE;
                 }
               else
                 {
-                  g_critical ("failed to allocate memory for mailto string");
+                  g_warning ("Failed to open email window to %s: %s",
+                             email_addr, error->message);
+                  g_clear_error (&error);
                 }
+
+              g_free (mailto);
             }
           else
             {
@@ -2011,6 +1996,8 @@
           GtkTextIter start;
           GtkTextIter end;
           EVCardAttribute *attr_adr = NULL;
+          EVCardAttributeParam *param = NULL;
+          EVCardAttribute *attr_label = NULL;
 
           entry_add_po = GTK_ENTRY (glade_xml_get_widget
                                                   (wtree,
@@ -2049,43 +2036,33 @@
 
           /* Create the multi-field VCard "ADR" address entry */
           attr_adr = e_vcard_attribute_new (NULL, EVC_ADR);
-          if (attr_adr)
-            {
-              EVCardAttributeParam *param = NULL;
-              EVCardAttribute *attr_label = NULL;
 
-              if (param_val)
-                {
-                  param = e_vcard_attribute_param_new (EVC_TYPE);
-                  e_vcard_attribute_add_param_with_value (attr_adr, param,
-                                                          param_val);
-                }
+          if (param_val)
+            {
+              param = e_vcard_attribute_param_new (EVC_TYPE);
+              e_vcard_attribute_add_param_with_value (attr_adr, param,
+                                                      param_val);
+            }
 
-              e_vcard_add_attribute_with_values (e_vcard, attr_adr, addr->po,
-                                                 "", addr->street,
-                                                 addr->locality, addr->region,
-                                                 addr->code, addr->country,
-                                                 NULL);
+          e_vcard_add_attribute_with_values (e_vcard, attr_adr, addr->po, "",
+                                             addr->street, addr->locality,
+                                             addr->region, addr->code,
+                                             addr->country, NULL);
 
-              /* Create the single-string VCard "LABEL" address entry */
-              attr_label = e_vcard_attribute_new (NULL, "LABEL");
-              if (attr_label)
-                {
-                  if (param)
-                    {
-                      e_vcard_attribute_add_param
+          /* Create the single-string VCard "LABEL" address entry */
+          attr_label = e_vcard_attribute_new (NULL, "LABEL");
+          if (param)
+            {
+              e_vcard_attribute_add_param
                                         (attr_label,
                                          e_vcard_attribute_param_copy (param));
-                    }
-                  e_vcard_add_attribute_with_value
-                                            (e_vcard, attr_label,
-                                             e_contact_address_to_label (addr));
-                }
+            }
+          e_vcard_add_attribute_with_value (e_vcard, attr_label,
+                                            e_contact_address_to_label (addr));
 
-              e_contact_address_free (addr);
+          e_contact_address_free (addr);
 
-              retval = TRUE;
-            }
+          retval = TRUE;
         }
     }
 

Modified: trunk/src/soylent-browser.c
==============================================================================
--- trunk/src/soylent-browser.c	(original)
+++ trunk/src/soylent-browser.c	Sun Oct 12 22:52:07 2008
@@ -84,119 +84,116 @@
   soylent_browser_people_view_mode view_mode;
 
   browser = g_new0 (SoylentBrowser, 1);
-  if (browser)
-    {
-      view_mode = SB_PEOPLE_VIEW_MODE_BROWSE;
+  view_mode = SB_PEOPLE_VIEW_MODE_BROWSE;
 
-      /* Try to load the local glade file first for development builds */
+  /* Try to load the local glade file first for development builds */
 #ifdef BUILD_DEV
-      browser->main_window = glade_xml_new (SOYLENT_GLADE_FILE_UNINSTALLED,
-                                            NULL, NULL);
-      if (!browser->main_window)
+  browser->main_window = glade_xml_new (SOYLENT_GLADE_FILE_UNINSTALLED,
+                                        NULL, NULL);
+  if (!browser->main_window)
 #endif /* BUILD_DEV */
-          browser->main_window = glade_xml_new (SOYLENT_GLADE_FILE_INSTALLED,
-                                                NULL, NULL);
-      if (browser->main_window)
-        {
-          GtkIconTheme *gtk_icon_theme = NULL;
-          browser->live_manager = NULL;
-          browser->empathy_contacts_pending = NULL;
-          browser->icon_width_max  = ICON_MAX_WIDTH;
-          browser->icon_height_max = ICON_MAX_HEIGHT;
+      browser->main_window = glade_xml_new (SOYLENT_GLADE_FILE_INSTALLED,
+                                            NULL, NULL);
+  if (browser->main_window)
+    {
+      GtkIconTheme *gtk_icon_theme = NULL;
+      browser->live_manager = NULL;
+      browser->empathy_contacts_pending = NULL;
+      browser->icon_width_max  = ICON_MAX_WIDTH;
+      browser->icon_height_max = ICON_MAX_HEIGHT;
+
+      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
+          */
+          gboolean set_mode_retval = FALSE;
 
-          gtk_icon_theme = gtk_icon_theme_get_default ();
-          if (gtk_icon_theme)
+          browser->live_idle = empathy_idle_new ();
+          if (browser->live_idle)
             {
-              /* 
-               * 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
-              */
-              gboolean set_mode_retval = FALSE;
+              /* XXX: some of these should be user-configurable */
+              empathy_idle_set_auto_away (browser->live_idle, TRUE);
+              empathy_idle_set_presence (browser->live_idle,
+                                        MC_PRESENCE_AVAILABLE, "");
+            }
+          else
+            {
+              /* non-fatal */
+              g_warning ("unable to initialize Empathy presence "
+                          "handler");
+            }
 
-              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_presence (browser->live_idle,
-                                            MC_PRESENCE_AVAILABLE, "");
-                }
-              else
-                {
-                  /* non-fatal */
-                  g_warning ("unable to initialize Empathy presence "
-                              "handler");
-                }
+          set_mode_retval = soylent_browser_view_set_mode (browser,
+                                                            view_mode);
+          if (set_mode_retval)
+            {
+              gboolean signal_setup_retval = FALSE;
 
-              set_mode_retval = soylent_browser_view_set_mode (browser,
-                                                               view_mode);
-              if (set_mode_retval)
+              signal_setup_retval = soylent_browser_widget_signals_setup
+                                                                  (browser);
+              if (signal_setup_retval)
                 {
-                  gboolean signal_setup_retval = FALSE;
+                  gboolean widget_setup_retval = FALSE;
 
-                  signal_setup_retval = soylent_browser_widget_signals_setup
-                                                                      (browser);
-                  if (signal_setup_retval)
+                  widget_setup_retval = soylent_browser_widget_setup
+                                                                  (browser);
+                  if (widget_setup_retval)
                     {
-                      gboolean widget_setup_retval = FALSE;
+                      gboolean ebook_setup_retval = FALSE;
 
-                      widget_setup_retval = soylent_browser_widget_setup
-                                                                      (browser);
-                      if (widget_setup_retval)
+                      ebook_setup_retval = soylent_browser_eds_ebook_setup
+                                                                  (browser);
+                      if (ebook_setup_retval)
                         {
-                          gboolean ebook_setup_retval = FALSE;
-
-                          ebook_setup_retval = soylent_browser_eds_ebook_setup
-                                                                      (browser);
-                          if (ebook_setup_retval)
-                            {
-                              /* success */
-                              retval = browser;
-                            }
-                          else
-                            {
-                              g_critical ("failed to set up EBook (address "
-                                          "book)");
-                            }
+                          /* success */
+                          retval = browser;
                         }
                       else
                         {
-                          g_critical ("failed to set up major widgets");
+                          g_critical ("failed to set up EBook (address "
+                                      "book)");
                         }
                     }
                   else
                     {
-                      g_critical ("failed to set up major GObject signals");
+                      g_critical ("failed to set up major widgets");
                     }
                 }
               else
                 {
-                  g_critical ("failed to set the browser view mode");
+                  g_critical ("failed to set up major GObject signals");
                 }
             }
           else
             {
-              g_critical ("unable to get default GTK theme");
+              g_critical ("failed to set the browser view mode");
             }
         }
       else
         {
-          g_critical ("unable to load glade file");
+          g_critical ("unable to get default GTK theme");
         }
     }
+  else
+    {
+      g_critical ("unable to load glade file");
+    }
 
   if (!retval)
     {
@@ -332,24 +329,17 @@
   if (subcontext)
     {
       widget_name = g_strdup_printf ("%s_person_%s_%s_%s", type_widget,
-                                    type_data, context, subcontext);
+                                     type_data, context, subcontext);
     }
   else
     {
       widget_name = g_strdup_printf ("%s_person_%s_%s", type_widget,
-                                    type_data, context);
+                                     type_data, context);
     }
 
-  if (widget_name)
-    {
-      retval = glade_xml_get_widget (wtree, widget_name);
+  retval = glade_xml_get_widget (wtree, widget_name);
 
-      g_free (widget_name);
-    }
-  else
-    {
-      g_warning ("failed to allocate a widget string");
-    }
+  g_free (widget_name);
 
   return retval;
 }
@@ -640,13 +630,7 @@
               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
@@ -1560,7 +1544,6 @@
   return retval;
 }
 
-
 /* Any widget setup that Glade won't do/doesn't do properly.
  *
  * Return TRUE for complete success, FALSE otherwise. */
@@ -1570,6 +1553,9 @@
   gboolean retval = FALSE;
   GladeXML *wtree = NULL;
   GtkListStore *list_store = NULL;
+  GtkComboBox *cbox_presence = NULL;
+  GtkIconView *icon_view = NULL;
+  gboolean detail_add_retval = FALSE;
 
   g_return_val_if_fail (browser, retval);
   /* FIXME: uncomment once SoylentBrowser is a GObject:
@@ -1578,67 +1564,43 @@
 
   wtree = browser->main_window;
 
+  /* Configure the main icon view */
   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;
-      GtkIconView *icon_view = NULL;
-
-      icon_view = GTK_ICON_VIEW (glade_xml_get_widget (wtree, "iv_people"));
-
-      /* 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,
+  icon_view = GTK_ICON_VIEW (glade_xml_get_widget (wtree, "iv_people"));
+  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,
                                    soylent_browser_compare_people_by_icon_iter,
                                    NULL, NULL);
-    
-      /* 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))
-        {
-          gboolean detail_add_retval = FALSE;
 
-          gtk_combo_box_set_active (cbox_presence, 0);
+  /* XXX - Glade lets us set these values, but they aren't honored */
+  cbox_presence = GTK_COMBO_BOX (glade_xml_get_widget (wtree, "cbox_presence"));
+  gtk_combo_box_set_active (cbox_presence, 0);
 
-          detail_add_retval = soylent_browser_person_detail_add_cbox_setup
-                                                                      (browser,
-                                                                       FALSE);
-          if (detail_add_retval)
-            {
-              gboolean menu_bar_retval = FALSE;
+  detail_add_retval = soylent_browser_person_detail_add_cbox_setup (browser,
+                                                                    FALSE);
+  if (detail_add_retval)
+    {
+      gboolean menu_bar_retval = FALSE;
 
-              menu_bar_retval = soylent_browser_menu_bar_setup (browser);
-              if (menu_bar_retval)
-                {
-                  retval = soylent_browser_about_dialog_setup (browser);
-                }
-              else
-                {
-                  g_critical ("failed to set up menu bar");
-                }
-            }
-          else
-            {
-              g_critical ("failed to set up Detail Add combo boxes");
-            }
+      menu_bar_retval = soylent_browser_menu_bar_setup (browser);
+      if (menu_bar_retval)
+        {
+          retval = soylent_browser_about_dialog_setup (browser);
         }
       else
         {
-          g_critical ("failed to get presence combo box");
+          g_critical ("failed to set up menu bar");
         }
     }
   else
     {
-      g_critical ("failed to allocate memory");
+      g_critical ("failed to set up Detail Add combo boxes");
     }
 
   return retval;

Modified: trunk/src/soylent-person.c
==============================================================================
--- trunk/src/soylent-person.c	(original)
+++ trunk/src/soylent-person.c	Sun Oct 12 22:52:07 2008
@@ -55,29 +55,13 @@
   g_return_val_if_fail (E_IS_CONTACT (e_contact), retval);
 
   retval = g_new (SoylentPerson, 1);
-  if (retval)
-    {
-      retval->iter = g_new0 (GtkTreeIter, 1);
-      if (retval->iter)
-        {
-          retval->iter->stamp = SP_ITER_UNSET;
-          retval->e_contact = g_object_ref (e_contact);
-          retval->presence = SP_PRESENCE_UNSET;
-          retval->empathy_contacts = NULL;
-          retval->browser = browser;
-        }
-      else
-        {
-          /* error: out of memory */
 
-          g_free (retval);
-          retval = NULL;
-        }
-    }
-  else
-    {
-      /* error: out of memory */
-    }
+  retval->iter = g_new0 (GtkTreeIter, 1);
+  retval->iter->stamp = SP_ITER_UNSET;
+  retval->e_contact = g_object_ref (e_contact);
+  retval->presence = SP_PRESENCE_UNSET;
+  retval->empathy_contacts = NULL;
+  retval->browser = browser;
 
   return retval;
 }

Modified: trunk/src/soylent-utils.c
==============================================================================
--- trunk/src/soylent-utils.c	(original)
+++ trunk/src/soylent-utils.c	Sun Oct 12 22:52:07 2008
@@ -110,24 +110,20 @@
             break;
           case CB_DATA_COMPLEX_FROM_E_CONTACT_FIELD:
             cb_data = g_new0 (cb_entry_changed_e_contact, 1);
-            if (cb_data)
+            cb_data->browser = browser;
+            cb_data->widget_name = cur_args.widget_name;
+            cb_data->field = g_new0 (EContactField, 1);
+            if (cb_data->field)
               {
-                cb_data->browser = browser;
-                cb_data->widget_name = cur_args.widget_name;
-                cb_data->field = g_new0 (EContactField, 1);
-                if (cb_data->field)
-                  {
-                    *(cb_data->field) = (EContactField) cur_args.user_data;
+                *(cb_data->field) = (EContactField) cur_args.user_data;
 
-                    /* FIXME - use a version which uses g_signal_connect_data so
-                     * we can eventually free each instance of cb_data */
-                    connect_retval = widget_signal_connect
-                                                          (wtree,
-                                                           cur_args.widget_name,
-                                                           cur_args.signal_name,
-                                                           cur_args.callback,
-                                                           cb_data);
-                  }
+                /* FIXME - use a version which uses g_signal_connect_data so
+                  * we can eventually free each instance of cb_data */
+                connect_retval = widget_signal_connect (wtree,
+                                                        cur_args.widget_name,
+                                                        cur_args.signal_name,
+                                                        cur_args.callback,
+                                                        cb_data);
               }
 
             if (!connect_retval)



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