From 4207f22ac83a0c4f06cc2ae588605c2f235449e8 Mon Sep 17 00:00:00 2001 From: Javier Jardón Date: Thu, 25 Aug 2011 15:46:51 +0100 Subject: Update the date when open the indicator-datetime menu Fixes https://bugs.launchpad.net/indicator-datetime/+bug/793450 --- src/indicator-datetime.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/indicator-datetime.c') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index aca1101..59bcaf3 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -274,12 +274,6 @@ menu_visible_notfy_cb(GtkWidget * menu, G_GNUC_UNUSED GParamSpec *pspec, gpointe gint y, m, d; g_debug("notify visible signal received"); - - // we should only react if we're currently visible - gboolean visible; - g_object_get(G_OBJECT(menu), "visible", &visible, NULL); - if (visible) return; - g_debug("notify visible menu hidden, resetting date"); datetime = g_date_time_new_now_local (); g_date_time_get_ymd (datetime, &y, &m, &d); -- cgit v1.2.3 From 0fad515e1b65662306219464f00485817fc75511 Mon Sep 17 00:00:00 2001 From: Javier Jardón Date: Fri, 2 Sep 2011 16:43:16 +0100 Subject: Warning when the user use a date format not supported We are using the g_date_time_format () function and the format strings understood by this function are a subset of the strftime() format language. --- src/indicator-datetime.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/indicator-datetime.c') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 59bcaf3..f773159 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -215,7 +215,7 @@ indicator_datetime_class_init (IndicatorDatetimeClass *klass) PROP_TIME_FORMAT, g_param_spec_int(PROP_TIME_FORMAT_S, "A choice of which format should be used on the panel", - "Chooses between letting the locale choose the time, 12-hour time, 24-time or using the custom string passed to strftime().", + "Chooses between letting the locale choose the time, 12-hour time, 24-time or using the custom string passed to g_date_time_format().", SETTINGS_TIME_LOCALE, /* min */ SETTINGS_TIME_CUSTOM, /* max */ SETTINGS_TIME_LOCALE, /* default */ @@ -245,7 +245,7 @@ indicator_datetime_class_init (IndicatorDatetimeClass *klass) PROP_CUSTOM_TIME_FORMAT, g_param_spec_string(PROP_CUSTOM_TIME_FORMAT_S, "The format that is used to show the time on the panel.", - "A format string in the form used to pass to strftime to make a string for displaying on the panel.", + "A format string in the form used to pass to g_date_time_format() to make a string for displaying on the panel.", DEFAULT_TIME_FORMAT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); @@ -775,6 +775,12 @@ set_label_to_time_in_zone (IndicatorDatetime * self, GtkLabel * label, } else { timestr = g_date_time_format(datetime_now, format); + if (timestr == NULL) { + g_warning ("The custom date format is not valid, check the + g_date_time_format() documentation for the supported + format specifiers "); + timestr = g_strdup ("Date format not supported"); + } } gboolean use_markup = FALSE; -- cgit v1.2.3 From 805b0b286192282b590b4003612fdf29d2284c0a Mon Sep 17 00:00:00 2001 From: Javier Jardón Date: Mon, 5 Sep 2011 14:31:13 +0100 Subject: indicator-datetime.c: 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 --- configure.ac | 2 ++ src/indicator-datetime.c | 92 ++++++++++++++---------------------------------- 2 files changed, 28 insertions(+), 66 deletions(-) (limited to 'src/indicator-datetime.c') diff --git a/configure.ac b/configure.ac index 7b8682c..55c4f3b 100644 --- a/configure.ac +++ b/configure.ac @@ -26,6 +26,7 @@ AC_HEADER_STDC LT_PREREQ([2.2]) LT_INIT([disable-static]) +AC_CHECK_LIB([m],[pow]) AC_ARG_ENABLE([deprecations], [AS_HELP_STRING([--enable-deprecations], @@ -74,6 +75,7 @@ GCONF_REQUIRED_VERSION=2.31 AS_IF([test "x$with_gtk" = x3], [PKG_CHECK_MODULES(INDICATOR, indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION glib-2.0 >= $GLIB_REQUIRED_VERSION + gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION libido3-0.1 >= $INDICATOR_DISPLAY_OBJECTS) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 59bcaf3..2562b62 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -45,6 +45,10 @@ with this program. If not, see . #include #include +/* For GnomeWallClock */ +#define GNOME_DESKTOP_USE_UNSTABLE_API +#include + #include "utils.h" #include "dbus-shared.h" #include "settings-shared.h" @@ -72,7 +76,6 @@ struct _IndicatorDatetime { struct _IndicatorDatetimePrivate { GtkLabel * label; - guint timer; gchar * time_string; @@ -103,6 +106,8 @@ struct _IndicatorDatetimePrivate { GSettings * settings; GtkSizeGroup * indicator_right_group; + + GnomeWallClock *clock; }; /* Enum for the properties so that they can be quickly @@ -169,8 +174,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); @@ -294,7 +299,6 @@ indicator_datetime_init (IndicatorDatetime *self) self->priv = INDICATOR_DATETIME_GET_PRIVATE(self); self->priv->label = NULL; - self->priv->timer = 0; self->priv->idle_measure = 0; self->priv->max_width = 0; @@ -363,6 +367,9 @@ indicator_datetime_init (IndicatorDatetime *self) g_warning("Unable to get settings for '" SETTINGS_INTERFACE "'"); } + self->priv->clock = g_object_new (GNOME_TYPE_WALL_CLOCK, NULL); + g_signal_connect (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)); @@ -435,9 +442,9 @@ indicator_datetime_dispose (GObject *object) self->priv->label = NULL; } - if (self->priv->timer != 0) { - g_source_remove(self->priv->timer); - self->priv->timer = 0; + if (self->priv->clock != NULL) { + g_object_unref (self->priv->clock); + self->priv->clock = NULL; } if (self->priv->idle_measure != 0) { @@ -563,7 +570,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; - setup_timer(self, NULL); + update_time (self); } break; } @@ -572,7 +579,7 @@ 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; - setup_timer(self, NULL); + update_time (self); } } break; @@ -607,7 +614,7 @@ 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; - setup_timer(self, NULL); + update_time (self); } } break; @@ -825,11 +832,16 @@ update_time (IndicatorDatetime * self) 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; +} + +static void +on_clock_changed (GnomeWallClock *clock, + GParamSpec *pspec, + gpointer user_data) +{ + IndicatorDatetime *self = INDICATOR_DATETIME (user_data); + + update_time (self); } /* Receives all signals from the service, routed to the appropriate functions */ @@ -846,54 +858,6 @@ 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 @@ -1513,10 +1477,6 @@ 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; } -- cgit v1.2.3 From ef6479a971ec5e8ab1c12a090e6f2a338bd0c8ad Mon Sep 17 00:00:00 2001 From: Javier Jardón Date: Mon, 5 Sep 2011 15:17:31 +0100 Subject: indicator-datetime.c: Fix typo --- src/indicator-datetime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/indicator-datetime.c') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 2562b62..9a74ced 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -368,7 +368,7 @@ indicator_datetime_init (IndicatorDatetime *self) } self->priv->clock = g_object_new (GNOME_TYPE_WALL_CLOCK, NULL); - g_signal_connect (clock, "notify::clock", G_CALLBACK (on_clock_changed), self); + 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)); -- cgit v1.2.3 From 87eaa8d2fa412e2f28360587308530fd3e9231d9 Mon Sep 17 00:00:00 2001 From: Javier Jardón Date: Mon, 5 Sep 2011 18:18:18 +0100 Subject: indicator-datetime: Update the desktop schema when showing seconds As GnomeWallClock uses "clock-show-seconds" desktop key to update the current time --- configure.ac | 2 ++ src/indicator-datetime.c | 9 +++++++++ 2 files changed, 11 insertions(+) (limited to 'src/indicator-datetime.c') diff --git a/configure.ac b/configure.ac index 55c4f3b..eaeb958 100644 --- a/configure.ac +++ b/configure.ac @@ -66,6 +66,7 @@ ECAL_REQUIRED_VERSION=2.30 EDS_REQUIRED_VERSION=2.30 ICAL_REQUIRED_VERSION=0.44 GNOME_DESKTOP_REQUIRED_VERSION=3.1.91 +GSETTINGS_DESKTOP_SCHEMAS_REQUIRED=3.1.4 CAIRO_REQUIRED_VERSION=1.10 GDK_REQUIRED_VERSION=2.22 GLIB_REQUIRED_VERSION=2.26 @@ -76,6 +77,7 @@ AS_IF([test "x$with_gtk" = x3], [PKG_CHECK_MODULES(INDICATOR, indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION glib-2.0 >= $GLIB_REQUIRED_VERSION gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION + gsettings-desktop-schemas >= $GSETTINGS_DESKTOP_SCHEMAS_REQUIRED dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION libido3-0.1 >= $INDICATOR_DISPLAY_OBJECTS) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 9a74ced..16ad131 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -104,6 +104,7 @@ struct _IndicatorDatetimePrivate { GList * timezone_items; GSettings * settings; + GSettings * gnome_settings; GtkSizeGroup * indicator_right_group; @@ -367,6 +368,8 @@ 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); @@ -581,6 +584,9 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec update = TRUE; update_time (self); } + g_settings_set_boolean (self->priv->gnome_settings, + "clock-show-seconds", + self->priv->show_seconds); } break; } @@ -616,6 +622,9 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec update = TRUE; update_time (self); } + g_settings_set_boolean (self->priv->gnome_settings, + "clock-show-seconds", + self->priv->show_seconds); } break; } -- cgit v1.2.3 From 5a40e16a537fe56e220d5db42c3870ce48ef1e88 Mon Sep 17 00:00:00 2001 From: Javier Jardón Date: Tue, 6 Sep 2011 13:54:49 +0100 Subject: indicator-datetime.c: Use private pointer instead GET_PRIV macro --- src/indicator-datetime.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/indicator-datetime.c') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 59bcaf3..f8dbdae 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -138,9 +138,6 @@ struct _indicator_item_t { #define PROP_SHOW_WEEK_NUMBERS_S "show-week-numbers" #define PROP_SHOW_CALENDAR_S "show-calendar" -#define INDICATOR_DATETIME_GET_PRIVATE(o) \ -(G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_DATETIME_TYPE, IndicatorDatetimePrivate)) - enum { STRFTIME_MASK_NONE = 0, /* Hours or minutes as we always test those */ STRFTIME_MASK_SECONDS = 1 << 0, /* Seconds count */ @@ -291,7 +288,9 @@ menu_visible_notfy_cb(GtkWidget * menu, G_GNUC_UNUSED GParamSpec *pspec, gpointe static void indicator_datetime_init (IndicatorDatetime *self) { - self->priv = INDICATOR_DATETIME_GET_PRIVATE(self); + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + INDICATOR_DATETIME_TYPE, + IndicatorDatetimePrivate); self->priv->label = NULL; self->priv->timer = 0; @@ -400,11 +399,10 @@ service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) IndicatorDatetime * self = INDICATOR_DATETIME(user_data); g_return_if_fail(self != NULL); + IndicatorDatetimePrivate * priv = self->priv; GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); - IndicatorDatetimePrivate * priv = INDICATOR_DATETIME_GET_PRIVATE(self); - if (priv->service_proxy_cancel != NULL) { g_object_unref(priv->service_proxy_cancel); priv->service_proxy_cancel = NULL; @@ -537,7 +535,8 @@ bind_enum_get (GValue * value, GVariant * variant, gpointer user_data) static void timezone_update_all_labels (IndicatorDatetime * self) { - IndicatorDatetimePrivate *priv = INDICATOR_DATETIME_GET_PRIVATE(self); + IndicatorDatetimePrivate *priv = self->priv; + g_list_foreach(priv->timezone_items, (GFunc)timezone_update_labels, NULL); } @@ -1386,8 +1385,7 @@ new_calendar_item (DbusmenuMenuitem * newitem, /* Note: not checking parent, it's reasonable for it to be NULL */ IndicatorDatetime *self = INDICATOR_DATETIME(user_data); - self->priv = INDICATOR_DATETIME_GET_PRIVATE(self); - + IdoCalendarMenuItem *ido = IDO_CALENDAR_MENU_ITEM (ido_calendar_menu_item_new ()); self->priv->ido_calendar = ido; @@ -1431,7 +1429,9 @@ timezone_toggled_cb (GtkCheckMenuItem *checkmenuitem, DbusmenuMenuitem * dbusite static void timezone_destroyed_cb (indicator_item_t * mi_data, DbusmenuMenuitem * dbusitem) { - IndicatorDatetimePrivate *priv = INDICATOR_DATETIME_GET_PRIVATE(mi_data->self); + IndicatorDatetime *self = INDICATOR_DATETIME (mi_data->self); + IndicatorDatetimePrivate *priv = self->priv; + priv->timezone_items = g_list_remove(priv->timezone_items, mi_data); g_signal_handlers_disconnect_by_func(G_OBJECT(mi_data->gmi), G_CALLBACK(timezone_toggled_cb), dbusitem); g_free(mi_data); @@ -1449,7 +1449,7 @@ new_timezone_item(DbusmenuMenuitem * newitem, /* Note: not checking parent, it's reasonable for it to be NULL */ IndicatorDatetime * self = INDICATOR_DATETIME(user_data); - IndicatorDatetimePrivate *priv = INDICATOR_DATETIME_GET_PRIVATE(self); + IndicatorDatetimePrivate *priv = self->priv; // Menu item with a radio button and a right aligned time indicator_item_t * mi_data = g_new0(indicator_item_t, 1); -- cgit v1.2.3 From 46ab5ac5bcb2811effd36f4418726421aba1052b Mon Sep 17 00:00:00 2001 From: Javier Jardón Date: Tue, 6 Sep 2011 13:55:50 +0100 Subject: indicator-datetime.c: Use G_GNUC_CONST in the type declaration --- src/indicator-datetime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/indicator-datetime.c') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index f8dbdae..a9c8469 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -150,7 +150,7 @@ enum { STRFTIME_MASK_ALL = (STRFTIME_MASK_SECONDS | STRFTIME_MASK_AMPM | STRFTIME_MASK_WEEK | STRFTIME_MASK_DAY | STRFTIME_MASK_MONTH | STRFTIME_MASK_YEAR) }; -GType indicator_datetime_get_type (void); +GType indicator_datetime_get_type (void) G_GNUC_CONST; static void indicator_datetime_class_init (IndicatorDatetimeClass *klass); static void indicator_datetime_init (IndicatorDatetime *self); -- cgit v1.2.3