aboutsummaryrefslogtreecommitdiff
path: root/src/clock-live.c
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2013-10-24 16:47:08 -0500
committerCharles Kerr <charles.kerr@canonical.com>2013-10-24 16:47:08 -0500
commit24ae79c9809c7283d73639127e2370acc414d525 (patch)
treee10414afdb60f4b3ed162a2a49d787252f8b1e4b /src/clock-live.c
parent1e0cfb884a92540d8fbcac662c75633ff6eb1e2a (diff)
parent9e2f24172c1fa388e2be2938998b20f5bf3a8241 (diff)
downloadayatana-indicator-datetime-24ae79c9809c7283d73639127e2370acc414d525.tar.gz
ayatana-indicator-datetime-24ae79c9809c7283d73639127e2370acc414d525.tar.bz2
ayatana-indicator-datetime-24ae79c9809c7283d73639127e2370acc414d525.zip
sync with trunk
Diffstat (limited to 'src/clock-live.c')
-rw-r--r--src/clock-live.c94
1 files changed, 43 insertions, 51 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);
}