Debugger: Flesh out network config view.

NetworkConnectionConfigView:
- Port input field is now prepopulated with the default remote debug port
  number.
- Changes to either field now trigger listener notifications.
This commit is contained in:
Rene Gollent
2017-05-21 19:54:48 -04:00
parent f9065b53ad
commit 1dda890ae2
2 changed files with 57 additions and 13 deletions
@@ -1,31 +1,47 @@
/*
* Copyright 2016, Rene Gollent, [email protected].
* Copyright 2016-2017, Rene Gollent, [email protected].
* Distributed under the terms of the MIT License.
*/
#include "NetworkConnectionConfigView.h"
#include <stdio.h>
#include <stdlib.h>
#include <LayoutBuilder.h>
#include <MenuField.h>
#include <TextControl.h>
#include "Settings.h"
#include "SettingsDescription.h"
#include "TargetHostInterfaceInfo.h"
enum {
MSG_NET_CONFIG_INPUT_CHANGED = 'ncic'
};
static const char* kHostSetting = "hostname";
static const char* kPortSetting = "port";
NetworkConnectionConfigView::NetworkConnectionConfigView()
:
ConnectionConfigView("NetworkConnectionConfig"),
fProtocolField(NULL),
fHostInput(NULL),
fPortInput(NULL)
fPortInput(NULL),
fSettings(NULL),
fHostSetting(NULL),
fPortSetting(NULL)
{
}
NetworkConnectionConfigView::~NetworkConnectionConfigView()
{
if (fSettings != NULL)
fSettings->ReleaseReference();
}
@@ -45,10 +61,12 @@ NetworkConnectionConfigView::MessageReceived(BMessage* message)
switch (message->what) {
case MSG_NET_CONFIG_INPUT_CHANGED:
{
// TODO: implement
fSettings->SetValue(fHostSetting, fHostInput->Text());
uint16 port = (uint16)strtoul(fPortInput->Text(), NULL, 10);
fSettings->SetValue(fPortSetting, port);
NotifyConfigurationChanged(fSettings);
break;
}
default:
{
ConnectionConfigView::MessageReceived(message);
@@ -61,25 +79,47 @@ NetworkConnectionConfigView::MessageReceived(BMessage* message)
status_t
NetworkConnectionConfigView::InitSpecific()
{
SettingsDescription* description
= InterfaceInfo()->GetSettingsDescription();
for (int32 i = 0; i < description->CountSettings(); i++) {
Setting* setting = description->SettingAt(i);
if (strcmp(setting->ID(), kPortSetting) == 0)
fPortSetting = setting;
else if (strcmp(setting->ID(), kHostSetting) == 0)
fHostSetting = setting;
}
if (fPortSetting == NULL || fHostSetting == NULL)
return B_BAD_VALUE;
fSettings = new Settings(description);
fPortInput = new BTextControl("port_input", "Port:", "",
new BMessage(MSG_NET_CONFIG_INPUT_CHANGED));
BLayoutBuilder::Group<>(this, B_VERTICAL)
.AddGroup(B_HORIZONTAL)
.Add((fHostInput = new BTextControl("host_input", "Host:", "",
new BMessage(MSG_NET_CONFIG_INPUT_CHANGED))))
.Add(fPortInput->CreateLabelLayoutItem())
.Add(fPortInput->CreateTextViewLayoutItem())
.End()
BLayoutItem* textLayoutItem;
BLayoutBuilder::Group<>(this, B_HORIZONTAL)
.Add((fHostInput = new BTextControl("host_input", "Host:", "",
new BMessage(MSG_NET_CONFIG_INPUT_CHANGED))))
.Add(fPortInput->CreateLabelLayoutItem())
.Add((textLayoutItem = fPortInput->CreateTextViewLayoutItem()))
.End();
// since port numbers are limited to 5 digits, there's no need for
// the port input to expand farther than that. Instead, let the
// host field take the extra space.
fPortInput->CreateTextViewLayoutItem()->SetExplicitMaxSize(BSize(
textLayoutItem->SetExplicitMaxSize(BSize(
be_plain_font->StringWidth("999999"), B_SIZE_UNSET));
// TODO: init settings and protocol input
BString buffer;
buffer.SetToFormat("%" B_PRIu16, fPortSetting->DefaultValue().ToUInt16());
fPortInput->SetText(buffer);
fHostInput->SetModificationMessage(
new BMessage(MSG_NET_CONFIG_INPUT_CHANGED));
fPortInput->SetModificationMessage(
new BMessage(MSG_NET_CONFIG_INPUT_CHANGED));
return B_OK;
}
@@ -10,6 +10,7 @@
class BMenuField;
class BTextControl;
class Setting;
class NetworkConnectionConfigView : public ConnectionConfigView{
@@ -27,6 +28,9 @@ private:
BMenuField* fProtocolField;
BTextControl* fHostInput;
BTextControl* fPortInput;
Settings* fSettings;
Setting* fHostSetting;
Setting* fPortSetting;
};