on b670702 help sign in
110 lines 3.0 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 &profile, 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("/Position") || key.endsWith("/ObjectPath")) {
41 m_settings.insert(key, settings.value(key));
42 }
43 }
45 setId(settings.value("Indicator Service/Name").toString());
47 QString actionObjectPath = settings.value("Indicator Service/ObjectPath").toString();
49 QVariantMap properties;
50 properties.clear();
51 properties.insert("busType", 1);
52 properties.insert("busName", busName);
53 properties.insert("actionsObjectPath", actionObjectPath);
55 m_properties = properties;
56 setProfile(profile); // will emit changed signals for us and set position
59QString Indicator::identifier() const
61 return m_identifier;
64void Indicator::setId(const QString &identifier)
66 if (identifier != m_identifier) {
67 m_identifier = identifier;
68 Q_EMIT identifierChanged(m_identifier);
69 }
72int Indicator::position() const
74 return m_position;
77void Indicator::setPosition(int position)
79 if (position != m_position) {
80 m_position = position;
81 Q_EMIT positionChanged(m_position);
82 }
85void Indicator::setProfile(const QString& profile)
87 QVariant pos = m_settings.value(profile + "/Position");
88 if (!pos.isValid())
89 pos = m_settings.value("Indicator Service/Position", QVariant::fromValue(0));
90 setPosition(pos.toInt());
92 QString menuObjectPath = m_settings.value(profile + "/ObjectPath").toString();
93 QVariantMap map = m_properties.toMap();
94 map.insert("menuObjectPath", menuObjectPath);
95 setIndicatorProperties(map);
98QVariant Indicator::indicatorProperties() const
100 return m_properties;
103void Indicator::setIndicatorProperties(const QVariant &properties)
105 if (m_properties != properties)
106 {
107 m_properties = properties;
108 Q_EMIT indicatorPropertiesChanged(m_properties);
109 }