soylent r90 - trunk/src



Author: treitter
Date: Fri Mar  7 05:39:55 2008
New Revision: 90
URL: http://svn.gnome.org/viewvc/soylent?rev=90&view=rev

Log:
continue cleaning up commit_detail_add() and dependent functions

Modified:
   trunk/src/soylent-browser-person-view.c
   trunk/src/soylent-browser-person-view.h

Modified: trunk/src/soylent-browser-person-view.c
==============================================================================
--- trunk/src/soylent-browser-person-view.c	(original)
+++ trunk/src/soylent-browser-person-view.c	Fri Mar  7 05:39:55 2008
@@ -78,9 +78,9 @@
                                           gpointer handler);
 
 /* Adding individual details to the VCard/EContact */
-static void detail_add_person_add_attr (SoylentBrowser *browser,
-                                        const gchar *attr_name,
-                                        const gchar *param_val);
+static gboolean detail_add_person_add_attr (SoylentBrowser *browser,
+                                            const gchar *attr_name,
+                                            const gchar *param_val);
 static void detail_add_person_add_mail_attrs (SoylentBrowser *browser,
                                               const gchar *param_val);
 
@@ -643,112 +643,31 @@
   return retval;
 }
 
-gboolean
-soylent_browser_detail_add_get_attr_val_email (SoylentBrowser *browser,
-                                               gchar **attr, gchar **val)
+gchar*
+soylent_browser_detail_add_get_cbox_val (SoylentBrowser *browser,
+                                         const gchar *cbox_name)
 {
-  gboolean retval = FALSE;
+  gchar *retval = NULL;
+  gchar *retval_lc = NULL;
   GladeXML *wtree = NULL;
+  GtkComboBox *cbox = NULL;
 
   g_return_val_if_fail (browser != NULL, retval);
   /* FIXME: uncomment once SoylentBrowser is a GObject:
   g_return_val_if_fail (SOYLENT_IS_BROWSER (user_data), NULL);
    */
-  g_return_val_if_fail (attr != NULL, retval);
-  g_return_val_if_fail (val != NULL, retval);
+  g_return_val_if_fail (cbox_name != NULL, retval);
 
   wtree = soylent_browser_get_widget_tree (browser);
- 
-  /* Fill the parameter value with the IM protocol name */
-  {
-    GtkComboBox *cbox_type = NULL;
-    gchar *val_lc = NULL;
-
-    cbox_type = GTK_COMBO_BOX (glade_xml_get_widget (wtree,
-                                                     "cbox_detail_type"));
-    val_lc = gtk_combo_box_get_active_text (cbox_type);
-    /* eg, HOME, WORK, OTHER */
-    *val = g_ascii_strup (val_lc, -1);
+  cbox = GTK_COMBO_BOX (glade_xml_get_widget (wtree, cbox_name));
+  retval_lc = gtk_combo_box_get_active_text (cbox);
+  retval = g_ascii_strup (retval_lc, -1);
 
-    g_free (val_lc);
-  }
-
-  *attr = g_strdup ("EMAIL");
-  if (*attr && *val)
-    {
-      retval = TRUE;
-    }
-  else
-    {
-      g_free (*attr);
-      g_free (*val);
-    }
+  g_free (retval_lc);
 
   return retval;
 }
 
-gboolean
-soylent_browser_detail_add_get_attr_val_im (SoylentBrowser *browser,
-                                            gchar **attr, gchar **val)
-{
-  gboolean retval = FALSE;
-  GladeXML *wtree = NULL;
-
-  g_return_val_if_fail (browser != NULL, retval);
-  /* FIXME: uncomment once SoylentBrowser is a GObject:
-  g_return_val_if_fail (SOYLENT_IS_BROWSER (user_data), NULL);
-   */
-  g_return_val_if_fail (attr != NULL, retval);
-  g_return_val_if_fail (val != NULL, retval);
- 
-  wtree = soylent_browser_get_widget_tree (browser);
-
-  /* Fill in the attribute name */
-  {
-    GtkComboBox *cbox_proto = NULL;
-    gchar *proto = NULL;
-    gchar *proto_uc = NULL;
-
-    cbox_proto = GTK_COMBO_BOX (glade_xml_get_widget (wtree,
-                                                      "cbox_detail_proto"));
-    proto = gtk_combo_box_get_active_text (cbox_proto);
-    proto_uc = g_ascii_strup (proto, -1);
-
-    *attr = g_strdup_printf ("X-%s", proto_uc);
-
-    g_free (proto);
-    g_free (proto_uc);
-  }
-
-  /* Fill the parameter value with the IM protocol name */
-  {
-    GtkComboBox *cbox_type = NULL;
-    gchar *val_lc = NULL;
-
-    cbox_type = GTK_COMBO_BOX (glade_xml_get_widget (wtree,
-                                                     "cbox_detail_type"));
-    val_lc = gtk_combo_box_get_active_text (cbox_type);
-    /* eg, HOME, WORK, OTHER */
-    *val = g_ascii_strup (val_lc, -1);
-
-    g_free (val_lc);
-  }
-
-  if (*attr && *val)
-    {
-      retval = TRUE;
-    }
-  else
-    {
-      g_free (*attr);
-      g_free (*val);
-    }
-
-  return retval;
-}
-
-
-
 /* FIXME: make this boolean */
 /* Commit any new details to the person being edited */
 void
@@ -776,31 +695,28 @@
 
   if (g_str_equal (domain, "Email"))
     {
-      /* FIXME: check the return value */
-      soylent_browser_detail_add_get_attr_val_email (browser, &attr_name,
-                                                     &param_val);
+      param_val = soylent_browser_detail_add_get_cbox_val (browser,
+                                                           "cbox_detail_type");
+      attr_name = g_strdup ("EMAIL");
     }
   else if (g_str_equal (domain, "Instant Messaging"))
     {
-      /* FIXME: check the return value */
-      soylent_browser_detail_add_get_attr_val_im (browser, &attr_name,
-                                                  &param_val);
+      gchar *proto = NULL;
+
+      param_val = soylent_browser_detail_add_get_cbox_val (browser,
+                                                           "cbox_detail_type");
+      proto = soylent_browser_detail_add_get_cbox_val (browser,
+                                                       "cbox_detail_proto");
+      attr_name = g_strdup_printf ("X-%s", proto);
+
+      g_free (proto);
     }
   else if (g_str_equal (domain, "Phone"))
     {
-      GtkComboBox *cbox_type_phone = NULL;
-      gchar *param_val_lc = NULL;
-
-      cbox_type_phone = GTK_COMBO_BOX (glade_xml_get_widget
-                                                    (wtree,
-                                                     "cbox_detail_type_phone"));
-      param_val_lc = gtk_combo_box_get_active_text (cbox_type_phone);
-
-      param_val = g_ascii_strup (param_val_lc, -1);
-
+      param_val = soylent_browser_detail_add_get_cbox_val
+                                                    (browser,
+                                                     "cbox_detail_type_phone");
       attr_name = g_strdup ("TEL");
-
-      g_free (param_val_lc);
     }
   else if (g_str_equal (domain, "Web Address"))
     {
@@ -840,10 +756,6 @@
   else if (g_str_equal (domain, "Mailing Address"))
     {
       /* TODO: set the corresponding LABEL attribute that Evolution sets */
-      /*
-       * FIXME: this is stupid - we allocate this, only to free it (and
-       * basically ignore it) later
-       */
       attr_name = g_strdup (EVC_ADR);
     }
   else
@@ -862,9 +774,6 @@
         {
           detail_add_person_add_attr (browser, attr_name, param_val);
         }
-
-      g_free (attr_name);
-      g_free (param_val);
     }
 
   /* Make sure we actually commit these changes back */
@@ -877,6 +786,8 @@
   gtk_widget_set_sensitive (widget, FALSE);
 
   g_free (domain);
+  g_free (attr_name);
+  g_free (param_val);
 }
 
 /* Hook up signal handlers for the Detail Add UI section widgets
@@ -1695,11 +1606,13 @@
 }
 
 /* Save a new simple (single GtkEntry-based) detail for the person being edited 
- * */
-static void
+ *
+ * Return TRUE for success, FALSE for any failure. */
+static gboolean
 detail_add_person_add_attr (SoylentBrowser *browser, const gchar *attr_name,
                             const gchar *param_val)
 {
+  gboolean retval = FALSE;
   EVCard *vcard = NULL;
   EVCardAttribute *attr = NULL;
   EVCardAttributeParam *param = NULL;
@@ -1707,6 +1620,13 @@
   const gchar *attr_val = NULL;
   GladeXML *wtree = NULL;
 
+  g_return_val_if_fail (browser != NULL, retval);
+  /* FIXME: uncomment once SoylentBrowser is a GObject:
+  g_return_val_if_fail (SOYLENT_IS_BROWSER (user_data), NULL);
+   */
+  g_return_val_if_fail (attr_name != NULL, retval);
+  g_return_val_if_fail (param_val != NULL, retval);
+
   wtree = soylent_browser_get_widget_tree (browser);
 
   attr = e_vcard_attribute_new (NULL, attr_name);
@@ -1717,6 +1637,7 @@
 
   /* FIXME: this special-case code is really ugly; push it into the appropriate
    * detail_add_get_attr_val_*() functions */
+  /*
   if (!param_val)
     {
       GtkComboBox *cbox_type = GTK_COMBO_BOX (glade_xml_get_widget (wtree,
@@ -1726,12 +1647,13 @@
 
       g_free (param_val_lc);
     }
+    */
 
   e_vcard_attribute_add_param_with_value (attr, param, param_val);
   vcard = E_VCARD (soylent_browser_get_selected_person_e_contact (browser));
   e_vcard_add_attribute_with_value (vcard, attr, attr_val);
 
-  /* XXX: do we need to free attr and param here? */
+  return retval;
 }
 
 /* Save a new mailing address for the person being edited */

Modified: trunk/src/soylent-browser-person-view.h
==============================================================================
--- trunk/src/soylent-browser-person-view.h	(original)
+++ trunk/src/soylent-browser-person-view.h	Fri Mar  7 05:39:55 2008
@@ -67,11 +67,8 @@
 gboolean entry_changed_e_contact    (GtkEditable *editable, gpointer user_data);
 
 /* Committing changes from the above functions */
-gboolean soylent_browser_detail_add_get_attr_val_email (SoylentBrowser *browser,
-                                                        gchar **attr,
-                                                        gchar **val);
-gboolean soylent_browser_detail_add_get_attr_val_im (SoylentBrowser *browser,
-                                                     gchar **attr, gchar **val);
+gchar* soylent_browser_detail_add_get_cbox_val (SoylentBrowser *browser,
+                                                const gchar *cbox_name);
 void commit_detail_add        (GtkWidget *widget, gpointer user_data);
 
 /* Setup/update sections of the person view UI with latest data from e-d-s */



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