NetworkStatus: Sort wireless networks by signal strength.

This commit is contained in:
Michael Lotz
2014-09-05 00:28:30 +02:00
parent 4d292b8186
commit aba4cb2085
+29 -3
View File
@@ -12,7 +12,9 @@
#include "NetworkStatusView.h"
#include <algorithm>
#include <set>
#include <vector>
#include <arpa/inet.h>
#include <net/if.h>
@@ -76,6 +78,19 @@ const uint32 kMinIconHeight = 16;
// #pragma mark -
static bool
signal_strength_compare(const wireless_network &a,
const wireless_network &b)
{
if (a.signal_strength == b.signal_strength)
return strcmp(a.name, b.name) > 0;
return a.signal_strength > b.signal_strength;
}
// #pragma mark -
NetworkStatusView::NetworkStatusView(BRect frame, int32 resizingMode,
bool inDeskbar)
: BView(frame, kDeskbarItemName, resizingMode,
@@ -404,10 +419,21 @@ NetworkStatusView::MouseDown(BPoint point)
while (wifiDevice.GetNextAssociatedNetwork(cookie, address) == B_OK)
associated.insert(address);
wireless_network network;
int32 count = 0;
cookie = 0;
while (wifiDevice.GetNextNetwork(cookie, network) == B_OK) {
wireless_network network;
typedef std::vector<wireless_network> WirelessNetworkVector;
WirelessNetworkVector wirelessNetworks;
while (wifiDevice.GetNextNetwork(cookie, network) == B_OK)
wirelessNetworks.push_back(network);
std::sort(wirelessNetworks.begin(), wirelessNetworks.end(),
signal_strength_compare);
int32 count = 0;
for (WirelessNetworkVector::iterator it = wirelessNetworks.begin();
it != wirelessNetworks.end(); it++) {
wireless_network &network = *it;
BMessage* message = new BMessage(kMsgJoinNetwork);
message->AddString("device", wifiInterface);
message->AddString("name", network.name);