s/paramter/parameter/
[midnight-commander.git] / src / boxes.c
blob90af7582be890c36148732d0b6cb11f9276e4057
1 /* Some misc dialog boxes for the program.
3 Copyright (C) 1994, 1995 the Free Software Foundation
5 Authors: 1994, 1995 Miguel de Icaza
6 1995 Jakub Jelinek
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include <config.h>
23 #include <string.h>
24 #include <stdio.h>
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <signal.h>
28 #include <ctype.h>
30 #include "global.h"
31 #include "tty.h"
32 #include "win.h" /* Our window tools */
33 #include "color.h" /* Color definitions */
34 #include "dlg.h" /* The nice dialog manager */
35 #include "widget.h" /* The widgets for the nice dialog manager */
36 #include "dialog.h" /* For do_refresh() */
37 #include "wtools.h"
38 #include "setup.h" /* For profile_name */
39 #include "profile.h" /* Load/save user formats */
40 #include "key.h" /* XCTRL and ALT macros */
41 #include "command.h" /* For cmdline */
42 #include "dir.h"
43 #include "panel.h"
44 #include "boxes.h"
45 #include "main.h" /* For the confirm_* variables */
46 #include "tree.h"
47 #include "layout.h" /* for get_nth_panel_name proto */
48 #include "fileopctx.h"
49 #include "background.h"
51 #ifdef HAVE_CHARSET
52 #include "charsets.h"
53 #include "selcodepage.h"
54 #endif
56 #include "../vfs/vfs.h" /* vfs_timeout */
57 #ifdef USE_NETCODE
58 # include "../vfs/ftpfs.h"
59 #endif
61 static int DISPLAY_X = 45, DISPLAY_Y = 14;
63 static Dlg_head *dd;
64 static WRadio *my_radio;
65 static WInput *user;
66 static WInput *status;
67 static WCheck *check_status;
68 static int current_mode;
70 static char **displays_status;
72 /* Controls whether the array strings have been translated */
73 static char *displays [LIST_TYPES] = {
74 N_("&Full file list"),
75 N_("&Brief file list"),
76 N_("&Long file list"),
77 N_("&User defined:")
80 /* Index in displays[] for "user defined" */
81 #define USER_TYPE 3
83 static int user_hotkey = 'u';
85 static int
86 display_callback (struct Dlg_head *h, int id, int Msg)
88 switch (Msg){
89 case DLG_DRAW:
90 common_dialog_repaint (h);
91 break;
93 case DLG_UNFOCUS:
94 if((WRadio *) h->current->widget == my_radio){
95 assign_text (status, displays_status [my_radio->sel]);
96 input_set_point (status, 0);
98 break;
100 case DLG_KEY:
101 if (id == '\n'){
102 if((WRadio *) h->current->widget == my_radio){
103 assign_text (status, displays_status [my_radio->sel]);
104 dlg_stop (h);
105 break;
108 if ((WInput *) h->current->widget == user){
109 h->ret_value = B_USER + 6;
110 dlg_stop (h);
111 break;
114 if ((WInput *) h->current->widget == status){
115 h->ret_value = B_USER + 7;
116 dlg_stop (h);
117 break;
121 if (tolower(id) == user_hotkey && h->current->widget != (Widget *) user
122 && h->current->widget != (Widget *) status){
123 my_radio->sel = 3;
124 dlg_select_widget (h, my_radio); /* force redraw */
125 dlg_select_widget (h, user);
126 return MSG_HANDLED;
129 return MSG_NOT_HANDLED;
132 static void
133 display_init (int radio_sel, char *init_text, int _check_status,
134 char **_status)
136 static char *display_title = N_("Listing mode");
137 static int i18n_displays_flag;
138 char *user_mini_status = _("user &Mini status");
139 char *ok_button = _("&Ok");
140 char *cancel_button = _("&Cancel");
142 static int button_start = 30;
144 displays_status = _status;
146 if (!i18n_displays_flag) {
147 int i, l, maxlen = 0;
148 char *cp;
150 display_title = _(display_title);
151 for (i = 0; i < LIST_TYPES; i++) {
152 displays[i] = _(displays[i]);
153 if ((l = strlen (displays[i])) > maxlen)
154 maxlen = l;
157 i = strlen (ok_button) + 5;
158 l = strlen (cancel_button) + 3;
159 l = max (i, l);
161 i = maxlen + l + 16;
162 if (i > DISPLAY_X)
163 DISPLAY_X = i;
165 i = strlen (user_mini_status) + 13;
166 if (i > DISPLAY_X)
167 DISPLAY_X = i;
169 i = strlen (display_title) + 10;
170 if (i > DISPLAY_X)
171 DISPLAY_X = i;
173 button_start = DISPLAY_X - l - 5;
175 /* get hotkey of user-defined format string */
176 cp = strchr (displays[USER_TYPE], '&');
177 if (cp != NULL && *++cp != '\0')
178 user_hotkey = tolower (*cp);
180 i18n_displays_flag = 1;
182 dd = create_dlg (0, 0, DISPLAY_Y, DISPLAY_X, dialog_colors,
183 display_callback, "[Listing Mode...]", display_title,
184 DLG_CENTER);
186 add_widget (dd,
187 button_new (4, button_start, B_CANCEL, NORMAL_BUTTON,
188 cancel_button, 0, 0, "cancel-button"));
190 add_widget (dd,
191 button_new (3, button_start, B_ENTER, DEFPUSH_BUTTON,
192 ok_button, 0, 0, "ok-button"));
194 status =
195 input_new (10, 9, INPUT_COLOR, DISPLAY_X - 14, _status[radio_sel],
196 "mini-input");
197 add_widget (dd, status);
198 input_set_point (status, 0);
200 check_status =
201 check_new (9, 5, _check_status, user_mini_status, "mini-status");
202 add_widget (dd, check_status);
204 user =
205 input_new (7, 9, INPUT_COLOR, DISPLAY_X - 14, init_text,
206 "user-fmt-input");
207 add_widget (dd, user);
208 input_set_point (user, 0);
210 my_radio = radio_new (3, 5, LIST_TYPES, displays, 1, "radio");
211 my_radio->sel = my_radio->pos = current_mode;
212 add_widget (dd, my_radio);
216 display_box (WPanel *panel, char **userp, char **minip, int *use_msformat, int num)
218 int result, i;
219 char *section = NULL;
220 char *p;
222 if (!panel) {
223 p = get_nth_panel_name (num);
224 panel = g_new (WPanel, 1);
225 panel->list_type = list_full;
226 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
227 panel->user_mini_status = 0;
228 for (i = 0; i < LIST_TYPES; i++)
229 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
230 section = g_strconcat ("Temporal:", p, NULL);
231 if (!profile_has_section (section, profile_name)) {
232 g_free (section);
233 section = g_strdup (p);
235 panel_load_setup (panel, section);
236 g_free (section);
239 current_mode = panel->list_type;
240 display_init (current_mode, panel->user_format,
241 panel->user_mini_status, panel->user_status_format);
243 run_dlg (dd);
245 result = -1;
247 if (section) {
248 g_free (panel->user_format);
249 for (i = 0; i < LIST_TYPES; i++)
250 g_free (panel->user_status_format [i]);
251 g_free (panel);
254 if (dd->ret_value != B_CANCEL){
255 result = my_radio->sel;
256 *userp = g_strdup (user->buffer);
257 *minip = g_strdup (status->buffer);
258 *use_msformat = check_status->state & C_BOOL;
260 destroy_dlg (dd);
262 return result;
265 static int SORT_X = 40, SORT_Y = 14;
267 static char *sort_orders_names [SORT_TYPES];
269 sortfn *
270 sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive)
272 int i, r, l;
273 sortfn *result;
274 WCheck *c, *case_sense;
276 char* ok_button = _("&Ok");
277 char* cancel_button = _("&Cancel");
278 char* reverse_label = _("&Reverse");
279 char* case_label = _("case sensi&tive");
280 char* sort_title = _("Sort order");
282 static int i18n_sort_flag = 0, check_pos = 0, button_pos = 0;
284 if (!i18n_sort_flag)
286 int maxlen = 0;
287 for (i = SORT_TYPES-1; i >= 0; i--)
289 sort_orders_names [i] = _(sort_orders [i].sort_name);
290 r = strlen (sort_orders_names [i]);
291 if (r > maxlen)
292 maxlen = r;
295 check_pos = maxlen + 9;
297 r = strlen (reverse_label) + 4;
298 i = strlen (case_label) + 4;
299 if (i > r)
300 r = i;
302 l = strlen (ok_button) + 6;
303 i = strlen (cancel_button) + 4;
304 if (i > l)
305 l = i;
307 i = check_pos + max(r,l) + 2;
309 if (i > SORT_X)
310 SORT_X = i;
312 i = strlen (sort_title) + 6;
313 if (i > SORT_X)
314 SORT_X = i;
316 button_pos = SORT_X - l - 2;
318 i18n_sort_flag = 1;
321 result = 0;
323 for (i = 0; i < SORT_TYPES; i++)
324 if ((sortfn *) (sort_orders [i].sort_fn) == sort_fn){
325 current_mode = i;
326 break;
329 dd = create_dlg (0, 0, SORT_Y, SORT_X, dialog_colors, NULL,
330 "[Sort Order...]", sort_title, DLG_CENTER);
332 add_widget (dd,
333 button_new (10, button_pos, B_CANCEL, NORMAL_BUTTON, cancel_button,
334 0, 0, "cancel-button"));
336 add_widget (dd,
337 button_new (9, button_pos, B_ENTER, DEFPUSH_BUTTON, ok_button,
338 0, 0, "ok-button"));
340 case_sense = check_new (4, check_pos, *case_sensitive, case_label, "case-check");
341 add_widget (dd, case_sense);
342 c = check_new (3, check_pos, *reverse, reverse_label, "reverse-check");
343 add_widget (dd, c);
345 my_radio = radio_new (3, 3, SORT_TYPES, sort_orders_names, 1, "radio-1");
346 my_radio->sel = my_radio->pos = current_mode;
348 add_widget (dd, my_radio);
349 run_dlg (dd);
351 r = dd->ret_value;
352 if (r != B_CANCEL){
353 result = (sortfn *) sort_orders [my_radio->sel].sort_fn;
354 *reverse = c->state & C_BOOL;
355 *case_sensitive = case_sense->state & C_BOOL;
356 } else
357 result = sort_fn;
358 destroy_dlg (dd);
360 return result;
363 #define CONFY 10
364 #define CONFX 46
366 static int my_delete;
367 static int my_overwrite;
368 static int my_execute;
369 static int my_exit;
371 static QuickWidget conf_widgets [] = {
372 { quick_button, 4, 6, 4, CONFY, N_("&Cancel"),
373 0, B_CANCEL, 0, 0, "c" },
374 { quick_button, 4, 6, 3, CONFY, N_("&Ok"),
375 0, B_ENTER, 0, 0, "o" },
377 { quick_checkbox, 1, 13, 6, CONFY, N_(" confirm &Exit "),
378 9, 0, &my_exit, 0, "e" },
379 { quick_checkbox, 1, 13, 5, CONFY, N_(" confirm e&Xecute "),
380 10, 0, &my_execute, 0, "x" },
381 { quick_checkbox, 1, 13, 4, CONFY, N_(" confirm o&Verwrite "),
382 10, 0, &my_overwrite, 0, "ov" },
383 { quick_checkbox, 1, 13, 3, CONFY, N_(" confirm &Delete "),
384 9, 0, &my_delete, 0, "de" },
385 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
388 static QuickDialog confirmation =
389 { CONFX, CONFY, -1, -1, N_(" Confirmation "), "[Confirmation]",
390 conf_widgets, 0
393 void
394 confirm_box (void)
397 #ifdef ENABLE_NLS
398 static int i18n_flag = 0;
400 if (!i18n_flag)
402 register int i = sizeof(conf_widgets)/sizeof(QuickWidget) - 1;
403 int l1, maxlen = 0;
404 while (i--)
406 conf_widgets [i].text = _(conf_widgets [i].text);
407 l1 = strlen (conf_widgets [i].text) + 3;
408 if (l1 > maxlen)
409 maxlen = l1;
413 * If buttons start on 4/6, checkboxes (with some add'l space)
414 * must take not more than it.
416 confirmation.xlen = (maxlen + 5) * 6 / 4;
419 * And this for the case when buttons with some space to the right
420 * do not fit within 2/6
422 l1 = strlen (conf_widgets [0].text) + 3;
423 i = strlen (conf_widgets [1].text) + 5;
424 if (i > l1)
425 l1 = i;
427 i = (l1 + 3) * 6 / 2;
428 if (i > confirmation.xlen)
429 confirmation.xlen = i;
431 confirmation.title = _(confirmation.title);
433 i18n_flag = confirmation.i18n = 1;
436 #endif /* ENABLE_NLS */
438 my_delete = confirm_delete;
439 my_overwrite = confirm_overwrite;
440 my_execute = confirm_execute;
441 my_exit = confirm_exit;
443 if (quick_dialog (&confirmation) != B_CANCEL){
444 confirm_delete = my_delete;
445 confirm_overwrite = my_overwrite;
446 confirm_execute = my_execute;
447 confirm_exit = my_exit;
451 #define DISPY 11
452 #define DISPX 46
455 #ifndef HAVE_CHARSET
457 static int new_mode;
458 static int new_meta;
460 static char *display_bits_str [] =
461 { N_("Full 8 bits output"), N_("ISO 8859-1"), N_("7 bits") };
463 static QuickWidget display_widgets [] = {
464 { quick_button, 4, 6, 4, DISPY, N_("&Cancel"),
465 0, B_CANCEL, 0, 0, "c" },
466 { quick_button, 4, 6, 3, DISPY, N_("&Ok"),
467 0, B_ENTER, 0, 0, "o" },
468 { quick_checkbox, 4, DISPX, 7, DISPY, N_("F&ull 8 bits input"),
469 0, 0, &new_meta, 0, "u" },
470 { quick_radio, 4, DISPX, 3, DISPY, "", 3, 0,
471 &new_mode, display_bits_str, "r" },
472 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
475 static QuickDialog display_bits =
476 { DISPX, DISPY, -1, -1, N_(" Display bits "), "[Display bits]",
477 display_widgets, 0 };
479 void
480 display_bits_box (void)
482 int current_mode;
484 #ifdef ENABLE_NLS
485 static int i18n_flag = 0;
486 if (!i18n_flag)
488 register int i;
489 int l1, maxlen = 0;
490 for (i = 0; i < 3; i++)
492 display_widgets [i].text = _(display_widgets[i].text);
493 display_bits_str [i] = _(display_bits_str [i]);
494 l1 = strlen (display_bits_str [i]);
495 if (l1 > maxlen)
496 maxlen = l1;
498 l1 = strlen (display_widgets [2].text);
499 if (l1 > maxlen)
500 maxlen = l1;
503 display_bits.xlen = (maxlen + 5) * 6 / 4;
505 /* See above confirm_box */
506 l1 = strlen (display_widgets [0].text) + 3;
507 i = strlen (display_widgets [1].text) + 5;
508 if (i > l1)
509 l1 = i;
511 i = (l1 + 3) * 6 / 2;
512 if (i > display_bits.xlen)
513 display_bits.xlen = i;
515 display_bits.title = _(display_bits.title);
516 i18n_flag = display_bits.i18n = 1;
519 #endif /* ENABLE_NLS */
521 if (full_eight_bits)
522 current_mode = 0;
523 else if (eight_bit_clean)
524 current_mode = 1;
525 else
526 current_mode = 2;
528 display_widgets [3].value = current_mode;
529 new_meta = !use_8th_bit_as_meta;
530 if (quick_dialog (&display_bits) != B_ENTER)
531 return;
533 eight_bit_clean = new_mode < 2;
534 full_eight_bits = new_mode == 0;
535 #ifndef HAVE_SLANG
536 meta (stdscr, eight_bit_clean);
537 #else
538 SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
539 #endif
540 use_8th_bit_as_meta = !new_meta;
544 #else /* HAVE_CHARSET */
547 static int new_display_codepage;
549 static WLabel *cplabel;
550 static WCheck *inpcheck;
552 static int sel_charset_button( int action, void *param )
554 char *cpname, buf[64];
555 new_display_codepage = select_charset( new_display_codepage, 1 );
556 cpname = (new_display_codepage < 0)
557 ? _("Other 8 bit")
558 : codepages[ new_display_codepage ].name;
559 sprintf( buf, "%-27s", cpname ); /* avoid strange bug with label repainting */
560 label_set_text( cplabel, buf );
561 return 0;
564 Dlg_head *
565 init_disp_bits_box (void)
567 char *cpname;
568 Dlg_head *dbits_dlg;
570 do_refresh();
572 dbits_dlg = create_dlg( 0, 0, DISPY, DISPX, dialog_colors,
573 NULL, "[Display bits]", _(" Display bits "), DLG_CENTER);
575 add_widget( dbits_dlg,
576 label_new( 3, 4, _("Input / display codepage:"), NULL));
578 cpname = (new_display_codepage < 0)
579 ? "Other 8 bit"
580 : codepages[ new_display_codepage ].name;
581 cplabel = label_new( 4, 4, cpname, NULL);
582 add_widget( dbits_dlg, cplabel );
584 add_widget( dbits_dlg,
585 button_new( DISPY - 3, DISPX / 2 + 3, B_CANCEL,
586 NORMAL_BUTTON, _("&Cancel"), 0, 0, NULL ) );
587 add_widget( dbits_dlg,
588 button_new( DISPY - 3, 7, B_ENTER,
589 NORMAL_BUTTON, _("&Ok"), 0, 0, NULL ) );
591 inpcheck = check_new( 6, 4, !use_8th_bit_as_meta,
592 _("F&ull 8 bits input"), NULL );
593 add_widget( dbits_dlg, inpcheck );
595 cpname = _("&Select");
596 add_widget( dbits_dlg,
597 button_new( 4, DISPX - 8 - strlen(cpname) , B_USER,
598 NORMAL_BUTTON, cpname,
599 sel_charset_button, 0, NULL ) );
601 return dbits_dlg;
604 void
605 display_bits_box (void)
607 Dlg_head *dbits_dlg;
608 new_display_codepage = display_codepage;
610 application_keypad_mode ();
611 dbits_dlg = init_disp_bits_box ();
613 run_dlg (dbits_dlg);
615 if (dbits_dlg->ret_value == B_ENTER) {
616 char *errmsg;
617 display_codepage = new_display_codepage;
618 errmsg = init_translation_table( source_codepage, display_codepage );
619 if (errmsg)
620 message( 1, MSG_ERROR, "%s", errmsg );
621 #ifndef HAVE_SLANG
622 meta( stdscr, display_codepage != 0 );
623 #else
624 SLsmg_Display_Eight_Bit
625 = (display_codepage != 0 && display_codepage != 1) ? 128 : 160;
626 #endif
627 use_8th_bit_as_meta = ! (inpcheck->state & C_BOOL);
629 destroy_dlg( dbits_dlg );
630 repaint_screen();
633 #endif /* HAVE_CHARSET */
636 #define TREE_Y 20
637 #define TREE_X 60
639 static int
640 tree_callback (struct Dlg_head *h, int id, int msg)
642 switch (msg){
644 case DLG_POST_KEY:
645 /* The enter key will be processed by the tree widget */
646 if (id == '\n' || ((WTree *)(h->current->widget))->done){
647 h->ret_value = B_ENTER;
648 dlg_stop (h);
650 return MSG_HANDLED;
652 case DLG_DRAW:
653 common_dialog_repaint (h);
654 break;
656 return MSG_NOT_HANDLED;
659 /* Show tree in a box, not on a panel */
660 char *
661 tree_box (char *current_dir)
663 WTree *mytree;
664 Dlg_head *dlg;
665 char *val;
666 WButtonBar *bar;
668 /* Create the components */
669 dlg = create_dlg (0, 0, TREE_Y, TREE_X, dialog_colors,
670 tree_callback, "[Directory Tree]", NULL, DLG_CENTER);
671 mytree = tree_new (0, 2, 2, TREE_Y - 6, TREE_X - 5);
672 add_widget (dlg, mytree);
673 bar = buttonbar_new(1);
674 add_widget (dlg, bar);
675 bar->widget.x = 0;
676 bar->widget.y = LINES - 1;
678 run_dlg (dlg);
679 if (dlg->ret_value == B_ENTER)
680 val = g_strdup (mytree->selected_ptr->name);
681 else
682 val = 0;
684 destroy_dlg (dlg);
685 return val;
688 #ifdef USE_VFS
690 #if defined(USE_NETCODE)
691 #define VFSY 15
692 #define VFS_WIDGETBASE 8
693 #else
694 #define VFSY 8
695 #define VFS_WIDGETBASE 0
696 #endif
698 #define VFSX 56
700 static char *ret_timeout;
702 #if defined(USE_NETCODE)
703 static char *ret_passwd;
704 static char *ret_directory_timeout;
705 static char *ret_ftp_proxy;
706 static int ret_use_netrc;
707 #endif
709 static QuickWidget confvfs_widgets [] = {
710 { quick_button, 30, VFSX, VFSY - 3, VFSY, N_("&Cancel"),
711 0, B_CANCEL, 0, 0, "button-cancel" },
712 { quick_button, 12, VFSX, VFSY - 3, VFSY, N_("&Ok"),
713 0, B_ENTER, 0, 0, "button-ok" },
714 #if defined(USE_NETCODE)
715 { quick_checkbox, 4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), 0, 0,
716 &ret_use_netrc, 0, "check-use-netrc" },
717 { quick_input, 4, VFSX, 9, VFSY, "", 48, 0, 0, &ret_ftp_proxy,
718 "input-ftp-proxy" },
719 { quick_checkbox, 4, VFSX, 8, VFSY, N_("&Always use ftp proxy"), 0, 0,
720 &ftpfs_always_use_proxy, 0, "check-ftp-proxy" },
721 { quick_label, 49, VFSX, 7, VFSY, N_("sec"),
722 0, 0, 0, 0, "label-sec" },
723 { quick_input, 38, VFSX, 7, VFSY, "", 10, 0, 0, &ret_directory_timeout,
724 "input-timeout" },
725 { quick_label, 4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:"),
726 0, 0, 0, 0, "label-cache"},
727 { quick_input, 4, VFSX, 6, VFSY, "", 48, 0, 0, &ret_passwd,
728 "input-passwd" },
729 { quick_label, 4, VFSX, 5, VFSY, N_("ftp anonymous password:"),
730 0, 0, 0, 0, "label-pass"},
731 #endif
732 { quick_label, 49, VFSX, 3, VFSY, "sec",
733 0, 0, 0, 0, "label-sec2" },
734 { quick_input, 38, VFSX, 3, VFSY, "", 10, 0, 0, &ret_timeout,
735 "input-timo-vfs" },
736 { quick_label, 4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:"),
737 0, 0, 0, 0, "label-vfs" },
738 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
741 static QuickDialog confvfs_dlg =
742 { VFSX, VFSY, -1, -1, N_(" Virtual File System Setting "),
743 "[Virtual FS]", confvfs_widgets, 0 };
745 void
746 configure_vfs (void)
748 char buffer2[BUF_TINY];
749 #if defined(USE_NETCODE)
750 char buffer3[BUF_TINY];
751 #endif
753 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
754 confvfs_widgets [3 + VFS_WIDGETBASE].text = buffer2;
755 #if defined(USE_NETCODE)
756 ret_use_netrc = use_netrc;
757 g_snprintf(buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
758 confvfs_widgets[6].text = buffer3;
759 confvfs_widgets[8].text = ftpfs_anonymous_passwd;
760 confvfs_widgets[3].text = ftpfs_proxy_host;
761 #endif
763 if (quick_dialog (&confvfs_dlg) != B_CANCEL) {
764 vfs_timeout = atoi (ret_timeout);
765 g_free (ret_timeout);
766 if (vfs_timeout < 0 || vfs_timeout > 10000)
767 vfs_timeout = 10;
768 #if defined(USE_NETCODE)
769 g_free (ftpfs_anonymous_passwd);
770 ftpfs_anonymous_passwd = ret_passwd;
771 if (ftpfs_proxy_host)
772 g_free (ftpfs_proxy_host);
773 ftpfs_proxy_host = ret_ftp_proxy;
774 ftpfs_directory_timeout = atoi(ret_directory_timeout);
775 use_netrc = ret_use_netrc;
776 g_free (ret_directory_timeout);
777 #endif
781 #endif
783 char *
784 cd_dialog (void)
786 QuickDialog Quick_input;
787 QuickWidget quick_widgets [] = {
788 { quick_input, 6, 57, 5, 0, "", 50, 0, 0, 0, "input" },
789 { quick_label, 3, 57, 2, 0, "", 0, 0, 0, 0, "label" },
790 { 0 } };
792 char *my_str;
793 int len;
795 Quick_input.xlen = 57;
796 Quick_input.title = _("Quick cd");
797 Quick_input.help = "[Quick cd]";
798 quick_widgets [0].text = "";
799 quick_widgets [0].value = 2; /* want cd like completion */
800 quick_widgets [1].text = _("cd");
801 quick_widgets [1].y_divisions =
802 quick_widgets [0].y_divisions = Quick_input.ylen = 5;
804 len = strlen (quick_widgets [1].text);
806 quick_widgets [1].relative_x = 3;
807 quick_widgets [0].relative_x =
808 quick_widgets [1].relative_x + len + 1;
810 Quick_input.xlen = len + quick_widgets [0].hotkey_pos + 7;
811 quick_widgets [0].x_divisions =
812 quick_widgets [1].x_divisions = Quick_input.xlen;
814 Quick_input.i18n = 1;
815 Quick_input.xpos = 2;
816 Quick_input.ypos = LINES - 2 - Quick_input.ylen;
817 quick_widgets [0].relative_y = 2;
818 quick_widgets [0].str_result = &my_str;
820 Quick_input.widgets = quick_widgets;
821 if (quick_dialog (&Quick_input) != B_CANCEL){
822 return *(quick_widgets [0].str_result);
823 } else
824 return 0;
827 void
828 symlink_dialog (char *existing, char *new, char **ret_existing, char **ret_new)
830 QuickDialog Quick_input;
831 QuickWidget quick_widgets [] = {
832 { quick_input, 4, 80, 5, 8, "", 58, 0, 0, 0, "input-1" },
833 { quick_label, 4, 80, 4, 8, "", 0, 0, 0, 0, "label-1" },
834 { quick_input, 4, 80, 3, 8, "", 58, 0, 0, 0, "input-2" },
835 { quick_label, 4, 80, 2, 8, "", 0, 0, 0, 0, "label-2" },
836 { 0 } };
838 Quick_input.xlen = 64;
839 Quick_input.ylen = 8;
840 Quick_input.title = _("Symbolic link");
841 Quick_input.help = "[File Menu]";
842 Quick_input.i18n = 0;
843 quick_widgets [0].text = new;
844 quick_widgets [1].text = _("Symbolic link filename:");
845 quick_widgets [2].text = existing;
846 quick_widgets [3].text = _("Existing filename (filename symlink will point to):");
847 Quick_input.xpos = -1;
848 quick_widgets [0].str_result = ret_new;
849 quick_widgets [2].str_result = ret_existing;
851 Quick_input.widgets = quick_widgets;
852 if (quick_dialog (&Quick_input) == B_CANCEL){
853 *ret_new = NULL;
854 *ret_existing = NULL;
858 #ifdef WITH_BACKGROUND
859 #define B_STOP B_USER+1
860 #define B_RESUME B_USER+2
861 #define B_KILL B_USER+3
863 static int JOBS_X = 60;
864 #define JOBS_Y 15
865 static WListbox *bg_list;
866 static Dlg_head *jobs_dlg;
868 static void
869 jobs_fill_listbox (void)
871 static char *state_str [2];
872 TaskList *tl = task_list;
874 if (!state_str [0]){
875 state_str [0] = _("Running ");
876 state_str [1] = _("Stopped");
879 while (tl){
880 char *s;
882 s = g_strconcat (state_str [tl->state], " ", tl->info, NULL);
883 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
884 g_free (s);
885 tl = tl->next;
889 static int
890 task_cb (int action, void *ignored)
892 TaskList *tl;
893 int sig = 0;
895 if (!bg_list->list)
896 return 0;
898 /* Get this instance information */
899 tl = (TaskList *) bg_list->current->data;
901 # ifdef SIGTSTP
902 if (action == B_STOP){
903 sig = SIGSTOP;
904 tl->state = Task_Stopped;
905 } else if (action == B_RESUME){
906 sig = SIGCONT;
907 tl->state = Task_Running;
908 } else
909 # endif
910 if (action == B_KILL){
911 sig = SIGKILL;
914 if (sig == SIGINT)
915 unregister_task_running (tl->pid, tl->fd);
917 kill (tl->pid, sig);
918 listbox_remove_list (bg_list);
919 jobs_fill_listbox ();
921 /* This can be optimized to just redraw this widget :-) */
922 dlg_redraw (jobs_dlg);
924 return 0;
927 static struct
929 char* name;
930 int xpos;
931 int value;
932 int (*callback)(int, void *);
933 char* tkname;
935 job_buttons [] =
937 {N_("&Stop"), 3, B_STOP, task_cb, "button-stop"},
938 {N_("&Resume"), 12, B_RESUME, task_cb, "button-cont"},
939 {N_("&Kill"), 23, B_KILL, task_cb, "button-kill"},
940 {N_("&Ok"), 35, B_CANCEL, NULL, "button-ok"},
943 void
944 jobs_cmd (void)
946 register int i;
947 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
949 #ifdef ENABLE_NLS
950 static int i18n_flag = 0;
951 if (!i18n_flag)
953 int startx = job_buttons [0].xpos;
954 int len;
956 for (i = 0; i < n_buttons; i++)
958 job_buttons [i].name = _(job_buttons [i].name);
960 len = strlen (job_buttons [i].name) + 4;
961 JOBS_X = max (JOBS_X, startx + len + 3);
963 job_buttons [i].xpos = startx;
964 startx += len;
967 /* Last button - Ok a.k.a. Cancel :) */
968 job_buttons [n_buttons - 1].xpos =
969 JOBS_X - strlen (job_buttons [n_buttons - 1].name) - 7;
971 i18n_flag = 1;
973 #endif /* ENABLE_NLS */
975 jobs_dlg = create_dlg (0, 0, JOBS_Y, JOBS_X, dialog_colors, NULL,
976 "[Background jobs]", _("Background Jobs"),
977 DLG_CENTER);
979 bg_list = listbox_new (2, 3, JOBS_X-7, JOBS_Y-9, listbox_nothing, 0, "listbox");
980 add_widget (jobs_dlg, bg_list);
982 i = n_buttons;
983 while (i--)
985 add_widget (jobs_dlg, button_new (JOBS_Y-4,
986 job_buttons [i].xpos, job_buttons [i].value,
987 NORMAL_BUTTON, job_buttons [i].name,
988 job_buttons [i].callback, 0,
989 job_buttons [i].tkname));
992 /* Insert all of task information in the list */
993 jobs_fill_listbox ();
994 run_dlg (jobs_dlg);
996 destroy_dlg (jobs_dlg);
998 #endif /* WITH_BACKGROUND */
1000 #ifdef WITH_SMBFS
1001 struct smb_authinfo *
1002 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
1003 const char *user)
1005 static int dialog_x = 44;
1006 int dialog_y = 12;
1007 struct smb_authinfo *return_value;
1008 static char* labs[] = {N_("Domain:"), N_("Username:"), N_("Password:")};
1009 static char* buts[] = {N_("&Ok"), N_("&Cancel")};
1010 static int ilen = 30, istart = 14;
1011 static int b0 = 3, b2 = 30;
1012 char *title;
1013 WInput *in_password;
1014 WInput *in_user;
1015 WInput *in_domain;
1016 Dlg_head *auth_dlg;
1018 #ifdef ENABLE_NLS
1019 static int i18n_flag = 0;
1021 if (!i18n_flag)
1023 register int i = sizeof(labs)/sizeof(labs[0]);
1024 int l1, maxlen = 0;
1026 while (i--)
1028 l1 = strlen (labs [i] = _(labs [i]));
1029 if (l1 > maxlen)
1030 maxlen = l1;
1032 i = maxlen + ilen + 7;
1033 if (i > dialog_x)
1034 dialog_x = i;
1036 for (i = sizeof(buts)/sizeof(buts[0]), l1 = 0; i--; )
1038 l1 += strlen (buts [i] = _(buts [i]));
1040 l1 += 15;
1041 if (l1 > dialog_x)
1042 dialog_x = l1;
1044 ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
1045 istart = dialog_x - 3 - ilen;
1047 b2 = dialog_x - (strlen(buts[1]) + 6);
1049 i18n_flag = 1;
1052 #endif /* ENABLE_NLS */
1054 if (!domain)
1055 domain = "";
1056 if (!user)
1057 user = "";
1059 title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1061 auth_dlg = create_dlg (0, 0, dialog_y, dialog_x, dialog_colors, NULL,
1062 "[Smb Authinfo]", title, DLG_CENTER);
1064 g_free (title);
1066 in_user = input_new (5, istart, INPUT_COLOR, ilen, user, "auth_name");
1067 add_widget (auth_dlg, in_user);
1069 in_domain = input_new (3, istart, INPUT_COLOR, ilen, domain, "auth_domain");
1070 add_widget (auth_dlg, in_domain);
1071 add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON,
1072 buts[1], 0 ,0, "cancel"));
1073 add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON,
1074 buts[0], 0, 0, "ok"));
1076 in_password = input_new (7, istart, INPUT_COLOR, ilen, "", "auth_password");
1077 in_password->completion_flags = 0;
1078 in_password->is_password = 1;
1079 add_widget (auth_dlg, in_password);
1081 add_widget (auth_dlg, label_new (7, 3, labs[2], "label-passwd"));
1082 add_widget (auth_dlg, label_new (5, 3, labs[1], "label-user"));
1083 add_widget (auth_dlg, label_new (3, 3, labs[0], "label-domain"));
1085 run_dlg (auth_dlg);
1087 switch (auth_dlg->ret_value) {
1088 case B_CANCEL:
1089 return_value = 0;
1090 break;
1091 default:
1092 return_value = g_new (struct smb_authinfo, 1);
1093 if (return_value) {
1094 return_value->host = g_strdup (host);
1095 return_value->share = g_strdup (share);
1096 return_value->domain = g_strdup (in_domain->buffer);
1097 return_value->user = g_strdup (in_user->buffer);
1098 return_value->password = g_strdup (in_password->buffer);
1102 destroy_dlg (auth_dlg);
1104 return return_value;
1106 #endif /* WITH_SMBFS */