1 /***************************************************************************
2                           tqslapp.h  -  description
3                              -------------------
4     begin                : Sun Jun 16 2002
5     copyright            : (C) 2002 by ARRL
6     author               : Jon Bloom
7     email                : jbloom@arrl.org
8     revision             : $Id$
9  ***************************************************************************/
10 
11 #ifndef __tqslapp_h
12 #define __tqslapp_h
13 
14 #define TQSL_CRQ_FILE_EXT "tq5"
15 #define TQSL_CERT_FILE_EXT "tq6"
16 
17 #ifdef __WXMSW__
18 	#define ALLFILESWILD "*.*"
19 #else
20 	#define ALLFILESWILD "*"
21 #endif
22 
23 #define MAIN_WINDOW_MIN_HEIGHT 400
24 #define MAIN_WINDOW_MIN_WIDTH  575
25 
26 #include "tqslconvert.h"
27 #include "qsodatadialog.h"
28 #include "certtree.h"
29 #include "loctree.h"
30 #include "wxutil.h"
31 
32 enum {
33 	tm_f_import = 7000,
34 	tm_f_import_compress,
35 	tm_f_upload,
36 	tm_f_compress,
37 	tm_f_uncompress,
38 	tm_f_preferences,
39 	tm_f_loadconfig,
40 	tm_f_saveconfig,
41 	tm_f_new,
42 	tm_f_edit,
43 	tm_f_diag,
44 	tm_f_exit,
45 	tm_f_lang,
46 	tm_s_add,
47 	tm_s_edit,
48 	tm_s_undelete,
49 	tm_h_contents,
50 	tm_h_about,
51 	tm_h_update,
52 	bg_updateCheck,
53 	bg_expiring
54 };
55 
56 // Action values
57 enum {
58 	TQSL_ACTION_ASK = 0,
59 	TQSL_ACTION_ABORT = 1,
60 	TQSL_ACTION_NEW = 2,
61 	TQSL_ACTION_ALL = 3,
62 	TQSL_ACTION_UNSPEC = 4
63 };
64 
65 #define TQSL_LOG_TAB 3
66 
67 #define TQSL_CD_MSG TQSL_ID_LOW
68 #define TQSL_CD_CANBUT TQSL_ID_LOW+1
69 
70 #define CERTLIST_FLAGS TQSL_SELECT_CERT_WITHKEYS | TQSL_SELECT_CERT_SUPERCEDED | TQSL_SELECT_CERT_EXPIRED
71 // Exit codes
72 enum {
73 	TQSL_EXIT_SUCCESS = 0,
74 	TQSL_EXIT_CANCEL = 1,
75 	TQSL_EXIT_REJECTED = 2,
76 	TQSL_EXIT_UNEXP_RESP = 3,
77 	TQSL_EXIT_TQSL_ERROR = 4,
78 	TQSL_EXIT_LIB_ERROR = 5,
79 	TQSL_EXIT_ERR_OPEN_INPUT = 6,
80 	TQSL_EXIT_ERR_OPEN_OUTPUT = 7,
81 	TQSL_EXIT_NO_QSOS = 8,
82 	TQSL_EXIT_QSOS_SUPPRESSED = 9,
83 	TQSL_EXIT_COMMAND_ERROR = 10,
84 	TQSL_EXIT_CONNECTION_FAILED = 11,
85 	TQSL_EXIT_UNKNOWN = 12,
86 	TQSL_EXIT_BUSY = 13
87 };
88 
89 class MyFrame : public wxFrame {
90  public:
91 	MyFrame(const wxString& title, int x, int y, int w, int h, bool checkUpdates, bool quiet, wxLocale* locale);
92 
IsQuiet(void)93 	bool IsQuiet(void) { return _quiet; }
94 	void AddStationLocation(wxCommandEvent& event);
95 	void EditStationLocation(wxCommandEvent& event);
96 	void EnterQSOData(wxCommandEvent& event);
97 	void EditQSOData(wxCommandEvent& event);
98 	void ProcessQSODataFile(bool upload, bool compressed);
99 	void ImportQSODataFile(wxCommandEvent& event);
100 	void UploadQSODataFile(wxCommandEvent& event);
101 	void SaveWindowLayout(void);
102 	void OnExit(TQ_WXCLOSEEVENT& event);
103 	void DoExit(wxCommandEvent& event);
104 	void DoUpdateCheck(bool silent, bool noGUI);
105 	void OnUpdateCheckDone(wxCommandEvent& event);
106 	void OnHelpAbout(wxCommandEvent& event);
107 	void OnHelpContents(wxCommandEvent& event);
108 	void OnHelpDiagnose(wxCommandEvent& event);
109 #ifdef ALLOW_UNCOMPRESSED
110 	void OnFileCompress(wxCommandEvent& event);
111 #endif
112 	void OnPreferences(wxCommandEvent& event);
113 	void OnSaveConfig(wxCommandEvent& event);
114 	void OnLoadConfig(wxCommandEvent& event);
115 	int ConvertLogFile(tQSL_Location loc, const wxString& infile, const wxString& outfile, bool compress = false, bool suppressdate = false, tQSL_Date* startdate = NULL, tQSL_Date* enddate = NULL, int action = TQSL_ACTION_ASK, const char *password = NULL, const char *defcall = NULL);
116 	tQSL_Location SelectStationLocation(const wxString& title = wxT(""), const wxString& okLabel = _("OK"), bool editonly = false);
117 	int ConvertLogToString(tQSL_Location loc, const wxString& infile, wxString& output, int& n, bool suppressdate = false, tQSL_Date* startdate = NULL, tQSL_Date* enddate = NULL, int action = TQSL_ACTION_ASK, const char* password = NULL, const char* defcall = NULL);
118 	int UploadLogFile(tQSL_Location loc, const wxString& infile, bool compress = false, bool suppressdate = false, tQSL_Date* startdate = NULL, tQSL_Date* enddate = NULL, int action = TQSL_ACTION_ASK, const char* password = NULL, const char *defcall = NULL);
119 	int UploadFile(const wxString& infile, const char* filename, int numrecs, void *content, size_t clen, const wxString& fileType);
120 
121 	void CheckForUpdates(wxCommandEvent&);
122 	void DoCheckForUpdates(bool quiet = false, bool noGUI = false);
123 	void UpdateConfigFile(void);
124 #ifdef _WIN32
125 	void UpdateTQSL(wxString& url);
126 #endif
127 	void DoCheckExpiringCerts(bool noGUI = false);
128 	void OnExpiredCertFound(wxCommandEvent& event);
129 
130 	bool CheckCertStatus(long serial, wxString& result);
131 
132 	void OnQuit(wxCommandEvent& event);
133 	void CRQWizard(wxCommandEvent& event);
134 	void CRQWizardRenew(wxCommandEvent& event);
135 	void OnCertTreeSel(wxTreeEvent& event);
136 	void CertTreeReset(void);
137 	void OnCertProperties(wxCommandEvent& event);
138 	void OnCertExport(wxCommandEvent& event);
139 	void OnCertDelete(wxCommandEvent& event);
140 	void OnCertUndelete(wxCommandEvent& event);
141 //	void OnCertImport(wxCommandEvent& event);
142 	void OnSign(wxCommandEvent& event);
143 	void OnLoadCertificateFile(wxCommandEvent& event);
144 	void OnLocProperties(wxCommandEvent& event);
145 	void OnLocDelete(wxCommandEvent& event);
146 	void OnLocUndelete(wxCommandEvent& event);
147 	void OnLocEdit(wxCommandEvent& event);
148 	void OnLocTreeSel(wxTreeEvent& event);
149 	void OnLoginToLogbook(wxCommandEvent& event);
150 	void OnChooseLanguage(wxCommandEvent& event);
151 	void LocTreeReset(void);
152 	void DisplayHelp(const char *file = "main.htm") { help->Display(wxString::FromUTF8(file)); }
153 	void FirstTime(void);
154 	void BackupConfig(const wxString& event, bool quiet);
155 	void SaveOldBackups(const wxString& directory, const wxString& filename, const wxString& ext);
156 	int SaveAddressInfo(const char* callsign);
157 
158 	CertTree *cert_tree;
159 	LocTree *loc_tree;
160 	wxTextCtrl *logwin;
161 	wxNotebook *notebook;
162 	wxHtmlHelpController *help;
163 	wxMenu* file_menu;
164 	wxMenu *cert_menu;
165 	wxMenu* help_menu;
166 	FILE *curlLogFile;
167 	CURL *curlReq;
168 	tQSL_Converter logConv;
169 
170 	DECLARE_EVENT_TABLE()
171 
172 	wxLocale* locale;
173 
174  private:
175 	wxBitmapButton* loc_add_button;
176 	wxStaticText* loc_add_label;
177 	wxBitmapButton* loc_edit_button;
178 	wxStaticText* loc_edit_label;
179 	wxBitmapButton* loc_delete_button;
180 	wxStaticText* loc_delete_label;
181 	wxBitmapButton* cert_load_button;
182 	wxStaticText* cert_load_label;
183 	wxBitmapButton* cert_save_button;
184 	wxStaticText* cert_save_label;
185 	wxBitmapButton* cert_renew_button;
186 	wxStaticText* cert_renew_label;
187 	wxStaticText* loc_select_label;
188 	wxStaticText* cert_select_label;
189 	wxBitmapButton* cert_prop_button;
190 	wxStaticText* cert_prop_label;
191 	wxBitmapButton* loc_prop_button;
192 	wxStaticText* loc_prop_label;
193 	int renew;
194 	TQSL_CERT_REQ *req;
195 	bool _quiet;
196 };
197 
198 // language data
199 static const wxLanguage langIds[] = {
200     wxLANGUAGE_DEFAULT,
201     wxLANGUAGE_CHINESE,
202     wxLANGUAGE_ENGLISH,
203     wxLANGUAGE_FINNISH,
204     wxLANGUAGE_FRENCH,
205     wxLANGUAGE_GERMAN,
206     wxLANGUAGE_HINDI,
207     wxLANGUAGE_ITALIAN,
208     wxLANGUAGE_JAPANESE,
209     wxLANGUAGE_PORTUGUESE,
210     wxLANGUAGE_RUSSIAN,
211     wxLANGUAGE_SPANISH,
212 };
213 
214 // note that it makes no sense to translate these strings, they are
215 // shown before we set the locale anyhow
216 const wxString langNames[] = {
217     wxT("System default"),
218     wxT("Chinese"),
219     wxT("English"),
220     wxT("Finnish"),
221     wxT("French"),
222     wxT("German"),
223     wxT("Hindi"),
224     wxT("Italian"),
225     wxT("Japanese"),
226     wxT("Portuguese"),
227     wxT("Russian"),
228     wxT("Spanish"),
229 };
230 
231 // the arrays must be in sync
232 wxCOMPILE_TIME_ASSERT(WXSIZEOF(langNames) == WXSIZEOF(langIds),
233                        LangArraysMismatch);
234 
235 #endif // __tqslapp_h
236