OpenCPN Partial API docs
Loading...
Searching...
No Matches
peer_client_dlg.cpp
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2022 by David Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#include <cassert>
25#include <iostream>
26#include <sstream>
27
28#include "gl_headers.h" // Must come before anything using GL stuff
29
30#include <wx/fileconf.h>
31#include <wx/tokenzr.h>
32
33#include <curl/curl.h>
34
35#include "model/peer_client.h"
36#include "model/rest_server.h"
37#include "model/semantic_vers.h"
38#include "model/config_vars.h"
39
40#include "peer_client_dlg.h"
41#include "font_mgr.h"
42#include "gui_lib.h"
43
44struct MemoryStruct {
45 char* memory;
46 size_t size;
47};
48
49PinConfirmDlg::PinConfirmDlg() {
50 m_ok_btn = NULL;
51 m_cancel_btn = NULL;
52 premtext = NULL;
53}
54
55PinConfirmDlg::PinConfirmDlg(wxWindow* parent, wxWindowID id,
56 const wxString& caption, const wxString& hint,
57 const wxPoint& pos, const wxSize& size,
58 long style) {
59 wxFont* pif = FontMgr::Get().GetFont(_("Dialog"));
60 SetFont(*pif);
61 Create(parent, id, caption, hint, pos, size, style);
62}
63
64PinConfirmDlg::~PinConfirmDlg() {
65 delete m_ok_btn;
66 delete m_cancel_btn;
67}
68
70void PinConfirmDlg::OnTextChange(wxCommandEvent&) {
71 auto txt = m_pin_textctrl->GetValue().ToStdString();
72 int value = -1;
73 if (txt.size() >= 4) {
74 try {
75 value = std::stoi(txt);
76 } catch (std::exception&) {
77 ;
78 }
79 }
80 m_ok_btn->Enable(value >= 0 && txt.size() >= 4);
81}
82
83bool PinConfirmDlg::Create(wxWindow* parent, wxWindowID id,
84 const wxString& caption, const wxString& hint,
85 const wxPoint& pos, const wxSize& size, long style) {
86 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
87 wxDialog::Create(parent, id, caption, pos, size, style);
88
89 CreateControls(hint);
90 GetSizer()->Fit(this);
91 GetSizer()->SetSizeHints(this);
92 Centre();
93 return TRUE;
94}
95
96void PinConfirmDlg::CreateControls(const wxString&) {
97 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
98 SetSizer(itemBoxSizer2);
99
100 // Add a reminder text box
101 itemBoxSizer2->AddSpacer(20);
102
103 premtext = new wxStaticText(
104 this, -1, "A loooooooooooooooooooooooooooooooooooooooooooooong line\n");
105 itemBoxSizer2->Add(premtext, 0, wxEXPAND | wxALL, 10);
106
107 m_pin_textctrl = new wxTextCtrl(this, wxID_ANY, " ", wxDefaultPosition,
108 wxDefaultSize, wxTE_CENTRE);
109 itemBoxSizer2->Add(m_pin_textctrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 10);
110
111 // OK/Cancel/etc.
112 wxBoxSizer* itemBoxSizer16 = new wxBoxSizer(wxHORIZONTAL);
113 itemBoxSizer2->Add(itemBoxSizer16, 0, wxALIGN_RIGHT | wxALL, 5);
114
115 m_cancel_btn = new wxButton(this, wxID_CANCEL);
116
117 m_cancel_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED,
118 [&](wxCommandEvent e) { OnCancelClick(e); });
119 itemBoxSizer16->Add(m_cancel_btn, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
120
121 m_ok_btn = new wxButton(this, wxID_OK);
122 itemBoxSizer16->Add(m_ok_btn, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
123 m_ok_btn->SetDefault();
124 m_ok_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED,
125 [&](wxCommandEvent e) { OnOKClick(e); });
126 m_ok_btn->Enable(false);
127 m_pin_textctrl->Bind(wxEVT_TEXT,
128 [&](wxCommandEvent& ev) { OnTextChange(ev); });
129}
130
131void PinConfirmDlg::SetMessage(const wxString& msg) {
132 if (premtext) {
133 premtext->SetLabel(msg);
134 premtext->Refresh(true);
135 }
136}
137
138void PinConfirmDlg::SetPincodeText(const wxString& message) {
139 m_pin_textctrl->ChangeValue(message);
140 m_pin_textctrl->Show();
141 GetSizer()->Fit(this);
142}
143
144void PinConfirmDlg::OnOKClick(wxCommandEvent&) { EndModal(wxID_OK); }
145
146void PinConfirmDlg::OnCancelClick(wxCommandEvent&) { EndModal(wxID_CANCEL); }
wxFont * GetFont(const wxString &TextElement, int requested_font_size=0)
Get a font object for a UI element.
Definition font_mgr.cpp:193
Global variables stored in configuration file.
Font list manager.
Platform independent GL includes.
General purpose GUI support.
Peer client non-gui abstraction.
Confirm peer transfer PIN code dialog.
REST API server.
Semantic version encode/decode object.