Merge lp:~ken-vandine/ubuntu-system-settings/lp1337200 into lp:ubuntu-system-settings

Proposed by Ken VanDine
Status: Rejected
Rejected by: Sebastien Bacher
Proposed branch: lp:~ken-vandine/ubuntu-system-settings/lp1337200
Merge into: lp:ubuntu-system-settings
Diff against target: 138 lines (+58/-31)
1 file modified
plugins/battery/plugin/battery-plugin.cpp (+58/-31)
To merge this branch: bzr merge lp:~ken-vandine/ubuntu-system-settings/lp1337200
Reviewer Review Type Date Requested Status
Sebastien Bacher (community) Disapprove
Iain Lane Needs Information
PS Jenkins bot continuous-integration Approve
Review via email: mp+241747@code.launchpad.net

Commit message

Disconnect from upower on suspend and connect on resume

Description of the change

Disconnect from upower on suspend and connect on resume

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
1204. By Ken VanDine

Moved up_client_enumerate_devices_sync to the constructor, we only need to call it once.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Iain Lane (laney) wrote :

One inline comment.

If we disconnect when suspended, what happens if a battery is added or removed then?

Can you add a test for this (how do you programatically suspend an application?) and fix it (call the callback on resuming) if it's broken?

review: Needs Information
Revision history for this message
Sebastien Bacher (seb128) wrote :

Thanks, can you explain why we need to disconnect from upower? With a suspend device not a lot should be happening, if there are events generated/queued while the device is sleeping and not getting any interaction then that seems to be the real bug to fix. Or do we plan to patch every single upower client to workaround the issue?

review: Needs Information
Revision history for this message
Sebastien Bacher (seb128) wrote :

(just read the bug comments, still it feels like wrong to have to workaround in every client)

Revision history for this message
Ken VanDine (ken-vandine) wrote :

It doesn't really fix the issue either, I think the only solution is to really fix upower.

Revision history for this message
Sebastien Bacher (seb128) wrote :

setting as rejected then

review: Disapprove

Unmerged revisions

1204. By Ken VanDine

Moved up_client_enumerate_devices_sync to the constructor, we only need to call it once.

1203. By Ken VanDine

Disconnect from upower on suspend and connect on resume

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/battery/plugin/battery-plugin.cpp'
2--- plugins/battery/plugin/battery-plugin.cpp 2014-09-12 15:42:58 +0000
3+++ plugins/battery/plugin/battery-plugin.cpp 2014-11-14 02:59:39 +0000
4@@ -20,6 +20,7 @@
5
6 #include "battery-plugin.h"
7
8+#include <QCoreApplication>
9 #include <QDebug>
10 #include <QStringList>
11 #include <SystemSettings/ItemBase>
12@@ -39,8 +40,14 @@
13 ~BatteryItem();
14
15 private:
16+ void up_connect();
17+ void up_disconnect();
18 UpClient *m_client;
19+ QCoreApplication *m_app;
20 gulong m_addedHandler, m_removedHandler;
21+
22+private Q_SLOTS:
23+ void onApplicationStateChanged(Qt::ApplicationState st);
24 };
25
26 void deviceChanged(UpClient *client,
27@@ -48,44 +55,56 @@
28 gpointer user_data)
29 {
30 BatteryItem *item (static_cast<BatteryItem *> (user_data));
31-
32-#if !UP_CHECK_VERSION(0, 99, 0)
33- gboolean ret = up_client_enumerate_devices_sync (client, nullptr, nullptr);
34- if (!ret) {
35- item->setVisibility (false);
36- } else
37-#endif
38- {
39- GPtrArray *devices = up_client_get_devices (client);
40- item->setVisibility (devices->len > 0);
41- g_ptr_array_unref (devices);
42- }
43-
44+ GPtrArray *devices = up_client_get_devices (client);
45+ item->setVisibility (devices->len > 0);
46+ g_ptr_array_unref (devices);
47 }
48
49 BatteryItem::BatteryItem(const QVariantMap &staticData, QObject *parent):
50 ItemBase(staticData, parent),
51 m_client(up_client_new()),
52+ m_app(QCoreApplication::instance()),
53 m_addedHandler(0),
54 m_removedHandler(0)
55 {
56+#if !UP_CHECK_VERSION(0, 99, 0)
57+ gboolean ret = up_client_enumerate_devices_sync (m_client, nullptr, nullptr);
58+ if (!ret) {
59+ setVisibility (false);
60+ }
61+#endif
62+
63 deviceChanged(m_client, nullptr, this);
64- m_addedHandler = g_signal_connect (m_client,
65- "device-added",
66- G_CALLBACK (::deviceChanged),
67- this /* user_data */);
68- m_removedHandler = g_signal_connect (m_client,
69- "device-removed",
70- G_CALLBACK (::deviceChanged),
71- this /* user_data */);
72-}
73-
74-void BatteryItem::setVisibility(bool visible)
75-{
76- setVisible(visible);
77-}
78-
79-BatteryItem::~BatteryItem()
80+ connect(m_app, SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(onApplicationStateChanged(Qt::ApplicationState)));
81+ up_connect();
82+}
83+
84+void BatteryItem::onApplicationStateChanged(Qt::ApplicationState st)
85+{
86+ if (st == Qt::ApplicationActive)
87+ up_connect();
88+ else
89+ up_disconnect();
90+}
91+
92+void BatteryItem::up_connect()
93+{
94+ if (!m_addedHandler) {
95+ m_addedHandler = g_signal_connect (m_client,
96+ "device-added",
97+ G_CALLBACK (::deviceChanged),
98+ this /* user_data */);
99+ }
100+
101+ if (!m_removedHandler) {
102+ m_removedHandler = g_signal_connect (m_client,
103+ "device-removed",
104+ G_CALLBACK (::deviceChanged),
105+ this /* user_data */);
106+ }
107+}
108+
109+void BatteryItem::up_disconnect()
110 {
111 if (m_addedHandler) {
112 g_signal_handler_disconnect (m_client, m_addedHandler);
113@@ -96,7 +115,16 @@
114 g_signal_handler_disconnect (m_client, m_removedHandler);
115 m_removedHandler = 0;
116 }
117-
118+}
119+
120+void BatteryItem::setVisibility(bool visible)
121+{
122+ setVisible(visible);
123+}
124+
125+BatteryItem::~BatteryItem()
126+{
127+ up_disconnect();
128 g_object_unref (m_client);
129 }
130
131@@ -105,7 +133,6 @@
132 {
133 }
134
135-
136 ItemBase *BatteryPlugin::createItem(const QVariantMap &staticData,
137 QObject *parent)
138 {

Subscribers

People subscribed via source and target branches