Added dlg_set_top_widget() function
[midnight-commander.git] / src / filemanager / boxes.c
blob7abc8dc216fa1479c2f8a769d2ad89d2a5531c00
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 #include "src/background.h" /* task_list */
64 #ifdef HAVE_CHARSET
65 #include "lib/charsets.h"
66 #include "src/selcodepage.h"
67 #endif
69 #include "command.h" /* For cmdline */
70 #include "dir.h"
71 #include "panel.h" /* LIST_TYPES */
72 #include "tree.h"
73 #include "layout.h" /* for get_nth_panel_name proto */
75 #include "boxes.h"
77 /*** global variables ****************************************************************************/
79 /*** file scope macro definitions ****************************************************************/
81 #ifdef ENABLE_VFS
82 #define VFSX 56
84 #ifdef ENABLE_VFS_FTP
85 #define VFSY 17
86 #else
87 #define VFSY 8
88 #endif /* ENABLE_VFS_FTP */
89 #endif /* ENABLE_VFS */
91 #ifdef WITH_BACKGROUND
92 #define B_STOP (B_USER+1)
93 #define B_RESUME (B_USER+2)
94 #define B_KILL (B_USER+3)
95 #define JOBS_Y 15
96 #endif /* WITH_BACKGROUND */
98 /*** file scope type declarations ****************************************************************/
100 /*** file scope variables ************************************************************************/
102 static WRadio *display_radio;
103 static WInput *display_user_format;
104 static WInput *display_mini_status;
105 static WCheck *display_check_status;
106 static char **displays_status;
107 static int display_user_hotkey = 'u';
109 #ifdef HAVE_CHARSET
110 static int new_display_codepage;
111 static WLabel *cplabel;
112 static WCheck *inpcheck;
113 #endif /* HAVE_CHARSET */
115 #ifdef ENABLE_VFS
116 static char *ret_timeout;
117 #ifdef ENABLE_VFS_FTP
118 static char *ret_ftp_proxy;
119 static char *ret_passwd;
120 static char *ret_directory_timeout;
121 #endif /* ENABLE_VFS_FTP */
122 #endif /* ENABLE_VFS */
124 #ifdef WITH_BACKGROUND
125 static int JOBS_X = 60;
126 static WListbox *bg_list;
127 static Dlg_head *jobs_dlg;
129 static int task_cb (WButton * button, int action);
131 static struct
133 const char *name;
134 int xpos;
135 int value;
136 bcback_fn callback;
138 job_buttons[] =
140 /* *INDENT-OFF* */
141 { N_("&Stop"), 3, B_STOP, task_cb },
142 { N_("&Resume"), 12, B_RESUME, task_cb },
143 { N_("&Kill"), 23, B_KILL, task_cb },
144 { N_("&OK"), 35, B_CANCEL, NULL }
145 /* *INDENT-ON* */
148 #endif /* WITH_BACKGROUND */
150 /*** file scope functions ************************************************************************/
151 /* --------------------------------------------------------------------------------------------- */
153 static cb_ret_t
154 display_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
156 switch (msg)
158 case DLG_KEY:
159 if (parm == '\n')
161 if (dlg_widget_active (display_radio))
163 input_assign_text (display_mini_status, displays_status[display_radio->sel]);
164 dlg_stop (h);
165 return MSG_HANDLED;
168 if (dlg_widget_active (display_user_format))
170 h->ret_value = B_USER + 6;
171 dlg_stop (h);
172 return MSG_HANDLED;
175 if (dlg_widget_active (display_mini_status))
177 h->ret_value = B_USER + 7;
178 dlg_stop (h);
179 return MSG_HANDLED;
183 if ((g_ascii_tolower (parm) == display_user_hotkey)
184 && dlg_widget_active (display_user_format) && dlg_widget_active (display_mini_status))
186 display_radio->pos = display_radio->sel = 3;
187 dlg_select_widget (display_radio); /* force redraw */
188 h->callback (h, (Widget *) display_radio, DLG_ACTION, 0, NULL);
189 return MSG_HANDLED;
191 return MSG_NOT_HANDLED;
193 case DLG_ACTION:
194 if (sender == (Widget *) display_radio)
196 if (!(display_check_status->state & C_BOOL))
197 input_assign_text (display_mini_status, displays_status[display_radio->sel]);
198 input_update (display_mini_status, FALSE);
199 input_update (display_user_format, FALSE);
200 widget_disable (display_user_format->widget, display_radio->sel != 3);
201 return MSG_HANDLED;
204 if (sender == (Widget *) display_check_status)
206 if (display_check_status->state & C_BOOL)
208 widget_disable (display_mini_status->widget, FALSE);
209 input_assign_text (display_mini_status, displays_status[3]);
211 else
213 widget_disable (display_mini_status->widget, TRUE);
214 input_assign_text (display_mini_status, displays_status[display_radio->sel]);
216 input_update (display_mini_status, FALSE);
217 return MSG_HANDLED;
220 return MSG_NOT_HANDLED;
222 default:
223 return default_dlg_callback (h, sender, msg, parm, data);
227 /* --------------------------------------------------------------------------------------------- */
229 static Dlg_head *
230 display_init (int radio_sel, char *init_text, int _check_status, char **_status)
232 int dlg_width = 48, dlg_height = 15;
233 Dlg_head *dd;
235 /* Controls whether the array strings have been translated */
236 const char *displays[LIST_TYPES] = {
237 N_("&Full file list"),
238 N_("&Brief file list"),
239 N_("&Long file list"),
240 N_("&User defined:")
243 /* Index in displays[] for "user defined" */
244 const int user_type_idx = 3;
246 const char *display_title = N_("Listing mode");
247 const char *user_mini_status = N_("User &mini status");
248 const char *ok_name = N_("&OK");
249 const char *cancel_name = N_("&Cancel");
251 WButton *ok_button, *cancel_button;
254 int i, maxlen = 0;
255 const char *cp;
256 int ok_len, cancel_len, b_len, gap;
258 #ifdef ENABLE_NLS
259 display_title = _(display_title);
260 user_mini_status = _(user_mini_status);
261 ok_name = _(ok_name);
262 cancel_name = _(cancel_name);
264 for (i = 0; i < LIST_TYPES; i++)
265 displays[i] = _(displays[i]);
266 #endif
268 /* get hotkey of user-defined format string */
269 cp = strchr (displays[user_type_idx], '&');
270 if (cp != NULL && *++cp != '\0')
271 display_user_hotkey = g_ascii_tolower (*cp);
273 /* xpos will be fixed later */
274 ok_button = button_new (dlg_height - 3, 0, B_ENTER, DEFPUSH_BUTTON, ok_name, 0);
275 ok_len = button_get_len (ok_button);
276 cancel_button = button_new (dlg_height - 3, 0, B_CANCEL, NORMAL_BUTTON, cancel_name, 0);
277 cancel_len = button_get_len (cancel_button);
278 b_len = ok_len + cancel_len + 2;
280 dlg_width = max (dlg_width, str_term_width1 (display_title) + 10);
281 /* calculate max width of radiobutons */
282 for (i = 0; i < LIST_TYPES; i++)
283 maxlen = max (maxlen, str_term_width1 (displays[i]));
284 dlg_width = max (dlg_width, maxlen);
285 dlg_width = max (dlg_width, str_term_width1 (user_mini_status) + 13);
287 /* buttons */
288 dlg_width = max (dlg_width, b_len + 6);
289 gap = (dlg_width - 6 - b_len) / 3;
290 ok_button->widget.x = 3 + gap;
291 cancel_button->widget.x = ok_button->widget.x + ok_len + gap + 2;
294 displays_status = _status;
296 dd = create_dlg (TRUE, 0, 0, dlg_height, dlg_width, dialog_colors,
297 display_callback, "[Listing Mode...]", display_title,
298 DLG_CENTER | DLG_REVERSE);
300 add_widget (dd, cancel_button);
301 add_widget (dd, ok_button);
303 display_mini_status =
304 input_new (10, 8, input_get_default_colors (), dlg_width - 12, _status[radio_sel],
305 "mini-input", INPUT_COMPLETE_DEFAULT);
306 add_widget (dd, display_mini_status);
308 display_check_status = check_new (9, 4, _check_status, user_mini_status);
309 add_widget (dd, display_check_status);
311 display_user_format = input_new (7, 8, input_get_default_colors (), dlg_width - 12, init_text,
312 "user-fmt-input", INPUT_COMPLETE_DEFAULT);
313 add_widget (dd, display_user_format);
315 display_radio = radio_new (3, 4, LIST_TYPES, displays);
316 display_radio->sel = display_radio->pos = radio_sel;
317 add_widget (dd, display_radio);
319 return dd;
322 /* --------------------------------------------------------------------------------------------- */
323 #ifdef HAVE_CHARSET
325 static int
326 sel_charset_button (WButton * button, int action)
328 int new_dcp;
330 (void) button;
331 (void) action;
333 new_dcp = select_charset (-1, -1, new_display_codepage, TRUE);
335 if (new_dcp != SELECT_CHARSET_CANCEL)
337 const char *cpname;
338 char buf[BUF_TINY];
340 new_display_codepage = new_dcp;
341 cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ?
342 _("Other 8 bit") :
343 ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
344 if (cpname != NULL)
345 mc_global.utf8_display = str_isutf8 (cpname);
346 /* avoid strange bug with label repainting */
347 g_snprintf (buf, sizeof (buf), "%-27s", cpname);
348 label_set_text (cplabel, buf);
351 return 0;
354 /* --------------------------------------------------------------------------------------------- */
356 static Dlg_head *
357 init_disp_bits_box (void)
359 /* dialog sizes */
360 const int DISPY = 11;
361 const int DISPX = 46;
363 const char *cpname;
364 Dlg_head *dbits_dlg;
366 do_refresh ();
368 dbits_dlg =
369 create_dlg (TRUE, 0, 0, DISPY, DISPX, dialog_colors, NULL,
370 "[Display bits]", _("Display bits"), DLG_CENTER | DLG_REVERSE);
372 add_widget (dbits_dlg, label_new (3, 4, _("Input / display codepage:")));
374 cpname = (new_display_codepage < 0) ? _("Other 8 bit")
375 : ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name;
376 cplabel = label_new (4, 4, cpname);
377 add_widget (dbits_dlg, cplabel);
379 add_widget (dbits_dlg,
380 button_new (DISPY - 3, DISPX / 2 + 3, B_CANCEL, NORMAL_BUTTON, _("&Cancel"), 0));
381 add_widget (dbits_dlg, button_new (DISPY - 3, 7, B_ENTER, NORMAL_BUTTON, _("&OK"), 0));
383 inpcheck = check_new (6, 4, !use_8th_bit_as_meta, _("F&ull 8 bits input"));
384 add_widget (dbits_dlg, inpcheck);
386 cpname = _("&Select");
387 add_widget (dbits_dlg,
388 button_new (4, DISPX - 7 - str_term_width1 (cpname), B_USER,
389 NORMAL_BUTTON, cpname, sel_charset_button));
391 return dbits_dlg;
393 #endif /* HAVE_CHARSET */
395 /* --------------------------------------------------------------------------------------------- */
397 static cb_ret_t
398 tree_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
400 switch (msg)
402 case DLG_POST_KEY:
403 /* The enter key will be processed by the tree widget */
404 if (parm == '\n')
406 h->ret_value = B_ENTER;
407 dlg_stop (h);
409 return MSG_HANDLED;
411 case DLG_ACTION:
412 return send_message ((Widget *) find_tree (h), WIDGET_COMMAND, parm);
414 default:
415 return default_dlg_callback (h, sender, msg, parm, data);
419 /* --------------------------------------------------------------------------------------------- */
421 #ifdef ENABLE_VFS
422 #ifdef ENABLE_VFS_FTP
424 static cb_ret_t
425 confvfs_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
427 switch (msg)
429 case DLG_ACTION:
430 /* message from "Always use ftp proxy" checkbutton */
431 if (sender != NULL && sender->id == 6)
433 const gboolean not_use = !(((WCheck *) sender)->state & C_BOOL);
434 Widget *w;
436 /* input */
437 w = dlg_find_by_id (h, sender->id - 1);
438 widget_disable (*w, not_use);
439 send_message (w, WIDGET_DRAW, 0);
441 return MSG_HANDLED;
443 return MSG_NOT_HANDLED;
445 default:
446 return default_dlg_callback (h, sender, msg, parm, data);
449 #endif /* ENABLE_VFS_FTP */
450 #endif /* ENABLE_VFS */
452 #ifdef WITH_BACKGROUND
453 static void
454 jobs_fill_listbox (void)
456 static const char *state_str[2];
457 TaskList *tl = task_list;
459 if (!state_str[0])
461 state_str[0] = _("Running");
462 state_str[1] = _("Stopped");
465 while (tl)
467 char *s;
469 s = g_strconcat (state_str[tl->state], " ", tl->info, (char *) NULL);
470 listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
471 g_free (s);
472 tl = tl->next;
476 /* --------------------------------------------------------------------------------------------- */
478 static int
479 task_cb (WButton * button, int action)
481 TaskList *tl;
482 int sig = 0;
484 (void) button;
486 if (bg_list->list == NULL)
487 return 0;
489 /* Get this instance information */
490 listbox_get_current (bg_list, NULL, (void **) &tl);
492 #ifdef SIGTSTP
493 if (action == B_STOP)
495 sig = SIGSTOP;
496 tl->state = Task_Stopped;
498 else if (action == B_RESUME)
500 sig = SIGCONT;
501 tl->state = Task_Running;
503 else
504 #endif
505 if (action == B_KILL)
507 sig = SIGKILL;
510 if (sig == SIGKILL)
511 unregister_task_running (tl->pid, tl->fd);
513 kill (tl->pid, sig);
514 listbox_remove_list (bg_list);
515 jobs_fill_listbox ();
517 /* This can be optimized to just redraw this widget :-) */
518 dlg_redraw (jobs_dlg);
520 return 0;
522 #endif /* WITH_BACKGROUND */
524 /* --------------------------------------------------------------------------------------------- */
525 /*** public functions ****************************************************************************/
526 /* --------------------------------------------------------------------------------------------- */
528 /* return list type */
530 display_box (WPanel * panel, char **userp, char **minip, int *use_msformat, int num)
532 int result = -1;
533 Dlg_head *dd;
534 char *section = NULL;
535 size_t i;
537 if (panel == NULL)
539 const char *p = get_nth_panel_name (num);
540 panel = g_new (WPanel, 1);
541 panel->list_type = list_full;
542 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
543 panel->user_mini_status = 0;
544 for (i = 0; i < LIST_TYPES; i++)
545 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
546 section = g_strconcat ("Temporal:", p, (char *) NULL);
547 if (!mc_config_has_group (mc_main_config, section))
549 g_free (section);
550 section = g_strdup (p);
552 panel_load_setup (panel, section);
553 g_free (section);
556 dd = display_init (panel->list_type, panel->user_format,
557 panel->user_mini_status, panel->user_status_format);
559 if (run_dlg (dd) != B_CANCEL)
561 result = display_radio->sel;
562 *userp = g_strdup (display_user_format->buffer);
563 *minip = g_strdup (display_mini_status->buffer);
564 *use_msformat = display_check_status->state & C_BOOL;
567 if (section != NULL)
569 g_free (panel->user_format);
570 for (i = 0; i < LIST_TYPES; i++)
571 g_free (panel->user_status_format[i]);
572 g_free (panel);
575 destroy_dlg (dd);
577 return result;
580 /* --------------------------------------------------------------------------------------------- */
582 const panel_field_t *
583 sort_box (panel_sort_info_t * info)
585 int dlg_width = 40, dlg_height = 7;
587 const char **sort_orders_names;
588 gsize sort_names_num;
590 int sort_idx = 0;
592 const panel_field_t *result = info->sort_field;
594 sort_orders_names = panel_get_sortable_fields (&sort_names_num);
595 dlg_height += sort_names_num;
598 int max_radio = 0, max_check = 0;
599 int ok_len, cancel_len;
600 gsize i;
602 QuickWidget quick_widgets[] = {
603 /* 0 */
604 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
605 /* 1 */
606 QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
607 /* 2 */
608 QUICK_CHECKBOX (0, dlg_width, 5, dlg_height, N_("&Reverse"), &info->reverse),
609 /* 3 */
610 QUICK_CHECKBOX (0, dlg_width, 4, dlg_height, N_("Case sensi&tive"),
611 &info->case_sensitive),
612 /* 4 */
613 QUICK_CHECKBOX (0, dlg_width, 3, dlg_height, N_("Executable &first"),
614 &info->exec_first),
615 /* 5 */
616 QUICK_RADIO (4, dlg_width, 3, dlg_height, 0, NULL, &sort_idx),
617 QUICK_END
620 QuickDialog quick_dlg = {
621 dlg_width, dlg_height, -1, -1,
622 N_("Sort order"), "[Sort Order...]",
623 quick_widgets, NULL, TRUE
626 quick_widgets[5].u.radio.items = sort_orders_names;
627 quick_widgets[5].u.radio.count = sort_names_num;
629 for (i = 0; i < sort_names_num; i++)
630 if (strcmp (sort_orders_names[i], _(info->sort_field->title_hotkey)) == 0)
632 sort_idx = i;
633 break;
636 #ifdef ENABLE_NLS
637 quick_dlg.title = _(quick_dlg.title);
638 /* buttons */
639 for (i = 0; i < 2; i++)
640 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
641 /* checkboxes */
642 for (i = 2; i < 5; i++)
643 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
644 #endif /* ENABLE_NlS */
646 /* buttons */
647 cancel_len = str_term_width1 (quick_widgets[0].u.button.text) + 4;
648 ok_len = str_term_width1 (quick_widgets[1].u.button.text) + 6;
649 /* checkboxes */
650 for (i = 2; i < 5; i++)
651 max_check = max (max_check, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
652 /* radiobuttons */
653 for (i = 0; i < sort_names_num; i++)
654 max_radio = max (max_radio, str_term_width1 (sort_orders_names[i]) + 4);
656 /* dialog width */
657 dlg_width = max (dlg_width, str_term_width1 (quick_dlg.title) + 8);
658 dlg_width = max (dlg_width, ok_len + cancel_len + 8);
659 dlg_width = max (dlg_width, 2 * max (max_radio, max_check) + 8);
661 /* fix widget and dialog parameters */
662 /* dialog */
663 quick_dlg.xlen = dlg_width;
664 /* widgets */
665 for (i = 0; (size_t) i < sizeof (quick_widgets) / sizeof (quick_widgets[0]) - 1; i++)
666 quick_widgets[i].x_divisions = dlg_width;
667 /* buttons */
668 quick_widgets[0].relative_x = dlg_width * 2 / 3 - cancel_len / 2;
669 quick_widgets[1].relative_x = dlg_width / 3 - ok_len / 2;
670 /* checkboxes */
671 for (i = 2; i < 5; i++)
672 quick_widgets[i].relative_x = dlg_width / 2 + 2;
674 if (quick_dialog (&quick_dlg) != B_CANCEL)
675 result = panel_get_field_by_title_hotkey (sort_orders_names[sort_idx]);
677 if (result == NULL)
678 result = info->sort_field;
680 g_strfreev ((gchar **) sort_orders_names);
681 return result;
684 /* --------------------------------------------------------------------------------------------- */
686 void
687 confirm_box (void)
689 const char *title = _("Confirmation");
691 QuickWidget conf_widgets[] = {
692 /* 0 */ QUICK_BUTTON (29, 46, 10, 13, N_("&Cancel"), B_CANCEL, NULL),
693 /* 1 */ QUICK_BUTTON (12, 46, 10, 13, N_("&OK"), B_ENTER, NULL),
694 /* TRANSLATORS: no need to translate 'Confirmation', it's just a context prefix */
695 /* 2 */ QUICK_CHECKBOX (3, 46, 8, 13, N_("Confirmation|&History cleanup"),
696 &mc_global.widget.confirm_history_cleanup),
697 /* 3 */ QUICK_CHECKBOX (3, 46, 7, 13, N_("Confirmation|Di&rectory hotlist delete"),
698 &confirm_directory_hotlist_delete),
699 /* 4 */ QUICK_CHECKBOX (3, 46, 6, 13, N_("Confirmation|E&xit"), &confirm_exit),
700 /* 5 */ QUICK_CHECKBOX (3, 46, 5, 13, N_("Confirmation|&Execute"), &confirm_execute),
701 /* 6 */ QUICK_CHECKBOX (3, 46, 4, 13, N_("Confirmation|O&verwrite"), &confirm_overwrite),
702 /* 7 */ QUICK_CHECKBOX (3, 46, 3, 13, N_("Confirmation|&Delete"), &confirm_delete),
703 QUICK_END
706 const size_t w_num = sizeof (conf_widgets) / sizeof (conf_widgets[0]) - 1;
708 /* dialog sizes */
709 int dlg_width = 46;
710 int dlg_height = w_num + 5;
712 size_t i;
713 int maxlen = 0;
714 int cancel_len, ok_len, blen;
716 #ifdef ENABLE_NLS
717 title = _(title);
719 for (i = 0; i < 2; i++)
720 conf_widgets[i].u.button.text = _(conf_widgets[i].u.button.text);
721 #endif /* ENABLE_NLS */
723 for (i = 2; i < w_num; i++)
724 conf_widgets[i].u.checkbox.text = Q_ (conf_widgets[i].u.checkbox.text);
726 /* maximum length of checkboxes */
727 for (i = 2; i < w_num; i++)
728 maxlen = max (maxlen, str_term_width1 (conf_widgets[i].u.checkbox.text) + 4);
730 /* length of buttons */
731 cancel_len = str_term_width1 (conf_widgets[0].u.button.text) + 3;
732 ok_len = str_term_width1 (conf_widgets[1].u.button.text) + 5; /* default button */
734 blen = cancel_len + ok_len + 2;
736 dlg_width = max (maxlen, blen) + 6;
737 dlg_width = max (dlg_width, str_term_width1 (title) + 4);
739 /* correct widget parameters */
740 for (i = 0; i < w_num; i++)
742 conf_widgets[i].x_divisions = dlg_width;
743 conf_widgets[i].y_divisions = dlg_height;
746 conf_widgets[1].relative_x = dlg_width / 2 - blen / 2;
747 conf_widgets[0].relative_x = conf_widgets[1].relative_x + ok_len + 2;
750 QuickDialog confirmation = {
751 dlg_width, dlg_height, -1, -1, title,
752 "[Confirmation]", conf_widgets, NULL, TRUE
755 (void) quick_dialog (&confirmation);
759 /* --------------------------------------------------------------------------------------------- */
761 #ifndef HAVE_CHARSET
762 void
763 display_bits_box (void) /* AB:FIXME: test dialog */
765 /* dialog sizes */
766 const int DISPY = 13;
767 const int DISPX = 46;
769 int new_meta = 0;
770 int current_mode;
772 const char *display_bits_str[] = {
773 N_("UTF-8 output"),
774 N_("Full 8 bits output"),
775 N_("ISO 8859-1"),
776 N_("7 bits")
779 QuickWidget display_widgets[] = {
780 /* 0 */ QUICK_BUTTON (15, DISPX, DISPY - 3, DISPY, N_("&Cancel"), B_CANCEL, NULL),
781 /* 1 */ QUICK_BUTTON (29, DISPX, DISPY - 3, DISPY, N_("&OK"), B_ENTER, NULL),
782 /* 2 */ QUICK_CHECKBOX (3, DISPX, 8, DISPY, N_("F&ull 8 bits input"), &new_meta),
783 /* 3 */ QUICK_RADIO (3, DISPX, 3, DISPY, 4, display_bits_str, &current_mode),
784 QUICK_END
787 QuickDialog display_bits = {
788 DISPX, DISPY, -1, -1, _("Display bits"),
789 "[Display bits]", display_widgets, NULL, TRUE
792 int i;
793 int l1, maxlen = 0;
794 int ok_len, cancel_len;
796 #ifdef ENABLE_NLS
797 static gboolean i18n_flag = FALSE;
799 if (!i18n_flag)
801 for (i = 0; i < 3; i++)
803 display_bits_str[i] = _(display_bits_str[i]);
806 display_widgets[0].u.button.text = _(display_widgets[0].u.button.text);
807 display_widgets[1].u.button.text = _(display_widgets[1].u.button.text);
808 display_widgets[2].u.checkbox.text = _(display_widgets[2].u.checkbox.text);
810 i18n_flag = TRUE;
812 #endif /* ENABLE_NLS */
814 /* radiobuttons */
815 for (i = 0; i < 3; i++)
816 maxlen = max (maxlen, str_term_width1 (display_bits_str[i]));
818 /* buttons */
819 cancel_len = str_term_width1 (display_widgets[0].u.button.text) + 2;
820 ok_len = str_term_width1 (display_widgets[1].u.button.text) + 4; /* default button */
822 l1 = max (cancel_len, ok_len);
824 display_bits.xlen = max (maxlen, l1) + 20;
826 for (i = 0; i < 4; i++)
827 display_widgets[i].x_divisions = display_bits.xlen;
829 display_widgets[0].relative_x = display_bits.xlen * 2 / 3 - cancel_len / 2;
830 display_widgets[1].relative_x = display_bits.xlen / 3 - ok_len / 2;
832 if (mc_global.full_eight_bits)
833 current_mode = 0;
834 else if (mc_global.eight_bit_clean)
835 current_mode = 1;
836 else
837 current_mode = 2;
839 new_meta = !use_8th_bit_as_meta;
841 if (quick_dialog (&display_bits) != B_CANCEL)
843 mc_global.eight_bit_clean = current_mode < 3;
844 mc_global.full_eight_bits = current_mode < 2;
845 #ifndef HAVE_SLANG
846 meta (stdscr, mc_global.eight_bit_clean);
847 #else
848 SLsmg_Display_Eight_Bit = mc_global.full_eight_bits ? 128 : 160;
849 #endif
850 use_8th_bit_as_meta = !new_meta;
854 /* --------------------------------------------------------------------------------------------- */
855 #else /* HAVE_CHARSET */
857 void
858 display_bits_box (void)
860 Dlg_head *dbits_dlg;
861 new_display_codepage = mc_global.display_codepage;
863 application_keypad_mode ();
864 dbits_dlg = init_disp_bits_box ();
866 run_dlg (dbits_dlg);
868 if (dbits_dlg->ret_value == B_ENTER)
870 char *errmsg;
872 mc_global.display_codepage = new_display_codepage;
873 errmsg = init_translation_table (mc_global.source_codepage, mc_global.display_codepage);
874 if (errmsg != NULL)
876 message (D_ERROR, MSG_ERROR, "%s", errmsg);
877 g_free (errmsg);
879 #ifdef HAVE_SLANG
880 tty_display_8bit (mc_global.display_codepage != 0 && mc_global.display_codepage != 1);
881 #else
882 tty_display_8bit (mc_global.display_codepage != 0);
883 #endif
884 use_8th_bit_as_meta = !(inpcheck->state & C_BOOL);
886 destroy_dlg (dbits_dlg);
887 repaint_screen ();
889 #endif /* HAVE_CHARSET */
891 /* --------------------------------------------------------------------------------------------- */
892 /** Show tree in a box, not on a panel */
894 char *
895 tree_box (const char *current_dir)
897 WTree *mytree;
898 Dlg_head *dlg;
899 char *val = NULL;
900 WButtonBar *bar;
902 (void) current_dir;
904 /* Create the components */
905 dlg = create_dlg (TRUE, 0, 0, LINES - 9, COLS - 20, dialog_colors,
906 tree_callback, "[Directory Tree]",
907 _("Directory tree"), DLG_CENTER | DLG_REVERSE);
909 mytree = tree_new (2, 2, dlg->lines - 6, dlg->cols - 5, FALSE);
910 add_widget (dlg, mytree);
911 add_widget (dlg, hline_new (dlg->lines - 4, 1, -1));
912 bar = buttonbar_new (TRUE);
913 add_widget (dlg, bar);
914 /* restore ButtonBar coordinates after add_widget() */
915 ((Widget *) bar)->x = 0;
916 ((Widget *) bar)->y = LINES - 1;
918 if (run_dlg (dlg) == B_ENTER)
919 val = vfs_path_to_str (tree_selected_name (mytree));
921 destroy_dlg (dlg);
922 return val;
925 /* --------------------------------------------------------------------------------------------- */
927 #ifdef ENABLE_VFS
928 void
929 configure_vfs (void)
931 char buffer2[BUF_TINY];
932 #ifdef ENABLE_VFS_FTP
933 char buffer3[BUF_TINY];
934 #endif
936 QuickWidget confvfs_widgets[] = {
937 /* 0 */ QUICK_BUTTON (30, VFSX, VFSY - 3, VFSY, N_("&Cancel"), B_CANCEL, NULL),
938 /* 1 */ QUICK_BUTTON (12, VFSX, VFSY - 3, VFSY, N_("&OK"), B_ENTER, NULL),
939 #ifdef ENABLE_VFS_FTP
940 /* 2 */ QUICK_CHECKBOX (4, VFSX, 12, VFSY, N_("Use passive mode over pro&xy"),
941 &ftpfs_use_passive_connections_over_proxy),
942 /* 3 */ QUICK_CHECKBOX (4, VFSX, 11, VFSY, N_("Use &passive mode"),
943 &ftpfs_use_passive_connections),
944 /* 4 */ QUICK_CHECKBOX (4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), &ftpfs_use_netrc),
945 /* 5 */ QUICK_INPUT (4, VFSX, 9, VFSY, ftpfs_proxy_host, 48, 0, "input-ftp-proxy",
946 &ret_ftp_proxy),
947 /* 6 */ QUICK_CHECKBOX (4, VFSX, 8, VFSY, N_("&Always use ftp proxy"),
948 &ftpfs_always_use_proxy),
949 /* 7 */ QUICK_LABEL (49, VFSX, 7, VFSY, N_("sec")),
950 /* 8 */ QUICK_INPUT (38, VFSX, 7, VFSY, buffer3, 10, 0, "input-timeout",
951 &ret_directory_timeout),
952 /* 9 */ QUICK_LABEL (4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:")),
953 /* 10 */ QUICK_INPUT (4, VFSX, 6, VFSY, ftpfs_anonymous_passwd, 48, 0, "input-passwd",
954 &ret_passwd),
955 /* 11 */ QUICK_LABEL (4, VFSX, 5, VFSY, N_("ftp anonymous password:")),
956 #endif /* ENABLE_VFS_FTP */
957 /* 12 */ QUICK_LABEL (49, VFSX, 3, VFSY, N_("sec")),
958 /* 13 */ QUICK_INPUT (38, VFSX, 3, VFSY, buffer2, 10, 0, "input-timo-vfs", &ret_timeout),
959 /* 14 */ QUICK_LABEL (4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:")),
960 QUICK_END
963 QuickDialog confvfs_dlg = {
964 VFSX, VFSY, -1, -1, N_("Virtual File System Setting"),
965 "[Virtual FS]", confvfs_widgets,
966 #ifdef ENABLE_VFS_FTP
967 confvfs_callback,
968 #else
969 NULL,
970 #endif
971 FALSE
974 #ifdef ENABLE_VFS_FTP
975 g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
977 if (!ftpfs_always_use_proxy)
978 confvfs_widgets[5].options = W_DISABLED;
979 #endif
981 g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
983 if (quick_dialog (&confvfs_dlg) != B_CANCEL)
985 vfs_timeout = atoi (ret_timeout);
986 g_free (ret_timeout);
988 if (vfs_timeout < 0 || vfs_timeout > 10000)
989 vfs_timeout = 10;
990 #ifdef ENABLE_VFS_FTP
991 g_free (ftpfs_anonymous_passwd);
992 ftpfs_anonymous_passwd = ret_passwd;
993 g_free (ftpfs_proxy_host);
994 ftpfs_proxy_host = ret_ftp_proxy;
995 ftpfs_directory_timeout = atoi (ret_directory_timeout);
996 g_free (ret_directory_timeout);
997 #endif
1000 #undef VFSX
1001 #undef VFSY
1004 #endif /* ENABLE_VFS */
1006 /* --------------------------------------------------------------------------------------------- */
1008 char *
1009 cd_dialog (void)
1011 const char *label = N_("cd");
1012 const int ylen = 5;
1013 const int xlen = 57;
1015 int len;
1017 #ifdef ENABLE_NLS
1018 label = _(label);
1019 #endif
1021 len = str_term_width1 (label);
1024 char *my_str;
1026 QuickWidget quick_widgets[] = {
1027 /* 0 */ QUICK_INPUT (4 + len, xlen, 2, ylen, "", xlen - 7 - len, 2, "input", &my_str),
1028 /* 1 */ QUICK_LABEL (3, xlen, 2, ylen, label),
1029 QUICK_END
1032 QuickDialog Quick_input = {
1033 xlen, ylen, 2, LINES - 2 - ylen, _("Quick cd"),
1034 "[Quick cd]", quick_widgets, NULL, TRUE
1037 return (quick_dialog (&Quick_input) != B_CANCEL) ? my_str : NULL;
1041 /* --------------------------------------------------------------------------------------------- */
1043 void
1044 symlink_dialog (const vfs_path_t * existing_vpath, const vfs_path_t * new_vpath,
1045 char **ret_existing, char **ret_new)
1047 char *existing = vfs_path_to_str (existing_vpath);
1048 char *new = vfs_path_to_str (new_vpath);
1050 QuickWidget quick_widgets[] = {
1051 /* 0 */ QUICK_BUTTON (50, 80, 6, 8, N_("&Cancel"), B_CANCEL, NULL),
1052 /* 1 */ QUICK_BUTTON (16, 80, 6, 8, N_("&OK"), B_ENTER, NULL),
1053 /* 2 */ QUICK_INPUT (4, 80, 5, 8, new, 58, 0, "input-1", ret_new),
1054 /* 3 */ QUICK_LABEL (4, 80, 4, 8, N_("Symbolic link filename:")),
1055 /* 4 */ QUICK_INPUT (4, 80, 3, 8, existing, 58, 0, "input-2", ret_existing),
1056 /* 5 */ QUICK_LABEL (4, 80, 2, 8,
1057 N_("Existing filename (filename symlink will point to):")),
1058 QUICK_END
1061 QuickDialog Quick_input = {
1062 64, 12, -1, -1, N_("Symbolic link"),
1063 "[File Menu]", quick_widgets, NULL, FALSE
1066 if (quick_dialog (&Quick_input) == B_CANCEL)
1068 *ret_new = NULL;
1069 *ret_existing = NULL;
1071 g_free (existing);
1072 g_free (new);
1075 /* --------------------------------------------------------------------------------------------- */
1077 #ifdef WITH_BACKGROUND
1078 void
1079 jobs_cmd (void)
1081 register int i;
1082 int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
1084 #ifdef ENABLE_NLS
1085 static int i18n_flag = 0;
1086 if (!i18n_flag)
1088 int startx = job_buttons[0].xpos;
1089 int len;
1091 for (i = 0; i < n_buttons; i++)
1093 job_buttons[i].name = _(job_buttons[i].name);
1095 len = str_term_width1 (job_buttons[i].name) + 4;
1096 JOBS_X = max (JOBS_X, startx + len + 3);
1098 job_buttons[i].xpos = startx;
1099 startx += len;
1102 /* Last button - Ok a.k.a. Cancel :) */
1103 job_buttons[n_buttons - 1].xpos =
1104 JOBS_X - str_term_width1 (job_buttons[n_buttons - 1].name) - 7;
1106 i18n_flag = 1;
1108 #endif /* ENABLE_NLS */
1110 jobs_dlg = create_dlg (TRUE, 0, 0, JOBS_Y, JOBS_X, dialog_colors, NULL,
1111 "[Background jobs]", _("Background Jobs"), DLG_CENTER | DLG_REVERSE);
1113 bg_list = listbox_new (2, 3, JOBS_Y - 9, JOBS_X - 7, FALSE, NULL);
1114 add_widget (jobs_dlg, bg_list);
1116 i = n_buttons;
1117 while (i--)
1119 add_widget (jobs_dlg, button_new (JOBS_Y - 4,
1120 job_buttons[i].xpos, job_buttons[i].value,
1121 NORMAL_BUTTON, job_buttons[i].name,
1122 job_buttons[i].callback));
1125 /* Insert all of task information in the list */
1126 jobs_fill_listbox ();
1127 run_dlg (jobs_dlg);
1129 destroy_dlg (jobs_dlg);
1131 #endif /* WITH_BACKGROUND */
1133 /* --------------------------------------------------------------------------------------------- */
1135 #ifdef ENABLE_VFS_SMB
1136 struct smb_authinfo *
1137 vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, const char *user)
1139 static int dialog_x = 44;
1140 int b0 = 3, dialog_y = 12;
1141 static const char *lc_labs[] = { N_("Domain:"), N_("Username:"), N_("Password:") };
1142 static const char *buts[] = { N_("&OK"), N_("&Cancel") };
1143 static int ilen = 30, istart = 14;
1144 static int b2 = 30;
1145 char *title;
1146 WInput *in_password;
1147 WInput *in_user;
1148 WInput *in_domain;
1149 Dlg_head *auth_dlg;
1150 struct smb_authinfo *return_value = NULL;
1152 #ifdef ENABLE_NLS
1153 static int i18n_flag = 0;
1155 if (!i18n_flag)
1157 register int i = sizeof (lc_labs) / sizeof (lc_labs[0]);
1158 int l1, maxlen = 0;
1160 while (i--)
1162 l1 = str_term_width1 (lc_labs[i] = _(lc_labs[i]));
1163 if (l1 > maxlen)
1164 maxlen = l1;
1166 i = maxlen + ilen + 7;
1167 if (i > dialog_x)
1168 dialog_x = i;
1170 for (i = sizeof (buts) / sizeof (buts[0]), l1 = 0; i--;)
1172 l1 += str_term_width1 (buts[i] = _(buts[i]));
1174 l1 += 15;
1175 if (l1 > dialog_x)
1176 dialog_x = l1;
1178 ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
1179 istart = dialog_x - 3 - ilen;
1181 b2 = dialog_x - (str_term_width1 (buts[1]) + 6);
1183 i18n_flag = 1;
1186 #endif /* ENABLE_NLS */
1188 if (!domain)
1189 domain = "";
1190 if (!user)
1191 user = "";
1193 title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
1195 auth_dlg = create_dlg (TRUE, 0, 0, dialog_y, dialog_x, dialog_colors, NULL,
1196 "[Smb Authinfo]", title, DLG_CENTER | DLG_REVERSE);
1198 g_free (title);
1200 in_user =
1201 input_new (5, istart, input_get_default_colors (), ilen, user, "auth_name",
1202 INPUT_COMPLETE_DEFAULT);
1203 add_widget (auth_dlg, in_user);
1205 in_domain =
1206 input_new (3, istart, input_get_default_colors (), ilen, domain, "auth_domain",
1207 INPUT_COMPLETE_DEFAULT);
1209 add_widget (auth_dlg, in_domain);
1210 add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON, buts[1], 0));
1211 add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON, buts[0], 0));
1213 in_password =
1214 input_new (7, istart, input_get_default_colors (), ilen, "", "auth_password",
1215 INPUT_COMPLETE_DEFAULT);
1217 in_password->completion_flags = 0;
1218 in_password->is_password = 1;
1219 add_widget (auth_dlg, in_password);
1221 add_widget (auth_dlg, label_new (7, 3, lc_labs[2]));
1222 add_widget (auth_dlg, label_new (5, 3, lc_labs[1]));
1223 add_widget (auth_dlg, label_new (3, 3, lc_labs[0]));
1225 if (run_dlg (auth_dlg) != B_CANCEL)
1226 return_value = vfs_smb_authinfo_new (host, share, in_domain->buffer, in_user->buffer,
1227 in_password->buffer);
1229 destroy_dlg (auth_dlg);
1231 return return_value;
1233 #endif /* ENABLE_VFS_SMB */
1235 /* --------------------------------------------------------------------------------------------- */