Merge lp:~aacid/unity-2d/unity-2d-shell_abstractdbusmonitor_improvements into lp:~unity-2d-team/unity-2d/unity-2d-shell

Proposed by Albert Astals Cid
Status: Merged
Approved by: Florian Boucault
Approved revision: 991
Merged at revision: 991
Proposed branch: lp:~aacid/unity-2d/unity-2d-shell_abstractdbusmonitor_improvements
Merge into: lp:~unity-2d-team/unity-2d/unity-2d-shell
Diff against target: 189 lines (+32/-55)
5 files modified
libunity-2d-private/src/abstractdbusservicemonitor.cpp (+19/-42)
libunity-2d-private/src/abstractdbusservicemonitor.h (+6/-9)
libunity-2d-private/src/spreadmonitor.cpp (+6/-2)
libunity-2d-private/src/spreadmonitor.h (+1/-1)
shell/Shell.qml (+0/-1)
To merge this branch: bzr merge lp:~aacid/unity-2d/unity-2d-shell_abstractdbusmonitor_improvements
Reviewer Review Type Date Requested Status
Ugo Riboni Pending
Florian Boucault Pending
Review via email: mp+92044@code.launchpad.net

Description of the change

Remove the enabled and add the serviceState properties to AbstractDBusServiceMonitor

To post a comment you must log in.
Revision history for this message
Albert Astals Cid (aacid) wrote :

Tested with the Spread already up and the QueuedConnection does the trick nicely

989. By Albert Astals Cid

serviceState -> serviceAvailable

990. By Albert Astals Cid

The team did not like the QueuedConnection solution

991. By Albert Astals Cid

Florian prefers it in this order

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libunity-2d-private/src/abstractdbusservicemonitor.cpp'
--- libunity-2d-private/src/abstractdbusservicemonitor.cpp 2011-11-17 21:40:33 +0000
+++ libunity-2d-private/src/abstractdbusservicemonitor.cpp 2012-02-08 15:38:26 +0000
@@ -26,13 +26,21 @@
26AbstractDBusServiceMonitor::AbstractDBusServiceMonitor(QString service, QString path,26AbstractDBusServiceMonitor::AbstractDBusServiceMonitor(QString service, QString path,
27 QString interface, QObject *parent)27 QString interface, QObject *parent)
28 : QObject(parent)28 : QObject(parent)
29 , m_enabled(false)
30 , m_service(service)29 , m_service(service)
31 , m_path(path)30 , m_path(path)
32 , m_interface(interface)31 , m_interface(interface)
33 , m_watcher(new QDBusServiceWatcher(service, QDBusConnection::sessionBus()))32 , m_watcher(new QDBusServiceWatcher(service, QDBusConnection::sessionBus()))
34 , m_dbusInterface(0)33 , m_dbusInterface(0)
35{34{
35 connect(m_watcher, SIGNAL(serviceRegistered(QString)), SLOT(createInterface()));
36 connect(m_watcher, SIGNAL(serviceUnregistered(QString)), SLOT(destroyInterface()));
37
38 // Connect to the service if it's up already
39 QDBusConnectionInterface* sessionBus = QDBusConnection::sessionBus().interface();
40 QDBusReply<bool> reply = sessionBus->isServiceRegistered(m_service);
41 if (reply.isValid() && reply.value()) {
42 createInterface();
43 }
36}44}
3745
38AbstractDBusServiceMonitor::~AbstractDBusServiceMonitor()46AbstractDBusServiceMonitor::~AbstractDBusServiceMonitor()
@@ -43,62 +51,26 @@
43 }51 }
44}52}
4553
46bool AbstractDBusServiceMonitor::enabled() const54void AbstractDBusServiceMonitor::createInterface()
47{
48 return m_enabled;
49}
50
51/* We don't do this in the constructor because if the service is already up we emit the
52 serviceStateChanged() signal during the constructor and we lose it since we can't have any slot
53 connected to it already */
54
55void AbstractDBusServiceMonitor::setEnabled(bool enabled)
56{
57 if (m_enabled != enabled) {
58 if (enabled) {
59 connect(m_watcher, SIGNAL(serviceRegistered(QString)), SLOT(createInterface(QString)));
60 connect(m_watcher, SIGNAL(serviceUnregistered(QString)), SLOT(destroyInterface(QString)));
61
62 // Connect to the service if it's up already
63 QDBusConnectionInterface* sessionBus = QDBusConnection::sessionBus().interface();
64 QDBusReply<bool> reply = sessionBus->isServiceRegistered(m_service);
65 if (reply.isValid() && reply.value()) {
66 createInterface(m_service);
67 }
68 } else {
69 if (m_dbusInterface != 0) {
70 delete m_dbusInterface;
71 m_dbusInterface = 0;
72 }
73 m_watcher->disconnect(this);
74 }
75
76 m_enabled = enabled;
77 }
78}
79
80void AbstractDBusServiceMonitor::createInterface(QString service)
81{55{
82 if (m_dbusInterface != 0) {56 if (m_dbusInterface != 0) {
83 delete m_dbusInterface;57 delete m_dbusInterface;
84 m_dbusInterface = 0;58 m_dbusInterface = 0;
85 }59 }
8660
87 m_dbusInterface = new QDBusInterface(service, m_path, m_interface,61 m_dbusInterface = new QDBusInterface(m_service, m_path, m_interface,
88 QDBusConnection::sessionBus());62 QDBusConnection::sessionBus());
89 Q_EMIT serviceStateChanged(true);63 Q_EMIT serviceAvailableChanged(true);
90}64}
9165
92void AbstractDBusServiceMonitor::destroyInterface(QString service)66void AbstractDBusServiceMonitor::destroyInterface()
93{67{
94 Q_UNUSED(service);
95
96 if (m_dbusInterface != 0) {68 if (m_dbusInterface != 0) {
97 delete m_dbusInterface;69 delete m_dbusInterface;
98 m_dbusInterface = 0;70 m_dbusInterface = 0;
99 }71 }
10072
101 Q_EMIT serviceStateChanged(false);73 Q_EMIT serviceAvailableChanged(false);
102}74}
10375
104QDBusInterface* AbstractDBusServiceMonitor::dbusInterface() const76QDBusInterface* AbstractDBusServiceMonitor::dbusInterface() const
@@ -106,4 +78,9 @@
106 return m_dbusInterface;78 return m_dbusInterface;
107}79}
10880
81bool AbstractDBusServiceMonitor::serviceAvailable() const
82{
83 return m_dbusInterface != 0;
84}
85
109#include "abstractdbusservicemonitor.moc"86#include "abstractdbusservicemonitor.moc"
11087
=== modified file 'libunity-2d-private/src/abstractdbusservicemonitor.h'
--- libunity-2d-private/src/abstractdbusservicemonitor.h 2011-11-17 21:40:33 +0000
+++ libunity-2d-private/src/abstractdbusservicemonitor.h 2012-02-08 15:38:26 +0000
@@ -30,28 +30,25 @@
30class AbstractDBusServiceMonitor : public QObject30class AbstractDBusServiceMonitor : public QObject
31{31{
32 Q_OBJECT32 Q_OBJECT
33 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)33 Q_PROPERTY(bool serviceAvailable READ serviceAvailable NOTIFY serviceAvailableChanged)
3434
35public:35public:
36 explicit AbstractDBusServiceMonitor(QString service, QString path, QString interface,36 explicit AbstractDBusServiceMonitor(QString service, QString path, QString interface,
37 QObject *parent = 0);37 QObject *parent = 0);
38 ~AbstractDBusServiceMonitor();38 ~AbstractDBusServiceMonitor();
3939
40 void setEnabled(bool enabled);
41 bool enabled() const;
42
43 QDBusInterface* dbusInterface() const;40 QDBusInterface* dbusInterface() const;
4441
42 bool serviceAvailable() const;
43
45Q_SIGNALS:44Q_SIGNALS:
46 void enabledChanged(bool enabled);45 void serviceAvailableChanged(bool available);
47 void serviceStateChanged(bool available);
4846
49private Q_SLOTS:47private Q_SLOTS:
50 void createInterface(QString);48 void createInterface();
51 void destroyInterface(QString);49 void destroyInterface();
5250
53protected:51protected:
54 bool m_enabled;
55 QString m_service;52 QString m_service;
56 QString m_path;53 QString m_path;
57 QString m_interface;54 QString m_interface;
5855
=== modified file 'libunity-2d-private/src/spreadmonitor.cpp'
--- libunity-2d-private/src/spreadmonitor.cpp 2011-11-17 21:40:33 +0000
+++ libunity-2d-private/src/spreadmonitor.cpp 2012-02-08 15:38:26 +0000
@@ -30,10 +30,14 @@
30 : AbstractDBusServiceMonitor("com.canonical.Unity2d.Spread", "/Spread",30 : AbstractDBusServiceMonitor("com.canonical.Unity2d.Spread", "/Spread",
31 "com.canonical.Unity2d.Spread", parent)31 "com.canonical.Unity2d.Spread", parent)
32{32{
33 connect(this, SIGNAL(serviceStateChanged(bool)), SLOT(onServiceStateChanged(bool)));33 connect(this, SIGNAL(serviceAvailableChanged(bool)), SLOT(onServiceAvailableChanged(bool)));
34
35 if (serviceAvailable()) {
36 onServiceAvailableChanged(true);
37 }
34}38}
3539
36void SpreadMonitor::onServiceStateChanged(bool available)40void SpreadMonitor::onServiceAvailableChanged(bool available)
37{41{
38 if (available) {42 if (available) {
39 connect(dbusInterface(), SIGNAL(IsShownChanged(bool)), SIGNAL(shownChanged(bool)));43 connect(dbusInterface(), SIGNAL(IsShownChanged(bool)), SIGNAL(shownChanged(bool)));
4044
=== modified file 'libunity-2d-private/src/spreadmonitor.h'
--- libunity-2d-private/src/spreadmonitor.h 2011-11-17 21:40:33 +0000
+++ libunity-2d-private/src/spreadmonitor.h 2012-02-08 15:38:26 +0000
@@ -37,7 +37,7 @@
37 bool shown() const;37 bool shown() const;
3838
39protected Q_SLOTS:39protected Q_SLOTS:
40 void onServiceStateChanged(bool available);40 void onServiceAvailableChanged(bool available);
4141
42Q_SIGNALS:42Q_SIGNALS:
43 void shownChanged(bool visible);43 void shownChanged(bool visible);
4444
=== modified file 'shell/Shell.qml'
--- shell/Shell.qml 2012-02-08 11:45:09 +0000
+++ shell/Shell.qml 2012-02-08 15:38:26 +0000
@@ -67,7 +67,6 @@
6767
68 SpreadMonitor {68 SpreadMonitor {
69 id: spread69 id: spread
70 enabled: true
71 onShownChanged: if (shown) {70 onShownChanged: if (shown) {
72 /* The the spread grabs input and Qt can't properly71 /* The the spread grabs input and Qt can't properly
73 detect we've lost input, so explicitly hide the menus */72 detect we've lost input, so explicitly hide the menus */

Subscribers

People subscribed via source and target branches