Merge lp:~nick-dedekind/unity8/rtm-1385331 into lp:unity8/rtm-14.09

Proposed by Michał Sawicz
Status: Merged
Approved by: Michael Zanetti
Approved revision: 1432
Merged at revision: 1414
Proposed branch: lp:~nick-dedekind/unity8/rtm-1385331
Merge into: lp:unity8/rtm-14.09
Prerequisite: lp:~unity-team/unity8/rtm-20150113
Diff against target: 1841 lines (+1038/-301)
33 files modified
debian/control (+3/-3)
plugins/Lights/Lights.cpp (+9/-24)
plugins/Unity/Indicators/CMakeLists.txt (+3/-1)
plugins/Unity/Indicators/actionrootstate.cpp (+97/-0)
plugins/Unity/Indicators/actionrootstate.h (+55/-0)
plugins/Unity/Indicators/modelactionrootstate.cpp (+127/-0)
plugins/Unity/Indicators/modelactionrootstate.h (+61/-0)
plugins/Unity/Indicators/plugin.cpp (+4/-2)
plugins/Unity/Indicators/rootstateparser.cpp (+75/-142)
plugins/Unity/Indicators/rootstateparser.h (+20/-36)
qml/Greeter/Clock.qml (+1/-1)
qml/Panel/IndicatorItem.qml (+0/-8)
qml/Panel/Indicators/IndicatorBase.qml (+1/-1)
qml/Panel/Indicators/IndicatorsLight.qml (+19/-1)
qml/Panel/IndicatorsBar.qml (+29/-20)
qml/Panel/IndicatorsMenu.qml (+5/-0)
tests/mocks/CMakeLists.txt (+1/-0)
tests/mocks/Lights/CMakeLists.txt (+8/-0)
tests/mocks/Lights/Lights.cpp (+84/-0)
tests/mocks/Lights/Lights.h (+66/-0)
tests/mocks/Lights/plugin.cpp (+33/-0)
tests/mocks/Lights/plugin.h (+32/-0)
tests/mocks/Lights/qmldir (+3/-0)
tests/mocks/QMenuModel/CMakeLists.txt (+1/-0)
tests/mocks/QMenuModel/QDBusActionGroup.qml (+7/-57)
tests/mocks/QMenuModel/actiondata.h (+52/-0)
tests/mocks/QMenuModel/plugin.cpp (+10/-0)
tests/mocks/Unity/Indicators/ActionRootState.qml (+46/-0)
tests/mocks/Unity/Indicators/qmldir (+2/-1)
tests/plugins/Unity/Indicators/rootactionstatetest.cpp (+4/-4)
tests/qmltests/CMakeLists.txt (+1/-0)
tests/qmltests/Panel/Indicators/tst_IndicatorsLight.qml (+129/-0)
tests/qmltests/Panel/Indicators/tst_MenuItemFactory.qml (+50/-0)
To merge this branch: bzr merge lp:~nick-dedekind/unity8/rtm-1385331
Reviewer Review Type Date Requested Status
Michael Zanetti (community) Approve
Michał Sawicz Needs Fixing
Review via email: mp+246403@code.launchpad.net

Commit message

Unhook Lights interface from indicator widgets
Approved by: Albert Astals Cid

Description of the change

Led fix

To post a comment you must log in.
Revision history for this message
Michał Sawicz (saviq) wrote :

Hey, this caused a FTBFS:

unity8-8.02+15.04.20150114~rtm/plugins/Unity/Indicators/plugin.cpp:34:29: fatal error: rootactionstate.h: No such file or directory
 #include "rootactionstate.h"
                             ^
compilation terminated.

review: Needs Fixing
lp:~nick-dedekind/unity8/rtm-1385331 updated
1428. By Nick Dedekind

removed old file

1429. By Nick Dedekind

removed multiple new lines

Revision history for this message
Michał Sawicz (saviq) wrote :

:(

file:///usr/share/unity8/Shell.qml:685:9: Type Panel unavailable
             Panel {
             ^
file:///usr/share/unity8/Panel/Panel.qml:116:9: Type IndicatorsMenu unavailable
             IndicatorsMenu {
             ^
file:///usr/share/unity8/Panel/IndicatorsMenu.qml:63:5: IndicatorsLight is not a type
         IndicatorsLight {
         ^

review: Needs Fixing
lp:~nick-dedekind/unity8/rtm-1385331 updated
1430. By Nick Dedekind

merged parent

1431. By Nick Dedekind

added import

Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

> :(
>
> file:///usr/share/unity8/Shell.qml:685:9: Type Panel unavailable
> Panel {
> ^
> file:///usr/share/unity8/Panel/Panel.qml:116:9: Type IndicatorsMenu
> unavailable
> IndicatorsMenu {
> ^
> file:///usr/share/unity8/Panel/IndicatorsMenu.qml:63:5: IndicatorsLight is not
> a type
> IndicatorsLight {
> ^

Fixed.

Revision history for this message
Michael Zanetti (mzanetti) wrote :

This seems to break the panel: http://i.imgur.com/8ASuvJE.png?1

lp:~nick-dedekind/unity8/rtm-1385331 updated
1432. By Nick Dedekind

fixes for indicators

Revision history for this message
Michael Zanetti (mzanetti) wrote :

seems to work fine now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/control'
--- debian/control 2015-01-08 12:51:33 +0000
+++ debian/control 2015-01-19 17:39:20 +0000
@@ -23,7 +23,7 @@
23 libpam0g-dev,23 libpam0g-dev,
24 libpay2-dev,24 libpay2-dev,
25 libpulse-dev,25 libpulse-dev,
26 libqmenumodel-dev (>= 0.2.8),26 libqmenumodel-dev (>= 0.2.9),
27 libqt5xmlpatterns5-dev,27 libqt5xmlpatterns5-dev,
28 libunity-api-dev (>= 7.94~),28 libunity-api-dev (>= 7.94~),
29 libusermetricsoutput1-dev,29 libusermetricsoutput1-dev,
@@ -59,7 +59,7 @@
5959
60Package: indicators-client60Package: indicators-client
61Architecture: amd64 armhf i38661Architecture: amd64 armhf i386
62Depends: qmenumodel-qml (>= 0.2.8),62Depends: qmenumodel-qml (>= 0.2.9),
63 qtdeclarative5-ubuntu-ui-toolkit-plugin (>= 0.1.49) | qtdeclarative5-ubuntu-ui-toolkit-plugin-gles (>= 0.1.49),63 qtdeclarative5-ubuntu-ui-toolkit-plugin (>= 0.1.49) | qtdeclarative5-ubuntu-ui-toolkit-plugin-gles (>= 0.1.49),
64 unity8 (= ${binary:Version}),64 unity8 (= ${binary:Version}),
65 ${misc:Depends},65 ${misc:Depends},
@@ -83,7 +83,7 @@
83Depends: gsettings-desktop-schemas,83Depends: gsettings-desktop-schemas,
84 libcap2-bin,84 libcap2-bin,
85 libglib2.0-bin,85 libglib2.0-bin,
86 qmenumodel-qml (>= 0.2.8),86 qmenumodel-qml (>= 0.2.9),
87 qml-module-qtquick-xmllistmodel,87 qml-module-qtquick-xmllistmodel,
88 qtdeclarative5-gsettings1.0,88 qtdeclarative5-gsettings1.0,
89 qtdeclarative5-qtmir-plugin (>= 0.4.4),89 qtdeclarative5-qtmir-plugin (>= 0.4.4),
9090
=== modified file 'plugins/Lights/Lights.cpp'
--- plugins/Lights/Lights.cpp 2014-09-08 15:07:24 +0000
+++ plugins/Lights/Lights.cpp 2015-01-19 17:39:20 +0000
@@ -44,12 +44,20 @@
4444
45void Lights::setState(Lights::State newState)45void Lights::setState(Lights::State newState)
46{46{
47 if (!init()) {
48 qWarning() << "No lights device";
49 return;
50 }
51
47 if (m_state != newState) {52 if (m_state != newState) {
48 if (newState == Lights::On) {53 if (newState == Lights::On) {
49 turnOn();54 turnOn();
50 } else {55 } else {
51 turnOff();56 turnOff();
52 }57 }
58
59 m_state = newState;
60 Q_EMIT stateChanged(m_state);
53 }61 }
54}62}
5563
@@ -115,6 +123,7 @@
115 err = module->methods->open(module, LIGHT_ID_NOTIFICATIONS, &device);123 err = module->methods->open(module, LIGHT_ID_NOTIFICATIONS, &device);
116 if (err == 0) {124 if (err == 0) {
117 m_lightDevice = (light_device_t*)device;125 m_lightDevice = (light_device_t*)device;
126 turnOff();
118 return true;127 return true;
119 } else {128 } else {
120 qWarning() << "Failed to access notification lights";129 qWarning() << "Failed to access notification lights";
@@ -127,15 +136,6 @@
127136
128void Lights::turnOn()137void Lights::turnOn()
129{138{
130 if (!init()) {
131 qWarning() << "No lights device";
132 return;
133 }
134
135 if (m_state == Lights::On) {
136 return;
137 }
138
139 // pulse139 // pulse
140 light_state_t state;140 light_state_t state;
141 memset(&state, 0, sizeof(light_state_t));141 memset(&state, 0, sizeof(light_state_t));
@@ -147,23 +147,11 @@
147147
148 if (m_lightDevice->set_light(m_lightDevice, &state) != 0) {148 if (m_lightDevice->set_light(m_lightDevice, &state) != 0) {
149 qWarning() << "Failed to turn the light off";149 qWarning() << "Failed to turn the light off";
150 } else {
151 m_state = Lights::On;
152 Q_EMIT stateChanged(m_state);
153 }150 }
154}151}
155152
156void Lights::turnOff()153void Lights::turnOff()
157{154{
158 if (!init()) {
159 qWarning() << "No lights device";
160 return;
161 }
162
163 if (m_state == Lights::Off) {
164 return;
165 }
166
167 light_state_t state;155 light_state_t state;
168 memset(&state, 0, sizeof(light_state_t));156 memset(&state, 0, sizeof(light_state_t));
169 state.color = 0x00000000;157 state.color = 0x00000000;
@@ -174,8 +162,5 @@
174162
175 if (m_lightDevice->set_light(m_lightDevice, &state) != 0) {163 if (m_lightDevice->set_light(m_lightDevice, &state) != 0) {
176 qWarning() << "Failed to turn the light off";164 qWarning() << "Failed to turn the light off";
177 } else {
178 m_state = Lights::Off;
179 Q_EMIT stateChanged(m_state);
180 }165 }
181}166}
182167
=== modified file 'plugins/Unity/Indicators/CMakeLists.txt'
--- plugins/Unity/Indicators/CMakeLists.txt 2014-10-03 10:53:02 +0000
+++ plugins/Unity/Indicators/CMakeLists.txt 2015-01-19 17:39:20 +0000
@@ -16,14 +16,16 @@
16)16)
1717
18set(IndicatorsQML_SOURCES18set(IndicatorsQML_SOURCES
19 actionrootstate.cpp
19 indicator.cpp20 indicator.cpp
20 indicators.h21 indicators.h
21 indicatorsmanager.cpp22 indicatorsmanager.cpp
22 indicatorsmodel.cpp23 indicatorsmodel.cpp
23 menucontentactivator.cpp24 menucontentactivator.cpp
25 modelactionrootstate.cpp
24 modelprinter.cpp26 modelprinter.cpp
25 plugin.cpp27 plugin.cpp
26 rootactionstate.cpp28 rootstateparser.cpp
27 sharedunitymenumodel.cpp29 sharedunitymenumodel.cpp
28 unitymenumodelcache.cpp30 unitymenumodelcache.cpp
29 unitymenumodelstack.cpp31 unitymenumodelstack.cpp
3032
=== added file 'plugins/Unity/Indicators/actionrootstate.cpp'
--- plugins/Unity/Indicators/actionrootstate.cpp 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Indicators/actionrootstate.cpp 2015-01-19 17:39:20 +0000
@@ -0,0 +1,97 @@
1/*
2 * Copyright 2014 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
17#include "actionrootstate.h"
18
19#include <qdbusactiongroup.h>
20#include <QDebug>
21
22ActionRootState::ActionRootState(QObject *parent)
23 : RootStateObject(parent)
24 , m_actionGroup(nullptr)
25{
26}
27
28QDBusActionGroup *ActionRootState::actionGroup() const
29{
30 return m_actionGroup;
31}
32
33void ActionRootState::setActionGroup(QDBusActionGroup *actionGroup)
34{
35 if (m_actionGroup != actionGroup) {
36 bool wasValid = valid();
37
38 if (m_actionGroup) {
39 disconnect(m_actionGroup, 0, this, 0);
40 }
41 m_actionGroup = actionGroup;
42
43 if (m_actionGroup) {
44 connect(m_actionGroup, &QDBusActionGroup::statusChanged, this, [&](bool) { updateActionState(); });
45 connect(m_actionGroup, &QDBusActionGroup::actionAppear, this, [&](const QString&) { updateActionState(); });
46 connect(m_actionGroup, &QDBusActionGroup::actionVanish, this, [&](const QString&) { updateActionState(); });
47 connect(m_actionGroup, &QDBusActionGroup::actionStateChanged, this, [&](QVariant) { updateActionState(); });
48
49 connect(m_actionGroup, &QObject::destroyed, this, [&](QObject*) { updateActionState(); });
50 }
51 updateActionState();
52 Q_EMIT actionGroupChanged();
53
54 if (wasValid != valid()) Q_EMIT validChanged();
55 }
56}
57
58QString ActionRootState::actionName() const
59{
60 return m_actionName;
61}
62
63void ActionRootState::setActionName(const QString &actionName)
64{
65 if (m_actionName != actionName) {
66 bool wasValid = valid();
67
68 m_actionName = actionName;
69 updateActionState();
70
71 Q_EMIT actionNameChanged();
72
73 if (wasValid != valid()) Q_EMIT validChanged();
74 }
75}
76
77bool ActionRootState::valid() const
78{
79 return m_actionGroup && m_actionGroup->status() == DBusEnums::Connected &&
80 !m_actionName.isEmpty() && m_actionGroup->hasAction(m_actionName);
81}
82
83void ActionRootState::updateActionState()
84{
85 if (valid()) {
86 ActionStateParser* oldParser = m_actionGroup->actionStateParser();
87 m_actionGroup->setActionStateParser(&m_parser);
88
89 QVariantMap state = m_actionGroup->actionState(m_actionName).toMap();
90
91 m_actionGroup->setActionStateParser(oldParser);
92
93 setCurrentState(state);
94 } else {
95 setCurrentState(QVariantMap());
96 }
97}
098
=== added file 'plugins/Unity/Indicators/actionrootstate.h'
--- plugins/Unity/Indicators/actionrootstate.h 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Indicators/actionrootstate.h 2015-01-19 17:39:20 +0000
@@ -0,0 +1,55 @@
1/*
2 * Copyright 2014 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
17#ifndef ACTIONROOTSTATE_H
18#define ACTIONROOTSTATE_H
19
20#include "unityindicatorsglobal.h"
21
22#include "rootstateparser.h"
23
24class QDBusActionGroup;
25
26class UNITYINDICATORS_EXPORT ActionRootState : public RootStateObject
27{
28 Q_OBJECT
29 Q_PROPERTY(QDBusActionGroup* actionGroup READ actionGroup WRITE setActionGroup NOTIFY actionGroupChanged)
30 Q_PROPERTY(QString actionName READ actionName WRITE setActionName NOTIFY actionNameChanged)
31
32public:
33 ActionRootState(QObject *parent = 0);
34
35 QDBusActionGroup *actionGroup() const;
36 void setActionGroup(QDBusActionGroup *actionGroup);
37
38 QString actionName() const;
39 void setActionName(const QString& actionName);
40
41 bool valid() const override;
42
43Q_SIGNALS:
44 void actionGroupChanged();
45 void actionNameChanged();
46
47private Q_SLOTS:
48 void updateActionState();
49
50private:
51 QDBusActionGroup* m_actionGroup;
52 QString m_actionName;
53};
54
55#endif // ACTIONROOTSTATE_H
056
=== added file 'plugins/Unity/Indicators/modelactionrootstate.cpp'
--- plugins/Unity/Indicators/modelactionrootstate.cpp 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Indicators/modelactionrootstate.cpp 2015-01-19 17:39:20 +0000
@@ -0,0 +1,127 @@
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 * Nick Dedekind <nick.dedekind@canonical.com>
18 */
19
20#include "modelactionrootstate.h"
21#include "indicators.h"
22
23#include <unitymenumodel.h>
24#include <QVariant>
25#include <QIcon>
26
27extern "C" {
28#include <glib.h>
29#include <gio/gio.h>
30}
31
32ModelActionRootState::ModelActionRootState(QObject *parent)
33 : RootStateObject(parent),
34 m_menu(nullptr)
35{
36}
37
38ModelActionRootState::~ModelActionRootState()
39{
40}
41
42UnityMenuModel* ModelActionRootState::menu() const
43{
44 return m_menu;
45}
46
47void ModelActionRootState::setMenu(UnityMenuModel* menu)
48{
49 if (m_menu != menu) {
50 bool wasValid = valid();
51
52 if (m_menu) {
53 m_menu->disconnect(this);
54 }
55 m_menu = menu;
56
57 if (m_menu) {
58 connect(m_menu, SIGNAL(rowsInserted(const QModelIndex&, int, int)), SLOT(onModelRowsAdded(const QModelIndex&, int, int)));
59 connect(m_menu, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), SLOT(onModelRowsRemoved(const QModelIndex&, int, int)));
60 connect(m_menu, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)), SLOT(onModelDataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)));
61
62 connect(m_menu, SIGNAL(destroyed()), SLOT(reset()));
63 }
64 updateActionState();
65 Q_EMIT menuChanged();
66
67 if (wasValid != valid())
68 Q_EMIT validChanged();
69 }
70}
71
72bool ModelActionRootState::valid() const
73{
74 return m_menu && m_menu->rowCount() > 0;
75}
76
77void ModelActionRootState::onModelRowsAdded(const QModelIndex& parent, int start, int end)
78{
79 Q_UNUSED(parent);
80 if (start == 0 && end >= 0) {
81 updateActionState();
82 }
83}
84
85void ModelActionRootState::onModelRowsRemoved(const QModelIndex& parent, int start, int end)
86{
87 Q_UNUSED(parent);
88 if (start == 0 && end >= 0) {
89 updateActionState();
90 }
91}
92
93void ModelActionRootState::onModelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles)
94{
95 Q_UNUSED(roles);
96 if (!topLeft.isValid() || !bottomRight.isValid()) {
97 return;
98 }
99
100 if (topLeft.row() <= 0 && bottomRight.row() >= 0) {
101 updateActionState();
102 }
103}
104
105void ModelActionRootState::reset()
106{
107 m_menu = nullptr;
108
109 Q_EMIT menuChanged();
110 setCurrentState(QVariantMap());
111}
112
113void ModelActionRootState::updateActionState()
114{
115 if (m_menu && m_menu->rowCount() > 0) {
116 ActionStateParser* oldParser = m_menu->actionStateParser();
117 m_menu->setActionStateParser(&m_parser);
118
119 QVariantMap state = m_menu->get(0, "actionState").toMap();
120
121 m_menu->setActionStateParser(oldParser);
122
123 setCurrentState(state);
124 } else {
125 setCurrentState(QVariantMap());
126 }
127}
0128
=== added file 'plugins/Unity/Indicators/modelactionrootstate.h'
--- plugins/Unity/Indicators/modelactionrootstate.h 1970-01-01 00:00:00 +0000
+++ plugins/Unity/Indicators/modelactionrootstate.h 2015-01-19 17:39:20 +0000
@@ -0,0 +1,61 @@
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 * Nick Dedekind <nick.dedekind@canonical.com>
18 */
19
20#ifndef MODELACTIONROOTSTATE_H
21#define MODELACTIONROOTSTATE_H
22
23#include "unityindicatorsglobal.h"
24
25#include "rootstateparser.h"
26
27class UnityMenuModel;
28
29class UNITYINDICATORS_EXPORT ModelActionRootState : public RootStateObject
30{
31 Q_OBJECT
32 Q_PROPERTY(UnityMenuModel* menu READ menu WRITE setMenu NOTIFY menuChanged)
33public:
34 ModelActionRootState(QObject *parent = 0);
35 virtual ~ModelActionRootState();
36
37 UnityMenuModel* menu() const;
38 void setMenu(UnityMenuModel* menu);
39
40 int index() const;
41 void setIndex(int index);
42
43 bool valid() const override;
44
45Q_SIGNALS:
46 void menuChanged();
47 void indexChanged();
48
49private Q_SLOTS:
50 void onModelRowsAdded(const QModelIndex& parent, int start, int end);
51 void onModelRowsRemoved(const QModelIndex& parent, int start, int end);
52 void onModelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>&);
53 void reset();
54
55private:
56 void updateActionState();
57
58 UnityMenuModel* m_menu;
59};
60
61#endif // MODELACTIONROOTSTATE_H
062
=== modified file 'plugins/Unity/Indicators/plugin.cpp'
--- plugins/Unity/Indicators/plugin.cpp 2014-10-07 10:28:59 +0000
+++ plugins/Unity/Indicators/plugin.cpp 2015-01-19 17:39:20 +0000
@@ -24,12 +24,13 @@
24#include "plugin.h"24#include "plugin.h"
2525
26// local26// local
27#include "actionrootstate.h"
27#include "indicators.h"28#include "indicators.h"
28#include "indicatorsmanager.h"29#include "indicatorsmanager.h"
29#include "indicatorsmodel.h"30#include "indicatorsmodel.h"
30#include "menucontentactivator.h"31#include "menucontentactivator.h"
32#include "modelactionrootstate.h"
31#include "modelprinter.h"33#include "modelprinter.h"
32#include "rootactionstate.h"
33#include "sharedunitymenumodel.h"34#include "sharedunitymenumodel.h"
34#include "unitymenumodelcache.h"35#include "unitymenumodelcache.h"
35#include "unitymenumodelstack.h"36#include "unitymenumodelstack.h"
@@ -51,7 +52,8 @@
51 qmlRegisterType<IndicatorsModel>(uri, 0, 1, "IndicatorsModel");52 qmlRegisterType<IndicatorsModel>(uri, 0, 1, "IndicatorsModel");
52 qmlRegisterType<MenuContentActivator>(uri, 0, 1, "MenuContentActivator");53 qmlRegisterType<MenuContentActivator>(uri, 0, 1, "MenuContentActivator");
53 qmlRegisterType<UnityMenuModelStack>(uri, 0, 1, "UnityMenuModelStack");54 qmlRegisterType<UnityMenuModelStack>(uri, 0, 1, "UnityMenuModelStack");
54 qmlRegisterType<RootActionState>(uri, 0, 1, "RootActionState");55 qmlRegisterType<ModelActionRootState>(uri, 0, 1, "ModelActionRootState");
56 qmlRegisterType<ActionRootState>(uri, 0, 1, "ActionRootState");
55 qmlRegisterType<ModelPrinter>(uri, 0, 1, "ModelPrinter");57 qmlRegisterType<ModelPrinter>(uri, 0, 1, "ModelPrinter");
56 qmlRegisterType<VisibleIndicatorsModel>(uri, 0, 1, "VisibleIndicatorsModel");58 qmlRegisterType<VisibleIndicatorsModel>(uri, 0, 1, "VisibleIndicatorsModel");
57 qmlRegisterType<SharedUnityMenuModel>(uri, 0, 1, "SharedUnityMenuModel");59 qmlRegisterType<SharedUnityMenuModel>(uri, 0, 1, "SharedUnityMenuModel");
5860
=== renamed file 'plugins/Unity/Indicators/rootactionstate.cpp' => 'plugins/Unity/Indicators/rootstateparser.cpp'
--- plugins/Unity/Indicators/rootactionstate.cpp 2014-10-20 12:38:16 +0000
+++ plugins/Unity/Indicators/rootstateparser.cpp 2015-01-19 17:39:20 +0000
@@ -12,155 +12,18 @@
12 *12 *
13 * You should have received a copy of the GNU Lesser General Public License13 * 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/>.14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Nick Dedekind <nick.dedekind@canonical.com>
18 */15 */
1916
20#include "rootactionstate.h"17#include "rootstateparser.h"
21#include "indicators.h"
22
23#include <unitymenumodel.h>
24#include <QVariant>
25#include <QIcon>
2618
27extern "C" {19extern "C" {
28#include <glib.h>20#include <glib.h>
29#include <gio/gio.h>21#include <gio/gio.h>
30}22}
3123
32RootActionState::RootActionState(QObject *parent)24RootStateParser::RootStateParser(QObject* parent)
33 : ActionStateParser(parent),25 : ActionStateParser(parent)
34 m_menu(nullptr)26{
35{
36}
37
38RootActionState::~RootActionState()
39{
40}
41
42UnityMenuModel* RootActionState::menu() const
43{
44 return m_menu;
45}
46
47void RootActionState::setMenu(UnityMenuModel* menu)
48{
49 if (m_menu != menu) {
50 if (m_menu) {
51 m_menu->disconnect(this);
52 }
53 m_menu = menu;
54
55 if (m_menu) {
56 connect(m_menu, SIGNAL(rowsInserted(const QModelIndex&, int, int)), SLOT(onModelRowsAdded(const QModelIndex&, int, int)));
57 connect(m_menu, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), SLOT(onModelRowsRemoved(const QModelIndex&, int, int)));
58 connect(m_menu, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)), SLOT(onModelDataChanged(const QModelIndex&, const QModelIndex&, const QVector<int>&)));
59
60 connect(m_menu, SIGNAL(destroyed()), SLOT(reset()));
61 }
62 updateActionState();
63 Q_EMIT menuChanged();
64 }
65}
66
67void RootActionState::onModelRowsAdded(const QModelIndex& parent, int start, int end)
68{
69 Q_UNUSED(parent);
70 if (start == 0 && end >= 0) {
71 updateActionState();
72 }
73}
74
75void RootActionState::onModelRowsRemoved(const QModelIndex& parent, int start, int end)
76{
77 Q_UNUSED(parent);
78 if (start == 0 && end >= 0) {
79 updateActionState();
80 }
81}
82
83void RootActionState::onModelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles)
84{
85 Q_UNUSED(roles);
86 if (!topLeft.isValid() || !bottomRight.isValid()) {
87 return;
88 }
89
90 if (topLeft.row() <= 0 && bottomRight.row() >= 0) {
91 updateActionState();
92 }
93}
94
95void RootActionState::reset()
96{
97 m_cachedState.clear();
98 m_menu = nullptr;
99
100 Q_EMIT menuChanged();
101 Q_EMIT updated();
102}
103
104void RootActionState::updateActionState()
105{
106 if (m_menu && m_menu->rowCount() > 0) {
107 ActionStateParser* oldParser = m_menu->actionStateParser();
108 m_menu->setActionStateParser(this);
109
110 m_cachedState = m_menu->get(0, "actionState").toMap();
111
112 m_menu->setActionStateParser(oldParser);
113 } else {
114 m_cachedState.clear();
115 }
116 Q_EMIT updated();
117}
118
119bool RootActionState::isValid() const
120{
121 return m_menu && m_menu->rowCount() > 0;
122}
123
124QString RootActionState::title() const
125{
126 if (!isValid()) return QString();
127
128 return m_cachedState.value("title", QVariant::fromValue(QString())).toString();
129}
130
131QString RootActionState::leftLabel() const
132{
133 if (!isValid()) return QString();
134
135 return m_cachedState.value("pre-label", QVariant::fromValue(QString())).toString();
136}
137
138QString RootActionState::rightLabel() const
139{
140 if (!isValid()) return QString();
141
142 return m_cachedState.value("label", QVariant::fromValue(QString())).toString();
143}
144
145QStringList RootActionState::icons() const
146{
147 if (!isValid()) return QStringList();
148
149 return m_cachedState.value("icons", QVariant::fromValue(QStringList())).toStringList();
150}
151
152QString RootActionState::accessibleName() const
153{
154 if (!isValid()) return QString();
155
156 return m_cachedState.value("accessible-desc", QVariant::fromValue(QString())).toString();
157}
158
159bool RootActionState::indicatorVisible() const
160{
161 if (!isValid()) return false;
162
163 return m_cachedState.value("visible", QVariant::fromValue(true)).toBool();
164}27}
16528
166static QString iconUri(GIcon *icon)29static QString iconUri(GIcon *icon)
@@ -209,7 +72,7 @@
209 return uri;72 return uri;
210}73}
21174
212QVariant RootActionState::toQVariant(GVariant* state) const75QVariant RootStateParser::toQVariant(GVariant* state) const
213{76{
214 if (!state) {77 if (!state) {
215 return QVariant();78 return QVariant();
@@ -296,3 +159,73 @@
296 }159 }
297 return ActionStateParser::toQVariant(state);160 return ActionStateParser::toQVariant(state);
298}161}
162
163
164RootStateObject::RootStateObject(QObject* parent)
165 : QObject(parent)
166{
167}
168
169QString RootStateObject::title() const
170{
171 if (!valid()) return QString();
172
173 return m_currentState.value("title", QVariant::fromValue(QString())).toString();
174}
175
176QString RootStateObject::leftLabel() const
177{
178 if (!valid()) return QString();
179
180 return m_currentState.value("pre-label", QVariant::fromValue(QString())).toString();
181}
182
183QString RootStateObject::rightLabel() const
184{
185 if (!valid()) return QString();
186
187 return m_currentState.value("label", QVariant::fromValue(QString())).toString();
188}
189
190QStringList RootStateObject::icons() const
191{
192 if (!valid()) return QStringList();
193
194 return m_currentState.value("icons", QVariant::fromValue(QStringList())).toStringList();
195}
196
197QString RootStateObject::accessibleName() const
198{
199 if (!valid()) return QString();
200
201 return m_currentState.value("accessible-desc", QVariant::fromValue(QString())).toString();
202}
203
204bool RootStateObject::indicatorVisible() const
205{
206 if (!valid()) return false;
207
208 return m_currentState.value("visible", QVariant::fromValue(true)).toBool();
209}
210
211void RootStateObject::setCurrentState(const QVariantMap& newState)
212{
213 QString oldTitle = title();
214 QString oldLeftLabel = leftLabel();
215 QString oldRightLabel = rightLabel();
216 QStringList oldIcons = icons();
217 QString oldAccessibleName = accessibleName();
218 bool oldIndicatorVisible = indicatorVisible();
219
220 if (m_currentState != newState) {
221 m_currentState = newState;
222 Q_EMIT updated();
223
224 if (oldTitle != title()) Q_EMIT titleChanged();
225 if (oldLeftLabel != leftLabel()) Q_EMIT leftLabelChanged();
226 if (oldRightLabel != rightLabel()) Q_EMIT rightLabelChanged();
227 if (oldIcons != icons()) Q_EMIT iconsChanged();
228 if (oldAccessibleName != accessibleName()) Q_EMIT accessibleNameChanged();
229 if (oldIndicatorVisible != indicatorVisible()) Q_EMIT indicatorVisibleChanged();
230 }
231}
299232
=== renamed file 'plugins/Unity/Indicators/rootactionstate.h' => 'plugins/Unity/Indicators/rootstateparser.h'
--- plugins/Unity/Indicators/rootactionstate.h 2014-10-20 12:38:16 +0000
+++ plugins/Unity/Indicators/rootstateparser.h 2015-01-19 17:39:20 +0000
@@ -12,26 +12,27 @@
12 *12 *
13 * You should have received a copy of the GNU Lesser General Public License13 * 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/>.14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Nick Dedekind <nick.dedekind@canonical.com>
18 */15 */
1916
20#ifndef ROOTACTIONSTATE_H17#ifndef ROOTSTATEPARSER_H
21#define ROOTACTIONSTATE_H18#define ROOTSTATEPARSER_H
2219
23#include "unityindicatorsglobal.h"20#include "unityindicatorsglobal.h"
2421
25#include <actionstateparser.h>22#include <actionstateparser.h>
2623
27class UnityMenuModel;24class UNITYINDICATORS_EXPORT RootStateParser : public ActionStateParser
25{
26public:
27 RootStateParser(QObject* parent = nullptr);
28 virtual QVariant toQVariant(GVariant* state) const override;
29};
2830
29class UNITYINDICATORS_EXPORT RootActionState : public ActionStateParser31class UNITYINDICATORS_EXPORT RootStateObject : public QObject
30{32{
31 Q_OBJECT33 Q_OBJECT
32 Q_PROPERTY(UnityMenuModel* menu READ menu WRITE setMenu NOTIFY menuChanged)
3334
34 Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)35 Q_PROPERTY(bool valid READ valid NOTIFY validChanged)
35 Q_PROPERTY(QString title READ title NOTIFY titleChanged)36 Q_PROPERTY(QString title READ title NOTIFY titleChanged)
36 Q_PROPERTY(QString leftLabel READ leftLabel NOTIFY leftLabelChanged)37 Q_PROPERTY(QString leftLabel READ leftLabel NOTIFY leftLabelChanged)
37 Q_PROPERTY(QString rightLabel READ rightLabel NOTIFY rightLabelChanged)38 Q_PROPERTY(QString rightLabel READ rightLabel NOTIFY rightLabelChanged)
@@ -39,16 +40,10 @@
39 Q_PROPERTY(QString accessibleName READ accessibleName NOTIFY accessibleNameChanged)40 Q_PROPERTY(QString accessibleName READ accessibleName NOTIFY accessibleNameChanged)
40 Q_PROPERTY(bool indicatorVisible READ indicatorVisible NOTIFY indicatorVisibleChanged)41 Q_PROPERTY(bool indicatorVisible READ indicatorVisible NOTIFY indicatorVisibleChanged)
41public:42public:
42 RootActionState(QObject *parent = 0);43 RootStateObject(QObject* parent = 0);
43 virtual ~RootActionState();44
4445 virtual bool valid() const = 0;
45 UnityMenuModel* menu() const;46
46 void setMenu(UnityMenuModel* menu);
47
48 int index() const;
49 void setIndex(int index);
50
51 bool isValid() const;
52 QString title() const;47 QString title() const;
53 QString leftLabel() const;48 QString leftLabel() const;
54 QString rightLabel() const;49 QString rightLabel() const;
@@ -56,15 +51,12 @@
56 QString accessibleName() const;51 QString accessibleName() const;
57 bool indicatorVisible() const;52 bool indicatorVisible() const;
5853
59 // from ActionStateParser54 QVariantMap currentState() const { return m_currentState; }
60 virtual QVariant toQVariant(GVariant* state) const override;55 void setCurrentState(const QVariantMap& currentState);
6156
62Q_SIGNALS:57Q_SIGNALS:
63 void updated();58 void updated();
6459
65 void menuChanged();
66 void indexChanged();
67
68 void validChanged();60 void validChanged();
69 void titleChanged();61 void titleChanged();
70 void leftLabelChanged();62 void leftLabelChanged();
@@ -73,17 +65,9 @@
73 void accessibleNameChanged();65 void accessibleNameChanged();
74 void indicatorVisibleChanged();66 void indicatorVisibleChanged();
7567
76private Q_SLOTS:68protected:
77 void onModelRowsAdded(const QModelIndex& parent, int start, int end);69 RootStateParser m_parser;
78 void onModelRowsRemoved(const QModelIndex& parent, int start, int end);70 QVariantMap m_currentState;
79 void onModelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>&);
80 void reset();
81
82private:
83 void updateActionState();
84
85 UnityMenuModel* m_menu;
86 QVariantMap m_cachedState;
87};71};
8872
89#endif // ROOTACTIONSTATE_H73#endif // ROOTSTATEPARSER_H
9074
=== modified file 'qml/Greeter/Clock.qml'
--- qml/Greeter/Clock.qml 2014-10-07 10:28:59 +0000
+++ qml/Greeter/Clock.qml 2015-01-19 17:39:20 +0000
@@ -43,7 +43,7 @@
43 menuObjectPath: clock.visible ? "/com/canonical/indicator/datetime/phone" : ""43 menuObjectPath: clock.visible ? "/com/canonical/indicator/datetime/phone" : ""
44 }44 }
4545
46 Indicators.RootActionState {46 Indicators.ModelActionRootState {
47 menu: timeModel.model47 menu: timeModel.model
48 onUpdated: {48 onUpdated: {
49 if (timeLabel.text != rightLabel) {49 if (timeLabel.text != rightLabel) {
5050
=== modified file 'qml/Panel/IndicatorItem.qml'
--- qml/Panel/IndicatorItem.qml 2014-10-17 14:55:35 +0000
+++ qml/Panel/IndicatorItem.qml 2015-01-19 17:39:20 +0000
@@ -45,14 +45,6 @@
45 onClicked: parent.clicked()45 onClicked: parent.clicked()
46 }46 }
4747
48 // FIXME: For now we will enable led indicator support only for messaging indicator
49 // in the future we should export a led API insted of doing that,
50 Loader {
51 id: indicatorLed
52 // only load source Component if the icons contains the new message icon
53 source: (root.icons && (String(root.icons).indexOf("indicator-messages-new") != -1)) ? Qt.resolvedUrl("Indicators/IndicatorsLight.qml") : ""
54 }
55
56 Item {48 Item {
57 id: mainItems49 id: mainItems
58 anchors.centerIn: parent50 anchors.centerIn: parent
5951
=== modified file 'qml/Panel/Indicators/IndicatorBase.qml'
--- qml/Panel/Indicators/IndicatorBase.qml 2014-10-17 14:55:35 +0000
+++ qml/Panel/Indicators/IndicatorBase.qml 2015-01-19 17:39:20 +0000
@@ -40,7 +40,7 @@
40 menuObjectPath: indicatorItem.menuObjectPath40 menuObjectPath: indicatorItem.menuObjectPath
41 }41 }
4242
43 RootActionState {43 ModelActionRootState {
44 id: rootAction44 id: rootAction
45 menu: menuModel ? menuModel : null45 menu: menuModel ? menuModel : null
46 onUpdated: indicatorItem.rootActionStateChanged()46 onUpdated: indicatorItem.rootActionStateChanged()
4747
=== modified file 'qml/Panel/Indicators/IndicatorsLight.qml'
--- qml/Panel/Indicators/IndicatorsLight.qml 2014-08-05 14:31:12 +0000
+++ qml/Panel/Indicators/IndicatorsLight.qml 2015-01-19 17:39:20 +0000
@@ -20,16 +20,34 @@
20import QtQuick 2.020import QtQuick 2.0
21import Powerd 0.121import Powerd 0.1
22import Lights 0.122import Lights 0.1
23import QMenuModel 0.1 as QMenuModel
24import Unity.Indicators 0.1 as Indicators
2325
24QtObject {26QtObject {
25 id: root27 id: root
2628
29 property var _actionGroup: QMenuModel.QDBusActionGroup {
30 busType: 1
31 busName: "com.canonical.indicator.messages"
32 objectPath: "/com/canonical/indicator/messages"
33 }
34
35 property var _rootState: Indicators.ActionRootState {
36 actionGroup: _actionGroup
37 actionName: "messages"
38 Component.onCompleted: actionGroup.start()
39
40 property bool hasMessages: valid && (String(icons).indexOf("indicator-messages-new") != -1)
41 }
42
27 Component.onDestruction: Lights.state = Lights.Off43 Component.onDestruction: Lights.state = Lights.Off
2844
29 // QtObject does not have children45 // QtObject does not have children
30 property var _binding: Binding {46 property var _binding: Binding {
31 target: Lights47 target: Lights
32 property: "state"48 property: "state"
33 value: (Powerd.status === Powerd.Off) ? Lights.On : Lights.Off49 value: {
50 return (Powerd.status === Powerd.Off && _rootState.hasMessages) ? Lights.On : Lights.Off
51 }
34 }52 }
35}53}
3654
=== modified file 'qml/Panel/IndicatorsBar.qml'
--- qml/Panel/IndicatorsBar.qml 2014-10-20 20:35:50 +0000
+++ qml/Panel/IndicatorsBar.qml 2015-01-19 17:39:20 +0000
@@ -46,13 +46,14 @@
4646
47 function addScrollOffset(scrollAmmout) {47 function addScrollOffset(scrollAmmout) {
48 if (scrollAmmout < 0) { // left scroll48 if (scrollAmmout < 0) { // left scroll
49 if (flickable.contentX < 0) return; // already off the left.49 if (flickable.contentX + flickable.width > row.width) return; // already off the left.
50 if (flickable.contentX + scrollAmmout < 0) scrollAmmout = -flickable.contentX; // going to be off the left50
51 if (flickable.contentX + flickable.width - scrollAmmout > row.width) { // going to be off the right
52 scrollAmmout = (flickable.contentX + flickable.width) - row.width;
53 }
51 } else { // right scroll54 } else { // right scroll
52 if (flickable.contentX + flickable.width > row.width) return; // already off the right.55 if (flickable.contentX < 0) return; // already off the right.
53 if (flickable.contentX + flickable.width + scrollAmmout > row.width) { // going to be off the right56 if (flickable.contentX - scrollAmmout < 0) scrollAmmout = flickable.contentX; // going to be off the right
54 scrollAmmout = row.width - (flickable.contentX + flickable.width);
55 }
56 }57 }
57 d.scrollOffset = d.scrollOffset + scrollAmmout;58 d.scrollOffset = d.scrollOffset + scrollAmmout;
58 }59 }
@@ -91,24 +92,26 @@
91 flickable.resetContentXComponents();92 flickable.resetContentXComponents();
9293
93 if (expanded && !flickable.moving) {94 if (expanded && !flickable.moving) {
94
95 // gap between left and row?95 // gap between left and row?
96 if (flickable.contentX < 0) {96 if (flickable.contentX + flickable.width > row.width) {
97 d.alignmentAdjustment += flickable.contentX;
98 // gap between right and row?
99 } else if (flickable.contentX + flickable.width > row.width) {
100 // row width is less than flickable97 // row width is less than flickable
101 if (row.width < flickable.width) {98 if (row.width < flickable.width) {
102 d.alignmentAdjustment += flickable.contentX;99 d.alignmentAdjustment -= flickable.contentX;
103 } else {100 } else {
104 d.alignmentAdjustment += ((flickable.contentX + flickable.width) - row.width);101 d.alignmentAdjustment -= ((flickable.contentX + flickable.width) - row.width);
105 }102 }
103
104 // gap between right and row?
105 } else if (flickable.contentX < 0) {
106 d.alignmentAdjustment -= flickable.contentX;
107
106 // current item overlap on left108 // current item overlap on left
107 } else if (row.currentItem && row.currentItem.x < flickable.contentX) {109 } else if (row.currentItem && (flickable.contentX + flickable.width) < (row.width - row.currentItem.x)) {
108 d.alignmentAdjustment -= (row.currentItem.x - flickable.contentX);110 d.alignmentAdjustment += ((row.width - row.currentItem.x) - (flickable.contentX + flickable.width));
111
109 // current item overlap on right112 // current item overlap on right
110 } else if (row.currentItem && row.currentItem.x + row.currentItem.width > flickable.contentX + flickable.width) {113 } else if (row.currentItem && flickable.contentX > (row.width - row.currentItem.x - row.currentItem.width)) {
111 d.alignmentAdjustment -= ((row.currentItem.x + row.currentItem.width) - (flickable.contentX + flickable.width));114 d.alignmentAdjustment -= flickable.contentX - (row.width - row.currentItem.x - row.currentItem.width);
112 }115 }
113 }116 }
114 }117 }
@@ -134,16 +137,19 @@
134 id: flickable137 id: flickable
135 objectName: "flickable"138 objectName: "flickable"
136139
140 // we rotate it because we want the Flickable to align its content item
141 // on the right instead of on the left
142 rotation: 180
143
137 anchors.fill: parent144 anchors.fill: parent
138 contentWidth: row.width145 contentWidth: row.width
146 contentX: d.combinedOffset
139 interactive: false147 interactive: false
140 // align right + offset from row selection + scrolling
141 contentX: row.width - flickable.width - d.combinedOffset
142148
143 // contentX can change by user interaction as well as user offset changes149 // contentX can change by user interaction as well as user offset changes
144 // This function re-aligns the offsets so that the offsets match the contentX150 // This function re-aligns the offsets so that the offsets match the contentX
145 function resetContentXComponents() {151 function resetContentXComponents() {
146 d.scrollOffset += (flickable.contentX - (row.width - flickable.width - d.combinedOffset));152 d.scrollOffset += d.combinedOffset - flickable.contentX;
147 }153 }
148154
149 rebound: Transition {155 rebound: Transition {
@@ -162,6 +168,9 @@
162 bottom: parent.bottom168 bottom: parent.bottom
163 }169 }
164170
171 // Compensate for the Flickable rotation (ie, counter-rotate)
172 rotation: 180
173
165 lateralPosition: {174 lateralPosition: {
166 if (root.lateralPosition == -1) return -1;175 if (root.lateralPosition == -1) return -1;
167176
168177
=== modified file 'qml/Panel/IndicatorsMenu.qml'
--- qml/Panel/IndicatorsMenu.qml 2014-10-21 19:32:03 +0000
+++ qml/Panel/IndicatorsMenu.qml 2015-01-19 17:39:20 +0000
@@ -18,6 +18,7 @@
18import Ubuntu.Components 1.118import Ubuntu.Components 1.1
19import Ubuntu.Gestures 0.119import Ubuntu.Gestures 0.1
20import "../Components"20import "../Components"
21import "Indicators"
2122
22Showable {23Showable {
23 id: root24 id: root
@@ -60,6 +61,10 @@
60 onUnitProgressChanged: d.updateState()61 onUnitProgressChanged: d.updateState()
61 clip: root.partiallyOpened62 clip: root.partiallyOpened
6263
64 IndicatorsLight {
65 id: indicatorLights
66 }
67
63 // eater68 // eater
64 MouseArea {69 MouseArea {
65 anchors.fill: parent70 anchors.fill: parent
6671
=== modified file 'tests/mocks/CMakeLists.txt'
--- tests/mocks/CMakeLists.txt 2014-06-11 15:36:51 +0000
+++ tests/mocks/CMakeLists.txt 2015-01-19 17:39:20 +0000
@@ -33,6 +33,7 @@
33add_subdirectory(HudClient)33add_subdirectory(HudClient)
34add_subdirectory(libusermetrics)34add_subdirectory(libusermetrics)
35add_subdirectory(LightDM)35add_subdirectory(LightDM)
36add_subdirectory(Lights)
36add_subdirectory(Powerd)37add_subdirectory(Powerd)
37add_subdirectory(QMenuModel)38add_subdirectory(QMenuModel)
38add_subdirectory(Ubuntu)39add_subdirectory(Ubuntu)
3940
=== added directory 'tests/mocks/Lights'
=== added file 'tests/mocks/Lights/CMakeLists.txt'
--- tests/mocks/Lights/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/mocks/Lights/CMakeLists.txt 2015-01-19 17:39:20 +0000
@@ -0,0 +1,8 @@
1add_library(MockLights-qml MODULE
2 plugin.cpp
3 Lights.cpp
4 )
5
6qt5_use_modules(MockLights-qml Qml Gui)
7
8add_unity8_mock(Lights 0.1 Lights TARGETS MockLights-qml)
09
=== added file 'tests/mocks/Lights/Lights.cpp'
--- tests/mocks/Lights/Lights.cpp 1970-01-01 00:00:00 +0000
+++ tests/mocks/Lights/Lights.cpp 2015-01-19 17:39:20 +0000
@@ -0,0 +1,84 @@
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU 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 General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "Lights.h"
18
19#include <QDebug>
20
21Lights::Lights(QObject* parent)
22 : QObject(parent),
23 m_color("blue"),
24 m_state(Lights::Off),
25 m_onMs(1000),
26 m_offMs(3000)
27{
28}
29
30Lights::~Lights()
31{
32}
33
34void Lights::setState(Lights::State newState)
35{
36 if (m_state != newState) {
37 m_state = newState;
38 Q_EMIT stateChanged(m_state);
39 }
40}
41
42Lights::State Lights::state() const
43{
44 return m_state;
45}
46
47void Lights::setColor(const QColor &color)
48{
49 if (m_color != color) {
50 m_color = color;
51 Q_EMIT colorChanged(m_color);
52 }
53}
54
55QColor Lights::color() const
56{
57 return m_color;
58}
59
60int Lights::onMillisec() const
61{
62 return m_onMs;
63}
64
65void Lights::setOnMillisec(int onMs)
66{
67 if (m_onMs != onMs) {
68 m_onMs = onMs;
69 Q_EMIT onMillisecChanged(m_onMs);
70 }
71}
72
73int Lights::offMillisec() const
74{
75 return m_offMs;
76}
77
78void Lights::setOffMillisec(int offMs)
79{
80 if (m_offMs != offMs) {
81 m_offMs = offMs;
82 Q_EMIT offMillisecChanged(m_offMs);
83 }
84}
085
=== added file 'tests/mocks/Lights/Lights.h'
--- tests/mocks/Lights/Lights.h 1970-01-01 00:00:00 +0000
+++ tests/mocks/Lights/Lights.h 2015-01-19 17:39:20 +0000
@@ -0,0 +1,66 @@
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU 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 General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef UNITY_MOCK_LIGHTS_H
18#define UNITY_MOCK_LIGHTS_H
19
20#include <QtCore/QObject>
21#include <QtGui/QColor>
22
23class Lights: public QObject
24{
25 Q_OBJECT
26 Q_ENUMS(State)
27 Q_PROPERTY(State state READ state WRITE setState NOTIFY stateChanged)
28 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
29 Q_PROPERTY(int onMillisec READ onMillisec WRITE setOnMillisec NOTIFY onMillisecChanged)
30 Q_PROPERTY(int offMillisec READ offMillisec WRITE setOffMillisec NOTIFY offMillisecChanged)
31
32public:
33 enum State {
34 Off,
35 On,
36 };
37
38 explicit Lights(QObject *parent = 0);
39 ~Lights();
40
41 void setState(State newState);
42 State state() const;
43
44 void setColor(const QColor &color);
45 QColor color() const;
46
47 int onMillisec() const;
48 void setOnMillisec(int onMs);
49
50 int offMillisec() const;
51 void setOffMillisec(int offMs);
52
53Q_SIGNALS:
54 void stateChanged(State newState);
55 void colorChanged(const QColor &color);
56 void onMillisecChanged(int onMs);
57 void offMillisecChanged(int offMs);
58
59private:
60 QColor m_color;
61 State m_state;
62 int m_onMs;
63 int m_offMs;
64};
65
66#endif
067
=== added file 'tests/mocks/Lights/plugin.cpp'
--- tests/mocks/Lights/plugin.cpp 1970-01-01 00:00:00 +0000
+++ tests/mocks/Lights/plugin.cpp 2015-01-19 17:39:20 +0000
@@ -0,0 +1,33 @@
1/*
2 * Copyright (C) 2012,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 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 General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "plugin.h"
18#include "Lights.h"
19
20#include <QtQml/qqml.h>
21
22static QObject *lights_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
23{
24 Q_UNUSED(engine)
25 Q_UNUSED(scriptEngine)
26 return new Lights();
27}
28
29void PowerdPlugin::registerTypes(const char *uri)
30{
31 Q_ASSERT(uri == QLatin1String("Lights"));
32 qmlRegisterSingletonType<Lights>(uri, 0, 1, "Lights", lights_provider);
33}
034
=== added file 'tests/mocks/Lights/plugin.h'
--- tests/mocks/Lights/plugin.h 1970-01-01 00:00:00 +0000
+++ tests/mocks/Lights/plugin.h 2015-01-19 17:39:20 +0000
@@ -0,0 +1,32 @@
1/*
2 * Copyright (C) 2012,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 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 General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef MOCK_POWER_PLUGIN_H
18#define MOCK_POWER_PLUGIN_H
19
20#include <QtQml/QQmlEngine>
21#include <QtQml/QQmlExtensionPlugin>
22
23class PowerdPlugin : public QQmlExtensionPlugin
24{
25 Q_OBJECT
26 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
27
28public:
29 void registerTypes(const char *uri);
30};
31
32#endif
033
=== added file 'tests/mocks/Lights/qmldir'
--- tests/mocks/Lights/qmldir 1970-01-01 00:00:00 +0000
+++ tests/mocks/Lights/qmldir 2015-01-19 17:39:20 +0000
@@ -0,0 +1,3 @@
1module Lights
2plugin MockLights-qml
3typeinfo Lights.qmltypes
04
=== modified file 'tests/mocks/QMenuModel/CMakeLists.txt'
--- tests/mocks/QMenuModel/CMakeLists.txt 2014-05-02 22:57:21 +0000
+++ tests/mocks/QMenuModel/CMakeLists.txt 2015-01-19 17:39:20 +0000
@@ -4,6 +4,7 @@
4)4)
55
6set(QMenuModelQml_SOURCES6set(QMenuModelQml_SOURCES
7 actiondata.h
7 actionstateparser.cpp8 actionstateparser.cpp
8 plugin.cpp9 plugin.cpp
9 unitymenumodel.cpp10 unitymenumodel.cpp
1011
=== modified file 'tests/mocks/QMenuModel/QDBusActionGroup.qml'
--- tests/mocks/QMenuModel/QDBusActionGroup.qml 2014-07-04 17:53:52 +0000
+++ tests/mocks/QMenuModel/QDBusActionGroup.qml 2015-01-19 17:39:20 +0000
@@ -19,69 +19,19 @@
1919
20import QtQuick 2.020import QtQuick 2.0
21import Ubuntu.Settings.Menus 0.1 as Menus21import Ubuntu.Settings.Menus 0.1 as Menus
22import QMenuModel 0.1
2223
23QtObject {24QtObject {
24 property int busType25 property int busType
25 property string busName26 property string busName
26 property string objectPath27 property string objectPath
28 property var actions: ActionData ? ActionData.data : undefined
29
30 signal dataChanged
31
27 function start() {}32 function start() {}
33
28 function action(actionName) {34 function action(actionName) {
29 switch (actionName) {35 return actions[actionName];
30 case "transfer-state.queued":
31 return {
32 'valid': true,
33 'state': {
34 'state': Menus.TransferState.Queued,
35 'percent': 0.0
36 }
37 }
38 case "transfer-state.running":
39 return {
40 'valid': true,
41 'state': {
42 'state': Menus.TransferState.Running,
43 'seconds-left': 100,
44 'percent': 0.1
45 }
46 }
47 case "transfer-state.paused":
48 return {
49 'valid': true,
50 'state': {
51 'state': Menus.TransferState.Paused,
52 'seconds-left': 100,
53 'percent': 0.5
54 }
55 }
56 case "transfer-state.cancelled":
57 return {
58 'valid': true,
59 'state': {
60 'state': Menus.TransferState.Canceled,
61 'percent': 0.4
62 }
63 }
64 case "transfer-state.finished": return {
65 'valid': true,
66 'state': {
67 'state': Menus.TransferState.Finished,
68 'seconds-left': 0,
69 'percent': 1.0
70 }
71 }
72 case "transfer-state.error":
73 return {
74 'valid': true,
75 'state': {
76 'state': Menus.TransferState.Error,
77 'seconds-left': 100,
78 'percent': 0.0
79 }
80 }
81 default:
82 break;
83 }
84
85 return null;
86 }36 }
87}37}
8838
=== added file 'tests/mocks/QMenuModel/actiondata.h'
--- tests/mocks/QMenuModel/actiondata.h 1970-01-01 00:00:00 +0000
+++ tests/mocks/QMenuModel/actiondata.h 2015-01-19 17:39:20 +0000
@@ -0,0 +1,52 @@
1/*
2 * Copyright (C) 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 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 General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Nick Dedekind <nick.dedekind@canonical.com>
17 */
18
19#ifndef ACTIONDATA_H
20#define ACTIONDATA_H
21
22#include <QObject>
23#include <QVariant>
24
25typedef struct _GVariant GVariant;
26
27class Q_DECL_EXPORT ActionData : public QObject
28{
29 Q_OBJECT
30 Q_PROPERTY(QVariant data READ data WRITE setData NOTIFY dataChanged)
31public:
32 ActionData(QObject* parent = 0)
33 : QObject(parent)
34 {}
35
36 QVariant data() const { return m_data; }
37 void setData(const QVariant& data)
38 {
39 if (m_data != data) {
40 m_data = data;
41 Q_EMIT dataChanged();
42 }
43 }
44
45Q_SIGNALS:
46 void dataChanged();
47
48private:
49 QVariant m_data;
50};
51
52#endif // ACTIONDATA_H
053
=== modified file 'tests/mocks/QMenuModel/plugin.cpp'
--- tests/mocks/QMenuModel/plugin.cpp 2013-11-19 17:01:25 +0000
+++ tests/mocks/QMenuModel/plugin.cpp 2015-01-19 17:39:20 +0000
@@ -18,13 +18,23 @@
1818
19#include "plugin.h"19#include "plugin.h"
20#include "unitymenumodel.h"20#include "unitymenumodel.h"
21#include "actiondata.h"
21#include "actionstateparser.h"22#include "actionstateparser.h"
2223
23#include <QtQml/qqml.h>24#include <QtQml/qqml.h>
2425
26static QObject* actionDataSingleton(QQmlEngine* engine, QJSEngine* scriptEngine)
27{
28 Q_UNUSED(engine);
29 Q_UNUSED(scriptEngine);
30 return new ActionData;
31}
32
25void QMenuModelPlugin::registerTypes(const char *uri)33void QMenuModelPlugin::registerTypes(const char *uri)
26{34{
27 Q_ASSERT(uri == QLatin1String("QMenuModel"));35 Q_ASSERT(uri == QLatin1String("QMenuModel"));
28 qmlRegisterType<UnityMenuModel>(uri, 0, 1, "UnityMenuModel");36 qmlRegisterType<UnityMenuModel>(uri, 0, 1, "UnityMenuModel");
29 qmlRegisterType<ActionStateParser>(uri, 0, 1, "ActionStateParser");37 qmlRegisterType<ActionStateParser>(uri, 0, 1, "ActionStateParser");
38
39 qmlRegisterSingletonType<ActionData>(uri, 0, 1, "ActionData", actionDataSingleton);
30}40}
3141
=== added file 'tests/mocks/Unity/Indicators/ActionRootState.qml'
--- tests/mocks/Unity/Indicators/ActionRootState.qml 1970-01-01 00:00:00 +0000
+++ tests/mocks/Unity/Indicators/ActionRootState.qml 2015-01-19 17:39:20 +0000
@@ -0,0 +1,46 @@
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 * Nick Dedekind <nick.dedekind@canonical.com>
18 */
19
20import QtQuick 2.0
21
22QtObject {
23 property var actionGroup
24 property var actionName
25
26 property var action: actionGroup ? actionGroup.actions[actionName] : undefined
27 property var state: action && action.hasOwnProperty("state") ? action.state : undefined
28
29 property bool valid: action && action.hasOwnProperty("valid") ? action.valid : false
30 property string title: state && state.hasOwnProperty("title") ? state["title"] : ""
31 property string leftLabel: state && state.hasOwnProperty("pre-label") ? state["pre-label"] : ""
32 property string rightLabel: state && state.hasOwnProperty("label") ? state["label"] : ""
33 property var icons: state && state.hasOwnProperty("icons") ? state["icons"] : []
34 property string accessibleName: state && state.hasOwnProperty("accessible-desc") ? state["accessible-desc"] : ""
35 property bool visible: state && state.hasOwnProperty("visible") ? state["visible"] : true
36
37 signal updated
38
39 onValidChanged: updated()
40 onTitleChanged: updated()
41 onLeftLabelChanged: updated()
42 onRightLabelChanged: updated()
43 onIconsChanged: updated()
44 onAccessibleNameChanged: updated()
45 onVisibleChanged: updated()
46}
047
=== renamed file 'tests/mocks/Unity/Indicators/RootActionState.qml' => 'tests/mocks/Unity/Indicators/ModelActionRootState.qml'
=== modified file 'tests/mocks/Unity/Indicators/qmldir'
--- tests/mocks/Unity/Indicators/qmldir 2014-10-07 10:28:59 +0000
+++ tests/mocks/Unity/Indicators/qmldir 2015-01-19 17:39:20 +0000
@@ -2,5 +2,6 @@
2plugin IndicatorsFakeQml2plugin IndicatorsFakeQml
3typeinfo Indicators.qmltypes3typeinfo Indicators.qmltypes
44
5ActionRootState 0.1 ActionRootState.qml
5IndicatorsModel 0.1 IndicatorsModel.qml6IndicatorsModel 0.1 IndicatorsModel.qml
6RootActionState 0.1 RootActionState.qml7ModelActionRootState 0.1 ModelActionRootState.qml
78
=== modified file 'tests/plugins/Unity/Indicators/rootactionstatetest.cpp'
--- tests/plugins/Unity/Indicators/rootactionstatetest.cpp 2014-08-26 08:14:44 +0000
+++ tests/plugins/Unity/Indicators/rootactionstatetest.cpp 2015-01-19 17:39:20 +0000
@@ -17,7 +17,7 @@
17 * Nick Dedekind <nick.dedekind@canonical.com>17 * Nick Dedekind <nick.dedekind@canonical.com>
18 */18 */
1919
20#include "rootactionstate.h"20#include "modelactionrootstate.h"
2121
22#include <unitymenumodel.h>22#include <unitymenumodel.h>
23#include <QtTest>23#include <QtTest>
@@ -32,7 +32,7 @@
32 {32 {
33 UnityMenuModel* menuModel = new UnityMenuModel();33 UnityMenuModel* menuModel = new UnityMenuModel();
34 ActionStateParser* originalParser = menuModel->actionStateParser();34 ActionStateParser* originalParser = menuModel->actionStateParser();
35 RootActionState* rootState = new RootActionState();35 ModelActionRootState* rootState = new ModelActionRootState();
3636
37 rootState->setMenu(menuModel);37 rootState->setMenu(menuModel);
3838
@@ -44,7 +44,7 @@
44 void testDeleteUnityMenuModel()44 void testDeleteUnityMenuModel()
45 {45 {
46 UnityMenuModel* menuModel = new UnityMenuModel();46 UnityMenuModel* menuModel = new UnityMenuModel();
47 RootActionState* rootState = new RootActionState();47 ModelActionRootState* rootState = new ModelActionRootState();
4848
49 rootState->setMenu(menuModel);49 rootState->setMenu(menuModel);
5050
@@ -77,7 +77,7 @@
7777
78 GVariant* params = g_variant_builder_end (&builderParams);78 GVariant* params = g_variant_builder_end (&builderParams);
7979
80 RootActionState rootState;80 RootStateParser rootState;
81 QVariant result = rootState.toQVariant(params);81 QVariant result = rootState.toQVariant(params);
82 g_variant_unref(params);82 g_variant_unref(params);
8383
8484
=== modified file 'tests/qmltests/CMakeLists.txt'
--- tests/qmltests/CMakeLists.txt 2014-11-10 09:14:30 +0000
+++ tests/qmltests/CMakeLists.txt 2015-01-19 17:39:20 +0000
@@ -81,6 +81,7 @@
81add_qml_test(Panel MenuContent ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")81add_qml_test(Panel MenuContent ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
82add_qml_test(Panel Panel ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")82add_qml_test(Panel Panel ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
83add_qml_test(Panel SearchIndicator)83add_qml_test(Panel SearchIndicator)
84add_qml_test(Panel/Indicators IndicatorsLight ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
84# These MenuItemFactory tests need the test/mocks/ to come before plugins/85# These MenuItemFactory tests need the test/mocks/ to come before plugins/
85add_qml_test(Panel/Indicators MenuItemFactory IMPORT_PATHS ${CMAKE_BINARY_DIR}/tests/mocks ${qmltest_DEFAULT_IMPORT_PATHS})86add_qml_test(Panel/Indicators MenuItemFactory IMPORT_PATHS ${CMAKE_BINARY_DIR}/tests/mocks ${qmltest_DEFAULT_IMPORT_PATHS})
86add_qml_test(Panel/Indicators MessageMenuItemFactory IMPORT_PATHS ${CMAKE_BINARY_DIR}/tests/mocks ${qmltest_DEFAULT_IMPORT_PATHS})87add_qml_test(Panel/Indicators MessageMenuItemFactory IMPORT_PATHS ${CMAKE_BINARY_DIR}/tests/mocks ${qmltest_DEFAULT_IMPORT_PATHS})
8788
=== added file 'tests/qmltests/Panel/Indicators/tst_IndicatorsLight.qml'
--- tests/qmltests/Panel/Indicators/tst_IndicatorsLight.qml 1970-01-01 00:00:00 +0000
+++ tests/qmltests/Panel/Indicators/tst_IndicatorsLight.qml 2015-01-19 17:39:20 +0000
@@ -0,0 +1,129 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU 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 General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17import QtQuick 2.0
18import QtQuick.Layouts 1.1
19import Unity.Test 0.1 as UT
20import Unity.Indicators 0.1 as Indicators
21import Ubuntu.Components 1.1
22import Powerd 0.1
23import Lights 0.1
24import QMenuModel 0.1
25import "../../../../qml/Panel/Indicators"
26
27Item {
28 id: root
29 width: units.gu(30)
30 height: units.gu(30)
31
32 property var newMessage: {
33 "messages" : {
34 'valid': true,
35 'state': {
36 'icons': [ 'indicator-messages-new' ]
37 }
38 }
39 };
40 property var noNewMessage: {
41 "messages" : {
42 'valid': true,
43 'state': {
44 'icons': [ 'indicator-messages' ]
45 }
46 }
47 };
48
49 Component {
50 id: light
51 IndicatorsLight {}
52 }
53
54 Loader {
55 id: loader
56 sourceComponent: light
57 }
58
59 Component.onCompleted: {
60 ActionData.data = newMessage;
61 Powerd.status = Powerd.On
62 }
63
64 RowLayout {
65 anchors.fill: parent
66 anchors.margins: units.gu(1)
67
68 Item {
69 Layout.fillWidth: true
70 Layout.fillHeight: true
71
72 Rectangle {
73 width: units.gu(4)
74 height: width
75 radius: width / 2
76 anchors.centerIn: parent
77
78 color: Lights.state === Lights.On ? Lights.color : "transparent"
79
80 border.color: "black"
81 border.width: 1
82 }
83 }
84
85 ColumnLayout {
86 Layout.alignment: Qt.AlignTop
87 Layout.fillWidth: false
88 Layout.preferredWidth: units.gu(15)
89
90 Button {
91 Layout.fillWidth: true
92 text: Powerd.status === Powerd.On ? "Power Off" : "Power On"
93 onClicked: {
94 if (Powerd.status === Powerd.On) Powerd.status = Powerd.Off;
95 else Powerd.status = Powerd.On;
96 }
97 }
98 }
99 }
100
101 UT.UnityTestCase {
102 name: "IndicatorsLight"
103 when: windowShown
104
105 function init() {
106 // reload
107 ActionData.data = noNewMessage;
108 loader.sourceComponent = undefined;
109 loader.sourceComponent = light;
110 Powerd.status = Powerd.On
111 }
112
113 function test_LightsStatus_data() {
114 return [
115 { tag: "Powerd.On with No Message", powerd: Powerd.On, actionData: noNewMessage, expected: Lights.Off },
116 { tag: "Powerd.Off with No Message", powerd: Powerd.Off, actionData: noNewMessage, expected: Lights.Off },
117 { tag: "Powerd.On with New Message", powerd: Powerd.On, actionData: newMessage, expected: Lights.Off },
118 { tag: "Powerd.Off with New Message", powerd: Powerd.Off, actionData: newMessage, expected: Lights.On },
119 ]
120 }
121
122 function test_LightsStatus(data) {
123 Powerd.status = data.powerd;
124 ActionData.data = data.actionData;
125
126 compare(Lights.state, data.expected, "Light does not match expected value");
127 }
128 }
129}
0130
=== modified file 'tests/qmltests/Panel/Indicators/tst_MenuItemFactory.qml'
--- tests/qmltests/Panel/Indicators/tst_MenuItemFactory.qml 2014-11-05 00:20:05 +0000
+++ tests/qmltests/Panel/Indicators/tst_MenuItemFactory.qml 2015-01-19 17:39:20 +0000
@@ -17,6 +17,7 @@
17import QtQuick 2.017import QtQuick 2.0
18import QtTest 1.018import QtTest 1.0
19import Unity.Test 0.1 as UT19import Unity.Test 0.1 as UT
20import Ubuntu.Settings.Menus 0.1 as Menus
20import QMenuModel 0.121import QMenuModel 0.1
21import Utils 0.1 as Utils22import Utils 0.1 as Utils
22import "../../../../qml/Panel/Indicators"23import "../../../../qml/Panel/Indicators"
@@ -448,6 +449,55 @@
448 }449 }
449450
450 function test_create_transferMenu(data) {451 function test_create_transferMenu(data) {
452 ActionData.data = {
453 "transfer-state.queued": {
454 'valid': true,
455 'state': {
456 'state': Menus.TransferState.Queued,
457 'percent': 0.0
458 }
459 },
460 "transfer-state.running": {
461 'valid': true,
462 'state': {
463 'state': Menus.TransferState.Running,
464 'seconds-left': 100,
465 'percent': 0.1
466 }
467 },
468 "transfer-state.paused": {
469 'valid': true,
470 'state': {
471 'state': Menus.TransferState.Paused,
472 'seconds-left': 100,
473 'percent': 0.5
474 }
475 },
476 "transfer-state.cancelled": {
477 'valid': true,
478 'state': {
479 'state': Menus.TransferState.Canceled,
480 'percent': 0.4
481 }
482 },
483 "transfer-state.finished": {
484 'valid': true,
485 'state': {
486 'state': Menus.TransferState.Finished,
487 'seconds-left': 0,
488 'percent': 1.0
489 }
490 },
491 "transfer-state.error": {
492 'valid': true,
493 'state': {
494 'state': Menus.TransferState.Error,
495 'seconds-left': 100,
496 'percent': 0.0
497 }
498 }
499 };
500
451 menuData.type = "com.canonical.indicator.transfer";501 menuData.type = "com.canonical.indicator.transfer";
452 menuData.label = data.label;502 menuData.label = data.label;
453 menuData.sensitive = data.enabled;503 menuData.sensitive = data.enabled;

Subscribers

People subscribed via source and target branches

to all changes: