Refactored the code that offers UI to add contacts to address book
authorSergio Villar Senin <svillar@igalia.com>
Wed, 4 Nov 2009 17:05:18 +0000 (18:05 +0100)
committerSergio Villar Senin <svillar@igalia.com>
Mon, 9 Nov 2009 17:45:34 +0000 (18:45 +0100)
Fixes NB#144914 (4/8)

src/hildon2/modest-address-book.c
src/hildon2/modest-msg-view-window.c
src/modest-address-book.h

index 4e19d89..0f1e92d 100644 (file)
@@ -1200,3 +1200,48 @@ modest_address_book_add_address_list (GSList *address_list)
        /* Frees. This will unref the subqueries as well */
        e_book_query_unref (composite_query);
 }
        /* Frees. This will unref the subqueries as well */
        e_book_query_unref (composite_query);
 }
+
+void
+modest_address_book_add_address_list_with_selector (GSList *address_list, GtkWindow *parent)
+{
+       GtkWidget *picker_dialog;
+       GtkWidget *selector;
+       GSList *node;
+       gchar *selected = NULL;
+       gboolean contacts_to_add = FALSE;
+
+       selector = hildon_touch_selector_new_text ();
+       g_object_ref (selector);
+
+       for (node = address_list; node != NULL; node = g_slist_next (node)) {
+               if (!modest_address_book_has_address ((const gchar *) node->data)) {
+                       hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), 
+                                                          (const gchar *) node->data);
+                       contacts_to_add = TRUE;
+               }
+       }
+
+       if (contacts_to_add) {
+               gint picker_result;
+
+               picker_dialog = hildon_picker_dialog_new (parent);
+               gtk_window_set_title (GTK_WINDOW (picker_dialog), _("mcen_me_viewer_addtocontacts"));
+
+               hildon_picker_dialog_set_selector (HILDON_PICKER_DIALOG (picker_dialog),
+                                                  HILDON_TOUCH_SELECTOR (selector));
+
+               picker_result = gtk_dialog_run (GTK_DIALOG (picker_dialog));
+
+               if (picker_result == GTK_RESPONSE_OK) {
+                       selected = hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector));
+               }
+               gtk_widget_destroy (picker_dialog);
+
+               if (selected)
+                       modest_address_book_add_address (selected, parent);
+               g_free (selected);
+
+       } else {
+               g_object_unref (selector);
+       }
+}
index 6b0f9db..25659fe 100644 (file)
@@ -3631,7 +3631,6 @@ modest_msg_view_window_add_to_contacts (ModestMsgViewWindow *self)
        priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (self);
        GSList *recipients = NULL;
        TnyMsg *msg = NULL;
        priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (self);
        GSList *recipients = NULL;
        TnyMsg *msg = NULL;
-       gboolean contacts_to_add = FALSE;
 
        msg = tny_msg_view_get_msg (TNY_MSG_VIEW (priv->msg_view));
        if (msg == NULL) {
 
        msg = tny_msg_view_get_msg (TNY_MSG_VIEW (priv->msg_view));
        if (msg == NULL) {
@@ -3647,51 +3646,11 @@ modest_msg_view_window_add_to_contacts (ModestMsgViewWindow *self)
                g_object_unref (msg);
        }
 
                g_object_unref (msg);
        }
 
-       if (recipients != NULL) {
-               GtkWidget *picker_dialog;
-               GtkWidget *selector;
-               GSList *node;
-               gchar *selected = NULL;
-
-               selector = hildon_touch_selector_new_text ();
-               g_object_ref (selector);
-
-               for (node = recipients; node != NULL; node = g_slist_next (node)) {
-                       if (!modest_address_book_has_address ((const gchar *) node->data)) {
-                               hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), 
-                                                                  (const gchar *) node->data);
-                               contacts_to_add = TRUE;
-                       }
-               }
-
-               if (contacts_to_add) {
-                       gint picker_result;
-
-                       picker_dialog = hildon_picker_dialog_new (GTK_WINDOW (self));
-                       gtk_window_set_title (GTK_WINDOW (picker_dialog), _("mcen_me_viewer_addtocontacts"));
-
-                       hildon_picker_dialog_set_selector (HILDON_PICKER_DIALOG (picker_dialog), 
-                                                          HILDON_TOUCH_SELECTOR (selector));
-                       
-                       picker_result = gtk_dialog_run (GTK_DIALOG (picker_dialog));
-
-                       if (picker_result == GTK_RESPONSE_OK) {
-                               selected = hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector));
-                       }
-                       gtk_widget_destroy (picker_dialog);
-
-                       if (selected)
-                               modest_address_book_add_address (selected, (GtkWindow *) self);
-                       g_free (selected);
-
-               } else {
-
-                       g_object_unref (selector);
-
-               }
+       if (recipients) {
+               /* Offer the user to add recipients to the address book */
+               modest_address_book_add_address_list_with_selector (recipients, (GtkWindow *) self);
+               g_slist_foreach (recipients, (GFunc) g_free, NULL); g_slist_free (recipients);
        }
        }
-       
-       if (recipients) {g_slist_foreach (recipients, (GFunc) g_free, NULL); g_slist_free (recipients);}
 }
 
 static gboolean 
 }
 
 static gboolean 
index f0d5690..8fea6fa 100644 (file)
@@ -111,4 +111,17 @@ modest_address_book_get_my_name ();
 void
 modest_address_book_add_address_list (GSList *address_list);
 
 void
 modest_address_book_add_address_list (GSList *address_list);
 
+/**
+ * modest_address_book_add_address_list_with_selector:
+ * @address_list: a list of email addresses to add to the addressbook
+ * @parent: the parent window. The UI elements shown to the user
+ * (tipically a dialog) will have that window as parent
+ *
+ * Presents some UI to the users to allow them to select and then
+ * insert a list of selected addresses in the addressbook.
+ **/
+void
+modest_address_book_add_address_list_with_selector (GSList *address_list,
+                                                   GtkWindow *parent);
+
 #endif /* __MODEST_ADDRESS_BOOK_H__ */
 #endif /* __MODEST_ADDRESS_BOOK_H__ */