瀏覽代碼

added some checks and a destructor for SystemdCommunicator class

maldela 7 年之前
父節點
當前提交
17a1bfee37
共有 2 個文件被更改,包括 13 次插入0 次删除
  1. 12 0
      import/src/systemdcommunicator.cpp
  2. 1 0
      import/src/systemdcommunicator.h

+ 12 - 0
import/src/systemdcommunicator.cpp

@@ -75,6 +75,9 @@ SystemdCommunicator::SystemdCommunicator(GUIBase *parent, const QString &service
                                           this)),
     m_serviceInterface(Q_NULLPTR)
 {
+    if (!m_managerInterface)
+        emit error(i18n("Unable to init systemd dbus manager interface!"), true);
+
     if (parent)
     {
         connect(this, &SystemdCommunicator::error, parent, &GUIBase::handleError);
@@ -95,6 +98,12 @@ SystemdCommunicator::SystemdCommunicator(GUIBase *parent, const QString &service
     emit serviceEnabledChanged();
 }
 
+SystemdCommunicator::~SystemdCommunicator()
+{
+    delete m_managerInterface;
+    delete m_serviceInterface;
+}
+
 void SystemdCommunicator::setServiceName(const QString &name)
 {
     if (name != m_serviceName)
@@ -132,6 +141,9 @@ void SystemdCommunicator::setServiceName(const QString &name)
                                                         QStringLiteral("org.freedesktop.systemd1.Unit"),
                                                         QDBusConnection::systemBus(),
                                                         this);
+                if (!m_serviceInterface)
+                    emit error(i18n("Unable to init systemd dbus service interface!"), true);
+
                 QDBusConnection::systemBus().connect(QStringLiteral("org.freedesktop.systemd1"),
                                                      m_serviceObjectPath,
                                                      QStringLiteral("org.freedesktop.DBus.Properties"),

+ 1 - 0
import/src/systemdcommunicator.h

@@ -46,6 +46,7 @@ class SystemdCommunicator : public QObject
 public:
 
     explicit SystemdCommunicator(GUIBase *parent = Q_NULLPTR, const QString &serviceName = QString());
+    virtual ~SystemdCommunicator();
 
     QString serviceName() const { return m_serviceName; }
     void setServiceName(const QString &name);