[gnome-control-center/wip/jsparber/background: 6/45] background: clean up and fix build warnings



commit bbc3ad0e74c1d1a15da6a5149d84a8aeb68f0dd1
Author: Julian Sparber <julian sparber net>
Date:   Sun Nov 5 17:50:48 2017 +0100

    background: clean up and fix build warnings
    
    https://bugzilla.gnome.org/show_bug.cgi?id=788515

 panels/background/bg-source.c                    |   12 +-
 panels/background/bg-wallpapers-source.c         |    4 +-
 panels/background/bg-wallpapers-source.h         |    2 +-
 panels/background/cc-background-chooser-dialog.c |    2 +-
 panels/background/cc-background-grid-item.c      |    8 +-
 panels/background/cc-background-grid-item.h      |    8 +-
 panels/background/cc-background-panel.c          |  154 +++++++---------------
 panels/background/cc-background-store.c          |   57 ++++++++-
 panels/background/cc-background-store.h          |    3 +-
 9 files changed, 123 insertions(+), 127 deletions(-)
---
diff --git a/panels/background/bg-source.c b/panels/background/bg-source.c
index 7d08dbd..f1fac84 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;
 
 
-  //scale_factor = gtk_widget_get_scale_factor (priv->window);
-  scale_factor = 1;
+  scale_factor = gtk_widget_get_scale_factor (priv->window);
+
   if (scale_factor > 1)
     {
       priv->thumbnail_height *= scale_factor;
@@ -144,7 +144,7 @@ bg_source_class_init (BgSourceClass *klass)
   pspec = g_param_spec_object ("window",
                                "Window",
                                "Toplevel window used to view the source",
-                               GTK_TYPE_WINDOW,
+                               GTK_TYPE_WIDGET,
                                G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
   g_object_class_install_property (object_class, PROP_WINDOW, pspec);
 }
@@ -176,8 +176,6 @@ 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 f5b7da1..546405d 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));
@@ -169,7 +169,7 @@ bg_wallpapers_source_class_init (BgWallpapersSourceClass *klass)
 }
 
 BgWallpapersSource *
-bg_wallpapers_source_new (GtkWindow *window)
+bg_wallpapers_source_new (GtkWidget *window)
 {
   return g_object_new (BG_TYPE_WALLPAPERS_SOURCE, "window", window, NULL);
 }
diff --git a/panels/background/bg-wallpapers-source.h b/panels/background/bg-wallpapers-source.h
index 7292669..3d0d2e0 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 *);
+BgWallpapersSource *bg_wallpapers_source_new (GtkWidget *);
 
 G_END_DECLS
 
diff --git a/panels/background/cc-background-chooser-dialog.c 
b/panels/background/cc-background-chooser-dialog.c
index 47329ca..b766b6e 100644
--- a/panels/background/cc-background-chooser-dialog.c
+++ b/panels/background/cc-background-chooser-dialog.c
@@ -458,7 +458,7 @@ cc_background_chooser_dialog_init (CcBackgroundChooserDialog *chooser)
   g_autofree gchar *pictures_dir_uri = NULL;
   GtkTargetList *target_list;
 
-  chooser->wallpapers_source = bg_wallpapers_source_new (GTK_WINDOW (chooser));
+  chooser->wallpapers_source = bg_wallpapers_source_new (GTK_WIDGET (chooser));
   chooser->pictures_source = bg_pictures_source_new (GTK_WINDOW (chooser));
   chooser->colors_source = bg_colors_source_new (GTK_WINDOW (chooser));
 
diff --git a/panels/background/cc-background-grid-item.c b/panels/background/cc-background-grid-item.c
index 991267b..c2341cc 100644
--- a/panels/background/cc-background-grid-item.c
+++ b/panels/background/cc-background-grid-item.c
@@ -48,13 +48,15 @@ cc_background_grid_item_new (CcBackgroundItem *item)
                        NULL);
 }
 
-CcBackgroundItem * cc_background_grid_item_get_ref (CcBackgroundGridItem *self)
+CcBackgroundItem * cc_background_grid_item_get_ref (GtkWidget *widget)
 {
+  CcBackgroundGridItem *self = (CcBackgroundGridItem *) widget;
   return self->item;
 }
 void
-cc_background_grid_item_set_ref (CcBackgroundGridItem *self, CcBackgroundItem *item)
+cc_background_grid_item_set_ref (GtkWidget *widget, CcBackgroundItem *item)
 {
+  CcBackgroundGridItem *self = (CcBackgroundGridItem *) widget;
   self->item = item;
 }
 
@@ -119,7 +121,7 @@ static void
 cc_background_grid_item_class_init (CcBackgroundGridItemClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  GtkWidgetClass *widget_class = GTK_WIDGET_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;
diff --git a/panels/background/cc-background-grid-item.h b/panels/background/cc-background-grid-item.h
index 025a56f..2c0a197 100644
--- a/panels/background/cc-background-grid-item.h
+++ b/panels/background/cc-background-grid-item.h
@@ -28,10 +28,10 @@ G_BEGIN_DECLS
 
 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);
+GtkWidget *             cc_background_grid_item_new             (CcBackgroundItem             *);
+void                    cc_background_grid_item_set_ref         (GtkWidget                    *,
+                                                                 CcBackgroundItem             *);
+CcBackgroundItem *      cc_background_grid_item_get_ref         (GtkWidget                    *);
 
 G_END_DECLS
 
diff --git a/panels/background/cc-background-panel.c b/panels/background/cc-background-panel.c
index 54c1170..3ec2239 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;
 
@@ -115,6 +114,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);
 }
@@ -649,6 +650,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)
     {
@@ -680,6 +682,7 @@ set_background (CcBackgroundPanel *panel,
       if (create_save_dir ())
         cc_background_xml_save (panel->current_background, filename);
     }
+
 }
 
 static void
@@ -691,43 +694,12 @@ on_settings_changed (GSettings         *settings,
   update_preview (self, settings, NULL);
 }
 
-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
 on_background_select (GtkFlowBox      *box,
                       GtkFlowBoxChild *child,
                       gpointer         user_data)
 {
-  CcBackgroundGridItem *selected = (CcBackgroundGridItem *) child;
+  GtkWidget *selected = GTK_WIDGET (child);
   CcBackgroundPanel *panel = user_data;
   CcBackgroundItem *item;
   item = cc_background_grid_item_get_ref (selected);
@@ -735,63 +707,15 @@ on_background_select (GtkFlowBox      *box,
   set_background (panel, panel->settings, item);
 }
 
-gboolean
-do_foreach_background_item (GtkTreeModel *model,
-                            GtkTreePath *path,
-                            GtkTreeIter *iter,
-                            gpointer data)
-{
-  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_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)
 {
-  GdkAppLaunchContext *context;
+  GAppLaunchContext *context;
   GDesktopAppInfo *appInfo;
   GError **error = NULL;
 
-  context = gdk_display_get_app_launch_context (gdk_display_get_default ());
+  context = G_APP_LAUNCH_CONTEXT (gdk_display_get_app_launch_context (gdk_display_get_default ()));
   appInfo = g_desktop_app_info_new("org.gnome.Photos.desktop");
 
   g_object_unref (context);
@@ -800,7 +724,7 @@ on_open_gnome_photos (GtkWidget *widget,
     g_debug ("Gnome Photos is not installed.");
   }
   else {
-    g_app_info_launch (appInfo, NULL, context, error);
+    g_app_info_launch (G_APP_INFO (appInfo), NULL, context, error);
     g_prefix_error (error,
                     ("Problem opening Gnome Photos: "));
 
@@ -869,26 +793,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;
-  GtkTreeIter iter;
-  GtkTreePath  *path;
-  GValue *value = NULL;
+  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;
 
-  scale_factor = gtk_widget_get_scale_factor (panel);
+  scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (panel));
 
-  panel->wallpapers_source = bg_wallpapers_source_new (GTK_WINDOW (NULL));
-  model = bg_source_get_liststore (BG_SOURCE (panel->wallpapers_source));
+  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);
 
-  gtk_tree_model_foreach (model, do_foreach_background_item, panel);
+  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);
 
-  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);
+  return flow;
 }
 
 static void
@@ -898,9 +833,11 @@ cc_background_panel_init (CcBackgroundPanel *panel)
   g_autoptr(GError) err = NULL;
   GtkCssProvider *provider;
   GtkStyleProvider *provider;
-  GtkStyleContext *context;
   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 ());
 
@@ -926,12 +863,11 @@ cc_background_panel_init (CcBackgroundPanel *panel)
 
   /* add style */
   widget = WID ("background-preview-top");
-  provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
+  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 (provider),
                                              GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
   g_object_unref (provider);
 
@@ -943,7 +879,6 @@ cc_background_panel_init (CcBackgroundPanel *panel)
 
   panel->thumb_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
 
-
   /* add button handler */
   widget = WID ("open-gnome-photos");
   g_signal_connect (G_OBJECT (widget), "clicked",
@@ -963,12 +898,17 @@ cc_background_panel_init (CcBackgroundPanel *panel)
   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);
 
+  /* 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]