Changeset View
Changeset View
Standalone View
Standalone View
libs/models/networkmodel.cpp
Show First 20 Lines • Show All 100 Lines • ▼ Show 20 Line(s) | 52 | switch (role) { | |||
---|---|---|---|---|---|
101 | case UniRole: | 101 | case UniRole: | ||
102 | return item->uni(); | 102 | return item->uni(); | ||
103 | case UuidRole: | 103 | case UuidRole: | ||
104 | return item->uuid(); | 104 | return item->uuid(); | ||
105 | case VpnState: | 105 | case VpnState: | ||
106 | return item->vpnState(); | 106 | return item->vpnState(); | ||
107 | case VpnType: | 107 | case VpnType: | ||
108 | return item->vpnType(); | 108 | return item->vpnType(); | ||
109 | case RxBytesRole: | ||||
110 | return item->rxBytes(); | ||||
111 | case TxBytesRole: | ||||
112 | return item->txBytes(); | ||||
109 | default: | 113 | default: | ||
110 | break; | 114 | break; | ||
111 | } | 115 | } | ||
112 | } | 116 | } | ||
113 | 117 | | |||
114 | return QVariant(); | 118 | return QVariant(); | ||
115 | } | 119 | } | ||
116 | 120 | | |||
Show All 27 Lines | 128 | { | |||
144 | roles[SecurityTypeRole] = "SecurityType"; | 148 | roles[SecurityTypeRole] = "SecurityType"; | ||
145 | roles[SecurityTypeStringRole] = "SecurityTypeString"; | 149 | roles[SecurityTypeStringRole] = "SecurityTypeString"; | ||
146 | roles[TimeStampRole] = "TimeStamp"; | 150 | roles[TimeStampRole] = "TimeStamp"; | ||
147 | roles[TypeRole] = "Type"; | 151 | roles[TypeRole] = "Type"; | ||
148 | roles[UniRole] = "Uni"; | 152 | roles[UniRole] = "Uni"; | ||
149 | roles[UuidRole] = "Uuid"; | 153 | roles[UuidRole] = "Uuid"; | ||
150 | roles[VpnState] = "VpnState"; | 154 | roles[VpnState] = "VpnState"; | ||
151 | roles[VpnType] = "VpnType"; | 155 | roles[VpnType] = "VpnType"; | ||
156 | roles[RxBytesRole] = "RxBytes"; | ||||
157 | roles[TxBytesRole] = "TxBytes"; | ||||
152 | 158 | | |||
153 | return roles; | 159 | return roles; | ||
154 | } | 160 | } | ||
155 | 161 | | |||
156 | void NetworkModel::initialize() | 162 | void NetworkModel::initialize() | ||
157 | { | 163 | { | ||
158 | // Initialize existing connections | 164 | // Initialize existing connections | ||
159 | for (const NetworkManager::Connection::Ptr &connection : NetworkManager::listConnections()) { | 165 | for (const NetworkManager::Connection::Ptr &connection : NetworkManager::listConnections()) { | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | |||||
205 | { | 211 | { | ||
206 | connect(device.data(), &NetworkManager::Device::availableConnectionAppeared, this, &NetworkModel::availableConnectionAppeared, Qt::UniqueConnection); | 212 | connect(device.data(), &NetworkManager::Device::availableConnectionAppeared, this, &NetworkModel::availableConnectionAppeared, Qt::UniqueConnection); | ||
207 | connect(device.data(), &NetworkManager::Device::availableConnectionDisappeared, this, &NetworkModel::availableConnectionDisappeared, Qt::UniqueConnection); | 213 | connect(device.data(), &NetworkManager::Device::availableConnectionDisappeared, this, &NetworkModel::availableConnectionDisappeared, Qt::UniqueConnection); | ||
208 | connect(device.data(), &NetworkManager::Device::ipV4ConfigChanged, this, &NetworkModel::ipConfigChanged, Qt::UniqueConnection); | 214 | connect(device.data(), &NetworkManager::Device::ipV4ConfigChanged, this, &NetworkModel::ipConfigChanged, Qt::UniqueConnection); | ||
209 | connect(device.data(), &NetworkManager::Device::ipV6ConfigChanged, this, &NetworkModel::ipConfigChanged, Qt::UniqueConnection); | 215 | connect(device.data(), &NetworkManager::Device::ipV6ConfigChanged, this, &NetworkModel::ipConfigChanged, Qt::UniqueConnection); | ||
210 | connect(device.data(), &NetworkManager::Device::ipInterfaceChanged, this, &NetworkModel::ipInterfaceChanged); | 216 | connect(device.data(), &NetworkManager::Device::ipInterfaceChanged, this, &NetworkModel::ipInterfaceChanged); | ||
211 | connect(device.data(), &NetworkManager::Device::stateChanged, this, &NetworkModel::deviceStateChanged, Qt::UniqueConnection); | 217 | connect(device.data(), &NetworkManager::Device::stateChanged, this, &NetworkModel::deviceStateChanged, Qt::UniqueConnection); | ||
212 | 218 | | |||
219 | auto deviceStatistics = device->deviceStatistics(); | ||||
220 | connect(deviceStatistics.data(), &NetworkManager::DeviceStatistics::rxBytesChanged, this, [this, device](qulonglong rxBytes) { | ||||
broulik: Would it be better to only request the data when the statistics are open to avoid wakeups and… | |||||
volkov: Yes, good point. | |||||
221 | for (auto *item : m_list.returnItems(NetworkItemsList::Device, device->uni())) { | ||||
222 | item->setRxBytes(rxBytes); | ||||
223 | updateItem(item); | ||||
224 | } | ||||
225 | }); | ||||
226 | connect(deviceStatistics.data(), &NetworkManager::DeviceStatistics::txBytesChanged, this, [this, device](qulonglong txBytes) { | ||||
227 | for (auto *item : m_list.returnItems(NetworkItemsList::Device, device->uni())) { | ||||
228 | item->setTxBytes(txBytes); | ||||
229 | updateItem(item); | ||||
230 | } | ||||
231 | }); | ||||
232 | | ||||
213 | if (device->type() == NetworkManager::Device::Wifi) { | 233 | if (device->type() == NetworkManager::Device::Wifi) { | ||
214 | NetworkManager::WirelessDevice::Ptr wifiDev = device.objectCast<NetworkManager::WirelessDevice>(); | 234 | NetworkManager::WirelessDevice::Ptr wifiDev = device.objectCast<NetworkManager::WirelessDevice>(); | ||
215 | connect(wifiDev.data(), &NetworkManager::WirelessDevice::networkAppeared, this, &NetworkModel::wirelessNetworkAppeared, Qt::UniqueConnection); | 235 | connect(wifiDev.data(), &NetworkManager::WirelessDevice::networkAppeared, this, &NetworkModel::wirelessNetworkAppeared, Qt::UniqueConnection); | ||
216 | connect(wifiDev.data(), &NetworkManager::WirelessDevice::networkDisappeared, this, &NetworkModel::wirelessNetworkDisappeared, Qt::UniqueConnection); | 236 | connect(wifiDev.data(), &NetworkManager::WirelessDevice::networkDisappeared, this, &NetworkModel::wirelessNetworkDisappeared, Qt::UniqueConnection); | ||
217 | 237 | | |||
218 | } | 238 | } | ||
219 | 239 | | |||
220 | #if WITH_MODEMMANAGER_SUPPORT | 240 | #if WITH_MODEMMANAGER_SUPPORT | ||
▲ Show 20 Lines • Show All 282 Lines • ▼ Show 20 Line(s) | |||||
503 | void NetworkModel::onItemUpdated() | 523 | void NetworkModel::onItemUpdated() | ||
504 | { | 524 | { | ||
505 | NetworkModelItem *item = static_cast<NetworkModelItem*>(sender()); | 525 | NetworkModelItem *item = static_cast<NetworkModelItem*>(sender()); | ||
506 | if (item) { | 526 | if (item) { | ||
507 | updateItem(item); | 527 | updateItem(item); | ||
508 | } | 528 | } | ||
509 | } | 529 | } | ||
510 | 530 | | |||
531 | void NetworkModel::setDeviceStatisticsRefreshRateMs(const QString &devicePath, uint refreshRate) | ||||
532 | { | ||||
533 | NetworkManager::Device::Ptr device = NetworkManager::findNetworkInterface(devicePath); | ||||
534 | | ||||
535 | if (device) { | ||||
536 | device->deviceStatistics()->setRefreshRateMs(refreshRate); | ||||
537 | } | ||||
538 | } | ||||
539 | | ||||
511 | void NetworkModel::updateItem(NetworkModelItem*item) | 540 | void NetworkModel::updateItem(NetworkModelItem*item) | ||
512 | { | 541 | { | ||
513 | const int row = m_list.indexOf(item); | 542 | const int row = m_list.indexOf(item); | ||
514 | 543 | | |||
515 | if (row >= 0) { | 544 | if (row >= 0) { | ||
516 | item->invalidateDetails(); | 545 | item->invalidateDetails(); | ||
517 | QModelIndex index = createIndex(row, 0); | 546 | QModelIndex index = createIndex(row, 0); | ||
518 | Q_EMIT dataChanged(index, index); | 547 | Q_EMIT dataChanged(index, index); | ||
▲ Show 20 Lines • Show All 491 Lines • Show Last 20 Lines |
Would it be better to only request the data when the statistics are open to avoid wakeups and processing?