Merge lp:~ricmm/qtpowerd/names-and-display into lp:qtpowerd

Proposed by Ricardo Mendoza
Status: Merged
Approved by: Loïc Minier
Approved revision: 7
Merged at revision: 7
Proposed branch: lp:~ricmm/qtpowerd/names-and-display
Merge into: lp:qtpowerd
Diff against target: 143 lines (+53/-8)
3 files modified
QtPowerd.cpp (+43/-6)
QtPowerd.h (+9/-1)
qtpowerd.pro (+1/-1)
To merge this branch: bzr merge lp:~ricmm/qtpowerd/names-and-display
Reviewer Review Type Date Requested Status
Loïc Minier Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+191009@code.launchpad.net

Commit message

* Select lock name dynamically according to application
* Hold display active as well on KeepAlive

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Loïc Minier (lool) wrote :

Rather than:
+ POWERD_DISPLAY_STATE_ON = POWERD_SYS_STATE_ACTIVE,
maybe you should copy-paste the whole powerd.h enum:
enum powerd_display_state {
    POWERD_DISPLAY_STATE_DONT_CARE = 0,
    POWERD_DISPLAY_STATE_ON,

    /* Keep last */
    POWERD_NUM_DISPLAY_STATES
};

Revision history for this message
Loïc Minier (lool) wrote :

Hmm this doens't look good, it seems to me like music-app and mediaplayer-app will both take both locks when we want a different lock for each of them.

review: Disapprove
lp:~ricmm/qtpowerd/names-and-display updated
7. By Ricardo Mendoza

Split state setters and add keepDisplayOn for the Display value

Revision history for this message
Loïc Minier (lool) wrote :

Looks good to me; thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'QtPowerd.cpp'
--- QtPowerd.cpp 2013-10-01 21:49:39 +0000
+++ QtPowerd.cpp 2013-10-14 18:53:43 +0000
@@ -17,6 +17,7 @@
17 */17 */
1818
19#include <QtDebug>19#include <QtDebug>
20#include <QGuiApplication>
2021
21/* FIXME should really include powerd.h, but not available right now */22/* FIXME should really include powerd.h, but not available right now */
22//#include <powerd.h>23//#include <powerd.h>
@@ -27,24 +28,26 @@
2728
28 //The Active state will prevent system suspend29 //The Active state will prevent system suspend
29 POWERD_SYS_STATE_ACTIVE,30 POWERD_SYS_STATE_ACTIVE,
31 POWERD_DISPLAY_STATE_ON = POWERD_SYS_STATE_ACTIVE,
3032
31 POWERD_NUM_POWER_STATES33 POWERD_NUM_POWER_STATES
32};34};
3335
34#include "QtPowerd.h"36#include "QtPowerd.h"
3537
36// XXX this should be set by QML app; in fact it could hold multiple ones
37#define LOCK_NAME "music-app-background"
38
39QtPowerd::QtPowerd(QObject* parent)38QtPowerd::QtPowerd(QObject* parent)
40 : QObject(parent),39 : QObject(parent),
41 m_keepAlive(false),40 m_keepAlive(false),
41 m_keepDisplayOn(false),
42 m_qtpowerd(NULL)42 m_qtpowerd(NULL)
43{43{
44 m_qtpowerd = new QDBusInterface("com.canonical.powerd",44 m_qtpowerd = new QDBusInterface("com.canonical.powerd",
45 "/com/canonical/powerd",45 "/com/canonical/powerd",
46 "com.canonical.powerd",46 "com.canonical.powerd",
47 QDBusConnection::SM_BUSNAME(), this);47 QDBusConnection::SM_BUSNAME(), this);
48
49 m_lockName = QGuiApplication::instance()->applicationName();
50 m_lockName.append("-background");
48}51}
4952
50bool QtPowerd::keepAlive() const53bool QtPowerd::keepAlive() const
@@ -61,15 +64,15 @@
6164
62 if (keep) {65 if (keep) {
63 QDBusReply<QString> reply = m_qtpowerd->call("requestSysState",66 QDBusReply<QString> reply = m_qtpowerd->call("requestSysState",
64 LOCK_NAME,67 m_lockName,
65 POWERD_SYS_STATE_ACTIVE);68 POWERD_SYS_STATE_ACTIVE);
66 if (!reply.isValid()) {69 if (!reply.isValid()) {
67 qCritical() << "requestSysState:" << reply.error();70 qCritical() << "requestSysState:" << reply.error();
68 return;71 return;
69 }72 }
70 m_cookie = reply.value();73 m_sysCookie = reply.value();
71 } else {74 } else {
72 QDBusReply<void> reply = m_qtpowerd->call("clearSysState", m_cookie);75 QDBusReply<void> reply = m_qtpowerd->call("clearSysState", m_sysCookie);
73 if (!reply.isValid()) {76 if (!reply.isValid()) {
74 qCritical() << "clearSysState:" << reply.error();77 qCritical() << "clearSysState:" << reply.error();
75 return;78 return;
@@ -79,3 +82,37 @@
79 m_keepAlive = keep;82 m_keepAlive = keep;
80 Q_EMIT keepAliveChanged();83 Q_EMIT keepAliveChanged();
81}84}
85
86bool QtPowerd::keepDisplayOn() const
87{
88 return m_keepDisplayOn;
89}
90
91void QtPowerd::setDisplayOn(const bool keep)
92{
93 if (m_keepDisplayOn == keep) {
94 // nothing to do
95 return;
96 }
97
98 if (keep) {
99 QDBusReply<QString> reply = m_qtpowerd->call("requestDisplayState",
100 m_lockName,
101 POWERD_DISPLAY_STATE_ON,
102 QVariant((uint) 0));
103 if (!reply.isValid()) {
104 qCritical() << "requestDisplayState:" << reply.error();
105 return;
106 }
107 m_dispCookie = reply.value();
108 } else {
109 QDBusReply<void> reply = m_qtpowerd->call("clearDisplayState", m_dispCookie);
110 if (!reply.isValid()) {
111 qCritical() << "clearDisplayState:" << reply.error();
112 return;
113 }
114 }
115
116 m_keepDisplayOn = keep;
117 Q_EMIT keepDisplayOnChanged();
118}
82119
=== modified file 'QtPowerd.h'
--- QtPowerd.h 2013-10-01 21:49:39 +0000
+++ QtPowerd.h 2013-10-14 18:53:43 +0000
@@ -28,6 +28,7 @@
28{28{
29 Q_OBJECT29 Q_OBJECT
30 Q_PROPERTY(bool keepAlive READ keepAlive WRITE setKeepAlive NOTIFY keepAliveChanged)30 Q_PROPERTY(bool keepAlive READ keepAlive WRITE setKeepAlive NOTIFY keepAliveChanged)
31 Q_PROPERTY(bool keepDisplayOn READ keepDisplayOn WRITE setDisplayOn NOTIFY keepDisplayOnChanged)
3132
32public:33public:
33 explicit QtPowerd(QObject *parent = 0);34 explicit QtPowerd(QObject *parent = 0);
@@ -35,12 +36,19 @@
35 bool keepAlive() const;36 bool keepAlive() const;
36 void setKeepAlive(const bool keepAlive);37 void setKeepAlive(const bool keepAlive);
3738
39 bool keepDisplayOn() const;
40 void setDisplayOn(const bool keepDisplayOn);
41
38Q_SIGNALS:42Q_SIGNALS:
39 void keepAliveChanged();43 void keepAliveChanged();
44 void keepDisplayOnChanged();
4045
41private:46private:
42 QString m_cookie;47 QString m_lockName;
48 QString m_dispCookie;
49 QString m_sysCookie;
43 bool m_keepAlive;50 bool m_keepAlive;
51 bool m_keepDisplayOn;
44 QDBusInterface *m_qtpowerd;52 QDBusInterface *m_qtpowerd;
45};53};
4654
4755
=== modified file 'qtpowerd.pro'
--- qtpowerd.pro 2013-10-01 21:49:39 +0000
+++ qtpowerd.pro 2013-10-14 18:53:43 +0000
@@ -1,7 +1,7 @@
1TEMPLATE = lib1TEMPLATE = lib
2CONFIG += qt plugin link_pkgconfig2CONFIG += qt plugin link_pkgconfig
33
4equals(QT_MAJOR_VERSION, 5): QT = core dbus qml4equals(QT_MAJOR_VERSION, 5): QT = core dbus qml quick
55
6PKGCONFIG =6PKGCONFIG =
77

Subscribers

People subscribed via source and target branches