soylent r144 - trunk/src



Author: treitter
Date: Sun May 25 21:06:25 2008
New Revision: 144
URL: http://svn.gnome.org/viewvc/soylent?rev=144&view=rev

Log:
factor IM field saving prep work into its own function for readability

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 May 25 21:06:25 2008
@@ -39,6 +39,9 @@
 
 static gboolean soylent_browser_person_view_editor_hide
                                                       (SoylentBrowser *browser);
+static gboolean soylent_browser_person_view_prep_changes_im
+                                                      (SoylentBrowser *browser,
+                                                       EContact *e_contact);
 static gboolean soylent_browser_person_view_save_changes (GtkWidget *widget,
                                                           gpointer user_data);
 static gboolean soylent_browser_person_edit_save_scroll_cb
@@ -1145,6 +1148,198 @@
 }
 #endif
 
+/* Add modified and new IM fields to the EContact (but do not commit) */
+static gboolean
+soylent_browser_person_view_prep_changes_im (SoylentBrowser *browser,
+                                             EContact *e_contact)
+{
+  gboolean retval = FALSE;
+  GladeXML *wtree = NULL;
+  guint context = CONTEXT_FIRST;
+  GList *pre_save_list_im = NULL;
+  GList *l = NULL;
+
+  g_return_val_if_fail (browser, retval);
+  /* FIXME: uncomment once SoylentBrowser is a GObject:
+  g_return_val_if_fail (SOYLENT_IS_BROWSER (browser), retval);
+   */
+
+  wtree = soylent_browser_get_widget_tree (browser);
+
+  retval = TRUE;
+
+  /* FIXME: build up GList(s) of pre_save_im_t* as necessary for each of
+   * the IM fields, then dump them into the contact all at once. Don't bother
+   * with soylent_browser_person_apply_edits_from_widgets_switch() */
+  for (context = CONTEXT_IM_FIRST; context <= CONTEXT_IM_LAST; context++)
+    {
+      guint im_field_pos = 0;
+      /*
+      e_contact_field = CB_DATA_FIELD_IM;
+      */
+
+      for (im_field_pos = 0;
+           im_field_pos < IM_FIELDS_PER_CONTEXT;
+           im_field_pos++)
+        {
+          GtkHBox *hbox_im = NULL;
+          GtkEntry *entry_im = NULL;
+          gchar *hbox_name = NULL;
+          gchar *label_name = NULL;
+          gchar *entry_name = NULL;
+          /*
+          gchar *pos_str = NULL;
+          */
+
+          hbox_name = g_strdup_printf ("hbox_person_im_%s_%d",
+                                       CONTEXT_STRS[context], im_field_pos + 1);
+          label_name = g_strdup_printf ("label_person_im_%s_%d",
+                                        CONTEXT_STRS[context],
+                                        im_field_pos + 1);
+          entry_name = g_strdup_printf ("entry_person_im_%s_%d",
+                                        CONTEXT_STRS[context],
+                                        im_field_pos + 1);
+          entry_im = GTK_ENTRY (glade_xml_get_widget (wtree, entry_name));
+          /*
+          g_debug ("widget name: '%s'", hbox_name);
+          */
+
+          /*
+          pos_str = g_strdup_printf ("hbox_person_im_%s_%d",
+                                     CONTEXT_STRS[context], im_field_pos);
+                                     */
+
+          /*
+          hbox_im = GTK_HBOX (soylent_browser_get_widget (browser, "hbox", "im",
+                                                          CONTEXT_STRS[context],
+                                                          pos_str));
+                                                          */
+          hbox_im = GTK_HBOX (glade_xml_get_widget (wtree, hbox_name));
+          if (GTK_WIDGET_VISIBLE(hbox_im))
+            {
+              /*
+              gchar *label_str = NULL;
+              */
+              GtkLabel *label = NULL;
+              const gchar *label_text = NULL;
+              gchar *proto_name_lc = NULL;
+              gchar *field_name = NULL;
+              pre_save_im_t *pre_save_im = NULL;
+              gchar *value = NULL;
+
+              /*
+              gchar *widget_name = NULL;
+              */
+
+              /*
+              g_debug ("hbox visible");
+              */
+
+              /* FIXME: factor this code better */
+              /*
+              widget_name = g_strdup_printf ("mail_%s", CONTEXT_STRS[context]);
+              */
+              /*
+              soylent_browser_person_apply_edits_from_widgets_switch
+                                                              (entry_name,
+                                                               &e_contact_field,
+                                                               browser);
+                                                               */
+
+              
+              /* TODO: use this solution instead */
+              /*
+              label_str = g_strstr_len (widget_name, strlen (widget_name),
+                                        "person");
+              label_str = g_strdup_printf ("label_%s", label_str);
+              */
+              label = GTK_LABEL (glade_xml_get_widget (wtree, label_name)); 
+              label_text = gtk_label_get_text (label);
+              proto_name_lc = g_ascii_strdown (label_text, strlen (label_text));
+              field_name = g_strdup_printf ("im_%s", proto_name_lc);
+              /*
+              field = e_contact_field_id (field_name);
+              */
+
+              value = g_strdup (gtk_entry_get_text (entry_im));
+
+              pre_save_im = g_new (pre_save_im_t, 1);
+              pre_save_im->context = context;
+              /* FIXME: actually use the correct IM field, based on proto */
+              pre_save_im->e_contact_field = e_contact_field_id (field_name);
+              pre_save_im->value = value;
+              pre_save_list_im = g_list_prepend (pre_save_list_im, pre_save_im);
+
+              e_contact_set_attributes (e_contact, pre_save_im->e_contact_field,
+                                        NULL);
+
+              /*
+              g_free (widget_name);
+              */
+
+              g_free (proto_name_lc);
+              g_free (field_name);
+              /*
+              g_free (context_str);
+              */
+            }
+          /*
+          else
+            {
+              g_debug ("hbox *in*visible");
+            }
+            */
+
+          /*
+          g_free (pos_str);
+          */
+          g_free (hbox_name);
+          g_free (entry_name);
+          g_free (label_name);
+        }
+    }
+
+  /* FIXME: un-hardcode this; handle all types */
+  /*
+  use eds_im_field_id_to_vcard_attr (field_id)); for the IM fields
+  e_vcard_remove_attributes (e_contact, "X-JABBER");
+  */
+
+  g_debug ("would save these IM fields:");
+  /* Traverse in reverse order to preserve order from the editor */
+  for (l = g_list_last (pre_save_list_im); l; l = g_list_previous (l))
+    {
+      pre_save_im_t *fields_im = NULL;
+
+      fields_im = l->data;
+      g_debug ("  %s, %d, %s", CONTEXT_STRS[fields_im->context],
+               fields_im->e_contact_field, fields_im->value);
+
+      /*
+      BREAK ME
+      soylent_browser_person_set_im_field (browser, e_contact,
+                                           fields_im->e_contact_field,
+                                           fields_im->context,
+                                           fields_im->value);
+                                           */
+
+      if (fields_im->value && !g_str_equal (fields_im->value, ""))
+        {
+          e_vcard_attr_list_prepend_value (e_contact,
+                                           fields_im->e_contact_field,
+                                           CONTEXT_STRS[fields_im->context],
+                                           fields_im->value);
+        }
+    }
+
+  /* FIXME: go through pre_save_list_im and g_free all datas' value field, each
+   * struct */
+
+  g_list_free (pre_save_list_im);
+
+  return retval;
+}
+
 /* Save unsaved changes to the person's details
  *
  * Return TRUE for success, FALSE for any failure. */
@@ -1160,9 +1355,12 @@
   guint context = CONTEXT_FIRST;
   EContactField e_contact_field = E_CONTACT_FIELD_FIRST - 1;
   EContact *e_contact = NULL;
+  /*
   GList *pre_save_list_im = NULL;
+  */
+  /*
   GList *l = 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);
@@ -1193,6 +1391,8 @@
   /* FIXME: handle phone fields */
   /* FIXME: handle web address fields */
 
+  soylent_browser_person_view_prep_changes_im (browser, e_contact);
+#if 0
   /* FIXME: build up GList(s) of pre_save_im_t* as necessary for each of
    * the IM fields, then dump them into the contact all at once. Don't bother
    * with soylent_browser_person_apply_edits_from_widgets_switch() */
@@ -1361,6 +1561,8 @@
    * struct */
 
   g_list_free (pre_save_list_im);
+#endif
+
 
   for (context = CONTEXT_FIRST, e_contact_field = E_CONTACT_FIRST_ADDRESS_ID;
        (context <= CONTEXT_LAST)



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