aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/service.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/service.c b/src/service.c
index 6601914..12857bb 100644
--- a/src/service.c
+++ b/src/service.c
@@ -95,6 +95,9 @@ struct _IndicatorDatetimeServicePrivate
IndicatorDatetimeTimezone * tz_geoclue;
IndicatorDatetimePlanner * planner;
+ /* cached GTimeZone for use by indicator_datetime_service_get_localtime() */
+ GTimeZone * internal_timezone;
+
guint own_id;
guint actions_export_id;
GDBusConnection * conn;
@@ -377,6 +380,23 @@ start_header_timer (IndicatorDatetimeService * self)
g_date_time_unref (now);
}
+static void
+update_internal_timezone (IndicatorDatetimeService * self)
+{
+ priv_t * p = self->priv;
+ const char * id;
+
+ /* find the id from tz_file or tz_geoclue if possible; NULL otherwise */
+ id = NULL;
+ if (!id && p->tz_file)
+ id = indicator_datetime_timezone_get_timezone (p->tz_file);
+ if (!id && p->tz_geoclue)
+ id = indicator_datetime_timezone_get_timezone (p->tz_geoclue);
+
+ g_clear_pointer (&p->internal_timezone, g_time_zone_unref);
+ p->internal_timezone = g_time_zone_new (id);
+}
+
/**
* General purpose handler for rebuilding sections and restarting their timers
* when time jumps for whatever reason:
@@ -395,6 +415,7 @@ on_local_time_jumped (IndicatorDatetimeService * self)
1. rebuild the necessary states / menuitems when time jumps
2. restart the timers so their new wait interval is correct */
+ update_internal_timezone (self);
on_header_timer (self);
on_timezone_timer (self);
}
@@ -1798,6 +1819,7 @@ my_dispose (GObject * o)
for (i=0; i<N_PROFILES; ++i)
g_clear_object (&p->menus[i].menu);
+ g_clear_pointer (&p->internal_timezone, g_time_zone_unref);
g_clear_object (&p->calendar_action);
g_clear_object (&p->desktop_header_action);
g_clear_object (&p->phone_header_action);
@@ -1993,9 +2015,14 @@ indicator_datetime_service_new (void)
/* This currently just returns the system time,
As we add test coverage, we'll need this to bypass the system time. */
GDateTime *
-indicator_datetime_service_get_localtime (IndicatorDatetimeService * self G_GNUC_UNUSED)
+indicator_datetime_service_get_localtime (IndicatorDatetimeService * self)
{
- return g_date_time_new_now_local ();
+ priv_t * p = self->priv;
+
+ if (G_UNLIKELY (p->internal_timezone == NULL))
+ update_internal_timezone (self);
+
+ return g_date_time_new_now (p->internal_timezone);
}
void