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
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 wxString m_schartdldr_sources;
136 int m_selected_source;
137
138 ChartDldrPanelImpl* m_dldrpanel;
139 wxString m_base_chart_dir;
140};
141
142class ChartSource : public wxTreeItemData {
143public:
144 ChartSource(wxString name, wxString url, wxString localdir);
145 ~ChartSource();
146
147 wxString GetName() { return m_name; }
148 wxString GetUrl() { return m_url; }
149 wxString GetDir() { return m_dir; }
150 void SetDir(wxString dir) { m_dir = dir; }
151 void SetName(wxString name) { m_name = name; }
152 void SetUrl(wxString url) { m_url = url; }
153 bool ExistsLocaly(wxString chart_number, wxString filename);
154 bool IsNewerThanLocal(wxString chart_number, wxString filename,
155 wxDateTime validDate);
156 void UpdateLocalFiles() { GetLocalFiles(); }
157
158 bool UpdateDataExists();
159 void LoadUpdateData();
160 void SaveUpdateData();
161 void ChartUpdated(wxString chart_number, time_t timestamp);
162
163private:
164 wxArrayString m_localfiles;
165 std::vector<wxDateTime> m_localdt;
166 void GetLocalFiles();
167 wxString m_name;
168 wxString m_url;
169 wxString m_dir;
170 std::map<std::string, time_t> m_update_data;
171};
172
175 friend class chartdldr_pi;
176
177private:
178 bool DownloadChart(wxString url, wxString file, wxString title);
179 int to_download;
180
181 int updatingAll;
182 bool cancelled;
183 bool DownloadIsCancel;
184 chartdldr_pi* pPlugIn;
185 bool m_populated;
186
187 void OnPopupClick(wxCommandEvent& evt);
188 int GetSelectedCatalog();
189 void AppendCatalog(std::unique_ptr<ChartSource>& cs);
190 void DoEditSource();
191
192 bool m_bTransferComplete;
193 bool m_bTransferSuccess;
194 long m_totalsize;
195 long m_transferredsize;
196 int m_failed_downloads;
197 int m_downloading;
198
199 void DisableForDownload(bool enabled);
200 bool m_bconnected;
201 bool m_bInfoHold; // Don't update chart selection stats right now
202 size_t m_newCharts;
203 size_t m_updatedCharts;
204
205protected:
206 // Handlers for ChartDldrPanel events.
207 void SetSource(int id);
208 void SelectSource(wxListEvent& event) override;
209 void AddSource(wxCommandEvent& event) override;
210 void DeleteSource(wxCommandEvent& event) override;
211 void EditSource(wxCommandEvent& event) override;
212 void UpdateChartList(wxCommandEvent& event) override;
213 void OnDownloadCharts(wxCommandEvent& event) override;
214
215 void OnSelectChartItem(wxCommandEvent& event);
216 void OnSelectNewCharts(wxCommandEvent& event);
217 void OnSelectUpdatedCharts(wxCommandEvent& event);
218 void OnSelectAllCharts(wxCommandEvent& event);
219
220 void DownloadCharts();
221 void DoHelp(wxCommandEvent& event) override {
222#ifdef __WXMSW__
223 wxLaunchDefaultBrowser(_T("file:///") + *GetpSharedDataLocation() +
224 _T("plugins/chartdldr_pi/data/doc/index.html"));
225#else
226 wxLaunchDefaultBrowser(_T("file://") + *GetpSharedDataLocation() +
227 _T("plugins/chartdldr_pi/data/doc/index.html"));
228#endif
229 }
230 void UpdateAllCharts(wxCommandEvent& event) override;
231 void OnShowLocalDir(wxCommandEvent& event) override;
232 void OnPaint(wxPaintEvent& event) override;
233 void OnLeftDClick(wxMouseEvent& event) override;
234
235 void CleanForm();
236 void FillFromFile(wxString url, wxString dir, bool selnew = false,
237 bool selupd = false);
238
239 void OnContextMenu(wxMouseEvent& event) override;
240 void SetBulkUpdate(bool bulk_update);
241
242 int GetChartCount();
243 int GetCheckedChartCount();
244 bool isChartChecked(int i);
245 void CheckAllCharts(bool value);
246 void InvertCheckAllCharts();
247
248 void CheckNewCharts(bool value);
249 void CheckUpdatedCharts(bool value);
250
251public:
252 // ChartDldrPanelImpl() { m_bconnected = false; DownloadIsCancel = false; }
254 ChartDldrPanelImpl(chartdldr_pi* plugin = NULL, wxWindow* parent = NULL,
255 wxWindowID id = wxID_ANY,
256 const wxPoint& pos = wxDefaultPosition,
257 const wxSize& size = wxDefaultSize,
258 long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
259 void SelectCatalog(int item);
260 void onDLEvent(OCPN_downloadEvent& ev);
261 void CancelDownload() {
262 Disconnect(
263 wxEVT_DOWNLOAD_EVENT,
264 (wxObjectEventFunction)(wxEventFunction)&ChartDldrPanelImpl::onDLEvent);
265 cancelled = true;
266 m_bconnected = false;
267 }
268
269private:
270 DECLARE_EVENT_TABLE()
271};
272
274protected:
275 void OnChangeType(wxCommandEvent& event);
276 void OnSourceSelected(wxTreeEvent& event);
277 void OnOkClick(wxCommandEvent& event);
278 void OnCancelClick(wxCommandEvent& event);
279
280 bool LoadSources();
281 bool LoadSections(const wxTreeItemId& root, pugi::xml_node& node);
282 bool LoadSection(const wxTreeItemId& root, pugi::xml_node& node);
283 bool LoadCatalogs(const wxTreeItemId& root, pugi::xml_node& node);
284 bool LoadCatalog(const wxTreeItemId& root, pugi::xml_node& node);
285
286public:
287 ChartDldrGuiAddSourceDlg(wxWindow* parent);
289 void SetBasePath(const wxString path) { m_base_path = path; }
290 void SetSourceEdit(std::unique_ptr<ChartSource>& cs);
291
292private:
293 bool ValidateUrl(const wxString Url, bool catalog_xml = true);
294 wxString FixPath(wxString path);
295 wxString m_base_path;
296 wxString m_last_path;
297 wxImageList* p_iconList;
298#ifdef __OCPN__ANDROID__
299 wxImageList* p_buttonIconList;
300#endif /* __OCPN__ANDROID__ */
301};
302
304protected:
305 void OnOkClick(wxCommandEvent& event);
306
307public:
308 ChartDldrPrefsDlgImpl(wxWindow* parent);
310 wxString GetPath() { return m_tcDefaultDir->GetValue(); }
311 void SetPath(const wxString path);
312 void GetPreferences(bool& preselect_new, bool& preselect_updated,
313 bool& bulk_update);
314 void SetPreferences(bool preselect_new, bool preselect_updated,
315 bool bulk_update);
316};
317
318#endif
Class AddSourceDlg.
Implementing ChartDldrPanel.
Class ChartDldrPanel.
Class ChartDldrPrefsDlg.
int GetPlugInVersionMinor()
Returns the minor version number of the plugin itself.
wxString GetLongDescription()
Get detailed plugin information.
wxBitmap * GetPlugInBitmap()
Get the plugin's icon bitmap.
void ShowPreferencesDialog(wxWindow *parent)
Shows the plugin preferences dialog.
int Init(void)
Initialize the plugin and declare its capabilities.
int GetAPIVersionMinor()
Returns the minor version number of the plugin API that this plugin supports.
bool DeInit(void)
Clean up plugin resources.
void OnCloseToolboxPanel(int page_sel, int ok_apply_cancel)
Handles preference page closure.
int GetAPIVersionMajor()
Returns the major version number of the plugin API that this plugin supports.
wxString GetShortDescription()
Get a brief description of the plugin.
wxString GetCommonName()
Get the plugin's common (short) name.
int GetPlugInVersionMajor()
Returns the major version number of the plugin itself.
void OnSetupOptions(void)
Allows plugin to add pages to global Options dialog.
PlugIn Object Definition/API.
wxString * GetpSharedDataLocation(void)
Gets shared application data location.