background: Use G_DEFINE_TYPE

This commit is contained in:
Robert Ancell 2017-09-25 14:16:09 -04:00
parent 045b1f03b9
commit 378e837a06
18 changed files with 441 additions and 760 deletions

View file

@ -28,10 +28,12 @@
#include <glib/gi18n-lib.h>
#include <gdesktop-enums.h>
G_DEFINE_TYPE (BgColorsSource, bg_colors_source, BG_TYPE_SOURCE)
struct _BgColorsSource
{
BgSource parent_instance;
};
#define COLORS_SOURCE_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), BG_TYPE_COLORS_SOURCE, BgColorsSourcePrivate))
G_DEFINE_TYPE (BgColorsSource, bg_colors_source, BG_TYPE_SOURCE)
struct {
GDesktopBackgroundShading type;

View file

@ -27,42 +27,8 @@
G_BEGIN_DECLS
#define BG_TYPE_COLORS_SOURCE bg_colors_source_get_type()
#define BG_COLORS_SOURCE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
BG_TYPE_COLORS_SOURCE, BgColorsSource))
#define BG_COLORS_SOURCE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), \
BG_TYPE_COLORS_SOURCE, BgColorsSourceClass))
#define BG_IS_COLORS_SOURCE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
BG_TYPE_COLORS_SOURCE))
#define BG_IS_COLORS_SOURCE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
BG_TYPE_COLORS_SOURCE))
#define BG_COLORS_SOURCE_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
BG_TYPE_COLORS_SOURCE, BgColorsSourceClass))
typedef struct _BgColorsSource BgColorsSource;
typedef struct _BgColorsSourceClass BgColorsSourceClass;
struct _BgColorsSource
{
BgSource parent;
};
struct _BgColorsSourceClass
{
BgSourceClass parent_class;
};
GType bg_colors_source_get_type (void) G_GNUC_CONST;
#define BG_TYPE_COLORS_SOURCE (bg_colors_source_get_type ())
G_DECLARE_FINAL_TYPE (BgColorsSource, bg_colors_source, BG, COLORS_SOURCE, BgSource)
BgColorsSource *bg_colors_source_new (GtkWindow *window);

View file

@ -33,17 +33,14 @@
#include <libgnome-desktop/gnome-desktop-thumbnail.h>
#include <gdesktop-enums.h>
G_DEFINE_TYPE (BgPicturesSource, bg_pictures_source, BG_TYPE_SOURCE)
#define PICTURES_SOURCE_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), BG_TYPE_PICTURES_SOURCE, BgPicturesSourcePrivate))
#define ATTRIBUTES G_FILE_ATTRIBUTE_STANDARD_NAME "," \
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," \
G_FILE_ATTRIBUTE_TIME_MODIFIED
struct _BgPicturesSourcePrivate
struct _BgPicturesSource
{
BgSource parent_instance;
GCancellable *cancellable;
CcBackgroundGriloMiner *grl_miner;
@ -56,6 +53,8 @@ struct _BgPicturesSourcePrivate
GHashTable *known_items;
};
G_DEFINE_TYPE (BgPicturesSource, bg_pictures_source, BG_TYPE_SOURCE)
const char * const content_types[] = {
"image/png",
"image/jp2",
@ -78,16 +77,16 @@ static void picture_opened_for_read (GObject *source_object, GAsyncResult *res,
static void
bg_pictures_source_dispose (GObject *object)
{
BgPicturesSourcePrivate *priv = BG_PICTURES_SOURCE (object)->priv;
BgPicturesSource *source = BG_PICTURES_SOURCE (object);
if (priv->cancellable)
if (source->cancellable)
{
g_cancellable_cancel (priv->cancellable);
g_clear_object (&priv->cancellable);
g_cancellable_cancel (source->cancellable);
g_clear_object (&source->cancellable);
}
g_clear_object (&priv->grl_miner);
g_clear_object (&priv->thumb_factory);
g_clear_object (&source->grl_miner);
g_clear_object (&source->thumb_factory);
G_OBJECT_CLASS (bg_pictures_source_parent_class)->dispose (object);
}
@ -97,12 +96,12 @@ bg_pictures_source_finalize (GObject *object)
{
BgPicturesSource *bg_source = BG_PICTURES_SOURCE (object);
g_clear_object (&bg_source->priv->thumb_factory);
g_clear_object (&bg_source->thumb_factory);
g_clear_pointer (&bg_source->priv->known_items, g_hash_table_destroy);
g_clear_pointer (&bg_source->known_items, g_hash_table_destroy);
g_clear_object (&bg_source->priv->picture_dir_monitor);
g_clear_object (&bg_source->priv->cache_dir_monitor);
g_clear_object (&bg_source->picture_dir_monitor);
g_clear_object (&bg_source->cache_dir_monitor);
G_OBJECT_CLASS (bg_pictures_source_parent_class)->finalize (object);
}
@ -112,8 +111,6 @@ bg_pictures_source_class_init (BgPicturesSourceClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (BgPicturesSourcePrivate));
object_class->dispose = bg_pictures_source_dispose;
object_class->finalize = bg_pictures_source_finalize;
}
@ -231,7 +228,7 @@ picture_scaled (GObject *source_object,
g_object_set_data (G_OBJECT (item), "needs-rotation", GINT_TO_POINTER (TRUE));
g_object_set_data_full (G_OBJECT (file), "item", g_object_ref (item), g_object_unref);
g_file_read_async (G_FILE (file), G_PRIORITY_DEFAULT,
bg_source->priv->cancellable,
bg_source->cancellable,
picture_opened_for_read, bg_source);
g_object_unref (file);
goto out;
@ -264,7 +261,7 @@ picture_scaled (GObject *source_object,
}
}
g_hash_table_insert (bg_source->priv->known_items,
g_hash_table_insert (bg_source->known_items,
bg_pictures_source_get_unique_filename (uri),
GINT_TO_POINTER (TRUE));
@ -326,7 +323,7 @@ picture_opened_for_read (GObject *source_object,
gdk_pixbuf_new_from_stream_at_scale_async (G_INPUT_STREAM (stream),
thumbnail_width, thumbnail_height,
TRUE,
bg_source->priv->cancellable,
bg_source->cancellable,
picture_scaled, bg_source);
g_object_unref (stream);
}
@ -364,7 +361,7 @@ picture_copied_for_read (GObject *source_object,
g_object_set_data_full (G_OBJECT (native_file), "item", g_object_ref (item), g_object_unref);
g_file_read_async (native_file,
G_PRIORITY_DEFAULT,
bg_source->priv->cancellable,
bg_source->cancellable,
picture_opened_for_read,
bg_source);
@ -543,7 +540,7 @@ add_single_file (BgPicturesSource *bg_source,
{
g_object_set_data_full (G_OBJECT (file), "item", g_object_ref (item), g_object_unref);
g_file_read_async (file, G_PRIORITY_DEFAULT,
bg_source->priv->cancellable,
bg_source->cancellable,
picture_opened_for_read, bg_source);
}
else
@ -576,7 +573,7 @@ add_single_file (BgPicturesSource *bg_source,
native_file,
G_FILE_COPY_ALL_METADATA,
G_PRIORITY_DEFAULT,
bg_source->priv->cancellable,
bg_source->cancellable,
NULL,
NULL,
picture_copied_for_read,
@ -689,7 +686,7 @@ bg_pictures_source_remove (BgPicturesSource *bg_source,
{
char *uuid;
uuid = bg_pictures_source_get_unique_filename (uri);
g_hash_table_insert (bg_source->priv->known_items,
g_hash_table_insert (bg_source->known_items,
uuid, NULL);
gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
@ -763,15 +760,15 @@ file_info_async_ready (GObject *source,
}
static void
dir_enum_async_ready (GObject *source,
dir_enum_async_ready (GObject *s,
GAsyncResult *res,
gpointer user_data)
{
BgPicturesSourcePrivate *priv;
BgPicturesSource *source = (BgPicturesSource *) user_data;
GFileEnumerator *enumerator;
GError *err = NULL;
enumerator = g_file_enumerate_children_finish (G_FILE (source), res, &err);
enumerator = g_file_enumerate_children_finish (G_FILE (s), res, &err);
if (err)
{
@ -781,13 +778,11 @@ dir_enum_async_ready (GObject *source,
return;
}
priv = BG_PICTURES_SOURCE (user_data)->priv;
/* get the files */
g_file_enumerator_next_files_async (enumerator,
G_MAXINT,
G_PRIORITY_LOW,
priv->cancellable,
source->cancellable,
file_info_async_ready,
user_data);
g_object_unref (enumerator);
@ -846,7 +841,7 @@ bg_pictures_source_is_known (BgPicturesSource *bg_source,
char *uuid;
uuid = bg_pictures_source_get_unique_filename (uri);
retval = (GPOINTER_TO_INT (g_hash_table_lookup (bg_source->priv->known_items, uuid)));
retval = (GPOINTER_TO_INT (g_hash_table_lookup (bg_source->known_items, uuid)));
g_free (uuid);
return retval;
@ -969,12 +964,12 @@ monitor_path (BgPicturesSource *self,
g_file_enumerate_children_async (dir,
ATTRIBUTES,
G_FILE_QUERY_INFO_NONE,
G_PRIORITY_LOW, self->priv->cancellable,
G_PRIORITY_LOW, self->cancellable,
dir_enum_async_ready, self);
monitor = g_file_monitor_directory (dir,
G_FILE_MONITOR_NONE,
self->priv->cancellable,
self->cancellable,
NULL);
if (monitor)
@ -1004,14 +999,11 @@ static void
bg_pictures_source_init (BgPicturesSource *self)
{
const gchar *pictures_path;
BgPicturesSourcePrivate *priv;
char *cache_path;
GtkListStore *store;
priv = self->priv = PICTURES_SOURCE_PRIVATE (self);
priv->cancellable = g_cancellable_new ();
priv->known_items = g_hash_table_new_full (g_str_hash,
self->cancellable = g_cancellable_new ();
self->known_items = g_hash_table_new_full (g_str_hash,
g_str_equal,
(GDestroyNotify) g_free,
NULL);
@ -1020,17 +1012,17 @@ bg_pictures_source_init (BgPicturesSource *self)
if (pictures_path == NULL)
pictures_path = g_get_home_dir ();
priv->picture_dir_monitor = monitor_path (self, pictures_path);
self->picture_dir_monitor = monitor_path (self, pictures_path);
cache_path = bg_pictures_source_get_cache_path ();
priv->cache_dir_monitor = monitor_path (self, cache_path);
self->cache_dir_monitor = monitor_path (self, cache_path);
g_free (cache_path);
priv->grl_miner = cc_background_grilo_miner_new ();
g_signal_connect_swapped (priv->grl_miner, "media-found", G_CALLBACK (media_found_cb), self);
cc_background_grilo_miner_start (priv->grl_miner);
self->grl_miner = cc_background_grilo_miner_new ();
g_signal_connect_swapped (self->grl_miner, "media-found", G_CALLBACK (media_found_cb), self);
cc_background_grilo_miner_start (self->grl_miner);
priv->thumb_factory =
self->thumb_factory =
gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
store = bg_source_get_liststore (BG_SOURCE (self));

View file

@ -29,45 +29,8 @@
G_BEGIN_DECLS
#define BG_TYPE_PICTURES_SOURCE bg_pictures_source_get_type()
#define BG_PICTURES_SOURCE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
BG_TYPE_PICTURES_SOURCE, BgPicturesSource))
#define BG_PICTURES_SOURCE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), \
BG_TYPE_PICTURES_SOURCE, BgPicturesSourceClass))
#define BG_IS_PICTURES_SOURCE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
BG_TYPE_PICTURES_SOURCE))
#define BG_IS_PICTURES_SOURCE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
BG_TYPE_PICTURES_SOURCE))
#define BG_PICTURES_SOURCE_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
BG_TYPE_PICTURES_SOURCE, BgPicturesSourceClass))
typedef struct _BgPicturesSource BgPicturesSource;
typedef struct _BgPicturesSourceClass BgPicturesSourceClass;
typedef struct _BgPicturesSourcePrivate BgPicturesSourcePrivate;
struct _BgPicturesSource
{
BgSource parent;
BgPicturesSourcePrivate *priv;
};
struct _BgPicturesSourceClass
{
BgSourceClass parent_class;
};
GType bg_pictures_source_get_type (void) G_GNUC_CONST;
#define BG_TYPE_PICTURES_SOURCE (bg_pictures_source_get_type ())
G_DECLARE_FINAL_TYPE (BgPicturesSource, bg_pictures_source, BG, PICTURES_SOURCE, BgSource)
BgPicturesSource *bg_pictures_source_new (GtkWindow *window);
char *bg_pictures_source_get_cache_path (void);

View file

@ -26,18 +26,15 @@
#define THUMBNAIL_WIDTH 256
#define THUMBNAIL_HEIGHT (THUMBNAIL_WIDTH * 3 / 4)
G_DEFINE_ABSTRACT_TYPE (BgSource, bg_source, G_TYPE_OBJECT)
#define SOURCE_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), BG_TYPE_SOURCE, BgSourcePrivate))
struct _BgSourcePrivate
typedef struct
{
GtkListStore *store;
GtkWidget *window;
gint thumbnail_height;
gint thumbnail_width;
};
} BgSourcePrivate;
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (BgSource, bg_source, G_TYPE_OBJECT)
enum
{
@ -49,7 +46,7 @@ enum
static void
bg_source_calculate_thumbnail_dimensions (BgSource *source)
{
BgSourcePrivate *priv = source->priv;
BgSourcePrivate *priv = bg_source_get_instance_private (source);
gint scale_factor;
priv->thumbnail_height = THUMBNAIL_HEIGHT;
@ -99,7 +96,8 @@ bg_source_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
BgSourcePrivate *priv = BG_SOURCE (object)->priv;
BgSource *source = BG_SOURCE (object);
BgSourcePrivate *priv = bg_source_get_instance_private (source);
switch (property_id)
{
@ -115,7 +113,8 @@ bg_source_set_property (GObject *object,
static void
bg_source_dispose (GObject *object)
{
BgSourcePrivate *priv = BG_SOURCE (object)->priv;
BgSource *source = BG_SOURCE (object);
BgSourcePrivate *priv = bg_source_get_instance_private (source);
g_clear_object (&priv->store);
@ -128,8 +127,6 @@ bg_source_class_init (BgSourceClass *klass)
GParamSpec *pspec;
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (BgSourcePrivate));
object_class->constructed = bg_source_constructed;
object_class->get_property = bg_source_get_property;
object_class->set_property = bg_source_set_property;
@ -153,41 +150,50 @@ bg_source_class_init (BgSourceClass *klass)
static void
bg_source_init (BgSource *self)
{
BgSourcePrivate *priv;
priv = self->priv = SOURCE_PRIVATE (self);
BgSourcePrivate *priv = bg_source_get_instance_private (self);
priv->store = gtk_list_store_new (3, CAIRO_GOBJECT_TYPE_SURFACE, G_TYPE_OBJECT, G_TYPE_STRING);
}
GtkListStore*
bg_source_get_liststore (BgSource *source)
{
BgSourcePrivate *priv;
g_return_val_if_fail (BG_IS_SOURCE (source), NULL);
return source->priv->store;
priv = bg_source_get_instance_private (source);
return priv->store;
}
gint
bg_source_get_scale_factor (BgSource *source)
{
BgSourcePrivate *priv;
g_return_val_if_fail (BG_IS_SOURCE (source), 1);
return gtk_widget_get_scale_factor (source->priv->window);
priv = bg_source_get_instance_private (source);
return gtk_widget_get_scale_factor (priv->window);
}
gint
bg_source_get_thumbnail_height (BgSource *source)
{
BgSourcePrivate *priv;
g_return_val_if_fail (BG_IS_SOURCE (source), THUMBNAIL_HEIGHT);
return source->priv->thumbnail_height;
priv = bg_source_get_instance_private (source);
return priv->thumbnail_height;
}
gint
bg_source_get_thumbnail_width (BgSource *source)
{
BgSourcePrivate *priv;
g_return_val_if_fail (BG_IS_SOURCE (source), THUMBNAIL_WIDTH);
return source->priv->thumbnail_width;
priv = bg_source_get_instance_private (source);
return priv->thumbnail_width;
}

View file

@ -25,46 +25,14 @@
G_BEGIN_DECLS
#define BG_TYPE_SOURCE bg_source_get_type()
#define BG_SOURCE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
BG_TYPE_SOURCE, BgSource))
#define BG_SOURCE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), \
BG_TYPE_SOURCE, BgSourceClass))
#define BG_IS_SOURCE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
BG_TYPE_SOURCE))
#define BG_IS_SOURCE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
BG_TYPE_SOURCE))
#define BG_SOURCE_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
BG_TYPE_SOURCE, BgSourceClass))
typedef struct _BgSource BgSource;
typedef struct _BgSourceClass BgSourceClass;
typedef struct _BgSourcePrivate BgSourcePrivate;
struct _BgSource
{
GObject parent;
BgSourcePrivate *priv;
};
#define BG_TYPE_SOURCE (bg_source_get_type ())
G_DECLARE_DERIVABLE_TYPE (BgSource, bg_source, BG, SOURCE, GObject)
struct _BgSourceClass
{
GObjectClass parent_class;
};
GType bg_source_get_type (void) G_GNUC_CONST;
GtkListStore* bg_source_get_liststore (BgSource *source);
gint bg_source_get_scale_factor (BgSource *source);

View file

@ -19,7 +19,6 @@
*
*/
#include "bg-wallpapers-source.h"
#include "cc-background-item.h"
@ -29,24 +28,20 @@
#include <libgnome-desktop/gnome-desktop-thumbnail.h>
#include <gio/gio.h>
G_DEFINE_TYPE (BgWallpapersSource, bg_wallpapers_source, BG_TYPE_SOURCE)
#define WALLPAPERS_SOURCE_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), BG_TYPE_WALLPAPERS_SOURCE, BgWallpapersSourcePrivate))
struct _BgWallpapersSourcePrivate
struct _BgWallpapersSource
{
BgSource parent_instance;
GnomeDesktopThumbnailFactory *thumb_factory;
CcBackgroundXml *xml;
};
G_DEFINE_TYPE (BgWallpapersSource, bg_wallpapers_source, BG_TYPE_SOURCE)
static void
load_wallpapers (gchar *key,
CcBackgroundItem *item,
BgWallpapersSource *source)
{
BgWallpapersSourcePrivate *priv = source->priv;
GtkTreeIter iter;
GdkPixbuf *pixbuf;
GtkListStore *store = bg_source_get_liststore (BG_SOURCE (source));
@ -66,7 +61,7 @@ load_wallpapers (gchar *key,
scale_factor = bg_source_get_scale_factor (BG_SOURCE (source));
thumbnail_height = bg_source_get_thumbnail_height (BG_SOURCE (source));
thumbnail_width = bg_source_get_thumbnail_width (BG_SOURCE (source));
pixbuf = cc_background_item_get_thumbnail (item, priv->thumb_factory,
pixbuf = cc_background_item_get_thumbnail (item, source->thumb_factory,
thumbnail_width, thumbnail_height,
scale_factor);
if (pixbuf == NULL)
@ -116,7 +111,7 @@ load_default_bg (BgWallpapersSource *self)
"gnome-background-properties",
"adwaita.xml",
NULL);
if (cc_background_xml_load_xml (self->priv->xml, filename)) {
if (cc_background_xml_load_xml (self->xml, filename)) {
g_free (filename);
break;
}
@ -128,26 +123,25 @@ static void
bg_wallpapers_source_constructed (GObject *object)
{
BgWallpapersSource *self = BG_WALLPAPERS_SOURCE (object);
BgWallpapersSourcePrivate *priv = self->priv;
G_OBJECT_CLASS (bg_wallpapers_source_parent_class)->constructed (object);
g_signal_connect (G_OBJECT (priv->xml), "added",
g_signal_connect (G_OBJECT (self->xml), "added",
G_CALLBACK (item_added), self);
/* Try adding the default background first */
load_default_bg (self);
cc_background_xml_load_list_async (priv->xml, NULL, list_load_cb, self);
cc_background_xml_load_list_async (self->xml, NULL, list_load_cb, self);
}
static void
bg_wallpapers_source_dispose (GObject *object)
{
BgWallpapersSourcePrivate *priv = BG_WALLPAPERS_SOURCE (object)->priv;
BgWallpapersSource *self = BG_WALLPAPERS_SOURCE (object);
g_clear_object (&priv->thumb_factory);
g_clear_object (&priv->xml);
g_clear_object (&self->thumb_factory);
g_clear_object (&self->xml);
G_OBJECT_CLASS (bg_wallpapers_source_parent_class)->dispose (object);
}
@ -155,13 +149,9 @@ bg_wallpapers_source_dispose (GObject *object)
static void
bg_wallpapers_source_init (BgWallpapersSource *self)
{
BgWallpapersSourcePrivate *priv;
priv = self->priv = WALLPAPERS_SOURCE_PRIVATE (self);
priv->thumb_factory =
self->thumb_factory =
gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
priv->xml = cc_background_xml_new ();
self->xml = cc_background_xml_new ();
}
static void
@ -169,8 +159,6 @@ bg_wallpapers_source_class_init (BgWallpapersSourceClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (BgWallpapersSourcePrivate));
object_class->constructed = bg_wallpapers_source_constructed;
object_class->dispose = bg_wallpapers_source_dispose;
}

View file

@ -28,45 +28,8 @@
G_BEGIN_DECLS
#define BG_TYPE_WALLPAPERS_SOURCE bg_wallpapers_source_get_type()
#define BG_WALLPAPERS_SOURCE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
BG_TYPE_WALLPAPERS_SOURCE, BgWallpapersSource))
#define BG_WALLPAPERS_SOURCE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), \
BG_TYPE_WALLPAPERS_SOURCE, BgWallpapersSourceClass))
#define BG_IS_WALLPAPERS_SOURCE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
BG_TYPE_WALLPAPERS_SOURCE))
#define BG_IS_WALLPAPERS_SOURCE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
BG_TYPE_WALLPAPERS_SOURCE))
#define BG_WALLPAPERS_SOURCE_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
BG_TYPE_WALLPAPERS_SOURCE, BgWallpapersSourceClass))
typedef struct _BgWallpapersSource BgWallpapersSource;
typedef struct _BgWallpapersSourceClass BgWallpapersSourceClass;
typedef struct _BgWallpapersSourcePrivate BgWallpapersSourcePrivate;
struct _BgWallpapersSource
{
BgSource parent;
BgWallpapersSourcePrivate *priv;
};
struct _BgWallpapersSourceClass
{
BgSourceClass parent_class;
};
GType bg_wallpapers_source_get_type (void) G_GNUC_CONST;
#define BG_TYPE_WALLPAPERS_SOURCE (bg_wallpapers_source_get_type ())
G_DECLARE_FINAL_TYPE (BgWallpapersSource, bg_wallpapers_source, BG, WALLPAPERS_SOURCE, BgSource)
BgWallpapersSource *bg_wallpapers_source_new (GtkWindow *window);

View file

@ -44,8 +44,10 @@ enum
SOURCE_COLORS,
};
struct _CcBackgroundChooserDialogPrivate
struct _CcBackgroundChooserDialog
{
GtkDialog parent_instance;
GtkListStore *sources;
GtkWidget *stack;
GtkWidget *pictures_stack;
@ -67,7 +69,7 @@ struct _CcBackgroundChooserDialogPrivate
gulong row_modified_id;
};
#define CC_CHOOSER_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CC_TYPE_BACKGROUND_CHOOSER_DIALOG, CcBackgroundChooserDialogPrivate))
G_DEFINE_TYPE (CcBackgroundChooserDialog, cc_background_chooser_dialog, GTK_TYPE_DIALOG)
enum
{
@ -85,8 +87,6 @@ static const GtkTargetEntry color_targets[] =
{ "application/x-color", 0, COLOR }
};
G_DEFINE_TYPE (CcBackgroundChooserDialog, cc_background_chooser_dialog, GTK_TYPE_DIALOG)
static void on_visible_child_notify (CcBackgroundChooserDialog *chooser);
static void
@ -117,14 +117,13 @@ static void
cc_background_chooser_dialog_dispose (GObject *object)
{
CcBackgroundChooserDialog *chooser = CC_BACKGROUND_CHOOSER_DIALOG (object);
CcBackgroundChooserDialogPrivate *priv = chooser->priv;
if (priv->copy_cancellable)
if (chooser->copy_cancellable)
{
/* cancel any copy operation */
g_cancellable_cancel (priv->copy_cancellable);
g_cancellable_cancel (chooser->copy_cancellable);
g_clear_object (&priv->copy_cancellable);
g_clear_object (&chooser->copy_cancellable);
}
/* GtkStack triggers notify::visible-child during dispose and this
@ -133,17 +132,17 @@ cc_background_chooser_dialog_dispose (GObject *object)
* on_visible_child_notify() will get called while we're in an
* inconsistent state.
*/
if (priv->stack != NULL)
if (chooser->stack != NULL)
{
g_signal_handlers_disconnect_by_func (priv->stack, on_visible_child_notify, chooser);
priv->stack = NULL;
g_signal_handlers_disconnect_by_func (chooser->stack, on_visible_child_notify, chooser);
chooser->stack = NULL;
}
g_clear_pointer (&chooser->priv->item_to_focus, gtk_tree_row_reference_free);
g_clear_object (&priv->pictures_source);
g_clear_object (&priv->colors_source);
g_clear_object (&priv->wallpapers_source);
g_clear_object (&priv->thumb_factory);
g_clear_pointer (&chooser->item_to_focus, gtk_tree_row_reference_free);
g_clear_object (&chooser->pictures_source);
g_clear_object (&chooser->colors_source);
g_clear_object (&chooser->wallpapers_source);
g_clear_object (&chooser->thumb_factory);
G_OBJECT_CLASS (cc_background_chooser_dialog_parent_class)->dispose (object);
}
@ -151,11 +150,10 @@ cc_background_chooser_dialog_dispose (GObject *object)
static GtkWidget *
get_visible_view (CcBackgroundChooserDialog *chooser)
{
CcBackgroundChooserDialogPrivate *priv = chooser->priv;
GtkWidget *visible;
GtkWidget *icon_view = NULL;
visible = gtk_stack_get_visible_child (GTK_STACK (priv->stack));
visible = gtk_stack_get_visible_child (GTK_STACK (chooser->stack));
if (GTK_IS_STACK (visible))
{
GtkWidget *sw;
@ -183,11 +181,11 @@ possibly_show_empty_pictures_box (GtkTreeModel *model,
if (gtk_tree_model_get_iter_first (model, &iter))
{
gtk_stack_set_visible_child_name (GTK_STACK (chooser->priv->pictures_stack), "view");
gtk_stack_set_visible_child_name (GTK_STACK (chooser->pictures_stack), "view");
}
else
{
gtk_stack_set_visible_child_name (GTK_STACK (chooser->priv->pictures_stack), "empty");
gtk_stack_set_visible_child_name (GTK_STACK (chooser->pictures_stack), "empty");
}
}
@ -197,28 +195,27 @@ on_source_modified_cb (GtkTreeModel *tree_model,
GtkTreeIter *iter,
gpointer user_data)
{
CcBackgroundChooserDialog *chooser = user_data;
GtkTreePath *to_focus_path;
GtkWidget *icon_view;
CcBackgroundChooserDialog *chooser = user_data;
CcBackgroundChooserDialogPrivate *priv = chooser->priv;
if (chooser->priv->item_to_focus == NULL)
if (chooser->item_to_focus == NULL)
return;
to_focus_path = gtk_tree_row_reference_get_path (chooser->priv->item_to_focus);
to_focus_path = gtk_tree_row_reference_get_path (chooser->item_to_focus);
if (gtk_tree_path_compare (to_focus_path, path) != 0)
goto out;
/* Change source */
gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "pictures");
gtk_stack_set_visible_child_name (GTK_STACK (chooser->stack), "pictures");
/* And select the newly added item */
icon_view = get_visible_view (chooser);
gtk_icon_view_select_path (GTK_ICON_VIEW (icon_view), to_focus_path);
gtk_icon_view_scroll_to_path (GTK_ICON_VIEW (icon_view),
to_focus_path, TRUE, 1.0, 1.0);
g_clear_pointer (&chooser->priv->item_to_focus, gtk_tree_row_reference_free);
g_clear_pointer (&chooser->item_to_focus, gtk_tree_row_reference_free);
out:
gtk_tree_path_free (to_focus_path);
@ -247,7 +244,7 @@ monitor_pictures_model (CcBackgroundChooserDialog *chooser)
{
GtkTreeModel *model;
model = GTK_TREE_MODEL (bg_source_get_liststore (BG_SOURCE (chooser->priv->pictures_source)));
model = GTK_TREE_MODEL (bg_source_get_liststore (BG_SOURCE (chooser->pictures_source)));
g_signal_connect (model, "row-inserted", G_CALLBACK (on_source_added_cb), chooser);
g_signal_connect (model, "row-deleted", G_CALLBACK (on_source_removed_cb), chooser);
@ -292,9 +289,9 @@ static void
add_custom_wallpaper (CcBackgroundChooserDialog *chooser,
const char *uri)
{
g_clear_pointer (&chooser->priv->item_to_focus, gtk_tree_row_reference_free);
g_clear_pointer (&chooser->item_to_focus, gtk_tree_row_reference_free);
bg_pictures_source_add (chooser->priv->pictures_source, uri, &chooser->priv->item_to_focus);
bg_pictures_source_add (chooser->pictures_source, uri, &chooser->item_to_focus);
/* and wait for the item to get added */
}
@ -326,11 +323,11 @@ cc_background_panel_drag_color (CcBackgroundChooserDialog *chooser,
rgba.blue = dropped[2] / 65535.;
rgba.alpha = dropped[3] / 65535.;
if (bg_colors_source_add (chooser->priv->colors_source, &rgba, &row_ref) == FALSE)
if (bg_colors_source_add (chooser->colors_source, &rgba, &row_ref) == FALSE)
return FALSE;
/* Change source */
gtk_stack_set_visible_child_name (GTK_STACK (chooser->priv->stack), "colors");
gtk_stack_set_visible_child_name (GTK_STACK (chooser->stack), "colors");
/* And select the newly added item */
to_focus_path = gtk_tree_row_reference_get_path (row_ref);
@ -368,7 +365,7 @@ cc_background_panel_drag_items (GtkWidget *widget,
for (i = 0; uris[i] != NULL; i++)
{
uri = uris[i];
if (!bg_pictures_source_is_known (chooser->priv->pictures_source, uri))
if (!bg_pictures_source_is_known (chooser->pictures_source, uri))
{
add_custom_wallpaper (chooser, uri);
ret = TRUE;
@ -418,37 +415,35 @@ static void
cc_background_chooser_dialog_constructed (GObject *object)
{
CcBackgroundChooserDialog *chooser = CC_BACKGROUND_CHOOSER_DIALOG (object);
CcBackgroundChooserDialogPrivate *priv = chooser->priv;
GtkListStore *model;
GtkWidget *sw;
GtkWidget *vbox;
G_OBJECT_CLASS (cc_background_chooser_dialog_parent_class)->constructed (object);
model = bg_source_get_liststore (BG_SOURCE (priv->wallpapers_source));
model = bg_source_get_liststore (BG_SOURCE (chooser->wallpapers_source));
sw = create_view (chooser, GTK_TREE_MODEL (model));
gtk_stack_add_titled (GTK_STACK (priv->stack), sw, "wallpapers", _("Wallpapers"));
gtk_container_child_set (GTK_CONTAINER (priv->stack), sw, "position", 0, NULL);
gtk_stack_add_titled (GTK_STACK (chooser->stack), sw, "wallpapers", _("Wallpapers"));
gtk_container_child_set (GTK_CONTAINER (chooser->stack), sw, "position", 0, NULL);
model = bg_source_get_liststore (BG_SOURCE (priv->pictures_source));
model = bg_source_get_liststore (BG_SOURCE (chooser->pictures_source));
sw = create_view (chooser, GTK_TREE_MODEL (model));
gtk_stack_add_named (GTK_STACK (priv->pictures_stack), sw, "view");
gtk_stack_add_named (GTK_STACK (chooser->pictures_stack), sw, "view");
model = bg_source_get_liststore (BG_SOURCE (priv->colors_source));
model = bg_source_get_liststore (BG_SOURCE (chooser->colors_source));
sw = create_view (chooser, GTK_TREE_MODEL (model));
gtk_stack_add_titled (GTK_STACK (priv->stack), sw, "colors", _("Colors"));
gtk_stack_add_titled (GTK_STACK (chooser->stack), sw, "colors", _("Colors"));
vbox = gtk_dialog_get_content_area (GTK_DIALOG (chooser));
gtk_widget_show_all (vbox);
gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "wallpapers");
gtk_stack_set_visible_child_name (GTK_STACK (chooser->stack), "wallpapers");
monitor_pictures_model (chooser);
}
static void
cc_background_chooser_dialog_init (CcBackgroundChooserDialog *chooser)
{
CcBackgroundChooserDialogPrivate *priv;
GtkWidget *empty_pictures_box;
GtkWidget *vbox;
GtkWidget *headerbar;
@ -463,12 +458,9 @@ cc_background_chooser_dialog_init (CcBackgroundChooserDialog *chooser)
gchar *pictures_dir_uri;
GtkTargetList *target_list;
chooser->priv = CC_CHOOSER_DIALOG_GET_PRIVATE (chooser);
priv = chooser->priv;
priv->wallpapers_source = bg_wallpapers_source_new (GTK_WINDOW (chooser));
priv->pictures_source = bg_pictures_source_new (GTK_WINDOW (chooser));
priv->colors_source = bg_colors_source_new (GTK_WINDOW (chooser));
chooser->wallpapers_source = bg_wallpapers_source_new (GTK_WINDOW (chooser));
chooser->pictures_source = bg_pictures_source_new (GTK_WINDOW (chooser));
chooser->colors_source = bg_colors_source_new (GTK_WINDOW (chooser));
gtk_window_set_modal (GTK_WINDOW (chooser), TRUE);
gtk_window_set_resizable (GTK_WINDOW (chooser), FALSE);
@ -478,30 +470,30 @@ cc_background_chooser_dialog_init (CcBackgroundChooserDialog *chooser)
vbox = gtk_dialog_get_content_area (GTK_DIALOG (chooser));
gtk_container_set_border_width (GTK_CONTAINER (vbox), 0);
priv->stack = gtk_stack_new ();
gtk_stack_set_homogeneous (GTK_STACK (priv->stack), TRUE);
gtk_container_add (GTK_CONTAINER (vbox), priv->stack);
g_signal_connect_swapped (priv->stack, "notify::visible-child", G_CALLBACK (on_visible_child_notify), chooser);
chooser->stack = gtk_stack_new ();
gtk_stack_set_homogeneous (GTK_STACK (chooser->stack), TRUE);
gtk_container_add (GTK_CONTAINER (vbox), chooser->stack);
g_signal_connect_swapped (chooser->stack, "notify::visible-child", G_CALLBACK (on_visible_child_notify), chooser);
/* Add drag and drop support for bg images */
gtk_drag_dest_set (priv->stack, GTK_DEST_DEFAULT_ALL, NULL, 0, GDK_ACTION_COPY);
gtk_drag_dest_set (chooser->stack, GTK_DEST_DEFAULT_ALL, NULL, 0, GDK_ACTION_COPY);
target_list = gtk_target_list_new (NULL, 0);
gtk_target_list_add_uri_targets (target_list, URI_LIST);
gtk_target_list_add_table (target_list, color_targets, 1);
gtk_drag_dest_set_target_list (priv->stack, target_list);
gtk_drag_dest_set_target_list (chooser->stack, target_list);
gtk_target_list_unref (target_list);
g_signal_connect (priv->stack, "drag-data-received", G_CALLBACK (cc_background_panel_drag_items), chooser);
g_signal_connect (chooser->stack, "drag-data-received", G_CALLBACK (cc_background_panel_drag_items), chooser);
headerbar = gtk_dialog_get_header_bar (GTK_DIALOG (chooser));
switcher = gtk_stack_switcher_new ();
gtk_stack_switcher_set_stack (GTK_STACK_SWITCHER (switcher), GTK_STACK (priv->stack));
gtk_stack_switcher_set_stack (GTK_STACK_SWITCHER (switcher), GTK_STACK (chooser->stack));
gtk_header_bar_set_custom_title (GTK_HEADER_BAR (headerbar), switcher);
gtk_widget_show (switcher);
priv->pictures_stack = gtk_stack_new ();
gtk_stack_set_homogeneous (GTK_STACK (priv->pictures_stack), TRUE);
gtk_stack_add_titled (GTK_STACK (priv->stack), priv->pictures_stack, "pictures", _("Pictures"));
chooser->pictures_stack = gtk_stack_new ();
gtk_stack_set_homogeneous (GTK_STACK (chooser->pictures_stack), TRUE);
gtk_stack_add_titled (GTK_STACK (chooser->stack), chooser->pictures_stack, "pictures", _("Pictures"));
empty_pictures_box = gtk_grid_new ();
gtk_grid_set_column_spacing (GTK_GRID (empty_pictures_box), 12);
@ -509,7 +501,7 @@ cc_background_chooser_dialog_init (CcBackgroundChooserDialog *chooser)
GTK_ORIENTATION_HORIZONTAL);
context = gtk_widget_get_style_context (empty_pictures_box);
gtk_style_context_add_class (context, "dim-label");
gtk_stack_add_named (GTK_STACK (priv->pictures_stack), empty_pictures_box, "empty");
gtk_stack_add_named (GTK_STACK (chooser->pictures_stack), empty_pictures_box, "empty");
img = gtk_image_new_from_icon_name ("emblem-photos-symbolic", GTK_ICON_SIZE_DIALOG);
gtk_image_set_pixel_size (GTK_IMAGE (img), 64);
gtk_widget_set_halign (img, GTK_ALIGN_END);
@ -588,8 +580,6 @@ cc_background_chooser_dialog_class_init (CcBackgroundChooserDialogClass *klass)
widget_class = GTK_WIDGET_CLASS (klass);
widget_class->realize = cc_background_chooser_dialog_realize;
g_type_class_add_private (object_class, sizeof (CcBackgroundChooserDialogPrivate));
}
GtkWidget *

View file

@ -26,29 +26,9 @@
G_BEGIN_DECLS
#define CC_TYPE_BACKGROUND_CHOOSER_DIALOG (cc_background_chooser_dialog_get_type ())
#define CC_BACKGROUND_CHOOSER_DIALOG(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), CC_TYPE_BACKGROUND_CHOOSER_DIALOG, CcBackgroundChooserDialog))
#define CC_BACKGROUND_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CC_TYPE_BACKGROUND_CHOOSER_DIALOG, CcBackgroundChooserDialogClass))
#define CC_IS_BACKGROUND_CHOOSER_DIALOG(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), CC_TYPE_BACKGROUND_CHOOSER_DIALOG))
#define CC_IS_BACKGROUND_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CC_TYPE_BACKGROUND_CHOOSER_DIALOG))
#define CC_BACKGROUND_CHOOSER_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CC_TYPE_BACKGROUND_CHOOSER_DIALOG, CcBackgroundChooserDialogClass))
#define CC_TYPE_BACKGROUND_CHOOSER_DIALOG (cc_background_chooser_dialog_get_type ())
G_DECLARE_FINAL_TYPE (CcBackgroundChooserDialog, cc_background_chooser_dialog, CC, BACKGROUND_CHOOSER_DIALOG, GtkDialog)
typedef struct _CcBackgroundChooserDialog CcBackgroundChooserDialog;
typedef struct _CcBackgroundChooserDialogClass CcBackgroundChooserDialogClass;
typedef struct _CcBackgroundChooserDialogPrivate CcBackgroundChooserDialogPrivate;
struct _CcBackgroundChooserDialog
{
GtkDialog parent_instance;
CcBackgroundChooserDialogPrivate *priv;
};
struct _CcBackgroundChooserDialogClass
{
GtkDialogClass parent_class;
};
GType cc_background_chooser_dialog_get_type (void) G_GNUC_CONST;
GtkWidget * cc_background_chooser_dialog_new (GtkWindow *transient_for);
CcBackgroundItem * cc_background_chooser_dialog_get_item (CcBackgroundChooserDialog *chooser);

View file

@ -28,15 +28,13 @@
struct _CcBackgroundGriloMiner
{
GObject parent;
GObject parent_instance;
GCancellable *cancellable;
GList *accounts;
};
struct _CcBackgroundGriloMinerClass
{
GObjectClass parent_class;
};
G_DEFINE_TYPE (CcBackgroundGriloMiner, cc_background_grilo_miner, G_TYPE_OBJECT)
enum
{
@ -46,8 +44,6 @@ enum
static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (CcBackgroundGriloMiner, cc_background_grilo_miner, G_TYPE_OBJECT)
#define REMOTE_ITEM_COUNT 50
static gchar *

View file

@ -23,32 +23,8 @@
G_BEGIN_DECLS
#define CC_TYPE_BACKGROUND_GRILO_MINER cc_background_grilo_miner_get_type()
#define CC_BACKGROUND_GRILO_MINER(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
CC_TYPE_BACKGROUND_GRILO_MINER, CcBackgroundGriloMiner))
#define CC_BACKGROUND_GRILO_MINER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), \
CC_TYPE_BACKGROUND_GRILO_MINER, CcBackgroundGriloMinerClass))
#define CC_IS_BACKGROUND_GRILO_MINER(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
CC_TYPE_BACKGROUND_GRILO_MINER))
#define CC_IS_BACKGROUND_GRILO_MINER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
CC_TYPE_BACKGROUND_GRILO_MINER))
#define CC_BACKGROUND_GRILO_MINER_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
CC_TYPE_BACKGROUND_GRILO_MINER, CcBackgroundGriloMinerClass))
typedef struct _CcBackgroundGriloMiner CcBackgroundGriloMiner;
typedef struct _CcBackgroundGriloMinerClass CcBackgroundGriloMinerClass;
GType cc_background_grilo_miner_get_type (void) G_GNUC_CONST;
#define CC_TYPE_BACKGROUND_GRILO_MINER (cc_background_grilo_miner_get_type ())
G_DECLARE_FINAL_TYPE (CcBackgroundGriloMiner, cc_background_grilo_miner, CC, BACKGROUND_GRILO_MINER, GObject);
CcBackgroundGriloMiner *cc_background_grilo_miner_new (void);

View file

@ -32,10 +32,10 @@
#include "cc-background-item.h"
#include "gdesktop-enums-types.h"
#define CC_BACKGROUND_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_BACKGROUND_ITEM, CcBackgroundItemPrivate))
struct CcBackgroundItemPrivate
struct _CcBackgroundItem
{
GObject parent_instance;
/* properties */
char *name;
char *uri;
@ -99,7 +99,7 @@ get_emblemed_pixbuf (CcBackgroundItem *item, GdkPixbuf *pixbuf, gint scale_facto
retval = g_object_ref (pixbuf);
if (item->priv->slideshow_emblem == NULL) {
if (item->slideshow_emblem == NULL) {
if (slideshow_emblem == NULL) {
GError *error = NULL;
GtkIconTheme *theme;
@ -126,9 +126,9 @@ get_emblemed_pixbuf (CcBackgroundItem *item, GdkPixbuf *pixbuf, gint scale_facto
}
g_object_add_weak_pointer (G_OBJECT (slideshow_emblem), (gpointer *) (&slideshow_emblem));
item->priv->slideshow_emblem = slideshow_emblem;
item->slideshow_emblem = slideshow_emblem;
} else {
item->priv->slideshow_emblem = g_object_ref (slideshow_emblem);
item->slideshow_emblem = g_object_ref (slideshow_emblem);
}
}
@ -153,27 +153,27 @@ set_bg_properties (CcBackgroundItem *item)
GdkColor pcolor = { 0, 0, 0, 0 };
GdkColor scolor = { 0, 0, 0, 0 };
if (item->priv->uri) {
if (item->uri) {
GFile *file;
char *filename;
file = g_file_new_for_commandline_arg (item->priv->uri);
file = g_file_new_for_commandline_arg (item->uri);
filename = g_file_get_path (file);
g_object_unref (file);
gnome_bg_set_filename (item->priv->bg, filename);
gnome_bg_set_filename (item->bg, filename);
g_free (filename);
}
if (item->priv->primary_color != NULL) {
gdk_color_parse (item->priv->primary_color, &pcolor);
if (item->primary_color != NULL) {
gdk_color_parse (item->primary_color, &pcolor);
}
if (item->priv->secondary_color != NULL) {
gdk_color_parse (item->priv->secondary_color, &scolor);
if (item->secondary_color != NULL) {
gdk_color_parse (item->secondary_color, &scolor);
}
gnome_bg_set_color (item->priv->bg, item->priv->shading, &pcolor, &scolor);
gnome_bg_set_placement (item->priv->bg, item->priv->placement);
gnome_bg_set_color (item->bg, item->shading, &pcolor, &scolor);
gnome_bg_set_placement (item->bg, item->placement);
}
@ -185,8 +185,8 @@ cc_background_item_changes_with_time (CcBackgroundItem *item)
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), FALSE);
changes = FALSE;
if (item->priv->bg != NULL) {
changes = gnome_bg_changes_with_time (item->priv->bg);
if (item->bg != NULL) {
changes = gnome_bg_changes_with_time (item->bg);
}
return changes;
}
@ -194,19 +194,19 @@ cc_background_item_changes_with_time (CcBackgroundItem *item)
static void
update_size (CcBackgroundItem *item)
{
g_clear_pointer (&item->priv->size, g_free);
g_clear_pointer (&item->size, g_free);
if (item->priv->uri == NULL) {
item->priv->size = g_strdup ("");
if (item->uri == NULL) {
item->size = g_strdup ("");
} else {
if (gnome_bg_has_multiple_sizes (item->priv->bg) || gnome_bg_changes_with_time (item->priv->bg)) {
item->priv->size = g_strdup (_("multiple sizes"));
if (gnome_bg_has_multiple_sizes (item->bg) || gnome_bg_changes_with_time (item->bg)) {
item->size = g_strdup (_("multiple sizes"));
} else {
/* translators: 100 × 100px
* Note that this is not an "x", but U+00D7 MULTIPLICATION SIGN */
item->priv->size = g_strdup_printf (_("%d × %d"),
item->priv->width,
item->priv->height);
item->size = g_strdup_printf (_("%d × %d"),
item->width,
item->height);
}
}
}
@ -249,17 +249,17 @@ cc_background_item_get_frame_thumbnail (CcBackgroundItem *item,
* the slideshow frame though, so we can't do much better than this
* for now.
*/
pixbuf = render_at_size (item->priv->bg, width, height);
pixbuf = render_at_size (item->bg, width, height);
} else {
if (frame >= 0) {
pixbuf = gnome_bg_create_frame_thumbnail (item->priv->bg,
pixbuf = gnome_bg_create_frame_thumbnail (item->bg,
thumbs,
gdk_screen_get_default (),
width,
height,
frame);
} else {
pixbuf = gnome_bg_create_thumbnail (item->priv->bg,
pixbuf = gnome_bg_create_thumbnail (item->bg,
thumbs,
gdk_screen_get_default (),
width,
@ -269,19 +269,19 @@ cc_background_item_get_frame_thumbnail (CcBackgroundItem *item,
if (pixbuf != NULL
&& frame != -2
&& gnome_bg_changes_with_time (item->priv->bg)) {
&& gnome_bg_changes_with_time (item->bg)) {
retval = get_emblemed_pixbuf (item, pixbuf, scale_factor);
g_object_unref (pixbuf);
} else {
retval = pixbuf;
}
gnome_bg_get_image_size (item->priv->bg,
gnome_bg_get_image_size (item->bg,
thumbs,
width,
height,
&item->priv->width,
&item->priv->height);
&item->width,
&item->height);
update_size (item);
@ -307,7 +307,7 @@ update_info (CcBackgroundItem *item,
GFileInfo *info;
if (_info == NULL) {
file = g_file_new_for_uri (item->priv->uri);
file = g_file_new_for_uri (item->uri);
info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_NAME ","
@ -323,22 +323,22 @@ update_info (CcBackgroundItem *item,
info = g_object_ref (_info);
}
g_clear_pointer (&item->priv->mime_type, g_free);
g_clear_pointer (&item->mime_type, g_free);
if (info == NULL
|| g_file_info_get_content_type (info) == NULL) {
if (item->priv->uri == NULL) {
item->priv->mime_type = g_strdup ("image/x-no-data");
g_free (item->priv->name);
item->priv->name = g_strdup (_("No Desktop Background"));
if (item->uri == NULL) {
item->mime_type = g_strdup ("image/x-no-data");
g_free (item->name);
item->name = g_strdup (_("No Desktop Background"));
}
} else {
if (item->priv->name == NULL)
item->priv->name = g_strdup (g_file_info_get_display_name (info));
if (item->name == NULL)
item->name = g_strdup (g_file_info_get_display_name (info));
item->priv->mime_type = g_strdup (g_file_info_get_content_type (info));
if (item->priv->modified == 0)
item->priv->modified = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
item->mime_type = g_strdup (g_file_info_get_content_type (info));
if (item->modified == 0)
item->modified = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
}
if (info != NULL)
@ -351,28 +351,28 @@ cc_background_item_load (CcBackgroundItem *item,
{
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), FALSE);
if (item->priv->uri == NULL)
if (item->uri == NULL)
return TRUE;
update_info (item, info);
if (item->priv->mime_type != NULL
&& (g_str_has_prefix (item->priv->mime_type, "image/")
|| strcmp (item->priv->mime_type, "application/xml") == 0)) {
if (item->mime_type != NULL
&& (g_str_has_prefix (item->mime_type, "image/")
|| strcmp (item->mime_type, "application/xml") == 0)) {
set_bg_properties (item);
} else {
return FALSE;
}
/* FIXME we should handle XML files as well */
if (item->priv->mime_type != NULL &&
g_str_has_prefix (item->priv->mime_type, "image/")) {
if (item->mime_type != NULL &&
g_str_has_prefix (item->mime_type, "image/")) {
char *filename;
filename = g_filename_from_uri (item->priv->uri, NULL, NULL);
filename = g_filename_from_uri (item->uri, NULL, NULL);
gdk_pixbuf_get_file_info (filename,
&item->priv->width,
&item->priv->height);
&item->width,
&item->height);
g_free (filename);
update_size (item);
}
@ -384,8 +384,8 @@ static void
_set_name (CcBackgroundItem *item,
const char *value)
{
g_free (item->priv->name);
item->priv->name = g_strdup (value);
g_free (item->name);
item->name = g_strdup (value);
}
const char *
@ -393,20 +393,20 @@ cc_background_item_get_name (CcBackgroundItem *item)
{
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), NULL);
return item->priv->name;
return item->name;
}
static void
_set_uri (CcBackgroundItem *item,
const char *value)
{
g_free (item->priv->uri);
g_free (item->uri);
if (value && *value == '\0') {
item->priv->uri = NULL;
item->uri = NULL;
} else {
if (value && strstr (value, "://") == NULL)
g_warning ("URI '%s' is invalid", value);
item->priv->uri = g_strdup (value);
item->uri = g_strdup (value);
}
}
@ -415,29 +415,29 @@ cc_background_item_get_uri (CcBackgroundItem *item)
{
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), NULL);
return item->priv->uri;
return item->uri;
}
static void
_set_placement (CcBackgroundItem *item,
GDesktopBackgroundStyle value)
{
item->priv->placement = value;
item->placement = value;
}
static void
_set_shading (CcBackgroundItem *item,
GDesktopBackgroundShading value)
{
item->priv->shading = value;
item->shading = value;
}
static void
_set_primary_color (CcBackgroundItem *item,
const char *value)
{
g_free (item->priv->primary_color);
item->priv->primary_color = g_strdup (value);
g_free (item->primary_color);
item->primary_color = g_strdup (value);
}
const char *
@ -445,15 +445,15 @@ cc_background_item_get_pcolor (CcBackgroundItem *item)
{
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), NULL);
return item->priv->primary_color;
return item->primary_color;
}
static void
_set_secondary_color (CcBackgroundItem *item,
const char *value)
{
g_free (item->priv->secondary_color);
item->priv->secondary_color = g_strdup (value);
g_free (item->secondary_color);
item->secondary_color = g_strdup (value);
}
const char *
@ -461,7 +461,7 @@ cc_background_item_get_scolor (CcBackgroundItem *item)
{
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), NULL);
return item->priv->secondary_color;
return item->secondary_color;
}
GDesktopBackgroundStyle
@ -469,7 +469,7 @@ cc_background_item_get_placement (CcBackgroundItem *item)
{
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), G_DESKTOP_BACKGROUND_STYLE_SCALED);
return item->priv->placement;
return item->placement;
}
GDesktopBackgroundShading
@ -477,22 +477,22 @@ cc_background_item_get_shading (CcBackgroundItem *item)
{
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), G_DESKTOP_BACKGROUND_SHADING_SOLID);
return item->priv->shading;
return item->shading;
}
static void
_set_is_deleted (CcBackgroundItem *item,
gboolean value)
{
item->priv->is_deleted = value;
item->is_deleted = value;
}
static void
_set_source_url (CcBackgroundItem *item,
const char *value)
{
g_free (item->priv->source_url);
item->priv->source_url = g_strdup (value);
g_free (item->source_url);
item->source_url = g_strdup (value);
}
const char *
@ -500,15 +500,15 @@ cc_background_item_get_source_url (CcBackgroundItem *item)
{
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), NULL);
return item->priv->source_url;
return item->source_url;
}
static void
_set_source_xml (CcBackgroundItem *item,
const char *value)
{
g_free (item->priv->source_xml);
item->priv->source_xml = g_strdup (value);
g_free (item->source_xml);
item->source_xml = g_strdup (value);
}
const char *
@ -516,14 +516,14 @@ cc_background_item_get_source_xml (CcBackgroundItem *item)
{
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), NULL);
return item->priv->source_xml;
return item->source_xml;
}
static void
_set_flags (CcBackgroundItem *item,
CcBackgroundItemFlags value)
{
item->priv->flags = value;
item->flags = value;
}
CcBackgroundItemFlags
@ -531,7 +531,7 @@ cc_background_item_get_flags (CcBackgroundItem *item)
{
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), 0);
return item->priv->flags;
return item->flags;
}
const char *
@ -539,14 +539,14 @@ cc_background_item_get_size (CcBackgroundItem *item)
{
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), NULL);
return item->priv->size;
return item->size;
}
static void
_set_needs_download (CcBackgroundItem *item,
gboolean value)
{
item->priv->needs_download = value;
item->needs_download = value;
}
gboolean
@ -554,14 +554,14 @@ cc_background_item_get_needs_download (CcBackgroundItem *item)
{
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), 0);
return item->priv->needs_download;
return item->needs_download;
}
static void
_set_modified (CcBackgroundItem *item,
guint64 value)
{
item->priv->modified = value;
item->modified = value;
}
guint64
@ -569,7 +569,7 @@ cc_background_item_get_modified (CcBackgroundItem *item)
{
g_return_val_if_fail (CC_IS_BACKGROUND_ITEM (item), 0);
return item->priv->modified;
return item->modified;
}
static void
@ -637,43 +637,43 @@ cc_background_item_get_property (GObject *object,
switch (prop_id) {
case PROP_NAME:
g_value_set_string (value, self->priv->name);
g_value_set_string (value, self->name);
break;
case PROP_URI:
g_value_set_string (value, self->priv->uri);
g_value_set_string (value, self->uri);
break;
case PROP_PLACEMENT:
g_value_set_enum (value, self->priv->placement);
g_value_set_enum (value, self->placement);
break;
case PROP_SHADING:
g_value_set_enum (value, self->priv->shading);
g_value_set_enum (value, self->shading);
break;
case PROP_PRIMARY_COLOR:
g_value_set_string (value, self->priv->primary_color);
g_value_set_string (value, self->primary_color);
break;
case PROP_SECONDARY_COLOR:
g_value_set_string (value, self->priv->secondary_color);
g_value_set_string (value, self->secondary_color);
break;
case PROP_IS_DELETED:
g_value_set_boolean (value, self->priv->is_deleted);
g_value_set_boolean (value, self->is_deleted);
break;
case PROP_SOURCE_URL:
g_value_set_string (value, self->priv->source_url);
g_value_set_string (value, self->source_url);
break;
case PROP_SOURCE_XML:
g_value_set_string (value, self->priv->source_xml);
g_value_set_string (value, self->source_xml);
break;
case PROP_FLAGS:
g_value_set_flags (value, self->priv->flags);
g_value_set_flags (value, self->flags);
break;
case PROP_SIZE:
g_value_set_string (value, self->priv->size);
g_value_set_string (value, self->size);
break;
case PROP_NEEDS_DOWNLOAD:
g_value_set_boolean (value, self->priv->needs_download);
g_value_set_boolean (value, self->needs_download);
break;
case PROP_MODIFIED:
g_value_set_uint64 (value, self->priv->modified);
g_value_set_uint64 (value, self->modified);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -809,25 +809,20 @@ cc_background_item_class_init (CcBackgroundItemClass *klass)
G_MAXUINT64,
0,
G_PARAM_READWRITE));
g_type_class_add_private (klass, sizeof (CcBackgroundItemPrivate));
}
static void
cc_background_item_init (CcBackgroundItem *item)
{
item->priv = CC_BACKGROUND_ITEM_GET_PRIVATE (item);
item->bg = gnome_bg_new ();
item->priv->bg = gnome_bg_new ();
item->priv->shading = G_DESKTOP_BACKGROUND_SHADING_SOLID;
item->priv->placement = G_DESKTOP_BACKGROUND_STYLE_SCALED;
item->priv->primary_color = g_strdup ("#000000000000");
item->priv->secondary_color = g_strdup ("#000000000000");
item->priv->needs_download = TRUE;
item->priv->flags = 0;
item->priv->modified = 0;
item->shading = G_DESKTOP_BACKGROUND_SHADING_SOLID;
item->placement = G_DESKTOP_BACKGROUND_STYLE_SCALED;
item->primary_color = g_strdup ("#000000000000");
item->secondary_color = g_strdup ("#000000000000");
item->needs_download = TRUE;
item->flags = 0;
item->modified = 0;
}
static void
@ -840,21 +835,21 @@ cc_background_item_finalize (GObject *object)
item = CC_BACKGROUND_ITEM (object);
g_return_if_fail (item->priv != NULL);
g_return_if_fail (item != NULL);
g_free (item->priv->name);
g_free (item->priv->uri);
g_free (item->priv->primary_color);
g_free (item->priv->secondary_color);
g_free (item->priv->mime_type);
g_free (item->priv->size);
g_free (item->priv->source_url);
g_free (item->priv->source_xml);
g_free (item->name);
g_free (item->uri);
g_free (item->primary_color);
g_free (item->secondary_color);
g_free (item->mime_type);
g_free (item->size);
g_free (item->source_url);
g_free (item->source_xml);
if (item->priv->bg != NULL)
g_object_unref (item->priv->bg);
if (item->bg != NULL)
g_object_unref (item->bg);
g_clear_object (&item->priv->slideshow_emblem);
g_clear_object (&item->slideshow_emblem);
G_OBJECT_CLASS (cc_background_item_parent_class)->finalize (object);
}
@ -876,18 +871,18 @@ cc_background_item_copy (CcBackgroundItem *item)
{
CcBackgroundItem *ret;
ret = cc_background_item_new (item->priv->uri);
ret->priv->name = g_strdup (item->priv->name);
ret->priv->size = g_strdup (item->priv->size);
ret->priv->placement = item->priv->placement;
ret->priv->shading = item->priv->shading;
ret->priv->primary_color = g_strdup (item->priv->primary_color);
ret->priv->secondary_color = g_strdup (item->priv->secondary_color);
ret->priv->source_url = g_strdup (item->priv->source_url);
ret->priv->source_xml = g_strdup (item->priv->source_xml);
ret->priv->is_deleted = item->priv->is_deleted;
ret->priv->needs_download = item->priv->needs_download;
ret->priv->flags = item->priv->flags;
ret = cc_background_item_new (item->uri);
ret->name = g_strdup (item->name);
ret->size = g_strdup (item->size);
ret->placement = item->placement;
ret->shading = item->shading;
ret->primary_color = g_strdup (item->primary_color);
ret->secondary_color = g_strdup (item->secondary_color);
ret->source_url = g_strdup (item->source_url);
ret->source_xml = g_strdup (item->source_xml);
ret->is_deleted = item->is_deleted;
ret->needs_download = item->needs_download;
ret->flags = item->flags;
return ret;
}
@ -924,21 +919,18 @@ enum_to_str (GType type,
void
cc_background_item_dump (CcBackgroundItem *item)
{
CcBackgroundItemPrivate *priv;
GString *flags;
int i;
g_return_if_fail (CC_IS_BACKGROUND_ITEM (item));
priv = item->priv;
g_debug ("name:\t\t\t%s", priv->name);
g_debug ("URI:\t\t\t%s", priv->uri ? priv->uri : "NULL");
if (priv->size)
g_debug ("size:\t\t\t'%s'", priv->size);
g_debug ("name:\t\t\t%s", item->name);
g_debug ("URI:\t\t\t%s", item->uri ? item->uri : "NULL");
if (item->size)
g_debug ("size:\t\t\t'%s'", item->size);
flags = g_string_new (NULL);
for (i = 0; i < 5; i++) {
if (priv->flags & (1 << i)) {
if (item->flags & (1 << i)) {
g_string_append (flags, flags_to_str (1 << i));
g_string_append_c (flags, ' ');
}
@ -947,21 +939,21 @@ cc_background_item_dump (CcBackgroundItem *item)
g_string_append (flags, "-none-");
g_debug ("flags:\t\t\t%s", flags->str);
g_string_free (flags, TRUE);
if (priv->primary_color)
g_debug ("pcolor:\t\t\t%s", priv->primary_color);
if (priv->secondary_color)
g_debug ("scolor:\t\t\t%s", priv->secondary_color);
g_debug ("placement:\t\t%s", enum_to_str (G_DESKTOP_TYPE_DESKTOP_BACKGROUND_STYLE, priv->placement));
g_debug ("shading:\t\t%s", enum_to_str (G_DESKTOP_TYPE_DESKTOP_BACKGROUND_SHADING, priv->shading));
if (priv->source_url)
g_debug ("source URL:\t\t%s", priv->source_url);
if (priv->source_xml)
g_debug ("source XML:\t\t%s", priv->source_xml);
g_debug ("deleted:\t\t%s", priv->is_deleted ? "yes" : "no");
if (priv->mime_type)
g_debug ("mime-type:\t\t%s", priv->mime_type);
g_debug ("dimensions:\t\t%d x %d", priv->width, priv->height);
g_debug ("modified: %"G_GUINT64_FORMAT, priv->modified);
if (item->primary_color)
g_debug ("pcolor:\t\t\t%s", item->primary_color);
if (item->secondary_color)
g_debug ("scolor:\t\t\t%s", item->secondary_color);
g_debug ("placement:\t\t%s", enum_to_str (G_DESKTOP_TYPE_DESKTOP_BACKGROUND_STYLE, item->placement));
g_debug ("shading:\t\t%s", enum_to_str (G_DESKTOP_TYPE_DESKTOP_BACKGROUND_SHADING, item->shading));
if (item->source_url)
g_debug ("source URL:\t\t%s", item->source_url);
if (item->source_xml)
g_debug ("source XML:\t\t%s", item->source_xml);
g_debug ("deleted:\t\t%s", item->is_deleted ? "yes" : "no");
if (item->mime_type)
g_debug ("mime-type:\t\t%s", item->mime_type);
g_debug ("dimensions:\t\t%d x %d", item->width, item->height);
g_debug ("modified: %"G_GUINT64_FORMAT, item->modified);
g_debug (" ");
}
@ -1010,31 +1002,31 @@ cc_background_item_compare (CcBackgroundItem *saved,
{
CcBackgroundItemFlags flags;
flags = saved->priv->flags;
flags = saved->flags;
if (flags == 0)
return FALSE;
if (flags & CC_BACKGROUND_ITEM_HAS_URI) {
if (files_equal (saved->priv->uri, configured->priv->uri) == FALSE)
if (files_equal (saved->uri, configured->uri) == FALSE)
return FALSE;
}
if (flags & CC_BACKGROUND_ITEM_HAS_SHADING) {
if (saved->priv->shading != configured->priv->shading)
if (saved->shading != configured->shading)
return FALSE;
}
if (flags & CC_BACKGROUND_ITEM_HAS_PLACEMENT) {
if (saved->priv->placement != configured->priv->placement)
if (saved->placement != configured->placement)
return FALSE;
}
if (flags & CC_BACKGROUND_ITEM_HAS_PCOLOR) {
if (colors_equal (saved->priv->primary_color,
configured->priv->primary_color) == FALSE) {
if (colors_equal (saved->primary_color,
configured->primary_color) == FALSE) {
return FALSE;
}
}
if (flags & CC_BACKGROUND_ITEM_HAS_SCOLOR) {
if (colors_equal (saved->priv->secondary_color,
configured->priv->secondary_color) == FALSE) {
if (colors_equal (saved->secondary_color,
configured->secondary_color) == FALSE) {
return FALSE;
}
}

View file

@ -28,12 +28,8 @@
G_BEGIN_DECLS
#define CC_TYPE_BACKGROUND_ITEM (cc_background_item_get_type ())
#define CC_BACKGROUND_ITEM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CC_TYPE_BACKGROUND_ITEM, CcBackgroundItem))
#define CC_BACKGROUND_ITEM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), CC_TYPE_BACKGROUND_ITEM, CcBackgroundItemClass))
#define CC_IS_BACKGROUND_ITEM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CC_TYPE_BACKGROUND_ITEM))
#define CC_IS_BACKGROUND_ITEM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CC_TYPE_BACKGROUND_ITEM))
#define CC_BACKGROUND_ITEM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CC_TYPE_BACKGROUND_ITEM, CcBackgroundItemClass))
#define CC_TYPE_BACKGROUND_ITEM (cc_background_item_get_type ())
G_DECLARE_FINAL_TYPE (CcBackgroundItem, cc_background_item, CC, BACKGROUND_ITEM, GObject)
typedef enum {
CC_BACKGROUND_ITEM_HAS_SHADING = 1 << 0,
@ -49,21 +45,6 @@ typedef enum {
CC_BACKGROUND_ITEM_HAS_SCOLOR & \
CC_BACKGROUND_ITEM_HAS_FNAME)
typedef struct CcBackgroundItemPrivate CcBackgroundItemPrivate;
typedef struct
{
GObject parent;
CcBackgroundItemPrivate *priv;
} CcBackgroundItem;
typedef struct
{
GObjectClass parent_class;
} CcBackgroundItemClass;
GType cc_background_item_get_type (void);
CcBackgroundItem * cc_background_item_new (const char *uri);
CcBackgroundItem * cc_background_item_copy (CcBackgroundItem *item);
gboolean cc_background_item_load (CcBackgroundItem *item,

View file

@ -44,13 +44,10 @@
#define WP_PCOLOR_KEY "primary-color"
#define WP_SCOLOR_KEY "secondary-color"
CC_PANEL_REGISTER (CcBackgroundPanel, cc_background_panel)
#define BACKGROUND_PANEL_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_BACKGROUND_PANEL, CcBackgroundPanelPrivate))
struct _CcBackgroundPanelPrivate
struct _CcBackgroundPanel
{
CcPanel parent_instance;
GtkBuilder *builder;
GDBusConnection *connection;
@ -72,9 +69,11 @@ struct _CcBackgroundPanelPrivate
char *screenshot_path;
};
#define WID(y) (GtkWidget *) gtk_builder_get_object (priv->builder, y)
#define CURRENT_BG (settings == priv->settings ? priv->current_background : priv->current_lock_background)
#define SAVE_PATH (settings == priv->settings ? "last-edited.xml" : "last-edited-lock.xml")
CC_PANEL_REGISTER (CcBackgroundPanel, cc_background_panel)
#define WID(y) (GtkWidget *) gtk_builder_get_object (panel->builder, y)
#define CURRENT_BG (settings == panel->settings ? panel->current_background : panel->current_lock_background)
#define SAVE_PATH (settings == panel->settings ? "last-edited.xml" : "last-edited-lock.xml")
static const char *
cc_background_panel_get_help_uri (CcPanel *panel)
@ -85,42 +84,42 @@ cc_background_panel_get_help_uri (CcPanel *panel)
static void
cc_background_panel_dispose (GObject *object)
{
CcBackgroundPanelPrivate *priv = CC_BACKGROUND_PANEL (object)->priv;
CcBackgroundPanel *panel = CC_BACKGROUND_PANEL (object);
g_clear_object (&priv->builder);
g_clear_object (&panel->builder);
/* destroying the builder object will also destroy the spinner */
priv->spinner = NULL;
panel->spinner = NULL;
g_clear_object (&priv->settings);
g_clear_object (&priv->lock_settings);
g_clear_object (&panel->settings);
g_clear_object (&panel->lock_settings);
if (priv->copy_cancellable)
if (panel->copy_cancellable)
{
/* cancel any copy operation */
g_cancellable_cancel (priv->copy_cancellable);
g_cancellable_cancel (panel->copy_cancellable);
g_clear_object (&priv->copy_cancellable);
g_clear_object (&panel->copy_cancellable);
}
if (priv->capture_cancellable)
if (panel->capture_cancellable)
{
/* cancel screenshot operations */
g_cancellable_cancel (priv->capture_cancellable);
g_cancellable_cancel (panel->capture_cancellable);
g_clear_object (&priv->capture_cancellable);
g_clear_object (&panel->capture_cancellable);
}
if (priv->chooser)
if (panel->chooser)
{
gtk_widget_destroy (priv->chooser);
priv->chooser = NULL;
gtk_widget_destroy (panel->chooser);
panel->chooser = NULL;
}
g_clear_object (&priv->thumb_factory);
g_clear_object (&priv->display_screenshot);
g_clear_object (&panel->thumb_factory);
g_clear_object (&panel->display_screenshot);
g_clear_pointer (&priv->screenshot_path, g_free);
g_clear_pointer (&panel->screenshot_path, g_free);
G_OBJECT_CLASS (cc_background_panel_parent_class)->dispose (object);
}
@ -128,10 +127,10 @@ cc_background_panel_dispose (GObject *object)
static void
cc_background_panel_finalize (GObject *object)
{
CcBackgroundPanelPrivate *priv = CC_BACKGROUND_PANEL (object)->priv;
CcBackgroundPanel *panel = CC_BACKGROUND_PANEL (object);
g_clear_object (&priv->current_background);
g_clear_object (&priv->current_lock_background);
g_clear_object (&panel->current_background);
g_clear_object (&panel->current_lock_background);
G_OBJECT_CLASS (cc_background_panel_parent_class)->finalize (object);
}
@ -142,8 +141,6 @@ cc_background_panel_class_init (CcBackgroundPanelClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
CcPanelClass *panel_class = CC_PANEL_CLASS (klass);
g_type_class_add_private (klass, sizeof (CcBackgroundPanelPrivate));
panel_class->get_help_uri = cc_background_panel_get_help_uri;
object_class->dispose = cc_background_panel_dispose;
@ -151,9 +148,9 @@ cc_background_panel_class_init (CcBackgroundPanelClass *klass)
}
static void
update_preview (CcBackgroundPanelPrivate *priv,
GSettings *settings,
CcBackgroundItem *item)
update_preview (CcBackgroundPanel *panel,
GSettings *settings,
CcBackgroundItem *item)
{
gboolean changes_with_time;
CcBackgroundItem *current_background;
@ -164,10 +161,10 @@ update_preview (CcBackgroundPanelPrivate *priv,
{
g_object_unref (current_background);
current_background = cc_background_item_copy (item);
if (settings == priv->settings)
priv->current_background = current_background;
if (settings == panel->settings)
panel->current_background = current_background;
else
priv->current_lock_background = current_background;
panel->current_lock_background = current_background;
cc_background_item_load (current_background, NULL);
}
@ -178,7 +175,7 @@ update_preview (CcBackgroundPanelPrivate *priv,
changes_with_time = cc_background_item_changes_with_time (current_background);
}
if (settings == priv->settings)
if (settings == panel->settings)
{
gtk_widget_set_visible (WID ("slide_image"), changes_with_time);
gtk_widget_set_visible (WID ("slide-label"), changes_with_time);
@ -209,7 +206,6 @@ get_or_create_cached_pixbuf (CcBackgroundPanel *panel,
GtkWidget *widget,
CcBackgroundItem *background)
{
CcBackgroundPanelPrivate *priv = panel->priv;
GtkAllocation allocation;
const gint preview_width = 309;
const gint preview_height = 168;
@ -219,10 +215,10 @@ get_or_create_cached_pixbuf (CcBackgroundPanel *panel,
pixbuf = g_object_get_data (G_OBJECT (background), "pixbuf");
if (pixbuf == NULL)
{
if (background == priv->current_background &&
priv->display_screenshot != NULL)
if (background == panel->current_background &&
panel->display_screenshot != NULL)
{
pixbuf = gdk_pixbuf_scale_simple (priv->display_screenshot,
pixbuf = gdk_pixbuf_scale_simple (panel->display_screenshot,
preview_width,
preview_height,
GDK_INTERP_BILINEAR);
@ -232,7 +228,7 @@ get_or_create_cached_pixbuf (CcBackgroundPanel *panel,
gtk_widget_get_allocation (widget, &allocation);
scale_factor = gtk_widget_get_scale_factor (widget);
pixbuf = cc_background_item_get_frame_thumbnail (background,
priv->thumb_factory,
panel->thumb_factory,
preview_width,
preview_height,
scale_factor,
@ -276,7 +272,6 @@ on_screenshot_finished (GObject *source,
{
ScreenshotData *data = user_data;
CcBackgroundPanel *panel = data->panel;
CcBackgroundPanelPrivate *priv;
GError *error;
GdkPixbuf *pixbuf;
cairo_surface_t *surface;
@ -298,14 +293,11 @@ on_screenshot_finished (GObject *source,
error->message);
g_error_free (error);
/* fallback? */
priv = panel->priv;
goto out;
}
g_variant_unref (result);
priv = panel->priv;
pixbuf = gdk_pixbuf_new_from_file (panel->priv->screenshot_path, &error);
pixbuf = gdk_pixbuf_new_from_file (panel->screenshot_path, &error);
if (pixbuf == NULL)
{
g_debug ("Unable to use GNOME Shell's builtin screenshot interface: %s",
@ -335,23 +327,23 @@ on_screenshot_finished (GObject *source,
cairo_restore (cr);
}
g_clear_object (&panel->priv->display_screenshot);
panel->priv->display_screenshot = gdk_pixbuf_get_from_surface (surface,
g_clear_object (&panel->display_screenshot);
panel->display_screenshot = gdk_pixbuf_get_from_surface (surface,
0, 0,
data->monitor_rect.width,
data->monitor_rect.height);
/* invalidate existing cached pixbuf */
g_object_set_data (G_OBJECT (priv->current_background), "pixbuf", NULL);
g_object_set_data (G_OBJECT (panel->current_background), "pixbuf", NULL);
/* remove the temporary file created by the shell */
g_unlink (panel->priv->screenshot_path);
g_clear_pointer (&priv->screenshot_path, g_free);
g_unlink (panel->screenshot_path);
g_clear_pointer (&panel->screenshot_path, g_free);
cairo_destroy (cr);
cairo_surface_destroy (surface);
out:
update_display_preview (panel, WID ("background-desktop-drawingarea"), priv->current_background);
update_display_preview (panel, WID ("background-desktop-drawingarea"), panel->current_background);
g_free (data);
}
@ -376,7 +368,6 @@ calculate_contiguous_workarea (ScreenshotData *data)
static void
get_screenshot_async (CcBackgroundPanel *panel)
{
CcBackgroundPanelPrivate *priv = panel->priv;
gchar *path, *tmpname;
const gchar *method_name;
GVariant *method_params;
@ -406,8 +397,8 @@ get_screenshot_async (CcBackgroundPanel *panel)
g_mkdir_with_parents (path, USER_DIR_MODE);
tmpname = g_strdup_printf ("scr-%d.png", g_random_int ());
g_free (panel->priv->screenshot_path);
panel->priv->screenshot_path = g_build_filename (path, tmpname, NULL);
g_free (panel->screenshot_path);
panel->screenshot_path = g_build_filename (path, tmpname, NULL);
g_free (path);
g_free (tmpname);
@ -416,9 +407,9 @@ get_screenshot_async (CcBackgroundPanel *panel)
data->capture_rect.x, data->capture_rect.y,
data->capture_rect.width, data->capture_rect.height,
FALSE, /* flash */
panel->priv->screenshot_path);
panel->screenshot_path);
g_dbus_connection_call (panel->priv->connection,
g_dbus_connection_call (panel->connection,
"org.gnome.Shell.Screenshot",
"/org/gnome/Shell/Screenshot",
"org.gnome.Shell.Screenshot",
@ -427,7 +418,7 @@ get_screenshot_async (CcBackgroundPanel *panel)
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
priv->capture_cancellable,
panel->capture_cancellable,
on_screenshot_finished,
data);
}
@ -437,15 +428,14 @@ on_preview_draw (GtkWidget *widget,
cairo_t *cr,
CcBackgroundPanel *panel)
{
CcBackgroundPanelPrivate *priv = panel->priv;
/* we have another shot in flight or an existing cache */
if (panel->priv->display_screenshot == NULL
&& panel->priv->screenshot_path == NULL)
if (panel->display_screenshot == NULL
&& panel->screenshot_path == NULL)
{
get_screenshot_async (panel);
}
else
update_display_preview (panel, widget, priv->current_background);
update_display_preview (panel, widget, panel->current_background);
return TRUE;
}
@ -455,21 +445,17 @@ on_lock_preview_draw (GtkWidget *widget,
cairo_t *cr,
CcBackgroundPanel *panel)
{
CcBackgroundPanelPrivate *priv = panel->priv;
update_display_preview (panel, widget, priv->current_lock_background);
update_display_preview (panel, widget, panel->current_lock_background);
return TRUE;
}
static void
reload_current_bg (CcBackgroundPanel *self,
reload_current_bg (CcBackgroundPanel *panel,
GSettings *settings)
{
CcBackgroundPanelPrivate *priv;
CcBackgroundItem *saved, *configured;
gchar *uri, *pcolor, *scolor;
priv = self->priv;
/* Load the saved configuration */
uri = get_save_path (SAVE_PATH);
saved = cc_background_xml_get_item (uri);
@ -520,15 +506,15 @@ reload_current_bg (CcBackgroundPanel *self,
if (saved != NULL)
g_object_unref (saved);
if (settings == priv->settings)
if (settings == panel->settings)
{
g_clear_object (&priv->current_background);
priv->current_background = configured;
g_clear_object (&panel->current_background);
panel->current_background = configured;
}
else
{
g_clear_object (&priv->current_lock_background);
priv->current_lock_background = configured;
g_clear_object (&panel->current_lock_background);
panel->current_lock_background = configured;
}
cc_background_item_load (configured, NULL);
}
@ -559,7 +545,6 @@ copy_finished_cb (GObject *source_object,
{
GError *err = NULL;
CcBackgroundPanel *panel = (CcBackgroundPanel *) pointer;
CcBackgroundPanelPrivate *priv = panel->priv;
CcBackgroundItem *item;
CcBackgroundItem *current_background;
GSettings *settings;
@ -582,20 +567,20 @@ copy_finished_cb (GObject *source_object,
/* the panel may have been destroyed before the callback is run, so be sure
* to check the widgets are not NULL */
if (priv->spinner)
if (panel->spinner)
{
gtk_widget_destroy (GTK_WIDGET (priv->spinner));
priv->spinner = NULL;
gtk_widget_destroy (GTK_WIDGET (panel->spinner));
panel->spinner = NULL;
}
if (current_background)
cc_background_item_load (current_background, NULL);
if (priv->builder)
if (panel->builder)
{
char *filename;
update_preview (priv, settings, item);
update_preview (panel, settings, item);
current_background = CURRENT_BG;
/* Save the source XML if there is one */
@ -613,7 +598,6 @@ set_background (CcBackgroundPanel *panel,
GSettings *settings,
CcBackgroundItem *item)
{
CcBackgroundPanelPrivate *priv = panel->priv;
GDesktopBackgroundStyle style;
gboolean save_settings = TRUE;
const char *uri;
@ -663,24 +647,24 @@ set_background (CcBackgroundPanel *panel,
g_object_unref (pixbuf);
g_free (dest_path);
if (priv->copy_cancellable)
if (panel->copy_cancellable)
{
g_cancellable_cancel (priv->copy_cancellable);
g_cancellable_reset (priv->copy_cancellable);
g_cancellable_cancel (panel->copy_cancellable);
g_cancellable_reset (panel->copy_cancellable);
}
if (priv->spinner)
if (panel->spinner)
{
gtk_widget_destroy (GTK_WIDGET (priv->spinner));
priv->spinner = NULL;
gtk_widget_destroy (GTK_WIDGET (panel->spinner));
panel->spinner = NULL;
}
/* create a spinner while the file downloads */
priv->spinner = gtk_spinner_new ();
gtk_spinner_start (GTK_SPINNER (priv->spinner));
gtk_box_pack_start (GTK_BOX (WID ("bottom-hbox")), priv->spinner, FALSE,
panel->spinner = gtk_spinner_new ();
gtk_spinner_start (GTK_SPINNER (panel->spinner));
gtk_box_pack_start (GTK_BOX (WID ("bottom-hbox")), panel->spinner, FALSE,
FALSE, 6);
gtk_widget_show (priv->spinner);
gtk_widget_show (panel->spinner);
/* reference the panel in case it is removed before the copy is
* finished */
@ -688,7 +672,7 @@ set_background (CcBackgroundPanel *panel,
g_object_set_data_full (G_OBJECT (source), "item", g_object_ref (item), g_object_unref);
g_object_set_data (G_OBJECT (source), "settings", settings);
g_file_copy_async (source, dest, G_FILE_COPY_OVERWRITE,
G_PRIORITY_DEFAULT, priv->copy_cancellable,
G_PRIORITY_DEFAULT, panel->copy_cancellable,
NULL, NULL,
copy_finished_cb, panel);
g_object_unref (source);
@ -764,32 +748,31 @@ on_chooser_dialog_response (GtkDialog *dialog,
}
static void
launch_chooser (CcBackgroundPanel *self,
launch_chooser (CcBackgroundPanel *panel,
GSettings *settings)
{
CcBackgroundPanelPrivate *priv = self->priv;
GtkWidget *dialog;
dialog = cc_background_chooser_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (WID ("background-panel"))));
g_object_set_data (G_OBJECT (dialog), "settings", settings);
gtk_widget_show (dialog);
g_signal_connect (dialog, "response", G_CALLBACK (on_chooser_dialog_response), self);
priv->chooser = dialog;
g_object_add_weak_pointer (G_OBJECT (dialog), (gpointer *) &priv->chooser);
g_signal_connect (dialog, "response", G_CALLBACK (on_chooser_dialog_response), panel);
panel->chooser = dialog;
g_object_add_weak_pointer (G_OBJECT (dialog), (gpointer *) &panel->chooser);
}
static void
on_background_button_clicked (GtkButton *button,
CcBackgroundPanel *self)
{
launch_chooser (self, self->priv->settings);
launch_chooser (self, self->settings);
}
static void
on_lock_button_clicked (GtkButton *button,
CcBackgroundPanel *self)
{
launch_chooser (self, self->priv->lock_settings);
launch_chooser (self, self->lock_settings);
}
static void
@ -798,24 +781,21 @@ on_settings_changed (GSettings *settings,
CcBackgroundPanel *self)
{
reload_current_bg (self, settings);
update_preview (self->priv, settings, NULL);
update_preview (self, settings, NULL);
}
static void
cc_background_panel_init (CcBackgroundPanel *self)
cc_background_panel_init (CcBackgroundPanel *panel)
{
CcBackgroundPanelPrivate *priv;
gchar *objects[] = {"background-panel", NULL };
GError *err = NULL;
GtkWidget *widget;
priv = self->priv = BACKGROUND_PANEL_PRIVATE (self);
priv->connection = g_application_get_dbus_connection (g_application_get_default ());
panel->connection = g_application_get_dbus_connection (g_application_get_default ());
g_resources_register (cc_background_get_resource ());
priv->builder = gtk_builder_new ();
gtk_builder_add_objects_from_resource (priv->builder,
panel->builder = gtk_builder_new ();
gtk_builder_add_objects_from_resource (panel->builder,
"/org/gnome/control-center/background/background.ui",
objects, &err);
@ -826,42 +806,42 @@ cc_background_panel_init (CcBackgroundPanel *self)
return;
}
priv->settings = g_settings_new (WP_PATH_ID);
g_settings_delay (priv->settings);
panel->settings = g_settings_new (WP_PATH_ID);
g_settings_delay (panel->settings);
priv->lock_settings = g_settings_new (WP_LOCK_PATH_ID);
g_settings_delay (priv->lock_settings);
panel->lock_settings = g_settings_new (WP_LOCK_PATH_ID);
g_settings_delay (panel->lock_settings);
/* add the top level widget */
widget = WID ("background-panel");
gtk_container_add (GTK_CONTAINER (self), widget);
gtk_widget_show_all (GTK_WIDGET (self));
gtk_container_add (GTK_CONTAINER (panel), widget);
gtk_widget_show_all (GTK_WIDGET (panel));
/* setup preview area */
widget = WID ("background-desktop-drawingarea");
g_signal_connect (widget, "draw", G_CALLBACK (on_preview_draw), self);
g_signal_connect (widget, "draw", G_CALLBACK (on_preview_draw), panel);
widget = WID ("background-lock-drawingarea");
g_signal_connect (widget, "draw", G_CALLBACK (on_lock_preview_draw), self);
g_signal_connect (widget, "draw", G_CALLBACK (on_lock_preview_draw), panel);
priv->copy_cancellable = g_cancellable_new ();
priv->capture_cancellable = g_cancellable_new ();
panel->copy_cancellable = g_cancellable_new ();
panel->capture_cancellable = g_cancellable_new ();
priv->thumb_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
panel->thumb_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
/* Load the backgrounds */
reload_current_bg (self, priv->settings);
update_preview (priv, priv->settings, NULL);
reload_current_bg (self, priv->lock_settings);
update_preview (priv, priv->lock_settings, NULL);
reload_current_bg (panel, panel->settings);
update_preview (panel, panel->settings, NULL);
reload_current_bg (panel, panel->lock_settings);
update_preview (panel, panel->lock_settings, NULL);
/* Background settings */
g_signal_connect (priv->settings, "changed", G_CALLBACK (on_settings_changed), self);
g_signal_connect (priv->lock_settings, "changed", G_CALLBACK (on_settings_changed), self);
g_signal_connect (panel->settings, "changed", G_CALLBACK (on_settings_changed), panel);
g_signal_connect (panel->lock_settings, "changed", G_CALLBACK (on_settings_changed), panel);
/* Background buttons */
widget = WID ("background-set-button");
g_signal_connect (widget, "clicked", G_CALLBACK (on_background_button_clicked), self);
g_signal_connect (widget, "clicked", G_CALLBACK (on_background_button_clicked), panel);
widget = WID ("background-lock-set-button");
g_signal_connect (widget, "clicked", G_CALLBACK (on_lock_button_clicked), self);
g_signal_connect (widget, "clicked", G_CALLBACK (on_lock_button_clicked), panel);
}

View file

@ -26,45 +26,8 @@
G_BEGIN_DECLS
#define CC_TYPE_BACKGROUND_PANEL cc_background_panel_get_type()
#define CC_BACKGROUND_PANEL(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
CC_TYPE_BACKGROUND_PANEL, CcBackgroundPanel))
#define CC_BACKGROUND_PANEL_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), \
CC_TYPE_BACKGROUND_PANEL, CcBackgroundPanelClass))
#define CC_IS_BACKGROUND_PANEL(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
CC_TYPE_BACKGROUND_PANEL))
#define CC_IS_BACKGROUND_PANEL_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
CC_TYPE_BACKGROUND_PANEL))
#define CC_BACKGROUND_PANEL_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
CC_TYPE_BACKGROUND_PANEL, CcBackgroundPanelClass))
typedef struct _CcBackgroundPanel CcBackgroundPanel;
typedef struct _CcBackgroundPanelClass CcBackgroundPanelClass;
typedef struct _CcBackgroundPanelPrivate CcBackgroundPanelPrivate;
struct _CcBackgroundPanel
{
CcPanel parent;
CcBackgroundPanelPrivate *priv;
};
struct _CcBackgroundPanelClass
{
CcPanelClass parent_class;
};
GType cc_background_panel_get_type (void) G_GNUC_CONST;
#define CC_TYPE_BACKGROUND_PANEL (cc_background_panel_get_type ())
G_DECLARE_FINAL_TYPE (CcBackgroundPanel, cc_background_panel, CC, BACKGROUND_PANEL, CcPanel)
G_END_DECLS

View file

@ -33,16 +33,16 @@
* returning to the main loop */
#define NUM_ITEMS_PER_BATCH 1
struct CcBackgroundXmlPrivate
struct _CcBackgroundXml
{
GObject parent_instance;
GHashTable *wp_hash;
GAsyncQueue *item_added_queue;
guint item_added_id;
GSList *monitors; /* GSList of GFileMonitor */
};
#define CC_BACKGROUND_XML_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_BACKGROUND_XML, CcBackgroundXmlPrivate))
enum {
ADDED,
LAST_SIGNAL
@ -118,20 +118,20 @@ idle_emit (CcBackgroundXml *xml)
GObject *item;
guint i = NUM_ITEMS_PER_BATCH;
g_async_queue_lock (xml->priv->item_added_queue);
g_async_queue_lock (xml->item_added_queue);
while (i > 0 && (item = g_async_queue_try_pop_unlocked (xml->priv->item_added_queue)) != NULL) {
while (i > 0 && (item = g_async_queue_try_pop_unlocked (xml->item_added_queue)) != NULL) {
g_signal_emit (G_OBJECT (xml), signals[ADDED], 0, item);
g_object_unref (item);
i--;
}
g_async_queue_unlock (xml->priv->item_added_queue);
g_async_queue_unlock (xml->item_added_queue);
if (g_async_queue_length (xml->priv->item_added_queue) > 0) {
if (g_async_queue_length (xml->item_added_queue) > 0) {
return TRUE;
} else {
xml->priv->item_added_id = 0;
xml->item_added_id = 0;
return FALSE;
}
}
@ -140,11 +140,11 @@ static void
emit_added_in_idle (CcBackgroundXml *xml,
GObject *object)
{
g_async_queue_lock (xml->priv->item_added_queue);
g_async_queue_push_unlocked (xml->priv->item_added_queue, object);
if (xml->priv->item_added_id == 0)
xml->priv->item_added_id = g_idle_add ((GSourceFunc) idle_emit, xml);
g_async_queue_unlock (xml->priv->item_added_queue);
g_async_queue_lock (xml->item_added_queue);
g_async_queue_push_unlocked (xml->item_added_queue, object);
if (xml->item_added_id == 0)
xml->item_added_id = g_idle_add ((GSourceFunc) idle_emit, xml);
g_async_queue_unlock (xml->item_added_queue);
}
#define NONE "(none)"
@ -305,14 +305,14 @@ cc_background_xml_load_xml_internal (CcBackgroundXml *xml,
g_free (uri);
/* Make sure we don't already have this one and that filename exists */
if (g_hash_table_lookup (xml->priv->wp_hash, id) != NULL) {
if (g_hash_table_lookup (xml->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 (xml->priv->wp_hash,
g_hash_table_insert (xml->wp_hash,
g_strdup (id),
g_object_ref (item));
if (in_thread)
@ -377,7 +377,7 @@ cc_background_xml_add_monitor (GFile *directory,
G_CALLBACK (gnome_wp_file_changed),
data);
data->priv->monitors = g_slist_prepend (data->priv->monitors, monitor);
data->monitors = g_slist_prepend (data->monitors, monitor);
}
static void
@ -460,7 +460,7 @@ cc_background_xml_load_list_finish (GAsyncResult *async_result)
g_warn_if_fail (g_simple_async_result_get_source_tag (result) == cc_background_xml_load_list_async);
data = CC_BACKGROUND_XML (g_simple_async_result_get_op_res_gpointer (result));
return data->priv->wp_hash;
return data->wp_hash;
}
static void
@ -631,16 +631,14 @@ cc_background_xml_finalize (GObject *object)
xml = CC_BACKGROUND_XML (object);
g_return_if_fail (xml->priv != NULL);
g_slist_free_full (xml->monitors, g_object_unref);
g_slist_free_full (xml->priv->monitors, g_object_unref);
g_clear_pointer (&xml->priv->wp_hash, g_hash_table_destroy);
if (xml->priv->item_added_id != 0) {
g_source_remove (xml->priv->item_added_id);
xml->priv->item_added_id = 0;
g_clear_pointer (&xml->wp_hash, g_hash_table_destroy);
if (xml->item_added_id != 0) {
g_source_remove (xml->item_added_id);
xml->item_added_id = 0;
}
g_clear_pointer (&xml->priv->item_added_queue, g_async_queue_unref);
g_clear_pointer (&xml->item_added_queue, g_async_queue_unref);
}
static void
@ -657,19 +655,16 @@ cc_background_xml_class_init (CcBackgroundXmlClass *klass)
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, CC_TYPE_BACKGROUND_ITEM);
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,
xml->wp_hash = g_hash_table_new_full (g_str_hash,
g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_object_unref);
xml->priv->item_added_queue = g_async_queue_new_full ((GDestroyNotify) g_object_unref);
xml->item_added_queue = g_async_queue_new_full ((GDestroyNotify) g_object_unref);
}
CcBackgroundXml *

View file

@ -26,28 +26,8 @@
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
{
GObject parent;
CcBackgroundXmlPrivate *priv;
} CcBackgroundXml;
typedef struct
{
GObjectClass parent_class;
void (*added) (CcBackgroundXml *xml, GObject *item);
} CcBackgroundXmlClass;
GType cc_background_xml_get_type (void);
#define CC_TYPE_BACKGROUND_XML (cc_background_xml_get_type ())
G_DECLARE_FINAL_TYPE (CcBackgroundXml, cc_background_xml, CC, BACKGROUND_XML, GObject)
CcBackgroundXml *cc_background_xml_new (void);