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