Network/DNS settings: apply button, improved layout.
* The buttons now all end up with the same width. * Put the grid into a BBox. * The new "apply" button will actually apply the changes.
This commit is contained in:
@@ -16,50 +16,72 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include <Box.h>
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
|
#include <Catalog.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <FindDirectory.h>
|
#include <FindDirectory.h>
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
#include <ListView.h>
|
#include <ListView.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
|
#include <StringView.h>
|
||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
|
|
||||||
|
|
||||||
static const int32 kAddServer = 'adds';
|
static const int32 kMsgAddServer = 'adds';
|
||||||
static const int32 kDeleteServer = 'dels';
|
static const int32 kMsgDeleteServer = 'dels';
|
||||||
static const int32 kMoveUp = 'mvup';
|
static const int32 kMsgMoveUp = 'mvup';
|
||||||
static const int32 kMoveDown = 'mvdn';
|
static const int32 kMsgMoveDown = 'mvdn';
|
||||||
static const int32 kEditServer = 'edit';
|
static const int32 kMsgEditServer = 'edit';
|
||||||
|
static const int32 kMsgApply = 'aply';
|
||||||
|
|
||||||
|
|
||||||
|
#undef B_TRANSLATION_CONTEXT
|
||||||
|
#define B_TRANSLATION_CONTEXT "DNSSettingsView"
|
||||||
|
|
||||||
|
|
||||||
DNSSettingsView::DNSSettingsView()
|
DNSSettingsView::DNSSettingsView()
|
||||||
:
|
:
|
||||||
BGroupView(B_VERTICAL)
|
BView("dns", 0)
|
||||||
{
|
{
|
||||||
fServerListView = new BListView("nameservers");
|
fServerListView = new BListView("nameservers");
|
||||||
fTextControl = new BTextControl("", "", NULL);
|
fTextControl = new BTextControl("", "", NULL);
|
||||||
fTextControl->SetModificationMessage(new BMessage(kEditServer));
|
fTextControl->SetModificationMessage(new BMessage(kMsgEditServer));
|
||||||
fTextControl->SetExplicitMinSize(BSize(fTextControl->StringWidth("5") * 18,
|
fTextControl->SetExplicitMinSize(BSize(fTextControl->StringWidth("5") * 18,
|
||||||
B_SIZE_UNSET));
|
B_SIZE_UNSET));
|
||||||
|
|
||||||
fAddButton = new BButton("Add", new BMessage(kAddServer));
|
fAddButton = new BButton(B_TRANSLATE("Add"), new BMessage(kMsgAddServer));
|
||||||
fUpButton = new BButton("Move up", new BMessage(kMoveUp));
|
fAddButton->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
|
||||||
fDownButton = new BButton("Move down", new BMessage(kMoveDown));
|
fUpButton = new BButton(B_TRANSLATE("Move up"), new BMessage(kMsgMoveUp));
|
||||||
fRemoveButton = new BButton("Remove", new BMessage(kDeleteServer));
|
fUpButton->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
|
||||||
|
fDownButton = new BButton(B_TRANSLATE("Move down"),
|
||||||
|
new BMessage(kMsgMoveDown));
|
||||||
|
fDownButton->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
|
||||||
|
fRemoveButton = new BButton(B_TRANSLATE("Remove"), new BMessage(kMsgDeleteServer));
|
||||||
|
fRemoveButton->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
|
||||||
|
|
||||||
BLayoutBuilder::Group<>(this)
|
fApplyButton = new BButton(B_TRANSLATE("Apply"), new BMessage(kMsgApply));
|
||||||
.AddGrid()
|
|
||||||
.Add(fTextControl, 0, 0)
|
BBox* box = new BBox("dns");
|
||||||
.Add(fAddButton, 1, 0)
|
box->SetLabel(B_TRANSLATE("DNS servers"));
|
||||||
.Add(new BScrollView("scroll", fServerListView, 0, false, true),
|
box->AddChild(BLayoutBuilder::Grid<>()
|
||||||
0, 1, 1, 4)
|
.SetInsets(B_USE_DEFAULT_SPACING)
|
||||||
.Add(fUpButton, 1, 1)
|
.Add(fTextControl, 0, 0)
|
||||||
.Add(fDownButton, 1, 2)
|
.Add(fAddButton, 1, 0)
|
||||||
.Add(fRemoveButton, 1, 3)
|
.Add(new BScrollView("scroll", fServerListView, 0, false, true),
|
||||||
.End()
|
0, 1, 1, 3)
|
||||||
.Add(fDomain = new BTextControl("Domain", "", NULL))
|
.Add(fUpButton, 1, 1)
|
||||||
.End();
|
.Add(fDownButton, 1, 2)
|
||||||
|
.Add(fRemoveButton, 1, 3)
|
||||||
|
.View());
|
||||||
|
|
||||||
|
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
||||||
|
.Add(box)
|
||||||
|
.Add(fDomain = new BTextControl(B_TRANSLATE("Domain"), "", NULL))
|
||||||
|
.AddGroup(B_HORIZONTAL)
|
||||||
|
.AddGlue()
|
||||||
|
.Add(fApplyButton);
|
||||||
|
|
||||||
_LoadDNSConfiguration();
|
_LoadDNSConfiguration();
|
||||||
}
|
}
|
||||||
@@ -70,68 +92,6 @@ DNSSettingsView::~DNSSettingsView()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
DNSSettingsView::AttachedToWindow()
|
|
||||||
{
|
|
||||||
fAddButton->SetTarget(this);
|
|
||||||
fRemoveButton->SetTarget(this);
|
|
||||||
fUpButton->SetTarget(this);
|
|
||||||
fDownButton->SetTarget(this);
|
|
||||||
|
|
||||||
fTextControl->SetTarget(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
DNSSettingsView::MessageReceived(BMessage* message)
|
|
||||||
{
|
|
||||||
switch (message->what) {
|
|
||||||
case kAddServer:
|
|
||||||
{
|
|
||||||
const char* address = fTextControl->Text();
|
|
||||||
fServerListView->AddItem(new BStringItem(address));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case kDeleteServer:
|
|
||||||
delete fServerListView->RemoveItem(
|
|
||||||
fServerListView->CurrentSelection());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case kMoveUp:
|
|
||||||
{
|
|
||||||
int index = fServerListView->CurrentSelection();
|
|
||||||
if (index > 0)
|
|
||||||
fServerListView->SwapItems(index, index - 1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case kMoveDown:
|
|
||||||
{
|
|
||||||
int index = fServerListView->CurrentSelection();
|
|
||||||
if (index < fServerListView->CountItems() - 1)
|
|
||||||
fServerListView->SwapItems(index, index + 1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case kEditServer:
|
|
||||||
{
|
|
||||||
struct in_addr dummy;
|
|
||||||
bool success = inet_aton(fTextControl->Text(), &dummy);
|
|
||||||
fTextControl->MarkAsInvalid(!success);
|
|
||||||
fAddButton->SetEnabled(success);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
BGroupView::MessageReceived(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
DNSSettingsView::Apply()
|
|
||||||
{
|
|
||||||
return _SaveDNSConfiguration();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
DNSSettingsView::Revert()
|
DNSSettingsView::Revert()
|
||||||
{
|
{
|
||||||
@@ -155,6 +115,68 @@ DNSSettingsView::Revert()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DNSSettingsView::AttachedToWindow()
|
||||||
|
{
|
||||||
|
fAddButton->SetTarget(this);
|
||||||
|
fRemoveButton->SetTarget(this);
|
||||||
|
fUpButton->SetTarget(this);
|
||||||
|
fDownButton->SetTarget(this);
|
||||||
|
|
||||||
|
fTextControl->SetTarget(this);
|
||||||
|
|
||||||
|
fApplyButton->SetTarget(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DNSSettingsView::MessageReceived(BMessage* message)
|
||||||
|
{
|
||||||
|
switch (message->what) {
|
||||||
|
case kMsgAddServer:
|
||||||
|
{
|
||||||
|
const char* address = fTextControl->Text();
|
||||||
|
fServerListView->AddItem(new BStringItem(address));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case kMsgDeleteServer:
|
||||||
|
delete fServerListView->RemoveItem(
|
||||||
|
fServerListView->CurrentSelection());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case kMsgMoveUp:
|
||||||
|
{
|
||||||
|
int index = fServerListView->CurrentSelection();
|
||||||
|
if (index > 0)
|
||||||
|
fServerListView->SwapItems(index, index - 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case kMsgMoveDown:
|
||||||
|
{
|
||||||
|
int index = fServerListView->CurrentSelection();
|
||||||
|
if (index < fServerListView->CountItems() - 1)
|
||||||
|
fServerListView->SwapItems(index, index + 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case kMsgEditServer:
|
||||||
|
{
|
||||||
|
struct in_addr dummy;
|
||||||
|
bool success = inet_aton(fTextControl->Text(), &dummy);
|
||||||
|
fTextControl->MarkAsInvalid(!success);
|
||||||
|
fAddButton->SetEnabled(success);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case kMsgApply:
|
||||||
|
_SaveDNSConfiguration();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
BView::MessageReceived(message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
DNSSettingsView::_LoadDNSConfiguration()
|
DNSSettingsView::_LoadDNSConfiguration()
|
||||||
{
|
{
|
||||||
@@ -194,7 +216,7 @@ DNSSettingsView::_SaveDNSConfiguration()
|
|||||||
return file.InitCheck();
|
return file.InitCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
BString content("# Generated by Network Preflet\n");
|
BString content("# Generated by Network preferences\n");
|
||||||
|
|
||||||
for (int i = 0; i < fServerListView->CountItems(); i++) {
|
for (int i = 0; i < fServerListView->CountItems(); i++) {
|
||||||
BString item = ((BStringItem*)fServerListView->ItemAt(i))->Text();
|
BString item = ((BStringItem*)fServerListView->ItemAt(i))->Text();
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
#define DNS_SETTINGS_VIEW_H
|
#define DNS_SETTINGS_VIEW_H
|
||||||
|
|
||||||
|
|
||||||
#include <GroupView.h>
|
|
||||||
#include <StringList.h>
|
#include <StringList.h>
|
||||||
|
#include <View.h>
|
||||||
|
|
||||||
|
|
||||||
class BButton;
|
class BButton;
|
||||||
@@ -18,12 +18,11 @@ class BListView;
|
|||||||
class BTextControl;
|
class BTextControl;
|
||||||
|
|
||||||
|
|
||||||
class DNSSettingsView : public BGroupView {
|
class DNSSettingsView : public BView {
|
||||||
public:
|
public:
|
||||||
DNSSettingsView();
|
DNSSettingsView();
|
||||||
~DNSSettingsView();
|
~DNSSettingsView();
|
||||||
|
|
||||||
status_t Apply();
|
|
||||||
status_t Revert();
|
status_t Revert();
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
@@ -43,6 +42,7 @@ private:
|
|||||||
BButton* fRemoveButton;
|
BButton* fRemoveButton;
|
||||||
BButton* fUpButton;
|
BButton* fUpButton;
|
||||||
BButton* fDownButton;
|
BButton* fDownButton;
|
||||||
|
BButton* fApplyButton;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user