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.
This commit is contained in:
+13
-14
@@ -43,7 +43,6 @@ struct _GcalApplication
|
|||||||
|
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
|
|
||||||
GSettings *settings;
|
|
||||||
GcalManager *manager;
|
GcalManager *manager;
|
||||||
|
|
||||||
GtkCssProvider *provider;
|
GtkCssProvider *provider;
|
||||||
@@ -168,7 +167,6 @@ gcal_application_finalize (GObject *object)
|
|||||||
|
|
||||||
g_clear_object (&(self->provider));
|
g_clear_object (&(self->provider));
|
||||||
g_clear_object (&self->colors_provider);
|
g_clear_object (&self->colors_provider);
|
||||||
g_clear_object (&self->settings);
|
|
||||||
|
|
||||||
g_clear_object (&self->manager);
|
g_clear_object (&self->manager);
|
||||||
g_clear_object (&self->search_provider);
|
g_clear_object (&self->search_provider);
|
||||||
@@ -182,10 +180,12 @@ static void
|
|||||||
gcal_application_activate (GApplication *application)
|
gcal_application_activate (GApplication *application)
|
||||||
{
|
{
|
||||||
GcalApplication *self;
|
GcalApplication *self;
|
||||||
|
GSettings *settings;
|
||||||
|
|
||||||
GCAL_ENTRY;
|
GCAL_ENTRY;
|
||||||
|
|
||||||
self = GCAL_APPLICATION (application);
|
self = GCAL_APPLICATION (application);
|
||||||
|
settings = gcal_manager_get_settings (self->manager);
|
||||||
|
|
||||||
if (!self->provider)
|
if (!self->provider)
|
||||||
{
|
{
|
||||||
@@ -216,12 +216,12 @@ gcal_application_activate (GApplication *application)
|
|||||||
}
|
}
|
||||||
|
|
||||||
self->window = gcal_window_new_with_view_and_date (GCAL_APPLICATION (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);
|
self->initial_date);
|
||||||
|
|
||||||
g_signal_connect (self->window, "destroy", G_CALLBACK (gtk_widget_destroyed), &(self->window));
|
g_signal_connect (self->window, "destroy", G_CALLBACK (gtk_widget_destroyed), &(self->window));
|
||||||
|
|
||||||
g_settings_bind (self->settings,
|
g_settings_bind (settings,
|
||||||
"active-view",
|
"active-view",
|
||||||
self->window,
|
self->window,
|
||||||
"active-view",
|
"active-view",
|
||||||
@@ -398,10 +398,9 @@ gcal_application_init (GcalApplication *self)
|
|||||||
{
|
{
|
||||||
g_application_add_main_option_entries (G_APPLICATION (self), gcal_application_goptions);
|
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->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-added", G_CALLBACK (process_sources), self);
|
||||||
g_signal_connect_swapped (self->manager, "source-changed", 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);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gcal_application_get_manager:
|
||||||
|
* @self: a #GcalApplication
|
||||||
|
*
|
||||||
|
* Retrieves the #GcalManager of the application.
|
||||||
|
*
|
||||||
|
* Returns: (transfer none): a #GcalManager
|
||||||
|
*/
|
||||||
GcalManager*
|
GcalManager*
|
||||||
gcal_application_get_manager (GcalApplication *self)
|
gcal_application_get_manager (GcalApplication *self)
|
||||||
{
|
{
|
||||||
@@ -521,14 +528,6 @@ gcal_application_get_manager (GcalApplication *self)
|
|||||||
return self->manager;
|
return self->manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
GSettings*
|
|
||||||
gcal_application_get_settings (GcalApplication *self)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (GCAL_IS_APPLICATION (self), NULL);
|
|
||||||
|
|
||||||
return self->settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
gcal_application_set_uuid (GcalApplication *self,
|
gcal_application_set_uuid (GcalApplication *self,
|
||||||
const gchar *app_uuid)
|
const gchar *app_uuid)
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ GcalApplication* gcal_application_new (void);
|
|||||||
|
|
||||||
GcalManager* gcal_application_get_manager (GcalApplication *self);
|
GcalManager* gcal_application_get_manager (GcalApplication *self);
|
||||||
|
|
||||||
GSettings* gcal_application_get_settings (GcalApplication *self);
|
|
||||||
|
|
||||||
void gcal_application_set_uuid (GcalApplication *self,
|
void gcal_application_set_uuid (GcalApplication *self,
|
||||||
const gchar *app_uuid);
|
const gchar *app_uuid);
|
||||||
|
|
||||||
|
|||||||
+22
-13
@@ -954,11 +954,6 @@ gcal_manager_set_property (GObject *object,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_SETTINGS:
|
|
||||||
if (g_set_object (&self->settings, g_value_get_object (value)))
|
|
||||||
g_object_notify (object, "settings");
|
|
||||||
return;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||||
}
|
}
|
||||||
@@ -1051,7 +1046,7 @@ gcal_manager_class_init (GcalManagerClass *klass)
|
|||||||
"Application settings",
|
"Application settings",
|
||||||
"The settings of the application passed down from GcalApplication",
|
"The settings of the application passed down from GcalApplication",
|
||||||
G_TYPE_SETTINGS,
|
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);
|
g_object_class_install_properties (object_class, NUM_PROPS, properties);
|
||||||
|
|
||||||
@@ -1103,23 +1098,37 @@ static void
|
|||||||
gcal_manager_init (GcalManager *self)
|
gcal_manager_init (GcalManager *self)
|
||||||
{
|
{
|
||||||
self->clock = gcal_clock_new ();
|
self->clock = gcal_clock_new ();
|
||||||
|
self->settings = g_settings_new ("org.gnome.calendar");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Public API */
|
/* Public API */
|
||||||
/**
|
/**
|
||||||
* gcal_manager_new_with_settings:
|
* gcal_manager_new:
|
||||||
* @settings: a #GSettings
|
|
||||||
*
|
*
|
||||||
* Creates a new #GcalManager with @settings.
|
* Creates a new #GcalManager.
|
||||||
*
|
*
|
||||||
* Returns: (transfer full): a newly created #GcalManager
|
* Returns: (transfer full): a newly created #GcalManager
|
||||||
*/
|
*/
|
||||||
GcalManager*
|
GcalManager*
|
||||||
gcal_manager_new_with_settings (GSettings *settings)
|
gcal_manager_new (void)
|
||||||
{
|
{
|
||||||
return g_object_new (GCAL_TYPE_MANAGER,
|
return g_object_new (GCAL_TYPE_MANAGER, NULL);
|
||||||
"settings", settings,
|
}
|
||||||
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)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (GCAL_IS_MANAGER (self), NULL);
|
||||||
|
|
||||||
|
return self->settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+3
-1
@@ -33,7 +33,9 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
G_DECLARE_FINAL_TYPE (GcalManager, gcal_manager, GCAL, MANAGER, GObject)
|
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,
|
ESource* gcal_manager_get_source (GcalManager *self,
|
||||||
const gchar *uid);
|
const gchar *uid);
|
||||||
|
|||||||
+2
-8
@@ -522,7 +522,6 @@ calendar_listbox_sort_func (GtkListBoxRow *row1,
|
|||||||
static void
|
static void
|
||||||
load_geometry (GcalWindow *window)
|
load_geometry (GcalWindow *window)
|
||||||
{
|
{
|
||||||
GcalApplication *app;
|
|
||||||
GSettings *settings;
|
GSettings *settings;
|
||||||
GVariant *variant;
|
GVariant *variant;
|
||||||
gboolean maximized;
|
gboolean maximized;
|
||||||
@@ -532,8 +531,7 @@ load_geometry (GcalWindow *window)
|
|||||||
|
|
||||||
GCAL_ENTRY;
|
GCAL_ENTRY;
|
||||||
|
|
||||||
app = GCAL_APPLICATION (gtk_window_get_application (GTK_WINDOW (window)));
|
settings = gcal_manager_get_settings (window->manager);
|
||||||
settings = gcal_application_get_settings (app);
|
|
||||||
|
|
||||||
/* load window settings: size */
|
/* load window settings: size */
|
||||||
variant = g_settings_get_value (settings,
|
variant = g_settings_get_value (settings,
|
||||||
@@ -576,7 +574,6 @@ save_geometry (gpointer user_data)
|
|||||||
GtkWindow *self;
|
GtkWindow *self;
|
||||||
GdkWindow *win;
|
GdkWindow *win;
|
||||||
GdkWindowState state;
|
GdkWindowState state;
|
||||||
GcalApplication *app;
|
|
||||||
GSettings *settings;
|
GSettings *settings;
|
||||||
gboolean maximized;
|
gboolean maximized;
|
||||||
GVariant *variant;
|
GVariant *variant;
|
||||||
@@ -589,10 +586,7 @@ save_geometry (gpointer user_data)
|
|||||||
window = GCAL_WINDOW (self);
|
window = GCAL_WINDOW (self);
|
||||||
win = gtk_widget_get_window (GTK_WIDGET (self));
|
win = gtk_widget_get_window (GTK_WIDGET (self));
|
||||||
state = gdk_window_get_state (win);
|
state = gdk_window_get_state (win);
|
||||||
|
settings = gcal_manager_get_settings (window->manager);
|
||||||
|
|
||||||
app = GCAL_APPLICATION (gtk_window_get_application (self));
|
|
||||||
settings = gcal_application_get_settings (app);
|
|
||||||
|
|
||||||
/* save window's state */
|
/* save window's state */
|
||||||
maximized = state & GDK_WINDOW_STATE_MAXIMIZED;
|
maximized = state & GDK_WINDOW_STATE_MAXIMIZED;
|
||||||
|
|||||||
@@ -23,13 +23,11 @@
|
|||||||
/*********************************************************************************************************************/
|
/*********************************************************************************************************************/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
manager_new_with_settings (void)
|
manager_new (void)
|
||||||
{
|
{
|
||||||
g_autoptr (GcalManager) manager;
|
g_autoptr (GcalManager) manager;
|
||||||
g_autoptr (GSettings) settings;
|
|
||||||
|
|
||||||
settings = g_settings_new ("org.gnome.calendar");
|
manager = gcal_manager_new ();
|
||||||
manager = gcal_manager_new_with_settings (settings);
|
|
||||||
|
|
||||||
g_assert_nonnull (manager);
|
g_assert_nonnull (manager);
|
||||||
}
|
}
|
||||||
@@ -42,7 +40,7 @@ main (gint argc,
|
|||||||
{
|
{
|
||||||
g_test_init (&argc, &argv, NULL);
|
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 ();
|
return g_test_run ();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user