From c2e21fb7e504c913cfd431ee8649a892548e8130 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Dapena=20Paz?= Date: Fri, 15 Jan 2010 12:04:08 +0100 Subject: [PATCH] Only remove mail notifications for each account, when we see mails or folders from that account (fixes NB#140276). --- src/dbus_api/modest-dbus-callbacks.c | 5 ----- src/gtk/modest-platform.c | 2 +- src/hildon2/modest-hildon2-window-mgr.c | 12 +++++++++- src/hildon2/modest-platform.c | 37 ++++++++++++++++++------------- src/modest-account-mgr.h | 9 ++++++++ src/modest-defs.h | 1 + src/modest-main.c | 2 -- src/modest-platform.h | 3 ++- src/modest-ui-actions.c | 2 +- 9 files changed, 47 insertions(+), 26 deletions(-) diff --git a/src/dbus_api/modest-dbus-callbacks.c b/src/dbus_api/modest-dbus-callbacks.c index 1f07719..597ad77 100644 --- a/src/dbus_api/modest-dbus-callbacks.c +++ b/src/dbus_api/modest-dbus-callbacks.c @@ -1365,11 +1365,6 @@ on_idle_top_application (gpointer user_data) mgr = modest_runtime_get_window_mgr (); window = (GtkWidget *) modest_window_mgr_show_initial_window (mgr); - if (window) { - modest_platform_remove_new_mail_notifications (FALSE); - } else { - g_printerr ("modest: failed to get main window instance\n"); - } } gdk_threads_leave (); /* CHECKED */ diff --git a/src/gtk/modest-platform.c b/src/gtk/modest-platform.c index d950cb1..7af2d23 100644 --- a/src/gtk/modest-platform.c +++ b/src/gtk/modest-platform.c @@ -1239,7 +1239,7 @@ modest_platform_on_new_headers_received (GList *URI_list, } void -modest_platform_remove_new_mail_notifications (gboolean only_visuals) +modest_platform_remove_new_mail_notifications (gboolean only_visuals, const gchar *acc_name) { return; } diff --git a/src/hildon2/modest-hildon2-window-mgr.c b/src/hildon2/modest-hildon2-window-mgr.c index 66a6906..29c687c 100644 --- a/src/hildon2/modest-hildon2-window-mgr.c +++ b/src/hildon2/modest-hildon2-window-mgr.c @@ -432,6 +432,7 @@ modest_hildon2_window_mgr_register_window (ModestWindowMgr *self, HildonWindowStack *stack; gboolean nested_msg = FALSE; ModestWindow *current_top; + const gchar *acc_name; g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self), FALSE); g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE); @@ -577,6 +578,15 @@ modest_hildon2_window_mgr_register_window (ModestWindowMgr *self, *handler_id = g_signal_connect (window, "delete-event", G_CALLBACK (on_window_destroy), self); g_hash_table_insert (priv->destroy_handlers, window, handler_id); + if (!MODEST_IS_MSG_EDIT_WINDOW (window) && + !MODEST_IS_ACCOUNTS_WINDOW (window)) { + acc_name = modest_window_get_active_account (window); + + if (acc_name) { + modest_platform_remove_new_mail_notifications (FALSE, acc_name); + } + } + /* Show toolbar always */ modest_window_show_toolbar (window, TRUE); @@ -1017,7 +1027,7 @@ osso_display_event_cb (osso_display_state_t state, /* Stop blinking if the screen becomes on */ if (priv->display_state == OSSO_DISPLAY_ON) - modest_platform_remove_new_mail_notifications (TRUE); + modest_platform_remove_new_mail_notifications (TRUE, NULL); } static gboolean diff --git a/src/hildon2/modest-platform.c b/src/hildon2/modest-platform.c index 6b57a1d..c71c1d5 100644 --- a/src/hildon2/modest-platform.c +++ b/src/hildon2/modest-platform.c @@ -1610,6 +1610,7 @@ modest_platform_on_new_headers_received (GList *URI_list, gchar *from; TnyAccountStore *acc_store; TnyAccount *account; + gchar *acc_name; data = (ModestMsgNotificationData *) URI_list->data; @@ -1659,10 +1660,9 @@ modest_platform_on_new_headers_received (GList *URI_list, /* Set the account of the headers */ acc_store = (TnyAccountStore *) modest_runtime_get_account_store (); account = tny_account_store_find_account (acc_store, data->uri); + acc_name = NULL; if (account) { - const gchar *acc_name; - acc_name = - modest_tny_account_get_parent_modest_account_name_for_server_account (account); + acc_name = g_strdup (modest_tny_account_get_parent_modest_account_name_for_server_account (account)); notify_notification_set_hint_string(NOTIFY_NOTIFICATION (notification), "email-account", acc_name); @@ -1673,9 +1673,11 @@ modest_platform_on_new_headers_received (GList *URI_list, 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); + if (acc_name) { + notifications_list = modest_account_mgr_get_list (modest_runtime_get_account_mgr (), acc_name, + MODEST_ACCOUNT_NOTIFICATION_IDS, + MODEST_CONF_VALUE_INT, FALSE); + } /* Save id in the list */ g_object_get(G_OBJECT (notification), "id", ¬if_id, NULL); @@ -1686,19 +1688,22 @@ modest_platform_on_new_headers_received (GList *URI_list, not to store the list in gconf */ /* Save the ids */ - modest_conf_set_list (modest_runtime_get_conf (), MODEST_CONF_NOTIFICATION_IDS, - notifications_list, MODEST_CONF_VALUE_INT, NULL); - + if (acc_name) + modest_account_mgr_set_list (modest_runtime_get_account_mgr (), acc_name, + MODEST_ACCOUNT_NOTIFICATION_IDS, + notifications_list, MODEST_CONF_VALUE_INT, FALSE); + g_slist_free (notifications_list); } else { g_warning ("Failed to send notification"); } + g_free (acc_name); #endif /*MODEST_HAVE_HILDON_NOTIFY*/ } void -modest_platform_remove_new_mail_notifications (gboolean only_visuals) +modest_platform_remove_new_mail_notifications (gboolean only_visuals, const gchar *acc_name) { if (only_visuals) { #ifdef MODEST_HAVE_MCE @@ -1718,9 +1723,10 @@ modest_platform_remove_new_mail_notifications (gboolean only_visuals) 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); + notif_list = modest_account_mgr_get_list (modest_runtime_get_account_mgr (), + acc_name, + MODEST_ACCOUNT_NOTIFICATION_IDS, + MODEST_CONF_VALUE_INT, FALSE); while (notif_list) { gint notif_id; @@ -1743,8 +1749,9 @@ modest_platform_remove_new_mail_notifications (gboolean only_visuals) } /* Save the ids */ - modest_conf_set_list (modest_runtime_get_conf (), MODEST_CONF_NOTIFICATION_IDS, - notif_list, MODEST_CONF_VALUE_INT, NULL); + modest_account_mgr_set_list (modest_runtime_get_account_mgr (), acc_name, + MODEST_ACCOUNT_NOTIFICATION_IDS, + notif_list, MODEST_CONF_VALUE_INT, FALSE); g_slist_free (notif_list); diff --git a/src/modest-account-mgr.h b/src/modest-account-mgr.h index 679c97d..859e390 100644 --- a/src/modest-account-mgr.h +++ b/src/modest-account-mgr.h @@ -375,6 +375,15 @@ gboolean modest_account_mgr_singleton_protocol_exists (ModestAccountMgr *mgr, gchar * modest_account_mgr_get_string (ModestAccountMgr *self, const gchar *name, const gchar *key, gboolean server_account); +GSList * modest_account_mgr_get_list (ModestAccountMgr *self, const gchar *name, + const gchar *key, ModestConfValueType list_type, + gboolean server_account); +gboolean modest_account_mgr_set_list (ModestAccountMgr *self, + const gchar *name, + const gchar *key, + GSList *val, + ModestConfValueType list_type, + gboolean server_account); G_END_DECLS #endif /* __MODEST_ACCOUNT_MGR_H__ */ diff --git a/src/modest-defs.h b/src/modest-defs.h index 4198225..988ba1a 100644 --- a/src/modest-defs.h +++ b/src/modest-defs.h @@ -248,6 +248,7 @@ const gchar *modest_defs_namespace (const gchar *string); /* Notification ids */ #define MODEST_CONF_NOTIFICATION_IDS (modest_defs_namespace ("/notification_ids")) /* list of ints */ +#define MODEST_ACCOUNT_NOTIFICATION_IDS "notification_ids" /* list of ints */ #ifdef MODEST_TOOLKIT_HILDON2 #define MODEST_EXAMPLE_EMAIL_ADDRESS _("mcen_va_example_email_address") diff --git a/src/modest-main.c b/src/modest-main.c index ed753dd..19ceda6 100644 --- a/src/modest-main.c +++ b/src/modest-main.c @@ -220,8 +220,6 @@ main (int argc, char *argv[]) retval = 1; goto cleanup; } - /* Remove new mail notifications if exist */ - modest_platform_remove_new_mail_notifications (FALSE); } gtk_main (); diff --git a/src/modest-platform.h b/src/modest-platform.h index 3489a0e..5ade99b 100644 --- a/src/modest-platform.h +++ b/src/modest-platform.h @@ -404,10 +404,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) + * @acc_name: account to remove notifications * * Removes all the active new mail notifications **/ -void modest_platform_remove_new_mail_notifications (gboolean only_visuals); +void modest_platform_remove_new_mail_notifications (gboolean only_visuals, const gchar *acc_name); /* ModestConnectedPerformer: * @canceled: whether or not the user canceled diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 97bb9c8..6e3f733 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -5836,7 +5836,7 @@ modest_ui_actions_on_delete_account (GtkWindow *parent_window, distinguish if the notification belongs to this account or not, so for safety reasons we remove them all */ - modest_platform_remove_new_mail_notifications (FALSE); + modest_platform_remove_new_mail_notifications (FALSE, account_name); } else { g_warning ("%s: modest_account_mgr_remove_account() failed.\n", __FUNCTION__); } -- 1.7.9.5