on xenial help sign in
Indicator Icon Widgets
e2b019bNick Dedekind
Panel/IndicatorItem.qml+28−35
@@ -16,18 +16,42 @@
16
16
17import QtQuick 2.0
17import QtQuick 2.0
18import Ubuntu.Components 0.1
18import Ubuntu.Components 0.1
19+import IndicatorsClient 0.1 as IndicatorsClient
19
20
20Item {
21Item {
21 id: indicatorItem
22 id: indicatorItem
22
23
23− property alias iconSource: itemImage.source
24+ property alias iconUrl: loader.source
24− property alias label: itemLabel.text
25 property bool highlighted: false
25 property bool highlighted: false
26 property bool dimmed: false
26 property bool dimmed: false
27+ property var initialProperties: undefined
28+
29+ opacity: dimmed ? 0.4 : 1
27
30
28 // only visible when non-empty
31 // only visible when non-empty
29− visible: label != "" || iconSource != ""
32+ visible: loader.item != undefined && loader.status == Loader.Ready
30− width: itemRow.width + units.gu(1)
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+ }
31
55
32 Rectangle {
56 Rectangle {
33 color: "#dd4814"
57 color: "#dd4814"
@@ -36,35 +60,4 @@ Item {
36 anchors.top: parent.bottom
60 anchors.top: parent.bottom
37 visible: highlighted
61 visible: highlighted
38 }
62 }
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− }
70}
63}
Panel/IndicatorRow.qml+2−2
@@ -59,8 +59,8 @@ Item {
59
59
60 property int ownIndex: index
60 property int ownIndex: index
61
61
62− label: model.label
62+ iconUrl: model.iconUrl
63− iconSource: model.iconSource
63+ initialProperties : model.initialProperties
64 highlighted: indicatorRow.state == "reveal" || indicatorRow.state == "locked" || indicatorRow.state == "commit" ? ownIndex == indicatorRow.currentItemIndex : false
64 highlighted: indicatorRow.state == "reveal" || indicatorRow.state == "locked" || indicatorRow.state == "commit" ? ownIndex == indicatorRow.currentItemIndex : false
65 dimmed: { //See FIXME in Indicators regarding the "states" change
65 dimmed: { //See FIXME in Indicators regarding the "states" change
66 if (indicatorRow.state == "initial" || indicatorRow.state == "") {
66 if (indicatorRow.state == "initial" || indicatorRow.state == "") {
Panel/MenuContent.qml+1−1
@@ -94,7 +94,7 @@ Rectangle {
94
94
95 width: menus.width
95 width: menus.width
96 height: menus.height
96 height: menus.height
97− source: component
97+ source: pageUrl
98 visible: content.__shown
98 visible: content.__shown
99 onVisibleChanged: {
99 onVisibleChanged: {
100 // Reset the indicator states
100 // Reset the indicator states
plugins/IndicatorsClient/flatmenuproxymodel.cpp+15
@@ -323,3 +323,18 @@ int FlatMenuProxyModel::rowOffsetOf(const QModelIndex &index, int row, bool incl
323
323
324 return offset;
324 return offset;
325}
325}
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:
60
60
61 int status() const;
61 int status() const;
62
62
63+ /* QML */
64+ Q_INVOKABLE QVariantMap get(int row) const;
65+
63public Q_SLOTS:
66public Q_SLOTS:
64 void onRowsInserted(const QModelIndex &parent, int start, int end);
67 void onRowsInserted(const QModelIndex &parent, int start, int end);
65 void onRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
68 void onRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
plugins/IndicatorsClient/indicatorclientinterface.h+8−13
@@ -63,14 +63,6 @@ public:
63 */
63 */
64 virtual QString identifier() const = 0;
64 virtual QString identifier() const = 0;
65
65
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−
74 /**
66 /**
75 * @brief Used to retrieve the current plugin title
67 * @brief Used to retrieve the current plugin title
76 * @return The title
68 * @return The title
@@ -109,14 +101,17 @@ public:
109 */
101 */
110 virtual int priority() const = 0;
102 virtual int priority() const = 0;
111
103
104+ /**
105+ * @brief Used to retrieve the icon component source file
106+ * @return The icon component url
107+ */
108+ virtual QUrl iconComponentSource() const = 0;
112
109
113 /**
110 /**
114− * @brief Used to retrieve the plugin initial component
111+ * @brief Used to retrieve the plugin page component source file
115− * @param engine The current \l QDeclarativeEngine used to parse the componente code
112+ * @return A url pointing to the component source file
116− * @param parent The parent of the returned object
117− * @return A new \l QDeclarativeComponent with the initial plugin view
118 */
113 */
119− virtual QUrl componentSource() const = 0;
114+ virtual QUrl pageComponentSource() const = 0;
120
115
121 /**
116 /**
122 * @brief Used during the plugin Component instanciation to set the initial properties
117 * @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 @@
38
38
39IndicatorClientCommon::IndicatorClientCommon(QObject *parent)
39IndicatorClientCommon::IndicatorClientCommon(QObject *parent)
40 : QObject(parent),
40 : QObject(parent),
41− m_icon(""),
42 m_visible(false),
41 m_visible(false),
43− m_priority(0),
42+ m_priority(0)
44− m_model(0),
45− m_actionGroup(0),
46− m_action(0),
47− m_component(0)
48{
43{
49}
44}
50
45
@@ -59,107 +54,15 @@ void IndicatorClientCommon::init(const QSettings& settings)
59 QString dbusService = settings.value("Indicator Service/DBusName").toString();
54 QString dbusService = settings.value("Indicator Service/DBusName").toString();
60 QString objectPath = settings.value("Indicator Service/ObjectPath").toString();
55 QString objectPath = settings.value("Indicator Service/ObjectPath").toString();
61
56
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−
78 m_initialProperties.clear();
57 m_initialProperties.clear();
79 m_initialProperties.insert("title", m_title);
58 m_initialProperties.insert("title", m_title);
80 m_initialProperties.insert("busType", 1);
59 m_initialProperties.insert("busType", 1);
81 m_initialProperties.insert("busName", dbusService);
60 m_initialProperties.insert("busName", dbusService);
82 m_initialProperties.insert("objectPath", objectPath);
61 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);
148}
62}
149
63
150void IndicatorClientCommon::shutdown()
64void IndicatorClientCommon::shutdown()
151{
65{
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;
163}
66}
164
67
165QString IndicatorClientCommon::identifier() const
68QString IndicatorClientCommon::identifier() const
@@ -175,23 +78,6 @@ void IndicatorClientCommon::setId(const QString &identifier)
175 }
78 }
176}
79}
177
80
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−
195QString IndicatorClientCommon::title() const
81QString IndicatorClientCommon::title() const
196{
82{
197 return m_title;
83 return m_title;
@@ -257,14 +143,14 @@ void IndicatorClientCommon::setLabel(const QString &label)
257 }
143 }
258}
144}
259
145
260−QDBusActionGroup *IndicatorClientCommon::actionGroup() const
146+QUrl IndicatorClientCommon::iconComponentSource() const
261{
147{
262− return m_actionGroup;
148+ return QUrl("qrc:/indicatorsclient/qml/DefaultIndicatorIcon.qml");
263}
149}
264
150
265−QUrl IndicatorClientCommon::componentSource() const
151+QUrl IndicatorClientCommon::pageComponentSource() const
266{
152{
267− return QUrl("qrc:/indicatorsclient/qml/CommonIndicator.qml");
153+ return QUrl("qrc:/indicatorsclient/qml/DefaultIndicatorPage.qml");
268}
154}
269
155
270IndicatorClientInterface::PropertiesMap IndicatorClientCommon::initialProperties()
156IndicatorClientInterface::PropertiesMap IndicatorClientCommon::initialProperties()
plugins/IndicatorsClient/indicators/common/indicatorclient_common.h+2−16
@@ -35,7 +35,6 @@ class IndicatorClientCommon : public QObject, public IndicatorClientInterface
35 Q_PROPERTY(QString title READ title NOTIFY titleChanged)
35 Q_PROPERTY(QString title READ title NOTIFY titleChanged)
36 Q_PROPERTY(QString label READ label NOTIFY labelChanged)
36 Q_PROPERTY(QString label READ label NOTIFY labelChanged)
37 Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
37 Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
38− Q_PROPERTY(QUrl icon READ icon NOTIFY iconChanged)
39 Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
38 Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
40 Q_PROPERTY(int priority READ priority NOTIFY priorityChanged)
39 Q_PROPERTY(int priority READ priority NOTIFY priorityChanged)
41
40
@@ -47,19 +46,18 @@ public:
47 void shutdown();
46 void shutdown();
48
47
49 QString identifier() const;
48 QString identifier() const;
50− QUrl icon() const;
51 QString title() const;
49 QString title() const;
52 bool visible() const;
50 bool visible() const;
53 QString description() const;
51 QString description() const;
54 QString label() const;
52 QString label() const;
55 int priority() const;
53 int priority() const;
56
54
57− QUrl componentSource() const;
55+ QUrl iconComponentSource() const;
56+ QUrl pageComponentSource() const;
58 PropertiesMap initialProperties();
57 PropertiesMap initialProperties();
59
58
60Q_SIGNALS:
59Q_SIGNALS:
61 void identifierChanged(const QString &identifier);
60 void identifierChanged(const QString &identifier);
62− void iconChanged(const QUrl &icon);
63 void titleChanged(const QString &title);
61 void titleChanged(const QString &title);
64 void visibleChanged(bool visible);
62 void visibleChanged(bool visible);
65 void descriptionChanged(const QString &description);
63 void descriptionChanged(const QString &description);
@@ -70,31 +68,19 @@ protected:
70 PropertiesMap m_initialProperties;
68 PropertiesMap m_initialProperties;
71
69
72 void setId(const QString &id);
70 void setId(const QString &id);
73− void setIcon(const QUrl &icon);
74 void setTitle(const QString &title);
71 void setTitle(const QString &title);
75 void setDescription(const QString &description);
72 void setDescription(const QString &description);
76 void setVisible(bool visible);
73 void setVisible(bool visible);
77 void setLabel(const QString &title);
74 void setLabel(const QString &title);
78 void setPriority(int priority);
75 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);
85
76
86private:
77private:
87 QString m_identifier;
78 QString m_identifier;
88− QUrl m_icon;
89 QString m_title;
79 QString m_title;
90 QString m_description;
80 QString m_description;
91 QString m_label;
81 QString m_label;
92 bool m_visible;
82 bool m_visible;
93 int m_priority;
83 int m_priority;
94− QDBusMenuModel *m_model;
95− QDBusActionGroup *m_actionGroup;
96− QStateAction *m_action;
97− QQmlComponent *m_component;
98};
84};
99
85
100#endif // INDICATORCLIENT_COMMON_H
86#endif // INDICATORCLIENT_COMMON_H
plugins/IndicatorsClient/indicators/datetime/indicatorclient_datetime.cpp+4−67
@@ -32,90 +32,27 @@ IndicatorClientDateTime::IndicatorClientDateTime(QObject *parent)
32{
32{
33 setTitle("Date and Time");
33 setTitle("Date and Time");
34 setPriority(IndicatorPriority::DATETIME);
34 setPriority(IndicatorPriority::DATETIME);
35−
36− connect(&m_timer, SIGNAL(timeout()), SLOT(onTimeout()));
37}
35}
38
36
39IndicatorClientDateTime::~IndicatorClientDateTime()
37IndicatorClientDateTime::~IndicatorClientDateTime()
40{
38{
41− if (m_action) {
42− delete m_action;
43− }
44}
39}
45
40
46void IndicatorClientDateTime::init(const QSettings& settings)
41void IndicatorClientDateTime::init(const QSettings& settings)
47{
42{
48 IndicatorClientCommon::init(settings);
43 IndicatorClientCommon::init(settings);
49−
50− m_timer.start(1000 * 10);
51}
44}
52
45
53void IndicatorClientDateTime::shutdown()
46void IndicatorClientDateTime::shutdown()
54{
47{
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− }
110}
48}
111
49
112−QUrl IndicatorClientDateTime::componentSource() const
50+QUrl IndicatorClientDateTime::iconComponentSource() const
113{
51{
114− return QUrl("qrc:/indicatorsclient/qml/DatetimeIndicator.qml");
52+ return QUrl("qrc:/indicatorsclient/qml/DatetimeIndicatorIcon.qml");
115}
53}
116
54
117−void IndicatorClientDateTime::onTimeout()
55+QUrl IndicatorClientDateTime::pageComponentSource() const
118{
56{
119− QString newValue = dateTime();
57+ return QUrl("qrc:/indicatorsclient/qml/DatetimeIndicatorPage.qml");
120− setLabel(newValue);
121}
58}
plugins/IndicatorsClient/indicators/datetime/indicatorclient_datetime.h+2−6
@@ -36,13 +36,9 @@ public:
36
36
37 void init(const QSettings& settings);
37 void init(const QSettings& settings);
38 void shutdown();
38 void shutdown();
39− QString dateTime() const;
40− bool parseRootElement(const QString &type, QMap<int, QVariant> data);
41− QUrl componentSource() const;
42
39
43−private Q_SLOTS:
40+ QUrl iconComponentSource() const;
44− void onTimeout();
41+ QUrl pageComponentSource() const;
45− void updateTimeFormat(const QVariant &state);
46
42
47private:
43private:
48 QTimer m_timer;
44 QTimer m_timer;
plugins/IndicatorsClient/indicators/messaging/indicatorclient_messaging.cpp+7−2
@@ -42,7 +42,12 @@ void IndicatorClientMessaging::init(const QSettings& settings)
42 m_initialProperties.insert("highlightFollowsCurrentItem", false);
42 m_initialProperties.insert("highlightFollowsCurrentItem", false);
43}
43}
44
44
45−QUrl IndicatorClientMessaging::componentSource() const
45+QUrl IndicatorClientMessaging::iconComponentSource() const
46{
46{
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");
48}
53}
plugins/IndicatorsClient/indicators/messaging/indicatorclient_messaging.h+3−1
@@ -31,7 +31,9 @@ public:
31 ~IndicatorClientMessaging();
31 ~IndicatorClientMessaging();
32
32
33 void init(const QSettings& settings);
33 void init(const QSettings& settings);
34− QUrl componentSource() const;
34+
35+ QUrl iconComponentSource() const;
36+ QUrl pageComponentSource() const;
35};
37};
36
38
37#endif
39#endif
plugins/IndicatorsClient/indicators/network/indicatorclient_network.cpp+6−110
@@ -29,14 +29,10 @@
29#include <qstateaction.h>
29#include <qstateaction.h>
30
30
31IndicatorClientNetwork::IndicatorClientNetwork(QObject *parent)
31IndicatorClientNetwork::IndicatorClientNetwork(QObject *parent)
32− : IndicatorClientCommon(parent),
32+ : IndicatorClientCommon(parent)
33− m_action(0)
34{
33{
35 setTitle("Networks");
34 setTitle("Networks");
36 setPriority(IndicatorPriority::NETWORK);
35 setPriority(IndicatorPriority::NETWORK);
37−
38− m_timedAnimation.setInterval(500);
39− connect(&m_timedAnimation, SIGNAL(timeout()), SLOT(animationNextFrame()));
40}
36}
41
37
42IndicatorClientNetwork::~IndicatorClientNetwork()
38IndicatorClientNetwork::~IndicatorClientNetwork()
@@ -48,115 +44,15 @@ void IndicatorClientNetwork::init(const QSettings& settings)
48 IndicatorClientCommon::init(settings);
44 IndicatorClientCommon::init(settings);
49
45
50 qmlRegisterType<NetworkAgent>("NetworkSettings", 0, 1, "NetworkAgent");
46 qmlRegisterType<NetworkAgent>("NetworkSettings", 0, 1, "NetworkAgent");
51− setIcon(QUrl("image://gicon/wifi-none"));
47+ // setIcon(QUrl("image://gicon/wifi-none"));
52}
48}
53
49
54−QUrl IndicatorClientNetwork::componentSource() const
50+QUrl IndicatorClientNetwork::iconComponentSource() const
55{
51{
56− return QUrl("qrc:/indicatorsclient/qml/NetworkIndicator.qml");
52+ return QUrl("qrc:/indicatorsclient/qml/NetworkIndicatorIcon.qml");
57}
53}
58
54
59−bool IndicatorClientNetwork::parseRootElement(const QString &type, QMap<int, QVariant> data)
55+QUrl IndicatorClientNetwork::pageComponentSource() const
60{
56{
61− if (type == "com.canonical.indicator.root.network") {
57+ return QUrl("qrc:/indicatorsclient/qml/NetworkIndicatorPage.qml");
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− }
162}
58}
plugins/IndicatorsClient/indicators/network/indicatorclient_network.h+2−12
@@ -33,18 +33,8 @@ public:
33 ~IndicatorClientNetwork();
33 ~IndicatorClientNetwork();
34
34
35 void init(const QSettings& settings);
35 void init(const QSettings& settings);
36− QUrl componentSource() const;
36+ QUrl iconComponentSource() const;
37− bool parseRootElement(const QString &type, QMap<int, QVariant> data);
37+ QUrl pageComponentSource() const;
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;
48};
38};
49
39
50#endif
40#endif
plugins/IndicatorsClient/indicators/power/indicatorclient_power.cpp+6−1
@@ -30,4 +30,9 @@ IndicatorClientPower::IndicatorClientPower(QObject *parent)
30void IndicatorClientPower::init(const QSettings& settings)
30void IndicatorClientPower::init(const QSettings& settings)
31{
31{
32 IndicatorClientCommon::init(settings);
32 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:
30 IndicatorClientPower(QObject *parent=0);
30 IndicatorClientPower(QObject *parent=0);
31
31
32 void init(const QSettings& settings);
32 void init(const QSettings& settings);
33+
34+ QUrl iconComponentSource() const;
33};
35};
34
36
35#endif
37#endif
plugins/IndicatorsClient/indicators/sound/indicatorclient_sound.cpp+6−1
@@ -24,7 +24,7 @@ IndicatorClientSound::IndicatorClientSound(QObject *parent)
24{
24{
25 setTitle("Sound");
25 setTitle("Sound");
26 setPriority(IndicatorPriority::SOUND);
26 setPriority(IndicatorPriority::SOUND);
27− setIcon(QUrl("audio-volume-high"));
27+ // setIcon(QUrl("audio-volume-high"));
28}
28}
29
29
30
30
@@ -32,3 +32,8 @@ void IndicatorClientSound::init(const QSettings& settings)
32{
32{
33 IndicatorClientCommon::init(settings);
33 IndicatorClientCommon::init(settings);
34}
34}
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:
29 IndicatorClientSound(QObject *parent=0);
29 IndicatorClientSound(QObject *parent=0);
30
30
31 void init(const QSettings& settings);
31 void init(const QSettings& settings);
32+
33+ QUrl iconComponentSource() const;
32};
34};
33
35
34#endif
36#endif
plugins/IndicatorsClient/indicatorsmodel.cpp+11−18
@@ -141,7 +141,6 @@ void IndicatorsModel::onIndicatorLoaded(const QString& indicator)
141 if (obj)
141 if (obj)
142 {
142 {
143 QObject::connect(obj, SIGNAL(identifierChanged(const QString&)), this, SLOT(onIdentifierChanged()));
143 QObject::connect(obj, SIGNAL(identifierChanged(const QString&)), this, SLOT(onIdentifierChanged()));
144− QObject::connect(obj, SIGNAL(iconChanged(const QUrl&)), this, SLOT(onIconChanged()));
145 QObject::connect(obj, SIGNAL(titleChanged(const QString&)), this, SLOT(onTitleChanged()));
144 QObject::connect(obj, SIGNAL(titleChanged(const QString&)), this, SLOT(onTitleChanged()));
146 QObject::connect(obj, SIGNAL(labelChanged(const QString&)), this, SLOT(onLabelChanged()));
145 QObject::connect(obj, SIGNAL(labelChanged(const QString&)), this, SLOT(onLabelChanged()));
147 }
146 }
@@ -179,12 +178,6 @@ void IndicatorsModel::onIdentifierChanged()
179 notifyDataChanged(QObject::sender(), Identifier);
178 notifyDataChanged(QObject::sender(), Identifier);
180}
179}
181
180
182−/*! \internal */
183−void IndicatorsModel::onIconChanged()
184−{
185− notifyDataChanged(QObject::sender(), IconSource);
186−}
187−
188/*! \internal */
181/*! \internal */
189void IndicatorsModel::onTitleChanged()
182void IndicatorsModel::onTitleChanged()
190{
183{
@@ -225,10 +218,10 @@ QHash<int, QByteArray> IndicatorsModel::roleNames() const
225 if (roles.isEmpty()) {
218 if (roles.isEmpty()) {
226 roles[Identifier] = "identifier";
219 roles[Identifier] = "identifier";
227 roles[Title] = "title";
220 roles[Title] = "title";
228− roles[IconSource] = "iconSource";
229 roles[Label] = "label";
221 roles[Label] = "label";
230 roles[Description] = "description";
222 roles[Description] = "description";
231− roles[QMLComponent] = "component";
223+ roles[IconUrl] = "iconUrl";
224+ roles[PageUrl] = "pageUrl";
232 roles[InitialProperties] = "initialProperties";
225 roles[InitialProperties] = "initialProperties";
233 roles[IsValid] = "isValid";
226 roles[IsValid] = "isValid";
234 }
227 }
@@ -262,13 +255,6 @@ QVariant IndicatorsModel::data(const QModelIndex &index, int role) const
262 attribute = QVariant(plugin->title());
255 attribute = QVariant(plugin->title());
263 }
256 }
264 break;
257 break;
265− case IconSource:
266− if (plugin) {
267− return plugin->icon().toString();
268− } else {
269− attribute = QVariant("No plugin");
270− }
271− break;
272 case Label:
258 case Label:
273 if (plugin) {
259 if (plugin) {
274 attribute = QVariant(plugin->label());
260 attribute = QVariant(plugin->label());
@@ -281,9 +267,16 @@ QVariant IndicatorsModel::data(const QModelIndex &index, int role) const
281 }
267 }
282 break;
268 break;
283 }
269 }
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:
285 if (plugin) {
278 if (plugin) {
286− return plugin->componentSource();
279+ return plugin->pageComponentSource();
287 }
280 }
288 break;
281 break;
289 case InitialProperties:
282 case InitialProperties:
plugins/IndicatorsClient/indicatorsmodel.h+2−3
@@ -37,10 +37,10 @@ public:
37 enum ModelRoles {
37 enum ModelRoles {
38 Identifier = 0,
38 Identifier = 0,
39 Title,
39 Title,
40− IconSource,
41 Label,
40 Label,
42 Description,
41 Description,
43− QMLComponent,
42+ IconUrl,
43+ PageUrl,
44 InitialProperties,
44 InitialProperties,
45 IsValid
45 IsValid
46 };
46 };
@@ -65,7 +65,6 @@ Q_SIGNALS:
65
65
66private Q_SLOTS:
66private Q_SLOTS:
67 void onIdentifierChanged();
67 void onIdentifierChanged();
68− void onIconChanged();
69 void onTitleChanged();
68 void onTitleChanged();
70 void onLabelChanged();
69 void onLabelChanged();
71 void onIndicatorLoaded(const QString& indicator);
70 void onIndicatorLoaded(const QString& indicator);
plugins/IndicatorsClient/qml/DBusActionState.qml+2−2
@@ -79,12 +79,12 @@ Item {
79 Item {
79 Item {
80 id: priv
80 id: priv
81 property variant actionObject : action && actionGroup ? actionGroup.action(action) : null
81 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
83
83
84 Binding {
84 Binding {
85 id: propertyBinding
85 id: propertyBinding
86 value: priv.actionState
86 value: priv.actionState
87− when: (actionGroup && active && priv.actionObject && priv.actionObject.valid)
87+ when: (actionGroup && active && priv.actionObject)
88 }
88 }
89 }
89 }
90
90
plugins/IndicatorsClient/qml/FactoryMenu.qml+25−25
@@ -39,7 +39,7 @@ Item {
39 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
39 "unity.widgets.systemsettings.tablet.volumecontrol" : sliderMenu,
40 "unity.widgets.systemsettings.tablet.switch" : switchMenu,
40 "unity.widgets.systemsettings.tablet.switch" : switchMenu,
41
41
42− "com.canonical.indicator.button" : buttomMenu,
42+ "com.canonical.indicator.button" : buttonMenu,
43 "com.canonical.indicator.div" : divMenu,
43 "com.canonical.indicator.div" : divMenu,
44 "com.canonical.indicator.section" : sectionMenu,
44 "com.canonical.indicator.section" : sectionMenu,
45 "com.canonical.indicator.progress" : progressMenu,
45 "com.canonical.indicator.progress" : progressMenu,
@@ -57,7 +57,7 @@ Item {
57
57
58 Component { id: sliderMenu; IC.SliderMenu {} }
58 Component { id: sliderMenu; IC.SliderMenu {} }
59 Component { id: switchMenu; IC.SwitchMenu {} }
59 Component { id: switchMenu; IC.SwitchMenu {} }
60− Component { id: buttomMenu; IC.ButtonMenu {} }
60+ Component { id: buttonMenu; IC.ButtonMenu {} }
61 Component { id: divMenu; IC.DivMenu {} }
61 Component { id: divMenu; IC.DivMenu {} }
62 Component { id: sectionMenu; IC.SectionMenu {} }
62 Component { id: sectionMenu; IC.SectionMenu {} }
63 Component { id: progressMenu; IC.ProgressMenu {} }
63 Component { id: progressMenu; IC.ProgressMenu {} }
@@ -69,38 +69,38 @@ Item {
69 Component { id: indicatorMenu; IC.Menu {} }
69 Component { id: indicatorMenu; IC.Menu {} }
70
70
71 Loader {
71 Loader {
72− id: __loader
72+ id: __loader
73− anchors.fill: parent
73+ anchors.fill: parent
74− asynchronous: true
74+ asynchronous: true
75− sourceComponent: {
75+ sourceComponent: {
76− if (!__menuFactory.menu || !__menuFactory.menu.extra) {
76+ if (!__menuFactory.menu || !__menuFactory.menu.extra) {
77− return undefined
77+ return undefined
78− }
78+ }
79
79
80− var widgetType = __menuFactory.menu.extra.canonical_type
80+ var widgetType = __menuFactory.menu.extra.canonical_type
81− var sourceFile = null
82− if (widgetType) {
81+ if (widgetType) {
83− var component = _map[widgetType]
82+ return _map[widgetType]
84− if (component != undefined) {
83+ }
85− return component
84+ else {
86− }
87− }
88 if (widgetType === "com.canonical.indicator.root") {
85 if (widgetType === "com.canonical.indicator.root") {
89 return undefined
86 return undefined
90 // Try discovery the item based on the basic properties
87 // Try discovery the item based on the basic properties
91 } else if (menu.hasSection) {
88 } else if (menu.hasSection) {
92 return sectionMenu
89 return sectionMenu
93 }
90 }
91+ else {
94− return indicatorMenu
92+ return indicatorMenu
93+ }
95 }
94 }
95+ return undefined
96+ }
96
97
97− onStatusChanged: {
98+ onStatusChanged: {
98− if (status == Loader.Ready) {
99+ if (status == Loader.Ready) {
99− item.listViewIsCurrentItem = Qt.binding(function() { return isCurrentItem; });
100+ item.listViewIsCurrentItem = Qt.binding(function() { return isCurrentItem; });
100− item.actionGroup = Qt.binding(function() { return __menuFactory.actionGroup; });
101+ item.actionGroup = Qt.binding(function() { return __menuFactory.actionGroup; });
101− item.menu = Qt.binding(function() { return __menuFactory.menu; });
102+ item.menu = Qt.binding(function() { return __menuFactory.menu; });
102− }
103 }
103 }
104+ }
104 }
105 }
105−
106}
106}
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
23import Ubuntu.Components.ListItems 0.1 as ListItem
23import Ubuntu.Components.ListItems 0.1 as ListItem
24import IndicatorsClient 0.1 as IndicatorsClient
24import IndicatorsClient 0.1 as IndicatorsClient
25
25
26−Item {
26+IndicatorBase {
27 id: main
27 id: main
28
28
29 //const
29 //const
30− property string device: "phone"
31− property string title
32 property alias emptyText: emptyLabel.text
30 property alias emptyText: emptyLabel.text
33− property int busType
34− property string busName
35− property string objectPath
36 property alias highlightFollowsCurrentItem : mainMenu.highlightFollowsCurrentItem
31 property alias highlightFollowsCurrentItem : mainMenu.highlightFollowsCurrentItem
37 readonly property real overshootHeight: (mainMenu.contentY < 0) ? -mainMenu.contentY : 0
32 readonly property real overshootHeight: (mainMenu.contentY < 0) ? -mainMenu.contentY : 0
38 property bool __active: false
33 property bool __active: false
39
34
40 anchors.fill: parent
35 anchors.fill: parent
41
36
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−
57 ListView {
37 ListView {
58 id: mainMenu
38 id: mainMenu
59
39
60 property int visibleItems: 0
40 property int visibleItems: 0
61
41
62− model: __proxyModel
42+ model: proxyModel
63 anchors {
43 anchors {
64 fill: parent
44 fill: parent
65 bottomMargin: Qt.inputMethod.visible ? (Qt.inputMethod.keyboardRectangle.height - main.anchors.bottomMargin) : 0
45 bottomMargin: Qt.inputMethod.visible ? (Qt.inputMethod.keyboardRectangle.height - main.anchors.bottomMargin) : 0
@@ -147,7 +127,7 @@ Item {
147 FactoryMenu {
127 FactoryMenu {
148 id: factory
128 id: factory
149
129
150− actionGroup: __actionGroup
130+ actionGroup: main.actionGroup
151 isCurrentItem: item.ListView.isCurrentItem
131 isCurrentItem: item.ListView.isCurrentItem
152 anchors.left: parent.left
132 anchors.left: parent.left
153 anchors.right: parent.right
133 anchors.right: parent.right
@@ -181,19 +161,19 @@ Item {
181 function start()
161 function start()
182 {
162 {
183 reset()
163 reset()
184− if (!main.__active) {
164+ if (!__active) {
185− __proxyModel.start()
165+ proxyModel.start()
186− __actionGroup.start()
166+ actionGroup.start()
187− main.__active = true
167+ __active = true
188 }
168 }
189 }
169 }
190
170
191 function stop()
171 function stop()
192 {
172 {
193− if (main.__active) {
173+ if (__active) {
194− main.__active = false
174+ __active = false
195− __proxyModel.stop()
175+ proxyModel.stop()
196− __actionGroup.stop()
176+ actionGroup.stop()
197 }
177 }
198 }
178 }
199
179
plugins/IndicatorsClient/qml/qmldir+3−1
@@ -1,7 +1,9 @@
1module IndicatorsClient
1module IndicatorsClient
2plugin IndicatorsClientQml
2plugin IndicatorsClientQml
3
3
4−PluginItem 0.1 PluginItem.qml
4+IndicatorItem 0.1 IndicatorItem.qml
5+IndicatorIcon 0.1 IndicatorIcon.qml
6+IndicatorPage 0.1 IndicatorPage.qml
5BasicMenu 0.1 BasicMenu.qml
7BasicMenu 0.1 BasicMenu.qml
6ButtonMenu 0.1 ButtonMenu.qml
8ButtonMenu 0.1 ButtonMenu.qml
7DBusActionState 0.1 DBusActionState.qml
9DBusActionState 0.1 DBusActionState.qml
plugins/IndicatorsClient/resources/indicatorclient.qrc+7−4
@@ -5,9 +5,12 @@
5 <file>artwork/messaging/default_app.svg</file>
5 <file>artwork/messaging/default_app.svg</file>
6 <file>artwork/messaging/message_sms01_54px.png</file>
6 <file>artwork/messaging/message_sms01_54px.png</file>
7
7
8− <file>qml/CommonIndicator.qml</file>
8+ <file>qml/DefaultIndicatorIcon.qml</file>
9+ <file>qml/DefaultIndicatorPage.qml</file>
9− <file>qml/DatetimeIndicator.qml</file>
10+ <file>qml/DatetimeIndicatorIcon.qml</file>
10− <file>qml/MessagingIndicator.qml</file>
11+ <file>qml/DatetimeIndicatorPage.qml</file>
11− <file>qml/NetworkIndicator.qml</file>
12+ <file>qml/MessagingIndicatorPage.qml</file>
13+ <file>qml/NetworkIndicatorIcon.qml</file>
14+ <file>qml/NetworkIndicatorPage.qml</file>
12 </qresource>
15 </qresource>
13</RCC>
16</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 @@
17 * Renato Araujo Oliveira Filho <renato@canonical.com>
17 * Renato Araujo Oliveira Filho <renato@canonical.com>
18 */
18 */
19
19
20+import QtQuick 2.0
20import IndicatorsClient 0.1 as IndicatorsClient
21import IndicatorsClient 0.1 as IndicatorsClient
21
22
22−IndicatorsClient.PluginItem {
23+IndicatorsClient.IndicatorPage {
23 anchors.fill: parent
24 anchors.fill: parent
24}
25}
plugins/IndicatorsClient/resources/qml/MessagingIndicator.qml → plugins/IndicatorsClient/resources/qml/MessagingIndicatorPage.qmlrenamed+2−2
@@ -17,11 +17,11 @@
17 * Renato Araujo Oliveira Filho <renato.filho@canonical.com>
17 * Renato Araujo Oliveira Filho <renato.filho@canonical.com>
18 */
18 */
19
19
20−import IndicatorsClient 0.1 as IndicatorsClient
21import QtQuick 2.0
20import QtQuick 2.0
22import Ubuntu.Components 0.1
21import Ubuntu.Components 0.1
22+import IndicatorsClient 0.1 as IndicatorsClient
23
23
24−IndicatorsClient.PluginItem {
24+IndicatorsClient.IndicatorPage {
25 anchors.fill: parent
25 anchors.fill: parent
26
26
27 function stop() {
27 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 @@
17 * Renato Araujo Oliveira Filho <renato@canonical.com>
17 * Renato Araujo Oliveira Filho <renato@canonical.com>
18 */
18 */
19
19
20+import QtQuick 2.0
20import IndicatorsClient 0.1 as IndicatorsClient
21import IndicatorsClient 0.1 as IndicatorsClient
21import Ubuntu.Components 0.1
22import Ubuntu.Components 0.1
22import NetworkSettings 0.1
23import NetworkSettings 0.1
@@ -36,7 +37,7 @@ PageStack {
36 Page {
37 Page {
37 id: _mainPage
38 id: _mainPage
38
39
39− IndicatorsClient.PluginItem {
40+ IndicatorsClient.IndicatorPage {
40 id: _pluginItem
41 id: _pluginItem
41 anchors.fill: parent
42 anchors.fill: parent
42 }
43 }
tests/plugins/IndicatorsClient/fakeindicator.h+1−2
@@ -46,7 +46,7 @@ public:
46};
46};
47
47
48
48
49−#define FAKE_INDICATOR(number, title, icon) \
49+#define FAKE_INDICATOR(number, title) \
50 class FakeIndicatorClient##number : public FakeIndicatorClient \
50 class FakeIndicatorClient##number : public FakeIndicatorClient \
51 { \
51 { \
52 public: \
52 public: \
@@ -55,7 +55,6 @@ public:
55 { \
55 { \
56 setTitle(title); \
56 setTitle(title); \
57 setPriority(number); \
57 setPriority(number); \
58− setIcon(QUrl(icon)); \
59 } \
58 } \
60 };
59 };
61
60
tests/plugins/IndicatorsClient/indicatorsmanagertest.cpp+2−3
@@ -25,8 +25,8 @@
25#include <QtTest>
25#include <QtTest>
26#include <QDebug>
26#include <QDebug>
27
27
28−FAKE_INDICATOR(1, "Fake Title 1", "fake-indicator-1")
28+FAKE_INDICATOR(1, "Fake Title 1")
29−FAKE_INDICATOR(2, "Fake Title 2", "fake-indicator-2")
29+FAKE_INDICATOR(2, "Fake Title 2")
30
30
31class IndicatorsManagerTest : public QObject
31class IndicatorsManagerTest : public QObject
32{
32{
@@ -74,7 +74,6 @@ private Q_SLOTS:
74 QVERIFY(indicator.get());
74 QVERIFY(indicator.get());
75
75
76 QCOMPARE(indicator->identifier(), QString("indicator-fake1"));
76 QCOMPARE(indicator->identifier(), QString("indicator-fake1"));
77− QCOMPARE(indicator->icon(), QUrl("image://gicon/fake-indicator-1"));
78 QCOMPARE(indicator->title(), QString("Fake Title 1"));
77 QCOMPARE(indicator->title(), QString("Fake Title 1"));
79 QCOMPARE(indicator->label(), QString());
78 QCOMPARE(indicator->label(), QString());
80 QCOMPARE(indicator->description(), QString());
79 QCOMPARE(indicator->description(), QString());
tests/plugins/IndicatorsClient/indicatorsmodeltest.cpp+2−4
@@ -25,8 +25,8 @@
25#include <QtTest>
25#include <QtTest>
26#include <QDebug>
26#include <QDebug>
27
27
28−FAKE_INDICATOR(1, "Fake Title 1", "fake-indicator-1")
28+FAKE_INDICATOR(1, "Fake Title 1")
29−FAKE_INDICATOR(2, "Fake Title 2", "fake-indicator-2")
29+FAKE_INDICATOR(2, "Fake Title 2")
30
30
31class IndicatorsModelTest : public QObject
31class IndicatorsModelTest : public QObject
32{
32{
@@ -70,7 +70,6 @@ private Q_SLOTS:
70 QVariantMap data = model.get(0);
70 QVariantMap data = model.get(0);
71 QCOMPARE(data["title"].toString(), QString("Fake Title 1"));
71 QCOMPARE(data["title"].toString(), QString("Fake Title 1"));
72 QCOMPARE(data["label"].toString(), QString());
72 QCOMPARE(data["label"].toString(), QString());
73− QCOMPARE(data["iconSource"].value<QUrl>(), QUrl("image://gicon/fake-indicator-1"));
74 QCOMPARE(data["description"].toString(), QString());
73 QCOMPARE(data["description"].toString(), QString());
75 // There is no QML context
74 // There is no QML context
76 QVERIFY(!data["component"].value<QObject*>());
75 QVERIFY(!data["component"].value<QObject*>());
@@ -79,7 +78,6 @@ private Q_SLOTS:
79 data = model.get(1);
78 data = model.get(1);
80 QCOMPARE(data["title"].toString(), QString("Fake Title 2"));
79 QCOMPARE(data["title"].toString(), QString("Fake Title 2"));
81 QCOMPARE(data["label"].toString(), QString());
80 QCOMPARE(data["label"].toString(), QString());
82− QCOMPARE(data["iconSource"].value<QUrl>(), QUrl("image://gicon/fake-indicator-2"));
83 QCOMPARE(data["description"].toString(), QString());
81 QCOMPARE(data["description"].toString(), QString());
84 // There is no QML context
82 // There is no QML context
85 QVERIFY(!data["component"].value<QObject*>());
83 QVERIFY(!data["component"].value<QObject*>());