on xenial help sign in
Indicate charging state only if device supports multi color led (#287)
db503eeWillem-Jan de Hoog
plugins/Utils/deviceconfigparser.cpp+18
@@ -116,6 +116,24 @@ QString DeviceConfigParser::category() const
116 return value;
116 return value;
117}
117}
118
118
119+bool DeviceConfigParser::supportsMultiColorLed() const
120+{
121+ return readBoolFromConfig("SupportsMultiColorLed", true);
122+}
123+
124+bool DeviceConfigParser::readBoolFromConfig(const QString &key, bool defaultValue) const
125+{
126+ m_config->beginGroup(m_name);
127+
128+ bool ret = defaultValue;
129+ if (m_config->contains(key)) {
130+ ret = m_config->value(key).toBool();
131+ }
132+
133+ m_config->endGroup();
134+ return ret;
135+}
136+
119QStringList DeviceConfigParser::readOrientationsFromConfig(const QString &key) const
137QStringList DeviceConfigParser::readOrientationsFromConfig(const QString &key) const
120{
138{
121 m_config->beginGroup(m_name);
139 m_config->beginGroup(m_name);
plugins/Utils/deviceconfigparser.h+3
@@ -33,6 +33,7 @@ class DeviceConfigParser: public QObject
33 Q_PROPERTY(Qt::ScreenOrientation portraitOrientation READ portraitOrientation NOTIFY changed)
33 Q_PROPERTY(Qt::ScreenOrientation portraitOrientation READ portraitOrientation NOTIFY changed)
34 Q_PROPERTY(Qt::ScreenOrientation invertedPortraitOrientation READ invertedPortraitOrientation NOTIFY changed)
34 Q_PROPERTY(Qt::ScreenOrientation invertedPortraitOrientation READ invertedPortraitOrientation NOTIFY changed)
35 Q_PROPERTY(QString category READ category NOTIFY changed)
35 Q_PROPERTY(QString category READ category NOTIFY changed)
36+ Q_PROPERTY(bool supportsMultiColorLed READ supportsMultiColorLed NOTIFY changed)
36
37
37public:
38public:
38 DeviceConfigParser(QObject *parent = nullptr);
39 DeviceConfigParser(QObject *parent = nullptr);
@@ -47,6 +48,7 @@ public:
47 Qt::ScreenOrientation portraitOrientation() const;
48 Qt::ScreenOrientation portraitOrientation() const;
48 Qt::ScreenOrientation invertedPortraitOrientation() const;
49 Qt::ScreenOrientation invertedPortraitOrientation() const;
49 QString category() const;
50 QString category() const;
51+ bool supportsMultiColorLed() const;
50
52
51Q_SIGNALS:
53Q_SIGNALS:
52 void changed();
54 void changed();
@@ -58,6 +60,7 @@ private:
58 QStringList readOrientationsFromConfig(const QString &key) const;
60 QStringList readOrientationsFromConfig(const QString &key) const;
59 QString readOrientationFromConfig(const QString &key) const;
61 QString readOrientationFromConfig(const QString &key) const;
60 Qt::ScreenOrientation stringToOrientation(const QString &orientationString, Qt::ScreenOrientation defaultValue) const;
62 Qt::ScreenOrientation stringToOrientation(const QString &orientationString, Qt::ScreenOrientation defaultValue) const;
63+ bool readBoolFromConfig(const QString &key, bool defaultValue) const;
61};
64};
62
65
63#endif
66#endif
qml/DeviceConfiguration.qml+11
@@ -35,6 +35,8 @@ QtObject {
35
35
36 readonly property alias category: priv.category
36 readonly property alias category: priv.category
37
37
38+ readonly property alias supportsMultiColorLed: priv.supportsMultiColorLed
39+
38 readonly property var deviceConfigParser: DeviceConfigParser {
40 readonly property var deviceConfigParser: DeviceConfigParser {
39 name: root.name
41 name: root.name
40 }
42 }
@@ -52,6 +54,7 @@ QtObject {
52 property int portraitOrientation: deviceConfigParser.portraitOrientation
54 property int portraitOrientation: deviceConfigParser.portraitOrientation
53 property int invertedPortraitOrientation: deviceConfigParser.invertedPortraitOrientation
55 property int invertedPortraitOrientation: deviceConfigParser.invertedPortraitOrientation
54 property string category: deviceConfigParser.category
56 property string category: deviceConfigParser.category
57+ property bool supportsMultiColorLed: deviceConfigParser.supportsMultiColorLed
55
58
56 states: [
59 states: [
57 State {
60 State {
@@ -96,6 +99,7 @@ QtObject {
96 invertedLandscapeOrientation: Qt.InvertedLandscapeOrientation
99 invertedLandscapeOrientation: Qt.InvertedLandscapeOrientation
97 portraitOrientation: Qt.PortraitOrientation
100 portraitOrientation: Qt.PortraitOrientation
98 invertedPortraitOrientation: Qt.InvertedPortraitOrientation
101 invertedPortraitOrientation: Qt.InvertedPortraitOrientation
102+ supportsMultiColorLed: false
99 category: "phone"
103 category: "phone"
100 }
104 }
101 },
105 },
@@ -143,6 +147,13 @@ QtObject {
143 invertedPortraitOrientation: Qt.InvertedPortraitOrientation
147 invertedPortraitOrientation: Qt.InvertedPortraitOrientation
144 category: "desktop"
148 category: "desktop"
145 }
149 }
150+ },
151+ State {
152+ name: "turbo"
153+ PropertyChanges {
154+ target: priv
155+ supportsMultiColorLed: false
156+ }
146 }
157 }
147 ]
158 ]
148 }
159 }
qml/OrientedShell.qml+1
@@ -275,6 +275,7 @@ Item {
275 hasMouse: pointerInputDevices > 0
275 hasMouse: pointerInputDevices > 0
276 hasKeyboard: keyboardsModel.count > 0
276 hasKeyboard: keyboardsModel.count > 0
277 hasTouchscreen: touchScreensModel.count > 0
277 hasTouchscreen: touchScreensModel.count > 0
278+ supportsMultiColorLed: deviceConfiguration.supportsMultiColorLed
278
279
279 // Since we dont have proper multiscreen support yet
280 // Since we dont have proper multiscreen support yet
280 // hardcode screen count to only show osk on this screen
281 // hardcode screen count to only show osk on this screen
qml/Panel/Indicators/IndicatorsLight.qml+24−3
@@ -25,9 +25,13 @@ import QMenuModel 0.1 as QMenuModel
25import Unity.Indicators 0.1 as Indicators
25import Unity.Indicators 0.1 as Indicators
26import Wizard 0.1
26import Wizard 0.1
27
27
28+import "../../.."
29+
28QtObject {
30QtObject {
29 id: root
31 id: root
30
32
33+ property bool supportsMultiColorLed: true
34+
31 property string indicatorState: "INDICATOR_OFF"
35 property string indicatorState: "INDICATOR_OFF"
32
36
33 property color color: "darkgreen"
37 property color color: "darkgreen"
@@ -41,6 +45,10 @@ QtObject {
41 property string batteryIconName: Status.batteryIcon
45 property string batteryIconName: Status.batteryIcon
42 property string displayStatus: Powerd.status
46 property string displayStatus: Powerd.status
43
47
48+ onSupportsMultiColorLedChanged: {
49+ updateLightState("onSupportsMultiColorLedChanged")
50+ }
51+
44 onDisplayStatusChanged: {
52 onDisplayStatusChanged: {
45 updateLightState("onDisplayStatusChanged")
53 updateLightState("onDisplayStatusChanged")
46 }
54 }
@@ -50,9 +58,14 @@ QtObject {
50 }
58 }
51
59
52 function updateLightState(msg) {
60 function updateLightState(msg) {
53− console.log("updateLightState: " + msg + ", hasMessages: " + hasMessages + ", icon: "
61+ console.log("updateLightState: " + msg
62+ + ", indicatorState: " + indicatorState
63+ + ", supportsMultiColorLed: " + supportsMultiColorLed
64+ + ", hasMessages: " + hasMessages
65+ + ", icon: " + batteryIconName
54− + batteryIconName + ", displayStatus: " + displayStatus + ", deviceState: "
66+ + ", displayStatus: " + displayStatus
67+ + ", deviceState: " + deviceState
55− + deviceState + ", batteryLevel: " + batteryLevel)
68+ + ", batteryLevel: " + batteryLevel)
56
69
57 //
70 //
58 // priorities:
71 // priorities:
@@ -99,6 +112,13 @@ QtObject {
99 return
112 return
100 }
113 }
101
114
115+ // if device does not support a multi color led set led off
116+ if(!supportsMultiColorLed) {
117+console.log("no support for Multicolor LED. " + indicatorState)
118+ indicatorState = "INDICATOR_OFF"
119+ return
120+ }
121+
102 var isCharging = batteryIconName.indexOf("charging") >= 0
122 var isCharging = batteryIconName.indexOf("charging") >= 0
103 || deviceState == "charging"
123 || deviceState == "charging"
104 || deviceState == "fully-charged"
124 || deviceState == "fully-charged"
@@ -193,6 +213,7 @@ QtObject {
193 }
213 }
194 }
214 }
195
215
216+ Component.onCompleted: Lights.state = Lights.Off
196 Component.onDestruction: Lights.state = Lights.Off
217 Component.onDestruction: Lights.state = Lights.Off
197
218
198 property var _colorBinding: Binding {
219 property var _colorBinding: Binding {
qml/Panel/Panel.qml+2
@@ -47,6 +47,7 @@ Item {
47 property real panelAreaShowProgress: 1.0
47 property real panelAreaShowProgress: 1.0
48 property bool greeterShown: false
48 property bool greeterShown: false
49 property bool hasKeyboard: false
49 property bool hasKeyboard: false
50+ property bool supportsMultiColorLed: true
50
51
51 // Whether our expanded menus should take up the full width of the panel
52 // Whether our expanded menus should take up the full width of the panel
52 property bool partialWidth: width >= units.gu(60)
53 property bool partialWidth: width >= units.gu(60)
@@ -472,6 +473,7 @@ Item {
472
473
473 IndicatorsLight {
474 IndicatorsLight {
474 id: indicatorLights
475 id: indicatorLights
476+ supportsMultiColorLed: root.supportsMultiColorLed
475 }
477 }
476
478
477 states: [
479 states: [
qml/Shell.qml+2
@@ -69,6 +69,7 @@ StyledItem {
69 property bool hasMouse: false
69 property bool hasMouse: false
70 property bool hasKeyboard: false
70 property bool hasKeyboard: false
71 property bool hasTouchscreen: false
71 property bool hasTouchscreen: false
72+ property bool supportsMultiColorLed: true
72
73
73 // to be read from outside
74 // to be read from outside
74 readonly property int mainAppWindowOrientationAngle: stage.mainAppWindowOrientationAngle
75 readonly property int mainAppWindowOrientationAngle: stage.mainAppWindowOrientationAngle
@@ -553,6 +554,7 @@ StyledItem {
553 || greeter.hasLockedApp
554 || greeter.hasLockedApp
554 greeterShown: greeter && greeter.shown
555 greeterShown: greeter && greeter.shown
555 hasKeyboard: shell.hasKeyboard
556 hasKeyboard: shell.hasKeyboard
557+ supportsMultiColorLed: shell.supportsMultiColorLed
556 }
558 }
557
559
558 Launcher {
560 Launcher {
tests/plugins/Utils/DeviceConfigParserTest.cpp+3
@@ -43,6 +43,7 @@ private Q_SLOTS:
43 QCOMPARE(p.invertedPortraitOrientation(), Qt::InvertedPortraitOrientation);
43 QCOMPARE(p.invertedPortraitOrientation(), Qt::InvertedPortraitOrientation);
44 QCOMPARE(p.landscapeOrientation(), Qt::LandscapeOrientation);
44 QCOMPARE(p.landscapeOrientation(), Qt::LandscapeOrientation);
45 QCOMPARE(p.invertedLandscapeOrientation(), Qt::InvertedLandscapeOrientation);
45 QCOMPARE(p.invertedLandscapeOrientation(), Qt::InvertedLandscapeOrientation);
46+ QCOMPARE(p.supportsMultiColorLed(), true);
46 }
47 }
47
48
48 void testCustomFile() {
49 void testCustomFile() {
@@ -52,6 +53,7 @@ private Q_SLOTS:
52
53
53 s.setValue("SupportedOrientations", QStringList() << "Portrait" << "Landscape" << "InvertedLandscape");
54 s.setValue("SupportedOrientations", QStringList() << "Portrait" << "Landscape" << "InvertedLandscape");
54 s.setValue("PrimaryOrientation", "InvertedLandscape");
55 s.setValue("PrimaryOrientation", "InvertedLandscape");
56+ s.setValue("SupportsMultiColorLed", false);
55 s.sync();
57 s.sync();
56
58
57 qputenv("XDG_CONFIG_HOME", dir.path().toUtf8());
59 qputenv("XDG_CONFIG_HOME", dir.path().toUtf8());
@@ -64,6 +66,7 @@ private Q_SLOTS:
64 QCOMPARE(p.invertedPortraitOrientation(), Qt::InvertedPortraitOrientation);
66 QCOMPARE(p.invertedPortraitOrientation(), Qt::InvertedPortraitOrientation);
65 QCOMPARE(p.landscapeOrientation(), Qt::LandscapeOrientation);
67 QCOMPARE(p.landscapeOrientation(), Qt::LandscapeOrientation);
66 QCOMPARE(p.invertedLandscapeOrientation(), Qt::InvertedLandscapeOrientation);
68 QCOMPARE(p.invertedLandscapeOrientation(), Qt::InvertedLandscapeOrientation);
69+ QCOMPARE(p.supportsMultiColorLed(), false);
67 }
70 }
68
71
69};
72};
tests/qmltests/Panel/Indicators/tst_IndicatorsLight.qml+15−1
@@ -155,7 +155,6 @@ Item {
155 ActionData.data = noNewMessage;
155 ActionData.data = noNewMessage;
156 loader.sourceComponent = undefined;
156 loader.sourceComponent = undefined;
157 loader.sourceComponent = light;
157 loader.sourceComponent = light;
158− Powerd.setStatus(Powerd.On, Powerd.Unknown);
159 }
158 }
160
159
161 function test_LightsStatus_data() {
160 function test_LightsStatus_data() {
@@ -253,12 +252,27 @@ Item {
253 expectedLightsOnMillisec: 1000,
252 expectedLightsOnMillisec: 1000,
254 expectedLightsOffMillisec: 0,
253 expectedLightsOffMillisec: 0,
255 powerd: Powerd.Off, actionData: batteryLevelDBusSignals["100"], wizardStatus: batteryIconNames.charging },
254 powerd: Powerd.Off, actionData: batteryLevelDBusSignals["100"], wizardStatus: batteryIconNames.charging },
255+
256+ //
257+ // Support for Multicolor LED
258+ //
259+ { tag: "Powerd.Off with New Message & no support for multicolor led",
260+ expectedLightsState: Lights.On,
261+ powerd: Powerd.Off, actionData: newMessage, supportsMultiColorLed: false },
262+ { tag: "Powerd.Off while charging & support for multicolor led",
263+ expectedLightsState: Lights.On,
264+ powerd: Powerd.Off, actionData: deviceStateDBusSignals.charging, supportsMultiColorLed: true },
265+ { tag: "Powerd.Off while charging & no support for multicolor led",
266+ expectedLightsState: Lights.Off,
267+ powerd: Powerd.Off, actionData: deviceStateDBusSignals.charging, supportsMultiColorLed: false },
256 ]
268 ]
257 }
269 }
258
270
259 function test_LightsStatus(data) {
271 function test_LightsStatus(data) {
260 console.log("----------------------------------------------------------------")
272 console.log("----------------------------------------------------------------")
261
273
274+ if (data.hasOwnProperty("supportsMultiColorLed"))
275+ loader.item.supportsMultiColorLed = data.supportsMultiColorLed
262 if (data.hasOwnProperty("powerd"))
276 if (data.hasOwnProperty("powerd"))
263 Powerd.setStatus(data.powerd, Powerd.Unknown)
277 Powerd.setStatus(data.powerd, Powerd.Unknown)
264 if (data.hasOwnProperty("actionData"))
278 if (data.hasOwnProperty("actionData"))