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

Proposed by Ken VanDine
Status: Work in progress
Proposed branch: lp:~ken-vandine/ubuntu-system-settings/rtm-lp1337200
Merge into: lp:ubuntu-system-settings/rtm-14.09
Diff against target: 135 lines (+58/-28)
1 file modified
plugins/battery/plugin/battery-plugin.cpp (+58/-28)
To merge this branch: bzr merge lp:~ken-vandine/ubuntu-system-settings/rtm-lp1337200
Reviewer Review Type Date Requested Status
Ken VanDine Disapprove
Sebastien Bacher (community) Needs Fixing
Review via email: mp+241749@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.
937. By Ken VanDine

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

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

Thanks, but see the merge request for the version in trunk. It would maybe make sense to wait to have the trunk work approved before putting up a backport for review, this way we avoid having to track "needs fixing" on different pages?

review: Needs Fixing
Revision history for this message
Iain Lane (laney) wrote :
Revision history for this message
Ken VanDine (ken-vandine) wrote :

I just needed a MP to use to build for rtm in a silo.

review: Disapprove

Unmerged revisions

937. By Ken VanDine

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

936. 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-07-23 13:37:06 +0000
3+++ plugins/battery/plugin/battery-plugin.cpp 2014-11-13 23:11:19 +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,41 +55,56 @@
28 gpointer user_data)
29 {
30 BatteryItem *item (static_cast<BatteryItem *> (user_data));
31-
32- gboolean ret = up_client_enumerate_devices_sync (client, nullptr, nullptr);
33- if (!ret) {
34- item->setVisibility (false);
35- } else {
36- GPtrArray *devices = up_client_get_devices (client);
37- item->setVisibility (devices->len > 0);
38- g_ptr_array_unref (devices);
39- }
40-
41+ GPtrArray *devices = up_client_get_devices (client);
42+ item->setVisibility (devices->len > 0);
43+ g_ptr_array_unref (devices);
44 }
45
46 BatteryItem::BatteryItem(const QVariantMap &staticData, QObject *parent):
47 ItemBase(staticData, parent),
48 m_client(up_client_new()),
49+ m_app(QCoreApplication::instance()),
50 m_addedHandler(0),
51 m_removedHandler(0)
52 {
53+#if !UP_CHECK_VERSION(0, 99, 0)
54+ gboolean ret = up_client_enumerate_devices_sync (m_client, nullptr, nullptr);
55+ if (!ret) {
56+ setVisibility (false);
57+ }
58+#endif
59+
60 deviceChanged(m_client, nullptr, this);
61- m_addedHandler = g_signal_connect (m_client,
62- "device-added",
63- G_CALLBACK (::deviceChanged),
64- this /* user_data */);
65- m_removedHandler = g_signal_connect (m_client,
66- "device-removed",
67- G_CALLBACK (::deviceChanged),
68- this /* user_data */);
69-}
70-
71-void BatteryItem::setVisibility(bool visible)
72-{
73- setVisible(visible);
74-}
75-
76-BatteryItem::~BatteryItem()
77+ connect(m_app, SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(onApplicationStateChanged(Qt::ApplicationState)));
78+ up_connect();
79+}
80+
81+void BatteryItem::onApplicationStateChanged(Qt::ApplicationState st)
82+{
83+ if (st == Qt::ApplicationActive)
84+ up_connect();
85+ else
86+ up_disconnect();
87+}
88+
89+void BatteryItem::up_connect()
90+{
91+ if (!m_addedHandler) {
92+ m_addedHandler = g_signal_connect (m_client,
93+ "device-added",
94+ G_CALLBACK (::deviceChanged),
95+ this /* user_data */);
96+ }
97+
98+ if (!m_removedHandler) {
99+ m_removedHandler = g_signal_connect (m_client,
100+ "device-removed",
101+ G_CALLBACK (::deviceChanged),
102+ this /* user_data */);
103+ }
104+}
105+
106+void BatteryItem::up_disconnect()
107 {
108 if (m_addedHandler) {
109 g_signal_handler_disconnect (m_client, m_addedHandler);
110@@ -93,7 +115,16 @@
111 g_signal_handler_disconnect (m_client, m_removedHandler);
112 m_removedHandler = 0;
113 }
114-
115+}
116+
117+void BatteryItem::setVisibility(bool visible)
118+{
119+ setVisible(visible);
120+}
121+
122+BatteryItem::~BatteryItem()
123+{
124+ up_disconnect();
125 g_object_unref (m_client);
126 }
127
128@@ -102,7 +133,6 @@
129 {
130 }
131
132-
133 ItemBase *BatteryPlugin::createItem(const QVariantMap &staticData,
134 QObject *parent)
135 {

Subscribers

People subscribed via source and target branches