Add option to set link network port.
Add field for the network port to the start link dialog, default is 5738 as before. The port is stored in the user's options config. Add TextCtrl support to UIntValidator for this. Related: #594. Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
parent
98f3948ea8
commit
136c094f0c
|
@ -98,7 +98,10 @@ bool gba_link_enabled = false;
|
|||
bool speedhack = true;
|
||||
|
||||
#define LOCAL_LINK_NAME "VBA link memory"
|
||||
#define IP_LINK_PORT 5738
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t IP_LINK_PORT = 5738;
|
||||
|
||||
#include "../common/Port.h"
|
||||
#include "GBA.h"
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
#ifndef GBA_GBALINK_H
|
||||
#define GBA_GBALINK_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern uint32_t IP_LINK_PORT;
|
||||
|
||||
/**
|
||||
* Link modes to be passed to InitLink
|
||||
*/
|
||||
|
|
|
@ -89,6 +89,8 @@ public:
|
|||
if (!dlg->Validate() || !dlg->TransferDataFromWindow())
|
||||
return;
|
||||
|
||||
IP_LINK_PORT = gopts.link_port;
|
||||
|
||||
if (!server) {
|
||||
bool valid = SetLinkServerHost(gopts.link_host.utf8_str());
|
||||
|
||||
|
@ -3181,6 +3183,11 @@ bool MainFrame::BindControls()
|
|||
tc = SafeXRCCTRL<wxTextCtrl>(d, n); \
|
||||
tc->SetValidator(wxPositiveDoubleValidator(&o)); \
|
||||
} while (0)
|
||||
#define getutc(n, o) \
|
||||
do { \
|
||||
tc = SafeXRCCTRL<wxTextCtrl>(d, n); \
|
||||
tc->SetValidator(wxUIntValidator(&o)); \
|
||||
} while (0)
|
||||
#ifndef NO_LINK
|
||||
{
|
||||
net_link_handler.dlg = d;
|
||||
|
@ -3199,6 +3206,7 @@ bool MainFrame::BindControls()
|
|||
addrber(lab, true);
|
||||
gettc("ServerIP", gopts.link_host);
|
||||
addrber(tc, true);
|
||||
getutc("ServerPort", gopts.link_port);
|
||||
wxWindow* okb = d->FindWindow(wxID_OK);
|
||||
|
||||
if (okb) // may be gone if style guidlines removed it
|
||||
|
|
|
@ -223,6 +223,7 @@ opt_desc opts[] = {
|
|||
BOOLOPT("GBA/LinkAuto", "LinkAuto", wxTRANSLATE("Enable link at boot"), gopts.link_auto),
|
||||
INTOPT("GBA/LinkFast", "SpeedOn", wxTRANSLATE("Enable faster network protocol by default"), linkHacks, 0, 1),
|
||||
STROPT("GBA/LinkHost", "", wxTRANSLATE("Default network link client host"), gopts.link_host),
|
||||
UINTOPT("GBA/LinkPort", "", wxTRANSLATE("Default network link port (server and client)"), gopts.link_port, 0, 65535),
|
||||
INTOPT("GBA/LinkProto", "LinkProto", wxTRANSLATE("Default network protocol"), gopts.link_proto, 0, 1),
|
||||
INTOPT("GBA/LinkTimeout", "LinkTimeout", wxTRANSLATE("Link timeout (ms)"), linkTimeout, 0, 9999999),
|
||||
INTOPT("GBA/LinkType", "LinkType", wxTRANSLATE("Link cable type"), gopts.gba_link_type, 0, 5),
|
||||
|
@ -359,6 +360,7 @@ opts_t::opts_t()
|
|||
autoPatch = true;
|
||||
// quick fix for issues #48 and #445
|
||||
link_host = "127.0.0.1";
|
||||
link_port = 5738;
|
||||
}
|
||||
|
||||
// for binary_search() and friends
|
||||
|
|
|
@ -38,6 +38,7 @@ extern struct opts_t {
|
|||
wxString gba_bios;
|
||||
int gba_link_type;
|
||||
wxString link_host;
|
||||
uint32_t link_port;
|
||||
int link_proto;
|
||||
bool link_auto;
|
||||
wxString gba_rom_dir;
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
// utility widgets
|
||||
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
#include "wx/wxmisc.h"
|
||||
#include <wx/wx.h>
|
||||
#include <wx/spinctrl.h>
|
||||
|
@ -443,36 +448,62 @@ wxUIntValidator::wxUIntValidator(uint32_t* _val)
|
|||
|
||||
bool wxUIntValidator::TransferToWindow()
|
||||
{
|
||||
wxSpinCtrl* ctrl = wxDynamicCast(GetWindow(), wxSpinCtrl);
|
||||
if (ctrl && uint_val) {
|
||||
ctrl->SetValue(*uint_val);
|
||||
return true;
|
||||
if (uint_val) {
|
||||
wxSpinCtrl* spin = wxDynamicCast(GetWindow(), wxSpinCtrl);
|
||||
if (spin) {
|
||||
spin->SetValue(*uint_val);
|
||||
return true;
|
||||
}
|
||||
|
||||
wxTextCtrl* txt = wxDynamicCast(GetWindow(), wxTextCtrl);
|
||||
if (txt) {
|
||||
txt->SetValue(wxString::Format(wxT("%d"), *uint_val));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wxUIntValidator::TransferFromWindow()
|
||||
{
|
||||
wxSpinCtrl* ctrl = wxDynamicCast(GetWindow(), wxSpinCtrl);
|
||||
if (ctrl && uint_val) {
|
||||
*uint_val = ctrl->GetValue();
|
||||
return true;
|
||||
if (uint_val) {
|
||||
wxSpinCtrl* spin = wxDynamicCast(GetWindow(), wxSpinCtrl);
|
||||
if (spin) {
|
||||
*uint_val = spin->GetValue();
|
||||
return true;
|
||||
}
|
||||
|
||||
wxTextCtrl* txt = wxDynamicCast(GetWindow(), wxTextCtrl);
|
||||
if (txt) {
|
||||
*uint_val = wxAtoi(txt->GetValue());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wxUIntValidator::Validate(wxWindow* parent)
|
||||
{
|
||||
(void)parent; // unused params
|
||||
wxSpinCtrl* ctrl = wxDynamicCast(GetWindow(), wxSpinCtrl);
|
||||
|
||||
if (ctrl) {
|
||||
if (ctrl->GetValue() >= 0) {
|
||||
wxSpinCtrl* spin = wxDynamicCast(GetWindow(), wxSpinCtrl);
|
||||
if (spin) {
|
||||
if (spin->GetValue() >= 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
wxTextCtrl* txt = wxDynamicCast(GetWindow(), wxTextCtrl);
|
||||
if (txt) {
|
||||
std::string val = std::string(txt->GetValue().mb_str());
|
||||
|
||||
return !val.empty()
|
||||
&& std::find_if(val.begin(), val.end(), [](unsigned char c) { return !std::isdigit(c); }) == val.end();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -76,6 +76,19 @@
|
|||
<flag>wxALL|wxEXPAND</flag>
|
||||
<border>5</border>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxStaticText" name="ServerPortLab">
|
||||
<label>Port:</label>
|
||||
</object>
|
||||
<flag>wxALL|wxALIGN_CENTRE_VERTICAL</flag>
|
||||
<border>5</border>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxTextCtrl" name="ServerPort"/>
|
||||
<option>1</option>
|
||||
<flag>wxALL|wxEXPAND</flag>
|
||||
<border>5</border>
|
||||
</object>
|
||||
</object>
|
||||
<flag>wxEXPAND</flag>
|
||||
</object>
|
||||
|
|
Loading…
Reference in New Issue