@@ -0,0 +1,74 @@
2+ * Copyright (C) 2013 Canonical, Ltd.
5+ * Pawel Stolowski <pawel.stolowski@canonical.com>
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.
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.
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/>.
20+#include "variantutils.h"
22+/* Returns floating ref */
23+GVariant* GVariantFromQVariant(const QVariant &var)
25+ GVariant *gv = nullptr;
27+ switch (var.type()) {
28+ case QVariant::String:
29+ gv = g_variant_new_string(var.toString().toUtf8());
32+ gv = g_variant_new_uint32(var.toUInt());
35+ gv = g_variant_new_int32(var.toInt());
37+ case QVariant::LongLong:
38+ gv = g_variant_new_int64(var.toLongLong());
40+ case QVariant::ULongLong:
41+ gv = g_variant_new_uint64(var.toULongLong());
43+ case QVariant::Double:
44+ gv = g_variant_new_double(var.toDouble());
47+ gv = g_variant_new_boolean(var.toBool());
49+ case QVariant::Hash: {
50+ const auto hash = var.toHash();
51+ GVariant **children = new GVariant*[hash.size()];
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()));
59+ gv = g_variant_new_array(G_VARIANT_TYPE_DICT_ENTRY, children, 1);
69+unity::glib::HintsMap hintsMapFromQVariant(const QVariant &var)
71+ if (var.type() == QVariant::Hash) {
73+ return unity::glib::HintsMap();