on aa291ee help sign in
108 lines 3.1 kB history raw
1/*
2 * Copyright 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 Lesser 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Renato Araujo Oliveira Filho <renato@canonical.com>
18 */
20#include "indicator.h"
22#include <QStringList>
24Indicator::Indicator(QObject *parent)
25 : QObject(parent),
26 m_position(0)
30Indicator::~Indicator()
34void Indicator::init(const QString& busName, const QSettings& settings)
36 // Save all keys we care about from the QSettings object. It's annoying
37 // that we can't just copy the object.
38 m_settings.clear();
39 Q_FOREACH(const QString& key, settings.allKeys()) {
40 if (key.endsWith(QLatin1String("/Position")) || key.endsWith(QLatin1String("/ObjectPath"))) {
41 m_settings.insert(key, settings.value(key));
42 }
43 }
45 setId(settings.value(QStringLiteral("Indicator Service/Name")).toString());
47 QString actionObjectPath = settings.value(QStringLiteral("Indicator Service/ObjectPath")).toString();
49 QVariantMap properties;
50 properties.clear();
51 properties.insert(QStringLiteral("busType"), 1);
52 properties.insert(QStringLiteral("busName"), busName);
53 properties.insert(QStringLiteral("actionsObjectPath"), actionObjectPath);
54 setIndicatorProperties(properties);
57QString Indicator::identifier() const
59 return m_identifier;
62void Indicator::setId(const QString &identifier)
64 if (identifier != m_identifier) {
65 m_identifier = identifier;
66 Q_EMIT identifierChanged(m_identifier);
67 }
70int Indicator::position() const
72 return m_position;
75void Indicator::setPosition(int position)
77 if (position != m_position) {
78 m_position = position;
79 Q_EMIT positionChanged(m_position);
80 }
83void Indicator::setProfile(const QString& profile)
85 QVariant pos = m_settings.value(profile + "/Position");
86 if (!pos.isValid())
87 pos = m_settings.value(QStringLiteral("Indicator Service/Position"), QVariant::fromValue(0));
88 setPosition(pos.toInt());
90 QString menuObjectPath = m_settings.value(profile + "/ObjectPath").toString();
91 QVariantMap map = m_properties.toMap();
92 map.insert(QStringLiteral("menuObjectPath"), menuObjectPath);
93 setIndicatorProperties(map);
96QVariant Indicator::indicatorProperties() const
98 return m_properties;
101void Indicator::setIndicatorProperties(const QVariant &properties)
103 if (m_properties != properties)
104 {
105 m_properties = properties;
106 Q_EMIT indicatorPropertiesChanged(m_properties);
107 }