aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel/src
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2016-10-14 17:29:10 +0200
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2016-10-14 17:29:10 +0200
commit1e9cf635d3074b82759b0edab44ba4549af5085e (patch)
tree3757e229e816cf88fbe524c5471e27edef8ddb4d /libqmenumodel/src
parent449ac3d20ef7aa4d63f258eeb2a160a5f55cfa9c (diff)
downloadqmenumodel-1e9cf635d3074b82759b0edab44ba4549af5085e.tar.gz
qmenumodel-1e9cf635d3074b82759b0edab44ba4549af5085e.tar.bz2
qmenumodel-1e9cf635d3074b82759b0edab44ba4549af5085e.zip
UnityMenuModel add support for activating and changing state with a variant string parameter
Diffstat (limited to 'libqmenumodel/src')
-rw-r--r--libqmenumodel/src/unitymenumodel.cpp34
-rw-r--r--libqmenumodel/src/unitymenumodel.h2
2 files changed, 36 insertions, 0 deletions
diff --git a/libqmenumodel/src/unitymenumodel.cpp b/libqmenumodel/src/unitymenumodel.cpp
index 70412a4..6e9a5f7 100644
--- a/libqmenumodel/src/unitymenumodel.cpp
+++ b/libqmenumodel/src/unitymenumodel.cpp
@@ -715,6 +715,40 @@ void UnityMenuModel::activate(int index, const QVariant& parameter)
}
}
+static QVariant parseVariantString(const QString& string)
+{
+ QVariant qvariant;
+ GVariant *gvariant;
+ GError *error = NULL;
+
+ if (string.isEmpty()) {
+ return qvariant;
+ }
+
+ gvariant = g_variant_parse (NULL, string.toStdString().c_str(), NULL, NULL, &error);
+
+ if (error) {
+ qWarning() << "Impossible to parse" << string << "as variant string:"<< error->message;
+ g_error_free (error);
+ return qvariant;
+ }
+
+ qvariant = Converter::toQVariant(gvariant);
+ g_variant_unref (gvariant);
+
+ return qvariant;
+}
+
+void UnityMenuModel::activateByVariantString(int index, const QString& parameter)
+{
+ activate(index, parseVariantString(parameter));
+}
+
+void UnityMenuModel::changeStateByVariantString(int index, const QString& parameter)
+{
+ changeState(index, parseVariantString(parameter));
+}
+
void UnityMenuModel::changeState(int index, const QVariant& parameter)
{
GSequenceIter *it;
diff --git a/libqmenumodel/src/unitymenumodel.h b/libqmenumodel/src/unitymenumodel.h
index 8816d22..826d5b2 100644
--- a/libqmenumodel/src/unitymenumodel.h
+++ b/libqmenumodel/src/unitymenumodel.h
@@ -63,7 +63,9 @@ public:
Q_INVOKABLE QVariant get(int row, const QByteArray &role);
Q_INVOKABLE void activate(int index, const QVariant& parameter = QVariant());
+ Q_INVOKABLE void activateByVariantString(int index, const QString& parameter = QString());
Q_INVOKABLE void changeState(int index, const QVariant& parameter);
+ Q_INVOKABLE void changeStateByVariantString(int index, const QString& parameter = QString());
void registerAction(UnityMenuAction* action);
void unregisterAction(UnityMenuAction* action);