NetworkSetup: list and join wireless networks

* Reuse the logic from the old network preflet for now. Something better
can be done later.
This commit is contained in:
Adrien Destugues 2014-09-19 17:50:06 +02:00
parent 763cd902f6
commit ee2985c144
7 changed files with 116 additions and 17 deletions

View File

@ -9,7 +9,10 @@
#include "InterfaceHardwareView.h" #include "InterfaceHardwareView.h"
#include "InterfaceView.h"
#include "NetworkSettings.h" #include "NetworkSettings.h"
#include "WirelessNetworkMenuItem.h"
#include <Catalog.h> #include <Catalog.h>
#include <ControlLook.h> #include <ControlLook.h>
@ -22,6 +25,7 @@
#include <StringView.h> #include <StringView.h>
#include <TextControl.h> #include <TextControl.h>
#include <set>
#include <stdio.h> #include <stdio.h>
@ -70,21 +74,25 @@ InterfaceHardwareView::InterfaceHardwareView(NetworkSettings* settings)
fLinkRxField = new BStringView("rx field", ""); fLinkRxField = new BStringView("rx field", "");
fLinkRxField ->SetExplicitMinSize(BSize(minimumWidth, B_SIZE_UNSET)); fLinkRxField ->SetExplicitMinSize(BSize(minimumWidth, B_SIZE_UNSET));
Update(); fNetworkMenuField = new BMenuField(B_TRANSLATE("Network:"), new BMenu(
// Populate the fields B_TRANSLATE("Choose automatically")));
fNetworkMenuField->SetAlignment(B_ALIGN_RIGHT);
fNetworkMenuField->Menu()->SetLabelFromMarked(true);
BLayoutBuilder::Group<>(this) BLayoutBuilder::Group<>(this)
.AddGrid() .AddGrid()
.Add(status, 0, 0) .Add(status, 0, 0)
.Add(fStatusField, 1, 0) .Add(fStatusField, 1, 0)
.Add(macAddress, 0, 1) .Add(fNetworkMenuField->CreateLabelLayoutItem(), 0, 1)
.Add(fMacAddressField, 1, 1) .Add(fNetworkMenuField->CreateMenuBarLayoutItem(), 1, 1)
.Add(linkSpeed, 0, 2) .Add(macAddress, 0, 2)
.Add(fLinkSpeedField, 1, 2) .Add(fMacAddressField, 1, 2)
.Add(linkTx, 0, 3) .Add(linkSpeed, 0, 3)
.Add(fLinkTxField, 1, 3) .Add(fLinkSpeedField, 1, 3)
.Add(linkRx, 0, 4) .Add(linkTx, 0, 4)
.Add(fLinkRxField, 1, 4) .Add(fLinkTxField, 1, 4)
.Add(linkRx, 0, 5)
.Add(fLinkRxField, 1, 5)
.End() .End()
.AddGlue() .AddGlue()
.SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING,
@ -104,7 +112,8 @@ InterfaceHardwareView::~InterfaceHardwareView()
void void
InterfaceHardwareView::AttachedToWindow() InterfaceHardwareView::AttachedToWindow()
{ {
Update();
// Populate the fields
} }
@ -112,6 +121,11 @@ void
InterfaceHardwareView::MessageReceived(BMessage* message) InterfaceHardwareView::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case kMsgNetwork:
{
fSettings->SetWirelessNetwork(message->FindString("name"));
break;
}
default: default:
BView::MessageReceived(message); BView::MessageReceived(message);
} }
@ -163,6 +177,62 @@ InterfaceHardwareView::Update()
stats.receive.bytes / 1024); stats.receive.bytes / 1024);
fLinkRxField->SetText(buffer); fLinkRxField->SetText(buffer);
// TODO move the wireless info to a separate tab. We should have a
// BListView of available networks, rather than a menu, to make them more
// readable and easier to browse and select.
if (fNetworkMenuField->IsHidden(fNetworkMenuField)
&& fSettings->IsWireless()) {
fNetworkMenuField->Show();
} else if (!fNetworkMenuField->IsHidden(fNetworkMenuField)
&& !fSettings->IsWireless()) {
fNetworkMenuField->Hide();
}
if (fSettings->IsWireless()) {
// Rebuild network menu
BMenu* menu = fNetworkMenuField->Menu();
menu->RemoveItems(0, menu->CountItems(), true);
std::set<BNetworkAddress> associated;
BNetworkAddress address;
uint32 cookie = 0;
while (fSettings->GetNextAssociatedNetwork(cookie, address) == B_OK)
associated.insert(address);
wireless_network network;
int32 count = 0;
cookie = 0;
while (fSettings->GetNextNetwork(cookie, network) == B_OK) {
BMessage* message = new BMessage(kMsgNetwork);
message->AddString("device", fSettings->Name());
message->AddString("name", network.name);
BMenuItem* item = new WirelessNetworkMenuItem(network.name,
network.signal_strength,
network.authentication_mode, message);
if (associated.find(network.address) != associated.end())
item->SetMarked(true);
menu->AddItem(item);
count++;
}
if (count == 0) {
BMenuItem* item = new BMenuItem(
B_TRANSLATE("<no wireless networks found>"), NULL);
item->SetEnabled(false);
menu->AddItem(item);
} else {
BMenuItem* item = new BMenuItem(
B_TRANSLATE("Choose automatically"), NULL);
if (menu->FindMarked() == NULL)
item->SetMarked(true);
menu->AddItem(item, 0);
menu->AddItem(new BSeparatorItem(), 1);
}
menu->SetTargetForItems(this);
}
return B_OK; return B_OK;
} }

View File

@ -15,6 +15,7 @@
#include <GroupView.h> #include <GroupView.h>
class BMenuField;
class BMessage; class BMessage;
class BRect; class BRect;
class BStringView; class BStringView;
@ -42,6 +43,8 @@ private:
BStringView* fLinkSpeedField; BStringView* fLinkSpeedField;
BStringView* fLinkTxField; BStringView* fLinkTxField;
BStringView* fLinkRxField; BStringView* fLinkRxField;
BMenuField* fNetworkMenuField;
}; };

View File

@ -21,8 +21,7 @@
enum { enum {
MSG_IP_SAVE = 'ipap', kMsgNetwork = 'netw'
MSG_IP_REVERT = 'iprv'
}; };

View File

@ -95,8 +95,6 @@ InterfacesAddOn::CreateView()
.AddGlue() .AddGlue()
.Add(fRenegotiate) .Add(fRenegotiate)
.End() .End()
.SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING,
B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
); );
return this; return this;

View File

@ -286,6 +286,9 @@ void
NetworkSettings::SetConfiguration() NetworkSettings::SetConfiguration()
{ {
printf("Setting %s\n", Name()); printf("Setting %s\n", Name());
fNetworkDevice->JoinNetwork(WirelessNetwork());
for (int index = 0; index < MAX_PROTOCOLS; index++) { for (int index = 0; index < MAX_PROTOCOLS; index++) {
int inet_id = fProtocols[index].inet_id; int inet_id = fProtocols[index].inet_id;
if (fProtocols[index].present) { if (fProtocols[index].present) {
@ -362,3 +365,19 @@ NetworkSettings::HardwareAddress()
return NULL; return NULL;
} }
status_t
NetworkSettings::GetNextAssociatedNetwork(uint32& cookie,
BNetworkAddress& address)
{
return fNetworkDevice->GetNextAssociatedNetwork(cookie, address);
}
status_t
NetworkSettings::GetNextNetwork(uint32& cookie, wireless_network& network)
{
return fNetworkDevice->GetNextNetwork(cookie, network);
}

View File

@ -61,8 +61,8 @@ public:
void SetDisabled(bool disabled) void SetDisabled(bool disabled)
{ fDisabled = disabled; } { fDisabled = disabled; }
// void SetWirelessNetwork(const char* name) void SetWirelessNetwork(const char* name)
// { fWirelessNetwork.SetTo(name); } { fWirelessNetwork.SetTo(name); }
// void SetDomain(const BString& domain) // void SetDomain(const BString& domain)
// { fDomain = domain; } // { fDomain = domain; }
@ -98,6 +98,10 @@ public:
const char* HardwareAddress(); const char* HardwareAddress();
const BString& WirelessNetwork() { return fWirelessNetwork; } const BString& WirelessNetwork() { return fWirelessNetwork; }
status_t GetNextAssociatedNetwork(uint32& cookie,
BNetworkAddress& address);
status_t GetNextNetwork(uint32& cookie,
wireless_network& network);
BObjectList<BString>& NameServers() { return fNameServers; } BObjectList<BString>& NameServers() { return fNameServers; }

View File

@ -1,10 +1,16 @@
SubDir HAIKU_TOP src tests kits net preflet ; SubDir HAIKU_TOP src tests kits net preflet ;
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src apps networkstatus ] ;
Preference NetworkSetup : Preference NetworkSetup :
NetworkSetup.cpp NetworkSetup.cpp
NetworkSetupWindow.cpp NetworkSetupWindow.cpp
NetworkSetupProfile.cpp NetworkSetupProfile.cpp
NetworkSetupAddOn.cpp NetworkSetupAddOn.cpp
# from NetworkStatus
RadioView.cpp
WirelessNetworkMenuItem.cpp
: be root [ TargetLibstdc++ ] localestub : be root [ TargetLibstdc++ ] localestub
: NetworkSetup.rdef : NetworkSetup.rdef
; ;