Codepage messages related translated & other stuff...
[midnight-commander.git] / src / boxes.c
blob0b6dc48f86750dcdba2f518da9a39bf4dacc845e
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 "tty.h"
24 #include <string.h>
25 #include <stdio.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <sys/param.h>
29 #include <signal.h>
30 #include <ctype.h>
31 #include "global.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"
50 #include "x.h"
52 #ifdef HAVE_CHARSET
53 #include "charsets.h"
54 #include "selcodepage.h"
55 #endif
57 static int DISPLAY_X = 45, DISPLAY_Y = 14;
59 static Dlg_head *dd;
60 static WRadio *my_radio;
61 static WInput *user;
62 static WInput *status;
63 static WCheck *check_status;
64 static int current_mode;
65 extern int ftpfs_always_use_proxy;
67 static char **displays_status;
68 static char* display_title = N_(" Listing mode ");
70 /* Controls whether the array strings have been translated */
71 static int i18n_displays_flag;
72 static char *displays [LIST_TYPES] = {
73 N_("&Full file list"),
74 N_("&Brief file list"),
75 N_("&Long file list"),
76 N_("&User defined:"),
77 N_("&Icon view"),
80 static int user_hotkey = 'u';
82 static int
83 display_callback (struct Dlg_head *h, int id, int Msg)
85 switch (Msg){
86 case DLG_DRAW:
87 attrset (COLOR_NORMAL);
88 dlg_erase (h);
89 draw_box (h, 1, 2, h->lines - 2, h->cols - 4);
91 attrset (COLOR_HOT_NORMAL);
92 dlg_move (h, 1, (h->cols - strlen(display_title))/2);
93 addstr (display_title);
94 attrset (COLOR_NORMAL);
95 break;
97 case DLG_UNFOCUS:
98 if((WRadio *) h->current->widget == my_radio){
99 assign_text (status, displays_status [my_radio->sel]);
100 input_set_point (status, 0);
102 break;
104 case DLG_KEY:
105 if (id == '\n'){
106 if((WRadio *) h->current->widget == my_radio){
107 assign_text (status, displays_status [my_radio->sel]);
108 dlg_stop (h);
109 break;
112 if ((WInput *) h->current->widget == user){
113 h->ret_value = B_USER + 6;
114 dlg_stop (h);
115 break;
118 if ((WInput *) h->current->widget == status){
119 h->ret_value = B_USER + 7;
120 dlg_stop (h);
121 break;
125 if (tolower(id) == user_hotkey && h->current->widget != (Widget *) user
126 && h->current->widget != (Widget *) status){
127 my_radio->sel = 3;
128 dlg_select_widget (h, my_radio); /* force redraw */
129 dlg_select_widget (h, user);
130 return MSG_HANDLED;
133 return MSG_NOT_HANDLED;
136 static void
137 display_init (int radio_sel, char *init_text,
138 int _check_status, char ** _status)
140 char* user_mini_status = _("user &Mini status");
141 char* ok_button = _("&Ok");
142 char* cancel_button = _("&Cancel");
144 static int button_start = 30;
146 displays_status = _status;
148 if (!i18n_displays_flag){
149 int i, l, maxlen = 0;
150 char* cp;
152 display_title = _(display_title);
153 for (i = 0; i < LIST_TYPES; i++)
155 displays [i] = _(displays [i]);
156 if ((l = strlen(displays [i])) > maxlen)
157 maxlen = l;
160 i = strlen (ok_button) + 5;
161 l = strlen (cancel_button) + 3;
162 l = max(i, l);
164 i = maxlen + l + 16;
165 if (i > DISPLAY_X)
166 DISPLAY_X = i;
168 i = strlen (user_mini_status) + 13;
169 if (i > DISPLAY_X)
170 DISPLAY_X = i;
172 i = strlen (display_title) + 8;
173 if (i > DISPLAY_X)
174 DISPLAY_X = i;
176 button_start = DISPLAY_X - l - 5;
178 /* get hotkey of user-defined format string */
179 cp = strchr(displays[LIST_TYPES-1],'&');
180 if (cp != NULL && *++cp != '\0')
181 user_hotkey = tolower(*cp);
183 i18n_displays_flag = 1;
185 dd = create_dlg (0, 0, DISPLAY_Y, DISPLAY_X, dialog_colors,
186 display_callback, "[Left and Right Menus]", "display",
187 DLG_CENTER | DLG_GRID);
189 x_set_dialog_title (dd, _("Listing mode"));
190 add_widget (dd,
191 button_new (4, button_start, B_CANCEL,
192 NORMAL_BUTTON, cancel_button, 0, 0, "cancel-button"));
194 add_widget (dd,
195 button_new (3, button_start, B_ENTER,
196 DEFPUSH_BUTTON, ok_button, 0, 0, "ok-button"));
198 status = input_new (10, 9, INPUT_COLOR, DISPLAY_X-14, _status [radio_sel], "mini-input");
199 add_widget (dd, status);
200 input_set_point (status, 0);
202 check_status = check_new (9, 5, _check_status, user_mini_status, "mini-status");
203 add_widget (dd, check_status);
205 user = input_new (7, 9, INPUT_COLOR, DISPLAY_X-14, init_text, "user-fmt-input");
206 add_widget (dd, user);
207 input_set_point (user, 0);
209 my_radio = radio_new (3, 5, LIST_TYPES-1, displays, 1, "radio");
210 my_radio->sel = my_radio->pos = current_mode;
211 add_widget (dd, my_radio);
215 display_box (WPanel *panel, char **userp, char **minip, int *use_msformat, int num)
217 int result, i;
218 char *section = NULL;
219 char *p;
221 if (!panel) {
222 p = get_nth_panel_name (num);
223 panel = g_new (WPanel, 1);
224 panel->list_type = list_full;
225 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
226 panel->user_mini_status = 0;
227 for (i = 0; i < LIST_TYPES; i++)
228 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
229 section = g_strconcat ("Temporal:", p, NULL);
230 if (!profile_has_section (section, profile_name)) {
231 g_free (section);
232 section = g_strdup (p);
234 panel_load_setup (panel, section);
235 g_free (section);
238 current_mode = panel->list_type;
239 display_init (current_mode, panel->user_format,
240 panel->user_mini_status, panel->user_status_format);
242 run_dlg (dd);
244 result = -1;
246 if (section) {
247 g_free (panel->user_format);
248 for (i = 0; i < LIST_TYPES; i++)
249 g_free (panel->user_status_format [i]);
250 g_free (panel);
253 if (dd->ret_value != B_CANCEL){
254 result = my_radio->sel;
255 *userp = g_strdup (user->buffer);
256 *minip = g_strdup (status->buffer);
257 *use_msformat = check_status->state & C_BOOL;
259 destroy_dlg (dd);
261 return result;
264 int SORT_X = 40, SORT_Y = 14;
266 char *sort_orders_names [SORT_TYPES];
268 sortfn *
269 sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive)
271 int i, r, l;
272 sortfn *result;
273 WCheck *c, *case_sense;
275 char* ok_button = _("&Ok");
276 char* cancel_button = _("&Cancel");
277 char* reverse_label = _("&Reverse");
278 char* case_label = _("case sensi&tive");
279 char* sort_title = _("Sort order");
281 static int i18n_sort_flag = 0, check_pos = 0, button_pos = 0;
283 if (!i18n_sort_flag)
285 int maxlen = 0;
286 for (i = SORT_TYPES-1; i >= 0; i--)
288 sort_orders_names [i] = _(sort_orders [i].sort_name);
289 r = strlen (sort_orders_names [i]);
290 if (r > maxlen)
291 maxlen = r;
294 check_pos = maxlen + 9;
296 r = strlen (reverse_label) + 4;
297 i = strlen (case_label) + 4;
298 if (i > r)
299 r = i;
301 l = strlen (ok_button) + 6;
302 i = strlen (cancel_button) + 4;
303 if (i > l)
304 l = i;
306 i = check_pos + max(r,l) + 2;
308 if (i > SORT_X)
309 SORT_X = i;
311 i = strlen (sort_title) + 6;
312 if (i > SORT_X)
313 SORT_X = i;
315 button_pos = SORT_X - l - 2;
317 i18n_sort_flag = 1;
320 result = 0;
322 for (i = 0; i < SORT_TYPES; i++)
323 if ((sortfn *) (sort_orders [i].sort_fn) == sort_fn){
324 current_mode = i;
325 break;
328 dd = create_dlg (0, 0, SORT_Y, SORT_X, dialog_colors, common_dialog_callback,
329 "[Left and Right Menus]", "sort", DLG_CENTER | DLG_GRID);
331 x_set_dialog_title (dd, sort_title);
333 add_widget (dd,
334 button_new (10, button_pos, B_CANCEL, NORMAL_BUTTON, cancel_button,
335 0, 0, "cancel-button"));
337 add_widget (dd,
338 button_new (9, button_pos, B_ENTER, DEFPUSH_BUTTON, ok_button,
339 0, 0, "ok-button"));
341 case_sense = check_new (4, check_pos, *case_sensitive, case_label, "case-check");
342 add_widget (dd, case_sense);
343 c = check_new (3, check_pos, *reverse, reverse_label, "reverse-check");
344 add_widget (dd, c);
346 my_radio = radio_new (3, 3, SORT_TYPES, sort_orders_names, 1, "radio-1");
347 my_radio->sel = my_radio->pos = current_mode;
349 add_widget (dd, my_radio);
350 run_dlg (dd);
352 r = dd->ret_value;
353 if (r != B_CANCEL){
354 result = (sortfn *) sort_orders [my_radio->sel].sort_fn;
355 *reverse = c->state & C_BOOL;
356 *case_sensitive = case_sense->state & C_BOOL;
357 } else
358 result = sort_fn;
359 destroy_dlg (dd);
361 return result;
364 #define CONFY 10
365 #define CONFX 46
367 static int my_delete;
368 static int my_overwrite;
369 static int my_execute;
370 static int my_exit;
372 static QuickWidget conf_widgets [] = {
373 { quick_button, 4, 6, 4, CONFY, N_("&Cancel"),
374 0, B_CANCEL, 0, 0, "c" },
375 { quick_button, 4, 6, 3, CONFY, N_("&Ok"),
376 0, B_ENTER, 0, 0, "o" },
378 { quick_checkbox, 1, 13, 6, CONFY, N_(" confirm &Exit "),
379 9, 0, &my_exit, 0, "e" },
380 { quick_checkbox, 1, 13, 5, CONFY, N_(" confirm e&Xecute "),
381 10, 0, &my_execute, 0, "x" },
382 { quick_checkbox, 1, 13, 4, CONFY, N_(" confirm o&Verwrite "),
383 10, 0, &my_overwrite, 0, "ov" },
384 { quick_checkbox, 1, 13, 3, CONFY, N_(" confirm &Delete "),
385 9, 0, &my_delete, 0, "de" },
386 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
389 static QuickDialog confirmation =
390 { CONFX, CONFY, -1, -1, N_(" Confirmation "), "[Confirmation]", "quick_confirm",
391 conf_widgets, 0 };
393 void
394 confirm_box ()
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 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 "dbits", display_widgets, 0 };
479 void
480 display_bits_box ()
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 Dlg_head *dbits_dlg;
549 static char* dbits_title = N_(" Display bits ");
551 #ifndef HAVE_X
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_title)) / 2 );
561 addstr( dbits_title );
563 #endif /* HAVE_X */
565 static int dbits_callback( Dlg_head * h, int Par, int Msg )
567 #ifndef HAVE_X
568 switch (Msg) {
569 case DLG_DRAW:
570 dbits_refresh();
571 break;
573 #endif /* HAVE_X */
574 return 0;
577 static int new_display_codepage;
579 WLabel *cplabel;
580 WCheck *inpcheck;
582 static int sel_charset_button( int action, void *param )
584 char *cpname, buf[64];
585 new_display_codepage = select_charset( new_display_codepage, 1 );
586 cpname = (new_display_codepage < 0)
587 ? "Other 8 bit"
588 : codepages[ new_display_codepage ].name;
589 sprintf( buf, "%-27s", cpname ); /* avoid strange bug with label repainting */
590 label_set_text( cplabel, buf );
591 return 0;
594 void init_disp_bits_box()
596 char *cpname;
598 do_refresh();
600 dbits_dlg = create_dlg( 0, 0, DISPY, DISPX, dialog_colors,
601 dbits_callback, "[Display bits]", "Display bits",
602 DLG_CENTER );
603 x_set_dialog_title( dbits_dlg, dbits_title );
605 add_widget( dbits_dlg,
606 label_new( 3, 4, _("Input / display codepage:"), NULL));
608 cpname = (new_display_codepage < 0)
609 ? "Other 8 bit"
610 : codepages[ new_display_codepage ].name;
611 cplabel = label_new( 4, 4, cpname, NULL);
612 add_widget( dbits_dlg, cplabel );
614 add_widget( dbits_dlg,
615 button_new( DISPY - 3, DISPX / 2 + 3, B_CANCEL,
616 NORMAL_BUTTON, _("&Cancel"), 0, 0, NULL ) );
617 add_widget( dbits_dlg,
618 button_new( DISPY - 3, 7, B_ENTER,
619 NORMAL_BUTTON, _("&Ok"), 0, 0, NULL ) );
621 inpcheck = check_new( 6, 4, !use_8th_bit_as_meta,
622 _("F&ull 8 bits input"), NULL );
623 add_widget( dbits_dlg, inpcheck );
625 cpname = _("&Select");
626 add_widget( dbits_dlg,
627 button_new( 4, DISPX - 8 - strlen(cpname) , B_USER,
628 NORMAL_BUTTON, cpname,
629 sel_charset_button, 0, NULL ) );
632 void display_bits_box()
634 new_display_codepage = display_codepage;
636 #ifndef HAVE_X
637 application_keypad_mode ();
638 #endif
639 init_disp_bits_box();
641 run_dlg( dbits_dlg );
643 if (dbits_dlg->ret_value == B_ENTER) {
644 char *errmsg;
645 display_codepage = new_display_codepage;
646 errmsg = init_translation_table( source_codepage, display_codepage );
647 if (errmsg)
648 message( 1, MSG_ERROR, "%s", errmsg );
649 #ifndef HAVE_X
650 #ifndef HAVE_SLANG
651 meta( stdscr, display_codepage != 0 );
652 #else
653 SLsmg_Display_Eight_Bit
654 = (display_codepage != 0 && display_codepage != 1) ? 128 : 160;
655 #endif
656 #endif
657 use_8th_bit_as_meta = ! (inpcheck->state & C_BOOL);
659 destroy_dlg( dbits_dlg );
660 repaint_screen();
663 #endif /* HAVE_CHARSET */
666 #define TREE_Y 20
667 #define TREE_X 60
669 static int tree_colors [4];
671 static int
672 tree_callback (struct Dlg_head *h, int id, int msg)
674 switch (msg){
676 case DLG_POST_KEY:
677 /* The enter key will be processed by the tree widget */
678 if (id == '\n' || ((WTree *)(h->current->widget))->done){
679 h->ret_value = B_ENTER;
680 dlg_stop (h);
682 return MSG_HANDLED;
684 case DLG_DRAW:
685 common_dialog_repaint (h);
686 break;
688 return MSG_NOT_HANDLED;
691 char *
692 tree (char *current_dir)
694 WTree *mytree;
695 Dlg_head *dlg;
696 char *val;
697 WButtonBar *bar;
699 tree_colors [3] = dialog_colors [0];
700 tree_colors [1] = dialog_colors [1];
702 /* Create the components */
703 dlg = create_dlg (0, 0, TREE_Y, TREE_X, tree_colors,
704 tree_callback, "[Directory Tree]", "tree", DLG_CENTER);
705 mytree = tree_new (0, 2, 2, TREE_Y - 6, TREE_X - 5);
706 add_widget (dlg, mytree);
707 bar = buttonbar_new(1);
708 add_widget (dlg, bar);
709 bar->widget.x = 0;
710 bar->widget.y = LINES - 1;
712 run_dlg (dlg);
713 if (dlg->ret_value == B_ENTER)
714 val = g_strdup (mytree->selected_ptr->name);
715 else
716 val = 0;
718 destroy_dlg (dlg);
719 return val;
722 #ifdef USE_VFS
724 #if defined(USE_NETCODE)
725 #define VFSY 14
726 #else
727 #define VFSY 8
728 #endif
730 #define VFSX 56
732 extern int vfs_timeout;
733 extern int ftpfs_always_use_proxy;
735 #if defined(USE_NETCODE)
736 extern char *ftpfs_anonymous_passwd;
737 extern char *ftpfs_proxy_host;
738 extern int use_netrc;
739 #endif
741 static char *ret_timeout;
743 #if defined(USE_NETCODE)
744 static char *ret_passwd;
745 static char *ret_directory_timeout;
746 static char *ret_ftp_proxy;
747 static int ret_use_netrc;
748 #endif
750 #if 0
751 /* Not used currently */
752 { quick_checkbox, 4, VFSX, 10, VFSY, "Use ~/.netrc",
753 'U', 0, 0, &ret_use_netrc, 0, "" },
754 #endif
756 static QuickWidget confvfs_widgets [] = {
757 { quick_button, 30, VFSX, VFSY - 3, VFSY, N_("&Cancel"),
758 0, B_CANCEL, 0, 0, "button-cancel" },
759 { quick_button, 12, VFSX, VFSY - 3, VFSY, N_("&Ok"),
760 0, B_ENTER, 0, 0, "button-ok" },
761 #if defined(USE_NETCODE)
762 { quick_input, 4, VFSX, 9, VFSY, "", 48, 0, 0, &ret_ftp_proxy,
763 "input-ftp-proxy" },
764 { quick_checkbox, 4, VFSX, 8, VFSY, N_("&Always use ftp proxy"), 0, 0,
765 &ftpfs_always_use_proxy, 0, "check-ftp-proxy" },
766 { quick_label, 49, VFSX, 7, VFSY, N_("sec"),
767 0, 0, 0, 0, "label-sec" },
768 { quick_input, 38, VFSX, 7, VFSY, "", 10, 0, 0, &ret_directory_timeout,
769 "input-timeout" },
770 { quick_label, 4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:"),
771 0, 0, 0, 0, "label-cache"},
772 { quick_input, 4, VFSX, 6, VFSY, "", 48, 0, 0, &ret_passwd,
773 "input-passwd" },
774 { quick_label, 4, VFSX, 5, VFSY, N_("ftp anonymous password:"),
775 0, 0, 0, 0, "label-pass"},
776 #endif
777 { quick_label, 49, VFSX, 3, VFSY, "sec",
778 0, 0, 0, 0, "label-sec2" },
779 { quick_input, 38, VFSX, 3, VFSY, "", 10, 0, 0, &ret_timeout,
780 "input-timo-vfs" },
781 { quick_label, 4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:"),
782 0, 0, 0, 0, "label-vfs" },
783 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
786 static QuickDialog confvfs_dlg =
787 { VFSX, VFSY, -1, -1, N_(" Virtual File System Setting "), "[Virtual FS]", "quick_vfs", confvfs_widgets, 0 };
789 #if defined(USE_NETCODE)
790 #define VFS_WIDGETBASE 7
791 #else
792 #define VFS_WIDGETBASE 0
793 #endif
795 void
796 configure_vfs (void)
798 char buffer2[BUF_TINY];
799 #if defined(USE_NETCODE)
800 char buffer3[BUF_TINY];
801 #endif
803 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
804 confvfs_widgets [3 + VFS_WIDGETBASE].text = buffer2;
805 #if defined(USE_NETCODE)
806 ret_use_netrc = use_netrc;
807 g_snprintf(buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
808 confvfs_widgets[5].text = buffer3;
809 confvfs_widgets[7].text = ftpfs_anonymous_passwd;
810 confvfs_widgets[2].text = ftpfs_proxy_host;
811 #endif
813 if (quick_dialog (&confvfs_dlg) != B_CANCEL) {
814 vfs_timeout = atoi (ret_timeout);
815 g_free (ret_timeout);
816 if (vfs_timeout < 0 || vfs_timeout > 10000)
817 vfs_timeout = 10;
818 #if defined(USE_NETCODE)
819 g_free (ftpfs_anonymous_passwd);
820 ftpfs_anonymous_passwd = ret_passwd;
821 if (ftpfs_proxy_host)
822 g_free (ftpfs_proxy_host);
823 ftpfs_proxy_host = ret_ftp_proxy;
824 ftpfs_directory_timeout = atoi(ret_directory_timeout);
825 use_netrc = ret_use_netrc;
826 g_free (ret_directory_timeout);
827 #endif
831 #endif
833 char *
834 cd_dialog (void)
836 QuickDialog Quick_input;
837 QuickWidget quick_widgets [] = {
838 { quick_input, 6, 57, 5, 0, "", 50, 0, 0, 0, "input" },
839 { quick_label, 3, 57, 2, 0, "", 0, 0, 0, 0, "label" },
840 { 0 } };
842 char *my_str;
843 int len;
845 Quick_input.xlen = 57;
846 Quick_input.title = _("Quick cd");
847 Quick_input.help = "[Quick cd]";
848 Quick_input.class = "quick_input";
849 quick_widgets [0].text = "";
850 quick_widgets [0].value = 2; /* want cd like completion */
851 quick_widgets [1].text = _("cd");
852 quick_widgets [1].y_divisions =
853 quick_widgets [0].y_divisions = Quick_input.ylen = 5;
855 len = strlen (quick_widgets [1].text);
857 quick_widgets [1].relative_x = 3;
858 quick_widgets [0].relative_x =
859 quick_widgets [1].relative_x + len + 1;
861 Quick_input.xlen = len + quick_widgets [0].hotkey_pos + 7;
862 quick_widgets [0].x_divisions =
863 quick_widgets [1].x_divisions = Quick_input.xlen;
865 Quick_input.i18n = 1;
866 Quick_input.xpos = 2;
867 Quick_input.ypos = LINES - 2 - Quick_input.ylen;
868 quick_widgets [0].relative_y = 2;
869 quick_widgets [0].str_result = &my_str;
871 Quick_input.widgets = quick_widgets;
872 if (quick_dialog (&Quick_input) != B_CANCEL){
873 return *(quick_widgets [0].str_result);
874 } else
875 return 0;
878 void
879 symlink_dialog (char *existing, char *new, char **ret_existing, char **ret_new)
881 QuickDialog Quick_input;
882 QuickWidget quick_widgets [] = {
883 { quick_input, 4, 80, 5, 8, "", 58, 0, 0, 0, "input-1" },
884 { quick_label, 4, 80, 4, 8, "", 0, 0, 0, 0, "label-1" },
885 { quick_input, 4, 80, 3, 8, "", 58, 0, 0, 0, "input-2" },
886 { quick_label, 4, 80, 2, 8, "", 0, 0, 0, 0, "label-2" },
887 { 0 } };
889 Quick_input.xlen = 64;
890 Quick_input.ylen = 8;
891 Quick_input.title = _("Symbolic link");
892 Quick_input.help = "[File Menu]";
893 Quick_input.class = "quick_symlink";
894 Quick_input.i18n = 0;
895 quick_widgets [0].text = new;
896 quick_widgets [1].text = _("Symbolic link filename:");
897 quick_widgets [2].text = existing;
898 quick_widgets [3].text = _("Existing filename (filename symlink will point to):");
899 Quick_input.xpos = -1;
900 quick_widgets [0].str_result = ret_new;
901 quick_widgets [2].str_result = ret_existing;
903 Quick_input.widgets = quick_widgets;
904 if (quick_dialog (&Quick_input) == B_CANCEL){
905 *ret_new = NULL;
906 *ret_existing = NULL;
910 #ifdef WITH_BACKGROUND
911 #define B_STOP B_USER+1
912 #define B_RESUME B_USER+2
913 #define B_KILL B_USER+3
915 static int JOBS_X = 60;
916 #define JOBS_Y 15
917 static WListbox *bg_list;
918 static Dlg_head *jobs_dlg;
920 static void
921 jobs_fill_listbox (void)
923 static char *state_str [2];
924 TaskList *tl = task_list;
926 if (!state_str [0]){
927 state_str [0] = _("Running ");
928 state_str [1] = _("Stopped");
931 while (tl){
932 char *s;
934 s = g_strconcat (state_str [tl->state], " ", tl->info, NULL);
935 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
936 g_free (s);
937 tl = tl->next;
941 static int
942 task_cb (int action, void *ignored)
944 TaskList *tl;
945 int sig = 0;
947 if (!bg_list->list)
948 return 0;
950 /* Get this instance information */
951 tl = (TaskList *) bg_list->current->data;
953 # ifdef SIGTSTP
954 if (action == B_STOP){
955 sig = SIGSTOP;
956 tl->state = Task_Stopped;
957 } else if (action == B_RESUME){
958 sig = SIGCONT;
959 tl->state = Task_Running;
960 } else
961 # endif
962 if (action == B_KILL){
963 sig = SIGKILL;
966 if (sig == SIGINT)
967 unregister_task_running (tl->pid, tl->fd);
969 kill (tl->pid, sig);
970 listbox_remove_list (bg_list);
971 jobs_fill_listbox ();
973 /* This can be optimized to just redraw this widget :-) */
974 dlg_redraw (jobs_dlg);
976 return 0;
979 static struct
981 char* name;
982 int xpos;
983 int value;
984 int (*callback)();
985 char* tkname;
987 job_buttons [] =
989 {N_("&Stop"), 3, B_STOP, task_cb, "button-stop"},
990 {N_("&Resume"), 12, B_RESUME, task_cb, "button-cont"},
991 {N_("&Kill"), 23, B_KILL, task_cb, "button-kill"},
992 {N_("&Ok"), 35, B_CANCEL, NULL, "button-ok"},
995 void
996 jobs_cmd (void)
998 register int i;
999 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
1001 #ifdef ENABLE_NLS
1002 static int i18n_flag = 0;
1003 if (!i18n_flag)
1005 int startx = job_buttons [0].xpos;
1006 int len;
1008 for (i = 0; i < n_buttons; i++)
1010 job_buttons [i].name = _(job_buttons [i].name);
1012 len = strlen (job_buttons [i].name) + 4;
1013 JOBS_X = max (JOBS_X, startx + len + 3);
1015 job_buttons [i].xpos = startx;
1016 startx += len;
1019 /* Last button - Ok a.k.a. Cancel :) */
1020 job_buttons [n_buttons - 1].xpos =
1021 JOBS_X - strlen (job_buttons [n_buttons - 1].name) - 7;
1023 i18n_flag = 1;
1025 #endif /* ENABLE_NLS */
1027 jobs_dlg = create_dlg (0, 0, JOBS_Y, JOBS_X, dialog_colors,
1028 common_dialog_callback, "[Background jobs]", "jobs",
1029 DLG_CENTER | DLG_GRID);
1030 x_set_dialog_title (jobs_dlg, _("Background Jobs"));
1032 bg_list = listbox_new (2, 3, JOBS_X-7, JOBS_Y-9, listbox_nothing, 0, "listbox");
1033 add_widget (jobs_dlg, bg_list);
1035 i = n_buttons;
1036 while (i--)
1038 add_widget (jobs_dlg, button_new (JOBS_Y-4,
1039 job_buttons [i].xpos, job_buttons [i].value,
1040 NORMAL_BUTTON, job_buttons [i].name,
1041 job_buttons [i].callback, 0,
1042 job_buttons [i].tkname));
1045 /* Insert all of task information in the list */
1046 jobs_fill_listbox ();
1047 run_dlg (jobs_dlg);
1049 destroy_dlg (jobs_dlg);
1051 #endif