OpenCPN Partial API docs
Loading...
Searching...
No Matches
chartdldr_pi.h
1/******************************************************************************
2 * $Id: chartdldr_pi.h,v 1.0 2011/02/26 01:54:37 nohal Exp $
3 *
4 * Project: OpenCPN
5 * Purpose: Chart Downloader Plugin
6 * Author: Pavel Kalian
7 *
8 ***************************************************************************
9 * Copyright (C) 2011 by Pavel Kalian *
10 * $EMAIL$ *
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 * This program is distributed in the hope that it will be useful, *
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20 * GNU General Public License for more details. *
21 * *
22 * You should have received a copy of the GNU General Public License *
23 * along with this program; if not, write to the *
24 * Free Software Foundation, Inc., *
25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
26 ***************************************************************************
27 */
28
29#ifndef _CHARTDLDRPI_H_
30#define _CHARTDLDRPI_H_
31
32#include "wx/wxprec.h"
33
34#ifndef WX_PRECOMP
35#include "wx/wx.h"
36#endif // precompiled headers
37
38#include <wx/fileconf.h>
39#include <wx/tokenzr.h>
40#include <wx/event.h>
41
42#include <wx/imaglist.h>
43
44#include <map>
45
46#include "version.h"
47
48#define MY_API_VERSION_MAJOR 1
49#define MY_API_VERSION_MINOR 13
50
51#define USERDATA "{USERDATA}"
52
53#include "ocpn_plugin.h"
54
55#include "chartdldrgui.h"
56#include "chartcatalog.h"
57
58#define UPDATE_DATA_FILENAME "chartdldr_pi.dat"
59
60// forward declarations
61class ChartSource;
65
66//----------------------------------------------------------------------------------------------------------
67// The PlugIn Class Definition
68//----------------------------------------------------------------------------------------------------------
69
71public:
72 chartdldr_pi(void* ppimgr);
73
74 // The required PlugIn Methods
75 int Init(void);
76 bool DeInit(void);
77
78 int GetAPIVersionMajor();
79 int GetAPIVersionMinor();
80 int GetPlugInVersionMajor();
81 int GetPlugInVersionMinor();
82 wxBitmap* GetPlugInBitmap();
83 wxString GetCommonName();
84 wxString GetShortDescription();
85 wxString GetLongDescription();
86
87 void OnSetupOptions(void);
88 void OnCloseToolboxPanel(int page_sel, int ok_apply_cancel);
89
90 // The required override PlugIn Methods
91 void ShowPreferencesDialog(wxWindow* parent);
92
93 // Other public methods
94 bool SaveConfig(void);
95 bool ProcessFile(const wxString& aFile, const wxString& aTargetDir,
96 bool aStripPath = true,
97 wxDateTime aMTime = wxDateTime::Now());
98 bool ExtractZipFiles(const wxString& aZipFile, const wxString& aTargetDir,
99 bool aStripPath = true,
100 wxDateTime aMTime = wxDateTime::Now(),
101 bool aRemoveZip = false);
102#ifdef DLDR_USE_LIBARCHIVE
103 bool ExtractLibArchiveFiles(const wxString& aArchiveFile,
104 const wxString& aTargetDir,
105 bool aStripPath = true,
106 wxDateTime aMTime = wxDateTime::Now(),
107 bool aRemoveArchive = false);
108#endif
109#if defined(CHARTDLDR_RAR_UNARR) || !defined(DLDR_USE_LIBARCHIVE)
110 bool ExtractUnarrFiles(const wxString& aRarFile, const wxString& aTargetDir,
111 bool aStripPath = true,
112 wxDateTime aMTime = wxDateTime::Now(),
113 bool aRemoveRar = false);
114#endif
115
116 void UpdatePrefs(ChartDldrPrefsDlgImpl* dialog);
117
118 // Public properties
119 std::vector<std::unique_ptr<ChartSource>> m_ChartSources;
120 wxWindow* m_parent_window;
121 ChartCatalog m_pChartCatalog;
122 ChartSource* m_pChartSource;
123 void SetSourceId(int id) { m_selected_source = id; }
124 int GetSourceId() { return m_selected_source; }
125 wxString GetBaseChartDir() { return m_base_chart_dir; }
126 bool m_preselect_new;
127 bool m_preselect_updated;
128 bool m_allow_bulk_update;
129
130private:
131 wxFileConfig* m_pconfig;
132 wxScrolledWindow* m_pOptionsPage;
133 bool LoadConfig(void);
134
135 int m_leftclick_tool_id;
136
137 wxString m_schartdldr_sources;
138 int m_selected_source;
139
140 ChartDldrPanelImpl* m_dldrpanel;
141 wxString m_base_chart_dir;
142};
143
144class ChartSource : public wxTreeItemData {
145public:
146 ChartSource(wxString name, wxString url, wxString localdir);
147 ~ChartSource();
148
149 wxString GetName() { return m_name; }
150 wxString GetUrl() { return m_url; }
151 wxString GetDir() { return m_dir; }
152 void SetDir(wxString dir) { m_dir = dir; }
153 void SetName(wxString name) { m_name = name; }
154 void SetUrl(wxString url) { m_url = url; }
155 bool ExistsLocaly(wxString chart_number, wxString filename);
156 bool IsNewerThanLocal(wxString chart_number, wxString filename,
157 wxDateTime validDate);
158 void UpdateLocalFiles() { GetLocalFiles(); }
159
160 bool UpdateDataExists();
161 void LoadUpdateData();
162 void SaveUpdateData();
163 void ChartUpdated(wxString chart_number, time_t timestamp);
164
165private:
166 wxArrayString m_localfiles;
167 std::vector<wxDateTime> m_localdt;
168 void GetLocalFiles();
169 wxString m_name;
170 wxString m_url;
171 wxString m_dir;
172 std::map<std::string, time_t> m_update_data;
173};
174
177 friend class chartdldr_pi;
178
179private:
180 bool DownloadChart(wxString url, wxString file, wxString title);
181 bool downloadInProgress;
182 int to_download;
183
184 int updatingAll;
185 bool cancelled;
186 bool DownloadIsCancel;
187 chartdldr_pi* pPlugIn;
188 bool m_populated;
189
190 void OnPopupClick(wxCommandEvent& evt);
191 int GetSelectedCatalog();
192 void AppendCatalog(std::unique_ptr<ChartSource>& cs);
193 void DoEditSource();
194
195 bool m_bTransferComplete;
196 bool m_bTransferSuccess;
197 wxString m_totalsize;
198 wxString m_transferredsize;
199 int m_failed_downloads;
200 int m_downloading;
201
202 void DisableForDownload(bool enabled);
203 bool m_bconnected;
204 bool m_bInfoHold; // Don't update chart selection stats right now
205 size_t m_newCharts;
206 size_t m_updatedCharts;
207
208protected:
209 // Handlers for ChartDldrPanel events.
210 void SetSource(int id);
211 void SelectSource(wxListEvent& event);
212 void AddSource(wxCommandEvent& event);
213 void DeleteSource(wxCommandEvent& event);
214 void EditSource(wxCommandEvent& event);
215 void UpdateChartList(wxCommandEvent& event);
216 void OnDownloadCharts(wxCommandEvent& event);
217
218 void OnSelectChartItem(wxCommandEvent& event);
219 void OnSelectNewCharts(wxCommandEvent& event);
220 void OnSelectUpdatedCharts(wxCommandEvent& event);
221 void OnSelectAllCharts(wxCommandEvent& event);
222
223 void DownloadCharts();
224 void DoHelp(wxCommandEvent& event) {
225#ifdef __WXMSW__
226 wxLaunchDefaultBrowser(_T("file:///") + *GetpSharedDataLocation() +
227 _T("plugins/chartdldr_pi/data/doc/index.html"));
228#else
229 wxLaunchDefaultBrowser(_T("file://") + *GetpSharedDataLocation() +
230 _T("plugins/chartdldr_pi/data/doc/index.html"));
231#endif
232 }
233 void UpdateAllCharts(wxCommandEvent& event);
234 void OnShowLocalDir(wxCommandEvent& event);
235 void OnPaint(wxPaintEvent& event);
236 void OnLeftDClick(wxMouseEvent& event);
237
238 void CleanForm();
239 void FillFromFile(wxString url, wxString dir, bool selnew = false,
240 bool selupd = false);
241
242 void OnContextMenu(wxMouseEvent& event);
243 void SetBulkUpdate(bool bulk_update);
244
245 int GetChartCount();
246 int GetCheckedChartCount();
247 bool isChartChecked(int i);
248 void CheckAllCharts(bool value);
249 void InvertCheckAllCharts();
250
251 void CheckNewCharts(bool value);
252 void CheckUpdatedCharts(bool value);
253
254public:
255 // ChartDldrPanelImpl() { m_bconnected = false; DownloadIsCancel = false; }
257 ChartDldrPanelImpl(chartdldr_pi* plugin = NULL, wxWindow* parent = NULL,
258 wxWindowID id = wxID_ANY,
259 const wxPoint& pos = wxDefaultPosition,
260 const wxSize& size = wxDefaultSize,
261 long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
262 void SelectCatalog(int item);
263 void onDLEvent(OCPN_downloadEvent& ev);
264 void CancelDownload() {
265 Disconnect(
266 wxEVT_DOWNLOAD_EVENT,
267 (wxObjectEventFunction)(wxEventFunction)&ChartDldrPanelImpl::onDLEvent);
268 cancelled = true;
269 m_bconnected = false;
270 }
271
272private:
273 DECLARE_EVENT_TABLE()
274};
275
277protected:
278 void OnChangeType(wxCommandEvent& event);
279 void OnSourceSelected(wxTreeEvent& event);
280 void OnOkClick(wxCommandEvent& event);
281 void OnCancelClick(wxCommandEvent& event);
282
283 bool LoadSources();
284 bool LoadSections(const wxTreeItemId& root, pugi::xml_node& node);
285 bool LoadSection(const wxTreeItemId& root, pugi::xml_node& node);
286 bool LoadCatalogs(const wxTreeItemId& root, pugi::xml_node& node);
287 bool LoadCatalog(const wxTreeItemId& root, pugi::xml_node& node);
288
289public:
290 ChartDldrGuiAddSourceDlg(wxWindow* parent);
292 void SetBasePath(const wxString path) { m_base_path = path; }
293 void SetSourceEdit(std::unique_ptr<ChartSource>& cs);
294
295private:
296 bool ValidateUrl(const wxString Url, bool catalog_xml = true);
297 wxString FixPath(wxString path);
298 wxString m_base_path;
299 wxString m_last_path;
300 wxImageList* p_iconList;
301#ifdef __OCPN__ANDROID__
302 wxImageList* p_buttonIconList;
303#endif /* __OCPN__ANDROID__ */
304};
305
307protected:
308 void OnOkClick(wxCommandEvent& event);
309
310public:
311 ChartDldrPrefsDlgImpl(wxWindow* parent);
313 wxString GetPath() { return m_tcDefaultDir->GetValue(); }
314 void SetPath(const wxString path);
315 void GetPreferences(bool& preselect_new, bool& preselect_updated,
316 bool& bulk_update);
317 void SetPreferences(bool preselect_new, bool preselect_updated,
318 bool bulk_update);
319};
320
321#endif
Class AddSourceDlg.
Implementing ChartDldrPanel.
Class ChartDldrPanel.
Class ChartDldrPrefsDlg.
wxBitmap * GetPlugInBitmap()
FIXME static wxBitmap* LoadSVG(const wxString filename, unsigned int width, ...
PlugIn Object Definition/API.