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