From 3e01d82f44bf587251455368f7502e9e4e204176 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sun, 28 Nov 2021 17:28:40 +0000 Subject: [PATCH] solid-networkstatus: fallback implementation via QNetworkInterface Signed-off-by: Ivailo Monev --- solid-networkstatus/kded/CMakeLists.txt | 1 + solid-networkstatus/kded/networkstatus.cpp | 2 + solid-networkstatus/kded/toolkitstatus.cpp | 69 ++++++++++++++++++++++++++++++ solid-networkstatus/kded/toolkitstatus.h | 50 ++++++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 solid-networkstatus/kded/toolkitstatus.cpp create mode 100644 solid-networkstatus/kded/toolkitstatus.h diff --git a/solid-networkstatus/kded/CMakeLists.txt b/solid-networkstatus/kded/CMakeLists.txt index ce39568c..729575b7 100644 --- a/solid-networkstatus/kded/CMakeLists.txt +++ b/solid-networkstatus/kded/CMakeLists.txt @@ -7,6 +7,7 @@ set(kded_networkstatus_PART_SRCS wicdstatus.cpp wicdcustomtypes.cpp connmanstatus.cpp + toolkitstatus.cpp ) if(NETWORKMANAGER_FOUND) diff --git a/solid-networkstatus/kded/networkstatus.cpp b/solid-networkstatus/kded/networkstatus.cpp index a82d8218..755d344a 100644 --- a/solid-networkstatus/kded/networkstatus.cpp +++ b/solid-networkstatus/kded/networkstatus.cpp @@ -44,6 +44,7 @@ #include "wicdstatus.h" #include "connmanstatus.h" +#include "toolkitstatus.h" #include @@ -286,6 +287,7 @@ void NetworkStatusModule::init() #endif backends << new WicdStatus( this ); backends << new ConnmanStatus( this ); + backends << new ToolkitStatus( this ); } for ( int i = 0; i < backends.count(); i++ ) { diff --git a/solid-networkstatus/kded/toolkitstatus.cpp b/solid-networkstatus/kded/toolkitstatus.cpp new file mode 100644 index 00000000..0beee7b0 --- /dev/null +++ b/solid-networkstatus/kded/toolkitstatus.cpp @@ -0,0 +1,69 @@ +/* This file is part of the KDE project + + Copyright (c) 2021 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "toolkitstatus.h" + +#include +#include + +ToolkitStatus::ToolkitStatus(QObject *parent) + : SystemStatusInterface(parent), + m_status(Solid::Networking::Unknown), + m_timer(this) +{ + connect(&m_timer, SIGNAL(timeout()), this, SLOT(checkStatus())); + m_timer.start(2000); +} + +Solid::Networking::Status ToolkitStatus::status() const +{ + return m_status; +} + +bool ToolkitStatus::isSupported() const +{ + return true; +} + +QString ToolkitStatus::serviceName() const +{ + return QString::fromLatin1("org.kde.kded"); +} + +void ToolkitStatus::checkStatus() +{ + Solid::Networking::Status newstatus = Solid::Networking::Unconnected; + Q_FOREACH (const QNetworkInterface &iface, QNetworkInterface::allInterfaces()) { + const QNetworkInterface::InterfaceFlags iflags = iface.flags(); + if (iflags & QNetworkInterface::CanBroadcast && iflags & QNetworkInterface::IsRunning) { + newstatus = Solid::Networking::Connected; + break; + } + } + // qDebug() << Q_FUNC_INFO << m_status << newstatus; + + if (m_status != newstatus) { + m_status = newstatus; + Q_EMIT statusChanged(m_status); + } +} + +#include "moc_toolkitstatus.cpp" diff --git a/solid-networkstatus/kded/toolkitstatus.h b/solid-networkstatus/kded/toolkitstatus.h new file mode 100644 index 00000000..5b2be1c1 --- /dev/null +++ b/solid-networkstatus/kded/toolkitstatus.h @@ -0,0 +1,50 @@ +/* This file is part of the KDE project + + Copyright (c) 2021 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef NETWORKSTATUS_TOOLKIT_H +#define NETWORKSTATUS_TOOLKIT_H + +#include "systemstatusinterface.h" + +#include +#include + +class ToolkitStatus : public SystemStatusInterface +{ + Q_OBJECT +public: + ToolkitStatus(QObject *parent = 0); + + // reimplementations + Solid::Networking::Status status() const; + bool isSupported() const; + QString serviceName() const; + +private Q_SLOTS: + void checkStatus(); + +private: + Solid::Networking::Status m_status; + QTimer m_timer; +}; + +#endif + -- 2.11.0