diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2013-07-25 18:57:29 -0500 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2013-07-25 18:57:29 -0500 |
commit | 5761e8d1d75838c8a097ab1e41c3b51b33037437 (patch) | |
tree | 81120e85ed02c280b3750e07bb7974b4a2231bb0 /src | |
parent | 1b7166676eb42a26a8547e795064631edd0653df (diff) | |
download | ayatana-ido-5761e8d1d75838c8a097ab1e41c3b51b33037437.tar.gz ayatana-ido-5761e8d1d75838c8a097ab1e41c3b51b33037437.tar.bz2 ayatana-ido-5761e8d1d75838c8a097ab1e41c3b51b33037437.zip |
implement IdoLocationMenuItem as a subclass of IdoTimeStampMenuItem
Diffstat (limited to 'src')
-rw-r--r-- | src/idoappointmentmenuitem.c | 4 | ||||
-rw-r--r-- | src/idolocationmenuitem.c | 115 | ||||
-rw-r--r-- | src/idolocationmenuitem.h | 6 |
3 files changed, 34 insertions, 91 deletions
diff --git a/src/idoappointmentmenuitem.c b/src/idoappointmentmenuitem.c index b383729..cfc0bf8 100644 --- a/src/idoappointmentmenuitem.c +++ b/src/idoappointmentmenuitem.c @@ -74,8 +74,8 @@ create_color_icon_pixbuf (const char * color_spec) * @menu_item: the corresponding menuitem * @actions: action group to tell when this GtkMenuItem is activated * - * Creates a new IdoAppointmentMenuItem with properties initialized from - * the menuitem's attributes. + * Creates a new IdoTimeStampMenuItem with properties initialized + * appropriately for a com.canonical.indicator.alarm * * If the menuitem's 'action' attribute is set, trigger that action * in @actions when this IdoAppointmentMenuItem is activated. diff --git a/src/idolocationmenuitem.c b/src/idolocationmenuitem.c index df7c210..335422a 100644 --- a/src/idolocationmenuitem.c +++ b/src/idolocationmenuitem.c @@ -32,7 +32,6 @@ enum { PROP_0, PROP_TIMEZONE, - PROP_FORMAT, PROP_LAST }; @@ -41,48 +40,34 @@ static GParamSpec *properties[PROP_LAST]; struct _IdoLocationMenuItemPrivate { char * timezone; - char * format; guint timestamp_timer; }; typedef IdoLocationMenuItemPrivate priv_t; -G_DEFINE_TYPE (IdoLocationMenuItem, ido_location_menu_item, IDO_TYPE_BASIC_MENU_ITEM); +G_DEFINE_TYPE (IdoLocationMenuItem, ido_location_menu_item, IDO_TYPE_TIME_STAMP_MENU_ITEM); /*** **** Timestamp Label ***/ static void -update_timestamp_label (IdoLocationMenuItem * self) +update_timestamp (IdoLocationMenuItem * self) { - char * str; - priv_t * p = self->priv; - - if (p->format && *p->format) - { - GTimeZone * tz; - GDateTime * now; - - tz = g_time_zone_new (p->timezone); - if (tz == NULL) - tz = g_time_zone_new_local (); - now = g_date_time_new_now (tz); - - str = g_date_time_format (now, p->format); + GTimeZone * tz; + GDateTime * date_time; - g_date_time_unref (now); - g_time_zone_unref (tz); - } - else - { - str = NULL; - } + tz = g_time_zone_new (self->priv->timezone); + if (tz == NULL) + tz = g_time_zone_new_local (); + date_time = g_date_time_new_now (tz); - ido_basic_menu_item_set_secondary_text (IDO_BASIC_MENU_ITEM(self), str); + ido_time_stamp_menu_item_set_date_time (IDO_TIME_STAMP_MENU_ITEM(self), + date_time); - g_free (str); + g_date_time_unref (date_time); + g_time_zone_unref (tz); } static void @@ -97,16 +82,16 @@ stop_timestamp_timer (IdoLocationMenuItem * self) } } -static void start_timestamp_timer (IdoLocationMenuItem * self); +static void restart_timestamp_timer (IdoLocationMenuItem * self); static gboolean on_timestamp_timer (gpointer gself) { IdoLocationMenuItem * self = IDO_LOCATION_MENU_ITEM (gself); - update_timestamp_label (self); + update_timestamp (self); - start_timestamp_timer (self); + restart_timestamp_timer (self); return G_SOURCE_REMOVE; } @@ -140,12 +125,11 @@ calculate_seconds_until_next_minute (void) } static void -start_timestamp_timer (IdoLocationMenuItem * self) +restart_timestamp_timer (IdoLocationMenuItem * self) { - int interval_sec; + const char * fmt = ido_time_stamp_menu_item_get_format (IDO_TIME_STAMP_MENU_ITEM (self)); gboolean timestamp_shows_seconds; - priv_t * p = self->priv; - const char * const fmt = p->format; + int interval_sec; stop_timestamp_timer (self); @@ -158,9 +142,9 @@ start_timestamp_timer (IdoLocationMenuItem * self) else interval_sec = calculate_seconds_until_next_minute(); - p->timestamp_timer = g_timeout_add_seconds (interval_sec, - on_timestamp_timer, - self); + self->priv->timestamp_timer = g_timeout_add_seconds (interval_sec, + on_timestamp_timer, + self); } /*** @@ -182,10 +166,6 @@ my_get_property (GObject * o, g_value_set_string (value, p->timezone); break; - case PROP_FORMAT: - g_value_set_string (value, p->format); - break; - default: G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); break; @@ -206,10 +186,6 @@ my_set_property (GObject * o, ido_location_menu_item_set_timezone (self, g_value_get_string (value)); break; - case PROP_FORMAT: - ido_location_menu_item_set_format (self, g_value_get_string (value)); - break; - default: G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); break; @@ -228,10 +204,8 @@ static void my_finalize (GObject * object) { IdoLocationMenuItem * self = IDO_LOCATION_MENU_ITEM (object); - priv_t * p = self->priv; - g_free (p->format); - g_free (p->timezone); + g_free (self->priv->timezone); G_OBJECT_CLASS (ido_location_menu_item_parent_class)->finalize (object); } @@ -243,7 +217,6 @@ my_finalize (GObject * object) static void ido_location_menu_item_class_init (IdoLocationMenuItemClass *klass) { - GParamFlags prop_flags; GObjectClass * gobject_class = G_OBJECT_CLASS (klass); g_type_class_add_private (klass, sizeof (IdoLocationMenuItemPrivate)); @@ -253,23 +226,12 @@ ido_location_menu_item_class_init (IdoLocationMenuItemClass *klass) gobject_class->dispose = my_dispose; gobject_class->finalize = my_finalize; - prop_flags = G_PARAM_CONSTRUCT - | G_PARAM_READWRITE - | G_PARAM_STATIC_STRINGS; - properties[PROP_TIMEZONE] = g_param_spec_string ( "timezone", "timezone identifier", "string used to identify a timezone; eg, 'America/Chicago'", NULL, - prop_flags); - - properties[PROP_FORMAT] = g_param_spec_string ( - "format", - "strftime format", - "strftime-style format string for the timestamp", - "%T", - prop_flags); + G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (gobject_class, PROP_LAST, properties); } @@ -280,6 +242,11 @@ ido_location_menu_item_init (IdoLocationMenuItem *self) self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, IDO_LOCATION_MENU_ITEM_TYPE, IdoLocationMenuItemPrivate); + + /* Update the timer whenever the format string changes + because it determines whether we update once per second or per minute */ + g_signal_connect (self, "notify::format", + G_CALLBACK(restart_timestamp_timer), NULL); } /*** @@ -311,31 +278,7 @@ ido_location_menu_item_set_timezone (IdoLocationMenuItem * self, g_free (p->timezone); p->timezone = g_strdup (timezone); - update_timestamp_label (self); -} - -/** - * ido_location_menu_item_set_format: - * @format: the format string used when showing the location's time - * - * Set the format string for rendering the location's time - * in its right-justified secondary label. - * - * See strfrtime(3) for more information on the format string. - */ -void -ido_location_menu_item_set_format (IdoLocationMenuItem * self, - const char * format) -{ - priv_t * p; - - g_return_if_fail (IDO_IS_LOCATION_MENU_ITEM (self)); - p = self->priv; - - g_free (p->format); - p->format = g_strdup (format); - update_timestamp_label (self); - start_timestamp_timer (self); + update_timestamp (self); } /** diff --git a/src/idolocationmenuitem.h b/src/idolocationmenuitem.h index 53fe063..2ae231f 100644 --- a/src/idolocationmenuitem.h +++ b/src/idolocationmenuitem.h @@ -21,7 +21,7 @@ #define __IDO_LOCATION_MENU_ITEM_H__ #include <gtk/gtk.h> -#include "idobasicmenuitem.h" +#include "idotimestampmenuitem.h" G_BEGIN_DECLS @@ -35,7 +35,7 @@ typedef struct _IdoLocationMenuItemPrivate IdoLocationMenuItemPrivate; struct _IdoLocationMenuItemClass { - IdoBasicMenuItemClass parent_class; + IdoTimeStampMenuItemClass parent_class; }; /** @@ -47,7 +47,7 @@ struct _IdoLocationMenuItemClass struct _IdoLocationMenuItem { /*< private >*/ - IdoBasicMenuItem parent; + IdoTimeStampMenuItem parent; IdoLocationMenuItemPrivate * priv; }; |