From 4586df056f8a637c9a33d1d6a70ca0480b2c9e0c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 1 Mar 2012 21:01:49 -0600 Subject: tweak: use g_clear_object() in dispose() --- src/indicator-datetime.c | 52 +++++++++++++----------------------------------- 1 file changed, 14 insertions(+), 38 deletions(-) (limited to 'src/indicator-datetime.c') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index c847d47..08d7383 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -405,10 +405,7 @@ service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); - if (priv->service_proxy_cancel != NULL) { - g_object_unref(priv->service_proxy_cancel); - priv->service_proxy_cancel = NULL; - } + g_clear_object (&priv->service_proxy_cancel); if (error != NULL) { g_warning("Could not grab DBus proxy for %s: %s", SERVICE_NAME, error->message); @@ -429,46 +426,25 @@ static void indicator_datetime_dispose (GObject *object) { IndicatorDatetime * self = INDICATOR_DATETIME(object); + IndicatorDatetimePrivate * priv = self->priv; - if (self->priv->label != NULL) { - g_object_unref(self->priv->label); - self->priv->label = NULL; - } - - if (self->priv->timer != 0) { - g_source_remove(self->priv->timer); - self->priv->timer = 0; - } - - if (self->priv->idle_measure != 0) { - g_source_remove(self->priv->idle_measure); - self->priv->idle_measure = 0; - } - - if (self->priv->menu != NULL) { - g_object_unref(G_OBJECT(self->priv->menu)); - self->priv->menu = NULL; - } - - if (self->priv->sm != NULL) { - g_object_unref(G_OBJECT(self->priv->sm)); - self->priv->sm = NULL; + if (priv->timer != 0) { + g_source_remove(priv->timer); + priv->timer = 0; } - if (self->priv->settings != NULL) { - g_object_unref(G_OBJECT(self->priv->settings)); - self->priv->settings = NULL; + if (priv->idle_measure != 0) { + g_source_remove(priv->idle_measure); + priv->idle_measure = 0; } - if (self->priv->service_proxy != NULL) { - g_object_unref(self->priv->service_proxy); - self->priv->service_proxy = NULL; - } + g_clear_object (&priv->label); + g_clear_object (&priv->menu); + g_clear_object (&priv->sm); + g_clear_object (&priv->settings); + g_clear_object (&priv->service_proxy); + g_clear_object (&priv->indicator_right_group); - if (self->priv->indicator_right_group != NULL) { - g_object_unref(G_OBJECT(self->priv->indicator_right_group)); - self->priv->indicator_right_group = NULL; - } G_OBJECT_CLASS (indicator_datetime_parent_class)->dispose (object); return; -- cgit v1.2.3 From 8be0daf8d37a2c53df8f097c389e35c7d4c5ea6b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 1 Mar 2012 21:02:57 -0600 Subject: in dispose(), add g_clear_object() for priv.ido_calendar and priv.service_proxy_cancel --- src/indicator-datetime.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/indicator-datetime.c') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 08d7383..91a029c 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -444,7 +444,8 @@ indicator_datetime_dispose (GObject *object) g_clear_object (&priv->settings); g_clear_object (&priv->service_proxy); g_clear_object (&priv->indicator_right_group); - + g_clear_object (&priv->ido_calendar); + g_clear_object (&priv->service_proxy_cancel); G_OBJECT_CLASS (indicator_datetime_parent_class)->dispose (object); return; -- cgit v1.2.3 From 562575c97ba29a47cd64c85c20725267b79d593b Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Wed, 7 Mar 2012 15:49:58 -0500 Subject: Establish read-only bindings to GSettings from the indicator The bindings to GSettings are established in the GTypeInstance _init function of the indicator. During this time, the property notify queue is frozen. After the construction completes, the queue thaws and the rush of property change notifications causes GSettings writes to occur. We can fix this by switching to using readonly bindings. --- src/indicator-datetime.c | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) (limited to 'src/indicator-datetime.c') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 91a029c..77fdb40 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -162,7 +162,6 @@ static GtkLabel * get_label (IndicatorObject * io); static GtkMenu * get_menu (IndicatorObject * io); static const gchar * get_accessible_desc (IndicatorObject * io); static const gchar * get_name_hint (IndicatorObject * io); -static GVariant * bind_enum_set (const GValue * value, const GVariantType * type, gpointer user_data); static gboolean bind_enum_get (GValue * value, GVariant * variant, gpointer user_data); static gchar * generate_format_string_now (IndicatorDatetime * self); static void update_label (IndicatorDatetime * io, GDateTime ** datetime); @@ -321,45 +320,44 @@ indicator_datetime_init (IndicatorDatetime *self) SETTINGS_SHOW_CLOCK_S, self, PROP_SHOW_CLOCK_S, - G_SETTINGS_BIND_DEFAULT); + G_SETTINGS_BIND_GET); g_settings_bind_with_mapping(self->priv->settings, SETTINGS_TIME_FORMAT_S, self, PROP_TIME_FORMAT_S, - G_SETTINGS_BIND_DEFAULT, + G_SETTINGS_BIND_GET, bind_enum_get, - bind_enum_set, - NULL, NULL); /* Userdata and destroy func */ + NULL, NULL, NULL); /* set mapping, userdata and destroy func */ g_settings_bind(self->priv->settings, SETTINGS_SHOW_SECONDS_S, self, PROP_SHOW_SECONDS_S, - G_SETTINGS_BIND_DEFAULT); + G_SETTINGS_BIND_GET); g_settings_bind(self->priv->settings, SETTINGS_SHOW_DAY_S, self, PROP_SHOW_DAY_S, - G_SETTINGS_BIND_DEFAULT); + G_SETTINGS_BIND_GET); g_settings_bind(self->priv->settings, SETTINGS_SHOW_DATE_S, self, PROP_SHOW_DATE_S, - G_SETTINGS_BIND_DEFAULT); + G_SETTINGS_BIND_GET); g_settings_bind(self->priv->settings, SETTINGS_CUSTOM_TIME_FORMAT_S, self, PROP_CUSTOM_TIME_FORMAT_S, - G_SETTINGS_BIND_DEFAULT); + G_SETTINGS_BIND_GET); g_settings_bind(self->priv->settings, SETTINGS_SHOW_WEEK_NUMBERS_S, self, PROP_SHOW_WEEK_NUMBERS_S, - G_SETTINGS_BIND_DEFAULT); + G_SETTINGS_BIND_GET); g_settings_bind(self->priv->settings, SETTINGS_SHOW_CALENDAR_S, self, PROP_SHOW_CALENDAR_S, - G_SETTINGS_BIND_DEFAULT); + G_SETTINGS_BIND_GET); } else { g_warning("Unable to get settings for '" SETTINGS_INTERFACE "'"); } @@ -470,24 +468,6 @@ indicator_datetime_finalize (GObject *object) return; } -/* Turns the int value into a string GVariant */ -static GVariant * -bind_enum_set (const GValue * value, const GVariantType * type, gpointer user_data) -{ - switch (g_value_get_int(value)) { - case SETTINGS_TIME_LOCALE: - return g_variant_new_string("locale-default"); - case SETTINGS_TIME_12_HOUR: - return g_variant_new_string("12-hour"); - case SETTINGS_TIME_24_HOUR: - return g_variant_new_string("24-hour"); - case SETTINGS_TIME_CUSTOM: - return g_variant_new_string("custom"); - default: - return NULL; - } -} - /* Turns a string GVariant into an int value */ static gboolean bind_enum_get (GValue * value, GVariant * variant, gpointer user_data) -- cgit v1.2.3