From 059f215cec94c21c941a925b521f6c4bef640550 Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Thu, 21 May 2009 18:17:58 +0200 Subject: [PATCH] Notification system now receives a list of structures with the required data for notifications instead of a list of TnyHeader --- src/gnome/modest-platform.c | 2 +- src/hildon2/modest-platform.c | 53 ++++++++++++++------------------ src/maemo/modest-platform.c | 53 ++++++++++++-------------------- src/modest-platform.h | 4 +-- src/modest-ui-actions.c | 14 +++++++-- src/modest-utils.c | 67 +++++++++++++++++++++++++++++++++++++++++ src/modest-utils.h | 8 +++++ 7 files changed, 131 insertions(+), 70 deletions(-) diff --git a/src/gnome/modest-platform.c b/src/gnome/modest-platform.c index 33493c3..58af847 100644 --- a/src/gnome/modest-platform.c +++ b/src/gnome/modest-platform.c @@ -350,7 +350,7 @@ modest_platform_push_email_notification(void) } void -modest_platform_on_new_headers_received (TnyList *header_list, +modest_platform_on_new_headers_received (GList *URI_list, gboolean show_visual) { /* TODO: implement this */ diff --git a/src/hildon2/modest-platform.c b/src/hildon2/modest-platform.c index 2f3f84f..de1b74c 100644 --- a/src/hildon2/modest-platform.c +++ b/src/hildon2/modest-platform.c @@ -1539,12 +1539,10 @@ modest_platform_push_email_notification(void) } void -modest_platform_on_new_headers_received (TnyList *header_list, +modest_platform_on_new_headers_received (GList *URI_list, gboolean show_visual) { - g_return_if_fail (TNY_IS_LIST (header_list)); - - if (tny_list_get_length (header_list) < 1) + if (g_list_length (URI_list) == 0) return; /* If the window is in the foreground don't do anything */ @@ -1554,7 +1552,7 @@ modest_platform_on_new_headers_received (TnyList *header_list, #ifdef MODEST_HAVE_HILDON_NOTIFY /* For any other case issue a notification */ HildonNotification *notification; - TnyIterator *iter; + GList *iter; GSList *notifications_list = NULL; /* Get previous notifications ids */ @@ -1562,30 +1560,26 @@ modest_platform_on_new_headers_received (TnyList *header_list, MODEST_CONF_NOTIFICATION_IDS, MODEST_CONF_VALUE_INT, NULL); - iter = tny_list_create_iterator (header_list); - while (!tny_iterator_is_done (iter)) { - gchar *url = NULL, *display_address = NULL; - TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter)); - TnyFolder *folder = tny_header_get_folder (header); + iter = URI_list; + while (iter) { + ModestMsgNotificationData *data; gboolean first_notification = TRUE; gint notif_id; - gchar *str; + gchar *from; + + data = (ModestMsgNotificationData *) iter->data; - display_address = tny_header_dup_from (header); - /* string is changed in-place */ - modest_text_utils_get_display_address (display_address); + /* String is changed in-place. There is no need to + actually dup the data->from string but we just do + it in order not to modify the original contents */ + from = g_strdup (data->from); + modest_text_utils_get_display_address (from); - str = tny_header_dup_subject (header); - notification = hildon_notification_new (display_address, - str, + notification = hildon_notification_new (from, + data->subject, "qgn_list_messagin", MODEST_NOTIFICATION_CATEGORY); - g_free (str); - /* Create the message URL */ - str = tny_header_dup_uid (header); - url = g_strdup_printf ("%s/%s", tny_folder_get_url_string (folder), - str); - g_free (str); + g_free (from); hildon_notification_add_dbus_action(notification, "default", @@ -1594,12 +1588,13 @@ modest_platform_on_new_headers_received (TnyList *header_list, MODEST_DBUS_OBJECT, MODEST_DBUS_IFACE, MODEST_DBUS_METHOD_OPEN_MESSAGE, - G_TYPE_STRING, url, + G_TYPE_STRING, data->uri, -1); /* Play sound if the user wants. Show the LED pattern. Show and play just one */ if (G_UNLIKELY (first_notification)) { + TnyAccountStore *acc_store; TnyAccount *account; first_notification = FALSE; @@ -1614,7 +1609,8 @@ modest_platform_on_new_headers_received (TnyList *header_list, "persistent", TRUE); /* Set the account of the headers */ - account = tny_folder_get_account (folder); + acc_store = (TnyAccountStore *) modest_runtime_get_account_store (); + account = tny_account_store_find_account (acc_store, data->uri); if (account) { const gchar *acc_name; acc_name = @@ -1640,13 +1636,8 @@ modest_platform_on_new_headers_received (TnyList *header_list, not to store the list in gconf */ /* Free & carry on */ - g_free (display_address); - g_free (url); - g_object_unref (folder); - g_object_unref (header); - tny_iterator_next (iter); + iter = g_list_next (iter); } - g_object_unref (iter); /* Save the ids */ modest_conf_set_list (modest_runtime_get_conf (), MODEST_CONF_NOTIFICATION_IDS, diff --git a/src/maemo/modest-platform.c b/src/maemo/modest-platform.c index c56fbdf..8df3cda 100644 --- a/src/maemo/modest-platform.c +++ b/src/maemo/modest-platform.c @@ -1215,16 +1215,12 @@ modest_platform_push_email_notification(void) } void -modest_platform_on_new_headers_received (TnyList *header_list, +modest_platform_on_new_headers_received (GList *URI_list, gboolean show_visual) { - g_return_if_fail (TNY_IS_LIST(header_list)); - - if (tny_list_get_length(header_list) == 0) { - g_warning ("%s: header list is empty", __FUNCTION__); + if (g_list_length (URI_list) == 0) return; - } - + if (!show_visual) { modest_platform_push_email_notification (); /* We do a return here to avoid indentation with an else */ @@ -1240,7 +1236,7 @@ modest_platform_on_new_headers_received (TnyList *header_list, NULL); HildonNotification *notification; - TnyIterator *iter; + GList *iter; GSList *notifications_list = NULL; /* Get previous notifications ids */ @@ -1248,35 +1244,29 @@ modest_platform_on_new_headers_received (TnyList *header_list, MODEST_CONF_NOTIFICATION_IDS, MODEST_CONF_VALUE_INT, NULL); - iter = tny_list_create_iterator (header_list); - while (!tny_iterator_is_done (iter)) { - gchar *url = NULL, *display_address = NULL, *summary = NULL; + iter = header_list; + while (iter) { + gchar *display_address = NULL, *summary = NULL; const gchar *display_date; - TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter)); - TnyFolder *folder = tny_header_get_folder (header); gboolean first_notification = TRUE; gint notif_id; gchar *str; + ModestMsgNotificationData *data; + + data = (ModestMsgNotificationData *) iter->data; /* constant string, don't free */ display_date = modest_text_utils_get_display_date (tny_header_get_date_received (header)); - display_address = tny_header_dup_from (header); + display_address = g_strdup (data->from); modest_text_utils_get_display_address (display_address); /* string is changed in-place */ - + summary = g_strdup_printf ("%s - %s", display_date, display_address); - str = tny_header_dup_subject (header); notification = hildon_notification_new (summary, - str, + data->subject, "qgn_list_messagin", "email.arrive"); - g_free (str); - /* Create the message URL */ - str = tny_header_dup_uid (header); - url = g_strdup_printf ("%s/%s", tny_folder_get_url_string (folder), - str); - g_free (str); - + /* Add DBus action */ hildon_notification_add_dbus_action(notification, "default", "Cancel", @@ -1284,7 +1274,7 @@ modest_platform_on_new_headers_received (TnyList *header_list, MODEST_DBUS_OBJECT, MODEST_DBUS_IFACE, MODEST_DBUS_METHOD_OPEN_MESSAGE, - G_TYPE_STRING, url, + G_TYPE_STRING, data->url, -1); /* Play sound if the user wants. Show the LED @@ -1301,7 +1291,7 @@ modest_platform_on_new_headers_received (TnyList *header_list, "dialog-type", 4); notify_notification_set_hint_string(NOTIFY_NOTIFICATION (notification), "led-pattern", - MODEST_NEW_MAIL_LIGHTING_PATTERN); + MODEST_NEW_MAIL_LIGHTING_PATTERN); } /* Notify. We need to do this in an idle because this function @@ -1314,23 +1304,20 @@ modest_platform_on_new_headers_received (TnyList *header_list, /* We don't listen for the "closed" signal, because we don't care about if the notification was removed or not to store the list in gconf */ - + /* Free & carry on */ g_free (display_address); g_free (summary); - g_free (url); - g_object_unref (folder); - g_object_unref (header); - tny_iterator_next (iter); + + iter = g_list_next (iter); } - g_object_unref (iter); /* Save the ids */ modest_conf_set_list (modest_runtime_get_conf (), MODEST_CONF_NOTIFICATION_IDS, notifications_list, MODEST_CONF_VALUE_INT, NULL); g_slist_free (notifications_list); - + #endif /*MODEST_HAVE_HILDON_NOTIFY*/ } diff --git a/src/modest-platform.h b/src/modest-platform.h index 36752bd..f3e5404 100644 --- a/src/modest-platform.h +++ b/src/modest-platform.h @@ -304,13 +304,13 @@ void modest_platform_push_email_notification(void); /** * modest_platform_on_new_headers_received: - * @header_list: the list of new received headers + * @header_list: a list of #ModestMsgNotificationData * @show_visual: adds a visual notification * * Performs the required actions when new headers are * received. Tipically it's useful for showing new email notifications **/ -void modest_platform_on_new_headers_received (TnyList *header_list, +void modest_platform_on_new_headers_received (GList *URI_list, gboolean show_visual); /** diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 4512dbe..12ba163 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -2230,13 +2230,21 @@ new_messages_arrived (ModestMailOperation *self, tny_list_append (actually_new_list, G_OBJECT (header)); } g_object_unref (header); - } g_object_unref (iterator); if (tny_list_get_length (actually_new_list) > 0) { - modest_platform_on_new_headers_received (actually_new_list, - show_visual_notifications); + GList *new_headers_list = NULL; + + new_headers_list = modest_utils_create_notification_list_from_header_list (actually_new_list); + + /* Send notifications */ + if (new_headers_list) { + modest_platform_on_new_headers_received (new_headers_list, + show_visual_notifications); + /* Free the list */ + modest_utils_free_notification_list (new_headers_list); + } } g_object_unref (actually_new_list); } diff --git a/src/modest-utils.c b/src/modest-utils.c index b91f6e6..5f934c1 100644 --- a/src/modest-utils.c +++ b/src/modest-utils.c @@ -1072,3 +1072,70 @@ modest_utils_fill_country_model (GtkTreeModel *model, gint *locale_mcc) MODEST_UTILS_COUNTRY_MODEL_COLUMN_NAME, GTK_SORT_ASCENDING); } +GList * +modest_utils_create_notification_list_from_header_list (TnyList *header_list) +{ + GList *new_headers_list; + TnyIterator *iter; + + g_return_val_if_fail (TNY_IS_LIST (header_list), NULL); + g_return_val_if_fail (tny_list_get_length (header_list) > 0, NULL); + + new_headers_list = NULL; + iter = tny_list_create_iterator (header_list); + while (!tny_iterator_is_done (iter)) { + ModestMsgNotificationData *data; + TnyHeader *header; + TnyFolder *folder; + + header = (TnyHeader *) tny_iterator_get_current (iter); + if (header) { + folder = tny_header_get_folder (header); + + if (folder) { + gchar *uri, *uid; + + uid = tny_header_dup_uid (header); + uri = g_strdup_printf ("%s/%s", + tny_folder_get_url_string (folder), + uid); + g_free (uid); + + /* Create data & add to list */ + data = g_slice_new0 (ModestMsgNotificationData); + data->subject = tny_header_dup_subject (header); + data->from = tny_header_dup_from (header); + data->uri = uri; + + new_headers_list = g_list_append (new_headers_list, data); + + g_object_unref (folder); + } + g_object_unref (header); + } + tny_iterator_next (iter); + } + g_object_unref (iter); + + return new_headers_list; +} + +static void +free_notification_data (gpointer data, + gpointer user_data) +{ + ModestMsgNotificationData *notification_data = (ModestMsgNotificationData *) data; + + g_free (notification_data->from); + g_free (notification_data->subject); + g_free (notification_data->uri); +} + +void +modest_utils_free_notification_list (GList *notification_list) +{ + g_return_if_fail (g_list_length (notification_list) > 0); + + g_list_foreach (notification_list, free_notification_data, NULL); + g_list_free (notification_list); +} diff --git a/src/modest-utils.h b/src/modest-utils.h index 7f377df..fe20265 100644 --- a/src/modest-utils.h +++ b/src/modest-utils.h @@ -45,6 +45,12 @@ typedef enum _ModestSortDialogType { MODEST_SORT_HEADERS, } ModestSortDialogType; +typedef struct _ModestMsgNotificationData { + gchar *subject; + gchar *from; + gchar *uri; +} ModestMsgNotificationData; + GQuark modest_utils_get_supported_secure_authentication_error_quark (void); @@ -229,6 +235,8 @@ GtkTreeModel *modest_utils_create_country_model (void); */ void modest_utils_fill_country_model (GtkTreeModel *model, gint *locale_mcc); +GList *modest_utils_create_notification_list_from_header_list (TnyList *header_list); +void modest_utils_free_notification_list (GList *notification_list); #endif /*__MODEST_MAEMO_UTILS_H__*/ -- 1.7.9.5