[balsa] mailbox: Always use an idle callback



commit 9c40d094a3de22037fd46688fb9aa7fa3ce5f6bb
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sun Jan 26 16:41:05 2020 -0500

    mailbox: Always use an idle callback
    
    mailbox: Always use the idle callback to sort after changing the
    threading; save the handler id, to remove the source at finalize
    time instead of taking a ref on the mailbox.
    
    * libbalsa/mailbox.c (libbalsa_mailbox_finalize): remove the
      source, if the handler id has been stored and not cleared;
      (lbm_set_threading_idle_cb), (lbm_set_threading): clear and
      store, respectively, the handler id.

 ChangeLog          | 11 +++++++++++
 libbalsa/mailbox.c | 16 +++++++++++-----
 2 files changed, 22 insertions(+), 5 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6b50091b6..199f7177f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2020-01-26  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       mailbox: Always use the idle callback to sort after changing the
+       threading; save the handler id, to remove the source at finalize
+       time instead of taking a ref on the mailbox.
+
+       * libbalsa/mailbox.c (libbalsa_mailbox_finalize): remove the
+       source, if the handler id has been stored and not cleared;
+       (lbm_set_threading_idle_cb), (lbm_set_threading): clear and
+       store, respectively, the handler id.
+
 2020-01-23  Peter Bloomfield  <pbloomfield bellsouth net>
 
        Header eye candy
diff --git a/libbalsa/mailbox.c b/libbalsa/mailbox.c
index d7c62dd33..61b9697b5 100644
--- a/libbalsa/mailbox.c
+++ b/libbalsa/mailbox.c
@@ -150,6 +150,7 @@ struct _LibBalsaMailboxPrivate {
     guint queue_check_idle_id;
     guint need_threading_idle_id;
     guint run_filters_idle_id;
+    guint set_threading_idle_id;
 
     gboolean is_directory : 1;
     gboolean readonly : 1;
@@ -499,6 +500,9 @@ libbalsa_mailbox_finalize(GObject * object)
     if (priv->run_filters_idle_id != 0)
         g_source_remove(priv->run_filters_idle_id);
 
+    if (priv->set_threading_idle_id != 0)
+        g_source_remove(priv->set_threading_idle_id);
+
     G_OBJECT_CLASS(libbalsa_mailbox_parent_class)->finalize(object);
 }
 
@@ -2320,8 +2324,11 @@ lbm_check_and_sort(LibBalsaMailbox * mailbox)
 static gboolean
 lbm_set_threading_idle_cb(LibBalsaMailbox * mailbox)
 {
+    LibBalsaMailboxPrivate *priv = libbalsa_mailbox_get_instance_private(mailbox);
+
     lbm_check_and_sort(mailbox);
-    g_object_unref(mailbox);
+
+    priv->set_threading_idle_id = 0;
 
     return G_SOURCE_REMOVE;
 }
@@ -2337,10 +2344,9 @@ lbm_set_threading(LibBalsaMailbox * mailbox)
     LIBBALSA_MAILBOX_GET_CLASS(mailbox)->set_threading(mailbox,
                                                        priv->view->threading_type);
 
-    if (libbalsa_am_i_subthread()) {
-        g_idle_add((GSourceFunc) lbm_set_threading_idle_cb, g_object_ref(mailbox));
-    } else {
-        lbm_check_and_sort(mailbox);
+    if (priv->set_threading_idle_id == 0) {
+        priv->set_threading_idle_id =
+            g_idle_add((GSourceFunc) lbm_set_threading_idle_cb, mailbox);
     }
 
     return TRUE;


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