Merge commit 'origin/mc-4.6'
[midnight-commander.git] / src / hotlist.c
blob737c9c17463e33bfdd84df8fec03e0e7153d9f7e
1 /* Directory hotlist -- for the Midnight Commander
2 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5 Written by:
6 1994 Radek Doulik
7 1995 Janne Kukonlehto
8 1996 Andrej Borsenkow
9 1997 Norbert Warmuth
11 Janne did the original Hotlist code, Andrej made the groupable
12 hotlist; the move hotlist and revamped the file format and made
13 it stronger.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 #include <config.h>
32 #include <ctype.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <unistd.h>
39 #include <mhl/string.h>
41 #include "global.h"
42 #include "tty.h" /* COLS */
43 #include "color.h" /* dialog_colors */
44 #include "dialog.h"
45 #include "widget.h"
46 #include "setup.h" /* For profile_bname */
47 #include "profile.h" /* Load/save directories hotlist */
48 #include "wtools.h" /* QuickDialog */
49 #include "panel.h" /* current_panel */
50 #include "main.h" /* repaint_screen */
51 #include "hotlist.h"
52 #include "key.h" /* KEY_M_CTRL */
53 #include "command.h" /* cmdline */
54 #include "glibcompat.h" /* g_strlcpy for glib < 2.0 */
55 #include "history.h"
57 #define UX 5
58 #define UY 2
60 #define BX UX
61 #define BY (LINES - 6)
63 #define BUTTONS (sizeof(hotlist_but)/sizeof(struct _hotlist_but))
64 #define LABELS 3
65 #define B_ADD_CURRENT B_USER
66 #define B_REMOVE (B_USER + 1)
67 #define B_NEW_GROUP (B_USER + 2)
68 #define B_NEW_ENTRY (B_USER + 3)
69 #define B_UP_GROUP (B_USER + 4)
70 #define B_INSERT (B_USER + 5)
71 #define B_APPEND (B_USER + 6)
72 #define B_MOVE (B_USER + 7)
74 #ifdef USE_VFS
75 #include "../vfs/gc.h"
76 #define B_FREE_ALL_VFS (B_USER + 8)
77 #define B_REFRESH_VFS (B_USER + 9)
78 #endif
80 int hotlist_has_dot_dot = 1;
82 static WListbox *l_hotlist;
83 static WListbox *l_movelist;
85 static Dlg_head *hotlist_dlg;
86 static Dlg_head *movelist_dlg;
88 static WLabel *pname, *pname_group, *movelist_group;
90 enum HotListType {
91 HL_TYPE_GROUP,
92 HL_TYPE_ENTRY,
93 HL_TYPE_COMMENT,
94 HL_TYPE_DOTDOT
97 static struct {
99 * these parameters are intended to be user configurable
101 int expanded; /* expanded view of all groups at startup */
104 * these reflect run time state
107 int loaded; /* hotlist is loaded */
108 int readonly; /* hotlist readonly */
109 int file_error; /* parse error while reading file */
110 int running; /* we are running dlg (and have to
111 update listbox */
112 int moving; /* we are in moving hotlist currently */
113 int modified; /* hotlist was modified */
114 int type; /* LIST_HOTLIST || LIST_VFSLIST */
115 } hotlist_state;
117 static struct _hotlist_but {
118 int ret_cmd, flags, y, x;
119 const char *text;
120 int type;
121 } hotlist_but[] = {
122 { B_MOVE, NORMAL_BUTTON, 1, 42, N_("&Move"), LIST_HOTLIST},
123 { B_REMOVE, NORMAL_BUTTON, 1, 30, N_("&Remove"), LIST_HOTLIST},
124 { B_APPEND, NORMAL_BUTTON, 1, 15, N_("&Append"), LIST_MOVELIST},
125 { B_INSERT, NORMAL_BUTTON, 1, 0, N_("&Insert"), LIST_MOVELIST},
126 { B_NEW_ENTRY, NORMAL_BUTTON, 1, 15, N_("New &Entry"), LIST_HOTLIST},
127 { B_NEW_GROUP, NORMAL_BUTTON, 1, 0, N_("New &Group"), LIST_HOTLIST},
128 { B_CANCEL, NORMAL_BUTTON, 0, 53, N_("&Cancel"), LIST_HOTLIST|LIST_VFSLIST|LIST_MOVELIST},
129 { B_UP_GROUP, NORMAL_BUTTON, 0, 42, N_("&Up"), LIST_HOTLIST|LIST_MOVELIST},
130 { B_ADD_CURRENT, NORMAL_BUTTON, 0, 20, N_("&Add current"), LIST_HOTLIST},
131 #ifdef USE_VFS
132 { B_REFRESH_VFS, NORMAL_BUTTON, 0, 43, N_("&Refresh"), LIST_VFSLIST},
133 { B_FREE_ALL_VFS, NORMAL_BUTTON, 0, 20, N_("Fr&ee VFSs now"), LIST_VFSLIST},
134 #endif
135 { B_ENTER, DEFPUSH_BUTTON, 0, 0, N_("Change &To"), LIST_HOTLIST|LIST_VFSLIST|LIST_MOVELIST},
138 /* Directory hotlist */
139 static struct hotlist{
140 enum HotListType type;
141 char *directory;
142 char *label;
143 struct hotlist *head;
144 struct hotlist *up;
145 struct hotlist *next;
146 } *hotlist = NULL;
148 static struct hotlist *current_group;
150 static void init_movelist (int, struct hotlist *);
151 static void add_new_group_cmd (void);
152 static void add_new_entry_cmd (void);
153 static void remove_from_hotlist (struct hotlist *entry);
154 static void load_hotlist (void);
155 static void add_dotdot_to_list (void);
157 #define new_hotlist() g_new0(struct hotlist, 1)
159 static void
160 hotlist_refresh (Dlg_head * dlg)
162 common_dialog_repaint (dlg);
163 attrset (COLOR_NORMAL);
164 draw_box (dlg, 2, 5, dlg->lines - (hotlist_state.moving ? 6 : 10),
165 dlg->cols - (UX * 2));
166 if (!hotlist_state.moving)
167 draw_box (dlg, dlg->lines - 8, 5, 3, dlg->cols - (UX * 2));
170 /* If current->data is 0, then we are dealing with a VFS pathname */
171 static inline void
172 update_path_name (void)
174 const char *text = "";
175 char *p;
176 WListbox *list = hotlist_state.moving ? l_movelist : l_hotlist;
177 Dlg_head *dlg = list->widget.parent;
179 if (list->current) {
180 if (list->current->data != 0) {
181 struct hotlist *hlp = (struct hotlist *) list->current->data;
183 if (hlp->type == HL_TYPE_ENTRY ||
184 hlp->type == HL_TYPE_DOTDOT)
185 text = hlp->directory;
186 else if (hlp->type == HL_TYPE_GROUP)
187 text = _("Subgroup - press ENTER to see list");
188 } else {
189 text = list->current->text;
192 if (!hotlist_state.moving)
193 label_set_text (pname,
194 name_trunc (text, dlg->cols - (UX * 2 + 4)));
196 p = g_strconcat (" ", current_group->label, " ", (char *) NULL);
197 if (!hotlist_state.moving)
198 label_set_text (pname_group,
199 name_trunc (p, dlg->cols - (UX * 2 + 4)));
200 else
201 label_set_text (movelist_group,
202 name_trunc (p, dlg->cols - (UX * 2 + 4)));
203 g_free (p);
205 dlg_redraw (dlg);
208 #define CHECK_BUFFER \
209 do { \
210 int i; \
212 if ((i = strlen (current->label) + 3) > buflen) { \
213 g_free (buf); \
214 buf = g_malloc (buflen = 1024 * (i/1024 + 1)); \
216 buf[0] = '\0'; \
217 } while (0)
219 static void fill_listbox (void)
221 struct hotlist *current = current_group->head;
222 static char *buf;
223 static int buflen;
225 if (!buf)
226 buf = g_malloc (buflen = 1024);
227 buf[0] = '\0';
229 while (current){
230 switch (current->type) {
231 case HL_TYPE_GROUP:
233 CHECK_BUFFER;
234 strcat (strcat (buf, "->"), current->label);
235 if (hotlist_state.moving)
236 listbox_add_item (l_movelist, 0, 0, buf, current);
237 else
238 listbox_add_item (l_hotlist, 0, 0, buf, current);
240 break;
241 case HL_TYPE_DOTDOT:
242 case HL_TYPE_ENTRY:
243 if (hotlist_state.moving)
244 listbox_add_item (l_movelist, 0, 0, current->label, current);
245 else
246 listbox_add_item (l_hotlist, 0, 0, current->label, current);
247 break;
248 default:
249 break;
251 current = current->next;
255 #undef CHECK_BUFFER
257 static void
258 unlink_entry (struct hotlist *entry)
260 struct hotlist *current = current_group->head;
262 if (current == entry)
263 current_group->head = entry->next;
264 else {
265 while (current && current->next != entry)
266 current = current->next;
267 if (current)
268 current->next = entry->next;
270 entry->next =
271 entry->up = 0;
274 #ifdef USE_VFS
275 static void add_name_to_list (const char *path)
277 listbox_add_item (l_hotlist, 0, 0, path, 0);
279 #endif /* !USE_VFS */
281 static int
282 hotlist_button_callback (int action)
284 switch (action) {
285 case B_MOVE:
287 struct hotlist *saved = current_group;
288 struct hotlist *item;
289 struct hotlist *moveto_item = 0;
290 struct hotlist *moveto_group = 0;
291 int ret;
293 if (!l_hotlist->current)
294 return MSG_NOT_HANDLED; /* empty group - nothing to do */
295 item = l_hotlist->current->data;
296 hotlist_state.moving = 1;
297 init_movelist (LIST_MOVELIST, item);
298 run_dlg (movelist_dlg);
299 ret = movelist_dlg->ret_value;
300 hotlist_state.moving = 0;
301 if (l_movelist->current)
302 moveto_item = l_movelist->current->data;
303 moveto_group = current_group;
304 destroy_dlg (movelist_dlg);
305 current_group = saved;
306 if (ret == B_CANCEL)
307 return MSG_NOT_HANDLED;
308 if (moveto_item == item)
309 return MSG_NOT_HANDLED; /* If we insert/append a before/after a
310 it hardly changes anything ;) */
311 unlink_entry (item);
312 listbox_remove_current (l_hotlist, 1);
313 item->up = moveto_group;
314 if (!moveto_group->head)
315 moveto_group->head = item;
316 else if (!moveto_item) { /* we have group with just comments */
317 struct hotlist *p = moveto_group->head;
319 /* skip comments */
320 while (p->next)
321 p = p->next;
322 p->next = item;
323 } else if (ret == B_ENTER || ret == B_APPEND)
324 if (!moveto_item->next)
325 moveto_item->next = item;
326 else {
327 item->next = moveto_item->next;
328 moveto_item->next = item;
329 } else if (moveto_group->head == moveto_item) {
330 moveto_group->head = item;
331 item->next = moveto_item;
332 } else {
333 struct hotlist *p = moveto_group->head;
335 while (p->next != moveto_item)
336 p = p->next;
337 item->next = p->next;
338 p->next = item;
340 listbox_remove_list (l_hotlist);
341 fill_listbox ();
342 repaint_screen ();
343 hotlist_state.modified = 1;
344 return MSG_NOT_HANDLED;
345 break;
347 case B_REMOVE:
348 if (l_hotlist->current && l_hotlist->current->data)
349 remove_from_hotlist (l_hotlist->current->data);
350 return MSG_NOT_HANDLED;
351 break;
353 case B_NEW_GROUP:
354 add_new_group_cmd ();
355 return MSG_NOT_HANDLED;
356 break;
358 case B_ADD_CURRENT:
359 add2hotlist_cmd ();
360 return MSG_NOT_HANDLED;
361 break;
363 case B_NEW_ENTRY:
364 add_new_entry_cmd ();
365 return MSG_NOT_HANDLED;
366 break;
368 case B_ENTER:
370 WListbox *list = hotlist_state.moving ? l_movelist : l_hotlist;
371 if (list->current) {
372 if (list->current->data) {
373 struct hotlist *hlp =
374 (struct hotlist *) list->current->data;
375 if (hlp->type == HL_TYPE_ENTRY)
376 return MSG_HANDLED;
377 else if (hlp->type == HL_TYPE_DOTDOT) {
378 /* Fall through - go up */
381 else {
382 listbox_remove_list (list);
383 current_group = hlp;
384 fill_listbox ();
385 return MSG_NOT_HANDLED;
387 } else
388 return MSG_HANDLED;
391 /* Fall through if list empty - just go up */
393 case B_UP_GROUP:
395 WListbox *list = hotlist_state.moving ? l_movelist : l_hotlist;
396 listbox_remove_list (list);
397 current_group = current_group->up;
398 fill_listbox ();
399 return MSG_NOT_HANDLED;
400 break;
403 #ifdef USE_VFS
404 case B_FREE_ALL_VFS:
405 vfs_expire (1);
406 /* fall through */
408 case B_REFRESH_VFS:
409 listbox_remove_list (l_hotlist);
410 listbox_add_item (l_hotlist, 0, 0, home_dir, 0);
411 vfs_fill_names (add_name_to_list);
412 return MSG_NOT_HANDLED;
413 #endif /* USE_VFS */
415 default:
416 return MSG_HANDLED;
417 break;
422 static cb_ret_t
423 hotlist_callback (Dlg_head *h, dlg_msg_t msg, int parm)
425 switch (msg) {
426 case DLG_DRAW:
427 hotlist_refresh (h);
428 return MSG_HANDLED;
430 case DLG_UNHANDLED_KEY:
431 switch (parm) {
432 case KEY_M_CTRL | '\n':
433 goto l1;
434 case '\n':
435 case KEY_ENTER:
436 case KEY_RIGHT:
437 if (hotlist_button_callback (B_ENTER)) {
438 h->ret_value = B_ENTER;
439 dlg_stop (h);
441 return MSG_HANDLED;
442 break;
443 case KEY_LEFT:
444 if (hotlist_state.type != LIST_VFSLIST)
445 return !hotlist_button_callback (B_UP_GROUP);
446 else
447 return MSG_NOT_HANDLED;
448 break;
449 case KEY_DC:
450 if (!hotlist_state.moving) {
451 hotlist_button_callback (B_REMOVE);
452 return MSG_HANDLED;
454 break;
456 case ALT ('\n'):
457 case ALT ('\r'):
458 if (!hotlist_state.moving) {
459 if (l_hotlist->current) {
460 if (l_hotlist->current->data) {
461 struct hotlist *hlp =
462 (struct hotlist *) l_hotlist->current->data;
463 if (hlp->type == HL_TYPE_ENTRY) {
464 char *tmp =
465 g_strconcat ("cd ", hlp->directory, (char *) NULL);
466 stuff (cmdline, tmp, 0);
467 g_free (tmp);
468 dlg_stop (h);
469 h->ret_value = B_CANCEL;
470 return MSG_HANDLED;
475 return MSG_HANDLED; /* ignore key */
477 return MSG_NOT_HANDLED;
479 case DLG_POST_KEY:
480 if (hotlist_state.moving)
481 dlg_select_widget (l_movelist);
482 else
483 dlg_select_widget (l_hotlist);
484 /* always stay on hotlist */
485 /* fall through */
487 case DLG_INIT:
488 attrset (MENU_ENTRY_COLOR);
489 update_path_name ();
490 return MSG_HANDLED;
492 default:
493 return default_dlg_callback (h, msg, parm);
497 static int l_call (WListbox *list)
499 Dlg_head *dlg = list->widget.parent;
501 if (list->current){
502 if (list->current->data) {
503 struct hotlist *hlp = (struct hotlist*) list->current->data;
504 if (hlp->type == HL_TYPE_ENTRY) {
505 dlg->ret_value = B_ENTER;
506 dlg_stop (dlg);
507 return LISTBOX_DONE;
508 } else {
509 hotlist_button_callback (B_ENTER);
510 hotlist_callback (dlg, DLG_POST_KEY, '\n');
511 return LISTBOX_CONT;
513 } else {
514 dlg->ret_value = B_ENTER;
515 dlg_stop (dlg);
516 return LISTBOX_DONE;
520 hotlist_button_callback (B_UP_GROUP);
521 hotlist_callback (dlg, DLG_POST_KEY, 'u');
522 return LISTBOX_CONT;
526 * Expands all button names (once) and recalculates button positions.
527 * returns number of columns in the dialog box, which is 10 chars longer
528 * then buttonbar.
530 * If common width of the window (i.e. in xterm) is less than returned
531 * width - sorry :) (anyway this did not handled in previous version too)
533 static int
534 init_i18n_stuff(int list_type, int cols)
536 register int i;
537 static const char* cancel_but = N_("&Cancel");
539 #ifdef ENABLE_NLS
540 static int hotlist_i18n_flag = 0;
542 if (!hotlist_i18n_flag)
544 i = sizeof (hotlist_but) / sizeof (hotlist_but [0]);
545 while (i--)
546 hotlist_but [i].text = _(hotlist_but [i].text);
548 cancel_but = _(cancel_but);
549 hotlist_i18n_flag = 1;
551 #endif /* ENABLE_NLS */
553 /* Dynamic resizing of buttonbars */
555 int len[2], count[2]; /* at most two lines of buttons */
556 int cur_x[2], row;
558 i = sizeof (hotlist_but) / sizeof (hotlist_but [0]);
559 len[0] = len[1] = count[0] = count[1] = 0;
561 /* Count len of buttonbars, assuming 2 extra space between buttons */
562 while (i--)
564 if (! (hotlist_but[i].type & list_type))
565 continue;
567 row = hotlist_but [i].y;
568 ++count [row];
569 len [row] += strlen (hotlist_but [i].text) + 5;
570 if (hotlist_but [i].flags == DEFPUSH_BUTTON)
571 len [row] += 2;
573 len[0] -= 2;
574 len[1] -= 2;
576 cols = max(cols, max(len[0], len[1]));
578 /* arrange buttons */
580 cur_x[0] = cur_x[1] = 0;
581 i = sizeof (hotlist_but) / sizeof (hotlist_but [0]);
582 while (i--)
584 if (! (hotlist_but[i].type & list_type))
585 continue;
587 row = hotlist_but [i].y;
589 if (hotlist_but [i].x != 0)
591 /* not first int the row */
592 if (!strcmp (hotlist_but [i].text, cancel_but))
593 hotlist_but [i].x =
594 cols - strlen (hotlist_but [i].text) - 13;
595 else
596 hotlist_but [i].x = cur_x [row];
599 cur_x [row] += strlen (hotlist_but [i].text) + 2
600 + (hotlist_but [i].flags == DEFPUSH_BUTTON ? 5 : 3);
604 return cols;
607 static void
608 init_hotlist (int list_type)
610 size_t i;
611 const char *title, *help_node;
612 int hotlist_cols;
614 hotlist_cols = init_i18n_stuff (list_type, COLS - 6);
616 do_refresh ();
618 hotlist_state.expanded =
619 GetPrivateProfileInt ("HotlistConfig", "expanded_view_of_groups",
620 0, profile_name);
622 if (list_type == LIST_VFSLIST) {
623 title = _("Active VFS directories");
624 help_node = "[vfshot]"; /* FIXME - no such node */
625 } else {
626 title = _("Directory hotlist");
627 help_node = "[Hotlist]";
630 hotlist_dlg =
631 create_dlg (0, 0, LINES - 2, hotlist_cols, dialog_colors,
632 hotlist_callback, help_node, title, DLG_CENTER | DLG_REVERSE);
634 for (i = 0; i < BUTTONS; i++) {
635 if (hotlist_but[i].type & list_type)
636 add_widget (hotlist_dlg,
637 button_new (BY + hotlist_but[i].y,
638 BX + hotlist_but[i].x,
639 hotlist_but[i].ret_cmd,
640 hotlist_but[i].flags,
641 hotlist_but[i].text,
642 hotlist_button_callback));
645 /* We add the labels.
646 * pname will hold entry's pathname;
647 * pname_group will hold name of current group
649 pname = label_new (UY - 11 + LINES, UX + 2, "");
650 add_widget (hotlist_dlg, pname);
651 if (!hotlist_state.moving) {
652 add_widget (hotlist_dlg,
653 label_new (UY - 12 + LINES, UX + 1,
654 _(" Directory path ")));
656 /* This one holds the displayed pathname */
657 pname_group = label_new (UY, UX + 1, _(" Directory label "));
658 add_widget (hotlist_dlg, pname_group);
660 /* get new listbox */
661 l_hotlist =
662 listbox_new (UY + 1, UX + 1, COLS - 2 * UX - 8, LINES - 14,
663 l_call);
665 /* Fill the hotlist with the active VFS or the hotlist */
666 #ifdef USE_VFS
667 if (list_type == LIST_VFSLIST) {
668 listbox_add_item (l_hotlist, 0, 0, home_dir, 0);
669 vfs_fill_names (add_name_to_list);
670 } else
671 #endif /* !USE_VFS */
672 fill_listbox ();
674 add_widget (hotlist_dlg, l_hotlist);
675 /* add listbox to the dialogs */
678 static void
679 init_movelist (int list_type, struct hotlist *item)
681 size_t i;
682 char *hdr = g_strdup_printf (_("Moving %s"), item->label);
683 int movelist_cols = init_i18n_stuff (list_type, COLS - 6);
685 do_refresh ();
687 movelist_dlg =
688 create_dlg (0, 0, LINES - 6, movelist_cols, dialog_colors,
689 hotlist_callback, "[Hotlist]", hdr, DLG_CENTER | DLG_REVERSE);
690 g_free (hdr);
692 for (i = 0; i < BUTTONS; i++) {
693 if (hotlist_but[i].type & list_type)
694 add_widget (movelist_dlg,
695 button_new (BY - 4 + hotlist_but[i].y,
696 BX + hotlist_but[i].x,
697 hotlist_but[i].ret_cmd,
698 hotlist_but[i].flags,
699 hotlist_but[i].text,
700 hotlist_button_callback));
703 /* We add the labels. We are interested in the last one,
704 * that one will hold the path name label
706 movelist_group = label_new (UY, UX + 1, _(" Directory label "));
707 add_widget (movelist_dlg, movelist_group);
708 /* get new listbox */
709 l_movelist =
710 listbox_new (UY + 1, UX + 1, movelist_dlg->cols - 2 * UX - 2,
711 movelist_dlg->lines - 8, l_call);
713 fill_listbox ();
715 add_widget (movelist_dlg, l_movelist);
716 /* add listbox to the dialogs */
720 * Destroy the list dialog.
721 * Don't confuse with done_hotlist() for the list in memory.
723 static void hotlist_done (void)
725 destroy_dlg (hotlist_dlg);
726 l_hotlist = NULL;
727 if (0)
728 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
729 repaint_screen ();
732 static inline char *
733 find_group_section (struct hotlist *grp)
735 return g_strconcat (grp->directory, ".Group", (char *) NULL);
739 /* 1.11.96 bor: added pos parameter to control placement of new item.
740 see widget.c, listbox_add_item()
741 now hotlist is in unsorted mode
743 enum {
744 HL_BEFORE_CURRENT = 1
745 ,HL_AFTER_CURRENT = 2
748 static struct hotlist *
749 add2hotlist (char *label, char *directory, enum HotListType type, int pos)
751 struct hotlist *new;
752 struct hotlist *current = NULL;
755 * Hotlist is neither loaded nor loading.
756 * Must be called by "Ctrl-x a" before using hotlist.
758 if (!current_group)
759 load_hotlist ();
761 if (l_hotlist && l_hotlist->current) {
762 current = l_hotlist->current->data;
764 /* Make sure `..' stays at the top of the list. */
765 if (current->type == HL_TYPE_DOTDOT)
766 pos = HL_AFTER_CURRENT;
769 new = new_hotlist ();
771 new->type = type;
772 new->label = label;
773 new->directory = directory;
774 new->up = current_group;
776 if (type == HL_TYPE_GROUP) {
777 current_group = new;
778 add_dotdot_to_list ();
779 current_group = new->up;
782 if (!current_group->head) { /* first element in group */
783 current_group->head = new;
784 } else if (pos == HL_AFTER_CURRENT) {
785 new->next = current->next;
786 current->next = new;
787 } else if (pos == HL_BEFORE_CURRENT &&
788 current == current_group->head) {
789 /* should be inserted before first item */
790 new->next = current;
791 current_group->head = new;
792 } else if (pos == HL_BEFORE_CURRENT) {
793 struct hotlist *p = current_group->head;
795 while (p->next != current)
796 p = p->next;
798 new->next = current;
799 p->next = new;
800 } else { /* append at the end */
801 struct hotlist *p = current_group->head;
803 while (p->next)
804 p = p->next;
806 p->next = new;
809 if (hotlist_state.running && type != HL_TYPE_COMMENT &&
810 type != HL_TYPE_DOTDOT) {
811 if (type == HL_TYPE_GROUP) {
812 char *lbl = g_strconcat ("->", new->label, (char *) NULL);
814 listbox_add_item (l_hotlist, pos, 0, lbl, new);
815 g_free (lbl);
816 } else
817 listbox_add_item (l_hotlist, pos, 0, new->label, new);
818 listbox_select_entry (l_hotlist, l_hotlist->current);
820 return new;
824 #ifdef ENABLE_NLS
826 * Support routine for add_new_entry_input()/add_new_group_input()
827 * Change positions of buttons (first three widgets).
829 * This is just a quick hack. Accurate procedure must take care of
830 * internationalized label lengths and total buttonbar length...assume
831 * 64 is longer anyway.
833 static void add_widgets_i18n(QuickWidget* qw, int len)
835 int i, l[3], space, cur_x;
837 for (i = 0; i < 3; i++)
839 qw [i].text = _(qw [i].text);
840 l[i] = strlen (qw [i].text) + 3;
842 space = (len - 4 - l[0] - l[1] - l[2]) / 4;
844 for (cur_x = 2 + space, i = 3; i--; cur_x += l[i] + space)
846 qw [i].relative_x = cur_x;
847 qw [i].x_divisions = len;
850 #endif /* ENABLE_NLS */
852 static int
853 add_new_entry_input (const char *header, const char *text1, const char *text2,
854 const char *help, char **r1, char **r2)
856 #define RELATIVE_Y_BUTTONS 4
857 #define RELATIVE_Y_LABEL_PTH 3
858 #define RELATIVE_Y_INPUT_PTH 4
860 QuickDialog Quick_input;
861 static QuickWidget quick_widgets [] = {
862 { quick_button, 55, 80, RELATIVE_Y_BUTTONS, 0, N_("&Cancel"), 0, B_CANCEL,
863 0, 0, NULL },
864 { quick_button, 30, 80, RELATIVE_Y_BUTTONS, 0, N_("&Insert"), 0, B_INSERT,
865 0, 0, NULL },
866 { quick_button, 10, 80, RELATIVE_Y_BUTTONS, 0, N_("&Append"), 0, B_APPEND,
867 0, 0, NULL },
868 { quick_input, 4, 80, RELATIVE_Y_INPUT_PTH, 0, "",58, 0,
869 0, 0, "input-pth" },
870 { quick_label, RELATIVE_Y_LABEL_PTH, 80, 3, 0, 0, 0, 0,
871 0, 0, NULL },
872 { quick_input, 4, 80, 3, 0, "", 58, 0,
873 0, 0, "input-lbl" },
874 { quick_label, 3, 80, 2, 0, 0, 0, 0,
875 0, 0, NULL },
876 NULL_QuickWidget };
878 int len;
879 int i;
880 int lines1, lines2;
881 int cols1, cols2;
883 #ifdef ENABLE_NLS
884 static int i18n_flag = 0;
885 #endif /* ENABLE_NLS */
887 msglen(text1, &lines1, &cols1);
888 msglen(text2, &lines2, &cols2);
889 len = max ((int) strlen (header), cols1);
890 len = max (len, cols2) + 4;
891 len = max (len, 64);
893 #ifdef ENABLE_NLS
894 if (!i18n_flag)
896 add_widgets_i18n(quick_widgets, len);
897 i18n_flag = 1;
899 #endif /* ENABLE_NLS */
901 Quick_input.xlen = len;
902 Quick_input.xpos = -1;
903 Quick_input.title = header;
904 Quick_input.help = help;
905 Quick_input.i18n = 0;
906 quick_widgets [6].text = text1;
907 quick_widgets [4].text = text2;
908 quick_widgets [5].text = *r1;
909 quick_widgets [3].text = *r2;
911 for (i = 0; i < 7; i++)
912 quick_widgets [i].y_divisions = lines1+lines2+7;
913 Quick_input.ylen = lines1 + lines2 + 7;
915 quick_widgets [0].relative_y = RELATIVE_Y_BUTTONS + (lines1 + lines2);
916 quick_widgets [1].relative_y = RELATIVE_Y_BUTTONS + (lines1 + lines2);
917 quick_widgets [2].relative_y = RELATIVE_Y_BUTTONS + (lines1 + lines2);
918 quick_widgets [3].relative_y = RELATIVE_Y_INPUT_PTH + (lines1);
919 quick_widgets [4].relative_y = RELATIVE_Y_LABEL_PTH + (lines1);
921 quick_widgets [5].str_result = r1;
922 quick_widgets [3].str_result = r2;
924 Quick_input.widgets = quick_widgets;
925 if ((i = quick_dialog (&Quick_input)) != B_CANCEL){
926 return i;
927 } else
928 return 0;
931 static void add_new_entry_cmd (void)
933 char *title, *url, *to_free;
934 int ret;
936 /* Take current directory as default value for input fields */
937 to_free = title = url = strip_password (g_strdup (current_panel->cwd), 1);
939 ret = add_new_entry_input (_("New hotlist entry"), _("Directory label"),
940 _("Directory path"), "[Hotlist]", &title, &url);
941 g_free (to_free);
943 if (!ret)
944 return;
945 if (!title || !*title || !url || !*url) {
946 g_free (title);
947 g_free (url);
948 return;
951 if (ret == B_ENTER || ret == B_APPEND)
952 add2hotlist (title, url, HL_TYPE_ENTRY, HL_AFTER_CURRENT);
953 else
954 add2hotlist (title, url, HL_TYPE_ENTRY, HL_BEFORE_CURRENT);
956 hotlist_state.modified = 1;
959 static int
960 add_new_group_input (const char *header, const char *label, char **result)
962 int ret;
963 QuickDialog Quick_input;
964 static QuickWidget quick_widgets [] = {
965 { quick_button, 55, 80, 1, 0, N_("&Cancel"), 0, B_CANCEL, 0, 0,
966 NULL },
967 { quick_button, 30, 80, 1, 0, N_("&Insert"), 0, B_INSERT, 0, 0,
968 NULL },
969 { quick_button, 10, 80, 1, 0, N_("&Append"), 0, B_APPEND, 0, 0,
970 NULL },
971 { quick_input, 4, 80, 0, 0, "", 58, 0, 0, 0, "input" },
972 { quick_label, 3, 80, 2, 0, 0, 0, 0, 0, 0, NULL },
973 NULL_QuickWidget };
974 int relative_y[] = {1, 1, 1, 0, 2}; /* the relative_x component from the
975 quick_widgets variable above */
976 int len;
977 int i;
978 int lines, cols;
980 #ifdef ENABLE_NLS
981 static int i18n_flag = 0;
982 #endif /* ENABLE_NLS */
984 msglen (label, &lines, &cols);
985 len = max ((int) strlen (header), cols) + 4;
986 len = max (len, 64);
988 #ifdef ENABLE_NLS
989 if (!i18n_flag)
991 add_widgets_i18n(quick_widgets, len);
992 i18n_flag = 1;
994 #endif /* ENABLE_NLS */
996 Quick_input.xlen = len;
997 Quick_input.xpos = -1;
998 Quick_input.title = header;
999 Quick_input.help = "[Hotlist]";
1000 Quick_input.i18n = 0;
1001 quick_widgets [4].text = label;
1003 for (i = 0; i < 5; i++)
1004 quick_widgets [i].y_divisions = lines+6;
1005 Quick_input.ylen = lines + 6;
1007 for (i = 0; i < 4; i++)
1008 quick_widgets [i].relative_y = relative_y[i] + 2 + lines;
1010 quick_widgets [3].str_result = result;
1011 quick_widgets [3].text = "";
1013 Quick_input.widgets = quick_widgets;
1014 if ((ret = quick_dialog (&Quick_input)) != B_CANCEL){
1015 return ret;
1016 } else
1017 return 0;
1020 static void add_new_group_cmd (void)
1022 char *label;
1023 int ret;
1025 ret = add_new_group_input (_(" New hotlist group "), _("Name of new group"), &label);
1026 if (!ret || !label || !*label)
1027 return;
1029 if (ret == B_ENTER || ret == B_APPEND)
1030 add2hotlist (label, 0, HL_TYPE_GROUP, HL_AFTER_CURRENT);
1031 else
1032 add2hotlist (label, 0, HL_TYPE_GROUP, HL_BEFORE_CURRENT);
1034 hotlist_state.modified = 1;
1037 void add2hotlist_cmd (void)
1039 char *prompt, *label;
1040 const char *cp = _("Label for \"%s\":");
1041 int l = strlen (cp);
1042 char *label_string = g_strdup (current_panel->cwd);
1044 strip_password (label_string, 1);
1046 prompt = g_strdup_printf (cp, path_trunc (current_panel->cwd, COLS-2*UX-(l+8)));
1047 label = input_dialog (_(" Add to hotlist "), prompt, MC_HISTORY_HOTLIST_ADD, label_string);
1048 g_free (prompt);
1050 if (!label || !*label) {
1051 g_free (label_string);
1052 g_free (label);
1053 return;
1055 add2hotlist (label, label_string, HL_TYPE_ENTRY, 0);
1056 hotlist_state.modified = 1;
1059 static void remove_group (struct hotlist *grp)
1061 struct hotlist *current = grp->head;
1063 while (current) {
1064 struct hotlist *next = current->next;
1066 if (current->type == HL_TYPE_GROUP)
1067 remove_group (current);
1069 g_free (current->label);
1070 g_free (current->directory);
1071 g_free (current);
1073 current = next;
1078 static void remove_from_hotlist (struct hotlist *entry)
1080 if (entry->type == HL_TYPE_DOTDOT)
1081 return;
1083 if (confirm_directory_hotlist_delete) {
1084 char *title;
1085 int result;
1087 title = g_strconcat (_(" Remove: "),
1088 name_trunc (entry->label, 30),
1089 " ",
1090 NULL);
1092 if (safe_delete)
1093 query_set_sel (1);
1094 result = query_dialog (title,
1095 _("\n Are you sure you want to remove this entry?"),
1096 D_ERROR, 2, _("&Yes"), _("&No"));
1098 g_free (title);
1100 if (result != 0)
1101 return;
1104 if (entry->type == HL_TYPE_GROUP) {
1105 if (entry->head) {
1106 char *header;
1107 int result;
1109 header = g_strconcat (_(" Remove: "),
1110 name_trunc (entry->label, 30),
1111 " ",
1112 NULL);
1113 result = query_dialog (header, _("\n Group not empty.\n Remove it?"),
1114 D_ERROR, 2,
1115 _("&Yes"), _("&No"));
1116 g_free (header);
1118 if (result != 0)
1119 return;
1122 remove_group (entry);
1125 unlink_entry (entry);
1127 g_free (entry->label);
1128 g_free (entry->directory);
1129 g_free (entry);
1130 /* now remove list entry from screen */
1131 listbox_remove_current (l_hotlist, 1);
1132 hotlist_state.modified = 1;
1135 char *hotlist_cmd (int vfs_or_hotlist)
1137 char *target = NULL;
1139 hotlist_state.type = vfs_or_hotlist;
1140 load_hotlist ();
1142 init_hotlist (vfs_or_hotlist);
1144 /* display file info */
1145 attrset (SELECTED_COLOR);
1147 hotlist_state.running = 1;
1148 run_dlg (hotlist_dlg);
1149 hotlist_state.running = 0;
1150 save_hotlist ();
1152 switch (hotlist_dlg->ret_value) {
1153 case B_CANCEL:
1154 break;
1156 case B_ENTER:
1157 if (l_hotlist->current->data) {
1158 struct hotlist *hlp = (struct hotlist*) l_hotlist->current->data;
1159 target = g_strdup (hlp->directory);
1160 } else
1161 target = g_strdup (l_hotlist->current->text);
1162 break;
1165 hotlist_done ();
1166 return target;
1169 static void
1170 load_group (struct hotlist *grp)
1172 void *profile_keys;
1173 char *key, *value;
1174 char *group_section;
1175 struct hotlist *current = 0;
1177 group_section = find_group_section (grp);
1179 profile_keys = profile_init_iterator (group_section, profile_name);
1181 current_group = grp;
1183 while (profile_keys){
1184 profile_keys = profile_iterator_next (profile_keys, &key, &value);
1185 add2hotlist (g_strdup (value), g_strdup (key), HL_TYPE_GROUP, 0);
1187 g_free (group_section);
1189 profile_keys = profile_init_iterator (grp->directory, profile_name);
1191 while (profile_keys){
1192 profile_keys = profile_iterator_next (profile_keys, &key, &value);
1193 add2hotlist (g_strdup (value),g_strdup (key), HL_TYPE_ENTRY, 0);
1196 for (current = grp->head; current; current = current->next)
1197 load_group (current);
1200 #define TKN_GROUP 0
1201 #define TKN_ENTRY 1
1202 #define TKN_STRING 2
1203 #define TKN_URL 3
1204 #define TKN_ENDGROUP 4
1205 #define TKN_COMMENT 5
1206 #define TKN_EOL 125
1207 #define TKN_EOF 126
1208 #define TKN_UNKNOWN 127
1210 static char *tkn_buf;
1211 static int tkn_buf_length;
1212 static int tkn_length;
1214 static char *hotlist_file_name;
1215 static FILE *hotlist_file;
1216 static time_t hotlist_file_mtime;
1218 static int hot_skip_blanks (void)
1220 int c;
1222 while ((c = getc (hotlist_file)) != EOF && c != '\n' && isspace (c))
1224 return c;
1228 static int hot_next_token (void)
1230 int c;
1232 #define CHECK_BUF() \
1233 do { \
1234 if (tkn_length == tkn_buf_length) \
1235 tkn_buf = tkn_buf ? ( g_realloc (tkn_buf, tkn_buf_length += 1024)) \
1236 : ( g_malloc (tkn_buf_length = 1024)); \
1237 } while (0)
1239 tkn_length = 0;
1241 again:
1242 c = hot_skip_blanks ();
1243 switch (c) {
1244 case EOF:
1245 return TKN_EOF;
1246 break;
1247 case '\n':
1248 return TKN_EOL;
1249 break;
1250 case '#':
1251 while ((c = getc (hotlist_file)) != EOF && c != '\n') {
1252 if (c == EOF)
1253 return TKN_EOF;
1254 if (c != '\n') {
1255 CHECK_BUF();
1256 tkn_buf[tkn_length++] = c == '\n' ? ' ' : c;
1259 CHECK_BUF();
1260 tkn_buf[tkn_length] = '\0';
1261 return TKN_COMMENT;
1262 break;
1263 case '"':
1264 while ((c = getc (hotlist_file)) != EOF && c != '"') {
1265 if (c == '\\')
1266 if ((c = getc (hotlist_file)) == EOF)
1267 return TKN_EOF;
1268 CHECK_BUF();
1269 tkn_buf[tkn_length++] = c == '\n' ? ' ' : c;
1271 if (c == EOF)
1272 return TKN_EOF;
1273 CHECK_BUF();
1274 tkn_buf[tkn_length] = '\0';
1275 return TKN_STRING;
1276 break;
1277 case '\\':
1278 if ((c = getc (hotlist_file)) == EOF)
1279 return TKN_EOF;
1280 if (c == '\n')
1281 goto again;
1283 /* fall through; it is taken as normal character */
1285 default:
1286 do {
1287 CHECK_BUF();
1288 tkn_buf[tkn_length++] = toupper(c);
1289 } while ((c = fgetc (hotlist_file)) != EOF && isalnum (c));
1290 if (c != EOF)
1291 ungetc (c, hotlist_file);
1292 CHECK_BUF();
1293 tkn_buf[tkn_length] = '\0';
1294 if (strncmp (tkn_buf, "GROUP", tkn_length) == 0)
1295 return TKN_GROUP;
1296 else if (strncmp (tkn_buf, "ENTRY", tkn_length) == 0)
1297 return TKN_ENTRY;
1298 else if (strncmp (tkn_buf, "ENDGROUP", tkn_length) == 0)
1299 return TKN_ENDGROUP;
1300 else if (strncmp (tkn_buf, "URL", tkn_length) == 0)
1301 return TKN_URL;
1302 else
1303 return TKN_UNKNOWN;
1304 break;
1308 #define SKIP_TO_EOL { \
1309 int _tkn; \
1310 while ((_tkn = hot_next_token ()) != TKN_EOF && _tkn != TKN_EOL) ; \
1313 #define CHECK_TOKEN(_TKN_) \
1314 if ((tkn = hot_next_token ()) != _TKN_) { \
1315 hotlist_state.readonly = 1; \
1316 hotlist_state.file_error = 1; \
1317 while (tkn != TKN_EOL && tkn != TKN_EOF) \
1318 tkn = hot_next_token (); \
1319 break; \
1322 static void
1323 hot_load_group (struct hotlist * grp)
1325 int tkn;
1326 struct hotlist *new_grp;
1327 char *label, *url;
1329 current_group = grp;
1331 while ((tkn = hot_next_token()) != TKN_ENDGROUP)
1332 switch (tkn) {
1333 case TKN_GROUP:
1334 CHECK_TOKEN(TKN_STRING);
1335 new_grp = add2hotlist (g_strdup (tkn_buf), 0, HL_TYPE_GROUP, 0);
1336 SKIP_TO_EOL;
1337 hot_load_group (new_grp);
1338 current_group = grp;
1339 break;
1340 case TKN_ENTRY:
1341 CHECK_TOKEN(TKN_STRING);
1342 label = g_strdup (tkn_buf);
1343 CHECK_TOKEN(TKN_URL);
1344 CHECK_TOKEN(TKN_STRING);
1345 url = g_strdup (tkn_buf);
1346 add2hotlist (label, url, HL_TYPE_ENTRY, 0);
1347 SKIP_TO_EOL;
1348 break;
1349 case TKN_COMMENT:
1350 label = g_strdup (tkn_buf);
1351 add2hotlist (label, 0, HL_TYPE_COMMENT, 0);
1352 break;
1353 case TKN_EOF:
1354 hotlist_state.readonly = 1;
1355 hotlist_state.file_error = 1;
1356 return;
1357 break;
1358 case TKN_EOL:
1359 /* skip empty lines */
1360 break;
1361 default:
1362 hotlist_state.readonly = 1;
1363 hotlist_state.file_error = 1;
1364 SKIP_TO_EOL;
1365 break;
1367 SKIP_TO_EOL;
1370 static void
1371 hot_load_file (struct hotlist * grp)
1373 int tkn;
1374 struct hotlist *new_grp;
1375 char *label, *url;
1377 current_group = grp;
1379 while ((tkn = hot_next_token())!= TKN_EOF)
1380 switch (tkn) {
1381 case TKN_GROUP:
1382 CHECK_TOKEN(TKN_STRING);
1383 new_grp = add2hotlist (g_strdup (tkn_buf), 0, HL_TYPE_GROUP, 0);
1384 SKIP_TO_EOL;
1385 hot_load_group (new_grp);
1386 current_group = grp;
1387 break;
1388 case TKN_ENTRY:
1389 CHECK_TOKEN(TKN_STRING);
1390 label = g_strdup (tkn_buf);
1391 CHECK_TOKEN(TKN_URL);
1392 CHECK_TOKEN(TKN_STRING);
1393 url = g_strdup (tkn_buf);
1394 add2hotlist (label, url, HL_TYPE_ENTRY, 0);
1395 SKIP_TO_EOL;
1396 break;
1397 case TKN_COMMENT:
1398 label = g_strdup (tkn_buf);
1399 add2hotlist (label, 0, HL_TYPE_COMMENT, 0);
1400 break;
1401 case TKN_EOL:
1402 /* skip empty lines */
1403 break;
1404 default:
1405 hotlist_state.readonly = 1;
1406 hotlist_state.file_error = 1;
1407 SKIP_TO_EOL;
1408 break;
1412 static void
1413 clean_up_hotlist_groups (const char *section)
1415 char *grp_section;
1416 void *profile_keys;
1417 char *key, *value;
1419 grp_section = g_strconcat (section, ".Group", (char *) NULL);
1420 if (profile_has_section (section, profile_name))
1421 profile_clean_section (section, profile_name);
1422 if (profile_has_section (grp_section, profile_name)) {
1423 profile_keys = profile_init_iterator (grp_section, profile_name);
1425 while (profile_keys) {
1426 profile_keys = profile_iterator_next (profile_keys, &key, &value);
1427 clean_up_hotlist_groups (key);
1429 profile_clean_section (grp_section, profile_name);
1431 g_free (grp_section);
1436 static void
1437 load_hotlist (void)
1439 int remove_old_list = 0;
1440 struct stat stat_buf;
1442 if (hotlist_state.loaded) {
1443 stat (hotlist_file_name, &stat_buf);
1444 if (hotlist_file_mtime < stat_buf.st_mtime)
1445 done_hotlist ();
1446 else
1447 return;
1450 if (!hotlist_file_name)
1451 hotlist_file_name = mhl_str_dir_plus_file (home_dir, HOTLIST_FILENAME);
1453 hotlist = new_hotlist ();
1454 hotlist->type = HL_TYPE_GROUP;
1455 hotlist->label = g_strdup (_(" Top level group "));
1456 hotlist->up = hotlist;
1458 * compatibility :-(
1460 hotlist->directory = g_strdup ("Hotlist");
1462 if ((hotlist_file = fopen (hotlist_file_name, "r")) == 0) {
1463 int result;
1465 load_group (hotlist);
1466 hotlist_state.loaded = 1;
1468 * just to be sure we got copy
1470 hotlist_state.modified = 1;
1471 result = save_hotlist ();
1472 hotlist_state.modified = 0;
1473 if (result) {
1474 remove_old_list = 1;
1475 } else {
1476 message (D_ERROR, _(" Hotlist Load "),
1477 _("MC was unable to write ~/%s file, your old hotlist entries were not deleted"),
1478 HOTLIST_FILENAME);
1480 } else {
1481 hot_load_file (hotlist);
1482 fclose (hotlist_file);
1483 hotlist_state.loaded = 1;
1486 if (remove_old_list) {
1487 clean_up_hotlist_groups ("Hotlist");
1488 sync_profiles ();
1491 stat (hotlist_file_name, &stat_buf);
1492 hotlist_file_mtime = stat_buf.st_mtime;
1493 current_group = hotlist;
1497 static int list_level = 0;
1499 static void
1500 hot_save_group (struct hotlist *grp)
1502 struct hotlist *current = grp->head;
1503 int i;
1504 char *s;
1506 #define INDENT(n) \
1507 do { \
1508 for (i = 0; i < n; i++) \
1509 putc (' ', hotlist_file); \
1510 } while (0)
1512 for (;current; current = current->next)
1513 switch (current->type) {
1514 case HL_TYPE_GROUP:
1515 INDENT (list_level);
1516 fputs ("GROUP \"", hotlist_file);
1517 for (s = current->label; *s; s++) {
1518 if (*s == '"' || *s == '\\')
1519 putc ('\\', hotlist_file);
1520 putc (*s, hotlist_file);
1522 fputs ("\"\n", hotlist_file);
1523 list_level += 2;
1524 hot_save_group (current);
1525 list_level -= 2;
1526 INDENT (list_level);
1527 fputs ("ENDGROUP\n", hotlist_file);
1528 break;
1529 case HL_TYPE_ENTRY:
1530 INDENT(list_level);
1531 fputs ("ENTRY \"", hotlist_file);
1532 for (s = current->label; *s; s++) {
1533 if (*s == '"' || *s == '\\')
1534 putc ('\\', hotlist_file);
1535 putc (*s, hotlist_file);
1537 fputs ("\" URL \"", hotlist_file);
1538 for (s = current->directory; *s; s++) {
1539 if (*s == '"' || *s == '\\')
1540 putc ('\\', hotlist_file);
1541 putc (*s, hotlist_file);
1543 fputs ("\"\n", hotlist_file);
1544 break;
1545 case HL_TYPE_COMMENT:
1546 fprintf (hotlist_file, "#%s\n", current->label);
1547 break;
1548 case HL_TYPE_DOTDOT:
1549 /* do nothing */
1550 break;
1554 int save_hotlist (void)
1556 int saved = 0;
1557 struct stat stat_buf;
1559 if (!hotlist_state.readonly && hotlist_state.modified && hotlist_file_name) {
1560 char *fbak = g_strconcat (hotlist_file_name, ".bak", (char *) NULL);
1562 rename (hotlist_file_name, fbak);
1563 if ((hotlist_file = fopen (hotlist_file_name, "w")) != 0) {
1564 if (stat (fbak, &stat_buf) == 0)
1565 chmod (hotlist_file_name, stat_buf.st_mode);
1566 else
1567 chmod (hotlist_file_name, S_IRUSR | S_IWUSR);
1568 hot_save_group (hotlist);
1569 fclose (hotlist_file);
1570 stat (hotlist_file_name, &stat_buf);
1571 hotlist_file_mtime = stat_buf.st_mtime;
1572 saved = 1;
1573 hotlist_state.modified = 0;
1574 } else
1575 rename (fbak, hotlist_file_name);
1576 g_free (fbak);
1579 return saved;
1583 * Unload list from memory.
1584 * Don't confuse with hotlist_done() for GUI.
1586 void done_hotlist (void)
1588 if (hotlist){
1589 remove_group (hotlist);
1590 g_free (hotlist->label);
1591 g_free (hotlist->directory);
1592 g_free (hotlist);
1593 hotlist = 0;
1596 hotlist_state.loaded = 0;
1598 g_free (hotlist_file_name);
1599 hotlist_file_name = 0;
1600 l_hotlist = 0;
1601 current_group = 0;
1602 if (tkn_buf){
1603 g_free (tkn_buf);
1604 tkn_buf_length = 0;
1605 tkn_length = 0;
1606 tkn_buf = NULL;
1610 static void
1611 add_dotdot_to_list (void)
1613 if (current_group != hotlist) {
1614 if (hotlist_has_dot_dot != 0)
1615 add2hotlist (g_strdup (".."), g_strdup (".."), HL_TYPE_DOTDOT, 0);