* Makefile.am: Remove definition of CONFDIR, it's not used.
[midnight-commander.git] / src / boxes.c
blob8b1474a2e0af4f6ed7b81bf4083135eedecc8397
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;
71 static char* display_title = N_(" Listing mode ");
73 /* Controls whether the array strings have been translated */
74 static int i18n_displays_flag;
75 static char *displays [LIST_TYPES] = {
76 N_("&Full file list"),
77 N_("&Brief file list"),
78 N_("&Long file list"),
79 N_("&User defined:"),
80 N_("&Icon view"),
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 attrset (COLOR_NORMAL);
91 dlg_erase (h);
92 draw_box (h, 1, 2, h->lines - 2, h->cols - 4);
94 attrset (COLOR_HOT_NORMAL);
95 dlg_move (h, 1, (h->cols - strlen(display_title))/2);
96 addstr (display_title);
97 attrset (COLOR_NORMAL);
98 break;
100 case DLG_UNFOCUS:
101 if((WRadio *) h->current->widget == my_radio){
102 assign_text (status, displays_status [my_radio->sel]);
103 input_set_point (status, 0);
105 break;
107 case DLG_KEY:
108 if (id == '\n'){
109 if((WRadio *) h->current->widget == my_radio){
110 assign_text (status, displays_status [my_radio->sel]);
111 dlg_stop (h);
112 break;
115 if ((WInput *) h->current->widget == user){
116 h->ret_value = B_USER + 6;
117 dlg_stop (h);
118 break;
121 if ((WInput *) h->current->widget == status){
122 h->ret_value = B_USER + 7;
123 dlg_stop (h);
124 break;
128 if (tolower(id) == user_hotkey && h->current->widget != (Widget *) user
129 && h->current->widget != (Widget *) status){
130 my_radio->sel = 3;
131 dlg_select_widget (h, my_radio); /* force redraw */
132 dlg_select_widget (h, user);
133 return MSG_HANDLED;
136 return MSG_NOT_HANDLED;
139 static void
140 display_init (int radio_sel, char *init_text,
141 int _check_status, char ** _status)
143 char* user_mini_status = _("user &Mini status");
144 char* ok_button = _("&Ok");
145 char* cancel_button = _("&Cancel");
147 static int button_start = 30;
149 displays_status = _status;
151 if (!i18n_displays_flag){
152 int i, l, maxlen = 0;
153 char* cp;
155 display_title = _(display_title);
156 for (i = 0; i < LIST_TYPES; i++)
158 displays [i] = _(displays [i]);
159 if ((l = strlen(displays [i])) > maxlen)
160 maxlen = l;
163 i = strlen (ok_button) + 5;
164 l = strlen (cancel_button) + 3;
165 l = max(i, l);
167 i = maxlen + l + 16;
168 if (i > DISPLAY_X)
169 DISPLAY_X = i;
171 i = strlen (user_mini_status) + 13;
172 if (i > DISPLAY_X)
173 DISPLAY_X = i;
175 i = strlen (display_title) + 8;
176 if (i > DISPLAY_X)
177 DISPLAY_X = i;
179 button_start = DISPLAY_X - l - 5;
181 /* get hotkey of user-defined format string */
182 cp = strchr(displays[LIST_TYPES-1],'&');
183 if (cp != NULL && *++cp != '\0')
184 user_hotkey = tolower(*cp);
186 i18n_displays_flag = 1;
188 dd = create_dlg (0, 0, DISPLAY_Y, DISPLAY_X, dialog_colors,
189 display_callback, "[Listing Mode...]", "display",
190 DLG_CENTER);
192 x_set_dialog_title (dd, _("Listing mode"));
193 add_widget (dd,
194 button_new (4, button_start, B_CANCEL,
195 NORMAL_BUTTON, cancel_button, 0, 0, "cancel-button"));
197 add_widget (dd,
198 button_new (3, button_start, B_ENTER,
199 DEFPUSH_BUTTON, ok_button, 0, 0, "ok-button"));
201 status = input_new (10, 9, INPUT_COLOR, DISPLAY_X-14, _status [radio_sel], "mini-input");
202 add_widget (dd, status);
203 input_set_point (status, 0);
205 check_status = check_new (9, 5, _check_status, user_mini_status, "mini-status");
206 add_widget (dd, check_status);
208 user = input_new (7, 9, INPUT_COLOR, DISPLAY_X-14, init_text, "user-fmt-input");
209 add_widget (dd, user);
210 input_set_point (user, 0);
212 my_radio = radio_new (3, 5, LIST_TYPES-1, displays, 1, "radio");
213 my_radio->sel = my_radio->pos = current_mode;
214 add_widget (dd, my_radio);
218 display_box (WPanel *panel, char **userp, char **minip, int *use_msformat, int num)
220 int result, i;
221 char *section = NULL;
222 char *p;
224 if (!panel) {
225 p = get_nth_panel_name (num);
226 panel = g_new (WPanel, 1);
227 panel->list_type = list_full;
228 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
229 panel->user_mini_status = 0;
230 for (i = 0; i < LIST_TYPES; i++)
231 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
232 section = g_strconcat ("Temporal:", p, NULL);
233 if (!profile_has_section (section, profile_name)) {
234 g_free (section);
235 section = g_strdup (p);
237 panel_load_setup (panel, section);
238 g_free (section);
241 current_mode = panel->list_type;
242 display_init (current_mode, panel->user_format,
243 panel->user_mini_status, panel->user_status_format);
245 run_dlg (dd);
247 result = -1;
249 if (section) {
250 g_free (panel->user_format);
251 for (i = 0; i < LIST_TYPES; i++)
252 g_free (panel->user_status_format [i]);
253 g_free (panel);
256 if (dd->ret_value != B_CANCEL){
257 result = my_radio->sel;
258 *userp = g_strdup (user->buffer);
259 *minip = g_strdup (status->buffer);
260 *use_msformat = check_status->state & C_BOOL;
262 destroy_dlg (dd);
264 return result;
267 static int SORT_X = 40, SORT_Y = 14;
269 static char *sort_orders_names [SORT_TYPES];
271 sortfn *
272 sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive)
274 int i, r, l;
275 sortfn *result;
276 WCheck *c, *case_sense;
278 char* ok_button = _("&Ok");
279 char* cancel_button = _("&Cancel");
280 char* reverse_label = _("&Reverse");
281 char* case_label = _("case sensi&tive");
282 char* sort_title = _("Sort order");
284 static int i18n_sort_flag = 0, check_pos = 0, button_pos = 0;
286 if (!i18n_sort_flag)
288 int maxlen = 0;
289 for (i = SORT_TYPES-1; i >= 0; i--)
291 sort_orders_names [i] = _(sort_orders [i].sort_name);
292 r = strlen (sort_orders_names [i]);
293 if (r > maxlen)
294 maxlen = r;
297 check_pos = maxlen + 9;
299 r = strlen (reverse_label) + 4;
300 i = strlen (case_label) + 4;
301 if (i > r)
302 r = i;
304 l = strlen (ok_button) + 6;
305 i = strlen (cancel_button) + 4;
306 if (i > l)
307 l = i;
309 i = check_pos + max(r,l) + 2;
311 if (i > SORT_X)
312 SORT_X = i;
314 i = strlen (sort_title) + 6;
315 if (i > SORT_X)
316 SORT_X = i;
318 button_pos = SORT_X - l - 2;
320 i18n_sort_flag = 1;
323 result = 0;
325 for (i = 0; i < SORT_TYPES; i++)
326 if ((sortfn *) (sort_orders [i].sort_fn) == sort_fn){
327 current_mode = i;
328 break;
331 dd = create_dlg (0, 0, SORT_Y, SORT_X, dialog_colors, common_dialog_callback,
332 "[Sort Order...]", "sort", DLG_CENTER);
334 x_set_dialog_title (dd, sort_title);
336 add_widget (dd,
337 button_new (10, button_pos, B_CANCEL, NORMAL_BUTTON, cancel_button,
338 0, 0, "cancel-button"));
340 add_widget (dd,
341 button_new (9, button_pos, B_ENTER, DEFPUSH_BUTTON, ok_button,
342 0, 0, "ok-button"));
344 case_sense = check_new (4, check_pos, *case_sensitive, case_label, "case-check");
345 add_widget (dd, case_sense);
346 c = check_new (3, check_pos, *reverse, reverse_label, "reverse-check");
347 add_widget (dd, c);
349 my_radio = radio_new (3, 3, SORT_TYPES, sort_orders_names, 1, "radio-1");
350 my_radio->sel = my_radio->pos = current_mode;
352 add_widget (dd, my_radio);
353 run_dlg (dd);
355 r = dd->ret_value;
356 if (r != B_CANCEL){
357 result = (sortfn *) sort_orders [my_radio->sel].sort_fn;
358 *reverse = c->state & C_BOOL;
359 *case_sensitive = case_sense->state & C_BOOL;
360 } else
361 result = sort_fn;
362 destroy_dlg (dd);
364 return result;
367 #define CONFY 10
368 #define CONFX 46
370 static int my_delete;
371 static int my_overwrite;
372 static int my_execute;
373 static int my_exit;
375 static QuickWidget conf_widgets [] = {
376 { quick_button, 4, 6, 4, CONFY, N_("&Cancel"),
377 0, B_CANCEL, 0, 0, "c" },
378 { quick_button, 4, 6, 3, CONFY, N_("&Ok"),
379 0, B_ENTER, 0, 0, "o" },
381 { quick_checkbox, 1, 13, 6, CONFY, N_(" confirm &Exit "),
382 9, 0, &my_exit, 0, "e" },
383 { quick_checkbox, 1, 13, 5, CONFY, N_(" confirm e&Xecute "),
384 10, 0, &my_execute, 0, "x" },
385 { quick_checkbox, 1, 13, 4, CONFY, N_(" confirm o&Verwrite "),
386 10, 0, &my_overwrite, 0, "ov" },
387 { quick_checkbox, 1, 13, 3, CONFY, N_(" confirm &Delete "),
388 9, 0, &my_delete, 0, "de" },
389 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
392 static QuickDialog confirmation =
393 { CONFX, CONFY, -1, -1, N_(" Confirmation "), "[Confirmation]", "quick_confirm",
394 conf_widgets, 0 };
396 void
397 confirm_box ()
400 #ifdef ENABLE_NLS
401 static int i18n_flag = 0;
403 if (!i18n_flag)
405 register int i = sizeof(conf_widgets)/sizeof(QuickWidget) - 1;
406 int l1, maxlen = 0;
407 while (i--)
409 conf_widgets [i].text = _(conf_widgets [i].text);
410 l1 = strlen (conf_widgets [i].text) + 3;
411 if (l1 > maxlen)
412 maxlen = l1;
416 * If buttons start on 4/6, checkboxes (with some add'l space)
417 * must take not more than it.
419 confirmation.xlen = (maxlen + 5) * 6 / 4;
422 * And this for the case when buttons with some space to the right
423 * do not fit within 2/6
425 l1 = strlen (conf_widgets [0].text) + 3;
426 i = strlen (conf_widgets [1].text) + 5;
427 if (i > l1)
428 l1 = i;
430 i = (l1 + 3) * 6 / 2;
431 if (i > confirmation.xlen)
432 confirmation.xlen = i;
434 confirmation.title = _(confirmation.title);
436 i18n_flag = confirmation.i18n = 1;
439 #endif /* ENABLE_NLS */
441 my_delete = confirm_delete;
442 my_overwrite = confirm_overwrite;
443 my_execute = confirm_execute;
444 my_exit = confirm_exit;
446 if (quick_dialog (&confirmation) != B_CANCEL){
447 confirm_delete = my_delete;
448 confirm_overwrite = my_overwrite;
449 confirm_execute = my_execute;
450 confirm_exit = my_exit;
454 #define DISPY 11
455 #define DISPX 46
458 #ifndef HAVE_CHARSET
460 static int new_mode;
461 static int new_meta;
463 static char *display_bits_str [] =
464 { N_("Full 8 bits output"), N_("ISO 8859-1"), N_("7 bits") };
466 static QuickWidget display_widgets [] = {
467 { quick_button, 4, 6, 4, DISPY, N_("&Cancel"),
468 0, B_CANCEL, 0, 0, "c" },
469 { quick_button, 4, 6, 3, DISPY, N_("&Ok"),
470 0, B_ENTER, 0, 0, "o" },
471 { quick_checkbox, 4, DISPX, 7, DISPY, N_("F&ull 8 bits input"),
472 0, 0, &new_meta, 0, "u" },
473 { quick_radio, 4, DISPX, 3, DISPY, "", 3, 0,
474 &new_mode, display_bits_str, "r" },
475 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
478 static QuickDialog display_bits =
479 { DISPX, DISPY, -1, -1, N_(" Display bits "), "[Display bits]",
480 "dbits", display_widgets, 0 };
482 void
483 display_bits_box ()
485 int current_mode;
487 #ifdef ENABLE_NLS
488 static int i18n_flag = 0;
489 if (!i18n_flag)
491 register int i;
492 int l1, maxlen = 0;
493 for (i = 0; i < 3; i++)
495 display_widgets [i].text = _(display_widgets[i].text);
496 display_bits_str [i] = _(display_bits_str [i]);
497 l1 = strlen (display_bits_str [i]);
498 if (l1 > maxlen)
499 maxlen = l1;
501 l1 = strlen (display_widgets [2].text);
502 if (l1 > maxlen)
503 maxlen = l1;
506 display_bits.xlen = (maxlen + 5) * 6 / 4;
508 /* See above confirm_box */
509 l1 = strlen (display_widgets [0].text) + 3;
510 i = strlen (display_widgets [1].text) + 5;
511 if (i > l1)
512 l1 = i;
514 i = (l1 + 3) * 6 / 2;
515 if (i > display_bits.xlen)
516 display_bits.xlen = i;
518 display_bits.title = _(display_bits.title);
519 i18n_flag = display_bits.i18n = 1;
522 #endif /* ENABLE_NLS */
524 if (full_eight_bits)
525 current_mode = 0;
526 else if (eight_bit_clean)
527 current_mode = 1;
528 else
529 current_mode = 2;
531 display_widgets [3].value = current_mode;
532 new_meta = !use_8th_bit_as_meta;
533 if (quick_dialog (&display_bits) != B_ENTER)
534 return;
536 eight_bit_clean = new_mode < 2;
537 full_eight_bits = new_mode == 0;
538 #ifndef HAVE_SLANG
539 meta (stdscr, eight_bit_clean);
540 #else
541 SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
542 #endif
543 use_8th_bit_as_meta = !new_meta;
547 #else /* HAVE_CHARSET */
550 static Dlg_head *dbits_dlg;
552 static void dbits_refresh()
554 attrset( COLOR_NORMAL );
555 dlg_erase( dbits_dlg );
557 draw_box( dbits_dlg, 1, 2, dbits_dlg->lines - 2, dbits_dlg->cols - 4 );
559 attrset( COLOR_HOT_NORMAL );
560 dlg_move( dbits_dlg, 1, (dbits_dlg->cols - strlen(dbits_dlg->title)) / 2 );
561 addstr( dbits_dlg->title );
564 static int dbits_callback( Dlg_head * h, int Par, int Msg )
566 switch (Msg) {
567 case DLG_DRAW:
568 dbits_refresh();
569 break;
571 return 0;
574 static int new_display_codepage;
576 static WLabel *cplabel;
577 static WCheck *inpcheck;
579 static int sel_charset_button( int action, void *param )
581 char *cpname, buf[64];
582 new_display_codepage = select_charset( new_display_codepage, 1 );
583 cpname = (new_display_codepage < 0)
584 ? _("Other 8 bit")
585 : codepages[ new_display_codepage ].name;
586 sprintf( buf, "%-27s", cpname ); /* avoid strange bug with label repainting */
587 label_set_text( cplabel, buf );
588 return 0;
591 void init_disp_bits_box()
593 char *cpname;
595 do_refresh();
597 dbits_dlg = create_dlg( 0, 0, DISPY, DISPX, dialog_colors,
598 dbits_callback, "[Display bits]", "Display bits",
599 DLG_CENTER );
600 x_set_dialog_title( dbits_dlg, _(" Display bits "));
602 add_widget( dbits_dlg,
603 label_new( 3, 4, _("Input / display codepage:"), NULL));
605 cpname = (new_display_codepage < 0)
606 ? "Other 8 bit"
607 : codepages[ new_display_codepage ].name;
608 cplabel = label_new( 4, 4, cpname, NULL);
609 add_widget( dbits_dlg, cplabel );
611 add_widget( dbits_dlg,
612 button_new( DISPY - 3, DISPX / 2 + 3, B_CANCEL,
613 NORMAL_BUTTON, _("&Cancel"), 0, 0, NULL ) );
614 add_widget( dbits_dlg,
615 button_new( DISPY - 3, 7, B_ENTER,
616 NORMAL_BUTTON, _("&Ok"), 0, 0, NULL ) );
618 inpcheck = check_new( 6, 4, !use_8th_bit_as_meta,
619 _("F&ull 8 bits input"), NULL );
620 add_widget( dbits_dlg, inpcheck );
622 cpname = _("&Select");
623 add_widget( dbits_dlg,
624 button_new( 4, DISPX - 8 - strlen(cpname) , B_USER,
625 NORMAL_BUTTON, cpname,
626 sel_charset_button, 0, NULL ) );
629 void display_bits_box()
631 new_display_codepage = display_codepage;
633 application_keypad_mode ();
634 init_disp_bits_box();
636 run_dlg( dbits_dlg );
638 if (dbits_dlg->ret_value == B_ENTER) {
639 char *errmsg;
640 display_codepage = new_display_codepage;
641 errmsg = init_translation_table( source_codepage, display_codepage );
642 if (errmsg)
643 message( 1, MSG_ERROR, "%s", errmsg );
644 #ifndef HAVE_SLANG
645 meta( stdscr, display_codepage != 0 );
646 #else
647 SLsmg_Display_Eight_Bit
648 = (display_codepage != 0 && display_codepage != 1) ? 128 : 160;
649 #endif
650 use_8th_bit_as_meta = ! (inpcheck->state & C_BOOL);
652 destroy_dlg( dbits_dlg );
653 repaint_screen();
656 #endif /* HAVE_CHARSET */
659 #define TREE_Y 20
660 #define TREE_X 60
662 static int tree_colors [4];
664 static int
665 tree_callback (struct Dlg_head *h, int id, int msg)
667 switch (msg){
669 case DLG_POST_KEY:
670 /* The enter key will be processed by the tree widget */
671 if (id == '\n' || ((WTree *)(h->current->widget))->done){
672 h->ret_value = B_ENTER;
673 dlg_stop (h);
675 return MSG_HANDLED;
677 case DLG_DRAW:
678 common_dialog_repaint (h);
679 break;
681 return MSG_NOT_HANDLED;
684 /* Show tree in a box, not on a panel */
685 char *
686 tree_box (char *current_dir)
688 WTree *mytree;
689 Dlg_head *dlg;
690 char *val;
691 WButtonBar *bar;
693 tree_colors [3] = dialog_colors [0];
694 tree_colors [1] = dialog_colors [1];
696 /* Create the components */
697 dlg = create_dlg (0, 0, TREE_Y, TREE_X, tree_colors,
698 tree_callback, "[Directory Tree]", "tree", DLG_CENTER);
699 mytree = tree_new (0, 2, 2, TREE_Y - 6, TREE_X - 5);
700 add_widget (dlg, mytree);
701 bar = buttonbar_new(1);
702 add_widget (dlg, bar);
703 bar->widget.x = 0;
704 bar->widget.y = LINES - 1;
706 run_dlg (dlg);
707 if (dlg->ret_value == B_ENTER)
708 val = g_strdup (mytree->selected_ptr->name);
709 else
710 val = 0;
712 destroy_dlg (dlg);
713 return val;
716 #ifdef USE_VFS
718 #if defined(USE_NETCODE)
719 #define VFSY 15
720 #define VFS_WIDGETBASE 8
721 #else
722 #define VFSY 8
723 #define VFS_WIDGETBASE 0
724 #endif
726 #define VFSX 56
728 static char *ret_timeout;
730 #if defined(USE_NETCODE)
731 static char *ret_passwd;
732 static char *ret_directory_timeout;
733 static char *ret_ftp_proxy;
734 static int ret_use_netrc;
735 #endif
737 static QuickWidget confvfs_widgets [] = {
738 { quick_button, 30, VFSX, VFSY - 3, VFSY, N_("&Cancel"),
739 0, B_CANCEL, 0, 0, "button-cancel" },
740 { quick_button, 12, VFSX, VFSY - 3, VFSY, N_("&Ok"),
741 0, B_ENTER, 0, 0, "button-ok" },
742 #if defined(USE_NETCODE)
743 { quick_checkbox, 4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), 0, 0,
744 &ret_use_netrc, 0, "check-use-netrc" },
745 { quick_input, 4, VFSX, 9, VFSY, "", 48, 0, 0, &ret_ftp_proxy,
746 "input-ftp-proxy" },
747 { quick_checkbox, 4, VFSX, 8, VFSY, N_("&Always use ftp proxy"), 0, 0,
748 &ftpfs_always_use_proxy, 0, "check-ftp-proxy" },
749 { quick_label, 49, VFSX, 7, VFSY, N_("sec"),
750 0, 0, 0, 0, "label-sec" },
751 { quick_input, 38, VFSX, 7, VFSY, "", 10, 0, 0, &ret_directory_timeout,
752 "input-timeout" },
753 { quick_label, 4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:"),
754 0, 0, 0, 0, "label-cache"},
755 { quick_input, 4, VFSX, 6, VFSY, "", 48, 0, 0, &ret_passwd,
756 "input-passwd" },
757 { quick_label, 4, VFSX, 5, VFSY, N_("ftp anonymous password:"),
758 0, 0, 0, 0, "label-pass"},
759 #endif
760 { quick_label, 49, VFSX, 3, VFSY, "sec",
761 0, 0, 0, 0, "label-sec2" },
762 { quick_input, 38, VFSX, 3, VFSY, "", 10, 0, 0, &ret_timeout,
763 "input-timo-vfs" },
764 { quick_label, 4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:"),
765 0, 0, 0, 0, "label-vfs" },
766 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
769 static QuickDialog confvfs_dlg =
770 { VFSX, VFSY, -1, -1, N_(" Virtual File System Setting "), "[Virtual FS]", "quick_vfs", confvfs_widgets, 0 };
772 void
773 configure_vfs (void)
775 char buffer2[BUF_TINY];
776 #if defined(USE_NETCODE)
777 char buffer3[BUF_TINY];
778 #endif
780 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
781 confvfs_widgets [3 + VFS_WIDGETBASE].text = buffer2;
782 #if defined(USE_NETCODE)
783 ret_use_netrc = use_netrc;
784 g_snprintf(buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
785 confvfs_widgets[6].text = buffer3;
786 confvfs_widgets[8].text = ftpfs_anonymous_passwd;
787 confvfs_widgets[3].text = ftpfs_proxy_host;
788 #endif
790 if (quick_dialog (&confvfs_dlg) != B_CANCEL) {
791 vfs_timeout = atoi (ret_timeout);
792 g_free (ret_timeout);
793 if (vfs_timeout < 0 || vfs_timeout > 10000)
794 vfs_timeout = 10;
795 #if defined(USE_NETCODE)
796 g_free (ftpfs_anonymous_passwd);
797 ftpfs_anonymous_passwd = ret_passwd;
798 if (ftpfs_proxy_host)
799 g_free (ftpfs_proxy_host);
800 ftpfs_proxy_host = ret_ftp_proxy;
801 ftpfs_directory_timeout = atoi(ret_directory_timeout);
802 use_netrc = ret_use_netrc;
803 g_free (ret_directory_timeout);
804 #endif
808 #endif
810 char *
811 cd_dialog (void)
813 QuickDialog Quick_input;
814 QuickWidget quick_widgets [] = {
815 { quick_input, 6, 57, 5, 0, "", 50, 0, 0, 0, "input" },
816 { quick_label, 3, 57, 2, 0, "", 0, 0, 0, 0, "label" },
817 { 0 } };
819 char *my_str;
820 int len;
822 Quick_input.xlen = 57;
823 Quick_input.title = _("Quick cd");
824 Quick_input.help = "[Quick cd]";
825 Quick_input.class = "quick_input";
826 quick_widgets [0].text = "";
827 quick_widgets [0].value = 2; /* want cd like completion */
828 quick_widgets [1].text = _("cd");
829 quick_widgets [1].y_divisions =
830 quick_widgets [0].y_divisions = Quick_input.ylen = 5;
832 len = strlen (quick_widgets [1].text);
834 quick_widgets [1].relative_x = 3;
835 quick_widgets [0].relative_x =
836 quick_widgets [1].relative_x + len + 1;
838 Quick_input.xlen = len + quick_widgets [0].hotkey_pos + 7;
839 quick_widgets [0].x_divisions =
840 quick_widgets [1].x_divisions = Quick_input.xlen;
842 Quick_input.i18n = 1;
843 Quick_input.xpos = 2;
844 Quick_input.ypos = LINES - 2 - Quick_input.ylen;
845 quick_widgets [0].relative_y = 2;
846 quick_widgets [0].str_result = &my_str;
848 Quick_input.widgets = quick_widgets;
849 if (quick_dialog (&Quick_input) != B_CANCEL){
850 return *(quick_widgets [0].str_result);
851 } else
852 return 0;
855 void
856 symlink_dialog (char *existing, char *new, char **ret_existing, char **ret_new)
858 QuickDialog Quick_input;
859 QuickWidget quick_widgets [] = {
860 { quick_input, 4, 80, 5, 8, "", 58, 0, 0, 0, "input-1" },
861 { quick_label, 4, 80, 4, 8, "", 0, 0, 0, 0, "label-1" },
862 { quick_input, 4, 80, 3, 8, "", 58, 0, 0, 0, "input-2" },
863 { quick_label, 4, 80, 2, 8, "", 0, 0, 0, 0, "label-2" },
864 { 0 } };
866 Quick_input.xlen = 64;
867 Quick_input.ylen = 8;
868 Quick_input.title = _("Symbolic link");
869 Quick_input.help = "[File Menu]";
870 Quick_input.class = "quick_symlink";
871 Quick_input.i18n = 0;
872 quick_widgets [0].text = new;
873 quick_widgets [1].text = _("Symbolic link filename:");
874 quick_widgets [2].text = existing;
875 quick_widgets [3].text = _("Existing filename (filename symlink will point to):");
876 Quick_input.xpos = -1;
877 quick_widgets [0].str_result = ret_new;
878 quick_widgets [2].str_result = ret_existing;
880 Quick_input.widgets = quick_widgets;
881 if (quick_dialog (&Quick_input) == B_CANCEL){
882 *ret_new = NULL;
883 *ret_existing = NULL;
887 #ifdef WITH_BACKGROUND
888 #define B_STOP B_USER+1
889 #define B_RESUME B_USER+2
890 #define B_KILL B_USER+3
892 static int JOBS_X = 60;
893 #define JOBS_Y 15
894 static WListbox *bg_list;
895 static Dlg_head *jobs_dlg;
897 static void
898 jobs_fill_listbox (void)
900 static char *state_str [2];
901 TaskList *tl = task_list;
903 if (!state_str [0]){
904 state_str [0] = _("Running ");
905 state_str [1] = _("Stopped");
908 while (tl){
909 char *s;
911 s = g_strconcat (state_str [tl->state], " ", tl->info, NULL);
912 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
913 g_free (s);
914 tl = tl->next;
918 static int
919 task_cb (int action, void *ignored)
921 TaskList *tl;
922 int sig = 0;
924 if (!bg_list->list)
925 return 0;
927 /* Get this instance information */
928 tl = (TaskList *) bg_list->current->data;
930 # ifdef SIGTSTP
931 if (action == B_STOP){
932 sig = SIGSTOP;
933 tl->state = Task_Stopped;
934 } else if (action == B_RESUME){
935 sig = SIGCONT;
936 tl->state = Task_Running;
937 } else
938 # endif
939 if (action == B_KILL){
940 sig = SIGKILL;
943 if (sig == SIGINT)
944 unregister_task_running (tl->pid, tl->fd);
946 kill (tl->pid, sig);
947 listbox_remove_list (bg_list);
948 jobs_fill_listbox ();
950 /* This can be optimized to just redraw this widget :-) */
951 dlg_redraw (jobs_dlg);
953 return 0;
956 static struct
958 char* name;
959 int xpos;
960 int value;
961 int (*callback)(int, void *);
962 char* tkname;
964 job_buttons [] =
966 {N_("&Stop"), 3, B_STOP, task_cb, "button-stop"},
967 {N_("&Resume"), 12, B_RESUME, task_cb, "button-cont"},
968 {N_("&Kill"), 23, B_KILL, task_cb, "button-kill"},
969 {N_("&Ok"), 35, B_CANCEL, NULL, "button-ok"},
972 void
973 jobs_cmd (void)
975 register int i;
976 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
978 #ifdef ENABLE_NLS
979 static int i18n_flag = 0;
980 if (!i18n_flag)
982 int startx = job_buttons [0].xpos;
983 int len;
985 for (i = 0; i < n_buttons; i++)
987 job_buttons [i].name = _(job_buttons [i].name);
989 len = strlen (job_buttons [i].name) + 4;
990 JOBS_X = max (JOBS_X, startx + len + 3);
992 job_buttons [i].xpos = startx;
993 startx += len;
996 /* Last button - Ok a.k.a. Cancel :) */
997 job_buttons [n_buttons - 1].xpos =
998 JOBS_X - strlen (job_buttons [n_buttons - 1].name) - 7;
1000 i18n_flag = 1;
1002 #endif /* ENABLE_NLS */
1004 jobs_dlg = create_dlg (0, 0, JOBS_Y, JOBS_X, dialog_colors,
1005 common_dialog_callback, "[Background jobs]", "jobs",
1006 DLG_CENTER);
1007 x_set_dialog_title (jobs_dlg, _("Background Jobs"));
1009 bg_list = listbox_new (2, 3, JOBS_X-7, JOBS_Y-9, listbox_nothing, 0, "listbox");
1010 add_widget (jobs_dlg, bg_list);
1012 i = n_buttons;
1013 while (i--)
1015 add_widget (jobs_dlg, button_new (JOBS_Y-4,
1016 job_buttons [i].xpos, job_buttons [i].value,
1017 NORMAL_BUTTON, job_buttons [i].name,
1018 job_buttons [i].callback, 0,
1019 job_buttons [i].tkname));
1022 /* Insert all of task information in the list */
1023 jobs_fill_listbox ();
1024 run_dlg (jobs_dlg);
1026 destroy_dlg (jobs_dlg);
1028 #endif /* WITH_BACKGROUND */
1030 #ifdef WITH_SMBFS
1031 struct smb_authinfo *
1032 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
1033 const char *user)
1035 static int dialog_x = 44;
1036 int dialog_y = 12;
1037 struct smb_authinfo *return_value;
1038 static char* labs[] = {N_("Domain:"), N_("Username:"), N_("Password: ")};
1039 static char* buts[] = {N_("&Ok"), N_("&Cancel")};
1040 static int ilen = 30, istart = 14;
1041 static int b0 = 3, b2 = 30;
1042 char *title;
1043 WInput *in_password;
1044 WInput *in_user;
1045 WInput *in_domain;
1046 Dlg_head *auth_dlg;
1048 #ifdef ENABLE_NLS
1049 static int i18n_flag = 0;
1051 if (!i18n_flag)
1053 register int i = sizeof(labs)/sizeof(labs[0]);
1054 int l1, maxlen = 0;
1056 while (i--)
1058 l1 = strlen (labs [i] = _(labs [i]));
1059 if (l1 > maxlen)
1060 maxlen = l1;
1062 i = maxlen + ilen + 7;
1063 if (i > dialog_x)
1064 dialog_x = i;
1066 for (i = sizeof(buts)/sizeof(buts[0]), l1 = 0; i--; )
1068 l1 += strlen (buts [i] = _(buts [i]));
1070 l1 += 15;
1071 if (l1 > dialog_x)
1072 dialog_x = l1;
1074 ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
1075 istart = dialog_x - 3 - ilen;
1077 b2 = dialog_x - (strlen(buts[1]) + 6);
1079 i18n_flag = 1;
1082 #endif /* ENABLE_NLS */
1084 if (!domain)
1085 domain = "";
1086 if (!user)
1087 user = "";
1089 auth_dlg = create_dlg (0, 0, dialog_y, dialog_x, dialog_colors,
1090 common_dialog_callback, "[Smb Authinfo]", "smbauthinfo",
1091 DLG_CENTER);
1093 title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1094 x_set_dialog_title (auth_dlg, title);
1095 g_free (title);
1097 in_user = input_new (5, istart, INPUT_COLOR, ilen, user, "auth_name");
1098 add_widget (auth_dlg, in_user);
1100 in_domain = input_new (3, istart, INPUT_COLOR, ilen, domain, "auth_domain");
1101 add_widget (auth_dlg, in_domain);
1102 add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON,
1103 buts[1], 0 ,0, "cancel"));
1104 add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON,
1105 buts[0], 0, 0, "ok"));
1107 in_password = input_new (7, istart, INPUT_COLOR, ilen, "", "auth_password");
1108 in_password->completion_flags = 0;
1109 in_password->is_password = 1;
1110 add_widget (auth_dlg, in_password);
1112 add_widget (auth_dlg, label_new (7, 3, labs[2], "label-passwd"));
1113 add_widget (auth_dlg, label_new (5, 3, labs[1], "label-user"));
1114 add_widget (auth_dlg, label_new (3, 3, labs[0], "label-domain"));
1116 run_dlg (auth_dlg);
1118 switch (auth_dlg->ret_value) {
1119 case B_CANCEL:
1120 return_value = 0;
1121 break;
1122 default:
1123 return_value = g_new (struct smb_authinfo, 1);
1124 if (return_value) {
1125 return_value->host = g_strdup (host);
1126 return_value->share = g_strdup (share);
1127 return_value->domain = g_strdup (in_domain->buffer);
1128 return_value->user = g_strdup (in_user->buffer);
1129 return_value->password = g_strdup (in_password->buffer);
1133 destroy_dlg (auth_dlg);
1135 return return_value;
1137 #endif /* WITH_SMBFS */