Lomiri
Loading...
Searching...
No Matches
lomirimenumodelpaths.cpp
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Nick Dedekind <nick.dedekind@canonical.com>
17 */
18
19
20#include "lomirimenumodelpaths.h"
21#include <QDBusArgument>
22
23static QVariant parseVariantData(const QVariant& var);
24
25const QDBusArgument &operator>>(const QDBusArgument &arg, QVariantMap &map)
26{
27 arg.beginMap();
28 map.clear();
29 while (!arg.atEnd()) {
30 QString key;
31 QVariant value;
32 arg.beginMapEntry();
33
34 arg >> key >> value;
35 map.insertMulti(key, parseVariantData(value)); // re-parse for qdbusargument
36
37 arg.endMapEntry();
38 }
39 arg.endMap();
40 return arg;
41}
42
43static QVariant parseVariantData(const QVariant& var) {
44 if ((int)var.type() == QMetaType::User && var.userType() == qMetaTypeId<QDBusArgument>()) {
45 QDBusArgument arg(var.value<QDBusArgument>());
46 if (arg.currentType() == QDBusArgument::MapType) {
47 QVariantMap map;
48 arg >> map;
49 return map;
50 }
51 return arg.asVariant();
52 }
53
54 return var;
55}
56
57LomiriMenuModelPaths::LomiriMenuModelPaths(QObject *parent)
58 : QObject(parent)
59{
60}
61
62QVariant LomiriMenuModelPaths::source() const
63{
64 return m_sourceData;
65}
66
67void LomiriMenuModelPaths::setSource(const QVariant& data)
68{
69 if (m_sourceData != data) {
70 m_sourceData = data;
71 Q_EMIT sourceChanged();
72
73 updateData();
74 }
75}
76
77void LomiriMenuModelPaths::updateData()
78{
79 QVariantMap dataMap = parseVariantData(m_sourceData).toMap();
80
81 if (!m_busNameHint.isEmpty() && dataMap.contains(m_busNameHint)) {
82 setBusName(dataMap[m_busNameHint].toByteArray());
83 } else {
84 setBusName("");
85 }
86
87 if (!m_menuObjectPathHint.isEmpty() && dataMap.contains(m_menuObjectPathHint)) {
88 setMenuObjectPath(dataMap[m_menuObjectPathHint].toByteArray());
89 } else {
90 setMenuObjectPath("");
91 }
92
93 if (!m_actionsHint.isEmpty() && dataMap.contains(m_actionsHint)) {
94 setActions(dataMap[m_actionsHint].toMap());
95 } else {
96 setActions(QVariantMap());
97 }
98}
99
100QByteArray LomiriMenuModelPaths::busName() const
101{
102 return m_busName;
103}
104
105void LomiriMenuModelPaths::setBusName(const QByteArray &name)
106{
107 if (m_busName != name) {
108 m_busName = name;
109 Q_EMIT busNameChanged();
110 }
111}
112
113QVariantMap LomiriMenuModelPaths::actions() const
114{
115 return m_actions;
116}
117
118void LomiriMenuModelPaths::setActions(const QVariantMap &actions)
119{
120 if (m_actions != actions) {
121 m_actions = actions;
122 Q_EMIT actionsChanged();
123 }
124}
125
126QByteArray LomiriMenuModelPaths::menuObjectPath() const
127{
128 return m_menuObjectPath;
129}
130
131void LomiriMenuModelPaths::setMenuObjectPath(const QByteArray &path)
132{
133 if (m_menuObjectPath != path) {
134 m_menuObjectPath = path;
135 Q_EMIT menuObjectPathChanged();
136 }
137}
138
139QByteArray LomiriMenuModelPaths::busNameHint() const
140{
141 return m_busNameHint;
142}
143
144void LomiriMenuModelPaths::setBusNameHint(const QByteArray &nameHint)
145{
146 if (m_busNameHint != nameHint) {
147 m_busNameHint = nameHint;
148 Q_EMIT busNameHintChanged();
149
150 updateData();
151 }
152}
153
154QByteArray LomiriMenuModelPaths::actionsHint() const
155{
156 return m_actionsHint;
157}
158
159void LomiriMenuModelPaths::setActionsHint(const QByteArray &actionsHint)
160{
161 if (m_actionsHint != actionsHint) {
162 m_actionsHint = actionsHint;
163 Q_EMIT actionsHintChanged();
164
165 updateData();
166 }
167}
168
169QByteArray LomiriMenuModelPaths::menuObjectPathHint() const
170{
171 return m_menuObjectPathHint;
172}
173
174void LomiriMenuModelPaths::setMenuObjectPathHint(const QByteArray &pathHint)
175{
176 if (m_menuObjectPathHint != pathHint) {
177 m_menuObjectPathHint = pathHint;
178 Q_EMIT menuObjectPathHintChanged();
179
180 updateData();
181 }
182}