[gnome-calendar] window: Rework property initialization
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] window: Rework property initialization
- Date: Sat, 27 Jan 2018 23:48:31 +0000 (UTC)
commit 5a651b01f8fdd46ad9002763fced8e923261cab4
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sat Jan 27 21:46:15 2018 -0200
window: Rework property initialization
There is a clear chain of properties that must be respected
in order to make Calendar initialize properly:
1. GcalManager, since it provider access to the settings
2. The initial date
3. GcalWeatherService, that depends on settings and the initial date
src/gcal-application.c | 76 ++++++++++++++++++++++++++++++++++++++++++++------
src/gcal-window.c | 64 +++++++++++++++++++++++++++++-------------
2 files changed, 112 insertions(+), 28 deletions(-)
---
diff --git a/src/gcal-application.c b/src/gcal-application.c
index 4c8edbd2..772864a2 100644
--- a/src/gcal-application.c
+++ b/src/gcal-application.c
@@ -114,6 +114,16 @@ static const GActionEntry gcal_app_entries[] = {
{ "quit", gcal_application_quit },
};
+enum
+{
+ PROP_0,
+ PROP_MANAGER,
+ PROP_WEATHER_SERVICE,
+ N_PROPS
+};
+
+static GParamSpec* properties[N_PROPS] = { NULL, };
+
static void
process_sources (GcalApplication *self)
{
@@ -207,6 +217,33 @@ gcal_application_finalize (GObject *object)
GCAL_EXIT;
}
+static void
+gcal_application_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GcalApplication *self = GCAL_APPLICATION (object);
+
+ switch (property_id)
+ {
+ case PROP_MANAGER:
+ g_value_set_object (value, self->manager);
+ break;
+
+ case PROP_WEATHER_SERVICE:
+ g_value_set_object (value, self->weather_service);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+/*
+ * GApplication overrides
+ */
+
static void
gcal_application_activate (GApplication *application)
{
@@ -230,13 +267,22 @@ gcal_application_activate (GApplication *application)
{
if (!self->initial_date)
{
+ icaltimezone *tz;
+
+ tz = gcal_manager_get_system_timezone (self->manager);
+
self->initial_date = g_new0 (icaltimetype, 1);
- *(self->initial_date) = icaltime_current_time_with_zone (gcal_manager_get_system_timezone
(self->manager));
- *(self->initial_date) = icaltime_set_timezone (self->initial_date,
- gcal_manager_get_system_timezone (self->manager));
+ *self->initial_date = icaltime_current_time_with_zone (tz);
+ *self->initial_date = icaltime_set_timezone (self->initial_date, tz);
}
- self->window = gcal_window_new_with_date (GCAL_APPLICATION (application), self->initial_date);
+ self->window = g_object_new (GCAL_TYPE_WINDOW,
+ "application", self,
+ "manager", self->manager,
+ "active-date", self->initial_date,
+ "weather-service", self->weather_service,
+ NULL);
+
g_signal_connect (self->window, "destroy", G_CALLBACK (gtk_widget_destroyed), &self->window);
gtk_widget_show (self->window);
}
@@ -251,7 +297,7 @@ gcal_application_activate (GApplication *application)
if (self->uuid != NULL)
{
gcal_window_open_event_by_uuid (GCAL_WINDOW (self->window), self->uuid);
- g_clear_pointer (&(self->uuid), g_free);
+ g_clear_pointer (&self->uuid, g_free);
}
GCAL_EXIT;
@@ -370,9 +416,9 @@ gcal_application_dbus_register (GApplication *application,
}
static void
-gcal_application_dbus_unregister (GApplication *application,
+gcal_application_dbus_unregister (GApplication *application,
GDBusConnection *connection,
- const gchar *object_path)
+ const gchar *object_path)
{
GcalApplication *self;
g_autofree gchar *search_provider_path = NULL;
@@ -393,15 +439,29 @@ gcal_application_class_init (GcalApplicationClass *klass)
object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gcal_application_finalize;
+ object_class->get_property = gcal_application_get_property;
application_class = G_APPLICATION_CLASS (klass);
application_class->activate = gcal_application_activate;
application_class->startup = gcal_application_startup;
application_class->command_line = gcal_application_command_line;
application_class->handle_local_options = gcal_application_handle_local_options;
-
application_class->dbus_register = gcal_application_dbus_register;
application_class->dbus_unregister = gcal_application_dbus_unregister;
+
+ properties[PROP_MANAGER] = g_param_spec_object ("manager",
+ "The manager object",
+ "The manager object",
+ GCAL_TYPE_MANAGER,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+ properties[PROP_WEATHER_SERVICE] = g_param_spec_object ("weather-service",
+ "The weather service object",
+ "The weather service object",
+ GCAL_TYPE_WEATHER_SERVICE,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
diff --git a/src/gcal-window.c b/src/gcal-window.c
index f1efd5db..8b6e2ebf 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -1223,6 +1223,11 @@ schedule_open_edit_dialog_by_uuid (OpenEditDialogData *edit_dialog_data)
return G_SOURCE_CONTINUE;
}
+
+/*
+ * GObject overrides
+ */
+
static void
gcal_window_finalize (GObject *object)
{
@@ -1261,6 +1266,23 @@ gcal_window_finalize (GObject *object)
GCAL_EXIT;
}
+static void
+gcal_window_constructed (GObject *object)
+{
+ GcalWindow *self;
+
+ GCAL_ENTRY;
+
+ self = GCAL_WINDOW (object);
+
+ G_OBJECT_CLASS (gcal_window_parent_class)->constructed (object);
+
+ /* Load saved geometry *after* the construct-time properties are set */
+ load_geometry (self);
+
+ GCAL_EXIT;
+}
+
static void
gcal_window_set_property (GObject *object,
guint property_id,
@@ -1319,6 +1341,11 @@ gcal_window_set_property (GObject *object,
}
break;
+ case PROP_WEATHER_SERVICE:
+ if (g_set_object (&self->weather_service, g_value_get_object (value)))
+ g_object_notify_by_pspec (object, properties[PROP_WEATHER_SERVICE]);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -1361,6 +1388,11 @@ gcal_window_get_property (GObject *object,
}
}
+
+/*
+ * GtkWidget overrides
+ */
+
static gboolean
gcal_window_configure_event (GtkWidget *widget,
GdkEventConfigure *event)
@@ -1397,6 +1429,7 @@ gcal_window_class_init (GcalWindowClass *klass)
object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gcal_window_finalize;
+ object_class->constructed = gcal_window_constructed;
object_class->set_property = gcal_window_set_property;
object_class->get_property = gcal_window_get_property;
@@ -1421,7 +1454,7 @@ gcal_window_class_init (GcalWindowClass *klass)
"The manager object",
"The manager object",
GCAL_TYPE_MANAGER,
- G_PARAM_CONSTRUCT | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
properties[PROP_NEW_EVENT_MODE] = g_param_spec_boolean ("new-event-mode",
"New Event mode",
@@ -1433,7 +1466,7 @@ gcal_window_class_init (GcalWindowClass *klass)
"The weather service object",
"The weather service object",
GCAL_TYPE_WEATHER_SERVICE,
- G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, properties);
@@ -1572,10 +1605,10 @@ gcal_window_init (GcalWindow *self)
g_object_bind_property (self, "manager", self->month_view, "manager", G_BINDING_DEFAULT);
g_object_bind_property (self, "manager", self->year_view, "manager", G_BINDING_DEFAULT);
g_object_bind_property (self, "manager", self->quick_add_popover, "manager", G_BINDING_DEFAULT);
- g_object_bind_property (self, "weather-service", self->weather_settings, "weather-service",
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
- g_object_bind_property (self, "weather-service", self->month_view, "weather-service", G_BINDING_DEFAULT |
G_BINDING_SYNC_CREATE);
- g_object_bind_property (self, "weather-service", self->week_view, "weather-service", G_BINDING_DEFAULT |
G_BINDING_SYNC_CREATE);
- g_object_bind_property (self, "weather-service", self->year_view, "weather-service", G_BINDING_DEFAULT |
G_BINDING_SYNC_CREATE);
+ g_object_bind_property (self, "weather-service", self->weather_settings, "weather-service",
G_BINDING_DEFAULT);
+ g_object_bind_property (self, "weather-service", self->month_view, "weather-service", G_BINDING_DEFAULT);
+ g_object_bind_property (self, "weather-service", self->week_view, "weather-service", G_BINDING_DEFAULT);
+ g_object_bind_property (self, "weather-service", self->year_view, "weather-service", G_BINDING_DEFAULT);
/* setup accels */
gcal_window_add_accelerator (app, "win.change-view(-1)", "<Ctrl>Page_Down");
@@ -1599,20 +1632,11 @@ GtkWidget*
gcal_window_new_with_date (GcalApplication *app,
icaltimetype *date)
{
- GcalManager *manager;
- GcalWindow *win;
-
- manager = gcal_application_get_manager (GCAL_APPLICATION (app));
- win = g_object_new (GCAL_TYPE_WINDOW,
- "application", GTK_APPLICATION (app),
- "manager", manager,
- "active-date", date,
- NULL);
-
- /* loading size */
- load_geometry (win);
-
- return GTK_WIDGET (win);
+ return g_object_new (GCAL_TYPE_WINDOW,
+ "application", GTK_APPLICATION (app),
+ "manager", gcal_application_get_manager (GCAL_APPLICATION (app)),
+ "active-date", date,
+ NULL);
}
/* new-event interaction: first variant */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]