forked from comotion/cpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface_gui.c
2440 lines (2065 loc) · 75 KB
/
interface_gui.c
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
/* #############################################################################
* code for handling the GUI interface
* #############################################################################
* Copyright (C) 2005-2009 Harry Brueckner
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contact: Harry Brueckner <[email protected]>
* Muenchener Strasse 12a
* 85253 Kleinberghofen
* Germany
* #############################################################################
*/
/* #############################################################################
* includes
*/
#include "cpm.h"
#ifdef HAVE_LIBNCURSES
#include <ncurses.h>
#endif
#ifdef HAVE_LIBNCURSESW
#include <ncurses.h>
#endif
#ifdef HAVE_TERMIOS_H
#include <termios.h>
#endif
#include "configuration.h"
#include "general.h"
#include "interface_gui.h"
#include "interface_keys.h"
#include "interface_utf8.h"
#include "interface_xml.h"
#include "listhandler.h"
#include "memory.h"
#include "string.h"
#include "xml.h"
/* #############################################################################
* global interface variables
*/
struct sKeyEvent
{
CDKLABEL* infobox;
PROCESSFN preprocessfunction;
void* preprocessdata;
void* widget;
int widgettype;
int bindused;
int level;
int selectionid;
char** infodata;
char* selection;
};
typedef struct sKeyEvent KEYEVENT;
CDKSCREEN* cdkscreen;
WINDOW* curseswin;
WINDOW* statusline = NULL;
/* #############################################################################
* internal functions
*/
int checkForSecretKey(void);
void clearStatusline(void);
void commentFormat(char** infodata, char* comment);
void drawStatusline(int level);
int getInfodataLength(void);
char* getListtitle(int level);
int keyPreProcess(EObjectType cdktype, void* object, void* clientdata,
chtype key);
int guiDialogAddEncryptionKey(EObjectType cdktype, void* object,
void* clientdata, chtype key);
int guiDialogAddNode(EObjectType cdktype, void* object, void* clientdata,
chtype key);
int guiDialogDeleteEncryptionKey(EObjectType cdktype, void* object,
void* clientdata, chtype key);
int guiDialogDeleteNode(EObjectType cdktype, void* object, void* clientdata,
chtype key);
int guiDialogEditComment(EObjectType cdktype, void* object, void* clientdata,
chtype key);
int guiDialogEditEncryptionKey(EObjectType cdktype, void* object,
void* clientdata, chtype key);
int guiDialogEditNode(EObjectType cdktype, void* object, void* clientdata,
chtype key);
int guiDialogHandleKeys(EObjectType cdktype, void* object, void* clientdata,
chtype key);
int guiDialogHelp(EObjectType cdktype, void* object, void* clientdata,
chtype key);
void guiDialogOk(int level, char** message);
const char* guiDialogPassphrase(int retry, char* realm);
void guiDialogShowError(const char* headline, const char* message);
int guiDialogTemplateName(EObjectType cdktype, void* object, void* clientdata,
chtype key);
int guiDialogWrite(EObjectType cdktype, void* object, void* clientdata,
chtype key);
int guiDialogYesNo(int level, char** message);
int guiDialogYesNoCancel(int level, char** message);
char** guiMessageFormat(char** message);
void guiMessageClear(char** message);
void guiUpdateInfo(CDKLABEL* infobox, char** infodata, int id);
void freshAlphalist(CDKALPHALIST* widget);
int initializeScreen(void);
char* isNodename(KEYEVENT* event);
void updateKeyList(KEYEVENT* event);
RETSIGTYPE resizehandler(int signum);
/* #############################################################################
*
* Description redraw scroll list after key add/remove
* Author Kacper Wysocki
* Date 2010-06-14
* Arguments KEYEVENT
* Return void
*/
void updateKeyList(KEYEVENT* event)
{
if (event->widget && event->widgettype == vSCROLL) {
int counter = keyCount();
CDKSCROLL* scroll = (CDKSCROLL*) event->widget;
setCDKScrollItems(scroll, keyGetList(), counter, NONUMBERS);
eraseCDKScroll(scroll);
drawCDKScroll(scroll, TRUE);
}
return;
}
/* #############################################################################
*
* Description check if we have any secret keys in our keylist
* Author Harry Brueckner
* Date 2005-04-25
* Arguments void
* Return int 1 if we have our secret key in use, otherwise 0
*/
int checkForSecretKey(void)
{
int i,
j,
secret = 0,
size;
char* key;
char* keyptr;
TRACE(99, "checkForSecretKey()", NULL);
for (i = keyCount() - 1; i >= 0; i--)
{
key = keyGet(i);
/* we create a copy of the key id string */
size = strlen(key) + 1;
/* extract the mail address listed in <...> at the end of the string */
keyptr = key + size;
for (j = size; j >= 0; j--, keyptr--)
{
if (keyptr[0] == '<')
{ break; }
}
switch (gpgIsSecretKey(keyptr))
{
case -1:
case 0:
break;
case 1:
secret = 1;
break;
}
/* if we found a secret key we exit */
if (secret)
{ break; }
}
return secret;
}
/* #############################################################################
*
* Description clear the statusline window
* Author Harry Brueckner
* Date 2005-08-04
* Arguments void
* Return void
*/
void clearStatusline(void)
{
TRACE(99, "clearStatusline()", NULL);
if (statusline)
{
werase(statusline);
wrefresh(statusline);
delwin(statusline);
statusline = NULL;
}
}
/* #############################################################################
*
* Description format the comment field into the infobox
* Author Harry Brueckner
* Date 2005-04-05
* Arguments char** infodata - data array to put the data in, starting
* at entry 2
* char* comment - the comment to format
* Return void
*/
void commentFormat(char** infodata, char* comment)
{
int id,
llength = getInfodataLength(),
nl,
size;
char* ptr;
char* wstart;
TRACE(99, "commentFormat()", NULL);
if (!comment)
{ return; }
id = 2;
nl = 0;
size = 0;
ptr = wstart = comment;
while (*ptr)
{
if (ptr[0] == '\\' && ptr[1] == 'n')
{ /* we replace those two chars with a newline */
nl = 1;
*ptr += 2;
}
if (*ptr == ' ' || nl)
{ /* we found a word border */
if ((strlen(infodata[id]) + size > llength &&
strlen(infodata[id]) > 1))
{ /* we need a new line, if there is any left */
if (++id >= config -> infoheight)
{ break; }
}
strStrncat(infodata[id], wstart, size + 1);
strStrncat(infodata[id], " ", 1 + 1);
if (nl)
{
nl = 0;
ptr++;
if (++id >= config -> infoheight)
{ break; }
}
wstart = ptr + 1;
size = -1;
}
ptr++;
size++;
}
if (*wstart &&
id < config -> infoheight &&
strlen(infodata[id]) < llength)
{ strStrncat(infodata[id], wstart, llength - strlen(infodata[id]) + 1); }
}
/* #############################################################################
*
* Description destroy the ncurses screen
* Author Harry Brueckner
* Date 2005-03-17
* Arguments int line - line number of the error
* char* message - message to display in case it's an error
* and we want to exit immediately
* Return 1 for error, 0 if all is well
*/
void destroyScreen(int line, char* message)
{
TRACE(99, "destroyScreen()", NULL);
/* clear and destroy the statusline */
clearStatusline();
/* clear the screen */
if (cdkscreen)
{ eraseCDKScreen(cdkscreen); }
/* free the curses and cdk environment */
if (curseswin)
{
delwin(curseswin);
curseswin = NULL;
}
if (cdkscreen)
{
destroyCDKScreen(cdkscreen);
endCDK();
cdkscreen = NULL;
}
if (message)
{
fprintf(stderr, _("t-error: %s (%d)\n"), message, line);
exit(1);
}
}
/* #############################################################################
*
* Description display a statusline; this is drawn without the use of CDK
* so we can access the last line in the terminal
* Author Harry Brueckner
* Date 2005-03-29
* Arguments int level - the level to draw the statusline for
* Return void
*/
void drawStatusline(int level)
{
int i,
max_x,
max_y;
TRACE(99, "drawStatusline()", NULL);
getmaxyx(curseswin, max_y, max_x);
if (!statusline)
{ statusline = newwin(1, max_x, max_y - 1, 0); }
wmove(statusline, 0, 0);
wattron(statusline, A_REVERSE);
for (i = 0; i < max_x; i++)
{ waddch(statusline, ' '); }
wmove(statusline, 0, 1);
wattron(statusline, A_BOLD | COLOR_PAIR(3));
waddstr(statusline, "^H");
wattroff(statusline, A_BOLD | COLOR_PAIR(3));
waddstr(statusline, _(" Help"));
waddstr(statusline, " | ");
if (!runtime -> readonly)
{
wattron(statusline, A_BOLD | COLOR_PAIR(3));
waddstr(statusline, "^A");
wattroff(statusline, A_BOLD | COLOR_PAIR(3));
waddstr(statusline, _(" Add"));
waddstr(statusline, " | ");
wattron(statusline, A_BOLD | COLOR_PAIR(3));
waddstr(statusline, "^E");
wattroff(statusline, A_BOLD | COLOR_PAIR(3));
waddstr(statusline, _(" Edit"));
waddstr(statusline, " | ");
wattron(statusline, A_BOLD | COLOR_PAIR(3));
waddstr(statusline, "^O");
wattroff(statusline, A_BOLD | COLOR_PAIR(3));
waddstr(statusline, _(" Comment"));
waddstr(statusline, " | ");
}
wattron(statusline, A_BOLD | COLOR_PAIR(3));
waddstr(statusline, "ENTER");
wattroff(statusline, A_BOLD | COLOR_PAIR(3));
waddstr(statusline, _(" Choose"));
waddstr(statusline, " | ");
wattron(statusline, A_BOLD | COLOR_PAIR(3));
waddstr(statusline, "ESC");
wattroff(statusline, A_BOLD | COLOR_PAIR(3));
if (level <= 1)
{ waddstr(statusline, _(" Exit")); }
else
{ waddstr(statusline, _(" Back")); }
wattroff(statusline, A_REVERSE);
wrefresh(statusline);
}
/* #############################################################################
*
* Description determine the width of the text for the infobox
* Author Harry Brueckner
* Date 2005-08-04
* Arguments void
* Return int with the width of the data for the infobox
*/
int getInfodataLength(void)
{
int max_x,
max_y;
TRACE(99, "getInfodataLength()", NULL);
getmaxyx(curseswin, max_y, max_x);
#ifdef CDK_VERSION_5
max_x -= 2;
#else
max_x -= 5;
#endif
if (max_x + 1 < STDBUFFERLENGTH)
return max_x;
else
return STDBUFFERLENGTH;
(void)max_y; // remove unused var warning
}
/* #############################################################################
*
* Description generate the title of the alphalist
* Author Harry Brueckner
* Date 2005-04-14
* Arguments int level - the level to display to
* Return char* containing the 2line title; it must be freed by the
* caller
*/
char* getListtitle(int level)
{
int defaultlevel,
hide,
i,
is_static;
char* subtitle;
char* templatename;
char* title;
TRACE(99, "getListtitle()", NULL);
title = memAlloc(__FILE__, __LINE__, 7 + 1);
strStrncpy(title, "</B/24>", 7 + 1);
subtitle = memAlloc(__FILE__, __LINE__, 7 + 1);
strStrncpy(subtitle, "</B/24>", 7 + 1);
for (i = 1; i <= level - 1; i++)
{ /* we collect the template tree */
templatename = xmlInterfaceTemplateGet(i, &is_static);
title = memRealloc(__FILE__, __LINE__, title,
strlen(title) + 1,
strlen(title) + strlen(templatename) + 1 + 1);
if (i == 1)
{ strStrncat(title, " ", 1 + 1); }
else
{ strStrncat(title, "/", 1 + 1); }
strStrncat(title, templatename, strlen(templatename) + 1);
}
defaultlevel = listCount(config -> defaulttemplates);
for (i = 1; i <= level - 1; i++)
{ /* we collect the data of the tree */
hide = 0;
if (i <= defaultlevel)
{
templatename = xmlInterfaceTemplateGet(i, &is_static);
if (!strcmp(templatename, config -> defaulttemplates[i - 1]))
{ /* this is still the default template name */
if (!strcmp(config -> defaulttemplatestatus[i - 1], "password"))
{ hide = 1; }
}
}
if (hide)
{ /* if it's a password level, we don't show it in the headline */
templatename = _("password");
}
else
{ templatename = xmlInterfaceNodeGet(i); }
subtitle = memRealloc(__FILE__, __LINE__, subtitle,
strlen(subtitle) + 1,
strlen(subtitle) + strlen(templatename) + 1 + 1);
if (i == 1)
{ strStrncat(subtitle, " ", 1 + 1); }
else
{ strStrncat(subtitle, "/", 1 + 1); }
strStrncat(subtitle, templatename, strlen(templatename) + 1);
}
title = memRealloc(__FILE__, __LINE__, title,
strlen(title) + 1,
strlen(title) + strlen(subtitle) + 1 + 1);
strStrncat(title, "\n", 1 + 1);
strStrncat(title, subtitle, strlen(subtitle) + 1);
memFreeString(__FILE__, __LINE__, subtitle);
return title;
}
/* #############################################################################
*
* Description update the infobox when any key is modified in the alphalist
* widget
* Author Harry Brueckner
* Date 2005-04-05
* Arguments EObjectType cdktype - type of object
* void* object - the object
* void* clientdata - special data to the bind function
* chtype key - pressed key
* Return 1 if the key was 'used', otherwise 0
*/
int keyPreProcess(EObjectType cdktype, void* object, void* clientdata,
chtype key)
{
CDKALPHALIST* list;
KEYEVENT* event = (KEYEVENT*)clientdata;
int id,
nodes;
char** nodenames;
TRACE(99, "keyPreProcess()", NULL);
list = event -> widget;
if (event -> preprocessfunction)
{ /* here we use our ugly hack to keep the preProcessFunction of the
* real alphalist widget. If we don't do this, we break the
* quicksearch feature of the alphalist.
*/
(event -> preprocessfunction)(vALPHALIST, list,
event -> preprocessdata, key);
}
nodenames = xmlInterfaceGetNames();
nodes = listCount(nodenames);
xmlInterfaceFreeNames(nodenames);
id = list -> scrollField -> currentItem;
if (nodes == 0 ||
id >= nodes)
{ return 1; }
if (key == KEY_DOWN)
{
if (++id >= nodes)
{ id--; }
}
else if (key == KEY_UP)
{
if (--id < 0)
{ id = 0; }
}
guiUpdateInfo(event -> infobox, event -> infodata, id);
return 1;
}
/* #############################################################################
*
* Description re-create the entry list for the given widget (which must be
* the 'current node' in the xml interface)
* Author Harry Brueckner
* Date 2005-03-29
* Arguments CDKALPHALIST* widget - the widget to update
* Return void
*/
void freshAlphalist(CDKALPHALIST* widget)
{
int nodes;
char** nodenames;
TRACE(99, "freshAlphalist()", NULL);
nodenames = xmlInterfaceGetNames();
nodes = listCount(nodenames);
setCDKAlphalistContents(widget, nodenames, nodes);
/* TODO: add support to place the cursor at last added/modified item */
#ifdef CDK_VERSION_5
setCDKScrollCurrentTop(widget -> scrollField, 0);
setCDKAlphalistCurrentItem(widget, 0);
drawCDKAlphalist(widget, BorderOf(widget));
#endif
xmlInterfaceFreeNames(nodenames);
}
/* #############################################################################
*
* Description dialog to request the passphrase
* Author Harry Brueckner
* Date 2005-03-31
* Arguments int retry - number of this retry
* const char* realm - name of the realm the passphrase is for
* Return const char* to the passphrase
*/
const char* guiDialogPassphrase(int retry, char* realm)
{
CDKENTRY* entry = NULL;
char* data;
char* trealm;
char* title;
TRACE(99, "guiDialogPassphrase()", NULL);
if (strlen(runtime -> passphrase))
{ return runtime -> passphrase; }
/* we make the realm terminal usable */
trealm = convert2terminal((xmlChar*)realm);
title = memAlloc(__FILE__, __LINE__, STDBUFFERLENGTH);
snprintf(title, STDBUFFERLENGTH,
_("</B>enter your passphrase (try #%d)<!B>\n%s"),
retry, trealm);
entry = newCDKEntry(cdkscreen, CENTER, CENTER,
title,
"",
A_NORMAL, '_',
vHMIXED, 60, 0, PASSPHRASE_LENGTH,
SHOW_BOX, SHOW_SHADOW);
if (!entry)
{ destroyScreen(__LINE__, _("can not create dialog.")); }
if (title)
memFree(__FILE__, __LINE__, title, STDBUFFERLENGTH);
/* set the data of the input field */
setCDKEntry(entry, "", 0, PASSPHRASE_LENGTH, SHOW_BOX);
setCDKEntryHiddenChar(entry, config -> hidecharacter);
data = activateCDKEntry(entry, (chtype*)NULL);
if (entry -> exitType == vNORMAL)
{ /* add a new entry to the current node */
strStrncpy(runtime -> passphrase, data, PASSPHRASE_LENGTH);
runtime -> passphrase[PASSPHRASE_LENGTH] = 0;
}
destroyCDKEntry(entry);
/* redraw the statusline */
if (statusline)
{ drawStatusline(0); }
return runtime -> passphrase;
}
/* #############################################################################
*
* Description dialog to add a new encryption key
* Author Harry Brueckner
* Date 2005-03-30
* Arguments EObjectType cdktype - type of object
* void* object - the object
* void* clientdata - special data to the bind function
* chtype key - pressed key
* Return 1 if the key was 'used', otherwise 0
*/
int guiDialogAddEncryptionKey(EObjectType cdktype, void* object,
void* clientdata, chtype key)
{
char* msgKeyError[] = { NULL, NULL };
CDKENTRY* entry = NULL;
KEYEVENT* event = (KEYEVENT*)clientdata;
char* data;
TRACE(99, "guiDialogAddEncryptionKey()", NULL);
/* we tell our caller, that an external event modified it's data */
event -> bindused = 1;
entry = newCDKEntry(cdkscreen, CENTER, CENTER,
_("</B>add a new encryption key<!B>"),
"",
A_NORMAL, '_',
vMIXED, 60, 0, STDSTRINGLENGTH,
SHOW_BOX, SHOW_SHADOW);
if (!entry)
{ destroyScreen(__LINE__, _("can not create dialog.")); }
/* set the data of the input field */
setCDKEntry(entry, event -> selection, 0, STDSTRINGLENGTH, SHOW_BOX);
data = activateCDKEntry(entry, (chtype*)NULL);
if (entry -> exitType == vNORMAL)
{ /* add a new entry to the current node */
if (keyAdd(data))
{ runtime -> datachanged = 1; }
else
{
msgKeyError[0] = _("The key you entered could not be validated.");
guiDialogOk(event -> level, msgKeyError);
}
}
destroyCDKEntry(entry);
#ifdef CDK_VERSION_5
/* tell the widget that it has to exit */
/* I am not sure if this is a bug in CDK or not, but it can be
* solved this way. */
EarlyExitOf((CDKSCROLL*)object) = vESCAPE_HIT;
#endif
/* redraw the statusline */
if (statusline)
{ drawStatusline(event -> level); }
/* redraw the calling widget */
updateKeyList(event);
return 1;
}
/* #############################################################################
*
* Description dialog to add a new entry to the current level
* Author Harry Brueckner
* Date 2005-03-23
* Arguments EObjectType cdktype - type of object
* void* object - the object
* void* clientdata - special data to the bind function
* chtype key - pressed key
* Return 1 if the key was 'used', otherwise 0
*/
int guiDialogAddNode(EObjectType cdktype, void* object, void* clientdata,
chtype key)
{
char* msgCryptMessage[] = { NULL, NULL, NULL };
CDKENTRY* entry = NULL;
KEYEVENT* event = (KEYEVENT*)clientdata;
int is_static;
char* data;
char* errormsg;
char* status = NULL;
char* title;
TRACE(99, "guiDialogAddNode()", NULL);
/* we tell our caller, that an external event modified it's data */
event -> bindused = 1;
if (runtime -> readonly)
{ /* if the file is readonly, we just beep */
Beep();
return 1;
}
title = memAlloc(__FILE__, __LINE__, STDBUFFERLENGTH);
snprintf(title, STDBUFFERLENGTH,
_("</B>add new %s<!B>"),
xmlInterfaceTemplateGet(event -> level, &is_static));
if (event -> level &&
listCount(config -> defaulttemplatestatus) >= event -> level)
{ /* we create the title with the template name if possible */
status = config -> defaulttemplatestatus[event -> level - 1];
}
entry = newCDKEntry(cdkscreen, CENTER, CENTER,
title,
"",
A_NORMAL, '_',
vMIXED, 60, 0, STDSTRINGLENGTH,
SHOW_BOX, SHOW_SHADOW);
if (!entry)
{ destroyScreen(__LINE__, _("can not create dialog.")); }
memFree(__FILE__, __LINE__, title, STDBUFFERLENGTH);
/* set the data of the input field */
setCDKEntry(entry, NULL, 0, STDSTRINGLENGTH, SHOW_BOX);
data = activateCDKEntry(entry, (chtype*)NULL);
if (entry -> exitType == vNORMAL)
{ /* add a new entry to the current node */
if (strlen(data))
{
if (config -> cracklibstatus == CRACKLIB_ON &&
status &&
!strcmp(status, "password"))
{ /* we must check the password */
errormsg = isGoodPassword(data);
if (errormsg)
{ /* cracklib complains about the password */
msgCryptMessage[0] =
_("The password you have chosen is unsuitable.");
msgCryptMessage[1] = errormsg;
guiDialogOk(event -> level, msgCryptMessage);
}
}
if (xmlInterfaceNodeExists(data))
{ Beep(); }
else
{
xmlInterfaceAddNode(data);
runtime -> datachanged = 1;
}
/* fresh the widget to add the entry */
freshAlphalist(event -> widget);
}
}
destroyCDKEntry(entry);
/* redraw the statusline */
if (statusline)
{ drawStatusline(event -> level); }
return 1;
}
/* #############################################################################
*
* Description dialog to delete the current encryption key
* Author Harry Brueckner
* Date 2005-03-30
* Arguments EObjectType cdktype - type of object
* void* object - the object
* void* clientdata - special data to the bind function
* chtype key - pressed key
* Return 1 if the key was 'used', otherwise 0
*/
int guiDialogDeleteEncryptionKey(EObjectType cdktype, void* object,
void* clientdata, chtype key)
{
char* msgDeleteNode[] = { NULL, NULL, NULL };
CDKSCROLL* scroll;
KEYEVENT* event = (KEYEVENT*)clientdata;
int counter,
length;
TRACE(99, "guiDialogDeleteEncryptionKey()", NULL);
/* we tell our caller, that an external event modified it's data */
event -> bindused = 1;
scroll = event -> widget;
counter = scroll -> currentItem;
if (counter < 0 ||
counter >= keyCount())
{
Beep();
return 1;
}
/* we ask if this key should be deleted */
length = strlen(keyGet(counter)) + 9 + 1;
msgDeleteNode[0] = _("Are you sure you want to delete the encryption key");
msgDeleteNode[1] = memAlloc(__FILE__, __LINE__, length);
snprintf(msgDeleteNode[1], length, "%s?", keyGet(counter));
if (guiDialogYesNo(event -> level, msgDeleteNode) == 1)
{ /* we really want to delete this key */
keyDelete(counter);
runtime -> datachanged = 1;
}
memFree(__FILE__, __LINE__, msgDeleteNode[1], length);
#ifdef CDK_VERSION_5
/* tell the widget that it has to exit */
/* I am not sure if this is a bug in CDK or not, but it can be
* solved this way. */
EarlyExitOf((CDKSCROLL*)object) = vESCAPE_HIT;
#endif
updateKeyList(event);
return 1;
}
/* #############################################################################
*
* Description dialog to delete the current node
* Author Harry Brueckner
* Date 2005-03-29
* Arguments EObjectType cdktype - type of object
* void* object - the object
* void* clientdata - special data to the bind function
* chtype key - pressed key
* Return 1 if the key was 'used', otherwise 0
*/
int guiDialogDeleteNode(EObjectType cdktype, void* object, void* clientdata,
chtype key)
{
char* msgDeleteNode[] = { NULL, NULL, NULL };
KEYEVENT* event = (KEYEVENT*)clientdata;
int length;
char* label;
TRACE(99, "guiDialogDeleteNode()", NULL);
/* we tell our caller, that an external event modified it's data */
event -> bindused = 1;
if (runtime -> readonly)
{ /* if the file is readonly, we just beep */
Beep();
return 1;
}
label = isNodename(event);
if (!label)
{
Beep();
return 1;
}
length = strlen(label) + 15 + 1;
msgDeleteNode[0] = _("Are you sure you want to delete");
msgDeleteNode[1] = memAlloc(__FILE__, __LINE__, length);
snprintf(msgDeleteNode[1], length, _("entry %s?"), label);
if (guiDialogYesNo(event -> level, msgDeleteNode) == 1)
{ /* we really want to delete this node */
xmlInterfaceDeleteNode(label);
runtime -> datachanged = 1;
/* fresh the widget to remove the entry */
freshAlphalist(event -> widget);
}
memFree(__FILE__, __LINE__, msgDeleteNode[1], length);
return 1;
}
/* #############################################################################
*
* Description dialog to edit the current node's comment
* Author Harry Brueckner
* Date 2005-04-05
* Arguments EObjectType cdktype - type of object
* void* object - the object
* void* clientdata - special data to the bind function
* chtype key - pressed key
* Return 1 if the key was 'used', otherwise 0
*/
int guiDialogEditComment(EObjectType cdktype, void* object, void* clientdata,
chtype key)
{
CDKMENTRY* mentry;
KEYEVENT* event = (KEYEVENT*)clientdata;
int id;
char** nodenames;
char* comment;
char* label;
TRACE(99, "guiDialogEditComment()", NULL);
/* we tell our caller, that an external event modified it's data */
event -> bindused = 1;
if (runtime -> readonly)
{ /* if the file is readonly, we just beep */
Beep();
return 1;
}
label = isNodename(event);
if (!label)
{
Beep();
return 1;
}
/* get the current comment */
comment = xmlInterfaceGetComment(label);
mentry = newCDKMentry(cdkscreen, CENTER, CENTER,