aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel/src
diff options
context:
space:
mode:
Diffstat (limited to 'libqmenumodel/src')
-rw-r--r--libqmenumodel/src/converter.cpp24
-rw-r--r--libqmenumodel/src/converter.h2
-rw-r--r--libqmenumodel/src/unitymenumodel.cpp27
3 files changed, 28 insertions, 25 deletions
diff --git a/libqmenumodel/src/converter.cpp b/libqmenumodel/src/converter.cpp
index 021fc82..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;
diff --git a/libqmenumodel/src/converter.h b/libqmenumodel/src/converter.h
index f47c09e..27cdcae 100644
--- a/libqmenumodel/src/converter.h
+++ b/libqmenumodel/src/converter.h
@@ -21,12 +21,14 @@
#define CONVERTER_H
typedef struct _GVariant GVariant;
+class QString;
class QVariant;
class Converter
{
public:
static QVariant toQVariant(GVariant *value);
+ static QVariant toQVariantFromVariantString(const QString &variantString);
static GVariant* toGVariant(const QVariant &value);
// This converts a QVariant to a GVariant using a provided gvariant schema as
diff --git a/libqmenumodel/src/unitymenumodel.cpp b/libqmenumodel/src/unitymenumodel.cpp
index 4c238d8..5e8c8e3 100644
--- a/libqmenumodel/src/unitymenumodel.cpp
+++ b/libqmenumodel/src/unitymenumodel.cpp
@@ -715,37 +715,14 @@ void UnityMenuModel::activate(int index, const QVariant& parameter)
}
}
-static QVariant parseVariantString(const QString& string)
-{
- GVariant *gvariant;
- GError *error = NULL;
-
- if (string.isEmpty()) {
- return QVariant();
- }
-
- gvariant = g_variant_parse (NULL, string.toUtf8().data(), NULL, NULL, &error);
-
- if (error) {
- qWarning() << "Impossible to parse" << string << "as variant string:"<< error->message;
- g_error_free (error);
- return QVariant();
- }
-
- const QVariant& qvariant = Converter::toQVariant(gvariant);
- g_variant_unref (gvariant);
-
- return qvariant;
-}
-
void UnityMenuModel::activateByVariantString(int index, const QString& parameter)
{
- activate(index, parseVariantString(parameter));
+ activate(index, Converter::toQVariantFromVariantString(parameter));
}
void UnityMenuModel::changeStateByVariantString(int index, const QString& parameter)
{
- changeState(index, parseVariantString(parameter));
+ changeState(index, Converter::toQVariantFromVariantString(parameter));
}
void UnityMenuModel::changeState(int index, const QVariant& parameter)