Commit f301f1ea authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Use return early

Summary: Makes the code more readable by reducing the indentation depth

Reviewers: jgrulich

Reviewed By: jgrulich

Subscribers: broulik, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D24905
parent 4627aaf6
......@@ -453,7 +453,9 @@ void NetworkModel::addWirelessNetwork(const NetworkManager::WirelessNetwork::Ptr
// AccessPoint appeared signal, this time we know SSID, but we don't attempt any merging, because it's usually the other way around, thus
// we need to attempt to merge it here with a connection we guess it's related to this new AP
for (NetworkModelItem *item : m_list.returnItems(NetworkItemsList::Type, NetworkManager::ConnectionSettings::Wireless)) {
if (item->itemType() == NetworkModelItem::AvailableConnection) {
if (item->itemType() != NetworkModelItem::AvailableConnection)
continue;
NetworkManager::ConnectionSettings::Ptr connectionSettings = NetworkManager::findConnection(item->connectionPath())->settings();
if (connectionSettings && connectionSettings->connectionType() == NetworkManager::ConnectionSettings::Wireless) {
NetworkManager::WirelessSetting::Ptr wirelessSetting = connectionSettings->setting(NetworkManager::Setting::Wireless).dynamicCast<NetworkManager::WirelessSetting>();
......@@ -468,7 +470,6 @@ void NetworkModel::addWirelessNetwork(const NetworkManager::WirelessNetwork::Ptr
}
}
}
}
NetworkManager::WirelessSetting::NetworkMode mode = NetworkManager::WirelessSetting::Infrastructure;
NetworkManager::WirelessSecurityType securityType = NetworkManager::UnknownSecurity;
......@@ -566,7 +567,9 @@ void NetworkModel::updateItem(NetworkModelItem*item)
void NetworkModel::accessPointSignalStrengthChanged(int signal)
{
NetworkManager::AccessPoint *apPtr = qobject_cast<NetworkManager::AccessPoint*>(sender());
if (apPtr) {
if (!apPtr)
return;
for (NetworkModelItem *item : m_list.returnItems(NetworkItemsList::Ssid, apPtr->ssid())) {
if (item->specificPath() == apPtr->uni()) {
item->setSignal(signal);
......@@ -574,7 +577,6 @@ void NetworkModel::accessPointSignalStrengthChanged(int signal)
qCDebug(PLASMA_NM) << "AccessPoint " << item->name() << ": signal changed to " << item->signal();
}
}
}
}
void NetworkModel::activeConnectionAdded(const QString &activeConnection)
......@@ -600,7 +602,10 @@ void NetworkModel::activeConnectionRemoved(const QString &activeConnection)
void NetworkModel::activeConnectionStateChanged(NetworkManager::ActiveConnection::State state)
{
NetworkManager::ActiveConnection *activePtr = qobject_cast<NetworkManager::ActiveConnection*>(sender());
if (activePtr) {
if (!activePtr)
return;
for (NetworkModelItem *item : m_list.returnItems(NetworkItemsList::ActiveConnection, activePtr->path())) {
item->setConnectionState(state);
item->invalidateDetails();
......@@ -617,7 +622,9 @@ void NetworkModel::activeVpnConnectionStateChanged(NetworkManager::VpnConnection
Q_UNUSED(reason)
NetworkManager::ActiveConnection *activePtr = qobject_cast<NetworkManager::ActiveConnection*>(sender());
if (activePtr) {
if (!activePtr)
return;
for (NetworkModelItem *item : m_list.returnItems(NetworkItemsList::ActiveConnection, activePtr->path())) {
if (state == NetworkManager::VpnConnection::Prepare ||
state == NetworkManager::VpnConnection::NeedAuth ||
......@@ -633,7 +640,6 @@ void NetworkModel::activeVpnConnectionStateChanged(NetworkManager::VpnConnection
updateItem(item);
qCDebug(PLASMA_NM) << "Item " << item->name() << ": active connection changed to " << item->connectionState();
}
}
}
void NetworkModel::availableConnectionAppeared(const QString &connection)
......@@ -767,7 +773,9 @@ void NetworkModel::connectionRemoved(const QString &connection)
void NetworkModel::connectionUpdated()
{
NetworkManager::Connection *connectionPtr = qobject_cast<NetworkManager::Connection*>(sender());
if (connectionPtr) {
if (!connectionPtr)
return;
NetworkManager::ConnectionSettings::Ptr settings = connectionPtr->settings();
for (NetworkModelItem *item : m_list.returnItems(NetworkItemsList::Connection, connectionPtr->path())) {
item->setConnectionPath(connectionPtr->path());
......@@ -788,7 +796,6 @@ void NetworkModel::connectionUpdated()
updateItem(item);
qCDebug(PLASMA_NM) << "Item " << item->name() << ": connection updated";
}
}
}
void NetworkModel::deviceAdded(const QString &device)
......@@ -814,7 +821,9 @@ void NetworkModel::deviceStateChanged(NetworkManager::Device::State state, Netwo
NetworkManager::Device::Ptr device = NetworkManager::findNetworkInterface(qobject_cast<NetworkManager::Device*>(sender())->uni());
if (device) {
if (!device)
return;
beginResetModel();
for (NetworkModelItem *item : m_list.returnItems(NetworkItemsList::Device, device->uni())) {
item->setDeviceState(state);
......@@ -822,7 +831,6 @@ void NetworkModel::deviceStateChanged(NetworkManager::Device::State state, Netwo
// qCDebug(PLASMA_NM) << "Item " << item->name() << ": device state changed to " << item->deviceState();
}
endResetModel();
}
}
#if WITH_MODEMMANAGER_SUPPORT
......@@ -830,69 +838,84 @@ void NetworkModel::gsmNetworkAccessTechnologiesChanged(QFlags<MMModemAccessTechn
{
Q_UNUSED(accessTechnologies);
ModemManager::Modem *gsmNetwork = qobject_cast<ModemManager::Modem*>(sender());
if (gsmNetwork) {
if (!gsmNetwork)
return;
for (const NetworkManager::Device::Ptr &dev : NetworkManager::networkInterfaces()) {
if (dev->type() == NetworkManager::Device::Modem) {
if (dev->type() != NetworkManager::Device::Modem)
continue;
ModemManager::ModemDevice::Ptr modem = ModemManager::findModemDevice(dev->udi());
if (modem) {
if (modem->hasInterface(ModemManager::ModemDevice::ModemInterface)) {
if (!modem)
continue;
if (!modem->hasInterface(ModemManager::ModemDevice::ModemInterface))
continue;
ModemManager::Modem::Ptr modemNetwork = modem->interface(ModemManager::ModemDevice::ModemInterface).objectCast<ModemManager::Modem>();
if (modemNetwork && modemNetwork->device() == gsmNetwork->device()) {
if (!modemNetwork || modemNetwork->device() != gsmNetwork->device())
continue;
// TODO store access technology internally?
for (NetworkModelItem *item : m_list.returnItems(NetworkItemsList::Device, dev->uni())) {
updateItem(item);
}
}
}
}
}
}
}
}
void NetworkModel::gsmNetworkCurrentModesChanged()
{
ModemManager::Modem *gsmNetwork = qobject_cast<ModemManager::Modem*>(sender());
if (gsmNetwork) {
if (!gsmNetwork)
return;
for (const NetworkManager::Device::Ptr &dev : NetworkManager::networkInterfaces()) {
if (dev->type() == NetworkManager::Device::Modem) {
if (dev->type() != NetworkManager::Device::Modem)
continue;
ModemManager::ModemDevice::Ptr modem = ModemManager::findModemDevice(dev->udi());
if (modem) {
if (modem->hasInterface(ModemManager::ModemDevice::ModemInterface)) {
if (!modem)
continue;
if (!modem->hasInterface(ModemManager::ModemDevice::ModemInterface))
continue;
ModemManager::Modem::Ptr modemNetwork = modem->interface(ModemManager::ModemDevice::ModemInterface).objectCast<ModemManager::Modem>();
if (modemNetwork && modemNetwork->device() == gsmNetwork->device()) {
if (!modemNetwork || modemNetwork->device() != gsmNetwork->device())
continue;
for (NetworkModelItem *item : m_list.returnItems(NetworkItemsList::Device, dev->uni())) {
updateItem(item);
}
}
}
}
}
}
}
}
void NetworkModel::gsmNetworkSignalQualityChanged(const ModemManager::SignalQualityPair &signalQuality)
{
ModemManager::Modem *gsmNetwork = qobject_cast<ModemManager::Modem*>(sender());
if (gsmNetwork) {
if (!gsmNetwork)
return;
for (const NetworkManager::Device::Ptr &dev : NetworkManager::networkInterfaces()) {
if (dev->type() == NetworkManager::Device::Modem) {
if (dev->type() != NetworkManager::Device::Modem)
continue;
ModemManager::ModemDevice::Ptr modem = ModemManager::findModemDevice(dev->udi());
if (modem) {
if (modem->hasInterface(ModemManager::ModemDevice::ModemInterface)) {
if (!modem)
continue;
if (!modem->hasInterface(ModemManager::ModemDevice::ModemInterface))
continue;
ModemManager::Modem::Ptr modemNetwork = modem->interface(ModemManager::ModemDevice::ModemInterface).objectCast<ModemManager::Modem>();
if (modemNetwork && modemNetwork->device() == gsmNetwork->device()) {
if (!modemNetwork || modemNetwork->device() != gsmNetwork->device())
continue;
for (NetworkModelItem *item : m_list.returnItems(NetworkItemsList::Device, dev->uni())) {
item->setSignal(signalQuality.signal);
updateItem(item);
}
}
}
}
}
}
}
}
#endif
......@@ -901,18 +924,21 @@ void NetworkModel::ipConfigChanged()
{
NetworkManager::Device::Ptr device = NetworkManager::findNetworkInterface(qobject_cast<NetworkManager::Device*>(sender())->uni());
if (device) {
if (!device)
return;
for (NetworkModelItem *item : m_list.returnItems(NetworkItemsList::Device, device->uni())) {
updateItem(item);
// qCDebug(PLASMA_NM) << "Item " << item->name() << ": device ipconfig changed";
}
}
}
void NetworkModel::ipInterfaceChanged()
{
NetworkManager::Device *device = qobject_cast<NetworkManager::Device*>(sender());
if (device) {
if (!device)
return;
for (NetworkModelItem *item : m_list.returnItems(NetworkItemsList::Device, device->uni())) {
if (device->ipInterfaceName().isEmpty()) {
item->setDeviceName(device->interfaceName());
......@@ -920,7 +946,6 @@ void NetworkModel::ipInterfaceChanged()
item->setDeviceName(device->ipInterfaceName());
}
}
}
}
void NetworkModel::statusChanged(NetworkManager::Status status)
......@@ -947,7 +972,9 @@ void NetworkModel::wirelessNetworkAppeared(const QString &ssid)
void NetworkModel::wirelessNetworkDisappeared(const QString &ssid)
{
NetworkManager::Device::Ptr device = NetworkManager::findNetworkInterface(qobject_cast<NetworkManager::Device*>(sender())->uni());
if (device) {
if (!device)
return;
for (NetworkModelItem *item : m_list.returnItems(NetworkItemsList::Ssid, ssid, device->uni())) {
// Remove the entire item, because it's only AP or it's a duplicated available connection
if (item->itemType() == NetworkModelItem::AvailableAccessPoint || item->duplicate()) {
......@@ -971,33 +998,35 @@ void NetworkModel::wirelessNetworkDisappeared(const QString &ssid)
qCDebug(PLASMA_NM) << "Item " << item->name() << ": wireless network removed";
}
}
}
}
void NetworkModel::wirelessNetworkReferenceApChanged(const QString &accessPoint)
{
NetworkManager::WirelessNetwork *networkPtr = qobject_cast<NetworkManager::WirelessNetwork*>(sender());
if (networkPtr) {
if (!networkPtr)
return;
for (NetworkModelItem *item : m_list.returnItems(NetworkItemsList::Ssid, networkPtr->ssid(), networkPtr->device())) {
NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(item->connectionPath());
if (connection) {
if (!connection)
continue;
NetworkManager::WirelessSetting::Ptr wirelessSetting = connection->settings()->setting(NetworkManager::Setting::Wireless).staticCast<NetworkManager::WirelessSetting>();
if (wirelessSetting) {
if (!wirelessSetting)
continue;
if (wirelessSetting->bssid().isEmpty()) {
item->setSpecificPath(accessPoint);
updateItem(item);
}
}
}
}
}
}
void NetworkModel::wirelessNetworkSignalChanged(int signal)
{
NetworkManager::WirelessNetwork *networkPtr = qobject_cast<NetworkManager::WirelessNetwork*>(sender());
if (networkPtr) {
if (!networkPtr)
return;
for (NetworkModelItem *item : m_list.returnItems(NetworkItemsList::Ssid, networkPtr->ssid(), networkPtr->device())) {
if (item->specificPath() == networkPtr->referenceAccessPoint()->uni()) {
item->setSignal(signal);
......@@ -1005,7 +1034,6 @@ void NetworkModel::wirelessNetworkSignalChanged(int signal)
// qCDebug(PLASMA_NM) << "Wireless network " << item->name() << ": signal changed to " << item->signal();
}
}
}
}
NetworkManager::WirelessSecurityType NetworkModel::alternativeWirelessSecurity(const NetworkManager::WirelessSecurityType type)
......
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