Commit ab45698f authored by Alexander Volkov's avatar Alexander Volkov

Update connection details only when necessary

Summary:
They are needed only when the Details tab is visible.
In other cases, their update is just eating CPU time.

Reviewers: #plasma, jgrulich

Reviewed By: jgrulich

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D14793
parent 1b911b2b
......@@ -278,7 +278,7 @@ void NetworkModel::addActiveConnection(const NetworkManager::ActiveConnection::P
}
item->setVpnState(state);
}
item->updateDetails();
item->invalidateDetails();
qCDebug(PLASMA_NM) << "Item " << item->name() << ": active connection state changed to " << item->connectionState();
}
}
......@@ -382,7 +382,7 @@ void NetworkModel::addConnection(const NetworkManager::Connection::Ptr &connecti
item->setSsid(QString::fromUtf8(wirelessSetting->ssid()));
}
item->updateDetails();
item->invalidateDetails();
const int index = m_list.count();
beginInsertRows(QModelIndex(), index, index);
......@@ -465,7 +465,7 @@ void NetworkModel::addWirelessNetwork(const NetworkManager::WirelessNetwork::Ptr
item->setSsid(network->ssid());
item->setType(NetworkManager::ConnectionSettings::Wireless);
item->setSecurityType(securityType);
item->updateDetails();
item->invalidateDetails();
const int index = m_list.count();
beginInsertRows(QModelIndex(), index, index);
......@@ -491,7 +491,7 @@ void NetworkModel::checkAndCreateDuplicate(const QString &connection, const Netw
if (createDuplicate) {
NetworkModelItem *duplicatedItem = new NetworkModelItem(originalItem);
duplicatedItem->updateDetails();
duplicatedItem->invalidateDetails();
const int index = m_list.count();
beginInsertRows(QModelIndex(), index, index);
......@@ -513,7 +513,7 @@ void NetworkModel::updateItem(NetworkModelItem*item)
const int row = m_list.indexOf(item);
if (row >= 0) {
item->updateDetails();
item->invalidateDetails();
QModelIndex index = createIndex(row, 0);
Q_EMIT dataChanged(index, index);
}
......@@ -560,7 +560,7 @@ void NetworkModel::activeConnectionStateChanged(NetworkManager::ActiveConnection
beginResetModel();
for (NetworkModelItem *item : m_list.returnItems(NetworkItemsList::ActiveConnection, activePtr->path())) {
item->setConnectionState(state);
item->updateDetails();
item->invalidateDetails();
qCDebug(PLASMA_NM) << "Item " << item->name() << ": active connection changed to " << item->connectionState();
}
endResetModel();
......@@ -771,7 +771,7 @@ void NetworkModel::deviceStateChanged(NetworkManager::Device::State state, Netwo
beginResetModel();
for (NetworkModelItem *item : m_list.returnItems(NetworkItemsList::Device, device->uni())) {
item->setDeviceState(state);
item->updateDetails();
item->invalidateDetails();
// qCDebug(PLASMA_NM) << "Item " << item->name() << ": device state changed to " << item->deviceState();
}
endResetModel();
......
......@@ -54,6 +54,7 @@ NetworkModelItem::NetworkModelItem(QObject *parent)
: QObject(parent)
, m_connectionState(NetworkManager::ActiveConnection::Deactivated)
, m_deviceState(NetworkManager::Device::UnknownState)
, m_detailsValid(false)
, m_duplicate(false)
, m_mode(NetworkManager::WirelessSetting::Infrastructure)
, m_securityType(NetworkManager::NoneSecurity)
......@@ -68,6 +69,7 @@ NetworkModelItem::NetworkModelItem(const NetworkModelItem *item, QObject *parent
: QObject(parent)
, m_connectionPath(item->connectionPath())
, m_connectionState(NetworkManager::ActiveConnection::Deactivated)
, m_detailsValid(false)
, m_duplicate(true)
, m_mode(item->mode())
, m_name(item->name())
......@@ -117,6 +119,9 @@ void NetworkModelItem::setConnectionState(NetworkManager::ActiveConnection::Stat
QStringList NetworkModelItem::details() const
{
if (!m_detailsValid) {
updateDetails();
}
return m_details;
}
......@@ -418,8 +423,14 @@ bool NetworkModelItem::operator==(const NetworkModelItem *item) const
return false;
}
void NetworkModelItem::updateDetails()
void NetworkModelItem::invalidateDetails()
{
m_detailsValid = false;
}
void NetworkModelItem::updateDetails() const
{
m_detailsValid = true;
m_details.clear();
if (itemType() == NetworkModelItem::UnavailableConnection) {
......
......@@ -111,16 +111,19 @@ public:
bool operator==(const NetworkModelItem *item) const;
public Q_SLOTS:
void updateDetails();
void invalidateDetails();
private:
void updateDetails() const;
QString m_activeConnectionPath;
QString m_connectionPath;
NetworkManager::ActiveConnection::State m_connectionState;
QString m_devicePath;
QString m_deviceName;
NetworkManager::Device::State m_deviceState;
QStringList m_details;
mutable QStringList m_details;
mutable bool m_detailsValid;
bool m_duplicate;
NetworkManager::WirelessSetting::NetworkMode m_mode;
QString m_name;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment