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