aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/unityqmlmenumodel.qml22
-rw-r--r--libqmenumodel/src/gtk/gtkmenutrackeritem.c36
-rw-r--r--libqmenumodel/src/gtk/gtkmenutrackeritem.h2
-rw-r--r--libqmenumodel/src/unitymenumodel.cpp25
4 files changed, 75 insertions, 10 deletions
diff --git a/examples/unityqmlmenumodel.qml b/examples/unityqmlmenumodel.qml
index 8028674..e1de3c8 100644
--- a/examples/unityqmlmenumodel.qml
+++ b/examples/unityqmlmenumodel.qml
@@ -63,13 +63,21 @@ Item {
Component {
id: slider
- Row {
- anchors.fill: parent
- Image {
- source: ext.minIcon
- }
- Image {
- source: ext.maxIcon
+ Rectangle {
+ width: listview.width
+ color: "#ddd"
+ height: 40
+ Row {
+ anchors.fill: parent
+ Image {
+ source: ext.minIcon
+ }
+ Text {
+ text: model.actionState
+ }
+ Image {
+ source: ext.maxIcon
+ }
}
}
}
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;
}