diff --git a/includes/CMakeLists.txt b/includes/CMakeLists.txt index 3e57851d..be8da460 100644 --- a/includes/CMakeLists.txt +++ b/includes/CMakeLists.txt @@ -198,6 +198,7 @@ install( KMultiTabBarButton KMultiTabBarTab KNameAndUrlInputDialog + KNetworkManager KNewFileMenu KNewPasswordDialog KNotification @@ -472,7 +473,6 @@ install( Solid/DeviceNotifier Solid/GenericInterface Solid/NetworkInterface - Solid/Networking Solid/OpticalDisc Solid/OpticalDrive Solid/PortableMediaPlayer diff --git a/includes/KNetworkManager b/includes/KNetworkManager new file mode 100644 index 00000000..69b73dd9 --- /dev/null +++ b/includes/KNetworkManager @@ -0,0 +1 @@ +#include "../knetworkmanager.h" diff --git a/includes/Solid/Networking b/includes/Solid/Networking deleted file mode 100644 index 79f8c6df..00000000 --- a/includes/Solid/Networking +++ /dev/null @@ -1 +0,0 @@ -#include "../../solid/networking.h" diff --git a/kdecore/kdebug.areas b/kdecore/kdebug.areas index 471a6dfa..146394a4 100644 --- a/kdecore/kdebug.areas +++ b/kdecore/kdebug.areas @@ -39,7 +39,6 @@ 711 kutils (KCModuleProxy) 712 kutils (KCModuleInfo) 713 kutils (KCModuleContainer) -921 Solid Networking 930 KUnitConversion 940 kmediaplayer 1000 kparts @@ -74,6 +73,7 @@ 51006 kdnssd 51009 karchive 51010 kemail +51011 knetworkmanager # kde-workspace 101 kioclient diff --git a/kutils/CMakeLists.txt b/kutils/CMakeLists.txt index 8604ec35..e753ae8e 100644 --- a/kutils/CMakeLists.txt +++ b/kutils/CMakeLists.txt @@ -14,6 +14,7 @@ add_subdirectory(kpowermanager) add_subdirectory(kdnssd) add_subdirectory(karchive) add_subdirectory(kemail) +add_subdirectory(knetworkmanager) ######## kidletime #################### diff --git a/kutils/knetworkmanager/CMakeLists.txt b/kutils/knetworkmanager/CMakeLists.txt new file mode 100644 index 00000000..1d9d1c7d --- /dev/null +++ b/kutils/knetworkmanager/CMakeLists.txt @@ -0,0 +1,40 @@ +# for the kded module +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} +) + +add_definitions(-DKDE_DEFAULT_DEBUG_AREA=51011) + +set(knetworkmanager_LIB_SRCS + knetworkmanager.cpp +) + +add_library(knetworkmanager SHARED ${knetworkmanager_LIB_SRCS}) + +target_link_libraries(knetworkmanager PUBLIC + ${QT_QTDBUS_LIBRARY} + kdecore +) + +set_target_properties(knetworkmanager PROPERTIES + VERSION ${GENERIC_LIB_VERSION} + SOVERSION ${GENERIC_LIB_SOVERSION} +) + +generate_export_header(knetworkmanager) + +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/knetworkmanager_export.h + knetworkmanager.h + DESTINATION ${KDE4_INCLUDE_INSTALL_DIR} +) + +install( + TARGETS knetworkmanager + EXPORT kdelibsTargets + DESTINATION ${KDE4_LIB_INSTALL_DIR} +) + +# add_subdirectory(kded) diff --git a/kutils/knetworkmanager/knetworkmanager.cpp b/kutils/knetworkmanager/knetworkmanager.cpp new file mode 100644 index 00000000..94ef6f13 --- /dev/null +++ b/kutils/knetworkmanager/knetworkmanager.cpp @@ -0,0 +1,82 @@ +/* This file is part of the KDE libraries + Copyright (C) 2023 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "knetworkmanager.h" +#include "kdebug.h" + +#include +#include + +class KNetworkManagerPrivate + { +public: + KNetworkManagerPrivate(); + + KNetworkManager::KNetworkStatus status; + QTimer* statustimer; +}; + +KNetworkManagerPrivate::KNetworkManagerPrivate() + : status(KNetworkManager::UnknownStatus), + statustimer(nullptr) +{ +} + +KNetworkManager::KNetworkManager(QObject *parent) + : QObject(parent), + d(new KNetworkManagerPrivate()) +{ + d->statustimer = new QTimer(this); + connect(d->statustimer, SIGNAL(timeout()), this, SLOT(_checkStatus())); + d->statustimer->start(2000); +} + +KNetworkManager::~KNetworkManager() +{ + delete d; +} + +KNetworkManager::KNetworkStatus KNetworkManager::status() const +{ + return d->status; +} + +bool KNetworkManager::isSupported() +{ + return true; +} + +void KNetworkManager::_checkStatus() +{ + KNetworkManager::KNetworkStatus newstatus = KNetworkManager::DisconnectedStatus; + foreach (const QNetworkInterface &iface, QNetworkInterface::allInterfaces()) { + const QNetworkInterface::InterfaceFlags iflags = iface.flags(); + if (iflags & QNetworkInterface::CanBroadcast && iflags & QNetworkInterface::IsRunning) { + newstatus = KNetworkManager::ConnectedStatus; + break; + } + } + + if (d->status != newstatus) { + d->status = newstatus; + kDebug() << "Status changed to" << newstatus; + emit statusChanged(newstatus); + } +} + +#include "moc_knetworkmanager.cpp" diff --git a/kutils/knetworkmanager/knetworkmanager.h b/kutils/knetworkmanager/knetworkmanager.h new file mode 100644 index 00000000..36aebf7b --- /dev/null +++ b/kutils/knetworkmanager/knetworkmanager.h @@ -0,0 +1,75 @@ +/* This file is part of the KDE libraries + Copyright (C) 2023 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KNETWORKMANAGER_H +#define KNETWORKMANAGER_H + +#include "knetworkmanager_export.h" + +#include + +class KNetworkManagerPrivate; + +/*! + Class to query, manage and watch the system network state. + + @since 4.23 + @warning the API is subject to change +*/ +class KNETWORKMANAGER_EXPORT KNetworkManager : public QObject +{ + Q_OBJECT +public: + enum KNetworkStatus { + UnknownStatus = 0, + ConnectedStatus = 1, + DisconnectedStatus = 2 + }; + + /*! + @brief Contructs object with @p parent + */ + KNetworkManager(QObject *parent = nullptr); + ~KNetworkManager(); + + /*! + @brief Returns the current network manager status + */ + KNetworkStatus status() const; + + /*! + @brief Returns @p true if network management is supported on this host, + @p false otherwise + */ + static bool isSupported(); + +Q_SIGNALS: + /*! + @brief Signals that the current status has changed to @p status + */ + void statusChanged(const KNetworkStatus status); + +private Q_SLOTS: + void _checkStatus(); + +private: + Q_DISABLE_COPY(KNetworkManager); + KNetworkManagerPrivate *d; +}; + +#endif // KNETWORKMANAGER_H diff --git a/solid/solid/CMakeLists.txt b/solid/solid/CMakeLists.txt index 07e7682b..b7a127aa 100644 --- a/solid/solid/CMakeLists.txt +++ b/solid/solid/CMakeLists.txt @@ -20,7 +20,6 @@ set_source_files_properties( ) set(solid_LIB_SRCS - networking.cpp solidnamespace.cpp managerbase.cpp device.cpp @@ -185,11 +184,6 @@ if(DEVINFO_FOUND) set(solid_OPTIONAL_LIBS ${solid_OPTIONAL_LIBS} ${DEVINFO_LIBRARIES}) endif() -qt4_add_dbus_interface(solid_LIB_SRCS - org.kde.Solid.Networking.Client.xml - org_kde_solid_networking_client -) - add_library(solid SHARED ${solid_LIB_SRCS}) target_link_libraries(solid PRIVATE @@ -213,12 +207,6 @@ install( DESTINATION ${KDE4_LIB_INSTALL_DIR} ) -install( - FILES - org.kde.Solid.Networking.Client.xml - DESTINATION ${KDE4_DBUS_INTERFACES_INSTALL_DIR} -) - ########### install files ############### generate_export_header(solid) @@ -246,7 +234,6 @@ install( audiointerface.h predicate.h powermanagement.h - networking.h video.h graphic.h DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}/solid diff --git a/solid/solid/networking.cpp b/solid/solid/networking.cpp deleted file mode 100644 index 3ab2d323..00000000 --- a/solid/solid/networking.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - Copyright 2006-2007 Will Stephenson - Copyright 2006-2007 Kevin Ottens - - 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 - -#include "networking.h" -#include "networking_p.h" - -#include "soliddefs_p.h" -#include "org_kde_solid_networking_client.h" - -Q_GLOBAL_STATIC(Solid::NetworkingPrivate, globalNetworkManager) - -Solid::NetworkingPrivate::NetworkingPrivate() - : netStatus(Solid::Networking::Unknown), - iface(nullptr) -{ - QDBusServiceWatcher *watcher = new QDBusServiceWatcher( - "org.kde.kded", QDBusConnection::sessionBus(), - QDBusServiceWatcher::WatchForOwnerChange, this - ); - connect( - watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)), - this, SLOT(serviceOwnerChanged(QString,QString,QString)) - ); - - initialize(); -} - -Solid::Networking::Notifier::Notifier() -{ -} - -void Solid::NetworkingPrivate::initialize() -{ - delete iface; - iface = new OrgKdeSolidNetworkingClientInterface( - "org.kde.kded", - "/modules/networkstatus", - QDBusConnection::sessionBus(), - this - ); - - // connect(iface, SIGNAL(statusChanged(uint)), globalNetworkManager(), SIGNAL(statusChanged(Networking::Status))); - connect(iface, SIGNAL(statusChanged(uint)), this, SLOT(serviceStatusChanged(uint))); - - QDBusReply reply = iface->status(); - if (reply.isValid()) { - netStatus = static_cast(reply.value()); - } else { - netStatus = Solid::Networking::Unknown; - } -} - -uint Solid::NetworkingPrivate::status() const -{ - return netStatus; -} - -/*=========================================================================*/ - -Solid::Networking::Status Solid::Networking::status() -{ - return static_cast(globalNetworkManager()->status()); -} - -Solid::Networking::Notifier *Solid::Networking::notifier() -{ - return globalNetworkManager(); -} - -void Solid::NetworkingPrivate::serviceStatusChanged(uint status) -{ - // kDebug(921) ; - netStatus = static_cast(status); - switch (netStatus) { - case Solid::Networking::Unknown: - break; - case Solid::Networking::Unconnected: - case Solid::Networking::Disconnecting: - case Solid::Networking::Connecting: - emit globalNetworkManager()->shouldDisconnect(); - break; - case Solid::Networking::Connected: - emit globalNetworkManager()->shouldConnect(); - break; - // default: - // kDebug(921) << "Unrecognised status code!"; - } - emit globalNetworkManager()->statusChanged(netStatus); -} - -void Solid::NetworkingPrivate::serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner) -{ - Q_UNUSED(name) - Q_UNUSED(oldOwner) - if (newOwner.isEmpty()) { - // kded quit on us - netStatus = Solid::Networking::Unknown; - emit globalNetworkManager()->statusChanged(netStatus); - } else { - // kded was replaced or started - initialize(); - emit globalNetworkManager()->statusChanged(netStatus); - serviceStatusChanged(netStatus); - } -} - -#include "moc_networking_p.cpp" -#include "moc_networking.cpp" diff --git a/solid/solid/networking.h b/solid/solid/networking.h deleted file mode 100644 index ce69be30..00000000 --- a/solid/solid/networking.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - Copyright 2006-2007 Will Stephenson - Copyright 2006-2007 Kevin Ottens - - 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 SOLID_NETWORKING -#define SOLID_NETWORKING - -#include - -#include - -namespace Solid -{ - /** - * This namespace contains all the network-related high-level methods: - * querying the underlying system for network availability, - * being notified when network availability changes - * (e.g. due to interfaces appearing or disappearing). - * - * It also allows application to specify the connection and disconnection policies - * that it would like to use, for the network. - */ - namespace Networking - { - /** - * Describes the state of the networking system - */ - enum Status { - Unknown, /**< the networking system is not active or unable to report its status - proceed with caution */ - Unconnected,/**< the system is not connected to any network */ - Disconnecting, /**< the system is breaking the connection */ - Connecting, /**< the system is not connected to any network */ - Connected /**< the system is currently connected to a network */ - }; - - /** - * Get the current networking status - * If the result is Unknown, the backend may be unconfigured or otherwise in a state where - * it cannot report useful networking status @ref Solid::Networking::Status. - */ - SOLID_EXPORT Status status(); - - /** - * This object emits signals, for use if your application requires notification - * of changes to networking. - */ - class SOLID_EXPORT Notifier : public QObject - { - Q_OBJECT - Q_SIGNALS: - /** - * Signals that the network status has changed - * @param status the new status of the network status service - */ - void statusChanged(Solid::Networking::Status status); - /** - * Signals that the system's network has become connected, so receivers - * should connect their sockets, ioslaves etc. - */ - void shouldConnect(); - /** - * Signals that the system's network has become disconnected, - * so receivers should adjust application state appropriately. - */ - void shouldDisconnect(); - - protected: - Notifier(); - }; - - SOLID_EXPORT Notifier *notifier(); - } - -} // Solid - -#endif diff --git a/solid/solid/networking_p.h b/solid/solid/networking_p.h deleted file mode 100644 index 9e2109f9..00000000 --- a/solid/solid/networking_p.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - Copyright 2006-2007 Will Stephenson - Copyright 2006-2007 Kevin Ottens - - 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 SOLID_NETWORKING_P_H -#define SOLID_NETWORKING_P_H - -#include -#include - -#include "networking.h" - -class OrgKdeSolidNetworkingClientInterface; - -namespace Solid -{ - class NetworkingPrivate : public Networking::Notifier - { - Q_OBJECT - Q_PROPERTY(uint Status READ status) - Q_CLASSINFO("D-Bus Interface", "org.kde.Solid.Networking.Client") - public: - NetworkingPrivate(); - - void shouldConnect() { Networking::Notifier::shouldConnect(); } - void shouldDisconnect() { Networking::Notifier::shouldDisconnect(); } - - Networking::Status netStatus; - public Q_SLOTS: - uint status() const; - /** - * Called on DBus signal from the network status service - */ - void serviceStatusChanged(uint status); - /** - * Detects when kded restarts, and sets status to NoNetworks so that apps - * may proceed - */ - void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner); - - private: - void initialize(); - OrgKdeSolidNetworkingClientInterface* iface; - }; -} // namespace Solid -#endif diff --git a/solid/solid/org.kde.Solid.Networking.Client.xml b/solid/solid/org.kde.Solid.Networking.Client.xml deleted file mode 100644 index 70b46de7..00000000 --- a/solid/solid/org.kde.Solid.Networking.Client.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - -