Network: DNSSettingsView style cleanup.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 Haiku Inc. All rights reserved.
|
||||
* Copyright 2014-2015 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -9,6 +9,13 @@
|
||||
|
||||
#include "DNSSettingsView.h"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <resolv.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <Button.h>
|
||||
#include <File.h>
|
||||
#include <FindDirectory.h>
|
||||
@@ -18,13 +25,6 @@
|
||||
#include <ScrollView.h>
|
||||
#include <TextControl.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <resolv.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
|
||||
static const int32 kAddServer = 'adds';
|
||||
static const int32 kDeleteServer = 'dels';
|
||||
@@ -34,7 +34,8 @@ static const int32 kEditServer = 'edit';
|
||||
|
||||
|
||||
DNSSettingsView::DNSSettingsView()
|
||||
: BGroupView(B_VERTICAL)
|
||||
:
|
||||
BGroupView(B_VERTICAL)
|
||||
{
|
||||
fServerListView = new BListView("nameservers");
|
||||
fTextControl = new BTextControl("", "", NULL);
|
||||
@@ -64,6 +65,11 @@ DNSSettingsView::DNSSettingsView()
|
||||
}
|
||||
|
||||
|
||||
DNSSettingsView::~DNSSettingsView()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DNSSettingsView::AttachedToWindow()
|
||||
{
|
||||
@@ -79,7 +85,7 @@ DNSSettingsView::AttachedToWindow()
|
||||
void
|
||||
DNSSettingsView::MessageReceived(BMessage* message)
|
||||
{
|
||||
switch(message->what) {
|
||||
switch (message->what) {
|
||||
case kAddServer:
|
||||
{
|
||||
const char* address = fTextControl->Text();
|
||||
@@ -87,15 +93,13 @@ DNSSettingsView::MessageReceived(BMessage* message)
|
||||
break;
|
||||
}
|
||||
case kDeleteServer:
|
||||
{
|
||||
delete fServerListView->RemoveItem(
|
||||
fServerListView->CurrentSelection());
|
||||
break;
|
||||
}
|
||||
|
||||
case kMoveUp:
|
||||
{
|
||||
int index = fServerListView->CurrentSelection();
|
||||
|
||||
if (index > 0)
|
||||
fServerListView->SwapItems(index, index - 1);
|
||||
break;
|
||||
@@ -103,7 +107,6 @@ DNSSettingsView::MessageReceived(BMessage* message)
|
||||
case kMoveDown:
|
||||
{
|
||||
int index = fServerListView->CurrentSelection();
|
||||
|
||||
if (index < fServerListView->CountItems() - 1)
|
||||
fServerListView->SwapItems(index, index + 1);
|
||||
break;
|
||||
@@ -133,8 +136,9 @@ status_t
|
||||
DNSSettingsView::Revert()
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < fRevertList.CountStrings(); i++) {
|
||||
BStringItem* item = static_cast<BStringItem*>(fServerListView->ItemAt(i));
|
||||
for (i = 0; i < fRevertList.CountStrings(); i++) {
|
||||
BStringItem* item = static_cast<BStringItem*>(
|
||||
fServerListView->ItemAt(i));
|
||||
if (item == NULL) {
|
||||
item = new BStringItem("");
|
||||
fServerListView->AddItem(item);
|
||||
@@ -144,7 +148,7 @@ DNSSettingsView::Revert()
|
||||
}
|
||||
|
||||
// Now remove any extra item
|
||||
for(; i < fServerListView->CountItems(); i++)
|
||||
for (; i < fServerListView->CountItems(); i++)
|
||||
delete fServerListView->RemoveItem(i);
|
||||
|
||||
return B_OK;
|
||||
@@ -192,11 +196,10 @@ DNSSettingsView::_SaveDNSConfiguration()
|
||||
|
||||
BString content("# Generated by Network Preflet\n");
|
||||
|
||||
for (int j = 0; j < fServerListView->CountItems(); j++) {
|
||||
BString item = ((BStringItem*)fServerListView->ItemAt(j))->Text();
|
||||
if (item.Length() > 0) {
|
||||
for (int i = 0; i < fServerListView->CountItems(); i++) {
|
||||
BString item = ((BStringItem*)fServerListView->ItemAt(i))->Text();
|
||||
if (item.Length() > 0)
|
||||
content << "nameserver\t" << item.String() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen(fDomain->Text()) > 0)
|
||||
@@ -204,5 +207,3 @@ DNSSettingsView::_SaveDNSConfiguration()
|
||||
|
||||
return file.Write(content.String(), content.Length());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
/*
|
||||
* Copyright 2014 Haiku Inc. All rights reserved.
|
||||
* Copyright 2014-2015 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Adrien Destugues, [email protected]
|
||||
*/
|
||||
#ifndef DNS_SETTINGS_VIEW_H
|
||||
#define DNS_SETTINGS_VIEW_H
|
||||
|
||||
|
||||
#include <GroupView.h>
|
||||
@@ -16,28 +18,32 @@ class BListView;
|
||||
class BTextControl;
|
||||
|
||||
|
||||
class DNSSettingsView: public BGroupView
|
||||
{
|
||||
class DNSSettingsView : public BGroupView {
|
||||
public:
|
||||
DNSSettingsView();
|
||||
void AttachedToWindow();
|
||||
void MessageReceived(BMessage* message);
|
||||
DNSSettingsView();
|
||||
~DNSSettingsView();
|
||||
|
||||
status_t Apply();
|
||||
status_t Revert();
|
||||
status_t Apply();
|
||||
status_t Revert();
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
private:
|
||||
status_t _LoadDNSConfiguration();
|
||||
status_t _SaveDNSConfiguration();
|
||||
status_t _LoadDNSConfiguration();
|
||||
status_t _SaveDNSConfiguration();
|
||||
|
||||
private:
|
||||
BListView* fServerListView;
|
||||
BStringList fRevertList;
|
||||
BTextControl* fTextControl;
|
||||
BTextControl* fDomain;
|
||||
BListView* fServerListView;
|
||||
BStringList fRevertList;
|
||||
BTextControl* fTextControl;
|
||||
BTextControl* fDomain;
|
||||
|
||||
BButton* fAddButton;
|
||||
BButton* fRemoveButton;
|
||||
BButton* fUpButton;
|
||||
BButton* fDownButton;
|
||||
BButton* fAddButton;
|
||||
BButton* fRemoveButton;
|
||||
BButton* fUpButton;
|
||||
BButton* fDownButton;
|
||||
};
|
||||
|
||||
|
||||
#endif // DNS_SETTINGS_VIEW_H
|
||||
|
||||
Reference in New Issue
Block a user