on xenial help sign in
Small tweaks to AbstractDBusServiceMonitor to use Qt5 and C++11 features
7126ce1Gerry Boland
src/libunity8-utils/abstractdbusservicemonitor.cpp+12−10
@@ -19,6 +19,8 @@
19
19
20#include "abstractdbusservicemonitor.h"
20#include "abstractdbusservicemonitor.h"
21
21
22+#include <QDBusInterface>
23+#include <QDBusServiceWatcher>
22#include <QDBusConnection>
24#include <QDBusConnection>
23#include <QDBusConnectionInterface>
25#include <QDBusConnectionInterface>
24#include <QDBusReply>
26#include <QDBusReply>
@@ -32,14 +34,14 @@ AbstractDBusServiceMonitor::AbstractDBusServiceMonitor(QString service, QString
32 , m_watcher(new QDBusServiceWatcher(service, QDBusConnection::sessionBus()))
34 , m_watcher(new QDBusServiceWatcher(service, QDBusConnection::sessionBus()))
33 , m_dbusInterface(0)
35 , m_dbusInterface(0)
34{
36{
35− connect(m_watcher, SIGNAL(serviceRegistered(QString)), SLOT(createInterface()));
37+ connect(m_watcher, &QDBusServiceWatcher::serviceRegistered, this, &AbstractDBusServiceMonitor::createInterface);
36− connect(m_watcher, SIGNAL(serviceUnregistered(QString)), SLOT(destroyInterface()));
38+ connect(m_watcher, &QDBusServiceWatcher::serviceUnregistered, this, &AbstractDBusServiceMonitor::destroyInterface);
37
39
38 // Connect to the service if it's up already
40 // Connect to the service if it's up already
39 QDBusConnectionInterface* sessionBus = QDBusConnection::sessionBus().interface();
41 QDBusConnectionInterface* sessionBus = QDBusConnection::sessionBus().interface();
40 QDBusReply<bool> reply = sessionBus->isServiceRegistered(m_service);
42 QDBusReply<bool> reply = sessionBus->isServiceRegistered(m_service);
41 if (reply.isValid() && reply.value()) {
43 if (reply.isValid() && reply.value()) {
42− createInterface();
44+ createInterface(m_service);
43 }
45 }
44}
46}
45
47
@@ -51,11 +53,11 @@ AbstractDBusServiceMonitor::~AbstractDBusServiceMonitor()
51 }
53 }
52}
54}
53
55
54−void AbstractDBusServiceMonitor::createInterface()
56+void AbstractDBusServiceMonitor::createInterface(const QString &)
55{
57{
56− if (m_dbusInterface != 0) {
58+ if (m_dbusInterface != nullptr) {
57 delete m_dbusInterface;
59 delete m_dbusInterface;
58− m_dbusInterface = 0;
60+ m_dbusInterface = nullptr;
59 }
61 }
60
62
61 m_dbusInterface = new QDBusInterface(m_service, m_path, m_interface,
63 m_dbusInterface = new QDBusInterface(m_service, m_path, m_interface,
@@ -63,11 +65,11 @@ void AbstractDBusServiceMonitor::createInterface()
63 Q_EMIT serviceAvailableChanged(true);
65 Q_EMIT serviceAvailableChanged(true);
64}
66}
65
67
66−void AbstractDBusServiceMonitor::destroyInterface()
68+void AbstractDBusServiceMonitor::destroyInterface(const QString &)
67{
69{
68− if (m_dbusInterface != 0) {
70+ if (m_dbusInterface != nullptr) {
69 delete m_dbusInterface;
71 delete m_dbusInterface;
70− m_dbusInterface = 0;
72+ m_dbusInterface = nullptr;
71 }
73 }
72
74
73 Q_EMIT serviceAvailableChanged(false);
75 Q_EMIT serviceAvailableChanged(false);
@@ -80,5 +82,5 @@ QDBusInterface* AbstractDBusServiceMonitor::dbusInterface() const
80
82
81bool AbstractDBusServiceMonitor::serviceAvailable() const
83bool AbstractDBusServiceMonitor::serviceAvailable() const
82{
84{
83− return m_dbusInterface != 0;
85+ return m_dbusInterface != nullptr;
84}
86}
src/libunity8-utils/abstractdbusservicemonitor.h+5−6
@@ -20,13 +20,12 @@
20#ifndef ABSTRACTDBUSSERVICEMONITOR_H
20#ifndef ABSTRACTDBUSSERVICEMONITOR_H
21#define ABSTRACTDBUSSERVICEMONITOR_H
21#define ABSTRACTDBUSSERVICEMONITOR_H
22
22
23−#include <QObject>
24−
25−#include <QDBusInterface>
26−#include <QDBusServiceWatcher>
27#include <QObject>
23#include <QObject>
28#include <QString>
24#include <QString>
29
25
26+class QDBusInterface;
27+class QDBusServiceWatcher;
28+
30class AbstractDBusServiceMonitor : public QObject
29class AbstractDBusServiceMonitor : public QObject
31{
30{
32 Q_OBJECT
31 Q_OBJECT
@@ -45,8 +44,8 @@ Q_SIGNALS:
45 void serviceAvailableChanged(bool available);
44 void serviceAvailableChanged(bool available);
46
45
47private Q_SLOTS:
46private Q_SLOTS:
48− void createInterface();
47+ void createInterface(const QString&);
49− void destroyInterface();
48+ void destroyInterface(const QString&);
50
49
51protected:
50protected:
52 QString m_service;
51 QString m_service;