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 */
23GVariant* GVariantFromQVariant(const QVariant &var)
25 GVariant *gv = nullptr;
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, g_variant_new_variant(GVariantFromQVariant(it.value())));
59 gv = g_variant_new_array(G_VARIANT_TYPE("{sv}"), children, hash.size());
70unity::glib::HintsMap convertToHintsMap(const QHash<QString, QVariant> &val)
72 unity::glib::HintsMap hintsMap;
73 QHash<QString, QVariant>::const_iterator it = val.constBegin();
74 while (it != val.constEnd()) {
75 hintsMap[it.key().toStdString()] = GVariantFromQVariant(it.value());
81unity::glib::HintsMap convertToHintsMap(const QVariant &var)
83 if (var.type() == QVariant::Hash) {
84 unity::glib::HintsMap hintsMap;
85 const auto hash = var.toHash();
86 return convertToHintsMap(hash);
88 return unity::glib::HintsMap();
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list