[gnome-panel/wip/applets/clock: 8/15] clock: detect timezone change



commit 07a24e3219e8f46b36d728a4afbd56297008bdae
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Nov 10 00:41:07 2014 +0200

    clock: detect timezone change
    
    Unused at this moment, but will be used to update current location
    when timezone changes.

 applets/clock/Makefile.am                   |   10 ++++++
 applets/clock/clock.c                       |   45 +++++++++++++++++++++++++++
 applets/clock/org.freedesktop.timedate1.xml |   27 ++++++++++++++++
 3 files changed, 82 insertions(+), 0 deletions(-)
---
diff --git a/applets/clock/Makefile.am b/applets/clock/Makefile.am
index 1136ab1..d25fbc7 100644
--- a/applets/clock/Makefile.am
+++ b/applets/clock/Makefile.am
@@ -122,6 +122,8 @@ clock-typebuiltins.h: $(clock_enum_headers)
                $(clock_enum_headers) > $@
 
 BUILT_SOURCES =                                        \
+       timedate1.c \
+       timedate1.h \
        clock-marshallers.c                     \
        clock-marshallers.h                     \
        clock-resources.c                       \
@@ -151,7 +153,15 @@ clock-resources.c: clock.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourc
 clock-resources.h: clock.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) 
--generate-dependencies $(srcdir)/clock.gresource.xml)
        $(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name clock $<
 
+timedate1.c: timedate1.h
+timedate1.h: Makefile.in org.freedesktop.timedate1.xml
+       gdbus-codegen \
+               --interface-prefix org.freedesktop. \
+               --generate-c-code timedate1 \
+               $(srcdir)/org.freedesktop.timedate1.xml
+
 EXTRA_DIST =                                           \
+       org.freedesktop.timedate1.xml \
        org.gnome.panel.ClockApplet.panel-applet.in.in  \
        $(ui_FILES)                                     \
        clock.gresource.xml                             \
diff --git a/applets/clock/clock.c b/applets/clock/clock.c
index 7ec90bd..0014028 100644
--- a/applets/clock/clock.c
+++ b/applets/clock/clock.c
@@ -63,6 +63,7 @@
 #include "clock-location-tile.h"
 #include "clock-map.h"
 #include "clock-utils.h"
+#include "timedate1.h"
 #include "system-timezone.h"
 
 enum {
@@ -140,6 +141,8 @@ struct _ClockData {
         gboolean   custom_format_shown;
 
        gboolean   can_handle_format_12;
+
+        Timedate1 *timedate1;
 };
 
 static void  update_clock (GnomeWallClock *, GParamSpec *, ClockData * cd);
@@ -321,6 +324,8 @@ free_locations (ClockData *cd)
 static void
 destroy_clock (GtkWidget * widget, ClockData *cd)
 {
+        g_clear_object (&cd->timedate1);
+
         g_clear_object (&cd->applet_settings);
         g_clear_object (&cd->clock_settings);
         g_clear_object (&cd->weather_settings);
@@ -1271,12 +1276,37 @@ load_cities (ClockData *cd)
         cd->locations = g_list_reverse (cd->locations);
 }
 
+static void
+timezone_changed (ClockData *cd)
+{
+        const gchar *timezone;
+        GList       *locations;
+        GList       *l;
+
+        timezone = timedate1_get_timezone (cd->timedate1);
+
+        if (timezone == NULL)
+                return;
+
+        locations = cd->locations;
+        for (l = locations; l; l = l->next) {
+                ClockLocation *location = l->data;
+                const gchar   *tzname = clock_location_get_tzname (location);
+
+                if (g_strcmp0 (timezone, tzname) == 0) {
+                        /* FIXME: make this location as current */
+                        break;
+                }
+        }
+}
+
 static gboolean
 fill_clock_applet (PanelApplet *applet)
 {
        ClockData          *cd;
         GSimpleActionGroup *action_group;
         GAction            *action;
+        GError             *error;
 
        panel_applet_set_flags (applet, PANEL_APPLET_EXPAND_MINOR);
 
@@ -1299,6 +1329,21 @@ fill_clock_applet (PanelApplet *applet)
         load_cities (cd);
         locations_changed (NULL, NULL, cd);
 
+        error = NULL;
+        cd->timedate1 = timedate1_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+                                                          G_DBUS_PROXY_FLAGS_NONE,
+                                                          "org.freedesktop.timedate1",
+                                                          "/org/freedesktop/timedate1",
+                                                          NULL,
+                                                          &error);
+        if (error) {
+                g_warning ("%s", error->message);
+                g_error_free (error);
+        } else {
+                g_signal_connect_swapped (cd->timedate1, "notify::timezone",
+                                          G_CALLBACK (timezone_changed), cd);
+        }
+
        cd->builder = gtk_builder_new ();
        gtk_builder_set_translation_domain (cd->builder, GETTEXT_PACKAGE);
        gtk_builder_add_from_resource (cd->builder, CLOCK_RESOURCE_PATH "clock.ui", NULL);
diff --git a/applets/clock/org.freedesktop.timedate1.xml b/applets/clock/org.freedesktop.timedate1.xml
new file mode 100644
index 0000000..b035d10
--- /dev/null
+++ b/applets/clock/org.freedesktop.timedate1.xml
@@ -0,0 +1,27 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd";>
+<node>
+ <interface name="org.freedesktop.timedate1">
+  <property name="Timezone" type="s" access="read"/>
+  <property name="LocalRTC" type="b" access="read"/>
+  <property name="NTP" type="b" access="read"/>
+  <method name="SetTime">
+   <arg name="usec_utc" type="x" direction="in"/>
+   <arg name="relative" type="b" direction="in"/>
+   <arg name="user_interaction" type="b" direction="in"/>
+  </method>
+  <method name="SetTimezone">
+   <arg name="timezone" type="s" direction="in"/>
+   <arg name="user_interaction" type="b" direction="in"/>
+  </method>
+  <method name="SetLocalRTC">
+   <arg name="local_rtc" type="b" direction="in"/>
+   <arg name="fix_system" type="b" direction="in"/>
+   <arg name="user_interaction" type="b" direction="in"/>
+  </method>
+  <method name="SetNTP">
+   <arg name="use_ntp" type="b" direction="in"/>
+   <arg name="user_interaction" type="b" direction="in"/>
+  </method>
+ </interface>
+</node>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]