[balsa] Revert 90ee8bcc82d8ebdae0bd286212c21d1138531658



commit 63d072dd98058e099ed6b2eb1dbf87dbb5e3a135
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Thu Jan 16 11:21:10 2020 -0500

    Revert 90ee8bcc82d8ebdae0bd286212c21d1138531658
    
    Moving code to the mailbox-opening thread resulted in calls to
    Gtk from the thread; moving those calls to an idle handler in
    the main thread got things out of order. We need a more radical
    refactoring to get more work done in threads.
    
    This commit reverses the changes in commit
    90ee8bcc82d8ebdae0bd286212c21d1138531658, while keeping the
    later fixes.
    
    * src/balsa-index.c (bndx_scroll_on_open_idle),
      (balsa_index_load_mailbox_node):
    * src/main-window.c (bw_real_open_mbnode_idle_cb),
      (bw_real_open_mbnode_thread):

 ChangeLog         | 18 +++++++++++++
 src/balsa-index.c | 75 +++++++++++++++++++++----------------------------------
 src/main-window.c | 21 ++++++++++------
 3 files changed, 59 insertions(+), 55 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1b4aa379e..913f823ce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2020-01-16  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       Revert 90ee8bcc82d8ebdae0bd286212c21d1138531658
+
+       Moving code to the mailbox-opening thread resulted in calls to
+       Gtk from the thread; moving those calls to an idle handler in
+       the main thread got things out of order. We need a more radical
+       refactoring to get more work done in threads.
+
+       This commit reverses the changes in commit
+       90ee8bcc82d8ebdae0bd286212c21d1138531658, while keeping the
+       later fixes.
+
+       * src/balsa-index.c (bndx_scroll_on_open_idle),
+       (balsa_index_load_mailbox_node):
+       * src/main-window.c (bw_real_open_mbnode_idle_cb),
+       (bw_real_open_mbnode_thread):
+
 2020-01-15  Peter Bloomfield  <pbloomfield bellsouth net>
 
        mailbox-local: Set messages-loaded
diff --git a/src/balsa-index.c b/src/balsa-index.c
index bec543e22..12ceeb9c8 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -819,10 +819,6 @@ bndx_scroll_on_open_idle(BalsaIndex *bindex)
     GtkTreePath *path;
     gpointer view_on_open;
 
-    /* Make sure the tree-view has a model: */
-    if (gtk_tree_view_get_model(tree_view) == NULL)
-        return TRUE; /* G_SOURCE_CONTINUE */
-
     mailbox = balsa_mailbox_node_get_mailbox(bindex->mailbox_node);
 
     if (!libbalsa_mailbox_get_messages_threaded(mailbox))
@@ -854,12 +850,10 @@ 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);
     }
 
@@ -984,41 +978,15 @@ bndx_mailbox_message_expunged_cb(LibBalsaMailbox * mailbox, guint msgno,
  * balsa_mailbox_node_get_mailbox(mbnode) is already open
  */
 
-static gboolean
-bndx_load_mailbox_node_idle(BalsaIndex *bindex)
-{
-    LibBalsaMailbox *mailbox;
-    GtkTreeView *tree_view;
-
-    mailbox = balsa_mailbox_node_get_mailbox(bindex->mailbox_node);
-    tree_view = GTK_TREE_VIEW(bindex);
-
-    /*
-     * rename "from" column to "to" for outgoing mail
-     */
-    if (libbalsa_mailbox_get_show(mailbox) == LB_MAILBOX_SHOW_TO) {
-        GtkTreeViewColumn *column =
-           gtk_tree_view_get_column(tree_view, LB_MBOX_FROM_COL);
-        bindex->filter_no = 1; /* FIXME: this is hack! */
-        gtk_tree_view_column_set_title(column, _("To"));
-    }
-
-    /* Set the tree store */
-    gtk_tree_view_set_model(tree_view, GTK_TREE_MODEL(mailbox));
-
-    g_object_unref(bindex);
-
-    return G_SOURCE_REMOVE;
-}
-
 gboolean
-balsa_index_load_mailbox_node(BalsaIndex * bindex,
+balsa_index_load_mailbox_node(BalsaIndex * index,
                               BalsaMailboxNode* mbnode)
 {
+    GtkTreeView *tree_view;
     LibBalsaMailbox *mailbox;
 
-    g_return_val_if_fail(BALSA_IS_INDEX(bindex), TRUE);
-    g_return_val_if_fail(bindex->mailbox_node == NULL, TRUE);
+    g_return_val_if_fail(BALSA_IS_INDEX(index), TRUE);
+    g_return_val_if_fail(index->mailbox_node == NULL, TRUE);
     g_return_val_if_fail(BALSA_IS_MAILBOX_NODE(mbnode), TRUE);
 
     mailbox = balsa_mailbox_node_get_mailbox(mbnode);
@@ -1027,28 +995,41 @@ balsa_index_load_mailbox_node(BalsaIndex * bindex,
     /*
      * set the new mailbox
      */
-    bindex->mailbox_node = mbnode;
+    index->mailbox_node = mbnode;
     g_object_weak_ref(G_OBJECT(mbnode),
-                      (GWeakNotify) bndx_mbnode_weak_notify, bindex);
+                      (GWeakNotify) bndx_mbnode_weak_notify, index);
+    /*
+     * rename "from" column to "to" for outgoing mail
+     */
+    tree_view = GTK_TREE_VIEW(index);
+    if (libbalsa_mailbox_get_show(mailbox) == LB_MAILBOX_SHOW_TO) {
+        GtkTreeViewColumn *column =
+           gtk_tree_view_get_column(tree_view, LB_MBOX_FROM_COL);
+        index->filter_no = 1; /* FIXME: this is hack! */
+        gtk_tree_view_column_set_title(column, _("To"));
+    }
+
     g_signal_connect(mailbox, "changed",
-                     G_CALLBACK(bndx_mailbox_changed_cb), bindex);
+                     G_CALLBACK(bndx_mailbox_changed_cb), index);
     g_signal_connect(mailbox, "row-inserted",
-                     G_CALLBACK(bndx_mailbox_row_inserted_cb), bindex);
+                     G_CALLBACK(bndx_mailbox_row_inserted_cb), index);
     g_signal_connect(mailbox, "message-expunged",
-                     G_CALLBACK(bndx_mailbox_message_expunged_cb), bindex);
+                     G_CALLBACK(bndx_mailbox_message_expunged_cb), index);
+
+    /* Set the tree store */
+#ifndef GTK2_FETCHES_ONLY_VISIBLE_CELLS
+    g_object_set_data(G_OBJECT(mailbox), "tree-view", tree_view);
+#endif
+    gtk_tree_view_set_model(tree_view, GTK_TREE_MODEL(mailbox));
 
     /* Create a search-iter for SEARCH UNDELETED. */
     if (!cond_undeleted)
         cond_undeleted =
             libbalsa_condition_new_flag_enum(TRUE,
                                              LIBBALSA_MESSAGE_FLAG_DELETED);
-    bindex->search_iter = libbalsa_mailbox_search_iter_new(cond_undeleted);
+    index->search_iter = libbalsa_mailbox_search_iter_new(cond_undeleted);
     /* Note when this mailbox was opened, for use in auto-closing. */
-    balsa_mailbox_node_set_last_use_time(bindex->mailbox_node);
-
-    /* In case we are called in a thread, use an idle handler to
-     * complete the loading: */
-    g_idle_add((GSourceFunc) bndx_load_mailbox_node_idle, g_object_ref(bindex));
+    balsa_mailbox_node_set_last_use_time(index->mailbox_node);
 
     return FALSE;
 }
diff --git a/src/main-window.c b/src/main-window.c
index c4057ae06..bd4ebe84a 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -2889,6 +2889,16 @@ bw_real_open_mbnode_idle_cb(BalsaWindowRealOpenMbnodeInfo * info)
                                  (gpointer *) &info->window);
     g_free(info->message);
 
+    if (balsa_find_notebook_page_num(mailbox) >= 0) {
+        g_object_unref(g_object_ref_sink(index));
+        g_object_unref(mbnode);
+        g_application_release(info->application);
+        g_free(info);
+        return FALSE;
+    }
+
+    balsa_index_load_mailbox_node(index, mbnode);
+
     g_signal_connect(index, "index-changed",
                      G_CALLBACK(bw_index_changed_cb), window);
 
@@ -2914,6 +2924,8 @@ bw_real_open_mbnode_idle_cb(BalsaWindowRealOpenMbnodeInfo * info)
         gtk_notebook_set_current_page(GTK_NOTEBOOK(priv->notebook),
                                       page_num);
 
+    libbalsa_mailbox_set_threading(mailbox);
+
     filter =
         bw_get_condition_from_int(libbalsa_mailbox_get_filter(mailbox));
     libbalsa_mailbox_set_view_filter(mailbox, filter, FALSE);
@@ -2967,14 +2979,7 @@ bw_real_open_mbnode_thread(BalsaWindowRealOpenMbnodeInfo * info)
     } while(try_cnt++<3);
 
     if (successp) {
-        if (balsa_find_notebook_page_num(mailbox) < 0) {
-            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));
-        }
+        g_idle_add((GSourceFunc) bw_real_open_mbnode_idle_cb, info);
     } else {
         libbalsa_information(
             LIBBALSA_INFORMATION_ERROR,


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