diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.cpp b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.cpp index 01403ca532..4b3cdb88c6 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.cpp +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.cpp @@ -9,7 +9,10 @@ #include "InterfaceHardwareView.h" + +#include "InterfaceView.h" #include "NetworkSettings.h" +#include "WirelessNetworkMenuItem.h" #include #include @@ -22,6 +25,7 @@ #include #include +#include #include @@ -70,21 +74,25 @@ InterfaceHardwareView::InterfaceHardwareView(NetworkSettings* settings) fLinkRxField = new BStringView("rx field", ""); fLinkRxField ->SetExplicitMinSize(BSize(minimumWidth, B_SIZE_UNSET)); - Update(); - // Populate the fields + fNetworkMenuField = new BMenuField(B_TRANSLATE("Network:"), new BMenu( + B_TRANSLATE("Choose automatically"))); + fNetworkMenuField->SetAlignment(B_ALIGN_RIGHT); + fNetworkMenuField->Menu()->SetLabelFromMarked(true); BLayoutBuilder::Group<>(this) .AddGrid() .Add(status, 0, 0) .Add(fStatusField, 1, 0) - .Add(macAddress, 0, 1) - .Add(fMacAddressField, 1, 1) - .Add(linkSpeed, 0, 2) - .Add(fLinkSpeedField, 1, 2) - .Add(linkTx, 0, 3) - .Add(fLinkTxField, 1, 3) - .Add(linkRx, 0, 4) - .Add(fLinkRxField, 1, 4) + .Add(fNetworkMenuField->CreateLabelLayoutItem(), 0, 1) + .Add(fNetworkMenuField->CreateMenuBarLayoutItem(), 1, 1) + .Add(macAddress, 0, 2) + .Add(fMacAddressField, 1, 2) + .Add(linkSpeed, 0, 3) + .Add(fLinkSpeedField, 1, 3) + .Add(linkTx, 0, 4) + .Add(fLinkTxField, 1, 4) + .Add(linkRx, 0, 5) + .Add(fLinkRxField, 1, 5) .End() .AddGlue() .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, @@ -104,7 +112,8 @@ InterfaceHardwareView::~InterfaceHardwareView() void InterfaceHardwareView::AttachedToWindow() { - + Update(); + // Populate the fields } @@ -112,6 +121,11 @@ void InterfaceHardwareView::MessageReceived(BMessage* message) { switch (message->what) { + case kMsgNetwork: + { + fSettings->SetWirelessNetwork(message->FindString("name")); + break; + } default: BView::MessageReceived(message); } @@ -163,6 +177,62 @@ InterfaceHardwareView::Update() stats.receive.bytes / 1024); 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 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(""), 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; } diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.h b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.h index 09c8859097..d6a7384842 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.h +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.h @@ -15,6 +15,7 @@ #include +class BMenuField; class BMessage; class BRect; class BStringView; @@ -42,6 +43,8 @@ private: BStringView* fLinkSpeedField; BStringView* fLinkTxField; BStringView* fLinkRxField; + + BMenuField* fNetworkMenuField; }; diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceView.h b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceView.h index 749f594bfd..57aeda2f7c 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceView.h +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceView.h @@ -21,8 +21,7 @@ enum { - MSG_IP_SAVE = 'ipap', - MSG_IP_REVERT = 'iprv' + kMsgNetwork = 'netw' }; diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp index 0851c13d1b..8a916fbab4 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfacesAddOn.cpp @@ -95,8 +95,6 @@ InterfacesAddOn::CreateView() .AddGlue() .Add(fRenegotiate) .End() - .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, - B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) ); return this; diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp b/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp index c538f6d6c1..97771bd343 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp +++ b/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.cpp @@ -286,6 +286,9 @@ void NetworkSettings::SetConfiguration() { printf("Setting %s\n", Name()); + + fNetworkDevice->JoinNetwork(WirelessNetwork()); + for (int index = 0; index < MAX_PROTOCOLS; index++) { int inet_id = fProtocols[index].inet_id; if (fProtocols[index].present) { @@ -362,3 +365,19 @@ NetworkSettings::HardwareAddress() 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); +} + diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h b/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h index 0ecce147f1..e2ed80477b 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h +++ b/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h @@ -61,8 +61,8 @@ public: void SetDisabled(bool disabled) { fDisabled = disabled; } -// void SetWirelessNetwork(const char* name) -// { fWirelessNetwork.SetTo(name); } + void SetWirelessNetwork(const char* name) + { fWirelessNetwork.SetTo(name); } // void SetDomain(const BString& domain) // { fDomain = domain; } @@ -98,6 +98,10 @@ public: const char* HardwareAddress(); const BString& WirelessNetwork() { return fWirelessNetwork; } + status_t GetNextAssociatedNetwork(uint32& cookie, + BNetworkAddress& address); + status_t GetNextNetwork(uint32& cookie, + wireless_network& network); BObjectList& NameServers() { return fNameServers; } diff --git a/src/tests/kits/net/preflet/Jamfile b/src/tests/kits/net/preflet/Jamfile index 634c0297cf..c9675da528 100644 --- a/src/tests/kits/net/preflet/Jamfile +++ b/src/tests/kits/net/preflet/Jamfile @@ -1,10 +1,16 @@ SubDir HAIKU_TOP src tests kits net preflet ; +SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src apps networkstatus ] ; Preference NetworkSetup : NetworkSetup.cpp NetworkSetupWindow.cpp NetworkSetupProfile.cpp NetworkSetupAddOn.cpp + + # from NetworkStatus + RadioView.cpp + WirelessNetworkMenuItem.cpp + : be root [ TargetLibstdc++ ] localestub : NetworkSetup.rdef ;