soylent r177 - trunk/src



Author: treitter
Date: Mon Jun 23 04:16:49 2008
New Revision: 177
URL: http://svn.gnome.org/viewvc/soylent?rev=177&view=rev

Log:
factor out prep_mail

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

Modified: trunk/src/soylent-browser-person-view.c
==============================================================================
--- trunk/src/soylent-browser-person-view.c	(original)
+++ trunk/src/soylent-browser-person-view.c	Mon Jun 23 04:16:49 2008
@@ -1428,48 +1428,25 @@
   return retval;
 }
 
-/* Save unsaved changes to the person's details
- *
- * Return TRUE for success, FALSE for any failure. */
+/* Add postal mail changes to selected EContact (but do not commit) */
 static gboolean
-soylent_browser_person_view_save_changes (GtkWidget *widget, gpointer user_data)
+soylent_browser_person_view_save_changes_prep_mail (SoylentBrowser *browser,
+                                                    EContact *e_contact)
 {
   gboolean retval = FALSE;
-  SoylentBrowser *browser = NULL;
   GladeXML *wtree = NULL;
-  guint context = CONTEXT_FIRST;
+  guint context = 0;
   EContactField e_contact_field = E_CONTACT_FIELD_FIRST - 1;
-  EContact *e_contact = NULL;
 
-  g_return_val_if_fail (user_data, retval);
+  g_return_val_if_fail (browser, retval);
   /* FIXME: uncomment once SoylentBrowser is a GObject:
-  g_return_val_if_fail (SOYLENT_IS_BROWSER (user_data), retval);
+  g_return_val_if_fail (SOYLENT_IS_BROWSER (browser), retval);
    */
 
-  browser = (SoylentBrowser*) user_data;
   wtree = soylent_browser_get_widget_tree (browser);
 
-  /* TODO: make this one of the parameters instead */
-  e_contact = soylent_browser_get_selected_person_e_contact (browser);
-
-  soylent_browser_person_view_save_changes_prep_name (browser, e_contact);
-  soylent_browser_person_view_save_changes_prep_email (browser, e_contact);
-
-  /* Prep the phone numbers for saving */
-  soylent_browser_person_view_save_changes_prep_list
-                                          (browser, e_contact, "phone",
-                                           ARRAY_LEN (E_CONTACT_FIELDS_PHONE),
-                                           E_CONTACT_FIELDS_PHONE,
-                                           CONTEXT_LIST_PHONE);
-
-  /* Prep the web URLs for saving */
-  soylent_browser_person_view_save_changes_prep_list
-                                              (browser, e_contact, "web",
-                                               ARRAY_LEN (E_CONTACT_FIELDS_WEB),
-                                               E_CONTACT_FIELDS_WEB,
-                                               CONTEXT_LIST_WEB);
-
-  soylent_browser_person_view_save_changes_prep_im (browser, e_contact);
+  /* invert usual logic to simplify code below */
+  retval = TRUE;
 
   for (context = CONTEXT_FIRST, e_contact_field = E_CONTACT_FIRST_ADDRESS_ID;
        (context <= CONTEXT_LAST)
@@ -1493,14 +1470,60 @@
            * section in this function its own simple function (like
            * soylent_browser_person_view_prep_changes_im() ; call it here */
           widget_name = g_strdup_printf ("mail_%s", CONTEXT_STRS[context]);
-          soylent_browser_person_apply_edits_from_widgets_switch
+          retval &= soylent_browser_person_apply_edits_from_widgets_switch
                                                               (widget_name,
                                                                &e_contact_field,
                                                                browser);
           g_free (widget_name);
         }
     }
+  
+  return retval;
+}
+
+/* Save unsaved changes to the person's details
+ *
+ * Return TRUE for success, FALSE for any failure. */
+static gboolean
+soylent_browser_person_view_save_changes (GtkWidget *widget, gpointer user_data)
+{
+  gboolean retval = FALSE;
+  SoylentBrowser *browser = NULL;
+  GladeXML *wtree = NULL;
+  EContact *e_contact = NULL;
+
+  g_return_val_if_fail (user_data, retval);
+  /* FIXME: uncomment once SoylentBrowser is a GObject:
+  g_return_val_if_fail (SOYLENT_IS_BROWSER (user_data), retval);
+   */
+
+  browser = (SoylentBrowser*) user_data;
+  wtree = soylent_browser_get_widget_tree (browser);
+
+  /* TODO: make this one of the parameters instead */
+  e_contact = soylent_browser_get_selected_person_e_contact (browser);
+
+  soylent_browser_person_view_save_changes_prep_name (browser, e_contact);
+  soylent_browser_person_view_save_changes_prep_email (browser, e_contact);
+
+  /* Prep the phone numbers for saving */
+  soylent_browser_person_view_save_changes_prep_list
+                                          (browser, e_contact, "phone",
+                                           ARRAY_LEN (E_CONTACT_FIELDS_PHONE),
+                                           E_CONTACT_FIELDS_PHONE,
+                                           CONTEXT_LIST_PHONE);
 
+  /* Prep the web URLs for saving */
+  soylent_browser_person_view_save_changes_prep_list
+                                              (browser, e_contact, "web",
+                                               ARRAY_LEN (E_CONTACT_FIELDS_WEB),
+                                               E_CONTACT_FIELDS_WEB,
+                                               CONTEXT_LIST_WEB);
+
+  soylent_browser_person_view_save_changes_prep_im (browser, e_contact);
+  soylent_browser_person_view_save_changes_prep_mail (browser, e_contact);
+
+  /* Commit the changes */
   if (e_contact)
     {
       EBook *e_book = NULL;
@@ -1566,8 +1589,6 @@
   return retval;
 }
 
-
-
 static gboolean
 soylent_browser_person_edit_save_scroll_cb (EBookView *book_view,
                                             const GList *e_contacts,
@@ -2401,6 +2422,11 @@
   e_contact = soylent_browser_get_selected_person_e_contact (browser);
   addr = e_contact_get (e_contact, e_contact_field);
 
+  if (!addr)
+    {
+      addr = g_new0 (EContactAddress, 1);
+    }
+
   for (fieldnum = 0; fieldnum < MAIL_FIELDS_NUM; fieldnum++)
     {
       GtkWidget *widget_cur = NULL;
@@ -2438,13 +2464,12 @@
   else
     {
       e_contact_set (e_contact, e_contact_field, (gpointer) addr);
+      e_contact_set (e_contact,
+                     e_contact_field
+                        - E_CONTACT_FIRST_ADDRESS_ID + E_CONTACT_FIRST_LABEL_ID,
+                     (gpointer) e_contact_address_to_label (addr));
     }
 
-  e_contact_set (e_contact,
-                 e_contact_field
-                  - E_CONTACT_FIRST_ADDRESS_ID + E_CONTACT_FIRST_LABEL_ID,
-                 (gpointer) e_contact_address_to_label (addr));
-
   retval = TRUE;
 
   return retval;



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