File indexing completed on 2024-07-21 07:58:12

0001 /*
0002     SPDX-FileCopyrightText: 2013 Jan Grulich <jgrulich@redhat.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef PLASMA_NM_CONNECTION_ICON_H
0008 #define PLASMA_NM_CONNECTION_ICON_H
0009 
0010 #include <ModemManagerQt/Modem>
0011 #include <NetworkManagerQt/ActiveConnection>
0012 #include <NetworkManagerQt/Manager>
0013 #include <NetworkManagerQt/VpnConnection>
0014 #include <NetworkManagerQt/WirelessNetwork>
0015 
0016 #include <QCoroCore>
0017 
0018 #include <qqmlregistration.h>
0019 
0020 class ConnectionIcon : public QObject
0021 {
0022     Q_OBJECT
0023     QML_ELEMENT
0024 
0025     Q_PROPERTY(bool connecting READ connecting NOTIFY connectingChanged)
0026     Q_PROPERTY(QString connectionIcon READ connectionIcon NOTIFY connectionIconChanged)
0027     Q_PROPERTY(QString connectionTooltipIcon READ connectionTooltipIcon NOTIFY connectionTooltipIconChanged)
0028 
0029     Q_PROPERTY(NetworkManager::Connectivity connectivity READ connectivity WRITE setConnectivity NOTIFY connectivityChanged)
0030 public:
0031     explicit ConnectionIcon(QObject *parent = nullptr);
0032     ~ConnectionIcon() override;
0033 
0034     bool connecting() const;
0035     QString connectionIcon() const;
0036     QString connectionTooltipIcon() const;
0037 
0038     NetworkManager::Connectivity connectivity() const;
0039     void setConnectivity(NetworkManager::Connectivity connectivity);
0040     Q_SIGNAL void connectivityChanged(NetworkManager::Connectivity connectivity);
0041 
0042 private Q_SLOTS:
0043     void activatingConnectionChanged(const QString &connection);
0044     void activeConnectionAdded(const QString &activeConnection);
0045     void activeConnectionDestroyed();
0046     void activeConnectionStateChanged(NetworkManager::ActiveConnection::State state);
0047     void carrierChanged(bool carrier);
0048     void deviceAdded(const QString &device);
0049     void deviceRemoved(const QString &device);
0050     void networkingEnabledChanged(bool enabled);
0051     void primaryConnectionChanged(const QString &connection);
0052     void modemNetworkRemoved();
0053     void modemSignalChanged(ModemManager::SignalQualityPair signalQuality);
0054     void setIconForModem();
0055     void statusChanged(NetworkManager::Status status);
0056     void setWirelessIconForSignalStrength(int strength);
0057     void vpnConnectionStateChanged(NetworkManager::VpnConnection::State state, NetworkManager::VpnConnection::StateChangeReason reason);
0058     void wirelessEnabledChanged(bool enabled);
0059     void wirelessNetworkAppeared(const QString &network);
0060     void wwanEnabledChanged(bool enabled);
0061 Q_SIGNALS:
0062     void connectingChanged(bool connecting);
0063     void connectionIconChanged(const QString &icon);
0064     void connectionTooltipIconChanged(const QString &icon);
0065 
0066 private:
0067     void addActiveConnection(const QString &activeConnection);
0068     void setConnecting(bool connecting);
0069     void setConnectionIcon(const QString &icon);
0070     void setConnectionTooltipIcon(const QString &icon);
0071     void setVpn(bool vpn);
0072     uint m_signal = 0;
0073     NetworkManager::WirelessNetwork::Ptr m_wirelessNetwork;
0074 
0075     bool m_connecting = false;
0076     bool m_limited = false;
0077     bool m_vpn = false;
0078     QString m_connectionIcon;
0079     QString m_connectionTooltipIcon;
0080     NetworkManager::Connectivity m_connectivity = NetworkManager::UnknownConnectivity;
0081 
0082     void setDisconnectedIcon();
0083     void setIcons();
0084     void setStates();
0085     void setWirelessIcon(const NetworkManager::Device::Ptr &device, const QString &ssid);
0086     ModemManager::Modem::Ptr m_modemNetwork;
0087     void setModemIcon(const NetworkManager::Device::Ptr &device);
0088 };
0089 
0090 #endif // PLASMA_NM_CONNECTION_ICON_H