summaryrefslogtreecommitdiffstats
path: root/src/bus.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bus.cpp')
-rw-r--r--src/bus.cpp48
1 files changed, 31 insertions, 17 deletions
diff --git a/src/bus.cpp b/src/bus.cpp
index 1dadedb..1a722c1 100644
--- a/src/bus.cpp
+++ b/src/bus.cpp
@@ -13,28 +13,42 @@ Bus::Bus(QObject *parent) : QObject(parent), _hasListener(false)
bool Bus::registerListener()
{
- if (!QDBusConnection::systemBus().isConnected()) {
- qDebug() << "Cannot connect to system bus";
- return false;
+ QList<QDBusConnection> 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;
}
- QDBusServiceWatcher *w = new QDBusServiceWatcher("de.bwlehrpool.beamergui", QDBusConnection::systemBus());
- w->setParent(this);
- connect(w, &QDBusServiceWatcher::serviceRegistered, [=](const QString &service) {
- qDebug() << "Registered Service" << service;
- emit serviceConnected();
- });
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()
{
- if (!QDBusConnection::systemBus().isConnected()) {
- qDebug() << "Cannot connect to system bus";
- return false;
+ bool ok = false;
+ QList<QDBusConnection> 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();
+ }
+ }
}
- if (!QDBusConnection::systemBus().registerService(SERVICE_NAME)) {
- qDebug() << QDBusConnection::systemBus().lastError().message();
- return false;
- }
- return true;
+ return ok;
}