aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier Jardón <javier.jardon@codethink.co.uk>2011-09-05 12:34:31 +0100
committerJavier Jardón <javier.jardon@codethink.co.uk>2011-09-05 12:34:31 +0100
commite4fed0186ac63ebf14a5d35b6f1aacfc306ad1ef (patch)
tree70d6da2f6988a7af0bcefb1aecfa3bebb2bfc00d
parent1ab5a36d28ea2d3bac39534de9c18a95bfcb0670 (diff)
downloadayatana-indicator-datetime-e4fed0186ac63ebf14a5d35b6f1aacfc306ad1ef.tar.gz
ayatana-indicator-datetime-e4fed0186ac63ebf14a5d35b6f1aacfc306ad1ef.tar.bz2
ayatana-indicator-datetime-e4fed0186ac63ebf14a5d35b6f1aacfc306ad1ef.zip
Use GnomeWallClock instead of periodic timeout
This class support changes in the timezone and notifications of clock skews when using a recent version of Linux (using timerfds) See https://bugzilla.gnome.org/show_bug.cgi?id=655129 Fixes https://bugs.launchpad.net/indicator-datetime/+bug/837440
-rw-r--r--configure.ac2
-rw-r--r--src/datetime-service.c77
2 files changed, 14 insertions, 65 deletions
diff --git a/configure.ac b/configure.ac
index 71fd0e9..7c7317f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -64,6 +64,7 @@ GEOCLUE_REQUIRED_VERSION=0.12.0
ECAL_REQUIRED_VERSION=2.30
EDS_REQUIRED_VERSION=2.30
ICAL_REQUIRED_VERSION=0.44
+GNOME_DESKTOP_REQUIRED_VERSION=3.1.90
CAIRO_REQUIRED_VERSION=1.10
GDK_REQUIRED_VERSION=2.22
GLIB_REQUIRED_VERSION=2.26
@@ -100,6 +101,7 @@ PKG_CHECK_MODULES(SERVICE, indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION
libedataserverui-3.0 >= EDS_REQUIRED_VERSION
cairo >= CAIRO_REQUIRED_VERSION
gdk-3.0 >= GDK_REQUIRED_VERSION
+ gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION
gconf-2.0 >= GCONF_REQUIRED_VERSION)
PKG_CHECK_MODULES(PREF, gio-2.0 >= $GIO_REQUIRED_VERSION
diff --git a/src/datetime-service.c b/src/datetime-service.c
index 80c0b57..8026398 100644
--- a/src/datetime-service.c
+++ b/src/datetime-service.c
@@ -38,6 +38,10 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <geoclue/geoclue-master.h>
#include <geoclue/geoclue-master-client.h>
+#define GNOME_DESKTOP_USE_UNSTABLE_API
+#include <gdesktop-enums.h>
+#include <libgnome-desktop/gnome-wall-clock.h>
+
#include <time.h>
#include <libecal/e-cal.h>
#include <libical/ical.h>
@@ -57,7 +61,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
static void geo_create_client (GeoclueMaster * master, GeoclueMasterClient * client, gchar * path, GError * error, gpointer user_data);
static gboolean update_appointment_menu_items (gpointer user_data);
static gboolean update_timezone_menu_items(gpointer user_data);
-static void setup_timer (void);
static void geo_client_invalid (GeoclueMasterClient * client, gpointer user_data);
static void geo_address_change (GeoclueMasterClient * client, gchar * a, gchar * b, gchar * c, gchar * d, gpointer user_data);
static gboolean get_greeter_mode (void);
@@ -1139,67 +1142,12 @@ build_menus (DbusmenuMenuitem * root)
return;
}
-/* Run when the timezone file changes */
static void
-timezone_changed (GFileMonitor * monitor, GFile * file, GFile * otherfile, GFileMonitorEvent event, gpointer user_data)
+on_clock_changed (GnomeWallClock *clock,
+ GParamSpec *pspec,
+ gpointer user_data)
{
- update_current_timezone();
- datetime_interface_update(DATETIME_INTERFACE(user_data));
- update_datetime(NULL);
- setup_timer();
- return;
-}
-
-/* Set up monitoring the timezone file */
-static void
-build_timezone (DatetimeInterface * dbus)
-{
- GFile * timezonefile = g_file_new_for_path(TIMEZONE_FILE);
- GFileMonitor * monitor = g_file_monitor_file(timezonefile, G_FILE_MONITOR_NONE, NULL, NULL);
- if (monitor != NULL) {
- g_signal_connect(G_OBJECT(monitor), "changed", G_CALLBACK(timezone_changed), dbus);
- g_debug("Monitoring timezone file: '" TIMEZONE_FILE "'");
- } else {
- g_warning("Unable to monitor timezone file: '" TIMEZONE_FILE "'");
- }
- return;
-}
-
-/* Source ID for the timer */
-static guint timer = 0;
-
-/* Execute at a given time, update and setup a new
- timer to go again. */
-static gboolean
-timer_func (gpointer user_data)
-{
- timer = 0;
- /* Reset up each time to reduce error */
- setup_timer();
- update_datetime(NULL);
- return FALSE;
-}
-
-/* Sets up the time to launch the timer to update the
- date in the datetime entry */
-static void
-setup_timer (void)
-{
- if (timer != 0) {
- g_source_remove(timer);
- timer = 0;
- }
-
- time_t t;
- t = time(NULL);
- struct tm * ltime = localtime(&t);
-
- timer = g_timeout_add_seconds(((23 - ltime->tm_hour) * 60 * 60) +
- ((59 - ltime->tm_min) * 60) +
- ((60 - ltime->tm_sec)) + 60 /* one minute past */,
- timer_func, NULL);
-
- return;
+ update_datetime (NULL);
}
static void
@@ -1213,7 +1161,6 @@ session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signa
if (!idle) {
datetime_interface_update(DATETIME_INTERFACE(user_data));
update_datetime(NULL);
- setup_timer();
}
}
return;
@@ -1437,6 +1384,8 @@ service_shutdown (IndicatorService * service, gpointer user_data)
int
main (int argc, char ** argv)
{
+ GnomeWallClock *clock;
+
g_type_init();
/* Acknowledging the service init and setting up the interface */
@@ -1472,11 +1421,9 @@ main (int argc, char ** argv)
/* Setup dbus interface */
dbus = g_object_new(DATETIME_INTERFACE_TYPE, NULL);
- /* Setup timezone watch */
- build_timezone(dbus);
-
/* Setup the timer */
- setup_timer();
+ clock = g_object_new (GNOME_TYPE_WALL_CLOCK, NULL);
+ g_signal_connect (priv->clock_tracker, "notify::clock", G_CALLBACK (on_clock_changed), NULL);
/* And watch for system resumes */
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,