soylent r87 - trunk/src



Author: treitter
Date: Sun Mar  2 19:18:13 2008
New Revision: 87
URL: http://svn.gnome.org/viewvc/soylent?rev=87&view=rev

Log:
Clean up entry_changed_e_contact() and cut two similar (but unnecessary) functions

Modified:
   trunk/src/soylent-browser-person-view.c
   trunk/src/soylent-browser-person-view.h
   trunk/src/soylent-browser.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 Mar  2 19:18:13 2008
@@ -572,59 +572,55 @@
   return retval;
 }
 
-/* Handle a person's (simple, GtkEntry-based) detail's edit */
-void
+/* Handle a person's (simple, GtkEntry-based) detail's edit
+ *
+ * Return TRUE for success, FALSE for any failure. */
+gboolean
 entry_changed_e_contact (GtkEditable *editable, gpointer user_data)
 {
+  gboolean retval = FALSE;
   cb_entry_changed_e_contact *cb_data = NULL;
   SoylentBrowser *browser = NULL;
   GHashTable *edits_pending = NULL;
   gpointer value_existing = NULL;
 
+  g_return_val_if_fail (user_data != NULL, retval);
+  /* FIXME: uncomment once SoylentBrowser is a GObject:
+  g_return_val_if_fail (SOYLENT_IS_BROWSER (browser), NULL);
+   */
+
   cb_data = (cb_entry_changed_e_contact*) user_data;
   browser = cb_data->browser;
-  edits_pending = soylent_browser_get_edits_pending (browser);
-  value_existing = g_hash_table_lookup (edits_pending, cb_data->widget_name);
-
-  /* Note: if we ever insert values == NULL (which we shouldn't be anyhow), this
-   * assumes the key doesn't have an entry in the hash */
-  if (value_existing == NULL)
+  /* FIXME: once SoylentBrowser is a GObject, check SOYLENT_IS_BROWSER */
+  if (browser)
     {
-      g_hash_table_insert (edits_pending, cb_data->widget_name,
-                           cb_data->field);
-    }
-}
-
-/* Save edits to a person's non-trivial (multi-valued) detail */
-void
-multival_changed_e_contact (GtkEditable *editable, gpointer user_data)
-{
-  cb_entry_changed_e_contact *cb_data = NULL;
-  SoylentBrowser *browser = NULL;
-  GHashTable *edits_pending = NULL;
-  gpointer value_existing = NULL;
+      edits_pending = soylent_browser_get_edits_pending (browser);
+      if (edits_pending)
+        {
+          value_existing = g_hash_table_lookup (edits_pending,
+                                                cb_data->widget_name);
 
-  cb_data = (cb_entry_changed_e_contact*) user_data;
-  browser = cb_data->browser;
-  edits_pending = soylent_browser_get_edits_pending (browser);
-  /* XXX: why aren't we just inserting a pointer to editable instead of its
-   * name?
-   */
-  value_existing = g_hash_table_lookup (edits_pending, cb_data->widget_name);
+          /* Note: if we ever insert values == NULL (which we shouldn't be
+           * anyhow), this assumes the key doesn't have an entry in the hash */
+          if (value_existing == NULL)
+            {
+              g_hash_table_insert (edits_pending, cb_data->widget_name,
+                                   cb_data->field);
+            }
 
-  /* Note: if we ever insert values == NULL (which we shouldn't be anyhow), this
-   * assumes the key doesn't have an entry in the hash */
-  if (value_existing == NULL)
+          retval = TRUE;
+        }
+      else
+        {
+          g_critical ("pending edits hash is invalid");
+        }
+    }
+  else
     {
-      g_hash_table_insert (edits_pending, cb_data->widget_name,
-                           cb_data->field);
+      g_critical ("SoylentBrowser is invalid");
     }
-}
 
-void
-text_buffer_changed_e_contact (GtkTextBuffer *buf, gpointer user_data)
-{
- /* TODO */
+  return retval;
 }
 
 /* Create a new SoylentPerson and matching EContact in e-d-s */
@@ -2570,17 +2566,17 @@
 
       /* FIXME: factor out the commonality */
       text_buffer_set_text_block_handler (tb_street, addr->street,
-                                          multival_changed_e_contact);
+                                          entry_changed_e_contact);
       entry_set_text_block_handler (entry_po, addr->po,
-                                    multival_changed_e_contact);
+                                    entry_changed_e_contact);
       entry_set_text_block_handler (entry_code, addr->code,
-                                    multival_changed_e_contact);
+                                    entry_changed_e_contact);
       entry_set_text_block_handler (entry_locality, addr->locality,
-                                    multival_changed_e_contact);
+                                    entry_changed_e_contact);
       entry_set_text_block_handler (entry_region, addr->region,
-                                    multival_changed_e_contact);
+                                    entry_changed_e_contact);
       entry_set_text_block_handler (entry_country, addr->country,
-                                    multival_changed_e_contact);
+                                    entry_changed_e_contact);
     }
 
   if (frames_visible > 0)

Modified: trunk/src/soylent-browser-person-view.h
==============================================================================
--- trunk/src/soylent-browser-person-view.h	(original)
+++ trunk/src/soylent-browser-person-view.h	Sun Mar  2 19:18:13 2008
@@ -64,9 +64,7 @@
                                                       (SoylentBrowser *browser,
                                                        SoylentPerson *person);
 
-void entry_changed_e_contact        (GtkEditable *editable, gpointer user_data);
-void multival_changed_e_contact     (GtkEditable *editable, gpointer user_data);
-void text_buffer_changed_e_contact  (GtkTextBuffer *buf, gpointer user_data);
+gboolean entry_changed_e_contact    (GtkEditable *editable, gpointer user_data);
 
 /* Committing changes from the above functions */
 void commit_detail_add        (GtkWidget *widget, gpointer user_data);

Modified: trunk/src/soylent-browser.c
==============================================================================
--- trunk/src/soylent-browser.c	(original)
+++ trunk/src/soylent-browser.c	Sun Mar  2 19:18:13 2008
@@ -1878,7 +1878,7 @@
         /* TODO: factor this out somewhere else, if possible */
         const gchar *context_list[] = {"home", "work", "other"};
         const gchar *signal_name = "changed";
-        const GCallback callback = G_CALLBACK (multival_changed_e_contact);
+        const GCallback callback = G_CALLBACK (entry_changed_e_contact);
         gboolean connect_retval = FALSE;
         gchar *widget_name = NULL;
         cb_entry_changed_e_contact *cb_data = NULL;



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