aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel/src
diff options
context:
space:
mode:
Diffstat (limited to 'libqmenumodel/src')
-rw-r--r--libqmenumodel/src/CMakeLists.txt2
-rw-r--r--libqmenumodel/src/unitymenuaction.cpp60
-rw-r--r--libqmenumodel/src/unitymenuaction.h66
-rw-r--r--libqmenumodel/src/unitymenumodel.cpp94
-rw-r--r--libqmenumodel/src/unitymenumodel.h4
5 files changed, 34 insertions, 192 deletions
diff --git a/libqmenumodel/src/CMakeLists.txt b/libqmenumodel/src/CMakeLists.txt
index db8095a..ad7c6ab 100644
--- a/libqmenumodel/src/CMakeLists.txt
+++ b/libqmenumodel/src/CMakeLists.txt
@@ -10,7 +10,6 @@ set(QMENUMODEL_SRC
qdbusmenumodel.cpp
qdbusactiongroup.cpp
qstateaction.cpp
- unitymenuaction.cpp
unitymenumodel.cpp
unitymenumodelevents.cpp
unitythemediconprovider.cpp
@@ -59,7 +58,6 @@ set(QMENUMODEL_HEADERS
qdbusobject.h
qmenumodel.h
qstateaction.h
- unitymenuaction.h
unitymenumodel.h
unitythemediconprovider.h
)
diff --git a/libqmenumodel/src/unitymenuaction.cpp b/libqmenumodel/src/unitymenuaction.cpp
deleted file mode 100644
index f391bfe..0000000
--- a/libqmenumodel/src/unitymenuaction.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2013 Canonical Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * Authors:
- * Nick Dedekind <nick.dedekind@canonical.com>
- */
-
-#include "unitymenuaction.h"
-#include "unitymenumodel.h"
-
-UnityMenuAction::UnityMenuAction(QObject* parent)
- : QObject(parent),
- m_model(NULL),
- m_index(-1)
-{
-}
-
-int UnityMenuAction::index() const
-{
- return m_index;
-}
-
-void UnityMenuAction::setIndex(int index)
-{
- if (m_index != index) {
- m_index = index;
- Q_EMIT indexChanged(index);
- }
-}
-
-UnityMenuModel* UnityMenuAction::model() const
-{
- return m_model;
-}
-
-void UnityMenuAction::setModel(UnityMenuModel* model)
-{
- if (m_model != model) {
- if (m_model) {
- disconnect(m_model);
- }
- m_model = model;
-
- connect(model, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)), SIGNAL(stateChanged()));
-
- Q_EMIT modelChanged(model);
- }
-}
diff --git a/libqmenumodel/src/unitymenuaction.h b/libqmenumodel/src/unitymenuaction.h
deleted file mode 100644
index bcbb50d..0000000
--- a/libqmenumodel/src/unitymenuaction.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2013 Canonical Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * Authors:
- * Nick Dedekind <nick.dedekind@canonical.com>
- */
-
-#ifndef UNITYMENUACTION_H
-#define UNITYMENUACTION_H
-
-#include <QObject>
-#include <QVariant>
-
-typedef struct _GVariant GVariant;
-class UnityMenuModel;
-
-class UnityMenuAction : public QObject
-{
- Q_OBJECT
- 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:
- UnityMenuAction(QObject* parent=0);
-
- int index() const;
- void setIndex(int index);
-
- UnityMenuModel* model() const;
- void setModel(UnityMenuModel* model);
-
- virtual QString name() const = 0;
-
- virtual QVariant state() const = 0;
-
- Q_INVOKABLE virtual void activate(const QVariant &parameter) = 0;
-
- Q_INVOKABLE virtual void changeState(const QVariant& vvalue) = 0;
-
-Q_SIGNALS:
- void nameChanged();
- void stateChanged();
- void indexChanged(int index);
- void modelChanged(UnityMenuModel* model);
-
-private:
- UnityMenuModel* m_model;
- int m_index;
-};
-
-Q_DECLARE_METATYPE(UnityMenuAction*)
-
-#endif // UNITYMENUACTION_H
diff --git a/libqmenumodel/src/unitymenumodel.cpp b/libqmenumodel/src/unitymenumodel.cpp
index 8191dee..e5407ab 100644
--- a/libqmenumodel/src/unitymenumodel.cpp
+++ b/libqmenumodel/src/unitymenumodel.cpp
@@ -19,7 +19,6 @@
#include "unitymenumodel.h"
#include "converter.h"
#include "actionstateparser.h"
-#include "unitymenuaction.h"
#include "unitymenumodelevents.h"
#include <QIcon>
@@ -43,6 +42,7 @@ enum MenuRoles {
TypeRole,
ExtendedAttributesRole,
ActionRole,
+ ActionStateRole,
IsCheckRole,
IsRadioRole,
IsToggledRole
@@ -80,65 +80,6 @@ public:
static void menuItemChanged(GObject *object, GParamSpec *pspec, gpointer user_data);
};
-class UnityGtkMenuTrackerItemAction : public UnityMenuAction
-{
-public:
- UnityGtkMenuTrackerItemAction(int index, UnityMenuModelPrivate* priv)
- : UnityMenuAction(priv->model),
- d(priv)
- {
- setModel(priv->model);
- 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;
-
- item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (d->items, index()));
- if (!item) return QVariant();
-
- return d->itemState(item);
- }
-
- virtual void activate(const QVariant &parameter)
- {
- 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_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)
- {
- 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;
-};
-
void menu_item_free (gpointer data)
{
GtkMenuTrackerItem *item = (GtkMenuTrackerItem *) data;
@@ -455,7 +396,10 @@ QVariant UnityMenuModel::data(const QModelIndex &index, int role) const
}
case ActionRole:
- return QVariant::fromValue(new UnityGtkMenuTrackerItemAction(index.row(), priv));
+ return gtk_menu_tracker_item_get_action_name (item);
+
+ case ActionStateRole:
+ return priv->itemState(item);
case IsCheckRole:
return gtk_menu_tracker_item_get_role (item) == GTK_MENU_TRACKER_ITEM_ROLE_CHECK;
@@ -493,6 +437,7 @@ QHash<int, QByteArray> UnityMenuModel::roleNames() const
names[TypeRole] = "type";
names[ExtendedAttributesRole] = "ext";
names[ActionRole] = "action";
+ names[ActionStateRole] = "actionState";
names[IsCheckRole] = "isCheck";
names[IsRadioRole] = "isRadio";
names[IsToggledRole] = "isToggled";
@@ -641,14 +586,37 @@ QVariant UnityMenuModel::get(int row, const QByteArray &role)
return this->data(this->index(row, 0), priv->roles[role]);
}
-void UnityMenuModel::activate(int index)
+void UnityMenuModel::activate(int index, const QVariant& parameter)
{
GtkMenuTrackerItem *item;
item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (priv->items, index));
- gtk_menu_tracker_item_activated (item);
+
+ if (parameter.isValid()) {
+ gchar *action;
+
+ gtk_menu_tracker_item_get_attribute (item, "action", "s", &action);
+ g_action_group_activate_action (G_ACTION_GROUP (priv->muxer), action, Converter::toGVariant(parameter));
+
+ g_free (action);
+ } else {
+ gtk_menu_tracker_item_activated (item);
+ }
+}
+
+void UnityMenuModel::changeState(int index, const QVariant& parameter)
+{
+ GtkMenuTrackerItem* item;
+
+ item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (priv->items, index));
+ if (!item) return;
+
+ GVariant* data = Converter::toGVariant(parameter);
+ gtk_menu_tracker_item_change_state (item, data);
+ g_variant_unref(data);
}
+
bool UnityMenuModel::event(QEvent* e)
{
if (e->type() == UnityMenuModelClearEvent::eventType) {
diff --git a/libqmenumodel/src/unitymenumodel.h b/libqmenumodel/src/unitymenumodel.h
index 5cce732..df35f08 100644
--- a/libqmenumodel/src/unitymenumodel.h
+++ b/libqmenumodel/src/unitymenumodel.h
@@ -57,7 +57,9 @@ 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_INVOKABLE void activate(int index, const QVariant& parameter = QVariant());
+ Q_INVOKABLE void changeState(int index, const QVariant& parameter);
Q_SIGNALS:
void busNameChanged(const QByteArray &name);