aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel/src/converter.cpp
diff options
context:
space:
mode:
authorBileto Bot <ci-train-bot@canonical.com>2016-10-26 17:28:07 +0000
committerBileto Bot <ci-train-bot@canonical.com>2016-10-26 17:28:07 +0000
commit662f2630e3f8d9b869dea6a47ca7e2265b84eb17 (patch)
tree3c36858a15f7724317f6dc8a0749bf2b491e7924 /libqmenumodel/src/converter.cpp
parent9efd410b91168d2afe730d3fc53bc8718ca39347 (diff)
parent0d1bfd69b848b2c86b48a3de198bc7dad9c96441 (diff)
downloadqmenumodel-662f2630e3f8d9b869dea6a47ca7e2265b84eb17.tar.gz
qmenumodel-662f2630e3f8d9b869dea6a47ca7e2265b84eb17.tar.bz2
qmenumodel-662f2630e3f8d9b869dea6a47ca7e2265b84eb17.zip
Add ability to activate or change state of an action by variant string
Diffstat (limited to 'libqmenumodel/src/converter.cpp')
-rw-r--r--libqmenumodel/src/converter.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/libqmenumodel/src/converter.cpp b/libqmenumodel/src/converter.cpp
index 69e6629..527ae85 100644
--- a/libqmenumodel/src/converter.cpp
+++ b/libqmenumodel/src/converter.cpp
@@ -24,6 +24,7 @@ extern "C" {
#include "converter.h"
#include <QDebug>
+#include <QString>
#include <QVariant>
/*! \internal */
@@ -137,6 +138,29 @@ static GVariant* toGVariant(const QString &typeName, const QVariant &value)
return NULL;
}
+QVariant Converter::toQVariantFromVariantString(const QString &variantString)
+{
+ GVariant *gvariant;
+ GError *error = NULL;
+
+ if (variantString.isEmpty()) {
+ return QVariant();
+ }
+
+ gvariant = g_variant_parse (NULL, variantString.toUtf8().data(), NULL, NULL, &error);
+
+ if (error) {
+ qWarning() << "Impossible to parse" << variantString << "as variant string:"<< error->message;
+ g_error_free (error);
+ return QVariant();
+ }
+
+ const QVariant& qvariant = Converter::toQVariant(gvariant);
+ g_variant_unref (gvariant);
+
+ return qvariant;
+}
+
GVariant* Converter::toGVariant(const QVariant &value)
{
GVariant *result = NULL;
@@ -156,12 +180,18 @@ GVariant* Converter::toGVariant(const QVariant &value)
case QVariant::Int:
result = g_variant_new_int32(value.toInt());
break;
+ case QVariant::LongLong:
+ result = g_variant_new_int64(value.toLongLong());
+ break;
case QVariant::String:
result = g_variant_new_string(value.toString().toUtf8().data());
break;
case QVariant::UInt:
result = g_variant_new_uint32(value.toUInt());
break;
+ case QVariant::ULongLong:
+ result = g_variant_new_uint64(value.toULongLong());
+ break;
case QVariant::Map:
{
GVariantBuilder *b;