datetime: Use GnomeWallClock instead of periodic timeout

We don't actually use the ::clock property string here - this
is just making it so we don't need to wake up once a second.

https://bugzilla.gnome.org/show_bug.cgi?id=658011
This commit is contained in:
Colin Walters 2011-09-01 16:34:52 -04:00 committed by Javier Jardón
parent 8b96ec6d50
commit f708c36fc3
2 changed files with 20 additions and 32 deletions

View file

@ -77,6 +77,7 @@ POLKIT_REQUIRED_VERSION=0.97
GSD_REQUIRED_VERSION=2.91.94 GSD_REQUIRED_VERSION=2.91.94
NETWORK_MANAGER_REQUIRED_VERSION=0.8.992 NETWORK_MANAGER_REQUIRED_VERSION=0.8.992
LIBNOTIFY_REQUIRED_VERSION=0.7.3 LIBNOTIFY_REQUIRED_VERSION=0.7.3
GNOME_DESKTOP_REQUIRED_VERSION=3.1.91
COMMON_MODULES="gtk+-3.0 >= $GTK_REQUIRED_VERSION COMMON_MODULES="gtk+-3.0 >= $GTK_REQUIRED_VERSION
glib-2.0 >= $GLIB_REQUIRED_VERSION glib-2.0 >= $GLIB_REQUIRED_VERSION
@ -93,6 +94,7 @@ PKG_CHECK_MODULES(SHELL, $COMMON_MODULES libgnome-menu-3.0 gio-unix-2.0)
PKG_CHECK_MODULES(BACKGROUND_PANEL, $COMMON_MODULES libxml-2.0 gnome-desktop-3.0 PKG_CHECK_MODULES(BACKGROUND_PANEL, $COMMON_MODULES libxml-2.0 gnome-desktop-3.0
gdk-pixbuf-2.0 >= $GDKPIXBUF_REQUIRED_VERSION) gdk-pixbuf-2.0 >= $GDKPIXBUF_REQUIRED_VERSION)
PKG_CHECK_MODULES(DATETIME_PANEL, $COMMON_MODULES dbus-glib-1 PKG_CHECK_MODULES(DATETIME_PANEL, $COMMON_MODULES dbus-glib-1
gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION
polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION
gdk-pixbuf-2.0 >= $GDKPIXBUF_REQUIRED_VERSION) gdk-pixbuf-2.0 >= $GDKPIXBUF_REQUIRED_VERSION)
PKG_CHECK_MODULES(DISPLAY_PANEL, $COMMON_MODULES dbus-glib-1 gnome-desktop-3.0 >= 3.1.0) PKG_CHECK_MODULES(DISPLAY_PANEL, $COMMON_MODULES dbus-glib-1 gnome-desktop-3.0 >= 3.1.0)

View file

@ -26,11 +26,14 @@
#include "cc-timezone-map.h" #include "cc-timezone-map.h"
#include "dtm.h" #include "dtm.h"
#include "date-endian.h" #include "date-endian.h"
#define GNOME_DESKTOP_USE_UNSTABLE_API
#include <gdesktop-enums.h> #include <gdesktop-enums.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <libintl.h> #include <libintl.h>
#include <libgnome-desktop/gnome-wall-clock.h>
#include <polkit/polkit.h> #include <polkit/polkit.h>
/* FIXME: This should be "Etc/GMT" instead */ /* FIXME: This should be "Etc/GMT" instead */
@ -77,7 +80,7 @@ struct _CcDateTimePanelPrivate
GSettings *settings; GSettings *settings;
GDesktopClockFormat clock_format; GDesktopClockFormat clock_format;
guint update_id; GnomeWallClock *clock_tracker;
DateTimeMechanism *dtm; DateTimeMechanism *dtm;
GCancellable *cancellable; GCancellable *cancellable;
@ -86,7 +89,6 @@ struct _CcDateTimePanelPrivate
}; };
static void update_time (CcDateTimePanel *self); static void update_time (CcDateTimePanel *self);
static void queue_clock_update (CcDateTimePanel *self);
static void static void
cc_date_time_panel_get_property (GObject *object, cc_date_time_panel_get_property (GObject *object,
@ -119,10 +121,10 @@ cc_date_time_panel_dispose (GObject *object)
{ {
CcDateTimePanelPrivate *priv = CC_DATE_TIME_PANEL (object)->priv; CcDateTimePanelPrivate *priv = CC_DATE_TIME_PANEL (object)->priv;
if (priv->update_id != 0) if (priv->clock_tracker != NULL)
{ {
g_source_remove (priv->update_id); g_object_unref (priv->clock_tracker);
priv->update_id = 0; priv->clock_tracker = NULL;
} }
if (priv->builder) if (priv->builder)
@ -753,6 +755,14 @@ month_year_changed (GtkWidget *widget,
change_date (panel); change_date (panel);
} }
static void
on_clock_changed (GnomeWallClock *clock,
GParamSpec *pspec,
CcDateTimePanel *panel)
{
update_time (panel);
}
static void static void
change_time (GtkButton *button, change_time (GtkButton *button,
CcDateTimePanel *panel) CcDateTimePanel *panel)
@ -803,31 +813,6 @@ change_ntp (GObject *gobject,
queue_set_ntp (self); queue_set_ntp (self);
} }
static gboolean
update_time_timer (CcDateTimePanel *self)
{
g_date_time_unref (self->priv->date);
self->priv->date = g_date_time_new_now_local ();
update_time (self);
queue_clock_update (self);
return FALSE;
}
static void
queue_clock_update (CcDateTimePanel *self)
{
int timeouttime;
struct timeval tv;
gettimeofday (&tv, NULL);
timeouttime = (G_USEC_PER_SEC - tv.tv_usec) / 1000 + 1;
/* timeout of one minute if we don't care about the seconds */
timeouttime += 1000 * (59 - tv.tv_sec % 60);
self->priv->update_id = g_timeout_add (timeouttime, (GSourceFunc)update_time_timer, self);
}
static void static void
on_permission_changed (GPermission *permission, on_permission_changed (GPermission *permission,
GParamSpec *pspec, GParamSpec *pspec,
@ -998,6 +983,9 @@ cc_date_time_panel_init (CcDateTimePanel *self)
/* setup the time itself */ /* setup the time itself */
priv->clock_tracker = g_object_new (GNOME_TYPE_WALL_CLOCK, NULL);
g_signal_connect (priv->clock_tracker, "notify::clock", G_CALLBACK (on_clock_changed), self);
priv->settings = g_settings_new (CLOCK_SCHEMA); priv->settings = g_settings_new (CLOCK_SCHEMA);
clock_settings_changed_cb (priv->settings, CLOCK_FORMAT_KEY, self); clock_settings_changed_cb (priv->settings, CLOCK_FORMAT_KEY, self);
g_signal_connect (priv->settings, "changed::" CLOCK_FORMAT_KEY, g_signal_connect (priv->settings, "changed::" CLOCK_FORMAT_KEY,
@ -1035,8 +1023,6 @@ cc_date_time_panel_init (CcDateTimePanel *self)
get_timezone_cb, get_timezone_cb,
self); self);
queue_clock_update (self);
/* add the lock button */ /* add the lock button */
priv->permission = polkit_permission_new_sync ("org.gnome.settingsdaemon.datetimemechanism.configure", NULL, NULL, NULL); priv->permission = polkit_permission_new_sync ("org.gnome.settingsdaemon.datetimemechanism.configure", NULL, NULL, NULL);
if (priv->permission == NULL) if (priv->permission == NULL)