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
=== modified file 'plugins/battery/plugin/battery-plugin.cpp'
--- plugins/battery/plugin/battery-plugin.cpp 2014-07-23 13:37:06 +0000
+++ plugins/battery/plugin/battery-plugin.cpp 2014-11-13 23:11:19 +0000
@@ -20,6 +20,7 @@
2020
21#include "battery-plugin.h"21#include "battery-plugin.h"
2222
23#include <QCoreApplication>
23#include <QDebug>24#include <QDebug>
24#include <QStringList>25#include <QStringList>
25#include <SystemSettings/ItemBase>26#include <SystemSettings/ItemBase>
@@ -39,8 +40,14 @@
39 ~BatteryItem();40 ~BatteryItem();
4041
41private:42private:
43 void up_connect();
44 void up_disconnect();
42 UpClient *m_client;45 UpClient *m_client;
46 QCoreApplication *m_app;
43 gulong m_addedHandler, m_removedHandler;47 gulong m_addedHandler, m_removedHandler;
48
49private Q_SLOTS:
50 void onApplicationStateChanged(Qt::ApplicationState st);
44};51};
4552
46void deviceChanged(UpClient *client,53void deviceChanged(UpClient *client,
@@ -48,41 +55,56 @@
48 gpointer user_data)55 gpointer user_data)
49{56{
50 BatteryItem *item (static_cast<BatteryItem *> (user_data));57 BatteryItem *item (static_cast<BatteryItem *> (user_data));
5158 GPtrArray *devices = up_client_get_devices (client);
52 gboolean ret = up_client_enumerate_devices_sync (client, nullptr, nullptr);59 item->setVisibility (devices->len > 0);
53 if (!ret) {60 g_ptr_array_unref (devices);
54 item->setVisibility (false);
55 } else {
56 GPtrArray *devices = up_client_get_devices (client);
57 item->setVisibility (devices->len > 0);
58 g_ptr_array_unref (devices);
59 }
60
61}61}
6262
63BatteryItem::BatteryItem(const QVariantMap &staticData, QObject *parent):63BatteryItem::BatteryItem(const QVariantMap &staticData, QObject *parent):
64 ItemBase(staticData, parent),64 ItemBase(staticData, parent),
65 m_client(up_client_new()),65 m_client(up_client_new()),
66 m_app(QCoreApplication::instance()),
66 m_addedHandler(0),67 m_addedHandler(0),
67 m_removedHandler(0)68 m_removedHandler(0)
68{69{
70#if !UP_CHECK_VERSION(0, 99, 0)
71 gboolean ret = up_client_enumerate_devices_sync (m_client, nullptr, nullptr);
72 if (!ret) {
73 setVisibility (false);
74 }
75#endif
76
69 deviceChanged(m_client, nullptr, this);77 deviceChanged(m_client, nullptr, this);
70 m_addedHandler = g_signal_connect (m_client,78 connect(m_app, SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(onApplicationStateChanged(Qt::ApplicationState)));
71 "device-added",79 up_connect();
72 G_CALLBACK (::deviceChanged),80}
73 this /* user_data */);81
74 m_removedHandler = g_signal_connect (m_client,82void BatteryItem::onApplicationStateChanged(Qt::ApplicationState st)
75 "device-removed",83{
76 G_CALLBACK (::deviceChanged),84 if (st == Qt::ApplicationActive)
77 this /* user_data */);85 up_connect();
78}86 else
7987 up_disconnect();
80void BatteryItem::setVisibility(bool visible)88}
81{89
82 setVisible(visible);90void BatteryItem::up_connect()
83}91{
8492 if (!m_addedHandler) {
85BatteryItem::~BatteryItem()93 m_addedHandler = g_signal_connect (m_client,
94 "device-added",
95 G_CALLBACK (::deviceChanged),
96 this /* user_data */);
97 }
98
99 if (!m_removedHandler) {
100 m_removedHandler = g_signal_connect (m_client,
101 "device-removed",
102 G_CALLBACK (::deviceChanged),
103 this /* user_data */);
104 }
105}
106
107void BatteryItem::up_disconnect()
86{108{
87 if (m_addedHandler) {109 if (m_addedHandler) {
88 g_signal_handler_disconnect (m_client, m_addedHandler);110 g_signal_handler_disconnect (m_client, m_addedHandler);
@@ -93,7 +115,16 @@
93 g_signal_handler_disconnect (m_client, m_removedHandler);115 g_signal_handler_disconnect (m_client, m_removedHandler);
94 m_removedHandler = 0;116 m_removedHandler = 0;
95 }117 }
96118}
119
120void BatteryItem::setVisibility(bool visible)
121{
122 setVisible(visible);
123}
124
125BatteryItem::~BatteryItem()
126{
127 up_disconnect();
97 g_object_unref (m_client);128 g_object_unref (m_client);
98}129}
99130
@@ -102,7 +133,6 @@
102{133{
103}134}
104135
105
106ItemBase *BatteryPlugin::createItem(const QVariantMap &staticData,136ItemBase *BatteryPlugin::createItem(const QVariantMap &staticData,
107 QObject *parent)137 QObject *parent)
108{138{

Subscribers

People subscribed via source and target branches