aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel
diff options
context:
space:
mode:
authorNick Dedekind <nicholas.dedekind@gmail.com>2013-07-30 07:01:48 +0200
committerLars Uebernickel <lars.uebernickel@canonical.com>2013-07-30 07:01:48 +0200
commit01d57d800729a0ca7b9fd023b47b4517495883b3 (patch)
treeb28d92464cc96005bcabef4e70d67310ea797e9b /libqmenumodel
parented4b69482684c7070c928af4966ba52c32bf041b (diff)
downloadqmenumodel-01d57d800729a0ca7b9fd023b47b4517495883b3.tar.gz
qmenumodel-01d57d800729a0ca7b9fd023b47b4517495883b3.tar.bz2
qmenumodel-01d57d800729a0ca7b9fd023b47b4517495883b3.zip
Add ActionStateParser
Diffstat (limited to 'libqmenumodel')
-rw-r--r--libqmenumodel/src/CMakeLists.txt2
-rw-r--r--libqmenumodel/src/actionstateparser.cpp34
-rw-r--r--libqmenumodel/src/actionstateparser.h37
-rw-r--r--libqmenumodel/src/unitymenumodel.cpp37
-rw-r--r--libqmenumodel/src/unitymenumodel.h9
5 files changed, 116 insertions, 3 deletions
diff --git a/libqmenumodel/src/CMakeLists.txt b/libqmenumodel/src/CMakeLists.txt
index 24b65d2..cf9c426 100644
--- a/libqmenumodel/src/CMakeLists.txt
+++ b/libqmenumodel/src/CMakeLists.txt
@@ -1,6 +1,7 @@
project(src)
set(QMENUMODEL_SRC
+ actionstateparser.cpp
converter.cpp
dbus-enums.h
menunode.cpp
@@ -49,6 +50,7 @@ qt5_use_modules(${SHAREDLIBNAME} Core Qml Quick)
install(TARGETS ${SHAREDLIBNAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
set(QMENUMODEL_HEADERS
+ actionstateparser.h
dbus-enums.h
qdbusactiongroup.h
qdbusmenumodel.h
diff --git a/libqmenumodel/src/actionstateparser.cpp b/libqmenumodel/src/actionstateparser.cpp
new file mode 100644
index 0000000..6637b56
--- /dev/null
+++ b/libqmenumodel/src/actionstateparser.cpp
@@ -0,0 +1,34 @@
+/*
+ * 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 "actionstateparser.h"
+#include "converter.h"
+
+ActionStateParser::ActionStateParser(QObject* parent)
+ : QObject(parent)
+{
+}
+
+QVariant ActionStateParser::toQVariant(GVariant* state) const
+{
+ if (state) {
+ return Converter::toQVariant(state);
+ }
+ return QVariant();
+} \ No newline at end of file
diff --git a/libqmenumodel/src/actionstateparser.h b/libqmenumodel/src/actionstateparser.h
new file mode 100644
index 0000000..044dea1
--- /dev/null
+++ b/libqmenumodel/src/actionstateparser.h
@@ -0,0 +1,37 @@
+/*
+ * 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 ACTIONSTATEPARSER_H
+#define ACTIONSTATEPARSER_H
+
+#include <QObject>
+#include <QVariant>
+
+typedef struct _GVariant GVariant;
+
+class ActionStateParser : public QObject
+{
+ Q_OBJECT
+public:
+ ActionStateParser(QObject* parent = 0);
+
+ virtual QVariant toQVariant(GVariant* state) const;
+};
+
+#endif // ACTIONSTATEPARSER_H
diff --git a/libqmenumodel/src/unitymenumodel.cpp b/libqmenumodel/src/unitymenumodel.cpp
index 58dd84b..6108006 100644
--- a/libqmenumodel/src/unitymenumodel.cpp
+++ b/libqmenumodel/src/unitymenumodel.cpp
@@ -18,6 +18,10 @@
#include "unitymenumodel.h"
#include "converter.h"
+#include "actionstateparser.h"
+
+#include <QIcon>
+#include <QQmlComponent>
#include <QIcon>
@@ -64,6 +68,7 @@ public:
QVariantMap actions;
QByteArray menuObjectPath;
QHash<QByteArray, int> roles;
+ ActionStateParser* actionStateParser;
static void nameAppeared(GDBusConnection *connection, const gchar *name, const gchar *owner, gpointer user_data);
static void nameVanished(GDBusConnection *connection, const gchar *name, gpointer user_data);
@@ -86,6 +91,7 @@ UnityMenuModelPrivate::UnityMenuModelPrivate(UnityMenuModel *model)
this->menutracker = NULL;
this->connection = NULL;
this->nameWatchId = 0;
+ this->actionStateParser = new ActionStateParser(model);
this->muxer = gtk_action_muxer_new ();
g_object_set_qdata (G_OBJECT (this->muxer), unity_menu_model_quark (), model);
@@ -172,7 +178,9 @@ QVariant UnityMenuModelPrivate::itemState(GtkMenuTrackerItem *item)
GVariant *state = gtk_menu_tracker_item_get_action_state (item);
if (state != NULL) {
- result = Converter::toQVariant(state);
+ if (actionStateParser != NULL) {
+ result = actionStateParser->toQVariant(state);
+ }
g_variant_unref (state);
}
@@ -267,6 +275,7 @@ void UnityMenuModel::setBusName(const QByteArray &name)
priv->nameWatchId = g_bus_watch_name (G_BUS_TYPE_SESSION, name.constData(), G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
UnityMenuModelPrivate::nameAppeared, UnityMenuModelPrivate::nameVanished,
priv, NULL);
+ priv->busName = name;
}
QVariantMap UnityMenuModel::actions() const
@@ -291,6 +300,22 @@ void UnityMenuModel::setMenuObjectPath(const QByteArray &path)
priv->updateMenuModel();
}
+ActionStateParser* UnityMenuModel::actionStateParser() const
+{
+ return priv->actionStateParser;
+}
+
+void UnityMenuModel::setActionStateParser(ActionStateParser* actionStateParser)
+{
+ if (priv->actionStateParser != actionStateParser) {
+ if (priv->actionStateParser && priv->actionStateParser->parent() == this) {
+ delete priv->actionStateParser;
+ }
+ priv->actionStateParser = actionStateParser;
+ Q_EMIT actionStateParserChanged(actionStateParser);
+ }
+}
+
int UnityMenuModel::rowCount(const QModelIndex &parent) const
{
return !parent.isValid() ? g_sequence_get_length (priv->items) : 0;
@@ -423,7 +448,7 @@ QHash<int, QByteArray> UnityMenuModel::roleNames() const
return names;
}
-QObject * UnityMenuModel::submenu(int position)
+QObject * UnityMenuModel::submenu(int position, QQmlComponent* actionStateParser)
{
GSequenceIter *it;
GtkMenuTrackerItem *item;
@@ -441,6 +466,14 @@ QObject * UnityMenuModel::submenu(int position)
if (model == NULL) {
model = new UnityMenuModel(this);
model->priv = new UnityMenuModelPrivate(model);
+
+ if (actionStateParser) {
+ ActionStateParser* parser = qobject_cast<ActionStateParser*>(actionStateParser->create());
+ if (parser) {
+ model->setActionStateParser(parser);
+ }
+ }
+
model->priv->menutracker = gtk_menu_tracker_new_for_item_submenu (item,
UnityMenuModelPrivate::menuItemInserted,
UnityMenuModelPrivate::menuItemRemoved,
diff --git a/libqmenumodel/src/unitymenumodel.h b/libqmenumodel/src/unitymenumodel.h
index 396eea3..ad409ba 100644
--- a/libqmenumodel/src/unitymenumodel.h
+++ b/libqmenumodel/src/unitymenumodel.h
@@ -20,6 +20,8 @@
#define UNITYMENUMODEL_H
#include <QAbstractListModel>
+class ActionStateParser;
+class QQmlComponent;
class UnityMenuModel: public QAbstractListModel
{
@@ -27,6 +29,7 @@ class UnityMenuModel: public QAbstractListModel
Q_PROPERTY(QByteArray busName READ busName WRITE setBusName NOTIFY busNameChanged)
Q_PROPERTY(QVariantMap actions READ actions WRITE setActions NOTIFY actionsChanged)
Q_PROPERTY(QByteArray menuObjectPath READ menuObjectPath WRITE setMenuObjectPath NOTIFY menuObjectPathChanged)
+ Q_PROPERTY(ActionStateParser* actionStateParser READ actionStateParser WRITE setActionStateParser NOTIFY actionStateParserChanged)
public:
UnityMenuModel(QObject *parent = NULL);
@@ -41,6 +44,9 @@ public:
QByteArray menuObjectPath() const;
void setMenuObjectPath(const QByteArray &path);
+ ActionStateParser* actionStateParser() const;
+ void setActionStateParser(ActionStateParser* actionStateParser);
+
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
@@ -48,7 +54,7 @@ public:
QModelIndex parent(const QModelIndex &index) const;
QHash<int, QByteArray> roleNames() const;
- Q_INVOKABLE QObject * submenu(int position);
+ 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);
@@ -56,6 +62,7 @@ Q_SIGNALS:
void busNameChanged(const QByteArray &name);
void actionsChanged(const QByteArray &path);
void menuObjectPathChanged(const QByteArray &path);
+ void actionStateParserChanged(ActionStateParser* parser);
public Q_SLOTS:
void activate(int index);