soylent r173 - trunk/src
- From: treitter svn gnome org
- To: svn-commits-list gnome org
- Subject: soylent r173 - trunk/src
- Date: Mon, 23 Jun 2008 03:37:33 +0000 (UTC)
Author: treitter
Date: Mon Jun 23 03:37:33 2008
New Revision: 173
URL: http://svn.gnome.org/viewvc/soylent?rev=173&view=rev
Log:
factor out the save_changes prep for phone and web (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:37:33 2008
@@ -25,15 +25,15 @@
#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 EContactField E_CONTACT_FIELDS_PHONE[] = {E_CONTACT_PHONE_BUSINESS,
+ E_CONTACT_PHONE_HOME,
+ E_CONTACT_PHONE_MOBILE,};
const gchar *CONTEXT_LIST_PHONE[] = {"work", "home", "cell",};
-const guint E_CONTACT_FIELDS_WEB[] = {E_CONTACT_HOMEPAGE_URL,
- E_CONTACT_BLOG_URL,
- E_CONTACT_CALENDAR_URI,
- E_CONTACT_VIDEO_URL,};
+const EContactField E_CONTACT_FIELDS_WEB[] = {E_CONTACT_HOMEPAGE_URL,
+ E_CONTACT_BLOG_URL,
+ E_CONTACT_CALENDAR_URI,
+ E_CONTACT_VIDEO_URL,};
const gchar *CONTEXT_LIST_WEB[] = {"homepage", "blog", "calendar", "video",};
typedef struct pre_save_im_tag pre_save_im_t;
@@ -1256,6 +1256,7 @@
return retval;
}
+/* Add email field changes to selected EContact (but do not commit) */
static gboolean
soylent_browser_person_view_save_changes_prep_email (GtkWidget *widget,
gpointer user_data)
@@ -1341,6 +1342,73 @@
return retval;
}
+/* Add field changes to selected EContact (but do not commit)
+ *
+ * Arguments:
+ * browser -- SoylentBrowser
+ * e_contact -- EContact to modify
+ * widget_context -- widget name context (eg, 'phone', 'web')
+ * e_contact_fields -- list of EContactFields corresponding to context_list
+ * context_list -- widget name subcontexts (eg, 'home', 'work') corresponding to
+ * e_contact_fields
+ */
+static gboolean
+soylent_browser_person_view_save_changes_prep_list
+ (SoylentBrowser *browser,
+ EContact *e_contact,
+ const gchar *widget_context,
+ guint num_fields,
+ const EContactField *e_contact_fields,
+ const gchar **context_list)
+{
+ gboolean retval = FALSE;
+ GladeXML *wtree = NULL;
+ guint context = 0;
+
+ 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);
+
+ /* invert usual logic to simplify code below */
+ retval = TRUE;
+
+ for (context = 0; context < num_fields; context++)
+ {
+ gchar *contents_new = NULL;
+ gchar *widget_name = NULL;
+ GtkHBox *hbox = NULL;
+
+ widget_name = g_strdup_printf ("hbox_person_%s_%s", widget_context,
+ context_list[context]);
+ hbox = 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))
+ {
+ GtkEntry *entry = NULL;
+
+ widget_name = g_strdup_printf ("entry_person_%s_%s", widget_context,
+ context_list[context]);
+ entry = GTK_ENTRY (glade_xml_get_widget (wtree, widget_name));
+ g_free (widget_name);
+
+ contents_new = g_strdup (gtk_entry_get_text (entry));
+ retval &= soylent_browser_person_set_field_simple
+ (e_contact,
+ e_contact_fields[context],
+ contents_new);
+ g_free (contents_new);
+ }
+ }
+
+ return retval;
+}
+
/* Save unsaved changes to the person's details
*
* Return TRUE for success, FALSE for any failure. */
@@ -1386,79 +1454,19 @@
soylent_browser_person_view_save_changes_prep_email (NULL, browser);
- {
- guint context = 0;
-
- /* Prep the phone numbers for saving */
- for (context = 0; context < ARRAY_LEN (CONTEXT_LIST_PHONE); context++)
- {
- gchar *contents_new = NULL;
- gchar *widget_name = NULL;
- GtkHBox *hbox_phone = NULL;
-
- widget_name = g_strdup_printf ("hbox_person_phone_%s",
- CONTEXT_LIST_PHONE[context]);
- hbox_phone = 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_phone))
- {
- GtkEntry *entry_phone = NULL;
-
- widget_name = g_strdup_printf ("entry_person_phone_%s",
- CONTEXT_LIST_PHONE[context]);
- entry_phone = GTK_ENTRY (glade_xml_get_widget (wtree, widget_name));
- g_free (widget_name);
-
- contents_new = g_strdup (gtk_entry_get_text (entry_phone));
- soylent_browser_person_set_field_simple
- (e_contact,
- E_CONTACT_FIELDS_PHONE[context],
- contents_new);
- g_free (contents_new);
- }
- }
- }
-
- {
- guint context = 0;
-
- /* Prep the phone numbers for saving */
- for (context = 0; context < ARRAY_LEN (CONTEXT_LIST_WEB); context++)
- {
- gchar *contents_new = NULL;
- gchar *widget_name = NULL;
- GtkHBox *hbox_web = NULL;
-
- widget_name = g_strdup_printf ("hbox_person_web_%s",
- CONTEXT_LIST_WEB[context]);
- hbox_web = 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_web))
- {
- GtkEntry *entry_web = NULL;
-
- widget_name = g_strdup_printf ("entry_person_web_%s",
- CONTEXT_LIST_WEB[context]);
- entry_web = GTK_ENTRY (glade_xml_get_widget (wtree, widget_name));
- g_free (widget_name);
-
- contents_new = g_strdup (gtk_entry_get_text (entry_web));
- soylent_browser_person_set_field_simple
- (e_contact,
- E_CONTACT_FIELDS_WEB[context],
- contents_new);
- g_free (contents_new);
- }
- }
- }
-
- /* FIXME: handle web address fields */
+ /* 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_prep_changes_im (browser, e_contact);
/* FIXME: un-hardcode this; handle all types */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]