[gnome-control-center/wip/jsparber/background: 7/58] [feat] working wallpaper gallery
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/jsparber/background: 7/58] [feat] working wallpaper gallery
- Date: Fri, 24 Nov 2017 21:46:26 +0000 (UTC)
commit 4fe9a033c73d4b39c9c2da6d3604e30af372a9e8
Author: Julian Sparber <julian sparber net>
Date: Mon Oct 23 19:07:27 2017 +0200
[feat] working wallpaper gallery
panels/background/Makefile.am | 2 +
panels/background/bg-source.c | 9 +-
panels/background/bg-wallpapers-source.c | 40 ++++---
panels/background/cc-background-grid-item.c | 148 ++++++++++++++++++++++++
panels/background/cc-background-grid-item.h | 38 ++++++
panels/background/cc-background-panel.c | 165 ++++++++++++++++++++-------
6 files changed, 341 insertions(+), 61 deletions(-)
---
diff --git a/panels/background/Makefile.am b/panels/background/Makefile.am
index 688b2c1..3a38ae3 100644
--- a/panels/background/Makefile.am
+++ b/panels/background/Makefile.am
@@ -33,6 +33,8 @@ libbackground_chooser_la_SOURCES = \
cc-background-item.h \
cc-background-store.c \
cc-background-store.h \
+ cc-background-grid-item.c \
+ cc-background-grid-item.h \
cc-background-xml.c \
cc-background-xml.h \
bg-source.c \
diff --git a/panels/background/bg-source.c b/panels/background/bg-source.c
index 5c76d6b..7d08dbd 100644
--- a/panels/background/bg-source.c
+++ b/panels/background/bg-source.c
@@ -52,12 +52,12 @@ bg_source_calculate_thumbnail_dimensions (BgSource *source)
priv->thumbnail_height = THUMBNAIL_HEIGHT;
priv->thumbnail_width = THUMBNAIL_WIDTH;
- if (priv->window == NULL)
- return;
+ //if (priv->window == NULL)
+ // return;
- g_print("Error Here1\n");
- scale_factor = gtk_widget_get_scale_factor (priv->window);
+ //scale_factor = gtk_widget_get_scale_factor (priv->window);
+ scale_factor = 1;
if (scale_factor > 1)
{
priv->thumbnail_height *= scale_factor;
@@ -176,6 +176,7 @@ bg_source_get_scale_factor (BgSource *source)
priv = bg_source_get_instance_private (source);
+ return 1;
g_print("Error Here 2\n");
return gtk_widget_get_scale_factor (priv->window);
}
diff --git a/panels/background/bg-wallpapers-source.c b/panels/background/bg-wallpapers-source.c
index cfb032c..b94282c 100644
--- a/panels/background/bg-wallpapers-source.c
+++ b/panels/background/bg-wallpapers-source.c
@@ -56,7 +56,7 @@ load_wallpapers (gchar *key,
if (deleted)
return;
- gtk_list_store_append (store, &iter);
+// gtk_list_store_append (store, &iter);
scale_factor = bg_source_get_scale_factor (BG_SOURCE (source));
thumbnail_height = bg_source_get_thumbnail_height (BG_SOURCE (source));
@@ -68,13 +68,21 @@ load_wallpapers (gchar *key,
goto out;
surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale_factor, NULL);
- gtk_list_store_set (store, &iter,
- 0, surface,
- 1, item,
- 2, cc_background_item_get_name (item),
- -1);
- out:
+ gtk_list_store_insert_with_values (store, &iter, -1,
+ 0, surface,
+ 1, item,
+ 2, cc_background_item_get_name (item),
+ -1);
+
+ /* gtk_list_store_set (store, &iter,
+ 0, surface,
+ 1, item,
+ 2, cc_background_item_get_name (item),
+ -1);
+ */
+
+out:
g_clear_pointer (&surface, (GDestroyNotify) cairo_surface_destroy);
if (pixbuf)
g_object_unref (pixbuf);
@@ -82,16 +90,16 @@ load_wallpapers (gchar *key,
static void
list_load_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
+ GAsyncResult *res,
+ gpointer user_data)
{
cc_background_xml_load_list_finish (res);
}
static void
item_added (CcBackgroundXml *xml,
- CcBackgroundItem *item,
- BgWallpapersSource *self)
+ CcBackgroundItem *item,
+ BgWallpapersSource *self)
{
load_wallpapers (NULL, item, self);
}
@@ -108,9 +116,9 @@ load_default_bg (BgWallpapersSource *self)
system_data_dirs = g_get_system_data_dirs ();
for (i = 0; system_data_dirs[i]; i++) {
filename = g_build_filename (system_data_dirs[i],
- "gnome-background-properties",
- "adwaita.xml",
- NULL);
+ "gnome-background-properties",
+ "adwaita.xml",
+ NULL);
if (cc_background_xml_load_xml (self->xml, filename)) {
g_free (filename);
break;
@@ -127,7 +135,7 @@ bg_wallpapers_source_constructed (GObject *object)
G_OBJECT_CLASS (bg_wallpapers_source_parent_class)->constructed (object);
g_signal_connect (G_OBJECT (self->xml), "added",
- G_CALLBACK (item_added), self);
+ G_CALLBACK (item_added), self);
/* Try adding the default background first */
load_default_bg (self);
@@ -150,7 +158,7 @@ static void
bg_wallpapers_source_init (BgWallpapersSource *self)
{
self->thumb_factory =
- gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
+ gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
self->xml = cc_background_xml_new ();
}
diff --git a/panels/background/cc-background-grid-item.c b/panels/background/cc-background-grid-item.c
new file mode 100644
index 0000000..991267b
--- /dev/null
+++ b/panels/background/cc-background-grid-item.c
@@ -0,0 +1,148 @@
+/* cc-background-grid-item.c
+ *
+ * Copyright (C) 2017 Julian Sparber <julian sparber net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n.h>
+#include "cc-background-grid-item.h"
+#include "cc-background-item.h"
+
+struct _CcBackgroundGridItem
+{
+ GtkFlowBoxChild parent;
+
+ GtkImage *image;
+
+ /* data */
+ CcBackgroundItem *item;
+
+};
+
+
+G_DEFINE_TYPE (CcBackgroundGridItem, cc_background_grid_item, GTK_TYPE_FLOW_BOX_CHILD)
+
+ enum {
+ PROP_0,
+ PROP_ITEM
+ };
+
+GtkWidget*
+cc_background_grid_item_new (CcBackgroundItem *item)
+{
+
+ return g_object_new (CC_TYPE_BACKGROUND_GRID_ITEM,
+ "item", item,
+ NULL);
+}
+
+CcBackgroundItem * cc_background_grid_item_get_ref (CcBackgroundGridItem *self)
+{
+ return self->item;
+}
+void
+cc_background_grid_item_set_ref (CcBackgroundGridItem *self, CcBackgroundItem *item)
+{
+ self->item = item;
+}
+
+static void
+cc_background_grid_item_finalize (GObject *object)
+{
+ //CcBackgroundGridItem *self = CC_BACKGROUND_GRID_ITEM (object);
+
+ G_OBJECT_CLASS (cc_background_grid_item_parent_class)->finalize (object);
+
+}
+
+static void
+cc_background_grid_item_dispose (GObject *object)
+{
+ //CcBackgroundGridItem *self = CC_BACKGROUND_GRID_ITEM (object);
+
+ G_OBJECT_CLASS (cc_background_grid_item_parent_class)->dispose (object);
+}
+
+static void
+cc_background_grid_item_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ CcBackgroundGridItem *self = (CcBackgroundGridItem *) object;
+ switch (prop_id)
+ {
+
+ case PROP_ITEM:
+ self->item = g_value_dup_object (value);
+ g_debug ("Every set %p -> %p", value, self->item);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+cc_background_grid_item_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ CcBackgroundGridItem *self = (CcBackgroundGridItem *) object;
+
+ switch (prop_id)
+ {
+ case PROP_ITEM:
+ g_value_set_object (value, self->item);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+
+static void
+cc_background_grid_item_class_init (CcBackgroundGridItemClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->finalize = cc_background_grid_item_finalize;
+ object_class->dispose = cc_background_grid_item_dispose;
+ object_class->get_property = cc_background_grid_item_get_property;
+ object_class->set_property = cc_background_grid_item_set_property;
+
+ /*g_object_class_override_property (object_class,
+ PROP_ITEM,
+ "item");
+ */
+ g_object_class_install_property (object_class,
+ PROP_ITEM,
+ g_param_spec_object ("item",
+ "Background item reference",
+ "The reference to this background item",
+ CC_TYPE_BACKGROUND_ITEM,
+ G_PARAM_READWRITE));
+
+}
+
+static void
+cc_background_grid_item_init (CcBackgroundGridItem *self)
+{
+ g_debug ("Item ref: %p", self->item);
+ //gtk_widget_init_template (GTK_WIDGET (self));
+}
diff --git a/panels/background/cc-background-grid-item.h b/panels/background/cc-background-grid-item.h
new file mode 100644
index 0000000..025a56f
--- /dev/null
+++ b/panels/background/cc-background-grid-item.h
@@ -0,0 +1,38 @@
+/* cc-background-grid-item.h
+ *
+ * Copyright (C) 2017 Julian Sparber <julian sparber net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef CC_BACKGROUND_GRID_ITEM_H
+#define CC_BACKGROUND_GRID_ITEM_H
+
+#include <gtk/gtk.h>
+#include "cc-background-item.h"
+
+G_BEGIN_DECLS
+
+#define CC_TYPE_BACKGROUND_GRID_ITEM (cc_background_grid_item_get_type())
+
+G_DECLARE_FINAL_TYPE (CcBackgroundGridItem, cc_background_grid_item, CC, BACKGROUND_GRID_LIST,
GtkFlowBoxChild)
+
+GtkWidget* cc_background_grid_item_new (CcBackgroundItem *);
+
+void cc_background_grid_item_set_ref (CcBackgroundGridItem *self, CcBackgroundItem *item);
+CcBackgroundItem * cc_background_grid_item_get_ref (CcBackgroundGridItem *self);
+
+G_END_DECLS
+
+#endif /* CC_BACKGROUND_GRID_ITEM_H */
diff --git a/panels/background/cc-background-panel.c b/panels/background/cc-background-panel.c
index 4efece3..90ce89e 100644
--- a/panels/background/cc-background-panel.c
+++ b/panels/background/cc-background-panel.c
@@ -31,6 +31,7 @@
#include "bg-wallpapers-source.h"
#include "cc-background-item.h"
+#include "cc-background-grid-item.h"
#include "cc-background-resources.h"
#include "cc-background-xml.h"
@@ -55,6 +56,8 @@ struct _CcBackgroundPanel
CcBackgroundItem *current_background;
+ BgWallpapersSource *wallpapers_source;
+
GCancellable *copy_cancellable;
GCancellable *capture_cancellable;
@@ -100,6 +103,7 @@ cc_background_panel_dispose (GObject *object)
g_clear_object (&panel->capture_cancellable);
}
+ g_clear_object (&panel->wallpapers_source);
g_clear_object (&panel->thumb_factory);
g_clear_object (&panel->display_screenshot);
@@ -202,11 +206,11 @@ get_or_create_cached_pixbuf (CcBackgroundPanel *panel,
pixbuf = gdk_pixbuf_add_alpha (pixbuf, FALSE, 0,0,0);
pixbuf_tmp = gdk_pixbuf_scale_simple (panel->display_screenshot,
- preview_width,
- (preview_width
- * gdk_pixbuf_get_height (panel->display_screenshot)
- / gdk_pixbuf_get_width(panel->display_screenshot)),
- GDK_INTERP_BILINEAR);
+ preview_width,
+ (preview_width
+ * gdk_pixbuf_get_height (panel->display_screenshot)
+ / gdk_pixbuf_get_width(panel->display_screenshot)),
+ GDK_INTERP_BILINEAR);
gdk_pixbuf_copy_area (pixbuf_tmp,
0,
@@ -750,45 +754,123 @@ on_background_select (GtkFlowBox *box,
GtkFlowBoxChild *child,
gpointer user_data)
{
- g_debug ("New background selected");
-}
+ CcBackgroundGridItem *selected = (CcBackgroundGridItem *) child;
+ CcBackgroundPanel *panel = user_data;
+ CcBackgroundItem *item;
+ item = cc_background_grid_item_get_ref (selected);
+ g_print ("Background name %s\n", cc_background_item_get_name (item));
+ set_background (panel, panel->settings, item);
+}
-static void
-cc_background_create_wallpapers (CcBackgroundPanel *panel, GtkWidget *parent)
+gboolean
+foreach_background_item (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data)
{
- //GtkListStore *model;
- //GtkWidget *sw;
- //model = bg_source_get_liststore (BG_SOURCE (bg_wallpapers_source_new (GTK_WINDOW (WID
("background-desktop-drawingarea")))));
- //sw = create_view (parent, GTK_TREE_MODEL (model));
-
- GtkWidget *box;
+ CcBackgroundPanel *panel = data;
+ CcBackgroundGridItem *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);
+ g_print("Number of devices %d\n", gtk_tree_model_iter_n_children (model, iter));
+ g_print ("Background name %s\n", cc_background_item_get_name (item));
+
+ scale_factor = gtk_widget_get_scale_factor (panel);
+
+ pixbuf = cc_background_item_get_frame_thumbnail (item,
+ panel->thumb_factory,
+ preview_width,
+ preview_height,
+ scale_factor,
+ -2, TRUE);
+
+
+ //box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ widget = gtk_image_new_from_pixbuf (pixbuf);
+ //gtk_widget_show_all (box);
+ //gtk_widget_show_all (widget);
+
+ 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 (flow, widget);
+
+ //gtk_box_pack_start (box, widget, FALSE, FALSE, 0);
+ 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);
+ foreach_background_item (model, path, iter, user_data);
+}
+
+static void
+cc_background_create_wallpapers (CcBackgroundPanel *panel, GtkWidget *parent)
+{
+ GtkListStore *model;
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ GValue *value = NULL;
gint scale_factor;
+
scale_factor = gtk_widget_get_scale_factor (panel);
- for (int i = 0; i < 18; i++) {
- //widget = gtk_drawing_area_new ();
- box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- pixbuf = gdk_pixbuf_new_from_file ("/usr/share/backgrounds/gnome/adwaita-day.jpg", NULL);
- pixbuf = gdk_pixbuf_scale_simple (pixbuf,
- preview_width,
- preview_height,
- GDK_INTERP_BILINEAR);
-
- //widget = gtk_image_new ();
- //pixbuf = get_or_create_cached_pixbuf (panel, widget, panel->current_background);
- widget = gtk_image_new_from_pixbuf (pixbuf);
-
- gtk_box_pack_start (box, widget, FALSE, FALSE, 0);
- gtk_flow_box_insert (GTK_FLOW_BOX (parent), box, -1);
- //g_signal_connect (G_OBJECT (widget), "draw",
- // G_CALLBACK (on_slides_draw), panel);
+
+ g_print("Scale_factor works %d\n", scale_factor);
+ panel->wallpapers_source = bg_wallpapers_source_new (GTK_WINDOW (NULL));
+ model = bg_source_get_liststore (BG_SOURCE (panel->wallpapers_source));
+
+ gtk_tree_model_foreach (model, foreach_background_item, panel);
+
+ 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);
+ //path = gtk_tree_path_new_first ();
+
+ // path = gtk_tree_model_get (model, &iter, 1, &item, -1);
+ //if (gtk_tree_model_get_iter (model, &iter, (GtkTreePath*) path) == TRUE) {
+ //gtk_tree_model_get_value (model, &iter, 1, value);
+ //g_print (">>>>>>>>>>>>>>>>>>> %s", g_value_get_string(value));
+
+ //g_value_unset(value) ;
+ //}
+
+ /*
+ scale_factor = gtk_widget_get_scale_factor (panel);
+ for (int i = 0; i < 18; i++) {
+ //widget = gtk_drawing_area_new ();
+ box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ pixbuf = gdk_pixbuf_new_from_file ("/usr/share/backgrounds/gnome/adwaita-day.jpg", NULL);
+ pixbuf = gdk_pixbuf_scale_simple (pixbuf,
+ preview_width,
+ preview_height,
+ GDK_INTERP_BILINEAR);
+
+ //widget = gtk_image_new ();
+ //pixbuf = get_or_create_cached_pixbuf (panel, widget, panel->current_background);
+ widget = gtk_image_new_from_pixbuf (pixbuf);
+
+ gtk_box_pack_start (box, widget, FALSE, FALSE, 0);
+ gtk_flow_box_insert (GTK_FLOW_BOX (parent), box, -1);
+ //g_signal_connect (G_OBJECT (widget), "draw",
+ // G_CALLBACK (on_slides_draw), panel);
}
+ */
}
static void
@@ -818,15 +900,7 @@ cc_background_panel_init (CcBackgroundPanel *panel)
panel->settings = g_settings_new (WP_PATH_ID);
g_settings_delay (panel->settings);
- /* add the gallery widget */
- widget = WID ("background-gallery");
-
- g_signal_connect (G_OBJECT (widget), "child-activated",
- G_CALLBACK (on_background_select), panel);
-
- cc_background_create_wallpapers (panel, widget);
-
- /* add the top level widget */
+ /* add the top level widget */
widget = WID ("background-panel");
gtk_container_add (GTK_CONTAINER (panel), widget);
@@ -852,6 +926,15 @@ cc_background_panel_init (CcBackgroundPanel *panel)
panel->thumb_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
+/* add the gallery widget */
+ widget = WID ("background-gallery");
+
+ g_signal_connect (G_OBJECT (widget), "child-activated",
+ G_CALLBACK (on_background_select), panel);
+
+ cc_background_create_wallpapers (panel, widget);
+
+
/* Load the backgrounds */
reload_current_bg (panel, panel->settings);
update_preview (panel, panel->settings, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]