[gnome-control-center/wip/jsparber/background: 6/15] background: refactor cc-background-store



commit 7ebf74567ac9c77753b8e05c6c7eff1b9606f5ac
Author: Julian Sparber <julian sparber net>
Date:   Mon Jan 15 15:38:43 2018 +0100

    background: refactor cc-background-store
    
    - remove private struct of cc-background-store
    - remove CcBackgroundStore constructor
    - less exposure of the the wallpaper store
        use a wrapper to bind the GListModel to a flowbox
    
    https://bugzilla.gnome.org/show_bug.cgi?id=788515

 panels/background/cc-background-panel.c | 10 ++--
 panels/background/cc-background-store.c | 86 ++++++++++-----------------------
 panels/background/cc-background-store.h | 13 +++--
 3 files changed, 39 insertions(+), 70 deletions(-)
---
diff --git a/panels/background/cc-background-panel.c b/panels/background/cc-background-panel.c
index 400545cf6..ae75411f8 100644
--- a/panels/background/cc-background-panel.c
+++ b/panels/background/cc-background-panel.c
@@ -579,11 +579,11 @@ cc_background_panel_init (CcBackgroundPanel *panel)
   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);
+  cc_background_store_bind_flow_box (panel->store,
+                                     panel,
+                                     WID("background-gallery"),
+                                     create_gallery_item);
+
 
   /* 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 05eb09c27..1d11d89d6 100644
--- a/panels/background/cc-background-store.c
+++ b/panels/background/cc-background-store.c
@@ -27,39 +27,19 @@ struct _CcBackgroundStore
 {
   GObject parent_instance;
 
-  /* Other members, including private data. */
-  //CcBackgroundStorePrivate *priv;
-};
-
-/* Private structure definition. */
-typedef struct _CcBackgroundStorePrivate CcBackgroundStorePrivate;
-
-struct _CcBackgroundStorePrivate
-{
   GListStore *model;
   CcBackgroundXml *xml;
 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (CcBackgroundStore, cc_background_store, G_TYPE_OBJECT)
-
+G_DEFINE_TYPE (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.
-   */
+  CcBackgroundStore *self = CC_BACKGROUND_STORE (gobject);
 
-  /* 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);
-  g_clear_object (&priv->xml);
+  g_clear_object (&self->model);
+  g_clear_object (&self->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
@@ -71,13 +51,6 @@ cc_background_store_dispose (GObject *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);
 }
 
@@ -87,8 +60,7 @@ item_added (CcBackgroundXml    *xml,
             CcBackgroundItem   *item,
             CcBackgroundStore *self)
 {
-  CcBackgroundStorePrivate *priv = cc_background_store_get_instance_private (self);
-  g_list_store_append (priv->model, item);
+  g_list_store_append (self->model, item);
 }
 
 static void
@@ -99,49 +71,43 @@ list_load_cb (GObject *source_object,
   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;
 }
 
 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());
-  priv->xml = cc_background_xml_new ();
+  self->model = g_list_store_new (cc_background_item_get_type());
+  self->xml = cc_background_xml_new ();
+
+  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 (self->xml, NULL, list_load_cb, self);
 }
 
-GListStore *
-cc_background_store_get_liststore (CcBackgroundStore *self) {
-  CcBackgroundStorePrivate *priv = cc_background_store_get_instance_private (self);
-  return priv->model;
+void 
+cc_background_store_bind_flow_box (CcBackgroundStore *self,
+                                   gpointer panel,
+                                   GtkWidget *widget,
+                                   GtkFlowBoxCreateWidgetFunc create_widget_fun) {
+  gtk_flow_box_bind_model (GTK_FLOW_BOX (widget),
+                           G_LIST_MODEL(self->model),
+                           create_widget_fun,
+                           panel,
+                           NULL);
 }
 
+
 CcBackgroundStore *
 cc_background_store_new ()
 {
diff --git a/panels/background/cc-background-store.h b/panels/background/cc-background-store.h
index faec58006..d3264074a 100644
--- a/panels/background/cc-background-store.h
+++ b/panels/background/cc-background-store.h
@@ -22,6 +22,7 @@
 #define __CC_BACKGROUND_STORE_H__
 
 #include <glib-object.h>
+#include <gtk/gtk.h>
 /*
  * Potentially, include other headers on which this header depends.
  */
@@ -35,11 +36,13 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (CcBackgroundStore, cc_background_store, CC, BACKGROUND_STORE, GObject)
 
 /*
- * Method definitions.
- */
-CcBackgroundStore *cc_background_store_new (void);
-GListStore *cc_background_store_get_liststore (CcBackgroundStore *);
-
+* Method definitions.
+*/
+CcBackgroundStore       *cc_background_store_new           (void);
+void                    cc_background_store_bind_flow_box  (CcBackgroundStore           *self,
+                                                            gpointer                     panel,
+                                                            GtkWidget                   *widget,
+                                                            GtkFlowBoxCreateWidgetFunc   create_widget_fun);
 G_END_DECLS
 
 #endif /* __CC_BACKGROUND_STORE_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]