@@ -0,0 +1,182 @@
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 "unitymenumodelpaths.h"
21+#include <QDBusArgument>
22+
23+static QVariant parseVariantData(const QVariant& var);
24+
25+const 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+
43+static 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+
57+UnityMenuModelPaths::UnityMenuModelPaths(QObject *parent)
58+ : QObject(parent)
59+{
60+}
61+
62+QVariant UnityMenuModelPaths::source() const
63+{
64+ return m_sourceData;
65+}
66+
67+void UnityMenuModelPaths::setSource(const QVariant& data)
68+{
69+ if (m_sourceData != data) {
70+ m_sourceData = data;
71+ Q_EMIT sourceChanged();
72+
73+ updateData();
74+ }
75+}
76+
77+void UnityMenuModelPaths::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+
100+QByteArray UnityMenuModelPaths::busName() const
101+{
102+ return m_busName;
103+}
104+
105+void UnityMenuModelPaths::setBusName(const QByteArray &name)
106+{
107+ if (m_busName != name) {
108+ m_busName = name;
109+ Q_EMIT busNameChanged();
110+ }
111+}
112+
113+QVariantMap UnityMenuModelPaths::actions() const
114+{
115+ return m_actions;
116+}
117+
118+void UnityMenuModelPaths::setActions(const QVariantMap &actions)
119+{
120+ if (m_actions != actions) {
121+ m_actions = actions;
122+ Q_EMIT actionsChanged();
123+ }
124+}
125+
126+QByteArray UnityMenuModelPaths::menuObjectPath() const
127+{
128+ return m_menuObjectPath;
129+}
130+
131+void UnityMenuModelPaths::setMenuObjectPath(const QByteArray &path)
132+{
133+ if (m_menuObjectPath != path) {
134+ m_menuObjectPath = path;
135+ Q_EMIT menuObjectPathChanged();
136+ }
137+}
138+
139+QByteArray UnityMenuModelPaths::busNameHint() const
140+{
141+ return m_busNameHint;
142+}
143+
144+void UnityMenuModelPaths::setBusNameHint(const QByteArray &nameHint)
145+{
146+ if (m_busNameHint != nameHint) {
147+ m_busNameHint = nameHint;
148+ Q_EMIT busNameHintChanged();
149+
150+ updateData();
151+ }
152+}
153+
154+QByteArray UnityMenuModelPaths::actionsHint() const
155+{
156+ return m_actionsHint;
157+}
158+
159+void UnityMenuModelPaths::setActionsHint(const QByteArray &actionsHint)
160+{
161+ if (m_actionsHint != actionsHint) {
162+ m_actionsHint = actionsHint;
163+ Q_EMIT actionsHintChanged();
164+
165+ updateData();
166+ }
167+}
168+
169+QByteArray UnityMenuModelPaths::menuObjectPathHint() const
170+{
171+ return m_menuObjectPathHint;
172+}
173+
174+void UnityMenuModelPaths::setMenuObjectPathHint(const QByteArray &pathHint)
175+{
176+ if (m_menuObjectPathHint != pathHint) {
177+ m_menuObjectPathHint = pathHint;
178+ Q_EMIT menuObjectPathHintChanged();
179+
180+ updateData();
181+ }
182+}