aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2013-07-30 22:17:45 +0000
committerTarmac <Unknown>2013-07-30 22:17:45 +0000
commit86b63cfd16696227a2b36ca3b1942061703393c1 (patch)
tree31e991dd8fa547ab34732d7ef6842c7dc8a28ffd
parentf3e64f722774ccbac28b8628bcc75d072a190143 (diff)
parentad7dd27530f6d35706f6cd0ed5f5e9ce6ee53600 (diff)
downloadayatana-ido-86b63cfd16696227a2b36ca3b1942061703393c1.tar.gz
ayatana-ido-86b63cfd16696227a2b36ca3b1942061703393c1.tar.bz2
ayatana-ido-86b63cfd16696227a2b36ca3b1942061703393c1.zip
Support x-canonical-type: "com.canonical.indicator.progress" and "com.canonical.indicator.alarm".
Approved by Ted Gould, PS Jenkins bot.
-rw-r--r--debian/libido3-0.1-0.symbols21
-rw-r--r--example/menus.c2
-rw-r--r--src/Makefile.am6
-rw-r--r--src/idoalarmmenuitem.c116
-rw-r--r--src/idoalarmmenuitem.h32
-rw-r--r--src/idoappointmentmenuitem.c364
-rw-r--r--src/idoappointmentmenuitem.h47
-rw-r--r--src/idobasicmenuitem.c391
-rw-r--r--src/idobasicmenuitem.h77
-rw-r--r--src/idolocationmenuitem.c186
-rw-r--r--src/idolocationmenuitem.h8
-rw-r--r--src/idomenuitemfactory.c8
-rw-r--r--src/idotimestampmenuitem.c253
-rw-r--r--src/idotimestampmenuitem.h72
14 files changed, 1021 insertions, 562 deletions
diff --git a/debian/libido3-0.1-0.symbols b/debian/libido3-0.1-0.symbols
index 11cd621..4046ed4 100644
--- a/debian/libido3-0.1-0.symbols
+++ b/debian/libido3-0.1-0.symbols
@@ -5,13 +5,14 @@ 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
+ 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
@@ -31,13 +32,12 @@ 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
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
@@ -82,6 +82,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/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; i<G_N_ELEMENTS(locations); i++)
{
GtkWidget * w = g_object_new (IDO_LOCATION_MENU_ITEM_TYPE,
- "name", locations[i].name,
+ "text", locations[i].name,
"timezone", locations[i].timezone,
"format", locations[i].format,
NULL);
diff --git a/src/Makefile.am b/src/Makefile.am
index 2791964..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 \
@@ -19,6 +20,8 @@ sources_h = \
idoswitchmenuitem.h \
idousermenuitem.h \
idoappointmentmenuitem.h \
+ idobasicmenuitem.h \
+ idotimestampmenuitem.h \
idolocationmenuitem.h \
idotimeline.h \
libido.h \
@@ -68,6 +71,7 @@ libido_0_1_la_SOURCES = \
libido.c \
idotypebuiltins.c \
idocalendarmenuitem.c \
+ idoalarmmenuitem.c \
idoentrymenuitem.c \
idomessagedialog.c \
idorange.c \
@@ -80,6 +84,8 @@ libido_0_1_la_SOURCES = \
idomediaplayermenuitem.c \
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 <charles.kerr@canonical.com>
+ * Ted Gould <ted@canonical.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <gtk/gtk.h>
+
+#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<n; i++)
+ g_value_unset (&parameters[i].value);
+
+
+ /* add an ActionHelper */
+
+ if (g_menu_item_get_attribute (menu_item, "action", "s", &str))
+ {
+ GVariant * target;
+ IdoActionHelper * helper;
+
+ target = g_menu_item_get_attribute_value (menu_item, "target",
+ G_VARIANT_TYPE_ANY);
+ helper = ido_action_helper_new (GTK_WIDGET(ido_menu_item), actions,
+ str, target);
+ g_signal_connect_swapped (ido_menu_item, "activate",
+ G_CALLBACK (ido_action_helper_activate), helper);
+ g_signal_connect_swapped (ido_menu_item, "destroy",
+ G_CALLBACK (g_object_unref), helper);
+
+ g_clear_pointer (&target, g_variant_unref);
+ g_free (str);
+ }
+
+ return GTK_MENU_ITEM (ido_menu_item);
+}
diff --git a/src/idoalarmmenuitem.h b/src/idoalarmmenuitem.h
new file mode 100644
index 0000000..25e6b2e
--- /dev/null
+++ b/src/idoalarmmenuitem.h
@@ -0,0 +1,32 @@
+/**
+ * Copyright 2013 Canonical Ltd.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __IDO_ALARM_MENU_ITEM_H__
+#define __IDO_ALARM_MENU_ITEM_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+GtkMenuItem * ido_alarm_menu_item_new_from_model (GMenuItem * menuitem,
+ GActionGroup * actions);
+
+G_END_DECLS
+
+#endif
diff --git a/src/idoappointmentmenuitem.c b/src/idoappointmentmenuitem.c
index 734b038..cfc0bf8 100644
--- a/src/idoappointmentmenuitem.c
+++ b/src/idoappointmentmenuitem.c
@@ -22,221 +22,12 @@
#include "config.h"
#endif
-#include <string.h> /* strstr() */
-
#include <gtk/gtk.h>
#include "idoactionhelper.h"
-#include "idoappointmentmenuitem.h"
-
-enum
-{
- PROP_0,
- PROP_COLOR,
- PROP_SUMMARY,
- PROP_TIME,
- PROP_FORMAT,
- PROP_LAST
-};
-
-static GParamSpec *properties[PROP_LAST];
-
-struct _IdoAppointmentMenuItemPrivate
-{
- char * summary;
- 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);
-
-/***
-**** 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_SUMMARY:
- g_value_set_string (v, p->summary);
- 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_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;
-
- 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_SUMMARY] = g_param_spec_string (
- "summary",
- "Summary",
- "Brief description of the appointment",
- "",
- 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);
-
- g_object_class_install_properties (gobject_class, PROP_LAST, properties);
-}
-
-static void
-ido_appointment_menu_item_init (IdoAppointmentMenuItem *self)
-{
- priv_t * p;
- GtkBox * box;
- GtkWidget * w;
+#include "idotimestampmenuitem.h"
- 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);
-}
-
-/***
-****
-***/
-
-/* 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)
{
@@ -278,129 +69,13 @@ 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;
-
- gtk_label_set_text (GTK_LABEL(p->timestamp_label), 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);
- gtk_image_set_from_pixbuf (GTK_IMAGE(p->color_image), 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.
- *
- * 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
* @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.
@@ -413,16 +88,16 @@ 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;
- 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;
@@ -430,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))
@@ -446,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<n; i++)
g_value_unset (&parameters[i].value);
@@ -468,16 +144,16 @@ ido_appointment_menu_item_new_from_model (GMenuItem * menu_item,
target = g_menu_item_get_attribute_value (menu_item, "target",
G_VARIANT_TYPE_ANY);
- helper = ido_action_helper_new (GTK_WIDGET(ido_appointment), actions,
+ helper = ido_action_helper_new (GTK_WIDGET(ido_menu_item), actions,
str, target);
- g_signal_connect_swapped (ido_appointment, "activate",
+ g_signal_connect_swapped (ido_menu_item, "activate",
G_CALLBACK (ido_action_helper_activate), helper);
- g_signal_connect_swapped (ido_appointment, "destroy",
+ g_signal_connect_swapped (ido_menu_item, "destroy",
G_CALLBACK (g_object_unref), helper);
g_clear_pointer (&target, g_variant_unref);
g_free (str);
}
- return GTK_MENU_ITEM (ido_appointment);
+ return GTK_MENU_ITEM (ido_menu_item);
}
diff --git a/src/idoappointmentmenuitem.h b/src/idoappointmentmenuitem.h
index 3a8c853..6889fa7 100644
--- a/src/idoappointmentmenuitem.h
+++ b/src/idoappointmentmenuitem.h
@@ -20,60 +20,13 @@
#ifndef __IDO_APPOINTMENT_MENU_ITEM_H__
#define __IDO_APPOINTMENT_MENU_ITEM_H__
-#include <time.h> /* time_t */
-
#include <gtk/gtk.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
-{
- GtkMenuItemClass 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 >*/
- GtkMenuItem 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_summary (IdoAppointmentMenuItem * menuitem,
- const char * summary);
-
-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
diff --git a/src/idobasicmenuitem.c b/src/idobasicmenuitem.c
new file mode 100644
index 0000000..f07cc14
--- /dev/null
+++ b/src/idobasicmenuitem.c
@@ -0,0 +1,391 @@
+/*
+ * Copyright 2013 Canonical Ltd.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <gtk/gtk.h>
+
+#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_TYPE_BASIC_MENU_ITEM,
+ 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->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,
+ "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_TYPE_BASIC_MENU_ITEM, 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);
+ }
+}
+
+/***
+****
+**** Progress Menu Item
+****
+***/
+
+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_TYPE_BASIC_MENU_ITEM, n, parameters);
+
+ for (i=0; i<n; i++)
+ g_value_unset (&parameters[i].value);
+
+ /* 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..01aa4b3
--- /dev/null
+++ b/src/idobasicmenuitem.h
@@ -0,0 +1,77 @@
+/**
+ * Copyright 2013 Canonical Ltd.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __IDO_BASIC_MENU_ITEM_H__
+#define __IDO_BASIC_MENU_ITEM_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define IDO_TYPE_BASIC_MENU_ITEM (ido_basic_menu_item_get_type ())
+#define IDO_BASIC_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_TYPE_BASIC_MENU_ITEM, IdoBasicMenuItem))
+#define IDO_IS_BASIC_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_TYPE_BASIC_MENU_ITEM))
+
+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/idolocationmenuitem.c b/src/idolocationmenuitem.c
index 5c4f0e6..335422a 100644
--- a/src/idolocationmenuitem.c
+++ b/src/idolocationmenuitem.c
@@ -31,9 +31,7 @@
enum
{
PROP_0,
- PROP_NAME,
PROP_TIMEZONE,
- PROP_FORMAT,
PROP_LAST
};
@@ -41,51 +39,35 @@ static GParamSpec *properties[PROP_LAST];
struct _IdoLocationMenuItemPrivate
{
- char * name;
char * timezone;
- char * format;
guint timestamp_timer;
-
- GtkWidget * name_label;
- GtkWidget * timestamp_label;
};
typedef IdoLocationMenuItemPrivate priv_t;
-G_DEFINE_TYPE (IdoLocationMenuItem, ido_location_menu_item, GTK_TYPE_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)
{
- priv_t * p = self->priv;
-
- if (p->format && *p->format)
- {
- GTimeZone * tz;
- GDateTime * now;
- char * str;
+ GTimeZone * tz;
+ GDateTime * date_time;
- 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);
+ 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);
- gtk_label_set_text (GTK_LABEL(p->timestamp_label), str);
+ ido_time_stamp_menu_item_set_date_time (IDO_TIME_STAMP_MENU_ITEM(self),
+ date_time);
- g_free (str);
- g_date_time_unref (now);
- g_time_zone_unref (tz);
- }
- else
- {
- gtk_label_set_text (GTK_LABEL(p->timestamp_label), "");
- }
+ g_date_time_unref (date_time);
+ g_time_zone_unref (tz);
}
static void
@@ -100,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;
}
@@ -143,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);
@@ -161,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);
}
/***
@@ -181,18 +162,10 @@ 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;
- case PROP_FORMAT:
- g_value_set_string (value, p->format);
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec);
break;
@@ -209,18 +182,10 @@ 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;
- 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;
@@ -239,11 +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->name);
- g_free (p->timezone);
+ g_free (self->priv->timezone);
G_OBJECT_CLASS (ido_location_menu_item_parent_class)->finalize (object);
}
@@ -255,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));
@@ -265,30 +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_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",
"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);
}
@@ -296,43 +239,16 @@ 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);
+ /* 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);
}
-
/***
**** Public API
***/
@@ -345,26 +261,6 @@ ido_location_menu_item_new (void)
}
/**
- * 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")
*
@@ -382,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);
}
/**
@@ -436,7 +308,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..2ae231f 100644
--- a/src/idolocationmenuitem.h
+++ b/src/idolocationmenuitem.h
@@ -21,6 +21,7 @@
#define __IDO_LOCATION_MENU_ITEM_H__
#include <gtk/gtk.h>
+#include "idotimestampmenuitem.h"
G_BEGIN_DECLS
@@ -34,7 +35,7 @@ typedef struct _IdoLocationMenuItemPrivate IdoLocationMenuItemPrivate;
struct _IdoLocationMenuItemClass
{
- GtkMenuItemClass parent_class;
+ IdoTimeStampMenuItemClass parent_class;
};
/**
@@ -46,7 +47,7 @@ struct _IdoLocationMenuItemClass
struct _IdoLocationMenuItem
{
/*< private >*/
- GtkMenuItem parent;
+ IdoTimeStampMenuItem 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);
diff --git a/src/idomenuitemfactory.c b/src/idomenuitemfactory.c
index 5ded309..0b38941 100644
--- a/src/idomenuitemfactory.c
+++ b/src/idomenuitemfactory.c
@@ -20,7 +20,9 @@
#include <gtk/gtk.h>
#include <gtk/ubuntu-private.h>
+#include "idoalarmmenuitem.h"
#include "idoappointmentmenuitem.h"
+#include "idobasicmenuitem.h"
#include "idocalendarmenuitem.h"
#include "idolocationmenuitem.h"
#include "idoscalemenuitem.h"
@@ -66,6 +68,12 @@ 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);
+
else if (g_str_equal (type, "com.canonical.unity.slider"))
item = ido_scale_menu_item_new_from_model (menuitem, actions);
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 <charles.kerr@canonical.com>
+ * Ted Gould <ted@canonical.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <string.h> /* strstr() */
+
+#include <gtk/gtk.h>
+
+#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 <charles.kerr@canonical.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __IDO_TIME_STAMP_MENU_ITEM_H__
+#define __IDO_TIME_STAMP_MENU_ITEM_H__
+
+#include <gtk/gtk.h>
+#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