From 79875b4b19db7da66966aee7154620bf030cdbf4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 24 Jul 2013 00:08:29 -0500 Subject: add a menuitem that renders com.canonical.indicator.progress as laid out in https://wiki.ubuntu.com/Power#Phone --- src/Makefile.am | 2 + src/idobasicmenuitem.c | 392 +++++++++++++++++++++++++++++++++++++++++++++++ src/idobasicmenuitem.h | 77 ++++++++++ src/idomenuitemfactory.c | 4 + 4 files changed, 475 insertions(+) create mode 100644 src/idobasicmenuitem.c create mode 100644 src/idobasicmenuitem.h diff --git a/src/Makefile.am b/src/Makefile.am index 2791964..a4ca6fd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,6 +19,7 @@ sources_h = \ idoswitchmenuitem.h \ idousermenuitem.h \ idoappointmentmenuitem.h \ + idobasicmenuitem.h \ idolocationmenuitem.h \ idotimeline.h \ libido.h \ @@ -80,6 +81,7 @@ libido_0_1_la_SOURCES = \ idomediaplayermenuitem.c \ idoplaybackmenuitem.c \ idoappointmentmenuitem.c \ + idobasicmenuitem.c \ idolocationmenuitem.c libido3_0_1_la_SOURCES = $(libido_0_1_la_SOURCES) diff --git a/src/idobasicmenuitem.c b/src/idobasicmenuitem.c new file mode 100644 index 0000000..59e949c --- /dev/null +++ b/src/idobasicmenuitem.c @@ -0,0 +1,392 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * Authors: + * Charles Kerr + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +#include /* strstr() */ + +#include + +#include "idoactionhelper.h" +#include "idobasicmenuitem.h" + +enum +{ + PROP_0, + PROP_ICON, + PROP_TEXT, + PROP_SECONDARY_TEXT, + PROP_LAST +}; + +static GParamSpec *properties[PROP_LAST]; + +struct _IdoBasicMenuItemPrivate +{ + GIcon * icon; + char * text; + char * secondary_text; + + GtkWidget * image; + GtkWidget * label; + GtkWidget * secondary_label; +}; + +typedef IdoBasicMenuItemPrivate priv_t; + +G_DEFINE_TYPE (IdoBasicMenuItem, ido_basic_menu_item, GTK_TYPE_MENU_ITEM); + +/*** +**** GObject Virtual Functions +***/ + +static void +my_get_property (GObject * o, + guint property_id, + GValue * value, + GParamSpec * pspec) +{ + IdoBasicMenuItem * self = IDO_BASIC_MENU_ITEM (o); + priv_t * p = self->priv; + + switch (property_id) + { + case PROP_ICON: + g_value_set_object (value, p->icon); + break; + + case PROP_TEXT: + g_value_set_string (value, p->text); + break; + + case PROP_SECONDARY_TEXT: + g_value_set_string (value, p->secondary_text); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); + break; + } +} + +static void +my_set_property (GObject * o, + guint property_id, + const GValue * value, + GParamSpec * pspec) +{ + IdoBasicMenuItem * self = IDO_BASIC_MENU_ITEM (o); + + switch (property_id) + { + case PROP_ICON: + ido_basic_menu_item_set_icon (self, g_value_get_object (value)); + break; + + case PROP_TEXT: + ido_basic_menu_item_set_text (self, g_value_get_string (value)); + break; + + case PROP_SECONDARY_TEXT: + ido_basic_menu_item_set_secondary_text (self, g_value_get_string (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); + break; + } +} + +static void +my_dispose (GObject * object) +{ + IdoBasicMenuItem * self = IDO_BASIC_MENU_ITEM (object); + priv_t * p = self->priv; + + g_clear_object (&p->icon); + + G_OBJECT_CLASS (ido_basic_menu_item_parent_class)->dispose (object); +} + +static void +my_finalize (GObject * object) +{ + IdoBasicMenuItem * self = IDO_BASIC_MENU_ITEM (object); + priv_t * p = self->priv; + + g_free (p->text); + g_free (p->secondary_text); + + G_OBJECT_CLASS (ido_basic_menu_item_parent_class)->finalize (object); +} + +/*** +**** Instantiation +***/ + +static void +ido_basic_menu_item_class_init (IdoBasicMenuItemClass *klass) +{ + GParamFlags prop_flags; + GObjectClass * gobject_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (IdoBasicMenuItemPrivate)); + + gobject_class->get_property = my_get_property; + gobject_class->set_property = my_set_property; + gobject_class->dispose = my_dispose; + gobject_class->finalize = my_finalize; + + prop_flags = G_PARAM_CONSTRUCT + | G_PARAM_READWRITE + | G_PARAM_STATIC_STRINGS; + + properties[PROP_ICON] = g_param_spec_object ("icon", + "Icon", + "The menuitem's GIcon", + G_TYPE_OBJECT, + prop_flags); + + properties[PROP_TEXT] = g_param_spec_string ("text", + "Text", + "The menuitem's text", + "", + prop_flags); + + properties[PROP_SECONDARY_TEXT] = g_param_spec_string ("secondary-text", + "Secondary Text", + "The menuitem's secondary text", + "", + prop_flags); + + g_object_class_install_properties (gobject_class, PROP_LAST, properties); +} + +static void +ido_basic_menu_item_init (IdoBasicMenuItem *self) +{ + priv_t * p; + GtkWidget * w; + GtkGrid * grid; + + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + IDO_BASIC_MENU_ITEM_TYPE, + IdoBasicMenuItemPrivate); + + p = self->priv; + + p->image = gtk_image_new (); + gtk_misc_set_alignment(GTK_MISC(p->image), 0.0, 0.0); + p->label = gtk_label_new (""); + gtk_misc_set_alignment (GTK_MISC(p->label), 0.0, 0.5); + p->secondary_label = gtk_label_new (""); + gtk_misc_set_alignment (GTK_MISC(p->secondary_label), 1.0, 0.5); + + w = gtk_grid_new (); + grid = GTK_GRID (w); + gtk_grid_attach (grid, p->image, 0, 0, 1, 1); + gtk_grid_attach (grid, p->label, 1, 0, 1, 1); + gtk_grid_attach (grid, p->secondary_label, 2, 0, 1, 1); + g_object_set (p->label, + "halign", GTK_ALIGN_START, + "hexpand", TRUE, + "margin-right", 6, + "valign", GTK_ALIGN_CENTER, + NULL); + g_object_set (p->secondary_label, + "halign", GTK_ALIGN_END, + "hexpand", FALSE, + "valign", GTK_ALIGN_CENTER, + NULL); + + gtk_widget_show (w); + gtk_container_add (GTK_CONTAINER (self), w); +} + + +/*** +**** Public API +***/ + +/* create a new IdoBasicMenuItem */ +GtkWidget * +ido_basic_menu_item_new (void) +{ + return GTK_WIDGET (g_object_new (IDO_BASIC_MENU_ITEM_TYPE, NULL)); +} + +void +ido_basic_menu_item_set_icon (IdoBasicMenuItem * self, GIcon * icon) +{ + IdoBasicMenuItemPrivate * p = self->priv; + + if (p->icon != icon) + { + g_clear_object (&p->icon); + + if (icon == NULL) + { + gtk_image_clear (GTK_IMAGE(p->image)); + gtk_widget_set_visible (p->image, FALSE); + } + else + { + p->icon = g_object_ref (icon); + gtk_image_set_from_gicon (GTK_IMAGE(p->image), p->icon, GTK_ICON_SIZE_MENU); + gtk_widget_set_visible (p->image, TRUE); + } + } +} + +void +ido_basic_menu_item_set_icon_from_file (IdoBasicMenuItem * self, const char * filename) +{ + GFile * file = filename ? g_file_new_for_path (filename) : NULL; + GIcon * icon = file ? g_file_icon_new (file) : NULL; + + ido_basic_menu_item_set_icon (self, icon); + + g_clear_object (&icon); + g_clear_object (&file); +} + +void +ido_basic_menu_item_set_text (IdoBasicMenuItem * self, const char * text) +{ + IdoBasicMenuItemPrivate * p = self->priv; + + if (g_strcmp0 (p->text, text)) + { + g_free (p->text); + p->text = g_strdup (text); + + g_object_set (G_OBJECT(p->label), + "label", p->text, + "visible", (gboolean)(p->text && *p->text), + NULL); + } +} + +void +ido_basic_menu_item_set_secondary_text (IdoBasicMenuItem * self, const char * secondary_text) +{ + IdoBasicMenuItemPrivate * p = self->priv; + + if (g_strcmp0 (p->secondary_text, secondary_text)) + { + g_free (p->secondary_text); + p->secondary_text = g_strdup (secondary_text); + + g_object_set (G_OBJECT(p->secondary_label), + "label", p->secondary_text, + "visible", (gboolean)(p->secondary_text && *p->secondary_text), + NULL); + } +} + +/*** +**** +**** +**** +***/ + +static void +on_progress_action_state_changed (IdoActionHelper * helper, + GVariant * state, + gpointer unused G_GNUC_UNUSED) +{ + IdoBasicMenuItem * ido_menu_item; + char * str; + + ido_menu_item = IDO_BASIC_MENU_ITEM (ido_action_helper_get_widget (helper)); + + g_return_if_fail (ido_menu_item != NULL); + g_return_if_fail (g_variant_is_of_type (state, G_VARIANT_TYPE_UINT32)); + + str = g_strdup_printf ("%"G_GUINT32_FORMAT"%%", g_variant_get_uint32 (state)); + ido_basic_menu_item_set_secondary_text (ido_menu_item, str); + g_free (str); +} + +/** + * ido_progress_menu_item_new_from_model: + * @menu_item: the corresponding menuitem + * @actions: action group to tell when this GtkMenuItem is activated + * + * Creates a new progress menuitem with properties initialized from + * the menuitem's attributes. + * + * If the menuitem's 'action' attribute is set, trigger that action + * in @actions when this IdoBasicMenuItem is activated. + */ +GtkMenuItem * +ido_progress_menu_item_new_from_model (GMenuItem * menu_item, + GActionGroup * actions) +{ + guint i; + guint n; + gchar * str; + IdoBasicMenuItem * ido_menu_item; + GParameter parameters[4]; + + /* create the ido menuitem */; + + n = 0; + + if (g_menu_item_get_attribute (menu_item, "label", "s", &str)) + { + GParameter p = { "text", G_VALUE_INIT }; + g_value_init (&p.value, G_TYPE_STRING); + g_value_take_string (&p.value, str); + parameters[n++] = p; + } + + g_assert (n <= G_N_ELEMENTS (parameters)); + ido_menu_item = g_object_newv (IDO_BASIC_MENU_ITEM_TYPE, n, parameters); + + for (i=0; ipriv->label, FALSE); + gtk_widget_set_sensitive (ido_menu_item->priv->secondary_label, FALSE); + + /* give it an ActionHelper */ + + if (g_menu_item_get_attribute (menu_item, "action", "s", &str)) + { + IdoActionHelper * helper; + + helper = ido_action_helper_new (GTK_WIDGET(ido_menu_item), + actions, + str, + NULL); + g_signal_connect (helper, "action-state-changed", + G_CALLBACK (on_progress_action_state_changed), NULL); + g_signal_connect_swapped (ido_menu_item, "destroy", + G_CALLBACK (g_object_unref), helper); + + g_free (str); + } + + return GTK_MENU_ITEM (ido_menu_item); +} diff --git a/src/idobasicmenuitem.h b/src/idobasicmenuitem.h new file mode 100644 index 0000000..0da9086 --- /dev/null +++ b/src/idobasicmenuitem.h @@ -0,0 +1,77 @@ +/** + * Copyright 2013 Canonical Ltd. + * + * Authors: + * Charles Kerr + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef __IDO_BASIC_MENU_ITEM_H__ +#define __IDO_BASIC_MENU_ITEM_H__ + +#include + +G_BEGIN_DECLS + +#define IDO_BASIC_MENU_ITEM_TYPE (ido_basic_menu_item_get_type ()) +#define IDO_BASIC_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_BASIC_MENU_ITEM_TYPE, IdoBasicMenuItem)) +#define IDO_IS_BASIC_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_BASIC_MENU_ITEM_TYPE)) + +typedef struct _IdoBasicMenuItem IdoBasicMenuItem; +typedef struct _IdoBasicMenuItemClass IdoBasicMenuItemClass; +typedef struct _IdoBasicMenuItemPrivate IdoBasicMenuItemPrivate; + +struct _IdoBasicMenuItemClass +{ + GtkMenuItemClass parent_class; +}; + +/** + * A simple menuitem that includes a right-justified secondary text. + */ +struct _IdoBasicMenuItem +{ + /*< private >*/ + GtkMenuItem parent; + IdoBasicMenuItemPrivate * priv; +}; + + +GType ido_basic_menu_item_get_type (void) G_GNUC_CONST; + +GtkWidget * ido_basic_menu_item_new (void); + +void ido_basic_menu_item_set_icon (IdoBasicMenuItem * self, + GIcon * icon); + +void ido_basic_menu_item_set_icon_from_file (IdoBasicMenuItem * self, + const char * filename); + +void ido_basic_menu_item_set_text (IdoBasicMenuItem * self, + const char * text); + +void ido_basic_menu_item_set_secondary_text (IdoBasicMenuItem * self, + const char * text); + +/** +*** +**/ + +GtkMenuItem * ido_progress_menu_item_new_from_model (GMenuItem * menuitem, + GActionGroup * actions); + + +G_END_DECLS + +#endif diff --git a/src/idomenuitemfactory.c b/src/idomenuitemfactory.c index 5ded309..b233095 100644 --- a/src/idomenuitemfactory.c +++ b/src/idomenuitemfactory.c @@ -21,6 +21,7 @@ #include #include "idoappointmentmenuitem.h" +#include "idobasicmenuitem.h" #include "idocalendarmenuitem.h" #include "idolocationmenuitem.h" #include "idoscalemenuitem.h" @@ -66,6 +67,9 @@ ido_menu_item_factory_create_menu_item (UbuntuMenuItemFactory *factory, else if (g_str_equal (type, "com.canonical.indicator.appointment")) item = ido_appointment_menu_item_new_from_model (menuitem, actions); + else if (g_str_equal (type, "com.canonical.indicator.progress")) + item = ido_progress_menu_item_new_from_model (menuitem, actions); + else if (g_str_equal (type, "com.canonical.unity.slider")) item = ido_scale_menu_item_new_from_model (menuitem, actions); -- cgit v1.2.3 From 69f5f2cbbb7f12e71cf79ed3ae50187455dfd03a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 24 Jul 2013 13:09:24 -0500 Subject: add public API symbols to debian/ --- debian/libido3-0.1-0.symbols | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/debian/libido3-0.1-0.symbols b/debian/libido3-0.1-0.symbols index 11cd621..d2c427d 100644 --- a/debian/libido3-0.1-0.symbols +++ b/debian/libido3-0.1-0.symbols @@ -12,6 +12,12 @@ libido3-0.1.so.0 libido3-0.1-0 #MINVER# ido_appointment_menu_item_set_format@Base 13.10.0daily13.06.19 ido_appointment_menu_item_set_summary@Base 13.10.0daily13.06.19 ido_appointment_menu_item_set_time@Base 13.10.0daily13.06.19 + ido_basic_menu_item_get_type@Base 0replaceme + ido_basic_menu_item_new@Base 0replaceme + ido_basic_menu_item_set_icon@Base 0replaceme + ido_basic_menu_item_set_icon_from_file@Base 0replaceme + ido_basic_menu_item_set_secondary_text@Base 0replaceme + ido_basic_menu_item_set_text@Base 0replaceme ido_calendar_menu_item_clear_marks@Base 0.2.1 ido_calendar_menu_item_get_calendar@Base 0.1.10 ido_calendar_menu_item_get_date@Base 0.2.1 @@ -38,6 +44,7 @@ libido3-0.1.so.0 libido3-0.1-0 #MINVER# ido_message_dialog_get_type@Base 0.1.8 ido_message_dialog_new@Base 0.1.8 ido_message_dialog_new_with_markup@Base 0.1.8 + ido_progress_menu_item_new_from_model@Base 0replaceme ido_range_get_type@Base 0.1.9 ido_range_new@Base 0.1.9 ido_range_style_get_type@Base 0.1.9 -- cgit v1.2.3 From 2ef49dc4fcf1b156310cd937ab8a5ff65afb1874 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 24 Jul 2013 13:10:19 -0500 Subject: don't hardcode making com.canonical.indicator.progress insensitive; its sensitivity should follow its action's sensitivity. --- src/idobasicmenuitem.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/idobasicmenuitem.c b/src/idobasicmenuitem.c index 59e949c..b006d6a 100644 --- a/src/idobasicmenuitem.c +++ b/src/idobasicmenuitem.c @@ -21,8 +21,6 @@ #include "config.h" #endif -#include /* strstr() */ - #include #include "idoactionhelper.h" @@ -304,7 +302,7 @@ ido_basic_menu_item_set_secondary_text (IdoBasicMenuItem * self, const char * se /*** **** -**** +**** Progress Menu Item **** ***/ @@ -365,11 +363,6 @@ ido_progress_menu_item_new_from_model (GMenuItem * menu_item, for (i=0; ipriv->label, FALSE); - gtk_widget_set_sensitive (ido_menu_item->priv->secondary_label, FALSE); - /* give it an ActionHelper */ if (g_menu_item_get_attribute (menu_item, "action", "s", &str)) -- cgit v1.2.3 From 8a9b4b895d4cf4930ff6dd6865639397aed05c54 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 25 Jul 2013 15:51:57 -0500 Subject: add make the type macro for IdoBasicMenuItem follow the standard naming scheme --- src/idobasicmenuitem.c | 6 +++--- src/idobasicmenuitem.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/idobasicmenuitem.c b/src/idobasicmenuitem.c index b006d6a..a1eadbf 100644 --- a/src/idobasicmenuitem.c +++ b/src/idobasicmenuitem.c @@ -186,7 +186,7 @@ ido_basic_menu_item_init (IdoBasicMenuItem *self) GtkGrid * grid; self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - IDO_BASIC_MENU_ITEM_TYPE, + IDO_TYPE_BASIC_MENU_ITEM, IdoBasicMenuItemPrivate); p = self->priv; @@ -228,7 +228,7 @@ ido_basic_menu_item_init (IdoBasicMenuItem *self) GtkWidget * ido_basic_menu_item_new (void) { - return GTK_WIDGET (g_object_new (IDO_BASIC_MENU_ITEM_TYPE, NULL)); + return GTK_WIDGET (g_object_new (IDO_TYPE_BASIC_MENU_ITEM, NULL)); } void @@ -358,7 +358,7 @@ ido_progress_menu_item_new_from_model (GMenuItem * menu_item, } g_assert (n <= G_N_ELEMENTS (parameters)); - ido_menu_item = g_object_newv (IDO_BASIC_MENU_ITEM_TYPE, n, parameters); + ido_menu_item = g_object_newv (IDO_TYPE_BASIC_MENU_ITEM, n, parameters); for (i=0; i Date: Thu, 25 Jul 2013 15:53:36 -0500 Subject: subclass IdoLocationMenuItem from IdoBasicMenuItem --- example/menus.c | 2 +- src/idolocationmenuitem.c | 89 +++++------------------------------------------ src/idolocationmenuitem.h | 8 ++--- 3 files changed, 13 insertions(+), 86 deletions(-) diff --git a/example/menus.c b/example/menus.c index 66bc2f2..ab070ac 100644 --- a/example/menus.c +++ b/example/menus.c @@ -138,7 +138,7 @@ main (int argc, char *argv[]) for (i=0; ipriv; if (p->format && *p->format) { GTimeZone * tz; GDateTime * now; - char * str; 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); - gtk_label_set_text (GTK_LABEL(p->timestamp_label), str); + str = g_date_time_format (now, p->format); - g_free (str); g_date_time_unref (now); g_time_zone_unref (tz); } else { - gtk_label_set_text (GTK_LABEL(p->timestamp_label), ""); + str = NULL; } + + ido_basic_menu_item_set_secondary_text (IDO_BASIC_MENU_ITEM(self), str); + + g_free (str); } static void @@ -181,10 +178,6 @@ my_get_property (GObject * o, switch (property_id) { - case PROP_NAME: - g_value_set_string (value, p->name); - break; - case PROP_TIMEZONE: g_value_set_string (value, p->timezone); break; @@ -209,10 +202,6 @@ my_set_property (GObject * o, switch (property_id) { - case PROP_NAME: - ido_location_menu_item_set_name (self, g_value_get_string (value)); - break; - case PROP_TIMEZONE: ido_location_menu_item_set_timezone (self, g_value_get_string (value)); break; @@ -242,7 +231,6 @@ my_finalize (GObject * object) priv_t * p = self->priv; g_free (p->format); - g_free (p->name); g_free (p->timezone); G_OBJECT_CLASS (ido_location_menu_item_parent_class)->finalize (object); @@ -269,13 +257,6 @@ ido_location_menu_item_class_init (IdoLocationMenuItemClass *klass) | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS; - properties[PROP_NAME] = g_param_spec_string ( - "name", - "The location's name", - "The name to display; eg, 'Oklahoma City'", - "Location", - prop_flags); - properties[PROP_TIMEZONE] = g_param_spec_string ( "timezone", "timezone identifier", @@ -296,43 +277,11 @@ ido_location_menu_item_class_init (IdoLocationMenuItemClass *klass) static void ido_location_menu_item_init (IdoLocationMenuItem *self) { - priv_t * p; - GtkWidget * w; - GtkGrid * grid; - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, IDO_LOCATION_MENU_ITEM_TYPE, IdoLocationMenuItemPrivate); - - p = self->priv; - - p->name_label = gtk_label_new (NULL); - gtk_misc_set_alignment (GTK_MISC(p->name_label), 0.0, 0.5); - - p->timestamp_label = gtk_label_new (NULL); - gtk_misc_set_alignment (GTK_MISC(p->timestamp_label), 1.0, 0.5); - - w = gtk_grid_new (); - grid = GTK_GRID (w); - gtk_grid_attach (grid, p->name_label, 0, 0, 1, 1); - gtk_grid_attach (grid, p->timestamp_label, 1, 0, 1, 1); - g_object_set (p->name_label, - "halign", GTK_ALIGN_START, - "hexpand", TRUE, - "margin-right", 6, - "valign", GTK_ALIGN_CENTER, - NULL); - g_object_set (p->timestamp_label, - "halign", GTK_ALIGN_END, - "hexpand", FALSE, - "valign", GTK_ALIGN_CENTER, - NULL); - - gtk_widget_show_all (w); - gtk_container_add (GTK_CONTAINER (self), w); } - /*** **** Public API ***/ @@ -344,26 +293,6 @@ ido_location_menu_item_new (void) return GTK_WIDGET (g_object_new (IDO_LOCATION_MENU_ITEM_TYPE, NULL)); } -/** - * ido_location_menu_item_set_name: - * @name: human-readable name, such as a city (eg: "Oklahoma City") - * - * Sets this location's name, for display in the menuitem's primary label. - */ -void -ido_location_menu_item_set_name (IdoLocationMenuItem * self, - const char * name) -{ - priv_t * p; - - g_return_if_fail (IDO_IS_LOCATION_MENU_ITEM (self)); - p = self->priv; - - g_free (p->name); - p->name = g_strdup (name); - gtk_label_set_text (GTK_LABEL(p->name_label), p->name); -} - /** * ido_location_menu_item_set_timezone: * @timezone: timezone identifier (eg: "America/Chicago") @@ -436,7 +365,7 @@ ido_location_menu_item_new_from_model (GMenuItem * menu_item, if (g_menu_item_get_attribute (menu_item, "label", "s", &str)) { - GParameter p = { "name", G_VALUE_INIT }; + GParameter p = { "text", G_VALUE_INIT }; g_value_init (&p.value, G_TYPE_STRING); g_value_take_string (&p.value, str); parameters[n++] = p; diff --git a/src/idolocationmenuitem.h b/src/idolocationmenuitem.h index 08a97af..53fe063 100644 --- a/src/idolocationmenuitem.h +++ b/src/idolocationmenuitem.h @@ -21,6 +21,7 @@ #define __IDO_LOCATION_MENU_ITEM_H__ #include +#include "idobasicmenuitem.h" G_BEGIN_DECLS @@ -34,7 +35,7 @@ typedef struct _IdoLocationMenuItemPrivate IdoLocationMenuItemPrivate; struct _IdoLocationMenuItemClass { - GtkMenuItemClass parent_class; + IdoBasicMenuItemClass parent_class; }; /** @@ -46,7 +47,7 @@ struct _IdoLocationMenuItemClass struct _IdoLocationMenuItem { /*< private >*/ - GtkMenuItem parent; + IdoBasicMenuItem parent; IdoLocationMenuItemPrivate * priv; }; @@ -58,9 +59,6 @@ GtkWidget * ido_location_menu_item_new (void); GtkMenuItem * ido_location_menu_item_new_from_model (GMenuItem * menuitem, GActionGroup * actions); -void ido_location_menu_item_set_name (IdoLocationMenuItem * menuitem, - const char * name); - void ido_location_menu_item_set_timezone (IdoLocationMenuItem * menuitem, const char * timezone); -- cgit v1.2.3 From b4cc30dc8bf0b36f73417050e4e8c84554715b00 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 25 Jul 2013 16:22:45 -0500 Subject: add a 6px margin between the icon and primary text iff the icon is visible --- src/idobasicmenuitem.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/idobasicmenuitem.c b/src/idobasicmenuitem.c index a1eadbf..f07cc14 100644 --- a/src/idobasicmenuitem.c +++ b/src/idobasicmenuitem.c @@ -203,6 +203,12 @@ ido_basic_menu_item_init (IdoBasicMenuItem *self) gtk_grid_attach (grid, p->image, 0, 0, 1, 1); gtk_grid_attach (grid, p->label, 1, 0, 1, 1); gtk_grid_attach (grid, p->secondary_label, 2, 0, 1, 1); + g_object_set (p->image, + "halign", GTK_ALIGN_START, + "hexpand", FALSE, + "valign", GTK_ALIGN_CENTER, + "margin-right", 6, + NULL); g_object_set (p->label, "halign", GTK_ALIGN_START, "hexpand", TRUE, -- cgit v1.2.3 From 3565dadf6d58334f47e8d4eaabbc188a92c0de72 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 25 Jul 2013 16:24:49 -0500 Subject: subclass IdoAppointmentMenuItem from IdoBasicMenuItem --- src/idoappointmentmenuitem.c | 70 ++++---------------------------------------- src/idoappointmentmenuitem.h | 8 ++--- 2 files changed, 9 insertions(+), 69 deletions(-) diff --git a/src/idoappointmentmenuitem.c b/src/idoappointmentmenuitem.c index 734b038..e5bea24 100644 --- a/src/idoappointmentmenuitem.c +++ b/src/idoappointmentmenuitem.c @@ -33,7 +33,6 @@ enum { PROP_0, PROP_COLOR, - PROP_SUMMARY, PROP_TIME, PROP_FORMAT, PROP_LAST @@ -47,17 +46,13 @@ struct _IdoAppointmentMenuItemPrivate char * format; char * color_string; GDateTime * date_time; - - GtkWidget * color_image; - GtkWidget * summary_label; - GtkWidget * timestamp_label; }; typedef IdoAppointmentMenuItemPrivate priv_t; G_DEFINE_TYPE (IdoAppointmentMenuItem, ido_appointment_menu_item, - GTK_TYPE_MENU_ITEM); + IDO_TYPE_BASIC_MENU_ITEM); /*** **** GObject Virtual Functions @@ -78,10 +73,6 @@ my_get_property (GObject * o, g_value_set_string (v, p->color_string); break; - case PROP_SUMMARY: - g_value_set_string (v, p->summary); - break; - case PROP_FORMAT: g_value_set_string (v, p->format); break; @@ -110,10 +101,6 @@ my_set_property (GObject * o, ido_appointment_menu_item_set_color (self, g_value_get_string (v)); break; - case PROP_SUMMARY: - ido_appointment_menu_item_set_summary (self, g_value_get_string (v)); - break; - case PROP_FORMAT: ido_appointment_menu_item_set_format (self, g_value_get_string (v)); break; @@ -180,13 +167,6 @@ ido_appointment_menu_item_class_init (IdoAppointmentMenuItemClass *klass) "White", prop_flags); - properties[PROP_SUMMARY] = g_param_spec_string ( - "summary", - "Summary", - "Brief description of the appointment", - "", - prop_flags); - properties[PROP_TIME] = g_param_spec_int64 ( "time", "Time", @@ -207,29 +187,10 @@ ido_appointment_menu_item_class_init (IdoAppointmentMenuItemClass *klass) static void ido_appointment_menu_item_init (IdoAppointmentMenuItem *self) { - priv_t * p; - GtkBox * box; - GtkWidget * w; - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, IDO_APPOINTMENT_MENU_ITEM_TYPE, IdoAppointmentMenuItemPrivate); - p = self->priv; - - p->color_image = gtk_image_new (); - p->summary_label = gtk_label_new (NULL); - p->timestamp_label = gtk_label_new (NULL); - w = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3); - - gtk_misc_set_alignment (GTK_MISC(p->timestamp_label), 1.0, 0.5); - box = GTK_BOX (w); - gtk_box_pack_start (box, p->color_image, FALSE, FALSE, 2); - gtk_box_pack_start (box, p->summary_label, FALSE, FALSE, 2); - gtk_box_pack_end (box, p->timestamp_label, FALSE, FALSE, 5); - - gtk_widget_show_all (w); - gtk_container_add (GTK_CONTAINER (self), w); } /*** @@ -289,7 +250,7 @@ update_timestamp_label (IdoAppointmentMenuItem * self) else str = NULL; - gtk_label_set_text (GTK_LABEL(p->timestamp_label), str); + ido_basic_menu_item_set_secondary_text (IDO_BASIC_MENU_ITEM (self), str); g_free (str); } @@ -325,31 +286,12 @@ ido_appointment_menu_item_set_color (IdoAppointmentMenuItem * self, g_free (p->color_string); p->color_string = g_strdup (color_string); + pixbuf = create_color_icon_pixbuf (p->color_string); - gtk_image_set_from_pixbuf (GTK_IMAGE(p->color_image), pixbuf); + ido_basic_menu_item_set_icon (IDO_BASIC_MENU_ITEM(self), G_ICON(pixbuf)); g_object_unref (G_OBJECT(pixbuf)); } -/** - * ido_appointment_menu_item_set_summary: - * @summary: short string describing the appointment. - * - * Set the menuitem's primary label with a short description of the appointment - */ -void -ido_appointment_menu_item_set_summary (IdoAppointmentMenuItem * self, - const char * summary) -{ - priv_t * p; - - g_return_if_fail (IDO_IS_APPOINTMENT_MENU_ITEM (self)); - p = self->priv; - - g_free (p->summary); - p->summary = g_strdup (summary); - gtk_label_set_text (GTK_LABEL(p->summary_label), p->summary); -} - /** * ido_appointment_menu_item_set_time: * @time: the time to be rendered in the appointment's timestamp label. @@ -420,9 +362,9 @@ ido_appointment_menu_item_new_from_model (GMenuItem * menu_item, n = 0; - if (g_menu_item_get_attribute (menu_item, "label", "s", &str)) + if (g_menu_item_get_attribute (menu_item, G_MENU_ATTRIBUTE_LABEL, "s", &str)) { - GParameter p = { "summary", G_VALUE_INIT }; + GParameter p = { "text", G_VALUE_INIT }; g_value_init (&p.value, G_TYPE_STRING); g_value_take_string (&p.value, str); parameters[n++] = p; diff --git a/src/idoappointmentmenuitem.h b/src/idoappointmentmenuitem.h index 3a8c853..5317253 100644 --- a/src/idoappointmentmenuitem.h +++ b/src/idoappointmentmenuitem.h @@ -23,6 +23,7 @@ #include /* time_t */ #include +#include "idobasicmenuitem.h" G_BEGIN_DECLS @@ -36,7 +37,7 @@ typedef struct _IdoAppointmentMenuItemPrivate IdoAppointmentMenuItemPrivate; struct _IdoAppointmentMenuItemClass { - GtkMenuItemClass parent_class; + IdoBasicMenuItemClass parent_class; }; /** @@ -49,7 +50,7 @@ struct _IdoAppointmentMenuItemClass struct _IdoAppointmentMenuItem { /*< private >*/ - GtkMenuItem parent; + IdoBasicMenuItem parent; IdoAppointmentMenuItemPrivate * priv; }; @@ -61,9 +62,6 @@ GtkWidget * ido_appointment_menu_item_new (void); GtkMenuItem * ido_appointment_menu_item_new_from_model (GMenuItem * menuitem, GActionGroup * actions); -void ido_appointment_menu_item_set_summary (IdoAppointmentMenuItem * menuitem, - const char * summary); - void ido_appointment_menu_item_set_time (IdoAppointmentMenuItem * menuitem, time_t time); -- cgit v1.2.3 From 897843772fb6219f0cd723cd6ffddaaccd2365a5 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 25 Jul 2013 18:22:08 -0500 Subject: add IdoTimeStampMenuItem, a base class for appointments, locations, and alarms --- debian/libido3-0.1-0.symbols | 5 + src/idotimestampmenuitem.c | 253 +++++++++++++++++++++++++++++++++++++++++++ src/idotimestampmenuitem.h | 72 ++++++++++++ 3 files changed, 330 insertions(+) create mode 100644 src/idotimestampmenuitem.c create mode 100644 src/idotimestampmenuitem.h diff --git a/debian/libido3-0.1-0.symbols b/debian/libido3-0.1-0.symbols index d2c427d..93aad90 100644 --- a/debian/libido3-0.1-0.symbols +++ b/debian/libido3-0.1-0.symbols @@ -89,6 +89,11 @@ libido3-0.1.so.0 libido3-0.1-0 #MINVER# ido_timeline_set_progress@Base 0.1.10 ido_timeline_set_screen@Base 0.1.8 ido_timeline_start@Base 0.1.8 + ido_time_stamp_menu_item_get_type@Base 0replaceme + ido_time_stamp_menu_item_new@Base 0replaceme + ido_time_stamp_menu_item_set_format@Base 0replaceme + ido_time_stamp_menu_item_get_format@Base 0replaceme + ido_time_stamp_menu_item_set_date_time@Base 0replaceme ido_user_menu_item_get_type@Base 13.10.0daily13.06.19 ido_user_menu_item_new@Base 13.10.0daily13.06.19 ido_user_menu_item_new_from_model@Base 13.10.0daily13.06.19 diff --git a/src/idotimestampmenuitem.c b/src/idotimestampmenuitem.c new file mode 100644 index 0000000..0d33deb --- /dev/null +++ b/src/idotimestampmenuitem.c @@ -0,0 +1,253 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * Authors: + * Charles Kerr + * Ted Gould + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +#include /* strstr() */ + +#include + +#include "idoactionhelper.h" +#include "idotimestampmenuitem.h" + +enum +{ + PROP_0, + PROP_FORMAT, + PROP_DATE_TIME, + PROP_LAST +}; + +static GParamSpec *properties[PROP_LAST]; + +struct _IdoTimeStampMenuItemPrivate +{ + char * format; + GDateTime * date_time; +}; + +typedef IdoTimeStampMenuItemPrivate priv_t; + +G_DEFINE_TYPE (IdoTimeStampMenuItem, + ido_time_stamp_menu_item, + IDO_TYPE_BASIC_MENU_ITEM); + +/*** +**** GObject Virtual Functions +***/ + +static void +my_get_property (GObject * o, + guint property_id, + GValue * v, + GParamSpec * pspec) +{ + IdoTimeStampMenuItem * self = IDO_TIME_STAMP_MENU_ITEM (o); + priv_t * p = self->priv; + + switch (property_id) + { + case PROP_FORMAT: + g_value_set_string (v, p->format); + break; + + case PROP_DATE_TIME: + g_value_set_boxed (v, p->date_time); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); + break; + } +} + +static void +my_set_property (GObject * o, + guint property_id, + const GValue * v, + GParamSpec * pspec) +{ + IdoTimeStampMenuItem * self = IDO_TIME_STAMP_MENU_ITEM (o); + + switch (property_id) + { + case PROP_FORMAT: + ido_time_stamp_menu_item_set_format (self, g_value_get_string (v)); + break; + + case PROP_DATE_TIME: + ido_time_stamp_menu_item_set_date_time (self, g_value_get_boxed (v)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); + break; + } +} + +static void +my_dispose (GObject * object) +{ + IdoTimeStampMenuItem * self = IDO_TIME_STAMP_MENU_ITEM (object); + priv_t * p = self->priv; + + g_clear_pointer (&p->date_time, g_date_time_unref); + + G_OBJECT_CLASS (ido_time_stamp_menu_item_parent_class)->dispose (object); +} + +static void +my_finalize (GObject * object) +{ + IdoTimeStampMenuItem * self = IDO_TIME_STAMP_MENU_ITEM (object); + priv_t * p = self->priv; + + g_free (p->format); + + G_OBJECT_CLASS (ido_time_stamp_menu_item_parent_class)->finalize (object); +} + +/*** +**** Instantiation +***/ + +static void +ido_time_stamp_menu_item_class_init (IdoTimeStampMenuItemClass *klass) +{ + GParamFlags prop_flags; + GObjectClass * gobject_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (IdoTimeStampMenuItemPrivate)); + + gobject_class->get_property = my_get_property; + gobject_class->set_property = my_set_property; + gobject_class->dispose = my_dispose; + gobject_class->finalize = my_finalize; + + prop_flags = G_PARAM_CONSTRUCT + | G_PARAM_READWRITE + | G_PARAM_STATIC_STRINGS; + + properties[PROP_FORMAT] = g_param_spec_string ( + "format", + "strftime format", + "strftime-style format string for the timestamp", + "%F %T", + prop_flags); + + properties[PROP_DATE_TIME] = g_param_spec_boxed ( + "date-time", + "Date-Time", + "GDateTime specifying the time to render", + G_TYPE_DATE_TIME, + prop_flags); + + g_object_class_install_properties (gobject_class, PROP_LAST, properties); +} + +static void +ido_time_stamp_menu_item_init (IdoTimeStampMenuItem *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + IDO_TYPE_TIME_STAMP_MENU_ITEM, + IdoTimeStampMenuItemPrivate); + +} + +static void +update_timestamp_label (IdoTimeStampMenuItem * self) +{ + char * str; + priv_t * p = self->priv; + + if (p->date_time && p->format) + str = g_date_time_format (p->date_time, p->format); + else + str = NULL; + + ido_basic_menu_item_set_secondary_text (IDO_BASIC_MENU_ITEM (self), str); + g_free (str); +} + +/*** +**** Public API +***/ + +/* create a new IdoTimeStampMenuItem */ +GtkWidget * +ido_time_stamp_menu_item_new (void) +{ + return GTK_WIDGET (g_object_new (IDO_TYPE_TIME_STAMP_MENU_ITEM, NULL)); +} + +/** + * ido_time_stamp_menu_item_set_time: + * @time: the time to be rendered in the appointment's timestamp label. + * + * Set the time that will be displayed in the menuitem's + * right-justified timestamp label + */ +void +ido_time_stamp_menu_item_set_date_time (IdoTimeStampMenuItem * self, + GDateTime * date_time) +{ + priv_t * p; + + g_return_if_fail (IDO_IS_TIME_STAMP_MENU_ITEM (self)); + p = self->priv; + + g_clear_pointer (&p->date_time, g_date_time_unref); + if (date_time != NULL) + p->date_time = g_date_time_ref (date_time); + update_timestamp_label (self); +} + +/** + * ido_time_stamp_menu_item_set_format: + * @format: the format string used when showing the appointment's time + * + * Set the format string for rendering the appointment's time + * in its right-justified secondary label. + * + * See strfrtime(3) for more information on the format string. + */ +void +ido_time_stamp_menu_item_set_format (IdoTimeStampMenuItem * self, + const char * strftime_fmt) +{ + priv_t * p; + + g_return_if_fail (IDO_IS_TIME_STAMP_MENU_ITEM (self)); + p = self->priv; + + g_free (p->format); + p->format = g_strdup (strftime_fmt); + update_timestamp_label (self); +} + +const gchar * +ido_time_stamp_menu_item_get_format (IdoTimeStampMenuItem * self) +{ + g_return_val_if_fail (IDO_IS_TIME_STAMP_MENU_ITEM (self), NULL); + + return self->priv->format; +} diff --git a/src/idotimestampmenuitem.h b/src/idotimestampmenuitem.h new file mode 100644 index 0000000..5847ba8 --- /dev/null +++ b/src/idotimestampmenuitem.h @@ -0,0 +1,72 @@ +/** + * Copyright 2013 Canonical Ltd. + * + * Authors: + * Charles Kerr + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef __IDO_TIME_STAMP_MENU_ITEM_H__ +#define __IDO_TIME_STAMP_MENU_ITEM_H__ + +#include +#include "idobasicmenuitem.h" + +G_BEGIN_DECLS + +#define IDO_TYPE_TIME_STAMP_MENU_ITEM (ido_time_stamp_menu_item_get_type ()) +#define IDO_TIME_STAMP_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_TYPE_TIME_STAMP_MENU_ITEM, IdoTimeStampMenuItem)) +#define IDO_IS_TIME_STAMP_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_TYPE_TIME_STAMP_MENU_ITEM)) + +typedef struct _IdoTimeStampMenuItem IdoTimeStampMenuItem; +typedef struct _IdoTimeStampMenuItemClass IdoTimeStampMenuItemClass; +typedef struct _IdoTimeStampMenuItemPrivate IdoTimeStampMenuItemPrivate; + +struct _IdoTimeStampMenuItemClass +{ + IdoBasicMenuItemClass parent_class; +}; + +/** + * A menuitem that contains a left-aligned optional icon and label + * and a right-aligned secondary label showing the specified time + * in the specified format. + * + * Used by IdoLocationMenuItem, IdoAppointmentMenuItem, and IdoAlarmMenuItem. + */ +struct _IdoTimeStampMenuItem +{ + /*< private >*/ + IdoBasicMenuItem parent; + IdoTimeStampMenuItemPrivate * priv; +}; + + +GType ido_time_stamp_menu_item_get_type (void) G_GNUC_CONST; + +GtkWidget * ido_time_stamp_menu_item_new (void); + +void ido_time_stamp_menu_item_set_date_time (IdoTimeStampMenuItem * menuitem, + GDateTime * date_time); + +void ido_time_stamp_menu_item_set_format (IdoTimeStampMenuItem * menuitem, + const char * strftime_fmt); + +const char * ido_time_stamp_menu_item_get_format (IdoTimeStampMenuItem * menuitem); + + + +G_END_DECLS + +#endif -- cgit v1.2.3 From c823c870af34a67acf9ec718b96559afc9886afa Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 25 Jul 2013 18:34:23 -0500 Subject: implement IdoAppointmentMenuItem as a specialization of IdoTimeStampMenuItem --- src/idoappointmentmenuitem.c | 298 +++---------------------------------------- src/idoappointmentmenuitem.h | 45 ------- 2 files changed, 16 insertions(+), 327 deletions(-) diff --git a/src/idoappointmentmenuitem.c b/src/idoappointmentmenuitem.c index e5bea24..b383729 100644 --- a/src/idoappointmentmenuitem.c +++ b/src/idoappointmentmenuitem.c @@ -22,182 +22,12 @@ #include "config.h" #endif -#include /* strstr() */ - #include #include "idoactionhelper.h" -#include "idoappointmentmenuitem.h" - -enum -{ - PROP_0, - PROP_COLOR, - PROP_TIME, - PROP_FORMAT, - PROP_LAST -}; - -static GParamSpec *properties[PROP_LAST]; - -struct _IdoAppointmentMenuItemPrivate -{ - char * summary; - char * format; - char * color_string; - GDateTime * date_time; -}; - -typedef IdoAppointmentMenuItemPrivate priv_t; - -G_DEFINE_TYPE (IdoAppointmentMenuItem, - ido_appointment_menu_item, - IDO_TYPE_BASIC_MENU_ITEM); - -/*** -**** GObject Virtual Functions -***/ - -static void -my_get_property (GObject * o, - guint property_id, - GValue * v, - GParamSpec * pspec) -{ - IdoAppointmentMenuItem * self = IDO_APPOINTMENT_MENU_ITEM (o); - priv_t * p = self->priv; - - switch (property_id) - { - case PROP_COLOR: - g_value_set_string (v, p->color_string); - break; - - case PROP_FORMAT: - g_value_set_string (v, p->format); - break; - - case PROP_TIME: - g_value_set_uint64 (v, g_date_time_to_unix (p->date_time)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); - break; - } -} - -static void -my_set_property (GObject * o, - guint property_id, - const GValue * v, - GParamSpec * pspec) -{ - IdoAppointmentMenuItem * self = IDO_APPOINTMENT_MENU_ITEM (o); - - switch (property_id) - { - case PROP_COLOR: - ido_appointment_menu_item_set_color (self, g_value_get_string (v)); - break; - - case PROP_FORMAT: - ido_appointment_menu_item_set_format (self, g_value_get_string (v)); - break; - - case PROP_TIME: - ido_appointment_menu_item_set_time (self, g_value_get_int64 (v)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); - break; - } -} - -static void -my_dispose (GObject * object) -{ - IdoAppointmentMenuItem * self = IDO_APPOINTMENT_MENU_ITEM (object); - priv_t * p = self->priv; - - g_clear_pointer (&p->date_time, g_date_time_unref); - - G_OBJECT_CLASS (ido_appointment_menu_item_parent_class)->dispose (object); -} - -static void -my_finalize (GObject * object) -{ - IdoAppointmentMenuItem * self = IDO_APPOINTMENT_MENU_ITEM (object); - priv_t * p = self->priv; - - g_free (p->color_string); - g_free (p->summary); - g_free (p->format); - - G_OBJECT_CLASS (ido_appointment_menu_item_parent_class)->finalize (object); -} - -/*** -**** Instantiation -***/ - -static void -ido_appointment_menu_item_class_init (IdoAppointmentMenuItemClass *klass) -{ - GParamFlags prop_flags; - GObjectClass * gobject_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (IdoAppointmentMenuItemPrivate)); - - gobject_class->get_property = my_get_property; - gobject_class->set_property = my_set_property; - gobject_class->dispose = my_dispose; - gobject_class->finalize = my_finalize; - - prop_flags = G_PARAM_CONSTRUCT - | G_PARAM_READWRITE - | G_PARAM_STATIC_STRINGS; - - properties[PROP_COLOR] = g_param_spec_string ( - "color", - "Color", - "Color coding for the appointment's type", - "White", - prop_flags); - - properties[PROP_TIME] = g_param_spec_int64 ( - "time", - "Time", - "unix time_t specifying when the appointment begins", - 0, G_MAXINT64, 0, - prop_flags); - - properties[PROP_FORMAT] = g_param_spec_string ( - "format", - "strftime format", - "strftime-style format string for the timestamp", - "%F %T", - prop_flags); +#include "idotimestampmenuitem.h" - g_object_class_install_properties (gobject_class, PROP_LAST, properties); -} - -static void -ido_appointment_menu_item_init (IdoAppointmentMenuItem *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - IDO_APPOINTMENT_MENU_ITEM_TYPE, - IdoAppointmentMenuItemPrivate); - -} - -/*** -**** -***/ - -/* creates a menu-sized pixbuf filled with specified color */ +/* create a menu-sized pixbuf filled with specified color */ static GdkPixbuf * create_color_icon_pixbuf (const char * color_spec) { @@ -239,103 +69,6 @@ create_color_icon_pixbuf (const char * color_spec) return pixbuf; } -static void -update_timestamp_label (IdoAppointmentMenuItem * self) -{ - char * str; - priv_t * p = self->priv; - - if (p->date_time && p->format) - str = g_date_time_format (p->date_time, p->format); - else - str = NULL; - - ido_basic_menu_item_set_secondary_text (IDO_BASIC_MENU_ITEM (self), str); - g_free (str); -} - -/*** -**** Public API -***/ - -/* create a new IdoAppointmentMenuItem */ -GtkWidget * -ido_appointment_menu_item_new (void) -{ - return GTK_WIDGET (g_object_new (IDO_APPOINTMENT_MENU_ITEM_TYPE, NULL)); -} - -/** - * ido_appointment_menu_item_set_color: - * @color: parseable color string - * - * When this is set, the menuitem will include an icon with this color. - * - * These colors can be set in the end user's calendar app as a quick visual cue - * to show what kind of appointment this is. - */ -void -ido_appointment_menu_item_set_color (IdoAppointmentMenuItem * self, - const char * color_string) -{ - priv_t * p; - GdkPixbuf * pixbuf; - - g_return_if_fail (IDO_IS_APPOINTMENT_MENU_ITEM (self)); - p = self->priv; - - g_free (p->color_string); - p->color_string = g_strdup (color_string); - - pixbuf = create_color_icon_pixbuf (p->color_string); - ido_basic_menu_item_set_icon (IDO_BASIC_MENU_ITEM(self), G_ICON(pixbuf)); - g_object_unref (G_OBJECT(pixbuf)); -} - -/** - * ido_appointment_menu_item_set_time: - * @time: the time to be rendered in the appointment's timestamp label. - * - * Set the time that will be displayed in the menuitem's - * right-justified timestamp label - */ -void -ido_appointment_menu_item_set_time (IdoAppointmentMenuItem * self, - time_t time) -{ - priv_t * p; - - g_return_if_fail (IDO_IS_APPOINTMENT_MENU_ITEM (self)); - p = self->priv; - - g_clear_pointer (&p->date_time, g_date_time_unref); - p->date_time = g_date_time_new_from_unix_local (time); - update_timestamp_label (self); -} - -/** - * ido_appointment_menu_item_set_format: - * @format: the format string used when showing the appointment's time - * - * Set the format string for rendering the appointment's time - * in its right-justified secondary label. - * - * See strfrtime(3) for more information on the format string. - */ -void -ido_appointment_menu_item_set_format (IdoAppointmentMenuItem * self, - const char * strftime_fmt) -{ - priv_t * p; - - g_return_if_fail (IDO_IS_APPOINTMENT_MENU_ITEM (self)); - p = self->priv; - - g_free (p->format); - p->format = g_strdup (strftime_fmt); - update_timestamp_label (self); -} - /** * ido_appointment_menu_item_new_from_model: * @menu_item: the corresponding menuitem @@ -355,10 +88,10 @@ ido_appointment_menu_item_new_from_model (GMenuItem * menu_item, guint n; gint64 i64; gchar * str; - IdoAppointmentMenuItem * ido_appointment; + IdoBasicMenuItem * ido_menu_item; GParameter parameters[8]; - /* create the ido_appointment */ + /* create the ido_menu_item */ n = 0; @@ -372,10 +105,11 @@ ido_appointment_menu_item_new_from_model (GMenuItem * menu_item, if (g_menu_item_get_attribute (menu_item, "x-canonical-color", "s", &str)) { - GParameter p = { "color", G_VALUE_INIT }; - g_value_init (&p.value, G_TYPE_STRING); - g_value_take_string (&p.value, str); + GParameter p = { "icon", G_VALUE_INIT }; + g_value_init (&p.value, G_TYPE_OBJECT); + g_value_take_object (&p.value, create_color_icon_pixbuf (str)); parameters[n++] = p; + g_free (str); } if (g_menu_item_get_attribute (menu_item, "x-canonical-time-format", "s", &str)) @@ -388,14 +122,14 @@ ido_appointment_menu_item_new_from_model (GMenuItem * menu_item, if (g_menu_item_get_attribute (menu_item, "x-canonical-time", "x", &i64)) { - GParameter p = { "time", G_VALUE_INIT }; - g_value_init (&p.value, G_TYPE_INT64); - g_value_set_int64 (&p.value, i64); + GParameter p = { "date-time", G_VALUE_INIT }; + g_value_init (&p.value, G_TYPE_DATE_TIME); + g_value_take_boxed (&p.value, g_date_time_new_from_unix_local (i64)); parameters[n++] = p; } g_assert (n <= G_N_ELEMENTS (parameters)); - ido_appointment = g_object_newv (IDO_APPOINTMENT_MENU_ITEM_TYPE, n, parameters); + ido_menu_item = g_object_newv (IDO_TYPE_TIME_STAMP_MENU_ITEM, n, parameters); for (i=0; i /* time_t */ - #include -#include "idobasicmenuitem.h" G_BEGIN_DECLS -#define IDO_APPOINTMENT_MENU_ITEM_TYPE (ido_appointment_menu_item_get_type ()) -#define IDO_APPOINTMENT_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_APPOINTMENT_MENU_ITEM_TYPE, IdoAppointmentMenuItem)) -#define IDO_IS_APPOINTMENT_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_APPOINTMENT_MENU_ITEM_TYPE)) - -typedef struct _IdoAppointmentMenuItem IdoAppointmentMenuItem; -typedef struct _IdoAppointmentMenuItemClass IdoAppointmentMenuItemClass; -typedef struct _IdoAppointmentMenuItemPrivate IdoAppointmentMenuItemPrivate; - -struct _IdoAppointmentMenuItemClass -{ - IdoBasicMenuItemClass parent_class; -}; - -/** - * A menuitem that indicates a appointment. - * - * It contains a color-coded icon to indicate the appointment type, - * a primary label showing the appointment summary, - * and a right-justified secondary label telling when the appointment begins. - */ -struct _IdoAppointmentMenuItem -{ - /*< private >*/ - IdoBasicMenuItem parent; - IdoAppointmentMenuItemPrivate * priv; -}; - - -GType ido_appointment_menu_item_get_type (void) G_GNUC_CONST; - -GtkWidget * ido_appointment_menu_item_new (void); - GtkMenuItem * ido_appointment_menu_item_new_from_model (GMenuItem * menuitem, GActionGroup * actions); -void ido_appointment_menu_item_set_time (IdoAppointmentMenuItem * menuitem, - time_t time); - -void ido_appointment_menu_item_set_color (IdoAppointmentMenuItem * menuitem, - const char * color_str); - -void ido_appointment_menu_item_set_format (IdoAppointmentMenuItem * menuitem, - const char * strftime_fmt); - - G_END_DECLS #endif -- cgit v1.2.3 From 1b7166676eb42a26a8547e795064631edd0653df Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 25 Jul 2013 18:53:48 -0500 Subject: add support for com.canonical.indicator.alarm menuitems. --- debian/libido3-0.1-0.symbols | 7 +-- src/Makefile.am | 4 ++ src/idoalarmmenuitem.c | 116 +++++++++++++++++++++++++++++++++++++++++++ src/idoalarmmenuitem.h | 32 ++++++++++++ src/idomenuitemfactory.c | 4 ++ 5 files changed, 157 insertions(+), 6 deletions(-) create mode 100644 src/idoalarmmenuitem.c create mode 100644 src/idoalarmmenuitem.h diff --git a/debian/libido3-0.1-0.symbols b/debian/libido3-0.1-0.symbols index 93aad90..332f518 100644 --- a/debian/libido3-0.1-0.symbols +++ b/debian/libido3-0.1-0.symbols @@ -5,13 +5,8 @@ libido3-0.1.so.0 libido3-0.1-0 #MINVER# ido_action_helper_get_type@Base 13.10.0daily13.06.19 ido_action_helper_get_widget@Base 13.10.0daily13.06.19 ido_action_helper_new@Base 13.10.0daily13.06.19 - ido_appointment_menu_item_get_type@Base 13.10.0daily13.06.19 - ido_appointment_menu_item_new@Base 13.10.0daily13.06.19 + ido_alarm_menu_item_new_from_model@Base 0replaceme ido_appointment_menu_item_new_from_model@Base 13.10.0daily13.06.19 - ido_appointment_menu_item_set_color@Base 13.10.0daily13.06.19 - ido_appointment_menu_item_set_format@Base 13.10.0daily13.06.19 - ido_appointment_menu_item_set_summary@Base 13.10.0daily13.06.19 - ido_appointment_menu_item_set_time@Base 13.10.0daily13.06.19 ido_basic_menu_item_get_type@Base 0replaceme ido_basic_menu_item_new@Base 0replaceme ido_basic_menu_item_set_icon@Base 0replaceme diff --git a/src/Makefile.am b/src/Makefile.am index a4ca6fd..725652f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,6 +11,7 @@ stamp_files = \ idotypebuiltins.c sources_h = \ + idoalarmmenuitem.h \ idocalendarmenuitem.h \ idoentrymenuitem.h \ idomessagedialog.h \ @@ -20,6 +21,7 @@ sources_h = \ idousermenuitem.h \ idoappointmentmenuitem.h \ idobasicmenuitem.h \ + idotimestampmenuitem.h \ idolocationmenuitem.h \ idotimeline.h \ libido.h \ @@ -69,6 +71,7 @@ libido_0_1_la_SOURCES = \ libido.c \ idotypebuiltins.c \ idocalendarmenuitem.c \ + idoalarmmenuitem.c \ idoentrymenuitem.c \ idomessagedialog.c \ idorange.c \ @@ -82,6 +85,7 @@ libido_0_1_la_SOURCES = \ idoplaybackmenuitem.c \ idoappointmentmenuitem.c \ idobasicmenuitem.c \ + idotimestampmenuitem.c \ idolocationmenuitem.c libido3_0_1_la_SOURCES = $(libido_0_1_la_SOURCES) diff --git a/src/idoalarmmenuitem.c b/src/idoalarmmenuitem.c new file mode 100644 index 0000000..1c53836 --- /dev/null +++ b/src/idoalarmmenuitem.c @@ -0,0 +1,116 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * Authors: + * Charles Kerr + * Ted Gould + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +#include + +#include "idoactionhelper.h" +#include "idotimestampmenuitem.h" + +/** + * ido_alarm_menu_item_new_from_model: + * @menu_item: the corresponding menuitem + * @actions: action group to tell when this GtkMenuItem is activated + * + * 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. + */ +GtkMenuItem * +ido_alarm_menu_item_new_from_model (GMenuItem * menu_item, + GActionGroup * actions) +{ + guint i; + guint n; + gint64 i64; + gchar * str; + IdoBasicMenuItem * ido_menu_item; + GParameter parameters[8]; + + /* create the ido_menu_item */ + + n = 0; + + if (g_menu_item_get_attribute (menu_item, G_MENU_ATTRIBUTE_LABEL, "s", &str)) + { + GParameter p = { "text", G_VALUE_INIT }; + g_value_init (&p.value, G_TYPE_STRING); + g_value_take_string (&p.value, str); + parameters[n++] = p; + } + + if (TRUE) + { + GParameter p = { "icon", G_VALUE_INIT }; + g_value_init (&p.value, G_TYPE_OBJECT); + g_value_take_object (&p.value, g_themed_icon_new_with_default_fallbacks ("alarm-symbolic")); + parameters[n++] = p; + } + + if (g_menu_item_get_attribute (menu_item, "x-canonical-time-format", "s", &str)) + { + GParameter p = { "format", G_VALUE_INIT }; + g_value_init (&p.value, G_TYPE_STRING); + g_value_take_string (&p.value, str); + parameters[n++] = p; + } + + if (g_menu_item_get_attribute (menu_item, "x-canonical-time", "x", &i64)) + { + GParameter p = { "date-time", G_VALUE_INIT }; + g_value_init (&p.value, G_TYPE_DATE_TIME); + g_value_take_boxed (&p.value, g_date_time_new_from_unix_local (i64)); + parameters[n++] = p; + } + + g_assert (n <= G_N_ELEMENTS (parameters)); + ido_menu_item = g_object_newv (IDO_TYPE_TIME_STAMP_MENU_ITEM, n, parameters); + + for (i=0; i + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef __IDO_ALARM_MENU_ITEM_H__ +#define __IDO_ALARM_MENU_ITEM_H__ + +#include + +G_BEGIN_DECLS + +GtkMenuItem * ido_alarm_menu_item_new_from_model (GMenuItem * menuitem, + GActionGroup * actions); + +G_END_DECLS + +#endif diff --git a/src/idomenuitemfactory.c b/src/idomenuitemfactory.c index b233095..0b38941 100644 --- a/src/idomenuitemfactory.c +++ b/src/idomenuitemfactory.c @@ -20,6 +20,7 @@ #include #include +#include "idoalarmmenuitem.h" #include "idoappointmentmenuitem.h" #include "idobasicmenuitem.h" #include "idocalendarmenuitem.h" @@ -67,6 +68,9 @@ ido_menu_item_factory_create_menu_item (UbuntuMenuItemFactory *factory, else if (g_str_equal (type, "com.canonical.indicator.appointment")) item = ido_appointment_menu_item_new_from_model (menuitem, actions); + else if (g_str_equal (type, "com.canonical.indicator.alarm")) + item = ido_alarm_menu_item_new_from_model (menuitem, actions); + else if (g_str_equal (type, "com.canonical.indicator.progress")) item = ido_progress_menu_item_new_from_model (menuitem, actions); -- cgit v1.2.3 From 5761e8d1d75838c8a097ab1e41c3b51b33037437 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 25 Jul 2013 18:57:29 -0500 Subject: implement IdoLocationMenuItem as a subclass of IdoTimeStampMenuItem --- src/idoappointmentmenuitem.c | 4 +- src/idolocationmenuitem.c | 115 +++++++++++-------------------------------- 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 -#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; }; -- cgit v1.2.3 From ad7dd27530f6d35706f6cd0ed5f5e9ce6ee53600 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 25 Jul 2013 22:19:28 -0500 Subject: sync two removed API functions: ido_location_menu_item_set_format, ido_location_menu_item_set_name --- debian/libido3-0.1-0.symbols | 2 -- 1 file changed, 2 deletions(-) diff --git a/debian/libido3-0.1-0.symbols b/debian/libido3-0.1-0.symbols index 332f518..4046ed4 100644 --- a/debian/libido3-0.1-0.symbols +++ b/debian/libido3-0.1-0.symbols @@ -32,8 +32,6 @@ libido3-0.1.so.0 libido3-0.1-0 #MINVER# ido_location_menu_item_get_type@Base 13.10.0daily13.06.19 ido_location_menu_item_new@Base 13.10.0daily13.06.19 ido_location_menu_item_new_from_model@Base 13.10.0daily13.06.19 - ido_location_menu_item_set_format@Base 13.10.0daily13.06.19 - ido_location_menu_item_set_name@Base 13.10.0daily13.06.19 ido_location_menu_item_set_timezone@Base 13.10.0daily13.06.19 ido_menu_item_factory_get_type@Base 13.10.0daily13.06.19 ido_message_dialog_get_type@Base 0.1.8 -- cgit v1.2.3