1 /*
2 Copyright (C) 2016-2021, Dirk Krause
3 SPDX-License-Identifier: BSD-3-Clause
4 */
5 
6 /*
7 	WARNING: This file was generated by the dkct program (see
8 	http://dktools.sourceforge.net/ for details).
9 	Changes you make here will be lost if dkct is run again!
10 	You should modify the original source and run dkct on it.
11 	Original source: WxpqdicFrame.wxc
12 */
13 
14 /**	@file WxpqdicFrame.h Header file for the WxpqdicFrame module.
15 */
16 
17 #ifndef WXPQDICFRAME_H_INCLUDED
18 /** Avoid multiple inclusions. */
19 #define WXPQDICFRAME_H_INCLUDED 1
20 
21 
22 
23 
24 class WxpqdicFrame : public Dk4WxFrame
25 {
26   private:
27 
28     /**	Event table for frame.
29     */
30 #if	wxCHECK_VERSION(3,0,0)
31     wxDECLARE_EVENT_TABLE();
32 #else
33     DECLARE_EVENT_TABLE()
34 #endif
35 
36   protected:
37 
38     /**	Buffer for response processing.
39     */
40     char			 bResponse[32 * sizeof(dk4_um_t)];
41 
42     /**	Address pair, 0=remote, 1=local.
43     */
44     dk4_sockaddr_storage_t	 aAddresses[2];
45 
46     /**	Remote host name as wxChar string.
47     */
48     wxString			 sHostname;
49 
50     /**	Queue name as wxChar string.
51     */
52     wxString			 sQueuename;
53 
54     /**	User name as wxChar string.
55     */
56     wxString			 sUsername;
57 
58     /**	Localized texts.
59     */
60     wxChar const * const	*sTexts;
61 
62     /**	Non-localized texts.
63     */
64     wxChar const * const	*sNlWx;
65 
66     /**	Non-localized texts.
67     */
68     dkChar const * const	*sNlDk;
69 
70     /**	Copy of the command line arguments poiner.
71     */
72     wxChar			**copyArgv;
73 
74     /*	__CHANGE__ 011:	Add further member variables.
75     */
76 
77     /**	Critical section to protect socket and timer.
78     */
79     wxCriticalSection		 csProtect;
80 
81     /**	Black color for normal status text.
82     */
83     wxColour			 cBlack;
84 
85     /**	Red color for not allowed to print.
86     */
87     wxColour			 cRed;
88 
89     /**	Green color for allowed to print.
90     */
91     wxColour			 cGreen;
92 
93     /**	Timer for periodic updates.
94     */
95     wxTimer			 timer;
96 
97     /**	Error report from socket subsystem initialization.
98     */
99     dk4_er_t			 sockerr;
100 
101     /**	Host name to query.
102     */
103     dkChar			*pHostname;
104 
105     /**	Print queue to check.
106     */
107     char			*pQueuename;
108 
109     /**	User name to use in check.
110     */
111     char			*pUsername;
112 
113     /**	Request to send to server.
114     */
115     char			*pRequest;
116 
117     /**	Previous limit value.
118     */
119     dk4_um_t			uLimit;
120 
121     /**	Previous used value.
122     */
123     dk4_um_t			uUsed;
124 
125     /**	Previous account value.
126     */
127     dk4_um_t			uAccount;
128 
129     /**	Length of request.
130     */
131     size_t			 szRequest;
132 
133     /**	Size of response buffer.
134     */
135     size_t			 szResponse;
136 
137     /**	Time last request was sended.
138     */
139     dk4_time_t			 tRequestSended;
140 
141     /**	Update interval in seconds.
142     */
143     long			 lUpdateInterval;
144 
145     /**	Timeout interval before complaining about missing response.
146     */
147     long			 lWaitResponse;
148 
149     /**	Previous summary value.
150     */
151     int				 iSummary;
152 
153     /**	Number of command line arguments.
154     */
155     int				 copyArgc;
156 
157     /**	Current state.
158     */
159     int				 iState;
160 
161     /**	Socket for data exchange
162     */
163     dk4_socket_t		 sock;
164 
165     /**	Port number on remote host.
166     */
167     unsigned short		 usPortnumber;
168 
169     /**	Local port number to  use.
170     */
171     unsigned short		 usLocalPort;
172 
173     /**	Flag: Socket subsystem initialized.
174     */
175     bool			 bSockInit;
176 
177     /**	Flag: Remote host uses UTF-8 encoding (user name and queue name).
178     */
179     bool			 bIsUtf8;
180 
181     /**	Flag: This idle event is the first one (no idle events before).
182     */
183     bool			 bFirstIdle;
184 
185     /**	Flag: All components initialized completely.
186     */
187     bool			 bIsInitialized;
188 
189     /**	Flag: This is the first response.
190     */
191     bool			 bFirstResponse;
192 
193     /**	Flag: GUI ok.
194     */
195     bool dkctGUILayoutOK;
196 
197     /**	Contents panel.
198     */
199     wxPanel *dkctGUIContentsPanel;
200 
201     /**	GUI element mainSizer.
202     */
203     wxBoxSizer *mainSizer;
204 
205     /**	GUI element mbMain.
206     */
207     wxMenuBar *mbMain;
208 
209     /**	GUI element tbMain.
210     */
211     wxToolBar *tbMain;
212 
213     /**	GUI element menuFile.
214     */
215     wxMenu *menuFile;
216 
217     /**	GUI element menuView.
218     */
219     wxMenu *menuView;
220 
221     /**	GUI element menuHelp.
222     */
223     wxMenu *menuHelp;
224 
225     /**	GUI element miFileExit.
226     */
227     wxMenuItem *miFileExit;
228 
229     /**	GUI element miViewUpdate.
230     */
231     wxMenuItem *miViewUpdate;
232 
233     /**	GUI element miHelpAbout.
234     */
235     wxMenuItem *miHelpAbout;
236 
237     /**	GUI element miHelpContents.
238     */
239     wxMenuItem *miHelpContents;
240 
241     /**	GUI element verticalSizer.
242     */
243     wxBoxSizer *verticalSizer;
244 
245     /**	GUI element contentsSizer.
246     */
247     wxGridBagSizer *contentsSizer;
248 
249     /**	GUI element lLimit.
250     */
251     wxStaticText *lLimit;
252 
253     /**	GUI element tLimit.
254     */
255     wxStaticText *tLimit;
256 
257     /**	GUI element lUsed.
258     */
259     wxStaticText *lUsed;
260 
261     /**	GUI element tUsed.
262     */
263     wxStaticText *tUsed;
264 
265     /**	GUI element lAccount.
266     */
267     wxStaticText *lAccount;
268 
269     /**	GUI element tAccount.
270     */
271     wxStaticText *tAccount;
272 
273     /**	GUI element lAllowed.
274     */
275     wxStaticText *lAllowed;
276 
277     /**	GUI element tAllowed.
278     */
279     wxStaticText *tAllowed;
280 
281     /**	GUI element lStatus.
282     */
283     wxStaticText *lStatus;
284 
285     /**	GUI element bUpdate.
286     */
287     wxToolBarToolBase *bUpdate;
288 
289     /**	GUI element bExit.
290     */
291     wxToolBarToolBase *bExit;
292 
293 
294   public:
295 
296     /**	Constructor.
297 	@param	wxid			Window ID.
298 	@param	applicationHelper	Application helper object.
299 	@param	hc			Help controller for online help.
300 	@param	argc			Number of command line arguments.
301 	@param	argv			Command line arguments array.
302 	@param	localizedTexts		Localized wxChar texts.
303 	@param	nlWx			Non-localized wxChar texts.
304 	@param	nlDk			Non-localized dkChar texts.
305 	@param	bSocketsInitialized	Flag: Socket subsys initialized.
306 	@param	psockerr		Error report from socket initialization.
307     */
308     WxpqdicFrame(
309       int			  wxid,
310       Dk4WxApplicationHelper	 *applicationHelper,
311       Dk4WxHelpController	 *hc,
312       int			  argc,
313       wxChar			**argv,
314       wxChar const * const	 *localizedTexts,
315       wxChar const * const	 *nlWx,
316       dkChar const * const	 *nlDk,
317       bool			  bSocketsInitialized,
318       dk4_er_t		 	 *psockerr
319     );
320 
321     /**	Destructor.
322     */
323     ~WxpqdicFrame();
324 
325     /**	Check whether we can close the window.
326     	@param	isLast	Flag: Last main window to close.
327     */
328     bool
329     CanClose(bool isFinal);
330 
331     /**	Handler for File/Exit.
332     	@param	event	Event to process.
333     */
334     void
335     OnQuit(wxCommandEvent & event);
336 
337     /**	Handler for File/Update.
338     	@param	event	Event to process.
339     */
340     void
341     OnRun(wxCommandEvent & event);
342 
343     /**	Handler for Help/About.
344     	@param	event	Event to process.
345     */
346     void
347     OnAbout(wxCommandEvent & event);
348 
349     /**	Handler for Help/Contents.
350     	@param	event	Event to process.
351     */
352     void
353     OnHelpContents(wxCommandEvent & event);
354 
355     /*	__CHANGE__ 008:	Remove OnIdle if no idle processing required.
356     */
357     /**	Handler for idle events.
358     */
359     void
360     OnIdle(wxIdleEvent & event);
361 
362     /*	__CHANGE__ 017:	Event handlers for further events.
363     */
364 
365     /** Handler for timer event.
366         @param  event   Timer event to process.
367     */
368     void
369     OnTimer(wxTimerEvent & event);
370 
371 
372     /*	__CHANGE__ 014:	Add further methods.
373     */
374 
375   private:
376 
377     /**	Attempt to configure.
378 	@param	perrc	Address of error code variable.
379 	@return	True if configuration failed and the application should
380 	exit, false on success.
381     */
382     bool
383     ConfigureAndCheckNeedToClose(int *perrc);
384 
385     /**	Attempt to receive data, send request again if interval is over.
386 	@return	True if the windows requires an update, false otherwise.
387     */
388     bool
389     DataExchangeWithServer(void);
390 
391     bool
392     RetrieveResponse(void);
393 
394     bool
395     ProcessResponse(bool & found);
396 
397     bool
398     SendRequest(bool force = false);
399 
400 };
401 
402 
403 
404 #endif
405