File indexing completed on 2024-12-01 07:25:49

0001 /*
0002     SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 #include "wifimonitor_p.h"
0007 
0008 #include <NetworkManagerQt/Manager>
0009 #include <NetworkManagerQt/WirelessSetting>
0010 
0011 using namespace KPublicTransport;
0012 
0013 WifiMonitor::WifiMonitor(QObject *parent)
0014     : QObject(parent)
0015 {
0016     const auto getSsid = [this](){
0017         const auto connections = NetworkManager::activeConnections();
0018         for (const auto &con : connections) {
0019             if (con->type() != NetworkManager::ConnectionSettings::Wireless) {
0020                 continue;
0021             }
0022             setSsid(QString::fromUtf8(con->connection()->settings()->setting(NetworkManager::Setting::Wireless).staticCast<NetworkManager::WirelessSetting>()->ssid()));
0023             break;
0024         }
0025     };
0026 
0027     connect(NetworkManager::notifier(), &NetworkManager::Notifier::activatingConnectionChanged, this, getSsid);
0028     connect(NetworkManager::notifier(), &NetworkManager::Notifier::activeConnectionAdded, this, getSsid);
0029     connect(NetworkManager::notifier(), &NetworkManager::Notifier::activeConnectionRemoved, this, getSsid);
0030     connect(NetworkManager::notifier(), &NetworkManager::Notifier::networkingEnabledChanged, this, &WifiMonitor::statusChanged);
0031     connect(NetworkManager::notifier(), &NetworkManager::Notifier::wirelessEnabledChanged, this, &WifiMonitor::statusChanged);
0032 
0033     getSsid();
0034 }
0035 
0036 WifiMonitor::~WifiMonitor() = default;
0037 
0038 WifiMonitor::Status WifiMonitor::status() const
0039 {
0040     if (!NetworkManager::isNetworkingEnabled()) {
0041         return NotAvailable;
0042     }
0043 
0044     return NetworkManager::isWirelessEnabled() ? Available : WifiNotEnabled;
0045 }
0046 
0047 void WifiMonitor::requestPermissions()
0048 {
0049 }