diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-07-26 15:04:50 +0200 |
---|---|---|
committer | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-07-26 15:04:50 +0200 |
commit | d57caa61f787c4bd7cb0823eadbbc5d84f542f0a (patch) | |
tree | e29cdf2e161a31a5c79bc1ad854e5ba2a74ded33 /libqmenumodel | |
parent | 58afcb80014d14ab95a031e19bdc11664c8a1d5b (diff) | |
download | qmenumodel-d57caa61f787c4bd7cb0823eadbbc5d84f542f0a.tar.gz qmenumodel-d57caa61f787c4bd7cb0823eadbbc5d84f542f0a.tar.bz2 qmenumodel-d57caa61f787c4bd7cb0823eadbbc5d84f542f0a.zip |
Expose the state of a menu item's action in model.actionState
Diffstat (limited to 'libqmenumodel')
-rw-r--r-- | libqmenumodel/src/gtk/gtkmenutrackeritem.c | 36 | ||||
-rw-r--r-- | libqmenumodel/src/gtk/gtkmenutrackeritem.h | 2 | ||||
-rw-r--r-- | libqmenumodel/src/unitymenumodel.cpp | 25 |
3 files changed, 60 insertions, 3 deletions
diff --git a/libqmenumodel/src/gtk/gtkmenutrackeritem.c b/libqmenumodel/src/gtk/gtkmenutrackeritem.c index 356422d..fb856c9 100644 --- a/libqmenumodel/src/gtk/gtkmenutrackeritem.c +++ b/libqmenumodel/src/gtk/gtkmenutrackeritem.c @@ -91,6 +91,7 @@ struct _GtkMenuTrackerItem guint toggled : 1; guint submenu_shown : 1; guint submenu_requested : 1; + GVariant *action_state; }; enum { @@ -105,6 +106,7 @@ enum { PROP_TOGGLED, PROP_ACCEL, PROP_SUBMENU_SHOWN, + PROP_ACTION_STATE, N_PROPS }; @@ -177,6 +179,9 @@ gtk_menu_tracker_item_get_property (GObject *object, case PROP_SUBMENU_SHOWN: g_value_set_boolean (value, gtk_menu_tracker_item_get_submenu_shown (self)); break; + case PROP_ACTION_STATE: + g_value_set_variant (value, self->action_state); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -193,6 +198,9 @@ gtk_menu_tracker_item_finalize (GObject *object) if (self->observable) g_object_unref (self->observable); + if (self->action_state) + g_variant_unref (self->action_state); + g_object_unref (self->item); G_OBJECT_CLASS (gtk_menu_tracker_item_parent_class)->finalize (object); @@ -231,6 +239,8 @@ gtk_menu_tracker_item_class_init (GtkMenuTrackerItemClass *class) g_param_spec_string ("accel", "", "", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE); gtk_menu_tracker_item_pspecs[PROP_SUBMENU_SHOWN] = g_param_spec_boolean ("submenu-shown", "", "", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE); + gtk_menu_tracker_item_pspecs[PROP_ACTION_STATE] = + g_param_spec_boolean ("action-state", "", "", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE); g_object_class_install_properties (class, N_PROPS, gtk_menu_tracker_item_pspecs); } @@ -284,6 +294,12 @@ gtk_menu_tracker_item_action_added (GtkActionObserver *observer, if (self->role != GTK_MENU_TRACKER_ITEM_ROLE_NORMAL) g_object_notify_by_pspec (G_OBJECT (self), gtk_menu_tracker_item_pspecs[PROP_ROLE]); + if (state != NULL) + { + self->action_state = g_variant_ref (state); + g_object_notify_by_pspec (G_OBJECT (self), gtk_menu_tracker_item_pspecs[PROP_ACTION_STATE]); + } + g_object_thaw_notify (G_OBJECT (self)); if (action_target) @@ -339,6 +355,11 @@ gtk_menu_tracker_item_action_state_changed (GtkActionObserver *observer, if (self->toggled != was_toggled) g_object_notify_by_pspec (G_OBJECT (self), gtk_menu_tracker_item_pspecs[PROP_TOGGLED]); + + if (self->action_state) + g_variant_unref (self->action_state); + self->action_state = g_variant_ref (state); + g_object_notify_by_pspec (G_OBJECT (self), gtk_menu_tracker_item_pspecs[PROP_ACTION_STATE]); } static void @@ -371,6 +392,12 @@ gtk_menu_tracker_item_action_removed (GtkActionObserver *observer, g_object_notify_by_pspec (G_OBJECT (self), gtk_menu_tracker_item_pspecs[PROP_ROLE]); } + if (self->action_state != NULL) + { + g_variant_unref (self->action_state); + g_object_notify_by_pspec (G_OBJECT (self), gtk_menu_tracker_item_pspecs[PROP_ACTION_STATE]); + } + g_object_thaw_notify (G_OBJECT (self)); } @@ -585,6 +612,15 @@ gtk_menu_tracker_item_get_submenu_shown (GtkMenuTrackerItem *self) return self->submenu_shown; } +GVariant * +gtk_menu_tracker_item_get_action_state (GtkMenuTrackerItem *self) +{ + if (self->action_state != NULL) + return g_variant_ref (self->action_state); + + return NULL; +} + static void gtk_menu_tracker_item_set_submenu_shown (GtkMenuTrackerItem *self, gboolean submenu_shown) diff --git a/libqmenumodel/src/gtk/gtkmenutrackeritem.h b/libqmenumodel/src/gtk/gtkmenutrackeritem.h index 7e98a55..16c4415 100644 --- a/libqmenumodel/src/gtk/gtkmenutrackeritem.h +++ b/libqmenumodel/src/gtk/gtkmenutrackeritem.h @@ -81,6 +81,8 @@ void gtk_menu_tracker_item_request_submenu_shown (GtkMenu gboolean gtk_menu_tracker_item_get_submenu_shown (GtkMenuTrackerItem *self); +GVariant * gtk_menu_tracker_item_get_action_state (GtkMenuTrackerItem *self); + gboolean gtk_menu_tracker_item_get_attribute (GtkMenuTrackerItem *self, const gchar *attribute, const gchar *format, diff --git a/libqmenumodel/src/unitymenumodel.cpp b/libqmenumodel/src/unitymenumodel.cpp index 418de61..114c985 100644 --- a/libqmenumodel/src/unitymenumodel.cpp +++ b/libqmenumodel/src/unitymenumodel.cpp @@ -17,6 +17,7 @@ */ #include "unitymenumodel.h" +#include "converter.h" extern "C" { #include "gtk/gtkactionmuxer.h" @@ -29,13 +30,13 @@ G_DEFINE_QUARK (UNITY_MENU_ITEM_ITERATOR, unity_menu_item_iterator) G_DEFINE_QUARK (UNITY_MENU_ITEM_EXTENDED_ATTRIBUTES, unity_menu_item_extended_attributes) enum MenuRoles { - ActionRole = Qt::DisplayRole + 1, - LabelRole, + LabelRole = Qt::DisplayRole + 1, SensitiveRole, IsSeparatorRole, IconRole, TypeRole, ExtendedAttributesRole, + ActionStateRole }; class UnityMenuModelPrivate @@ -48,6 +49,7 @@ public: void clearName(); void updateActions(); void updateMenuModel(); + QVariant itemState(GtkMenuTrackerItem *item); UnityMenuModel *model; GtkActionMuxer *muxer; @@ -161,6 +163,19 @@ void UnityMenuModelPrivate::updateMenuModel() } } +QVariant UnityMenuModelPrivate::itemState(GtkMenuTrackerItem *item) +{ + QVariant result; + + GVariant *state = gtk_menu_tracker_item_get_action_state (item); + if (state != NULL) { + result = Converter::toQVariant(state); + g_variant_unref (state); + } + + return result; +} + void UnityMenuModelPrivate::nameAppeared(GDBusConnection *connection, const gchar *name, const gchar *owner, gpointer user_data) { UnityMenuModelPrivate *priv = (UnityMenuModelPrivate *)user_data; @@ -367,6 +382,9 @@ QVariant UnityMenuModel::data(const QModelIndex &index, int role) const return map ? *map : QVariant(); } + case ActionStateRole: + return priv->itemState(item); + default: return QVariant(); } @@ -382,17 +400,18 @@ QModelIndex UnityMenuModel::parent(const QModelIndex &index) const return QModelIndex(); } +#include <QtDebug> QHash<int, QByteArray> UnityMenuModel::roleNames() const { QHash<int, QByteArray> names; names[LabelRole] = "label"; - names[ActionRole] = "action"; names[SensitiveRole] = "sensitive"; names[IsSeparatorRole] = "isSeparator"; names[IconRole] = "icon"; names[TypeRole] = "type"; names[ExtendedAttributesRole] = "ext"; + names[ActionStateRole] = "actionState"; return names; } |