aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/systeminfo
diff options
context:
space:
mode:
authorLukáš Tinkl <ltinkl@luxoft.com>2018-02-07 14:31:44 +0100
committerDaniel d'Andrada <daniel.dandrada@luxoft.com>2018-02-28 15:58:33 +0100
commitdc75d2218d97d0b508b469d6b56a7318358d2577 (patch)
tree6d77e56492c8671b4e7d3f7ffd6ae4c676153416 /plugins/systeminfo
parent5cb14831da8f0389a28c1605e032bb2ec8b629fb (diff)
[sysinfo] add online property to detect network status
Diffstat (limited to 'plugins/systeminfo')
-rw-r--r--plugins/systeminfo/systeminfo.cpp41
-rw-r--r--plugins/systeminfo/systeminfo.h9
-rw-r--r--plugins/systeminfo/systeminfo.pro2
3 files changed, 49 insertions, 3 deletions
diff --git a/plugins/systeminfo/systeminfo.cpp b/plugins/systeminfo/systeminfo.cpp
index 773fbc91..bca9a8e8 100644
--- a/plugins/systeminfo/systeminfo.cpp
+++ b/plugins/systeminfo/systeminfo.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 Pelagicore AG
+** Copyright (C) 2017-2018 Pelagicore AG
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Neptune IVI UI.
@@ -30,8 +30,16 @@
****************************************************************************/
#include <QNetworkInterface>
+
+#include <QDBusConnection>
+#include <QDBusPendingReply>
+
#include "systeminfo.h"
+#define NM_SERVICE QStringLiteral("org.freedesktop.NetworkManager")
+#define NM_PATH QStringLiteral("/org/freedesktop/NetworkManager")
+#define NM_IFACE QStringLiteral("org.freedesktop.NetworkManager")
+
SystemInfo::SystemInfo(QObject *parent)
: QObject(parent)
{
@@ -61,13 +69,44 @@ void SystemInfo::getAddress()
}
}
+void SystemInfo::updateOnlineStatus(quint32 state)
+{
+ const bool online = state == 70; // NM_STATE_CONNECTED_GLOBAL
+ if (online != m_online) {
+ m_online = online;
+ emit onlineChanged();
+ }
+}
+
QStringList SystemInfo::addressList() const
{
return m_addressList;
}
+bool SystemInfo::online() const
+{
+ return m_online;
+}
+
void SystemInfo::classBegin()
{
+ auto conn = QDBusConnection::systemBus();
+ conn.connect(NM_SERVICE, NM_PATH, NM_IFACE, QStringLiteral("StateChanged"),
+ this, SLOT(updateOnlineStatus(quint32)));
+
+
+ QDBusMessage msg = QDBusMessage::createMethodCall(NM_SERVICE, NM_PATH, NM_IFACE, QStringLiteral("state"));
+ QDBusPendingCall pCall = conn.asyncCall(msg);
+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pCall, this);
+ connect(watcher, &QDBusPendingCallWatcher::finished, [this](QDBusPendingCallWatcher *self) {
+ QDBusPendingReply<quint32> reply = *self;
+ self->deleteLater();
+ if (reply.isValid()) {
+ updateOnlineStatus(reply.value());
+ } else {
+ qWarning() << "Error getting online status" << reply.error().name() << reply.error().message();
+ }
+ });
}
void SystemInfo::componentComplete()
diff --git a/plugins/systeminfo/systeminfo.h b/plugins/systeminfo/systeminfo.h
index c11bd44f..4a7a1d5b 100644
--- a/plugins/systeminfo/systeminfo.h
+++ b/plugins/systeminfo/systeminfo.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 Pelagicore AG
+** Copyright (C) 2017-2018 Pelagicore AG
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Neptune IVI UI.
@@ -42,24 +42,31 @@ class SystemInfo : public QObject, public QQmlParserStatus
Q_INTERFACES(QQmlParserStatus)
Q_PROPERTY(QStringList addressList READ addressList NOTIFY addressListChanged)
+ Q_PROPERTY(bool online READ online NOTIFY onlineChanged)
public:
explicit SystemInfo(QObject *parent = nullptr);
QStringList addressList() const;
+ bool online() const;
public slots:
void init();
signals:
void addressListChanged();
+ void onlineChanged();
protected:
void classBegin() override;
void componentComplete() override;
+private slots:
+ void updateOnlineStatus(quint32 state);
+
private:
void getAddress();
QStringList m_addressList;
+ bool m_online{false};
};
#endif // SYSTEMINFO_H
diff --git a/plugins/systeminfo/systeminfo.pro b/plugins/systeminfo/systeminfo.pro
index 7ec3f0e5..959665be 100644
--- a/plugins/systeminfo/systeminfo.pro
+++ b/plugins/systeminfo/systeminfo.pro
@@ -1,6 +1,6 @@
TEMPLATE = lib
TARGET = systeminfoplugin
-QT += qml quick
+QT += qml quick dbus
CONFIG += qt plugin c++11
uri = com.pelagicore.systeminfo