Some cleanup:

* Reordered to have the constructor/destructor first.
* Two blanks between functions.
* Removed superfluous constructor calls.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24953 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2008-04-13 04:57:13 +00:00
parent 4b3b81da9e
commit 6ad23dbbf4
3 changed files with 147 additions and 147 deletions

View File

@ -1,11 +1,11 @@
/*
* Copyright 2004-2007 Haiku Inc. All rights reserved.
* Copyright 2004-2008 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Author:
* Authors:
* Andre Alves Garzia, andre@andregarzia.com
* With code from:
* Axel Dorfler
* Stephan Assmuß
* Axel Dörfler
* Hugo Santos
*/
@ -79,90 +79,12 @@ SetupTextControl(BTextControl *control)
}
bool
EthernetSettingsView::_PrepareRequest(struct ifreq& request, const char* name)
{
// This function is used for talking direct to the stack.
// It's used by _ShowConfiguration.
if (strlen(name) > IF_NAMESIZE)
return false;
strcpy(request.ifr_name, name);
return true;
}
void
EthernetSettingsView::_GatherInterfaces()
{
// iterate over all interfaces and retrieve minimal status
ifconf config;
config.ifc_len = sizeof(config.ifc_value);
if (ioctl(fSocket, SIOCGIFCOUNT, &config, sizeof(struct ifconf)) < 0)
return;
uint32 count = (uint32)config.ifc_value;
if (count == 0)
return;
void* buffer = malloc(count * sizeof(struct ifreq));
if (buffer == NULL)
return;
MemoryDeleter deleter(buffer);
config.ifc_len = count * sizeof(struct ifreq);
config.ifc_buf = buffer;
if (ioctl(fSocket, SIOCGIFCONF, &config, sizeof(struct ifconf)) < 0)
return;
ifreq* interface = (ifreq*)buffer;
fInterfaces.MakeEmpty();
for (uint32 i = 0; i < count; i++) {
if (strncmp(interface->ifr_name, "loop", 4) && interface->ifr_name[0]) {
fInterfaces.AddItem(new BString(interface->ifr_name));
fSettings.AddItem(new Settings(interface->ifr_name));
}
interface = (ifreq*)((addr_t)interface + IF_NAMESIZE
+ interface->ifr_addr.sa_len);
}
}
void
EthernetSettingsView::AttachedToWindow()
{
fApplyButton->SetTarget(this);
fRevertButton->SetTarget(this);
fIPTextControl->SetTarget(this);
fNetMaskTextControl->SetTarget(this);
fGatewayTextControl->SetTarget(this);
fPrimaryDNSTextControl->SetTarget(this);
fSecondaryDNSTextControl->SetTarget(this);
fDeviceMenuField->Menu()->SetTargetForItems(this);
fTypeMenuField->Menu()->SetTargetForItems(this);
// display settigs of first adapter on startup
_ShowConfiguration(fSettings.ItemAt(0));
}
void
EthernetSettingsView::DetachedFromWindow()
{
}
// #pragma mark -
EthernetSettingsView::EthernetSettingsView()
: BView("EthernetSettingsView", 0, NULL)
, fInterfaces()
, fSettings()
, fCurrentSettings(NULL)
: BView("EthernetSettingsView", 0, NULL),
fCurrentSettings(NULL)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
@ -257,11 +179,92 @@ EthernetSettingsView::EthernetSettingsView()
rootLayout->AddView(buttonGroup);
}
EthernetSettingsView::~EthernetSettingsView()
{
close(fSocket);
}
bool
EthernetSettingsView::_PrepareRequest(struct ifreq& request, const char* name)
{
// This function is used for talking direct to the stack.
// It's used by _ShowConfiguration.
if (strlen(name) > IF_NAMESIZE)
return false;
strcpy(request.ifr_name, name);
return true;
}
void
EthernetSettingsView::_GatherInterfaces()
{
// iterate over all interfaces and retrieve minimal status
ifconf config;
config.ifc_len = sizeof(config.ifc_value);
if (ioctl(fSocket, SIOCGIFCOUNT, &config, sizeof(struct ifconf)) < 0)
return;
uint32 count = (uint32)config.ifc_value;
if (count == 0)
return;
void* buffer = malloc(count * sizeof(struct ifreq));
if (buffer == NULL)
return;
MemoryDeleter deleter(buffer);
config.ifc_len = count * sizeof(struct ifreq);
config.ifc_buf = buffer;
if (ioctl(fSocket, SIOCGIFCONF, &config, sizeof(struct ifconf)) < 0)
return;
ifreq* interface = (ifreq*)buffer;
fInterfaces.MakeEmpty();
for (uint32 i = 0; i < count; i++) {
if (strncmp(interface->ifr_name, "loop", 4) && interface->ifr_name[0]) {
fInterfaces.AddItem(new BString(interface->ifr_name));
fSettings.AddItem(new Settings(interface->ifr_name));
}
interface = (ifreq*)((addr_t)interface + IF_NAMESIZE
+ interface->ifr_addr.sa_len);
}
}
void
EthernetSettingsView::AttachedToWindow()
{
fApplyButton->SetTarget(this);
fRevertButton->SetTarget(this);
fIPTextControl->SetTarget(this);
fNetMaskTextControl->SetTarget(this);
fGatewayTextControl->SetTarget(this);
fPrimaryDNSTextControl->SetTarget(this);
fSecondaryDNSTextControl->SetTarget(this);
fDeviceMenuField->Menu()->SetTargetForItems(this);
fTypeMenuField->Menu()->SetTargetForItems(this);
// display settigs of first adapter on startup
_ShowConfiguration(fSettings.ItemAt(0));
}
void
EthernetSettingsView::DetachedFromWindow()
{
}
void
EthernetSettingsView::_ShowConfiguration(Settings* settings)
{

View File

@ -1,18 +1,16 @@
/*
* Copyright 2004-2007 Haiku Inc. All rights reserved.
* Copyright 2004-2008 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Author:
* Andre Alves Garzia, andre@andregarzia.com
* With code from:
* Axel Dorfler
* Hugo Santos
*/
#include "NetworkWindow.h"
#include <Application.h>
#include <GroupLayout.h>
#include "NetworkWindow.h"
#include "EthernetSettingsView.h"
@ -22,8 +20,13 @@ NetworkWindow::NetworkWindow()
| B_AUTO_UPDATE_SIZE_LIMITS)
{
SetLayout(new BGroupLayout(B_HORIZONTAL));
fEthView = new EthernetSettingsView();
GetLayout()->AddView(fEthView);
fEthernetView = new EthernetSettingsView();
GetLayout()->AddView(fEthernetView);
}
NetworkWindow::~NetworkWindow()
{
}
@ -37,10 +40,6 @@ NetworkWindow::MessageReceived(BMessage* message)
}
NetworkWindow::~NetworkWindow()
{
}
bool
NetworkWindow::QuitRequested()

View File

@ -1,30 +1,28 @@
/*
* Copyright 2004-2007 Haiku Inc. All rights reserved.
* Copyright 2004-2008 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Author:
* Andre Alves Garzia, andre@andregarzia.com
* With code from:
* Axel Dorfler
* Hugo Santos
*/
#ifndef NETWORK_WINDOW_H
#define NETWORK_WINDOW_H
#include <Window.h>
#include "EthernetSettingsView.h"
class NetworkWindow : public BWindow {
public:
NetworkWindow();
virtual ~NetworkWindow();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage* mesage);
private:
EthernetSettingsView *fEthView;
public:
NetworkWindow();
virtual ~NetworkWindow();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage* mesage);
private:
EthernetSettingsView* fEthernetView;
};
#endif /* NETWORK_WINDOW_H */
#endif /* NETWORK_WINDOW_H */