on xenial help sign in
Added variant conversion function.
4fc00e9Pawel Stolowski
plugins/Unity/CMakeLists.txt+1
@@ -20,6 +20,7 @@ set(QMLPLUGIN_SRC
20 plugin.cpp
20 plugin.cpp
21 bottombarvisibilitycommunicatorshell.cpp
21 bottombarvisibilitycommunicatorshell.cpp
22 launchermodel.cpp
22 launchermodel.cpp
23+ variantutils.cpp
23 )
24 )
24
25
25add_library(Unity-qml MODULE
26add_library(Unity-qml MODULE
plugins/Unity/scope.cpp+4−2
@@ -19,7 +19,10 @@
19
19
20// Self
20// Self
21#include "scope.h"
21#include "scope.h"
22+
23+// local
22#include "categories.h"
24#include "categories.h"
25+#include "variantutils.h"
23
26
24// Qt
27// Qt
25#include <QUrl>
28#include <QUrl>
@@ -131,8 +134,7 @@ void Scope::activate(const QVariant &uri, const QVariant &icon_hint, const QVari
131 res.name = title.toString().toStdString();
134 res.name = title.toString().toStdString();
132 res.comment = comment.toString().toStdString();
135 res.comment = comment.toString().toStdString();
133 res.dnd_uri = dnd_uri.toString().toStdString();
136 res.dnd_uri = dnd_uri.toString().toStdString();
134−
137+ res.hints = hintsMapFromQVariant(metadata);
135− //TODO metadata
136
138
137 m_unityScope->Activate(res);
139 m_unityScope->Activate(res);
138}
140}
plugins/Unity/variantutils.cppnew file+74
@@ -0,0 +1,74 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Pawel Stolowski <pawel.stolowski@canonical.com>
6+ *
7+ * This program is free software; you can redistribute it and/or modify
8+ * it under the terms of the GNU General Public License as published by
9+ * the Free Software Foundation; version 3.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
18+ */
19+
20+#include "variantutils.h"
21+
22+/* Returns floating ref */
23+GVariant* GVariantFromQVariant(const QVariant &var)
24+{
25+ GVariant *gv = nullptr;
26+
27+ switch (var.type()) {
28+ case QVariant::String:
29+ gv = g_variant_new_string(var.toString().toUtf8());
30+ break;
31+ case QVariant::UInt:
32+ gv = g_variant_new_uint32(var.toUInt());
33+ break;
34+ case QVariant::Int:
35+ gv = g_variant_new_int32(var.toInt());
36+ break;
37+ case QVariant::LongLong:
38+ gv = g_variant_new_int64(var.toLongLong());
39+ break;
40+ case QVariant::ULongLong:
41+ gv = g_variant_new_uint64(var.toULongLong());
42+ break;
43+ case QVariant::Double:
44+ gv = g_variant_new_double(var.toDouble());
45+ break;
46+ case QVariant::Bool:
47+ gv = g_variant_new_boolean(var.toBool());
48+ break;
49+ case QVariant::Hash: {
50+ const auto hash = var.toHash();
51+ GVariant **children = new GVariant*[hash.size()];
52+ int cnt = 0;
53+ QHash<QString, QVariant>::const_iterator it = hash.constBegin();
54+ while (it != hash.constEnd()) {
55+ GVariant *key = g_variant_new_string(it.key().toUtf8());
56+ children[++cnt] = g_variant_new_dict_entry(key, GVariantFromQVariant(it.value()));
57+ ++it;
58+ }
59+ gv = g_variant_new_array(G_VARIANT_TYPE_DICT_ENTRY, children, 1);
60+ delete [] children;
61+ break;
62+ }
63+ default:
64+ return NULL;
65+ }
66+ return gv;
67+}
68+
69+unity::glib::HintsMap hintsMapFromQVariant(const QVariant &var)
70+{
71+ if (var.type() == QVariant::Hash) {
72+ }
73+ return unity::glib::HintsMap();
74+}
plugins/Unity/variantutils.hnew file+32
@@ -0,0 +1,32 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Pawel Stolowski <pawel.stolowski@canonical.com>
6+ *
7+ * This program is free software; you can redistribute it and/or modify
8+ * it under the terms of the GNU General Public License as published by
9+ * the Free Software Foundation; version 3.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
18+ */
19+
20+#ifndef VARIANTUTILS_H
21+#define VARIANTUTILS_H
22+
23+#include <glib.h>
24+#include <QVariant>
25+
26+// libunity-core
27+#include <UnityCore/Variant.h>
28+
29+GVariant* GVariantFromQVariant(const QVariant &value);
30+unity::glib::HintsMap hintsMapFromQVariant(const QVariant &var);
31+
32+#endif