summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Sparber <julian@sparber.net>2017-12-05 16:22:29 +0100
committerJulian Sparber <julian@sparber.net>2018-02-17 19:53:41 +0100
commit6d95f0e685683f3ee2fbda50fecd5925df9c1f27 (patch)
tree0e29a96cf05586a0484dabf7edcd3f0ca1fd93af
parent4e43bd6ce866d39f9ae96fbb7beeccf9ede281b5 (diff)
downloadgnome-control-center-6d95f0e685683f3ee2fbda50fecd5925df9c1f27.tar.gz
background: start implementing the new design for the background panel
Start implementing the redesign v3 proposal made by Tobias Bernard wiki page: https://wiki.gnome.org/Design/SystemSettings/Background https://bugzilla.gnome.org/show_bug.cgi?id=788515
-rw-r--r--panels/background/background.gresource.xml1
-rw-r--r--panels/background/background.ui275
-rw-r--r--panels/background/bg-source.c11
-rw-r--r--panels/background/bg-wallpapers-source.c38
-rw-r--r--panels/background/bg-wallpapers-source.h2
-rw-r--r--panels/background/cc-background-grid-item.c148
-rw-r--r--panels/background/cc-background-grid-item.h38
-rw-r--r--panels/background/cc-background-panel.c305
-rw-r--r--panels/background/cc-background-store.c94
-rw-r--r--panels/background/cc-background-store.h44
-rw-r--r--panels/background/data/background.css7
-rw-r--r--panels/background/meson.build2
12 files changed, 619 insertions, 346 deletions
diff --git a/panels/background/background.gresource.xml b/panels/background/background.gresource.xml
index e8e4ff353..4a76129c2 100644
--- a/panels/background/background.gresource.xml
+++ b/panels/background/background.gresource.xml
@@ -2,5 +2,6 @@
<gresources>
<gresource prefix="/org/gnome/control-center/background">
<file preprocess="xml-stripblanks">background.ui</file>
+ <file alias="background.css">data/background.css</file>
</gresource>
</gresources>
diff --git a/panels/background/background.ui b/panels/background/background.ui
index abf79ea86..aae1f6bb1 100644
--- a/panels/background/background.ui
+++ b/panels/background/background.ui
@@ -4,245 +4,156 @@
<object class="GtkBox" id="background-panel">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="margin">32</property>
- <property name="spacing">12</property>
- <property name="valign">center</property>
+ <property name="hexpand">True</property>
+ <property name="orientation">vertical</property>
<child>
- <object class="GtkBox" id="box1">
+ <object class="GtkBox" id="background-preview">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="spacing">24</property>
+ <property name="margin">16</property>
+ <property name="halign">center</property>
+ <property name="orientation">vertical</property>
+ <property name="expand">False</property>
<child>
- <object class="GtkBox" id="vbox3">
+ <object class="GtkBox" id="background-preview-top">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="halign">end</property>
- <property name="valign">center</property>
+ <property name="margin">6</property>
+ <property name="spacing">6</property>
<property name="orientation">vertical</property>
+ <style>
+ <class name="black-border"/>
+ </style>
<child>
- <object class="GtkButton" id="background-set-button">
+ <object class="GtkDrawingArea" id="background-desktop-drawingarea">
+ <property name="width_request">310</property>
+ <property name="height_request">170</property>
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <child>
- <object class="GtkBox" id="box2">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="margin">6</property>
- <property name="spacing">6</property>
- <property name="orientation">vertical</property>
- <child>
- <object class="GtkDrawingArea" id="background-desktop-drawingarea">
- <property name="width_request">310</property>
- <property name="height_request">170</property>
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="valign">center</property>
- <property name="hexpand">True</property>
- <property name="vexpand">True</property>
- </object>
- </child>
- <child>
- <object class="GtkLabel" id="label1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">_Background</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">background-set-button</property>
- </object>
- </child>
- </object>
- </child>
+ <property name="can_focus">False</property>
+ <property name="valign">center</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
</object>
</child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkBox" id="bottom-hbox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">12</property>
<child>
- <object class="GtkBox" id="bottom-hbox">
+ <object class="GtkBox" id="hbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="spacing">12</property>
+ <property name="halign">center</property>
+ <property name="margin_top">12</property>
+ <property name="spacing">2</property>
<child>
- <object class="GtkBox" id="hbox2">
+ <object class="GtkImage" id="slide_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="halign">center</property>
- <property name="margin_top">12</property>
- <property name="spacing">2</property>
- <child>
- <object class="GtkImage" id="slide_image">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="icon_name">slideshow-symbolic</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="strut">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label"> </property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="slide-label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes" comments="This refers to a slideshow background">Changes throughout the day</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
- </child>
+ <property name="icon_name">slideshow-symbolic</property>
</object>
<packing>
- <property name="expand">True</property>
+ <property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
+ <child>
+ <object class="GtkLabel" id="strut">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label"> </property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="slide-label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes" comments="This refers to a slideshow background">Changes throughout the day</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
</object>
<packing>
- <property name="expand">False</property>
+ <property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">2</property>
+ <property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">0</property>
+ <property name="position">2</property>
</packing>
</child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="backgroud-gallery-box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
<child>
- <object class="GtkBox" id="vbox1">
+ <object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="orientation">vertical</property>
- <property name="halign">start</property>
- <property name="valign">center</property>
+ <property name="hscrollbar_policy">never</property>
<child>
- <object class="GtkButton" id="background-lock-set-button">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <child>
- <object class="GtkBox" id="box3">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="margin">6</property>
- <property name="spacing">6</property>
- <property name="orientation">vertical</property>
- <child>
- <object class="GtkDrawingArea" id="background-lock-drawingarea">
- <property name="width_request">310</property>
- <property name="height_request">170</property>
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="valign">center</property>
- <property name="hexpand">True</property>
- <property name="vexpand">True</property>
- </object>
- </child>
- <child>
- <object class="GtkLabel" id="label2">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes" comments="To translators: This is a noun, not a verb">_Lock Screen</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">background-lock-set-button</property>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkBox" id="bottom-hbox1">
+ <object class="GtkBox" id="box4">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="spacing">12</property>
+ <property name="orientation">vertical</property>
+ <style>
+ <class name="background-gallery"/>
+ </style>
<child>
- <object class="GtkBox" id="hbox1">
+ <object class="GtkFlowBox" id="background-gallery">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="homogeneous">True</property>
+ <property name="orientation">horizontal</property>
+ <property name="min-children-per-line">2</property>
+ <property name="row_spacing">5</property>
+ <property name="column_spacing">5</property>
<property name="halign">center</property>
- <property name="margin_top">12</property>
- <property name="spacing">2</property>
- <child>
- <object class="GtkImage" id="slide_image1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="icon_name">slideshow-symbolic</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="strut1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label"> </property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="slide-label1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes" comments="This refers to a slideshow background">Changes throughout the day</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
- </child>
+ <property name="valign">center</property>
+ <property name="margin">25</property>
+ <property name="margin_top">50</property>
</object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
</child>
+
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">2</property>
- </packing>
</child>
</object>
<packing>
- <property name="expand">False</property>
+ <property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">1</property>
+ <property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">0</property>
+ <property name="position">1</property>
</packing>
</child>
</object>
diff --git a/panels/background/bg-source.c b/panels/background/bg-source.c
index e48daf0f2..7d08dbd93 100644
--- a/panels/background/bg-source.c
+++ b/panels/background/bg-source.c
@@ -52,10 +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;
- 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;
@@ -173,6 +175,9 @@ bg_source_get_scale_factor (BgSource *source)
g_return_val_if_fail (BG_IS_SOURCE (source), 1);
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 50f40b369..40f8c1aff 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,26 +68,34 @@ load_wallpapers (gchar *key,
return;
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);
+
+ 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);
+ */
g_clear_pointer (&surface, (GDestroyNotify) cairo_surface_destroy);
}
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);
}
@@ -105,9 +113,9 @@ load_default_bg (BgWallpapersSource *self)
g_autofree gchar *filename = NULL;
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))
break;
}
@@ -121,7 +129,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);
@@ -144,7 +152,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/bg-wallpapers-source.h b/panels/background/bg-wallpapers-source.h
index 129c24931..729266910 100644
--- a/panels/background/bg-wallpapers-source.h
+++ b/panels/background/bg-wallpapers-source.h
@@ -31,7 +31,7 @@ G_BEGIN_DECLS
#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);
+BgWallpapersSource *bg_wallpapers_source_new (GtkWindow *);
G_END_DECLS
diff --git a/panels/background/cc-background-grid-item.c b/panels/background/cc-background-grid-item.c
new file mode 100644
index 000000000..991267b06
--- /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 000000000..025a56fab
--- /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 8d54d5633..afc822943 100644
--- a/panels/background/cc-background-panel.c
+++ b/panels/background/cc-background-panel.c
@@ -29,15 +29,15 @@
#include "cc-background-panel.h"
-#include "cc-background-chooser-dialog.h"
+#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"
#include "bg-pictures-source.h"
#define WP_PATH_ID "org.gnome.desktop.background"
-#define WP_LOCK_PATH_ID "org.gnome.desktop.screensaver"
#define WP_URI_KEY "picture-uri"
#define WP_OPTIONS_KEY "picture-options"
#define WP_SHADING_KEY "color-shading-type"
@@ -50,19 +50,17 @@ struct _CcBackgroundPanel
GtkBuilder *builder;
GDBusConnection *connection;
-
GSettings *settings;
- GSettings *lock_settings;
GnomeDesktopThumbnailFactory *thumb_factory;
CcBackgroundItem *current_background;
- CcBackgroundItem *current_lock_background;
+
+ BgWallpapersSource *wallpapers_source;
GCancellable *copy_cancellable;
GtkWidget *spinner;
- GtkWidget *chooser;
};
CC_PANEL_REGISTER (CcBackgroundPanel, cc_background_panel)
@@ -85,9 +83,6 @@ cc_background_panel_dispose (GObject *object)
/* destroying the builder object will also destroy the spinner */
panel->spinner = NULL;
- g_clear_object (&panel->settings);
- g_clear_object (&panel->lock_settings);
-
if (panel->copy_cancellable)
{
/* cancel any copy operation */
@@ -96,12 +91,6 @@ cc_background_panel_dispose (GObject *object)
g_clear_object (&panel->copy_cancellable);
}
- if (panel->chooser)
- {
- gtk_widget_destroy (panel->chooser);
- panel->chooser = NULL;
- }
-
g_clear_object (&panel->thumb_factory);
G_OBJECT_CLASS (cc_background_panel_parent_class)->dispose (object);
@@ -113,7 +102,6 @@ cc_background_panel_finalize (GObject *object)
CcBackgroundPanel *panel = CC_BACKGROUND_PANEL (object);
g_clear_object (&panel->current_background);
- g_clear_object (&panel->current_lock_background);
G_OBJECT_CLASS (cc_background_panel_parent_class)->finalize (object);
}
@@ -130,15 +118,6 @@ cc_background_panel_class_init (CcBackgroundPanelClass *klass)
object_class->finalize = cc_background_panel_finalize;
}
-static CcBackgroundItem *
-get_current_background (CcBackgroundPanel *panel, GSettings *settings)
-{
- if (settings == panel->settings)
- return panel->current_background;
- else
- return panel->current_lock_background;
-}
-
static void
update_preview (CcBackgroundPanel *panel,
GSettings *settings,
@@ -147,16 +126,13 @@ update_preview (CcBackgroundPanel *panel,
gboolean changes_with_time;
CcBackgroundItem *current_background;
- current_background = get_current_background (panel, settings);
+ current_background = panel->current_background;
if (item && current_background)
{
g_object_unref (current_background);
current_background = cc_background_item_copy (item);
- if (settings == panel->settings)
- panel->current_background = current_background;
- else
- panel->current_lock_background = current_background;
+ panel->current_background = current_background;
cc_background_item_load (current_background, NULL);
}
@@ -167,29 +143,19 @@ update_preview (CcBackgroundPanel *panel,
changes_with_time = cc_background_item_changes_with_time (current_background);
}
- if (settings == panel->settings)
- {
- gtk_widget_set_visible (WID ("slide_image"), changes_with_time);
- gtk_widget_set_visible (WID ("slide-label"), changes_with_time);
+ gtk_widget_set_visible (WID ("slide_image"), changes_with_time);
+ gtk_widget_set_visible (WID ("slide-label"), changes_with_time);
- gtk_widget_queue_draw (WID ("background-desktop-drawingarea"));
- }
- else
- {
- gtk_widget_set_visible (WID ("slide_image1"), changes_with_time);
- gtk_widget_set_visible (WID ("slide-label1"), changes_with_time);
-
- gtk_widget_queue_draw (WID ("background-lock-drawingarea"));
- }
+ gtk_widget_queue_draw (WID ("background-desktop-drawingarea"));
}
static gchar *
-get_save_path (CcBackgroundPanel *panel, GSettings *settings)
+get_save_path (const char *filename)
{
return g_build_filename (g_get_user_config_dir (),
"gnome-control-center",
"backgrounds",
- settings == panel->settings ? "last-edited.xml" : "last-edited-lock.xml",
+ filename,
NULL);
}
@@ -203,6 +169,7 @@ get_or_create_cached_pixbuf (CcBackgroundPanel *panel,
const gint preview_height = 168;
gint scale_factor;
GdkPixbuf *pixbuf;
+ GdkPixbuf *pixbuf_tmp;
pixbuf = g_object_get_data (G_OBJECT (background), "pixbuf");
if (pixbuf == NULL)
@@ -221,46 +188,26 @@ get_or_create_cached_pixbuf (CcBackgroundPanel *panel,
return pixbuf;
}
-static void
-update_display_preview (CcBackgroundPanel *panel,
- GtkWidget *widget,
- CcBackgroundItem *background)
+static gboolean
+on_preview_draw (GtkWidget *widget,
+ cairo_t *cr,
+ CcBackgroundPanel *panel)
{
GdkPixbuf *pixbuf;
- cairo_t *cr;
-
- pixbuf = get_or_create_cached_pixbuf (panel, widget, background);
-
- cr = gdk_cairo_create (gtk_widget_get_window (widget));
+ pixbuf = get_or_create_cached_pixbuf (panel,
+ widget,
+ panel->current_background);
gdk_cairo_set_source_pixbuf (cr,
pixbuf,
0, 0);
cairo_paint (cr);
- cairo_destroy (cr);
-}
-
-static gboolean
-on_preview_draw (GtkWidget *widget,
- cairo_t *cr,
- CcBackgroundPanel *panel)
-{
- update_display_preview (panel, widget, panel->current_background);
-
- return TRUE;
-}
-static gboolean
-on_lock_preview_draw (GtkWidget *widget,
- cairo_t *cr,
- CcBackgroundPanel *panel)
-{
- update_display_preview (panel, widget, panel->current_lock_background);
return TRUE;
}
static void
reload_current_bg (CcBackgroundPanel *panel,
- GSettings *settings)
+ GSettings *settings)
{
g_autoptr(CcBackgroundItem) saved = NULL;
CcBackgroundItem *configured;
@@ -269,7 +216,7 @@ reload_current_bg (CcBackgroundPanel *panel,
g_autofree gchar *scolor = NULL;
/* Load the saved configuration */
- uri = get_save_path (panel, settings);
+ uri = get_save_path ("last-edited.xml");
saved = cc_background_xml_get_item (uri);
/* initalise the current background information from settings */
@@ -303,23 +250,16 @@ reload_current_bg (CcBackgroundPanel *panel,
if (cc_background_item_get_placement (saved) == G_DESKTOP_BACKGROUND_STYLE_NONE)
flags &=~ (CC_BACKGROUND_ITEM_HAS_PCOLOR | CC_BACKGROUND_ITEM_HAS_SCOLOR);
g_object_set (G_OBJECT (configured),
- "name", cc_background_item_get_name (saved),
- "flags", flags,
- "source-url", cc_background_item_get_source_url (saved),
- "source-xml", cc_background_item_get_source_xml (saved),
- NULL);
+ "name", cc_background_item_get_name (saved),
+ "flags", flags,
+ "source-url", cc_background_item_get_source_url (saved),
+ "source-xml", cc_background_item_get_source_xml (saved),
+ NULL);
}
- if (settings == panel->settings)
- {
- g_clear_object (&panel->current_background);
- panel->current_background = configured;
- }
- else
- {
- g_clear_object (&panel->current_lock_background);
- panel->current_lock_background = configured;
- }
+ g_clear_object (&panel->current_background);
+ panel->current_background = configured;
+
cc_background_item_load (configured, NULL);
}
@@ -329,9 +269,9 @@ create_save_dir (void)
g_autofree char *path = NULL;
path = g_build_filename (g_get_user_config_dir (),
- "gnome-control-center",
- "backgrounds",
- NULL);
+ "gnome-control-center",
+ "backgrounds",
+ NULL);
if (g_mkdir_with_parents (path, USER_DIR_MODE) < 0)
{
g_warning ("Failed to create directory '%s'", path);
@@ -360,7 +300,7 @@ copy_finished_cb (GObject *source_object,
}
item = g_object_get_data (source_object, "item");
settings = g_object_get_data (source_object, "settings");
- current_background = get_current_background (panel, settings);
+ current_background = panel->current_background;
g_settings_apply (settings);
@@ -381,10 +321,10 @@ copy_finished_cb (GObject *source_object,
g_autofree gchar *filename = NULL;
update_preview (panel, settings, item);
- current_background = get_current_background (panel, settings);
+ current_background = panel->current_background;
/* Save the source XML if there is one */
- filename = get_save_path (panel, settings);
+ filename = get_save_path ("last-edited.xml");
if (create_save_dir ())
cc_background_xml_save (current_background, filename);
}
@@ -514,64 +454,132 @@ set_background (CcBackgroundPanel *panel,
g_settings_apply (settings);
/* Save the source XML if there is one */
- filename = get_save_path (panel, settings);
+ filename = get_save_path ("last-edited.xml");
if (create_save_dir ())
- cc_background_xml_save (get_current_background (panel, settings), filename);
+ cc_background_xml_save (panel->current_background, filename);
}
}
static void
-on_chooser_dialog_response (GtkDialog *dialog,
- int response_id,
- CcBackgroundPanel *panel)
+on_settings_changed (GSettings *settings,
+ gchar *key,
+ CcBackgroundPanel *self)
{
- if (response_id == GTK_RESPONSE_OK)
- {
- g_autoptr(CcBackgroundItem) item = NULL;
-
- item = cc_background_chooser_dialog_get_item (CC_BACKGROUND_CHOOSER_DIALOG (dialog));
- if (item != NULL)
- set_background (panel, g_object_get_data (G_OBJECT (dialog), "settings"), item);
- }
+ reload_current_bg (self, settings);
+ update_preview (self, settings, NULL);
+}
- gtk_widget_destroy (GTK_WIDGET (dialog));
+static GtkWidget *
+create_view (GtkWidget *parent, GtkTreeModel *model)
+{
+ GtkCellRenderer *renderer;
+ GtkWidget *icon_view;
+ GtkWidget *sw;
+
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+ gtk_widget_set_hexpand (sw, TRUE);
+ gtk_widget_set_vexpand (sw, TRUE);
+
+ icon_view = gtk_icon_view_new ();
+ gtk_icon_view_set_model (GTK_ICON_VIEW (icon_view), model);
+ gtk_widget_set_hexpand (icon_view, TRUE);
+ gtk_container_add (GTK_CONTAINER (sw), icon_view);
+
+ gtk_icon_view_set_columns (GTK_ICON_VIEW (icon_view), 3);
+
+ renderer = gtk_cell_renderer_pixbuf_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view),
+ renderer,
+ FALSE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
+ renderer,
+ "surface", 0,
+ NULL);
+
+ return sw;
}
static void
-launch_chooser (CcBackgroundPanel *panel,
- GSettings *settings)
+on_background_select (GtkFlowBox *box,
+ GtkFlowBoxChild *child,
+ gpointer user_data)
{
- 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), panel);
- panel->chooser = dialog;
- g_object_add_weak_pointer (G_OBJECT (dialog), (gpointer *) &panel->chooser);
+ CcBackgroundGridItem *selected = (CcBackgroundGridItem *) child;
+ CcBackgroundPanel *panel = user_data;
+ CcBackgroundItem *item;
+ item = cc_background_grid_item_get_ref (selected);
+
+ set_background (panel, panel->settings, item);
}
-static void
-on_background_button_clicked (GtkButton *button,
- CcBackgroundPanel *panel)
+gboolean
+do_foreach_background_item (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data)
{
- launch_chooser (panel, panel->settings);
+ 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);
+
+ 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);
+
+ 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 (flow, widget);
+
+ gtk_flow_box_insert (GTK_FLOW_BOX (WID("background-gallery")), flow, -1);
+ return TRUE;
}
static void
-on_lock_button_clicked (GtkButton *button,
- CcBackgroundPanel *panel)
+on_source_added_cb (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer user_data)
{
- launch_chooser (panel, panel->lock_settings);
+ //gtk_tree_model_foreach (model, foreach_background_item, user_data);
+ do_foreach_background_item (model, path, iter, user_data);
}
static void
-on_settings_changed (GSettings *settings,
- gchar *key,
- CcBackgroundPanel *panel)
+load_wallpapers (CcBackgroundPanel *panel, GtkWidget *parent)
{
- reload_current_bg (panel, settings);
- update_preview (panel, settings, NULL);
+ GtkListStore *model;
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ GValue *value = NULL;
+ gint scale_factor;
+
+ scale_factor = gtk_widget_get_scale_factor (panel);
+
+ 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, do_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);
}
static void
@@ -579,6 +587,8 @@ cc_background_panel_init (CcBackgroundPanel *panel)
{
gchar *objects[] = {"background-panel", NULL };
g_autoptr(GError) err = NULL;
+ GtkCssProvider *provider;
+ GtkStyleContext *context;
GtkWidget *widget;
panel->connection = g_application_get_dbus_connection (g_application_get_default ());
@@ -598,38 +608,43 @@ cc_background_panel_init (CcBackgroundPanel *panel)
panel->settings = g_settings_new (WP_PATH_ID);
g_settings_delay (panel->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 (panel), widget);
gtk_widget_show_all (GTK_WIDGET (panel));
+ /* add style */
+ widget = WID ("background-preview-top");
+ provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
+ gtk_css_provider_load_from_resource (provider,
+ "org/gnome/control-center/background/background.css");
+ context = gtk_widget_get_style_context (widget);
+ gtk_style_context_add_provider_for_screen (gdk_screen_get_default(),
+ provider,
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ g_object_unref (provider);
+
/* setup preview area */
widget = WID ("background-desktop-drawingarea");
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), panel);
panel->copy_cancellable = g_cancellable_new ();
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);
+
+ load_wallpapers (panel, widget);
+
/* Load the backgrounds */
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 (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), panel);
- widget = WID ("background-lock-set-button");
- g_signal_connect (widget, "clicked", G_CALLBACK (on_lock_button_clicked), panel);
}
diff --git a/panels/background/cc-background-store.c b/panels/background/cc-background-store.c
new file mode 100644
index 000000000..33c190049
--- /dev/null
+++ b/panels/background/cc-background-store.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2017 jsparber
+ *
+ * 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 2 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/>.
+ *
+ * Author: Julian Sparber <julian@sparber.net>
+ *
+ */
+
+#include <gio/gio.h>
+#include "cc-background-store.h"
+#include "cc-background-item.h"
+
+struct _CcBackgroundStore
+{
+ GObject parent_instance;
+
+ /* Other members, including private data. */
+};
+
+/* Private structure definition. */
+typedef struct _CcBackgroundStorePrivate CcBackgroundStorePrivate;
+
+struct _CcBackgroundStorePrivate
+{
+ GListStore * model;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (CcBackgroundStore, cc_background_store, G_TYPE_OBJECT)
+
+
+static void
+cc_background_store_dispose (GObject *gobject)
+{
+ CcBackgroundStorePrivate *priv = cc_background_store_get_instance_private (CC_BACKGROUND_STORE (gobject));
+
+ /* In dispose(), you are supposed to free all types referenced from this
+ * object which might themselves hold a reference to self. Generally,
+ * the most simple solution is to unref all members on which you own a
+ * reference.
+ */
+
+ /* dispose() might be called multiple times, so we must guard against
+ * calling g_object_unref() on an invalid GObject by setting the member
+ * NULL; g_clear_object() does this for us.
+ */
+ g_clear_object (&priv->model);
+
+ /* Always chain up to the parent class; there is no need to check if
+ * the parent class implements the dispose() virtual function: it is
+ * always guaranteed to do so
+ */
+ G_OBJECT_CLASS (cc_background_store_parent_class)->dispose (gobject);
+}
+
+static void
+cc_background_store_finalize (GObject *gobject)
+{
+ //CcBackgroundStorePrivate *priv = cc_background_store_get_instance_private (CC_BACKGROUND_STORE (gobject));
+
+ //g_free (priv->filename);
+
+ /* Always chain up to the parent class; as with dispose(), finalize()
+ * is guaranteed to exist on the parent's class virtual function table
+ */
+ G_OBJECT_CLASS (cc_background_store_parent_class)->finalize (gobject);
+}
+
+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->finalize = cc_background_store_finalize;
+}
+
+static void
+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());
+}
diff --git a/panels/background/cc-background-store.h b/panels/background/cc-background-store.h
new file mode 100644
index 000000000..40da76d8b
--- /dev/null
+++ b/panels/background/cc-background-store.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2017 jsparber
+ *
+ * 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 2 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/>.
+ *
+ * Author: Julian Sparber <julian@sparber.net>
+ *
+ */
+
+#ifndef __CC_BACKGROUND_STORE_H__
+#define __CC_BACKGROUND_STORE_H__
+
+#include <glib-object.h>
+/*
+ * Potentially, include other headers on which this header depends.
+ */
+
+G_BEGIN_DECLS
+
+/*
+ * Type declaration.
+ */
+#define CC_TYPE_BACKGROUND_STORE (cc_background_store_get_type ())
+G_DECLARE_FINAL_TYPE (CcBackgroundStore, cc_background_store, CC, BACKGROUND_STORE, GObject)
+
+/*
+ * Method definitions.
+ */
+CcBackgroundStore *cc_backgroud_store_new (void);
+
+G_END_DECLS
+
+#endif /* __CC_BACKGROUND_STORE_H__ */
diff --git a/panels/background/data/background.css b/panels/background/data/background.css
new file mode 100644
index 000000000..c2874a6bd
--- /dev/null
+++ b/panels/background/data/background.css
@@ -0,0 +1,7 @@
+.background-gallery {
+ background: #fff;
+}
+
+.black-border {
+ border: 1px solid black;
+}
diff --git a/panels/background/meson.build b/panels/background/meson.build
index bb34b69fb..69dad5bd3 100644
--- a/panels/background/meson.build
+++ b/panels/background/meson.build
@@ -74,6 +74,8 @@ sources = common_sources + files(
'bg-pictures-source.c',
'bg-source.c',
'bg-wallpapers-source.c',
+ 'cc-background-grid-item.c',
+ 'cc-background-store.c',
'cc-background-chooser-dialog.c',
'cc-background-grilo-miner.c',
'cc-background-item.c',