Merge lp:~renatofilho/unity8/blue-led into lp:unity8

Proposed by Renato Araujo Oliveira Filho on 2014-06-27
Status: Merged
Approved by: Michael Zanetti on 2014-07-03
Approved revision: 1002
Merged at revision: 1008
Proposed branch: lp:~renatofilho/unity8/blue-led
Merge into: lp:unity8
Diff against target: 483 lines (+397/-0)
11 files modified
debian/control (+2/-0)
debian/unity8-private.install (+1/-0)
plugins/CMakeLists.txt (+1/-0)
plugins/Lights/CMakeLists.txt (+18/-0)
plugins/Lights/Lights.cpp (+182/-0)
plugins/Lights/Lights.h (+75/-0)
plugins/Lights/plugin.cpp (+35/-0)
plugins/Lights/plugin.h (+34/-0)
plugins/Lights/qmldir (+3/-0)
qml/Panel/Indicators/DefaultIndicatorWidget.qml (+8/-0)
qml/Panel/Indicators/IndicatorsLight.qml (+38/-0)
To merge this branch: bzr merge lp:~renatofilho/unity8/blue-led
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing on 2014-07-03
Michael Zanetti (community) 2014-06-27 Approve on 2014-07-03
Review via email: mp+224899@code.launchpad.net

Commit Message

Create IndicatorsLight.qml component used to control indicator led.

A blue led will pulse if the message indicator is blue and screen is off.

Description of the Change

 * Are there any related MPs required for this MP to build/function as expected? NO

 * Did you perform an exploratory manual test run of your code change and any related functionality? YES

 * Did you make sure that your branch does not contain spurious tags? YES

 * If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP? NO PACKAGE CHANGE

 * If you changed the UI, has there been a design review? NO UI CHANGE

To post a comment you must log in.
Michael Zanetti (mzanetti) wrote :

Looks quite good. See some inline comments. Also please add the checklist [1] to the description and fill it in.

[1] https://wiki.ubuntu.com/Process/Merges/Checklists/Unity8

review: Needs Fixing

 * Are there any related MPs required for this MP to build/function as expected? NO

 * Did you perform an exploratory manual test run of your code change and any related functionality? YES

 * Did you make sure that your branch does not contain spurious tags? YES

 * If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP? NO PACKAGE CHANGE

 * If you changed the UI, has there been a design review? NO UI CHANGE

Michael Zanetti (mzanetti) wrote :

There's one last header we missed. See inline comment.

I guess the color of the light kinda counts as a UX change, so I think we should ask design for an opinion on the color.

As discussed on IRC, it'd be cool to have a color property of the class to allow setting the color easily in QML.

review: Needs Fixing
Michael Zanetti (mzanetti) wrote :

 * Did you perform an exploratory manual test run of the code change and any related functionality?

Yes. works fine

 * Did CI run pass? If not, please explain why.

it did

review: Approve
Michael Zanetti (mzanetti) wrote :

sorry, there's still plugin.h's copyright header out of date.

review: Needs Fixing
lp:~renatofilho/unity8/blue-led updated on 2014-07-03
1002. By Renato Araujo Oliveira Filho on 2014-07-03

Updated plugin.h license header.

> sorry, there's still plugin.h's copyright header out of date.
Fixed

Michael Zanetti (mzanetti) :
review: Approve
MichaƂ Sawicz (saviq) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2014-06-27 08:28:18 +0000
3+++ debian/control 2014-07-03 12:35:52 +0000
4@@ -13,6 +13,7 @@
5 libgles2-mesa-dev[armhf],
6 libglib2.0-dev,
7 libgsettings-qt-dev,
8+ libhardware-dev,
9 libhud-client2-dev,
10 libpulse-dev,
11 libqmenumodel-dev (>= 0.2.7),
12@@ -159,6 +160,7 @@
13 Multi-Arch: same
14 Pre-Depends: ${misc:Pre-Depends},
15 Depends: gsettings-ubuntu-schemas,
16+ libhardware2,
17 libunity-core-6.0-9,
18 ${misc:Depends},
19 ${shlibs:Depends},
20
21=== modified file 'debian/unity8-private.install'
22--- debian/unity8-private.install 2014-06-11 15:36:51 +0000
23+++ debian/unity8-private.install 2014-07-03 12:35:52 +0000
24@@ -2,6 +2,7 @@
25 usr/lib/*/unity8/qml/Dash
26 usr/lib/*/unity8/qml/HudClient
27 usr/lib/*/unity8/qml/LightDM
28+usr/lib/*/unity8/qml/Lights
29 usr/lib/*/unity8/qml/Powerd
30 usr/lib/*/unity8/qml/SessionBroadcast
31 usr/lib/*/unity8/qml/Ubuntu
32
33=== modified file 'plugins/CMakeLists.txt'
34--- plugins/CMakeLists.txt 2014-06-11 15:36:51 +0000
35+++ plugins/CMakeLists.txt 2014-07-03 12:35:52 +0000
36@@ -14,6 +14,7 @@
37 add_subdirectory(AccountsService)
38 add_subdirectory(HudClient)
39 add_subdirectory(LightDM)
40+add_subdirectory(Lights)
41 add_subdirectory(Dash)
42 add_subdirectory(Powerd)
43 add_subdirectory(SessionBroadcast)
44
45=== added directory 'plugins/Lights'
46=== added file 'plugins/Lights/CMakeLists.txt'
47--- plugins/Lights/CMakeLists.txt 1970-01-01 00:00:00 +0000
48+++ plugins/Lights/CMakeLists.txt 2014-07-03 12:35:52 +0000
49@@ -0,0 +1,18 @@
50+include(FindPkgConfig)
51+
52+pkg_check_modules(ANDROID_HEADERS REQUIRED android-headers)
53+pkg_check_modules(ANDROID_HARDWARE REQUIRED libhardware)
54+
55+include_directories(
56+ ${ANDROID_HEADERS_INCLUDE_DIRS}
57+)
58+
59+add_library(Lights-qml MODULE
60+ plugin.cpp
61+ Lights.cpp
62+ )
63+
64+qt5_use_modules(Lights-qml Qml Gui)
65+target_link_libraries(Lights-qml ${ANDROID_HARDWARE_LIBRARIES})
66+
67+add_unity8_plugin(Lights 0.1 Lights TARGETS Lights-qml)
68
69=== added file 'plugins/Lights/Lights.cpp'
70--- plugins/Lights/Lights.cpp 1970-01-01 00:00:00 +0000
71+++ plugins/Lights/Lights.cpp 2014-07-03 12:35:52 +0000
72@@ -0,0 +1,182 @@
73+/*
74+ * Copyright (C) 2014 Canonical, Ltd.
75+ *
76+ * This program is free software; you can redistribute it and/or modify
77+ * it under the terms of the GNU General Public License as published by
78+ * the Free Software Foundation; version 3.
79+ *
80+ * This program is distributed in the hope that it will be useful,
81+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
82+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83+ * GNU General Public License for more details.
84+ *
85+ * You should have received a copy of the GNU General Public License
86+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
87+ *
88+ * Author: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
89+ */
90+
91+#include "Lights.h"
92+#include <QtCore/QDebug>
93+
94+extern "C" {
95+#include <hardware/hardware.h>
96+#include <hardware/lights.h>
97+#include <string.h>
98+}
99+
100+Lights::Lights(QObject* parent)
101+ : QObject(parent),
102+ m_lightDevice(0),
103+ m_color("blue"),
104+ m_state(Lights::Off),
105+ m_onMs(1000),
106+ m_offMs(3000)
107+{
108+}
109+
110+Lights::~Lights()
111+{
112+ if (m_lightDevice) {
113+ hw_device_t* device = (hw_device_t*) m_lightDevice;
114+ device->close(device);
115+ }
116+}
117+
118+void Lights::setState(Lights::State newState)
119+{
120+ if (m_state != newState) {
121+ if (newState == Lights::On) {
122+ turnOn();
123+ } else {
124+ turnOff();
125+ }
126+ }
127+}
128+
129+Lights::State Lights::state() const
130+{
131+ return m_state;
132+}
133+
134+void Lights::setColor(const QColor &color)
135+{
136+ if (m_color != color) {
137+ m_color = color;
138+ Q_EMIT colorChanged(m_color);
139+ // FIXME: update the collor if the light is already on
140+ }
141+}
142+
143+QColor Lights::color() const
144+{
145+ return m_color;
146+}
147+
148+int Lights::onMillisec() const
149+{
150+ return m_onMs;
151+}
152+
153+void Lights::setOnMillisec(int onMs)
154+{
155+ if (m_onMs != onMs) {
156+ m_onMs = onMs;
157+ Q_EMIT onMillisecChanged(m_onMs);
158+ // FIXME: update the property if the light is already on
159+ }
160+}
161+
162+int Lights::offMillisec() const
163+{
164+ return m_offMs;
165+}
166+
167+void Lights::setOffMillisec(int offMs)
168+{
169+ if (m_offMs != offMs) {
170+ m_offMs = offMs;
171+ Q_EMIT offMillisecChanged(m_offMs);
172+ // FIXME: update the property if the light is already on
173+ }
174+}
175+
176+bool Lights::init()
177+{
178+ if (m_lightDevice) {
179+ return true;
180+ }
181+
182+ int err;
183+ hw_module_t* module;
184+
185+ err = hw_get_module(LIGHTS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
186+ if (err == 0) {
187+ hw_device_t* device;
188+ err = module->methods->open(module, LIGHT_ID_NOTIFICATIONS, &device);
189+ if (err == 0) {
190+ m_lightDevice = (light_device_t*)device;
191+ return true;
192+ } else {
193+ qWarning() << "Failed to access notification lights";
194+ }
195+ } else {
196+ qWarning() << "Failed to initialize lights hardware.";
197+ }
198+ return false;
199+}
200+
201+void Lights::turnOn()
202+{
203+ if (!init()) {
204+ qWarning() << "No lights device";
205+ return;
206+ }
207+
208+ if (m_state == Lights::On) {
209+ return;
210+ }
211+
212+ // pulse
213+ light_state_t state;
214+ memset(&state, 0, sizeof(light_state_t));
215+ state.color = m_color.rgba();
216+ state.flashMode = LIGHT_FLASH_TIMED;
217+ state.flashOnMS = m_onMs;
218+ state.flashOffMS = m_offMs;
219+ state.brightnessMode = BRIGHTNESS_MODE_USER;
220+
221+ if (m_lightDevice->set_light(m_lightDevice, &state) != 0) {
222+ qWarning() << "Failed to turn the light off";
223+ } else {
224+ m_state = Lights::On;
225+ Q_EMIT stateChanged(m_state);
226+ }
227+}
228+
229+void Lights::turnOff()
230+{
231+ if (!init()) {
232+ qWarning() << "No lights device";
233+ return;
234+ }
235+
236+ if (m_state == Lights::Off) {
237+ return;
238+ }
239+
240+ light_state_t state;
241+ memset(&state, 0, sizeof(light_state_t));
242+ state.color = 0x00000000;
243+ state.flashMode = LIGHT_FLASH_NONE;
244+ state.flashOnMS = 0;
245+ state.flashOffMS = 0;
246+ state.brightnessMode = 0;
247+
248+ if (m_lightDevice->set_light(m_lightDevice, &state) != 0) {
249+ qWarning() << "Failed to turn the light off";
250+ } else {
251+ m_state = Lights::Off;
252+ Q_EMIT stateChanged(m_state);
253+ }
254+}
255
256=== added file 'plugins/Lights/Lights.h'
257--- plugins/Lights/Lights.h 1970-01-01 00:00:00 +0000
258+++ plugins/Lights/Lights.h 2014-07-03 12:35:52 +0000
259@@ -0,0 +1,75 @@
260+/*
261+ * Copyright (C) 2014 Canonical, Ltd.
262+ *
263+ * This program is free software; you can redistribute it and/or modify
264+ * it under the terms of the GNU General Public License as published by
265+ * the Free Software Foundation; version 3.
266+ *
267+ * This program is distributed in the hope that it will be useful,
268+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
269+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
270+ * GNU General Public License for more details.
271+ *
272+ * You should have received a copy of the GNU General Public License
273+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
274+ *
275+ * Author: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
276+ */
277+
278+#ifndef UNITY_LIGHTS_H
279+#define UNITY_LIGHTS_H
280+
281+#include <QtCore/QObject>
282+#include <QtGui/QColor>
283+
284+struct light_device_t;
285+
286+class Lights: public QObject
287+{
288+ Q_OBJECT
289+ Q_ENUMS(State)
290+ Q_PROPERTY(State state READ state WRITE setState NOTIFY stateChanged)
291+ Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
292+ Q_PROPERTY(int onMillisec READ onMillisec WRITE setOnMillisec NOTIFY onMillisecChanged)
293+ Q_PROPERTY(int offMillisec READ offMillisec WRITE setOffMillisec NOTIFY offMillisecChanged)
294+
295+public:
296+ enum State {
297+ Off,
298+ On,
299+ };
300+
301+ explicit Lights(QObject *parent = 0);
302+ ~Lights();
303+
304+ void setState(State newState);
305+ State state() const;
306+
307+ void setColor(const QColor &color);
308+ QColor color() const;
309+
310+ int onMillisec() const;
311+ void setOnMillisec(int onMs);
312+
313+ int offMillisec() const;
314+ void setOffMillisec(int offMs);
315+
316+Q_SIGNALS:
317+ void stateChanged(State newState);
318+ void colorChanged(const QColor &color);
319+ void onMillisecChanged(int onMs);
320+ void offMillisecChanged(int offMs);
321+
322+private:
323+ light_device_t* m_lightDevice;
324+ QColor m_color;
325+ State m_state;
326+ int m_onMs;
327+ int m_offMs;
328+
329+ bool init();
330+ void turnOff();
331+ void turnOn();
332+};
333+
334+#endif
335
336=== added file 'plugins/Lights/plugin.cpp'
337--- plugins/Lights/plugin.cpp 1970-01-01 00:00:00 +0000
338+++ plugins/Lights/plugin.cpp 2014-07-03 12:35:52 +0000
339@@ -0,0 +1,35 @@
340+/*
341+ * Copyright (C) 2014 Canonical, Ltd.
342+ *
343+ * This program is free software; you can redistribute it and/or modify
344+ * it under the terms of the GNU General Public License as published by
345+ * the Free Software Foundation; version 3.
346+ *
347+ * This program is distributed in the hope that it will be useful,
348+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
349+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
350+ * GNU General Public License for more details.
351+ *
352+ * You should have received a copy of the GNU General Public License
353+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
354+ *
355+ * Author: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
356+ */
357+
358+#include "plugin.h"
359+#include "Lights.h"
360+
361+#include <QtQml/qqml.h>
362+
363+static QObject *lights_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
364+{
365+ Q_UNUSED(engine)
366+ Q_UNUSED(scriptEngine)
367+ return new Lights();
368+}
369+
370+void LightsPlugin::registerTypes(const char *uri)
371+{
372+ Q_ASSERT(uri == QLatin1String("Lights"));
373+ qmlRegisterSingletonType<Lights>(uri, 0, 1, "Lights", lights_provider);
374+}
375
376=== added file 'plugins/Lights/plugin.h'
377--- plugins/Lights/plugin.h 1970-01-01 00:00:00 +0000
378+++ plugins/Lights/plugin.h 2014-07-03 12:35:52 +0000
379@@ -0,0 +1,34 @@
380+/*
381+ * Copyright (C) 2014 Canonical, Ltd.
382+ *
383+ * This program is free software; you can redistribute it and/or modify
384+ * it under the terms of the GNU General Public License as published by
385+ * the Free Software Foundation; version 3.
386+ *
387+ * This program is distributed in the hope that it will be useful,
388+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
389+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
390+ * GNU General Public License for more details.
391+ *
392+ * You should have received a copy of the GNU General Public License
393+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
394+ *
395+ * Author: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
396+ */
397+
398+#ifndef LIGHTS_PLUGIN_H
399+#define LIGHTS_PLUGIN_H
400+
401+#include <QtQml/QQmlEngine>
402+#include <QtQml/QQmlExtensionPlugin>
403+
404+class LightsPlugin : public QQmlExtensionPlugin
405+{
406+ Q_OBJECT
407+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
408+
409+public:
410+ void registerTypes(const char *uri);
411+};
412+
413+#endif
414
415=== added file 'plugins/Lights/qmldir'
416--- plugins/Lights/qmldir 1970-01-01 00:00:00 +0000
417+++ plugins/Lights/qmldir 2014-07-03 12:35:52 +0000
418@@ -0,0 +1,3 @@
419+module Lights
420+plugin Lights-qml
421+typeinfo Lights.qmltypes
422
423=== modified file 'qml/Panel/Indicators/DefaultIndicatorWidget.qml'
424--- qml/Panel/Indicators/DefaultIndicatorWidget.qml 2013-12-12 09:55:17 +0000
425+++ qml/Panel/Indicators/DefaultIndicatorWidget.qml 2014-07-03 12:35:52 +0000
426@@ -32,6 +32,14 @@
427 width: itemRow.width
428 enabled: false
429
430+ // FIXME: For now we will enable led indicator support only for messaging indicator
431+ // in the future we should export a led API insted of doing that,
432+ Loader {
433+ id: indicatorLed
434+ // only load source Component if the icons contains the new message icon
435+ source: (indicatorWidget.icons && (String(indicatorWidget.icons).indexOf("indicator-messages-new") != -1)) ? Qt.resolvedUrl("IndicatorsLight.qml") : ""
436+ }
437+
438 Row {
439 id: itemRow
440 width: childrenRect.width
441
442=== added file 'qml/Panel/Indicators/IndicatorsLight.qml'
443--- qml/Panel/Indicators/IndicatorsLight.qml 1970-01-01 00:00:00 +0000
444+++ qml/Panel/Indicators/IndicatorsLight.qml 2014-07-03 12:35:52 +0000
445@@ -0,0 +1,38 @@
446+/*
447+ * Copyright 2014 Canonical Ltd.
448+ *
449+ * This program is free software; you can redistribute it and/or modify
450+ * it under the terms of the GNU Lesser General Public License as published by
451+ * the Free Software Foundation; version 3.
452+ *
453+ * This program is distributed in the hope that it will be useful,
454+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
455+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
456+ * GNU Lesser General Public License for more details.
457+ *
458+ * You should have received a copy of the GNU Lesser General Public License
459+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
460+ *
461+ * Authors:
462+ * Renato Araujo Oliveira Filho <renato@canonical.com>
463+ */
464+
465+import QtQuick 2.0
466+import Powerd 0.1
467+import Lights 0.1
468+
469+QtObject {
470+ id: root
471+
472+ Component.onDestruction: Lights.state = Lights.Off
473+
474+ // QtObject does not have children
475+ property var _connections: Connections {
476+ id: powerConnection
477+
478+ target: Powerd
479+ onDisplayPowerStateChange: {
480+ Lights.state = (status === Powerd.Off) ? Lights.On : Lights.Off
481+ }
482+ }
483+}

Subscribers

People subscribed via source and target branches