diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/idoappointmentmenuitem.c | 298 | ||||
-rw-r--r-- | src/idoappointmentmenuitem.h | 45 |
2 files changed, 16 insertions, 327 deletions
diff --git a/src/idoappointmentmenuitem.c b/src/idoappointmentmenuitem.c index e5bea24..b383729 100644 --- a/src/idoappointmentmenuitem.c +++ b/src/idoappointmentmenuitem.c @@ -22,182 +22,12 @@ #include "config.h" #endif -#include <string.h> /* strstr() */ - #include <gtk/gtk.h> #include "idoactionhelper.h" -#include "idoappointmentmenuitem.h" - -enum -{ - PROP_0, - PROP_COLOR, - PROP_TIME, - PROP_FORMAT, - PROP_LAST -}; - -static GParamSpec *properties[PROP_LAST]; - -struct _IdoAppointmentMenuItemPrivate -{ - char * summary; - char * format; - char * color_string; - GDateTime * date_time; -}; - -typedef IdoAppointmentMenuItemPrivate priv_t; - -G_DEFINE_TYPE (IdoAppointmentMenuItem, - ido_appointment_menu_item, - IDO_TYPE_BASIC_MENU_ITEM); - -/*** -**** GObject Virtual Functions -***/ - -static void -my_get_property (GObject * o, - guint property_id, - GValue * v, - GParamSpec * pspec) -{ - IdoAppointmentMenuItem * self = IDO_APPOINTMENT_MENU_ITEM (o); - priv_t * p = self->priv; - - switch (property_id) - { - case PROP_COLOR: - g_value_set_string (v, p->color_string); - break; - - case PROP_FORMAT: - g_value_set_string (v, p->format); - break; - - case PROP_TIME: - g_value_set_uint64 (v, g_date_time_to_unix (p->date_time)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); - break; - } -} - -static void -my_set_property (GObject * o, - guint property_id, - const GValue * v, - GParamSpec * pspec) -{ - IdoAppointmentMenuItem * self = IDO_APPOINTMENT_MENU_ITEM (o); - - switch (property_id) - { - case PROP_COLOR: - ido_appointment_menu_item_set_color (self, g_value_get_string (v)); - break; - - case PROP_FORMAT: - ido_appointment_menu_item_set_format (self, g_value_get_string (v)); - break; - - case PROP_TIME: - ido_appointment_menu_item_set_time (self, g_value_get_int64 (v)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); - break; - } -} - -static void -my_dispose (GObject * object) -{ - IdoAppointmentMenuItem * self = IDO_APPOINTMENT_MENU_ITEM (object); - priv_t * p = self->priv; - - g_clear_pointer (&p->date_time, g_date_time_unref); - - G_OBJECT_CLASS (ido_appointment_menu_item_parent_class)->dispose (object); -} - -static void -my_finalize (GObject * object) -{ - IdoAppointmentMenuItem * self = IDO_APPOINTMENT_MENU_ITEM (object); - priv_t * p = self->priv; - - g_free (p->color_string); - g_free (p->summary); - g_free (p->format); - - G_OBJECT_CLASS (ido_appointment_menu_item_parent_class)->finalize (object); -} - -/*** -**** Instantiation -***/ - -static void -ido_appointment_menu_item_class_init (IdoAppointmentMenuItemClass *klass) -{ - GParamFlags prop_flags; - GObjectClass * gobject_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (IdoAppointmentMenuItemPrivate)); - - gobject_class->get_property = my_get_property; - gobject_class->set_property = my_set_property; - gobject_class->dispose = my_dispose; - gobject_class->finalize = my_finalize; - - prop_flags = G_PARAM_CONSTRUCT - | G_PARAM_READWRITE - | G_PARAM_STATIC_STRINGS; - - properties[PROP_COLOR] = g_param_spec_string ( - "color", - "Color", - "Color coding for the appointment's type", - "White", - prop_flags); - - properties[PROP_TIME] = g_param_spec_int64 ( - "time", - "Time", - "unix time_t specifying when the appointment begins", - 0, G_MAXINT64, 0, - prop_flags); - - properties[PROP_FORMAT] = g_param_spec_string ( - "format", - "strftime format", - "strftime-style format string for the timestamp", - "%F %T", - prop_flags); +#include "idotimestampmenuitem.h" - g_object_class_install_properties (gobject_class, PROP_LAST, properties); -} - -static void -ido_appointment_menu_item_init (IdoAppointmentMenuItem *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - IDO_APPOINTMENT_MENU_ITEM_TYPE, - IdoAppointmentMenuItemPrivate); - -} - -/*** -**** -***/ - -/* creates a menu-sized pixbuf filled with specified color */ +/* create a menu-sized pixbuf filled with specified color */ static GdkPixbuf * create_color_icon_pixbuf (const char * color_spec) { @@ -239,103 +69,6 @@ create_color_icon_pixbuf (const char * color_spec) return pixbuf; } -static void -update_timestamp_label (IdoAppointmentMenuItem * self) -{ - char * str; - priv_t * p = self->priv; - - if (p->date_time && p->format) - str = g_date_time_format (p->date_time, p->format); - else - str = NULL; - - ido_basic_menu_item_set_secondary_text (IDO_BASIC_MENU_ITEM (self), str); - g_free (str); -} - -/*** -**** Public API -***/ - -/* create a new IdoAppointmentMenuItem */ -GtkWidget * -ido_appointment_menu_item_new (void) -{ - return GTK_WIDGET (g_object_new (IDO_APPOINTMENT_MENU_ITEM_TYPE, NULL)); -} - -/** - * ido_appointment_menu_item_set_color: - * @color: parseable color string - * - * When this is set, the menuitem will include an icon with this color. - * - * These colors can be set in the end user's calendar app as a quick visual cue - * to show what kind of appointment this is. - */ -void -ido_appointment_menu_item_set_color (IdoAppointmentMenuItem * self, - const char * color_string) -{ - priv_t * p; - GdkPixbuf * pixbuf; - - g_return_if_fail (IDO_IS_APPOINTMENT_MENU_ITEM (self)); - p = self->priv; - - g_free (p->color_string); - p->color_string = g_strdup (color_string); - - pixbuf = create_color_icon_pixbuf (p->color_string); - ido_basic_menu_item_set_icon (IDO_BASIC_MENU_ITEM(self), G_ICON(pixbuf)); - g_object_unref (G_OBJECT(pixbuf)); -} - -/** - * ido_appointment_menu_item_set_time: - * @time: the time to be rendered in the appointment's timestamp label. - * - * Set the time that will be displayed in the menuitem's - * right-justified timestamp label - */ -void -ido_appointment_menu_item_set_time (IdoAppointmentMenuItem * self, - time_t time) -{ - priv_t * p; - - g_return_if_fail (IDO_IS_APPOINTMENT_MENU_ITEM (self)); - p = self->priv; - - g_clear_pointer (&p->date_time, g_date_time_unref); - p->date_time = g_date_time_new_from_unix_local (time); - update_timestamp_label (self); -} - -/** - * ido_appointment_menu_item_set_format: - * @format: the format string used when showing the appointment's time - * - * Set the format string for rendering the appointment's time - * in its right-justified secondary label. - * - * See strfrtime(3) for more information on the format string. - */ -void -ido_appointment_menu_item_set_format (IdoAppointmentMenuItem * self, - const char * strftime_fmt) -{ - priv_t * p; - - g_return_if_fail (IDO_IS_APPOINTMENT_MENU_ITEM (self)); - p = self->priv; - - g_free (p->format); - p->format = g_strdup (strftime_fmt); - update_timestamp_label (self); -} - /** * ido_appointment_menu_item_new_from_model: * @menu_item: the corresponding menuitem @@ -355,10 +88,10 @@ ido_appointment_menu_item_new_from_model (GMenuItem * menu_item, guint n; gint64 i64; gchar * str; - IdoAppointmentMenuItem * ido_appointment; + IdoBasicMenuItem * ido_menu_item; GParameter parameters[8]; - /* create the ido_appointment */ + /* create the ido_menu_item */ n = 0; @@ -372,10 +105,11 @@ ido_appointment_menu_item_new_from_model (GMenuItem * menu_item, if (g_menu_item_get_attribute (menu_item, "x-canonical-color", "s", &str)) { - GParameter p = { "color", G_VALUE_INIT }; - g_value_init (&p.value, G_TYPE_STRING); - g_value_take_string (&p.value, str); + GParameter p = { "icon", G_VALUE_INIT }; + g_value_init (&p.value, G_TYPE_OBJECT); + g_value_take_object (&p.value, create_color_icon_pixbuf (str)); parameters[n++] = p; + g_free (str); } if (g_menu_item_get_attribute (menu_item, "x-canonical-time-format", "s", &str)) @@ -388,14 +122,14 @@ ido_appointment_menu_item_new_from_model (GMenuItem * menu_item, if (g_menu_item_get_attribute (menu_item, "x-canonical-time", "x", &i64)) { - GParameter p = { "time", G_VALUE_INIT }; - g_value_init (&p.value, G_TYPE_INT64); - g_value_set_int64 (&p.value, i64); + GParameter p = { "date-time", G_VALUE_INIT }; + g_value_init (&p.value, G_TYPE_DATE_TIME); + g_value_take_boxed (&p.value, g_date_time_new_from_unix_local (i64)); parameters[n++] = p; } g_assert (n <= G_N_ELEMENTS (parameters)); - ido_appointment = g_object_newv (IDO_APPOINTMENT_MENU_ITEM_TYPE, n, parameters); + ido_menu_item = g_object_newv (IDO_TYPE_TIME_STAMP_MENU_ITEM, n, parameters); for (i=0; i<n; i++) g_value_unset (¶meters[i].value); @@ -410,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 5317253..6889fa7 100644 --- a/src/idoappointmentmenuitem.h +++ b/src/idoappointmentmenuitem.h @@ -20,58 +20,13 @@ #ifndef __IDO_APPOINTMENT_MENU_ITEM_H__ #define __IDO_APPOINTMENT_MENU_ITEM_H__ -#include <time.h> /* time_t */ - #include <gtk/gtk.h> -#include "idobasicmenuitem.h" G_BEGIN_DECLS -#define IDO_APPOINTMENT_MENU_ITEM_TYPE (ido_appointment_menu_item_get_type ()) -#define IDO_APPOINTMENT_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_APPOINTMENT_MENU_ITEM_TYPE, IdoAppointmentMenuItem)) -#define IDO_IS_APPOINTMENT_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_APPOINTMENT_MENU_ITEM_TYPE)) - -typedef struct _IdoAppointmentMenuItem IdoAppointmentMenuItem; -typedef struct _IdoAppointmentMenuItemClass IdoAppointmentMenuItemClass; -typedef struct _IdoAppointmentMenuItemPrivate IdoAppointmentMenuItemPrivate; - -struct _IdoAppointmentMenuItemClass -{ - IdoBasicMenuItemClass parent_class; -}; - -/** - * A menuitem that indicates a appointment. - * - * It contains a color-coded icon to indicate the appointment type, - * a primary label showing the appointment summary, - * and a right-justified secondary label telling when the appointment begins. - */ -struct _IdoAppointmentMenuItem -{ - /*< private >*/ - IdoBasicMenuItem parent; - IdoAppointmentMenuItemPrivate * priv; -}; - - -GType ido_appointment_menu_item_get_type (void) G_GNUC_CONST; - -GtkWidget * ido_appointment_menu_item_new (void); - GtkMenuItem * ido_appointment_menu_item_new_from_model (GMenuItem * menuitem, GActionGroup * actions); -void ido_appointment_menu_item_set_time (IdoAppointmentMenuItem * menuitem, - time_t time); - -void ido_appointment_menu_item_set_color (IdoAppointmentMenuItem * menuitem, - const char * color_str); - -void ido_appointment_menu_item_set_format (IdoAppointmentMenuItem * menuitem, - const char * strftime_fmt); - - G_END_DECLS #endif |