aboutsummaryrefslogtreecommitdiff
path: root/src/indicator-datetime.c
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2011-09-15 10:43:16 -0500
committerTed Gould <ted@gould.cx>2011-09-15 10:43:16 -0500
commit1e2f73f716198aec43b76570e1926d73ddfeca19 (patch)
tree24f9f38d6af9f43cd24d6cdada4774acd089aa96 /src/indicator-datetime.c
parent59a60d1e418b2ad975a58890e9e925f5a6f6e013 (diff)
parent1272ced6625175ee20f4c6740a414152b09f9769 (diff)
downloadayatana-indicator-datetime-1e2f73f716198aec43b76570e1926d73ddfeca19.tar.gz
ayatana-indicator-datetime-1e2f73f716198aec43b76570e1926d73ddfeca19.tar.bz2
ayatana-indicator-datetime-1e2f73f716198aec43b76570e1926d73ddfeca19.zip
Import upstream version 0.2.95
Diffstat (limited to 'src/indicator-datetime.c')
-rw-r--r--src/indicator-datetime.c101
1 files changed, 66 insertions, 35 deletions
diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c
index 61cfc5f..339ea2f 100644
--- a/src/indicator-datetime.c
+++ b/src/indicator-datetime.c
@@ -45,10 +45,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <libido/libido.h>
#include <libdbusmenu-gtk3/menuitem.h>
-/* For GnomeWallClock */
-#define GNOME_DESKTOP_USE_UNSTABLE_API
-#include <libgnome-desktop/gnome-wall-clock.h>
-
#include "utils.h"
#include "dbus-shared.h"
#include "settings-shared.h"
@@ -76,6 +72,7 @@ struct _IndicatorDatetime {
struct _IndicatorDatetimePrivate {
GtkLabel * label;
+ guint timer;
gchar * time_string;
@@ -104,11 +101,8 @@ struct _IndicatorDatetimePrivate {
GList * timezone_items;
GSettings * settings;
- GSettings * gnome_settings;
GtkSizeGroup * indicator_right_group;
-
- GnomeWallClock *clock;
};
/* Enum for the properties so that they can be quickly
@@ -172,8 +166,8 @@ static gboolean bind_enum_get (GValue * value, GVariant * variant, g
static gchar * generate_format_string_now (IndicatorDatetime * self);
static void update_label (IndicatorDatetime * io, GDateTime ** datetime);
static void guess_label_size (IndicatorDatetime * self);
+static void setup_timer (IndicatorDatetime * self, GDateTime * datetime);
static void update_time (IndicatorDatetime * self);
-static void on_clock_changed (GnomeWallClock *clock, GParamSpec *pspec, gpointer user_data);
static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data);
static void service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data);
static gint generate_strftime_bitmask (const char *time_str);
@@ -299,6 +293,7 @@ indicator_datetime_init (IndicatorDatetime *self)
IndicatorDatetimePrivate);
self->priv->label = NULL;
+ self->priv->timer = 0;
self->priv->idle_measure = 0;
self->priv->max_width = 0;
@@ -367,11 +362,6 @@ indicator_datetime_init (IndicatorDatetime *self)
g_warning("Unable to get settings for '" SETTINGS_INTERFACE "'");
}
- self->priv->gnome_settings = g_settings_new ("org.gnome.desktop.interface");
-
- self->priv->clock = g_object_new (GNOME_TYPE_WALL_CLOCK, NULL);
- g_signal_connect (self->priv->clock, "notify::clock", G_CALLBACK (on_clock_changed), self);
-
self->priv->sm = indicator_service_manager_new_version(SERVICE_NAME, SERVICE_VERSION);
self->priv->indicator_right_group = GTK_SIZE_GROUP(gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL));
@@ -443,9 +433,9 @@ indicator_datetime_dispose (GObject *object)
self->priv->label = NULL;
}
- if (self->priv->clock != NULL) {
- g_object_unref (self->priv->clock);
- self->priv->clock = NULL;
+ if (self->priv->timer != 0) {
+ g_source_remove(self->priv->timer);
+ self->priv->timer = 0;
}
if (self->priv->idle_measure != 0) {
@@ -572,7 +562,7 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec
if (newval != self->priv->time_mode) {
update = TRUE;
self->priv->time_mode = newval;
- update_time (self);
+ setup_timer(self, NULL);
}
break;
}
@@ -581,11 +571,8 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec
self->priv->show_seconds = !self->priv->show_seconds;
if (self->priv->time_mode != SETTINGS_TIME_CUSTOM) {
update = TRUE;
- update_time (self);
+ setup_timer(self, NULL);
}
- g_settings_set_boolean (self->priv->gnome_settings,
- "clock-show-seconds",
- self->priv->show_seconds);
}
break;
}
@@ -619,11 +606,8 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec
self->priv->custom_show_seconds = (time_mask & STRFTIME_MASK_SECONDS);
if (self->priv->time_mode == SETTINGS_TIME_CUSTOM) {
update = TRUE;
- update_time (self);
+ setup_timer(self, NULL);
}
- g_settings_set_boolean (self->priv->gnome_settings,
- "clock-show-seconds",
- self->priv->show_seconds);
}
break;
}
@@ -846,16 +830,11 @@ update_time (IndicatorDatetime * self)
GDateTime * dt = NULL;
update_label(self, &dt);
timezone_update_all_labels(self);
-}
-
-static void
-on_clock_changed (GnomeWallClock *clock,
- GParamSpec *pspec,
- gpointer user_data)
-{
- IndicatorDatetime *self = INDICATOR_DATETIME (user_data);
-
- update_time (self);
+ if (dt != NULL) {
+ setup_timer(self, dt);
+ g_date_time_unref(dt);
+ }
+ return;
}
/* Receives all signals from the service, routed to the appropriate functions */
@@ -872,6 +851,54 @@ receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name,
return;
}
+/* Runs every minute and updates the time */
+gboolean
+timer_func (gpointer user_data)
+{
+ IndicatorDatetime * self = INDICATOR_DATETIME(user_data);
+ self->priv->timer = 0;
+ GDateTime * dt = NULL;
+ update_label(self, &dt);
+ timezone_update_all_labels(self);
+ if (dt != NULL) {
+ setup_timer(self, dt);
+ g_date_time_unref(dt);
+ }
+ return FALSE;
+}
+
+/* Configure the timer to run the next time through */
+static void
+setup_timer (IndicatorDatetime * self, GDateTime * datetime)
+{
+ gboolean unref = FALSE;
+
+ if (self->priv->timer != 0) {
+ g_source_remove(self->priv->timer);
+ self->priv->timer = 0;
+ }
+
+ if (self->priv->show_seconds ||
+ (self->priv->time_mode == SETTINGS_TIME_CUSTOM && self->priv->custom_show_seconds)) {
+ self->priv->timer = g_timeout_add_full(G_PRIORITY_HIGH, 999, timer_func, self, NULL);
+ } else {
+ if (datetime == NULL) {
+ datetime = g_date_time_new_now_local();
+ unref = TRUE;
+ }
+
+ /* Plus 2 so we're just after the minute, don't want to be early. */
+ gint seconds = (gint)g_date_time_get_seconds(datetime);
+ self->priv->timer = g_timeout_add_seconds(60 - seconds + 2, timer_func, self);
+
+ if (unref) {
+ g_date_time_unref(datetime);
+ }
+ }
+
+ return;
+}
+
/* Does a quick meausre of how big the string is in
pixels with a Pango layout */
static gint
@@ -1492,6 +1519,10 @@ get_label (IndicatorObject * io)
gtk_widget_set_visible(GTK_WIDGET (self->priv->label), self->priv->show_clock);
}
+ if (self->priv->timer == 0) {
+ setup_timer(self, NULL);
+ }
+
return self->priv->label;
}