solid-networkstatus: fallback implementation via QNetworkInterface

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-11-28 17:28:40 +00:00
parent 6a1e26ef74
commit 3e01d82f44
4 changed files with 122 additions and 0 deletions

View file

@ -7,6 +7,7 @@ set(kded_networkstatus_PART_SRCS
wicdstatus.cpp
wicdcustomtypes.cpp
connmanstatus.cpp
toolkitstatus.cpp
)
if(NETWORKMANAGER_FOUND)

View file

@ -44,6 +44,7 @@
#include "wicdstatus.h"
#include "connmanstatus.h"
#include "toolkitstatus.h"
#include <kpluginfactory.h>
@ -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++ ) {

View file

@ -0,0 +1,69 @@
/* This file is part of the KDE project
Copyright (c) 2021 Ivailo Monev <xakepa10@gmail.com>
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 <http://www.gnu.org/licenses/>.
*/
#include "toolkitstatus.h"
#include <QNetworkInterface>
#include <KDebug>
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"

View file

@ -0,0 +1,50 @@
/* This file is part of the KDE project
Copyright (c) 2021 Ivailo Monev <xakepa10@gmail.com>
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 <http://www.gnu.org/licenses/>.
*/
#ifndef NETWORKSTATUS_TOOLKIT_H
#define NETWORKSTATUS_TOOLKIT_H
#include "systemstatusinterface.h"
#include <QString>
#include <QTimer>
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