}
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 */
}
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 */
#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 */
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",
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;
"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 =
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,
}
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 */
NULL);
HildonNotification *notification;
- TnyIterator *iter;
+ GList *iter;
GSList *notifications_list = NULL;
/* Get previous notifications ids */
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",
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
"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
/* 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*/
}
/**
* 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);
/**
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);
}
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);
+}
MODEST_SORT_HEADERS,
} ModestSortDialogType;
+typedef struct _ModestMsgNotificationData {
+ gchar *subject;
+ gchar *from;
+ gchar *uri;
+} ModestMsgNotificationData;
+
GQuark modest_utils_get_supported_secure_authentication_error_quark (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__*/