background: Async function for loading XML wallpapers
It's ugly API, but it means we don't block anymore.
This commit is contained in:
parent
1416e68b92
commit
7b287b8c03
3 changed files with 66 additions and 9 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue