Use the new temporary contact dialog for adding addresses to abook
[modest] / src / hildon2 / modest-address-book.c
index 17c95d9..bb26fc2 100644 (file)
@@ -35,6 +35,7 @@
 #include <modest-text-utils.h>
 #include <libebook/e-book.h>
 #include <libebook/e-book-view.h>
+#include <libebook/e-vcard.h>
 #include <libosso-abook/osso-abook.h>
 #include "modest-hildon-includes.h"
 #include "modest-platform.h"
@@ -135,36 +136,25 @@ open_addressbook_sync ()
 void
 modest_address_book_add_address (const gchar *address)
 {
-       OssoABookAccount *account = NULL;
        GtkWidget *dialog = NULL;
-       gchar *email_address = NULL;
+       gchar *email_address;
+       EVCardAttribute *attribute;
 
-       contact_model = osso_abook_contact_model_new ();
        if (!open_addressbook ()) {
-               if (contact_model) {
-                       g_object_unref (contact_model);
-                       contact_model = NULL;
-               }
                return;
        }
 
        email_address = modest_text_utils_get_email_address (address);
        
-       account = osso_abook_account_get (EVC_EMAIL, NULL, email_address);
-       g_free (email_address);
-       if (account)
-       {
-               dialog = osso_abook_add_to_contacts_dialog_new (contact_model, account);
-               g_object_unref (account);
-               gtk_dialog_run (GTK_DIALOG (dialog));
+       attribute = e_vcard_attribute_new (NULL, EVC_EMAIL);
+       e_vcard_attribute_add_value (attribute, email_address);
+       dialog = osso_abook_temporary_contact_dialog_new (NULL, book, attribute, NULL);
+       gtk_dialog_run (GTK_DIALOG (dialog));
 
-               if (contact_model) {
-                       g_object_unref (contact_model);
-                       contact_model = NULL;
-               }
+       gtk_widget_destroy (dialog);
 
-               gtk_widget_destroy (dialog);
-       }
+       e_vcard_attribute_free (attribute);
+       g_free (email_address);
 
 }
 
@@ -176,7 +166,7 @@ modest_address_book_select_addresses (ModestRecptEditor *recpt_editor)
        GtkWidget *contact_dialog;
        GtkWidget *toplevel;
 #else /* MODEST_ABOOK_API < 4 */
-       OssoABookContactChooser *contact_chooser = NULL;
+       GtkWidget *contact_chooser = NULL;
 #endif /* MODEST_ABOOK_API < 4 */
 
        GList *contacts_list = NULL;
@@ -201,8 +191,8 @@ modest_address_book_select_addresses (ModestRecptEditor *recpt_editor)
 
        contact_dialog = osso_abook_select_dialog_new (OSSO_ABOOK_TREE_VIEW (contact_view));
        gtk_window_set_title (GTK_WINDOW (contact_dialog), _("mcen_ti_select_recipients"));
-       toplevel = gtk_widget_get_toplevel (recpt_editor);
-       modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (contact_dialog), toplevel);
+       toplevel = gtk_widget_get_toplevel (GTK_WIDGET (recpt_editor));
+       modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (contact_dialog), GTK_WINDOW (toplevel));
 
        gtk_widget_show (contact_dialog);
 
@@ -213,13 +203,14 @@ modest_address_book_select_addresses (ModestRecptEditor *recpt_editor)
        }
 #else /* MODEST_ABOOK_API < 4 */
        /* TODO: figure out how to make the contact chooser modal */
-       contact_chooser = osso_abook_contact_chooser_new
-               ("title", _("mcen_ti_select_recipients"),
-                "help-topic", "",
-                "minimum-selection", 1, NULL);
+       contact_chooser = osso_abook_contact_chooser_new_with_capabilities (NULL,
+                                                                           _("mcen_ti_select_recipients"),
+                                                                           OSSO_ABOOK_CAPS_EMAIL, 
+                                                                           OSSO_ABOOK_CONTACT_ORDER_NAME);
 
-       if (osso_abook_contact_chooser_run (contact_chooser) == GTK_RESPONSE_OK)
-               contacts_list = osso_abook_contact_chooser_get_selection (contact_chooser);
+       if (gtk_dialog_run (GTK_DIALOG (contact_chooser)) == GTK_RESPONSE_OK)
+               contacts_list = osso_abook_contact_chooser_get_selection (OSSO_ABOOK_CONTACT_CHOOSER (contact_chooser));
+       gtk_widget_destroy (contact_chooser);
 
        g_object_unref (contact_chooser);
 #endif
@@ -316,7 +307,6 @@ static GSList *get_recipients_for_given_contact(EContact * contact)
               
                abook_contact = osso_abook_contact_new_from_template (contact);
                display_name = osso_abook_contact_get_display_name(abook_contact);
-               g_object_unref (abook_contact);
 #endif
 
                emailid = get_email_addr_from_user(display_name);
@@ -324,6 +314,9 @@ static GSList *get_recipients_for_given_contact(EContact * contact)
                        e_contact_set(contact, E_CONTACT_EMAIL_1, emailid);
                        commit_contact(contact, FALSE);
                }
+#if MODEST_ABOOK_API >= 4
+               g_object_unref (abook_contact);
+#endif
        }
 
        if (emailid) {