X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fhildon2%2Fmodest-address-book.c;h=c1360bca42d672cbe957861de623a19ccdd78a19;hp=845f28ead569c21f1b006cf460385a0426f0cce7;hb=83cfbd96aa351d1ffc91d409cacb26ad1ec7df2d;hpb=7b9ad54259c83315032c080f05c90366c24235d7 diff --git a/src/hildon2/modest-address-book.c b/src/hildon2/modest-address-book.c index 845f28e..c1360bc 100644 --- a/src/hildon2/modest-address-book.c +++ b/src/hildon2/modest-address-book.c @@ -35,8 +35,9 @@ #include #include #include -#include +#include #include "modest-hildon-includes.h" +#include #include "modest-platform.h" #include "modest-runtime.h" #include "widgets/modest-window-mgr.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); } @@ -200,7 +190,6 @@ modest_address_book_select_addresses (ModestRecptEditor *recpt_editor) osso_abook_contact_selector_set_minimum_selection (OSSO_ABOOK_CONTACT_SELECTOR (contact_view), 1); 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 (GTK_WIDGET (recpt_editor)); modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (contact_dialog), GTK_WINDOW (toplevel)); @@ -214,17 +203,18 @@ 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_with_capabilities (NULL, - _("mcen_ti_select_recipients"), + _AB("addr_ti_dia_select_contacts"), OSSO_ABOOK_CAPS_EMAIL, OSSO_ABOOK_CONTACT_ORDER_NAME); + /* Enable multiselection */ + osso_abook_contact_chooser_set_maximum_selection (OSSO_ABOOK_CONTACT_CHOOSER (contact_chooser), + G_MAXUINT); 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 - + if (contacts_list) { GList *node; @@ -375,14 +365,21 @@ commit_contact(EContact * contact, gboolean is_new) { g_return_if_fail (contact); g_return_if_fail (book); - + if (!contact || !book) return; - -#if MODEST_ABOOK_API < 2 + +#if MODEST_ABOOK_API < 4 osso_abook_contact_commit(contact, is_new, book); #else - osso_abook_contact_commit(contact, is_new, book, NULL); + if (OSSO_ABOOK_IS_CONTACT (contact)) { + osso_abook_contact_commit(OSSO_ABOOK_CONTACT(contact), is_new, book, NULL); + } else { + if (is_new) + e_book_add_contact (book, contact, NULL); + else + e_book_commit_contact (book, contact, NULL); + } #endif /* MODEST_ABOOK_API < 2 */ } @@ -473,8 +470,7 @@ run_add_email_addr_to_contact_dlg(const gchar * contact_name) add_email_addr_to_contact_dlg = gtk_dialog_new_with_buttons(_("mcen_ti_add_email_title"), NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - _("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT, - _("mcen_bd_dialog_cancel"), GTK_RESPONSE_REJECT, NULL); + _HL("wdgt_bd_done"), GTK_RESPONSE_ACCEPT, NULL); gtk_dialog_set_has_separator(GTK_DIALOG(add_email_addr_to_contact_dlg), FALSE); /*Set app_name & state_save related tags to the window */ @@ -511,7 +507,7 @@ run_add_email_addr_to_contact_dlg(const gchar * contact_name) if ((invalid_char_offset != NULL)&&(*invalid_char_offset != '\0')) { gchar *char_in_string = g_strdup_printf ("%c", *invalid_char_offset); gchar *message = g_strdup_printf( - dgettext("hildon-common-strings", "ckdg_ib_illegal_characters_entered"), + _CS("ckdg_ib_illegal_characters_entered"), char_in_string); hildon_banner_show_information ( add_email_addr_to_contact_dlg, NULL, message ); @@ -563,8 +559,7 @@ select_email_addrs_for_contact(GList * email_addr_list) gtk_dialog_new_with_buttons(_("mcen_ti_select_email_title"), NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - _("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT, - _("mcen_bd_dialog_cancel"), GTK_RESPONSE_REJECT, NULL); + _HL("wdgt_bd_done"), GTK_RESPONSE_ACCEPT, NULL); gtk_dialog_set_has_separator(GTK_DIALOG(select_email_addr_dlg), FALSE); /* Make the window approximately big enough, because it doesn't resize to be big enough @@ -758,9 +753,9 @@ modest_address_book_check_names (ModestRecptEditor *recpt_editor, gboolean updat if (!modest_text_utils_validate_recipient (address, &invalid_char_position)) { if ((invalid_char_position != NULL) && (*invalid_char_position != '\0')) { gchar *char_in_string = g_strdup_printf("%c", *invalid_char_position); - gchar *message = g_strdup_printf( - dgettext("hildon-common-strings", "ckdg_ib_illegal_characters_entered"), - char_in_string); + gchar *message = + g_strdup_printf(_CS("ckdg_ib_illegal_characters_entered"), + char_in_string); g_free (char_in_string); hildon_banner_show_information (NULL, NULL, message ); g_free (message); @@ -883,18 +878,14 @@ select_contacts_for_name_dialog (const gchar *name) e_book_query_unref (full_name_book_query); if (book_view) { - GtkWidget *contact_view = NULL; GtkWidget *contact_dialog = NULL; #if MODEST_ABOOK_API < 4 + GtkWidget *contact_view = NULL; osso_abook_tree_model_set_book_view (OSSO_ABOOK_TREE_MODEL (contact_model), book_view); -#else /* MODEST_ABOOK_API < 4 */ - osso_abook_list_store_set_book_view (OSSO_ABOOK_LIST_STORE (contact_model), book_view); -#endif /* MODEST_ABOOK_API < 4 */ e_book_view_start (book_view); - + contact_view = osso_abook_contact_selector_new_basic (contact_model); 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")); if (gtk_dialog_run (GTK_DIALOG (contact_dialog)) == GTK_RESPONSE_OK) { result = osso_abook_contact_view_get_selection (OSSO_ABOOK_CONTACT_VIEW (contact_view)); @@ -902,6 +893,24 @@ select_contacts_for_name_dialog (const gchar *name) e_book_view_stop (book_view); g_object_unref (book_view); gtk_widget_destroy (contact_dialog); +#else /* MODEST_ABOOK_API < 4 */ + osso_abook_list_store_set_book_view (OSSO_ABOOK_LIST_STORE (contact_model), book_view); + e_book_view_start (book_view); + + /* TODO: figure out how to make the contact chooser modal */ + contact_dialog = osso_abook_contact_chooser_new_with_capabilities (NULL, + _AB("addr_ti_dia_select_contacts"), + OSSO_ABOOK_CAPS_EMAIL, + OSSO_ABOOK_CONTACT_ORDER_NAME); + osso_abook_contact_chooser_set_model (OSSO_ABOOK_CONTACT_CHOOSER (contact_dialog), + contact_model); + + if (gtk_dialog_run (GTK_DIALOG (contact_dialog)) == GTK_RESPONSE_OK) + result = osso_abook_contact_chooser_get_selection (OSSO_ABOOK_CONTACT_CHOOSER (contact_dialog)); + e_book_view_stop (book_view); + g_object_unref (book_view); + gtk_widget_destroy (contact_dialog); +#endif /* MODEST_ABOOK_API < 4 */ } return result; @@ -913,7 +922,7 @@ resolve_address (const gchar *address, GSList **resolved_addresses, gchar **cont GList *resolved_contacts; guint banner_timeout; GtkWidget *banner = NULL; - + banner_timeout = g_timeout_add (500, show_check_names_banner, &banner); contact_model = osso_abook_contact_model_new (); @@ -1002,3 +1011,45 @@ unquote_string (const gchar *str) return g_string_free (buffer, FALSE); } + +gboolean +modest_address_book_has_address (const gchar *address) +{ + EBookQuery *query; + GList *contacts = NULL; + GError *err = NULL; + gchar *email; + gboolean result; + + g_return_val_if_fail (address, FALSE); + + if (!book) { + if (!open_addressbook ()) { + g_return_val_if_reached (FALSE); + } + } + + g_return_val_if_fail (book, FALSE); + + email = modest_text_utils_get_email_address (address); + + query = e_book_query_field_test (E_CONTACT_EMAIL, E_BOOK_QUERY_IS, email); + if (!e_book_get_contacts (book, query, &contacts, &err)) { + g_printerr ("modest: failed to get contacts: %s", + err ? err->message : ""); + if (err) + g_error_free (err); + return FALSE; + } + e_book_query_unref (query); + + result = (contacts != NULL); + if (contacts) { + g_list_foreach (contacts, (GFunc)unref_gobject, NULL); + g_list_free (contacts); + } + + g_free (email); + + return result; +}