aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);