X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fhildon2%2Fmodest-address-book.c;h=6964ed31d41acd1d724a71679660be4305829e7b;hb=8d4419037aad046e1587b0df5dc9acff343adaf4;hp=783c02ce6771209a666166a0e57f28a27102f4cf;hpb=c3ac189b10be518611b467d9c9f0f733748f598e;p=modest diff --git a/src/hildon2/modest-address-book.c b/src/hildon2/modest-address-book.c index 783c02c..6964ed3 100644 --- a/src/hildon2/modest-address-book.c +++ b/src/hildon2/modest-address-book.c @@ -62,7 +62,7 @@ static gchar *ui_get_formatted_email_id(gchar * current_given_name, gchar * current_sur_name, gchar * current_email_id); static gchar *run_add_email_addr_to_contact_dlg(const gchar * contact_name, gboolean *canceled); static GSList *select_email_addrs_for_contact(GList * email_addr_list); -static gboolean resolve_address (const gchar *address, GSList **resolved_addresses, gchar **contact_id, gboolean *canceled); +static gboolean resolve_address (const gchar *address, GSList **resolved_addresses, GSList **contact_id, gboolean *canceled); static gchar *unquote_string (const gchar *str); @@ -591,6 +591,7 @@ run_add_email_addr_to_contact_dlg(const gchar * contact_name, gchar *message = g_strdup_printf( _CS("ckdg_ib_illegal_characters_entered"), char_in_string); + g_free (char_in_string); hildon_banner_show_information ( add_email_addr_to_contact_dlg, NULL, message ); g_free (message); @@ -689,6 +690,8 @@ add_to_address_book (const gchar* address) err ? err->message : ""); if (err) g_error_free (err); + g_free (email); + e_book_query_unref (query); return FALSE; } e_book_query_unref (query); @@ -724,28 +727,94 @@ add_to_address_book (const gchar* address) return TRUE; } -static gboolean -show_check_names_banner (gpointer userdata) +typedef struct _CheckNamesInfo { + GtkWidget *banner; + guint show_banner_timeout; + guint hide_banner_timeout; + gboolean hide; + gboolean free_info; +} CheckNamesInfo; + +static void +hide_check_names_banner (CheckNamesInfo *info) { - GtkWidget **banner = (GtkWidget **) userdata; + if (info->show_banner_timeout > 0) { + g_source_remove (info->show_banner_timeout); + info->show_banner_timeout = 0; + } + if (info->hide_banner_timeout > 0) { + info->hide = TRUE; + return; + } + + if (info->banner) { + gtk_widget_destroy (info->banner); + info->banner = NULL; + info->hide = FALSE; + } + + if (info->free_info) { + g_slice_free (CheckNamesInfo, info); + } +} - gdk_threads_enter (); - *banner = hildon_banner_show_animation (NULL, NULL, _("mail_ib_checking_names")); - gdk_threads_leave (); +static gboolean hide_banner_timeout_handler (CheckNamesInfo *info) +{ + info->hide_banner_timeout = 0; + if (info->hide) { + gtk_widget_destroy (info->banner); + info->banner = NULL; + } + if (info->free_info) { + g_slice_free (CheckNamesInfo, info); + } + return FALSE; +} +static gboolean show_banner_timeout_handler (CheckNamesInfo *info) +{ + info->show_banner_timeout = 0; + info->banner = hildon_banner_show_animation (NULL, NULL, _("mail_ib_checking_names")); + info->hide_banner_timeout = g_timeout_add (1000, (GSourceFunc) hide_banner_timeout_handler, (gpointer) info); return FALSE; } -static void -hide_check_names_banner (GtkWidget **banner, guint banner_timeout) +static void show_check_names_banner (CheckNamesInfo *info) { - if (*banner != NULL) { - gtk_widget_destroy (*banner); - *banner = NULL; + if (info->hide_banner_timeout > 0) { + g_source_remove (info->hide_banner_timeout); + info->hide_banner_timeout = 0; + } + + info->hide = FALSE; + if (info->show_banner_timeout > 0) + return; + + if (info->banner == NULL) { + info->show_banner_timeout = g_timeout_add (500, (GSourceFunc) show_banner_timeout_handler, (gpointer) info); + } +} + +static void clean_check_names_banner (CheckNamesInfo *info) +{ + if (info->hide_banner_timeout) { + info->free_info = TRUE; } else { - g_source_remove (banner_timeout); + if (info->show_banner_timeout) { + g_source_remove (info->show_banner_timeout); + } + if (info->banner) + gtk_widget_destroy (info->banner); + g_slice_free (CheckNamesInfo, info); } +} +void free_resolved_addresses_list (gpointer data, + gpointer ignored) +{ + GSList *list = (GSList *)data; + g_slist_foreach (list, (GFunc) g_free, NULL); + g_slist_free (list); } gboolean @@ -810,20 +879,21 @@ modest_address_book_check_names (ModestRecptEditor *recpt_editor, gboolean updat } else if (strstr (address, "@") == NULL) { /* here goes searching in addressbook */ gboolean canceled; - gchar *contact_id = NULL; + GSList *contact_ids = NULL; GSList *resolved_addresses = NULL; - result = resolve_address (address, &resolved_addresses, &contact_id, &canceled); + result = resolve_address (address, &resolved_addresses, &contact_ids, &canceled); if (result) { gint new_length; - /* replace string */ - modest_recpt_editor_replace_with_resolved_recipient (recpt_editor, - &start_iter, &end_iter, - resolved_addresses, - contact_id); - g_free (contact_id); - g_slist_foreach (resolved_addresses, (GFunc) g_free, NULL); + + modest_recpt_editor_replace_with_resolved_recipients (recpt_editor, + &start_iter, &end_iter, + resolved_addresses, + contact_ids); + g_slist_foreach (contact_ids, (GFunc) g_free, NULL); + g_slist_foreach (resolved_addresses, free_resolved_addresses_list, NULL); + g_slist_free (contact_ids); g_slist_free (resolved_addresses); /* update offset delta */ @@ -987,6 +1057,9 @@ select_contacts_for_name_dialog (const gchar *name) _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_dialog), + G_MAXUINT); osso_abook_contact_chooser_set_model (OSSO_ABOOK_CONTACT_CHOOSER (contact_dialog), contact_model); @@ -1004,34 +1077,38 @@ select_contacts_for_name_dialog (const gchar *name) static gboolean resolve_address (const gchar *address, GSList **resolved_addresses, - gchar **contact_id, + GSList **contact_ids, gboolean *canceled) { GList *resolved_contacts; - guint banner_timeout; - GtkWidget *banner = NULL; + CheckNamesInfo *info;; g_return_val_if_fail (canceled, FALSE); + *resolved_addresses = NULL; + *contact_ids = NULL; *canceled = FALSE; - banner_timeout = g_timeout_add (500, show_check_names_banner, &banner); - + info = g_slice_new0 (CheckNamesInfo); + show_check_names_banner (info); + contact_model = osso_abook_contact_model_new (); if (!open_addressbook_sync ()) { - hide_check_names_banner (&banner, banner_timeout); + hide_check_names_banner (info); if (contact_model) { g_object_unref (contact_model); contact_model = NULL; } + clean_check_names_banner (info); return FALSE; } - hide_check_names_banner (&banner, banner_timeout); + hide_check_names_banner (info); resolved_contacts = get_contacts_for_name (address); if (resolved_contacts == NULL) { /* no matching contacts for the search string */ modest_platform_run_information_dialog (NULL, _("mcen_nc_no_matching_contacts"), FALSE); + clean_check_names_banner (info); return FALSE; } @@ -1040,30 +1117,36 @@ resolve_address (const gchar *address, g_list_free (resolved_contacts); resolved_contacts = select_contacts_for_name_dialog (address); - banner_timeout = g_timeout_add (500, show_check_names_banner, &banner); - } /* get the resolved contacts (can be no contact) */ if (resolved_contacts) { - gboolean found; - EContact *contact = (EContact *) resolved_contacts->data; + GList *node; + gboolean found = FALSE; - *resolved_addresses = get_recipients_for_given_contact (contact, canceled); - if (*resolved_addresses) { - *contact_id = g_strdup (e_contact_get_const (contact, E_CONTACT_UID)); - found = TRUE; - } else { - found = FALSE; + for (node = resolved_contacts; node != NULL; node = g_list_next (node)) { + EContact *contact = (EContact *) node->data; + GSList *resolved; + gchar *contact_id; + + resolved = get_recipients_for_given_contact (contact, canceled); + if (resolved) { + contact_id = g_strdup (e_contact_get_const (contact, E_CONTACT_UID)); + *contact_ids = g_slist_append (*contact_ids, contact_id); + found = TRUE; + *resolved_addresses = g_slist_append (*resolved_addresses, resolved); + } } g_list_foreach (resolved_contacts, (GFunc)unref_gobject, NULL); g_list_free (resolved_contacts); + clean_check_names_banner (info); return found; } else { /* cancelled dialog to select more than one contact or * selected no contact */ + clean_check_names_banner (info); return FALSE; } @@ -1127,6 +1210,8 @@ modest_address_book_has_address (const gchar *address) err ? err->message : ""); if (err) g_error_free (err); + g_free (email); + e_book_query_unref (query); return FALSE; } e_book_query_unref (query);