X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmaemo%2Fmodest-platform.c;h=d848149c278e94b29f44ec185a2d0f4deedb351d;hp=9b0e49893174eda15aa14110ebba52a747eba8a7;hb=51ee3dbf9a9338a7683fb2efe9daeefb316849bd;hpb=560ace2e328a05c336b746733799bdecb37c3b42 diff --git a/src/maemo/modest-platform.c b/src/maemo/modest-platform.c index 9b0e498..d848149 100644 --- a/src/maemo/modest-platform.c +++ b/src/maemo/modest-platform.c @@ -36,7 +36,6 @@ #include "maemo/modest-maemo-global-settings-dialog.h" #include "modest-widget-memory.h" #include -#include #include #include #include @@ -60,6 +59,11 @@ #define HILDON_OSSO_URI_ACTION "uri-action" #define URI_ACTION_COPY "copy:" +/* The maximun number of notifications that could be shown in the + desktop. It's specified by the specs and limited by the screen + size */ +#define MAX_NOTIFICATIONS 6 + static osso_context_t *osso_context = NULL; static void @@ -1216,71 +1220,149 @@ modest_platform_set_update_interval (guint minutes) return TRUE; } -GtkWidget * -modest_platform_get_global_settings_dialog () -{ - return modest_maemo_global_settings_dialog_new (); -} - void -modest_platform_on_new_header_received (TnyHeader *header) +modest_platform_on_new_headers_received (TnyList *header_list) { #ifdef MODEST_HAVE_HILDON_NOTIFY HildonNotification *notification; - gchar *url = NULL; - TnyFolder *folder = NULL; - const gchar *subject; - - subject = tny_header_get_subject (header); - if (!subject || strlen(subject) == 0) - subject = _("mail_va_no_subject"); + TnyIterator *iter; + GSList *notifications_list = NULL; + + /* Get previous notifications ids */ + notifications_list = modest_conf_get_list (modest_runtime_get_conf (), + 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, *display_date = NULL, *summary = NULL; + TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter)); + TnyFolder *folder = tny_header_get_folder (header); + gboolean first_notification = TRUE; + gint notif_id; - notification = hildon_notification_new (tny_header_get_from (header), - subject, - "qgn_list_messagin", - NULL); - - folder = tny_header_get_folder (header); - url = g_strdup_printf ("%s/%s", - tny_folder_get_url_string (folder), - tny_header_get_uid (header)); - g_object_unref (folder); - - hildon_notification_add_dbus_action(notification, - "default", - "Cancel", - MODEST_DBUS_SERVICE, - MODEST_DBUS_OBJECT, - MODEST_DBUS_IFACE, - MODEST_DBUS_METHOD_OPEN_MESSAGE, - G_TYPE_STRING, url, - -1); - g_free (url); + display_date = modest_text_utils_get_display_date (tny_header_get_date_received (header)); + + display_address = g_strdup(tny_header_get_from (header)); + modest_text_utils_get_display_address (display_address); /* string is changed in-place */ + + summary = g_strdup_printf ("%s - %s", display_date, display_address); + notification = hildon_notification_new (summary, + tny_header_get_subject (header), + "qgn_list_messagin", + "email.arrive"); + + /* Create the message URL */ + url = g_strdup_printf ("%s/%s", tny_folder_get_url_string (folder), + tny_header_get_uid (header)); + + hildon_notification_add_dbus_action(notification, + "default", + "Cancel", + MODEST_DBUS_SERVICE, + MODEST_DBUS_OBJECT, + MODEST_DBUS_IFACE, + MODEST_DBUS_METHOD_OPEN_MESSAGE, + G_TYPE_STRING, url, + -1); + + /* Play sound if the user wants. Show the LED + pattern. Show and play just one */ + if (G_UNLIKELY (first_notification)) { + first_notification = FALSE; + if (modest_conf_get_bool (modest_runtime_get_conf (), + MODEST_CONF_PLAY_SOUND_MSG_ARRIVE, + NULL)) { + notify_notification_set_hint_string(NOTIFY_NOTIFICATION (notification), + "sound-file", "/usr/share/sounds/ui-new_email.wav"); + } + + /* Set the led pattern */ + notify_notification_set_hint_int32 (NOTIFY_NOTIFICATION (notification), + "dialog-type", 4); + notify_notification_set_hint_string(NOTIFY_NOTIFICATION (notification), + "led-pattern", + "PatternCommunicationEmail"); + } + + /* Notify. We need to do this in an idle because this function + could be called from a thread */ + notify_notification_show (NOTIFY_NOTIFICATION (notification), NULL); + + /* Save id in the list */ + g_object_get(G_OBJECT(notification), "id", ¬if_id, NULL); + notifications_list = g_slist_prepend (notifications_list, GINT_TO_POINTER(notif_id)); + /* 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 */ - /* Play sound if the user wants */ - if (modest_conf_get_bool (modest_runtime_get_conf (), - MODEST_CONF_PLAY_SOUND_MSG_ARRIVE, - NULL)) { - hildon_notification_set_sound (HILDON_NOTIFICATION(notification), - "/usr/share/sounds/ui-new_email.wav"); + /* Free & carry on */ + g_free (display_date); + g_free (display_address); + g_free (summary); + g_free (url); + g_object_unref (folder); + g_object_unref (header); + tny_iterator_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); - /* Set the led pattern */ - notify_notification_set_hint_int32 (NOTIFY_NOTIFICATION(notification), - "dialog-type", 4); - notify_notification_set_hint_string(NOTIFY_NOTIFICATION(notification), - "led-pattern", - "PatternCommunicationEmail"); - - /* Notify. We need to do this in an idle because this function - could be called from a thread */ - if (!notify_notification_show (NOTIFY_NOTIFICATION(notification), NULL)) - g_error ("Failed to send notification"); - - g_object_unref (notification); #endif /*MODEST_HAVE_HILDON_NOTIFY*/ } +void +modest_platform_remove_new_mail_notifications (void) +{ +#ifdef MODEST_HAVE_HILDON_NOTIFY + GSList *notif_list = NULL; + + /* Get previous notifications ids */ + notif_list = modest_conf_get_list (modest_runtime_get_conf (), + MODEST_CONF_NOTIFICATION_IDS, + MODEST_CONF_VALUE_INT, NULL); + + while (notif_list) { + gint notif_id; + NotifyNotification *notif; + + /* Nasty HACK to remove the notifications, set the id + of the existing ones and then close them */ + notif_id = GPOINTER_TO_INT(notif_list->data); + notif = notify_notification_new("dummy", NULL, NULL, NULL); + g_object_set(G_OBJECT(notif), "id", notif_id, NULL); + + /* Close the notification, note that some ids could be + already invalid, but we don't care because it does + not fail */ + notify_notification_close(notif, NULL); + g_object_unref(notif); + + /* Delete the link, it's like going to the next */ + notif_list = g_slist_delete_link (notif_list, notif_list); + } + + /* Save the ids */ + modest_conf_set_list (modest_runtime_get_conf (), MODEST_CONF_NOTIFICATION_IDS, + notif_list, MODEST_CONF_VALUE_INT, NULL); + + g_slist_free (notif_list); + +#endif /* MODEST_HAVE_HILDON_NOTIFY */ +} + + + +GtkWidget * +modest_platform_get_global_settings_dialog () +{ + return modest_maemo_global_settings_dialog_new (); +} void modest_platform_show_help (GtkWindow *parent_window, @@ -1291,12 +1373,7 @@ modest_platform_show_help (GtkWindow *parent_window, g_return_if_fail (help_id); g_return_if_fail (osso_context); - /* Show help */ -#ifdef MODEST_HAVE_OSSO_HELP - result = ossohelp_show (osso_context, help_id, OSSO_HELP_SHOW_DIALOG); -#else - result = hildon_help_show (osso_context, help_id, OSSO_HELP_SHOW_DIALOG); -#endif + result = hildon_help_show (osso_context, help_id, HILDON_HELP_SHOW_DIALOG); if (result != OSSO_OK) { gchar *error_msg; @@ -1317,12 +1394,7 @@ modest_platform_set_dialog_help (GtkDialog *parent_window, g_return_if_fail (osso_context); g_return_if_fail (GTK_IS_DIALOG (parent_window)); - /* Show help */ -#ifdef MODEST_HAVE_OSSO_HELP - result = ossohelp_dialog_help_enable (parent_window, help_id, osso_context); -#else result = hildon_help_dialog_help_enable (parent_window, help_id, osso_context); -#endif if (!result) g_warning ("Help topic %s not found", help_id);