[gnome-calendar] application: move GSettings object to GcalManager



commit a0b6bdb04a813577b5dea5bf15e584f236d52064
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Sep 7 12:52:49 2017 -0300

    application: move GSettings object to GcalManager
    
    The first outcome of the test suite. This separation does
    not make much sense now, and GcalManager is basically a
    holder for all data types.
    
    This commit moves the GSettings to the GcalManager instance
    of the application. Of course, in the future, the plan is to
    split GcalManager nicely.

 src/gcal-application.c |   27 +++++++++++++--------------
 src/gcal-application.h |    2 --
 src/gcal-manager.c     |   35 ++++++++++++++++++++++-------------
 src/gcal-manager.h     |    4 +++-
 src/gcal-window.c      |   10 ++--------
 tests/test-manager.c   |    8 +++-----
 6 files changed, 43 insertions(+), 43 deletions(-)
---
diff --git a/src/gcal-application.c b/src/gcal-application.c
index 571a9e4..bc31aba 100644
--- a/src/gcal-application.c
+++ b/src/gcal-application.c
@@ -43,7 +43,6 @@ struct _GcalApplication
 
   GtkWidget          *window;
 
-  GSettings          *settings;
   GcalManager        *manager;
 
   GtkCssProvider     *provider;
@@ -168,7 +167,6 @@ gcal_application_finalize (GObject *object)
 
   g_clear_object (&(self->provider));
   g_clear_object (&self->colors_provider);
-  g_clear_object (&self->settings);
 
   g_clear_object (&self->manager);
   g_clear_object (&self->search_provider);
@@ -182,10 +180,12 @@ static void
 gcal_application_activate (GApplication *application)
 {
   GcalApplication *self;
+  GSettings *settings;
 
   GCAL_ENTRY;
 
   self = GCAL_APPLICATION (application);
+  settings = gcal_manager_get_settings (self->manager);
 
   if (!self->provider)
     {
@@ -216,12 +216,12 @@ gcal_application_activate (GApplication *application)
         }
 
       self->window = gcal_window_new_with_view_and_date (GCAL_APPLICATION (application),
-                                                         g_settings_get_enum (self->settings, "active-view"),
+                                                         g_settings_get_enum (settings, "active-view"),
                                                          self->initial_date);
 
       g_signal_connect (self->window, "destroy", G_CALLBACK (gtk_widget_destroyed), &(self->window));
 
-      g_settings_bind (self->settings,
+      g_settings_bind (settings,
                        "active-view",
                        self->window,
                        "active-view",
@@ -398,10 +398,9 @@ gcal_application_init (GcalApplication *self)
 {
   g_application_add_main_option_entries (G_APPLICATION (self), gcal_application_goptions);
 
-  self->settings = g_settings_new ("org.gnome.calendar");
   self->colors_provider = gtk_css_provider_new ();
 
-  self->manager = gcal_manager_new_with_settings (self->settings);
+  self->manager = gcal_manager_new ();
   g_signal_connect_swapped (self->manager, "source-added", G_CALLBACK (process_sources), self);
   g_signal_connect_swapped (self->manager, "source-changed", G_CALLBACK (process_sources), self);
 
@@ -513,6 +512,14 @@ gcal_application_new (void)
                        NULL);
 }
 
+/**
+ * gcal_application_get_manager:
+ * @self: a #GcalApplication
+ *
+ * Retrieves the #GcalManager of the application.
+ *
+ * Returns: (transfer none): a #GcalManager
+ */
 GcalManager*
 gcal_application_get_manager (GcalApplication *self)
 {
@@ -521,14 +528,6 @@ gcal_application_get_manager (GcalApplication *self)
   return self->manager;
 }
 
-GSettings*
-gcal_application_get_settings (GcalApplication *self)
-{
-  g_return_val_if_fail (GCAL_IS_APPLICATION (self), NULL);
-
-  return self->settings;
-}
-
 void
 gcal_application_set_uuid (GcalApplication *self,
                            const gchar     *app_uuid)
diff --git a/src/gcal-application.h b/src/gcal-application.h
index 30e1262..9dc369d 100644
--- a/src/gcal-application.h
+++ b/src/gcal-application.h
@@ -34,8 +34,6 @@ GcalApplication*     gcal_application_new                        (void);
 
 GcalManager*         gcal_application_get_manager                (GcalApplication    *self);
 
-GSettings*           gcal_application_get_settings               (GcalApplication    *self);
-
 void                 gcal_application_set_uuid                   (GcalApplication    *self,
                                                                   const gchar        *app_uuid);
 
diff --git a/src/gcal-manager.c b/src/gcal-manager.c
index 3cbb13e..77b9367 100644
--- a/src/gcal-manager.c
+++ b/src/gcal-manager.c
@@ -954,11 +954,6 @@ gcal_manager_set_property (GObject      *object,
         }
       break;
 
-    case PROP_SETTINGS:
-      if (g_set_object (&self->settings, g_value_get_object (value)))
-        g_object_notify (object, "settings");
-      return;
-
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -1051,7 +1046,7 @@ gcal_manager_class_init (GcalManagerClass *klass)
                                                    "Application settings",
                                                    "The settings of the application passed down from 
GcalApplication",
                                                    G_TYPE_SETTINGS,
-                                                   G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
+                                                   G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
 
   g_object_class_install_properties (object_class, NUM_PROPS, properties);
 
@@ -1103,23 +1098,37 @@ static void
 gcal_manager_init (GcalManager *self)
 {
   self->clock = gcal_clock_new ();
+  self->settings = g_settings_new ("org.gnome.calendar");
 }
 
 /* Public API */
 /**
- * gcal_manager_new_with_settings:
- * @settings: a #GSettings
+ * gcal_manager_new:
  *
- * Creates a new #GcalManager with @settings.
+ * Creates a new #GcalManager.
  *
  * Returns: (transfer full): a newly created #GcalManager
  */
 GcalManager*
-gcal_manager_new_with_settings (GSettings *settings)
+gcal_manager_new (void)
+{
+  return g_object_new (GCAL_TYPE_MANAGER, NULL);
+}
+
+/**
+ * gcal_manager_get_settings:
+ * @self:  a #GcalManager
+ *
+ * Retrieves the #GSetting of @self.
+ *
+ * Returns: (transfer none): a #GSettings
+ */
+GSettings*
+gcal_manager_get_settings (GcalManager *self)
 {
-  return g_object_new (GCAL_TYPE_MANAGER,
-                       "settings", settings,
-                       NULL);
+  g_return_val_if_fail (GCAL_IS_MANAGER (self), NULL);
+
+  return self->settings;
 }
 
 /**
diff --git a/src/gcal-manager.h b/src/gcal-manager.h
index facecad..fb04732 100644
--- a/src/gcal-manager.h
+++ b/src/gcal-manager.h
@@ -33,7 +33,9 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GcalManager, gcal_manager, GCAL, MANAGER, GObject)
 
-GcalManager*         gcal_manager_new_with_settings              (GSettings          *settings);
+GcalManager*         gcal_manager_new                            (void);
+
+GSettings*           gcal_manager_get_settings                   (GcalManager        *self);
 
 ESource*             gcal_manager_get_source                     (GcalManager        *self,
                                                                   const gchar        *uid);
diff --git a/src/gcal-window.c b/src/gcal-window.c
index fea1adc..e505ea8 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -522,7 +522,6 @@ calendar_listbox_sort_func (GtkListBoxRow *row1,
 static void
 load_geometry (GcalWindow *window)
 {
-  GcalApplication *app;
   GSettings *settings;
   GVariant *variant;
   gboolean maximized;
@@ -532,8 +531,7 @@ load_geometry (GcalWindow *window)
 
   GCAL_ENTRY;
 
-  app = GCAL_APPLICATION (gtk_window_get_application (GTK_WINDOW (window)));
-  settings = gcal_application_get_settings (app);
+  settings = gcal_manager_get_settings (window->manager);
 
   /* load window settings: size */
   variant = g_settings_get_value (settings,
@@ -576,7 +574,6 @@ save_geometry (gpointer user_data)
   GtkWindow *self;
   GdkWindow *win;
   GdkWindowState state;
-  GcalApplication *app;
   GSettings *settings;
   gboolean maximized;
   GVariant *variant;
@@ -589,10 +586,7 @@ save_geometry (gpointer user_data)
   window = GCAL_WINDOW (self);
   win = gtk_widget_get_window (GTK_WIDGET (self));
   state = gdk_window_get_state (win);
-
-
-  app = GCAL_APPLICATION (gtk_window_get_application (self));
-  settings = gcal_application_get_settings (app);
+  settings = gcal_manager_get_settings (window->manager);
 
   /* save window's state */
   maximized = state & GDK_WINDOW_STATE_MAXIMIZED;
diff --git a/tests/test-manager.c b/tests/test-manager.c
index 5aa9d11..d97a16a 100644
--- a/tests/test-manager.c
+++ b/tests/test-manager.c
@@ -23,13 +23,11 @@
 
/*********************************************************************************************************************/
 
 static void
-manager_new_with_settings (void)
+manager_new (void)
 {
   g_autoptr (GcalManager) manager;
-  g_autoptr (GSettings) settings;
 
-  settings = g_settings_new ("org.gnome.calendar");
-  manager = gcal_manager_new_with_settings (settings);
+  manager = gcal_manager_new ();
 
   g_assert_nonnull (manager);
 }
@@ -42,7 +40,7 @@ main (gint   argc,
 {
   g_test_init (&argc, &argv, NULL);
 
-  g_test_add_func ("/manager/new_with_settings", manager_new_with_settings);
+  g_test_add_func ("/manager/new", manager_new);
 
   return g_test_run ();
 }


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