File indexing completed on 2025-04-27 05:08:17
0001 /* 0002 SPDX-FileCopyrightText: 2013-2018 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_NETWORK_MODEL_H 0008 #define PLASMA_NM_NETWORK_MODEL_H 0009 0010 #include "plasmanm_internal_export.h" 0011 0012 #include <QAbstractListModel> 0013 #include <QQueue> 0014 0015 #include <qqmlregistration.h> 0016 0017 #include "networkitemslist.h" 0018 0019 #include <NetworkManagerQt/Manager> 0020 #include <NetworkManagerQt/Utils> 0021 #include <NetworkManagerQt/VpnConnection> 0022 #include <NetworkManagerQt/WirelessDevice> 0023 0024 #include <ModemManagerQt/Modem> 0025 0026 class PLASMANM_INTERNAL_EXPORT NetworkModel : public QAbstractListModel 0027 { 0028 Q_OBJECT 0029 QML_ELEMENT 0030 public: 0031 // Delay model updates to prevent jumping password entry in the applet. 0032 // This is an aggregate property, which is true whenever any of model items is true. 0033 // BUG: 435430, 389052 0034 Q_PROPERTY(bool delayModelUpdates READ delayModelUpdates NOTIFY delayModelUpdatesChanged) 0035 0036 explicit NetworkModel(QObject *parent = nullptr); 0037 ~NetworkModel() override; 0038 0039 enum ItemRole { 0040 ConnectionDetailsRole = Qt::UserRole + 1, 0041 ConnectionIconRole, 0042 ConnectionPathRole, 0043 ConnectionStateRole, 0044 DeviceName, 0045 DevicePathRole, 0046 DeviceStateRole, 0047 DuplicateRole, 0048 ItemUniqueNameRole, 0049 ItemTypeRole, 0050 LastUsedRole, 0051 LastUsedDateOnlyRole, 0052 NameRole, 0053 SecurityTypeRole, 0054 SecurityTypeStringRole, 0055 SectionRole, 0056 SignalRole, 0057 SlaveRole, 0058 SsidRole, 0059 SpecificPathRole, 0060 TimeStampRole, 0061 TypeRole, 0062 UniRole, 0063 UuidRole, 0064 VpnState, 0065 VpnType, 0066 RxBytesRole, 0067 TxBytesRole, 0068 // writable roles 0069 DelayModelUpdatesRole, 0070 }; 0071 Q_ENUMS(ItemRole) 0072 0073 enum ModelChangeType { ItemAdded, ItemRemoved, ItemPropertyChanged }; 0074 0075 int rowCount(const QModelIndex &parent) const override; 0076 QVariant data(const QModelIndex &index, int role) const override; 0077 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; 0078 QHash<int, QByteArray> roleNames() const override; 0079 0080 bool delayModelUpdates() const; 0081 0082 Q_SIGNALS: 0083 void delayModelUpdatesChanged(); 0084 0085 public Q_SLOTS: 0086 void onItemUpdated(); 0087 void setDeviceStatisticsRefreshRateMs(const QString &devicePath, uint refreshRate); 0088 0089 private Q_SLOTS: 0090 void accessPointSignalStrengthChanged(int signal); 0091 void activeConnectionAdded(const QString &activeConnection); 0092 void activeConnectionRemoved(const QString &activeConnection); 0093 void activeConnectionStateChanged(NetworkManager::ActiveConnection::State state); 0094 void activeVpnConnectionStateChanged(NetworkManager::VpnConnection::State state, NetworkManager::VpnConnection::StateChangeReason reason); 0095 void availableConnectionAppeared(const QString &connection); 0096 void availableConnectionDisappeared(const QString &connection); 0097 void connectionAdded(const QString &connection); 0098 void connectionRemoved(const QString &connection); 0099 void connectionUpdated(); 0100 void deviceAdded(const QString &device); 0101 void deviceRemoved(const QString &device); 0102 void deviceStateChanged(NetworkManager::Device::State state, NetworkManager::Device::State oldState, NetworkManager::Device::StateChangeReason reason); 0103 void gsmNetworkAccessTechnologiesChanged(QFlags<MMModemAccessTechnology> accessTechnologies); 0104 void gsmNetworkCurrentModesChanged(); 0105 void gsmNetworkSignalQualityChanged(const ModemManager::SignalQualityPair &signalQuality); 0106 void ipConfigChanged(); 0107 void ipInterfaceChanged(); 0108 void statusChanged(NetworkManager::Status status); 0109 void wirelessNetworkAppeared(const QString &ssid); 0110 void wirelessNetworkDisappeared(const QString &ssid); 0111 void wirelessNetworkSignalChanged(int signal); 0112 void wirelessNetworkReferenceApChanged(const QString &accessPoint); 0113 0114 void initialize(); 0115 0116 private: 0117 bool m_delayModelUpdates = false; 0118 NetworkItemsList m_list; 0119 QQueue<QPair<ModelChangeType, NetworkModelItem *>> m_updateQueue; 0120 0121 void addActiveConnection(const NetworkManager::ActiveConnection::Ptr &activeConnection); 0122 void addAvailableConnection(const QString &connection, const NetworkManager::Device::Ptr &device); 0123 void addConnection(const NetworkManager::Connection::Ptr &connection); 0124 void addDevice(const NetworkManager::Device::Ptr &device); 0125 void addWirelessNetwork(const NetworkManager::WirelessNetwork::Ptr &network, const NetworkManager::WirelessDevice::Ptr &device); 0126 void checkAndCreateDuplicate(const QString &connection, const QString &deviceUni); 0127 void initializeSignals(); 0128 void initializeSignals(const NetworkManager::ActiveConnection::Ptr &activeConnection); 0129 void initializeSignals(const NetworkManager::Connection::Ptr &connection); 0130 void initializeSignals(const NetworkManager::Device::Ptr &device); 0131 void initializeSignals(const NetworkManager::WirelessNetwork::Ptr &network); 0132 void 0133 updateFromWirelessNetwork(NetworkModelItem *item, const NetworkManager::WirelessNetwork::Ptr &network, const NetworkManager::WirelessDevice::Ptr &device); 0134 void updateDelayModelUpdates(); 0135 void flushUpdateQueue(); 0136 0137 void insertItem(NetworkModelItem *item); 0138 void removeItem(NetworkModelItem *item); 0139 void updateItem(NetworkModelItem *item); 0140 0141 NetworkManager::WirelessSecurityType alternativeWirelessSecurity(const NetworkManager::WirelessSecurityType type); 0142 }; 0143 0144 #endif // PLASMA_NM_NETWORK_MODEL_H