[balsa/gtk3] Run filters in an idle callback



commit 3a8fd30d6d8b7040cb189aefdde91295c67809f7
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Wed Feb 27 07:45:01 2013 -0500

    Run filters in an idle callback
    
        * libbalsa/mailbox.c (lbm_run_filters_on_reception_idle_cb),
        (libbalsa_mailbox_run_filters_on_reception): run filters in an
        idle callback.

 ChangeLog          |    6 ++++++
 libbalsa/mailbox.c |   26 ++++++++++++++++++++------
 2 files changed, 26 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d031d0c..8f257d8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-02-27  Peter Bloomfield
+
+       * libbalsa/mailbox.c (lbm_run_filters_on_reception_idle_cb),
+       (libbalsa_mailbox_run_filters_on_reception): run filters in an
+       idle callback.
+
 2013-02-26  Peter Bloomfield
 
        * src/main-window.c: do not use another idle handler to set the
diff --git a/libbalsa/mailbox.c b/libbalsa/mailbox.c
index f363b21..b67cedc 100644
--- a/libbalsa/mailbox.c
+++ b/libbalsa/mailbox.c
@@ -813,8 +813,8 @@ libbalsa_mailbox_can_match(LibBalsaMailbox * mailbox,
 
 /* Helper function to run the "on reception" filters on a mailbox */
 
-void
-libbalsa_mailbox_run_filters_on_reception(LibBalsaMailbox * mailbox)
+static gboolean
+lbm_run_filters_on_reception_idle_cb(LibBalsaMailbox * mailbox)
 {
     GSList *filters;
     guint progress_count;
@@ -825,7 +825,11 @@ libbalsa_mailbox_run_filters_on_reception(LibBalsaMailbox * mailbox)
     guint progress_total;
     LibBalsaProgress progress;
 
-    g_return_if_fail(LIBBALSA_IS_MAILBOX(mailbox));
+    g_object_add_weak_pointer(G_OBJECT(mailbox), (gpointer) &mailbox);
+    g_object_unref(mailbox);
+    if (!mailbox)
+        return FALSE;
+    g_object_remove_weak_pointer(G_OBJECT(mailbox), (gpointer) &mailbox);
 
     if (!mailbox->filters_loaded) {
         config_mailbox_filters_load(mailbox);
@@ -836,10 +840,10 @@ libbalsa_mailbox_run_filters_on_reception(LibBalsaMailbox * mailbox)
                                             FILTER_WHEN_INCOMING);
 
     if (!filters)
-        return;
+        return FALSE;
     if (!filters_prepare_to_run(filters)) {
         g_slist_free(filters);
-        return;
+        return FALSE;
     }
 
     progress_count = 0;
@@ -866,7 +870,7 @@ libbalsa_mailbox_run_filters_on_reception(LibBalsaMailbox * mailbox)
     text = g_strdup_printf(_("Applying filter rules to %s"), mailbox->name);
     total = libbalsa_mailbox_total_messages(mailbox);
     progress_total = progress_count * total;
-        libbalsa_progress_set_text(&progress, text, progress_total);
+    libbalsa_progress_set_text(&progress, text, progress_total);
     g_free(text);
 
     progress_count = 0;
@@ -911,6 +915,16 @@ libbalsa_mailbox_run_filters_on_reception(LibBalsaMailbox * mailbox)
     libbalsa_unlock_mailbox(mailbox);
 
     g_slist_free(filters);
+    return FALSE;
+}
+
+void
+libbalsa_mailbox_run_filters_on_reception(LibBalsaMailbox * mailbox)
+{
+    g_return_if_fail(LIBBALSA_IS_MAILBOX(mailbox));
+
+    g_idle_add((GSourceFunc) lbm_run_filters_on_reception_idle_cb,
+               g_object_ref(mailbox));
 }
 
 void


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