- converted 1st stage setup stub from message box style to property sheet style
[reactos.git] / rosapps / applications / mc / src / boxes.c
1 /* Some misc dialog boxes for the program.
2
3 Copyright (C) 1994, 1995 the Free Software Foundation
4
5 Authors: 1994, 1995 Miguel de Icaza
6 1995 Jakub Jelinek
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21
22 #include <config.h>
23 #include "tty.h"
24 #include <string.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <sys/param.h>
30 #include <malloc.h>
31 #include <signal.h>
32 #include <ctype.h>
33 #include "global.h"
34 #include "mad.h" /* The great mad */
35 #include "util.h" /* Required by panel.h */
36 #include "win.h" /* Our window tools */
37 #include "color.h" /* Color definitions */
38 #include "dlg.h" /* The nice dialog manager */
39 #include "widget.h" /* The widgets for the nice dialog manager */
40 #include "dialog.h" /* For do_refresh() */
41 #include "wtools.h"
42 #include "setup.h" /* For profile_name */
43 #include "profile.h" /* Load/save user formats */
44 #include "key.h" /* XCTRL and ALT macros */
45 #include "command.h" /* For cmdline */
46 #include "dir.h"
47 #include "panel.h"
48 #include "boxes.h"
49 #include "main.h" /* For the confirm_* variables */
50 #include "tree.h"
51 #include "layout.h" /* for get_nth_panel_name proto */
52 #include "background.h" /* for background definitions */
53 #include "x.h"
54
55 static int DISPLAY_X = 45, DISPLAY_Y = 14;
56
57 static Dlg_head *dd;
58 static WRadio *my_radio;
59 static WInput *user;
60 static WInput *status;
61 static WCheck *check_status;
62 static int current_mode;
63 extern int ftpfs_always_use_proxy;
64
65 static char **displays_status;
66 static char* display_title = N_(" Listing mode ");
67
68 /* Controls whether the array strings have been translated */
69 static int i18n_displays_flag;
70 static char *displays [LIST_TYPES] = {
71 N_("&Full file list"),
72 N_("&Brief file list"),
73 N_("&Long file list"),
74 N_("&User defined:"),
75 N_("&Icon view"),
76 };
77
78 static int user_hotkey = 'u';
79
80 static int display_callback (struct Dlg_head *h, int id, int Msg)
81 {
82 #ifndef HAVE_X
83 char *text;
84 WInput *input;
85
86 switch (Msg){
87 case DLG_DRAW:
88 attrset (COLOR_NORMAL);
89 dlg_erase (h);
90 draw_box (h, 1, 2, h->lines - 2, h->cols - 4);
91
92 attrset (COLOR_HOT_NORMAL);
93 dlg_move (h, 1, (h->cols - strlen(display_title))/2);
94 addstr (display_title);
95 attrset (COLOR_NORMAL);
96 break;
97
98 case DLG_UNFOCUS:
99 if((WRadio *) h->current->widget == my_radio){
100 assign_text (status, displays_status [my_radio->sel]);
101 input_set_point (status, 0);
102 }
103 break;
104
105 case DLG_KEY:
106 if (id == '\n'){
107 if((WRadio *) h->current->widget == my_radio){
108 assign_text (status, displays_status [my_radio->sel]);
109 dlg_stop (h);
110 break;
111 }
112
113 if ((WInput *) h->current->widget == user){
114 h->ret_value = B_USER + 6;
115 dlg_stop (h);
116 break;
117 }
118
119 if ((WInput *) h->current->widget == status){
120 h->ret_value = B_USER + 7;
121 dlg_stop (h);
122 break;
123 }
124 }
125
126 if (tolower(id) == user_hotkey && h->current->widget != (Widget *) user
127 && h->current->widget != (Widget *) status){
128 my_radio->sel = 3;
129 dlg_select_widget (h, my_radio); /* force redraw */
130 dlg_select_widget (h, user);
131 return MSG_HANDLED;
132 }
133 }
134 #endif
135 return MSG_NOT_HANDLED;
136 }
137
138 static void display_init (int radio_sel, char *init_text,
139 int _check_status, char ** _status)
140 {
141 char* user_mini_status = _("user &Mini status");
142 char* ok_button = _("&Ok");
143 char* cancel_button = _("&Cancel");
144
145 static int button_start = 30;
146
147 displays_status = _status;
148
149 if (!i18n_displays_flag){
150 int i, l, maxlen = 0;
151 char* cp;
152
153 display_title = _(display_title);
154 for (i = 0; i < LIST_TYPES; i++)
155 {
156 displays [i] = _(displays [i]);
157 if ((l = strlen(displays [i])) > maxlen)
158 maxlen = l;
159 }
160
161 i = strlen (ok_button) + 5;
162 l = strlen (cancel_button) + 3;
163 l = max(i, l);
164
165 i = maxlen + l + 16;
166 if (i > DISPLAY_X)
167 DISPLAY_X = i;
168
169 i = strlen (user_mini_status) + 13;
170 if (i > DISPLAY_X)
171 DISPLAY_X = i;
172
173 i = strlen (display_title) + 8;
174 if (i > DISPLAY_X)
175 DISPLAY_X = i;
176
177 button_start = DISPLAY_X - l - 5;
178
179 /* get hotkey of user-defined format string */
180 cp = strchr(displays[LIST_TYPES-1],'&');
181 if (cp != NULL && *++cp != '\0')
182 user_hotkey = tolower(*cp);
183
184 i18n_displays_flag = 1;
185 }
186 dd = create_dlg (0, 0, DISPLAY_Y, DISPLAY_X, dialog_colors,
187 display_callback, "[Left and Right Menus]", "display",
188 DLG_CENTER | DLG_GRID);
189
190 x_set_dialog_title (dd, _("Listing mode"));
191 add_widgetl (dd,
192 button_new (4, button_start, B_CANCEL,
193 NORMAL_BUTTON, cancel_button, 0, 0, "cancel-button"),
194 XV_WLAY_RIGHTOF);
195
196 add_widgetl (dd,
197 button_new (3, button_start, B_ENTER,
198 DEFPUSH_BUTTON, ok_button, 0, 0, "ok-button"),
199 XV_WLAY_CENTERROW);
200
201 status = input_new (10, 9, INPUT_COLOR, DISPLAY_X-14, _status [radio_sel], "mini-input");
202 add_widgetl (dd, status, XV_WLAY_RIGHTDOWN);
203 input_set_point (status, 0);
204
205 check_status = check_new (9, 5, _check_status, user_mini_status, "mini-status");
206 add_widgetl (dd, check_status, XV_WLAY_NEXTROW);
207
208 user = input_new (7, 9, INPUT_COLOR, DISPLAY_X-14, init_text, "user-fmt-input");
209 add_widgetl (dd, user, XV_WLAY_RIGHTDOWN);
210 input_set_point (user, 0);
211
212 #ifdef PORT_HAS_ICON_VIEW
213 my_radio = radio_new (3, 5, LIST_TYPES, displays, 1, "radio");
214 #else
215 my_radio = radio_new (3, 5, LIST_TYPES-1, displays, 1, "radio");
216 #endif
217 my_radio->sel = my_radio->pos = current_mode;
218 add_widgetl (dd, my_radio, XV_WLAY_BELOWCLOSE);
219 }
220
221 int display_box (WPanel *panel, char **userp, char **minip, int *use_msformat,
222 int num)
223 {
224 int result, i;
225 char *section = NULL;
226 char *p;
227
228 if (!panel) {
229 p = get_nth_panel_name (num);
230 panel = (WPanel *) xmalloc (sizeof (WPanel), "temporary panel");
231 panel->list_type = list_full;
232 panel->user_format = strdup (DEFAULT_USER_FORMAT);
233 panel->user_mini_status = 0;
234 for (i = 0; i < LIST_TYPES; i++)
235 panel->user_status_format[i] = strdup (DEFAULT_USER_FORMAT);
236 section = copy_strings ("Temporal:", p, 0);
237 if (!profile_has_section (section, profile_name)) {
238 free (section);
239 section = strdup (p);
240 }
241 panel_load_setup (panel, section);
242 free (section);
243 }
244
245 current_mode = panel->list_type;
246 display_init (current_mode, panel->user_format,
247 panel->user_mini_status, panel->user_status_format);
248
249 run_dlg (dd);
250
251 result = -1;
252
253 if (section) {
254 free (panel->user_format);
255 for (i = 0; i < LIST_TYPES; i++)
256 free (panel->user_status_format [i]);
257 free (panel);
258 }
259
260 if (dd->ret_value != B_CANCEL){
261 result = my_radio->sel;
262 *userp = strdup (user->buffer);
263 *minip = strdup (status->buffer);
264 *use_msformat = check_status->state & C_BOOL;
265 }
266 destroy_dlg (dd);
267
268 return result;
269 }
270
271 int SORT_X = 40, SORT_Y = 14;
272
273 char *sort_orders_names [SORT_TYPES];
274
275 sortfn *sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive)
276 {
277 int i, r, l;
278 sortfn *result;
279 WCheck *c, *case_sense;
280
281 char* ok_button = _("&Ok");
282 char* cancel_button = _("&Cancel");
283 char* reverse_label = _("&Reverse");
284 char* case_label = _("case sensi&tive");
285 char* sort_title = _("Sort order");
286
287 static int i18n_sort_flag = 0, check_pos = 0, button_pos = 0;
288
289 if (!i18n_sort_flag)
290 {
291 int maxlen = 0;
292 for (i = SORT_TYPES-1; i >= 0; i--)
293 {
294 sort_orders_names [i] = _(sort_orders [i].sort_name);
295 r = strlen (sort_orders_names [i]);
296 if (r > maxlen)
297 maxlen = r;
298 }
299
300 check_pos = maxlen + 9;
301
302 r = strlen (reverse_label) + 4;
303 i = strlen (case_label) + 4;
304 if (i > r)
305 r = i;
306
307 l = strlen (ok_button) + 6;
308 i = strlen (cancel_button) + 4;
309 if (i > l)
310 l = i;
311
312 i = check_pos + max(r,l) + 2;
313
314 if (i > SORT_X)
315 SORT_X = i;
316
317 i = strlen (sort_title) + 6;
318 if (i > SORT_X)
319 SORT_X = i;
320
321 button_pos = SORT_X - l - 2;
322
323 i18n_sort_flag = 1;
324 }
325
326 result = 0;
327
328 for (i = 0; i < SORT_TYPES; i++)
329 if ((sortfn *) (sort_orders [i].sort_fn) == sort_fn){
330 current_mode = i;
331 break;
332 }
333
334 dd = create_dlg (0, 0, SORT_Y, SORT_X, dialog_colors, common_dialog_callback,
335 "[Left and Right Menus]", "sort", DLG_CENTER | DLG_GRID);
336
337 x_set_dialog_title (dd, sort_title);
338
339 add_widgetl (dd,
340 button_new (10, button_pos, B_CANCEL, NORMAL_BUTTON, cancel_button,
341 0, 0, "cancel-button"), XV_WLAY_CENTERROW);
342
343 add_widgetl (dd,
344 button_new (9, button_pos, B_ENTER, DEFPUSH_BUTTON, ok_button,
345 0, 0, "ok-button"), XV_WLAY_RIGHTDOWN);
346
347 case_sense = check_new (4, check_pos, *case_sensitive, case_label, "case-check");
348 add_widgetl (dd, case_sense, XV_WLAY_RIGHTDOWN);
349 c = check_new (3, check_pos, *reverse, reverse_label, "reverse-check");
350 add_widgetl (dd, c, XV_WLAY_RIGHTDOWN);
351
352 my_radio = radio_new (3, 3, SORT_TYPES, sort_orders_names, 1, "radio-1");
353 my_radio->sel = my_radio->pos = current_mode;
354
355 add_widget (dd, my_radio);
356 run_dlg (dd);
357
358 r = dd->ret_value;
359 if (r != B_CANCEL){
360 result = (sortfn *) sort_orders [my_radio->sel].sort_fn;
361 *reverse = c->state & C_BOOL;
362 *case_sensitive = case_sense->state & C_BOOL;
363 } else
364 result = sort_fn;
365 destroy_dlg (dd);
366
367 return result;
368 }
369
370 #define CONFY 10
371 #define CONFX 46
372
373 static int my_delete;
374 static int my_overwrite;
375 static int my_execute;
376 static int my_exit;
377
378 static QuickWidget conf_widgets [] = {
379 { quick_button, 4, 6, 4, CONFY, N_("&Cancel"),
380 0, B_CANCEL, 0, 0, XV_WLAY_RIGHTOF, "c" },
381 { quick_button, 4, 6, 3, CONFY, N_("&Ok"),
382 0, B_ENTER, 0, 0, XV_WLAY_CENTERROW, "o" },
383
384 { quick_checkbox, 1, 13, 6, CONFY, N_(" confirm &Exit "),
385 9, 0, &my_exit, 0, XV_WLAY_BELOWCLOSE, "e" },
386 { quick_checkbox, 1, 13, 5, CONFY, N_(" confirm e&Xecute "),
387 10, 0, &my_execute, 0, XV_WLAY_BELOWCLOSE, "x" },
388 { quick_checkbox, 1, 13, 4, CONFY, N_(" confirm o&Verwrite "),
389 10, 0, &my_overwrite, 0, XV_WLAY_BELOWCLOSE, "ov" },
390 { quick_checkbox, 1, 13, 3, CONFY, N_(" confirm &Delete "),
391 9, 0, &my_delete, 0, XV_WLAY_BELOWCLOSE, "de" },
392 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, XV_WLAY_DONTCARE }
393 };
394
395 static QuickDialog confirmation =
396 { CONFX, CONFY, -1, -1, N_(" Confirmation "), "[Confirmation]", "quick_confirm",
397 conf_widgets, 0 };
398
399 void confirm_box ()
400 {
401
402 #ifdef ENABLE_NLS
403 static int i18n_flag = 0;
404
405 if (!i18n_flag)
406 {
407 register int i = sizeof(conf_widgets)/sizeof(QuickWidget) - 1;
408 int l1, maxlen = 0;
409 while (i--)
410 {
411 conf_widgets [i].text = _(conf_widgets [i].text);
412 l1 = strlen (conf_widgets [i].text) + 3;
413 if (l1 > maxlen)
414 maxlen = l1;
415 }
416
417 /*
418 * If buttons start on 4/6, checkboxes (with some add'l space)
419 * must take not more than it.
420 */
421 confirmation.xlen = (maxlen + 5) * 6 / 4;
422
423 /*
424 * And this for the case when buttons with some space to the right
425 * do not fit within 2/6
426 */
427 l1 = strlen (conf_widgets [0].text) + 3;
428 i = strlen (conf_widgets [1].text) + 5;
429 if (i > l1)
430 l1 = i;
431
432 i = (l1 + 3) * 6 / 2;
433 if (i > confirmation.xlen)
434 confirmation.xlen = i;
435
436 confirmation.title = _(confirmation.title);
437
438 i18n_flag = confirmation.i18n = 1;
439 }
440
441 #endif /* ENABLE_NLS */
442
443 my_delete = confirm_delete;
444 my_overwrite = confirm_overwrite;
445 my_execute = confirm_execute;
446 my_exit = confirm_exit;
447
448 if (quick_dialog (&confirmation) != B_CANCEL){
449 confirm_delete = my_delete;
450 confirm_overwrite = my_overwrite;
451 confirm_execute = my_execute;
452 confirm_exit = my_exit;
453 }
454 }
455
456 #define DISPY 11
457 #define DISPX 46
458
459 static int new_mode;
460 static int new_meta;
461
462 char *display_bits_str [] =
463 { N_("Full 8 bits output"), N_("ISO 8859-1"), N_("7 bits") };
464
465 static QuickWidget display_widgets [] = {
466 { quick_button, 4, 6, 4, DISPY, N_("&Cancel"),
467 0, B_CANCEL, 0, 0, XV_WLAY_CENTERROW, "c" },
468 { quick_button, 4, 6, 3, DISPY, N_("&Ok"),
469 0, B_ENTER, 0, 0, XV_WLAY_CENTERROW, "o" },
470 { quick_checkbox, 4, DISPX, 7, DISPY, N_("F&ull 8 bits input"),
471 0, 0, &new_meta, 0, XV_WLAY_BELOWCLOSE, "u" },
472 { quick_radio, 4, DISPX, 3, DISPY, "", 3, 0,
473 &new_mode, display_bits_str, XV_WLAY_BELOWCLOSE, "r" },
474 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, XV_WLAY_DONTCARE }
475 };
476
477 static QuickDialog display_bits =
478 { DISPX, DISPY, -1, -1, N_(" Display bits "), "[Display bits]",
479 "dbits", display_widgets, 0 };
480
481 void display_bits_box ()
482 {
483 int current_mode;
484
485 #ifdef ENABLE_NLS
486 static int i18n_flag = 0;
487 if (!i18n_flag)
488 {
489 register int i;
490 int l1, maxlen = 0;
491 for (i = 0; i < 3; i++)
492 {
493 display_widgets [i].text = _(display_widgets[i].text);
494 display_bits_str [i] = _(display_bits_str [i]);
495 l1 = strlen (display_bits_str [i]);
496 if (l1 > maxlen)
497 maxlen = l1;
498 }
499 l1 = strlen (display_widgets [2].text);
500 if (l1 > maxlen)
501 maxlen = l1;
502
503
504 display_bits.xlen = (maxlen + 5) * 6 / 4;
505
506 /* See above confirm_box */
507 l1 = strlen (display_widgets [0].text) + 3;
508 i = strlen (display_widgets [1].text) + 5;
509 if (i > l1)
510 l1 = i;
511
512 i = (l1 + 3) * 6 / 2;
513 if (i > display_bits.xlen)
514 display_bits.xlen = i;
515
516 display_bits.title = _(display_bits.title);
517 i18n_flag = display_bits.i18n = 1;
518 }
519
520 #endif /* ENABLE_NLS */
521
522 if (full_eight_bits)
523 current_mode = 0;
524 else if (eight_bit_clean)
525 current_mode = 1;
526 else
527 current_mode = 2;
528
529 display_widgets [3].value = current_mode;
530 new_meta = !use_8th_bit_as_meta;
531 if (quick_dialog (&display_bits) != B_ENTER)
532 return;
533
534 eight_bit_clean = new_mode < 2;
535 full_eight_bits = new_mode == 0;
536 #ifndef HAVE_SLANG
537 meta (stdscr, eight_bit_clean);
538 #else
539 SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
540 #endif
541 use_8th_bit_as_meta = !new_meta;
542 }
543
544 #define TREE_Y 20
545 #define TREE_X 60
546
547 static int tree_colors [4];
548
549 static int tree_callback (struct Dlg_head *h, int id, int msg)
550 {
551 switch (msg){
552
553 case DLG_POST_KEY:
554 /* The enter key will be processed by the tree widget */
555 if (id == '\n' || ((WTree *)(h->current->widget))->done){
556 h->ret_value = B_ENTER;
557 dlg_stop (h);
558 }
559 return MSG_HANDLED;
560
561 case DLG_DRAW:
562 common_dialog_repaint (h);
563 break;
564 }
565 return MSG_NOT_HANDLED;
566 }
567
568 char *tree (char *current_dir)
569 {
570 WTree *mytree;
571 Dlg_head *dlg;
572 char *val;
573 WButtonBar *bar;
574
575 tree_colors [3] = dialog_colors [0];
576 tree_colors [1] = dialog_colors [1];
577
578 /* Create the components */
579 dlg = create_dlg (0, 0, TREE_Y, TREE_X, tree_colors,
580 tree_callback, "[Directory Tree]", "tree", DLG_CENTER);
581 mytree = tree_new (0, 2, 2, TREE_Y - 6, TREE_X - 5);
582 add_widget (dlg, mytree);
583 bar = buttonbar_new(1);
584 add_widget (dlg, bar);
585 bar->widget.x = 0;
586 bar->widget.y = LINES - 1;
587
588 run_dlg (dlg);
589 if (dlg->ret_value == B_ENTER)
590 val = strdup (mytree->selected_ptr->name);
591 else
592 val = 0;
593
594 destroy_dlg (dlg);
595 return val;
596 }
597 #ifndef USE_VFS
598 #ifdef USE_NETCODE
599 #undef USE_NETCODE
600 #endif
601 #endif
602
603 #ifdef USE_VFS
604
605 #if defined(USE_NETCODE)
606 #define VFSY 15
607 #else
608 #define VFSY 11
609 #endif
610
611 #define VFSX 56
612
613 extern int vfs_timeout;
614 extern int tar_gzipped_memlimit;
615 extern int ftpfs_always_use_proxy;
616
617 #if defined(USE_NETCODE)
618 extern char *ftpfs_anonymous_passwd;
619 extern char *ftpfs_proxy_host;
620 extern ftpfs_directory_timeout;
621 extern int use_netrc;
622 #endif
623
624 int vfs_use_limit = 1;
625 static char *ret_timeout;
626 static char *ret_limit;
627
628 #if defined(USE_NETCODE)
629 static char *ret_passwd;
630 static char *ret_directory_timeout;
631 static char *ret_ftp_proxy;
632 static int ret_use_netrc;
633 #endif
634
635 #if 0
636 /* Not used currently */
637 { quick_checkbox, 4, VFSX, 10, VFSY, "Use ~/.netrc",
638 'U', 0, 0, &ret_use_netrc, 0, XV_WLAY_BELOWCLOSE, "" },
639 #endif
640
641 char *confvfs_str [] =
642 { N_("Always to memory"), N_("If size less than:") };
643
644 static QuickWidget confvfs_widgets [] = {
645 { quick_button, 30, VFSX, VFSY - 3, VFSY, N_("&Cancel"),
646 0, B_CANCEL, 0, 0, XV_WLAY_RIGHTOF, "button-cancel" },
647 { quick_button, 12, VFSX, VFSY - 3, VFSY, N_("&Ok"),
648 0, B_ENTER, 0, 0, XV_WLAY_CENTERROW, "button-ok" },
649 #if defined(USE_NETCODE)
650 { quick_input, 30, VFSX, 10, VFSY, "", 22, 0, 0, &ret_ftp_proxy,
651 XV_WLAY_RIGHTDOWN, "input-ftp-proxy" },
652 { quick_checkbox, 4, VFSX, 10, VFSY, N_("&Always use ftp proxy"), 0, 0,
653 &ftpfs_always_use_proxy, 0, XV_WLAY_RIGHTDOWN, "check-ftp-proxy" },
654 { quick_label, 46, VFSX, 9, VFSY, N_("sec"),
655 0, 0, 0, 0, XV_WLAY_RIGHTOF, "label-sec" },
656 { quick_input, 35, VFSX, 9, VFSY, "", 10, 0, 0, &ret_directory_timeout,
657 XV_WLAY_RIGHTDOWN, "input-timeout" },
658 { quick_label, 4, VFSX, 9, VFSY, N_("ftpfs directory cache timeout:"),
659 0, 0, 0, 0, XV_WLAY_NEXTROW, "label-cache"},
660 { quick_input, 28, VFSX, 8, VFSY, "", 24, 0, 0, &ret_passwd,
661 XV_WLAY_RIGHTDOWN, "input-passwd" },
662 { quick_label, 4, VFSX, 8, VFSY, N_("ftp anonymous password:"),
663 0, 0, 0, 0, XV_WLAY_NEXTROW, "label-pass"},
664 #endif
665 { quick_input, 26, VFSX, 6, VFSY, "", 10, 0, 0, &ret_limit,
666 XV_WLAY_RIGHTDOWN, "input-limit" },
667 { quick_radio, 4, VFSX, 5, VFSY, "", 2, 0,
668 &vfs_use_limit, confvfs_str, XV_WLAY_BELOWCLOSE, "radio" },
669 { quick_label, 4, VFSX, 4, VFSY, N_("Gzipped tar archive extract:"),
670 0, 0, 0, 0, XV_WLAY_NEXTROW, "label-tar" },
671 { quick_label, 46, VFSX, 3, VFSY, "sec",
672 0, 0, 0, 0, XV_WLAY_RIGHTOF, "label-sec2" },
673 { quick_input, 35, VFSX, 3, VFSY, "", 10, 0, 0, &ret_timeout,
674 XV_WLAY_RIGHTOF, "input-timo-vfs" },
675 { quick_label, 4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:"),
676 0, 0, 0, 0, XV_WLAY_BELOWCLOSE, "label-vfs" },
677 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, XV_WLAY_DONTCARE, 0 }
678 };
679
680 static QuickDialog confvfs_dlg =
681 { VFSX, VFSY, -1, -1, N_(" Virtual File System Setting "), "[Virtual FS]", "quick_vfs", confvfs_widgets, 0 };
682
683 #if defined(USE_NETCODE)
684 #define VFS_WIDGETBASE 7
685 #else
686 #define VFS_WIDGETBASE 0
687 #endif
688
689 void configure_vfs ()
690 {
691 char buffer1 [15], buffer2 [15];
692 #if defined(USE_NETCODE)
693 char buffer3[15];
694 #endif
695
696 if (tar_gzipped_memlimit > -1) {
697 if (tar_gzipped_memlimit == 0)
698 strcpy (buffer1, "0 B");
699 else if ((tar_gzipped_memlimit % (1024*1024)) == 0) /* I.e. in M */
700 sprintf (buffer1, "%i MB", (int)(((unsigned)tar_gzipped_memlimit) >> 20));
701 else if ((tar_gzipped_memlimit % 1024) == 0) /* I.e. in K */
702 sprintf (buffer1, "%i KB", (int)(((unsigned)tar_gzipped_memlimit) >> 10));
703 else if ((tar_gzipped_memlimit % 1000) == 0)
704 sprintf (buffer1, "%i kB", (int)(tar_gzipped_memlimit / 1000));
705 else
706 sprintf (buffer1, "%i B", (int)tar_gzipped_memlimit);
707 confvfs_widgets [2 + VFS_WIDGETBASE].text = buffer1;
708 } else
709 confvfs_widgets [2 + VFS_WIDGETBASE].text = "5 MB";
710 sprintf (buffer2, "%i", vfs_timeout);
711 confvfs_widgets [6 + VFS_WIDGETBASE].text = buffer2;
712 confvfs_widgets [3 + VFS_WIDGETBASE].value = vfs_use_limit;
713 #if defined(USE_NETCODE)
714 ret_use_netrc = use_netrc;
715 sprintf(buffer3, "%i", ftpfs_directory_timeout);
716 confvfs_widgets[5].text = buffer3;
717 confvfs_widgets[7].text = ftpfs_anonymous_passwd;
718 confvfs_widgets[2].text = ftpfs_proxy_host ? ftpfs_proxy_host : "";
719 #endif
720
721 if (quick_dialog (&confvfs_dlg) != B_CANCEL) {
722 char *p;
723
724 vfs_timeout = atoi (ret_timeout);
725 free (ret_timeout);
726 if (vfs_timeout < 0 || vfs_timeout > 10000)
727 vfs_timeout = 10;
728 if (!vfs_use_limit)
729 tar_gzipped_memlimit = -1;
730 else {
731 tar_gzipped_memlimit = atoi (ret_limit);
732 if (tar_gzipped_memlimit < 0)
733 tar_gzipped_memlimit = -1;
734 else {
735 for (p = ret_limit; *p == ' ' || (*p >= '0' && *p <= '9'); p++);
736 switch (*p) {
737 case 'm':
738 case 'M': tar_gzipped_memlimit <<= 20; break;
739 case 'K': tar_gzipped_memlimit <<= 10; break;
740 case 'k': tar_gzipped_memlimit *= 1000; break;
741 }
742 }
743 }
744 free (ret_limit);
745 #if defined(USE_NETCODE)
746 free(ftpfs_anonymous_passwd);
747 ftpfs_anonymous_passwd = ret_passwd;
748 if (ftpfs_proxy_host)
749 free(ftpfs_proxy_host);
750 ftpfs_proxy_host = ret_ftp_proxy;
751 ftpfs_directory_timeout = atoi(ret_directory_timeout);
752 use_netrc = ret_use_netrc;
753 free(ret_directory_timeout);
754 #endif
755 }
756 }
757
758 #endif
759
760 char *cd_dialog (void)
761 {
762 QuickDialog Quick_input;
763 QuickWidget quick_widgets [] = {
764 #ifdef HAVE_TK
765 #define INPUT_INDEX 2
766 { quick_button, 0, 1, 0, 1, N_("&Cancel"), 0, B_CANCEL, 0, 0, XV_WLAY_DONTCARE, "cancel" },
767 { quick_button, 0, 1, 0, 1, N_("&Ok"), 0, B_ENTER, 0, 0, XV_WLAY_DONTCARE, "ok" },
768 #else
769 #define INPUT_INDEX 0
770 #endif
771 { quick_input, 6, 57, 5, 0, "", 50, 0, 0, 0, XV_WLAY_RIGHTOF, "input" },
772 { quick_label, 3, 57, 2, 0, "", 0, 0, 0, 0, XV_WLAY_DONTCARE, "label" },
773 { 0 } };
774
775 char *my_str;
776 int len;
777
778 Quick_input.xlen = 57;
779 Quick_input.title = _("Quick cd");
780 Quick_input.help = "[Quick cd]";
781 Quick_input.class = "quick_input";
782 quick_widgets [INPUT_INDEX].text = "";
783 quick_widgets [INPUT_INDEX].value = 2; /* want cd like completion */
784 quick_widgets [INPUT_INDEX+1].text = _("cd");
785 quick_widgets [INPUT_INDEX+1].y_divisions =
786 quick_widgets [INPUT_INDEX].y_divisions = Quick_input.ylen = 5;
787
788 len = strlen (quick_widgets [INPUT_INDEX+1].text);
789
790 quick_widgets [INPUT_INDEX+1].relative_x = 3;
791 quick_widgets [INPUT_INDEX].relative_x =
792 quick_widgets [INPUT_INDEX+1].relative_x + len + 1;
793
794 Quick_input.xlen = len + quick_widgets [INPUT_INDEX].hotkey_pos + 7;
795 quick_widgets [INPUT_INDEX].x_divisions =
796 quick_widgets [INPUT_INDEX+1].x_divisions = Quick_input.xlen;
797
798 Quick_input.i18n = 1;
799 Quick_input.xpos = 2;
800 Quick_input.ypos = LINES - 2 - Quick_input.ylen;
801 quick_widgets [INPUT_INDEX].relative_y = 2;
802 quick_widgets [INPUT_INDEX].str_result = &my_str;
803
804 Quick_input.widgets = quick_widgets;
805 if (quick_dialog (&Quick_input) != B_CANCEL){
806 return *(quick_widgets [INPUT_INDEX].str_result);
807 } else
808 return 0;
809 }
810
811 void symlink_dialog (char *existing, char *new, char **ret_existing,
812 char **ret_new)
813 {
814 QuickDialog Quick_input;
815 QuickWidget quick_widgets [] = {
816 #undef INPUT_INDEX
817 #if defined(HAVE_TK) || defined(HAVE_GNOME)
818 #define INPUT_INDEX 2
819 { quick_button, 0, 1, 0, 1, _("&Cancel"), 0, B_CANCEL, 0, 0,
820 XV_WLAY_DONTCARE, "cancel" },
821 { quick_button, 0, 1, 0, 1, _("&Ok"), 0, B_ENTER, 0, 0,
822 XV_WLAY_DONTCARE, "ok" },
823 #else
824 #define INPUT_INDEX 0
825 #endif
826 { quick_input, 6, 80, 5, 8, "", 58, 0, 0, 0, XV_WLAY_BELOWCLOSE, "input-1" },
827 { quick_label, 6, 80, 4, 8, "", 0, 0, 0, 0, XV_WLAY_BELOWOF, "label-1" },
828 { quick_input, 6, 80, 3, 8, "", 58, 0, 0, 0, XV_WLAY_BELOWCLOSE, "input-2" },
829 { quick_label, 6, 80, 2, 8, "", 0, 0, 0, 0, XV_WLAY_DONTCARE, "label-2" },
830 { 0 } };
831
832 Quick_input.xlen = 64;
833 Quick_input.ylen = 8;
834 Quick_input.title = "Symbolic link";
835 Quick_input.help = "[File Menu]";
836 Quick_input.class = "quick_symlink";
837 Quick_input.i18n = 0;
838 quick_widgets [INPUT_INDEX].text = new;
839 quick_widgets [INPUT_INDEX+1].text = _("Symbolic link filename:");
840 quick_widgets [INPUT_INDEX+2].text = existing;
841 quick_widgets [INPUT_INDEX+3].text = _("Existing filename (filename symlink will point to):");
842 Quick_input.xpos = -1;
843 quick_widgets [INPUT_INDEX].str_result = ret_new;
844 quick_widgets [INPUT_INDEX+2].str_result = ret_existing;
845
846 Quick_input.widgets = quick_widgets;
847 if (quick_dialog (&Quick_input) == B_CANCEL){
848 *ret_new = NULL;
849 *ret_existing = NULL;
850 }
851 }
852
853 #ifdef WITH_BACKGROUND
854 #define B_STOP B_USER+1
855 #define B_RESUME B_USER+2
856 #define B_KILL B_USER+3
857
858 static int JOBS_X = 60;
859 #define JOBS_Y 15
860 static WListbox *bg_list;
861 static Dlg_head *jobs_dlg;
862
863 static void
864 jobs_fill_listbox (void)
865 {
866 static char *state_str [2];
867 TaskList *tl = task_list;
868
869 if (!state_str [0]){
870 state_str [0] = _("Running ");
871 state_str [1] = _("Stopped");
872 }
873
874 while (tl){
875 char *s;
876
877 s = copy_strings (state_str [tl->state], " ", tl->info, NULL);
878 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
879 free (s);
880 tl = tl->next;
881 }
882 }
883
884 static int
885 task_cb (int action, void *ignored)
886 {
887 TaskList *tl;
888 int sig;
889
890 if (!bg_list->list)
891 return 0;
892
893 /* Get this instance information */
894 tl = (TaskList *) bg_list->current->data;
895
896 if (action == B_STOP){
897 sig = SIGSTOP;
898 tl->state = Task_Stopped;
899 } else if (action == B_RESUME){
900 sig = SIGCONT;
901 tl->state = Task_Running;
902 } else if (action == B_KILL){
903 sig = SIGKILL;
904 }
905
906 if (sig == SIGINT)
907 unregister_task_running (tl->pid, tl->fd);
908
909 kill (tl->pid, sig);
910 listbox_remove_list (bg_list);
911 jobs_fill_listbox ();
912
913 /* This can be optimized to just redraw this widget :-) */
914 dlg_redraw (jobs_dlg);
915
916 return 0;
917 }
918
919 static struct
920 {
921 char* name;
922 int xpos;
923 int value;
924 int (*callback)();
925 char* tkname;
926 }
927 job_buttons [] =
928 {
929 {N_("&Stop"), 3, B_STOP, task_cb, "button-stop"},
930 {N_("&Resume"), 12, B_RESUME, task_cb, "button-cont"},
931 {N_("&Kill"), 23, B_KILL, task_cb, "button-kill"},
932 {N_("&Ok"), 35, B_CANCEL, NULL, "button-ok"},
933 };
934
935 void
936 jobs_cmd (void)
937 {
938 register int i;
939 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
940
941 #ifdef ENABLE_NLS
942 static int i18n_flag = 0;
943 if (!i18n_flag)
944 {
945 int startx = job_buttons [0].xpos;
946 int len;
947
948 for (i = 0; i < n_buttons; i++)
949 {
950 job_buttons [i].name = _(job_buttons [i].name);
951
952 len = strlen (job_buttons [i].name) + 4;
953 JOBS_X = max (JOBS_X, startx + len + 3);
954
955 job_buttons [i].xpos = startx;
956 startx += len;
957 }
958
959 /* Last button - Ok a.k.a. Cancel :) */
960 job_buttons [n_buttons - 1].xpos =
961 JOBS_X - strlen (job_buttons [n_buttons - 1].name) - 7;
962
963 i18n_flag = 1;
964 }
965 #endif /* ENABLE_NLS */
966
967 jobs_dlg = create_dlg (0, 0, JOBS_Y, JOBS_X, dialog_colors,
968 common_dialog_callback, "[Background jobs]", "jobs",
969 DLG_CENTER | DLG_GRID);
970 x_set_dialog_title (jobs_dlg, _("Background Jobs"));
971
972 bg_list = listbox_new (2, 3, JOBS_X-7, JOBS_Y-9, listbox_nothing, 0, "listbox");
973 add_widget (jobs_dlg, bg_list);
974
975 i = n_buttons;
976 while (i--)
977 {
978 add_widget (jobs_dlg, button_new (JOBS_Y-4,
979 job_buttons [i].xpos, job_buttons [i].value,
980 NORMAL_BUTTON, job_buttons [i].name,
981 job_buttons [i].callback, 0,
982 job_buttons [i].tkname));
983 }
984
985 /* Insert all of task information in the list */
986 jobs_fill_listbox ();
987 run_dlg (jobs_dlg);
988
989 destroy_dlg (jobs_dlg);
990 }
991 #endif