OpenCPN Partial API docs
Loading...
Searching...
No Matches
chartdldr_pi.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2011 by Pavel Kalian *
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#ifndef ChartDLdrpI_H_
25#define ChartDLdrpI_H_
26
27#include <map>
28
29#include <wx/wxprec.h>
30
31#ifndef WX_PRECOMP
32#include <wx/wx.h>
33#endif
34
35#include <wx/event.h>
36#include <wx/fileconf.h>
37#include <wx/tokenzr.h>
38
39#include "chartcatalog.h"
40#include "chartdldrgui.h"
41#include "ocpn_plugin.h"
42
43#define MY_API_VERSION_MAJOR 1
44#define MY_API_VERSION_MINOR 13
45#define USERDATA "{USERDATA}"
46#define UPDATE_DATA_FILENAME "chartdldr_pi.dat"
47
48// forward declarations
49class ChartSource; // forward
50class ChartDldrPanelImpl; // in chartdldr.h
51class ChartDldrGuiAddSourceDlg; // in chartdldr.h
52class ChartDldrPrefsDlgImpl; // in chartdldr.h
53
58public:
59 explicit chartdldr_pi(void* ppimgr);
60
61 // The required PlugIn Methods
62 int Init() override;
63 bool DeInit() override;
64
65 // The required override PlugIn Methods
66 int GetAPIVersionMajor() override;
67 int GetAPIVersionMinor() override;
68 int GetPlugInVersionMajor() override;
69 int GetPlugInVersionMinor() override;
70 wxBitmap* GetPlugInBitmap() override;
71 wxString GetCommonName() override;
72 wxString GetShortDescription() override;
73 wxString GetLongDescription() override;
74
75 // Other public methods
76 void OnSetupOptions() override;
77 void OnCloseToolboxPanel(int page_sel, int ok_apply_cancel) override;
78
79 void ShowPreferencesDialog(wxWindow* parent) override;
80
81 bool SaveConfig();
82 bool ProcessFile(const wxString& aFile, const wxString& aTargetDir,
83 bool aStripPath = true,
84 wxDateTime aMTime = wxDateTime::Now());
85 bool ExtractZipFiles(const wxString& aZipFile, const wxString& aTargetDir,
86 bool aStripPath = true,
87 wxDateTime aMTime = wxDateTime::Now(),
88 bool aRemoveZip = false);
89#ifdef DLDR_USE_LIBARCHIVE
90 bool ExtractLibArchiveFiles(const wxString& aArchiveFile,
91 const wxString& aTargetDir,
92 bool aStripPath = true,
93 wxDateTime aMTime = wxDateTime::Now(),
94 bool aRemoveArchive = false);
95#endif
96#if defined(CHARTDLDR_RAR_UNARR) || !defined(DLDR_USE_LIBARCHIVE)
97 bool ExtractUnarrFiles(const wxString& aRarFile, const wxString& aTargetDir,
98 bool aStripPath = true,
99 wxDateTime aMTime = wxDateTime::Now(),
100 bool aRemoveRar = false);
101#endif
102
103 void UpdatePrefs(ChartDldrPrefsDlgImpl* dialog);
104
105 // Public properties
106 std::vector<std::unique_ptr<ChartSource>> m_ChartSources;
107 wxWindow* m_parent_window;
108 ChartCatalog m_chart_catalog;
109 ChartSource* m_chart_source;
110 void SetSourceId(int id) { m_selected_source = id; }
111 [[nodiscard]] int GetSourceId() const { return m_selected_source; }
112 wxString GetBaseChartDir() { return m_base_chart_dir; }
113 bool m_reselect_new;
114 bool m_reselect_updated;
115 bool m_allow_bulk_update;
116
117private:
118 wxFileConfig* m_config;
119 wxScrolledWindow* m_options_page;
120 wxString m_schartdldr_sources;
121 int m_selected_source;
122 ChartDldrPanelImpl* m_dldrpanel;
123 wxString m_base_chart_dir;
124
125 bool LoadConfig();
126};
127
128class ChartSource : public wxTreeItemData {
129public:
130 ChartSource(const wxString& name, const wxString& url,
131 const wxString& localdir);
132 ~ChartSource() override;
133
134 wxString GetName() { return m_name; }
135 wxString GetUrl() { return m_url; }
136 wxString GetDir() { return m_dir; }
137 void SetDir(const wxString& dir) { m_dir = dir; }
138 void SetName(const wxString& name) { m_name = name; }
139 void SetUrl(const wxString& url) { m_url = url; }
140 bool ExistsLocally(const wxString& chart_number, const wxString& filename);
141 bool IsNewerThanLocal(const wxString& chart_number, const wxString& filename,
142 const wxDateTime& validDate);
143 void UpdateLocalFiles() { GetLocalFiles(); }
144
145 bool UpdateDataExists();
146 void LoadUpdateData();
147 void SaveUpdateData();
148 void ChartUpdated(const wxString& chart_number, time_t timestamp);
149
150private:
151 wxArrayString m_localfiles;
152 std::vector<wxDateTime> m_localdt;
153 wxString m_name;
154 wxString m_url;
155 wxString m_dir;
156 std::map<std::string, time_t> m_update_data;
157
158 void GetLocalFiles();
159};
160
163 friend class chartdldr_pi;
164
165private:
166 int m_to_download;
167 int m_updating_all;
168 bool m_cancelled;
169 bool m_download_is_cancel;
170 chartdldr_pi* m_plugin;
171 bool m_is_populated;
172 bool m_is_transfer_complete;
173 bool m_is_transfer_ok;
174 long m_total_size;
175 long m_transferred_size;
176 int m_failed_downloads;
177 bool m_is_connected;
178 bool m_hold_info; // Don't update chart selection stats right now
179 size_t m_new_charts;
180 size_t m_updated_charts;
181 int m_downloading;
182
183 bool DownloadChart(const wxString& url, const wxString& file,
184 const wxString& title);
185 void OnPopupClick(wxCommandEvent& evt);
186 int GetSelectedCatalog();
187 void AppendCatalog(std::unique_ptr<ChartSource>& cs);
188 void DoEditSource();
189
190 void DisableForDownload(bool enabled);
191
192protected:
193 // Handlers for ChartDldrPanel events.
194 void SetSource(int id);
195 void SelectSource(wxListEvent& event) override;
196 void AddSource(wxCommandEvent& event) override;
197 void DeleteSource(wxCommandEvent& event) override;
198 void EditSource(wxCommandEvent& event) override;
199 void UpdateChartList(wxCommandEvent& event) override;
200 void OnDownloadCharts(wxCommandEvent& event) override;
201
202#if defined(CHART_LIST)
203 void OnSelectChartItem(wxCommandEvent& event);
204 void OnSelectNewCharts(wxCommandEvent& event);
205 void OnSelectUpdatedCharts(wxCommandEvent& event);
206 void OnSelectAllCharts(wxCommandEvent& event);
207#endif
208
209 void DownloadCharts();
210 void DoHelp(wxCommandEvent& event) override {
211#ifdef __WXMSW__
212 wxLaunchDefaultBrowser("file:///" + *GetpSharedDataLocation() +
213 "plugins/chartdldr_pi/data/doc/index.html");
214#else
215 wxLaunchDefaultBrowser("file://" + *GetpSharedDataLocation() +
216 "plugins/chartdldr_pi/data/doc/index.html");
217#endif
218 }
219 void UpdateAllCharts(wxCommandEvent& event) override;
220 void OnShowLocalDir(wxCommandEvent& event) override;
221 void OnPaint(wxPaintEvent& event) override;
222 void OnLeftDClick(wxMouseEvent& event) override;
223
224 void CleanForm();
225 void FillFromFile(const wxString& url, const wxString& dir,
226 bool selnew = false, bool selupd = false);
227
228 void SetBulkUpdate(bool bulk_update);
229
230 int GetChartCount();
231 int GetCheckedChartCount();
232 bool isChartChecked(int i);
233 void CheckAllCharts(bool value);
234 void InvertCheckAllCharts();
235
236 void CheckNewCharts(bool value);
237 void CheckUpdatedCharts(bool value);
238
239public:
240 ~ChartDldrPanelImpl() override;
241 explicit ChartDldrPanelImpl(chartdldr_pi* plugin = nullptr,
242 wxWindow* parent = nullptr,
243 wxWindowID id = wxID_ANY,
244 const wxPoint& pos = wxDefaultPosition,
245 const wxSize& size = wxDefaultSize,
246 long style = wxDEFAULT_DIALOG_STYLE |
247 wxRESIZE_BORDER);
248 void SelectCatalog(int item);
249 void onDLEvent(OCPN_downloadEvent& ev);
250 void CancelDownload() {
251 Disconnect(
252 wxEVT_DOWNLOAD_EVENT,
253 (wxObjectEventFunction)(wxEventFunction)&ChartDldrPanelImpl::onDLEvent);
254 m_cancelled = true;
255 m_is_connected = false;
256 }
257 void OnContextMenu(wxMouseEvent& event) override;
258
259private:
260 DECLARE_EVENT_TABLE()
261};
262
264protected:
265 void OnChangeType(wxCommandEvent& event);
266 void OnSourceSelected(wxTreeEvent& event) override;
267 void OnOkClick(wxCommandEvent& event) override;
268 void OnCancelClick(wxCommandEvent& event) override;
269
270 bool LoadSources();
271 bool LoadSections(const wxTreeItemId& root, pugi::xml_node& node);
272 bool LoadSection(const wxTreeItemId& root, pugi::xml_node& node);
273 bool LoadCatalogs(const wxTreeItemId& root, pugi::xml_node& node);
274 bool LoadCatalog(const wxTreeItemId& root, pugi::xml_node& node);
275
276public:
277 explicit ChartDldrGuiAddSourceDlg(wxWindow* parent);
278 ~ChartDldrGuiAddSourceDlg() override;
279 void SetBasePath(const wxString& path) { m_base_path = path; }
280 void SetSourceEdit(std::unique_ptr<ChartSource>& cs);
281
282private:
283 wxString m_base_path;
284 wxString m_last_path;
285 wxImageList* p_iconList;
286#ifdef __ANDROID__
287 wxImageList* p_buttonIconList;
288#endif /* __ANDROID__ */
289
290 bool ValidateUrl(const wxString& Url, bool catalog_xml = true);
291 wxString FixPath(const wxString& path);
292};
293
295protected:
296 void OnOkClick(wxCommandEvent& event) override;
297
298public:
299 explicit ChartDldrPrefsDlgImpl(wxWindow* parent);
300 ~ChartDldrPrefsDlgImpl() override;
301 [[nodiscard]] wxString GetPath() const { return m_tcDefaultDir->GetValue(); }
302 void SetPath(const wxString& path);
303 void GetPreferences(bool& preselect_new, bool& preselect_updated,
304 bool& bulk_update);
305 void SetPreferences(bool preselect_new, bool preselect_updated,
306 bool bulk_update);
307};
308
309#endif // ChartDLdrpI_H_
Chart Downloader Plugin chart classes.
Class AddSourceDlg.
Implementing ChartDldrPanel.
Class ChartDldrPanel.
Class ChartDldrPrefsDlg.
The PlugIn Class Definition.
wxBitmap * GetPlugInBitmap() override
Get the plugin's icon bitmap.
wxString GetShortDescription() override
Get a brief description of the plugin.
int GetAPIVersionMinor() override
Returns the minor version number of the plugin API that this plugin supports.
void ShowPreferencesDialog(wxWindow *parent) override
Shows the plugin preferences dialog.
int GetPlugInVersionMinor() override
Returns the minor version number of the plugin itself.
wxString GetCommonName() override
Get the plugin's common (short) name.
void OnSetupOptions() override
Allows plugin to add pages to global Options dialog.
bool DeInit() override
Clean up plugin resources.
wxString GetLongDescription() override
Get detailed plugin information.
int GetPlugInVersionMajor() override
Returns the major version number of the plugin itself.
void OnCloseToolboxPanel(int page_sel, int ok_apply_cancel) override
Handles preference page closure.
int Init() override
Initialize the plugin and declare its capabilities.
int GetAPIVersionMajor() override
Returns the major version number of the plugin API that this plugin supports.
PlugIn Object Definition/API.
wxString * GetpSharedDataLocation()
Gets shared application data location.