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/>.
22
#include <QStringList>
24
#include <deelistmodel.h>
25
#include "variantutils.h"
27
unity::glib::HintsMap convertToHintsMap(const QHash<QString, QVariant> &val)
29
unity::glib::HintsMap hintsMap;
30
QHash<QString, QVariant>::const_iterator it = val.constBegin();
31
while (it != val.constEnd()) {
32
hintsMap[it.key().toStdString()] = DeeListModel::DataFromVariant(it.value());
38
unity::glib::HintsMap convertToHintsMap(const QVariant &var)
40
if (var.type() == QVariant::Hash) {
41
unity::glib::HintsMap hintsMap;
42
const auto hash = var.toHash();
43
return convertToHintsMap(hash);
45
return unity::glib::HintsMap();
48
QVariantHash convertToQVariantHash(const unity::glib::HintsMap& var)
51
for (auto hint: var) {
52
hash.insert(QString::fromStdString(hint.first), DeeListModel::VariantForData(hint.second));
57
/* This will translate uris in the form of:
58
* "subscope:master.scope/sub.scope?foo=bar"
59
* into a QVariantHash that can be passed as a metadata field to scope.
61
QVariantHash subscopeUriToMetadataHash(const QString &metadata_string)
63
QUrl metadata_url(metadata_string);
64
if (metadata_url.scheme() == QLatin1String("subscope")) {
65
QString subscope_uri(metadata_url.toString(QUrl::RemoveScheme | QUrl::RemoveQuery));
66
QVariantHash new_metadata;
67
QUrlQuery query(metadata_url.query());
68
QList<QPair<QString,QString>> queryItems(query.queryItems());
69
for (auto it = queryItems.begin(); it != queryItems.end(); ++it) {
70
new_metadata[it->first] = QVariant::fromValue(it->second);
72
QStringList parts(subscope_uri.split(QChar('/')));
73
for (int i = parts.size() - 1; i >= 0; i--) {
75
inner["scope-id"] = QVariant::fromValue(parts[i]);
76
inner["content"] = QVariant::fromValue(new_metadata);
81
return QVariantHash();