[gnome-control-center] background: Async function for loading XML wallpapers
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] background: Async function for loading XML wallpapers
- Date: Thu, 10 Feb 2011 12:12:49 +0000 (UTC)
commit 7b287b8c03f3c272711239d9c4c2546d53ebe6bf
Author: Bastien Nocera <hadess hadess net>
Date: Thu Feb 10 12:01:17 2011 +0000
background: Async function for loading XML wallpapers
It's ugly API, but it means we don't block anymore.
panels/background/bg-wallpapers-source.c | 28 +++++++++++++++-------
panels/background/gnome-wp-xml.c | 37 ++++++++++++++++++++++++++++++
panels/background/gnome-wp-xml.h | 10 ++++++++
3 files changed, 66 insertions(+), 9 deletions(-)
---
diff --git a/panels/background/bg-wallpapers-source.c b/panels/background/bg-wallpapers-source.c
index 8b76007..c9a95d5 100644
--- a/panels/background/bg-wallpapers-source.c
+++ b/panels/background/bg-wallpapers-source.c
@@ -194,6 +194,24 @@ load_wallpapers (gchar *key,
gtk_tree_path_free (path);
}
+static void
+list_load_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ BgWallpapersSource *self = (BgWallpapersSource *) user_data;
+ GnomeWpXml *wp_xml;
+
+ wp_xml = gnome_wp_xml_load_list_finish (res);
+ g_hash_table_foreach (wp_xml->wp_hash,
+ (GHFunc) load_wallpapers,
+ self);
+
+ g_hash_table_destroy (wp_xml->wp_hash);
+ g_object_unref (wp_xml->settings);
+ g_free (wp_xml);
+}
+
static gboolean
reload_wallpapers (BgWallpapersSource *self)
{
@@ -208,15 +226,7 @@ reload_wallpapers (BgWallpapersSource *self)
wp_xml->thumb_height = THUMBNAIL_HEIGHT;
wp_xml->thumb_factory = self->priv->thumb_factory;
- gnome_wp_xml_load_list (wp_xml);
- g_hash_table_foreach (wp_xml->wp_hash,
- (GHFunc) load_wallpapers,
- self);
-
- g_hash_table_destroy (wp_xml->wp_hash);
- g_object_unref (wp_xml->settings);
- g_free (wp_xml);
-
+ gnome_wp_xml_load_list_async (wp_xml, NULL, list_load_cb, self);
self->priv->reload_id = 0;
return FALSE;
diff --git a/panels/background/gnome-wp-xml.c b/panels/background/gnome-wp-xml.c
index 46bddc2..2783226 100644
--- a/panels/background/gnome-wp-xml.c
+++ b/panels/background/gnome-wp-xml.c
@@ -318,6 +318,43 @@ void gnome_wp_xml_load_list (GnomeWpXml *data) {
}
}
+GnomeWpXml *
+gnome_wp_xml_load_list_finish (GAsyncResult *async_result)
+{
+ GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (async_result);
+
+ g_return_val_if_fail (G_IS_ASYNC_RESULT (async_result), NULL);
+ g_warn_if_fail (g_simple_async_result_get_source_tag (result) == gnome_wp_xml_load_list_async);
+
+ return g_simple_async_result_get_op_res_gpointer (result);
+}
+
+static void
+load_list_thread (GSimpleAsyncResult *res,
+ GObject *object,
+ GCancellable *cancellable)
+{
+ GnomeWpXml *data;
+
+ data = g_simple_async_result_get_op_res_gpointer (res);
+ gnome_wp_xml_load_list (data);
+}
+
+void gnome_wp_xml_load_list_async (GnomeWpXml *data,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ g_return_if_fail (data != NULL);
+
+ result = g_simple_async_result_new (NULL, callback, user_data, gnome_wp_xml_load_list_async);
+ g_simple_async_result_set_op_res_gpointer (result, data, NULL);
+ g_simple_async_result_run_in_thread (result, (GSimpleAsyncThreadFunc) load_list_thread, G_PRIORITY_LOW, cancellable);
+ g_object_unref (result);
+}
+
static void gnome_wp_list_flatten (const gchar * key, GnomeWPItem * item,
GSList ** list) {
g_return_if_fail (key != NULL);
diff --git a/panels/background/gnome-wp-xml.h b/panels/background/gnome-wp-xml.h
index 2140a61..178e2cb 100644
--- a/panels/background/gnome-wp-xml.h
+++ b/panels/background/gnome-wp-xml.h
@@ -22,6 +22,7 @@
#define _GNOME_WP_XML_H_
#include <libgnome-desktop/gnome-desktop-thumbnail.h>
+#include <gio/gio.h>
typedef struct _GnomeWpXml GnomeWpXml;
@@ -37,6 +38,15 @@ struct _GnomeWpXml
void gnome_wp_xml_load_list (GnomeWpXml *data);
void gnome_wp_xml_save_list (GnomeWpXml *data);
+/* FIXME this should be an iterator instead, so the bg
+ * pops up as soon as a new one is available */
+void gnome_wp_xml_load_list_async (GnomeWpXml *data,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+/* FIXME, this is ugly API, which wouldn't be
+ * needed if this was an object */
+GnomeWpXml *gnome_wp_xml_load_list_finish (GAsyncResult *async_result);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]