diff options
-rw-r--r-- | src/clock-live.c | 94 | ||||
-rw-r--r-- | src/clock.c | 2 | ||||
-rw-r--r-- | src/service.c | 2 |
3 files changed, 45 insertions, 53 deletions
diff --git a/src/clock-live.c b/src/clock-live.c index e5a7ba1..f2859e6 100644 --- a/src/clock-live.c +++ b/src/clock-live.c @@ -33,9 +33,8 @@ struct _IndicatorDatetimeClockLivePriv { GSettings * settings; - IndicatorDatetimeTimezone * tz_file; - IndicatorDatetimeTimezone * tz_geoclue; - gchar ** timezones; + GSList * timezones; /* IndicatorDatetimeTimezone */ + gchar ** timezones_strv; GTimeZone * localtime_zone; }; @@ -64,7 +63,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)); @@ -73,44 +74,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; } @@ -136,38 +129,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 ** @@ -176,10 +168,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 * @@ -228,7 +220,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); } diff --git a/src/clock.c b/src/clock.c index 314dddf..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 fedc809..6fb2ded 100644 --- a/src/service.c +++ b/src/service.c @@ -2315,7 +2315,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", |