manager: Move GSettings to GcalContext

This commit is contained in:
Georges Basile Stavracas Neto
2019-04-25 16:30:54 -03:00
parent dc9d1d0d9b
commit 802c6948e8
7 changed files with 37 additions and 55 deletions
+29
View File
@@ -28,6 +28,7 @@ struct _GcalContext
GcalClock *clock;
GcalManager *manager;
GSettings *settings;
GcalWeatherService *weather_service;
};
@@ -38,6 +39,7 @@ enum
PROP_0,
PROP_CLOCK,
PROP_MANAGER,
PROP_SETTINGS,
PROP_WEATHER_SERVICE,
N_PROPS
};
@@ -79,6 +81,10 @@ gcal_context_get_property (GObject *object,
g_value_set_object (value, self->manager);
break;
case PROP_SETTINGS:
g_value_set_object (value, self->settings);
break;
case PROP_WEATHER_SERVICE:
g_value_set_object (value, self->weather_service);
break;
@@ -98,6 +104,7 @@ gcal_context_set_property (GObject *object,
{
case PROP_CLOCK:
case PROP_MANAGER:
case PROP_SETTINGS:
case PROP_WEATHER_SERVICE:
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -125,6 +132,12 @@ gcal_context_class_init (GcalContextClass *klass)
GCAL_TYPE_MANAGER,
G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
properties[PROP_SETTINGS] = g_param_spec_object ("settings",
"GNOME Calendar settings",
"GNOME Calendar settings",
G_TYPE_SETTINGS,
G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
properties[PROP_WEATHER_SERVICE] = g_param_spec_object ("weather-service",
"Weather service",
"Weather service",
@@ -139,6 +152,7 @@ gcal_context_init (GcalContext *self)
{
self->clock = gcal_clock_new ();
self->manager = gcal_manager_new ();
self->settings = g_settings_new ("org.gnome.calendar");
self->weather_service = gcal_weather_service_new ();
}
@@ -186,6 +200,21 @@ gcal_context_get_manager (GcalContext *self)
return self->manager;
}
/**
* gcal_context_get_settings:
*
* Retrieves the #GSettings from @self.
*
* Returns: (transfer none): a #GSettings
*/
GSettings*
gcal_context_get_settings (GcalContext *self)
{
g_return_val_if_fail (GCAL_IS_CONTEXT (self), NULL);
return self->settings;
}
/**
* gcal_context_get_weather_service:
*
+2
View File
@@ -37,6 +37,8 @@ GcalClock* gcal_context_get_clock (GcalContext
GcalManager* gcal_context_get_manager (GcalContext *self);
GSettings* gcal_context_get_settings (GcalContext *self);
GcalWeatherService* gcal_context_get_weather_service (GcalContext *self);
G_END_DECLS
-37
View File
@@ -96,9 +96,6 @@ struct _GcalManager
/* timezone */
icaltimezone *system_timezone;
/* property */
GSettings *settings;
};
G_DEFINE_TYPE (GcalManager, gcal_manager, G_TYPE_OBJECT)
@@ -108,7 +105,6 @@ enum
PROP_0,
PROP_DEFAULT_CALENDAR,
PROP_LOADING,
PROP_SETTINGS,
NUM_PROPS
};
@@ -773,7 +769,6 @@ gcal_manager_finalize (GObject *object)
GCAL_ENTRY;
g_clear_object (&self->settings);
g_clear_object (&self->goa_client);
g_clear_object (&self->e_data_model);
g_clear_object (&self->search_data_model);
@@ -845,10 +840,6 @@ gcal_manager_get_property (GObject *object,
g_value_set_boolean (value, gcal_manager_get_loading (self));
break;
case PROP_SETTINGS:
g_value_set_object (value, self->settings);
return;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -889,17 +880,6 @@ gcal_manager_class_init (GcalManagerClass *klass)
TRUE,
G_PARAM_READABLE);
/**
* GcalManager:settings:
*
* The settings.
*/
properties[PROP_SETTINGS] = g_param_spec_object ("settings",
"Application settings",
"The settings of the application passed down from GcalApplication",
G_TYPE_SETTINGS,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, NUM_PROPS, properties);
/* signals */
@@ -949,7 +929,6 @@ gcal_manager_class_init (GcalManagerClass *klass)
static void
gcal_manager_init (GcalManager *self)
{
self->settings = g_settings_new ("org.gnome.calendar");
self->system_timezone = e_cal_util_get_system_timezone ();
}
@@ -967,22 +946,6 @@ 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)
{
g_return_val_if_fail (GCAL_IS_MANAGER (self), NULL);
return self->settings;
}
/**
* gcal_manager_get_source:
* @self: a #GcalManager
-2
View File
@@ -33,8 +33,6 @@ G_DECLARE_FINAL_TYPE (GcalManager, gcal_manager, GCAL, MANAGER, GObject)
GcalManager* gcal_manager_new (void);
GSettings* gcal_manager_get_settings (GcalManager *self);
ESource* gcal_manager_get_source (GcalManager *self,
const gchar *uid);
+1 -3
View File
@@ -52,14 +52,12 @@ on_night_light_proxy_properties_changed_cb (GcalNightLightMonitor *self,
const gchar * const *invalidated,
GDBusProxy *proxy)
{
GcalManager *manager;
GSettings *settings;
g_assert (GCAL_IS_NIGHT_LIGHT_MONITOR (self));
g_assert (G_IS_DBUS_PROXY (proxy));
manager = gcal_context_get_manager (self->context);
settings = gcal_manager_get_settings (manager);
settings = gcal_context_get_settings (self->context);
if (g_settings_get_boolean (settings, "follow-night-light"))
{
+3 -7
View File
@@ -523,13 +523,11 @@ calendar_listbox_sort_func (GtkListBoxRow *row1,
static void
load_geometry (GcalWindow *self)
{
GcalManager *manager;
GSettings *settings;
GCAL_ENTRY;
manager = gcal_context_get_manager (self->context);
settings = gcal_manager_get_settings (manager);
settings = gcal_context_get_settings (self->context);
self->is_maximized = g_settings_get_boolean (settings, "window-maximized");
g_settings_get (settings, "window-size", "(ii)", &self->width, &self->height);
@@ -552,13 +550,11 @@ load_geometry (GcalWindow *self)
static void
save_geometry (GcalWindow *self)
{
GcalManager *manager;
GSettings *settings;
GCAL_ENTRY;
manager = gcal_context_get_manager (self->context);
settings = gcal_manager_get_settings (manager);
settings = gcal_context_get_settings (self->context);
g_settings_set_boolean (settings, "window-maximized", self->is_maximized);
g_settings_set (settings, "window-size", "(ii)", self->width, self->height);
@@ -1310,7 +1306,7 @@ gcal_window_set_property (GObject *object,
{
GcalManager *manager = gcal_context_get_manager (self->context);
g_settings_bind (gcal_manager_get_settings (manager),
g_settings_bind (gcal_context_get_settings (self->context),
"active-view",
self,
"active-view",
+2 -6
View File
@@ -73,7 +73,6 @@ load_weather_settings (GcalWeatherSettings *self)
g_autoptr (GVariant) location = NULL;
g_autoptr (GVariant) value = NULL;
g_autofree gchar *location_name = NULL;
GcalManager *manager;
GSettings *settings;
gboolean show_weather;
gboolean auto_location;
@@ -83,8 +82,7 @@ load_weather_settings (GcalWeatherSettings *self)
if (!self->context)
GCAL_RETURN ();
manager = gcal_context_get_manager (self->context);
settings = gcal_manager_get_settings (manager);
settings = gcal_context_get_settings (self->context);
value = g_settings_get_value (settings, "weather-settings");
g_variant_get (value, "(bbsmv)",
@@ -130,7 +128,6 @@ static void
save_weather_settings (GcalWeatherSettings *self)
{
g_autoptr (GWeatherLocation) location = NULL;
GcalManager *manager;
GSettings *settings;
GVariant *value;
GVariant *vlocation;
@@ -144,8 +141,7 @@ save_weather_settings (GcalWeatherSettings *self)
location = gweather_location_entry_get_location (GWEATHER_LOCATION_ENTRY (self->weather_location_entry));
vlocation = location ? gweather_location_serialize (location) : NULL;
manager = gcal_context_get_manager (self->context);
settings = gcal_manager_get_settings (manager);
settings = gcal_context_get_settings (self->context);
value = g_variant_new ("(bbsmv)",
gtk_switch_get_active (self->show_weather_switch),
gtk_switch_get_active (self->weather_auto_location_switch),