on xenial help sign in
Added variant conversion function.
commit4fc00e9d7fc28093dfc8e03bbbf980e2f5611c58 authorPawel Stolowski <pawel.stolowski@canonical.com> dateFri 21 Jun 2013, 16:24 (13 years ago) parent9d56445
4 files changed+111−2
plugins/Unity/CMakeLists.txt+1 plugins/Unity/scope.cpp+4−2 plugins/Unity/variantutils.cpp+74 plugins/Unity/variantutils.h+32
plugins/Unity/CMakeLists.txt+1
@@ -20,6 +20,7 @@ set(QMLPLUGIN_SRC
2020 plugin.cpp
2121 bottombarvisibilitycommunicatorshell.cpp
2222 launchermodel.cpp
23+ variantutils.cpp
2324 )
2425
2526add_library(Unity-qml MODULE
plugins/Unity/scope.cpp+4−2
@@ -19,7 +19,10 @@
1919
2020// Self
2121#include "scope.h"
22+
23+// local
2224#include "categories.h"
25+#include "variantutils.h"
2326
2427// Qt
2528#include <QUrl>
@@ -131,8 +134,7 @@ void Scope::activate(const QVariant &uri, const QVariant &icon_hint, const QVari
131134 res.name = title.toString().toStdString();
132135 res.comment = comment.toString().toStdString();
133136 res.dnd_uri = dnd_uri.toString().toStdString();
134−
135− //TODO metadata
137+ res.hints = hintsMapFromQVariant(metadata);
136138
137139 m_unityScope->Activate(res);
138140}
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