[balsa] Fix a few bugs



commit 43264bc6e07e36b0ee47969e41b7566dc1cf9472
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Wed Jan 15 14:17:58 2020 -0500

    Fix a few bugs
    
    * libbalsa/mailbox_local.c
      (libbalsa_mailbox_local_set_threading): thread messages only if
      there are some; otherwise just set messages-threaded;
    * src/balsa-index.c (bndx_scroll_on_open_idle): if the mailbox
      is empty, just show it and return;
      (balsa_index_scroll_on_open): do not special case an empty
      mailbox;
    * src/main-window.c (bw_real_open_mbnode_idle_cb),
      (balsa_window_real_open_mbnode): register open mailbox earlier,
      to avoid a race with an idle handler;
      (bw_real_open_mbnode_thread): add a warning.

 ChangeLog                | 16 ++++++++++++++++
 libbalsa/mailbox_local.c |  5 ++++-
 src/balsa-index.c        | 34 +++++++++++++++-------------------
 src/main-window.c        |  6 ++++--
 4 files changed, 39 insertions(+), 22 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 439e7bb38..57e9a1a0a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2020-01-15  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       Fix a few bugs
+
+       * libbalsa/mailbox_local.c
+       (libbalsa_mailbox_local_set_threading): thread messages only if
+       there are some; otherwise just set messages-threaded;
+       * src/balsa-index.c (bndx_scroll_on_open_idle): if the mailbox
+       is empty, just show it and return;
+       (balsa_index_scroll_on_open): do not special case an empty
+       mailbox;
+       * src/main-window.c (bw_real_open_mbnode_idle_cb),
+       (balsa_window_real_open_mbnode): register open mailbox earlier,
+       to avoid a race with an idle handler;
+       (bw_real_open_mbnode_thread): add a warning.
+
 2020-01-14  Peter Bloomfield  <pbloomfield bellsouth net>
 
        Move some more code to a thread
diff --git a/libbalsa/mailbox_local.c b/libbalsa/mailbox_local.c
index 22d0fe474..0a3b33637 100644
--- a/libbalsa/mailbox_local.c
+++ b/libbalsa/mailbox_local.c
@@ -1219,7 +1219,10 @@ libbalsa_mailbox_local_set_threading(LibBalsaMailbox * mailbox,
         }
     }
 
-    { /* Scope */
+    if (libbalsa_mailbox_total_messages(mailbox) == 0) {
+        /* Nothing to thread, but we must set the flag. */
+        libbalsa_mailbox_set_messages_threaded(mailbox, TRUE);
+    } else {
         LbmlSetThreadingInfo *info;
 
         info = g_new(LbmlSetThreadingInfo, 1);
diff --git a/src/balsa-index.c b/src/balsa-index.c
index 8a357c10c..bec543e22 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -854,6 +854,12 @@ bndx_scroll_on_open_idle(BalsaIndex *bindex)
            used */
         gint n_children =
             gtk_tree_model_iter_n_children(GTK_TREE_MODEL(mailbox), NULL);
+
+        if (n_children == 0) {
+            gtk_widget_show(GTK_WIDGET(bindex));
+            return FALSE;
+        }
+
         path = gtk_tree_path_new_from_indices(n_children - 1, -1);
     }
 
@@ -887,25 +893,15 @@ bndx_scroll_on_open_idle(BalsaIndex *bindex)
 void
 balsa_index_scroll_on_open(BalsaIndex * bindex)
 {
-    LibBalsaMailbox *mailbox;
-    GtkTreeIter iter;
-
-    mailbox = balsa_mailbox_node_get_mailbox(bindex->mailbox_node);
-
-    if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(mailbox), &iter)) {
-        /* Empty view */
-        gtk_widget_show(GTK_WIDGET(bindex));
-    } else {
-        /* Scroll in an idle handler, because the mailbox is perhaps being
-         * opened in its own idle handler. */
-        /* Use low priority, so that GtkTreeView's layout idle handlers get
-         * to finish the layout first. */
-        if (bindex->scroll_on_open_idle_id == 0) {
-            bindex->scroll_on_open_idle_id =
-                g_idle_add_full(G_PRIORITY_LOW,
-                                (GSourceFunc) bndx_scroll_on_open_idle,
-                                bindex, NULL);
-        }
+    /* Scroll in an idle handler, because the mailbox is perhaps being
+     * opened in its own idle handler. */
+    /* Use low priority, so that GtkTreeView's layout idle handlers get
+     * to finish the layout first. */
+    if (bindex->scroll_on_open_idle_id == 0) {
+        bindex->scroll_on_open_idle_id =
+            g_idle_add_full(G_PRIORITY_LOW,
+                            (GSourceFunc) bndx_scroll_on_open_idle,
+                            bindex, NULL);
     }
 }
 
diff --git a/src/main-window.c b/src/main-window.c
index da88ff4d4..c4057ae06 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -2914,8 +2914,6 @@ bw_real_open_mbnode_idle_cb(BalsaWindowRealOpenMbnodeInfo * info)
         gtk_notebook_set_current_page(GTK_NOTEBOOK(priv->notebook),
                                       page_num);
 
-    bw_register_open_mailbox(mailbox);
-
     filter =
         bw_get_condition_from_int(libbalsa_mailbox_get_filter(mailbox));
     libbalsa_mailbox_set_view_filter(mailbox, filter, FALSE);
@@ -2973,6 +2971,9 @@ bw_real_open_mbnode_thread(BalsaWindowRealOpenMbnodeInfo * info)
             balsa_index_load_mailbox_node(info->index, info->mbnode);
             libbalsa_mailbox_set_threading(mailbox);
             g_idle_add((GSourceFunc) bw_real_open_mbnode_idle_cb, info);
+        } else {
+            g_warning("%s mailbox \"%s\" is already in the notebook",
+                      __func__, libbalsa_mailbox_get_name(mailbox));
         }
     } else {
         libbalsa_information(
@@ -3006,6 +3007,7 @@ balsa_window_real_open_mbnode(BalsaWindow * window,
 
     if (bw_is_open_mailbox(mailbox = balsa_mailbox_node_get_mailbox(mbnode)))
         return;
+    bw_register_open_mailbox(mailbox);
 
     index = BALSA_INDEX(balsa_index_new());
     balsa_index_set_width_preference


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