Ticket #2097: ChangeLog in its current form does not strictly make any sense
[midnight-commander.git] / src / boxes.c
blob7ccb287d91c48283a3e24951165b519b74ac3a66
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 "lib/global.h"
39 #include "lib/tty/tty.h"
40 #include "lib/skin.h" /* INPUT_COLOR */
41 #include "lib/tty/key.h" /* XCTRL and ALT macros */
42 #include "lib/mcconfig.h" /* Load/save user formats */
43 #include "lib/strutil.h"
45 #ifdef ENABLE_VFS
46 #include "lib/vfs/mc-vfs/vfs.h" /* vfs_timeout */
47 #endif
49 #ifdef USE_NETCODE
50 # include "lib/vfs/mc-vfs/ftpfs.h"
51 #endif
53 #include "dialog.h" /* The nice dialog manager */
54 #include "widget.h" /* The widgets for the nice dialog manager */
55 #include "wtools.h"
56 #include "setup.h" /* For profile_name */
57 #include "command.h" /* For cmdline */
58 #include "dir.h"
59 #include "panel.h" /* LIST_TYPES */
60 #include "boxes.h"
61 #include "main.h" /* For the confirm_* variables */
62 #include "tree.h"
63 #include "layout.h" /* for get_nth_panel_name proto */
64 #include "background.h" /* task_list */
66 #ifdef HAVE_CHARSET
67 #include "charsets.h"
68 #include "selcodepage.h"
69 #endif
72 static WRadio *display_radio;
73 static WInput *display_user_format;
74 static WInput *display_mini_status;
75 static WCheck *display_check_status;
76 static char **displays_status;
77 static int display_user_hotkey = 'u';
79 static cb_ret_t
80 display_callback (Dlg_head *h, Widget *sender,
81 dlg_msg_t msg, int parm, void *data)
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, sender, msg, parm, data);
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;
220 /* return list type */
222 display_box (WPanel *panel, char **userp, char **minip, int *use_msformat, int num)
224 int result = -1;
225 Dlg_head *dd;
226 char *section = NULL;
227 size_t i;
229 if (panel == NULL) {
230 const char *p = get_nth_panel_name (num);
231 panel = g_new (WPanel, 1);
232 panel->list_type = list_full;
233 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
234 panel->user_mini_status = 0;
235 for (i = 0; i < LIST_TYPES; i++)
236 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
237 section = g_strconcat ("Temporal:", p, (char *) NULL);
238 if (! mc_config_has_group (mc_main_config, section)) {
239 g_free (section);
240 section = g_strdup (p);
242 panel_load_setup (panel, section);
243 g_free (section);
246 dd = display_init (panel->list_type, panel->user_format,
247 panel->user_mini_status, panel->user_status_format);
249 if (run_dlg (dd) != B_CANCEL) {
250 result = display_radio->sel;
251 *userp = g_strdup (display_user_format->buffer);
252 *minip = g_strdup (display_mini_status->buffer);
253 *use_msformat = display_check_status->state & C_BOOL;
256 if (section != NULL) {
257 g_free (panel->user_format);
258 for (i = 0; i < LIST_TYPES; i++)
259 g_free (panel->user_status_format [i]);
260 g_free (panel);
263 destroy_dlg (dd);
265 return result;
268 const panel_field_t *
269 sort_box (const panel_field_t *sort_format, int *reverse, int *case_sensitive, int *exec_first)
271 int dlg_width = 40, dlg_height = 7;
273 const char **sort_orders_names;
274 gsize sort_names_num;
276 int sort_idx = 0;
278 const panel_field_t *result = sort_format;
280 sort_orders_names = panel_get_sortable_fields(&sort_names_num);
281 dlg_height += sort_names_num;
284 int max_radio = 0, max_check = 0;
285 int ok_len, cancel_len;
286 gsize i;
288 QuickWidget quick_widgets[] =
290 /* 0 */
291 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
292 /* 1 */
293 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
294 /* 2 */
295 QUICK_CHECKBOX (0, dlg_width, 5, dlg_height, N_("&Reverse"), reverse),
296 /* 3 */
297 QUICK_CHECKBOX (0, dlg_width, 4, dlg_height, N_("Case sensi&tive"), case_sensitive),
298 /* 4 */
299 QUICK_CHECKBOX (0, dlg_width, 3, dlg_height, N_("Executable &first"), exec_first),
300 /* 5 */
301 QUICK_RADIO (4, dlg_width, 3, dlg_height, 0,
302 NULL, &sort_idx),
303 QUICK_END
306 QuickDialog quick_dlg =
308 dlg_width, dlg_height, -1, -1,
309 N_("Sort order"), "[Sort Order...]",
310 quick_widgets, TRUE
313 quick_widgets[5].u.radio.items = sort_orders_names;
314 quick_widgets[5].u.radio.count = sort_names_num;
316 for (i = 0; i < sort_names_num; i++)
317 if (strcmp (sort_orders_names[i], _(sort_format->title_hotkey)) == 0 ) {
318 sort_idx = i;
319 break;
322 #ifdef ENABLE_NLS
323 quick_dlg.title = _(quick_dlg.title);
324 /* buttons */
325 for (i = 0; i < 2; i++)
326 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
327 /* checkboxes */
328 for (i = 2; i < 5; i++)
329 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
330 #endif /* ENABLE_NlS */
332 /* buttons */
333 cancel_len = str_term_width1 (quick_widgets[0].u.button.text) + 4;
334 ok_len = str_term_width1 (quick_widgets[1].u.button.text) + 6;
335 /* checkboxes */
336 for (i = 2; i < 5; i++)
337 max_check = max (max_check, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
338 /* radiobuttons */
339 for (i = 0; i < sort_names_num; i++)
340 max_radio = max (max_radio, str_term_width1 (sort_orders_names[i]) + 4);
342 /* dialog width */
343 dlg_width = max (dlg_width, str_term_width1 (quick_dlg.title) + 8);
344 dlg_width = max (dlg_width, ok_len + cancel_len + 8);
345 dlg_width = max (dlg_width, 2 * max (max_radio, max_check) + 8);
347 /* fix widget and dialog parameters */
348 /* dialog */
349 quick_dlg.xlen = dlg_width;
350 /* widgets */
351 for (i = 0; (size_t) i < sizeof (quick_widgets)/sizeof (quick_widgets[0]) - 1; i++)
352 quick_widgets[i].x_divisions = dlg_width;
353 /* buttons */
354 quick_widgets[0].relative_x = dlg_width * 2/3 - cancel_len/2;
355 quick_widgets[1].relative_x = dlg_width/3 - ok_len/2;
356 /* checkboxes */
357 for (i = 2; i < 5; i++)
358 quick_widgets[i].relative_x = dlg_width/2 + 2;
360 if (quick_dialog (&quick_dlg) != B_CANCEL)
361 result = panel_get_field_by_title_hotkey(sort_orders_names[sort_idx]);
363 if (result == NULL)
364 result = sort_format;
366 g_strfreev((gchar **)sort_orders_names);
367 return result;
371 void
372 confirm_box (void)
374 const char *title = _("Confirmation");
376 QuickWidget conf_widgets [] =
378 /* 0 */ QUICK_BUTTON (29, 46, 10, 13, N_("&Cancel"), B_CANCEL, NULL),
379 /* 1 */ QUICK_BUTTON (12, 46, 10, 13, N_("&OK"), B_ENTER, NULL),
380 /* TRANSLATORS: no need to translate 'Confirmation', it's just a context prefix */
381 /* 2 */ QUICK_CHECKBOX (3, 46, 8, 13, N_("Confirmation|&History cleanup"), &confirm_history_cleanup),
382 /* 3 */ QUICK_CHECKBOX (3, 46, 7, 13, N_("Confirmation|&Directory hotlist delete"), &confirm_directory_hotlist_delete),
383 /* 4 */ QUICK_CHECKBOX (3, 46, 6, 13, N_("Confirmation|E&xit"), &confirm_exit),
384 /* 5 */ QUICK_CHECKBOX (3, 46, 5, 13, N_("Confirmation|&Execute"), &confirm_execute),
385 /* 6 */ QUICK_CHECKBOX (3, 46, 4, 13, N_("Confirmation|O&verwrite"), &confirm_overwrite),
386 /* 7 */ QUICK_CHECKBOX (3, 46, 3, 13, N_("Confirmation|&Delete"), &confirm_delete),
387 QUICK_END
390 const size_t w_num = sizeof (conf_widgets) / sizeof (conf_widgets[0]) - 1;
392 /* dialog sizes */
393 int dlg_width = 46;
394 int dlg_height = w_num + 5;
396 size_t i;
397 int maxlen = 0;
398 int cancel_len, ok_len, blen;
400 #ifdef ENABLE_NLS
401 title = _(title);
403 for (i = 0; i < 2; i++)
404 conf_widgets [i].u.button.text = _(conf_widgets [i].u.button.text);
406 for (i = 2; i < w_num; i++)
407 conf_widgets [i].u.checkbox.text = Q_(conf_widgets [i].u.checkbox.text);
408 #endif /* ENABLE_NLS */
410 /* maximumr length of checkboxes */
411 for (i = 2; i < w_num; i++)
412 maxlen = max (maxlen, str_term_width1 (conf_widgets [i].u.checkbox.text) + 4);
414 /* length of buttons */
415 cancel_len = str_term_width1 (conf_widgets [0].u.button.text) + 3;
416 ok_len = str_term_width1 (conf_widgets [1].u.button.text) + 5; /* default button */
418 blen = cancel_len + ok_len + 2;
420 dlg_width = max (maxlen, blen) + 6;
421 dlg_width = max (dlg_width, str_term_width1 (title) + 4);
423 /* correct widget parameters */
424 for (i = 0; i < w_num; i++) {
425 conf_widgets[i].x_divisions = dlg_width;
426 conf_widgets[i].y_divisions = dlg_height;
429 conf_widgets[1].relative_x = dlg_width/2 - blen/2;
430 conf_widgets[0].relative_x = conf_widgets[1].relative_x + ok_len + 2;
433 QuickDialog confirmation =
435 dlg_width, dlg_height, -1, -1, title,
436 "[Confirmation]", conf_widgets, 1
439 (void) quick_dialog (&confirmation);
444 #ifndef HAVE_CHARSET
445 void
446 display_bits_box (void) /* AB:FIXME: test dialog */
448 /* dialog sizes */
449 const int DISPY = 13;
450 const int DISPX = 46;
452 int new_meta = 0;
453 int current_mode;
455 const char *display_bits_str [] =
457 N_("UTF-8 output"),
458 N_("Full 8 bits output"),
459 N_("ISO 8859-1"),
460 N_("7 bits")
463 QuickWidget display_widgets[] =
465 /* 0 */ QUICK_BUTTON (15, DISPX, DISPY - 3, DISPY, N_("&Cancel"), B_CANCEL, NULL),
466 /* 1 */ QUICK_BUTTON (29, DISPX, DISPY - 3, DISPY, N_("&OK"), B_ENTER, NULL),
467 /* 2 */ QUICK_CHECKBOX (3, DISPX, 8, DISPY, N_("F&ull 8 bits input"), &new_meta),
468 /* 3 */ QUICK_RADIO (3, DISPX, 3, DISPY, 4, display_bits_str, &current_mode),
469 QUICK_END
472 QuickDialog display_bits =
474 DISPX, DISPY, -1, -1, _(" Display bits "),
475 "[Display bits]", display_widgets, TRUE
478 int i;
479 int l1, maxlen = 0;
480 int ok_len, cancel_len;
482 #ifdef ENABLE_NLS
483 static gboolean i18n_flag = FALSE;
485 if (!i18n_flag) {
486 for (i = 0; i < 3; i++) {
487 display_bits_str[i] = _(display_bits_str [i]);
490 display_widgets[0].u.button.text = _(display_widgets[0].u.button.text);
491 display_widgets[1].u.button.text = _(display_widgets[1].u.button.text);
492 display_widgets[2].u.checkbox.text = _(display_widgets[2].u.checkbox.text);
494 i18n_flag = TRUE;
496 #endif /* ENABLE_NLS */
498 /* radiobuttons */
499 for (i = 0; i < 3; i++)
500 maxlen = max (maxlen, str_term_width1 (display_bits_str [i]));
502 /* buttons */
503 cancel_len = str_term_width1 (display_widgets [0].u.button.text) + 2;
504 ok_len = str_term_width1 (display_widgets [1].u.button.text) + 4; /* default button */
506 l1 = max (cancel_len, ok_len);
508 display_bits.xlen = max (maxlen, l1) + 20;
510 for (i = 0; i < 4; i++)
511 display_widgets[i].x_divisions = display_bits.xlen;
513 display_widgets[0].relative_x = display_bits.xlen * 2/3 - cancel_len/2;
514 display_widgets[1].relative_x = display_bits.xlen/3 - ok_len/2;
516 if (full_eight_bits)
517 current_mode = 0;
518 else if (eight_bit_clean)
519 current_mode = 1;
520 else
521 current_mode = 2;
523 new_meta = !use_8th_bit_as_meta;
525 if (quick_dialog (&display_bits) != B_CANCEL) {
526 eight_bit_clean = current_mode < 3;
527 full_eight_bits = current_mode < 2;
528 #ifndef HAVE_SLANG
529 meta (stdscr, eight_bit_clean);
530 #else
531 SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
532 #endif
533 use_8th_bit_as_meta = !new_meta;
537 #else /* HAVE_CHARSET */
539 static int new_display_codepage;
541 static WLabel *cplabel;
542 static WCheck *inpcheck;
544 static int
545 sel_charset_button (int action)
547 int new_dcp;
549 (void) action;
551 new_dcp = select_charset (-1, -1, new_display_codepage, TRUE);
553 if (new_dcp != SELECT_CHARSET_CANCEL) {
554 const char *cpname;
555 char buf[BUF_TINY];
557 new_display_codepage = new_dcp;
558 cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ?
559 _("Other 8 bit") : codepages[new_display_codepage].name;
560 if (cpname != NULL)
561 utf8_display = str_isutf8 (cpname);
562 /* avoid strange bug with label repainting */
563 g_snprintf (buf, sizeof (buf), "%-27s", cpname);
564 label_set_text (cplabel, buf);
567 return 0;
570 static Dlg_head *
571 init_disp_bits_box (void)
573 /* dialog sizes */
574 const int DISPY = 11;
575 const int DISPX = 46;
577 const char *cpname;
578 Dlg_head *dbits_dlg;
580 do_refresh ();
582 dbits_dlg =
583 create_dlg (0, 0, DISPY, DISPX, dialog_colors, NULL,
584 "[Display bits]", _(" Display bits "), DLG_CENTER | DLG_REVERSE);
586 add_widget (dbits_dlg,
587 label_new (3, 4, _("Input / display codepage:")));
589 cpname = (new_display_codepage < 0)
590 ? _("Other 8 bit")
591 : codepages[new_display_codepage].name;
592 cplabel = label_new (4, 4, cpname);
593 add_widget (dbits_dlg, cplabel);
595 add_widget (dbits_dlg,
596 button_new (DISPY - 3, DISPX / 2 + 3, B_CANCEL,
597 NORMAL_BUTTON, _("&Cancel"), 0));
598 add_widget (dbits_dlg,
599 button_new (DISPY - 3, 7, B_ENTER, NORMAL_BUTTON, _("&OK"),
600 0));
602 inpcheck =
603 check_new (6, 4, !use_8th_bit_as_meta, _("F&ull 8 bits input"));
604 add_widget (dbits_dlg, inpcheck);
606 cpname = _("&Select");
607 add_widget (dbits_dlg,
608 button_new (4, DISPX - 7 - str_term_width1 (cpname), B_USER,
609 NORMAL_BUTTON, cpname, sel_charset_button));
611 return dbits_dlg;
614 void
615 display_bits_box (void)
617 Dlg_head *dbits_dlg;
618 new_display_codepage = display_codepage;
620 application_keypad_mode ();
621 dbits_dlg = init_disp_bits_box ();
623 run_dlg (dbits_dlg);
625 if (dbits_dlg->ret_value == B_ENTER) {
626 char *errmsg;
628 display_codepage = new_display_codepage;
629 errmsg = init_translation_table (source_codepage, display_codepage);
630 if (errmsg != NULL) {
631 message (D_ERROR, MSG_ERROR, "%s", errmsg);
632 g_free (errmsg);
634 #ifdef HAVE_SLANG
635 tty_display_8bit (display_codepage != 0 && display_codepage != 1);
636 #else
637 tty_display_8bit (display_codepage != 0);
638 #endif
639 use_8th_bit_as_meta = !(inpcheck->state & C_BOOL);
641 destroy_dlg (dbits_dlg);
642 repaint_screen ();
645 #endif /* HAVE_CHARSET */
647 static cb_ret_t
648 tree_callback (Dlg_head *h, Widget *sender,
649 dlg_msg_t msg, int parm, void *data)
651 switch (msg) {
652 case DLG_POST_KEY:
653 /* The enter key will be processed by the tree widget */
654 if (parm == '\n') {
655 h->ret_value = B_ENTER;
656 dlg_stop (h);
658 return MSG_HANDLED;
660 case DLG_ACTION:
661 /* command from buttonbar */
662 return send_message ((Widget *) find_tree (h), WIDGET_COMMAND, parm);
664 default:
665 return default_dlg_callback (h, sender, msg, parm, data);
669 /* Show tree in a box, not on a panel */
670 char *
671 tree_box (const char *current_dir)
673 WTree *mytree;
674 Dlg_head *dlg;
675 char *val = NULL;
676 WButtonBar *bar;
678 (void) current_dir;
680 /* Create the components */
681 dlg = create_dlg (0, 0, LINES - 9, COLS - 20, dialog_colors,
682 tree_callback, "[Directory Tree]",
683 NULL, DLG_CENTER | DLG_REVERSE);
685 mytree = tree_new (0, 2, 2, dlg->lines - 6, dlg->cols - 5);
686 add_widget (dlg, mytree);
687 bar = buttonbar_new (TRUE);
688 add_widget (dlg, bar);
689 /* restore ButtonBar coordinates after add_widget() */
690 ((Widget *) bar)->x = 0;
691 ((Widget *) bar)->y = LINES - 1;
693 if (run_dlg (dlg) == B_ENTER)
694 val = g_strdup (tree_selected_name (mytree));
696 destroy_dlg (dlg);
697 return val;
700 #ifdef ENABLE_VFS
702 static char *ret_timeout;
704 #ifdef USE_NETCODE
705 static char *ret_passwd;
706 static char *ret_directory_timeout;
707 static char *ret_ftp_proxy;
708 #endif
710 void
711 configure_vfs (void)
713 #define VFSX 56
715 #ifdef USE_NETCODE
716 #define VFSY 17
717 #else
718 #define VFSY 8
719 #endif
721 char buffer2 [BUF_TINY];
722 #ifdef USE_NETCODE
723 char buffer3 [BUF_TINY];
724 #endif
726 QuickWidget confvfs_widgets [] =
728 /* 0 */ QUICK_BUTTON (30, VFSX, VFSY - 3, VFSY, N_("&Cancel"), B_CANCEL, NULL),
729 /* 1 */ QUICK_BUTTON (12, VFSX, VFSY - 3, VFSY, N_("&OK"), B_ENTER, NULL),
730 #ifdef USE_NETCODE
731 /* 2 */ QUICK_CHECKBOX (4, VFSX, 12, VFSY, N_("Use passive mode over pro&xy"), &ftpfs_use_passive_connections_over_proxy),
732 /* 3 */ QUICK_CHECKBOX (4, VFSX, 11, VFSY, N_("Use &passive mode"), &ftpfs_use_passive_connections),
733 /* 4 */ QUICK_CHECKBOX (4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), &use_netrc),
734 /* 5 */ QUICK_INPUT (4, VFSX, 9, VFSY, ftpfs_proxy_host, 48, 0, "input-ftp-proxy", &ret_ftp_proxy),
735 /* 6 */ QUICK_CHECKBOX (4, VFSX, 8, VFSY, N_("&Always use ftp proxy"), &ftpfs_always_use_proxy),
736 /* 7 */ QUICK_LABEL (49, VFSX, 7, VFSY, N_("sec")),
737 /* 8 */ QUICK_INPUT (38, VFSX, 7, VFSY, buffer3, 10, 0, "input-timeout", &ret_directory_timeout),
738 /* 9 */ QUICK_LABEL (4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:")),
739 /* 10 */ QUICK_INPUT (4, VFSX, 6, VFSY, ftpfs_anonymous_passwd, 48, 0, "input-passwd", &ret_passwd),
740 /* 11 */ QUICK_LABEL (4, VFSX, 5, VFSY, N_("ftp anonymous password:")),
741 #endif
742 /* 12 */ QUICK_LABEL (49, VFSX, 3, VFSY, N_("sec")),
743 /* 13 */ QUICK_INPUT (38, VFSX, 3, VFSY, buffer2, 10, 0, "input-timo-vfs", &ret_timeout),
744 /* 14 */ QUICK_LABEL (4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:")),
745 QUICK_END
748 QuickDialog confvfs_dlg =
750 VFSX, VFSY, -1, -1, N_(" Virtual File System Setting "),
751 "[Virtual FS]", confvfs_widgets, FALSE
754 #ifdef USE_NETCODE
755 g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
756 #endif
757 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
759 if (quick_dialog (&confvfs_dlg) != B_CANCEL) {
760 vfs_timeout = atoi (ret_timeout);
761 g_free (ret_timeout);
763 if (vfs_timeout < 0 || vfs_timeout > 10000)
764 vfs_timeout = 10;
765 #ifdef USE_NETCODE
766 g_free (ftpfs_anonymous_passwd);
767 ftpfs_anonymous_passwd = ret_passwd;
768 g_free (ftpfs_proxy_host);
769 ftpfs_proxy_host = ret_ftp_proxy;
770 ftpfs_directory_timeout = atoi(ret_directory_timeout);
771 g_free (ret_directory_timeout);
772 #endif
775 #undef VFSX
776 #undef VFSY
779 #endif /* ENABLE_VFS */
781 char *
782 cd_dialog (void)
784 const char *label = N_("cd");
785 const int ylen = 5;
786 const int xlen = 57;
788 int len;
790 #ifdef ENABLE_NLS
791 label = _(label);
792 #endif
794 len = str_term_width1 (label);
797 char *my_str;
799 QuickWidget quick_widgets [] =
801 /* 0 */ QUICK_INPUT (4 + len, xlen, 2, ylen, "", xlen - 7 - len, 2, "input" , &my_str),
802 /* 1 */ QUICK_LABEL (3, xlen, 2, ylen, label),
803 QUICK_END
806 QuickDialog Quick_input =
808 xlen, ylen, 2, LINES - 2 - ylen, _("Quick cd"),
809 "[Quick cd]", quick_widgets, TRUE
812 return (quick_dialog (&Quick_input) != B_CANCEL) ? my_str : NULL;
816 void
817 symlink_dialog (const char *existing, const char *new, char **ret_existing,
818 char **ret_new)
820 QuickWidget quick_widgets[] =
822 /* 0 */ QUICK_BUTTON (50, 80, 6, 8, N_("&Cancel"), B_CANCEL, NULL),
823 /* 1 */ QUICK_BUTTON (16, 80, 6, 8, N_("&OK"), B_ENTER, NULL),
824 /* 2 */ QUICK_INPUT (4, 80, 5, 8, new, 58, 0, "input-1", ret_new),
825 /* 3 */ QUICK_LABEL (4, 80, 4, 8, N_("Symbolic link filename:")),
826 /* 4 */ QUICK_INPUT (4, 80, 3, 8, existing, 58, 0, "input-2", ret_existing),
827 /* 5 */ QUICK_LABEL (4, 80, 2, 8, N_("Existing filename (filename symlink will point to):")),
828 QUICK_END
831 QuickDialog Quick_input =
833 64, 12, -1, -1, N_("Symbolic link"),
834 "[File Menu]", quick_widgets, FALSE
837 if (quick_dialog (&Quick_input) == B_CANCEL) {
838 *ret_new = NULL;
839 *ret_existing = NULL;
843 #ifdef WITH_BACKGROUND
844 #define B_STOP (B_USER+1)
845 #define B_RESUME (B_USER+2)
846 #define B_KILL (B_USER+3)
848 static int JOBS_X = 60;
849 #define JOBS_Y 15
850 static WListbox *bg_list;
851 static Dlg_head *jobs_dlg;
853 static void
854 jobs_fill_listbox (void)
856 static const char *state_str [2];
857 TaskList *tl = task_list;
859 if (!state_str [0]){
860 state_str [0] = _("Running ");
861 state_str [1] = _("Stopped");
864 while (tl){
865 char *s;
867 s = g_strconcat (state_str [tl->state], " ", tl->info, (char *) NULL);
868 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
869 g_free (s);
870 tl = tl->next;
874 static int
875 task_cb (int action)
877 TaskList *tl;
878 int sig = 0;
880 if (!bg_list->list)
881 return 0;
883 /* Get this instance information */
884 listbox_get_current (bg_list, NULL, (void **) &tl);
886 # ifdef SIGTSTP
887 if (action == B_STOP){
888 sig = SIGSTOP;
889 tl->state = Task_Stopped;
890 } else if (action == B_RESUME){
891 sig = SIGCONT;
892 tl->state = Task_Running;
893 } else
894 # endif
895 if (action == B_KILL){
896 sig = SIGKILL;
899 if (sig == SIGKILL)
900 unregister_task_running (tl->pid, tl->fd);
902 kill (tl->pid, sig);
903 listbox_remove_list (bg_list);
904 jobs_fill_listbox ();
906 /* This can be optimized to just redraw this widget :-) */
907 dlg_redraw (jobs_dlg);
909 return 0;
912 static struct
914 const char* name;
915 int xpos;
916 int value;
917 int (*callback)(int);
919 job_buttons [] =
921 {N_("&Stop"), 3, B_STOP, task_cb},
922 {N_("&Resume"), 12, B_RESUME, task_cb},
923 {N_("&Kill"), 23, B_KILL, task_cb},
924 {N_("&OK"), 35, B_CANCEL, NULL }
927 void
928 jobs_cmd (void)
930 register int i;
931 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
933 #ifdef ENABLE_NLS
934 static int i18n_flag = 0;
935 if (!i18n_flag)
937 int startx = job_buttons [0].xpos;
938 int len;
940 for (i = 0; i < n_buttons; i++)
942 job_buttons [i].name = _(job_buttons [i].name);
944 len = str_term_width1 (job_buttons [i].name) + 4;
945 JOBS_X = max (JOBS_X, startx + len + 3);
947 job_buttons [i].xpos = startx;
948 startx += len;
951 /* Last button - Ok a.k.a. Cancel :) */
952 job_buttons [n_buttons - 1].xpos =
953 JOBS_X - str_term_width1 (job_buttons [n_buttons - 1].name) - 7;
955 i18n_flag = 1;
957 #endif /* ENABLE_NLS */
959 jobs_dlg = create_dlg (0, 0, JOBS_Y, JOBS_X, dialog_colors, NULL,
960 "[Background jobs]", _("Background Jobs"),
961 DLG_CENTER | DLG_REVERSE);
963 bg_list = listbox_new (2, 3, JOBS_Y - 9, JOBS_X - 7, FALSE, NULL);
964 add_widget (jobs_dlg, bg_list);
966 i = n_buttons;
967 while (i--)
969 add_widget (jobs_dlg, button_new (JOBS_Y-4,
970 job_buttons [i].xpos, job_buttons [i].value,
971 NORMAL_BUTTON, job_buttons [i].name,
972 job_buttons [i].callback));
975 /* Insert all of task information in the list */
976 jobs_fill_listbox ();
977 run_dlg (jobs_dlg);
979 destroy_dlg (jobs_dlg);
981 #endif /* WITH_BACKGROUND */
983 #ifdef ENABLE_VFS_SMB
984 struct smb_authinfo *
985 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
986 const char *user)
988 static int dialog_x = 44;
989 enum { b0 = 3, dialog_y = 12};
990 struct smb_authinfo *return_value;
991 static const char* lc_labs[] = {N_("Domain:"), N_("Username:"), N_("Password:")};
992 static const char* buts[] = {N_("&OK"), N_("&Cancel")};
993 static int ilen = 30, istart = 14;
994 static int b2 = 30;
995 char *title;
996 WInput *in_password;
997 WInput *in_user;
998 WInput *in_domain;
999 Dlg_head *auth_dlg;
1001 #ifdef ENABLE_NLS
1002 static int i18n_flag = 0;
1004 if (!i18n_flag)
1006 register int i = sizeof(lc_labs)/sizeof(lc_labs[0]);
1007 int l1, maxlen = 0;
1009 while (i--)
1011 l1 = str_term_width1 (lc_labs [i] = _(lc_labs [i]));
1012 if (l1 > maxlen)
1013 maxlen = l1;
1015 i = maxlen + ilen + 7;
1016 if (i > dialog_x)
1017 dialog_x = i;
1019 for (i = sizeof(buts)/sizeof(buts[0]), l1 = 0; i--; )
1021 l1 += str_term_width1 (buts [i] = _(buts [i]));
1023 l1 += 15;
1024 if (l1 > dialog_x)
1025 dialog_x = l1;
1027 ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
1028 istart = dialog_x - 3 - ilen;
1030 b2 = dialog_x - (str_term_width1 (buts[1]) + 6);
1032 i18n_flag = 1;
1035 #endif /* ENABLE_NLS */
1037 if (!domain)
1038 domain = "";
1039 if (!user)
1040 user = "";
1042 title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1044 auth_dlg = create_dlg (0, 0, dialog_y, dialog_x, dialog_colors, NULL,
1045 "[Smb Authinfo]", title, DLG_CENTER | DLG_REVERSE);
1047 g_free (title);
1049 in_user = input_new (5, istart, INPUT_COLOR, ilen, user, "auth_name", INPUT_COMPLETE_DEFAULT);
1050 add_widget (auth_dlg, in_user);
1052 in_domain = input_new (3, istart, INPUT_COLOR, ilen, domain, "auth_domain", INPUT_COMPLETE_DEFAULT);
1053 add_widget (auth_dlg, in_domain);
1054 add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON,
1055 buts[1], 0));
1056 add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON,
1057 buts[0], 0));
1059 in_password = input_new (7, istart, INPUT_COLOR, ilen, "", "auth_password", INPUT_COMPLETE_DEFAULT);
1060 in_password->completion_flags = 0;
1061 in_password->is_password = 1;
1062 add_widget (auth_dlg, in_password);
1064 add_widget (auth_dlg, label_new (7, 3, lc_labs[2]));
1065 add_widget (auth_dlg, label_new (5, 3, lc_labs[1]));
1066 add_widget (auth_dlg, label_new (3, 3, lc_labs[0]));
1068 run_dlg (auth_dlg);
1070 switch (auth_dlg->ret_value) {
1071 case B_CANCEL:
1072 return_value = 0;
1073 break;
1074 default:
1075 return_value = g_try_new (struct smb_authinfo, 1);
1076 if (return_value) {
1077 return_value->host = g_strdup (host);
1078 return_value->share = g_strdup (share);
1079 return_value->domain = g_strdup (in_domain->buffer);
1080 return_value->user = g_strdup (in_user->buffer);
1081 return_value->password = g_strdup (in_password->buffer);
1085 destroy_dlg (auth_dlg);
1087 return return_value;
1089 #endif /* ENABLE_VFS_SMB */