Commit 3dfd43a2 authored by Jan Grulich's avatar Jan Grulich
Browse files

Display real signal strength when BSSID is specified

Conflicts:
	libs/models/networkmodel.cpp
parent 3ad7165e
......@@ -322,14 +322,9 @@ void NetworkModel::addAvailableConnection(const QString& connection, const Netwo
}
#endif
if (item->type() == NetworkManager::ConnectionSettings::Wireless && item->mode() == NetworkManager::WirelessSetting::Infrastructure) {
bool apFound = false;
// Check whether is there an available access point for this connection and remove it, because it should be part of the connection
// Find an accesspoint which could be removed, because it will be merged with a connection
foreach (NetworkModelItem * secondItem, m_list.returnItems(NetworkItemsList::Ssid, item->ssid())) {
if (secondItem->itemType() == NetworkModelItem::AvailableAccessPoint &&
secondItem->devicePath() == item->devicePath()) {
item->setSignal(secondItem->signal());
item->setSpecificPath(secondItem->specificPath());
apFound = true;
if (secondItem->itemType() == NetworkModelItem::AvailableAccessPoint && secondItem->devicePath() == item->devicePath()) {
const int row = m_list.indexOf(secondItem);
qCDebug(PLASMA_NM) << "Access point " << secondItem->name() << ": merged to " << item->name() << " connection";
if (row >= 0) {
......@@ -342,14 +337,9 @@ void NetworkModel::addAvailableConnection(const QString& connection, const Netwo
}
}
if (!apFound) {
NetworkManager::WirelessDevice::Ptr wifiDevice = device.objectCast<NetworkManager::WirelessDevice>();
NetworkManager::WirelessNetwork::Ptr wifiNetwork = wifiDevice->findNetwork(item->ssid());
if (wifiNetwork) {
item->setSignal(wifiNetwork->signalStrength());
item->setSpecificPath(wifiNetwork->referenceAccessPoint()->uni());
}
}
NetworkManager::WirelessDevice::Ptr wifiDevice = device.objectCast<NetworkManager::WirelessDevice>();
NetworkManager::WirelessNetwork::Ptr wifiNetwork = wifiDevice->findNetwork(item->ssid());
updateFromWirelessNetwork(item, wifiNetwork);
}
updateItem(item);
break;
......@@ -513,6 +503,20 @@ void NetworkModel::updateItems()
}
}
void NetworkModel::accessPointSignalStrengthChanged(int signal)
{
NetworkManager::AccessPoint * apPtr = qobject_cast<NetworkManager::AccessPoint*>(sender());
if (apPtr) {
foreach (NetworkModelItem * item, m_list.returnItems(NetworkItemsList::Ssid, apPtr->ssid())) {
if (item->specificPath() == apPtr->uni()) {
item->setSignal(signal);
updateItem(item);
nmDebug() << "AccessPoint " << item->name() << ": signal changed to " << item->signal();
}
}
}
}
void NetworkModel::activeConnectionAdded(const QString& activeConnection)
{
NetworkManager::ActiveConnection::Ptr activeCon = NetworkManager::findActiveConnection(activeConnection);
......@@ -709,6 +713,7 @@ void NetworkModel::connectionUpdated()
item->setMode(wirelessSetting->mode());
item->setSecurityType(NetworkManager::Utils::securityTypeFromConnectionSetting(settings));
item->setSsid(wirelessSetting->ssid());
// TODO check whether BSSID has changed and update the wireless info
}
updateItem(item);
qCDebug(PLASMA_NM) << "Item " << item->name() << ": connection updated";
......@@ -876,8 +881,16 @@ void NetworkModel::wirelessNetworkReferenceApChanged(const QString& accessPoint)
if (networkPtr) {
foreach (NetworkModelItem * item, m_list.returnItems(NetworkItemsList::Ssid, networkPtr->ssid(), networkPtr->device())) {
item->setSpecificPath(accessPoint);
updateItem(item);
NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(item->connectionPath());
if (connection) {
NetworkManager::WirelessSetting::Ptr wirelessSetting = connection->settings()->setting(NetworkManager::Setting::Wireless).staticCast<NetworkManager::WirelessSetting>();
if (wirelessSetting) {
if (wirelessSetting->bssid().isEmpty()) {
item->setSpecificPath(accessPoint);
updateItem(item);
}
}
}
}
}
}
......@@ -887,9 +900,11 @@ void NetworkModel::wirelessNetworkSignalChanged(int signal)
NetworkManager::WirelessNetwork * networkPtr = qobject_cast<NetworkManager::WirelessNetwork*>(sender());
if (networkPtr) {
foreach (NetworkModelItem * item, m_list.returnItems(NetworkItemsList::Ssid, networkPtr->ssid(), networkPtr->device())) {
item->setSignal(signal);
updateItem(item);
// qCDebug(PLASMA_NM) << "Wireless network " << item->name() << ": signal changed to " << item->signal();
if (item->specificPath() == networkPtr->referenceAccessPoint()->uni()) {
item->setSignal(signal);
updateItem(item);
// qCDebug(PLASMA_NM) << "Wireless network " << item->name() << ": signal changed to " << item->signal();
}
}
}
}
......@@ -907,3 +922,27 @@ NetworkManager::Utils::WirelessSecurityType NetworkModel::alternativeWirelessSec
}
return type;
}
void NetworkModel::updateFromWirelessNetwork(NetworkModelItem* item, const NetworkManager::WirelessNetwork::Ptr network)
{
// Check whether the connection is associated with some concrete AP
NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(item->connectionPath());
if (connection) {
NetworkManager::WirelessSetting::Ptr wirelessSetting = connection->settings()->setting(NetworkManager::Setting::Wireless).staticCast<NetworkManager::WirelessSetting>();
if (wirelessSetting) {
if (!wirelessSetting->bssid().isEmpty()) {
foreach (const NetworkManager::AccessPoint::Ptr ap, network->accessPoints()) {
if (ap->hardwareAddress() == NetworkManager::Utils::macAddressAsString(wirelessSetting->bssid())) {
item->setSignal(ap->signalStrength());
item->setSpecificPath(ap->uni());
// We need to watch this AP for signal changes
connect(ap.data(), SIGNAL(signalStrengthChanged(int)), SLOT(accessPointSignalStrengthChanged(int)), Qt::UniqueConnection);
}
}
} else {
item->setSignal(network->signalStrength());
item->setSpecificPath(network->referenceAccessPoint()->uni());
}
}
}
}
......@@ -81,6 +81,7 @@ public Q_SLOTS:
void updateItems();
private Q_SLOTS:
void accessPointSignalStrengthChanged(int signal);
void activeConnectionAdded(const QString& activeConnection);
void activeConnectionRemoved(const QString& activeConnection);
void activeConnectionStateChanged(NetworkManager::ActiveConnection::State state);
......@@ -120,6 +121,7 @@ private:
void initializeSignals(const NetworkManager::Device::Ptr& device);
void initializeSignals(const NetworkManager::WirelessNetwork::Ptr& network);
void updateItem(NetworkModelItem * item);
void updateFromWirelessNetwork(NetworkModelItem * item, const NetworkManager::WirelessNetwork::Ptr network);
NetworkManager::Utils::WirelessSecurityType alternativeWirelessSecurity(const NetworkManager::Utils::WirelessSecurityType type);
};
......
......@@ -450,11 +450,11 @@ void NetworkModelItem::updateDetails()
if (device) {
wirelessDevice = device.objectCast<NetworkManager::WirelessDevice>();
}
NetworkManager::WirelessNetwork::Ptr network;
NetworkManager::AccessPoint::Ptr ap;
if (wirelessDevice) {
network = wirelessDevice->findNetwork(m_ssid);
ap = wirelessDevice->findAccessPoint(m_specificPath);
}
m_details += UiUtils::wirelessDetails(wirelessDevice, network, connection, detailsList);
m_details += UiUtils::wirelessDetails(wirelessDevice, ap, connection, detailsList);
} else if (m_type == NetworkManager::ConnectionSettings::Vpn) {
NetworkManager::ActiveConnection::Ptr active = NetworkManager::findActiveConnection(m_activeConnectionPath);
NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(m_connectionPath);
......
......@@ -888,7 +888,7 @@ QString UiUtils::wiredDetails(const WiredDevice::Ptr& wiredDevice, const Network
return details;
}
QString UiUtils::wirelessDetails(const WirelessDevice::Ptr& wirelessDevice, const WirelessNetwork::Ptr& network, const NetworkManager::Connection::Ptr& connection, const QStringList& keys)
QString UiUtils::wirelessDetails(const WirelessDevice::Ptr& wirelessDevice, const AccessPoint::Ptr& ap, const NetworkManager::Connection::Ptr& connection, const QStringList& keys)
{
const QString format = "<tr><td align=\"right\" width=\"50%\"><b>%1</b></td><td align=\"left\" width=\"50%\">&nbsp;%2</td></tr>";
QString details;
......@@ -896,10 +896,6 @@ QString UiUtils::wirelessDetails(const WirelessDevice::Ptr& wirelessDevice, cons
const bool connected = wirelessDevice && connection && wirelessDevice->activeConnection() &&
wirelessDevice->activeConnection()->connection() == connection && wirelessDevice->activeConnection()->state() == ActiveConnection::Activated;
NetworkManager::AccessPoint::Ptr ap;
if (network) {
ap = network->referenceAccessPoint();
}
foreach (const QString& key, keys) {
if (key == "interface:bitrate") {
......@@ -915,12 +911,12 @@ QString UiUtils::wirelessDetails(const WirelessDevice::Ptr& wirelessDevice, cons
details += QString(format).arg(i18n("Mode:"), UiUtils::operationModeToString(wirelessDevice->mode()));
}
} else if (key == "wireless:signal") {
if (network) {
details += QString(format).arg(i18n("Signal strength:"), i18n("%1%", network->signalStrength()));
if (ap) {
details += QString(format).arg(i18n("Signal strength:"), i18n("%1%", ap->signalStrength()));
}
} else if (key == "wireless:ssid") {
if (network) {
details += QString(format).arg(i18n("Access point (SSID):"), network->ssid());
if (ap) {
details += QString(format).arg(i18n("Access point (SSID):"), ap->ssid());
}
} else if (key == "wireless:accesspoint") {
if (ap) {
......
......@@ -120,7 +120,7 @@ public:
static QString vpnDetails(const NetworkManager::VpnConnection::Ptr & vpnConnection, const NetworkManager::VpnSetting::Ptr & vpnSetting, const QStringList & keys);
static QString wimaxDetails(const NetworkManager::WimaxDevice::Ptr & wimaxDevice, const NetworkManager::WimaxNsp::Ptr & wimaxNsp, const NetworkManager::Connection::Ptr & connection, const QStringList & keys);
static QString wiredDetails(const NetworkManager::WiredDevice::Ptr & wiredDevice, const NetworkManager::Connection::Ptr & connection, const QStringList & keys);
static QString wirelessDetails(const NetworkManager::WirelessDevice::Ptr & wirelessDevice, const NetworkManager::WirelessNetwork::Ptr & network, const NetworkManager::Connection::Ptr & connection, const QStringList & keys);
static QString wirelessDetails(const NetworkManager::WirelessDevice::Ptr & wirelessDevice, const NetworkManager::AccessPoint::Ptr & network, const NetworkManager::Connection::Ptr & connection, const QStringList & keys);
static QString formatDateRelative(const QDateTime & lastUsed);
static QString formatLastUsedDateRelative(const QDateTime & lastUsed);
};
......
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