* extfs.c (extfs_generate_entry): Initialize inode->last_in_subdir.
[midnight-commander.git] / src / hotlist.c
blob5ce460631b91e66f6b1df06edbff345e14d34ef2
1 /* Directory hotlist -- for the Midnight Commander
2 Copyright (C) 1994, 1995, 1996, 1997 the Free Software Foundation.
4 Written by:
5 1994 Radek Doulik
6 1995 Janne Kukonlehto
7 1996 Andrej Borsenkow
8 1997 Norbert Warmuth
10 Janne did the original Hotlist code, Andrej made the groupable
11 hotlist; the move hotlist and revamped the file format and made
12 it stronger.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program 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, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include <config.h>
30 #ifdef HAVE_UNISTD_H
31 # include <unistd.h>
32 #endif
33 #include <string.h>
34 #include <stdio.h>
35 #include <ctype.h>
36 #include <sys/types.h>
37 #include <sys/stat.h>
39 #include "global.h"
40 #include "tty.h" /* COLS */
41 #include "color.h" /* dialog_colors */
42 #include "dialog.h"
43 #include "widget.h"
44 #include "setup.h" /* For profile_bname */
45 #include "profile.h" /* Load/save directories hotlist */
46 #include "wtools.h" /* QuickDialog */
47 #include "panel.h" /* current_panel */
48 #include "main.h" /* repaint_screen */
49 #include "hotlist.h"
50 #include "key.h" /* KEY_M_CTRL */
51 #include "command.h" /* cmdline */
52 #include "glibcompat.h" /* g_strlcpy for glib < 2.0 */
54 #define UX 5
55 #define UY 2
57 #define BX UX
58 #define BY (LINES - 6)
60 #define BUTTONS (sizeof(hotlist_but)/sizeof(struct _hotlist_but))
61 #define LABELS 3
62 #define B_ADD_CURRENT B_USER
63 #define B_REMOVE (B_USER + 1)
64 #define B_NEW_GROUP (B_USER + 2)
65 #define B_NEW_ENTRY (B_USER + 3)
66 #define B_UP_GROUP (B_USER + 4)
67 #define B_INSERT (B_USER + 5)
68 #define B_APPEND (B_USER + 6)
69 #define B_MOVE (B_USER + 7)
71 #ifdef USE_VFS
72 #include "../vfs/gc.h"
73 #define B_FREE_ALL_VFS (B_USER + 8)
74 #define B_REFRESH_VFS (B_USER + 9)
75 #endif
77 static WListbox *l_hotlist;
78 static WListbox *l_movelist;
80 static Dlg_head *hotlist_dlg;
81 static Dlg_head *movelist_dlg;
83 static WLabel *pname, *pname_group, *movelist_group;
85 enum HotListType {
86 HL_TYPE_GROUP,
87 HL_TYPE_ENTRY,
88 HL_TYPE_COMMENT
91 static struct {
93 * these parameters are intended to be user configurable
95 int expanded; /* expanded view of all groups at startup */
98 * these reflect run time state
101 int loaded; /* hotlist is loaded */
102 int readonly; /* hotlist readonly */
103 int file_error; /* parse error while reading file */
104 int running; /* we are running dlg (and have to
105 update listbox */
106 int moving; /* we are in moving hotlist currently */
107 int modified; /* hotlist was modified */
108 int type; /* LIST_HOTLIST || LIST_VFSLIST */
109 } hotlist_state;
111 static struct _hotlist_but {
112 int ret_cmd, flags, y, x;
113 const char *text;
114 int type;
115 } hotlist_but[] = {
116 { B_MOVE, NORMAL_BUTTON, 1, 42, N_("&Move"), LIST_HOTLIST},
117 { B_REMOVE, NORMAL_BUTTON, 1, 30, N_("&Remove"), LIST_HOTLIST},
118 { B_APPEND, NORMAL_BUTTON, 1, 15, N_("&Append"), LIST_MOVELIST},
119 { B_INSERT, NORMAL_BUTTON, 1, 0, N_("&Insert"), LIST_MOVELIST},
120 { B_NEW_ENTRY, NORMAL_BUTTON, 1, 15, N_("New &Entry"), LIST_HOTLIST},
121 { B_NEW_GROUP, NORMAL_BUTTON, 1, 0, N_("New &Group"), LIST_HOTLIST},
122 { B_CANCEL, NORMAL_BUTTON, 0, 53, N_("&Cancel"), LIST_HOTLIST|LIST_VFSLIST|LIST_MOVELIST},
123 { B_UP_GROUP, NORMAL_BUTTON, 0, 42, N_("&Up"), LIST_HOTLIST|LIST_MOVELIST},
124 { B_ADD_CURRENT, NORMAL_BUTTON, 0, 20, N_("&Add current"), LIST_HOTLIST},
125 #ifdef USE_VFS
126 { B_REFRESH_VFS, NORMAL_BUTTON, 0, 43, N_("&Refresh"), LIST_VFSLIST},
127 { B_FREE_ALL_VFS, NORMAL_BUTTON, 0, 20, N_("Fr&ee VFSs now"), LIST_VFSLIST},
128 #endif
129 { B_ENTER, DEFPUSH_BUTTON, 0, 0, N_("Change &To"), LIST_HOTLIST|LIST_VFSLIST|LIST_MOVELIST},
132 /* Directory hotlist */
133 static struct hotlist{
134 enum HotListType type;
135 char *directory;
136 char *label;
137 struct hotlist *head;
138 struct hotlist *up;
139 struct hotlist *next;
140 } *hotlist = NULL;
142 static struct hotlist *current_group;
144 static void init_movelist (int, struct hotlist *);
145 static void add_new_group_cmd (void);
146 static void add_new_entry_cmd (void);
147 static void remove_from_hotlist (struct hotlist *entry);
148 static void load_hotlist (void);
150 #define new_hotlist() g_new0(struct hotlist, 1)
152 static void
153 hotlist_refresh (Dlg_head * dlg)
155 common_dialog_repaint (dlg);
156 attrset (COLOR_NORMAL);
157 draw_box (dlg, 2, 5, dlg->lines - (hotlist_state.moving ? 6 : 10),
158 dlg->cols - (UX * 2));
159 if (!hotlist_state.moving)
160 draw_box (dlg, dlg->lines - 8, 5, 3, dlg->cols - (UX * 2));
163 /* If current->data is 0, then we are dealing with a VFS pathname */
164 static inline void
165 update_path_name (void)
167 const char *text;
168 char *p;
169 WListbox *list = hotlist_state.moving ? l_movelist : l_hotlist;
170 Dlg_head *dlg = list->widget.parent;
172 if (list->current) {
173 if (list->current->data != 0) {
174 struct hotlist *hlp = (struct hotlist *) list->current->data;
176 if (hlp->type == HL_TYPE_ENTRY)
177 text = hlp->directory;
178 else
179 text = _("Subgroup - press ENTER to see list");
180 } else {
181 text = list->current->text;
183 } else {
184 text = "";
186 if (!hotlist_state.moving)
187 label_set_text (pname,
188 name_trunc (text, dlg->cols - (UX * 2 + 4)));
190 p = g_strconcat (" ", current_group->label, " ", (char *) NULL);
191 if (!hotlist_state.moving)
192 label_set_text (pname_group,
193 name_trunc (p, dlg->cols - (UX * 2 + 4)));
194 else
195 label_set_text (movelist_group,
196 name_trunc (p, dlg->cols - (UX * 2 + 4)));
197 g_free (p);
199 dlg_redraw (dlg);
202 #define CHECK_BUFFER \
203 do { \
204 int i; \
206 if ((i = strlen (current->label) + 3) > buflen) { \
207 g_free (buf); \
208 buf = g_malloc (buflen = 1024 * (i/1024 + 1)); \
210 buf[0] = '\0'; \
211 } while (0)
213 static void fill_listbox (void)
215 struct hotlist *current = current_group->head;
216 static char *buf;
217 static int buflen;
219 if (!buf)
220 buf = g_malloc (buflen = 1024);
221 buf[0] = '\0';
223 while (current){
224 switch (current->type) {
225 case HL_TYPE_GROUP:
227 CHECK_BUFFER;
228 strcat (strcat (buf, "->"), current->label);
229 if (hotlist_state.moving)
230 listbox_add_item (l_movelist, 0, 0, buf, current);
231 else
232 listbox_add_item (l_hotlist, 0, 0, buf, current);
234 break;
235 case HL_TYPE_ENTRY:
236 if (hotlist_state.moving)
237 listbox_add_item (l_movelist, 0, 0, current->label, current);
238 else
239 listbox_add_item (l_hotlist, 0, 0, current->label, current);
240 break;
241 default:
242 break;
244 current = current->next;
248 #undef CHECK_BUFFER
250 static void
251 unlink_entry (struct hotlist *entry)
253 struct hotlist *current = current_group->head;
255 if (current == entry)
256 current_group->head = entry->next;
257 else {
258 while (current && current->next != entry)
259 current = current->next;
260 if (current)
261 current->next = entry->next;
263 entry->next =
264 entry->up = 0;
267 #ifdef USE_VFS
268 static void add_name_to_list (const char *path)
270 listbox_add_item (l_hotlist, 0, 0, path, 0);
272 #endif /* !USE_VFS */
274 static int
275 hotlist_button_callback (int action)
277 switch (action) {
278 case B_MOVE:
280 struct hotlist *saved = current_group;
281 struct hotlist *item;
282 struct hotlist *moveto_item = 0;
283 struct hotlist *moveto_group = 0;
284 int ret;
286 if (!l_hotlist->current)
287 return MSG_NOT_HANDLED; /* empty group - nothing to do */
288 item = l_hotlist->current->data;
289 hotlist_state.moving = 1;
290 init_movelist (LIST_MOVELIST, item);
291 run_dlg (movelist_dlg);
292 ret = movelist_dlg->ret_value;
293 hotlist_state.moving = 0;
294 if (l_movelist->current)
295 moveto_item = l_movelist->current->data;
296 moveto_group = current_group;
297 destroy_dlg (movelist_dlg);
298 current_group = saved;
299 if (ret == B_CANCEL)
300 return MSG_NOT_HANDLED;
301 if (moveto_item == item)
302 return MSG_NOT_HANDLED; /* If we insert/append a before/after a
303 it hardly changes anything ;) */
304 unlink_entry (item);
305 listbox_remove_current (l_hotlist, 1);
306 item->up = moveto_group;
307 if (!moveto_group->head)
308 moveto_group->head = item;
309 else if (!moveto_item) { /* we have group with just comments */
310 struct hotlist *p = moveto_group->head;
312 /* skip comments */
313 while (p->next)
314 p = p->next;
315 p->next = item;
316 } else if (ret == B_ENTER || ret == B_APPEND)
317 if (!moveto_item->next)
318 moveto_item->next = item;
319 else {
320 item->next = moveto_item->next;
321 moveto_item->next = item;
322 } else if (moveto_group->head == moveto_item) {
323 moveto_group->head = item;
324 item->next = moveto_item;
325 } else {
326 struct hotlist *p = moveto_group->head;
328 while (p->next != moveto_item)
329 p = p->next;
330 item->next = p->next;
331 p->next = item;
333 listbox_remove_list (l_hotlist);
334 fill_listbox ();
335 repaint_screen ();
336 hotlist_state.modified = 1;
337 return MSG_NOT_HANDLED;
338 break;
340 case B_REMOVE:
341 if (l_hotlist->current && l_hotlist->current->data)
342 remove_from_hotlist (l_hotlist->current->data);
343 return MSG_NOT_HANDLED;
344 break;
346 case B_NEW_GROUP:
347 add_new_group_cmd ();
348 return MSG_NOT_HANDLED;
349 break;
351 case B_ADD_CURRENT:
352 add2hotlist_cmd ();
353 return MSG_NOT_HANDLED;
354 break;
356 case B_NEW_ENTRY:
357 add_new_entry_cmd ();
358 return MSG_NOT_HANDLED;
359 break;
361 case B_ENTER:
363 WListbox *list = hotlist_state.moving ? l_movelist : l_hotlist;
364 if (list->current) {
365 if (list->current->data) {
366 struct hotlist *hlp =
367 (struct hotlist *) list->current->data;
368 if (hlp->type == HL_TYPE_ENTRY)
369 return MSG_HANDLED;
370 else {
371 listbox_remove_list (list);
372 current_group = hlp;
373 fill_listbox ();
374 return MSG_NOT_HANDLED;
376 } else
377 return MSG_HANDLED;
380 /* Fall through if list empty - just go up */
382 case B_UP_GROUP:
384 WListbox *list = hotlist_state.moving ? l_movelist : l_hotlist;
385 listbox_remove_list (list);
386 current_group = current_group->up;
387 fill_listbox ();
388 return MSG_NOT_HANDLED;
389 break;
392 #ifdef USE_VFS
393 case B_FREE_ALL_VFS:
394 vfs_expire (1);
395 /* fall through */
397 case B_REFRESH_VFS:
398 listbox_remove_list (l_hotlist);
399 listbox_add_item (l_hotlist, 0, 0, home_dir, 0);
400 vfs_fill_names (add_name_to_list);
401 return MSG_NOT_HANDLED;
402 #endif /* USE_VFS */
404 default:
405 return MSG_HANDLED;
406 break;
411 static cb_ret_t
412 hotlist_callback (Dlg_head *h, dlg_msg_t msg, int parm)
414 switch (msg) {
415 case DLG_DRAW:
416 hotlist_refresh (h);
417 return MSG_HANDLED;
419 case DLG_UNHANDLED_KEY:
420 switch (parm) {
421 case KEY_M_CTRL | '\n':
422 goto l1;
423 case '\n':
424 case KEY_ENTER:
425 case KEY_RIGHT:
426 if (hotlist_button_callback (B_ENTER)) {
427 h->ret_value = B_ENTER;
428 dlg_stop (h);
430 return MSG_HANDLED;
431 break;
432 case KEY_LEFT:
433 if (hotlist_state.type != LIST_VFSLIST)
434 return !hotlist_button_callback (B_UP_GROUP);
435 else
436 return MSG_NOT_HANDLED;
437 break;
438 case KEY_DC:
439 if (!hotlist_state.moving) {
440 hotlist_button_callback (B_REMOVE);
441 return MSG_HANDLED;
443 break;
445 case ALT ('\n'):
446 case ALT ('\r'):
447 if (!hotlist_state.moving) {
448 if (l_hotlist->current) {
449 if (l_hotlist->current->data) {
450 struct hotlist *hlp =
451 (struct hotlist *) l_hotlist->current->data;
452 if (hlp->type == HL_TYPE_ENTRY) {
453 char *tmp =
454 g_strconcat ("cd ", hlp->directory, (char *) NULL);
455 stuff (cmdline, tmp, 0);
456 g_free (tmp);
457 dlg_stop (h);
458 h->ret_value = B_CANCEL;
459 return MSG_HANDLED;
464 return MSG_HANDLED; /* ignore key */
466 return MSG_NOT_HANDLED;
468 case DLG_POST_KEY:
469 if (hotlist_state.moving)
470 dlg_select_widget (movelist_dlg, l_movelist);
471 else
472 dlg_select_widget (hotlist_dlg, l_hotlist);
473 /* always stay on hotlist */
474 /* fall through */
476 case DLG_INIT:
477 attrset (MENU_ENTRY_COLOR);
478 update_path_name ();
479 return MSG_HANDLED;
481 default:
482 return default_dlg_callback (h, msg, parm);
486 static int l_call (WListbox *list)
488 Dlg_head *dlg = list->widget.parent;
490 if (list->current){
491 if (list->current->data) {
492 struct hotlist *hlp = (struct hotlist*) list->current->data;
493 if (hlp->type == HL_TYPE_ENTRY) {
494 dlg->ret_value = B_ENTER;
495 dlg_stop (dlg);
496 return LISTBOX_DONE;
497 } else {
498 hotlist_button_callback (B_ENTER);
499 hotlist_callback (dlg, DLG_POST_KEY, '\n');
500 return LISTBOX_CONT;
502 } else {
503 dlg->ret_value = B_ENTER;
504 dlg_stop (dlg);
505 return LISTBOX_DONE;
509 hotlist_button_callback (B_UP_GROUP);
510 hotlist_callback (dlg, DLG_POST_KEY, 'u');
511 return LISTBOX_CONT;
515 * Expands all button names (once) and recalculates button positions.
516 * returns number of columns in the dialog box, which is 10 chars longer
517 * then buttonbar.
519 * If common width of the window (i.e. in xterm) is less than returned
520 * width - sorry :) (anyway this did not handled in previous version too)
522 static int
523 init_i18n_stuff(int list_type, int cols)
525 register int i;
526 static const char* cancel_but = N_("&Cancel");
528 #ifdef ENABLE_NLS
529 static int hotlist_i18n_flag = 0;
531 if (!hotlist_i18n_flag)
533 i = sizeof (hotlist_but) / sizeof (hotlist_but [0]);
534 while (i--)
535 hotlist_but [i].text = _(hotlist_but [i].text);
537 cancel_but = _(cancel_but);
538 hotlist_i18n_flag = 1;
540 #endif /* ENABLE_NLS */
542 /* Dynamic resizing of buttonbars */
544 int len[2], count[2]; /* at most two lines of buttons */
545 int cur_x[2], row;
547 i = sizeof (hotlist_but) / sizeof (hotlist_but [0]);
548 len[0] = len[1] = count[0] = count[1] = 0;
550 /* Count len of buttonbars, assuming 2 extra space between buttons */
551 while (i--)
553 if (! (hotlist_but[i].type & list_type))
554 continue;
556 row = hotlist_but [i].y;
557 ++count [row];
558 len [row] += strlen (hotlist_but [i].text) + 5;
559 if (hotlist_but [i].flags == DEFPUSH_BUTTON)
560 len [row] += 2;
562 len[0] -= 2;
563 len[1] -= 2;
565 cols = max(cols, max(len[0], len[1]));
567 /* arrange buttons */
569 cur_x[0] = cur_x[1] = 0;
570 i = sizeof (hotlist_but) / sizeof (hotlist_but [0]);
571 while (i--)
573 if (! (hotlist_but[i].type & list_type))
574 continue;
576 row = hotlist_but [i].y;
578 if (hotlist_but [i].x != 0)
580 /* not first int the row */
581 if (!strcmp (hotlist_but [i].text, cancel_but))
582 hotlist_but [i].x =
583 cols - strlen (hotlist_but [i].text) - 13;
584 else
585 hotlist_but [i].x = cur_x [row];
588 cur_x [row] += strlen (hotlist_but [i].text) + 2
589 + (hotlist_but [i].flags == DEFPUSH_BUTTON ? 5 : 3);
593 return cols;
596 static void
597 init_hotlist (int list_type)
599 size_t i;
600 const char *title, *help_node;
601 int hotlist_cols;
603 hotlist_cols = init_i18n_stuff (list_type, COLS - 6);
605 do_refresh ();
607 hotlist_state.expanded =
608 GetPrivateProfileInt ("HotlistConfig", "expanded_view_of_groups",
609 0, profile_name);
611 if (list_type == LIST_VFSLIST) {
612 title = _("Active VFS directories");
613 help_node = "[vfshot]"; /* FIXME - no such node */
614 } else {
615 title = _("Directory hotlist");
616 help_node = "[Hotlist]";
619 hotlist_dlg =
620 create_dlg (0, 0, LINES - 2, hotlist_cols, dialog_colors,
621 hotlist_callback, help_node, title, DLG_CENTER | DLG_REVERSE);
623 for (i = 0; i < BUTTONS; i++) {
624 if (hotlist_but[i].type & list_type)
625 add_widget (hotlist_dlg,
626 button_new (BY + hotlist_but[i].y,
627 BX + hotlist_but[i].x,
628 hotlist_but[i].ret_cmd,
629 hotlist_but[i].flags,
630 hotlist_but[i].text,
631 hotlist_button_callback));
634 /* We add the labels.
635 * pname will hold entry's pathname;
636 * pname_group will hold name of current group
638 pname = label_new (UY - 11 + LINES, UX + 2, "");
639 add_widget (hotlist_dlg, pname);
640 if (!hotlist_state.moving) {
641 add_widget (hotlist_dlg,
642 label_new (UY - 12 + LINES, UX + 1,
643 _(" Directory path ")));
645 /* This one holds the displayed pathname */
646 pname_group = label_new (UY, UX + 1, _(" Directory label "));
647 add_widget (hotlist_dlg, pname_group);
649 /* get new listbox */
650 l_hotlist =
651 listbox_new (UY + 1, UX + 1, COLS - 2 * UX - 8, LINES - 14,
652 l_call);
654 /* Fill the hotlist with the active VFS or the hotlist */
655 #ifdef USE_VFS
656 if (list_type == LIST_VFSLIST) {
657 listbox_add_item (l_hotlist, 0, 0, home_dir, 0);
658 vfs_fill_names (add_name_to_list);
659 } else
660 #endif /* !USE_VFS */
661 fill_listbox ();
663 add_widget (hotlist_dlg, l_hotlist);
664 /* add listbox to the dialogs */
667 static void
668 init_movelist (int list_type, struct hotlist *item)
670 size_t i;
671 char *hdr = g_strdup_printf (_("Moving %s"), item->label);
672 int movelist_cols = init_i18n_stuff (list_type, COLS - 6);
674 do_refresh ();
676 movelist_dlg =
677 create_dlg (0, 0, LINES - 6, movelist_cols, dialog_colors,
678 hotlist_callback, "[Hotlist]", hdr, DLG_CENTER | DLG_REVERSE);
679 g_free (hdr);
681 for (i = 0; i < BUTTONS; i++) {
682 if (hotlist_but[i].type & list_type)
683 add_widget (movelist_dlg,
684 button_new (BY - 4 + hotlist_but[i].y,
685 BX + hotlist_but[i].x,
686 hotlist_but[i].ret_cmd,
687 hotlist_but[i].flags,
688 hotlist_but[i].text,
689 hotlist_button_callback));
692 /* We add the labels. We are interested in the last one,
693 * that one will hold the path name label
695 movelist_group = label_new (UY, UX + 1, _(" Directory label "));
696 add_widget (movelist_dlg, movelist_group);
697 /* get new listbox */
698 l_movelist =
699 listbox_new (UY + 1, UX + 1, movelist_dlg->cols - 2 * UX - 2,
700 movelist_dlg->lines - 8, l_call);
702 fill_listbox ();
704 add_widget (movelist_dlg, l_movelist);
705 /* add listbox to the dialogs */
709 * Destroy the list dialog.
710 * Don't confuse with done_hotlist() for the list in memory.
712 static void hotlist_done (void)
714 destroy_dlg (hotlist_dlg);
715 l_hotlist = NULL;
716 if (0)
717 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
718 repaint_screen ();
721 static inline char *
722 find_group_section (struct hotlist *grp)
724 return g_strconcat (grp->directory, ".Group", (char *) NULL);
728 /* 1.11.96 bor: added pos parameter to control placement of new item.
729 see widget.c, listbox_add_item()
730 now hotlist is in unsorted mode
732 enum {
733 HL_BEFORE_CURRENT = 1
734 ,HL_AFTER_CURRENT = 2
737 static struct hotlist *
738 add2hotlist (char *label, char *directory, enum HotListType type, int pos)
740 struct hotlist *new;
741 struct hotlist *current = NULL;
744 * Hotlist is neither loaded nor loading.
745 * Must be called by "Ctrl-x a" before using hotlist.
747 if (!current_group)
748 load_hotlist ();
750 if (l_hotlist && l_hotlist->current)
751 current = l_hotlist->current->data;
753 new = new_hotlist ();
755 new->type = type;
756 new->label = label;
757 new->directory = directory;
758 new->up = current_group;
760 if (!current_group->head) { /* first element in group */
761 current_group->head = new;
762 } else if (pos == HL_AFTER_CURRENT) {
763 new->next = current->next;
764 current->next = new;
765 } else if (pos == HL_BEFORE_CURRENT &&
766 current == current_group->head) {
767 /* should be inserted before first item */
768 new->next = current;
769 current_group->head = new;
770 } else if (pos == HL_BEFORE_CURRENT) {
771 struct hotlist *p = current_group->head;
773 while (p->next != current)
774 p = p->next;
776 new->next = current;
777 p->next = new;
778 } else { /* append at the end */
779 struct hotlist *p = current_group->head;
781 while (p->next)
782 p = p->next;
784 p->next = new;
787 if (hotlist_state.running && type != HL_TYPE_COMMENT) {
788 if (type == HL_TYPE_GROUP) {
789 char *lbl = g_strconcat ("->", new->label, (char *) NULL);
791 listbox_add_item (l_hotlist, pos, 0, lbl, new);
792 g_free (lbl);
793 } else
794 listbox_add_item (l_hotlist, pos, 0, new->label, new);
795 listbox_select_entry (l_hotlist, l_hotlist->current);
797 return new;
801 #ifdef ENABLE_NLS
803 * Support routine for add_new_entry_input()/add_new_group_input()
804 * Change positions of buttons (first three widgets).
806 * This is just a quick hack. Accurate procedure must take care of
807 * internationalized label lengths and total buttonbar length...assume
808 * 64 is longer anyway.
810 static void add_widgets_i18n(QuickWidget* qw, int len)
812 int i, l[3], space, cur_x;
814 for (i = 0; i < 3; i++)
816 qw [i].text = _(qw [i].text);
817 l[i] = strlen (qw [i].text) + 3;
819 space = (len - 4 - l[0] - l[1] - l[2]) / 4;
821 for (cur_x = 2 + space, i = 3; i--; cur_x += l[i] + space)
823 qw [i].relative_x = cur_x;
824 qw [i].x_divisions = len;
827 #endif /* ENABLE_NLS */
829 static int
830 add_new_entry_input (const char *header, const char *text1, const char *text2,
831 const char *help, char **r1, char **r2)
833 #define RELATIVE_Y_BUTTONS 4
834 #define RELATIVE_Y_LABEL_PTH 3
835 #define RELATIVE_Y_INPUT_PTH 4
837 QuickDialog Quick_input;
838 static QuickWidget quick_widgets [] = {
839 { quick_button, 55, 80, RELATIVE_Y_BUTTONS, 0, N_("&Cancel"), 0, B_CANCEL,
840 0, 0, "button-cancel" },
841 { quick_button, 30, 80, RELATIVE_Y_BUTTONS, 0, N_("&Insert"), 0, B_INSERT,
842 0, 0, "button-insert" },
843 { quick_button, 10, 80, RELATIVE_Y_BUTTONS, 0, N_("&Append"), 0, B_APPEND,
844 0, 0, "button-append" },
845 { quick_input, 4, 80, RELATIVE_Y_INPUT_PTH, 0, "",58, 0,
846 0, 0, "input-pth" },
847 { quick_label, RELATIVE_Y_LABEL_PTH, 80, 3, 0, 0, 0, 0,
848 0, 0, "label-pth" },
849 { quick_input, 4, 80, 3, 0, "", 58, 0,
850 0, 0, "input-lbl" },
851 { quick_label, 3, 80, 2, 0, 0, 0, 0,
852 0, 0, "label-lbl" },
853 NULL_QuickWidget };
855 size_t len;
856 int i;
857 int lines1, lines2;
859 #ifdef ENABLE_NLS
860 static int i18n_flag = 0;
861 #endif /* ENABLE_NLS */
863 len = max (strlen (header), (size_t) msglen (text1, &lines1));
864 len = max (len, (size_t) msglen (text2, &lines2)) + 4;
865 len = max (len, 64);
867 #ifdef ENABLE_NLS
868 if (!i18n_flag)
870 add_widgets_i18n(quick_widgets, len);
871 i18n_flag = 1;
873 #endif /* ENABLE_NLS */
875 Quick_input.xlen = len;
876 Quick_input.xpos = -1;
877 Quick_input.title = header;
878 Quick_input.help = help;
879 Quick_input.i18n = 0;
880 quick_widgets [6].text = text1;
881 quick_widgets [4].text = text2;
882 quick_widgets [5].text = *r1;
883 quick_widgets [3].text = *r2;
885 for (i = 0; i < 7; i++)
886 quick_widgets [i].y_divisions = lines1+lines2+7;
887 Quick_input.ylen = lines1 + lines2 + 7;
889 quick_widgets [0].relative_y = RELATIVE_Y_BUTTONS + (lines1 + lines2);
890 quick_widgets [1].relative_y = RELATIVE_Y_BUTTONS + (lines1 + lines2);
891 quick_widgets [2].relative_y = RELATIVE_Y_BUTTONS + (lines1 + lines2);
892 quick_widgets [3].relative_y = RELATIVE_Y_INPUT_PTH + (lines1);
893 quick_widgets [4].relative_y = RELATIVE_Y_LABEL_PTH + (lines1);
895 quick_widgets [5].str_result = r1;
896 quick_widgets [3].str_result = r2;
898 Quick_input.widgets = quick_widgets;
899 if ((i = quick_dialog (&Quick_input)) != B_CANCEL){
900 return i;
901 } else
902 return 0;
905 static void add_new_entry_cmd (void)
907 char *title, *url, *to_free;
908 int ret;
910 /* Take current directory as default value for input fields */
911 to_free = title = url = strip_password (g_strdup (current_panel->cwd), 1);
913 ret = add_new_entry_input (_("New hotlist entry"), _("Directory label"),
914 _("Directory path"), "[Hotlist]", &title, &url);
915 g_free (to_free);
917 if (!ret)
918 return;
919 if (!title || !*title || !url || !*url) {
920 g_free (title);
921 g_free (url);
922 return;
925 if (ret == B_ENTER || ret == B_APPEND)
926 add2hotlist (title, url, HL_TYPE_ENTRY, HL_AFTER_CURRENT);
927 else
928 add2hotlist (title, url, HL_TYPE_ENTRY, HL_BEFORE_CURRENT);
930 hotlist_state.modified = 1;
933 static int
934 add_new_group_input (const char *header, const char *label, char **result)
936 int ret;
937 QuickDialog Quick_input;
938 static QuickWidget quick_widgets [] = {
939 { quick_button, 55, 80, 1, 0, N_("&Cancel"), 0, B_CANCEL, 0, 0,
940 "button-cancel" },
941 { quick_button, 30, 80, 1, 0, N_("&Insert"), 0, B_INSERT, 0, 0,
942 "button-insert" },
943 { quick_button, 10, 80, 1, 0, N_("&Append"), 0, B_APPEND, 0, 0,
944 "button-append" },
945 { quick_input, 4, 80, 0, 0, "", 58, 0, 0, 0, "input" },
946 { quick_label, 3, 80, 2, 0, 0, 0, 0, 0, 0, "label" },
947 NULL_QuickWidget };
948 int relative_y[] = {1, 1, 1, 0, 2}; /* the relative_x component from the
949 quick_widgets variable above */
950 int len;
951 int i;
952 int lines;
954 #ifdef ENABLE_NLS
955 static int i18n_flag = 0;
956 #endif /* ENABLE_NLS */
958 len = max (strlen (header), (size_t) msglen (label, &lines)) + 4;
959 len = max (len, 64);
961 #ifdef ENABLE_NLS
962 if (!i18n_flag)
964 add_widgets_i18n(quick_widgets, len);
965 i18n_flag = 1;
967 #endif /* ENABLE_NLS */
969 Quick_input.xlen = len;
970 Quick_input.xpos = -1;
971 Quick_input.title = header;
972 Quick_input.help = "[Hotlist]";
973 Quick_input.i18n = 0;
974 quick_widgets [4].text = label;
976 for (i = 0; i < 5; i++)
977 quick_widgets [i].y_divisions = lines+6;
978 Quick_input.ylen = lines + 6;
980 for (i = 0; i < 4; i++)
981 quick_widgets [i].relative_y = relative_y[i] + 2 + lines;
983 quick_widgets [3].str_result = result;
984 quick_widgets [3].text = "";
986 Quick_input.widgets = quick_widgets;
987 if ((ret = quick_dialog (&Quick_input)) != B_CANCEL){
988 return ret;
989 } else
990 return 0;
993 static void add_new_group_cmd (void)
995 char *label;
996 int ret;
998 ret = add_new_group_input (_(" New hotlist group "), _("Name of new group"), &label);
999 if (!ret || !label || !*label)
1000 return;
1002 if (ret == B_ENTER || ret == B_APPEND)
1003 add2hotlist (label, 0, HL_TYPE_GROUP, HL_AFTER_CURRENT);
1004 else
1005 add2hotlist (label, 0, HL_TYPE_GROUP, HL_BEFORE_CURRENT);
1007 hotlist_state.modified = 1;
1010 void add2hotlist_cmd (void)
1012 char *prompt, *label;
1013 const char *cp = _("Label for \"%s\":");
1014 int l = strlen (cp);
1015 char *label_string = g_strdup (current_panel->cwd);
1017 strip_password (label_string, 1);
1019 prompt = g_strdup_printf (cp, path_trunc (current_panel->cwd, COLS-2*UX-(l+8)));
1020 label = input_dialog (_(" Add to hotlist "), prompt, label_string);
1021 g_free (prompt);
1023 if (!label || !*label) {
1024 g_free (label_string);
1025 g_free (label);
1026 return;
1028 add2hotlist (label, label_string, HL_TYPE_ENTRY, 0);
1029 hotlist_state.modified = 1;
1032 static void remove_group (struct hotlist *grp)
1034 struct hotlist *current = grp->head;
1036 while (current) {
1037 struct hotlist *next = current->next;
1039 if (current->type == HL_TYPE_GROUP)
1040 remove_group (current);
1042 g_free (current->label);
1043 g_free (current->directory);
1044 g_free (current);
1046 current = next;
1051 static void remove_from_hotlist (struct hotlist *entry)
1053 if (entry->type == HL_TYPE_GROUP) {
1054 if (entry->head) {
1055 char *header;
1056 int result;
1058 header = g_strconcat (_(" Remove: "),
1059 name_trunc (entry->label, 30),
1060 " ",
1061 NULL);
1062 result = query_dialog (header, _("\n Group not empty.\n Remove it?"),
1063 D_ERROR, 2,
1064 _("&No"), _("&Yes"));
1065 g_free (header);
1067 if (result != 1)
1068 return;
1071 remove_group (entry);
1074 unlink_entry (entry);
1076 g_free (entry->label);
1077 g_free (entry->directory);
1078 g_free (entry);
1079 /* now remove list entry from screen */
1080 listbox_remove_current (l_hotlist, 1);
1081 hotlist_state.modified = 1;
1084 char *hotlist_cmd (int vfs_or_hotlist)
1086 char *target = NULL;
1088 hotlist_state.type = vfs_or_hotlist;
1089 load_hotlist ();
1091 init_hotlist (vfs_or_hotlist);
1093 /* display file info */
1094 attrset (SELECTED_COLOR);
1096 hotlist_state.running = 1;
1097 run_dlg (hotlist_dlg);
1098 hotlist_state.running = 0;
1099 save_hotlist ();
1101 switch (hotlist_dlg->ret_value) {
1102 case B_CANCEL:
1103 break;
1105 case B_ENTER:
1106 if (l_hotlist->current->data) {
1107 struct hotlist *hlp = (struct hotlist*) l_hotlist->current->data;
1108 target = g_strdup (hlp->directory);
1109 } else
1110 target = g_strdup (l_hotlist->current->text);
1111 break;
1114 hotlist_done ();
1115 return target;
1118 static void
1119 load_group (struct hotlist *grp)
1121 void *profile_keys;
1122 char *key, *value;
1123 char *group_section;
1124 struct hotlist *current = 0;
1126 group_section = find_group_section (grp);
1128 profile_keys = profile_init_iterator (group_section, profile_name);
1130 current_group = grp;
1132 while (profile_keys){
1133 profile_keys = profile_iterator_next (profile_keys, &key, &value);
1134 add2hotlist (g_strdup (value), g_strdup (key), HL_TYPE_GROUP, 0);
1136 g_free (group_section);
1138 profile_keys = profile_init_iterator (grp->directory, profile_name);
1140 while (profile_keys){
1141 profile_keys = profile_iterator_next (profile_keys, &key, &value);
1142 add2hotlist (g_strdup (value),g_strdup (key), HL_TYPE_ENTRY, 0);
1145 for (current = grp->head; current; current = current->next)
1146 load_group (current);
1149 #define TKN_GROUP 0
1150 #define TKN_ENTRY 1
1151 #define TKN_STRING 2
1152 #define TKN_URL 3
1153 #define TKN_ENDGROUP 4
1154 #define TKN_COMMENT 5
1155 #define TKN_EOL 125
1156 #define TKN_EOF 126
1157 #define TKN_UNKNOWN 127
1159 static char *tkn_buf;
1160 static int tkn_buf_length;
1161 static int tkn_length;
1163 static char *hotlist_file_name;
1164 static FILE *hotlist_file;
1165 static time_t hotlist_file_mtime;
1167 static int hot_skip_blanks (void)
1169 int c;
1171 while ((c = getc (hotlist_file)) != EOF && c != '\n' && isspace (c))
1173 return c;
1177 static int hot_next_token (void)
1179 int c;
1181 #define CHECK_BUF() \
1182 do { \
1183 if (tkn_length == tkn_buf_length) \
1184 tkn_buf = tkn_buf ? ( g_realloc (tkn_buf, tkn_buf_length += 1024)) \
1185 : ( g_malloc (tkn_buf_length = 1024)); \
1186 } while (0)
1188 tkn_length = 0;
1190 again:
1191 c = hot_skip_blanks ();
1192 switch (c) {
1193 case EOF:
1194 return TKN_EOF;
1195 break;
1196 case '\n':
1197 return TKN_EOL;
1198 break;
1199 case '#':
1200 while ((c = getc (hotlist_file)) != EOF && c != '\n') {
1201 if (c == EOF)
1202 return TKN_EOF;
1203 if (c != '\n') {
1204 CHECK_BUF();
1205 tkn_buf[tkn_length++] = c == '\n' ? ' ' : c;
1208 CHECK_BUF();
1209 tkn_buf[tkn_length] = '\0';
1210 return TKN_COMMENT;
1211 break;
1212 case '"':
1213 while ((c = getc (hotlist_file)) != EOF && c != '"') {
1214 if (c == '\\')
1215 if ((c = getc (hotlist_file)) == EOF)
1216 return TKN_EOF;
1217 CHECK_BUF();
1218 tkn_buf[tkn_length++] = c == '\n' ? ' ' : c;
1220 if (c == EOF)
1221 return TKN_EOF;
1222 CHECK_BUF();
1223 tkn_buf[tkn_length] = '\0';
1224 return TKN_STRING;
1225 break;
1226 case '\\':
1227 if ((c = getc (hotlist_file)) == EOF)
1228 return TKN_EOF;
1229 if (c == '\n')
1230 goto again;
1232 /* fall through; it is taken as normal character */
1234 default:
1235 do {
1236 CHECK_BUF();
1237 tkn_buf[tkn_length++] = toupper(c);
1238 } while ((c = fgetc (hotlist_file)) != EOF && isalnum (c));
1239 if (c != EOF)
1240 ungetc (c, hotlist_file);
1241 CHECK_BUF();
1242 tkn_buf[tkn_length] = '\0';
1243 if (strncmp (tkn_buf, "GROUP", tkn_length) == 0)
1244 return TKN_GROUP;
1245 else if (strncmp (tkn_buf, "ENTRY", tkn_length) == 0)
1246 return TKN_ENTRY;
1247 else if (strncmp (tkn_buf, "ENDGROUP", tkn_length) == 0)
1248 return TKN_ENDGROUP;
1249 else if (strncmp (tkn_buf, "URL", tkn_length) == 0)
1250 return TKN_URL;
1251 else
1252 return TKN_UNKNOWN;
1253 break;
1257 #define SKIP_TO_EOL { \
1258 int _tkn; \
1259 while ((_tkn = hot_next_token ()) != TKN_EOF && _tkn != TKN_EOL) ; \
1262 #define CHECK_TOKEN(_TKN_) \
1263 if ((tkn = hot_next_token ()) != _TKN_) { \
1264 hotlist_state.readonly = 1; \
1265 hotlist_state.file_error = 1; \
1266 while (tkn != TKN_EOL && tkn != TKN_EOF) \
1267 tkn = hot_next_token (); \
1268 break; \
1271 static void
1272 hot_load_group (struct hotlist * grp)
1274 int tkn;
1275 struct hotlist *new_grp;
1276 char *label, *url;
1278 current_group = grp;
1280 while ((tkn = hot_next_token()) != TKN_ENDGROUP)
1281 switch (tkn) {
1282 case TKN_GROUP:
1283 CHECK_TOKEN(TKN_STRING);
1284 new_grp = add2hotlist (g_strdup (tkn_buf), 0, HL_TYPE_GROUP, 0);
1285 SKIP_TO_EOL;
1286 hot_load_group (new_grp);
1287 current_group = grp;
1288 break;
1289 case TKN_ENTRY:
1290 CHECK_TOKEN(TKN_STRING);
1291 label = g_strdup (tkn_buf);
1292 CHECK_TOKEN(TKN_URL);
1293 CHECK_TOKEN(TKN_STRING);
1294 url = g_strdup (tkn_buf);
1295 add2hotlist (label, url, HL_TYPE_ENTRY, 0);
1296 SKIP_TO_EOL;
1297 break;
1298 case TKN_COMMENT:
1299 label = g_strdup (tkn_buf);
1300 add2hotlist (label, 0, HL_TYPE_COMMENT, 0);
1301 break;
1302 case TKN_EOF:
1303 hotlist_state.readonly = 1;
1304 hotlist_state.file_error = 1;
1305 return;
1306 break;
1307 case TKN_EOL:
1308 /* skip empty lines */
1309 break;
1310 default:
1311 hotlist_state.readonly = 1;
1312 hotlist_state.file_error = 1;
1313 SKIP_TO_EOL;
1314 break;
1316 SKIP_TO_EOL;
1319 static void
1320 hot_load_file (struct hotlist * grp)
1322 int tkn;
1323 struct hotlist *new_grp;
1324 char *label, *url;
1326 current_group = grp;
1328 while ((tkn = hot_next_token())!= TKN_EOF)
1329 switch (tkn) {
1330 case TKN_GROUP:
1331 CHECK_TOKEN(TKN_STRING);
1332 new_grp = add2hotlist (g_strdup (tkn_buf), 0, HL_TYPE_GROUP, 0);
1333 SKIP_TO_EOL;
1334 hot_load_group (new_grp);
1335 current_group = grp;
1336 break;
1337 case TKN_ENTRY:
1338 CHECK_TOKEN(TKN_STRING);
1339 label = g_strdup (tkn_buf);
1340 CHECK_TOKEN(TKN_URL);
1341 CHECK_TOKEN(TKN_STRING);
1342 url = g_strdup (tkn_buf);
1343 add2hotlist (label, url, HL_TYPE_ENTRY, 0);
1344 SKIP_TO_EOL;
1345 break;
1346 case TKN_COMMENT:
1347 label = g_strdup (tkn_buf);
1348 add2hotlist (label, 0, HL_TYPE_COMMENT, 0);
1349 break;
1350 case TKN_EOL:
1351 /* skip empty lines */
1352 break;
1353 default:
1354 hotlist_state.readonly = 1;
1355 hotlist_state.file_error = 1;
1356 SKIP_TO_EOL;
1357 break;
1361 static void
1362 clean_up_hotlist_groups (const char *section)
1364 char *grp_section;
1365 void *profile_keys;
1366 char *key, *value;
1368 grp_section = g_strconcat (section, ".Group", (char *) NULL);
1369 if (profile_has_section (section, profile_name))
1370 profile_clean_section (section, profile_name);
1371 if (profile_has_section (grp_section, profile_name)) {
1372 profile_keys = profile_init_iterator (grp_section, profile_name);
1374 while (profile_keys) {
1375 profile_keys = profile_iterator_next (profile_keys, &key, &value);
1376 clean_up_hotlist_groups (key);
1378 profile_clean_section (grp_section, profile_name);
1380 g_free (grp_section);
1385 static void
1386 load_hotlist (void)
1388 int remove_old_list = 0;
1389 struct stat stat_buf;
1391 if (hotlist_state.loaded) {
1392 stat (hotlist_file_name, &stat_buf);
1393 if (hotlist_file_mtime < stat_buf.st_mtime)
1394 done_hotlist ();
1395 else
1396 return;
1399 if (!hotlist_file_name)
1400 hotlist_file_name = concat_dir_and_file (home_dir, HOTLIST_FILENAME);
1402 hotlist = new_hotlist ();
1403 hotlist->type = HL_TYPE_GROUP;
1404 hotlist->label = g_strdup (_(" Top level group "));
1405 hotlist->up = hotlist;
1407 * compatibility :-(
1409 hotlist->directory = g_strdup ("Hotlist");
1411 if ((hotlist_file = fopen (hotlist_file_name, "r")) == 0) {
1412 int result;
1414 load_group (hotlist);
1415 hotlist_state.loaded = 1;
1417 * just to be sure we got copy
1419 hotlist_state.modified = 1;
1420 result = save_hotlist ();
1421 hotlist_state.modified = 0;
1422 if (result) {
1423 remove_old_list = 1;
1424 } else {
1425 char *msg;
1427 msg = g_strconcat (_("MC was unable to write ~/"), HOTLIST_FILENAME,
1428 _(" file, your old hotlist entries were not deleted"), (char *) NULL);
1430 message (D_ERROR, _(" Hotlist Load "), msg);
1431 g_free (msg);
1433 } else {
1434 hot_load_file (hotlist);
1435 fclose (hotlist_file);
1436 hotlist_state.loaded = 1;
1439 if (remove_old_list) {
1440 clean_up_hotlist_groups ("Hotlist");
1441 sync_profiles ();
1444 stat (hotlist_file_name, &stat_buf);
1445 hotlist_file_mtime = stat_buf.st_mtime;
1446 current_group = hotlist;
1449 static void
1450 save_group (struct hotlist *grp)
1452 struct hotlist *current = grp->head;
1453 char *group_section;
1455 group_section = find_group_section (grp);
1457 profile_clean_section (group_section, profile_name);
1458 for (;current && current->type == HL_TYPE_GROUP; current = current->next){
1459 WritePrivateProfileString (group_section,
1460 current->directory,
1461 current->label,
1462 profile_name);
1464 g_free (group_section);
1466 for (current = grp->head;
1467 current && current->type == HL_TYPE_GROUP;
1468 current = current->next)
1469 save_group (current);
1471 profile_clean_section (grp->directory, profile_name);
1472 for (;current; current = current->next){
1473 WritePrivateProfileString (grp->directory,
1474 current->directory,
1475 current->label,
1476 profile_name);
1480 static int list_level = 0;
1482 static void
1483 hot_save_group (struct hotlist *grp)
1485 struct hotlist *current = grp->head;
1486 int i;
1487 char *s;
1489 #define INDENT(n) \
1490 do { \
1491 for (i = 0; i < n; i++) \
1492 putc (' ', hotlist_file); \
1493 } while (0)
1495 for (;current; current = current->next)
1496 switch (current->type) {
1497 case HL_TYPE_GROUP:
1498 INDENT (list_level);
1499 fputs ("GROUP \"", hotlist_file);
1500 for (s = current->label; *s; s++) {
1501 if (*s == '"' || *s == '\\')
1502 putc ('\\', hotlist_file);
1503 putc (*s, hotlist_file);
1505 fputs ("\"\n", hotlist_file);
1506 list_level += 2;
1507 hot_save_group (current);
1508 list_level -= 2;
1509 INDENT (list_level);
1510 fputs ("ENDGROUP\n", hotlist_file);
1511 break;
1512 case HL_TYPE_ENTRY:
1513 INDENT(list_level);
1514 fputs ("ENTRY \"", hotlist_file);
1515 for (s = current->label; *s; s++) {
1516 if (*s == '"' || *s == '\\')
1517 putc ('\\', hotlist_file);
1518 putc (*s, hotlist_file);
1520 fputs ("\" URL \"", hotlist_file);
1521 for (s = current->directory; *s; s++) {
1522 if (*s == '"' || *s == '\\')
1523 putc ('\\', hotlist_file);
1524 putc (*s, hotlist_file);
1526 fputs ("\"\n", hotlist_file);
1527 break;
1528 case HL_TYPE_COMMENT:
1529 fprintf (hotlist_file, "#%s\n", current->label);
1530 break;
1535 int save_hotlist (void)
1537 int saved = 0;
1538 struct stat stat_buf;
1540 if (!hotlist_state.readonly && hotlist_state.modified && hotlist_file_name) {
1541 char *fbak = g_strconcat (hotlist_file_name, ".bak", (char *) NULL);
1543 rename (hotlist_file_name, fbak);
1544 if ((hotlist_file = fopen (hotlist_file_name, "w")) != 0) {
1545 if (stat (fbak, &stat_buf) == 0)
1546 chmod (hotlist_file_name, stat_buf.st_mode);
1547 else
1548 chmod (hotlist_file_name, S_IRUSR | S_IWUSR);
1549 hot_save_group (hotlist);
1550 fclose (hotlist_file);
1551 stat (hotlist_file_name, &stat_buf);
1552 hotlist_file_mtime = stat_buf.st_mtime;
1553 saved = 1;
1554 hotlist_state.modified = 0;
1555 } else
1556 rename (fbak, hotlist_file_name);
1557 g_free (fbak);
1560 return saved;
1564 * Unload list from memory.
1565 * Don't confuse with hotlist_done() for GUI.
1567 void done_hotlist (void)
1569 if (hotlist){
1570 remove_group (hotlist);
1571 g_free (hotlist->label);
1572 g_free (hotlist->directory);
1573 g_free (hotlist);
1574 hotlist = 0;
1577 hotlist_state.loaded = 0;
1579 g_free (hotlist_file_name);
1580 hotlist_file_name = 0;
1581 l_hotlist = 0;
1582 current_group = 0;
1583 if (tkn_buf){
1584 g_free (tkn_buf);
1585 tkn_buf_length = 0;
1586 tkn_length = 0;
1587 tkn_buf = NULL;