on xenial help sign in
Small tweaks to AbstractDBusServiceMonitor to use Qt5 and C++11 features
commit7126ce14170d02be025243d1951a42a4c5b06dc5 authorGerry Boland <gerry.boland@canonical.com> dateThu 4 Sep 2014, 23:53 (12 years ago) parentdfee783
2 files changed+17−16
src/libunity8-utils/abstractdbusservicemonitor.cpp+12−10 src/libunity8-utils/abstractdbusservicemonitor.h+5−6
src/libunity8-utils/abstractdbusservicemonitor.cpp+12−10
@@ -19,6 +19,8 @@
1919
2020#include "abstractdbusservicemonitor.h"
2121
22+#include <QDBusInterface>
23+#include <QDBusServiceWatcher>
2224#include <QDBusConnection>
2325#include <QDBusConnectionInterface>
2426#include <QDBusReply>
@@ -32,14 +34,14 @@ AbstractDBusServiceMonitor::AbstractDBusServiceMonitor(QString service, QString
3234 , m_watcher(new QDBusServiceWatcher(service, QDBusConnection::sessionBus()))
3335 , m_dbusInterface(0)
3436{
35− connect(m_watcher, SIGNAL(serviceRegistered(QString)), SLOT(createInterface()));
36− connect(m_watcher, SIGNAL(serviceUnregistered(QString)), SLOT(destroyInterface()));
37+ connect(m_watcher, &QDBusServiceWatcher::serviceRegistered, this, &AbstractDBusServiceMonitor::createInterface);
38+ connect(m_watcher, &QDBusServiceWatcher::serviceUnregistered, this, &AbstractDBusServiceMonitor::destroyInterface);
3739
3840 // Connect to the service if it's up already
3941 QDBusConnectionInterface* sessionBus = QDBusConnection::sessionBus().interface();
4042 QDBusReply<bool> reply = sessionBus->isServiceRegistered(m_service);
4143 if (reply.isValid() && reply.value()) {
42− createInterface();
44+ createInterface(m_service);
4345 }
4446}
4547
@@ -51,11 +53,11 @@ AbstractDBusServiceMonitor::~AbstractDBusServiceMonitor()
5153 }
5254}
5355
54−void AbstractDBusServiceMonitor::createInterface()
56+void AbstractDBusServiceMonitor::createInterface(const QString &)
5557{
56− if (m_dbusInterface != 0) {
58+ if (m_dbusInterface != nullptr) {
5759 delete m_dbusInterface;
58− m_dbusInterface = 0;
60+ m_dbusInterface = nullptr;
5961 }
6062
6163 m_dbusInterface = new QDBusInterface(m_service, m_path, m_interface,
@@ -63,11 +65,11 @@ void AbstractDBusServiceMonitor::createInterface()
6365 Q_EMIT serviceAvailableChanged(true);
6466}
6567
66−void AbstractDBusServiceMonitor::destroyInterface()
68+void AbstractDBusServiceMonitor::destroyInterface(const QString &)
6769{
68− if (m_dbusInterface != 0) {
70+ if (m_dbusInterface != nullptr) {
6971 delete m_dbusInterface;
70− m_dbusInterface = 0;
72+ m_dbusInterface = nullptr;
7173 }
7274
7375 Q_EMIT serviceAvailableChanged(false);
@@ -80,5 +82,5 @@ QDBusInterface* AbstractDBusServiceMonitor::dbusInterface() const
8082
8183bool AbstractDBusServiceMonitor::serviceAvailable() const
8284{
83− return m_dbusInterface != 0;
85+ return m_dbusInterface != nullptr;
8486}
src/libunity8-utils/abstractdbusservicemonitor.h+5−6
@@ -20,13 +20,12 @@
2020#ifndef ABSTRACTDBUSSERVICEMONITOR_H
2121#define ABSTRACTDBUSSERVICEMONITOR_H
2222
23−#include <QObject>
24−
25−#include <QDBusInterface>
26−#include <QDBusServiceWatcher>
2723#include <QObject>
2824#include <QString>
2925
26+class QDBusInterface;
27+class QDBusServiceWatcher;
28+
3029class AbstractDBusServiceMonitor : public QObject
3130{
3231 Q_OBJECT
@@ -45,8 +44,8 @@ Q_SIGNALS:
4544 void serviceAvailableChanged(bool available);
4645
4746private Q_SLOTS:
48− void createInterface();
49− void destroyInterface();
47+ void createInterface(const QString&);
48+ void destroyInterface(const QString&);
5049
5150protected:
5251 QString m_service;