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/json_defs.h>
32#include <wx/jsonreader.h>
33#include <wx/tokenzr.h>
34
35#include <curl/curl.h>
36
37#include "model/peer_client.h"
38#include "model/rest_server.h"
39#include "model/semantic_vers.h"
40#include "model/config_vars.h"
41
42#include "peer_client_dlg.h"
43#include "font_mgr.h"
44#include "gui_lib.h"
45
46struct MemoryStruct {
47 char* memory;
48 size_t size;
49};
50
51PinConfirmDlg::PinConfirmDlg() {
52 m_ok_btn = NULL;
53 m_cancel_btn = NULL;
54 premtext = NULL;
55}
56
57PinConfirmDlg::PinConfirmDlg(wxWindow* parent, wxWindowID id,
58 const wxString& caption, const wxString& hint,
59 const wxPoint& pos, const wxSize& size,
60 long style) {
61 wxFont* pif = FontMgr::Get().GetFont(_("Dialog"));
62 SetFont(*pif);
63 Create(parent, id, caption, hint, pos, size, style);
64}
65
66PinConfirmDlg::~PinConfirmDlg() {
67 delete m_ok_btn;
68 delete m_cancel_btn;
69}
70
72void PinConfirmDlg::OnTextChange(wxCommandEvent&) {
73 auto txt = m_pin_textctrl->GetValue().ToStdString();
74 int value = -1;
75 if (txt.size() >= 4) {
76 try {
77 value = std::stoi(txt);
78 } catch (std::exception&) {
79 ;
80 }
81 }
82 m_ok_btn->Enable(value >= 0 && txt.size() >= 4);
83}
84
85bool PinConfirmDlg::Create(wxWindow* parent, wxWindowID id,
86 const wxString& caption, const wxString& hint,
87 const wxPoint& pos, const wxSize& size, long style) {
88 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
89 wxDialog::Create(parent, id, caption, pos, size, style);
90
91 CreateControls(hint);
92 GetSizer()->Fit(this);
93 GetSizer()->SetSizeHints(this);
94 Centre();
95 return TRUE;
96}
97
98void PinConfirmDlg::CreateControls(const wxString&) {
99 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
100 SetSizer(itemBoxSizer2);
101
102 // Add a reminder text box
103 itemBoxSizer2->AddSpacer(20);
104
105 premtext = new wxStaticText(
106 this, -1, "A loooooooooooooooooooooooooooooooooooooooooooooong line\n");
107 itemBoxSizer2->Add(premtext, 0, wxEXPAND | wxALL, 10);
108
109 m_pin_textctrl = new wxTextCtrl(this, wxID_ANY, " ", wxDefaultPosition,
110 wxDefaultSize, wxTE_CENTRE);
111 itemBoxSizer2->Add(m_pin_textctrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 10);
112
113 // OK/Cancel/etc.
114 wxBoxSizer* itemBoxSizer16 = new wxBoxSizer(wxHORIZONTAL);
115 itemBoxSizer2->Add(itemBoxSizer16, 0, wxALIGN_RIGHT | wxALL, 5);
116
117 m_cancel_btn = new wxButton(this, wxID_CANCEL);
118
119 m_cancel_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED,
120 [&](wxCommandEvent e) { OnCancelClick(e); });
121 itemBoxSizer16->Add(m_cancel_btn, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
122
123 m_ok_btn = new wxButton(this, wxID_OK);
124 itemBoxSizer16->Add(m_ok_btn, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
125 m_ok_btn->SetDefault();
126 m_ok_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED,
127 [&](wxCommandEvent e) { OnOKClick(e); });
128 m_ok_btn->Enable(false);
129 m_pin_textctrl->Bind(wxEVT_TEXT,
130 [&](wxCommandEvent& ev) { OnTextChange(ev); });
131}
132
133void PinConfirmDlg::SetMessage(const wxString& msg) {
134 if (premtext) {
135 premtext->SetLabel(msg);
136 premtext->Refresh(true);
137 }
138}
139
140void PinConfirmDlg::SetPincodeText(const wxString& message) {
141 m_pin_textctrl->ChangeValue(message);
142 m_pin_textctrl->Show();
143 GetSizer()->Fit(this);
144}
145
146void PinConfirmDlg::OnOKClick(wxCommandEvent&) { EndModal(wxID_OK); }
147
148void 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.