boxes.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  1. /* Some misc dialog boxes for the program.
  2. Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
  3. 2005, 2006, 2009 Free Software Foundation, Inc.
  4. Authors: 1994, 1995 Miguel de Icaza
  5. 1995 Jakub Jelinek
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  17. /** \file boxes.c
  18. * \brief Source: Some misc dialog boxes for the program
  19. */
  20. #include <config.h>
  21. #include <ctype.h>
  22. #include <signal.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <sys/types.h>
  27. #include <sys/stat.h>
  28. #include "global.h"
  29. #include "../src/tty/tty.h"
  30. #include "../src/skin/skin.h" /* INPUT_COLOR */
  31. #include "../src/tty/key.h" /* XCTRL and ALT macros */
  32. #include "../src/mcconfig/mcconfig.h" /* Load/save user formats */
  33. #include "dialog.h" /* The nice dialog manager */
  34. #include "widget.h" /* The widgets for the nice dialog manager */
  35. #include "wtools.h"
  36. #include "setup.h" /* For profile_name */
  37. #include "command.h" /* For cmdline */
  38. #include "dir.h"
  39. #include "panel.h" /* LIST_TYPES */
  40. #include "boxes.h"
  41. #include "main.h" /* For the confirm_* variables */
  42. #include "tree.h"
  43. #include "layout.h" /* for get_nth_panel_name proto */
  44. #include "background.h" /* task_list */
  45. #include "strutil.h"
  46. #ifdef HAVE_CHARSET
  47. #include "charsets.h"
  48. #include "selcodepage.h"
  49. #endif
  50. #ifdef USE_NETCODE
  51. # include "../vfs/ftpfs.h"
  52. #endif
  53. #ifdef USE_VFS
  54. #include "../vfs/gc.h"
  55. #endif
  56. static WRadio *display_radio;
  57. static WInput *display_user_format;
  58. static WInput *display_mini_status;
  59. static WCheck *display_check_status;
  60. static char **displays_status;
  61. static int display_user_hotkey = 'u';
  62. static cb_ret_t
  63. display_callback (Dlg_head *h, dlg_msg_t msg, int parm)
  64. {
  65. switch (msg) {
  66. case DLG_UNFOCUS:
  67. if (dlg_widget_active (display_radio)) {
  68. assign_text (display_mini_status, displays_status[display_radio->sel]);
  69. input_set_point (display_mini_status, 0);
  70. }
  71. return MSG_HANDLED;
  72. case DLG_KEY:
  73. if (parm == '\n') {
  74. if (dlg_widget_active (display_radio)) {
  75. assign_text (display_mini_status, displays_status[display_radio->sel]);
  76. dlg_stop (h);
  77. return MSG_HANDLED;
  78. }
  79. if (dlg_widget_active (display_user_format)) {
  80. h->ret_value = B_USER + 6;
  81. dlg_stop (h);
  82. return MSG_HANDLED;
  83. }
  84. if (dlg_widget_active (display_mini_status)) {
  85. h->ret_value = B_USER + 7;
  86. dlg_stop (h);
  87. return MSG_HANDLED;
  88. }
  89. }
  90. if (g_ascii_tolower (parm) == display_user_hotkey && dlg_widget_active (display_user_format)
  91. && dlg_widget_active (display_mini_status)) {
  92. display_radio->sel = 3;
  93. dlg_select_widget (display_radio); /* force redraw */
  94. dlg_select_widget (display_user_format);
  95. return MSG_HANDLED;
  96. }
  97. return MSG_NOT_HANDLED;
  98. default:
  99. return default_dlg_callback (h, msg, parm);
  100. }
  101. }
  102. static Dlg_head *
  103. display_init (int radio_sel, char *init_text, int _check_status,
  104. char **_status)
  105. {
  106. int dlg_width = 48, dlg_height = 15;
  107. Dlg_head *dd;
  108. /* Controls whether the array strings have been translated */
  109. const char *displays [LIST_TYPES] =
  110. {
  111. N_("&Full file list"),
  112. N_("&Brief file list"),
  113. N_("&Long file list"),
  114. N_("&User defined:")
  115. };
  116. /* Index in displays[] for "user defined" */
  117. const int user_type_idx = 3;
  118. const char *display_title = N_("Listing mode");
  119. const char *user_mini_status = N_("user &Mini status");
  120. const char *ok_name = N_("&OK");
  121. const char *cancel_name = N_("&Cancel");
  122. WButton *ok_button, *cancel_button;
  123. {
  124. int i, maxlen = 0;
  125. const char *cp;
  126. int ok_len, cancel_len;
  127. #ifdef ENABLE_NLS
  128. display_title = _(display_title);
  129. user_mini_status = _(user_mini_status);
  130. ok_name = _(ok_name);
  131. cancel_name = _(cancel_name);
  132. for (i = 0; i < LIST_TYPES; i++)
  133. displays[i] = _(displays[i]);
  134. #endif
  135. /* get hotkey of user-defined format string */
  136. cp = strchr (displays[user_type_idx], '&');
  137. if (cp != NULL && *++cp != '\0')
  138. display_user_hotkey = g_ascii_tolower (*cp);
  139. /* xpos will be fixed later */
  140. ok_button = button_new (dlg_height - 3, 0, B_ENTER, DEFPUSH_BUTTON, ok_name, 0);
  141. ok_len = button_get_len (ok_button);
  142. cancel_button = button_new (dlg_height - 3, 0, B_CANCEL, NORMAL_BUTTON, cancel_name, 0);
  143. cancel_len = button_get_len (cancel_button);
  144. dlg_width = max (dlg_width, str_term_width1 (display_title) + 10);
  145. /* calculate max width of radiobutons */
  146. for (i = 0; i < LIST_TYPES; i++)
  147. maxlen = max (maxlen, str_term_width1 (displays[i]));
  148. dlg_width = max (dlg_width, maxlen);
  149. dlg_width = max (dlg_width, str_term_width1 (user_mini_status) + 13);
  150. /* buttons */
  151. dlg_width = max (dlg_width, ok_len + cancel_len + 8);
  152. ok_button->widget.x = dlg_width/3 - ok_len/2;
  153. cancel_button->widget.x = dlg_width * 2/3 - cancel_len/2;
  154. }
  155. displays_status = _status;
  156. dd = create_dlg (0, 0, dlg_height, dlg_width, dialog_colors,
  157. display_callback, "[Listing Mode...]", display_title,
  158. DLG_CENTER | DLG_REVERSE);
  159. add_widget (dd, cancel_button);
  160. add_widget (dd, ok_button);
  161. display_mini_status = input_new (10, 8, INPUT_COLOR, dlg_width - 12, _status[radio_sel],
  162. "mini-input", INPUT_COMPLETE_DEFAULT);
  163. add_widget (dd, display_mini_status);
  164. input_set_point (display_mini_status, 0);
  165. display_check_status = check_new (9, 4, _check_status, user_mini_status);
  166. add_widget (dd, display_check_status);
  167. display_user_format = input_new (7, 8, INPUT_COLOR, dlg_width - 12, init_text,
  168. "user-fmt-input", INPUT_COMPLETE_DEFAULT);
  169. add_widget (dd, display_user_format);
  170. input_set_point (display_user_format, 0);
  171. display_radio = radio_new (3, 4, LIST_TYPES, displays);
  172. display_radio->sel = display_radio->pos = radio_sel;
  173. add_widget (dd, display_radio);
  174. return dd;
  175. }
  176. int
  177. display_box (WPanel *panel, char **userp, char **minip, int *use_msformat, int num)
  178. {
  179. int result = -1;
  180. Dlg_head *dd;
  181. char *section = NULL;
  182. int i;
  183. if (panel == NULL) {
  184. const char *p = get_nth_panel_name (num);
  185. panel = g_new (WPanel, 1);
  186. panel->list_type = list_full;
  187. panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
  188. panel->user_mini_status = 0;
  189. for (i = 0; i < LIST_TYPES; i++)
  190. panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
  191. section = g_strconcat ("Temporal:", p, (char *) NULL);
  192. if (! mc_config_has_group (mc_main_config, section)) {
  193. g_free (section);
  194. section = g_strdup (p);
  195. }
  196. panel_load_setup (panel, section);
  197. g_free (section);
  198. }
  199. dd = display_init (panel->list_type, panel->user_format,
  200. panel->user_mini_status, panel->user_status_format);
  201. if (run_dlg (dd) != B_CANCEL) {
  202. result = display_radio->sel;
  203. *userp = g_strdup (display_user_format->buffer);
  204. *minip = g_strdup (display_mini_status->buffer);
  205. *use_msformat = display_check_status->state & C_BOOL;
  206. }
  207. if (section != NULL) {
  208. g_free (panel->user_format);
  209. for (i = 0; i < LIST_TYPES; i++)
  210. g_free (panel->user_status_format [i]);
  211. g_free (panel);
  212. }
  213. destroy_dlg (dd);
  214. return result;
  215. }
  216. sortfn *
  217. sort_box (sortfn *sort_fn, int *reverse, int *case_sensitive, int *exec_first)
  218. {
  219. int dlg_width = 40, dlg_height = 15;
  220. char *sort_orders_names [SORT_TYPES];
  221. int sort_idx = 0;
  222. sortfn *result = sort_fn;
  223. {
  224. int max_radio = 0, max_check = 0;
  225. int ok_len, cancel_len;
  226. int i;
  227. QuickWidget quick_widgets[] =
  228. {
  229. /* 0 */
  230. QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
  231. /* 1 */
  232. QUICK_BUTTON (0, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
  233. /* 2 */
  234. QUICK_CHECKBOX (0, dlg_width, 5, dlg_height, N_("&Reverse"), reverse),
  235. /* 3 */
  236. QUICK_CHECKBOX (0, dlg_width, 4, dlg_height, N_("Case sensi&tive"), case_sensitive),
  237. /* 4 */
  238. QUICK_CHECKBOX (0, dlg_width, 3, dlg_height, N_("Executable &first"), exec_first),
  239. /* 5 */
  240. QUICK_RADIO (4, dlg_width, 3, dlg_height, SORT_TYPES,
  241. (const char **) sort_orders_names, &sort_idx),
  242. QUICK_END
  243. };
  244. QuickDialog quick_dlg =
  245. {
  246. dlg_width, dlg_height, -1, -1,
  247. N_("Sort order"), "[Sort Order...]",
  248. quick_widgets, TRUE
  249. };
  250. for (i = 0; i < SORT_TYPES; i++)
  251. if ((sortfn *) (sort_orders[i].sort_fn) == sort_fn) {
  252. sort_idx = i;
  253. break;
  254. }
  255. #ifdef ENABLE_NLS
  256. quick_dlg.title = _(quick_dlg.title);
  257. /* buttons */
  258. for (i = 0; i < 2; i++)
  259. quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
  260. /* checkboxes */
  261. for (i = 2; i < 5; i++)
  262. quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
  263. /* radiobuttons */
  264. for (i = 0; i < SORT_TYPES; i++)
  265. sort_orders_names[i] = _(sort_orders[i].sort_name);
  266. #else
  267. /* radiobuttons */
  268. for (i = 0; i < SORT_TYPES; i++)
  269. sort_orders_names[i] = sort_orders[i].sort_name;
  270. #endif /* ENABLE_NlS */
  271. /* buttons */
  272. cancel_len = str_term_width1 (quick_widgets[0].u.button.text) + 4;
  273. ok_len = str_term_width1 (quick_widgets[1].u.button.text) + 6;
  274. /* checkboxes */
  275. for (i = 2; i < 5; i++)
  276. max_check = max (max_check, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
  277. /* radiobuttons */
  278. for (i = 0; i < SORT_TYPES; i++)
  279. max_radio = max (max_radio, str_term_width1 (sort_orders_names[i]) + 4);
  280. /* dialog width */
  281. dlg_width = max (dlg_width, str_term_width1 (quick_dlg.title) + 8);
  282. dlg_width = max (dlg_width, ok_len + cancel_len + 8);
  283. dlg_width = max (dlg_width, 2 * max (max_radio, max_check) + 8);
  284. /* fix widget and dialog parameters */
  285. /* dialog */
  286. quick_dlg.xlen = dlg_width;
  287. /* widgets */
  288. for (i = 0; i < sizeof (quick_widgets)/sizeof (quick_widgets[0]) - 1; i++)
  289. quick_widgets[i].x_divisions = dlg_width;
  290. /* buttons */
  291. quick_widgets[0].relative_x = dlg_width * 2/3 - cancel_len/2;
  292. quick_widgets[1].relative_x = dlg_width/3 - ok_len/2;
  293. /* checkboxes */
  294. for (i = 2; i < 5; i++)
  295. quick_widgets[i].relative_x = dlg_width/2 + 2;
  296. if (quick_dialog (&quick_dlg) != B_CANCEL)
  297. result = (sortfn *) sort_orders[sort_idx].sort_fn;
  298. }
  299. return result;
  300. }
  301. void
  302. confirm_box (void)
  303. {
  304. const int w_num = 7;
  305. /* dialog sizes */
  306. int dlg_width = 46;
  307. int dlg_height = 12;
  308. const char *title = _(" Confirmation ");
  309. QuickWidget conf_widgets [] =
  310. {
  311. /* 0 */ QUICK_BUTTON (29, dlg_width, 9, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
  312. /* 1 */ QUICK_BUTTON (12, dlg_width, 9, dlg_height, N_("&OK"), B_ENTER, NULL),
  313. /* 2 */ QUICK_CHECKBOX (3, dlg_width, 7, dlg_height, N_(" confirm di&Rectory hotlist delete "), &confirm_directory_hotlist_delete),
  314. /* 3 */ QUICK_CHECKBOX (3, dlg_width, 6, dlg_height, N_(" confirm &Exit "), &confirm_exit),
  315. /* 4 */ QUICK_CHECKBOX (3, dlg_width, 5, dlg_height, N_(" confirm e&Xecute "), &confirm_execute),
  316. /* 5 */ QUICK_CHECKBOX (3, dlg_width, 4, dlg_height, N_(" confirm o&Verwrite "), &confirm_overwrite),
  317. /* 6 */ QUICK_CHECKBOX (3, dlg_width, 3, dlg_height, N_(" confirm &Delete "), &confirm_delete),
  318. QUICK_END
  319. };
  320. int i;
  321. int maxlen = 0;
  322. int cancel_len, ok_len, blen;
  323. #ifdef ENABLE_NLS
  324. title = _(title);
  325. for (i = 0; i < 2; i++)
  326. conf_widgets [i].u.button.text = _(conf_widgets [i].u.button.text);
  327. for (i = 2; i < w_num; i++)
  328. conf_widgets [i].u.checkbox.text = _(conf_widgets [i].u.checkbox.text);
  329. #endif /* ENABLE_NLS */
  330. /* maximumr length of checkboxes */
  331. for (i = 2; i < w_num; i++)
  332. maxlen = max (maxlen, str_term_width1 (conf_widgets [i].u.checkbox.text) + 3);
  333. /* length of buttons */
  334. cancel_len = str_term_width1 (conf_widgets [0].u.button.text) + 2;
  335. ok_len = str_term_width1 (conf_widgets [0].u.button.text) + 4; /* default button */
  336. blen = cancel_len + ok_len + 2;
  337. dlg_width = max (maxlen, blen) + 6;
  338. dlg_width = max (dlg_width, str_term_width1 (title) + 4);
  339. /* correct widget parameters */
  340. for (i = 0; i < w_num; i++)
  341. conf_widgets[i].x_divisions = dlg_width;
  342. conf_widgets[0].relative_x = dlg_width * 2/3 - cancel_len/2;
  343. conf_widgets[1].relative_x = dlg_width/3 - ok_len/2;
  344. {
  345. QuickDialog confirmation =
  346. {
  347. dlg_width, dlg_height, -1, -1, title,
  348. "[Confirmation]", conf_widgets, 1
  349. };
  350. (void) quick_dialog (&confirmation);
  351. }
  352. }
  353. #ifndef HAVE_CHARSET
  354. void
  355. display_bits_box (void) /* AB:FIXME: test dialog */
  356. {
  357. /* dialog sizes */
  358. const int DISPY = 13;
  359. const int DISPX = 46;
  360. int new_meta = 0;
  361. int current_mode;
  362. const char *display_bits_str [] =
  363. {
  364. N_("UTF-8 output"),
  365. N_("Full 8 bits output"),
  366. N_("ISO 8859-1"),
  367. N_("7 bits")
  368. };
  369. QuickWidget display_widgets[] =
  370. {
  371. /* 0 */ QUICK_BUTTON (15, DISPX, DISPY - 3, DISPY, N_("&Cancel"), B_CANCEL, NULL),
  372. /* 1 */ QUICK_BUTTON (29, DISPX, DISPY - 3, DISPY, N_("&OK"), B_ENTER, NULL),
  373. /* 2 */ QUICK_CHECKBOX (3, DISPX, 8, DISPY, N_("F&ull 8 bits input"), &new_meta),
  374. /* 3 */ QUICK_RADIO (3, DISPX, 3, DISPY, 4, display_bits_str, &current_mode),
  375. QUICK_END
  376. };
  377. QuickDialog display_bits =
  378. {
  379. DISPX, DISPY, -1, -1, _(" Display bits "),
  380. "[Display bits]", display_widgets, TRUE
  381. };
  382. int i;
  383. int l1, maxlen = 0;
  384. int ok_len, cancel_len;
  385. #ifdef ENABLE_NLS
  386. static gboolean i18n_flag = FALSE;
  387. if (!i18n_flag) {
  388. for (i = 0; i < 3; i++) {
  389. display_bits_str[i] = _(display_bits_str [i]);
  390. }
  391. display_widgets[0].u.button.text = _(display_widgets[0].u.button.text);
  392. display_widgets[1].u.button.text = _(display_widgets[1].u.button.text);
  393. display_widgets[2].u.checkbox.text = _(display_widgets[2].u.checkbox.text);
  394. i18n_flag = TRUE;
  395. }
  396. #endif /* ENABLE_NLS */
  397. /* radiobuttons */
  398. for (i = 0; i < 3; i++)
  399. maxlen = max (maxlen, str_term_width1 (display_bits_str [i]));
  400. /* buttons */
  401. cancel_len = str_term_width1 (display_widgets [0].u.button.text) + 2;
  402. ok_len = str_term_width1 (display_widgets [1].u.button.text) + 4; /* default button */
  403. l1 = max (cancel_len, ok_len);
  404. display_bits.xlen = max (maxlen, l1) + 20;
  405. for (i = 0; i < 4; i++)
  406. display_widgets[i].x_divisions = display_bits.xlen;
  407. display_widgets[0].relative_x = display_bits.xlen * 2/3 - cancel_len/2;
  408. display_widgets[1].relative_x = display_bits.xlen/3 - ok_len/2;
  409. if (full_eight_bits)
  410. current_mode = 0;
  411. else if (eight_bit_clean)
  412. current_mode = 1;
  413. else
  414. current_mode = 2;
  415. new_meta = !use_8th_bit_as_meta;
  416. if (quick_dialog (&display_bits) != B_CANCEL) {
  417. eight_bit_clean = current_mode < 3;
  418. full_eight_bits = current_mode < 2;
  419. #ifndef HAVE_SLANG
  420. meta (stdscr, eight_bit_clean);
  421. #else
  422. SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
  423. #endif
  424. use_8th_bit_as_meta = !new_meta;
  425. }
  426. }
  427. #else /* HAVE_CHARSET */
  428. static int new_display_codepage;
  429. static WLabel *cplabel;
  430. static WCheck *inpcheck;
  431. static int
  432. sel_charset_button (int action)
  433. {
  434. int new_dcp;
  435. (void) action;
  436. new_dcp = select_charset (0, 0, new_display_codepage, TRUE);
  437. if (new_dcp != SELECT_CHARSET_CANCEL) {
  438. const char *cpname;
  439. char buf[BUF_TINY];
  440. new_display_codepage = new_dcp;
  441. cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ?
  442. _("Other 8 bit") : codepages[new_display_codepage].name;
  443. if (cpname != NULL)
  444. utf8_display = str_isutf8 (cpname);
  445. /* avoid strange bug with label repainting */
  446. g_snprintf (buf, sizeof (buf), "%-27s", cpname);
  447. label_set_text (cplabel, buf);
  448. }
  449. return 0;
  450. }
  451. static Dlg_head *
  452. init_disp_bits_box (void)
  453. {
  454. /* dialog sizes */
  455. const int DISPY = 11;
  456. const int DISPX = 46;
  457. const char *cpname;
  458. Dlg_head *dbits_dlg;
  459. do_refresh ();
  460. dbits_dlg =
  461. create_dlg (0, 0, DISPY, DISPX, dialog_colors, NULL,
  462. "[Display bits]", _(" Display bits "), DLG_CENTER | DLG_REVERSE);
  463. add_widget (dbits_dlg,
  464. label_new (3, 4, _("Input / display codepage:")));
  465. cpname = (new_display_codepage < 0)
  466. ? _("Other 8 bit")
  467. : codepages[new_display_codepage].name;
  468. cplabel = label_new (4, 4, cpname);
  469. add_widget (dbits_dlg, cplabel);
  470. add_widget (dbits_dlg,
  471. button_new (DISPY - 3, DISPX / 2 + 3, B_CANCEL,
  472. NORMAL_BUTTON, _("&Cancel"), 0));
  473. add_widget (dbits_dlg,
  474. button_new (DISPY - 3, 7, B_ENTER, NORMAL_BUTTON, _("&OK"),
  475. 0));
  476. inpcheck =
  477. check_new (6, 4, !use_8th_bit_as_meta, _("F&ull 8 bits input"));
  478. add_widget (dbits_dlg, inpcheck);
  479. cpname = _("&Select");
  480. add_widget (dbits_dlg,
  481. button_new (4, DISPX - 7 - str_term_width1 (cpname), B_USER,
  482. NORMAL_BUTTON, cpname, sel_charset_button));
  483. return dbits_dlg;
  484. }
  485. void
  486. display_bits_box (void)
  487. {
  488. Dlg_head *dbits_dlg;
  489. new_display_codepage = display_codepage;
  490. application_keypad_mode ();
  491. dbits_dlg = init_disp_bits_box ();
  492. run_dlg (dbits_dlg);
  493. if (dbits_dlg->ret_value == B_ENTER) {
  494. const char *errmsg;
  495. display_codepage = new_display_codepage;
  496. errmsg =
  497. init_translation_table (source_codepage, display_codepage);
  498. if (errmsg)
  499. message (D_ERROR, MSG_ERROR, "%s", errmsg);
  500. #ifdef HAVE_SLANG
  501. tty_display_8bit (display_codepage != 0 && display_codepage != 1);
  502. #else
  503. tty_display_8bit (display_codepage != 0);
  504. #endif
  505. use_8th_bit_as_meta = !(inpcheck->state & C_BOOL);
  506. }
  507. destroy_dlg (dbits_dlg);
  508. repaint_screen ();
  509. }
  510. #endif /* HAVE_CHARSET */
  511. #define TREE_Y 20
  512. #define TREE_X 60
  513. static cb_ret_t
  514. tree_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
  515. {
  516. switch (msg) {
  517. case DLG_POST_KEY:
  518. /* The enter key will be processed by the tree widget */
  519. if (parm == '\n') {
  520. h->ret_value = B_ENTER;
  521. dlg_stop (h);
  522. }
  523. return MSG_HANDLED;
  524. default:
  525. return default_dlg_callback (h, msg, parm);
  526. }
  527. }
  528. /* Show tree in a box, not on a panel */
  529. char *
  530. tree_box (const char *current_dir)
  531. {
  532. WTree *mytree;
  533. Dlg_head *dlg;
  534. char *val = NULL;
  535. WButtonBar *bar;
  536. (void) current_dir;
  537. /* Create the components */
  538. dlg = create_dlg (0, 0, TREE_Y, TREE_X, dialog_colors,
  539. tree_callback, "[Directory Tree]", NULL, DLG_CENTER | DLG_REVERSE);
  540. mytree = tree_new (0, 2, 2, TREE_Y - 6, TREE_X - 5);
  541. add_widget (dlg, mytree);
  542. bar = buttonbar_new(1);
  543. add_widget (dlg, bar);
  544. ((Widget *) bar)->x = 0;
  545. ((Widget *) bar)->y = LINES - 1;
  546. if (run_dlg (dlg) == B_ENTER)
  547. val = g_strdup (tree_selected_name (mytree));
  548. destroy_dlg (dlg);
  549. return val;
  550. }
  551. #ifdef USE_VFS
  552. static char *ret_timeout;
  553. #ifdef USE_NETCODE
  554. static char *ret_passwd;
  555. static char *ret_directory_timeout;
  556. static char *ret_ftp_proxy;
  557. #endif
  558. void
  559. configure_vfs (void)
  560. {
  561. #define VFSX 56
  562. #ifdef USE_NETCODE
  563. #define VFSY 17
  564. #else
  565. #define VFSY 8
  566. #endif
  567. char buffer2 [BUF_TINY];
  568. #ifdef USE_NETCODE
  569. char buffer3 [BUF_TINY];
  570. #endif
  571. QuickWidget confvfs_widgets [] =
  572. {
  573. /* 0 */ QUICK_BUTTON (30, VFSX, VFSY - 3, VFSY, N_("&Cancel"), B_CANCEL, NULL),
  574. /* 1 */ QUICK_BUTTON (12, VFSX, VFSY - 3, VFSY, N_("&OK"), B_ENTER, NULL),
  575. #ifdef USE_NETCODE
  576. /* 2 */ QUICK_CHECKBOX (4, VFSX, 12, VFSY, N_("Use passive mode over pro&xy"), &ftpfs_use_passive_connections_over_proxy),
  577. /* 3 */ QUICK_CHECKBOX (4, VFSX, 11, VFSY, N_("Use &passive mode"), &ftpfs_use_passive_connections),
  578. /* 4 */ QUICK_CHECKBOX (4, VFSX, 10, VFSY, N_("&Use ~/.netrc"), &use_netrc),
  579. /* 5 */ QUICK_INPUT (4, VFSX, 9, VFSY, ftpfs_proxy_host, 48, 0, "input-ftp-proxy", &ret_ftp_proxy),
  580. /* 6 */ QUICK_CHECKBOX (4, VFSX, 8, VFSY, N_("&Always use ftp proxy"), &ftpfs_always_use_proxy),
  581. /* 7 */ QUICK_LABEL (49, VFSX, 7, VFSY, N_("sec")),
  582. /* 8 */ QUICK_INPUT (38, VFSX, 7, VFSY, buffer3, 10, 0, "input-timeout", &ret_directory_timeout),
  583. /* 9 */ QUICK_LABEL (4, VFSX, 7, VFSY, N_("ftpfs directory cache timeout:")),
  584. /* 10 */ QUICK_INPUT (4, VFSX, 6, VFSY, ftpfs_anonymous_passwd, 48, 0, "input-passwd", &ret_passwd),
  585. /* 11 */ QUICK_LABEL (4, VFSX, 5, VFSY, N_("ftp anonymous password:")),
  586. #endif
  587. /* 12 */ QUICK_LABEL (49, VFSX, 3, VFSY, N_("sec")),
  588. /* 13 */ QUICK_INPUT (38, VFSX, 3, VFSY, buffer2, 10, 0, "input-timo-vfs", &ret_timeout),
  589. /* 14 */ QUICK_LABEL (4, VFSX, 3, VFSY, N_("Timeout for freeing VFSs:")),
  590. QUICK_END
  591. };
  592. QuickDialog confvfs_dlg =
  593. {
  594. VFSX, VFSY, -1, -1, N_(" Virtual File System Setting "),
  595. "[Virtual FS]", confvfs_widgets, FALSE
  596. };
  597. #ifdef SE_NETCODE
  598. g_snprintf (buffer3, sizeof (buffer3), "%i", ftpfs_directory_timeout);
  599. #endif
  600. g_snprintf (buffer2, sizeof (buffer2), "%i", vfs_timeout);
  601. if (quick_dialog (&confvfs_dlg) != B_CANCEL) {
  602. vfs_timeout = atoi (ret_timeout);
  603. g_free (ret_timeout);
  604. if (vfs_timeout < 0 || vfs_timeout > 10000)
  605. vfs_timeout = 10;
  606. #ifdef USE_NETCODE
  607. g_free (ftpfs_anonymous_passwd);
  608. ftpfs_anonymous_passwd = ret_passwd;
  609. g_free (ftpfs_proxy_host);
  610. ftpfs_proxy_host = ret_ftp_proxy;
  611. ftpfs_directory_timeout = atoi(ret_directory_timeout);
  612. g_free (ret_directory_timeout);
  613. #endif
  614. }
  615. #undef VFSX
  616. #undef VFSY
  617. }
  618. #endif /* USE_VFS */
  619. char *
  620. cd_dialog (void)
  621. {
  622. const char *label = N_("cd");
  623. const int ylen = 5;
  624. const int xlen = 57;
  625. int len;
  626. #ifdef ENABLE_NLS
  627. label = _(label);
  628. #endif
  629. len = str_term_width1 (label);
  630. {
  631. char *my_str;
  632. QuickWidget quick_widgets [] =
  633. {
  634. /* 0 */ QUICK_INPUT (4 + len, xlen, 2, ylen, "", xlen - 7 - len, 2, "input" , &my_str),
  635. /* 1 */ QUICK_LABEL (3, xlen, 2, ylen, label),
  636. QUICK_END
  637. };
  638. QuickDialog Quick_input =
  639. {
  640. xlen, ylen, 2, LINES - 2 - ylen, _("Quick cd"),
  641. "[Quick cd]", quick_widgets, TRUE
  642. };
  643. return (quick_dialog (&Quick_input) != B_CANCEL) ? my_str : NULL;
  644. }
  645. }
  646. void
  647. symlink_dialog (const char *existing, const char *new, char **ret_existing,
  648. char **ret_new)
  649. {
  650. QuickWidget quick_widgets[] =
  651. {
  652. /* 0 */ QUICK_BUTTON (50, 80, 6, 8, N_("&Cancel"), B_CANCEL, NULL),
  653. /* 1 */ QUICK_BUTTON (16, 80, 6, 8, N_("&OK"), B_ENTER, NULL),
  654. /* 2 */ QUICK_INPUT (4, 80, 5, 8, new, 58, 0, "input-1", ret_new),
  655. /* 3 */ QUICK_LABEL (4, 80, 4, 8, N_("Symbolic link filename:")),
  656. /* 4 */ QUICK_INPUT (4, 80, 3, 8, existing, 58, 0, "input-2", ret_existing),
  657. /* 5 */ QUICK_LABEL (4, 80, 2, 8, N_("Existing filename (filename symlink will point to):")),
  658. QUICK_END
  659. };
  660. QuickDialog Quick_input =
  661. {
  662. 64, 12, -1, -1, N_("Symbolic link"),
  663. "[File Menu]", quick_widgets, FALSE
  664. };
  665. if (quick_dialog (&Quick_input) == B_CANCEL) {
  666. *ret_new = NULL;
  667. *ret_existing = NULL;
  668. }
  669. }
  670. #ifdef WITH_BACKGROUND
  671. #define B_STOP (B_USER+1)
  672. #define B_RESUME (B_USER+2)
  673. #define B_KILL (B_USER+3)
  674. static int JOBS_X = 60;
  675. #define JOBS_Y 15
  676. static WListbox *bg_list;
  677. static Dlg_head *jobs_dlg;
  678. static void
  679. jobs_fill_listbox (void)
  680. {
  681. static const char *state_str [2];
  682. TaskList *tl = task_list;
  683. if (!state_str [0]){
  684. state_str [0] = _("Running ");
  685. state_str [1] = _("Stopped");
  686. }
  687. while (tl){
  688. char *s;
  689. s = g_strconcat (state_str [tl->state], " ", tl->info, (char *) NULL);
  690. listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
  691. g_free (s);
  692. tl = tl->next;
  693. }
  694. }
  695. static int
  696. task_cb (int action)
  697. {
  698. TaskList *tl;
  699. int sig = 0;
  700. if (!bg_list->list)
  701. return 0;
  702. /* Get this instance information */
  703. tl = (TaskList *) bg_list->current->data;
  704. # ifdef SIGTSTP
  705. if (action == B_STOP){
  706. sig = SIGSTOP;
  707. tl->state = Task_Stopped;
  708. } else if (action == B_RESUME){
  709. sig = SIGCONT;
  710. tl->state = Task_Running;
  711. } else
  712. # endif
  713. if (action == B_KILL){
  714. sig = SIGKILL;
  715. }
  716. if (sig == SIGINT)
  717. unregister_task_running (tl->pid, tl->fd);
  718. kill (tl->pid, sig);
  719. listbox_remove_list (bg_list);
  720. jobs_fill_listbox ();
  721. /* This can be optimized to just redraw this widget :-) */
  722. dlg_redraw (jobs_dlg);
  723. return 0;
  724. }
  725. static struct
  726. {
  727. const char* name;
  728. int xpos;
  729. int value;
  730. int (*callback)(int);
  731. }
  732. job_buttons [] =
  733. {
  734. {N_("&Stop"), 3, B_STOP, task_cb},
  735. {N_("&Resume"), 12, B_RESUME, task_cb},
  736. {N_("&Kill"), 23, B_KILL, task_cb},
  737. {N_("&OK"), 35, B_CANCEL, NULL }
  738. };
  739. void
  740. jobs_cmd (void)
  741. {
  742. register int i;
  743. int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);
  744. #ifdef ENABLE_NLS
  745. static int i18n_flag = 0;
  746. if (!i18n_flag)
  747. {
  748. int startx = job_buttons [0].xpos;
  749. int len;
  750. for (i = 0; i < n_buttons; i++)
  751. {
  752. job_buttons [i].name = _(job_buttons [i].name);
  753. len = str_term_width1 (job_buttons [i].name) + 4;
  754. JOBS_X = max (JOBS_X, startx + len + 3);
  755. job_buttons [i].xpos = startx;
  756. startx += len;
  757. }
  758. /* Last button - Ok a.k.a. Cancel :) */
  759. job_buttons [n_buttons - 1].xpos =
  760. JOBS_X - str_term_width1 (job_buttons [n_buttons - 1].name) - 7;
  761. i18n_flag = 1;
  762. }
  763. #endif /* ENABLE_NLS */
  764. jobs_dlg = create_dlg (0, 0, JOBS_Y, JOBS_X, dialog_colors, NULL,
  765. "[Background jobs]", _("Background Jobs"),
  766. DLG_CENTER | DLG_REVERSE);
  767. bg_list = listbox_new (2, 3, JOBS_Y - 9, JOBS_X - 7, NULL);
  768. add_widget (jobs_dlg, bg_list);
  769. i = n_buttons;
  770. while (i--)
  771. {
  772. add_widget (jobs_dlg, button_new (JOBS_Y-4,
  773. job_buttons [i].xpos, job_buttons [i].value,
  774. NORMAL_BUTTON, job_buttons [i].name,
  775. job_buttons [i].callback));
  776. }
  777. /* Insert all of task information in the list */
  778. jobs_fill_listbox ();
  779. run_dlg (jobs_dlg);
  780. destroy_dlg (jobs_dlg);
  781. }
  782. #endif /* WITH_BACKGROUND */
  783. #ifdef WITH_SMBFS
  784. struct smb_authinfo *
  785. vfs_smb_get_authinfo (const char *host, const char *share, const char *domain,
  786. const char *user)
  787. {
  788. static int dialog_x = 44;
  789. enum { b0 = 3, dialog_y = 12};
  790. struct smb_authinfo *return_value;
  791. static const char* labs[] = {N_("Domain:"), N_("Username:"), N_("Password:")};
  792. static const char* buts[] = {N_("&OK"), N_("&Cancel")};
  793. static int ilen = 30, istart = 14;
  794. static int b2 = 30;
  795. char *title;
  796. WInput *in_password;
  797. WInput *in_user;
  798. WInput *in_domain;
  799. Dlg_head *auth_dlg;
  800. #ifdef ENABLE_NLS
  801. static int i18n_flag = 0;
  802. if (!i18n_flag)
  803. {
  804. register int i = sizeof(labs)/sizeof(labs[0]);
  805. int l1, maxlen = 0;
  806. while (i--)
  807. {
  808. l1 = str_term_width1 (labs [i] = _(labs [i]));
  809. if (l1 > maxlen)
  810. maxlen = l1;
  811. }
  812. i = maxlen + ilen + 7;
  813. if (i > dialog_x)
  814. dialog_x = i;
  815. for (i = sizeof(buts)/sizeof(buts[0]), l1 = 0; i--; )
  816. {
  817. l1 += str_term_width1 (buts [i] = _(buts [i]));
  818. }
  819. l1 += 15;
  820. if (l1 > dialog_x)
  821. dialog_x = l1;
  822. ilen = dialog_x - 7 - maxlen; /* for the case of very long buttons :) */
  823. istart = dialog_x - 3 - ilen;
  824. b2 = dialog_x - (str_term_width1 (buts[1]) + 6);
  825. i18n_flag = 1;
  826. }
  827. #endif /* ENABLE_NLS */
  828. if (!domain)
  829. domain = "";
  830. if (!user)
  831. user = "";
  832. title = g_strdup_printf (_("Password for \\\\%s\\%s"), host, share);
  833. auth_dlg = create_dlg (0, 0, dialog_y, dialog_x, dialog_colors, NULL,
  834. "[Smb Authinfo]", title, DLG_CENTER | DLG_REVERSE);
  835. g_free (title);
  836. in_user = input_new (5, istart, INPUT_COLOR, ilen, user, "auth_name", INPUT_COMPLETE_DEFAULT);
  837. add_widget (auth_dlg, in_user);
  838. in_domain = input_new (3, istart, INPUT_COLOR, ilen, domain, "auth_domain", INPUT_COMPLETE_DEFAULT);
  839. add_widget (auth_dlg, in_domain);
  840. add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON,
  841. buts[1], 0));
  842. add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON,
  843. buts[0], 0));
  844. in_password = input_new (7, istart, INPUT_COLOR, ilen, "", "auth_password", INPUT_COMPLETE_DEFAULT);
  845. in_password->completion_flags = 0;
  846. in_password->is_password = 1;
  847. add_widget (auth_dlg, in_password);
  848. add_widget (auth_dlg, label_new (7, 3, labs[2]));
  849. add_widget (auth_dlg, label_new (5, 3, labs[1]));
  850. add_widget (auth_dlg, label_new (3, 3, labs[0]));
  851. run_dlg (auth_dlg);
  852. switch (auth_dlg->ret_value) {
  853. case B_CANCEL:
  854. return_value = 0;
  855. break;
  856. default:
  857. return_value = g_new (struct smb_authinfo, 1);
  858. if (return_value) {
  859. return_value->host = g_strdup (host);
  860. return_value->share = g_strdup (share);
  861. return_value->domain = g_strdup (in_domain->buffer);
  862. return_value->user = g_strdup (in_user->buffer);
  863. return_value->password = g_strdup (in_password->buffer);
  864. }
  865. }
  866. destroy_dlg (auth_dlg);
  867. return return_value;
  868. }
  869. #endif /* WITH_SMBFS */