26
26
AbstractDBusServiceMonitor::AbstractDBusServiceMonitor(QString service, QString path,
27
27
QString interface, QObject *parent)
30
29
, m_service(service)
32
31
, m_interface(interface)
33
32
, m_watcher(new QDBusServiceWatcher(service, QDBusConnection::sessionBus()))
34
33
, m_dbusInterface(0)
35
connect(m_watcher, SIGNAL(serviceRegistered(QString)), SLOT(createInterface()));
36
connect(m_watcher, SIGNAL(serviceUnregistered(QString)), SLOT(destroyInterface()));
38
// Connect to the service if it's up already
39
QDBusConnectionInterface* sessionBus = QDBusConnection::sessionBus().interface();
40
QDBusReply<bool> reply = sessionBus->isServiceRegistered(m_service);
41
if (reply.isValid() && reply.value()) {
38
46
AbstractDBusServiceMonitor::~AbstractDBusServiceMonitor()
46
bool AbstractDBusServiceMonitor::enabled() const
51
/* We don't do this in the constructor because if the service is already up we emit the
52
serviceStateChanged() signal during the constructor and we lose it since we can't have any slot
53
connected to it already */
55
void AbstractDBusServiceMonitor::setEnabled(bool enabled)
57
if (m_enabled != enabled) {
59
connect(m_watcher, SIGNAL(serviceRegistered(QString)), SLOT(createInterface(QString)));
60
connect(m_watcher, SIGNAL(serviceUnregistered(QString)), SLOT(destroyInterface(QString)));
62
// Connect to the service if it's up already
63
QDBusConnectionInterface* sessionBus = QDBusConnection::sessionBus().interface();
64
QDBusReply<bool> reply = sessionBus->isServiceRegistered(m_service);
65
if (reply.isValid() && reply.value()) {
66
createInterface(m_service);
69
if (m_dbusInterface != 0) {
70
delete m_dbusInterface;
73
m_watcher->disconnect(this);
80
void AbstractDBusServiceMonitor::createInterface(QString service)
54
void AbstractDBusServiceMonitor::createInterface()
82
56
if (m_dbusInterface != 0) {
83
57
delete m_dbusInterface;
84
58
m_dbusInterface = 0;
87
m_dbusInterface = new QDBusInterface(service, m_path, m_interface,
61
m_dbusInterface = new QDBusInterface(m_service, m_path, m_interface,
88
62
QDBusConnection::sessionBus());
89
Q_EMIT serviceStateChanged(true);
63
Q_EMIT serviceAvailableChanged(true);
92
void AbstractDBusServiceMonitor::destroyInterface(QString service)
66
void AbstractDBusServiceMonitor::destroyInterface()
96
68
if (m_dbusInterface != 0) {
97
69
delete m_dbusInterface;
98
70
m_dbusInterface = 0;
101
Q_EMIT serviceStateChanged(false);
73
Q_EMIT serviceAvailableChanged(false);
104
76
QDBusInterface* AbstractDBusServiceMonitor::dbusInterface() const