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
1=== modified file 'libunity-2d-private/src/abstractdbusservicemonitor.cpp'
2--- libunity-2d-private/src/abstractdbusservicemonitor.cpp 2011-11-17 21:40:33 +0000
3+++ libunity-2d-private/src/abstractdbusservicemonitor.cpp 2012-02-08 15:38:26 +0000
4@@ -26,13 +26,21 @@
5 AbstractDBusServiceMonitor::AbstractDBusServiceMonitor(QString service, QString path,
6 QString interface, QObject *parent)
7 : QObject(parent)
8- , m_enabled(false)
9 , m_service(service)
10 , m_path(path)
11 , m_interface(interface)
12 , m_watcher(new QDBusServiceWatcher(service, QDBusConnection::sessionBus()))
13 , m_dbusInterface(0)
14 {
15+ connect(m_watcher, SIGNAL(serviceRegistered(QString)), SLOT(createInterface()));
16+ connect(m_watcher, SIGNAL(serviceUnregistered(QString)), SLOT(destroyInterface()));
17+
18+ // Connect to the service if it's up already
19+ QDBusConnectionInterface* sessionBus = QDBusConnection::sessionBus().interface();
20+ QDBusReply<bool> reply = sessionBus->isServiceRegistered(m_service);
21+ if (reply.isValid() && reply.value()) {
22+ createInterface();
23+ }
24 }
25
26 AbstractDBusServiceMonitor::~AbstractDBusServiceMonitor()
27@@ -43,62 +51,26 @@
28 }
29 }
30
31-bool AbstractDBusServiceMonitor::enabled() const
32-{
33- return m_enabled;
34-}
35-
36-/* We don't do this in the constructor because if the service is already up we emit the
37- serviceStateChanged() signal during the constructor and we lose it since we can't have any slot
38- connected to it already */
39-
40-void AbstractDBusServiceMonitor::setEnabled(bool enabled)
41-{
42- if (m_enabled != enabled) {
43- if (enabled) {
44- connect(m_watcher, SIGNAL(serviceRegistered(QString)), SLOT(createInterface(QString)));
45- connect(m_watcher, SIGNAL(serviceUnregistered(QString)), SLOT(destroyInterface(QString)));
46-
47- // Connect to the service if it's up already
48- QDBusConnectionInterface* sessionBus = QDBusConnection::sessionBus().interface();
49- QDBusReply<bool> reply = sessionBus->isServiceRegistered(m_service);
50- if (reply.isValid() && reply.value()) {
51- createInterface(m_service);
52- }
53- } else {
54- if (m_dbusInterface != 0) {
55- delete m_dbusInterface;
56- m_dbusInterface = 0;
57- }
58- m_watcher->disconnect(this);
59- }
60-
61- m_enabled = enabled;
62- }
63-}
64-
65-void AbstractDBusServiceMonitor::createInterface(QString service)
66+void AbstractDBusServiceMonitor::createInterface()
67 {
68 if (m_dbusInterface != 0) {
69 delete m_dbusInterface;
70 m_dbusInterface = 0;
71 }
72
73- m_dbusInterface = new QDBusInterface(service, m_path, m_interface,
74+ m_dbusInterface = new QDBusInterface(m_service, m_path, m_interface,
75 QDBusConnection::sessionBus());
76- Q_EMIT serviceStateChanged(true);
77+ Q_EMIT serviceAvailableChanged(true);
78 }
79
80-void AbstractDBusServiceMonitor::destroyInterface(QString service)
81+void AbstractDBusServiceMonitor::destroyInterface()
82 {
83- Q_UNUSED(service);
84-
85 if (m_dbusInterface != 0) {
86 delete m_dbusInterface;
87 m_dbusInterface = 0;
88 }
89
90- Q_EMIT serviceStateChanged(false);
91+ Q_EMIT serviceAvailableChanged(false);
92 }
93
94 QDBusInterface* AbstractDBusServiceMonitor::dbusInterface() const
95@@ -106,4 +78,9 @@
96 return m_dbusInterface;
97 }
98
99+bool AbstractDBusServiceMonitor::serviceAvailable() const
100+{
101+ return m_dbusInterface != 0;
102+}
103+
104 #include "abstractdbusservicemonitor.moc"
105
106=== modified file 'libunity-2d-private/src/abstractdbusservicemonitor.h'
107--- libunity-2d-private/src/abstractdbusservicemonitor.h 2011-11-17 21:40:33 +0000
108+++ libunity-2d-private/src/abstractdbusservicemonitor.h 2012-02-08 15:38:26 +0000
109@@ -30,28 +30,25 @@
110 class AbstractDBusServiceMonitor : public QObject
111 {
112 Q_OBJECT
113- Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
114+ Q_PROPERTY(bool serviceAvailable READ serviceAvailable NOTIFY serviceAvailableChanged)
115
116 public:
117 explicit AbstractDBusServiceMonitor(QString service, QString path, QString interface,
118 QObject *parent = 0);
119 ~AbstractDBusServiceMonitor();
120
121- void setEnabled(bool enabled);
122- bool enabled() const;
123-
124 QDBusInterface* dbusInterface() const;
125
126+ bool serviceAvailable() const;
127+
128 Q_SIGNALS:
129- void enabledChanged(bool enabled);
130- void serviceStateChanged(bool available);
131+ void serviceAvailableChanged(bool available);
132
133 private Q_SLOTS:
134- void createInterface(QString);
135- void destroyInterface(QString);
136+ void createInterface();
137+ void destroyInterface();
138
139 protected:
140- bool m_enabled;
141 QString m_service;
142 QString m_path;
143 QString m_interface;
144
145=== modified file 'libunity-2d-private/src/spreadmonitor.cpp'
146--- libunity-2d-private/src/spreadmonitor.cpp 2011-11-17 21:40:33 +0000
147+++ libunity-2d-private/src/spreadmonitor.cpp 2012-02-08 15:38:26 +0000
148@@ -30,10 +30,14 @@
149 : AbstractDBusServiceMonitor("com.canonical.Unity2d.Spread", "/Spread",
150 "com.canonical.Unity2d.Spread", parent)
151 {
152- connect(this, SIGNAL(serviceStateChanged(bool)), SLOT(onServiceStateChanged(bool)));
153+ connect(this, SIGNAL(serviceAvailableChanged(bool)), SLOT(onServiceAvailableChanged(bool)));
154+
155+ if (serviceAvailable()) {
156+ onServiceAvailableChanged(true);
157+ }
158 }
159
160-void SpreadMonitor::onServiceStateChanged(bool available)
161+void SpreadMonitor::onServiceAvailableChanged(bool available)
162 {
163 if (available) {
164 connect(dbusInterface(), SIGNAL(IsShownChanged(bool)), SIGNAL(shownChanged(bool)));
165
166=== modified file 'libunity-2d-private/src/spreadmonitor.h'
167--- libunity-2d-private/src/spreadmonitor.h 2011-11-17 21:40:33 +0000
168+++ libunity-2d-private/src/spreadmonitor.h 2012-02-08 15:38:26 +0000
169@@ -37,7 +37,7 @@
170 bool shown() const;
171
172 protected Q_SLOTS:
173- void onServiceStateChanged(bool available);
174+ void onServiceAvailableChanged(bool available);
175
176 Q_SIGNALS:
177 void shownChanged(bool visible);
178
179=== modified file 'shell/Shell.qml'
180--- shell/Shell.qml 2012-02-08 11:45:09 +0000
181+++ shell/Shell.qml 2012-02-08 15:38:26 +0000
182@@ -67,7 +67,6 @@
183
184 SpreadMonitor {
185 id: spread
186- enabled: true
187 onShownChanged: if (shown) {
188 /* The the spread grabs input and Qt can't properly
189 detect we've lost input, so explicitly hide the menus */

Subscribers

People subscribed via source and target branches