Unity 8
 All Classes Functions
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 &profile, const QString& busName, const QSettings& settings)
35 {
36  setId(settings.value("Indicator Service/Name").toString());
37 
38  QVariant pos = settings.value(profile + "/Position");
39  if (!pos.isValid())
40  pos = settings.value("Indicator Service/Position", QVariant::fromValue(0));
41  setPosition(pos.toInt());
42 
43  QString actionObjectPath = settings.value("Indicator Service/ObjectPath").toString();
44  QString menuObjectPath = settings.value(profile + "/ObjectPath").toString();
45 
46  QVariantMap properties;
47  properties.clear();
48  properties.insert("busType", 1);
49  properties.insert("busName", busName);
50  properties.insert("actionsObjectPath", actionObjectPath);
51  properties.insert("menuObjectPath", menuObjectPath);
52  setIndicatorProperties(properties);
53 }
54 
55 QString Indicator::identifier() const
56 {
57  return m_identifier;
58 }
59 
60 void Indicator::setId(const QString &identifier)
61 {
62  if (identifier != m_identifier) {
63  m_identifier = identifier;
64  Q_EMIT identifierChanged(m_identifier);
65  }
66 }
67 
68 int Indicator::position() const
69 {
70  return m_position;
71 }
72 
73 void Indicator::setPosition(int position)
74 {
75  if (position != m_position) {
76  m_position = position;
77  Q_EMIT positionChanged(m_position);
78  }
79 }
80 
81 QVariant Indicator::indicatorProperties() const
82 {
83  return m_properties;
84 }
85 
86 void Indicator::setIndicatorProperties(const QVariant &properties)
87 {
88  if (m_properties != properties)
89  {
90  m_properties = properties;
91  Q_EMIT indicatorPropertiesChanged(m_properties);
92  }
93 }