Only remove mail notifications for each account, when we see mails
authorJosé Dapena Paz <jdapena@igalia.com>
Fri, 15 Jan 2010 11:04:08 +0000 (12:04 +0100)
committerJosé Dapena Paz <jdapena@igalia.com>
Fri, 15 Jan 2010 11:04:08 +0000 (12:04 +0100)
or folders from that account (fixes NB#140276).

src/dbus_api/modest-dbus-callbacks.c
src/gtk/modest-platform.c
src/hildon2/modest-hildon2-window-mgr.c
src/hildon2/modest-platform.c
src/modest-account-mgr.h
src/modest-defs.h
src/modest-main.c
src/modest-platform.h
src/modest-ui-actions.c

index 1f07719..597ad77 100644 (file)
@@ -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 */
index d950cb1..7af2d23 100644 (file)
@@ -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;
 }
index 66a6906..29c687c 100644 (file)
@@ -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
index 6b57a1d..c71c1d5 100644 (file)
@@ -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", &notif_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);
 
index 679c97d..859e390 100644 (file)
@@ -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__ */
index 4198225..988ba1a 100644 (file)
@@ -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")
index ed753dd..19ceda6 100644 (file)
@@ -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 ();
index 3489a0e..5ade99b 100644 (file)
@@ -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
index 97bb9c8..6e3f733 100644 (file)
@@ -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__);
                }