summaryrefslogtreecommitdiff
path: root/support/dktools/WxpqdicFrame.wxc
blob: 9b28dae9ab16ba0314a01014d4640372897d2085 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
%%	options

copyright owner	=	Dirk Krause

copyright year	=	2016-xxxx

license		=	bsd



%%	wx-gui

type		= 	frame
contents	=	mainSizer
icon		=	wxpqdic_icon
status bar	=	1 sTexts[8]
menu bar	=	mbMain
tool bar	=	tbMain

[wxMenuBar mbMain]
contents	=	menuFile
contents	=	menuView
contents	=	menuHelp

[wxMenu menuFile]
text		=	sTexts[0]
contents	=	miFileExit

[wxMenuItem miFileExit]
id		=	WxpqdicFrame_Quit
text		=	sTexts[1]
tip		=	sTexts[2]

[wxMenu menuView]
text		=	sTexts[22]
contents	=	miViewUpdate

[wxMenuItem miViewUpdate]
id		=	WxpqdicFrame_View_Update
text		=	sTexts[23]
tip		=	sTexts[24]

[wxMenu menuHelp]
text		=	sTexts[3]
contents	=	miHelpAbout
contents	=	miHelpContents

[wxMenuItem miHelpAbout]
id		=	WxpqdicFrame_Help_About
text		=	sTexts[4]
tip		=	sTexts[5]

[wxMenuItem miHelpContents]
id		=	WxpqdicFrame_Help_Contents
text		=	sTexts[6]
tip		=	sTexts[7]

[wxBoxSizer mainSizer]
direction	=	horizontal
contents	=	$space(10)
contents	=	verticalSizer
contents	=	$space(10)

[wxBoxSizer verticalSizer]
direction	=	vertical
grow		=	yes
proportion	=	1
contents	=	$space(10)
contents	=	contentsSizer
contents	=	$space(10)

[wxGridBagSizer contentsSizer]
grid		=	2 2
contents	=	lLimit		  0  0  1  1  right
contents	=	tLimit		  . +1  1  1
contents	=	lUsed		 +1  0  1  1  right
contents	=	tUsed		  . +1  1  1
contents	=	$space(5)	 +1  0  1  1
contents	=	lAccount	 +1  0  1  1  right
contents	=	tAccount	  . +1  1  1
contents	=	$space(5)	 +1  0  1  1
contents	=	lAllowed	 +1  0  1  1  right
contents	=	tAllowed	  . +1  1  1
contents	=	$space(5)	 +1  0  1  1
contents	=	lStatus		 +1  0  1  2

[wxStaticText lLimit]
text		=	sTexts[13]

[wxStaticText tLimit]
text		=	sTexts[14]

[wxStaticText lUsed]
text		=	sTexts[15]

[wxStaticText tUsed]
text		=	sTexts[27]

[wxStaticText lAccount]
text		=	sTexts[17]

[wxStaticText tAccount]
text		=	sTexts[16]

[wxStaticText lAllowed]
text		=	sTexts[18]

[wxStaticText tAllowed]
text		=	sTexts[27]

[wxStaticText lStatus]
text		=	sTexts[21]


[wxToolBar tbMain]
contents	=	bUpdate
contents	=	bExit

[wxToolBarToolBase bUpdate]
text		=	sTexts[25]
tip		=	sTexts[24]
bitmap		=	xpm_run_conversion
id		=	WxpqdicFrame_View_Update

[wxToolBarToolBase bExit]
text		=	sTexts[26]
tip		=	sTexts[2]
bitmap		=	xpm_exit_program
id		=	WxpqdicFrame_Quit


%%	header start



%%	class start
class WxpqdicFrame : public Dk4WxFrame
{
  private:

    /**	Event table for frame.
    */
    DECLARE_EVENT_TABLE()

  protected:

    /**	Buffer for response processing.
    */
    char			 bResponse[32 * sizeof(dk4_um_t)];

    /**	Address pair, 0=remote, 1=local.
    */
    dk4_sockaddr_storage_t	 aAddresses[2];

    /**	Remote host name as wxChar string.
    */
    wxString			 sHostname;

    /**	Queue name as wxChar string.
    */
    wxString			 sQueuename;

    /**	User name as wxChar string.
    */
    wxString			 sUsername;

    /**	Localized texts.
    */
    wxChar const * const	*sTexts;

    /**	Non-localized texts.
    */
    wxChar const * const	*sNlWx;

    /**	Non-localized texts.
    */
    dkChar const * const	*sNlDk;

    /**	Copy of the command line arguments poiner.
    */
    wxChar			**copyArgv;

    /*	__CHANGE__ 011:	Add further member variables.
    */

    /**	Critical section to protect socket and timer.
    */
    wxCriticalSection		 csProtect;

    /**	Black color for normal status text.
    */
    wxColour			 cBlack;

    /**	Red color for not allowed to print.
    */
    wxColour			 cRed;

    /**	Green color for allowed to print.
    */
    wxColour			 cGreen;

    /**	Timer for periodic updates.
    */
    wxTimer			 timer;

    /**	Error report from socket subsystem initialization.
    */
    dk4_er_t			 sockerr;

    /**	Host name to query.
    */
    dkChar			*pHostname;

    /**	Print queue to check.
    */
    char			*pQueuename;

    /**	User name to use in check.
    */
    char			*pUsername;

    /**	Request to send to server.
    */
    char			*pRequest;

    /**	Previous limit value.
    */
    dk4_um_t			uLimit;

    /**	Previous used value.
    */
    dk4_um_t			uUsed;

    /**	Previous account value.
    */
    dk4_um_t			uAccount;

    /**	Length of request.
    */
    size_t			 szRequest;

    /**	Size of response buffer.
    */
    size_t			 szResponse;

    /**	Time last request was sended.
    */
    dk4_time_t			 tRequestSended;

    /**	Update interval in seconds.
    */
    long			 lUpdateInterval;

    /**	Timeout interval before complaining about missing response.
    */
    long			 lWaitResponse;

    /**	Previous summary value.
    */
    int				 iSummary;

    /**	Number of command line arguments.
    */
    int				 copyArgc;

    /**	Current state.
    */
    int				 iState;

    /**	Socket for data exchange
    */
    dk4_socket_t		 sock;

    /**	Port number on remote host.
    */
    unsigned short		 usPortnumber;

    /**	Local port number to  use.
    */
    unsigned short		 usLocalPort;

    /**	Flag: Socket subsystem initialized.
    */
    bool			 bSockInit;

    /**	Flag: Remote host uses UTF-8 encoding (user name and queue name).
    */
    bool			 bIsUtf8;

    /**	Flag: This idle event is the first one (no idle events before).
    */
    bool			 bFirstIdle;

    /**	Flag: All components initialized completely.
    */
    bool			 bIsInitialized;

    /**	Flag: This is the first response.
    */
    bool			 bFirstResponse;

%%	class end

  public:

    /**	Constructor.
	@param	wxid			Window ID.
	@param	applicationHelper	Application helper object.
	@param	hc			Help controller for online help.
	@param	argc			Number of command line arguments.
	@param	argv			Command line arguments array.
	@param	localizedTexts		Localized wxChar texts.
	@param	nlWx			Non-localized wxChar texts.
	@param	nlDk			Non-localized dkChar texts.
	@param	bSocketsInitialized	Flag: Socket subsys initialized.
	@param	psockerr		Error report from socket initialization.
    */
    WxpqdicFrame(
      int			  wxid,
      Dk4WxApplicationHelper	 *applicationHelper,
      Dk4WxHelpController	 *hc,
      int			  argc,
      wxChar			**argv,
      wxChar const * const	 *localizedTexts,
      wxChar const * const	 *nlWx,
      dkChar const * const	 *nlDk,
      bool			  bSocketsInitialized,
      dk4_er_t		 	 *psockerr
    );

    /**	Destructor.
    */
    ~WxpqdicFrame();

    /**	Check whether we can close the window.
    	@param	isLast	Flag: Last main window to close.
    */
    bool
    CanClose(bool isFinal);

    /**	Handler for File/Exit.
    	@param	event	Event to process.
    */
    void
    OnQuit(wxCommandEvent & event);

    /**	Handler for File/Update.
    	@param	event	Event to process.
    */
    void
    OnRun(wxCommandEvent & event);

    /**	Handler for Help/About.
    	@param	event	Event to process.
    */
    void
    OnAbout(wxCommandEvent & event);

    /**	Handler for Help/Contents.
    	@param	event	Event to process.
    */
    void
    OnHelpContents(wxCommandEvent & event);

    /*	__CHANGE__ 008:	Remove OnIdle if no idle processing required.
    */
    /**	Handler for idle events.
    */
    void
    OnIdle(wxIdleEvent & event);

    /*	__CHANGE__ 017:	Event handlers for further events.
    */

    /** Handler for timer event.
        @param  event   Timer event to process.
    */
    void
    OnTimer(wxTimerEvent & event);


    /*	__CHANGE__ 014:	Add further methods.
    */

  private:

    /**	Attempt to configure.
	@param	perrc	Address of error code variable.
	@return	True if configuration failed and the application should
	exit, false on success.
    */
    bool
    ConfigureAndCheckNeedToClose(int *perrc);

    /**	Attempt to receive data, send request again if interval is over.
	@return	True if the windows requires an update, false otherwise.
    */
    bool
    DataExchangeWithServer(void);

    bool
    RetrieveResponse(void);

    bool
    ProcessResponse(bool & found);

    bool
    SendRequest(bool force = false);

};

%%	header end

%%	module start

#include "wxpqdic.h"
#include "dk4user.h"
#include "dk4enc.h"
#include "dk4strd.h"
#include "dk4rec.h"
#include "dk4str8.h"
#include "dk4strx.h"
#include "dk4recwx.h"
#include "dk4maasz.h"
#include "dk4mai8ddu.h"
#include "dk4mai8dii.h"
#include "dk4mao8d.h"
#include "dk4maowd.h"
#include "dk4numco.h"


#include "exit-program.xpm"
#include "run-conversion.xpm"

#include "dk4verswx.h"

#if !defined(__WXMSW__)
#include "dkicon.xpm"
#endif



$!trace-include



/*	__CHANGE__ 017: Add further events. */
/*	__CHANGE__ 008: Remove OnIdle if no idle processing required. */
BEGIN_EVENT_TABLE(WxpqdicFrame, wxFrame)
	EVT_MENU(WxpqdicFrame_View_Update, WxpqdicFrame::OnRun)
	EVT_MENU(WxpqdicFrame_Quit, WxpqdicFrame::OnQuit)
	EVT_MENU(WxpqdicFrame_Help_About, WxpqdicFrame::OnAbout)
	EVT_MENU(WxpqdicFrame_Help_Contents, WxpqdicFrame::OnHelpContents)
	EVT_TIMER(WxpqdicFrame_Timer, WxpqdicFrame::OnTimer)
	EVT_IDLE(WxpqdicFrame::OnIdle)
END_EVENT_TABLE()



static const wxChar versionNumber[] = { DKT_VERSION_WX };



static const wxCmdLineEntryDesc wxpqdic_cmd_line_entries[] = {
  {
    wxCMD_LINE_OPTION,
    wxT_2("h"),
    wxT_2("host"),
    wxT_2("Host to connect to."),
    wxCMD_LINE_VAL_STRING,
    0
  },
  {
    wxCMD_LINE_OPTION,
    wxT_2("p"),
    wxT_2("port"),
    wxT_2("Port number to connect to."),
    wxCMD_LINE_VAL_NUMBER,
    0
  },
  {
    wxCMD_LINE_OPTION,
    wxT_2("l"),
    wxT_2("local-port"),
    wxT_2("Local port number to use."),
    wxCMD_LINE_VAL_NUMBER,
    0
  },
  {
    wxCMD_LINE_OPTION,
    wxT_2("q"),
    wxT_2("queue"),
    wxT_2("Queue name to check."),
    wxCMD_LINE_VAL_STRING,
    0
  },
  {
    wxCMD_LINE_OPTION,
    wxT_2("u"),
    wxT_2("user"),
    wxT_2("User name to check."),
    wxCMD_LINE_VAL_STRING,
    0
  },
  {
    wxCMD_LINE_OPTION,
    wxT_2("i"),
    wxT_2("interval"),
    wxT_2("Time interval for automatic update."),
    wxCMD_LINE_VAL_NUMBER,
    0
  },
  {
    wxCMD_LINE_OPTION,
    wxT_2("a"),
    wxT_2("ascii"),
    wxT_2("Remote host uses ASCII encoding, not UTF-8."),
    wxCMD_LINE_VAL_NONE,
    0
  },
  { wxCMD_LINE_NONE }
};



/**	Key names for preferences.
*/
static	const wxChar * const	wxpqdic_pref_key_names[] = {
$!string-table	macro=wxT
printqd.host
printqd.port
printqd.queue
printqd.interval
printqd.local
printqd.encoding
$!end
};



/**	Constant 8-bit strings, not localized.
*/
static	const char * const	wxpqdic_kw[] = {
$!string-table
#
#	0	newline
#
\n
#
#	1	space
#
 
#
#	2	keyword info
#
info
$!end
};


%%	constructor start
WxpqdicFrame::WxpqdicFrame(
  int			  wxid,
  Dk4WxApplicationHelper *applicationHelper,
  Dk4WxHelpController	 *hc,
  int			  argc,
  wxChar		**argv,
  wxChar const * const	 *localizedTexts,
  wxChar const * const	 *nlWx,
  dkChar const * const	 *nlDk,
  bool			  bSocketsInitialized,
  dk4_er_t		 *psockerr
) : Dk4WxFrame(nlWx[0], applicationHelper, hc, wxid),
    sHostname(wxT("")),
    sQueuename(wxT("")),
    sUsername(wxT("")),
    cBlack(0, 0, 0),
    cRed(127, 0, 0),
    cGreen(0, 127, 0),
    timer(this, WxpqdicFrame_Timer)

{
  /*	__CHANGE__ 012:	Add further local variables.
  */

  /*	__CHANGE__ 012: Initialize further local variables.
  */

  sTexts = localizedTexts;
  sNlWx  = nlWx;
  sNlDk  = nlDk;
#if defined(__WXMSW__)
  wxIcon	wxpqdic_icon(sNlWx[4]);
#else
  wxIcon	wxpqdic_icon(xpm_dkicon);
#endif
  
  /*	__CHANGE__ 011:	Initialize further class members.
  */
  bSockInit		= bSocketsInitialized;
  DK4_MEMCPY(&sockerr, psockerr, sizeof(dk4_er_t));
  pHostname		= NULL;
  pQueuename		= NULL;
  pUsername		= NULL;
  pRequest		= NULL;
  szRequest		= (size_t)0UL;
  lUpdateInterval	= 30L;
  lWaitResponse		= 1L;
  usPortnumber		= 9100;
  usLocalPort		= 9100;
  bIsUtf8		= true;
  bFirstIdle		= true;
  bFirstResponse	= true;
  bIsInitialized	= false;
  copyArgc		= argc;
  copyArgv		= argv;
  sock			= INVALID_SOCKET;
  iState		= WXPQDIC_STATE_OK;
  tRequestSended	= (dk4_time_t)0UL;
  szResponse		= sizeof(bResponse);
  DK4_MEMRES(&(aAddresses[0]), (2*sizeof(dk4_sockaddr_storage_t)));

%%	constructor end
  if(dkctGUILayoutOK) {
    SetTitle(nlWx[0]);
  }


  /*	__CHANGE__ 012:	Release resources allocated by local variables.
  */
}

%%	module end



WxpqdicFrame::~WxpqdicFrame()
{

  /*	__CHANGE__ 011:	Release resources allocated by further class members.
  */
}



bool
WxpqdicFrame::CanClose(bool isLast)
{
  bool		back	= true;

  return back;
}


void
WxpqdicFrame::OnQuit(wxCommandEvent & event)
{
  {
    wxCriticalSectionLocker	lockCsProtect(csProtect);
    if (bIsInitialized) {
      timer.Stop();
      bIsInitialized = false;
    }
  }
  if (INVALID_SOCKET != sock) {
    dk4socket_close(sock, NULL);
    sock = INVALID_SOCKET;
  }
  dk4mem_release(pUsername);
  dk4mem_release(pQueuename);
  dk4mem_release(pHostname);
  dk4mem_release(pRequest);
  Show(false);
  /*	!!!!! TODO: Release resources */
  Close();
}



void
WxpqdicFrame::OnAbout(wxCommandEvent & event)
{
  wxString	text(wxT(""));
  wxString	title(wxT(""));

  /* Construct message text. */
  text.Append(sNlWx[0]);
  text.Append(sNlWx[7]);
#if 0
  text.Append(sNlWx[1]);
#endif
  text.Append(versionNumber);
  text.Append(sNlWx[8]);
  text.Append(sTexts[9]);
  text.Append(sNlWx[2]);
  text.Append(sNlWx[8]);
  text.Append(sNlWx[8]);
  text.Append(sTexts[11]);
  text.Append(sNlWx[8]);
  text.Append(sNlWx[9]);
  text.Append(sNlWx[8]);
  text.Append(sNlWx[8]);
  text.Append(sTexts[12]);
  text.Append(sNlWx[8]);
  text.Append(sNlWx[10]);
  text.Append(sNlWx[8]);
  text.Append(sNlWx[11]);
  text.Append(sNlWx[8]);
  text.Append(sNlWx[12]);
  text.Append(sNlWx[8]);
  text.Append(sNlWx[13]);
  text.Append(sNlWx[8]);
  text.Append(sNlWx[14]);
  text.Append(sNlWx[8]);
  text.Append(sNlWx[15]);
  text.Append(sNlWx[8]);
  
  /* Construct dialog box title. */
  title.Append(sTexts[10]);
  title.Append(sNlWx[0]);

  /* Show dialog box. */
  wxMessageBox(text, title);

}



void
WxpqdicFrame::OnHelpContents(wxCommandEvent & event)
{
  DisplayContents();
}

/*	__CHANGE__ 017:	Event handlers for further events.
*/

/*	__CHANGE__ 014:	Implementation of further methods.
*/


bool
WxpqdicFrame::ConfigureAndCheckNeedToClose(int *perrc)
{

  dkChar		 buf[1024];
  char			 c8b[1024];
  dk4_er_t		 er;
  wxChar		*pv[] = { NULL, NULL, NULL, NULL, NULL, NULL };
  const wxChar		*cptr;
  const size_t		 szbuf			= DK4_SIZEOF(buf,dkChar);
  const size_t		 szc8b			= sizeof(c8b);
  long		 	 l			= 0L;
  int		 	 res			= 0;
  bool			 back			= true;

  /*	Retrieve some fallback values from preferences.
  */
  pAppHelp->GetMultiple(wxpqdic_pref_key_names, pv, 6);
  $? ". host     = \"%!ws\"", TR_WXSTR(pv[0])
  $? ". port     = \"%!ws\"", TR_WXSTR(pv[1])
  $? ". queue    = \"%!ws\"", TR_WXSTR(pv[2])
  $? ". interval = \"%!ws\"", TR_WXSTR(pv[3])
  $? ". local    = \"%!ws\"", TR_WXSTR(pv[4])
  $? ". encoding = \"%!ws\"", TR_WXSTR(pv[5])

  /*	Check command line arguments
  */
  {
    wxLogNull log;
    wxCmdLineParser 	 parser(wxpqdic_cmd_line_entries, copyArgc, copyArgv);
    res = parser.Parse(false);
    /*
	Check overall parsing of arguments
    */
    if (0 != res) {		$? "! failed to parse cmd line args"
      /* ERROR: Failed to parse command line arguments */
      *perrc = WXPQDIC_FRAME_ERROR_PARSE;
      goto finished;
    }
    /*
	Option -a means the remote host wants ASCII data.
    */
    if (parser.Found(wxT_2("a"))) {
      bIsUtf8 = false;
    } else {
      if (NULL != pv[5]) {
        if (0 != dk4strx_casecmp(pv[5], sNlWx[16])) {
	  if (0 != dk4strx_casecmp(pv[5], sNlWx[17])) {
	    bIsUtf8 = false;
	  }
	}
      }
    }
    /*
	Try to obtain host name from arguments or from preferences.
    */
    dk4error_init(&er);
    cptr = NULL;
    if (parser.Found(wxT_2("h"), &sHostname)) {
      cptr = sHostname.c_str();
    }
    else {
      cptr = pv[0];
    }
    if (NULL != cptr) {
      if (pAppHelp->StringToDk(buf, szbuf, cptr, &er)) {
        pHostname = dk4str_dup(buf, NULL);
	if (NULL == pHostname) { $? ". pHostname = \"%!ds\"", pHostname
	  /* ERROR: Memory */
	  *perrc = WXPQDIC_FRAME_ERROR_MEMORY;
	  goto finished;
	}
      } else {
        /* ERROR: Failed to convert string */
	*perrc = WXPQDIC_FRAME_ERROR_STRCONV_HOSTNAME;
	goto finished;
      }
    }
    if (NULL == pHostname) {
      /* ERROR: Missing host name */
      *perrc = WXPQDIC_FRAME_ERROR_HOSTNAME;
      goto finished;
    }
    /*
	Queue name is required.
    */
    cptr = NULL;
    if (parser.Found(wxT_2("q"), &sQueuename)) {
      cptr = sQueuename.c_str();
    }
    else {
      cptr = pv[2];
    }
    if (NULL != cptr) {
      res = dk4recwx_wxchar_to_char(
        c8b, szc8b, ((bIsUtf8) ? (DK4_ENCODING_UTF8) : (DK4_ENCODING_ASCII)),
	cptr, pAppHelp->GetWxEncoding(), NULL
      );
      if (0 != res) {
        pQueuename = dk4str8_dup(c8b, NULL);
	if (NULL == pQueuename) {	$? ". pQueuename = \"%!8s\"", pQueuename
	  /* ERROR: Memory */
	  *perrc = WXPQDIC_FRAME_ERROR_MEMORY;
	  goto finished;
	}
      } else {
        /* ERROR: String conversion failed */
	*perrc = WXPQDIC_FRAME_ERROR_STRCONV_QUEUENAME;
	goto finished;
      }
    }
    else {
      /* ERROR: Missing queue name */
      *perrc = WXPQDIC_FRAME_ERROR_QUEUENAME;
      goto finished;
    }
    if (NULL == pQueuename) {
      /* ERROR: Missing queue name */
      *perrc = WXPQDIC_FRAME_ERROR_QUEUENAME;
      goto finished;
    }
    /*
	Port number is optional.
    */
    {
      bool	portnoFound	= false;
      l = 0L;
      if (parser.Found(wxT_2("p"), &l)) {
        portnoFound = true;
      }
      else {
        if (NULL != pv[1]) {
	  wxString s(pv[1]);
	  if (s.ToLong(&l, 0)) {
	    portnoFound = true;
	  }
	}
      }
      if (portnoFound) {
	if ((long)(USHRT_MAX) < l) {
	  /* ERROR: Port number out of range */
	  *perrc = WXPQDIC_FRAME_ERROR_PORT_OOR;
	  goto finished;
	}
	if (0L == l) {
	  /* ERROR: Illegal port number 0 */
	  *perrc = WXPQDIC_FRAME_ERROR_PORT_ZERO;
	  goto finished;
	}
	usPortnumber = (unsigned short)l;
      }
    }
    /*
	Local port number is optional.
    */
    {
      bool	portnoFound	= false;
      l = 0L;
      if (parser.Found(wxT_2("l"), &l)) {
        portnoFound = true;
      }
      else {
        if (NULL != pv[4]) {
	  wxString s(pv[4]);
	  if (s.ToLong(&l, 0)) {
	    portnoFound = true;
	  }
	}
      }
      if (portnoFound) {
	if ((long)(USHRT_MAX) < l) {
	  /* ERROR: Port number out of range */
	  *perrc = WXPQDIC_FRAME_ERROR_LOCALPORT_OOR;
	  goto finished;
	}
	if (0L == l) {
	  /* ERROR: Illegal port number 0 */
	  *perrc = WXPQDIC_FRAME_ERROR_LOCALPORT_ZERO;
	  goto finished;
	}
	usLocalPort = (unsigned short)l;
      }
    }
    /*
	User name is optional, use current user by default.
    */
    if (parser.Found(wxT_2("u"), &sUsername)) {
      res = dk4recwx_wxchar_to_char(
        c8b, szc8b, ((bIsUtf8) ? (DK4_ENCODING_UTF8) : (DK4_ENCODING_ASCII)),
	sUsername.c_str(), pAppHelp->GetWxEncoding(), NULL
      );
      if (0 != res) {
        pUsername = dk4str8_dup(c8b, NULL);
	if (NULL == pUsername) {
	  /* ERROR: Memory */
	  *perrc = WXPQDIC_FRAME_ERROR_MEMORY;
	  goto finished;
	}
      }
      else {
        /* ERROR: Failed to convert user name */
	*perrc = WXPQDIC_FRAME_ERROR_STRCONV_USERNAME;
	goto finished;
      }
    }
    else {
      res = dk4user_get_logname(buf, szbuf, 0, NULL);
      if (0 != res) {
        res = dk4recode_dk_to_any(
	  c8b, szc8b, ((bIsUtf8) ? (DK4_ENCODING_UTF8) : (DK4_ENCODING_ASCII)),
	  buf, pAppHelp->GetDkEncoding(), NULL
	);
	if (0 != res) {
	  pUsername = dk4str8_dup(c8b, NULL);
	  if (NULL == pUsername) {
	    /* ERROR: Memory */
	    *perrc = WXPQDIC_FRAME_ERROR_MEMORY;
	    goto finished;
	  }
	}
	else {
	  /* ERROR: Failed to convert user name */
	  *perrc = WXPQDIC_FRAME_ERROR_STRCONV_USERNAME;
	  goto finished;
	}
      } else {
        /* ERROR: User name not found! */
	*perrc = WXPQDIC_FRAME_ERROR_USERNAME;
	goto finished;
      }
    }
    if (NULL == pUsername) {
      /* ERROR: No user name */
      *perrc = WXPQDIC_FRAME_ERROR_USERNAME;
      goto finished;
    }
    /*
	Interval length is optional.
    */
    {
      bool	intervalFound	= false;
      l = 0L;
      if (parser.Found(wxT_2("p"), &l)) {
        intervalFound = true;
      }
      else {
        if (NULL != pv[3]) {
	  wxString s(pv[3]);
	  if (s.ToLong(&l, 0)) {
	    intervalFound = true;
	  }
	}
      }
      if (intervalFound) {
        if (5L <= l) {
	  lUpdateInterval = l;
	} else {
	  lUpdateInterval = 5L;
	}
      }
    }
    /*
	Now build request
    */
    dk4error_init(&er);
    szRequest = strlen(wxpqdic_kw[2]);
    szRequest = dk4ma_size_t_add(szRequest, dk4str8_len(pQueuename), &er);
    szRequest = dk4ma_size_t_add(szRequest, dk4str8_len(pUsername), &er);
    szRequest = dk4ma_size_t_add(szRequest, dk4str8_len(wxpqdic_kw[2]), &er);
    szRequest = dk4ma_size_t_add(szRequest, 4, &er);
    if (DK4_E_NONE == er.ec) {
      pRequest = dk4mem_new(char,szRequest,NULL);
      if (NULL != pRequest) {
        if (0 == dk4str8_cpy_s(pRequest, szRequest, wxpqdic_kw[2], NULL)) {
	  /* ERROR: BUG */
	  *perrc = WXPQDIC_FRAME_ERROR_BUG;
	  goto finished;
	}
	if (0 == dk4str8_cat_s(pRequest, szRequest, wxpqdic_kw[1], NULL)) {
	  /* ERROR: BUG */
	  *perrc = WXPQDIC_FRAME_ERROR_BUG;
	  goto finished;
	}
	if (0 == dk4str8_cat_s(pRequest, szRequest, pQueuename, NULL)) {
	  /* ERROR: BUG */
	  *perrc = WXPQDIC_FRAME_ERROR_BUG;
	  goto finished;
	}
	if (0 == dk4str8_cat_s(pRequest, szRequest, wxpqdic_kw[1], NULL)) {
	  /* ERROR: BUG */
	  *perrc = WXPQDIC_FRAME_ERROR_BUG;
	  goto finished;
	}
	if (0 == dk4str8_cat_s(pRequest, szRequest, pUsername, NULL)) {
	  /* ERROR: BUG */
	  *perrc = WXPQDIC_FRAME_ERROR_BUG;
	  goto finished;
	}
	if (0 == dk4str8_cat_s(pRequest, szRequest, wxpqdic_kw[0], NULL)) {
	  /* ERROR: BUG */
	  *perrc = WXPQDIC_FRAME_ERROR_BUG;
	  goto finished;
	}
	szRequest = dk4str8_len(pRequest);
	$? ". request = \"%s\"", TR_8STR(pRequest)
      } else {
        /* ERROR: Memory */
	*perrc = WXPQDIC_FRAME_ERROR_MEMORY;
	goto finished;
      }
    } else {
      /* ERROR: Numeric overflow in size calculation */
      *perrc = WXPQDIC_FRAME_ERROR_SIZE_CALC_OVERFLOW;
      goto finished;
    }
    /*
	Create socket.
    */
    sock = dk4socket_udp_client_for_host(
      aAddresses, pHostname, usPortnumber, usLocalPort, 1, NULL
    );
    if (INVALID_SOCKET == sock) {
      *perrc = WXPQDIC_FRAME_ERROR_SOCKET;
      goto finished;
    }

  }

  $? ". successfully completed setup"

  tLimit->SetLabel(sTexts[27]);
  tUsed->SetLabel(sTexts[27]);
  tAccount->SetLabel(sTexts[27]);

  /*	Finally indicate success.
  */
  timer.Start(500);
  bIsInitialized = true;
  back = false;

  /*	Clean up at end and return result.
  */
  finished:
  pAppHelp->ReleaseWxcharStringArray(pv, 6);
  if (back) {
    if (INVALID_SOCKET != sock) {
      dk4socket_close(sock, NULL);
      sock = INVALID_SOCKET;
    }
    dk4mem_release(pUsername);
    dk4mem_release(pQueuename);
    dk4mem_release(pHostname);
    dk4mem_release(pRequest);
  }
  return back;
}



void
WxpqdicFrame::OnIdle(wxIdleEvent & event)
{
  int			 errorCode		= WXPQDIC_FRAME_ERROR_NONE;
  bool			 mustClose		= false;
  $? "+ OnIdle"
  /* __CHANGE__
  */
  {
    wxCriticalSectionLocker	lockCsProtect(csProtect);
    if (bFirstIdle) {
      bFirstIdle = false;
      mustClose = ConfigureAndCheckNeedToClose(&errorCode);
    }
  }
  if (mustClose) {		$? "! error in setup, must close window"
    const wxChar *ti;
    const wxChar *tx;
    ti = sTexts[58]; tx = sTexts[59];
    switch (errorCode) {
      case WXPQDIC_FRAME_ERROR_PARSE : {
        ti = sTexts[30]; tx = sTexts[31];
      } break;
      case WXPQDIC_FRAME_ERROR_MEMORY : {
        ti = sTexts[32]; tx = sTexts[33];
      } break;
      case WXPQDIC_FRAME_ERROR_STRCONV_HOSTNAME : {
        ti = sTexts[34]; tx = sTexts[35];
      } break;
      case WXPQDIC_FRAME_ERROR_HOSTNAME : {
        ti = sTexts[36]; tx = sTexts[37];
      } break;
      case WXPQDIC_FRAME_ERROR_STRCONV_QUEUENAME : {
        ti = sTexts[38]; tx = sTexts[39];
      } break;
      case WXPQDIC_FRAME_ERROR_QUEUENAME : {
        ti = sTexts[40]; tx = sTexts[41];
      } break;
      case WXPQDIC_FRAME_ERROR_PORT_OOR : {
        ti = sTexts[42]; tx = sTexts[43];
      } break;
      case WXPQDIC_FRAME_ERROR_PORT_ZERO : {
        ti = sTexts[42]; tx = sTexts[44];
      } break;
      case WXPQDIC_FRAME_ERROR_STRCONV_USERNAME : {
        ti = sTexts[45]; tx = sTexts[46];
      } break;
      case WXPQDIC_FRAME_ERROR_USERNAME : {
        ti = sTexts[47]; tx = sTexts[48];
      } break;
      case WXPQDIC_FRAME_ERROR_LOCALPORT_OOR : {
        ti = sTexts[49]; tx = sTexts[50];
      } break;
      case WXPQDIC_FRAME_ERROR_LOCALPORT_ZERO : {
        ti = sTexts[49]; tx = sTexts[51];
      } break;
      case WXPQDIC_FRAME_ERROR_BUG : {
        ti = sTexts[52]; tx = sTexts[53];
      } break;
      case WXPQDIC_FRAME_ERROR_SIZE_CALC_OVERFLOW : {
        ti = sTexts[54]; tx = sTexts[55];
      } break;
      case WXPQDIC_FRAME_ERROR_SOCKET : {
        ti = sTexts[56]; tx = sTexts[57];
      } break;
    }
    wxMessageBox(tx, ti, (wxICON_ERROR | wxOK), this);
    Show(false);
    Close();
  }

  /*	Allow idle handlers from the base class.
  */
  $? "- OnIdle"
  event.Skip();
}


void
WxpqdicFrame::OnTimer(wxTimerEvent & event)
{
  bool	mustUpdate	= false;
  $? "+ OnTimer"
  {
    wxCriticalSectionLocker	lockCsProtect(csProtect);
    $? ". entered critical section"
    if (bIsInitialized) {	$? ". already initialized"
      mustUpdate = DataExchangeWithServer();
    }
#if TRACE_DEBUG
    else {			$? "! not yet initialized"
    }
#endif
    $? ". exiting critical section"
  }
  if (mustUpdate) {
    Refresh();
    Update();
  }
  $? "- OnTimer"
}



bool
WxpqdicFrame::ProcessResponse(bool & found)
{
  wxChar	 wxb[16*sizeof(dk4_um_t)];
  char		*tokens[8];		/* Tokens in the response */
  const char	*ep;			/* End part of text */
  dk4_um_t	 limit;			/* Print limit */
  dk4_um_t	 used;			/* Pages used with in limit */
  dk4_um_t	 account;		/* Personal account */
  size_t	 sz;			/* Number of tokens used */
  size_t	 szwxb;			/* Size of wxb */
  int		 founddet;		/* Details found. */
  int		 res;			/* Text to number conversion result */
  int		 summary;		/* Flag: Can print */
  bool		 force;			/* Flag: Force use of values */
  bool		 back	= false;
  $? "+ ProcessResponse"
  sz = dk4str8_tokenize(tokens, 8, bResponse, NULL, NULL);
  if (4 == sz) {				$? ". 4 tokens"
    founddet = 0;
    force = bFirstResponse;
    switch (iState) {
      case WXPQDIC_STATE_TIMEOUT :
      case WXPQDIC_STATE_SEND_FAILED :
      {
        force = true;			$? ". recover from error"
      } break;
    }					$? ". force = %d", (force ? 1 : 0)
    if (0 == dk4str8_cmp("-1", tokens[0])) {	$? ". 0 = unlimited"
      limit = DK4_UM_MAX;
      founddet |= 1;
    } else {
      limit = (dk4_um_t)0UL;
      ep = NULL;
      res = dk4ma_input_c8_dec_dk4_um_t(&limit, tokens[0], &ep, 1, NULL);
      if (0 != res) {				$? ". 0 = %lu", (unsigned long)limit
        founddet |= 1;
      }
#if TRACE_DEBUG
      else {					$? "! 0 not a number"
      }
#endif
    }
    used = (dk4_um_t)0UL;
    ep = NULL;
    res = dk4ma_input_c8_dec_dk4_um_t(&used, tokens[1], &ep, 1, NULL);
    if (0 != res) {				$? ". 1 = %lu", (unsigned long)used
      founddet |= 2;
    }
#if TRACE_DEBUG
    else {					$? "! 1 not a number"
    }
#endif
    account = (dk4_um_t)0UL;
    ep = NULL;
    res = dk4ma_input_c8_dec_dk4_um_t(&account, tokens[2], &ep, 1, NULL);
    if (0 != res) {				$? ". 2 = %lu", (unsigned long)account
      founddet |= 4;
    }
#if TRACE_DEBUG
    else {					$? "! 2 not a number"
    }
#endif
    summary = 0;
    ep = NULL;
    res = dk4ma_input_c8_dec_int(&summary, tokens[3], &ep, 1, NULL);
    if (0 != res) {				$? ". 3 = %d", summary
      founddet |= 8;
    }
#if TRACE_DEBUG
    else {					$? "! 3 not a number"
    }
#endif
    if (15 == (15 & founddet)) {		$? ". processed successfully"
      /*	Renew text labels
      */
#if DK4_SIZEOF_WXCHAR > 1
      szwxb = DK4_SIZEOF(wxb,wxChar);
      if ((force) || (limit != uLimit)) {
        if (DK4_UM_MAX == limit) {
	  tLimit->SetLabel(sTexts[14]);
	} else {
	  res = dk4ma_write_wc_decimal_unsigned(wxb, szwxb, limit, 0, NULL);
	  if (0 != res) {
	    wxString s(wxb);
	    tLimit->SetLabel(s);
	  }
	}
        back = true;
      }
      if ((force) || (used != uUsed)) {
        res = dk4ma_write_wc_decimal_unsigned(wxb, szwxb, used, 0, NULL);
	if (0 != res) {
	  wxString s(wxb);
	  tUsed->SetLabel(s);
	}
        back = true;
      }
      if ((force) || (account != uAccount)) {
        res = dk4ma_write_wc_decimal_unsigned(wxb, szwxb, account, 0, NULL);
	if (0 != res) {
	  wxString s(wxb);
	  tAccount->SetLabel(s);
	}
        back = true;
      }
#else
      if ((force) || (limit != uLimit)) {
        if (DK4_UM_MAX == limit) {
	  tLimit->SetLabel(sTexts[14]);
	} else {
	  wxString s(tokens[0]);
	  tLimit->SetLabel(s);
	}
	back = true;				$? ". update for limit"
      }
      if ((force) || (used != uUsed)) {
        wxString s(tokens[1]);
	tUsed->SetLabel(s);
        back = true;				$? ". update for used"
      }
      if ((force) || (account != uAccount)) {
        wxString s(tokens[2]);
	tAccount->SetLabel(s);
        back = true;				$? ". update for account"
      }
#endif
      if ((force) || (summary != iSummary)) {
        wxString s(sTexts[(0 != summary) ? 19 : 20]);
	tAllowed->SetLabel(s);
	if (0 != summary) {
	  tAllowed->SetForegroundColour(cGreen);
	} else {
	  tAllowed->SetForegroundColour(cRed);
	}
        back = true;				$? ". update for summary"
      }
      if (force) {
	lStatus->SetLabel(sNlWx[5]);
        switch (iState) {
          case WXPQDIC_STATE_TIMEOUT :
          case WXPQDIC_STATE_SEND_FAILED :
          {
            lStatus->SetForegroundColour(cBlack);
          } break;
        }
      }
      /*	Save values for later comparisons
      */
      uLimit   = limit;
      uUsed    = used;
      uAccount = account;
      iSummary = summary;
      bFirstResponse = false;
      /*	Change state
      */
      iState = WXPQDIC_STATE_OK;
      found = true;
    }
#if TRACE_DEBUG
    else {					$? "! processing failed"
    }
#endif
  }
#if TRACE_DEBUG
  else {				$? "! not 4 tokens"
  }
#endif
  $? "- ProcessResponse %d", ((back) ? (1) : (0))
  return back;
}



bool
WxpqdicFrame::RetrieveResponse(void)
{
  dk4_sockaddr_storage_t	 remaddr;		/* Source address */
  size_t	 		 sz;			/* Buffer size */
  size_t	 		 szrema;		/* Address size */
  int				 res;			/* Conversion result */
  bool				 back	= false;
  bool				 found	= false;	/* Flag: Found */
  $? "+ RetrieveResponse"
  sz = szResponse;
  szrema = sizeof(remaddr);
  res = dk4socket_recvfrom(
    sock, bResponse, &sz, 0,
    (struct sockaddr *)(&remaddr), &szrema,
    0L, 10000L, NULL
  );
  switch (res) {
    case DK4_SOCKET_RESULT_SUCCESS :
    case DK4_SOCKET_RESULT_IN_PROGRESS :
    {					$? ". data"
      if (0 < sz) {				$? ". data length"
	bResponse[(szResponse > sz) ? (sz) : (szResponse - 1)] = '\0';
#if TRACE_DEBUG
	dk4str8_delnl(bResponse);	$? ". response = \"%!8s\"", bResponse
#endif
	if (1 /* ##### TODO: Compare addresses */ ) { $? ". addr ok"
	  back = ProcessResponse(found);
	}
#if TRACE_DEBUG
	else {				$? "! addr mismatch"
	}
#endif
      }
#if TRACE_DEBUG
      else {				$? "! data length 0"
      }
#endif
    } break;
    default : {				$? ". no data"
    } break;
  }
  if (!(found)) {
    if (WXPQDIC_STATE_SENDED == iState) {
      iState = WXPQDIC_STATE_TIMEOUT;
      tLimit->SetLabel(sTexts[27]);
      tUsed->SetLabel(sTexts[27]);
      tAccount->SetLabel(sTexts[27]);
      tAllowed->SetLabel(sTexts[27]);
      tAllowed->SetForegroundColour(cBlack);
      lStatus->SetLabel(sTexts[29]);
      lStatus->SetForegroundColour(cRed);
      back = true;
    }
  }
  $? "- RetrieveResponse %d", ((back) ? (1) : (0))
  return back;
}



bool
WxpqdicFrame::SendRequest(bool force)
{
  dk4_time_t	 currenttime	= (dk4_time_t)0UL;
  size_t	 sz		= 0;
  int		 res		= 0;
  bool		 mustsend	= false;
  bool		 back		= false;
  $? "+ SendRequest"
  if ((dk4_time_t)0UL == tRequestSended) {
    mustsend = true;
  } else {
    if (force) {
      mustsend = true;
    } else {
      dk4time_get(&currenttime);
      if ((tRequestSended + (dk4_time_t)lUpdateInterval) <= currenttime) {
        mustsend = true;
      }
    }
  }
  if (mustsend) {					$? ". must send"
    sz = szRequest;
    if ((dk4_um_t)0UL == currenttime) {
      dk4time_get(&currenttime);
    }
    res = dk4socket_sendto(
      sock, pRequest, &sz, 0,
      (struct sockaddr *)(&(aAddresses[0])), sizeof(dk4_sockaddr_storage_t),
      0L, 0L, NULL
    );
    tRequestSended = currenttime;
    switch (res) {
      case DK4_SOCKET_RESULT_SUCCESS :
      case DK4_SOCKET_RESULT_IN_PROGRESS :
      {							$? ". success, sended"
        switch (iState) {
	  case WXPQDIC_STATE_OK : {
	    iState = WXPQDIC_STATE_SENDED;
	  } break;
	}
      } break;
      default : {					$? "! send"
        if (WXPQDIC_STATE_SEND_FAILED != iState) {
          tLimit->SetLabel(sTexts[27]);
	  tUsed->SetLabel(sTexts[27]);
	  tAccount->SetLabel(sTexts[27]);
	  tAllowed->SetLabel(sTexts[27]);
	  lStatus->SetLabel(sTexts[28]);
	  lStatus->SetForegroundColour(cRed);
	  back = true;
	}
        iState = WXPQDIC_STATE_SEND_FAILED;
      } break;
    }
  }
#if TRACE_DEBUG
  else {						$? ". no need to send"
  }
#endif
  $? "- SendRequest %d", ((back) ? (1) : (0))
  return back;
}



void
WxpqdicFrame::OnRun(wxCommandEvent & event)
{
  bool	mustUpdate	= false;
  $? "+ OnRun"
  {
    wxCriticalSectionLocker	lockCsProtect(csProtect);
    if (bIsInitialized) {
      mustUpdate = SendRequest(true);
    }
  }
  if (mustUpdate) {
    Refresh();
    Update();
  }
  $? "- OnRun"
}



bool
WxpqdicFrame::DataExchangeWithServer(void)
{
  bool		 back	=  false;
  $? "+ DataExchangeWithServer"
  if (RetrieveResponse()) {
    back = true;
  }
  if (SendRequest()) {
    back = true;
  }
  $? "- DataExchangeWithServer %d", ((back) ? (1) : (0))
  return back;
}