[gnome-control-center/wip/jsparber/background: 29/58] [feat] use GListstore to store wallpapers and bind it to gtkflowbox
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/jsparber/background: 29/58] [feat] use GListstore to store wallpapers and bind it to gtkflowbox
- Date: Fri, 24 Nov 2017 21:47:12 +0000 (UTC)
commit aab238bf102a1837d760657a7e736c8f9b19aa21
Author: Julian Sparber <julian sparber net>
Date: Tue Nov 7 04:13:05 2017 +0100
[feat] use GListstore to store wallpapers and bind it to gtkflowbox
panels/background/cc-background-panel.c | 105 +++++++++++++------------------
panels/background/cc-background-store.c | 57 ++++++++++++++++-
panels/background/cc-background-store.h | 3 +-
3 files changed, 101 insertions(+), 64 deletions(-)
---
diff --git a/panels/background/cc-background-panel.c b/panels/background/cc-background-panel.c
index 18d4ab3..25baf75 100644
--- a/panels/background/cc-background-panel.c
+++ b/panels/background/cc-background-panel.c
@@ -30,8 +30,8 @@
#include "cc-background-panel.h"
-#include "bg-wallpapers-source.h"
#include "cc-background-item.h"
+#include "cc-background-store.h"
#include "cc-background-grid-item.h"
#include "cc-background-resources.h"
#include "cc-background-xml.h"
@@ -56,8 +56,7 @@ struct _CcBackgroundPanel
GnomeDesktopThumbnailFactory *thumb_factory;
CcBackgroundItem *current_background;
-
- BgWallpapersSource *wallpapers_source;
+ CcBackgroundStore *store;
GCancellable *copy_cancellable;
@@ -103,6 +102,8 @@ cc_background_panel_finalize (GObject *object)
CcBackgroundPanel *panel = CC_BACKGROUND_PANEL (object);
g_clear_object (&panel->current_background);
+ g_clear_object (&panel->store);
+ g_clear_object (&panel->settings);
G_OBJECT_CLASS (cc_background_panel_parent_class)->finalize (object);
}
@@ -446,6 +447,7 @@ set_background (CcBackgroundPanel *panel,
g_settings_set_string (settings, WP_URI_KEY, uri);
}
+
/* Also set the placement if we have a URI and the previous value was none */
if (flags & CC_BACKGROUND_ITEM_HAS_PLACEMENT)
{
@@ -475,6 +477,7 @@ set_background (CcBackgroundPanel *panel,
if (create_save_dir ())
cc_background_xml_save (panel->current_background, filename);
}
+
}
static void
@@ -499,54 +502,6 @@ on_background_select (GtkFlowBox *box,
set_background (panel, panel->settings, item);
}
-static gboolean
-do_foreach_background_item (GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gpointer data)
-{
- CcBackgroundPanel *panel = data;
- GtkWidget *flow;
- GtkWidget *widget;
- GdkPixbuf *pixbuf;
- CcBackgroundItem *item;
- gint scale_factor;
- const gint preview_width = 309;
- const gint preview_height = 168;
-
- gtk_tree_model_get (model, iter, 1, &item, -1);
-
- scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (panel));
-
- pixbuf = cc_background_item_get_frame_thumbnail (item,
- panel->thumb_factory,
- preview_width,
- preview_height,
- scale_factor,
- -2, TRUE);
-
- widget = gtk_image_new_from_pixbuf (pixbuf);
-
- flow = cc_background_grid_item_new(item);
- cc_background_grid_item_set_ref (flow, item);
- gtk_widget_show (flow);
- gtk_widget_show (widget);
- gtk_container_add (GTK_CONTAINER (flow), widget);
-
- gtk_flow_box_insert (GTK_FLOW_BOX (WID("background-gallery")), flow, -1);
- return TRUE;
-}
-
-static void
-on_source_added_cb (GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gpointer user_data)
-{
- //gtk_tree_model_foreach (model, foreach_background_item, user_data);
- do_foreach_background_item (model, path, iter, user_data);
-}
-
static void
on_open_gnome_photos (GtkWidget *widget,
gpointer user_data)
@@ -633,20 +588,37 @@ is_gnome_photos_installed ()
return TRUE;
}
-static void
-load_wallpapers (CcBackgroundPanel *panel,
- GtkWidget *parent)
+static GtkWidget *
+create_gallery_item (gpointer item,
+ gpointer user_data)
{
- GtkListStore *model;
+ CcBackgroundPanel *panel = user_data;
+ GtkWidget *flow;
+ GtkWidget *widget;
+ GdkPixbuf *pixbuf;
+ CcBackgroundItem *self = item;
+ gint scale_factor;
+ const gint preview_width = 309;
+ const gint preview_height = 168;
- panel->wallpapers_source = bg_wallpapers_source_new (GTK_WIDGET (panel));
- model = bg_source_get_liststore (BG_SOURCE (panel->wallpapers_source));
+ scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (panel));
- gtk_tree_model_foreach (GTK_TREE_MODEL (model), do_foreach_background_item, panel);
+ pixbuf = cc_background_item_get_frame_thumbnail (self,
+ panel->thumb_factory,
+ preview_width,
+ preview_height,
+ scale_factor,
+ -2, TRUE);
+
+ widget = gtk_image_new_from_pixbuf (pixbuf);
- g_signal_connect (model, "row-inserted", G_CALLBACK (on_source_added_cb), panel);
- //g_signal_connect (model, "row-deleted", G_CALLBACK (on_source_removed_cb), chooser);
- //g_signal_connect (model, "row-changed", G_CALLBACK (on_source_modified_cb), chooser);
+ flow = cc_background_grid_item_new(self);
+ cc_background_grid_item_set_ref (flow, self);
+ gtk_widget_show (flow);
+ gtk_widget_show (widget);
+ gtk_container_add (GTK_CONTAINER (flow), widget);
+
+ return flow;
}
static void
@@ -657,6 +629,9 @@ cc_background_panel_init (CcBackgroundPanel *panel)
GtkCssProvider *provider;
GtkWidget *widget;
+ /* Create wallpapers store */
+ panel->store = cc_background_store_new ();
+
panel->connection = g_application_get_dbus_connection (g_application_get_default ());
g_resources_register (cc_background_get_resource ());
@@ -719,10 +694,16 @@ cc_background_panel_init (CcBackgroundPanel *panel)
G_CALLBACK (on_background_select), panel);
/* Load the backgrounds */
- load_wallpapers (panel, widget);
reload_current_bg (panel, panel->settings);
update_preview (panel, panel->settings, NULL);
+ /* Bind liststore to flowbox */
+ gtk_flow_box_bind_model (GTK_FLOW_BOX (WID("background-gallery")),
+ G_LIST_MODEL (cc_background_store_get_liststore (panel->store)),
+ create_gallery_item,
+ panel,
+ NULL);
+
/* Background settings */
g_signal_connect (panel->settings, "changed", G_CALLBACK (on_settings_changed), panel);
}
diff --git a/panels/background/cc-background-store.c b/panels/background/cc-background-store.c
index 33c1900..05eb09c 100644
--- a/panels/background/cc-background-store.c
+++ b/panels/background/cc-background-store.c
@@ -21,12 +21,14 @@
#include <gio/gio.h>
#include "cc-background-store.h"
#include "cc-background-item.h"
+#include "cc-background-xml.h"
struct _CcBackgroundStore
{
GObject parent_instance;
/* Other members, including private data. */
+ //CcBackgroundStorePrivate *priv;
};
/* Private structure definition. */
@@ -34,7 +36,8 @@ typedef struct _CcBackgroundStorePrivate CcBackgroundStorePrivate;
struct _CcBackgroundStorePrivate
{
- GListStore * model;
+ GListStore *model;
+ CcBackgroundXml *xml;
};
G_DEFINE_TYPE_WITH_PRIVATE (CcBackgroundStore, cc_background_store, G_TYPE_OBJECT)
@@ -56,6 +59,7 @@ cc_background_store_dispose (GObject *gobject)
* NULL; g_clear_object() does this for us.
*/
g_clear_object (&priv->model);
+ g_clear_object (&priv->xml);
/* Always chain up to the parent class; there is no need to check if
* the parent class implements the dispose() virtual function: it is
@@ -77,12 +81,50 @@ cc_background_store_finalize (GObject *gobject)
G_OBJECT_CLASS (cc_background_store_parent_class)->finalize (gobject);
}
+
+static void
+item_added (CcBackgroundXml *xml,
+ CcBackgroundItem *item,
+ CcBackgroundStore *self)
+{
+ CcBackgroundStorePrivate *priv = cc_background_store_get_instance_private (self);
+ g_list_store_append (priv->model, item);
+}
+
+static void
+list_load_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ cc_background_xml_load_list_finish (res);
+}
+
+static void
+cc_background_store_constructed (GObject *object)
+{
+ CcBackgroundStore *self = CC_BACKGROUND_STORE (object);
+ CcBackgroundStorePrivate *priv = cc_background_store_get_instance_private (self);
+
+ G_OBJECT_CLASS (cc_background_store_parent_class)->constructed (object);
+
+ g_signal_connect (G_OBJECT (priv->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);
+}
+
+
+
static void
cc_background_store_class_init (CcBackgroundStoreClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = cc_background_store_dispose;
+ object_class->constructed = cc_background_store_constructed;
object_class->finalize = cc_background_store_finalize;
}
@@ -91,4 +133,17 @@ cc_background_store_init (CcBackgroundStore *self)
{
CcBackgroundStorePrivate *priv = cc_background_store_get_instance_private (self);
priv->model = g_list_store_new (cc_background_item_get_type());
+ priv->xml = cc_background_xml_new ();
+}
+
+GListStore *
+cc_background_store_get_liststore (CcBackgroundStore *self) {
+ CcBackgroundStorePrivate *priv = cc_background_store_get_instance_private (self);
+ return priv->model;
+}
+
+CcBackgroundStore *
+cc_background_store_new ()
+{
+ return g_object_new (CC_TYPE_BACKGROUND_STORE, NULL);
}
diff --git a/panels/background/cc-background-store.h b/panels/background/cc-background-store.h
index 40da76d..faec580 100644
--- a/panels/background/cc-background-store.h
+++ b/panels/background/cc-background-store.h
@@ -37,7 +37,8 @@ G_DECLARE_FINAL_TYPE (CcBackgroundStore, cc_background_store, CC, BACKGROUND_STO
/*
* Method definitions.
*/
-CcBackgroundStore *cc_backgroud_store_new (void);
+CcBackgroundStore *cc_background_store_new (void);
+GListStore *cc_background_store_get_liststore (CcBackgroundStore *);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]