Ticket #1930: src/strutil8bit.c: fixed missing include of fs.h
[free-mc.git] / src / boxes.c
bloba4d24f663432239f9a65eb82ac1bca19826a117d
1 /* Some misc dialog boxes for the program.
3 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 2005, 2006, 2009 Free Software Foundation, Inc.
6 Authors: 1994, 1995 Miguel de Icaza
7 1995 Jakub Jelinek
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
23 /** \file boxes.c
24 * \brief Source: Some misc dialog boxes for the program
27 #include <config.h>
29 #include <ctype.h>
30 #include <signal.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
37 #include "global.h"
39 #include "../src/tty/tty.h"
40 #include "../src/skin/skin.h" /* INPUT_COLOR */
41 #include "../src/tty/key.h" /* XCTRL and ALT macros */
43 #include "../src/mcconfig/mcconfig.h" /* Load/save user formats */
45 #include "dialog.h" /* The nice dialog manager */
46 #include "widget.h" /* The widgets for the nice dialog manager */
47 #include "wtools.h"
48 #include "setup.h" /* For profile_name */
49 #include "command.h" /* For cmdline */
50 #include "dir.h"
51 #include "panel.h" /* LIST_TYPES */
52 #include "boxes.h"
53 #include "main.h" /* For the confirm_* variables */
54 #include "tree.h"
55 #include "layout.h" /* for get_nth_panel_name proto */
56 #include "background.h" /* task_list */
57 #include "strutil.h"
59 #ifdef HAVE_CHARSET
60 #include "charsets.h"
61 #include "selcodepage.h"
62 #endif
64 #ifdef USE_NETCODE
65 # include "../vfs/ftpfs.h"
66 #endif
68 #ifdef ENABLE_VFS
69 #include "../vfs/gc.h"
70 #endif
73 static WRadio *display_radio;
74 static WInput *display_user_format;
75 static WInput *display_mini_status;
76 static WCheck *display_check_status;
77 static char **displays_status;
78 static int display_user_hotkey = 'u';
80 static cb_ret_t
81 display_callback (Dlg_head *h, Widget *sender,
82 dlg_msg_t msg, int parm, void *data)
84 switch (msg) {
85 case DLG_UNFOCUS:
86 if (dlg_widget_active (display_radio)) {
87 assign_text (display_mini_status, displays_status[display_radio->sel]);
88 input_set_point (display_mini_status, 0);
90 return MSG_HANDLED;
92 case DLG_KEY:
93 if (parm == '\n') {
94 if (dlg_widget_active (display_radio)) {
95 assign_text (display_mini_status, displays_status[display_radio->sel]);
96 dlg_stop (h);
97 return MSG_HANDLED;
100 if (dlg_widget_active (display_user_format)) {
101 h->ret_value = B_USER + 6;
102 dlg_stop (h);
103 return MSG_HANDLED;
106 if (dlg_widget_active (display_mini_status)) {
107 h->ret_value = B_USER + 7;
108 dlg_stop (h);
109 return MSG_HANDLED;
113 if (g_ascii_tolower (parm) == display_user_hotkey && dlg_widget_active (display_user_format)
114 && dlg_widget_active (display_mini_status)) {
115 display_radio->sel = 3;
116 dlg_select_widget (display_radio); /* force redraw */
117 dlg_select_widget (display_user_format);
118 return MSG_HANDLED;
120 return MSG_NOT_HANDLED;
122 default:
123 return default_dlg_callback (h, sender, msg, parm, data);
127 static Dlg_head *
128 display_init (int radio_sel, char *init_text, int _check_status,
129 char **_status)
131 int dlg_width = 48, dlg_height = 15;
132 Dlg_head *dd;
134 /* Controls whether the array strings have been translated */
135 const char *displays [LIST_TYPES] =
137 N_("&Full file list"),
138 N_("&Brief file list"),
139 N_("&Long file list"),
140 N_("&User defined:")
143 /* Index in displays[] for "user defined" */
144 const int user_type_idx = 3;
146 const char *display_title = N_("Listing mode");
147 const char *user_mini_status = N_("user &Mini status");
148 const char *ok_name = N_("&OK");
149 const char *cancel_name = N_("&Cancel");
151 WButton *ok_button, *cancel_button;
154 int i, maxlen = 0;
155 const char *cp;
156 int ok_len, cancel_len;
158 #ifdef ENABLE_NLS
159 display_title = _(display_title);
160 user_mini_status = _(user_mini_status);
161 ok_name = _(ok_name);
162 cancel_name = _(cancel_name);
164 for (i = 0; i < LIST_TYPES; i++)
165 displays[i] = _(displays[i]);
166 #endif
168 /* get hotkey of user-defined format string */
169 cp = strchr (displays[user_type_idx], '&');
170 if (cp != NULL && *++cp != '\0')
171 display_user_hotkey = g_ascii_tolower (*cp);
173 /* xpos will be fixed later */
174 ok_button = button_new (dlg_height - 3, 0, B_ENTER, DEFPUSH_BUTTON, ok_name, 0);
175 ok_len = button_get_len (ok_button);
176 cancel_button = button_new (dlg_height - 3, 0, B_CANCEL, NORMAL_BUTTON, cancel_name, 0);
177 cancel_len = button_get_len (cancel_button);
179 dlg_width = max (dlg_width, str_term_width1 (display_title) + 10);
180 /* calculate max width of radiobutons */
181 for (i = 0; i < LIST_TYPES; i++)
182 maxlen = max (maxlen, str_term_width1 (displays[i]));
183 dlg_width = max (dlg_width, maxlen);
184 dlg_width = max (dlg_width, str_term_width1 (user_mini_status) + 13);
186 /* buttons */
187 dlg_width = max (dlg_width, ok_len + cancel_len + 8);
188 ok_button->widget.x = dlg_width/3 - ok_len/2;
189 cancel_button->widget.x = dlg_width * 2/3 - cancel_len/2;
192 displays_status = _status;
194 dd = create_dlg (0, 0, dlg_height, dlg_width, dialog_colors,
195 display_callback, "[Listing Mode...]", display_title,
196 DLG_CENTER | DLG_REVERSE);
198 add_widget (dd, cancel_button);
199 add_widget (dd, ok_button);
201 display_mini_status = input_new (10, 8, INPUT_COLOR, dlg_width - 12, _status[radio_sel],
202 "mini-input", INPUT_COMPLETE_DEFAULT);
203 add_widget (dd, display_mini_status);
204 input_set_point (display_mini_status, 0);
206 display_check_status = check_new (9, 4, _check_status, user_mini_status);
207 add_widget (dd, display_check_status);
209 display_user_format = input_new (7, 8, INPUT_COLOR, dlg_width - 12, init_text,
210 "user-fmt-input", INPUT_COMPLETE_DEFAULT);
211 add_widget (dd, display_user_format);
212 input_set_point (display_user_format, 0);
214 display_radio = radio_new (3, 4, LIST_TYPES, displays);
215 display_radio->sel = display_radio->pos = radio_sel;
216 add_widget (dd, display_radio);
218 return dd;
221 /* return list type */
223 display_box (WPanel *panel, char **userp, char **minip, int *use_msformat, int num)
225 int result = -1;
226 Dlg_head *dd;
227 char *section = NULL;
228 size_t i;
230 if (panel == NULL) {
231 const char *p = get_nth_panel_name (num);
232 panel = g_new (WPanel, 1);
233 panel->list_type = list_full;
234 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
235 panel->user_mini_status = 0;
236 for (i = 0; i < LIST_TYPES; i++)
237 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
238 section = g_strconcat ("Temporal:", p, (char *) NULL);
239 if (! mc_config_has_group (mc_main_config, section)) {
240 g_free (section);
241 section = g_strdup (p);
243 panel_load_setup (panel, section);
244 g_free (section);
247 dd = display_init (panel->list_type, panel->user_format,
248 panel->user_mini_status, panel->user_status_format);
250 if (run_dlg (dd) != B_CANCEL) {
251 result = display_radio->sel;
252 *userp = g_strdup (display_user_format->buffer);
253 *minip = g_strdup (display_mini_status->buffer);
254 *use_msformat = display_check_status->state & C_BOOL;
257 if (section != NULL) {
258 g_free (panel->user_format);
259 for (i = 0; i < LIST_TYPES; i++)
260 g_free (panel->user_status_format [i]);
261 g_free (panel);
264 destroy_dlg (dd);
266 return result;
269 const panel_field_t *
270 sort_box (const panel_field_t *sort_format, int *reverse, int *case_sensitive, int *exec_first)
272 int dlg_width = 40, dlg_height = 15;
274 const char **sort_orders_names;
275 gsize sort_names_num;
277 int sort_idx = 0;
279 const panel_field_t *result = sort_format;
282 int max_radio = 0, max_check = 0;
283 int ok_len, cancel_len;
284 gsize i;
286 QuickWidget quick_widgets[] =
288 /* 0 */
289 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
290 /* 1 */
291 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
292 /* 2 */
293 QUICK_CHECKBOX (0, dlg_width, 5, dlg_height, N_("&Reverse"), reverse),
294 /* 3 */
295 QUICK_CHECKBOX (0, dlg_width, 4, dlg_height, N_("Case sensi&tive"), case_sensitive),
296 /* 4 */
297 QUICK_CHECKBOX (0, dlg_width, 3, dlg_height, N_("Executable &first"), exec_first),
298 /* 5 */
299 QUICK_RADIO (4, dlg_width, 3, dlg_height, 0,
300 NULL, &sort_idx),
301 QUICK_END
304 QuickDialog quick_dlg =
306 dlg_width, dlg_height, -1, -1,
307 N_("Sort order"), "[Sort Order...]",
308 quick_widgets, TRUE
311 sort_orders_names = panel_get_sortable_fields(&sort_names_num);
312 quick_widgets[5].u.radio.items = sort_orders_names;
313 quick_widgets[5].u.radio.count = sort_names_num;
315 for (i = 0; i < sort_names_num; i++)
316 if (strcmp (sort_orders_names[i], _(sort_format->title_hotkey)) == 0 ) {
317 sort_idx = i;
318 break;
321 #ifdef ENABLE_NLS
322 quick_dlg.title = _(quick_dlg.title);
323 /* buttons */
324 for (i = 0; i < 2; i++)
325 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
326 /* checkboxes */
327 for (i = 2; i < 5; i++)
328 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
329 #endif /* ENABLE_NlS */
331 /* buttons */
332 cancel_len = str_term_width1 (quick_widgets[0].u.button.text) + 4;
333 ok_len = str_term_width1 (quick_widgets[1].u.button.text) + 6;
334 /* checkboxes */
335 for (i = 2; i < 5; i++)
336 max_check = max (max_check, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
337 /* radiobuttons */
338 for (i = 0; i < sort_names_num; i++)
339 max_radio = max (max_radio, str_term_width1 (sort_orders_names[i]) + 4);
341 /* dialog width */
342 dlg_width = max (dlg_width, str_term_width1 (quick_dlg.title) + 8);
343 dlg_width = max (dlg_width, ok_len + cancel_len + 8);
344 dlg_width = max (dlg_width, 2 * max (max_radio, max_check) + 8);
346 /* fix widget and dialog parameters */
347 /* dialog */
348 quick_dlg.xlen = dlg_width;
349 /* widgets */
350 for (i = 0; (size_t) i < sizeof (quick_widgets)/sizeof (quick_widgets[0]) - 1; i++)
351 quick_widgets[i].x_divisions = dlg_width;
352 /* buttons */
353 quick_widgets[0].relative_x = dlg_width * 2/3 - cancel_len/2;
354 quick_widgets[1].relative_x = dlg_width/3 - ok_len/2;
355 /* checkboxes */
356 for (i = 2; i < 5; i++)
357 quick_widgets[i].relative_x = dlg_width/2 + 2;
359 if (quick_dialog (&quick_dlg) != B_CANCEL)
360 result = panel_get_field_by_title_hotkey(sort_orders_names[sort_idx]);
362 if (result == NULL)
363 result = sort_format;
365 g_strfreev((gchar **)sort_orders_names);
366 return result;
370 void
371 confirm_box (void)
373 const int w_num = 7;
375 /* dialog sizes */
376 int dlg_width = 46;
377 int dlg_height = 12;
379 const char *title = _(" Confirmation ");
381 QuickWidget conf_widgets [] =
383 /* 0 */ QUICK_BUTTON (29, dlg_width, 9, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
384 /* 1 */ QUICK_BUTTON (12, dlg_width, 9, dlg_height, N_("&OK"), B_ENTER, NULL),
385 /* 2 */ QUICK_CHECKBOX (3, dlg_width, 7, dlg_height, N_(" confirm di&Rectory hotlist delete "), &confirm_directory_hotlist_delete),
386 /* 3 */ QUICK_CHECKBOX (3, dlg_width, 6, dlg_height, N_(" confirm &Exit "), &confirm_exit),
387 /* 4 */ QUICK_CHECKBOX (3, dlg_width, 5, dlg_height, N_(" confirm e&Xecute "), &confirm_execute),
388 /* 5 */ QUICK_CHECKBOX (3, dlg_width, 4, dlg_height, N_(" confirm o&Verwrite "), &confirm_overwrite),
389 /* 6 */ QUICK_CHECKBOX (3, dlg_width, 3, dlg_height, N_(" confirm &Delete "), &confirm_delete),
390 QUICK_END
393 int i;
394 int maxlen = 0;
395 int cancel_len, ok_len, blen;
397 #ifdef ENABLE_NLS
398 title = _(title);
400 for (i = 0; i < 2; i++)
401 conf_widgets [i].u.button.text = _(conf_widgets [i].u.button.text);
403 for (i = 2; i < w_num; i++)
404 conf_widgets [i].u.checkbox.text = _(conf_widgets [i].u.checkbox.text);
405 #endif /* ENABLE_NLS */
407 /* maximumr length of checkboxes */
408 for (i = 2; i < w_num; i++)
409 maxlen = max (maxlen, str_term_width1 (conf_widgets [i].u.checkbox.text) + 3);
411 /* length of buttons */
412 cancel_len = str_term_width1 (conf_widgets [0].u.button.text) + 2;
413 ok_len = str_term_width1 (conf_widgets [0].u.button.text) + 4; /* default button */
415 blen = cancel_len + ok_len + 2;
417 dlg_width = max (maxlen, blen) + 6;
418 dlg_width = max (dlg_width, str_term_width1 (title) + 4);
420 /* correct widget parameters */
421 for (i = 0; i < w_num; i++)
422 conf_widgets[i].x_divisions = dlg_width;
424 conf_widgets[0].relative_x = dlg_width * 2/3 - cancel_len/2;
425 conf_widgets[1].relative_x = dlg_width/3 - ok_len/2;
428 QuickDialog confirmation =
430 dlg_width, dlg_height, -1, -1, title,
431 "[Confirmation]", conf_widgets, 1
434 (void) quick_dialog (&confirmation);
439 #ifndef HAVE_CHARSET
440 void
441 display_bits_box (void) /* AB:FIXME: test dialog */
443 /* dialog sizes */
444 const int DISPY = 13;
445 const int DISPX = 46;
447 int new_meta = 0;
448 int current_mode;
450 const char *display_bits_str [] =
452 N_("UTF-8 output"),
453 N_("Full 8 bits output"),
454 N_("ISO 8859-1"),
455 N_("7 bits")
458 QuickWidget display_widgets[] =
460 /* 0 */ QUICK_BUTTON (15, DISPX, DISPY - 3, DISPY, N_("&Cancel"), B_CANCEL, NULL),
461 /* 1 */ QUICK_BUTTON (29, DISPX, DISPY - 3, DISPY, N_("&OK"), B_ENTER, NULL),
462 /* 2 */ QUICK_CHECKBOX (3, DISPX, 8, DISPY, N_("F&ull 8 bits input"), &new_meta),
463 /* 3 */ QUICK_RADIO (3, DISPX, 3, DISPY, 4, display_bits_str, &current_mode),
464 QUICK_END
467 QuickDialog display_bits =
469 DISPX, DISPY, -1, -1, _(" Display bits "),
470 "[Display bits]", display_widgets, TRUE
473 int i;
474 int l1, maxlen = 0;
475 int ok_len, cancel_len;
477 #ifdef ENABLE_NLS
478 static gboolean i18n_flag = FALSE;
480 if (!i18n_flag) {
481 for (i = 0; i < 3; i++) {
482 display_bits_str[i] = _(display_bits_str [i]);
485 display_widgets[0].u.button.text = _(display_widgets[0].u.button.text);
486 display_widgets[1].u.button.text = _(display_widgets[1].u.button.text);
487 display_widgets[2].u.checkbox.text = _(display_widgets[2].u.checkbox.text);
489 i18n_flag = TRUE;
491 #endif /* ENABLE_NLS */
493 /* radiobuttons */
494 for (i = 0; i < 3; i++)
495 maxlen = max (maxlen, str_term_width1 (display_bits_str [i]));
497 /* buttons */
498 cancel_len = str_term_width1 (display_widgets [0].u.button.text) + 2;
499 ok_len = str_term_width1 (display_widgets [1].u.button.text) + 4; /* default button */
501 l1 = max (cancel_len, ok_len);
503 display_bits.xlen = max (maxlen, l1) + 20;
505 for (i = 0; i < 4; i++)
506 display_widgets[i].x_divisions = display_bits.xlen;
508 display_widgets[0].relative_x = display_bits.xlen * 2/3 - cancel_len/2;
509 display_widgets[1].relative_x = display_bits.xlen/3 - ok_len/2;
511 if (full_eight_bits)
512 current_mode = 0;
513 else if (eight_bit_clean)
514 current_mode = 1;
515 else
516 current_mode = 2;
518 new_meta = !use_8th_bit_as_meta;
520 if (quick_dialog (&display_bits) != B_CANCEL) {
521 eight_bit_clean = current_mode < 3;
522 full_eight_bits = current_mode < 2;
523 #ifndef HAVE_SLANG
524 meta (stdscr, eight_bit_clean);
525 #else
526 SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
527 #endif
528 use_8th_bit_as_meta = !new_meta;
532 #else /* HAVE_CHARSET */
534 static int new_display_codepage;
536 static WLabel *cplabel;
537 static WCheck *inpcheck;
539 static int
540 sel_charset_button (int action)
542 int new_dcp;
544 (void) action;
546 new_dcp = select_charset (-1, -1, new_display_codepage, TRUE);
548 if (new_dcp != SELECT_CHARSET_CANCEL) {
549 const char *cpname;
550 char buf[BUF_TINY];
552 new_display_codepage = new_dcp;
553 cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ?
554 _("Other 8 bit") : codepages[new_display_codepage].name;
555 if (cpname != NULL)
556 utf8_display = str_isutf8 (cpname);
557 /* avoid strange bug with label repainting */
558 g_snprintf (buf, sizeof (buf), "%-27s", cpname);
559 label_set_text (cplabel, buf);
562 return 0;
565 static Dlg_head *
566 init_disp_bits_box (void)
568 /* dialog sizes */
569 const int DISPY = 11;
570 const int DISPX = 46;
572 const char *cpname;
573 Dlg_head *dbits_dlg;
575 do_refresh ();
577 dbits_dlg =
578 create_dlg (0, 0, DISPY, DISPX, dialog_colors, NULL,
579 "[Display bits]", _(" Display bits "), DLG_CENTER | DLG_REVERSE);
581 add_widget (dbits_dlg,
582 label_new (3, 4, _("Input / display codepage:")));
584 cpname = (new_display_codepage < 0)
585 ? _("Other 8 bit")
586 : codepages[new_display_codepage].name;
587 cplabel = label_new (4, 4, cpname);
588 add_widget (dbits_dlg, cplabel);
590 add_widget (dbits_dlg,
591 button_new (DISPY - 3, DISPX / 2 + 3, B_CANCEL,
592 NORMAL_BUTTON, _("&Cancel"), 0));
593 add_widget (dbits_dlg,
594 button_new (DISPY - 3, 7, B_ENTER, NORMAL_BUTTON, _("&OK"),
595 0));
597 inpcheck =
598 check_new (6, 4, !use_8th_bit_as_meta, _("F&ull 8 bits input"));
599 add_widget (dbits_dlg, inpcheck);
601 cpname = _("&Select");
602 add_widget (dbits_dlg,
603 button_new (4, DISPX - 7 - str_term_width1 (cpname), B_USER,
604 NORMAL_BUTTON, cpname, sel_charset_button));
606 return dbits_dlg;
609 void
610 display_bits_box (void)
612 Dlg_head *dbits_dlg;
613 new_display_codepage = display_codepage;
615 application_keypad_mode ();
616 dbits_dlg = init_disp_bits_box ();
618 run_dlg (dbits_dlg);
620 if (dbits_dlg->ret_value == B_ENTER) {
621 const char *errmsg;
622 display_codepage = new_display_codepage;
623 errmsg =
624 init_translation_table (source_codepage, display_codepage);
625 if (errmsg)
626 message (D_ERROR, MSG_ERROR, "%s", errmsg);
627 #ifdef HAVE_SLANG
628 tty_display_8bit (display_codepage != 0 && display_codepage != 1);
629 #else
630 tty_display_8bit (display_codepage != 0);
631 #endif
632 use_8th_bit_as_meta = !(inpcheck->state & C_BOOL);
634 destroy_dlg (dbits_dlg);
635 repaint_screen ();
638 #endif /* HAVE_CHARSET */
640 static cb_ret_t
641 tree_callback (Dlg_head *h, Widget *sender,
642 dlg_msg_t msg, int parm, void *data)
644 switch (msg) {
645 case DLG_POST_KEY:
646 /* The enter key will be processed by the tree widget */
647 if (parm == '\n') {
648 h->ret_value = B_ENTER;
649 dlg_stop (h);
651 return MSG_HANDLED;
653 case DLG_ACTION:
654 /* command from buttonbar */
655 return send_message ((Widget *) find_tree (h), WIDGET_COMMAND, parm);
657 default:
658 return default_dlg_callback (h, sender, msg, parm, data);
662 /* Show tree in a box, not on a panel */
663 char *
664 tree_box (const char *current_dir)
666 WTree *mytree;
667 Dlg_head *dlg;
668 char *val = NULL;
669 WButtonBar *bar;
671 (void) current_dir;
673 /* Create the components */
674 dlg = create_dlg (0, 0, LINES - 9, COLS - 20, dialog_colors,
675 tree_callback, "[Directory Tree]",
676 NULL, DLG_CENTER | DLG_REVERSE);
678 mytree = tree_new (0, 2, 2, dlg->lines - 6, dlg->cols - 5);
679 add_widget (dlg, mytree);
680 bar = buttonbar_new (TRUE);
681 add_widget (dlg, bar);
682 /* restore ButtonBar coordinates after add_widget() */
683 ((Widget *) bar)->x = 0;
684 ((Widget *) bar)->y = LINES - 1;
686 if (run_dlg (dlg) == B_ENTER)
687 val = g_strdup (tree_selected_name (mytree));
689 destroy_dlg (dlg);
690 return val;
693 #ifdef ENABLE_VFS
695 static char *ret_timeout;
697 #ifdef USE_NETCODE
698 static char *ret_passwd;
699 static char *ret_directory_timeout;
700 static char *ret_ftp_proxy;
701 #endif
703 void
704 configure_vfs (void)
706 #define VFSX 56
708 #ifdef USE_NETCODE
709 #define VFSY 17
710 #else
711 #define VFSY 8
712 #endif
714 char buffer2 [BUF_TINY];
715 #ifdef USE_NETCODE
716 char buffer3 [BUF_TINY];
717 #endif
719 QuickWidget confvfs_widgets [] =
721 /* 0 */ QUICK_BUTTON (30, VFSX, VFSY - 3, VFSY, N_("&Cancel"), B_CANCEL, NULL),
722 /* 1 */ QUICK_BUTTON (12, VFSX, VFSY - 3, VFSY, N_("&OK"), B_ENTER, NULL),
723 #ifdef USE_NETCODE
724 /* 2 */ QUICK_CHECKBOX (4, VFSX, 12, VFSY, N_("Use passive mode over pro&xy"), &ftpfs_use_passive_connections_over_proxy),
725 /* 3 */ QUICK_CHECKBOX (4, VFSX, 11, VFSY, N_("Use &passive mode"), &ftpfs_use_passive_connections),
726 /* 4 */ QUICK_CHECKBOX (4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), &use_netrc),
727 /* 5 */ QUICK_INPUT (4, VFSX, 9, VFSY, ftpfs_proxy_host, 48, 0, "input-ftp-proxy", &ret_ftp_proxy),
728 /* 6 */ QUICK_CHECKBOX (4, VFSX, 8, VFSY, N_("&Always use ftp proxy"), &ftpfs_always_use_proxy),
729 /* 7 */ QUICK_LABEL (49, VFSX, 7, VFSY, N_("sec")),
730 /* 8 */ QUICK_INPUT (38, VFSX, 7, VFSY, buffer3, 10, 0, "input-timeout", &ret_directory_timeout),
731 /* 9 */ QUICK_LABEL (4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:")),
732 /* 10 */ QUICK_INPUT (4, VFSX, 6, VFSY, ftpfs_anonymous_passwd, 48, 0, "input-passwd", &ret_passwd),
733 /* 11 */ QUICK_LABEL (4, VFSX, 5, VFSY, N_("ftp anonymous password:")),
734 #endif
735 /* 12 */ QUICK_LABEL (49, VFSX, 3, VFSY, N_("sec")),
736 /* 13 */ QUICK_INPUT (38, VFSX, 3, VFSY, buffer2, 10, 0, "input-timo-vfs", &ret_timeout),
737 /* 14 */ QUICK_LABEL (4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:")),
738 QUICK_END
741 QuickDialog confvfs_dlg =
743 VFSX, VFSY, -1, -1, N_(" Virtual File System Setting "),
744 "[Virtual FS]", confvfs_widgets, FALSE
747 #ifdef USE_NETCODE
748 g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
749 #endif
750 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
752 if (quick_dialog (&confvfs_dlg) != B_CANCEL) {
753 vfs_timeout = atoi (ret_timeout);
754 g_free (ret_timeout);
756 if (vfs_timeout < 0 || vfs_timeout > 10000)
757 vfs_timeout = 10;
758 #ifdef USE_NETCODE
759 g_free (ftpfs_anonymous_passwd);
760 ftpfs_anonymous_passwd = ret_passwd;
761 g_free (ftpfs_proxy_host);
762 ftpfs_proxy_host = ret_ftp_proxy;
763 ftpfs_directory_timeout = atoi(ret_directory_timeout);
764 g_free (ret_directory_timeout);
765 #endif
768 #undef VFSX
769 #undef VFSY
772 #endif /* ENABLE_VFS */
774 char *
775 cd_dialog (void)
777 const char *label = N_("cd");
778 const int ylen = 5;
779 const int xlen = 57;
781 int len;
783 #ifdef ENABLE_NLS
784 label = _(label);
785 #endif
787 len = str_term_width1 (label);
790 char *my_str;
792 QuickWidget quick_widgets [] =
794 /* 0 */ QUICK_INPUT (4 + len, xlen, 2, ylen, "", xlen - 7 - len, 2, "input" , &my_str),
795 /* 1 */ QUICK_LABEL (3, xlen, 2, ylen, label),
796 QUICK_END
799 QuickDialog Quick_input =
801 xlen, ylen, 2, LINES - 2 - ylen, _("Quick cd"),
802 "[Quick cd]", quick_widgets, TRUE
805 return (quick_dialog (&Quick_input) != B_CANCEL) ? my_str : NULL;
809 void
810 symlink_dialog (const char *existing, const char *new, char **ret_existing,
811 char **ret_new)
813 QuickWidget quick_widgets[] =
815 /* 0 */ QUICK_BUTTON (50, 80, 6, 8, N_("&Cancel"), B_CANCEL, NULL),
816 /* 1 */ QUICK_BUTTON (16, 80, 6, 8, N_("&OK"), B_ENTER, NULL),
817 /* 2 */ QUICK_INPUT (4, 80, 5, 8, new, 58, 0, "input-1", ret_new),
818 /* 3 */ QUICK_LABEL (4, 80, 4, 8, N_("Symbolic link filename:")),
819 /* 4 */ QUICK_INPUT (4, 80, 3, 8, existing, 58, 0, "input-2", ret_existing),
820 /* 5 */ QUICK_LABEL (4, 80, 2, 8, N_("Existing filename (filename symlink will point to):")),
821 QUICK_END
824 QuickDialog Quick_input =
826 64, 12, -1, -1, N_("Symbolic link"),
827 "[File Menu]", quick_widgets, FALSE
830 if (quick_dialog (&Quick_input) == B_CANCEL) {
831 *ret_new = NULL;
832 *ret_existing = NULL;
836 #ifdef WITH_BACKGROUND
837 #define B_STOP (B_USER+1)
838 #define B_RESUME (B_USER+2)
839 #define B_KILL (B_USER+3)
841 static int JOBS_X = 60;
842 #define JOBS_Y 15
843 static WListbox *bg_list;
844 static Dlg_head *jobs_dlg;
846 static void
847 jobs_fill_listbox (void)
849 static const char *state_str [2];
850 TaskList *tl = task_list;
852 if (!state_str [0]){
853 state_str [0] = _("Running ");
854 state_str [1] = _("Stopped");
857 while (tl){
858 char *s;
860 s = g_strconcat (state_str [tl->state], " ", tl->info, (char *) NULL);
861 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
862 g_free (s);
863 tl = tl->next;
867 static int
868 task_cb (int action)
870 TaskList *tl;
871 int sig = 0;
873 if (!bg_list->list)
874 return 0;
876 /* Get this instance information */
877 tl = (TaskList *) bg_list->current->data;
879 # ifdef SIGTSTP
880 if (action == B_STOP){
881 sig = SIGSTOP;
882 tl->state = Task_Stopped;
883 } else if (action == B_RESUME){
884 sig = SIGCONT;
885 tl->state = Task_Running;
886 } else
887 # endif
888 if (action == B_KILL){
889 sig = SIGKILL;
892 if (sig == SIGKILL)
893 unregister_task_running (tl->pid, tl->fd);
895 kill (tl->pid, sig);
896 listbox_remove_list (bg_list);
897 jobs_fill_listbox ();
899 /* This can be optimized to just redraw this widget :-) */
900 dlg_redraw (jobs_dlg);
902 return 0;
905 static struct
907 const char* name;
908 int xpos;
909 int value;
910 int (*callback)(int);
912 job_buttons [] =
914 {N_("&Stop"), 3, B_STOP, task_cb},
915 {N_("&Resume"), 12, B_RESUME, task_cb},
916 {N_("&Kill"), 23, B_KILL, task_cb},
917 {N_("&OK"), 35, B_CANCEL, NULL }
920 void
921 jobs_cmd (void)
923 register int i;
924 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
926 #ifdef ENABLE_NLS
927 static int i18n_flag = 0;
928 if (!i18n_flag)
930 int startx = job_buttons [0].xpos;
931 int len;
933 for (i = 0; i < n_buttons; i++)
935 job_buttons [i].name = _(job_buttons [i].name);
937 len = str_term_width1 (job_buttons [i].name) + 4;
938 JOBS_X = max (JOBS_X, startx + len + 3);
940 job_buttons [i].xpos = startx;
941 startx += len;
944 /* Last button - Ok a.k.a. Cancel :) */
945 job_buttons [n_buttons - 1].xpos =
946 JOBS_X - str_term_width1 (job_buttons [n_buttons - 1].name) - 7;
948 i18n_flag = 1;
950 #endif /* ENABLE_NLS */
952 jobs_dlg = create_dlg (0, 0, JOBS_Y, JOBS_X, dialog_colors, NULL,
953 "[Background jobs]", _("Background Jobs"),
954 DLG_CENTER | DLG_REVERSE);
956 bg_list = listbox_new (2, 3, JOBS_Y - 9, JOBS_X - 7, NULL);
957 add_widget (jobs_dlg, bg_list);
959 i = n_buttons;
960 while (i--)
962 add_widget (jobs_dlg, button_new (JOBS_Y-4,
963 job_buttons [i].xpos, job_buttons [i].value,
964 NORMAL_BUTTON, job_buttons [i].name,
965 job_buttons [i].callback));
968 /* Insert all of task information in the list */
969 jobs_fill_listbox ();
970 run_dlg (jobs_dlg);
972 destroy_dlg (jobs_dlg);
974 #endif /* WITH_BACKGROUND */
976 #ifdef ENABLE_VFS_SMB
977 struct smb_authinfo *
978 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
979 const char *user)
981 static int dialog_x = 44;
982 enum { b0 = 3, dialog_y = 12};
983 struct smb_authinfo *return_value;
984 static const char* lc_labs[] = {N_("Domain:"), N_("Username:"), N_("Password:")};
985 static const char* buts[] = {N_("&OK"), N_("&Cancel")};
986 static int ilen = 30, istart = 14;
987 static int b2 = 30;
988 char *title;
989 WInput *in_password;
990 WInput *in_user;
991 WInput *in_domain;
992 Dlg_head *auth_dlg;
994 #ifdef ENABLE_NLS
995 static int i18n_flag = 0;
997 if (!i18n_flag)
999 register int i = sizeof(lc_labs)/sizeof(lc_labs[0]);
1000 int l1, maxlen = 0;
1002 while (i--)
1004 l1 = str_term_width1 (lc_labs [i] = _(lc_labs [i]));
1005 if (l1 > maxlen)
1006 maxlen = l1;
1008 i = maxlen + ilen + 7;
1009 if (i > dialog_x)
1010 dialog_x = i;
1012 for (i = sizeof(buts)/sizeof(buts[0]), l1 = 0; i--; )
1014 l1 += str_term_width1 (buts [i] = _(buts [i]));
1016 l1 += 15;
1017 if (l1 > dialog_x)
1018 dialog_x = l1;
1020 ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
1021 istart = dialog_x - 3 - ilen;
1023 b2 = dialog_x - (str_term_width1 (buts[1]) + 6);
1025 i18n_flag = 1;
1028 #endif /* ENABLE_NLS */
1030 if (!domain)
1031 domain = "";
1032 if (!user)
1033 user = "";
1035 title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1037 auth_dlg = create_dlg (0, 0, dialog_y, dialog_x, dialog_colors, NULL,
1038 "[Smb Authinfo]", title, DLG_CENTER | DLG_REVERSE);
1040 g_free (title);
1042 in_user = input_new (5, istart, INPUT_COLOR, ilen, user, "auth_name", INPUT_COMPLETE_DEFAULT);
1043 add_widget (auth_dlg, in_user);
1045 in_domain = input_new (3, istart, INPUT_COLOR, ilen, domain, "auth_domain", INPUT_COMPLETE_DEFAULT);
1046 add_widget (auth_dlg, in_domain);
1047 add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON,
1048 buts[1], 0));
1049 add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON,
1050 buts[0], 0));
1052 in_password = input_new (7, istart, INPUT_COLOR, ilen, "", "auth_password", INPUT_COMPLETE_DEFAULT);
1053 in_password->completion_flags = 0;
1054 in_password->is_password = 1;
1055 add_widget (auth_dlg, in_password);
1057 add_widget (auth_dlg, label_new (7, 3, lc_labs[2]));
1058 add_widget (auth_dlg, label_new (5, 3, lc_labs[1]));
1059 add_widget (auth_dlg, label_new (3, 3, lc_labs[0]));
1061 run_dlg (auth_dlg);
1063 switch (auth_dlg->ret_value) {
1064 case B_CANCEL:
1065 return_value = 0;
1066 break;
1067 default:
1068 return_value = g_try_new (struct smb_authinfo, 1);
1069 if (return_value) {
1070 return_value->host = g_strdup (host);
1071 return_value->share = g_strdup (share);
1072 return_value->domain = g_strdup (in_domain->buffer);
1073 return_value->user = g_strdup (in_user->buffer);
1074 return_value->password = g_strdup (in_password->buffer);
1078 destroy_dlg (auth_dlg);
1080 return return_value;
1082 #endif /* ENABLE_VFS_SMB */