From a2f21a1da1b1f467751020b56b04808f5dd00695 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 23 Oct 2013 09:42:49 -0500 Subject: make GObject a prerequisite of the IndicatorDatetimeClock interface. --- src/clock.c | 2 +- src/service.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/clock.c b/src/clock.c index adfb0eb..2c2fec2 100644 --- a/src/clock.c +++ b/src/clock.c @@ -29,7 +29,7 @@ static guint signals[SIGNAL_LAST] = { 0 }; G_DEFINE_INTERFACE (IndicatorDatetimeClock, indicator_datetime_clock, - 0); + G_TYPE_OBJECT); static void indicator_datetime_clock_default_init (IndicatorDatetimeClockInterface * klass) diff --git a/src/service.c b/src/service.c index cb2ab4f..5fffc11 100644 --- a/src/service.c +++ b/src/service.c @@ -2317,7 +2317,7 @@ indicator_datetime_service_class_init (IndicatorDatetimeServiceClass * klass) properties[PROP_CLOCK] = g_param_spec_object ("clock", "Clock", "The clock", - G_TYPE_OBJECT, + INDICATOR_TYPE_DATETIME_CLOCK, flags); properties[PROP_PLANNER] = g_param_spec_object ("planner", -- cgit v1.2.3 From 6da162acd4a293a1cfe1933c54f6b06935deebbf Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 23 Oct 2013 13:14:25 -0500 Subject: instead of keeping IndicatorDatetimeTimezone objects in separate fields, keep them in a list so they can be handled in a loop. --- src/clock-live.c | 94 ++++++++++++++++++++++++++------------------------------ 1 file changed, 43 insertions(+), 51 deletions(-) (limited to 'src') diff --git a/src/clock-live.c b/src/clock-live.c index de5ce19..4153747 100644 --- a/src/clock-live.c +++ b/src/clock-live.c @@ -35,9 +35,8 @@ struct _IndicatorDatetimeClockLivePriv { GSettings * settings; - IndicatorDatetimeTimezone * tz_file; - IndicatorDatetimeTimezone * tz_geoclue; - gchar ** timezones; + GSList * timezones; /* IndicatorDatetimeTimezone */ + gchar ** timezones_strv; GTimeZone * localtime_zone; }; @@ -66,7 +65,9 @@ on_current_timezone_changed (IndicatorDatetimeClockLive * self) { priv_t * p = self->priv; - g_clear_pointer (&p->timezones, g_strfreev); + /* Invalidate the timezone information. + These fields will be lazily regenerated by rebuild_timezones() */ + g_clear_pointer (&p->timezones_strv, g_strfreev); g_clear_pointer (&p->localtime_zone, g_time_zone_unref); indicator_datetime_clock_emit_changed (INDICATOR_DATETIME_CLOCK (self)); @@ -75,44 +76,36 @@ on_current_timezone_changed (IndicatorDatetimeClockLive * self) static void set_detect_location_enabled (IndicatorDatetimeClockLive * self, gboolean enabled) { + GSList * l; priv_t * p = self->priv; gboolean changed = FALSE; - /* geoclue */ - - if (!p->tz_geoclue && enabled) + /* clear out the old timezone objects */ + if (p->timezones != NULL) { - p->tz_geoclue = indicator_datetime_timezone_geoclue_new (); - g_signal_connect_swapped (p->tz_geoclue, "notify::timezone", - G_CALLBACK(on_current_timezone_changed), - self); + for (l=p->timezones; l!=NULL; l=l->next) + { + g_signal_handlers_disconnect_by_func (l->data, on_current_timezone_changed, self); + g_object_unref (l->data); + } + + g_slist_free (p->timezones); + p->timezones = NULL; changed = TRUE; } - else if (p->tz_geoclue && !enabled) + + /* maybe add new timezone objects */ + if (enabled) { - g_signal_handlers_disconnect_by_func (p->tz_geoclue, - on_current_timezone_changed, - self); - g_clear_object (&p->tz_geoclue); - changed = TRUE; - } + p->timezones = g_slist_append (p->timezones, indicator_datetime_timezone_geoclue_new ()); + p->timezones = g_slist_append (p->timezones, indicator_datetime_timezone_file_new (TIMEZONE_FILE)); - /* timezone file */ + for (l=p->timezones; l!=NULL; l=l->next) + { + g_signal_connect_swapped (l->data, "notify::timezone", + G_CALLBACK(on_current_timezone_changed), self); + } - if (!p->tz_file && enabled) - { - p->tz_file = indicator_datetime_timezone_file_new (TIMEZONE_FILE); - g_signal_connect_swapped (p->tz_file, "notify::timezone", - G_CALLBACK(on_current_timezone_changed), - self); - changed = TRUE; - } - else if (p->tz_file && !enabled) - { - g_signal_handlers_disconnect_by_func (p->tz_file, - on_current_timezone_changed, - self); - g_clear_object (&p->tz_file); changed = TRUE; } @@ -138,38 +131,37 @@ rebuild_timezones (IndicatorDatetimeClockLive * self) { priv_t * p; GHashTable * hash; + GSList * l; int i; GHashTableIter iter; gpointer key; p = self->priv; + /* Build a hashtable of timezone strings. + This will weed out duplicates. */ hash = g_hash_table_new (g_str_hash, g_str_equal); - - if (p->tz_file != NULL) + for (l=p->timezones; l!=NULL; l=l->next) { - const gchar * tz = indicator_datetime_timezone_get_timezone (p->tz_file); + const gchar * tz = indicator_datetime_timezone_get_timezone (l->data); if (tz && *tz) g_hash_table_add (hash, (gpointer) tz); } - if (p->tz_geoclue != NULL) - { - const gchar * tz = indicator_datetime_timezone_get_timezone (p->tz_geoclue); - if (tz && *tz) - g_hash_table_add (hash, (gpointer) tz); - } - - g_strfreev (p->timezones); - p->timezones = g_new0 (gchar*, g_hash_table_size(hash) + 1); + /* rebuild p->timezone_strv */ + g_strfreev (p->timezones_strv); + p->timezones_strv = g_new0 (gchar*, g_hash_table_size(hash) + 1); i = 0; g_hash_table_iter_init (&iter, hash); while (g_hash_table_iter_next (&iter, &key, NULL)) - p->timezones[i++] = g_strdup (key); - g_hash_table_unref (hash); + p->timezones_strv[i++] = g_strdup (key); + /* rebuild localtime_zone */ g_clear_pointer (&p->localtime_zone, g_time_zone_unref); - p->localtime_zone = g_time_zone_new (p->timezones ? p->timezones[0] : NULL); + p->localtime_zone = g_time_zone_new (p->timezones_strv ? p->timezones_strv[0] : NULL); + + /* cleanup */ + g_hash_table_unref (hash); } static const gchar ** @@ -178,10 +170,10 @@ my_get_timezones (IndicatorDatetimeClock * clock) IndicatorDatetimeClockLive * self = INDICATOR_DATETIME_CLOCK_LIVE (clock); priv_t * p = self->priv; - if (G_UNLIKELY (p->timezones == NULL)) + if (G_UNLIKELY (p->timezones_strv == NULL)) rebuild_timezones (self); - return (const gchar **) p->timezones; + return (const gchar **) p->timezones_strv; } static GDateTime * @@ -230,7 +222,7 @@ my_finalize (GObject * o) p = self->priv; g_clear_pointer (&p->localtime_zone, g_time_zone_unref); - g_strfreev (p->timezones); + g_strfreev (p->timezones_strv); G_OBJECT_CLASS (indicator_datetime_clock_live_parent_class)->dispose (o); } -- cgit v1.2.3