From 3db9d6ff0a049700b55bb9766ae734fd19010e4a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 14 Jun 2013 13:02:50 -0500 Subject: add appointment menuitem --- src/idoappointmentmenuitem.c | 414 +++++++++++++++++++++++++++++++++++++++++++ src/idoappointmentmenuitem.h | 79 +++++++++ 2 files changed, 493 insertions(+) create mode 100644 src/idoappointmentmenuitem.c create mode 100644 src/idoappointmentmenuitem.h (limited to 'src') diff --git a/src/idoappointmentmenuitem.c b/src/idoappointmentmenuitem.c new file mode 100644 index 0000000..9329009 --- /dev/null +++ b/src/idoappointmentmenuitem.c @@ -0,0 +1,414 @@ +/** + * 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 "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; + + 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); +} + +/*** +**** +***/ + +static GdkPixbuf * +create_color_icon_pixbuf (const char * color_spec) +{ + static int width = -1; + static int height = -1; + GdkPixbuf * pixbuf = NULL; + + if (width == -1) + { + gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height); + width = CLAMP (width, 10, 30); + height = CLAMP (height, 10, 30); + } + + if (color_spec && *color_spec) + { + cairo_surface_t * surface; + cairo_t * cr; + GdkRGBA rgba; + + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); + cr = cairo_create (surface); + + if (gdk_rgba_parse (&rgba, color_spec)) + gdk_cairo_set_source_rgba (cr, &rgba); + + cairo_paint (cr); + cairo_set_source_rgba (cr, 0, 0, 0, 0.5); + cairo_set_line_width (cr, 1); + cairo_rectangle (cr, 0.5, 0.5, width-1, height-1); + cairo_stroke (cr); + + pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, width, height); + + cairo_destroy (cr); + cairo_surface_destroy (surface); + } + + return pixbuf; +} + +static void +update_timestamp_label (IdoAppointmentMenuItem * self) +{ + char * str; + priv_t * p = self->priv; + + str = g_date_time_format (p->date_time, p->format); + gtk_label_set_text (GTK_LABEL(p->timestamp_label), str); + g_free (str); +} + +/*** +**** Public API +***/ + +GtkWidget * +ido_appointment_menu_item_new (void) +{ + return GTK_WIDGET (g_object_new (IDO_APPOINTMENT_MENU_ITEM_TYPE, NULL)); +} + +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)); +} + +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); +} + +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); +} + +/** + * @strftime_fmt: the format string used to build the appointment's time 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); +} + +GtkMenuItem * +ido_appointment_menu_item_new_from_model (GMenuItem * menu_item, + GActionGroup * actions) +{ + gint64 i64; + gchar * str; + IdoAppointmentMenuItem * ido_appointment; + + ido_appointment = IDO_APPOINTMENT_MENU_ITEM (ido_appointment_menu_item_new()); + + if (g_menu_item_get_attribute (menu_item, "label", "s", &str)) + { + ido_appointment_menu_item_set_summary (ido_appointment, str); + g_free (str); + } + + if (g_menu_item_get_attribute (menu_item, "x-canonical-color", "s", &str)) + { + ido_appointment_menu_item_set_color (ido_appointment, str); + g_free (str); + } + + if (g_menu_item_get_attribute (menu_item, "x-canonical-time", "x", &i64)) + { + ido_appointment_menu_item_set_time (ido_appointment, (time_t)i64); + } + + if (g_menu_item_get_attribute (menu_item, "x-canonical-time-format", "s", &str)) + { + ido_appointment_menu_item_set_format (ido_appointment, str); + g_free (str); + } + + 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_appointment), actions, + str, target); + g_signal_connect_swapped (ido_appointment, "activate", + G_CALLBACK (ido_action_helper_activate), helper); + g_signal_connect_swapped (ido_appointment, "destroy", + G_CALLBACK (g_object_unref), helper); + + g_clear_pointer (&target, g_variant_unref); + g_free (str); + } + + return GTK_MENU_ITEM (ido_appointment); +} diff --git a/src/idoappointmentmenuitem.h b/src/idoappointmentmenuitem.h new file mode 100644 index 0000000..3a8c853 --- /dev/null +++ b/src/idoappointmentmenuitem.h @@ -0,0 +1,79 @@ +/** + * 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_APPOINTMENT_MENU_ITEM_H__ +#define __IDO_APPOINTMENT_MENU_ITEM_H__ + +#include /* time_t */ + +#include + +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 -- cgit v1.2.3 From 88522dcd394d16da85b998547c81ccec5d9426e2 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 14 Jun 2013 13:03:08 -0500 Subject: add location menuitem --- src/idolocationmenuitem.c | 433 ++++++++++++++++++++++++++++++++++++++++++++++ src/idolocationmenuitem.h | 74 ++++++++ 2 files changed, 507 insertions(+) create mode 100644 src/idolocationmenuitem.c create mode 100644 src/idolocationmenuitem.h (limited to 'src') diff --git a/src/idolocationmenuitem.c b/src/idolocationmenuitem.c new file mode 100644 index 0000000..1752e64 --- /dev/null +++ b/src/idolocationmenuitem.c @@ -0,0 +1,433 @@ +/** + * 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 "idolocationmenuitem.h" + +enum +{ + PROP_0, + PROP_NAME, + PROP_TIMEZONE, + PROP_FORMAT, + PROP_LAST +}; + +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); + +/*** +**** Timestamp Label +***/ + +static void +update_timestamp_label (IdoLocationMenuItem * self) +{ + priv_t * p = self->priv; + + 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); + + g_free (str); + g_date_time_unref (now); + g_time_zone_unref (tz); + } + else + { + gtk_label_set_text (GTK_LABEL(p->timestamp_label), ""); + } +} + +static void +stop_timestamp_timer (IdoLocationMenuItem * self) +{ + priv_t * p = self->priv; + + if (p->timestamp_timer != 0) + { + g_source_remove (p->timestamp_timer); + p->timestamp_timer = 0; + } +} + +static void start_timestamp_timer (IdoLocationMenuItem * self); + +static gboolean +on_timestamp_timer (gpointer gself) +{ + IdoLocationMenuItem * self = IDO_LOCATION_MENU_ITEM (gself); + + update_timestamp_label (self); + + start_timestamp_timer (self); + return G_SOURCE_REMOVE; +} + +static guint +calculate_seconds_until_next_minute (void) +{ + guint seconds; + GTimeSpan diff; + GDateTime * now; + GDateTime * next; + GDateTime * start_of_next; + + now = g_date_time_new_now_local (); + next = g_date_time_add_minutes (now, 1); + start_of_next = g_date_time_new_local (g_date_time_get_year (next), + g_date_time_get_month (next), + g_date_time_get_day_of_month (next), + g_date_time_get_hour (next), + g_date_time_get_minute (next), + 1); + + diff = g_date_time_difference (start_of_next, now); + seconds = (diff + (G_TIME_SPAN_SECOND - 1)) / G_TIME_SPAN_SECOND; + + /* cleanup */ + g_date_time_unref (start_of_next); + g_date_time_unref (next); + g_date_time_unref (now); + + g_message ("%s %s the next minute will be here in %u seconds", G_STRLOC, G_STRFUNC, seconds); + return seconds; +} + +static void +start_timestamp_timer (IdoLocationMenuItem * self) +{ + int interval_sec; + gboolean timestamp_shows_seconds; + priv_t * p = self->priv; + const char * const fmt = p->format; + + stop_timestamp_timer (self); + + timestamp_shows_seconds = fmt && (strstr(fmt,"%s") || + strstr(fmt,"%S") || + strstr(fmt,"%T")); + + if (timestamp_shows_seconds) + interval_sec = 1; + else + interval_sec = calculate_seconds_until_next_minute(); + + p->timestamp_timer = g_timeout_add_seconds (interval_sec, + on_timestamp_timer, + self); +} + +/*** +**** GObject Virtual Functions +***/ + +static void +my_get_property (GObject * o, + guint property_id, + GValue * value, + GParamSpec * pspec) +{ + IdoLocationMenuItem * self = IDO_LOCATION_MENU_ITEM (o); + priv_t * p = self->priv; + + 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; + } +} + +static void +my_set_property (GObject * o, + guint property_id, + const GValue * value, + GParamSpec * pspec) +{ + IdoLocationMenuItem * self = IDO_LOCATION_MENU_ITEM (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; + } +} + +static void +my_dispose (GObject * object) +{ + stop_timestamp_timer (IDO_LOCATION_MENU_ITEM (object)); + + G_OBJECT_CLASS (ido_location_menu_item_parent_class)->dispose (object); +} + +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_OBJECT_CLASS (ido_location_menu_item_parent_class)->finalize (object); +} + +/*** +**** Instantiation +***/ + +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)); + + 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_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_object_class_install_properties (gobject_class, PROP_LAST, properties); +} + +static void +ido_location_menu_item_init (IdoLocationMenuItem *self) +{ + priv_t * p; + GtkBox * box; + GtkWidget * w; + + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + IDO_LOCATION_MENU_ITEM_TYPE, + IdoLocationMenuItemPrivate); + + p = self->priv; + + p->name_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->name_label, FALSE, FALSE, 3); + gtk_box_pack_end (box, p->timestamp_label, FALSE, FALSE, 5); + + gtk_widget_show_all (w); + gtk_container_add (GTK_CONTAINER (self), w); +} + + +/*** +**** Public API +***/ + +GtkWidget * +ido_location_menu_item_new (void) +{ + return GTK_WIDGET (g_object_new (IDO_LOCATION_MENU_ITEM_TYPE, NULL)); +} + +/** + * @name: human-readable name, such as a city (eg: "Oklahoma City") + */ +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); +} + +/** + * @timezone: timezone identifier (eg: "America/Chicago") + */ +void +ido_location_menu_item_set_timezone (IdoLocationMenuItem * self, + const char * timezone) +{ + priv_t * p; + + g_return_if_fail (IDO_IS_LOCATION_MENU_ITEM (self)); + p = self->priv; + + g_free (p->timezone); + p->timezone = g_strdup (timezone); + update_timestamp_label (self); +} + +/** + * @strftime_fmt: the format string used to build the location's time string + */ +void +ido_location_menu_item_set_format (IdoLocationMenuItem * self, + const char * strftime_fmt) +{ + priv_t * p; + + g_return_if_fail (IDO_IS_LOCATION_MENU_ITEM (self)); + p = self->priv; + + g_free (p->format); + p->format = g_strdup (strftime_fmt); + update_timestamp_label (self); + start_timestamp_timer (self); +} + +GtkMenuItem * +ido_location_menu_item_new_from_model (GMenuItem * menu_item, + GActionGroup * actions) +{ + gchar * str; + IdoLocationMenuItem * ido_location; + + ido_location = IDO_LOCATION_MENU_ITEM (ido_location_menu_item_new ()); + + if (g_menu_item_get_attribute (menu_item, "label", "s", &str)) + { + ido_location_menu_item_set_name (ido_location, str); + g_free (str); + } + + if (g_menu_item_get_attribute (menu_item, "x-canonical-timezone", "s", &str)) + { + ido_location_menu_item_set_timezone (ido_location, str); + g_free (str); + } + + if (g_menu_item_get_attribute (menu_item, "x-canonical-time-format", "s", &str)) + { + ido_location_menu_item_set_format (ido_location, str); + g_free (str); + } + + 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_location), actions, + str, target); + g_signal_connect_swapped (ido_location, "activate", + G_CALLBACK (ido_action_helper_activate), helper); + g_signal_connect_swapped (ido_location, "destroy", + G_CALLBACK (g_object_unref), helper); + + if (target) + g_variant_unref (target); + g_free (str); + } + + return GTK_MENU_ITEM (ido_location); +} diff --git a/src/idolocationmenuitem.h b/src/idolocationmenuitem.h new file mode 100644 index 0000000..0b74dbd --- /dev/null +++ b/src/idolocationmenuitem.h @@ -0,0 +1,74 @@ +/** + * 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_LOCATION_MENU_ITEM_H__ +#define __IDO_LOCATION_MENU_ITEM_H__ + +#include + +G_BEGIN_DECLS + +#define IDO_LOCATION_MENU_ITEM_TYPE (ido_location_menu_item_get_type ()) +#define IDO_LOCATION_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_LOCATION_MENU_ITEM_TYPE, IdoLocationMenuItem)) +#define IDO_IS_LOCATION_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_LOCATION_MENU_ITEM_TYPE)) + +typedef struct _IdoLocationMenuItem IdoLocationMenuItem; +typedef struct _IdoLocationMenuItemClass IdoLocationMenuItemClass; +typedef struct _IdoLocationMenuItemPrivate IdoLocationMenuItemPrivate; + +struct _IdoLocationMenuItemClass +{ + GtkMenuItemClass parent_class; +}; + +/** + * A menuitem that indicates a location. + * + * It gives the location's name in the primary label, + * and a right-aligned secondary label shows the + * current time in that location's timezone + */ +struct _IdoLocationMenuItem +{ + /*< private >*/ + GtkMenuItem parent; + IdoLocationMenuItemPrivate * priv; +}; + + +GType ido_location_menu_item_get_type (void) G_GNUC_CONST; + +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); + +void ido_location_menu_item_set_format (IdoLocationMenuItem * menuitem, + const char * strftime_fmt); + + +G_END_DECLS + +#endif -- cgit v1.2.3 From 9373536218102cb5d0e385d5ca736b5c6f88f65e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 14 Jun 2013 13:04:00 -0500 Subject: add ido_calendar_menu_item_new_from_model() --- src/idocalendarmenuitem.c | 177 +++++++++++++++++++++++++++++++++++++++++++++- src/idocalendarmenuitem.h | 7 +- 2 files changed, 180 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/idocalendarmenuitem.c b/src/idocalendarmenuitem.c index a818c13..7bb1c18 100644 --- a/src/idocalendarmenuitem.c +++ b/src/idocalendarmenuitem.c @@ -24,6 +24,7 @@ */ #include +#include "idoactionhelper.h" #include "idocalendarmenuitem.h" #include "config.h" @@ -470,8 +471,178 @@ ido_calendar_menu_item_set_date (IdoCalendarMenuItem *menuitem, guint month, guint day) { - g_return_val_if_fail(IDO_IS_CALENDAR_MENU_ITEM(menuitem), FALSE); - gtk_calendar_select_month (GTK_CALENDAR (menuitem->priv->calendar), month, year); - gtk_calendar_select_day (GTK_CALENDAR (menuitem->priv->calendar), day); + guint old_y, old_m, old_d; + + g_return_val_if_fail (IDO_IS_CALENDAR_MENU_ITEM(menuitem), FALSE); + + ido_calendar_menu_item_get_date (menuitem, &old_y, &old_m, &old_d); + + if ((old_y != year) || (old_m != month)) + gtk_calendar_select_month (GTK_CALENDAR (menuitem->priv->calendar), month, year); + + if (old_d != day) + gtk_calendar_select_day (GTK_CALENDAR (menuitem->priv->calendar), day); + return TRUE; } + +/*** +**** +**** +**** +***/ + +static void +activate_current_day (IdoCalendarMenuItem * ido_calendar, + const char * action_name_key) +{ + GObject * o; + const char * action_name; + GActionGroup * action_group; + + o = G_OBJECT (ido_calendar); + action_name = g_object_get_data (o, action_name_key); + action_group = g_object_get_data (o, "ido-action-group"); + + if (action_group && action_name) + { + guint y, m, d; + GDateTime * date_time; + GVariant * target; + + ido_calendar_menu_item_get_date (ido_calendar, &y, &m, &d); + m++; /* adjust month from GtkCalendar (0 based) to GDateTime (1 based) */ + date_time = g_date_time_new_utc (y, m, d, 9, 0, 0); + target = g_variant_new_int64 (g_date_time_to_unix (date_time)); + + g_action_group_activate_action (action_group, action_name, target); + + g_date_time_unref (date_time); + } +} + +static void +on_day_selected (IdoCalendarMenuItem * ido_calendar) +{ + activate_current_day (ido_calendar, "ido-selection-action-name"); +} + +static void +on_day_double_clicked (IdoCalendarMenuItem * ido_calendar) +{ + activate_current_day (ido_calendar, "ido-activation-action-name"); +} + +static void +on_action_state_changed (IdoActionHelper * helper, + GVariant * state, + gpointer unused G_GNUC_UNUSED) +{ + GVariant * v; + const char * key; + IdoCalendarMenuItem * ido_calendar; + + ido_calendar = IDO_CALENDAR_MENU_ITEM (ido_action_helper_get_widget (helper)); + + g_return_if_fail (ido_calendar != NULL); + g_return_if_fail (g_variant_is_of_type (state, G_VARIANT_TYPE_DICTIONARY)); + + /* an int64 representing a utc time_t indicating which year and month should + be visible in the calendar and which day should be given the cursor. */ + key = "calendar-day"; + if ((v = g_variant_lookup_value (state, key, G_VARIANT_TYPE_INT64))) + { + int y, m, d; + gint64 unix_utc; + GDateTime * date_time; + + unix_utc = g_variant_get_int64 (v); + date_time = g_date_time_new_from_unix_local (unix_utc); + g_date_time_get_ymd (date_time, &y, &m, &d); + m--; /* adjust month from GDateTime (1 based) to GtkCalendar (0 based) */ + ido_calendar_menu_item_set_date (ido_calendar, y, m, d); + + g_date_time_unref (date_time); + g_variant_unref (v); + } + + /* a boolean value of whether or not to show the week numbers */ + key = "show-week-numbers"; + if ((v = g_variant_lookup_value (state, key, G_VARIANT_TYPE_BOOLEAN))) + { + const GtkCalendarDisplayOptions old_flags = ido_calendar_menu_item_get_display_options (ido_calendar); + GtkCalendarDisplayOptions new_flags = old_flags; + + if (g_variant_get_boolean (v)) + new_flags |= GTK_CALENDAR_SHOW_WEEK_NUMBERS; + else + new_flags &= ~GTK_CALENDAR_SHOW_WEEK_NUMBERS; + + if (new_flags != old_flags) + ido_calendar_menu_item_set_display_options (ido_calendar, new_flags); + + g_variant_unref (v); + } + + /* an array of int32 day-of-months denoting days that have appointments */ + key = "appointment-days"; + ido_calendar_menu_item_clear_marks (ido_calendar); + if ((v = g_variant_lookup_value (state, key, G_VARIANT_TYPE("ai")))) + { + gint32 day; + GVariantIter iter; + + g_variant_iter_init (&iter, v); + while (g_variant_iter_next (&iter, "i", &day)) + ido_calendar_menu_item_mark_day (ido_calendar, day); + + g_variant_unref (v); + } +} + +GtkMenuItem * +ido_calendar_menu_item_new_from_model (GMenuItem * menu_item, + GActionGroup * actions) +{ + GObject * o; + GtkWidget * calendar; + IdoCalendarMenuItem * ido_calendar; + gchar * selection_action_name; + gchar * activation_action_name; + + /* get the select & activate action names */ + g_menu_item_get_attribute (menu_item, "action", "s", &selection_action_name); + g_menu_item_get_attribute (menu_item, "activation-action", "s", &activation_action_name); + + /* remember the action group & action names so that we can poke them + when user selects and double-clicks */ + ido_calendar = IDO_CALENDAR_MENU_ITEM (ido_calendar_menu_item_new ()); + o = G_OBJECT (ido_calendar); + g_object_set_data_full (o, "ido-action-group", g_object_ref(actions), g_object_unref); + g_object_set_data_full (o, "ido-selection-action-name", selection_action_name, g_free); + g_object_set_data_full (o, "ido-activation-action-name", activation_action_name, g_free); + calendar = ido_calendar_menu_item_get_calendar (ido_calendar); + g_signal_connect_swapped (calendar, "day-selected", + G_CALLBACK(on_day_selected), ido_calendar); + g_signal_connect_swapped (calendar, "day-selected-double-click", + G_CALLBACK(on_day_double_clicked), ido_calendar); + + /* Use an IdoActionHelper for state updates. + Since we have two separate actions for selection & activation, + we'll do the activation & targets logic here in ido-calendar */ + if (selection_action_name != NULL) + { + IdoActionHelper * helper; + + helper = ido_action_helper_new (GTK_WIDGET(ido_calendar), + actions, + selection_action_name, + NULL); + g_signal_connect (helper, "action-state-changed", + G_CALLBACK (on_action_state_changed), NULL); + g_signal_connect_swapped (ido_calendar, "destroy", + G_CALLBACK (g_object_unref), helper); + } + + return GTK_MENU_ITEM (ido_calendar); +} diff --git a/src/idocalendarmenuitem.h b/src/idocalendarmenuitem.h index c4833fb..5cd913e 100644 --- a/src/idocalendarmenuitem.h +++ b/src/idocalendarmenuitem.h @@ -69,7 +69,12 @@ void ido_calendar_menu_item_get_date (IdoCalendarMenuItem *menu gboolean ido_calendar_menu_item_set_date (IdoCalendarMenuItem *menuitem, guint year, guint month, - guint day); + guint day); + +GtkMenuItem * ido_calendar_menu_item_new_from_model (GMenuItem * menuitem, + GActionGroup * actions); + + G_END_DECLS #endif /* __IDO_CALENDAR_MENU_ITEM_H__ */ -- cgit v1.2.3 From 17c7bd1fdee7794a8c324263db5ad8a2d41fe51e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 14 Jun 2013 13:04:45 -0500 Subject: add calendar, location, and appointment menuitems to the IDO factory --- src/Makefile.am | 4 ++++ src/idomenuitemfactory.c | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 0a4dbab..7b2e51e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,6 +18,8 @@ sources_h = \ idoscalemenuitem.h \ idoswitchmenuitem.h \ idousermenuitem.h \ + idoappointmentmenuitem.h \ + idolocationmenuitem.h \ idotimeline.h \ libido.h \ idoactionhelper.h @@ -72,6 +74,8 @@ libido_0_1_la_SOURCES = \ idotimeline.c \ idomenuitemfactory.c \ idoactionhelper.c \ + idoappointmentmenuitem.c \ + idolocationmenuitem.c \ idousermenuitem.c libido3_0_1_la_SOURCES = $(libido_0_1_la_SOURCES) diff --git a/src/idomenuitemfactory.c b/src/idomenuitemfactory.c index 0ff84a8..aef08e6 100644 --- a/src/idomenuitemfactory.c +++ b/src/idomenuitemfactory.c @@ -20,8 +20,11 @@ #include #include -#include "idousermenuitem.h" +#include "idoappointmentmenuitem.h" +#include "idocalendarmenuitem.h" +#include "idolocationmenuitem.h" #include "idoscalemenuitem.h" +#include "idousermenuitem.h" #define IDO_TYPE_MENU_ITEM_FACTORY (ido_menu_item_factory_get_type ()) #define IDO_MENU_ITEM_FACTORY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), IDO_TYPE_MENU_ITEM_FACTORY, IdoMenuItemFactory)) @@ -49,6 +52,15 @@ ido_menu_item_factory_create_menu_item (UbuntuMenuItemFactory *factory, if (g_str_equal (type, "indicator.user-menu-item")) item = ido_user_menu_item_new_from_model (menuitem, actions); + else if (g_str_equal (type, "com.canonical.indicator.calendar")) + item = ido_calendar_menu_item_new_from_model (menuitem, actions); + + else if (g_str_equal (type, "com.canonical.indicator.location")) + item = ido_location_menu_item_new_from_model (menuitem, actions); + + 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.unity.slider")) item = ido_scale_menu_item_new_from_model (menuitem, actions); -- cgit v1.2.3 From 914258f0839fefecfd8498aaabbcfd9de1c6f79d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 14 Jun 2013 13:21:27 -0500 Subject: remove g_message that leaked into last commit --- src/idolocationmenuitem.c | 1 - src/idolocationmenuitem.h | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/idolocationmenuitem.c b/src/idolocationmenuitem.c index 1752e64..6646d12 100644 --- a/src/idolocationmenuitem.c +++ b/src/idolocationmenuitem.c @@ -139,7 +139,6 @@ calculate_seconds_until_next_minute (void) g_date_time_unref (next); g_date_time_unref (now); - g_message ("%s %s the next minute will be here in %u seconds", G_STRLOC, G_STRFUNC, seconds); return seconds; } diff --git a/src/idolocationmenuitem.h b/src/idolocationmenuitem.h index 0b74dbd..08a97af 100644 --- a/src/idolocationmenuitem.h +++ b/src/idolocationmenuitem.h @@ -40,9 +40,8 @@ struct _IdoLocationMenuItemClass /** * A menuitem that indicates a location. * - * It gives the location's name in the primary label, - * and a right-aligned secondary label shows the - * current time in that location's timezone + * It contains a primary label giving the location's name and a + * right-aligned secondary label showing the location's current time */ struct _IdoLocationMenuItem { -- cgit v1.2.3 From 5988e06c3df519ae2dcce7454ffc597bcc3ce9e5 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 14 Jun 2013 13:22:03 -0500 Subject: add ted's name to idoappointmentmenuitem.c for create_color_icon_pixbuf() --- src/idoappointmentmenuitem.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/idoappointmentmenuitem.c b/src/idoappointmentmenuitem.c index 9329009..864081b 100644 --- a/src/idoappointmentmenuitem.c +++ b/src/idoappointmentmenuitem.c @@ -3,6 +3,7 @@ * * 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 -- cgit v1.2.3 From 2e2f7e3ddea38b1f53461a4b18d3cd133dd457c5 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 14 Jun 2013 14:15:11 -0500 Subject: in idolocationmenuitem, assume seconds are shown in the timestamp when the time format string includes '%s', '%S', '%T', '%X', or '%c' --- src/idolocationmenuitem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/idolocationmenuitem.c b/src/idolocationmenuitem.c index 6646d12..34e5de3 100644 --- a/src/idolocationmenuitem.c +++ b/src/idolocationmenuitem.c @@ -152,9 +152,9 @@ start_timestamp_timer (IdoLocationMenuItem * self) stop_timestamp_timer (self); - timestamp_shows_seconds = fmt && (strstr(fmt,"%s") || - strstr(fmt,"%S") || - strstr(fmt,"%T")); + timestamp_shows_seconds = fmt && (strstr(fmt,"%s") || strstr(fmt,"%S") || + strstr(fmt,"%T") || strstr(fmt,"%X") || + strstr(fmt,"%c")); if (timestamp_shows_seconds) interval_sec = 1; -- cgit v1.2.3 From 2e5b7f36068849053692b97fdda189c6ad506fdb Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 14 Jun 2013 19:10:26 -0500 Subject: fix time_t issue in idocalendarmenuitem's gmenu code --- src/idocalendarmenuitem.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/idocalendarmenuitem.c b/src/idocalendarmenuitem.c index 7bb1c18..94f4f61 100644 --- a/src/idocalendarmenuitem.c +++ b/src/idocalendarmenuitem.c @@ -512,7 +512,7 @@ activate_current_day (IdoCalendarMenuItem * ido_calendar, ido_calendar_menu_item_get_date (ido_calendar, &y, &m, &d); m++; /* adjust month from GtkCalendar (0 based) to GDateTime (1 based) */ - date_time = g_date_time_new_utc (y, m, d, 9, 0, 0); + date_time = g_date_time_new_local (y, m, d, 9, 0, 0); target = g_variant_new_int64 (g_date_time_to_unix (date_time)); g_action_group_activate_action (action_group, action_name, target); @@ -547,17 +547,17 @@ on_action_state_changed (IdoActionHelper * helper, g_return_if_fail (ido_calendar != NULL); g_return_if_fail (g_variant_is_of_type (state, G_VARIANT_TYPE_DICTIONARY)); - /* an int64 representing a utc time_t indicating which year and month should + /* an int64 representing a time_t indicating which year and month should be visible in the calendar and which day should be given the cursor. */ key = "calendar-day"; if ((v = g_variant_lookup_value (state, key, G_VARIANT_TYPE_INT64))) { int y, m, d; - gint64 unix_utc; + time_t t; GDateTime * date_time; - unix_utc = g_variant_get_int64 (v); - date_time = g_date_time_new_from_unix_local (unix_utc); + t = g_variant_get_int64 (v); + date_time = g_date_time_new_from_unix_local (t); g_date_time_get_ymd (date_time, &y, &m, &d); m--; /* adjust month from GDateTime (1 based) to GtkCalendar (0 based) */ ido_calendar_menu_item_set_date (ido_calendar, y, m, d); -- cgit v1.2.3 From 6de8e0386beb02beafc321aaef82176acaae5424 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 17 Jun 2013 10:04:35 -0500 Subject: in idoappointmentmenuitem.c, fix startup issue arising from updating the timestamp label when the strftime format string hasn't been initialized yet. --- src/idoappointmentmenuitem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/idoappointmentmenuitem.c b/src/idoappointmentmenuitem.c index 864081b..929e011 100644 --- a/src/idoappointmentmenuitem.c +++ b/src/idoappointmentmenuitem.c @@ -280,12 +280,14 @@ create_color_icon_pixbuf (const char * color_spec) static void update_timestamp_label (IdoAppointmentMenuItem * self) { - char * str; priv_t * p = self->priv; - str = g_date_time_format (p->date_time, p->format); - gtk_label_set_text (GTK_LABEL(p->timestamp_label), str); - g_free (str); + if (p->date_time && p->format) + { + char * str = g_date_time_format (p->date_time, p->format); + gtk_label_set_text (GTK_LABEL(p->timestamp_label), str); + g_free (str); + } } /*** -- cgit v1.2.3 From 9205983a6f1a75487abeb32e4fe6df3753980277 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 17 Jun 2013 10:41:25 -0500 Subject: when building location and appointment menuitems from a GMenu, grab all the parameters and then pass them to object_new() as a block to avoid them getting set twice -- once with the constructor's default values, and then once afterwards --- src/idoappointmentmenuitem.c | 43 +++++++++++++++++++++++++++++++++---------- src/idolocationmenuitem.c | 34 +++++++++++++++++++++++++++------- 2 files changed, 60 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/idoappointmentmenuitem.c b/src/idoappointmentmenuitem.c index 929e011..45daeed 100644 --- a/src/idoappointmentmenuitem.c +++ b/src/idoappointmentmenuitem.c @@ -366,35 +366,58 @@ GtkMenuItem * ido_appointment_menu_item_new_from_model (GMenuItem * menu_item, GActionGroup * actions) { + guint i; + guint n; gint64 i64; gchar * str; IdoAppointmentMenuItem * ido_appointment; + GParameter parameters[8]; - ido_appointment = IDO_APPOINTMENT_MENU_ITEM (ido_appointment_menu_item_new()); + /* create the ido_appointment */ + + n = 0; if (g_menu_item_get_attribute (menu_item, "label", "s", &str)) { - ido_appointment_menu_item_set_summary (ido_appointment, str); - g_free (str); + GParameter p = { "summary", 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-color", "s", &str)) { - ido_appointment_menu_item_set_color (ido_appointment, str); - g_free (str); + GParameter p = { "color", 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)) + if (g_menu_item_get_attribute (menu_item, "x-canonical-time-format", "s", &str)) { - ido_appointment_menu_item_set_time (ido_appointment, (time_t)i64); + 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-format", "s", &str)) + if (g_menu_item_get_attribute (menu_item, "x-canonical-time", "x", &i64)) { - ido_appointment_menu_item_set_format (ido_appointment, str); - g_free (str); + GParameter p = { "time", G_VALUE_INIT }; + g_value_init (&p.value, G_TYPE_INT64); + g_value_set_int64 (&p.value, i64); + parameters[n++] = p; } + g_assert (n <= G_N_ELEMENTS (parameters)); + ido_appointment = g_object_newv (IDO_APPOINTMENT_MENU_ITEM_TYPE, n, parameters); + + for (i=0; i Date: Mon, 17 Jun 2013 10:59:26 -0500 Subject: add documentation for the public API calls --- src/idoappointmentmenuitem.c | 42 +++++++++++++++++++++++++++++++++++++++++- src/idolocationmenuitem.c | 31 ++++++++++++++++++++++++++++--- 2 files changed, 69 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/idoappointmentmenuitem.c b/src/idoappointmentmenuitem.c index 45daeed..a24ab49 100644 --- a/src/idoappointmentmenuitem.c +++ b/src/idoappointmentmenuitem.c @@ -294,12 +294,22 @@ update_timestamp_label (IdoAppointmentMenuItem * self) **** 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) @@ -317,6 +327,12 @@ ido_appointment_menu_item_set_color (IdoAppointmentMenuItem * self, 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) @@ -331,6 +347,13 @@ ido_appointment_menu_item_set_summary (IdoAppointmentMenuItem * self, 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) @@ -346,7 +369,13 @@ ido_appointment_menu_item_set_time (IdoAppointmentMenuItem * self, } /** - * @strftime_fmt: the format string used to build the appointment's time string + * ido_appointment_menu_item_set_format: + * @format: the format string used when showing the appointment'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_appointment_menu_item_set_format (IdoAppointmentMenuItem * self, @@ -362,6 +391,17 @@ ido_appointment_menu_item_set_format (IdoAppointmentMenuItem * self, update_timestamp_label (self); } +/** + * ido_location_menu_item_new_from_model: + * @menu_item: the corresponding menuitem + * @actions: action group to tell when this GtkMenuItem is activated + * + * Creates a new IdoLocationMenuItem with properties initialized from + * the menuitem's attributes. + * + * If the menuitem's 'action' attribute is set, trigger that action + * in @actions when this IdoLocationMenuItem is activated. + */ GtkMenuItem * ido_appointment_menu_item_new_from_model (GMenuItem * menu_item, GActionGroup * actions) diff --git a/src/idolocationmenuitem.c b/src/idolocationmenuitem.c index 5993938..347c9e8 100644 --- a/src/idolocationmenuitem.c +++ b/src/idolocationmenuitem.c @@ -324,6 +324,7 @@ ido_location_menu_item_init (IdoLocationMenuItem *self) **** Public API ***/ +/* create a new IdoLocationMenuItemType */ GtkWidget * ido_location_menu_item_new (void) { @@ -331,7 +332,10 @@ 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, @@ -348,7 +352,11 @@ ido_location_menu_item_set_name (IdoLocationMenuItem * self, } /** + * ido_location_menu_item_set_timezone: * @timezone: timezone identifier (eg: "America/Chicago") + * + * Set this location's timezone. This will be used to show the location's + * current time in menuitem's right-justified secondary label. */ void ido_location_menu_item_set_timezone (IdoLocationMenuItem * self, @@ -365,11 +373,17 @@ ido_location_menu_item_set_timezone (IdoLocationMenuItem * self, } /** - * @strftime_fmt: the format string used to build the location's time string + * 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 * strftime_fmt) + const char * format) { priv_t * p; @@ -377,11 +391,22 @@ ido_location_menu_item_set_format (IdoLocationMenuItem * self, p = self->priv; g_free (p->format); - p->format = g_strdup (strftime_fmt); + p->format = g_strdup (format); update_timestamp_label (self); start_timestamp_timer (self); } +/** + * ido_location_menu_item_new_from_model: + * @menu_item: the corresponding menuitem + * @actions: action group to tell when this GtkMenuItem is activated + * + * Creates a new IdoLocationMenuItem with properties initialized from + * the menuitem's attributes. + * + * If the menuitem's 'action' attribute is set, trigger that action + * in @actions when this IdoLocationMenuItem is activated. + */ GtkMenuItem * ido_location_menu_item_new_from_model (GMenuItem * menu_item, GActionGroup * actions) -- cgit v1.2.3 From 32915975083819f39112f5c4c009b45a3e8ae33b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 17 Jun 2013 11:09:43 -0500 Subject: in IdoAppointmentMenuItem's update_timestamp_label(), clear the label text if either the time or format properties are unset --- src/idoappointmentmenuitem.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/idoappointmentmenuitem.c b/src/idoappointmentmenuitem.c index a24ab49..26029a7 100644 --- a/src/idoappointmentmenuitem.c +++ b/src/idoappointmentmenuitem.c @@ -236,6 +236,7 @@ ido_appointment_menu_item_init (IdoAppointmentMenuItem *self) **** ***/ +/* creates a menu-sized pixbuf filled with specified color */ static GdkPixbuf * create_color_icon_pixbuf (const char * color_spec) { @@ -280,14 +281,16 @@ create_color_icon_pixbuf (const char * color_spec) static void update_timestamp_label (IdoAppointmentMenuItem * self) { + char * str; priv_t * p = self->priv; if (p->date_time && p->format) - { - char * str = g_date_time_format (p->date_time, p->format); - gtk_label_set_text (GTK_LABEL(p->timestamp_label), str); - g_free (str); - } + 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); } /*** -- cgit v1.2.3 From 0aa36d9cf4e13d1247814122567739b02d67db9c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 17 Jun 2013 11:14:36 -0500 Subject: copyediting: fix copy/paste errors in the documentation --- src/idoappointmentmenuitem.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/idoappointmentmenuitem.c b/src/idoappointmentmenuitem.c index 26029a7..2ac518a 100644 --- a/src/idoappointmentmenuitem.c +++ b/src/idoappointmentmenuitem.c @@ -375,7 +375,7 @@ ido_appointment_menu_item_set_time (IdoAppointmentMenuItem * 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 location'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. @@ -395,15 +395,15 @@ ido_appointment_menu_item_set_format (IdoAppointmentMenuItem * self, } /** - * ido_location_menu_item_new_from_model: + * 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 IdoLocationMenuItem with properties initialized from + * Creates a new IdoAppointmentMenuItem with properties initialized from * the menuitem's attributes. * * If the menuitem's 'action' attribute is set, trigger that action - * in @actions when this IdoLocationMenuItem is activated. + * in @actions when this IdoAppointmentMenuItem is activated. */ GtkMenuItem * ido_appointment_menu_item_new_from_model (GMenuItem * menu_item, -- cgit v1.2.3