aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel
diff options
context:
space:
mode:
authorNick Dedekind <nicholas.dedekind@gmail.com>2013-07-30 20:49:44 +0100
committerNick Dedekind <nicholas.dedekind@gmail.com>2013-07-30 20:49:44 +0100
commit37e62467aaa50babb48a45dcba8ab3ce5f5a7ec8 (patch)
tree8c280e13bf8e256ece6556a572cc964eba728750 /libqmenumodel
parent56374f1cfdbe68658a139cfad9dac8936f6ae60e (diff)
downloadqmenumodel-37e62467aaa50babb48a45dcba8ab3ce5f5a7ec8.tar.gz
qmenumodel-37e62467aaa50babb48a45dcba8ab3ce5f5a7ec8.tar.bz2
qmenumodel-37e62467aaa50babb48a45dcba8ab3ce5f5a7ec8.zip
Added menu action updateState
Diffstat (limited to 'libqmenumodel')
-rw-r--r--libqmenumodel/src/gtk/gtkmenutrackeritem.c21
-rw-r--r--libqmenumodel/src/gtk/gtkmenutrackeritem.h6
-rw-r--r--libqmenumodel/src/unitymenuaction.h5
-rw-r--r--libqmenumodel/src/unitymenumodel.cpp48
-rw-r--r--libqmenumodel/src/unitymenumodel.h3
5 files changed, 62 insertions, 21 deletions
diff --git a/libqmenumodel/src/gtk/gtkmenutrackeritem.c b/libqmenumodel/src/gtk/gtkmenutrackeritem.c
index c14bbb8..7187921 100644
--- a/libqmenumodel/src/gtk/gtkmenutrackeritem.c
+++ b/libqmenumodel/src/gtk/gtkmenutrackeritem.c
@@ -685,6 +685,27 @@ gtk_menu_tracker_item_activated (GtkMenuTrackerItem *self)
g_variant_unref (action_target);
}
+void
+gtk_menu_tracker_item_update_state (GtkMenuTrackerItem *self, GVariant *value)
+{
+ const gchar *action_name;
+
+ g_return_if_fail (GTK_IS_MENU_TRACKER_ITEM (self));
+
+ g_menu_item_get_attribute (self->item, G_MENU_ATTRIBUTE_ACTION, "&s", &action_name);
+
+ if (self->action_namespace)
+ {
+ gchar *full_action;
+
+ full_action = g_strjoin (".", self->action_namespace, action_name, NULL);
+ g_action_group_change_action_state (G_ACTION_GROUP (self->observable), full_action, g_variant_ref(value));
+ g_free (full_action);
+ }
+ else
+ g_action_group_change_action_state (G_ACTION_GROUP (self->observable), action_name, g_variant_ref(value));
+}
+
typedef struct
{
GtkMenuTrackerItem *item;
diff --git a/libqmenumodel/src/gtk/gtkmenutrackeritem.h b/libqmenumodel/src/gtk/gtkmenutrackeritem.h
index 8b0afae..f38d9fe 100644
--- a/libqmenumodel/src/gtk/gtkmenutrackeritem.h
+++ b/libqmenumodel/src/gtk/gtkmenutrackeritem.h
@@ -76,6 +76,12 @@ gboolean gtk_menu_tracker_item_get_should_request_show (GtkMenu
void gtk_menu_tracker_item_activated (GtkMenuTrackerItem *self);
+void gtk_menu_tracker_item_update_state (GtkMenuTrackerItem *self,
+ GVariant *value);
+
+
+
+
void gtk_menu_tracker_item_request_submenu_shown (GtkMenuTrackerItem *self,
gboolean shown);
diff --git a/libqmenumodel/src/unitymenuaction.h b/libqmenumodel/src/unitymenuaction.h
index 4dea311..ac5eadb 100644
--- a/libqmenumodel/src/unitymenuaction.h
+++ b/libqmenumodel/src/unitymenuaction.h
@@ -45,7 +45,10 @@ public:
virtual QString name() const = 0;
virtual QVariant state() const = 0;
- Q_INVOKABLE virtual void updateState(const QVariant& = QVariant()) = 0;
+
+ Q_INVOKABLE virtual void activate() = 0;
+
+ Q_INVOKABLE virtual void updateState(const QVariant& vvalue) = 0;
Q_SIGNALS:
void nameChanged();
diff --git a/libqmenumodel/src/unitymenumodel.cpp b/libqmenumodel/src/unitymenumodel.cpp
index 7c5d597..9cad955 100644
--- a/libqmenumodel/src/unitymenumodel.cpp
+++ b/libqmenumodel/src/unitymenumodel.cpp
@@ -87,22 +87,44 @@ public:
}
virtual QString name() const {
- GtkMenuTrackerItem* item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (d->items, index()));
- if (!item) {
- return "";
- }
+ GtkMenuTrackerItem* item;
+
+ item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (d->items, index()));
+ if (!item) return QString();
+
return gtk_menu_tracker_item_get_action_name(item);
}
virtual QVariant state() const {
- GtkMenuTrackerItem* item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (d->items, index()));
- if (!item) {
- return QVariant();
- }
+ GtkMenuTrackerItem* item;
+
+ item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (d->items, index()));
+ if (!item) return QVariant();
+
return d->itemState(item);
}
- virtual void updateState(const QVariant& param = QVariant()) { }
+ virtual void activate()
+ {
+ GtkMenuTrackerItem* item;
+
+ item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (d->items, index()));
+ if (!item) return;
+
+ gtk_menu_tracker_item_activated (item);
+ }
+
+ virtual void updateState(const QVariant& vvalue)
+ {
+ GtkMenuTrackerItem* item;
+
+ item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (d->items, index()));
+ if (!item) return;
+
+ GVariant* data = Converter::toGVariant(vvalue);
+ gtk_menu_tracker_item_update_state (item, data);
+ g_variant_unref(data);
+ }
private:
UnityMenuModelPrivate* d;
@@ -512,14 +534,6 @@ QObject * UnityMenuModel::submenu(int position, QQmlComponent* actionStateParser
return model;
}
-void UnityMenuModel::activate(int index)
-{
- GtkMenuTrackerItem *item;
-
- item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (priv->items, index));
- gtk_menu_tracker_item_activated (item);
-}
-
static void freeExtendedAttrs(gpointer data)
{
QVariantMap *extendedAttrs = (QVariantMap *) data;
diff --git a/libqmenumodel/src/unitymenumodel.h b/libqmenumodel/src/unitymenumodel.h
index ad409ba..5401331 100644
--- a/libqmenumodel/src/unitymenumodel.h
+++ b/libqmenumodel/src/unitymenumodel.h
@@ -64,9 +64,6 @@ Q_SIGNALS:
void menuObjectPathChanged(const QByteArray &path);
void actionStateParserChanged(ActionStateParser* parser);
-public Q_SLOTS:
- void activate(int index);
-
private:
class UnityMenuModelPrivate *priv;
friend class UnityMenuModelPrivate;