26#include "config_vars.h"
27#include "mDNS_query.h"
28#include "OCPNPlatform.h"
29#include "peer_client.h"
32#include "route_point_gui.h"
33#include "route_point.h"
34#include "SendToPeerDlg.h"
36#define TIMER_AUTOSCAN 94522
37#define TIMER_SCANTICK 94523
40extern std::vector<std::shared_ptr<ocpn_DNS_record_t>> g_DNS_cache;
41extern wxDateTime g_DNS_cache_time;
42extern bool g_bportable;
47 EVT_BUTTON(ID_STP_CANCEL, SendToPeerDlg::OnCancelClick)
48 EVT_BUTTON(ID_STP_OK, SendToPeerDlg::OnSendClick)
49 EVT_BUTTON(ID_STP_SCAN, SendToPeerDlg::OnScanClick)
50 EVT_TIMER(TIMER_AUTOSCAN, SendToPeerDlg::OnTimerAutoscan)
51 EVT_TIMER(TIMER_SCANTICK, SendToPeerDlg::OnTimerScanTick)
58 m_CancelButton = NULL;
61 m_bScanOnCreate =
false;
64SendToPeerDlg::SendToPeerDlg(wxWindow* parent, wxWindowID
id,
65 const wxString& caption,
const wxString& hint,
66 const wxPoint& pos,
const wxSize& size,
long style) {
67 Create(parent,
id, caption, hint, pos, size, style);
70SendToPeerDlg::~SendToPeerDlg() {
74 delete m_CancelButton;
77bool SendToPeerDlg::Create(wxWindow* parent, wxWindowID
id,
78 const wxString& caption,
const wxString& hint,
79 const wxPoint& pos,
const wxSize& size,
long style) {
80 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
81 wxDialog::Create(parent,
id, caption, pos, size, style);
84 GetSizer()->Fit(
this);
85 GetSizer()->SetSizeHints(
this);
90 m_autoScanTimer.SetOwner(
this, TIMER_AUTOSCAN);
91 m_autoScanTimer.Start(500, wxTIMER_ONE_SHOT);
94 m_ScanTickTimer.SetOwner(
this, TIMER_SCANTICK);
99void SendToPeerDlg::CreateControls(
const wxString& hint) {
102 wxBoxSizer* itemBoxSizer2 =
new wxBoxSizer(wxVERTICAL);
103 itemDialog1->SetSizer(itemBoxSizer2);
107 wxStaticBox* comm_box =
108 new wxStaticBox(
this, wxID_ANY, _(
"Detected OpenCPN peer instances"));
110 wxStaticBoxSizer* comm_box_sizer =
new wxStaticBoxSizer(comm_box, wxVERTICAL);
111 itemBoxSizer2->Add(comm_box_sizer, 0, wxEXPAND | wxALL, 5);
113 m_PeerListBox =
new wxComboBox(
this, ID_STP_CHOICE_PEER);
116 for (
unsigned int i=0; i < g_DNS_cache.size(); i++){
117 wxString item(g_DNS_cache[i]->hostname.c_str());
120 if (!g_hostname.IsSameAs(item.BeforeFirst(
'.'))) {
122 item += g_DNS_cache[i]->ip.c_str();
124 m_PeerListBox->Append(item);
128 if (m_PeerListBox->GetCount())
129 m_PeerListBox->SetSelection(0);
131 comm_box_sizer->Add(m_PeerListBox, 0, wxEXPAND | wxALL, 5);
133 m_RescanButton =
new wxButton(itemDialog1, ID_STP_SCAN, _(
"Scan again"),
134 wxDefaultPosition, wxDefaultSize, 0);
135 itemBoxSizer2->Add(m_RescanButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
137 m_pgauge =
new wxGauge(
this, -1, m_scanTime);
138 itemBoxSizer2->Add(m_pgauge, 0, wxEXPAND | wxALL, 5);
141 itemBoxSizer2->AddSpacer(30);
144 premtext =
new wxStaticText(
145 this, -1, _(
"Prepare GPS for Route/Waypoint upload and press Send..."));
146 itemBoxSizer2->Add(premtext, 0, wxEXPAND | wxALL, 10);
149 wxStaticBox* prog_box =
new wxStaticBox(
this, wxID_ANY, _(
"Progress..."));
151 wxStaticBoxSizer* prog_box_sizer =
new wxStaticBoxSizer(prog_box, wxVERTICAL);
152 itemBoxSizer2->Add(prog_box_sizer, 0, wxEXPAND | wxALL, 5);
154 m_pgauge =
new wxGauge(
this, -1, 100);
155 prog_box_sizer->Add(m_pgauge, 0, wxEXPAND | wxALL, 5);
159 wxBoxSizer* itemBoxSizer16 =
new wxBoxSizer(wxHORIZONTAL);
160 itemBoxSizer2->Add(itemBoxSizer16, 0, wxALIGN_RIGHT | wxALL, 5);
162 m_CancelButton =
new wxButton(itemDialog1, ID_STP_CANCEL, _(
"Cancel"),
163 wxDefaultPosition, wxDefaultSize, 0);
164 itemBoxSizer16->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
166 m_SendButton =
new wxButton(itemDialog1, ID_STP_OK, _(
"Send"),
167 wxDefaultPosition, wxDefaultSize, 0);
168 itemBoxSizer16->Add(m_SendButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
169 m_SendButton->SetDefault();
172void SendToPeerDlg::SetMessage(wxString msg) {
174 premtext->SetLabel(msg);
175 premtext->Refresh(
true);
179void SendToPeerDlg::OnSendClick(wxCommandEvent& event) {
180 if (m_RouteList.empty() && m_TrackList.empty() && m_RoutePointList.empty())
184 wxString peer_ip = m_PeerListBox->GetValue();
185 wxString server_name = peer_ip.BeforeFirst(
'{').Trim();
186 int tail = peer_ip.Find(
'{');
187 if (tail != wxNOT_FOUND)
188 peer_ip = peer_ip.Mid(tail+1);
189 peer_ip = peer_ip.BeforeFirst(
'}');
193 wxString p =
"Portable";
194 if (p.IsSameAs(server_name.BeforeFirst(
'-')))
199 std::string server_address(
"https://");
200 server_address += peer_ip.ToStdString();
207 if (!m_RouteList.empty() || !m_RoutePointList.empty() || !m_TrackList.empty())
209 int return_code = SendRoute(server_address, server_name.ToStdString(), m_RouteList, m_RoutePointList, m_TrackList,
true);
217void SendToPeerDlg::OnScanClick(wxCommandEvent& event) {
221void SendToPeerDlg::OnTimerAutoscan(wxTimerEvent &event) {
225void SendToPeerDlg::OnTimerScanTick(wxTimerEvent &event) {
228 int v = m_pgauge->GetValue();
229 m_pgauge->SetValue(v+1);
234 m_ScanTickTimer.Stop();
235 g_Platform->HideBusySpinner();
236 m_RescanButton->Enable();
238 m_bScanOnCreate =
false;
241 m_PeerListBox->Clear();
244 for (
unsigned int i=0; i < g_DNS_cache.size(); i++){
245 wxString item(g_DNS_cache[i]->hostname.c_str());
248 if (!g_hostname.IsSameAs(item.BeforeFirst(
'.'))) {
250 item += g_DNS_cache[i]->ip.c_str();
252 m_PeerListBox->Append(item);
255 if (m_PeerListBox->GetCount())
256 m_PeerListBox->SetSelection(0);
258 g_DNS_cache_time = wxDateTime::Now();
262void SendToPeerDlg::DoScan() {
263 m_RescanButton->Disable();
264 g_Platform->ShowBusySpinner();
265 m_pgauge->SetRange(m_scanTime);
266 m_pgauge->SetValue(0);
269 FindAllOCPNServers(m_scanTime);
272 m_ScanTickTimer.Start(1000, wxTIMER_CONTINUOUS);
275void SendToPeerDlg::OnCancelClick(wxCommandEvent& event) {
Route "Send to Peer..." Dialog Definition.