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)));
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);
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();
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();
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();
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();
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);