[balsa/gtk3] Use idle handler to call Gtk



commit 0fcb12b8a4fcdd29236b644c082afdfa4f0d117e
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Wed Jun 6 13:42:22 2012 -0400

    Use idle handler to call Gtk
    
    	* libbalsa/mailbox.c (libbalsa_mailbox_close), (lbm_msgno_removed),
    	(lbm_msgno_removed_idle_cb), (libbalsa_mailbox_msgno_removed):
    	use an idle callback to remove the message from the tree-model.

 ChangeLog          |    6 ++++++
 libbalsa/mailbox.c |   40 ++++++++++++++++++++++++++++++++++++----
 2 files changed, 42 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index eb47540..d09de0c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2012-06-06  Peter Bloomfield
 
+	* libbalsa/mailbox.c (libbalsa_mailbox_close), (lbm_msgno_removed),
+	(lbm_msgno_removed_idle_cb), (libbalsa_mailbox_msgno_removed):
+	use an idle callback to remove the message from the tree-model.
+
+2012-06-06  Peter Bloomfield
+
 	* src/balsa-app.c (find_url_func), (find_url), (find_url_idle_cb),
 	(balsa_find_url): block the subthread and use an idle callback
 	to find the BalsaMailboxNode for the URL.
diff --git a/libbalsa/mailbox.c b/libbalsa/mailbox.c
index 073222e..98239ef 100644
--- a/libbalsa/mailbox.c
+++ b/libbalsa/mailbox.c
@@ -643,12 +643,10 @@ libbalsa_mailbox_close(LibBalsaMailbox * mailbox, gboolean expunge)
         /* do not try expunging read-only mailboxes, it's a waste of time */
         expunge = expunge && !mailbox->readonly;
         LIBBALSA_MAILBOX_GET_CLASS(mailbox)->close_mailbox(mailbox, expunge);
-        gdk_threads_enter();
         if(mailbox->msg_tree) {
             g_node_destroy(mailbox->msg_tree);
             mailbox->msg_tree = NULL;
         }
-        gdk_threads_leave();
         libbalsa_mailbox_free_mindex(mailbox);
         mailbox->stamp++;
 	mailbox->state = LB_MAILBOX_STATE_CLOSED;
@@ -1427,8 +1425,8 @@ decrease_post(GNode *node, gpointer data)
     return FALSE;
 }
 
-void
-libbalsa_mailbox_msgno_removed(LibBalsaMailbox * mailbox, guint seqno)
+static void
+lbm_msgno_removed(LibBalsaMailbox * mailbox, guint seqno)
 {
     GtkTreeIter iter;
     GtkTreePath *path;
@@ -1516,6 +1514,40 @@ libbalsa_mailbox_msgno_removed(LibBalsaMailbox * mailbox, guint seqno)
     gdk_threads_leave();
 }
 
+#ifdef BALSA_USE_THREADS
+typedef struct {
+    LibBalsaMailbox *mailbox;
+    guint seqno;
+} LbmMsgnoRemovedInfo;
+
+static gboolean
+lbm_msgno_removed_idle_cb(LbmMsgnoRemovedInfo * info)
+{
+    lbm_msgno_removed(info->mailbox, info->seqno);
+    g_object_unref(info->mailbox);
+    g_free(info);
+    return FALSE;
+}
+#endif                          /* BALSA_USE_THREADS */
+
+void
+libbalsa_mailbox_msgno_removed(LibBalsaMailbox * mailbox, guint seqno)
+{
+#ifdef BALSA_USE_THREADS
+    if (libbalsa_am_i_subthread()) {
+        LbmMsgnoRemovedInfo *info = g_new(LbmMsgnoRemovedInfo, 1);
+        info->mailbox = g_object_ref(mailbox);
+        info->seqno = seqno;
+        gdk_threads_add_idle((GSourceFunc) lbm_msgno_removed_idle_cb,
+                             info);
+    } else {
+        lbm_msgno_removed(mailbox, seqno);
+    }
+#else                           /* BALSA_USE_THREADS */
+    lbm_msgno_removed(mailbox, seqno);
+#endif                          /* BALSA_USE_THREADS */
+}
+
 void
 libbalsa_mailbox_msgno_filt_out(LibBalsaMailbox * mailbox, guint seqno)
 {



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