aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libqmenumodel/src/gtk/gtkmenutrackeritem.c43
-rw-r--r--libqmenumodel/src/gtk/gtkmenutrackeritem.h8
-rw-r--r--libqmenumodel/src/unitymenuaction.h11
-rw-r--r--libqmenumodel/src/unitymenumodel.cpp52
-rw-r--r--libqmenumodel/src/unitymenumodel.h3
5 files changed, 99 insertions, 18 deletions
diff --git a/libqmenumodel/src/gtk/gtkmenutrackeritem.c b/libqmenumodel/src/gtk/gtkmenutrackeritem.c
index fb856c9..e2ed1f0 100644
--- a/libqmenumodel/src/gtk/gtkmenutrackeritem.c
+++ b/libqmenumodel/src/gtk/gtkmenutrackeritem.c
@@ -106,6 +106,7 @@ enum {
PROP_TOGGLED,
PROP_ACCEL,
PROP_SUBMENU_SHOWN,
+ PROP_ACTION_NAME,
PROP_ACTION_STATE,
N_PROPS
};
@@ -179,6 +180,8 @@ 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_NAME:
+ g_value_set_string (value, gtk_menu_tracker_item_get_action_name (self));
case PROP_ACTION_STATE:
g_value_set_variant (value, self->action_state);
break;
@@ -239,6 +242,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_NAME] =
+ g_param_spec_boolean ("action-name", "", "", 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);
@@ -612,6 +617,22 @@ gtk_menu_tracker_item_get_submenu_shown (GtkMenuTrackerItem *self)
return self->submenu_shown;
}
+/**
+ * gtk_menu_tracker_item_get_action_name:
+ * @self: A #GtkMenuTrackerItem instance
+ *
+ * Returns the action name
+ */
+const gchar *
+gtk_menu_tracker_item_get_action_name (GtkMenuTrackerItem *self)
+{
+ const gchar *action_name = NULL;
+
+ g_menu_item_get_attribute (self->item, G_MENU_ATTRIBUTE_ACTION, "&s", &action_name);
+
+ return action_name;
+}
+
GVariant *
gtk_menu_tracker_item_get_action_state (GtkMenuTrackerItem *self)
{
@@ -661,6 +682,28 @@ gtk_menu_tracker_item_activated (GtkMenuTrackerItem *self)
g_variant_unref (action_target);
}
+void
+gtk_menu_tracker_item_change_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 16c4415..59a7080 100644
--- a/libqmenumodel/src/gtk/gtkmenutrackeritem.h
+++ b/libqmenumodel/src/gtk/gtkmenutrackeritem.h
@@ -76,11 +76,19 @@ gboolean gtk_menu_tracker_item_get_should_request_show (GtkMenu
void gtk_menu_tracker_item_activated (GtkMenuTrackerItem *self);
+void gtk_menu_tracker_item_change_state (GtkMenuTrackerItem *self,
+ GVariant *value);
+
+
+
+
void gtk_menu_tracker_item_request_submenu_shown (GtkMenuTrackerItem *self,
gboolean shown);
gboolean gtk_menu_tracker_item_get_submenu_shown (GtkMenuTrackerItem *self);
+const gchar * gtk_menu_tracker_item_get_action_name (GtkMenuTrackerItem *self);
+
GVariant * gtk_menu_tracker_item_get_action_state (GtkMenuTrackerItem *self);
gboolean gtk_menu_tracker_item_get_attribute (GtkMenuTrackerItem *self,
diff --git a/libqmenumodel/src/unitymenuaction.h b/libqmenumodel/src/unitymenuaction.h
index 26be02b..ef844fd 100644
--- a/libqmenumodel/src/unitymenuaction.h
+++ b/libqmenumodel/src/unitymenuaction.h
@@ -29,7 +29,8 @@ class UnityMenuModel;
class UnityMenuAction : public QObject
{
Q_OBJECT
- Q_PROPERTY(QVariant state READ state WRITE updateState NOTIFY stateChanged)
+ Q_PROPERTY(QVariant name READ name NOTIFY nameChanged)
+ Q_PROPERTY(QVariant state READ state WRITE changeState NOTIFY stateChanged)
Q_PROPERTY(int index READ index WRITE setIndex NOTIFY indexChanged)
Q_PROPERTY(UnityMenuModel* model READ model WRITE setModel NOTIFY modelChanged)
public:
@@ -41,10 +42,16 @@ public:
UnityMenuModel* model() const;
void setModel(UnityMenuModel* model);
+ 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 changeState(const QVariant& vvalue) = 0;
Q_SIGNALS:
+ void nameChanged();
void stateChanged();
void indexChanged(int index);
void modelChanged(UnityMenuModel* model);
diff --git a/libqmenumodel/src/unitymenumodel.cpp b/libqmenumodel/src/unitymenumodel.cpp
index 72a5985..c7afa2c 100644
--- a/libqmenumodel/src/unitymenumodel.cpp
+++ b/libqmenumodel/src/unitymenumodel.cpp
@@ -86,15 +86,45 @@ public:
setIndex(index);
}
+ virtual QString name() const {
+ 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 changeState(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_change_state (item, data);
+ g_variant_unref(data);
+ }
private:
UnityMenuModelPrivate* d;
@@ -504,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;
@@ -534,6 +556,10 @@ static QVariant attributeToQVariant(GVariant *value, const QString &type)
if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
result = QVariant(g_variant_get_string(value, NULL));
}
+ if (type == "double") {
+ if (g_variant_is_of_type (value, G_VARIANT_TYPE_DOUBLE))
+ result = QVariant(g_variant_get_double(value));
+ }
else if (type == "icon") {
GIcon *icon = g_icon_deserialize (value);
if (icon) {
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;