soylent r172 - trunk/src
- From: treitter svn gnome org
- To: svn-commits-list gnome org
- Subject: soylent r172 - trunk/src
- Date: Mon, 23 Jun 2008 03:07:55 +0000 (UTC)
Author: treitter
Date: Mon Jun 23 03:07:55 2008
New Revision: 172
URL: http://svn.gnome.org/viewvc/soylent?rev=172&view=rev
Log:
pull out _save_changes()'s email prep into a separate 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 Mon Jun 23 03:07:55 2008
@@ -1256,6 +1256,91 @@
return retval;
}
+static gboolean
+soylent_browser_person_view_save_changes_prep_email (GtkWidget *widget,
+ gpointer user_data)
+{
+ gboolean retval = FALSE;
+ SoylentBrowser *browser = NULL;
+ GladeXML *wtree = NULL;
+ EContactField e_contact_field = E_CONTACT_FIELD_FIRST - 1;
+ EContact *e_contact = NULL;
+ gchar *contents_new = NULL;
+ guint email_num = 1;
+
+ 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);
+
+ /* invert usual logic to simplify code below */
+ retval = TRUE;
+
+ /* XXX: potentially lossy; works around a bug where
+ * e_contact_set(contact, {NULL,""}) doesn't always stick */
+ e_vcard_remove_attributes (E_VCARD (e_contact), NULL, EVC_EMAIL);
+
+ 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 *widget_name = NULL;
+ GtkHBox *hbox_email = NULL;
+
+ 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 */
+ 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));
+
+ /* 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, ""))
+ {
+ retval &= 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 */
+ e_contact_field++;
+ }
+
+ g_free (contents_new);
+ }
+ }
+
+ /* 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++)
+ {
+ soylent_browser_person_set_field_simple (e_contact, e_contact_field,
+ NULL);
+ }
+
+ return retval;
+}
+
/* Save unsaved changes to the person's details
*
* Return TRUE for success, FALSE for any failure. */
@@ -1280,9 +1365,6 @@
/* TODO: make this one of the parameters instead */
e_contact = soylent_browser_get_selected_person_e_contact (browser);
- /* FIXME FIXME FIXME: for all the multi-value fields, apply all changes at
- * once via e-d-s' multi-value setting functions, for performance reasons */
-
/* Prep the name field (and its multiple vCard fields) for saving */
{
gchar *contents_new = NULL;
@@ -1302,63 +1384,7 @@
g_free (contents_new);
}
- /* 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, 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 *widget_name = NULL;
- GtkHBox *hbox_email = NULL;
-
- 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 */
- 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));
-
- /* 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 */
- e_contact_field++;
- }
-
- g_free (contents_new);
- }
- }
-
- /* 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++)
- {
- soylent_browser_person_set_field_simple (e_contact, e_contact_field,
- NULL);
- }
- }
+ soylent_browser_person_view_save_changes_prep_email (NULL, browser);
{
guint context = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]