11#include <private/qproperty_p.h>
12#include <private/qobject_p.h>
13#include <private/qdbusconnection_p.h>
21 Q_DECLARE_PUBLIC(QDBusServiceWatcher)
38 q_func()->setWatchMode(mode);
41 &QDBusServiceWatcherPrivate::setWatchModeForwardToQ)
44 void setConnection(
const QStringList &newServices,
const QDBusConnection &newConnection,
45 QDBusServiceWatcher::WatchMode newMode);
47 void addService(
const QString &service, QDBusServiceWatcher::WatchMode mode);
48 void removeService(
const QString &service, QDBusServiceWatcher::WatchMode mode);
51void QDBusServiceWatcherPrivate::_q_serviceOwnerChanged(
const QString &service,
const QString &oldOwner,
const QString &newOwner)
53 Q_Q(QDBusServiceWatcher);
54 emit q->serviceOwnerChanged(service, oldOwner, newOwner);
55 if (oldOwner.isEmpty())
56 emit q->serviceRegistered(service);
57 else if (newOwner.isEmpty())
58 emit q->serviceUnregistered(service);
62 const QDBusConnection &newConnection,
63 QDBusServiceWatcher::WatchMode newMode)
65 const QStringList oldServices = watchedServicesData.valueBypassingBindings();
66 const QDBusServiceWatcher::WatchMode oldMode = watchMode.valueBypassingBindings();
67 if (connection.isConnected()) {
69 for (
const QString &s : oldServices)
70 removeService(s, oldMode);
73 connection = newConnection;
74 watchMode.setValueBypassingBindings(newMode);
75 watchedServicesData.setValueBypassingBindings(newServices);
77 if (connection.isConnected()) {
79 for (
const QString &s : newServices)
80 addService(s, newMode);
85 QDBusServiceWatcher::WatchMode mode)
87 QDBusConnectionPrivate *d = QDBusConnectionPrivate::d(connection);
88 if (d && d->shouldWatchService(service))
89 d->watchService(service, mode, q_func(), SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
93 QDBusServiceWatcher::WatchMode mode)
95 QDBusConnectionPrivate *d = QDBusConnectionPrivate::d(connection);
96 if (d && d->shouldWatchService(service))
97 d->unwatchService(service, mode, q_func(), SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
141
142
143
144
145
146
147
148
149
150
151
152
153
156
157
158
159
160
161
164
165
166
167
168
169
170
173
174
175
176
177
178
179
182
183
184
185
186
187
188
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
212
213
214
215
216
217
218QDBusServiceWatcher::QDBusServiceWatcher(QObject *parent)
219 : QObject(*
new QDBusServiceWatcherPrivate(QDBusConnection(QString()), WatchForOwnerChange), parent)
224
225
226
227
228
229
230
231QDBusServiceWatcher::QDBusServiceWatcher(
const QString &service,
const QDBusConnection &connection, WatchMode watchMode, QObject *parent)
232 : QObject(*
new QDBusServiceWatcherPrivate(connection, watchMode), parent)
234 d_func()->setConnection(QStringList() << service, connection, watchMode);
238
239
240
241QDBusServiceWatcher::~QDBusServiceWatcher()
246
247
248
249
250QStringList QDBusServiceWatcher::watchedServices()
const
252 return d_func()->watchedServicesData;
256
257
258
259
260
261
262
263
264
265void QDBusServiceWatcher::setWatchedServices(
const QStringList &services)
267 Q_D(QDBusServiceWatcher);
268 d->watchedServicesData.removeBindingUnlessInWrapper();
269 if (services == d->watchedServicesData.valueBypassingBindings())
272 d->setConnection(services, d->connection, d->watchMode);
273 d->watchedServicesData.notify();
276QBindable<QStringList> QDBusServiceWatcher::bindableWatchedServices()
278 Q_D(QDBusServiceWatcher);
279 return &d->watchedServicesData;
283
284
285
286
287
288
289void QDBusServiceWatcher::addWatchedService(
const QString &newService)
291 Q_D(QDBusServiceWatcher);
292 d->watchedServicesData.removeBindingUnlessInWrapper();
293 auto services = d->watchedServicesData.valueBypassingBindings();
294 if (services.contains(newService))
297 d->addService(newService, d->watchMode);
299 services << newService;
300 d->watchedServicesData.setValueBypassingBindings(services);
302 d->watchedServicesData.notify();
306
307
308
309
310
311
312
313
314
315bool QDBusServiceWatcher::removeWatchedService(
const QString &service)
317 Q_D(QDBusServiceWatcher);
318 d->watchedServicesData.removeBindingUnlessInWrapper();
319 auto tempList = d->watchedServicesData.valueBypassingBindings();
320 const bool result = tempList.removeOne(service);
325 d->removeService(service, d->watchMode);
326 d->watchedServicesData.setValueBypassingBindings(tempList);
327 d->watchedServicesData.notify();
331QDBusServiceWatcher::WatchMode QDBusServiceWatcher::watchMode()
const
333 return d_func()->watchMode;
336QBindable<QDBusServiceWatcher::WatchMode> QDBusServiceWatcher::bindableWatchMode()
338 return &d_func()->watchMode;
341void QDBusServiceWatcher::setWatchMode(WatchMode mode)
343 Q_D(QDBusServiceWatcher);
344 d->watchMode.removeBindingUnlessInWrapper();
345 if (mode == d->watchMode.valueBypassingBindings())
348 d->setConnection(d->watchedServicesData, d->connection, mode);
349 d->watchMode.notify();
353
354
355
356
357QDBusConnection QDBusServiceWatcher::connection()
const
359 return d_func()->connection;
363
364
365
366
367
368
369
370
371
372
373
374void QDBusServiceWatcher::setConnection(
const QDBusConnection &connection)
376 Q_D(QDBusServiceWatcher);
377 if (connection.name() == d->connection.name())
379 d->setConnection(d->watchedServicesData, connection, d->watchMode);
386#include "moc_qdbusservicewatcher.cpp"
const QString const QString &void setConnection(const QStringList &newServices, const QDBusConnection &newConnection, QDBusServiceWatcher::WatchMode newMode)
void setWatchModeForwardToQ(QDBusServiceWatcher::WatchMode mode)
Q_OBJECT_COMPAT_PROPERTY(QDBusServiceWatcherPrivate, QDBusServiceWatcher::WatchMode, watchMode, &QDBusServiceWatcherPrivate::setWatchModeForwardToQ) void _q_serviceOwnerChanged(const QString &
void removeService(const QString &service, QDBusServiceWatcher::WatchMode mode)
void addService(const QString &service, QDBusServiceWatcher::WatchMode mode)
Combined button and popup list for selecting options.