soylent r167 - trunk/src



Author: treitter
Date: Sun Jun 22 23:41:15 2008
New Revision: 167
URL: http://svn.gnome.org/viewvc/soylent?rev=167&view=rev

Log:
begin moving over to cleaner editor saving implementation

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	Sun Jun 22 23:41:15 2008
@@ -25,6 +25,11 @@
 #include "soylent-browser-person-view.h"
 #include "soylent-utils.h"
 
+const guint E_CONTACT_FIELDS_PHONE[] = {E_CONTACT_PHONE_BUSINESS,
+                                        E_CONTACT_PHONE_HOME,
+                                        E_CONTACT_PHONE_MOBILE,};
+const gchar *CONTEXT_LIST_PHONE[] = {"work", "home", "cell",};
+
 typedef struct pre_save_im_tag pre_save_im_t;
 struct pre_save_im_tag
 {
@@ -1300,19 +1305,27 @@
     g_free (contents_new);
   }
 
+  g_debug ("\n");
+
   /* Prep the email fields for saving */
+  e_vcard_remove_attributes (E_VCARD (e_contact), NULL, EVC_EMAIL);
   {
     gchar *contents_new = NULL;
     guint email_num = 1;
 
-    for (email_num = 1; email_num <= MAX_GUI_EMAIL; email_num++)
+    for (email_num = 1, e_contact_field = E_CONTACT_EMAIL_1;
+         (email_num <= MAX_GUI_EMAIL)
+         && (e_contact_field < (E_CONTACT_EMAIL_1 + MAX_GUI_EMAIL));
+         email_num++)
       {
-        gchar *entry_str = NULL;
+        gchar *widget_name = NULL;
         GtkHBox *hbox_email = NULL;
 
-        entry_str = g_strdup_printf ("hbox_person_email_%d", email_num); 
-        hbox_email = GTK_HBOX (glade_xml_get_widget (wtree, entry_str)); 
-        g_free (entry_str);
+        g_debug ("e_contact_field: %d", e_contact_field);
+
+        widget_name = g_strdup_printf ("hbox_person_email_%d", email_num); 
+        hbox_email = GTK_HBOX (glade_xml_get_widget (wtree, widget_name)); 
+        g_free (widget_name);
 
         /* By convention, the hbox is only visible if there's something useful
          * in it */
@@ -1320,9 +1333,81 @@
           {
             GtkEntry *entry_email = NULL;
 
-            entry_str = g_strdup_printf ("entry_person_email_%d", email_num); 
-            entry_email = GTK_ENTRY (glade_xml_get_widget (wtree, entry_str)); 
-            g_free (entry_str);
+            g_debug ("hbox visible");
+
+            widget_name = g_strdup_printf ("entry_person_email_%d", email_num); 
+            entry_email = GTK_ENTRY (glade_xml_get_widget (wtree, widget_name));
+            g_free (widget_name);
+
+            contents_new = g_strdup (gtk_entry_get_text (entry_email));
+
+            /* Ensure name is set to something useful, to prevent blanking the
+             * name the first time it's edited */
+
+            if (contents_new && !g_str_equal (contents_new, ""))
+              {
+                soylent_browser_person_set_field_simple (e_contact,
+                                                         e_contact_field,
+                                                         contents_new);
+                /* only move on to the next field if the current one isn't
+                 * blank; this avoids a data aliasing problem */
+                g_debug ("wrote field: %d", (e_contact_field));
+                g_debug ("contents_new: %s", contents_new);
+                e_contact_field++;
+              }
+            else
+              {
+                g_debug ("contents NULL");
+              }
+
+            g_free (contents_new);
+          }
+      }
+
+    g_debug (" ");
+
+    /* if we run through any iterations, we skipped over empty fields above;
+     * clear out the remaining fields to overwrite any dangling values */
+    for (;
+         e_contact_field < (E_CONTACT_EMAIL_1 + MAX_GUI_EMAIL);
+         e_contact_field++)
+      {
+        g_debug ("e_contact_field: %d", e_contact_field);
+
+        g_debug ("e_contact_field contents (write): '(null)'");
+        soylent_browser_person_set_field_simple (e_contact, e_contact_field,
+                                                 NULL);
+
+        g_debug ("e_contact_field contents (read): '%s'",
+                 (gchar*) e_contact_get_const (e_contact, e_contact_field));
+      }
+  }
+
+#if 0
+  {
+    guint context = 0;
+
+    /* Prep the phone numbers for saving */
+    for (context = 0; context < ARRAY_LEN (CONTEXT_LIST_PHONE); context++)
+      {
+        gchar *contents_new = NULL;
+        guint phone_pos = 0;
+        gchar *widget_name = NULL;
+        GtkHBox *hbox_phone = NULL;
+
+        widget_name = g_strdup_printf ("hbox_person_phone_%d", email_num); 
+        hbox_email = GTK_HBOX (glade_xml_get_widget (wtree, widget_name)); 
+        g_free (widget_name);
+
+        /* By convention, the hbox is only visible if there's something
+         * useful in it */
+        if (GTK_WIDGET_VISIBLE (hbox_email))
+          {
+            GtkEntry *entry_email = NULL;
+
+            widget_name = g_strdup_printf ("entry_person_email_%d", email_num); 
+            entry_email = GTK_ENTRY (glade_xml_get_widget (wtree, widget_name));
+            g_free (widget_name);
 
             contents_new = g_strdup (gtk_entry_get_text (entry_email));
 
@@ -1338,10 +1423,11 @@
 
             g_free (contents_new);
           }
+        /* FIXME: handle phone fields */
       }
   }
+#endif
 
-  /* FIXME: handle phone fields */
   /* FIXME: handle web address fields */
 
   soylent_browser_person_view_prep_changes_im (browser, e_contact);
@@ -2488,6 +2574,13 @@
   g_return_val_if_fail (E_IS_CONTACT (e_contact), retval);
   g_return_val_if_fail (E_CONTACT_FIELD_IS_VALID (e_contact_field), retval);
 
+  g_debug (G_STRLOC ": setting simple field number %d: %s", e_contact_field,
+           contents_new);
+
+  if (contents_new && g_str_equal (contents_new, ""))
+    {
+      contents_new = NULL;
+    }
   e_contact_set (e_contact, e_contact_field, (gpointer) contents_new);
 
   if (e_contact_field == E_CONTACT_FULL_NAME)
@@ -2673,6 +2766,9 @@
             }
           else
             {
+              entry_set_text_block_handler
+                          (entry_email, "",
+                           soylent_browser_person_entry_changed_e_contact_cb);
               gtk_widget_hide (GTK_WIDGET (hbox_email));
             }
 
@@ -3150,12 +3246,6 @@
 soylent_browser_person_view_phone_update (SoylentBrowser *browser,
                                           SoylentPerson *person)
 {
-  const guint e_contact_fields[] = {E_CONTACT_PHONE_BUSINESS,
-                                    E_CONTACT_PHONE_HOME,
-                                    E_CONTACT_PHONE_MOBILE,};
-  const gchar *context_list[] = {"work", "home", "cell",};
-  const guint NUM_CONTEXT = 3;
-  const guint CONTEXT_POS_WORK = 0;
   gboolean retval = FALSE;
   GladeXML *wtree = NULL;
   EContact *e_contact = NULL;
@@ -3185,20 +3275,21 @@
   frame_phone = GTK_FRAME (glade_xml_get_widget (wtree, "frame_person_phone"));
   fixed_phone = GTK_FIXED (glade_xml_get_widget (wtree, "fixed_person_phone"));
 
-  for (context = CONTEXT_POS_WORK; context < NUM_CONTEXT; context++)
+  for (context = 0; context < ARRAY_LEN (CONTEXT_LIST_PHONE); context++)
     {
       widget_name = g_strdup_printf ("entry_person_phone_%s",
-                                    context_list[context]);
+                                     CONTEXT_LIST_PHONE[context]);
 
       entry_phone = GTK_ENTRY (glade_xml_get_widget (wtree, widget_name));
       g_free (widget_name);
 
       widget_name = g_strdup_printf ("hbox_person_phone_%s",
-                                    context_list[context]);
+                                     CONTEXT_LIST_PHONE[context]);
       hbox_phone = GTK_HBOX (glade_xml_get_widget (wtree, widget_name));
       g_free (widget_name);
 
-      phone_str = e_contact_get_const (e_contact, e_contact_fields[context]);
+      phone_str = e_contact_get_const (e_contact,
+                                       E_CONTACT_FIELDS_PHONE[context]);
       if (phone_str)
         {
           entry_set_text_block_handler



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