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.
This commit is contained in:
parent
960bf9918b
commit
2895c48c12
@ -22,6 +22,8 @@
|
||||
#include <StringView.h>
|
||||
#include <TextControl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user