[evolution/gnome-3-10] Bug #583773 - Does not always mark mails as read automatically



commit 574a63072841d6144fd9ffe6abf6ce44084c2062
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jan 23 21:38:34 2014 +0100

    Bug #583773 - Does not always mark mails as read automatically

 mail/e-mail-reader.c |   86 ++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 70 insertions(+), 16 deletions(-)
---
diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c
index 0ebf5f1..30b13be 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -93,6 +93,11 @@ struct _EMailReaderPrivate {
        guint avoid_next_mark_as_seen     : 1;
 
        guint group_by_threads : 1;
+
+       /* to be able to start the mark_seen timeout only after
+          the message is loaded into the EMailDisplay */
+       gboolean schedule_mark_seen;
+       guint schedule_mark_seen_interval;
 };
 
 enum {
@@ -2593,9 +2598,60 @@ mail_reader_message_seen_cb (EMailReaderClosure *closure)
        return FALSE;
 }
 
-static gboolean
+static void
 schedule_timeout_mark_seen (EMailReader *reader)
 {
+       EMailReaderPrivate *priv;
+       MessageList *message_list;
+
+       g_return_if_fail (E_IS_MAIL_READER (reader));
+
+       priv = E_MAIL_READER_GET_PRIVATE (reader);
+
+       message_list = MESSAGE_LIST (e_mail_reader_get_message_list (reader));
+       g_return_if_fail (message_list != NULL);
+
+       if (message_list->cursor_uid) {
+               EMailReaderClosure *timeout_closure;
+
+               if (message_list->seen_id > 0) {
+                       g_source_remove (message_list->seen_id);
+                       message_list->seen_id = 0;
+               }
+
+               timeout_closure = g_slice_new0 (EMailReaderClosure);
+               timeout_closure->reader = g_object_ref (reader);
+               timeout_closure->message_uid = g_strdup (message_list->cursor_uid);
+
+               MESSAGE_LIST (message_list)->seen_id = g_timeout_add_full (
+                       G_PRIORITY_DEFAULT, priv->schedule_mark_seen_interval,
+                       (GSourceFunc) mail_reader_message_seen_cb,
+                       timeout_closure, (GDestroyNotify)
+                       mail_reader_closure_free);
+       }
+}
+
+static void
+mail_reader_load_status_changed_cb (EMailReader *reader,
+                                   GParamSpec *pspec,
+                                   EMailDisplay *display)
+{
+       EMailReaderPrivate *priv;
+
+       if (webkit_web_view_get_load_status (WEBKIT_WEB_VIEW (display)) != WEBKIT_LOAD_FINISHED)
+               return;
+
+       priv = E_MAIL_READER_GET_PRIVATE (reader);
+       if (priv->schedule_mark_seen &&
+           e_mail_display_get_part_list (display) &&
+           e_mail_view_get_preview_visible (E_MAIL_VIEW (reader)))
+               schedule_timeout_mark_seen (reader);
+}
+
+static gboolean
+maybe_schedule_timeout_mark_seen (EMailReader *reader)
+{
+       EMailReaderPrivate *priv;
        MessageList *message_list;
        GSettings *settings;
        gboolean schedule_timeout;
@@ -2624,19 +2680,9 @@ schedule_timeout_mark_seen (EMailReader *reader)
                message_list->seen_id = 0;
        }
 
-       if (schedule_timeout) {
-               EMailReaderClosure *timeout_closure;
-
-               timeout_closure = g_slice_new0 (EMailReaderClosure);
-               timeout_closure->reader = g_object_ref (reader);
-               timeout_closure->message_uid = g_strdup (message_uid);
-
-               MESSAGE_LIST (message_list)->seen_id = g_timeout_add_full (
-                       G_PRIORITY_DEFAULT, timeout_interval,
-                       (GSourceFunc) mail_reader_message_seen_cb,
-                       timeout_closure, (GDestroyNotify)
-                       mail_reader_closure_free);
-       }
+       priv = E_MAIL_READER_GET_PRIVATE (reader);
+       priv->schedule_mark_seen = schedule_timeout;
+       priv->schedule_mark_seen_interval = timeout_interval;
 
        return schedule_timeout;
 }
@@ -2644,10 +2690,14 @@ schedule_timeout_mark_seen (EMailReader *reader)
 static gboolean
 discard_timeout_mark_seen_cb (EMailReader *reader)
 {
+       EMailReaderPrivate *priv;
        MessageList *message_list;
 
        g_return_val_if_fail (reader != NULL, FALSE);
 
+       priv = E_MAIL_READER_GET_PRIVATE (reader);
+       priv->schedule_mark_seen = FALSE;
+
        message_list = MESSAGE_LIST (e_mail_reader_get_message_list (reader));
        g_return_val_if_fail (message_list != NULL, FALSE);
 
@@ -2877,7 +2927,7 @@ mail_reader_message_cursor_change_cb (EMailReader *reader)
            E_IS_MAIL_VIEW (reader) &&
            e_mail_view_get_preview_visible (E_MAIL_VIEW (reader)) &&
            !priv->avoid_next_mark_as_seen)
-               schedule_timeout_mark_seen (reader);
+               maybe_schedule_timeout_mark_seen (reader);
 }
 
 static void
@@ -3103,7 +3153,7 @@ mail_reader_message_loaded (EMailReader *reader,
        if (message != NULL &&
            !priv->restoring_message_selection &&
            !priv->avoid_next_mark_as_seen &&
-           schedule_timeout_mark_seen (reader)) {
+           maybe_schedule_timeout_mark_seen (reader)) {
                g_clear_error (&error);
        } else if (error != NULL) {
                e_alert_submit (
@@ -3894,6 +3944,10 @@ connect_signals:
                G_CALLBACK (mail_reader_key_press_event_cb), reader);
 
        g_signal_connect_swapped (
+               display, "notify::load-status",
+               G_CALLBACK (mail_reader_load_status_changed_cb), reader);
+
+       g_signal_connect_swapped (
                message_list, "message-selected",
                G_CALLBACK (mail_reader_message_selected_cb), reader);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]