[balsa/gtk3] Use idle handler to call Gtk
- From: Peter Bloomfield <PeterB src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/gtk3] Use idle handler to call Gtk
- Date: Wed, 6 Jun 2012 17:43:06 +0000 (UTC)
commit 4d4c5f16af9a1a7730ee2dede6339e3a2ff0637e
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Wed Jun 6 13:39:43 2012 -0400
Use idle handler to call Gtk
* 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.
ChangeLog | 6 +++
src/balsa-app.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 86 insertions(+), 13 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 86d465a..eb47540 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
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.
+
+2012-06-06 Peter Bloomfield
+
* libbalsa/mime-stream-shared.c
(libbalsa_mime_stream_shared_lock): build with glib < 2.32.
diff --git a/src/balsa-app.c b/src/balsa-app.c
index 06a5005..771aa2c 100644
--- a/src/balsa-app.c
+++ b/src/balsa-app.c
@@ -694,16 +694,16 @@ balsa_find_dir(LibBalsaServer *server, const gchar * path)
}
static gint
-find_url(GtkTreeModel * model, GtkTreePath * path, GtkTreeIter * iter,
- BalsaFind * bf)
+find_url_func(GtkTreeModel * model, GtkTreePath * path, GtkTreeIter * iter,
+ BalsaFind * bf)
{
BalsaMailboxNode *mbnode;
LibBalsaMailbox *mailbox;
gtk_tree_model_get(model, iter, 0, &mbnode, -1);
if ((mailbox = mbnode->mailbox) && !strcmp(mailbox->url, bf->data)) {
- bf->mbnode = mbnode;
- return TRUE;
+ bf->mbnode = mbnode;
+ return TRUE;
}
g_object_unref(mbnode);
@@ -714,27 +714,94 @@ find_url(GtkTreeModel * model, GtkTreePath * path, GtkTreeIter * iter,
* looks for a mailbox node with the given url.
* returns NULL on failure; caller must unref mbnode when non-NULL.
*/
-BalsaMailboxNode *
-balsa_find_url(const gchar * url)
+
+static BalsaMailboxNode *
+find_url(const gchar * url)
{
BalsaFind bf;
- gboolean is_sub_thread = libbalsa_am_i_subthread();
-
- if (is_sub_thread)
- gdk_threads_enter();
+ gdk_threads_enter();
bf.data = url;
bf.mbnode = NULL;
if (balsa_app.mblist_tree_store)
gtk_tree_model_foreach(GTK_TREE_MODEL(balsa_app.mblist_tree_store),
- (GtkTreeModelForeachFunc) find_url, &bf);
- if (is_sub_thread)
- gdk_threads_leave();
+ (GtkTreeModelForeachFunc) find_url_func,
+ &bf);
+
+ gdk_threads_leave();
return bf.mbnode;
}
+#ifdef BALSA_USE_THREADS
+typedef struct {
+ const gchar * url;
+#if GLIB_CHECK_VERSION(2, 32, 0)
+ GMutex mutex;
+ GCond cond;
+#else /* GLIB_CHECK_VERSION(2, 32, 0) */
+ GMutex *mutex;
+ GCond *cond;
+#endif /* GLIB_CHECK_VERSION(2, 32, 0) */
+ gboolean wait;
+ BalsaMailboxNode *mbnode;
+} BalsaFindUrlInfo;
+
+static gboolean
+find_url_idle_cb(BalsaFindUrlInfo * info)
+{
+ info->mbnode = find_url(info->url);
+ info->wait = FALSE;
+
+#if GLIB_CHECK_VERSION(2, 32, 0)
+ g_cond_signal(&info->cond);
+#else /* GLIB_CHECK_VERSION(2, 32, 0) */
+ g_cond_signal(info->cond);
+#endif /* GLIB_CHECK_VERSION(2, 32, 0) */
+
+ return FALSE;
+}
+#endif /* BALSA_USE_THREADS */
+
+BalsaMailboxNode *
+balsa_find_url(const gchar * url)
+{
+#ifdef BALSA_USE_THREADS
+ if (libbalsa_am_i_subthread()) {
+ BalsaFindUrlInfo info;
+
+ info.url = url;
+ info.wait = TRUE;
+#if GLIB_CHECK_VERSION(2, 32, 0)
+ g_mutex_init(&info.mutex);
+ g_cond_init(&info.cond);
+ g_mutex_lock(&info.mutex);
+ g_idle_add((GSourceFunc) find_url_idle_cb, &info);
+ while (info.wait)
+ g_cond_wait(&info.cond, &info.mutex);
+ g_mutex_unlock(&info.mutex);
+ g_mutex_clear(&info.mutex);
+ g_cond_clear(&info.cond);
+#else /* GLIB_CHECK_VERSION(2, 32, 0) */
+ info.mutex = g_mutex_new();
+ info.cond = g_cond_new();
+ g_mutex_lock(info.mutex);
+ g_idle_add((GSourceFunc) find_url_idle_cb, &info);
+ while (info.wait)
+ g_cond_wait(info.cond, info.mutex);
+ g_mutex_unlock(info.mutex);
+ g_mutex_free(info.mutex);
+ g_cond_free(info.cond);
+#endif /* GLIB_CHECK_VERSION(2, 32, 0) */
+ return info.mbnode;
+ } else
+ return find_url(url);
+#else /* BALSA_USE_THREADS */
+ return find_url(url);
+#endif /* BALSA_USE_THREADS */
+}
+
/* balsa_find_mailbox_by_url:
* looks for a mailbox with the given url.
* returns NULL on failure
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]