From 6cfc86073c3ad33565a50c70fce034e9b3fb0a96 Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Tue, 18 Dec 2007 15:00:28 +0000 Subject: [PATCH 1/1] * Fixes NB#78357, new mail sound is played now with IMAP IDLE events pmo-trunk-r3936 --- src/gnome/modest-main-window.c | 7 ++++ src/gnome/modest-platform.c | 5 ++- src/maemo/modest-main-window.c | 67 +++++++++++++++++++++++----------- src/maemo/modest-platform.c | 75 +++++++++++++++++++++++++++++++++----- src/modest-main.c | 5 +-- src/modest-platform.h | 7 +++- src/modest-ui-actions.c | 18 +++++---- src/widgets/modest-main-window.h | 5 ++- 8 files changed, 141 insertions(+), 48 deletions(-) diff --git a/src/gnome/modest-main-window.c b/src/gnome/modest-main-window.c index 4491577..0030755 100644 --- a/src/gnome/modest-main-window.c +++ b/src/gnome/modest-main-window.c @@ -793,3 +793,10 @@ modest_main_window_on_msg_view_window_msg_changed (ModestMsgViewWindow *view_win g_message("NOT IMPLEMENTED %s", __FUNCTION__); return FALSE; } + +gboolean +modest_main_window_screen_is_on (ModestMainWindow *self) +{ + g_message("NOT IMPLEMENTED %s", __FUNCTION__); + return TRUE; +} diff --git a/src/gnome/modest-platform.c b/src/gnome/modest-platform.c index e5cf17f..dc4c4c8 100644 --- a/src/gnome/modest-platform.c +++ b/src/gnome/modest-platform.c @@ -322,7 +322,8 @@ modest_platform_get_global_settings_dialog () void -modest_platform_on_new_headers_received (TnyList *header_list) +modest_platform_on_new_headers_received (TnyList *header_list, + gboolean show_visual) { /* TODO: implement this */ g_print ("--------------- NEW MESSAGE ARRIVED ---------------\n"); @@ -421,7 +422,7 @@ modest_platform_connect_and_perform_if_network_folderstore (GtkWindow *parent_wi void -modest_platform_remove_new_mail_notifications (void) +modest_platform_remove_new_mail_notifications (gboolean only_visuals) { g_message ("NOT IMPLEMENTED %s", __FUNCTION__); } diff --git a/src/maemo/modest-main-window.c b/src/maemo/modest-main-window.c index e2f62b1..37d22ba 100644 --- a/src/maemo/modest-main-window.c +++ b/src/maemo/modest-main-window.c @@ -225,6 +225,9 @@ struct _ModestMainWindowPrivate { /* "Updating" banner for header view */ GtkWidget *updating_banner; guint updating_banner_timeout; + + /* Display state */ + osso_display_state_t display_state; }; #define MODEST_MAIN_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ MODEST_TYPE_MAIN_WINDOW, \ @@ -351,6 +354,7 @@ modest_main_window_init (ModestMainWindow *obj) priv->sighandlers = NULL; priv->updating_banner = NULL; priv->updating_banner_timeout = 0; + priv->display_state = OSSO_DISPLAY_ON; modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(), GTK_WINDOW(obj), @@ -985,26 +989,13 @@ connect_signals (ModestMainWindow *self) self); } -#if 0 -/** Idle handler, to send/receive at startup .*/ -gboolean -sync_accounts_cb (ModestMainWindow *win) -{ - modest_ui_actions_do_send_receive (NULL, MODEST_WINDOW (win)); - return FALSE; /* Do not call this idle handler again. */ -} -#endif - static void on_hildon_program_is_topmost_notify(GObject *self, - GParamSpec *propert_param, gpointer user_data) + GParamSpec *propert_param, + gpointer user_data) { HildonProgram *app = HILDON_PROGRAM (self); - /* - ModestWindow* self = MODEST_WINDOW(user_data); - */ - /* Note that use of hildon_program_set_can_hibernate() * is generally referred to as "setting the killable flag", * though hibernation does not seem equal to death. @@ -1015,13 +1006,16 @@ on_hildon_program_is_topmost_notify(GObject *self, * because hibernation should only happen when the application * is in the background: */ hildon_program_set_can_hibernate (app, FALSE); + + /* Remove new mail visual notifications */ + modest_platform_remove_new_mail_notifications (TRUE); } else { /* Allow hibernation if the program has gone to the background: */ /* However, prevent hibernation while the settings are being changed: */ const gboolean hibernation_prevented = modest_window_mgr_get_hibernation_is_prevented ( - modest_runtime_get_window_mgr ()); + modest_runtime_get_window_mgr ()); if (hibernation_prevented) hildon_program_set_can_hibernate (app, FALSE); @@ -1030,8 +1024,7 @@ on_hildon_program_is_topmost_notify(GObject *self, modest_osso_save_state(); hildon_program_set_can_hibernate (app, TRUE); } - } - + } } static void @@ -1081,6 +1074,19 @@ modest_main_window_on_show (GtkWidget *self, gpointer user_data) } } +static void +osso_display_event_cb (osso_display_state_t state, + gpointer data) +{ + ModestMainWindowPrivate *priv = MODEST_MAIN_WINDOW_GET_PRIVATE (data); + + priv->display_state = state; + + /* Stop blinking if the screen becomes on */ + if (priv->display_state == OSSO_DISPLAY_ON) + modest_platform_remove_new_mail_notifications (TRUE); +} + ModestWindow * modest_main_window_new (void) { @@ -1244,12 +1250,17 @@ modest_main_window_new (void) g_object_unref (window_icon); } + /* Listen for changes in the screen, we don't want to show a + led pattern when the display is on for example */ + osso_hw_set_display_event_cb (modest_maemo_utils_get_osso_context (), + osso_display_event_cb, + self); + /* Dont't restore settings here, * because it requires a gtk_widget_show(), * and we don't want to do that until later, * so that the UI is not visible for non-menu D-Bus activation. */ - /* restore_settings (MODEST_MAIN_WINDOW(self), FALSE); */ return MODEST_WINDOW(self); } @@ -1856,8 +1867,12 @@ on_msg_count_changed (ModestHeaderView *header_view, folder_empty = (tny_folder_change_get_new_all_count (change) == 0); else folder_empty = (tny_folder_get_all_count (TNY_FOLDER (folder)) == 0); + + /* Play a sound (if configured) and make the LED blink */ + if (changed & TNY_FOLDER_CHANGE_CHANGED_ADDED_HEADERS) + modest_platform_on_new_headers_received (NULL, FALSE); -/* Check header removed (hide marked as DELETED headers) */ + /* Check header removed (hide marked as DELETED headers) */ if (changed & TNY_FOLDER_CHANGE_CHANGED_EXPUNGED_HEADERS) { modest_header_view_refilter (MODEST_HEADER_VIEW(priv->header_view)); } @@ -1875,7 +1890,7 @@ on_msg_count_changed (ModestHeaderView *header_view, else { modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS); - } + } } @@ -2624,3 +2639,13 @@ on_updating_msg_list (ModestHeaderView *header_view, } } } + +gboolean +modest_main_window_screen_is_on (ModestMainWindow *self) +{ + ModestMainWindowPrivate *priv = NULL; + + priv = MODEST_MAIN_WINDOW_GET_PRIVATE (self); + + return (priv->display_state == OSSO_DISPLAY_ON) ? TRUE : FALSE; +} diff --git a/src/maemo/modest-platform.c b/src/maemo/modest-platform.c index 9062649..8b0f3b5 100644 --- a/src/maemo/modest-platform.c +++ b/src/maemo/modest-platform.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +56,7 @@ #include #include #include +#include #ifdef MODEST_HAVE_ABOOK #include @@ -67,6 +69,8 @@ #define HILDON_OSSO_URI_ACTION "uri-action" #define URI_ACTION_COPY "copy:" +#define MODEST_NEW_MAIL_SOUND_FILE "/usr/share/sounds/ui-new_email.wav" +#define MODEST_NEW_MAIL_LIGHTING_PATTERN "PatternCommunicationEmail" static void on_modest_conf_update_interval_changed (ModestConf* self, @@ -1329,8 +1333,49 @@ modest_platform_set_update_interval (guint minutes) } void -modest_platform_on_new_headers_received (TnyList *header_list) +modest_platform_on_new_headers_received (TnyList *header_list, + gboolean show_visual) { + gboolean play_sound; + + /* Check whether or not we should play a sound */ + play_sound = modest_conf_get_bool (modest_runtime_get_conf (), + MODEST_CONF_PLAY_SOUND_MSG_ARRIVE, + NULL); + + if (!show_visual) { + gboolean screen_on, app_in_foreground; + ModestWindow *main_window; + + /* Get the screen status */ + main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (), FALSE); + screen_on = modest_main_window_screen_is_on (MODEST_MAIN_WINDOW (main_window)); + + /* Get the window status */ + app_in_foreground = hildon_program_get_is_topmost (hildon_program_get_instance ()); + + /* If the screen is on and the app is in the + foreground we don't show anything */ + if (!(screen_on && app_in_foreground)) { + /* Play a sound */ + if (play_sound) + hildon_play_system_sound (MODEST_NEW_MAIL_SOUND_FILE); + + /* Activate LED. This must be deactivated by + modest_platform_remove_new_mail_notifications */ + osso_rpc_run_system (modest_maemo_utils_get_osso_context (), + MCE_SERVICE, + MCE_REQUEST_PATH, + MCE_REQUEST_IF, + MCE_ACTIVATE_LED_PATTERN, + NULL, + DBUS_TYPE_STRING, MODEST_NEW_MAIL_LIGHTING_PATTERN, + DBUS_TYPE_INVALID); + } + /* We do a return here to avoid indentation with an else */ + return; + } + #ifdef MODEST_HAVE_HILDON_NOTIFY HildonNotification *notification; TnyIterator *iter; @@ -1379,11 +1424,9 @@ modest_platform_on_new_headers_received (TnyList *header_list) 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)) { + if (play_sound) { notify_notification_set_hint_string(NOTIFY_NOTIFICATION (notification), - "sound-file", "/usr/share/sounds/ui-new_email.wav"); + "sound-file", MODEST_NEW_MAIL_SOUND_FILE); } /* Set the led pattern */ @@ -1391,7 +1434,7 @@ modest_platform_on_new_headers_received (TnyList *header_list) "dialog-type", 4); notify_notification_set_hint_string(NOTIFY_NOTIFICATION (notification), "led-pattern", - "PatternCommunicationEmail"); + MODEST_NEW_MAIL_LIGHTING_PATTERN); } /* Notify. We need to do this in an idle because this function @@ -1425,8 +1468,20 @@ modest_platform_on_new_headers_received (TnyList *header_list) } void -modest_platform_remove_new_mail_notifications (void) +modest_platform_remove_new_mail_notifications (gboolean only_visuals) { + if (only_visuals) { + osso_rpc_run_system (modest_maemo_utils_get_osso_context (), + MCE_SERVICE, + MCE_REQUEST_PATH, + MCE_REQUEST_IF, + MCE_DEACTIVATE_LED_PATTERN, + NULL, + DBUS_TYPE_STRING, MODEST_NEW_MAIL_LIGHTING_PATTERN, + DBUS_TYPE_INVALID); + return; + } + #ifdef MODEST_HAVE_HILDON_NOTIFY GSList *notif_list = NULL; @@ -2003,9 +2058,9 @@ modest_platform_connect_and_perform (GtkWindow *parent_window, void modest_platform_connect_if_remote_and_perform (GtkWindow *parent_window, - TnyFolderStore *folder_store, - ModestConnectedPerformer callback, - gpointer user_data) + TnyFolderStore *folder_store, + ModestConnectedPerformer callback, + gpointer user_data) { TnyAccount *account = NULL; diff --git a/src/modest-main.c b/src/modest-main.c index 7e5f319..10df9ed 100644 --- a/src/modest-main.c +++ b/src/modest-main.c @@ -152,7 +152,7 @@ main (int argc, char *argv[]) gtk_widget_show_all (GTK_WIDGET(main_win)); /* Remove new mail notifications if exist */ - modest_platform_remove_new_mail_notifications (); + modest_platform_remove_new_mail_notifications (FALSE); } gtk_main (); @@ -160,9 +160,6 @@ main (int argc, char *argv[]) cleanup: gdk_threads_leave (); - /* Remove new mail notifications if exist */ -/* modest_platform_remove_new_mail_notifications (); */ - if (!modest_init_uninit ()) { g_printerr ("modest: modest_init_uninit failed\n"); retval = 1; diff --git a/src/modest-platform.h b/src/modest-platform.h index 455a724..606b3d9 100644 --- a/src/modest-platform.h +++ b/src/modest-platform.h @@ -299,11 +299,13 @@ GtkWidget* modest_platform_get_global_settings_dialog (void); /** * modest_platform_on_new_headers_received: * @header_list: the list of new received headers + * @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 (TnyList *header_list, + gboolean show_visual); /** * modest_platform_show_help: @@ -391,10 +393,11 @@ gboolean modest_platform_run_alert_dialog (const gchar* prompt, gboolean is_ques /** * modest_platform_remove_new_mail_notifications: + * @only_visuals: remove only the visual notifications (like LEDs) * * Removes all the active new mail notifications **/ -void modest_platform_remove_new_mail_notifications (void); +void modest_platform_remove_new_mail_notifications (gboolean only_visuals); /* ModestConnectedPerformer: * @canceled: whether or not the user canceled diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index e38aa0c..e5f7ff6 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -1639,17 +1639,21 @@ new_messages_arrived (ModestMailOperation *self, gpointer user_data) { GObject *source; + gboolean show_visual_notifications; source = modest_mail_operation_get_source (self); - - /* Notify new messages have been downloaded. Do not notify if - the send&receive was invoked by the user, i.e, if the mail - operation has a source (the main window) */ - if ((new_headers != NULL) && (tny_list_get_length (new_headers) > 0) && !source) - modest_platform_on_new_headers_received (new_headers); - + show_visual_notifications = (source) ? FALSE : TRUE; if (source) g_object_unref (source); + + /* Notify new messages have been downloaded. If the + send&receive was invoked by the user then do not show any + visual notification, only play a sound and activate the LED + (for the Maemo version) */ + if ((new_headers != NULL) && (tny_list_get_length (new_headers) > 0)) + modest_platform_on_new_headers_received (new_headers, + show_visual_notifications); + } gboolean diff --git a/src/widgets/modest-main-window.h b/src/widgets/modest-main-window.h index 1256cc2..8c7462e 100644 --- a/src/widgets/modest-main-window.h +++ b/src/widgets/modest-main-window.h @@ -217,8 +217,9 @@ gboolean modest_main_window_on_msg_view_window_msg_changed (ModestMsgViewWindow * * Returns: TRUE if transfer mode is enabled, FASE otherwise. */ -gboolean -modest_main_window_transfer_mode_enabled (ModestMainWindow *self); +gboolean modest_main_window_transfer_mode_enabled (ModestMainWindow *self); + +gboolean modest_main_window_screen_is_on (ModestMainWindow *self); G_END_DECLS -- 1.7.9.5