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  const QString actionObjectPath = settings.value(QStringLiteral("Indicator Service/ObjectPath")).toString();
48 
49  QVariantMap properties;
50  properties.insert(QStringLiteral("busType"), 1);
51  properties.insert(QStringLiteral("busName"), busName);
52  properties.insert(QStringLiteral("actionsObjectPath"), actionObjectPath);
53  setIndicatorProperties(properties);
54 }
55 
56 QString Indicator::identifier() const
57 {
58  return m_identifier;
59 }
60 
61 void Indicator::setId(const QString &identifier)
62 {
63  if (identifier != m_identifier) {
64  m_identifier = identifier;
65  Q_EMIT identifierChanged(m_identifier);
66  }
67 }
68 
69 int Indicator::position() const
70 {
71  return m_position;
72 }
73 
74 void Indicator::setPosition(int position)
75 {
76  if (position != m_position) {
77  m_position = position;
78  Q_EMIT positionChanged(m_position);
79  }
80 }
81 
82 void Indicator::setProfile(const QString& profile)
83 {
84  QVariant pos = m_settings.value(profile + "/Position");
85  if (!pos.isValid())
86  pos = m_settings.value(QStringLiteral("Indicator Service/Position"), QVariant::fromValue(0));
87  setPosition(pos.toInt());
88 
89  const QString menuObjectPath = m_settings.value(profile + "/ObjectPath").toString();
90  QVariantMap map = m_properties.toMap();
91  map.insert(QStringLiteral("menuObjectPath"), menuObjectPath);
92  setIndicatorProperties(map);
93 }
94 
95 QVariant Indicator::indicatorProperties() const
96 {
97  return m_properties;
98 }
99 
100 void Indicator::setIndicatorProperties(const QVariant &properties)
101 {
102  if (m_properties != properties)
103  {
104  m_properties = properties;
105  Q_EMIT indicatorPropertiesChanged(m_properties);
106  }
107 }