vfs/vfs-impl.h: fixed missing includes
[free-mc.git] / src / boxes.c
blobb1ab846078570186ef3589c81c8f454fc053de6d
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 USE_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, dlg_msg_t msg, int parm)
83 switch (msg) {
84 case DLG_UNFOCUS:
85 if (dlg_widget_active (display_radio)) {
86 assign_text (display_mini_status, displays_status[display_radio->sel]);
87 input_set_point (display_mini_status, 0);
89 return MSG_HANDLED;
91 case DLG_KEY:
92 if (parm == '\n') {
93 if (dlg_widget_active (display_radio)) {
94 assign_text (display_mini_status, displays_status[display_radio->sel]);
95 dlg_stop (h);
96 return MSG_HANDLED;
99 if (dlg_widget_active (display_user_format)) {
100 h->ret_value = B_USER + 6;
101 dlg_stop (h);
102 return MSG_HANDLED;
105 if (dlg_widget_active (display_mini_status)) {
106 h->ret_value = B_USER + 7;
107 dlg_stop (h);
108 return MSG_HANDLED;
112 if (g_ascii_tolower (parm) == display_user_hotkey && dlg_widget_active (display_user_format)
113 && dlg_widget_active (display_mini_status)) {
114 display_radio->sel = 3;
115 dlg_select_widget (display_radio); /* force redraw */
116 dlg_select_widget (display_user_format);
117 return MSG_HANDLED;
119 return MSG_NOT_HANDLED;
121 default:
122 return default_dlg_callback (h, msg, parm);
126 static Dlg_head *
127 display_init (int radio_sel, char *init_text, int _check_status,
128 char **_status)
130 int dlg_width = 48, dlg_height = 15;
131 Dlg_head *dd;
133 /* Controls whether the array strings have been translated */
134 const char *displays [LIST_TYPES] =
136 N_("&Full file list"),
137 N_("&Brief file list"),
138 N_("&Long file list"),
139 N_("&User defined:")
142 /* Index in displays[] for "user defined" */
143 const int user_type_idx = 3;
145 const char *display_title = N_("Listing mode");
146 const char *user_mini_status = N_("user &Mini status");
147 const char *ok_name = N_("&OK");
148 const char *cancel_name = N_("&Cancel");
150 WButton *ok_button, *cancel_button;
153 int i, maxlen = 0;
154 const char *cp;
155 int ok_len, cancel_len;
157 #ifdef ENABLE_NLS
158 display_title = _(display_title);
159 user_mini_status = _(user_mini_status);
160 ok_name = _(ok_name);
161 cancel_name = _(cancel_name);
163 for (i = 0; i < LIST_TYPES; i++)
164 displays[i] = _(displays[i]);
165 #endif
167 /* get hotkey of user-defined format string */
168 cp = strchr (displays[user_type_idx], '&');
169 if (cp != NULL && *++cp != '\0')
170 display_user_hotkey = g_ascii_tolower (*cp);
172 /* xpos will be fixed later */
173 ok_button = button_new (dlg_height - 3, 0, B_ENTER, DEFPUSH_BUTTON, ok_name, 0);
174 ok_len = button_get_len (ok_button);
175 cancel_button = button_new (dlg_height - 3, 0, B_CANCEL, NORMAL_BUTTON, cancel_name, 0);
176 cancel_len = button_get_len (cancel_button);
178 dlg_width = max (dlg_width, str_term_width1 (display_title) + 10);
179 /* calculate max width of radiobutons */
180 for (i = 0; i < LIST_TYPES; i++)
181 maxlen = max (maxlen, str_term_width1 (displays[i]));
182 dlg_width = max (dlg_width, maxlen);
183 dlg_width = max (dlg_width, str_term_width1 (user_mini_status) + 13);
185 /* buttons */
186 dlg_width = max (dlg_width, ok_len + cancel_len + 8);
187 ok_button->widget.x = dlg_width/3 - ok_len/2;
188 cancel_button->widget.x = dlg_width * 2/3 - cancel_len/2;
191 displays_status = _status;
193 dd = create_dlg (0, 0, dlg_height, dlg_width, dialog_colors,
194 display_callback, "[Listing Mode...]", display_title,
195 DLG_CENTER | DLG_REVERSE);
197 add_widget (dd, cancel_button);
198 add_widget (dd, ok_button);
200 display_mini_status = input_new (10, 8, INPUT_COLOR, dlg_width - 12, _status[radio_sel],
201 "mini-input", INPUT_COMPLETE_DEFAULT);
202 add_widget (dd, display_mini_status);
203 input_set_point (display_mini_status, 0);
205 display_check_status = check_new (9, 4, _check_status, user_mini_status);
206 add_widget (dd, display_check_status);
208 display_user_format = input_new (7, 8, INPUT_COLOR, dlg_width - 12, init_text,
209 "user-fmt-input", INPUT_COMPLETE_DEFAULT);
210 add_widget (dd, display_user_format);
211 input_set_point (display_user_format, 0);
213 display_radio = radio_new (3, 4, LIST_TYPES, displays);
214 display_radio->sel = display_radio->pos = radio_sel;
215 add_widget (dd, display_radio);
217 return dd;
221 display_box (WPanel *panel, char **userp, char **minip, int *use_msformat, int num)
223 int result = -1;
224 Dlg_head *dd;
225 char *section = NULL;
226 int i;
228 if (panel == NULL) {
229 const char *p = get_nth_panel_name (num);
230 panel = g_new (WPanel, 1);
231 panel->list_type = list_full;
232 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
233 panel->user_mini_status = 0;
234 for (i = 0; i < LIST_TYPES; i++)
235 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
236 section = g_strconcat ("Temporal:", p, (char *) NULL);
237 if (! mc_config_has_group (mc_main_config, section)) {
238 g_free (section);
239 section = g_strdup (p);
241 panel_load_setup (panel, section);
242 g_free (section);
245 dd = display_init (panel->list_type, panel->user_format,
246 panel->user_mini_status, panel->user_status_format);
248 if (run_dlg (dd) != B_CANCEL) {
249 result = display_radio->sel;
250 *userp = g_strdup (display_user_format->buffer);
251 *minip = g_strdup (display_mini_status->buffer);
252 *use_msformat = display_check_status->state & C_BOOL;
255 if (section != NULL) {
256 g_free (panel->user_format);
257 for (i = 0; i < LIST_TYPES; i++)
258 g_free (panel->user_status_format [i]);
259 g_free (panel);
262 destroy_dlg (dd);
264 return result;
267 const panel_field_t *
268 sort_box (const panel_field_t *sort_format, int *reverse, int *case_sensitive, int *exec_first)
270 int dlg_width = 40, dlg_height = 15;
272 const char **sort_orders_names;
273 gsize sort_names_num;
275 int sort_idx = 0;
277 const panel_field_t *result = sort_format;
280 int max_radio = 0, max_check = 0;
281 int ok_len, cancel_len;
282 gsize i;
284 QuickWidget quick_widgets[] =
286 /* 0 */
287 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
288 /* 1 */
289 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
290 /* 2 */
291 QUICK_CHECKBOX (0, dlg_width, 5, dlg_height, N_("&Reverse"), reverse),
292 /* 3 */
293 QUICK_CHECKBOX (0, dlg_width, 4, dlg_height, N_("Case sensi&tive"), case_sensitive),
294 /* 4 */
295 QUICK_CHECKBOX (0, dlg_width, 3, dlg_height, N_("Executable &first"), exec_first),
296 /* 5 */
297 QUICK_RADIO (4, dlg_width, 3, dlg_height, 0,
298 NULL, &sort_idx),
299 QUICK_END
302 QuickDialog quick_dlg =
304 dlg_width, dlg_height, -1, -1,
305 N_("Sort order"), "[Sort Order...]",
306 quick_widgets, TRUE
309 sort_orders_names = panel_get_sortable_fields(&sort_names_num);
310 quick_widgets[5].u.radio.items = sort_orders_names;
311 quick_widgets[5].u.radio.count = sort_names_num;
313 for (i = 0; i < sort_names_num; i++)
314 if (strcmp (sort_orders_names[i], _(sort_format->title_hotkey)) == 0 ) {
315 sort_idx = i;
316 break;
319 #ifdef ENABLE_NLS
320 quick_dlg.title = _(quick_dlg.title);
321 /* buttons */
322 for (i = 0; i < 2; i++)
323 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
324 /* checkboxes */
325 for (i = 2; i < 5; i++)
326 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
327 #endif /* ENABLE_NlS */
329 /* buttons */
330 cancel_len = str_term_width1 (quick_widgets[0].u.button.text) + 4;
331 ok_len = str_term_width1 (quick_widgets[1].u.button.text) + 6;
332 /* checkboxes */
333 for (i = 2; i < 5; i++)
334 max_check = max (max_check, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
335 /* radiobuttons */
336 for (i = 0; i < sort_names_num; i++)
337 max_radio = max (max_radio, str_term_width1 (sort_orders_names[i]) + 4);
339 /* dialog width */
340 dlg_width = max (dlg_width, str_term_width1 (quick_dlg.title) + 8);
341 dlg_width = max (dlg_width, ok_len + cancel_len + 8);
342 dlg_width = max (dlg_width, 2 * max (max_radio, max_check) + 8);
344 /* fix widget and dialog parameters */
345 /* dialog */
346 quick_dlg.xlen = dlg_width;
347 /* widgets */
348 for (i = 0; (size_t) i < sizeof (quick_widgets)/sizeof (quick_widgets[0]) - 1; i++)
349 quick_widgets[i].x_divisions = dlg_width;
350 /* buttons */
351 quick_widgets[0].relative_x = dlg_width * 2/3 - cancel_len/2;
352 quick_widgets[1].relative_x = dlg_width/3 - ok_len/2;
353 /* checkboxes */
354 for (i = 2; i < 5; i++)
355 quick_widgets[i].relative_x = dlg_width/2 + 2;
357 if (quick_dialog (&quick_dlg) != B_CANCEL)
358 result = panel_get_field_by_title_hotkey(sort_orders_names[sort_idx]);
360 if (result == NULL)
361 result = sort_format;
363 g_strfreev((gchar **)sort_orders_names);
364 return result;
368 void
369 confirm_box (void)
371 const int w_num = 7;
373 /* dialog sizes */
374 int dlg_width = 46;
375 int dlg_height = 12;
377 const char *title = _(" Confirmation ");
379 QuickWidget conf_widgets [] =
381 /* 0 */ QUICK_BUTTON (29, dlg_width, 9, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
382 /* 1 */ QUICK_BUTTON (12, dlg_width, 9, dlg_height, N_("&OK"), B_ENTER, NULL),
383 /* 2 */ QUICK_CHECKBOX (3, dlg_width, 7, dlg_height, N_(" confirm di&Rectory hotlist delete "), &confirm_directory_hotlist_delete),
384 /* 3 */ QUICK_CHECKBOX (3, dlg_width, 6, dlg_height, N_(" confirm &Exit "), &confirm_exit),
385 /* 4 */ QUICK_CHECKBOX (3, dlg_width, 5, dlg_height, N_(" confirm e&Xecute "), &confirm_execute),
386 /* 5 */ QUICK_CHECKBOX (3, dlg_width, 4, dlg_height, N_(" confirm o&Verwrite "), &confirm_overwrite),
387 /* 6 */ QUICK_CHECKBOX (3, dlg_width, 3, dlg_height, N_(" confirm &Delete "), &confirm_delete),
388 QUICK_END
391 int i;
392 int maxlen = 0;
393 int cancel_len, ok_len, blen;
395 #ifdef ENABLE_NLS
396 title = _(title);
398 for (i = 0; i < 2; i++)
399 conf_widgets [i].u.button.text = _(conf_widgets [i].u.button.text);
401 for (i = 2; i < w_num; i++)
402 conf_widgets [i].u.checkbox.text = _(conf_widgets [i].u.checkbox.text);
403 #endif /* ENABLE_NLS */
405 /* maximumr length of checkboxes */
406 for (i = 2; i < w_num; i++)
407 maxlen = max (maxlen, str_term_width1 (conf_widgets [i].u.checkbox.text) + 3);
409 /* length of buttons */
410 cancel_len = str_term_width1 (conf_widgets [0].u.button.text) + 2;
411 ok_len = str_term_width1 (conf_widgets [0].u.button.text) + 4; /* default button */
413 blen = cancel_len + ok_len + 2;
415 dlg_width = max (maxlen, blen) + 6;
416 dlg_width = max (dlg_width, str_term_width1 (title) + 4);
418 /* correct widget parameters */
419 for (i = 0; i < w_num; i++)
420 conf_widgets[i].x_divisions = dlg_width;
422 conf_widgets[0].relative_x = dlg_width * 2/3 - cancel_len/2;
423 conf_widgets[1].relative_x = dlg_width/3 - ok_len/2;
426 QuickDialog confirmation =
428 dlg_width, dlg_height, -1, -1, title,
429 "[Confirmation]", conf_widgets, 1
432 (void) quick_dialog (&confirmation);
437 #ifndef HAVE_CHARSET
438 void
439 display_bits_box (void) /* AB:FIXME: test dialog */
441 /* dialog sizes */
442 const int DISPY = 13;
443 const int DISPX = 46;
445 int new_meta = 0;
446 int current_mode;
448 const char *display_bits_str [] =
450 N_("UTF-8 output"),
451 N_("Full 8 bits output"),
452 N_("ISO 8859-1"),
453 N_("7 bits")
456 QuickWidget display_widgets[] =
458 /* 0 */ QUICK_BUTTON (15, DISPX, DISPY - 3, DISPY, N_("&Cancel"), B_CANCEL, NULL),
459 /* 1 */ QUICK_BUTTON (29, DISPX, DISPY - 3, DISPY, N_("&OK"), B_ENTER, NULL),
460 /* 2 */ QUICK_CHECKBOX (3, DISPX, 8, DISPY, N_("F&ull 8 bits input"), &new_meta),
461 /* 3 */ QUICK_RADIO (3, DISPX, 3, DISPY, 4, display_bits_str, &current_mode),
462 QUICK_END
465 QuickDialog display_bits =
467 DISPX, DISPY, -1, -1, _(" Display bits "),
468 "[Display bits]", display_widgets, TRUE
471 int i;
472 int l1, maxlen = 0;
473 int ok_len, cancel_len;
475 #ifdef ENABLE_NLS
476 static gboolean i18n_flag = FALSE;
478 if (!i18n_flag) {
479 for (i = 0; i < 3; i++) {
480 display_bits_str[i] = _(display_bits_str [i]);
483 display_widgets[0].u.button.text = _(display_widgets[0].u.button.text);
484 display_widgets[1].u.button.text = _(display_widgets[1].u.button.text);
485 display_widgets[2].u.checkbox.text = _(display_widgets[2].u.checkbox.text);
487 i18n_flag = TRUE;
489 #endif /* ENABLE_NLS */
491 /* radiobuttons */
492 for (i = 0; i < 3; i++)
493 maxlen = max (maxlen, str_term_width1 (display_bits_str [i]));
495 /* buttons */
496 cancel_len = str_term_width1 (display_widgets [0].u.button.text) + 2;
497 ok_len = str_term_width1 (display_widgets [1].u.button.text) + 4; /* default button */
499 l1 = max (cancel_len, ok_len);
501 display_bits.xlen = max (maxlen, l1) + 20;
503 for (i = 0; i < 4; i++)
504 display_widgets[i].x_divisions = display_bits.xlen;
506 display_widgets[0].relative_x = display_bits.xlen * 2/3 - cancel_len/2;
507 display_widgets[1].relative_x = display_bits.xlen/3 - ok_len/2;
509 if (full_eight_bits)
510 current_mode = 0;
511 else if (eight_bit_clean)
512 current_mode = 1;
513 else
514 current_mode = 2;
516 new_meta = !use_8th_bit_as_meta;
518 if (quick_dialog (&display_bits) != B_CANCEL) {
519 eight_bit_clean = current_mode < 3;
520 full_eight_bits = current_mode < 2;
521 #ifndef HAVE_SLANG
522 meta (stdscr, eight_bit_clean);
523 #else
524 SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
525 #endif
526 use_8th_bit_as_meta = !new_meta;
530 #else /* HAVE_CHARSET */
532 static int new_display_codepage;
534 static WLabel *cplabel;
535 static WCheck *inpcheck;
537 static int
538 sel_charset_button (int action)
540 int new_dcp;
542 (void) action;
544 new_dcp = select_charset (-1, -1, new_display_codepage, TRUE);
546 if (new_dcp != SELECT_CHARSET_CANCEL) {
547 const char *cpname;
548 char buf[BUF_TINY];
550 new_display_codepage = new_dcp;
551 cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ?
552 _("Other 8 bit") : codepages[new_display_codepage].name;
553 if (cpname != NULL)
554 utf8_display = str_isutf8 (cpname);
555 /* avoid strange bug with label repainting */
556 g_snprintf (buf, sizeof (buf), "%-27s", cpname);
557 label_set_text (cplabel, buf);
560 return 0;
563 static Dlg_head *
564 init_disp_bits_box (void)
566 /* dialog sizes */
567 const int DISPY = 11;
568 const int DISPX = 46;
570 const char *cpname;
571 Dlg_head *dbits_dlg;
573 do_refresh ();
575 dbits_dlg =
576 create_dlg (0, 0, DISPY, DISPX, dialog_colors, NULL,
577 "[Display bits]", _(" Display bits "), DLG_CENTER | DLG_REVERSE);
579 add_widget (dbits_dlg,
580 label_new (3, 4, _("Input / display codepage:")));
582 cpname = (new_display_codepage < 0)
583 ? _("Other 8 bit")
584 : codepages[new_display_codepage].name;
585 cplabel = label_new (4, 4, cpname);
586 add_widget (dbits_dlg, cplabel);
588 add_widget (dbits_dlg,
589 button_new (DISPY - 3, DISPX / 2 + 3, B_CANCEL,
590 NORMAL_BUTTON, _("&Cancel"), 0));
591 add_widget (dbits_dlg,
592 button_new (DISPY - 3, 7, B_ENTER, NORMAL_BUTTON, _("&OK"),
593 0));
595 inpcheck =
596 check_new (6, 4, !use_8th_bit_as_meta, _("F&ull 8 bits input"));
597 add_widget (dbits_dlg, inpcheck);
599 cpname = _("&Select");
600 add_widget (dbits_dlg,
601 button_new (4, DISPX - 7 - str_term_width1 (cpname), B_USER,
602 NORMAL_BUTTON, cpname, sel_charset_button));
604 return dbits_dlg;
607 void
608 display_bits_box (void)
610 Dlg_head *dbits_dlg;
611 new_display_codepage = display_codepage;
613 application_keypad_mode ();
614 dbits_dlg = init_disp_bits_box ();
616 run_dlg (dbits_dlg);
618 if (dbits_dlg->ret_value == B_ENTER) {
619 const char *errmsg;
620 display_codepage = new_display_codepage;
621 errmsg =
622 init_translation_table (source_codepage, display_codepage);
623 if (errmsg)
624 message (D_ERROR, MSG_ERROR, "%s", errmsg);
625 #ifdef HAVE_SLANG
626 tty_display_8bit (display_codepage != 0 && display_codepage != 1);
627 #else
628 tty_display_8bit (display_codepage != 0);
629 #endif
630 use_8th_bit_as_meta = !(inpcheck->state & C_BOOL);
632 destroy_dlg (dbits_dlg);
633 repaint_screen ();
636 #endif /* HAVE_CHARSET */
639 #define TREE_Y 20
640 #define TREE_X 60
642 static cb_ret_t
643 tree_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
645 switch (msg) {
647 case DLG_POST_KEY:
648 /* The enter key will be processed by the tree widget */
649 if (parm == '\n') {
650 h->ret_value = B_ENTER;
651 dlg_stop (h);
653 return MSG_HANDLED;
655 default:
656 return default_dlg_callback (h, msg, parm);
660 /* Show tree in a box, not on a panel */
661 char *
662 tree_box (const char *current_dir)
664 WTree *mytree;
665 Dlg_head *dlg;
666 char *val = NULL;
667 WButtonBar *bar;
669 (void) current_dir;
670 /* Create the components */
671 dlg = create_dlg (0, 0, TREE_Y, TREE_X, dialog_colors,
672 tree_callback, "[Directory Tree]", NULL, DLG_CENTER | DLG_REVERSE);
673 mytree = tree_new (0, 2, 2, TREE_Y - 6, TREE_X - 5);
674 add_widget (dlg, mytree);
675 bar = buttonbar_new(1);
676 add_widget (dlg, bar);
677 ((Widget *) bar)->x = 0;
678 ((Widget *) bar)->y = LINES - 1;
680 if (run_dlg (dlg) == B_ENTER)
681 val = g_strdup (tree_selected_name (mytree));
683 destroy_dlg (dlg);
684 return val;
687 #ifdef USE_VFS
689 static char *ret_timeout;
691 #ifdef USE_NETCODE
692 static char *ret_passwd;
693 static char *ret_directory_timeout;
694 static char *ret_ftp_proxy;
695 #endif
697 void
698 configure_vfs (void)
700 #define VFSX 56
702 #ifdef USE_NETCODE
703 #define VFSY 17
704 #else
705 #define VFSY 8
706 #endif
708 char buffer2 [BUF_TINY];
709 #ifdef USE_NETCODE
710 char buffer3 [BUF_TINY];
711 #endif
713 QuickWidget confvfs_widgets [] =
715 /* 0 */ QUICK_BUTTON (30, VFSX, VFSY - 3, VFSY, N_("&Cancel"), B_CANCEL, NULL),
716 /* 1 */ QUICK_BUTTON (12, VFSX, VFSY - 3, VFSY, N_("&OK"), B_ENTER, NULL),
717 #ifdef USE_NETCODE
718 /* 2 */ QUICK_CHECKBOX (4, VFSX, 12, VFSY, N_("Use passive mode over pro&xy"), &ftpfs_use_passive_connections_over_proxy),
719 /* 3 */ QUICK_CHECKBOX (4, VFSX, 11, VFSY, N_("Use &passive mode"), &ftpfs_use_passive_connections),
720 /* 4 */ QUICK_CHECKBOX (4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), &use_netrc),
721 /* 5 */ QUICK_INPUT (4, VFSX, 9, VFSY, ftpfs_proxy_host, 48, 0, "input-ftp-proxy", &ret_ftp_proxy),
722 /* 6 */ QUICK_CHECKBOX (4, VFSX, 8, VFSY, N_("&Always use ftp proxy"), &ftpfs_always_use_proxy),
723 /* 7 */ QUICK_LABEL (49, VFSX, 7, VFSY, N_("sec")),
724 /* 8 */ QUICK_INPUT (38, VFSX, 7, VFSY, buffer3, 10, 0, "input-timeout", &ret_directory_timeout),
725 /* 9 */ QUICK_LABEL (4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:")),
726 /* 10 */ QUICK_INPUT (4, VFSX, 6, VFSY, ftpfs_anonymous_passwd, 48, 0, "input-passwd", &ret_passwd),
727 /* 11 */ QUICK_LABEL (4, VFSX, 5, VFSY, N_("ftp anonymous password:")),
728 #endif
729 /* 12 */ QUICK_LABEL (49, VFSX, 3, VFSY, N_("sec")),
730 /* 13 */ QUICK_INPUT (38, VFSX, 3, VFSY, buffer2, 10, 0, "input-timo-vfs", &ret_timeout),
731 /* 14 */ QUICK_LABEL (4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:")),
732 QUICK_END
735 QuickDialog confvfs_dlg =
737 VFSX, VFSY, -1, -1, N_(" Virtual File System Setting "),
738 "[Virtual FS]", confvfs_widgets, FALSE
741 #ifdef SE_NETCODE
742 g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
743 #endif
744 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
746 if (quick_dialog (&confvfs_dlg) != B_CANCEL) {
747 vfs_timeout = atoi (ret_timeout);
748 g_free (ret_timeout);
750 if (vfs_timeout < 0 || vfs_timeout > 10000)
751 vfs_timeout = 10;
752 #ifdef USE_NETCODE
753 g_free (ftpfs_anonymous_passwd);
754 ftpfs_anonymous_passwd = ret_passwd;
755 g_free (ftpfs_proxy_host);
756 ftpfs_proxy_host = ret_ftp_proxy;
757 ftpfs_directory_timeout = atoi(ret_directory_timeout);
758 g_free (ret_directory_timeout);
759 #endif
762 #undef VFSX
763 #undef VFSY
766 #endif /* USE_VFS */
768 char *
769 cd_dialog (void)
771 const char *label = N_("cd");
772 const int ylen = 5;
773 const int xlen = 57;
775 int len;
777 #ifdef ENABLE_NLS
778 label = _(label);
779 #endif
781 len = str_term_width1 (label);
784 char *my_str;
786 QuickWidget quick_widgets [] =
788 /* 0 */ QUICK_INPUT (4 + len, xlen, 2, ylen, "", xlen - 7 - len, 2, "input" , &my_str),
789 /* 1 */ QUICK_LABEL (3, xlen, 2, ylen, label),
790 QUICK_END
793 QuickDialog Quick_input =
795 xlen, ylen, 2, LINES - 2 - ylen, _("Quick cd"),
796 "[Quick cd]", quick_widgets, TRUE
799 return (quick_dialog (&Quick_input) != B_CANCEL) ? my_str : NULL;
803 void
804 symlink_dialog (const char *existing, const char *new, char **ret_existing,
805 char **ret_new)
807 QuickWidget quick_widgets[] =
809 /* 0 */ QUICK_BUTTON (50, 80, 6, 8, N_("&Cancel"), B_CANCEL, NULL),
810 /* 1 */ QUICK_BUTTON (16, 80, 6, 8, N_("&OK"), B_ENTER, NULL),
811 /* 2 */ QUICK_INPUT (4, 80, 5, 8, new, 58, 0, "input-1", ret_new),
812 /* 3 */ QUICK_LABEL (4, 80, 4, 8, N_("Symbolic link filename:")),
813 /* 4 */ QUICK_INPUT (4, 80, 3, 8, existing, 58, 0, "input-2", ret_existing),
814 /* 5 */ QUICK_LABEL (4, 80, 2, 8, N_("Existing filename (filename symlink will point to):")),
815 QUICK_END
818 QuickDialog Quick_input =
820 64, 12, -1, -1, N_("Symbolic link"),
821 "[File Menu]", quick_widgets, FALSE
824 if (quick_dialog (&Quick_input) == B_CANCEL) {
825 *ret_new = NULL;
826 *ret_existing = NULL;
830 #ifdef WITH_BACKGROUND
831 #define B_STOP (B_USER+1)
832 #define B_RESUME (B_USER+2)
833 #define B_KILL (B_USER+3)
835 static int JOBS_X = 60;
836 #define JOBS_Y 15
837 static WListbox *bg_list;
838 static Dlg_head *jobs_dlg;
840 static void
841 jobs_fill_listbox (void)
843 static const char *state_str [2];
844 TaskList *tl = task_list;
846 if (!state_str [0]){
847 state_str [0] = _("Running ");
848 state_str [1] = _("Stopped");
851 while (tl){
852 char *s;
854 s = g_strconcat (state_str [tl->state], " ", tl->info, (char *) NULL);
855 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
856 g_free (s);
857 tl = tl->next;
861 static int
862 task_cb (int action)
864 TaskList *tl;
865 int sig = 0;
867 if (!bg_list->list)
868 return 0;
870 /* Get this instance information */
871 tl = (TaskList *) bg_list->current->data;
873 # ifdef SIGTSTP
874 if (action == B_STOP){
875 sig = SIGSTOP;
876 tl->state = Task_Stopped;
877 } else if (action == B_RESUME){
878 sig = SIGCONT;
879 tl->state = Task_Running;
880 } else
881 # endif
882 if (action == B_KILL){
883 sig = SIGKILL;
886 if (sig == SIGKILL)
887 unregister_task_running (tl->pid, tl->fd);
889 kill (tl->pid, sig);
890 listbox_remove_list (bg_list);
891 jobs_fill_listbox ();
893 /* This can be optimized to just redraw this widget :-) */
894 dlg_redraw (jobs_dlg);
896 return 0;
899 static struct
901 const char* name;
902 int xpos;
903 int value;
904 int (*callback)(int);
906 job_buttons [] =
908 {N_("&Stop"), 3, B_STOP, task_cb},
909 {N_("&Resume"), 12, B_RESUME, task_cb},
910 {N_("&Kill"), 23, B_KILL, task_cb},
911 {N_("&OK"), 35, B_CANCEL, NULL }
914 void
915 jobs_cmd (void)
917 register int i;
918 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
920 #ifdef ENABLE_NLS
921 static int i18n_flag = 0;
922 if (!i18n_flag)
924 int startx = job_buttons [0].xpos;
925 int len;
927 for (i = 0; i < n_buttons; i++)
929 job_buttons [i].name = _(job_buttons [i].name);
931 len = str_term_width1 (job_buttons [i].name) + 4;
932 JOBS_X = max (JOBS_X, startx + len + 3);
934 job_buttons [i].xpos = startx;
935 startx += len;
938 /* Last button - Ok a.k.a. Cancel :) */
939 job_buttons [n_buttons - 1].xpos =
940 JOBS_X - str_term_width1 (job_buttons [n_buttons - 1].name) - 7;
942 i18n_flag = 1;
944 #endif /* ENABLE_NLS */
946 jobs_dlg = create_dlg (0, 0, JOBS_Y, JOBS_X, dialog_colors, NULL,
947 "[Background jobs]", _("Background Jobs"),
948 DLG_CENTER | DLG_REVERSE);
950 bg_list = listbox_new (2, 3, JOBS_Y - 9, JOBS_X - 7, NULL);
951 add_widget (jobs_dlg, bg_list);
953 i = n_buttons;
954 while (i--)
956 add_widget (jobs_dlg, button_new (JOBS_Y-4,
957 job_buttons [i].xpos, job_buttons [i].value,
958 NORMAL_BUTTON, job_buttons [i].name,
959 job_buttons [i].callback));
962 /* Insert all of task information in the list */
963 jobs_fill_listbox ();
964 run_dlg (jobs_dlg);
966 destroy_dlg (jobs_dlg);
968 #endif /* WITH_BACKGROUND */
970 #ifdef WITH_SMBFS
971 struct smb_authinfo *
972 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
973 const char *user)
975 static int dialog_x = 44;
976 enum { b0 = 3, dialog_y = 12};
977 struct smb_authinfo *return_value;
978 static const char* lc_labs[] = {N_("Domain:"), N_("Username:"), N_("Password:")};
979 static const char* buts[] = {N_("&OK"), N_("&Cancel")};
980 static int ilen = 30, istart = 14;
981 static int b2 = 30;
982 char *title;
983 WInput *in_password;
984 WInput *in_user;
985 WInput *in_domain;
986 Dlg_head *auth_dlg;
988 #ifdef ENABLE_NLS
989 static int i18n_flag = 0;
991 if (!i18n_flag)
993 register int i = sizeof(lc_labs)/sizeof(lc_labs[0]);
994 int l1, maxlen = 0;
996 while (i--)
998 l1 = str_term_width1 (lc_labs [i] = _(lc_labs [i]));
999 if (l1 > maxlen)
1000 maxlen = l1;
1002 i = maxlen + ilen + 7;
1003 if (i > dialog_x)
1004 dialog_x = i;
1006 for (i = sizeof(buts)/sizeof(buts[0]), l1 = 0; i--; )
1008 l1 += str_term_width1 (buts [i] = _(buts [i]));
1010 l1 += 15;
1011 if (l1 > dialog_x)
1012 dialog_x = l1;
1014 ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
1015 istart = dialog_x - 3 - ilen;
1017 b2 = dialog_x - (str_term_width1 (buts[1]) + 6);
1019 i18n_flag = 1;
1022 #endif /* ENABLE_NLS */
1024 if (!domain)
1025 domain = "";
1026 if (!user)
1027 user = "";
1029 title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1031 auth_dlg = create_dlg (0, 0, dialog_y, dialog_x, dialog_colors, NULL,
1032 "[Smb Authinfo]", title, DLG_CENTER | DLG_REVERSE);
1034 g_free (title);
1036 in_user = input_new (5, istart, INPUT_COLOR, ilen, user, "auth_name", INPUT_COMPLETE_DEFAULT);
1037 add_widget (auth_dlg, in_user);
1039 in_domain = input_new (3, istart, INPUT_COLOR, ilen, domain, "auth_domain", INPUT_COMPLETE_DEFAULT);
1040 add_widget (auth_dlg, in_domain);
1041 add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON,
1042 buts[1], 0));
1043 add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON,
1044 buts[0], 0));
1046 in_password = input_new (7, istart, INPUT_COLOR, ilen, "", "auth_password", INPUT_COMPLETE_DEFAULT);
1047 in_password->completion_flags = 0;
1048 in_password->is_password = 1;
1049 add_widget (auth_dlg, in_password);
1051 add_widget (auth_dlg, label_new (7, 3, lc_labs[2]));
1052 add_widget (auth_dlg, label_new (5, 3, lc_labs[1]));
1053 add_widget (auth_dlg, label_new (3, 3, lc_labs[0]));
1055 run_dlg (auth_dlg);
1057 switch (auth_dlg->ret_value) {
1058 case B_CANCEL:
1059 return_value = 0;
1060 break;
1061 default:
1062 return_value = g_new (struct smb_authinfo, 1);
1063 if (return_value) {
1064 return_value->host = g_strdup (host);
1065 return_value->share = g_strdup (share);
1066 return_value->domain = g_strdup (in_domain->buffer);
1067 return_value->user = g_strdup (in_user->buffer);
1068 return_value->password = g_strdup (in_password->buffer);
1072 destroy_dlg (auth_dlg);
1074 return return_value;
1076 #endif /* WITH_SMBFS */