#include "bus.h" #include static const QString SERVICE_NAME("de.bwlehrpool.beamergui"); Bus* Bus::_instance = nullptr; Bus::Bus(QObject *parent) : QObject(parent), _hasListener(false) { } bool Bus::registerListener() { QList cons = {QDBusConnection::systemBus(), QDBusConnection::sessionBus()}; int index = 0; // 0 == system, 1 == session for (auto con : cons) { if (!con.isConnected()) { qDebug() << "Cannot connect to" << con.name(); } else { QDBusServiceWatcher *w = new QDBusServiceWatcher(SERVICE_NAME, con); w->setParent(this); connect(w, &QDBusServiceWatcher::serviceRegistered, [=](const QString & /* service */) { emit serviceConnected(index == 1); }); } ++index; } return true; } /** * Try to grab the service name on either the system or the session * bus. This signals the listening beamergui (if any) that it should show * up again. */ bool Bus::registerService() { bool ok = false; QList cons = {QDBusConnection::systemBus(), QDBusConnection::sessionBus()}; for (auto con : cons) { if (!con.isConnected()) { qDebug() << "Cannot connect to" << con.name(); } else { if (con.registerService(SERVICE_NAME)) { ok = true; } else { qDebug() << con.lastError().message(); } } } return ok; }