Unity 8
indicator.cpp
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  */
19 
20 #include "indicator.h"
21 
22 #include <QStringList>
23 
24 Indicator::Indicator(QObject *parent)
25  : QObject(parent),
26  m_position(0)
27 {
28 }
29 
30 Indicator::~Indicator()
31 {
32 }
33 
34 void Indicator::init(const QString& busName, const QSettings& settings)
35 {
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  }
44 
45  setId(settings.value(QStringLiteral("Indicator Service/Name")).toString());
46 
47  QString actionObjectPath = settings.value(QStringLiteral("Indicator Service/ObjectPath")).toString();
48 
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);
55 }
56 
57 QString Indicator::identifier() const
58 {
59  return m_identifier;
60 }
61 
62 void Indicator::setId(const QString &identifier)
63 {
64  if (identifier != m_identifier) {
65  m_identifier = identifier;
66  Q_EMIT identifierChanged(m_identifier);
67  }
68 }
69 
70 int Indicator::position() const
71 {
72  return m_position;
73 }
74 
75 void Indicator::setPosition(int position)
76 {
77  if (position != m_position) {
78  m_position = position;
79  Q_EMIT positionChanged(m_position);
80  }
81 }
82 
83 void Indicator::setProfile(const QString& profile)
84 {
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());
89 
90  QString menuObjectPath = m_settings.value(profile + "/ObjectPath").toString();
91  QVariantMap map = m_properties.toMap();
92  map.insert(QStringLiteral("menuObjectPath"), menuObjectPath);
93  setIndicatorProperties(map);
94 }
95 
96 QVariant Indicator::indicatorProperties() const
97 {
98  return m_properties;
99 }
100 
101 void Indicator::setIndicatorProperties(const QVariant &properties)
102 {
103  if (m_properties != properties)
104  {
105  m_properties = properties;
106  Q_EMIT indicatorPropertiesChanged(m_properties);
107  }
108 }