on xenial help sign in
Indicator Icon Widgets
commite2b019b096fe427e3fb957bff2bf9a77a076546c authorNick Dedekind <nicholas.dedekind@gmail.com> dateFri 7 Jun 2013, 14:51 (13 years ago) parentf063450
37 files changed+569−483
Panel/IndicatorItem.qml+28−35 Panel/IndicatorRow.qml+2−2 Panel/MenuContent.qml+1−1 plugins/IndicatorsClient/flatmenuproxymodel.cpp+15 plugins/IndicatorsClient/flatmenuproxymodel.h+3 plugins/IndicatorsClient/indicatorclientinterface.h+8−13 plugins/IndicatorsClient/indicators/common/indicatorclient_common.cpp+5−119 plugins/IndicatorsClient/indicators/common/indicatorclient_common.h+2−16 plugins/IndicatorsClient/indicators/datetime/indicatorclient_datetime.cpp+4−67 plugins/IndicatorsClient/indicators/datetime/indicatorclient_datetime.h+2−6 plugins/IndicatorsClient/indicators/messaging/indicatorclient_messaging.cpp+7−2 plugins/IndicatorsClient/indicators/messaging/indicatorclient_messaging.h+3−1 plugins/IndicatorsClient/indicators/network/indicatorclient_network.cpp+6−110 plugins/IndicatorsClient/indicators/network/indicatorclient_network.h+2−12 plugins/IndicatorsClient/indicators/power/indicatorclient_power.cpp+6−1 plugins/IndicatorsClient/indicators/power/indicatorclient_power.h+2 plugins/IndicatorsClient/indicators/sound/indicatorclient_sound.cpp+6−1 plugins/IndicatorsClient/indicators/sound/indicatorclient_sound.h+2 plugins/IndicatorsClient/indicatorsmodel.cpp+11−18 plugins/IndicatorsClient/indicatorsmodel.h+2−3 plugins/IndicatorsClient/qml/DBusActionState.qml+2−2 plugins/IndicatorsClient/qml/FactoryMenu.qml+25−25 plugins/IndicatorsClient/qml/IndicatorBase.qml+57 plugins/IndicatorsClient/qml/IndicatorIcon.qml+73 plugins/IndicatorsClient/qml/PluginItem.qml → plugins/IndicatorsClient/qml/IndicatorPage.qml+11−31 plugins/IndicatorsClient/qml/qmldir+3−1 plugins/IndicatorsClient/resources/indicatorclient.qrc+7−4 plugins/IndicatorsClient/resources/qml/DatetimeIndicatorIcon.qml+67 plugins/IndicatorsClient/resources/qml/DatetimeIndicator.qml → plugins/IndicatorsClient/resources/qml/DatetimeIndicatorPage.qml plugins/IndicatorsClient/resources/qml/DefaultIndicatorIcon.qml+80 plugins/IndicatorsClient/resources/qml/CommonIndicator.qml → plugins/IndicatorsClient/resources/qml/DefaultIndicatorPage.qml+2−1 plugins/IndicatorsClient/resources/qml/MessagingIndicator.qml → plugins/IndicatorsClient/resources/qml/MessagingIndicatorPage.qml+2−2 plugins/IndicatorsClient/resources/qml/NetworkIndicatorIcon.qml+116 plugins/IndicatorsClient/resources/qml/NetworkIndicator.qml → plugins/IndicatorsClient/resources/qml/NetworkIndicatorPage.qml+2−1 tests/plugins/IndicatorsClient/fakeindicator.h+1−2 tests/plugins/IndicatorsClient/indicatorsmanagertest.cpp+2−3 tests/plugins/IndicatorsClient/indicatorsmodeltest.cpp+2−4
Panel/IndicatorItem.qml+28−35
@@ -16,18 +16,42 @@
1616
1717import QtQuick 2.0
1818import Ubuntu.Components 0.1
19+import IndicatorsClient 0.1 as IndicatorsClient
1920
2021Item {
2122 id: indicatorItem
2223
23− property alias iconSource: itemImage.source
24− property alias label: itemLabel.text
24+ property alias iconUrl: loader.source
2525 property bool highlighted: false
2626 property bool dimmed: false
27+ property var initialProperties: undefined
28+
29+ opacity: dimmed ? 0.4 : 1
2730
2831 // only visible when non-empty
29− visible: label != "" || iconSource != ""
30− width: itemRow.width + units.gu(1)
32+ visible: loader.item != undefined && loader.status == Loader.Ready
33+ width: visible ? loader.item.width : 0
34+
35+ Loader {
36+ id: loader
37+
38+ onStatusChanged: {
39+ if (status == Loader.Ready) {
40+ item.height = Qt.binding(function() { return indicatorItem.height; })
41+
42+ for(var pName in initialProperties) {
43+ if (item.hasOwnProperty(pName)) {
44+ item[pName] = initialProperties[pName]
45+ }
46+ }
47+ }
48+ }
49+ }
50+
51+ Connections {
52+ target: loader.item
53+ onVisibleChanged: { visible = loader.item.visible }
54+ }
3155
3256 Rectangle {
3357 color: "#dd4814"
@@ -36,35 +60,4 @@ Item {
3660 anchors.top: parent.bottom
3761 visible: highlighted
3862 }
39−
40− Row {
41− id: itemRow
42− objectName: "itemRow"
43− anchors {
44− top: parent.top
45− bottom: parent.bottom
46− horizontalCenter: parent.horizontalCenter
47− }
48− spacing: units.gu(0.5)
49− opacity: dimmed ? 0.4 : 1
50−
51− Image {
52− id: itemImage
53− objectName: "itemImage"
54− visible: source != ""
55− height: units.gu(2.5)
56− width: units.gu(2.5)
57− anchors.verticalCenter: parent.verticalCenter
58− }
59−
60− Label {
61− id: itemLabel
62− objectName: "itemLabel"
63− color: "#f3f3e7"
64− opacity: 0.8
65− font.family: "Ubuntu"
66− fontSize: "medium"
67− anchors.verticalCenter: parent.verticalCenter
68− }
69− }
7063}
Panel/IndicatorRow.qml+2−2
@@ -59,8 +59,8 @@ Item {
5959
6060 property int ownIndex: index
6161
62− label: model.label
63− iconSource: model.iconSource
62+ iconUrl: model.iconUrl
63+ initialProperties : model.initialProperties
6464 highlighted: indicatorRow.state == "reveal" || indicatorRow.state == "locked" || indicatorRow.state == "commit" ? ownIndex == indicatorRow.currentItemIndex : false
6565 dimmed: { //See FIXME in Indicators regarding the "states" change
6666 if (indicatorRow.state == "initial" || indicatorRow.state == "") {
Panel/MenuContent.qml+1−1
@@ -94,7 +94,7 @@ Rectangle {
9494
9595 width: menus.width
9696 height: menus.height
97− source: component
97+ source: pageUrl
9898 visible: content.__shown
9999 onVisibleChanged: {
100100 // Reset the indicator states
plugins/IndicatorsClient/flatmenuproxymodel.cpp+15
@@ -323,3 +323,18 @@ int FlatMenuProxyModel::rowOffsetOf(const QModelIndex &index, int row, bool incl
323323
324324 return offset;
325325}
326+
327+/*! \for use in qml */
328+QVariantMap FlatMenuProxyModel::get(int row) const
329+{
330+ QVariantMap result;
331+
332+ QModelIndex index = this->index(row);
333+ if (index.isValid()) {
334+ const QHash<int, QByteArray> roleNames = this->roleNames();
335+ Q_FOREACH(int i, roleNames.keys()) {
336+ result.insert(roleNames[i], data(index, i));
337+ }
338+ }
339+ return result;
340+}
plugins/IndicatorsClient/flatmenuproxymodel.h+3
@@ -60,6 +60,9 @@ public:
6060
6161 int status() const;
6262
63+ /* QML */
64+ Q_INVOKABLE QVariantMap get(int row) const;
65+
6366public Q_SLOTS:
6467 void onRowsInserted(const QModelIndex &parent, int start, int end);
6568 void onRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
plugins/IndicatorsClient/indicatorclientinterface.h+8−13
@@ -63,14 +63,6 @@ public:
6363 */
6464 virtual QString identifier() const = 0;
6565
66− /**
67− * @brief Used to retrieve the current plugin icon
68− * @return The icon url
69− *
70− * This function can be used to retrieve the indicator icon which will appear on the panel
71− */
72− virtual QUrl icon() const = 0;
73−
7466 /**
7567 * @brief Used to retrieve the current plugin title
7668 * @return The title
@@ -109,14 +101,17 @@ public:
109101 */
110102 virtual int priority() const = 0;
111103
104+ /**
105+ * @brief Used to retrieve the icon component source file
106+ * @return The icon component url
107+ */
108+ virtual QUrl iconComponentSource() const = 0;
112109
113110 /**
114− * @brief Used to retrieve the plugin initial component
115− * @param engine The current \l QDeclarativeEngine used to parse the componente code
116− * @param parent The parent of the returned object
117− * @return A new \l QDeclarativeComponent with the initial plugin view
111+ * @brief Used to retrieve the plugin page component source file
112+ * @return A url pointing to the component source file
118113 */
119− virtual QUrl componentSource() const = 0;
114+ virtual QUrl pageComponentSource() const = 0;
120115
121116 /**
122117 * @brief Used during the plugin Component instanciation to set the initial properties
plugins/IndicatorsClient/indicators/common/indicatorclient_common.cpp+5−119
@@ -38,13 +38,8 @@
3838
3939IndicatorClientCommon::IndicatorClientCommon(QObject *parent)
4040 : QObject(parent),
41− m_icon(""),
4241 m_visible(false),
43− m_priority(0),
44− m_model(0),
45− m_actionGroup(0),
46− m_action(0),
47− m_component(0)
42+ m_priority(0)
4843{
4944}
5045
@@ -59,107 +54,15 @@ void IndicatorClientCommon::init(const QSettings& settings)
5954 QString dbusService = settings.value("Indicator Service/DBusName").toString();
6055 QString objectPath = settings.value("Indicator Service/ObjectPath").toString();
6156
62− m_model = new QDBusMenuModel(this);
63− m_model->setBusName(dbusService);
64− m_model->setObjectPath(objectPath + "/" + TARGET_DEVICE);
65− m_model->setBusType(DBusEnums::SessionBus);
66−
67− //keep track of any change in the model
68− connect(m_model, SIGNAL(statusChanged(DBusEnums::ConnectionStatus)), SLOT(onModelChanged()));
69− connect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(onModelChanged()));
70− connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(onModelChanged()));
71− connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), SLOT(onModelChanged()));
72−
73− m_actionGroup = new QDBusActionGroup(this);
74− m_actionGroup->setBusType(m_model->busType());
75− m_actionGroup->setBusName(m_model->busName());
76− m_actionGroup->setObjectPath(objectPath);
77−
7857 m_initialProperties.clear();
7958 m_initialProperties.insert("title", m_title);
8059 m_initialProperties.insert("busType", 1);
8160 m_initialProperties.insert("busName", dbusService);
8261 m_initialProperties.insert("objectPath", objectPath);
83−
84− m_actionGroup->start();
85− m_model->start();
86−}
87−
88−void IndicatorClientCommon::onModelChanged()
89−{
90− DBusEnums::ConnectionStatus status = m_model->status();
91−
92− if (status == DBusEnums::Connected) {
93− QModelIndex index = m_model->index(0);
94− if (index.isValid()) {
95− QVariant extra = m_model->data(index, QDBusMenuModel::Extra);
96− QVariantMap extraMap = extra.toMap();
97− if (extraMap.contains("canonical_type")) {
98− QString type = extraMap["canonical_type"].toString();
99− parseRootElement(type, m_model->itemData(index));
100− }
101− }
102− } else {
103− parseRootElement("", QMap<int, QVariant>());
104− }
105−}
106−
107−bool IndicatorClientCommon::parseRootElement(const QString &type, QMap<int, QVariant> data)
108−{
109− if (type.isEmpty()) {
110− return false;
111− } else if (type != "com.canonical.indicator.root") {
112− if (!type.startsWith("com.canonical.indicator.root")) {
113− qWarning() << "indicator" << title() << "does not support root element";
114− }
115− return false;
116− } else {
117− if (m_action != 0) {
118− delete m_action;
119− }
120−
121− QVariant action = data[QDBusMenuModel::Action];
122− m_action = m_actionGroup->action(action.toString());
123−
124− if (m_action->isValid()) {
125− updateState(m_action->state());
126− }
127− QObject::connect(m_action, SIGNAL(stateChanged(QVariant)), this, SLOT(updateState(QVariant)));
128− return true;
129− }
130−}
131−
132−void IndicatorClientCommon::updateState(const QVariant &state)
133−{
134− if (state.isValid()) {
135− // (sssb) : the current label, icon name, accessible name, and visibility state of the indicator.
136− QVariantList states = state.toList();
137− if (states.size() == 4) {
138− setLabel(states[0].toString());
139− setIcon(QUrl(states[1].toString()));
140− setVisible(states[2].toBool());
141− return;
142− }
143− }
144−
145− setLabel("");
146− setIcon(QUrl());
147− setVisible(false);
14862}
14963
15064void IndicatorClientCommon::shutdown()
15165{
152− delete m_component;
153− m_component = 0;
154−
155− delete m_model;
156− m_model = 0;
157−
158− delete m_action;
159− m_action = 0;
160−
161− delete m_actionGroup;
162− m_actionGroup = 0;
16366}
16467
16568QString IndicatorClientCommon::identifier() const
@@ -175,23 +78,6 @@ void IndicatorClientCommon::setId(const QString &identifier)
17578 }
17679}
17780
178−QUrl IndicatorClientCommon::icon() const
179−{
180− if (!m_icon.isEmpty() && m_icon.scheme().isEmpty()) {
181− return QString("image://gicon/") + QUrl::toPercentEncoding(m_icon.toString());
182− } else {
183− return m_icon;
184− }
185−}
186−
187−void IndicatorClientCommon::setIcon(const QUrl &icon)
188−{
189− if (icon != m_icon) {
190− m_icon = icon;
191− Q_EMIT iconChanged(m_icon);
192− }
193−}
194−
19581QString IndicatorClientCommon::title() const
19682{
19783 return m_title;
@@ -257,14 +143,14 @@ void IndicatorClientCommon::setLabel(const QString &label)
257143 }
258144}
259145
260−QDBusActionGroup *IndicatorClientCommon::actionGroup() const
146+QUrl IndicatorClientCommon::iconComponentSource() const
261147{
262− return m_actionGroup;
148+ return QUrl("qrc:/indicatorsclient/qml/DefaultIndicatorIcon.qml");
263149}
264150
265−QUrl IndicatorClientCommon::componentSource() const
151+QUrl IndicatorClientCommon::pageComponentSource() const
266152{
267− return QUrl("qrc:/indicatorsclient/qml/CommonIndicator.qml");
153+ return QUrl("qrc:/indicatorsclient/qml/DefaultIndicatorPage.qml");
268154}
269155
270156IndicatorClientInterface::PropertiesMap IndicatorClientCommon::initialProperties()
plugins/IndicatorsClient/indicators/common/indicatorclient_common.h+2−16
@@ -35,7 +35,6 @@ class IndicatorClientCommon : public QObject, public IndicatorClientInterface
3535 Q_PROPERTY(QString title READ title NOTIFY titleChanged)
3636 Q_PROPERTY(QString label READ label NOTIFY labelChanged)
3737 Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
38− Q_PROPERTY(QUrl icon READ icon NOTIFY iconChanged)
3938 Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
4039 Q_PROPERTY(int priority READ priority NOTIFY priorityChanged)
4140
@@ -47,19 +46,18 @@ public:
4746 void shutdown();
4847
4948 QString identifier() const;
50− QUrl icon() const;
5149 QString title() const;
5250 bool visible() const;
5351 QString description() const;
5452 QString label() const;
5553 int priority() const;
5654
57− QUrl componentSource() const;
55+ QUrl iconComponentSource() const;
56+ QUrl pageComponentSource() const;
5857 PropertiesMap initialProperties();
5958
6059Q_SIGNALS:
6160 void identifierChanged(const QString &identifier);
62− void iconChanged(const QUrl &icon);
6361 void titleChanged(const QString &title);
6462 void visibleChanged(bool visible);
6563 void descriptionChanged(const QString &description);
@@ -70,31 +68,19 @@ protected:
7068 PropertiesMap m_initialProperties;
7169
7270 void setId(const QString &id);
73− void setIcon(const QUrl &icon);
7471 void setTitle(const QString &title);
7572 void setDescription(const QString &description);
7673 void setVisible(bool visible);
7774 void setLabel(const QString &title);
7875 void setPriority(int priority);
79− virtual bool parseRootElement(const QString &type, QMap<int, QVariant> data);
80− QDBusActionGroup *actionGroup() const;
81−
82−private Q_SLOTS:
83− void onModelChanged();
84− void updateState(const QVariant &state);
8576
8677private:
8778 QString m_identifier;
88− QUrl m_icon;
8979 QString m_title;
9080 QString m_description;
9181 QString m_label;
9282 bool m_visible;
9383 int m_priority;
94− QDBusMenuModel *m_model;
95− QDBusActionGroup *m_actionGroup;
96− QStateAction *m_action;
97− QQmlComponent *m_component;
9884};
9985
10086#endif // INDICATORCLIENT_COMMON_H
plugins/IndicatorsClient/indicators/datetime/indicatorclient_datetime.cpp+4−67
@@ -32,90 +32,27 @@ IndicatorClientDateTime::IndicatorClientDateTime(QObject *parent)
3232{
3333 setTitle("Date and Time");
3434 setPriority(IndicatorPriority::DATETIME);
35−
36− connect(&m_timer, SIGNAL(timeout()), SLOT(onTimeout()));
3735}
3836
3937IndicatorClientDateTime::~IndicatorClientDateTime()
4038{
41− if (m_action) {
42− delete m_action;
43− }
4439}
4540
4641void IndicatorClientDateTime::init(const QSettings& settings)
4742{
4843 IndicatorClientCommon::init(settings);
49−
50− m_timer.start(1000 * 10);
5144}
5245
5346void IndicatorClientDateTime::shutdown()
5447{
55− m_timer.stop();
56−}
57−
58−
59−QString IndicatorClientDateTime::dateTime() const
60−{
61− static char timestr[255];
62− time_t t;
63− struct tm *tmp;
64−
65− t = time(NULL);
66− tmp = localtime(&t);
67− if (tmp == 0) {
68− return "";
69− }
70−
71− int size = strftime(timestr, 255, m_format.toUtf8().data(), tmp);
72− if (size == 0) {
73− return "";
74− }
75−
76− return QString::fromLatin1(timestr, size);
77−}
78−
79−bool IndicatorClientDateTime::parseRootElement(const QString &type, QMap<int, QVariant> data)
80−{
81− if (type == "com.canonical.indicator.root.time") {
82− if (m_action != 0) {
83− delete m_action;
84− }
85−
86− QVariant action = data[QDBusMenuModel::Action];
87− m_action = actionGroup()->action(action.toString());
88− if (m_action->isValid()) {
89− updateTimeFormat(m_action->state());
90− }
91− QObject::connect(m_action, SIGNAL(stateChanged(QVariant)), this, SLOT(updateTimeFormat(QVariant)));
92− return true;
93− } else {
94− return false;
95− }
96−}
97−
98−void IndicatorClientDateTime::updateTimeFormat(const QVariant &state)
99−{
100− if (state.isValid()) {
101− // (sssb) : time format, icon, accessible name format, visible
102− QVariantList states = state.toList();
103− if (states.size() == 4) {
104− m_format = states[0].toString();
105− setIcon(QUrl(states[1].toString()));
106− setVisible(states[2].toBool());
107− onTimeout();
108− }
109− }
11048}
11149
112−QUrl IndicatorClientDateTime::componentSource() const
50+QUrl IndicatorClientDateTime::iconComponentSource() const
11351{
114− return QUrl("qrc:/indicatorsclient/qml/DatetimeIndicator.qml");
52+ return QUrl("qrc:/indicatorsclient/qml/DatetimeIndicatorIcon.qml");
11553}
11654
117−void IndicatorClientDateTime::onTimeout()
55+QUrl IndicatorClientDateTime::pageComponentSource() const
11856{
119− QString newValue = dateTime();
120− setLabel(newValue);
57+ return QUrl("qrc:/indicatorsclient/qml/DatetimeIndicatorPage.qml");
12158}
plugins/IndicatorsClient/indicators/datetime/indicatorclient_datetime.h+2−6
@@ -36,13 +36,9 @@ public:
3636
3737 void init(const QSettings& settings);
3838 void shutdown();
39− QString dateTime() const;
40− bool parseRootElement(const QString &type, QMap<int, QVariant> data);
41− QUrl componentSource() const;
4239
43−private Q_SLOTS:
44− void onTimeout();
45− void updateTimeFormat(const QVariant &state);
40+ QUrl iconComponentSource() const;
41+ QUrl pageComponentSource() const;
4642
4743private:
4844 QTimer m_timer;
plugins/IndicatorsClient/indicators/messaging/indicatorclient_messaging.cpp+7−2
@@ -42,7 +42,12 @@ void IndicatorClientMessaging::init(const QSettings& settings)
4242 m_initialProperties.insert("highlightFollowsCurrentItem", false);
4343}
4444
45−QUrl IndicatorClientMessaging::componentSource() const
45+QUrl IndicatorClientMessaging::iconComponentSource() const
4646{
47− return QUrl("qrc:/indicatorsclient/qml/MessagingIndicator.qml");
47+ return QUrl("qrc:/indicatorsclient/qml/DefaultIndicatorIcon.qml");
48+}
49+
50+QUrl IndicatorClientMessaging::pageComponentSource() const
51+{
52+ return QUrl("qrc:/indicatorsclient/qml/MessagingIndicatorPage.qml");
4853}
plugins/IndicatorsClient/indicators/messaging/indicatorclient_messaging.h+3−1
@@ -31,7 +31,9 @@ public:
3131 ~IndicatorClientMessaging();
3232
3333 void init(const QSettings& settings);
34− QUrl componentSource() const;
34+
35+ QUrl iconComponentSource() const;
36+ QUrl pageComponentSource() const;
3537};
3638
3739#endif
plugins/IndicatorsClient/indicators/network/indicatorclient_network.cpp+6−110
@@ -29,14 +29,10 @@
2929#include <qstateaction.h>
3030
3131IndicatorClientNetwork::IndicatorClientNetwork(QObject *parent)
32− : IndicatorClientCommon(parent),
33− m_action(0)
32+ : IndicatorClientCommon(parent)
3433{
3534 setTitle("Networks");
3635 setPriority(IndicatorPriority::NETWORK);
37−
38− m_timedAnimation.setInterval(500);
39− connect(&m_timedAnimation, SIGNAL(timeout()), SLOT(animationNextFrame()));
4036}
4137
4238IndicatorClientNetwork::~IndicatorClientNetwork()
@@ -48,115 +44,15 @@ void IndicatorClientNetwork::init(const QSettings& settings)
4844 IndicatorClientCommon::init(settings);
4945
5046 qmlRegisterType<NetworkAgent>("NetworkSettings", 0, 1, "NetworkAgent");
51− setIcon(QUrl("image://gicon/wifi-none"));
47+ // setIcon(QUrl("image://gicon/wifi-none"));
5248}
5349
54−QUrl IndicatorClientNetwork::componentSource() const
50+QUrl IndicatorClientNetwork::iconComponentSource() const
5551{
56− return QUrl("qrc:/indicatorsclient/qml/NetworkIndicator.qml");
52+ return QUrl("qrc:/indicatorsclient/qml/NetworkIndicatorIcon.qml");
5753}
5854
59−bool IndicatorClientNetwork::parseRootElement(const QString &type, QMap<int, QVariant> data)
55+QUrl IndicatorClientNetwork::pageComponentSource() const
6056{
61− if (type == "com.canonical.indicator.root.network") {
62− if (m_action != 0) {
63− delete m_action;
64− }
65−
66− QVariant action = data[QDBusMenuModel::Action];
67− m_action = actionGroup()->action(action.toString());
68− if (m_action->isValid()) {
69− updateNetworkStatus(m_action->state());
70− }
71− connect(m_action, SIGNAL(stateChanged(QVariant)), SLOT(updateNetworkStatus(QVariant)));
72− return true;
73− } else {
74− return false;
75− }
76−}
77−
78−QString IndicatorClientNetwork::getIconBasedOnSingal(uint signal) const
79−{
80− if (signal == 0) {
81− return "nm-signal-00";
82− } else if (signal <= 25) {
83− return "nm-signal-25";
84− } else if (signal <= 50) {
85− return "nm-signal-50";
86− } else if (signal <= 75) {
87− return "nm-signal-75";
88− } else {
89− return "nm-signal-100";
90− }
91−}
92−
93−void IndicatorClientNetwork::animationNextFrame()
94−{
95− static int frame = 0;
96− QString iconName;
97− switch (frame) {
98− case 0:
99− iconName = "nm-signal-00";
100− break;
101− case 1:
102− iconName = "nm-signal-25";
103− break;
104− case 2:
105− iconName = "nm-signal-50";
106− break;
107− case 3:
108− iconName = "nm-signal-75";
109− break;
110− case 4:
111− iconName = "nm-signal-100";
112− break;
113− }
114−
115− if (frame < 4) {
116− frame++;
117− } else {
118− frame = 0;
119− }
120− setIcon(QUrl("image://gicon/" + iconName));
121−}
122−
123−void IndicatorClientNetwork::updateNetworkStatus(const QVariant &state)
124−{
125− if (state.isValid()) {
126− // (uuu)
127− // - Device type
128− // - Connection state
129− // - Extended state
130− QVariantList states = state.toList();
131− if (states.size() == 3) {
132− QString iconName;
133− uint connectionState = states[1].toUInt();
134− switch (connectionState)
135− {
136− case 3: // NM_ACTIVE_CONNECTION_STATE_DEACTIVATING
137− case 1: // NM_ACTIVE_CONNECTION_STATE_ACTIVATING
138− m_timedAnimation.start();
139− iconName = "nm-signal-100";
140− break;
141− case 2: // NM_ACTIVE_CONNECTION_STATE_ACTIVATED
142− m_timedAnimation.stop();
143− iconName = getIconBasedOnSingal(states[2].toUInt());
144− break;
145− case 0: // NM_ACTIVE_CONNECTION_STATE_UNKNOWN
146− default:
147− m_timedAnimation.stop();
148− iconName = "wifi-none";
149− break;
150− }
151−
152− setIcon(QUrl("image://gicon/" + iconName));
153− return;
154− } else {
155− qWarning() << "Invalid network root state value";
156− m_timedAnimation.stop();
157− setIcon(QUrl());
158− }
159− } else {
160− qWarning() << "Invalid network root state";
161− }
57+ return QUrl("qrc:/indicatorsclient/qml/NetworkIndicatorPage.qml");
16258}
plugins/IndicatorsClient/indicators/network/indicatorclient_network.h+2−12
@@ -33,18 +33,8 @@ public:
3333 ~IndicatorClientNetwork();
3434
3535 void init(const QSettings& settings);
36− QUrl componentSource() const;
37− bool parseRootElement(const QString &type, QMap<int, QVariant> data);
38−
39−private Q_SLOTS:
40− void animationNextFrame();
41− void updateNetworkStatus(const QVariant &state);
42−
43−private:
44− QStateAction *m_action;
45− QTimer m_timedAnimation;
46−
47− QString getIconBasedOnSingal(uint signal) const;
36+ QUrl iconComponentSource() const;
37+ QUrl pageComponentSource() const;
4838};
4939
5040#endif
plugins/IndicatorsClient/indicators/power/indicatorclient_power.cpp+6−1
@@ -30,4 +30,9 @@ IndicatorClientPower::IndicatorClientPower(QObject *parent)
3030void IndicatorClientPower::init(const QSettings& settings)
3131{
3232 IndicatorClientCommon::init(settings);
33−}
33+}
34+
35+QUrl IndicatorClientPower::iconComponentSource() const
36+{
37+ return QUrl("qrc:/indicatorsclient/qml/DefaultIndicatorIcon.qml");
38+}
plugins/IndicatorsClient/indicators/power/indicatorclient_power.h+2
@@ -30,6 +30,8 @@ public:
3030 IndicatorClientPower(QObject *parent=0);
3131
3232 void init(const QSettings& settings);
33+
34+ QUrl iconComponentSource() const;
3335};
3436
3537#endif
plugins/IndicatorsClient/indicators/sound/indicatorclient_sound.cpp+6−1
@@ -24,7 +24,7 @@ IndicatorClientSound::IndicatorClientSound(QObject *parent)
2424{
2525 setTitle("Sound");
2626 setPriority(IndicatorPriority::SOUND);
27− setIcon(QUrl("audio-volume-high"));
27+ // setIcon(QUrl("audio-volume-high"));
2828}
2929
3030
@@ -32,3 +32,8 @@ void IndicatorClientSound::init(const QSettings& settings)
3232{
3333 IndicatorClientCommon::init(settings);
3434}
35+
36+QUrl IndicatorClientSound::iconComponentSource() const
37+{
38+ return QUrl("qrc:/indicatorsclient/qml/DefaultIndicatorIcon.qml");
39+}
plugins/IndicatorsClient/indicators/sound/indicatorclient_sound.h+2
@@ -29,6 +29,8 @@ public:
2929 IndicatorClientSound(QObject *parent=0);
3030
3131 void init(const QSettings& settings);
32+
33+ QUrl iconComponentSource() const;
3234};
3335
3436#endif
plugins/IndicatorsClient/indicatorsmodel.cpp+11−18
@@ -141,7 +141,6 @@ void IndicatorsModel::onIndicatorLoaded(const QString& indicator)
141141 if (obj)
142142 {
143143 QObject::connect(obj, SIGNAL(identifierChanged(const QString&)), this, SLOT(onIdentifierChanged()));
144− QObject::connect(obj, SIGNAL(iconChanged(const QUrl&)), this, SLOT(onIconChanged()));
145144 QObject::connect(obj, SIGNAL(titleChanged(const QString&)), this, SLOT(onTitleChanged()));
146145 QObject::connect(obj, SIGNAL(labelChanged(const QString&)), this, SLOT(onLabelChanged()));
147146 }
@@ -179,12 +178,6 @@ void IndicatorsModel::onIdentifierChanged()
179178 notifyDataChanged(QObject::sender(), Identifier);
180179}
181180
182−/*! \internal */
183−void IndicatorsModel::onIconChanged()
184−{
185− notifyDataChanged(QObject::sender(), IconSource);
186−}
187−
188181/*! \internal */
189182void IndicatorsModel::onTitleChanged()
190183{
@@ -225,10 +218,10 @@ QHash<int, QByteArray> IndicatorsModel::roleNames() const
225218 if (roles.isEmpty()) {
226219 roles[Identifier] = "identifier";
227220 roles[Title] = "title";
228− roles[IconSource] = "iconSource";
229221 roles[Label] = "label";
230222 roles[Description] = "description";
231− roles[QMLComponent] = "component";
223+ roles[IconUrl] = "iconUrl";
224+ roles[PageUrl] = "pageUrl";
232225 roles[InitialProperties] = "initialProperties";
233226 roles[IsValid] = "isValid";
234227 }
@@ -262,13 +255,6 @@ QVariant IndicatorsModel::data(const QModelIndex &index, int role) const
262255 attribute = QVariant(plugin->title());
263256 }
264257 break;
265− case IconSource:
266− if (plugin) {
267− return plugin->icon().toString();
268− } else {
269− attribute = QVariant("No plugin");
270− }
271− break;
272258 case Label:
273259 if (plugin) {
274260 attribute = QVariant(plugin->label());
@@ -281,9 +267,16 @@ QVariant IndicatorsModel::data(const QModelIndex &index, int role) const
281267 }
282268 break;
283269 }
284− case QMLComponent:
270+ case IconUrl:
271+ if (plugin) {
272+ return plugin->iconComponentSource().toString();
273+ } else {
274+ attribute = QVariant("No plugin");
275+ }
276+ break;
277+ case PageUrl:
285278 if (plugin) {
286− return plugin->componentSource();
279+ return plugin->pageComponentSource();
287280 }
288281 break;
289282 case InitialProperties:
plugins/IndicatorsClient/indicatorsmodel.h+2−3
@@ -37,10 +37,10 @@ public:
3737 enum ModelRoles {
3838 Identifier = 0,
3939 Title,
40− IconSource,
4140 Label,
4241 Description,
43− QMLComponent,
42+ IconUrl,
43+ PageUrl,
4444 InitialProperties,
4545 IsValid
4646 };
@@ -65,7 +65,6 @@ Q_SIGNALS:
6565
6666private Q_SLOTS:
6767 void onIdentifierChanged();
68− void onIconChanged();
6968 void onTitleChanged();
7069 void onLabelChanged();
7170 void onIndicatorLoaded(const QString& indicator);
plugins/IndicatorsClient/qml/DBusActionState.qml+2−2
@@ -79,12 +79,12 @@ Item {
7979 Item {
8080 id: priv
8181 property variant actionObject : action && actionGroup ? actionGroup.action(action) : null
82− property variant actionState: actionObject && actionObject.valid ? actionObject.state : undefined
82+ property variant actionState: actionObject ? actionObject.state : undefined
8383
8484 Binding {
8585 id: propertyBinding
8686 value: priv.actionState
87− when: (actionGroup && active && priv.actionObject && priv.actionObject.valid)
87+ when: (actionGroup && active && priv.actionObject)
8888 }
8989 }
9090
plugins/IndicatorsClient/qml/FactoryMenu.qml+25−25
@@ -39,7 +39,7 @@ Item {
3939 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
4040 "unity.widgets.systemsettings.tablet.switch" : switchMenu,
4141
42− "com.canonical.indicator.button" : buttomMenu,
42+ "com.canonical.indicator.button" : buttonMenu,
4343 "com.canonical.indicator.div" : divMenu,
4444 "com.canonical.indicator.section" : sectionMenu,
4545 "com.canonical.indicator.progress" : progressMenu,
@@ -57,7 +57,7 @@ Item {
5757
5858 Component { id: sliderMenu; IC.SliderMenu {} }
5959 Component { id: switchMenu; IC.SwitchMenu {} }
60− Component { id: buttomMenu; IC.ButtonMenu {} }
60+ Component { id: buttonMenu; IC.ButtonMenu {} }
6161 Component { id: divMenu; IC.DivMenu {} }
6262 Component { id: sectionMenu; IC.SectionMenu {} }
6363 Component { id: progressMenu; IC.ProgressMenu {} }
@@ -69,38 +69,38 @@ Item {
6969 Component { id: indicatorMenu; IC.Menu {} }
7070
7171 Loader {
72− id: __loader
73− anchors.fill: parent
74− asynchronous: true
75− sourceComponent: {
76− if (!__menuFactory.menu || !__menuFactory.menu.extra) {
77− return undefined
78− }
72+ id: __loader
73+ anchors.fill: parent
74+ asynchronous: true
75+ sourceComponent: {
76+ if (!__menuFactory.menu || !__menuFactory.menu.extra) {
77+ return undefined
78+ }
7979
80− var widgetType = __menuFactory.menu.extra.canonical_type
81− var sourceFile = null
82− if (widgetType) {
83− var component = _map[widgetType]
84− if (component != undefined) {
85− return component
86− }
87− }
80+ var widgetType = __menuFactory.menu.extra.canonical_type
81+ if (widgetType) {
82+ return _map[widgetType]
83+ }
84+ else {
8885 if (widgetType === "com.canonical.indicator.root") {
8986 return undefined
9087 // Try discovery the item based on the basic properties
9188 } else if (menu.hasSection) {
9289 return sectionMenu
9390 }
94− return indicatorMenu
91+ else {
92+ return indicatorMenu
93+ }
9594 }
95+ return undefined
96+ }
9697
97− onStatusChanged: {
98− if (status == Loader.Ready) {
99− item.listViewIsCurrentItem = Qt.binding(function() { return isCurrentItem; });
100− item.actionGroup = Qt.binding(function() { return __menuFactory.actionGroup; });
101− item.menu = Qt.binding(function() { return __menuFactory.menu; });
102− }
98+ onStatusChanged: {
99+ if (status == Loader.Ready) {
100+ item.listViewIsCurrentItem = Qt.binding(function() { return isCurrentItem; });
101+ item.actionGroup = Qt.binding(function() { return __menuFactory.actionGroup; });
102+ item.menu = Qt.binding(function() { return __menuFactory.menu; });
103103 }
104+ }
104105 }
105−
106106}
plugins/IndicatorsClient/qml/IndicatorBase.qmlnew file+57
@@ -0,0 +1,57 @@
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+import QtQuick 2.0
21+import QMenuModel 0.1
22+import Ubuntu.Components 0.1
23+import Ubuntu.Components.ListItems 0.1 as ListItem
24+import IndicatorsClient 0.1 as IndicatorsClient
25+
26+Item {
27+ id: indicatorItem
28+
29+ //const
30+ property string title
31+ property string device: "phone"
32+ property int busType
33+ property string busName
34+ property string objectPath
35+
36+ signal actionGroupUpdated()
37+ signal modelUpdated()
38+
39+ property var actionGroup : QDBusActionGroup {
40+ busType: indicatorItem.busType
41+ busName: indicatorItem.busName
42+ objectPath: indicatorItem.objectPath
43+
44+ onActionAppear: indicatorItem.actionGroupUpdated();
45+ }
46+
47+ property var proxyModel : IndicatorsClient.FlatMenuProxyModel {
48+ busType: indicatorItem.busType
49+ busName: indicatorItem.busName
50+ objectPath: indicatorItem.objectPath + "/" + device
51+
52+ onStatusChanged: indicatorItem.modelUpdated();
53+ onRowsInserted: indicatorItem.modelUpdated();
54+ onRowsRemoved: indicatorItem.modelUpdated();
55+ onDataChanged: indicatorItem.modelUpdated();
56+ }
57+}
plugins/IndicatorsClient/qml/IndicatorIcon.qmlnew file+73
@@ -0,0 +1,73 @@
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+import QtQuick 2.0
21+import QMenuModel 0.1
22+import Ubuntu.Components 0.1
23+import Ubuntu.Components.ListItems 0.1 as ListItem
24+
25+IndicatorBase {
26+ id: indicatorIcon
27+ property var action: undefined
28+ property bool started: (busType != 0) && (busName != "") && (objectPath != "")
29+
30+ signal actionStateChanged()
31+
32+ onStartedChanged: {
33+ if (started) {
34+ proxyModel.start()
35+ actionGroup.start()
36+ }
37+ else {
38+ proxyModel.stop()
39+ actionGroup.stop()
40+ }
41+ }
42+ onActionChanged: actionStateChanged()
43+ onActionGroupUpdated: update_state()
44+ onModelUpdated: update_state()
45+
46+ function update_state() {
47+ var data = proxyModel.get(0)
48+ if (data == undefined || data.extra == undefined) {
49+ return
50+ }
51+
52+ if (!data.extra.hasOwnProperty("canonical_type")) {
53+ return;
54+ }
55+
56+ if (parseRootElement(data.extra.canonical_type, data)) {
57+ action = actionGroup.action(data.action)
58+ }
59+ }
60+
61+ function parseRootElement(type, data) {
62+ if (type == "com.canonical.indicator.root")
63+ return true;
64+ return false;
65+ }
66+
67+ Connections {
68+ target: action == undefined ? null : action
69+ onStateChanged: actionStateChanged()
70+ onValidChanged: actionStateChanged()
71+ }
72+}
73+
plugins/IndicatorsClient/qml/PluginItem.qml → plugins/IndicatorsClient/qml/IndicatorPage.qmlrenamed+11−31
@@ -23,43 +23,23 @@ import Ubuntu.Components 0.1
2323import Ubuntu.Components.ListItems 0.1 as ListItem
2424import IndicatorsClient 0.1 as IndicatorsClient
2525
26−Item {
26+IndicatorBase {
2727 id: main
2828
2929 //const
30− property string device: "phone"
31− property string title
3230 property alias emptyText: emptyLabel.text
33− property int busType
34− property string busName
35− property string objectPath
3631 property alias highlightFollowsCurrentItem : mainMenu.highlightFollowsCurrentItem
3732 readonly property real overshootHeight: (mainMenu.contentY < 0) ? -mainMenu.contentY : 0
3833 property bool __active: false
3934
4035 anchors.fill: parent
4136
42− QDBusActionGroup {
43− id: __actionGroup
44− busType: main.busType
45− busName: main.busName
46− objectPath: main.objectPath
47− }
48−
49− IndicatorsClient.FlatMenuProxyModel {
50− id: __proxyModel
51−
52− busType: main.busType
53− busName: main.busName
54− objectPath: main.objectPath + "/" + device
55− }
56−
5737 ListView {
5838 id: mainMenu
5939
6040 property int visibleItems: 0
6141
62− model: __proxyModel
42+ model: proxyModel
6343 anchors {
6444 fill: parent
6545 bottomMargin: Qt.inputMethod.visible ? (Qt.inputMethod.keyboardRectangle.height - main.anchors.bottomMargin) : 0
@@ -147,7 +127,7 @@ Item {
147127 FactoryMenu {
148128 id: factory
149129
150− actionGroup: __actionGroup
130+ actionGroup: main.actionGroup
151131 isCurrentItem: item.ListView.isCurrentItem
152132 anchors.left: parent.left
153133 anchors.right: parent.right
@@ -181,19 +161,19 @@ Item {
181161 function start()
182162 {
183163 reset()
184− if (!main.__active) {
185− __proxyModel.start()
186− __actionGroup.start()
187− main.__active = true
164+ if (!__active) {
165+ proxyModel.start()
166+ actionGroup.start()
167+ __active = true
188168 }
189169 }
190170
191171 function stop()
192172 {
193− if (main.__active) {
194− main.__active = false
195− __proxyModel.stop()
196− __actionGroup.stop()
173+ if (__active) {
174+ __active = false
175+ proxyModel.stop()
176+ actionGroup.stop()
197177 }
198178 }
199179
plugins/IndicatorsClient/qml/qmldir+3−1
@@ -1,7 +1,9 @@
11module IndicatorsClient
22plugin IndicatorsClientQml
33
4−PluginItem 0.1 PluginItem.qml
4+IndicatorItem 0.1 IndicatorItem.qml
5+IndicatorIcon 0.1 IndicatorIcon.qml
6+IndicatorPage 0.1 IndicatorPage.qml
57BasicMenu 0.1 BasicMenu.qml
68ButtonMenu 0.1 ButtonMenu.qml
79DBusActionState 0.1 DBusActionState.qml
plugins/IndicatorsClient/resources/indicatorclient.qrc+7−4
@@ -5,9 +5,12 @@
55 <file>artwork/messaging/default_app.svg</file>
66 <file>artwork/messaging/message_sms01_54px.png</file>
77
8− <file>qml/CommonIndicator.qml</file>
9− <file>qml/DatetimeIndicator.qml</file>
10− <file>qml/MessagingIndicator.qml</file>
11− <file>qml/NetworkIndicator.qml</file>
8+ <file>qml/DefaultIndicatorIcon.qml</file>
9+ <file>qml/DefaultIndicatorPage.qml</file>
10+ <file>qml/DatetimeIndicatorIcon.qml</file>
11+ <file>qml/DatetimeIndicatorPage.qml</file>
12+ <file>qml/MessagingIndicatorPage.qml</file>
13+ <file>qml/NetworkIndicatorIcon.qml</file>
14+ <file>qml/NetworkIndicatorPage.qml</file>
1215 </qresource>
1316</RCC>
plugins/IndicatorsClient/resources/qml/DatetimeIndicatorIcon.qmlnew file+67
@@ -0,0 +1,67 @@
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+import QtQuick 2.0
21+import Ubuntu.Components 0.1
22+import IndicatorsClient 0.1 as IndicatorsClient
23+
24+IndicatorsClient.IndicatorIcon {
25+ id: indicatorIcon
26+
27+ width: timeLabel.width + units.gu(1)
28+
29+ property alias label: timeLabel.text
30+ property date __date
31+
32+ Label {
33+ id: timeLabel
34+ objectName: "timeLabel"
35+ color: "#f3f3e7"
36+ opacity: 0.8
37+ font.family: "Ubuntu"
38+ fontSize: "medium"
39+ anchors {
40+ verticalCenter: parent.verticalCenter
41+ horizontalCenter: parent.horizontalCenter
42+ }
43+ text: Qt.formatTime(__date)
44+ }
45+
46+ Timer {
47+ id: timer
48+ interval: 1000 * 60
49+ running: indicatorIcon.visible
50+ repeat: true
51+ triggeredOnStart: true
52+ onTriggered: __date = new Date
53+ }
54+
55+ onActionStateChanged: {
56+ if (action == undefined || !action.valid) {
57+ return
58+ }
59+
60+ if (action.state == undefined) {
61+ visible = false;
62+ return
63+ }
64+
65+ indicatorIcon.visible = action.state[3]
66+ }
67+}
plugins/IndicatorsClient/resources/qml/DatetimeIndicator.qml → plugins/IndicatorsClient/resources/qml/DatetimeIndicatorPage.qmlrenamed

The content is the same.

plugins/IndicatorsClient/resources/qml/DefaultIndicatorIcon.qmlnew file+80
@@ -0,0 +1,80 @@
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+import QtQuick 2.0
21+import Ubuntu.Components 0.1
22+import IndicatorsClient 0.1 as IndicatorsClient
23+
24+IndicatorsClient.IndicatorIcon {
25+ id: indicatorIcon
26+
27+ width: itemRow.width + units.gu(1)
28+
29+ property alias label: itemLabel.text
30+ property alias iconSource: itemImage.source
31+
32+ Row {
33+ id: itemRow
34+ objectName: "itemRow"
35+ anchors {
36+ top: parent.top
37+ bottom: parent.bottom
38+ horizontalCenter: parent.horizontalCenter
39+ }
40+ spacing: units.gu(0.5)
41+
42+ Image {
43+ id: itemImage
44+ objectName: "itemImage"
45+ source: "image://gicon/audio-volume-high"
46+ visible: source != ""
47+ height: units.gu(2.5)
48+ width: units.gu(2.5)
49+ anchors.verticalCenter: parent.verticalCenter
50+ }
51+
52+ Label {
53+ id: itemLabel
54+ objectName: "itemLabel"
55+ color: "#f3f3e7"
56+ opacity: 0.8
57+ font.family: "Ubuntu"
58+ fontSize: "medium"
59+ anchors.verticalCenter: parent.verticalCenter
60+ visible: text != ""
61+ }
62+ }
63+
64+ onActionStateChanged: {
65+ if (action == undefined || !action.valid) {
66+ return
67+ }
68+
69+ if (action.state == undefined) {
70+ label = "";
71+ iconSource = "";
72+ visible = false;
73+ return
74+ }
75+
76+ label = action.state[0]
77+ iconSource = "image://gicon/" + action.state[1]
78+ indicatorIcon.visible = action.state[3]
79+ }
80+}
plugins/IndicatorsClient/resources/qml/CommonIndicator.qml → plugins/IndicatorsClient/resources/qml/DefaultIndicatorPage.qmlrenamed+2−1
@@ -17,8 +17,9 @@
1717 * Renato Araujo Oliveira Filho <renato@canonical.com>
1818 */
1919
20+import QtQuick 2.0
2021import IndicatorsClient 0.1 as IndicatorsClient
2122
22−IndicatorsClient.PluginItem {
23+IndicatorsClient.IndicatorPage {
2324 anchors.fill: parent
2425}
plugins/IndicatorsClient/resources/qml/MessagingIndicator.qml → plugins/IndicatorsClient/resources/qml/MessagingIndicatorPage.qmlrenamed+2−2
@@ -17,11 +17,11 @@
1717 * Renato Araujo Oliveira Filho <renato.filho@canonical.com>
1818 */
1919
20−import IndicatorsClient 0.1 as IndicatorsClient
2120import QtQuick 2.0
2221import Ubuntu.Components 0.1
22+import IndicatorsClient 0.1 as IndicatorsClient
2323
24−IndicatorsClient.PluginItem {
24+IndicatorsClient.IndicatorPage {
2525 anchors.fill: parent
2626
2727 function stop() {
plugins/IndicatorsClient/resources/qml/NetworkIndicatorIcon.qmlnew file+116
@@ -0,0 +1,116 @@
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+import QtQuick 2.0
21+import Ubuntu.Components 0.1
22+import IndicatorsClient 0.1 as IndicatorsClient
23+
24+IndicatorsClient.IndicatorIcon {
25+ id: indicatorIcon
26+
27+ width: networkIcon.width + units.gu(1)
28+
29+ property int signalStrength: 0
30+ property int connectionState: 0
31+
32+ Image {
33+ id: networkIcon
34+ objectName: "itemImage"
35+ source: get_icon_for_signal(connectionState, signalStrength)
36+ visible: source != ""
37+ height: units.gu(2.5)
38+ width: units.gu(2.5)
39+ anchors {
40+ verticalCenter: parent.verticalCenter
41+ horizontalCenter: parent.horizontalCenter
42+ }
43+ }
44+
45+ function parseRootElement(type, data) {
46+ if (type == "com.canonical.indicator.root.network")
47+ return true
48+ return false
49+ }
50+
51+ onActionStateChanged: {
52+ if (action == undefined || !action.valid) {
53+ return
54+ }
55+
56+ if (action.state == undefined) {
57+ connectionState = 0
58+ return
59+ }
60+
61+ connectionState = action.state[1]
62+ if (connectionState == 2) {
63+ signalStrength = action.state[2]
64+ }
65+ }
66+
67+ NumberAnimation {
68+ id: activation_animation
69+ target: indicatorIcon
70+ property: "signalStrength"
71+ from: 0
72+ to: 100
73+ duration: 2500 // 5 states in 2.5 seconds
74+ loops: Animation.Infinite
75+ }
76+
77+ states: [
78+ State {
79+ name: "unknown"
80+ when: connectionState > 3 || connectionState < 1
81+ PropertyChanges { target: activation_animation; running: false }
82+ },
83+ State {
84+ name: "activating"
85+ when: connectionState == 1
86+ PropertyChanges { target: activation_animation; running: true }
87+ },
88+ State {
89+ name: "activated"
90+ when: connectionState == 2
91+ PropertyChanges { target: activation_animation; running: false }
92+ },
93+ State {
94+ name: "deactivating"
95+ when: connectionState == 3
96+ PropertyChanges { target: activation_animation; running: true }
97+ }
98+ ]
99+
100+
101+ function get_icon_for_signal(con_state, value) {
102+ if (con_state >= 1 && con_state <= 3) {
103+ if (value == 0) {
104+ return "image://gicon/nm-signal-00"
105+ } else if (value <= 25) {
106+ return "image://gicon/nm-signal-25"
107+ } else if (value <= 50) {
108+ return "image://gicon/nm-signal-50"
109+ } else if (value <= 75) {
110+ return "image://gicon/nm-signal-75"
111+ }
112+ return "image://gicon/nm-signal-100"
113+ }
114+ return "image://gicon/wifi-none"
115+ }
116+}
plugins/IndicatorsClient/resources/qml/NetworkIndicator.qml → plugins/IndicatorsClient/resources/qml/NetworkIndicatorPage.qmlrenamed+2−1
@@ -17,6 +17,7 @@
1717 * Renato Araujo Oliveira Filho <renato@canonical.com>
1818 */
1919
20+import QtQuick 2.0
2021import IndicatorsClient 0.1 as IndicatorsClient
2122import Ubuntu.Components 0.1
2223import NetworkSettings 0.1
@@ -36,7 +37,7 @@ PageStack {
3637 Page {
3738 id: _mainPage
3839
39− IndicatorsClient.PluginItem {
40+ IndicatorsClient.IndicatorPage {
4041 id: _pluginItem
4142 anchors.fill: parent
4243 }
tests/plugins/IndicatorsClient/fakeindicator.h+1−2
@@ -46,7 +46,7 @@ public:
4646};
4747
4848
49−#define FAKE_INDICATOR(number, title, icon) \
49+#define FAKE_INDICATOR(number, title) \
5050 class FakeIndicatorClient##number : public FakeIndicatorClient \
5151 { \
5252 public: \
@@ -55,7 +55,6 @@ public:
5555 { \
5656 setTitle(title); \
5757 setPriority(number); \
58− setIcon(QUrl(icon)); \
5958 } \
6059 };
6160
tests/plugins/IndicatorsClient/indicatorsmanagertest.cpp+2−3
@@ -25,8 +25,8 @@
2525#include <QtTest>
2626#include <QDebug>
2727
28−FAKE_INDICATOR(1, "Fake Title 1", "fake-indicator-1")
29−FAKE_INDICATOR(2, "Fake Title 2", "fake-indicator-2")
28+FAKE_INDICATOR(1, "Fake Title 1")
29+FAKE_INDICATOR(2, "Fake Title 2")
3030
3131class IndicatorsManagerTest : public QObject
3232{
@@ -74,7 +74,6 @@ private Q_SLOTS:
7474 QVERIFY(indicator.get());
7575
7676 QCOMPARE(indicator->identifier(), QString("indicator-fake1"));
77− QCOMPARE(indicator->icon(), QUrl("image://gicon/fake-indicator-1"));
7877 QCOMPARE(indicator->title(), QString("Fake Title 1"));
7978 QCOMPARE(indicator->label(), QString());
8079 QCOMPARE(indicator->description(), QString());
tests/plugins/IndicatorsClient/indicatorsmodeltest.cpp+2−4
@@ -25,8 +25,8 @@
2525#include <QtTest>
2626#include <QDebug>
2727
28−FAKE_INDICATOR(1, "Fake Title 1", "fake-indicator-1")
29−FAKE_INDICATOR(2, "Fake Title 2", "fake-indicator-2")
28+FAKE_INDICATOR(1, "Fake Title 1")
29+FAKE_INDICATOR(2, "Fake Title 2")
3030
3131class IndicatorsModelTest : public QObject
3232{
@@ -70,7 +70,6 @@ private Q_SLOTS:
7070 QVariantMap data = model.get(0);
7171 QCOMPARE(data["title"].toString(), QString("Fake Title 1"));
7272 QCOMPARE(data["label"].toString(), QString());
73− QCOMPARE(data["iconSource"].value<QUrl>(), QUrl("image://gicon/fake-indicator-1"));
7473 QCOMPARE(data["description"].toString(), QString());
7574 // There is no QML context
7675 QVERIFY(!data["component"].value<QObject*>());
@@ -79,7 +78,6 @@ private Q_SLOTS:
7978 data = model.get(1);
8079 QCOMPARE(data["title"].toString(), QString("Fake Title 2"));
8180 QCOMPARE(data["label"].toString(), QString());
82− QCOMPARE(data["iconSource"].value<QUrl>(), QUrl("image://gicon/fake-indicator-2"));
8381 QCOMPARE(data["description"].toString(), QString());
8482 // There is no QML context
8583 QVERIFY(!data["component"].value<QObject*>());