Tweak background operations support.
[midnight-commander.git] / src / filemanager / boxes.c
blobe0d6aef9eedffd81c0f708550eef43e7be1727d5
1 /*
2 Some misc dialog boxes for the program.
4 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 2005, 2006, 2009, 2010, 2011
6 The Free Software Foundation, Inc.
8 Written by:
9 Miguel de Icaza, 1994, 1995
10 Jakub Jelinek, 1995
12 This file is part of the Midnight Commander.
14 The Midnight Commander is free software: you can redistribute it
15 and/or modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation, either version 3 of the License,
17 or (at your option) any later version.
19 The Midnight Commander is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 /** \file boxes.c
29 * \brief Source: Some misc dialog boxes for the program
32 #include <config.h>
34 #include <ctype.h>
35 #include <signal.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <sys/types.h>
40 #include <sys/stat.h>
42 #include "lib/global.h"
44 #include "lib/tty/tty.h"
45 #include "lib/tty/key.h" /* XCTRL and ALT macros */
46 #include "lib/skin.h" /* INPUT_COLOR */
47 #include "lib/mcconfig.h" /* Load/save user formats */
48 #include "lib/strutil.h"
50 #include "lib/vfs/vfs.h"
51 #ifdef ENABLE_VFS_FTP
52 #include "src/vfs/ftpfs/ftpfs.h"
53 #endif /* ENABLE_VFS_FTP */
54 #ifdef ENABLE_VFS_SMB
55 #include "src/vfs/smbfs/smbfs.h"
56 #endif /* ENABLE_VFS_SMB */
58 #include "lib/util.h" /* Q_() */
59 #include "lib/widget.h"
61 #include "src/setup.h" /* For profile_name */
62 #ifdef ENABLE_BACKGROUND
63 #include "src/background.h" /* task_list */
64 #endif
66 #ifdef HAVE_CHARSET
67 #include "lib/charsets.h"
68 #include "src/selcodepage.h"
69 #endif
71 #include "command.h" /* For cmdline */
72 #include "dir.h"
73 #include "panel.h" /* LIST_TYPES */
74 #include "tree.h"
75 #include "layout.h" /* for get_nth_panel_name proto */
77 #include "boxes.h"
79 /*** global variables ****************************************************************************/
81 /*** file scope macro definitions ****************************************************************/
83 #ifdef ENABLE_VFS
84 #define VFSX 56
86 #ifdef ENABLE_VFS_FTP
87 #define VFSY 17
88 #else
89 #define VFSY 8
90 #endif /* ENABLE_VFS_FTP */
91 #endif /* ENABLE_VFS */
93 #ifdef ENABLE_BACKGROUND
94 #define B_STOP (B_USER+1)
95 #define B_RESUME (B_USER+2)
96 #define B_KILL (B_USER+3)
97 #define JOBS_Y 15
98 #endif /* ENABLE_BACKGROUND */
100 /*** file scope type declarations ****************************************************************/
102 /*** file scope variables ************************************************************************/
104 static WRadio *display_radio;
105 static WInput *display_user_format;
106 static WInput *display_mini_status;
107 static WCheck *display_check_status;
108 static char **displays_status;
109 static int display_user_hotkey = 'u';
111 #ifdef HAVE_CHARSET
112 static int new_display_codepage;
113 static WLabel *cplabel;
114 static WCheck *inpcheck;
115 #endif /* HAVE_CHARSET */
117 #ifdef ENABLE_VFS
118 static char *ret_timeout;
119 #ifdef ENABLE_VFS_FTP
120 static char *ret_ftp_proxy;
121 static char *ret_passwd;
122 static char *ret_directory_timeout;
123 #endif /* ENABLE_VFS_FTP */
124 #endif /* ENABLE_VFS */
126 #ifdef ENABLE_BACKGROUND
127 static int JOBS_X = 60;
128 static WListbox *bg_list;
129 static Dlg_head *jobs_dlg;
131 static int task_cb (WButton * button, int action);
133 static struct
135 const char *name;
136 int xpos;
137 int value;
138 bcback_fn callback;
140 job_buttons[] =
142 /* *INDENT-OFF* */
143 { N_("&Stop"), 3, B_STOP, task_cb },
144 { N_("&Resume"), 12, B_RESUME, task_cb },
145 { N_("&Kill"), 23, B_KILL, task_cb },
146 { N_("&OK"), 35, B_CANCEL, NULL }
147 /* *INDENT-ON* */
150 #endif /* ENABLE_BACKGROUND */
152 /*** file scope functions ************************************************************************/
153 /* --------------------------------------------------------------------------------------------- */
155 static cb_ret_t
156 display_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
158 switch (msg)
160 case DLG_KEY:
161 if (parm == '\n')
163 if (dlg_widget_active (display_radio))
165 input_assign_text (display_mini_status, displays_status[display_radio->sel]);
166 dlg_stop (h);
167 return MSG_HANDLED;
170 if (dlg_widget_active (display_user_format))
172 h->ret_value = B_USER + 6;
173 dlg_stop (h);
174 return MSG_HANDLED;
177 if (dlg_widget_active (display_mini_status))
179 h->ret_value = B_USER + 7;
180 dlg_stop (h);
181 return MSG_HANDLED;
185 if ((g_ascii_tolower (parm) == display_user_hotkey)
186 && dlg_widget_active (display_user_format) && dlg_widget_active (display_mini_status))
188 display_radio->pos = display_radio->sel = 3;
189 dlg_select_widget (display_radio); /* force redraw */
190 h->callback (h, (Widget *) display_radio, DLG_ACTION, 0, NULL);
191 return MSG_HANDLED;
193 return MSG_NOT_HANDLED;
195 case DLG_ACTION:
196 if (sender == (Widget *) display_radio)
198 if (!(display_check_status->state & C_BOOL))
199 input_assign_text (display_mini_status, displays_status[display_radio->sel]);
200 input_update (display_mini_status, FALSE);
201 input_update (display_user_format, FALSE);
202 widget_disable (display_user_format->widget, display_radio->sel != 3);
203 return MSG_HANDLED;
206 if (sender == (Widget *) display_check_status)
208 if (display_check_status->state & C_BOOL)
210 widget_disable (display_mini_status->widget, FALSE);
211 input_assign_text (display_mini_status, displays_status[3]);
213 else
215 widget_disable (display_mini_status->widget, TRUE);
216 input_assign_text (display_mini_status, displays_status[display_radio->sel]);
218 input_update (display_mini_status, FALSE);
219 return MSG_HANDLED;
222 return MSG_NOT_HANDLED;
224 default:
225 return default_dlg_callback (h, sender, msg, parm, data);
229 /* --------------------------------------------------------------------------------------------- */
231 static Dlg_head *
232 display_init (int radio_sel, char *init_text, int _check_status, char **_status)
234 int dlg_width = 48, dlg_height = 15;
235 Dlg_head *dd;
237 /* Controls whether the array strings have been translated */
238 const char *displays[LIST_TYPES] = {
239 N_("&Full file list"),
240 N_("&Brief file list"),
241 N_("&Long file list"),
242 N_("&User defined:")
245 /* Index in displays[] for "user defined" */
246 const int user_type_idx = 3;
248 const char *display_title = N_("Listing mode");
249 const char *user_mini_status = N_("User &mini status");
250 const char *ok_name = N_("&OK");
251 const char *cancel_name = N_("&Cancel");
253 WButton *ok_button, *cancel_button;
256 int i, maxlen = 0;
257 const char *cp;
258 int ok_len, cancel_len, b_len, gap;
260 #ifdef ENABLE_NLS
261 display_title = _(display_title);
262 user_mini_status = _(user_mini_status);
263 ok_name = _(ok_name);
264 cancel_name = _(cancel_name);
266 for (i = 0; i < LIST_TYPES; i++)
267 displays[i] = _(displays[i]);
268 #endif
270 /* get hotkey of user-defined format string */
271 cp = strchr (displays[user_type_idx], '&');
272 if (cp != NULL && *++cp != '\0')
273 display_user_hotkey = g_ascii_tolower (*cp);
275 /* xpos will be fixed later */
276 ok_button = button_new (dlg_height - 3, 0, B_ENTER, DEFPUSH_BUTTON, ok_name, 0);
277 ok_len = button_get_len (ok_button);
278 cancel_button = button_new (dlg_height - 3, 0, B_CANCEL, NORMAL_BUTTON, cancel_name, 0);
279 cancel_len = button_get_len (cancel_button);
280 b_len = ok_len + cancel_len + 2;
282 dlg_width = max (dlg_width, str_term_width1 (display_title) + 10);
283 /* calculate max width of radiobutons */
284 for (i = 0; i < LIST_TYPES; i++)
285 maxlen = max (maxlen, str_term_width1 (displays[i]));
286 dlg_width = max (dlg_width, maxlen);
287 dlg_width = max (dlg_width, str_term_width1 (user_mini_status) + 13);
289 /* buttons */
290 dlg_width = max (dlg_width, b_len + 6);
291 gap = (dlg_width - 6 - b_len) / 3;
292 ok_button->widget.x = 3 + gap;
293 cancel_button->widget.x = ok_button->widget.x + ok_len + gap + 2;
296 displays_status = _status;
298 dd = create_dlg (TRUE, 0, 0, dlg_height, dlg_width, dialog_colors,
299 display_callback, "[Listing Mode...]", display_title,
300 DLG_CENTER | DLG_REVERSE);
302 add_widget (dd, cancel_button);
303 add_widget (dd, ok_button);
305 display_mini_status =
306 input_new (10, 8, input_get_default_colors (), dlg_width - 12, _status[radio_sel],
307 "mini-input", INPUT_COMPLETE_DEFAULT);
308 add_widget (dd, display_mini_status);
310 display_check_status = check_new (9, 4, _check_status, user_mini_status);
311 add_widget (dd, display_check_status);
313 display_user_format = input_new (7, 8, input_get_default_colors (), dlg_width - 12, init_text,
314 "user-fmt-input", INPUT_COMPLETE_DEFAULT);
315 add_widget (dd, display_user_format);
317 display_radio = radio_new (3, 4, LIST_TYPES, displays);
318 display_radio->sel = display_radio->pos = radio_sel;
319 add_widget (dd, display_radio);
321 return dd;
324 /* --------------------------------------------------------------------------------------------- */
325 #ifdef HAVE_CHARSET
327 static int
328 sel_charset_button (WButton * button, int action)
330 int new_dcp;
332 (void) button;
333 (void) action;
335 new_dcp = select_charset (-1, -1, new_display_codepage, TRUE);
337 if (new_dcp != SELECT_CHARSET_CANCEL)
339 const char *cpname;
340 char buf[BUF_TINY];
342 new_display_codepage = new_dcp;
343 cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ?
344 _("Other 8 bit") :
345 ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
346 if (cpname != NULL)
347 mc_global.utf8_display = str_isutf8 (cpname);
348 /* avoid strange bug with label repainting */
349 g_snprintf (buf, sizeof (buf), "%-27s", cpname);
350 label_set_text (cplabel, buf);
353 return 0;
356 /* --------------------------------------------------------------------------------------------- */
358 static Dlg_head *
359 init_disp_bits_box (void)
361 /* dialog sizes */
362 const int DISPY = 11;
363 const int DISPX = 46;
365 const char *cpname;
366 Dlg_head *dbits_dlg;
368 do_refresh ();
370 dbits_dlg =
371 create_dlg (TRUE, 0, 0, DISPY, DISPX, dialog_colors, NULL,
372 "[Display bits]", _("Display bits"), DLG_CENTER | DLG_REVERSE);
374 add_widget (dbits_dlg, label_new (3, 4, _("Input / display codepage:")));
376 cpname = (new_display_codepage < 0) ? _("Other 8 bit")
377 : ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
378 cplabel = label_new (4, 4, cpname);
379 add_widget (dbits_dlg, cplabel);
381 add_widget (dbits_dlg,
382 button_new (DISPY - 3, DISPX / 2 + 3, B_CANCEL, NORMAL_BUTTON, _("&Cancel"), 0));
383 add_widget (dbits_dlg, button_new (DISPY - 3, 7, B_ENTER, NORMAL_BUTTON, _("&OK"), 0));
385 inpcheck = check_new (6, 4, !use_8th_bit_as_meta, _("F&ull 8 bits input"));
386 add_widget (dbits_dlg, inpcheck);
388 cpname = _("&Select");
389 add_widget (dbits_dlg,
390 button_new (4, DISPX - 7 - str_term_width1 (cpname), B_USER,
391 NORMAL_BUTTON, cpname, sel_charset_button));
393 return dbits_dlg;
395 #endif /* HAVE_CHARSET */
397 /* --------------------------------------------------------------------------------------------- */
399 static cb_ret_t
400 tree_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
402 switch (msg)
404 case DLG_POST_KEY:
405 /* The enter key will be processed by the tree widget */
406 if (parm == '\n')
408 h->ret_value = B_ENTER;
409 dlg_stop (h);
411 return MSG_HANDLED;
413 case DLG_ACTION:
414 return send_message ((Widget *) find_tree (h), WIDGET_COMMAND, parm);
416 default:
417 return default_dlg_callback (h, sender, msg, parm, data);
421 /* --------------------------------------------------------------------------------------------- */
423 #ifdef ENABLE_VFS
424 #ifdef ENABLE_VFS_FTP
426 static cb_ret_t
427 confvfs_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
429 switch (msg)
431 case DLG_ACTION:
432 /* message from "Always use ftp proxy" checkbutton */
433 if (sender != NULL && sender->id == 6)
435 const gboolean not_use = !(((WCheck *) sender)->state & C_BOOL);
436 Widget *w;
438 /* input */
439 w = dlg_find_by_id (h, sender->id - 1);
440 widget_disable (*w, not_use);
441 send_message (w, WIDGET_DRAW, 0);
443 return MSG_HANDLED;
445 return MSG_NOT_HANDLED;
447 default:
448 return default_dlg_callback (h, sender, msg, parm, data);
451 #endif /* ENABLE_VFS_FTP */
452 #endif /* ENABLE_VFS */
454 #ifdef ENABLE_BACKGROUND
455 static void
456 jobs_fill_listbox (void)
458 static const char *state_str[2];
459 TaskList *tl = task_list;
461 if (!state_str[0])
463 state_str[0] = _("Running");
464 state_str[1] = _("Stopped");
467 while (tl)
469 char *s;
471 s = g_strconcat (state_str[tl->state], " ", tl->info, (char *) NULL);
472 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
473 g_free (s);
474 tl = tl->next;
478 /* --------------------------------------------------------------------------------------------- */
480 static int
481 task_cb (WButton * button, int action)
483 TaskList *tl;
484 int sig = 0;
486 (void) button;
488 if (bg_list->list == NULL)
489 return 0;
491 /* Get this instance information */
492 listbox_get_current (bg_list, NULL, (void **) &tl);
494 #ifdef SIGTSTP
495 if (action == B_STOP)
497 sig = SIGSTOP;
498 tl->state = Task_Stopped;
500 else if (action == B_RESUME)
502 sig = SIGCONT;
503 tl->state = Task_Running;
505 else
506 #endif
507 if (action == B_KILL)
509 sig = SIGKILL;
512 if (sig == SIGKILL)
513 unregister_task_running (tl->pid, tl->fd);
515 kill (tl->pid, sig);
516 listbox_remove_list (bg_list);
517 jobs_fill_listbox ();
519 /* This can be optimized to just redraw this widget :-) */
520 dlg_redraw (jobs_dlg);
522 return 0;
524 #endif /* ENABLE_BACKGROUND */
526 /* --------------------------------------------------------------------------------------------- */
527 /*** public functions ****************************************************************************/
528 /* --------------------------------------------------------------------------------------------- */
530 /* return list type */
532 display_box (WPanel * panel, char **userp, char **minip, int *use_msformat, int num)
534 int result = -1;
535 Dlg_head *dd;
536 char *section = NULL;
537 size_t i;
539 if (panel == NULL)
541 const char *p = get_nth_panel_name (num);
542 panel = g_new (WPanel, 1);
543 panel->list_type = list_full;
544 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
545 panel->user_mini_status = 0;
546 for (i = 0; i < LIST_TYPES; i++)
547 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
548 section = g_strconcat ("Temporal:", p, (char *) NULL);
549 if (!mc_config_has_group (mc_main_config, section))
551 g_free (section);
552 section = g_strdup (p);
554 panel_load_setup (panel, section);
555 g_free (section);
558 dd = display_init (panel->list_type, panel->user_format,
559 panel->user_mini_status, panel->user_status_format);
561 if (run_dlg (dd) != B_CANCEL)
563 result = display_radio->sel;
564 *userp = g_strdup (display_user_format->buffer);
565 *minip = g_strdup (display_mini_status->buffer);
566 *use_msformat = display_check_status->state & C_BOOL;
569 if (section != NULL)
571 g_free (panel->user_format);
572 for (i = 0; i < LIST_TYPES; i++)
573 g_free (panel->user_status_format[i]);
574 g_free (panel);
577 destroy_dlg (dd);
579 return result;
582 /* --------------------------------------------------------------------------------------------- */
584 const panel_field_t *
585 sort_box (panel_sort_info_t * info)
587 int dlg_width = 40, dlg_height = 7;
589 const char **sort_orders_names;
590 gsize sort_names_num;
592 int sort_idx = 0;
594 const panel_field_t *result = info->sort_field;
596 sort_orders_names = panel_get_sortable_fields (&sort_names_num);
597 dlg_height += sort_names_num;
600 int max_radio = 0, max_check = 0;
601 int ok_len, cancel_len;
602 gsize i;
604 QuickWidget quick_widgets[] = {
605 /* 0 */
606 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
607 /* 1 */
608 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
609 /* 2 */
610 QUICK_CHECKBOX (0, dlg_width, 5, dlg_height, N_("&Reverse"), &info->reverse),
611 /* 3 */
612 QUICK_CHECKBOX (0, dlg_width, 4, dlg_height, N_("Case sensi&tive"),
613 &info->case_sensitive),
614 /* 4 */
615 QUICK_CHECKBOX (0, dlg_width, 3, dlg_height, N_("Executable &first"),
616 &info->exec_first),
617 /* 5 */
618 QUICK_RADIO (4, dlg_width, 3, dlg_height, 0, NULL, &sort_idx),
619 QUICK_END
622 QuickDialog quick_dlg = {
623 dlg_width, dlg_height, -1, -1,
624 N_("Sort order"), "[Sort Order...]",
625 quick_widgets, NULL, TRUE
628 quick_widgets[5].u.radio.items = sort_orders_names;
629 quick_widgets[5].u.radio.count = sort_names_num;
631 for (i = 0; i < sort_names_num; i++)
632 if (strcmp (sort_orders_names[i], _(info->sort_field->title_hotkey)) == 0)
634 sort_idx = i;
635 break;
638 #ifdef ENABLE_NLS
639 quick_dlg.title = _(quick_dlg.title);
640 /* buttons */
641 for (i = 0; i < 2; i++)
642 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
643 /* checkboxes */
644 for (i = 2; i < 5; i++)
645 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
646 #endif /* ENABLE_NlS */
648 /* buttons */
649 cancel_len = str_term_width1 (quick_widgets[0].u.button.text) + 4;
650 ok_len = str_term_width1 (quick_widgets[1].u.button.text) + 6;
651 /* checkboxes */
652 for (i = 2; i < 5; i++)
653 max_check = max (max_check, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
654 /* radiobuttons */
655 for (i = 0; i < sort_names_num; i++)
656 max_radio = max (max_radio, str_term_width1 (sort_orders_names[i]) + 4);
658 /* dialog width */
659 dlg_width = max (dlg_width, str_term_width1 (quick_dlg.title) + 8);
660 dlg_width = max (dlg_width, ok_len + cancel_len + 8);
661 dlg_width = max (dlg_width, 2 * max (max_radio, max_check) + 8);
663 /* fix widget and dialog parameters */
664 /* dialog */
665 quick_dlg.xlen = dlg_width;
666 /* widgets */
667 for (i = 0; (size_t) i < sizeof (quick_widgets) / sizeof (quick_widgets[0]) - 1; i++)
668 quick_widgets[i].x_divisions = dlg_width;
669 /* buttons */
670 quick_widgets[0].relative_x = dlg_width * 2 / 3 - cancel_len / 2;
671 quick_widgets[1].relative_x = dlg_width / 3 - ok_len / 2;
672 /* checkboxes */
673 for (i = 2; i < 5; i++)
674 quick_widgets[i].relative_x = dlg_width / 2 + 2;
676 if (quick_dialog (&quick_dlg) != B_CANCEL)
677 result = panel_get_field_by_title_hotkey (sort_orders_names[sort_idx]);
679 if (result == NULL)
680 result = info->sort_field;
682 g_strfreev ((gchar **) sort_orders_names);
683 return result;
686 /* --------------------------------------------------------------------------------------------- */
688 void
689 confirm_box (void)
691 const char *title = _("Confirmation");
693 QuickWidget conf_widgets[] = {
694 /* 0 */ QUICK_BUTTON (29, 46, 10, 13, N_("&Cancel"), B_CANCEL, NULL),
695 /* 1 */ QUICK_BUTTON (12, 46, 10, 13, N_("&OK"), B_ENTER, NULL),
696 /* TRANSLATORS: no need to translate 'Confirmation', it's just a context prefix */
697 /* 2 */ QUICK_CHECKBOX (3, 46, 8, 13, N_("Confirmation|&History cleanup"),
698 &mc_global.widget.confirm_history_cleanup),
699 /* 3 */ QUICK_CHECKBOX (3, 46, 7, 13, N_("Confirmation|Di&rectory hotlist delete"),
700 &confirm_directory_hotlist_delete),
701 /* 4 */ QUICK_CHECKBOX (3, 46, 6, 13, N_("Confirmation|E&xit"), &confirm_exit),
702 /* 5 */ QUICK_CHECKBOX (3, 46, 5, 13, N_("Confirmation|&Execute"), &confirm_execute),
703 /* 6 */ QUICK_CHECKBOX (3, 46, 4, 13, N_("Confirmation|O&verwrite"), &confirm_overwrite),
704 /* 7 */ QUICK_CHECKBOX (3, 46, 3, 13, N_("Confirmation|&Delete"), &confirm_delete),
705 QUICK_END
708 const size_t w_num = sizeof (conf_widgets) / sizeof (conf_widgets[0]) - 1;
710 /* dialog sizes */
711 int dlg_width = 46;
712 int dlg_height = w_num + 5;
714 size_t i;
715 int maxlen = 0;
716 int cancel_len, ok_len, blen;
718 #ifdef ENABLE_NLS
719 title = _(title);
721 for (i = 0; i < 2; i++)
722 conf_widgets[i].u.button.text = _(conf_widgets[i].u.button.text);
723 #endif /* ENABLE_NLS */
725 for (i = 2; i < w_num; i++)
726 conf_widgets[i].u.checkbox.text = Q_ (conf_widgets[i].u.checkbox.text);
728 /* maximum length of checkboxes */
729 for (i = 2; i < w_num; i++)
730 maxlen = max (maxlen, str_term_width1 (conf_widgets[i].u.checkbox.text) + 4);
732 /* length of buttons */
733 cancel_len = str_term_width1 (conf_widgets[0].u.button.text) + 3;
734 ok_len = str_term_width1 (conf_widgets[1].u.button.text) + 5; /* default button */
736 blen = cancel_len + ok_len + 2;
738 dlg_width = max (maxlen, blen) + 6;
739 dlg_width = max (dlg_width, str_term_width1 (title) + 4);
741 /* correct widget parameters */
742 for (i = 0; i < w_num; i++)
744 conf_widgets[i].x_divisions = dlg_width;
745 conf_widgets[i].y_divisions = dlg_height;
748 conf_widgets[1].relative_x = dlg_width / 2 - blen / 2;
749 conf_widgets[0].relative_x = conf_widgets[1].relative_x + ok_len + 2;
752 QuickDialog confirmation = {
753 dlg_width, dlg_height, -1, -1, title,
754 "[Confirmation]", conf_widgets, NULL, TRUE
757 (void) quick_dialog (&confirmation);
761 /* --------------------------------------------------------------------------------------------- */
763 #ifndef HAVE_CHARSET
764 void
765 display_bits_box (void) /* AB:FIXME: test dialog */
767 /* dialog sizes */
768 const int DISPY = 13;
769 const int DISPX = 46;
771 int new_meta = 0;
772 int current_mode;
774 const char *display_bits_str[] = {
775 N_("UTF-8 output"),
776 N_("Full 8 bits output"),
777 N_("ISO 8859-1"),
778 N_("7 bits")
781 QuickWidget display_widgets[] = {
782 /* 0 */ QUICK_BUTTON (15, DISPX, DISPY - 3, DISPY, N_("&Cancel"), B_CANCEL, NULL),
783 /* 1 */ QUICK_BUTTON (29, DISPX, DISPY - 3, DISPY, N_("&OK"), B_ENTER, NULL),
784 /* 2 */ QUICK_CHECKBOX (3, DISPX, 8, DISPY, N_("F&ull 8 bits input"), &new_meta),
785 /* 3 */ QUICK_RADIO (3, DISPX, 3, DISPY, 4, display_bits_str, &current_mode),
786 QUICK_END
789 QuickDialog display_bits = {
790 DISPX, DISPY, -1, -1, _("Display bits"),
791 "[Display bits]", display_widgets, NULL, TRUE
794 int i;
795 int l1, maxlen = 0;
796 int ok_len, cancel_len;
798 #ifdef ENABLE_NLS
799 static gboolean i18n_flag = FALSE;
801 if (!i18n_flag)
803 for (i = 0; i < 3; i++)
805 display_bits_str[i] = _(display_bits_str[i]);
808 display_widgets[0].u.button.text = _(display_widgets[0].u.button.text);
809 display_widgets[1].u.button.text = _(display_widgets[1].u.button.text);
810 display_widgets[2].u.checkbox.text = _(display_widgets[2].u.checkbox.text);
812 i18n_flag = TRUE;
814 #endif /* ENABLE_NLS */
816 /* radiobuttons */
817 for (i = 0; i < 3; i++)
818 maxlen = max (maxlen, str_term_width1 (display_bits_str[i]));
820 /* buttons */
821 cancel_len = str_term_width1 (display_widgets[0].u.button.text) + 2;
822 ok_len = str_term_width1 (display_widgets[1].u.button.text) + 4; /* default button */
824 l1 = max (cancel_len, ok_len);
826 display_bits.xlen = max (maxlen, l1) + 20;
828 for (i = 0; i < 4; i++)
829 display_widgets[i].x_divisions = display_bits.xlen;
831 display_widgets[0].relative_x = display_bits.xlen * 2 / 3 - cancel_len / 2;
832 display_widgets[1].relative_x = display_bits.xlen / 3 - ok_len / 2;
834 if (mc_global.full_eight_bits)
835 current_mode = 0;
836 else if (mc_global.eight_bit_clean)
837 current_mode = 1;
838 else
839 current_mode = 2;
841 new_meta = !use_8th_bit_as_meta;
843 if (quick_dialog (&display_bits) != B_CANCEL)
845 mc_global.eight_bit_clean = current_mode < 3;
846 mc_global.full_eight_bits = current_mode < 2;
847 #ifndef HAVE_SLANG
848 meta (stdscr, mc_global.eight_bit_clean);
849 #else
850 SLsmg_Display_Eight_Bit = mc_global.full_eight_bits ? 128 : 160;
851 #endif
852 use_8th_bit_as_meta = !new_meta;
856 /* --------------------------------------------------------------------------------------------- */
857 #else /* HAVE_CHARSET */
859 void
860 display_bits_box (void)
862 Dlg_head *dbits_dlg;
863 new_display_codepage = mc_global.display_codepage;
865 application_keypad_mode ();
866 dbits_dlg = init_disp_bits_box ();
868 run_dlg (dbits_dlg);
870 if (dbits_dlg->ret_value == B_ENTER)
872 char *errmsg;
874 mc_global.display_codepage = new_display_codepage;
875 errmsg = init_translation_table (mc_global.source_codepage, mc_global.display_codepage);
876 if (errmsg != NULL)
878 message (D_ERROR, MSG_ERROR, "%s", errmsg);
879 g_free (errmsg);
881 #ifdef HAVE_SLANG
882 tty_display_8bit (mc_global.display_codepage != 0 && mc_global.display_codepage != 1);
883 #else
884 tty_display_8bit (mc_global.display_codepage != 0);
885 #endif
886 use_8th_bit_as_meta = !(inpcheck->state & C_BOOL);
888 destroy_dlg (dbits_dlg);
889 repaint_screen ();
891 #endif /* HAVE_CHARSET */
893 /* --------------------------------------------------------------------------------------------- */
894 /** Show tree in a box, not on a panel */
896 char *
897 tree_box (const char *current_dir)
899 WTree *mytree;
900 Dlg_head *dlg;
901 char *val = NULL;
902 WButtonBar *bar;
904 (void) current_dir;
906 /* Create the components */
907 dlg = create_dlg (TRUE, 0, 0, LINES - 9, COLS - 20, dialog_colors,
908 tree_callback, "[Directory Tree]",
909 _("Directory tree"), DLG_CENTER | DLG_REVERSE);
911 mytree = tree_new (2, 2, dlg->lines - 6, dlg->cols - 5, FALSE);
912 add_widget (dlg, mytree);
913 add_widget (dlg, hline_new (dlg->lines - 4, 1, -1));
914 bar = buttonbar_new (TRUE);
915 add_widget (dlg, bar);
916 /* restore ButtonBar coordinates after add_widget() */
917 ((Widget *) bar)->x = 0;
918 ((Widget *) bar)->y = LINES - 1;
920 if (run_dlg (dlg) == B_ENTER)
921 val = vfs_path_to_str (tree_selected_name (mytree));
923 destroy_dlg (dlg);
924 return val;
927 /* --------------------------------------------------------------------------------------------- */
929 #ifdef ENABLE_VFS
930 void
931 configure_vfs (void)
933 char buffer2[BUF_TINY];
934 #ifdef ENABLE_VFS_FTP
935 char buffer3[BUF_TINY];
936 #endif
938 QuickWidget confvfs_widgets[] = {
939 /* 0 */ QUICK_BUTTON (30, VFSX, VFSY - 3, VFSY, N_("&Cancel"), B_CANCEL, NULL),
940 /* 1 */ QUICK_BUTTON (12, VFSX, VFSY - 3, VFSY, N_("&OK"), B_ENTER, NULL),
941 #ifdef ENABLE_VFS_FTP
942 /* 2 */ QUICK_CHECKBOX (4, VFSX, 12, VFSY, N_("Use passive mode over pro&xy"),
943 &ftpfs_use_passive_connections_over_proxy),
944 /* 3 */ QUICK_CHECKBOX (4, VFSX, 11, VFSY, N_("Use &passive mode"),
945 &ftpfs_use_passive_connections),
946 /* 4 */ QUICK_CHECKBOX (4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), &ftpfs_use_netrc),
947 /* 5 */ QUICK_INPUT (4, VFSX, 9, VFSY, ftpfs_proxy_host, 48, 0, "input-ftp-proxy",
948 &ret_ftp_proxy),
949 /* 6 */ QUICK_CHECKBOX (4, VFSX, 8, VFSY, N_("&Always use ftp proxy"),
950 &ftpfs_always_use_proxy),
951 /* 7 */ QUICK_LABEL (49, VFSX, 7, VFSY, N_("sec")),
952 /* 8 */ QUICK_INPUT (38, VFSX, 7, VFSY, buffer3, 10, 0, "input-timeout",
953 &ret_directory_timeout),
954 /* 9 */ QUICK_LABEL (4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:")),
955 /* 10 */ QUICK_INPUT (4, VFSX, 6, VFSY, ftpfs_anonymous_passwd, 48, 0, "input-passwd",
956 &ret_passwd),
957 /* 11 */ QUICK_LABEL (4, VFSX, 5, VFSY, N_("ftp anonymous password:")),
958 #endif /* ENABLE_VFS_FTP */
959 /* 12 */ QUICK_LABEL (49, VFSX, 3, VFSY, N_("sec")),
960 /* 13 */ QUICK_INPUT (38, VFSX, 3, VFSY, buffer2, 10, 0, "input-timo-vfs", &ret_timeout),
961 /* 14 */ QUICK_LABEL (4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:")),
962 QUICK_END
965 QuickDialog confvfs_dlg = {
966 VFSX, VFSY, -1, -1, N_("Virtual File System Setting"),
967 "[Virtual FS]", confvfs_widgets,
968 #ifdef ENABLE_VFS_FTP
969 confvfs_callback,
970 #else
971 NULL,
972 #endif
973 FALSE
976 #ifdef ENABLE_VFS_FTP
977 g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
979 if (!ftpfs_always_use_proxy)
980 confvfs_widgets[5].options = W_DISABLED;
981 #endif
983 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
985 if (quick_dialog (&confvfs_dlg) != B_CANCEL)
987 vfs_timeout = atoi (ret_timeout);
988 g_free (ret_timeout);
990 if (vfs_timeout < 0 || vfs_timeout > 10000)
991 vfs_timeout = 10;
992 #ifdef ENABLE_VFS_FTP
993 g_free (ftpfs_anonymous_passwd);
994 ftpfs_anonymous_passwd = ret_passwd;
995 g_free (ftpfs_proxy_host);
996 ftpfs_proxy_host = ret_ftp_proxy;
997 ftpfs_directory_timeout = atoi (ret_directory_timeout);
998 g_free (ret_directory_timeout);
999 #endif
1002 #undef VFSX
1003 #undef VFSY
1006 #endif /* ENABLE_VFS */
1008 /* --------------------------------------------------------------------------------------------- */
1010 char *
1011 cd_dialog (void)
1013 const char *label = N_("cd");
1014 const int ylen = 5;
1015 const int xlen = 57;
1017 int len;
1019 #ifdef ENABLE_NLS
1020 label = _(label);
1021 #endif
1023 len = str_term_width1 (label);
1026 char *my_str;
1028 QuickWidget quick_widgets[] = {
1029 /* 0 */ QUICK_INPUT (4 + len, xlen, 2, ylen, "", xlen - 7 - len, 2, "input", &my_str),
1030 /* 1 */ QUICK_LABEL (3, xlen, 2, ylen, label),
1031 QUICK_END
1034 QuickDialog Quick_input = {
1035 xlen, ylen, 2, LINES - 2 - ylen, _("Quick cd"),
1036 "[Quick cd]", quick_widgets, NULL, TRUE
1039 return (quick_dialog (&Quick_input) != B_CANCEL) ? my_str : NULL;
1043 /* --------------------------------------------------------------------------------------------- */
1045 void
1046 symlink_dialog (const vfs_path_t * existing_vpath, const vfs_path_t * new_vpath,
1047 char **ret_existing, char **ret_new)
1049 char *existing = vfs_path_to_str (existing_vpath);
1050 char *new = vfs_path_to_str (new_vpath);
1052 QuickWidget quick_widgets[] = {
1053 /* 0 */ QUICK_BUTTON (50, 80, 6, 8, N_("&Cancel"), B_CANCEL, NULL),
1054 /* 1 */ QUICK_BUTTON (16, 80, 6, 8, N_("&OK"), B_ENTER, NULL),
1055 /* 2 */ QUICK_INPUT (4, 80, 5, 8, new, 58, 0, "input-1", ret_new),
1056 /* 3 */ QUICK_LABEL (4, 80, 4, 8, N_("Symbolic link filename:")),
1057 /* 4 */ QUICK_INPUT (4, 80, 3, 8, existing, 58, 0, "input-2", ret_existing),
1058 /* 5 */ QUICK_LABEL (4, 80, 2, 8,
1059 N_("Existing filename (filename symlink will point to):")),
1060 QUICK_END
1063 QuickDialog Quick_input = {
1064 64, 12, -1, -1, N_("Symbolic link"),
1065 "[File Menu]", quick_widgets, NULL, FALSE
1068 if (quick_dialog (&Quick_input) == B_CANCEL)
1070 *ret_new = NULL;
1071 *ret_existing = NULL;
1073 g_free (existing);
1074 g_free (new);
1077 /* --------------------------------------------------------------------------------------------- */
1079 #ifdef ENABLE_BACKGROUND
1080 void
1081 jobs_cmd (void)
1083 register int i;
1084 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
1086 #ifdef ENABLE_NLS
1087 static int i18n_flag = 0;
1088 if (!i18n_flag)
1090 int startx = job_buttons[0].xpos;
1091 int len;
1093 for (i = 0; i < n_buttons; i++)
1095 job_buttons[i].name = _(job_buttons[i].name);
1097 len = str_term_width1 (job_buttons[i].name) + 4;
1098 JOBS_X = max (JOBS_X, startx + len + 3);
1100 job_buttons[i].xpos = startx;
1101 startx += len;
1104 /* Last button - Ok a.k.a. Cancel :) */
1105 job_buttons[n_buttons - 1].xpos =
1106 JOBS_X - str_term_width1 (job_buttons[n_buttons - 1].name) - 7;
1108 i18n_flag = 1;
1110 #endif /* ENABLE_NLS */
1112 jobs_dlg = create_dlg (TRUE, 0, 0, JOBS_Y, JOBS_X, dialog_colors, NULL,
1113 "[Background jobs]", _("Background Jobs"), DLG_CENTER | DLG_REVERSE);
1115 bg_list = listbox_new (2, 3, JOBS_Y - 9, JOBS_X - 7, FALSE, NULL);
1116 add_widget (jobs_dlg, bg_list);
1118 i = n_buttons;
1119 while (i--)
1121 add_widget (jobs_dlg, button_new (JOBS_Y - 4,
1122 job_buttons[i].xpos, job_buttons[i].value,
1123 NORMAL_BUTTON, job_buttons[i].name,
1124 job_buttons[i].callback));
1127 /* Insert all of task information in the list */
1128 jobs_fill_listbox ();
1129 run_dlg (jobs_dlg);
1131 destroy_dlg (jobs_dlg);
1133 #endif /* ENABLE_BACKGROUND */
1135 /* --------------------------------------------------------------------------------------------- */
1137 #ifdef ENABLE_VFS_SMB
1138 struct smb_authinfo *
1139 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, const char *user)
1141 static int dialog_x = 44;
1142 int b0 = 3, dialog_y = 12;
1143 static const char *lc_labs[] = { N_("Domain:"), N_("Username:"), N_("Password:") };
1144 static const char *buts[] = { N_("&OK"), N_("&Cancel") };
1145 static int ilen = 30, istart = 14;
1146 static int b2 = 30;
1147 char *title;
1148 WInput *in_password;
1149 WInput *in_user;
1150 WInput *in_domain;
1151 Dlg_head *auth_dlg;
1152 struct smb_authinfo *return_value = NULL;
1154 #ifdef ENABLE_NLS
1155 static int i18n_flag = 0;
1157 if (!i18n_flag)
1159 register int i = sizeof (lc_labs) / sizeof (lc_labs[0]);
1160 int l1, maxlen = 0;
1162 while (i--)
1164 l1 = str_term_width1 (lc_labs[i] = _(lc_labs[i]));
1165 if (l1 > maxlen)
1166 maxlen = l1;
1168 i = maxlen + ilen + 7;
1169 if (i > dialog_x)
1170 dialog_x = i;
1172 for (i = sizeof (buts) / sizeof (buts[0]), l1 = 0; i--;)
1174 l1 += str_term_width1 (buts[i] = _(buts[i]));
1176 l1 += 15;
1177 if (l1 > dialog_x)
1178 dialog_x = l1;
1180 ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
1181 istart = dialog_x - 3 - ilen;
1183 b2 = dialog_x - (str_term_width1 (buts[1]) + 6);
1185 i18n_flag = 1;
1188 #endif /* ENABLE_NLS */
1190 if (!domain)
1191 domain = "";
1192 if (!user)
1193 user = "";
1195 title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1197 auth_dlg = create_dlg (TRUE, 0, 0, dialog_y, dialog_x, dialog_colors, NULL,
1198 "[Smb Authinfo]", title, DLG_CENTER | DLG_REVERSE);
1200 g_free (title);
1202 in_user =
1203 input_new (5, istart, input_get_default_colors (), ilen, user, "auth_name",
1204 INPUT_COMPLETE_DEFAULT);
1205 add_widget (auth_dlg, in_user);
1207 in_domain =
1208 input_new (3, istart, input_get_default_colors (), ilen, domain, "auth_domain",
1209 INPUT_COMPLETE_DEFAULT);
1211 add_widget (auth_dlg, in_domain);
1212 add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON, buts[1], 0));
1213 add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON, buts[0], 0));
1215 in_password =
1216 input_new (7, istart, input_get_default_colors (), ilen, "", "auth_password",
1217 INPUT_COMPLETE_DEFAULT);
1219 in_password->completion_flags = 0;
1220 in_password->is_password = 1;
1221 add_widget (auth_dlg, in_password);
1223 add_widget (auth_dlg, label_new (7, 3, lc_labs[2]));
1224 add_widget (auth_dlg, label_new (5, 3, lc_labs[1]));
1225 add_widget (auth_dlg, label_new (3, 3, lc_labs[0]));
1227 if (run_dlg (auth_dlg) != B_CANCEL)
1228 return_value = vfs_smb_authinfo_new (host, share, in_domain->buffer, in_user->buffer,
1229 in_password->buffer);
1231 destroy_dlg (auth_dlg);
1233 return return_value;
1235 #endif /* ENABLE_VFS_SMB */
1237 /* --------------------------------------------------------------------------------------------- */