diff options
-rw-r--r-- | debian/libido3-0.1-0.symbols | 1 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/idobasicmenuitem.c | 127 | ||||
-rw-r--r-- | src/idobasicmenuitem.h | 9 | ||||
-rw-r--r-- | src/idomenuitemfactory.c | 4 | ||||
-rw-r--r-- | src/idoplaybackmenuitem.c | 88 | ||||
-rw-r--r-- | src/idoprogressmenuitem.c | 101 | ||||
-rw-r--r-- | src/idoprogressmenuitem.h | 28 |
8 files changed, 241 insertions, 119 deletions
diff --git a/debian/libido3-0.1-0.symbols b/debian/libido3-0.1-0.symbols index 8efde79..e1370ad 100644 --- a/debian/libido3-0.1-0.symbols +++ b/debian/libido3-0.1-0.symbols @@ -16,6 +16,7 @@ libido3-0.1.so.0 libido3-0.1-0 #MINVER# ido_basic_menu_item_set_icon_from_file@Base 13.10.0+13.10.20130731 ido_basic_menu_item_set_secondary_text@Base 13.10.0+13.10.20130731 ido_basic_menu_item_set_text@Base 13.10.0+13.10.20130731 + ido_basic_menu_item_new_from_model@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 diff --git a/src/Makefile.am b/src/Makefile.am index 3a3ea31..9b722cb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,6 +21,7 @@ sources_h = \ idousermenuitem.h \ idoappointmentmenuitem.h \ idobasicmenuitem.h \ + idoprogressmenuitem.h \ idotimestampmenuitem.h \ idolocationmenuitem.h \ idotimeline.h \ @@ -88,6 +89,7 @@ libido_0_1_la_SOURCES = \ idoplaybackmenuitem.c \ idoappointmentmenuitem.c \ idobasicmenuitem.c \ + idoprogressmenuitem.c \ idotimestampmenuitem.c \ idolocationmenuitem.c \ idoapplicationmenuitem.c \ diff --git a/src/idobasicmenuitem.c b/src/idobasicmenuitem.c index f07cc14..6185d23 100644 --- a/src/idobasicmenuitem.c +++ b/src/idobasicmenuitem.c @@ -245,17 +245,35 @@ ido_basic_menu_item_set_icon (IdoBasicMenuItem * self, GIcon * icon) if (p->icon != icon) { g_clear_object (&p->icon); + gtk_image_clear (GTK_IMAGE(p->image)); if (icon == NULL) { - gtk_image_clear (GTK_IMAGE(p->image)); gtk_widget_set_visible (p->image, FALSE); } else { + GtkIconInfo *info; + const gchar *filename; + 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); + + info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), p->icon, 16, 0); + filename = gtk_icon_info_get_filename (info); + + if (filename) + { + GdkPixbuf *pixbuf; + + pixbuf = gdk_pixbuf_new_from_file_at_scale (filename, -1, 16, TRUE, NULL); + gtk_image_set_from_pixbuf (GTK_IMAGE(p->image), pixbuf); + + g_object_unref (pixbuf); + } + + gtk_widget_set_visible (p->image, filename != NULL); + + g_object_unref (info); } } } @@ -306,86 +324,61 @@ ido_basic_menu_item_set_secondary_text (IdoBasicMenuItem * self, const char * se } } -/*** -**** -**** Progress Menu Item -**** -***/ - static void -on_progress_action_state_changed (IdoActionHelper * helper, - GVariant * state, - gpointer unused G_GNUC_UNUSED) +ido_basic_menu_item_activate (GtkMenuItem *item, + gpointer user_data) { - IdoBasicMenuItem * ido_menu_item; - char * str; - - ido_menu_item = IDO_BASIC_MENU_ITEM (ido_action_helper_get_widget (helper)); + IdoActionHelper *helper = user_data; - 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_action_helper_activate (helper); } -/** - * 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) +ido_basic_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 */; + GtkWidget *item; + gchar *label; + gchar *action; + GVariant *serialized_icon; - n = 0; + item = ido_basic_menu_item_new (); - if (g_menu_item_get_attribute (menu_item, "label", "s", &str)) + if (g_menu_item_get_attribute (menu_item, "label", "s", &label)) { - GParameter p = { "text", G_VALUE_INIT }; - g_value_init (&p.value, G_TYPE_STRING); - g_value_take_string (&p.value, str); - parameters[n++] = p; + ido_basic_menu_item_set_text (IDO_BASIC_MENU_ITEM (item), label); + g_free (label); } - g_assert (n <= G_N_ELEMENTS (parameters)); - ido_menu_item = g_object_newv (IDO_TYPE_BASIC_MENU_ITEM, n, parameters); + serialized_icon = g_menu_item_get_attribute_value (menu_item, "icon", NULL); + if (serialized_icon) + { + GIcon *icon; - for (i=0; i<n; i++) - g_value_unset (¶meters[i].value); + icon = g_icon_deserialize (serialized_icon); + ido_basic_menu_item_set_icon (IDO_BASIC_MENU_ITEM (item), icon); - /* give it an ActionHelper */ + g_object_unref (icon); + g_variant_unref (serialized_icon); + } - if (g_menu_item_get_attribute (menu_item, "action", "s", &str)) + if (g_menu_item_get_attribute (menu_item, "action", "s", &action)) { - 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); + IdoActionHelper *helper; + GVariant *target; + + target = g_menu_item_get_attribute_value (menu_item, "target", NULL); + + helper = ido_action_helper_new (item, actions, action, target); + g_signal_connect_object (item, "activate", + G_CALLBACK (ido_basic_menu_item_activate), helper, + 0); + g_signal_connect_swapped (item, "destroy", G_CALLBACK (g_object_unref), helper); + + if (target) + g_variant_unref (target); + g_free (action); } - return GTK_MENU_ITEM (ido_menu_item); + return GTK_MENU_ITEM (item); } diff --git a/src/idobasicmenuitem.h b/src/idobasicmenuitem.h index 01aa4b3..6a4b83a 100644 --- a/src/idobasicmenuitem.h +++ b/src/idobasicmenuitem.h @@ -64,13 +64,8 @@ void ido_basic_menu_item_set_text (IdoBasicMenuItem * self, 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); - +GtkMenuItem * ido_basic_menu_item_new_from_model (GMenuItem * menuitem, + GActionGroup * actions); G_END_DECLS diff --git a/src/idomenuitemfactory.c b/src/idomenuitemfactory.c index 11beaa8..cb10cce 100644 --- a/src/idomenuitemfactory.c +++ b/src/idomenuitemfactory.c @@ -32,6 +32,7 @@ #include "idoapplicationmenuitem.h" #include "idosourcemenuitem.h" #include "idoswitchmenuitem.h" +#include "idoprogressmenuitem.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)) @@ -74,6 +75,9 @@ ido_menu_item_factory_create_menu_item (UbuntuMenuItemFactory *factory, 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.basic")) + item = ido_basic_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); diff --git a/src/idoplaybackmenuitem.c b/src/idoplaybackmenuitem.c index 5fe8914..9d44b92 100644 --- a/src/idoplaybackmenuitem.c +++ b/src/idoplaybackmenuitem.c @@ -39,7 +39,8 @@ typedef enum BUTTON_NONE, BUTTON_PREVIOUS, BUTTON_PLAYPAUSE, - BUTTON_NEXT + BUTTON_NEXT, + N_BUTTONS } Button; typedef GtkMenuItemClass IdoPlaybackMenuItemClass; @@ -55,9 +56,7 @@ struct _IdoPlaybackMenuItem gboolean keyboard_activated; /* TRUE if the current button was activated with a key */ GActionGroup *action_group; - gchar *play_action; - gchar *next_action; - gchar *prev_action; + gchar *button_actions[N_BUTTONS]; }; G_DEFINE_TYPE (IdoPlaybackMenuItem, ido_playback_menu_item, GTK_TYPE_MENU_ITEM); @@ -82,10 +81,10 @@ static void ido_playback_menu_item_finalize (GObject *object) { IdoPlaybackMenuItem *item = IDO_PLAYBACK_MENU_ITEM (object); + gint i; - g_free (item->play_action); - g_free (item->next_action); - g_free (item->prev_action); + for (i = 0; i < N_BUTTONS; i++) + g_free (item->button_actions[i]); G_OBJECT_CLASS (ido_playback_menu_item_parent_class)->finalize (object); } @@ -129,20 +128,17 @@ ido_playback_menu_item_parent_key_press_event (GtkWidget *widget, { case GDK_KEY_Left: self->cur_pushed_button = BUTTON_PREVIOUS; - if (self->action_group && self->prev_action) - g_action_group_activate_action (self->action_group, self->prev_action, NULL); break; case GDK_KEY_Right: self->cur_pushed_button = BUTTON_NEXT; - if (self->action_group && self->next_action) - g_action_group_activate_action (self->action_group, self->next_action, NULL); break; case GDK_KEY_space: - self->cur_pushed_button = BUTTON_PLAYPAUSE; - if (self->action_group && self->play_action) - g_action_group_activate_action (self->action_group, self->play_action, NULL); + if (self->cur_hover_button != BUTTON_NONE) + self->cur_pushed_button = self->cur_hover_button; + else + self->cur_pushed_button = BUTTON_PLAYPAUSE; break; default: @@ -151,6 +147,11 @@ ido_playback_menu_item_parent_key_press_event (GtkWidget *widget, if (self->cur_pushed_button != BUTTON_NONE) { + const gchar *action = self->button_actions[self->cur_pushed_button]; + + if (self->action_group && action) + g_action_group_activate_action (self->action_group, action, NULL); + self->keyboard_activated = TRUE; gtk_widget_queue_draw (widget); return TRUE; @@ -243,31 +244,15 @@ ido_playback_menu_item_button_release_event (GtkWidget *menuitem, { IdoPlaybackMenuItem *item = IDO_PLAYBACK_MENU_ITEM (menuitem); Button button; + const gchar *action = action; button = ido_playback_menu_item_get_button_at_pos (event->x, event->y); if (button != item->cur_pushed_button) button = BUTTON_NONE; - switch (button) - { - case BUTTON_NONE: - break; - - case BUTTON_PREVIOUS: - if (item->action_group && item->prev_action) - g_action_group_activate_action (item->action_group, item->prev_action, NULL); - break; - - case BUTTON_NEXT: - if (item->action_group && item->next_action) - g_action_group_activate_action (item->action_group, item->next_action, NULL); - break; - - case BUTTON_PLAYPAUSE: - if (item->action_group && item->play_action) - g_action_group_activate_action (item->action_group, item->play_action, NULL); - break; - } + action = item->button_actions[item->cur_pushed_button]; + if (item->action_group && action) + g_action_group_activate_action (item->action_group, action, NULL); item->cur_pushed_button = BUTTON_NONE; gtk_widget_queue_draw (menuitem); @@ -363,12 +348,14 @@ ido_playback_menu_item_action_added (GActionGroup *action_group, gpointer user_data) { IdoPlaybackMenuItem *self = user_data; + const gchar *action; - if (self->play_action && g_str_equal (action_name, self->play_action)) + action = self->button_actions[BUTTON_PLAYPAUSE]; + if (action && g_str_equal (action_name, action)) { GVariant *state; - state = g_action_group_get_action_state (action_group, self->play_action); + state = g_action_group_get_action_state (action_group, action); if (g_variant_is_of_type (state, G_VARIANT_TYPE_STRING)) ido_playback_menu_item_set_state_from_string (self, g_variant_get_string (state, NULL)); @@ -382,8 +369,10 @@ ido_playback_menu_item_action_removed (GActionGroup *action_group, gpointer user_data) { IdoPlaybackMenuItem *self = user_data; + const gchar *action; - if (self->play_action && g_str_equal (action_name, self->play_action)) + action = self->button_actions[BUTTON_PLAYPAUSE]; + if (action && g_str_equal (action_name, action)) ido_playback_menu_item_set_state (self, STATE_PAUSED); } @@ -394,10 +383,13 @@ ido_playback_menu_item_action_state_changed (GActionGroup *action_group, gpointer user_data) { IdoPlaybackMenuItem *self = user_data; + const gchar *action; g_return_if_fail (action_name != NULL); - if (self->play_action && g_str_equal (action_name, self->play_action)) + action = self->button_actions[BUTTON_PLAYPAUSE]; + + if (action && g_str_equal (action_name, action)) { if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) ido_playback_menu_item_set_state_from_string (self, g_variant_get_string (value, NULL)); @@ -409,6 +401,7 @@ ido_playback_menu_item_new_from_model (GMenuItem *item, GActionGroup *actions) { IdoPlaybackMenuItem *widget; + gchar *play_action; widget = g_object_new (IDO_TYPE_PLAYBACK_MENU_ITEM, NULL); @@ -417,12 +410,13 @@ ido_playback_menu_item_new_from_model (GMenuItem *item, g_signal_connect (actions, "action-added", G_CALLBACK (ido_playback_menu_item_action_added), widget); g_signal_connect (actions, "action-removed", G_CALLBACK (ido_playback_menu_item_action_removed), widget); - g_menu_item_get_attribute (item, "x-canonical-play-action", "s", &widget->play_action); - g_menu_item_get_attribute (item, "x-canonical-next-action", "s", &widget->next_action); - g_menu_item_get_attribute (item, "x-canonical-previous-action", "s", &widget->prev_action); + g_menu_item_get_attribute (item, "x-canonical-play-action", "s", &widget->button_actions[BUTTON_PLAYPAUSE]); + g_menu_item_get_attribute (item, "x-canonical-next-action", "s", &widget->button_actions[BUTTON_NEXT]); + g_menu_item_get_attribute (item, "x-canonical-previous-action", "s", &widget->button_actions[BUTTON_PREVIOUS]); - if (widget->play_action && g_action_group_has_action (actions, widget->play_action)) - ido_playback_menu_item_action_added (actions, widget->play_action, widget); + play_action = widget->button_actions[BUTTON_PLAYPAUSE]; + if (play_action && g_action_group_has_action (actions, play_action)) + ido_playback_menu_item_action_added (actions, play_action, widget); return GTK_MENU_ITEM (widget); } @@ -1434,7 +1428,8 @@ ido_playback_menu_item_draw (GtkWidget* button, cairo_t *cr) } // draw previous-button drop-shadow - if (item->cur_pushed_button == BUTTON_PREVIOUS && item->keyboard_activated ) + if ((item->cur_pushed_button == BUTTON_PREVIOUS && item->keyboard_activated) || + item->cur_hover_button == BUTTON_PREVIOUS) { _setup (&cr_surf, &surf, PREV_WIDTH+6, PREV_HEIGHT+6); _mask_prev (cr_surf, @@ -1494,7 +1489,8 @@ ido_playback_menu_item_draw (GtkWidget* button, cairo_t *cr) _finalize (cr, &cr_surf, &surf, PREV_X, PREV_Y); // draw next-button drop-shadow - if (item->cur_pushed_button == BUTTON_NEXT && item->keyboard_activated) + if ((item->cur_pushed_button == BUTTON_NEXT && item->keyboard_activated) || + item->cur_hover_button == BUTTON_NEXT) { _setup (&cr_surf, &surf, NEXT_WIDTH+6, NEXT_HEIGHT+6); _mask_next (cr_surf, @@ -1557,6 +1553,7 @@ ido_playback_menu_item_draw (GtkWidget* button, cairo_t *cr) if (item->current_state == STATE_PLAYING) { if (item->has_focus && + (item->cur_hover_button == BUTTON_NONE || item->cur_hover_button == BUTTON_PLAYPAUSE) && (item->cur_pushed_button == BUTTON_NONE || item->cur_pushed_button == BUTTON_PLAYPAUSE)) { _setup (&cr_surf, &surf, PAUSE_WIDTH+6, PAUSE_HEIGHT+6); @@ -1619,6 +1616,7 @@ ido_playback_menu_item_draw (GtkWidget* button, cairo_t *cr) else if (item->current_state == STATE_PAUSED) { if (item->has_focus && + (item->cur_hover_button == BUTTON_NONE || item->cur_hover_button == BUTTON_PLAYPAUSE) && (item->cur_pushed_button == BUTTON_NONE || item->cur_pushed_button == BUTTON_PLAYPAUSE)) { _setup (&cr_surf, &surf, PLAY_WIDTH+6, PLAY_HEIGHT+6); diff --git a/src/idoprogressmenuitem.c b/src/idoprogressmenuitem.c new file mode 100644 index 0000000..9d456b8 --- /dev/null +++ b/src/idoprogressmenuitem.c @@ -0,0 +1,101 @@ +/** + * 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/>. + */ + +#include "idoprogressmenuitem.h" +#include "idobasicmenuitem.h" +#include "idoactionhelper.h" + +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 (¶meters[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/idoprogressmenuitem.h b/src/idoprogressmenuitem.h new file mode 100644 index 0000000..3b0028b --- /dev/null +++ b/src/idoprogressmenuitem.h @@ -0,0 +1,28 @@ +/** + * 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_PROGRESS_MENU_ITEM_H__ +#define __IDO_PROGRESS_MENU_ITEM_H__ + +#include <gtk/gtk.h> + +GtkMenuItem * ido_progress_menu_item_new_from_model (GMenuItem * menuitem, + GActionGroup * actions); + +#endif |