From 2895c48c1286e7cc275a023deb291d76af46d62e Mon Sep 17 00:00:00 2001 From: Alexander von Gluck IV Date: Sun, 7 Apr 2013 06:44:37 +0000 Subject: [PATCH] NetworkSetup: Add stats and wifi network name * Add ability for fSettings to pass on network stats * Show KB Sent / Received for interface * Drop the wireless / wired tab name. (we are going to need another tab for wifi) * Add wifi network name to connection field if interface is wifi. --- .../InterfacesAddOn/InterfaceHardwareView.cpp | 54 +++++++++++++++++-- .../InterfacesAddOn/InterfaceHardwareView.h | 4 ++ .../InterfacesAddOn/InterfaceWindow.cpp | 9 +--- .../preflet/InterfacesAddOn/NetworkSettings.h | 3 ++ 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.cpp b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.cpp index dd0ed59c9e..16b559c232 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.cpp +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.cpp @@ -22,6 +22,8 @@ #include #include +#include + #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "IntefaceHardwareView" @@ -57,7 +59,19 @@ InterfaceHardwareView::InterfaceHardwareView(BRect frame, fLinkSpeedField = new BStringView("link speed field", ""); fLinkSpeedField->SetExplicitMinSize(BSize(minimumWidth, B_SIZE_UNSET)); - Revert(); + // TODO: These metrics may be better in a BScrollView? + BStringView* linkTx = new BStringView("tx label", + B_TRANSLATE("Sent:")); + linkTx->SetAlignment(B_ALIGN_RIGHT); + fLinkTxField = new BStringView("tx field", ""); + fLinkTxField ->SetExplicitMinSize(BSize(minimumWidth, B_SIZE_UNSET)); + BStringView* linkRx = new BStringView("rx label", + B_TRANSLATE("Received:")); + linkRx->SetAlignment(B_ALIGN_RIGHT); + fLinkRxField = new BStringView("rx field", ""); + fLinkRxField ->SetExplicitMinSize(BSize(minimumWidth, B_SIZE_UNSET)); + + Update(); // Populate the fields BLayoutBuilder::Group<>(this) @@ -68,6 +82,10 @@ InterfaceHardwareView::InterfaceHardwareView(BRect frame, .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) .End() .AddGlue() .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, @@ -106,11 +124,27 @@ InterfaceHardwareView::MessageReceived(BMessage* message) status_t InterfaceHardwareView::Revert() +{ + Update(); + return B_OK; +} + + +status_t +InterfaceHardwareView::Update() { // Populate fields with current settings - if (fSettings->HasLink()) - fStatusField->SetText(B_TRANSLATE("connected")); - else + if (fSettings->HasLink()) { + if (fSettings->IsWireless()) { + BString network = fSettings->WirelessNetwork(); + network.Prepend(" ("); + network.Prepend(B_TRANSLATE("connected")); + network.Append(")"); + fStatusField->SetText(network.String()); + } else { + fStatusField->SetText(B_TRANSLATE("connected")); + } + } else fStatusField->SetText(B_TRANSLATE("disconnected")); fMacAddressField->SetText(fSettings->HardwareAddress()); @@ -118,6 +152,18 @@ InterfaceHardwareView::Revert() // TODO : Find how to get link speed fLinkSpeedField->SetText("100 Mb/s"); + // Update Link stats + ifreq_stats stats; + char buffer[100]; + fSettings->Stats(&stats); + snprintf(buffer, sizeof(buffer), B_TRANSLATE("%" B_PRIu64 " KBytes"), + stats.send.bytes / 1024); + fLinkTxField->SetText(buffer); + + snprintf(buffer, sizeof(buffer), B_TRANSLATE("%" B_PRIu64 " KBytes"), + stats.receive.bytes / 1024); + fLinkRxField->SetText(buffer); + return B_OK; } diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.h b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.h index 0d649c00be..43ddb790f9 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.h +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceHardwareView.h @@ -31,6 +31,8 @@ public: status_t Save(); private: + status_t Update(); + void _EnableFields(bool enabled); NetworkSettings* fSettings; @@ -38,6 +40,8 @@ private: BStringView* fStatusField; BStringView* fMacAddressField; BStringView* fLinkSpeedField; + BStringView* fLinkTxField; + BStringView* fLinkRxField; }; diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.cpp b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.cpp index 9f956a1735..38de21a6b7 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.cpp +++ b/src/tests/kits/net/preflet/InterfacesAddOn/InterfaceWindow.cpp @@ -104,14 +104,9 @@ InterfaceWindow::_PopulateTabs() fTabHardwareView = new InterfaceHardwareView(frame, fNetworkSettings); fTabView->AddTab(fTabHardwareView, hardwareTab); + hardwareTab->SetLabel(B_TRANSLATE("Interface")); - if (fNetworkSettings->IsEthernet()) - hardwareTab->SetLabel(B_TRANSLATE("Wired")); - else - hardwareTab->SetLabel(B_TRANSLATE("Wireless")); - - for (int index = 0; index < MAX_PROTOCOLS; index++) - { + for (int index = 0; index < MAX_PROTOCOLS; index++) { if (supportedFamilies[index].present) { int inet_id = supportedFamilies[index].inet_id; fTabIPView[inet_id] = new InterfaceAddressView(frame, diff --git a/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h b/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h index d2b476a332..0ecce147f1 100644 --- a/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h +++ b/src/tests/kits/net/preflet/InterfacesAddOn/NetworkSettings.h @@ -83,6 +83,9 @@ public: const char* Name() { return fName.String(); } const char* Domain() { return fDomain.String(); } + status_t Stats(ifreq_stats* ptr) + { return fNetworkInterface->GetStats(*ptr); } + bool IsDisabled() { return fDisabled; } bool IsWireless() {