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:
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Author:
|
* Authors:
|
||||||
* Andre Alves Garzia, [email protected]
|
* Andre Alves Garzia, [email protected]
|
||||||
* With code from:
|
* Stephan Assmuß
|
||||||
* Axel Dorfler
|
* Axel Dörfler
|
||||||
* Hugo Santos
|
* Hugo Santos
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -79,90 +79,12 @@ SetupTextControl(BTextControl *control)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
// #pragma mark -
|
||||||
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()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
EthernetSettingsView::EthernetSettingsView()
|
EthernetSettingsView::EthernetSettingsView()
|
||||||
: BView("EthernetSettingsView", 0, NULL)
|
: BView("EthernetSettingsView", 0, NULL),
|
||||||
, fInterfaces()
|
fCurrentSettings(NULL)
|
||||||
, fSettings()
|
|
||||||
, fCurrentSettings(NULL)
|
|
||||||
{
|
{
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
@@ -257,11 +179,92 @@ EthernetSettingsView::EthernetSettingsView()
|
|||||||
rootLayout->AddView(buttonGroup);
|
rootLayout->AddView(buttonGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EthernetSettingsView::~EthernetSettingsView()
|
EthernetSettingsView::~EthernetSettingsView()
|
||||||
{
|
{
|
||||||
close(fSocket);
|
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
|
void
|
||||||
EthernetSettingsView::_ShowConfiguration(Settings* settings)
|
EthernetSettingsView::_ShowConfiguration(Settings* settings)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Author:
|
* Author:
|
||||||
* Andre Alves Garzia, [email protected]
|
* Andre Alves Garzia, [email protected]
|
||||||
* With code from:
|
|
||||||
* Axel Dorfler
|
|
||||||
* Hugo Santos
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "NetworkWindow.h"
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <GroupLayout.h>
|
#include <GroupLayout.h>
|
||||||
|
|
||||||
#include "NetworkWindow.h"
|
|
||||||
#include "EthernetSettingsView.h"
|
#include "EthernetSettingsView.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -22,8 +20,13 @@ NetworkWindow::NetworkWindow()
|
|||||||
| B_AUTO_UPDATE_SIZE_LIMITS)
|
| B_AUTO_UPDATE_SIZE_LIMITS)
|
||||||
{
|
{
|
||||||
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
||||||
fEthView = new EthernetSettingsView();
|
fEthernetView = new EthernetSettingsView();
|
||||||
GetLayout()->AddView(fEthView);
|
GetLayout()->AddView(fEthernetView);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NetworkWindow::~NetworkWindow()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -37,10 +40,6 @@ NetworkWindow::MessageReceived(BMessage* message)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkWindow::~NetworkWindow()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
NetworkWindow::QuitRequested()
|
NetworkWindow::QuitRequested()
|
||||||
|
|||||||
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Author:
|
* Author:
|
||||||
* Andre Alves Garzia, [email protected]
|
* Andre Alves Garzia, [email protected]
|
||||||
* With code from:
|
|
||||||
* Axel Dorfler
|
|
||||||
* Hugo Santos
|
|
||||||
*/
|
*/
|
||||||
#ifndef NETWORK_WINDOW_H
|
#ifndef NETWORK_WINDOW_H
|
||||||
#define NETWORK_WINDOW_H
|
#define NETWORK_WINDOW_H
|
||||||
|
|
||||||
|
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
#include "EthernetSettingsView.h"
|
#include "EthernetSettingsView.h"
|
||||||
|
|
||||||
|
|
||||||
class NetworkWindow : public BWindow {
|
class NetworkWindow : public BWindow {
|
||||||
public:
|
public:
|
||||||
NetworkWindow();
|
NetworkWindow();
|
||||||
virtual ~NetworkWindow();
|
virtual ~NetworkWindow();
|
||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
virtual void MessageReceived(BMessage* mesage);
|
virtual void MessageReceived(BMessage* mesage);
|
||||||
|
|
||||||
private:
|
|
||||||
EthernetSettingsView *fEthView;
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
EthernetSettingsView* fEthernetView;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /* NETWORK_WINDOW_H */
|
||||||
#endif /* NETWORK_WINDOW_H */
|
|
||||||
|
|||||||
Reference in New Issue
Block a user