diff options
-rw-r--r-- | libqmenumodel/src/unitymenuaction.h | 2 | ||||
-rw-r--r-- | libqmenumodel/src/unitymenumodel.cpp | 33 | ||||
-rw-r--r-- | libqmenumodel/src/unitymenumodel.h | 1 |
3 files changed, 29 insertions, 7 deletions
diff --git a/libqmenumodel/src/unitymenuaction.h b/libqmenumodel/src/unitymenuaction.h index ef844fd..bcbb50d 100644 --- a/libqmenumodel/src/unitymenuaction.h +++ b/libqmenumodel/src/unitymenuaction.h @@ -46,7 +46,7 @@ public: virtual QVariant state() const = 0; - Q_INVOKABLE virtual void activate() = 0; + Q_INVOKABLE virtual void activate(const QVariant ¶meter) = 0; Q_INVOKABLE virtual void changeState(const QVariant& vvalue) = 0; diff --git a/libqmenumodel/src/unitymenumodel.cpp b/libqmenumodel/src/unitymenumodel.cpp index 8e0f0d1..8045d57 100644 --- a/libqmenumodel/src/unitymenumodel.cpp +++ b/libqmenumodel/src/unitymenumodel.cpp @@ -42,7 +42,9 @@ enum MenuRoles { IconRole, TypeRole, ExtendedAttributesRole, - ActionRole + ActionRole, + IsCheckRole, + IsRadioRole }; class UnityMenuModelPrivate @@ -106,14 +108,18 @@ public: return d->itemState(item); } - virtual void activate() + virtual void activate(const QVariant ¶meter) { GtkMenuTrackerItem* item; + gchar *action; item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (d->items, index())); if (!item) return; - gtk_menu_tracker_item_activated (item); + gtk_menu_tracker_item_get_attribute (item, "action", "s", &action); + g_action_group_activate_action (G_ACTION_GROUP (d->muxer), action, Converter::toGVariant(parameter)); + + g_free (action); } virtual void changeState(const QVariant& vvalue) @@ -278,7 +284,6 @@ void UnityMenuModelPrivate::menuItemChanged(GObject *object, GParamSpec *pspec, model = (UnityMenuModel *) g_object_get_qdata (G_OBJECT (item), unity_menu_model_quark ()); position = g_sequence_iter_get_position (it); - // FIXME UnityMenuModelDataChangeEvent ummdce(position); QCoreApplication::sendEvent(model, &ummdce); } @@ -416,10 +421,10 @@ QVariant UnityMenuModel::data(const QModelIndex &index, int role) const return gtk_menu_tracker_item_get_label (item); case SensitiveRole: - return gtk_menu_tracker_item_get_sensitive (item); + return gtk_menu_tracker_item_get_sensitive (item) == TRUE ? true : false; case IsSeparatorRole: - return gtk_menu_tracker_item_get_is_separator (item); + return gtk_menu_tracker_item_get_is_separator (item) == TRUE ? true : false; case IconRole: { GIcon *icon = gtk_menu_tracker_item_get_icon (item); @@ -451,6 +456,12 @@ QVariant UnityMenuModel::data(const QModelIndex &index, int role) const case ActionRole: return QVariant::fromValue(new UnityGtkMenuTrackerItemAction(index.row(), priv)); + case IsCheckRole: + return gtk_menu_tracker_item_get_role (item) == GTK_MENU_TRACKER_ITEM_ROLE_CHECK; + + case IsRadioRole: + return gtk_menu_tracker_item_get_role (item) == GTK_MENU_TRACKER_ITEM_ROLE_RADIO; + default: return QVariant(); } @@ -478,6 +489,8 @@ QHash<int, QByteArray> UnityMenuModel::roleNames() const names[TypeRole] = "type"; names[ExtendedAttributesRole] = "ext"; names[ActionRole] = "action"; + names[IsCheckRole] = "isCheck"; + names[IsRadioRole] = "isRadio"; return names; } @@ -623,6 +636,14 @@ QVariant UnityMenuModel::get(int row, const QByteArray &role) return this->data(this->index(row, 0), priv->roles[role]); } +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); +} + bool UnityMenuModel::event(QEvent* e) { if (e->type() == UnityMenuModelClearEvent::eventType) { diff --git a/libqmenumodel/src/unitymenumodel.h b/libqmenumodel/src/unitymenumodel.h index 4aaadfd..5cce732 100644 --- a/libqmenumodel/src/unitymenumodel.h +++ b/libqmenumodel/src/unitymenumodel.h @@ -57,6 +57,7 @@ public: Q_INVOKABLE QObject * submenu(int position, QQmlComponent* actionStateParser = NULL); Q_INVOKABLE bool loadExtendedAttributes(int position, const QVariantMap &schema); Q_INVOKABLE QVariant get(int row, const QByteArray &role); + Q_INVOKABLE void activate(int index); Q_SIGNALS: void busNameChanged(const QByteArray &name); |