From 1dda890ae2cb6bc94580959b1864898e636a11e1 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Sat, 20 May 2017 18:09:47 -0400 Subject: [PATCH] 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. --- .../NetworkConnectionConfigView.cpp | 66 +++++++++++++++---- .../NetworkConnectionConfigView.h | 4 ++ 2 files changed, 57 insertions(+), 13 deletions(-) diff --git a/src/apps/debugger/user_interface/gui/connection_config/config_handlers/NetworkConnectionConfigView.cpp b/src/apps/debugger/user_interface/gui/connection_config/config_handlers/NetworkConnectionConfigView.cpp index 2ad736499a..b58859ab3b 100644 --- a/src/apps/debugger/user_interface/gui/connection_config/config_handlers/NetworkConnectionConfigView.cpp +++ b/src/apps/debugger/user_interface/gui/connection_config/config_handlers/NetworkConnectionConfigView.cpp @@ -1,31 +1,47 @@ /* - * Copyright 2016, Rene Gollent, rene@gollent.com. + * Copyright 2016-2017, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ #include "NetworkConnectionConfigView.h" +#include +#include + #include #include #include +#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; } diff --git a/src/apps/debugger/user_interface/gui/connection_config/config_handlers/NetworkConnectionConfigView.h b/src/apps/debugger/user_interface/gui/connection_config/config_handlers/NetworkConnectionConfigView.h index fd0e11b5b1..5e0502cf77 100644 --- a/src/apps/debugger/user_interface/gui/connection_config/config_handlers/NetworkConnectionConfigView.h +++ b/src/apps/debugger/user_interface/gui/connection_config/config_handlers/NetworkConnectionConfigView.h @@ -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; };