blob: 1a722c1d66ecad64d05d9e6299381922d30978e9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include "bus.h"
#include <QtDBus/QtDBus>
static const QString SERVICE_NAME("de.bwlehrpool.beamergui");
Bus* Bus::_instance = nullptr;
Bus::Bus(QObject *parent) : QObject(parent), _hasListener(false)
{
}
bool Bus::registerListener()
{
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;
}
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<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();
}
}
}
return ok;
}
|