1 /***************************************************************************
2                           tqsl_prefs.h  -  description
3                              -------------------
4     begin                : Sun Jan 05 2003
5     copyright            : (C) 2003 by ARRL
6     author               : Jon Bloom
7     email                : jbloom@arrl.org
8     revision             : $Id$
9  ***************************************************************************/
10 
11 #ifndef __TQSL_PREFS_H
12 #define __TQSL_PREFS_H
13 
14 #ifdef HAVE_CONFIG_H
15 #include "sysconfig.h"
16 #endif
17 
18 #include "wx/wxprec.h"
19 #include "wx/object.h"
20 #include "wx/config.h"
21 
22 #ifdef __BORLANDC__
23 	#pragma hdrstop
24 #endif
25 
26 #ifndef WX_PRECOMP
27 	#include "wx/wx.h"
28 #endif
29 
30 #include "wx/dialog.h"
31 #include "wx/notebook.h"
32 #include "wx/checkbox.h"
33 #include "wx/grid.h"
34 #include "wx/wxhtml.h"
35 #if defined(__APPLE__) || defined(_WIN32)
36 #include "wx/filepicker.h"
37 #endif
38 
39 #include "tqslctrls.h"
40 
41 #include <map>
42 
43 using std::map;
44 using std::pair;
45 
46 #define DEFAULT_CABRILLO_FILES wxT("log cbr")
47 #if !defined(__APPLE__) && !defined(_WIN32)
48 #define DEFAULT_ADIF_FILES wxT("adi adif ADI ADIF")
49 #else
50 #define DEFAULT_ADIF_FILES wxT("adi adif")
51 #endif
52 #define DEFAULT_AUTO_BACKUP true
53 #define DEFAULT_BACKUP_VERSIONS 10
54 #define DEFAULT_CERT_WARNING 60
55 #define DEFAULT_ADIF_EDIT false
56 #define DEFAULT_DISP_DUPES false
57 #define DEFAULT_LOG_TAB false
58 //online
59 //#define ENABLE_ONLINE_PREFS
60 #define DEFAULT_UPL_URL wxT("https://lotw.arrl.org/lotw/upload")
61 #define DEFAULT_UPL_FIELD wxT("upfile")
62 #define DEFAULT_UPL_STATUSRE wxT("<!-- .UPL.\\s*([^-]+)\\s*-->")
63 #define DEFAULT_UPL_STATUSOK wxT("accepted")
64 #define DEFAULT_UPL_MESSAGERE wxT("<!-- .UPLMESSAGE.\\s*(.+)\\s*-->")
65 #define DEFAULT_UPL_VERIFYCA true
66 
67 #define DEFAULT_UPD_URL wxT("https://lotw.arrl.org/lotw/tqslupdate")
68 #define DEFAULT_UPD_CONFIG_URL wxT("https://lotw.arrl.org/lotw/config_xml_version")
69 #define DEFAULT_CONFIG_FILE_URL wxT("https://lotw.arrl.org/lotw/config.tq6")
70 
71 #define DEFAULT_CERT_CHECK_URL wxT("https://lotw.arrl.org/lotw/crl?serial=")
72 #define DEFAULT_CERT_CHECK_RE wxT(".*<Status>(.*)</Status>.*")
73 
74 #define DEFAULT_LOTW_LOGIN_URL wxT("https://lotw.arrl.org/lotwuser/default")
75 
76 enum {		// Window IDs
77 	ID_OK_BUT,
78 	ID_CAN_BUT,
79 	ID_HELP_BUT,
80 	ID_PREF_FILE_CABRILLO = (wxID_HIGHEST+100),
81 	ID_PREF_FILE_ADIF,
82 	ID_PREF_FILE_AUTO_BACKUP,
83 	ID_PREF_FILE_BACKUP,
84 	ID_PREF_FILE_BACKUP_VERSIONS,
85 	ID_PREF_FILE_BADCALLS,
86 	ID_PREF_FILE_DATERANGE,
87 	ID_PREF_FILE_EDIT_ADIF,
88 	ID_PREF_FILE_DISPLAY_DUPES,
89 	ID_PREF_FILE_LOG_TAB,
90 	ID_PREF_MODE_MAP,
91 	ID_PREF_MODE_ADIF,
92 	ID_PREF_MODE_DELETE,
93 	ID_PREF_MODE_ADD,
94 	ID_PREF_ADD_ADIF,
95 	ID_PREF_ADD_MODES,
96 	ID_PREF_CAB_DELETE,
97 	ID_PREF_CAB_ADD,
98 	ID_PREF_CAB_EDIT,
99 	ID_PREF_ONLINE_DEFAULT,
100 	ID_PREF_ONLINE_URL,
101 	ID_PREF_ONLINE_FIELD,
102 	ID_PREF_ONLINE_STATUSRE,
103 	ID_PREF_ONLINE_STATUSOK,
104 	ID_PREF_ONLINE_MESSAGERE,
105 	ID_PREF_ONLINE_VERIFYCA,
106 	ID_PREF_ONLINE_UPD_CONFIGURL,
107         ID_PREF_ONLINE_UPD_CONFIGFILE,
108 	ID_PREF_ONLINE_CERT_CHECK,
109 	ID_PREF_PROXY_ENABLED,
110 	ID_PREF_PROXY_HOST,
111 	ID_PREF_PROXY_PORT,
112 	ID_PREF_PROXY_TYPE
113 };
114 
115 class PrefsPanel : public wxPanel {
116  public:
117 	explicit PrefsPanel(wxWindow *parent, const wxString& helpfile = wxT("prefs.htm"))
wxPanel(parent)118 		: wxPanel(parent), _helpfile(helpfile) {}
HelpFile()119 	wxString HelpFile() { return _helpfile; }
120  private:
121 	wxString _helpfile;
122 };
123 
124 class FilePrefs : public PrefsPanel {
125  public:
126 	explicit FilePrefs(wxWindow *parent);
127 	virtual bool TransferDataFromWindow();
OnShowHide(wxCommandEvent &)128 	void OnShowHide(wxCommandEvent&) { ShowHide(); }
129 	void ShowHide();
130  private:
131 	wxTextCtrl *cabrillo, *adif, *versions;
132 	wxCheckBox *autobackup, *badcalls, *daterange, *adifedit, *dispdupes, *logtab;
133 #if !defined(__APPLE__) && !defined(_WIN32)
134 	wxTextCtrl *dirPick;
135 #else
136 	wxDirPickerCtrl *dirPick;
137 #endif
138 	DECLARE_EVENT_TABLE()
139 };
140 
141 #if defined(ENABLE_ONLINE_PREFS)
142 class OnlinePrefs : public PrefsPanel {
143  public:
144 	explicit OnlinePrefs(wxWindow *parent);
145 	virtual bool TransferDataFromWindow();
146 	void ShowHide();
OnShowHide(wxCommandEvent &)147 	void OnShowHide(wxCommandEvent&) { ShowHide(); }
148 	DECLARE_EVENT_TABLE()
149  private:
150 	wxTextCtrl *uploadURL, *postField, *statusRegex, *statusSuccess, *messageRegex;
151 	wxTextCtrl *updConfigURL, *configFileURL, *certCheckURL;
152 	wxCheckBox *verifyCA, *useDefaults;
153 	bool defaults;
154 };
155 #endif
156 
157 typedef map <wxString, wxString> ModeSet;
158 
159 class ModeMap : public PrefsPanel {
160  public:
161 	explicit ModeMap(wxWindow *parent);
162 	virtual bool TransferDataFromWindow();
163  private:
164 	void SetModeList();
165 	void OnDelete(wxCommandEvent &);
166 	void OnAdd(wxCommandEvent &);
167 	wxButton *delete_but;
168 	wxListBox *map;
169 	ModeSet modemap;
170 	DECLARE_EVENT_TABLE()
171 };
172 
173 typedef map <wxString, pair <int, int> > ContestSet;
174 
175 class ContestMap : public PrefsPanel {
176  public:
177 	explicit ContestMap(wxWindow *parent);
178 	virtual bool TransferDataFromWindow();
179  private:
180 	void SetContestList();
181 	void OnDelete(wxCommandEvent &);
182 	void OnAdd(wxCommandEvent &);
183 	void OnEdit(wxCommandEvent &);
184 	void Buttons();
185 
186 	wxButton *delete_but, *edit_but;
187 	wxGrid *grid;
188 	ContestSet contestmap;
189 	DECLARE_EVENT_TABLE()
190 };
191 
192 class ProxyPrefs : public PrefsPanel {
193  public:
194 	explicit ProxyPrefs(wxWindow *parent);
195 	virtual bool TransferDataFromWindow();
196 	void ShowHide();
OnShowHide(wxCommandEvent &)197 	void OnShowHide(wxCommandEvent&) { ShowHide(); }
198 	DECLARE_EVENT_TABLE()
199  private:
200 	wxCheckBox *proxyEnabled;
201 	wxTextCtrl *proxyHost, *proxyPort;
202 	wxChoice *proxyType;
203 	bool enabled;
204 };
205 
206 typedef map <wxString, wxString> ModeSet;
207 class Preferences : public wxFrame {
208  public:
209 	explicit Preferences(wxWindow *parent, wxHtmlHelpController *help = 0);
210 	void OnOK(wxCommandEvent &);
211 	void OnCancel(wxCommandEvent &);
212 	void OnHelp(wxCommandEvent &);
213 	void OnClose(wxCloseEvent&);
214 	DECLARE_EVENT_TABLE()
215  private:
216 	wxNotebook *notebook;
217 	FilePrefs *fileprefs;
218 	ModeMap *modemap;
219 	ContestMap *contestmap;
220 	ProxyPrefs *proxyPrefs;
221 #if defined(ENABLE_ONLINE_PREFS)
222 	OnlinePrefs *onlinePrefs;
223 #endif
224 	wxHtmlHelpController *_help;
225 };
226 
227 class AddMode : public wxDialog {
228  public:
229 	explicit AddMode(wxWindow *parent);
230 	virtual bool TransferDataFromWindow();
231 	void OnOK(wxCommandEvent &);
OnCancel(wxCommandEvent &)232 	void OnCancel(wxCommandEvent &) { Close(true); }
233 	wxString key, value;
234 	DECLARE_EVENT_TABLE()
235  private:
236 	wxTextCtrl *adif;
237 	wxListBox *modelist;
238 };
239 
240 class EditContest : public wxDialog {
241  public:
242 	EditContest(wxWindow *parent, wxString ctype = _("Edit"), wxString _contest = wxT(""),
243 		int _contest_type = 0, int _callsign_field = 5);
244 	void OnOK(wxCommandEvent&);
OnCancel(wxCommandEvent &)245 	void OnCancel(wxCommandEvent &) { Close(true); }
246 	virtual bool TransferDataFromWindow();
247 	wxString contest;
248 	int contest_type, callsign_field;
249  private:
250 	wxTextCtrl *name;
251 	wxRadioBox *type;
252 	wxTextCtrl *fieldnum;
253 	DECLARE_EVENT_TABLE()
254 };
255 
256 #endif	// __TQSL_PREFS_H
257