[gnome-control-center] background: GnomeWpXml to CcBackgroundXml
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] background: GnomeWpXml to CcBackgroundXml
- Date: Sat, 12 Feb 2011 03:14:23 +0000 (UTC)
commit 415d4c111191a419dd901d61b85425f95520625e
Author: Bastien Nocera <hadess hadess net>
Date: Sat Feb 12 02:01:23 2011 +0000
background: GnomeWpXml to CcBackgroundXml
and into a GObject.
panels/background/Makefile.am | 8 +-
panels/background/bg-wallpapers-source.c | 38 ++----
.../{gnome-wp-xml.c => cc-background-xml.c} | 152 ++++++++++++++-----
panels/background/cc-background-xml.h | 67 +++++++++
panels/background/gnome-wp-xml.h | 52 -------
5 files changed, 194 insertions(+), 123 deletions(-)
---
diff --git a/panels/background/Makefile.am b/panels/background/Makefile.am
index 687edf3..9ac3741 100644
--- a/panels/background/Makefile.am
+++ b/panels/background/Makefile.am
@@ -33,12 +33,14 @@ BUILT_SOURCES = \
gdesktop-enums-types.h
libbackground_la_SOURCES = \
- $(BUILT_SOURCES) \
+ $(BUILT_SOURCES) \
background-module.c \
cc-background-panel.c \
cc-background-panel.h \
cc-background-item.c \
cc-background-item.h \
+ cc-background-xml.c \
+ cc-background-xml.h \
bg-source.c \
bg-source.h \
bg-pictures-source.c \
@@ -46,9 +48,7 @@ libbackground_la_SOURCES = \
bg-wallpapers-source.c \
bg-wallpapers-source.h \
bg-colors-source.c \
- bg-colors-source.h \
- gnome-wp-xml.c \
- gnome-wp-xml.h
+ bg-colors-source.h
libbackground_la_LIBADD = \
diff --git a/panels/background/bg-wallpapers-source.c b/panels/background/bg-wallpapers-source.c
index 4f8dfa5..c202f9b 100644
--- a/panels/background/bg-wallpapers-source.c
+++ b/panels/background/bg-wallpapers-source.c
@@ -24,7 +24,7 @@
#include "bg-wallpapers-source.h"
#include "cc-background-item.h"
-#include "gnome-wp-xml.h"
+#include "cc-background-xml.h"
#include <libgnome-desktop/gnome-desktop-thumbnail.h>
#include <gio/gio.h>
@@ -38,7 +38,6 @@ struct _BgWallpapersSourcePrivate
{
GtkListStore *store;
GnomeDesktopThumbnailFactory *thumb_factory;
- guint reload_id;
};
@@ -79,12 +78,6 @@ bg_wallpapers_source_dispose (GObject *object)
priv->thumb_factory = NULL;
}
- if (priv->reload_id != 0)
- {
- g_source_remove (priv->reload_id);
- priv->reload_id = 0;
- }
-
G_OBJECT_CLASS (bg_wallpapers_source_parent_class)->dispose (object);
}
@@ -114,7 +107,6 @@ load_wallpapers (gchar *key,
{
BgWallpapersSourcePrivate *priv = source->priv;
GtkTreeIter iter;
-// GtkTreePath *path;
GIcon *pixbuf;
GtkListStore *store = bg_source_get_liststore (BG_SOURCE (source));
gboolean deleted;
@@ -127,11 +119,11 @@ load_wallpapers (gchar *key,
gtk_list_store_append (store, &iter);
pixbuf = cc_background_item_get_thumbnail (item, priv->thumb_factory,
- THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
+ THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
gtk_list_store_set (store, &iter,
0, pixbuf,
- 1, item,
+ 1, g_object_ref (item),
-1);
if (pixbuf)
@@ -144,32 +136,24 @@ list_load_cb (GObject *source_object,
gpointer user_data)
{
BgWallpapersSource *self = (BgWallpapersSource *) user_data;
- GnomeWpXml *wp_xml;
+ const GHashTable *ht;
- wp_xml = gnome_wp_xml_load_list_finish (res);
- g_hash_table_foreach (wp_xml->wp_hash,
+ ht = cc_background_xml_load_list_finish (res);
+ g_hash_table_foreach ((GHashTable *) ht,
(GHFunc) load_wallpapers,
self);
- g_hash_table_destroy (wp_xml->wp_hash);
- g_free (wp_xml);
+ g_object_unref (source_object);
}
static gboolean
reload_wallpapers (BgWallpapersSource *self)
{
- GnomeWpXml *wp_xml;
+ CcBackgroundXml *wp_xml;
/* set up wallpaper source */
- wp_xml = g_new0 (GnomeWpXml, 1);
- wp_xml->wp_hash = g_hash_table_new (g_str_hash, g_str_equal);
- wp_xml->wp_model = bg_source_get_liststore (BG_SOURCE (self));
- wp_xml->thumb_width = THUMBNAIL_WIDTH;
- wp_xml->thumb_height = THUMBNAIL_HEIGHT;
- wp_xml->thumb_factory = self->priv->thumb_factory;
-
- gnome_wp_xml_load_list_async (wp_xml, NULL, list_load_cb, self);
- self->priv->reload_id = 0;
+ wp_xml = cc_background_xml_new ();
+ cc_background_xml_load_list_async (wp_xml, NULL, list_load_cb, self);
return FALSE;
}
@@ -184,7 +168,7 @@ bg_wallpapers_source_init (BgWallpapersSource *self)
priv->thumb_factory =
gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL);
- priv->reload_id = g_idle_add ((GSourceFunc)reload_wallpapers, self);
+ reload_wallpapers (self);
}
BgWallpapersSource *
diff --git a/panels/background/gnome-wp-xml.c b/panels/background/cc-background-xml.c
similarity index 76%
rename from panels/background/gnome-wp-xml.c
rename to panels/background/cc-background-xml.c
index 5860f32..1292b0c 100644
--- a/panels/background/gnome-wp-xml.c
+++ b/panels/background/cc-background-xml.c
@@ -1,7 +1,9 @@
/*
* Authors: Rodney Dawes <dobey ximian com>
+ * Bastien Nocera <hadess hadess net>
*
* Copyright 2003-2006 Novell, Inc. (www.novell.com)
+ * Copyright 2011 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License
@@ -26,10 +28,25 @@
#include "gdesktop-enums-types.h"
#include "cc-background-item.h"
-#include "gnome-wp-xml.h"
+#include "cc-background-xml.h"
-static gboolean gnome_wp_xml_get_bool (const xmlNode * parent,
- const gchar * prop_name) {
+struct CcBackgroundXmlPrivate
+{
+ GHashTable *wp_hash;
+};
+
+#define CC_BACKGROUND_XML_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_BACKGROUND_XML, CcBackgroundXmlPrivate))
+
+static void cc_background_xml_class_init (CcBackgroundXmlClass *klass);
+static void cc_background_xml_init (CcBackgroundXml *background_item);
+static void cc_background_xml_finalize (GObject *object);
+
+G_DEFINE_TYPE (CcBackgroundXml, cc_background_xml, G_TYPE_OBJECT)
+
+static gboolean
+cc_background_xml_get_bool (const xmlNode *parent,
+ const gchar *prop_name)
+{
xmlChar * prop;
gboolean ret_val = FALSE;
@@ -50,7 +67,7 @@ static gboolean gnome_wp_xml_get_bool (const xmlNode * parent,
}
#if 0
-static void gnome_wp_xml_set_bool (const xmlNode * parent,
+static void cc_background_xml_set_bool (const xmlNode * parent,
const xmlChar * prop_name, gboolean value) {
g_return_if_fail (parent != NULL);
g_return_if_fail (prop_name != NULL);
@@ -100,8 +117,10 @@ enum_string_to_value (GType type,
#define UNSET_FLAG(flag) G_STMT_START{ (flags&=~(flag)); }G_STMT_END
#define SET_FLAG(flag) G_STMT_START{ (flags|=flag); }G_STMT_END
-static void gnome_wp_xml_load_xml (GnomeWpXml *data,
- const gchar * filename) {
+static void
+cc_background_xml_load_xml (CcBackgroundXml *xml,
+ const gchar * filename)
+{
xmlDoc * wplist;
xmlNode * root, * list, * wpa;
xmlChar * nodelang;
@@ -128,7 +147,7 @@ static void gnome_wp_xml_load_xml (GnomeWpXml *data,
item = cc_background_item_new (NULL);
g_object_set (G_OBJECT (item),
- "is-deleted", gnome_wp_xml_get_bool (list, "deleted"),
+ "is-deleted", cc_background_xml_get_bool (list, "deleted"),
"source-xml", filename,
NULL);
@@ -221,32 +240,34 @@ static void gnome_wp_xml_load_xml (GnomeWpXml *data,
g_free (uri);
/* Make sure we don't already have this one and that filename exists */
- if (g_hash_table_lookup (data->wp_hash, id) != NULL) {
+ if (g_hash_table_lookup (xml->priv->wp_hash, id) != NULL) {
g_object_unref (item);
g_free (id);
continue;
}
g_object_set (G_OBJECT (item), "flags", flags, NULL);
- g_hash_table_insert (data->wp_hash, id, item);
+ g_hash_table_insert (xml->priv->wp_hash, id, item);
/* Don't free ID, we added it to the hash table */
}
}
xmlFreeDoc (wplist);
}
-static void gnome_wp_file_changed (GFileMonitor *monitor,
- GFile *file,
- GFile *other_file,
- GFileMonitorEvent event_type,
- GnomeWpXml *data) {
- gchar * filename;
+static void
+gnome_wp_file_changed (GFileMonitor *monitor,
+ GFile *file,
+ GFile *other_file,
+ GFileMonitorEvent event_type,
+ CcBackgroundXml *data)
+{
+ gchar *filename;
switch (event_type) {
case G_FILE_MONITOR_EVENT_CHANGED:
case G_FILE_MONITOR_EVENT_CREATED:
filename = g_file_get_path (file);
- gnome_wp_xml_load_xml (data, filename);
+ cc_background_xml_load_xml (data, filename);
g_free (filename);
break;
default:
@@ -254,8 +275,10 @@ static void gnome_wp_file_changed (GFileMonitor *monitor,
}
}
-static void gnome_wp_xml_add_monitor (GFile *directory,
- GnomeWpXml *data) {
+static void
+cc_background_xml_add_monitor (GFile *directory,
+ CcBackgroundXml *data)
+{
GFileMonitor *monitor;
GError *error = NULL;
@@ -279,8 +302,10 @@ static void gnome_wp_xml_add_monitor (GFile *directory,
data);
}
-static void gnome_wp_xml_load_from_dir (const gchar *path,
- GnomeWpXml *data) {
+static void
+cc_background_xml_load_from_dir (const gchar *path,
+ CcBackgroundXml *data)
+{
GFile *directory;
GFileEnumerator *enumerator;
GError *error = NULL;
@@ -311,18 +336,20 @@ static void gnome_wp_xml_load_from_dir (const gchar *path,
fullpath = g_build_filename (path, filename, NULL);
g_object_unref (info);
- gnome_wp_xml_load_xml (data, fullpath);
+ cc_background_xml_load_xml (data, fullpath);
g_free (fullpath);
}
g_file_enumerator_close (enumerator, NULL, NULL);
- gnome_wp_xml_add_monitor (directory, data);
+ cc_background_xml_add_monitor (directory, data);
g_object_unref (directory);
g_object_unref (enumerator);
}
-void gnome_wp_xml_load_list (GnomeWpXml *data) {
+static void
+cc_background_xml_load_list (CcBackgroundXml *data)
+{
const char * const *system_data_dirs;
gchar * datadir;
gint i;
@@ -330,7 +357,7 @@ void gnome_wp_xml_load_list (GnomeWpXml *data) {
datadir = g_build_filename (g_get_user_data_dir (),
"gnome-background-properties",
NULL);
- gnome_wp_xml_load_from_dir (datadir, data);
+ cc_background_xml_load_from_dir (datadir, data);
g_free (datadir);
system_data_dirs = g_get_system_data_dirs ();
@@ -338,20 +365,22 @@ void gnome_wp_xml_load_list (GnomeWpXml *data) {
datadir = g_build_filename (system_data_dirs[i],
"gnome-background-properties",
NULL);
- gnome_wp_xml_load_from_dir (datadir, data);
+ cc_background_xml_load_from_dir (datadir, data);
g_free (datadir);
}
}
-GnomeWpXml *
-gnome_wp_xml_load_list_finish (GAsyncResult *async_result)
+const GHashTable *
+cc_background_xml_load_list_finish (GAsyncResult *async_result)
{
GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (async_result);
+ CcBackgroundXml *data;
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);
+ g_warn_if_fail (g_simple_async_result_get_source_tag (result) == cc_background_xml_load_list_async);
- return g_simple_async_result_get_op_res_gpointer (result);
+ data = CC_BACKGROUND_XML (g_simple_async_result_get_op_res_gpointer (result));
+ return data->priv->wp_hash;
}
static void
@@ -359,29 +388,29 @@ load_list_thread (GSimpleAsyncResult *res,
GObject *object,
GCancellable *cancellable)
{
- GnomeWpXml *data;
+ CcBackgroundXml *data;
data = g_simple_async_result_get_op_res_gpointer (res);
- gnome_wp_xml_load_list (data);
+ cc_background_xml_load_list (data);
}
-void gnome_wp_xml_load_list_async (GnomeWpXml *data,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+void cc_background_xml_load_list_async (CcBackgroundXml *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);
+ result = g_simple_async_result_new (G_OBJECT (data), callback, user_data, cc_background_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);
}
#if 0
-static void gnome_wp_list_flatten (const gchar * key, CcBackgroundItem * item,
+static void gnome_wp_list_flatten (const gchar * key, CcBackgroundXml * item,
GSList ** list) {
g_return_if_fail (key != NULL);
g_return_if_fail (item != NULL);
@@ -389,7 +418,7 @@ static void gnome_wp_list_flatten (const gchar * key, CcBackgroundItem * item,
*list = g_slist_prepend (*list, item);
}
#endif
-void gnome_wp_xml_save_list (GnomeWpXml *data) {
+void cc_background_xml_save_list (CcBackgroundXml *data) {
//FIXME implement save or remove?
#if 0
xmlDoc * wplist;
@@ -415,7 +444,7 @@ void gnome_wp_xml_save_list (GnomeWpXml *data) {
xmlDocSetRootElement (wplist, root);
while (list != NULL) {
- CcBackgroundItem * wpitem = list->data;
+ CcBackgroundXml * wpitem = list->data;
const char * none = "(none)";
gchar * filename;
const gchar * scale, * shade;
@@ -434,7 +463,7 @@ void gnome_wp_xml_save_list (GnomeWpXml *data) {
shade = wp_item_shading_to_string (wpitem->shade_type);
wallpaper = xmlNewChild (root, NULL, (xmlChar *)"wallpaper", NULL);
- gnome_wp_xml_set_bool (wallpaper, (xmlChar *)"deleted", wpitem->deleted);
+ cc_background_xml_set_bool (wallpaper, (xmlChar *)"deleted", wpitem->deleted);
item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"name", (xmlChar *)wpitem->name);
item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"filename", (xmlChar *)filename);
item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"options", (xmlChar *)scale);
@@ -454,3 +483,46 @@ void gnome_wp_xml_save_list (GnomeWpXml *data) {
#endif
}
+static void
+cc_background_xml_finalize (GObject *object)
+{
+ CcBackgroundXml *xml;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (CC_IS_BACKGROUND_XML (object));
+
+ xml = CC_BACKGROUND_XML (object);
+
+ g_return_if_fail (xml->priv != NULL);
+
+ if (xml->priv->wp_hash) {
+ g_hash_table_destroy (xml->priv->wp_hash);
+ xml->priv->wp_hash = NULL;
+ }
+}
+
+static void
+cc_background_xml_class_init (CcBackgroundXmlClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = cc_background_xml_finalize;
+
+ g_type_class_add_private (klass, sizeof (CcBackgroundXmlPrivate));
+}
+
+static void
+cc_background_xml_init (CcBackgroundXml *xml)
+{
+ xml->priv = CC_BACKGROUND_XML_GET_PRIVATE (xml);
+ xml->priv->wp_hash = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) g_object_unref);
+}
+
+CcBackgroundXml *
+cc_background_xml_new (void)
+{
+ return CC_BACKGROUND_XML (g_object_new (CC_TYPE_BACKGROUND_XML, NULL));
+}
diff --git a/panels/background/cc-background-xml.h b/panels/background/cc-background-xml.h
new file mode 100644
index 0000000..f302e0d
--- /dev/null
+++ b/panels/background/cc-background-xml.h
@@ -0,0 +1,67 @@
+/*
+ * Authors: Rodney Dawes <dobey ximian com>
+ *
+ * Copyright 2003-2006 Novell, Inc. (www.novell.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef _CC_BACKGROUND_XML_H_
+#define _CC_BACKGROUND_XML_H_
+
+#include <libgnome-desktop/gnome-desktop-thumbnail.h>
+#include <gtk/gtk.h>
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define CC_TYPE_BACKGROUND_XML (cc_background_xml_get_type ())
+#define CC_BACKGROUND_XML(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CC_TYPE_BACKGROUND_XML, CcBackgroundXml))
+#define CC_BACKGROUND_XML_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), CC_TYPE_BACKGROUND_XML, CcBackgroundXmlClass))
+#define CC_IS_BACKGROUND_XML(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CC_TYPE_BACKGROUND_XML))
+#define CC_IS_BACKGROUND_XML_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CC_TYPE_BACKGROUND_XML))
+#define CC_BACKGROUND_XML_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CC_TYPE_BACKGROUND_XML, CcBackgroundXmlClass))
+
+typedef struct CcBackgroundXmlPrivate CcBackgroundXmlPrivate;
+
+typedef struct
+{
+ GObjectClass parent_class;
+} CcBackgroundXmlClass;
+
+typedef struct
+{
+ GObject parent;
+ CcBackgroundXmlPrivate *priv;
+} CcBackgroundXml;
+
+GType cc_background_xml_get_type (void);
+
+CcBackgroundXml *cc_background_xml_new (void);
+void cc_background_xml_save_list (CcBackgroundXml *data);
+/* FIXME this should be an iterator instead, so the bg
+ * pops up as soon as a new one is available */
+void cc_background_xml_load_list_async (CcBackgroundXml *data,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+/* FIXME, this is ugly API, which wouldn't be
+ * needed if this was an object */
+const GHashTable *cc_background_xml_load_list_finish (GAsyncResult *async_result);
+
+G_END_DECLS
+
+#endif
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]