Completely removed MHL stuff
[midnight-commander.git] / src / hotlist.c
blob1d6c4df9c41d7ab3f886c9c1f8709127ad726eeb
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 "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 */
53 #include "history.h"
55 #define UX 5
56 #define UY 2
58 #define BX UX
59 #define BY (LINES - 6)
61 #define BUTTONS (sizeof(hotlist_but)/sizeof(struct _hotlist_but))
62 #define LABELS 3
63 #define B_ADD_CURRENT B_USER
64 #define B_REMOVE (B_USER + 1)
65 #define B_NEW_GROUP (B_USER + 2)
66 #define B_NEW_ENTRY (B_USER + 3)
67 #define B_UP_GROUP (B_USER + 4)
68 #define B_INSERT (B_USER + 5)
69 #define B_APPEND (B_USER + 6)
70 #define B_MOVE (B_USER + 7)
72 #ifdef USE_VFS
73 #include "../vfs/gc.h"
74 #define B_FREE_ALL_VFS (B_USER + 8)
75 #define B_REFRESH_VFS (B_USER + 9)
76 #endif
78 int hotlist_has_dot_dot = 1;
80 static WListbox *l_hotlist;
81 static WListbox *l_movelist;
83 static Dlg_head *hotlist_dlg;
84 static Dlg_head *movelist_dlg;
86 static WLabel *pname, *pname_group, *movelist_group;
88 enum HotListType {
89 HL_TYPE_GROUP,
90 HL_TYPE_ENTRY,
91 HL_TYPE_COMMENT,
92 HL_TYPE_DOTDOT
95 static struct {
97 * these parameters are intended to be user configurable
99 int expanded; /* expanded view of all groups at startup */
102 * these reflect run time state
105 int loaded; /* hotlist is loaded */
106 int readonly; /* hotlist readonly */
107 int file_error; /* parse error while reading file */
108 int running; /* we are running dlg (and have to
109 update listbox */
110 int moving; /* we are in moving hotlist currently */
111 int modified; /* hotlist was modified */
112 int type; /* LIST_HOTLIST || LIST_VFSLIST */
113 } hotlist_state;
115 static struct _hotlist_but {
116 int ret_cmd, flags, y, x;
117 const char *text;
118 int type;
119 } hotlist_but[] = {
120 { B_MOVE, NORMAL_BUTTON, 1, 42, N_("&Move"), LIST_HOTLIST},
121 { B_REMOVE, NORMAL_BUTTON, 1, 30, N_("&Remove"), LIST_HOTLIST},
122 { B_APPEND, NORMAL_BUTTON, 1, 15, N_("&Append"), LIST_MOVELIST},
123 { B_INSERT, NORMAL_BUTTON, 1, 0, N_("&Insert"), LIST_MOVELIST},
124 { B_NEW_ENTRY, NORMAL_BUTTON, 1, 15, N_("New &Entry"), LIST_HOTLIST},
125 { B_NEW_GROUP, NORMAL_BUTTON, 1, 0, N_("New &Group"), LIST_HOTLIST},
126 { B_CANCEL, NORMAL_BUTTON, 0, 53, N_("&Cancel"), LIST_HOTLIST|LIST_VFSLIST|LIST_MOVELIST},
127 { B_UP_GROUP, NORMAL_BUTTON, 0, 42, N_("&Up"), LIST_HOTLIST|LIST_MOVELIST},
128 { B_ADD_CURRENT, NORMAL_BUTTON, 0, 20, N_("&Add current"), LIST_HOTLIST},
129 #ifdef USE_VFS
130 { B_REFRESH_VFS, NORMAL_BUTTON, 0, 43, N_("&Refresh"), LIST_VFSLIST},
131 { B_FREE_ALL_VFS, NORMAL_BUTTON, 0, 20, N_("Fr&ee VFSs now"), LIST_VFSLIST},
132 #endif
133 { B_ENTER, DEFPUSH_BUTTON, 0, 0, N_("Change &To"), LIST_HOTLIST|LIST_VFSLIST|LIST_MOVELIST},
136 /* Directory hotlist */
137 static struct hotlist{
138 enum HotListType type;
139 char *directory;
140 char *label;
141 struct hotlist *head;
142 struct hotlist *up;
143 struct hotlist *next;
144 } *hotlist = NULL;
146 static struct hotlist *current_group;
148 static void init_movelist (int, struct hotlist *);
149 static void add_new_group_cmd (void);
150 static void add_new_entry_cmd (void);
151 static void remove_from_hotlist (struct hotlist *entry);
152 static void load_hotlist (void);
153 static void add_dotdot_to_list (void);
155 #define new_hotlist() g_new0(struct hotlist, 1)
157 static void
158 hotlist_refresh (Dlg_head * dlg)
160 common_dialog_repaint (dlg);
161 attrset (COLOR_NORMAL);
162 draw_box (dlg, 2, 5, dlg->lines - (hotlist_state.moving ? 6 : 10),
163 dlg->cols - (UX * 2));
164 if (!hotlist_state.moving)
165 draw_box (dlg, dlg->lines - 8, 5, 3, dlg->cols - (UX * 2));
168 /* If current->data is 0, then we are dealing with a VFS pathname */
169 static inline void
170 update_path_name (void)
172 const char *text = "";
173 char *p;
174 WListbox *list = hotlist_state.moving ? l_movelist : l_hotlist;
175 Dlg_head *dlg = list->widget.parent;
177 if (list->current) {
178 if (list->current->data != 0) {
179 struct hotlist *hlp = (struct hotlist *) list->current->data;
181 if (hlp->type == HL_TYPE_ENTRY ||
182 hlp->type == HL_TYPE_DOTDOT)
183 text = hlp->directory;
184 else if (hlp->type == HL_TYPE_GROUP)
185 text = _("Subgroup - press ENTER to see list");
186 } else {
187 text = list->current->text;
190 if (!hotlist_state.moving)
191 label_set_text (pname,
192 name_trunc (text, dlg->cols - (UX * 2 + 4)));
194 p = g_strconcat (" ", current_group->label, " ", (char *) NULL);
195 if (!hotlist_state.moving)
196 label_set_text (pname_group,
197 name_trunc (p, dlg->cols - (UX * 2 + 4)));
198 else
199 label_set_text (movelist_group,
200 name_trunc (p, dlg->cols - (UX * 2 + 4)));
201 g_free (p);
203 dlg_redraw (dlg);
206 #define CHECK_BUFFER \
207 do { \
208 int i; \
210 if ((i = strlen (current->label) + 3) > buflen) { \
211 g_free (buf); \
212 buf = g_malloc (buflen = 1024 * (i/1024 + 1)); \
214 buf[0] = '\0'; \
215 } while (0)
217 static void fill_listbox (void)
219 struct hotlist *current = current_group->head;
220 static char *buf;
221 static int buflen;
223 if (!buf)
224 buf = g_malloc (buflen = 1024);
225 buf[0] = '\0';
227 while (current){
228 switch (current->type) {
229 case HL_TYPE_GROUP:
231 CHECK_BUFFER;
232 strcat (strcat (buf, "->"), current->label);
233 if (hotlist_state.moving)
234 listbox_add_item (l_movelist, 0, 0, buf, current);
235 else
236 listbox_add_item (l_hotlist, 0, 0, buf, current);
238 break;
239 case HL_TYPE_DOTDOT:
240 case HL_TYPE_ENTRY:
241 if (hotlist_state.moving)
242 listbox_add_item (l_movelist, 0, 0, current->label, current);
243 else
244 listbox_add_item (l_hotlist, 0, 0, current->label, current);
245 break;
246 default:
247 break;
249 current = current->next;
253 #undef CHECK_BUFFER
255 static void
256 unlink_entry (struct hotlist *entry)
258 struct hotlist *current = current_group->head;
260 if (current == entry)
261 current_group->head = entry->next;
262 else {
263 while (current && current->next != entry)
264 current = current->next;
265 if (current)
266 current->next = entry->next;
268 entry->next =
269 entry->up = 0;
272 #ifdef USE_VFS
273 static void add_name_to_list (const char *path)
275 listbox_add_item (l_hotlist, 0, 0, path, 0);
277 #endif /* !USE_VFS */
279 static int
280 hotlist_button_callback (int action)
282 switch (action) {
283 case B_MOVE:
285 struct hotlist *saved = current_group;
286 struct hotlist *item;
287 struct hotlist *moveto_item = 0;
288 struct hotlist *moveto_group = 0;
289 int ret;
291 if (!l_hotlist->current)
292 return MSG_NOT_HANDLED; /* empty group - nothing to do */
293 item = l_hotlist->current->data;
294 hotlist_state.moving = 1;
295 init_movelist (LIST_MOVELIST, item);
296 run_dlg (movelist_dlg);
297 ret = movelist_dlg->ret_value;
298 hotlist_state.moving = 0;
299 if (l_movelist->current)
300 moveto_item = l_movelist->current->data;
301 moveto_group = current_group;
302 destroy_dlg (movelist_dlg);
303 current_group = saved;
304 if (ret == B_CANCEL)
305 return MSG_NOT_HANDLED;
306 if (moveto_item == item)
307 return MSG_NOT_HANDLED; /* If we insert/append a before/after a
308 it hardly changes anything ;) */
309 unlink_entry (item);
310 listbox_remove_current (l_hotlist, 1);
311 item->up = moveto_group;
312 if (!moveto_group->head)
313 moveto_group->head = item;
314 else if (!moveto_item) { /* we have group with just comments */
315 struct hotlist *p = moveto_group->head;
317 /* skip comments */
318 while (p->next)
319 p = p->next;
320 p->next = item;
321 } else if (ret == B_ENTER || ret == B_APPEND)
322 if (!moveto_item->next)
323 moveto_item->next = item;
324 else {
325 item->next = moveto_item->next;
326 moveto_item->next = item;
327 } else if (moveto_group->head == moveto_item) {
328 moveto_group->head = item;
329 item->next = moveto_item;
330 } else {
331 struct hotlist *p = moveto_group->head;
333 while (p->next != moveto_item)
334 p = p->next;
335 item->next = p->next;
336 p->next = item;
338 listbox_remove_list (l_hotlist);
339 fill_listbox ();
340 repaint_screen ();
341 hotlist_state.modified = 1;
342 return MSG_NOT_HANDLED;
343 break;
345 case B_REMOVE:
346 if (l_hotlist->current && l_hotlist->current->data)
347 remove_from_hotlist (l_hotlist->current->data);
348 return MSG_NOT_HANDLED;
349 break;
351 case B_NEW_GROUP:
352 add_new_group_cmd ();
353 return MSG_NOT_HANDLED;
354 break;
356 case B_ADD_CURRENT:
357 add2hotlist_cmd ();
358 return MSG_NOT_HANDLED;
359 break;
361 case B_NEW_ENTRY:
362 add_new_entry_cmd ();
363 return MSG_NOT_HANDLED;
364 break;
366 case B_ENTER:
368 WListbox *list = hotlist_state.moving ? l_movelist : l_hotlist;
369 if (list->current) {
370 if (list->current->data) {
371 struct hotlist *hlp =
372 (struct hotlist *) list->current->data;
373 if (hlp->type == HL_TYPE_ENTRY)
374 return MSG_HANDLED;
375 else if (hlp->type == HL_TYPE_DOTDOT) {
376 /* Fall through - go up */
379 else {
380 listbox_remove_list (list);
381 current_group = hlp;
382 fill_listbox ();
383 return MSG_NOT_HANDLED;
385 } else
386 return MSG_HANDLED;
389 /* Fall through if list empty - just go up */
391 case B_UP_GROUP:
393 WListbox *list = hotlist_state.moving ? l_movelist : l_hotlist;
394 listbox_remove_list (list);
395 current_group = current_group->up;
396 fill_listbox ();
397 return MSG_NOT_HANDLED;
398 break;
401 #ifdef USE_VFS
402 case B_FREE_ALL_VFS:
403 vfs_expire (1);
404 /* fall through */
406 case B_REFRESH_VFS:
407 listbox_remove_list (l_hotlist);
408 listbox_add_item (l_hotlist, 0, 0, home_dir, 0);
409 vfs_fill_names (add_name_to_list);
410 return MSG_NOT_HANDLED;
411 #endif /* USE_VFS */
413 default:
414 return MSG_HANDLED;
415 break;
420 static cb_ret_t
421 hotlist_callback (Dlg_head *h, dlg_msg_t msg, int parm)
423 switch (msg) {
424 case DLG_DRAW:
425 hotlist_refresh (h);
426 return MSG_HANDLED;
428 case DLG_UNHANDLED_KEY:
429 switch (parm) {
430 case KEY_M_CTRL | '\n':
431 goto l1;
432 case '\n':
433 case KEY_ENTER:
434 case KEY_RIGHT:
435 if (hotlist_button_callback (B_ENTER)) {
436 h->ret_value = B_ENTER;
437 dlg_stop (h);
439 return MSG_HANDLED;
440 break;
441 case KEY_LEFT:
442 if (hotlist_state.type != LIST_VFSLIST)
443 return !hotlist_button_callback (B_UP_GROUP);
444 else
445 return MSG_NOT_HANDLED;
446 break;
447 case KEY_DC:
448 if (!hotlist_state.moving) {
449 hotlist_button_callback (B_REMOVE);
450 return MSG_HANDLED;
452 break;
454 case ALT ('\n'):
455 case ALT ('\r'):
456 if (!hotlist_state.moving) {
457 if (l_hotlist->current) {
458 if (l_hotlist->current->data) {
459 struct hotlist *hlp =
460 (struct hotlist *) l_hotlist->current->data;
461 if (hlp->type == HL_TYPE_ENTRY) {
462 char *tmp =
463 g_strconcat ("cd ", hlp->directory, (char *) NULL);
464 stuff (cmdline, tmp, 0);
465 g_free (tmp);
466 dlg_stop (h);
467 h->ret_value = B_CANCEL;
468 return MSG_HANDLED;
473 return MSG_HANDLED; /* ignore key */
475 return MSG_NOT_HANDLED;
477 case DLG_POST_KEY:
478 if (hotlist_state.moving)
479 dlg_select_widget (l_movelist);
480 else
481 dlg_select_widget (l_hotlist);
482 /* always stay on hotlist */
483 /* fall through */
485 case DLG_INIT:
486 attrset (MENU_ENTRY_COLOR);
487 update_path_name ();
488 return MSG_HANDLED;
490 default:
491 return default_dlg_callback (h, msg, parm);
495 static int l_call (WListbox *list)
497 Dlg_head *dlg = list->widget.parent;
499 if (list->current){
500 if (list->current->data) {
501 struct hotlist *hlp = (struct hotlist*) list->current->data;
502 if (hlp->type == HL_TYPE_ENTRY) {
503 dlg->ret_value = B_ENTER;
504 dlg_stop (dlg);
505 return LISTBOX_DONE;
506 } else {
507 hotlist_button_callback (B_ENTER);
508 hotlist_callback (dlg, DLG_POST_KEY, '\n');
509 return LISTBOX_CONT;
511 } else {
512 dlg->ret_value = B_ENTER;
513 dlg_stop (dlg);
514 return LISTBOX_DONE;
518 hotlist_button_callback (B_UP_GROUP);
519 hotlist_callback (dlg, DLG_POST_KEY, 'u');
520 return LISTBOX_CONT;
524 * Expands all button names (once) and recalculates button positions.
525 * returns number of columns in the dialog box, which is 10 chars longer
526 * then buttonbar.
528 * If common width of the window (i.e. in xterm) is less than returned
529 * width - sorry :) (anyway this did not handled in previous version too)
531 static int
532 init_i18n_stuff(int list_type, int cols)
534 register int i;
535 static const char* cancel_but = N_("&Cancel");
537 #ifdef ENABLE_NLS
538 static int hotlist_i18n_flag = 0;
540 if (!hotlist_i18n_flag)
542 i = sizeof (hotlist_but) / sizeof (hotlist_but [0]);
543 while (i--)
544 hotlist_but [i].text = _(hotlist_but [i].text);
546 cancel_but = _(cancel_but);
547 hotlist_i18n_flag = 1;
549 #endif /* ENABLE_NLS */
551 /* Dynamic resizing of buttonbars */
553 int len[2], count[2]; /* at most two lines of buttons */
554 int cur_x[2], row;
556 i = sizeof (hotlist_but) / sizeof (hotlist_but [0]);
557 len[0] = len[1] = count[0] = count[1] = 0;
559 /* Count len of buttonbars, assuming 2 extra space between buttons */
560 while (i--)
562 if (! (hotlist_but[i].type & list_type))
563 continue;
565 row = hotlist_but [i].y;
566 ++count [row];
567 len [row] += strlen (hotlist_but [i].text) + 5;
568 if (hotlist_but [i].flags == DEFPUSH_BUTTON)
569 len [row] += 2;
571 len[0] -= 2;
572 len[1] -= 2;
574 cols = max(cols, max(len[0], len[1]));
576 /* arrange buttons */
578 cur_x[0] = cur_x[1] = 0;
579 i = sizeof (hotlist_but) / sizeof (hotlist_but [0]);
580 while (i--)
582 if (! (hotlist_but[i].type & list_type))
583 continue;
585 row = hotlist_but [i].y;
587 if (hotlist_but [i].x != 0)
589 /* not first int the row */
590 if (!strcmp (hotlist_but [i].text, cancel_but))
591 hotlist_but [i].x =
592 cols - strlen (hotlist_but [i].text) - 13;
593 else
594 hotlist_but [i].x = cur_x [row];
597 cur_x [row] += strlen (hotlist_but [i].text) + 2
598 + (hotlist_but [i].flags == DEFPUSH_BUTTON ? 5 : 3);
602 return cols;
605 static void
606 init_hotlist (int list_type)
608 size_t i;
609 const char *title, *help_node;
610 int hotlist_cols;
612 hotlist_cols = init_i18n_stuff (list_type, COLS - 6);
614 do_refresh ();
616 hotlist_state.expanded =
617 GetPrivateProfileInt ("HotlistConfig", "expanded_view_of_groups",
618 0, profile_name);
620 if (list_type == LIST_VFSLIST) {
621 title = _("Active VFS directories");
622 help_node = "[vfshot]"; /* FIXME - no such node */
623 } else {
624 title = _("Directory hotlist");
625 help_node = "[Hotlist]";
628 hotlist_dlg =
629 create_dlg (0, 0, LINES - 2, hotlist_cols, dialog_colors,
630 hotlist_callback, help_node, title, DLG_CENTER | DLG_REVERSE);
632 for (i = 0; i < BUTTONS; i++) {
633 if (hotlist_but[i].type & list_type)
634 add_widget (hotlist_dlg,
635 button_new (BY + hotlist_but[i].y,
636 BX + hotlist_but[i].x,
637 hotlist_but[i].ret_cmd,
638 hotlist_but[i].flags,
639 hotlist_but[i].text,
640 hotlist_button_callback));
643 /* We add the labels.
644 * pname will hold entry's pathname;
645 * pname_group will hold name of current group
647 pname = label_new (UY - 11 + LINES, UX + 2, "");
648 add_widget (hotlist_dlg, pname);
649 if (!hotlist_state.moving) {
650 add_widget (hotlist_dlg,
651 label_new (UY - 12 + LINES, UX + 1,
652 _(" Directory path ")));
654 /* This one holds the displayed pathname */
655 pname_group = label_new (UY, UX + 1, _(" Directory label "));
656 add_widget (hotlist_dlg, pname_group);
658 /* get new listbox */
659 l_hotlist =
660 listbox_new (UY + 1, UX + 1, COLS - 2 * UX - 8, LINES - 14,
661 l_call);
663 /* Fill the hotlist with the active VFS or the hotlist */
664 #ifdef USE_VFS
665 if (list_type == LIST_VFSLIST) {
666 listbox_add_item (l_hotlist, 0, 0, home_dir, 0);
667 vfs_fill_names (add_name_to_list);
668 } else
669 #endif /* !USE_VFS */
670 fill_listbox ();
672 add_widget (hotlist_dlg, l_hotlist);
673 /* add listbox to the dialogs */
676 static void
677 init_movelist (int list_type, struct hotlist *item)
679 size_t i;
680 char *hdr = g_strdup_printf (_("Moving %s"), item->label);
681 int movelist_cols = init_i18n_stuff (list_type, COLS - 6);
683 do_refresh ();
685 movelist_dlg =
686 create_dlg (0, 0, LINES - 6, movelist_cols, dialog_colors,
687 hotlist_callback, "[Hotlist]", hdr, DLG_CENTER | DLG_REVERSE);
688 g_free (hdr);
690 for (i = 0; i < BUTTONS; i++) {
691 if (hotlist_but[i].type & list_type)
692 add_widget (movelist_dlg,
693 button_new (BY - 4 + hotlist_but[i].y,
694 BX + hotlist_but[i].x,
695 hotlist_but[i].ret_cmd,
696 hotlist_but[i].flags,
697 hotlist_but[i].text,
698 hotlist_button_callback));
701 /* We add the labels. We are interested in the last one,
702 * that one will hold the path name label
704 movelist_group = label_new (UY, UX + 1, _(" Directory label "));
705 add_widget (movelist_dlg, movelist_group);
706 /* get new listbox */
707 l_movelist =
708 listbox_new (UY + 1, UX + 1, movelist_dlg->cols - 2 * UX - 2,
709 movelist_dlg->lines - 8, l_call);
711 fill_listbox ();
713 add_widget (movelist_dlg, l_movelist);
714 /* add listbox to the dialogs */
718 * Destroy the list dialog.
719 * Don't confuse with done_hotlist() for the list in memory.
721 static void hotlist_done (void)
723 destroy_dlg (hotlist_dlg);
724 l_hotlist = NULL;
725 if (0)
726 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
727 repaint_screen ();
730 static inline char *
731 find_group_section (struct hotlist *grp)
733 return g_strconcat (grp->directory, ".Group", (char *) NULL);
737 /* 1.11.96 bor: added pos parameter to control placement of new item.
738 see widget.c, listbox_add_item()
739 now hotlist is in unsorted mode
741 enum {
742 HL_BEFORE_CURRENT = 1
743 ,HL_AFTER_CURRENT = 2
746 static struct hotlist *
747 add2hotlist (char *label, char *directory, enum HotListType type, int pos)
749 struct hotlist *new;
750 struct hotlist *current = NULL;
753 * Hotlist is neither loaded nor loading.
754 * Must be called by "Ctrl-x a" before using hotlist.
756 if (!current_group)
757 load_hotlist ();
759 if (l_hotlist && l_hotlist->current) {
760 current = l_hotlist->current->data;
762 /* Make sure `..' stays at the top of the list. */
763 if (current->type == HL_TYPE_DOTDOT)
764 pos = HL_AFTER_CURRENT;
767 new = new_hotlist ();
769 new->type = type;
770 new->label = label;
771 new->directory = directory;
772 new->up = current_group;
774 if (type == HL_TYPE_GROUP) {
775 current_group = new;
776 add_dotdot_to_list ();
777 current_group = new->up;
780 if (!current_group->head) { /* first element in group */
781 current_group->head = new;
782 } else if (pos == HL_AFTER_CURRENT) {
783 new->next = current->next;
784 current->next = new;
785 } else if (pos == HL_BEFORE_CURRENT &&
786 current == current_group->head) {
787 /* should be inserted before first item */
788 new->next = current;
789 current_group->head = new;
790 } else if (pos == HL_BEFORE_CURRENT) {
791 struct hotlist *p = current_group->head;
793 while (p->next != current)
794 p = p->next;
796 new->next = current;
797 p->next = new;
798 } else { /* append at the end */
799 struct hotlist *p = current_group->head;
801 while (p->next)
802 p = p->next;
804 p->next = new;
807 if (hotlist_state.running && type != HL_TYPE_COMMENT &&
808 type != HL_TYPE_DOTDOT) {
809 if (type == HL_TYPE_GROUP) {
810 char *lbl = g_strconcat ("->", new->label, (char *) NULL);
812 listbox_add_item (l_hotlist, pos, 0, lbl, new);
813 g_free (lbl);
814 } else
815 listbox_add_item (l_hotlist, pos, 0, new->label, new);
816 listbox_select_entry (l_hotlist, l_hotlist->current);
818 return new;
822 #ifdef ENABLE_NLS
824 * Support routine for add_new_entry_input()/add_new_group_input()
825 * Change positions of buttons (first three widgets).
827 * This is just a quick hack. Accurate procedure must take care of
828 * internationalized label lengths and total buttonbar length...assume
829 * 64 is longer anyway.
831 static void add_widgets_i18n(QuickWidget* qw, int len)
833 int i, l[3], space, cur_x;
835 for (i = 0; i < 3; i++)
837 qw [i].text = _(qw [i].text);
838 l[i] = strlen (qw [i].text) + 3;
840 space = (len - 4 - l[0] - l[1] - l[2]) / 4;
842 for (cur_x = 2 + space, i = 3; i--; cur_x += l[i] + space)
844 qw [i].relative_x = cur_x;
845 qw [i].x_divisions = len;
848 #endif /* ENABLE_NLS */
850 static int
851 add_new_entry_input (const char *header, const char *text1, const char *text2,
852 const char *help, char **r1, char **r2)
854 #define RELATIVE_Y_BUTTONS 4
855 #define RELATIVE_Y_LABEL_PTH 3
856 #define RELATIVE_Y_INPUT_PTH 4
858 QuickDialog Quick_input;
859 static QuickWidget quick_widgets [] = {
860 { quick_button, 55, 80, RELATIVE_Y_BUTTONS, 0, N_("&Cancel"), 0, B_CANCEL,
861 0, 0, NULL },
862 { quick_button, 30, 80, RELATIVE_Y_BUTTONS, 0, N_("&Insert"), 0, B_INSERT,
863 0, 0, NULL },
864 { quick_button, 10, 80, RELATIVE_Y_BUTTONS, 0, N_("&Append"), 0, B_APPEND,
865 0, 0, NULL },
866 { quick_input, 4, 80, RELATIVE_Y_INPUT_PTH, 0, "",58, 0,
867 0, 0, "input-pth" },
868 { quick_label, RELATIVE_Y_LABEL_PTH, 80, 3, 0, 0, 0, 0,
869 0, 0, NULL },
870 { quick_input, 4, 80, 3, 0, "", 58, 0,
871 0, 0, "input-lbl" },
872 { quick_label, 3, 80, 2, 0, 0, 0, 0,
873 0, 0, NULL },
874 NULL_QuickWidget };
876 int len;
877 int i;
878 int lines1, lines2;
879 int cols1, cols2;
881 #ifdef ENABLE_NLS
882 static int i18n_flag = 0;
883 #endif /* ENABLE_NLS */
885 msglen(text1, &lines1, &cols1);
886 msglen(text2, &lines2, &cols2);
887 len = max ((int) strlen (header), cols1);
888 len = max (len, cols2) + 4;
889 len = max (len, 64);
891 #ifdef ENABLE_NLS
892 if (!i18n_flag)
894 add_widgets_i18n(quick_widgets, len);
895 i18n_flag = 1;
897 #endif /* ENABLE_NLS */
899 Quick_input.xlen = len;
900 Quick_input.xpos = -1;
901 Quick_input.title = header;
902 Quick_input.help = help;
903 Quick_input.i18n = 0;
904 quick_widgets [6].text = text1;
905 quick_widgets [4].text = text2;
906 quick_widgets [5].text = *r1;
907 quick_widgets [3].text = *r2;
909 for (i = 0; i < 7; i++)
910 quick_widgets [i].y_divisions = lines1+lines2+7;
911 Quick_input.ylen = lines1 + lines2 + 7;
913 quick_widgets [0].relative_y = RELATIVE_Y_BUTTONS + (lines1 + lines2);
914 quick_widgets [1].relative_y = RELATIVE_Y_BUTTONS + (lines1 + lines2);
915 quick_widgets [2].relative_y = RELATIVE_Y_BUTTONS + (lines1 + lines2);
916 quick_widgets [3].relative_y = RELATIVE_Y_INPUT_PTH + (lines1);
917 quick_widgets [4].relative_y = RELATIVE_Y_LABEL_PTH + (lines1);
919 quick_widgets [5].str_result = r1;
920 quick_widgets [3].str_result = r2;
922 Quick_input.widgets = quick_widgets;
923 if ((i = quick_dialog (&Quick_input)) != B_CANCEL){
924 return i;
925 } else
926 return 0;
929 static void add_new_entry_cmd (void)
931 char *title, *url, *to_free;
932 int ret;
934 /* Take current directory as default value for input fields */
935 to_free = title = url = strip_password (g_strdup (current_panel->cwd), 1);
937 ret = add_new_entry_input (_("New hotlist entry"), _("Directory label"),
938 _("Directory path"), "[Hotlist]", &title, &url);
939 g_free (to_free);
941 if (!ret)
942 return;
943 if (!title || !*title || !url || !*url) {
944 g_free (title);
945 g_free (url);
946 return;
949 if (ret == B_ENTER || ret == B_APPEND)
950 add2hotlist (title, url, HL_TYPE_ENTRY, HL_AFTER_CURRENT);
951 else
952 add2hotlist (title, url, HL_TYPE_ENTRY, HL_BEFORE_CURRENT);
954 hotlist_state.modified = 1;
957 static int
958 add_new_group_input (const char *header, const char *label, char **result)
960 int ret;
961 QuickDialog Quick_input;
962 static QuickWidget quick_widgets [] = {
963 { quick_button, 55, 80, 1, 0, N_("&Cancel"), 0, B_CANCEL, 0, 0,
964 NULL },
965 { quick_button, 30, 80, 1, 0, N_("&Insert"), 0, B_INSERT, 0, 0,
966 NULL },
967 { quick_button, 10, 80, 1, 0, N_("&Append"), 0, B_APPEND, 0, 0,
968 NULL },
969 { quick_input, 4, 80, 0, 0, "", 58, 0, 0, 0, "input" },
970 { quick_label, 3, 80, 2, 0, 0, 0, 0, 0, 0, NULL },
971 NULL_QuickWidget };
972 int relative_y[] = {1, 1, 1, 0, 2}; /* the relative_x component from the
973 quick_widgets variable above */
974 int len;
975 int i;
976 int lines, cols;
978 #ifdef ENABLE_NLS
979 static int i18n_flag = 0;
980 #endif /* ENABLE_NLS */
982 msglen (label, &lines, &cols);
983 len = max ((int) strlen (header), cols) + 4;
984 len = max (len, 64);
986 #ifdef ENABLE_NLS
987 if (!i18n_flag)
989 add_widgets_i18n(quick_widgets, len);
990 i18n_flag = 1;
992 #endif /* ENABLE_NLS */
994 Quick_input.xlen = len;
995 Quick_input.xpos = -1;
996 Quick_input.title = header;
997 Quick_input.help = "[Hotlist]";
998 Quick_input.i18n = 0;
999 quick_widgets [4].text = label;
1001 for (i = 0; i < 5; i++)
1002 quick_widgets [i].y_divisions = lines+6;
1003 Quick_input.ylen = lines + 6;
1005 for (i = 0; i < 4; i++)
1006 quick_widgets [i].relative_y = relative_y[i] + 2 + lines;
1008 quick_widgets [3].str_result = result;
1009 quick_widgets [3].text = "";
1011 Quick_input.widgets = quick_widgets;
1012 if ((ret = quick_dialog (&Quick_input)) != B_CANCEL){
1013 return ret;
1014 } else
1015 return 0;
1018 static void add_new_group_cmd (void)
1020 char *label;
1021 int ret;
1023 ret = add_new_group_input (_(" New hotlist group "), _("Name of new group"), &label);
1024 if (!ret || !label || !*label)
1025 return;
1027 if (ret == B_ENTER || ret == B_APPEND)
1028 add2hotlist (label, 0, HL_TYPE_GROUP, HL_AFTER_CURRENT);
1029 else
1030 add2hotlist (label, 0, HL_TYPE_GROUP, HL_BEFORE_CURRENT);
1032 hotlist_state.modified = 1;
1035 void add2hotlist_cmd (void)
1037 char *prompt, *label;
1038 const char *cp = _("Label for \"%s\":");
1039 int l = strlen (cp);
1040 char *label_string = g_strdup (current_panel->cwd);
1042 strip_password (label_string, 1);
1044 prompt = g_strdup_printf (cp, path_trunc (current_panel->cwd, COLS-2*UX-(l+8)));
1045 label = input_dialog (_(" Add to hotlist "), prompt, MC_HISTORY_HOTLIST_ADD, label_string);
1046 g_free (prompt);
1048 if (!label || !*label) {
1049 g_free (label_string);
1050 g_free (label);
1051 return;
1053 add2hotlist (label, label_string, HL_TYPE_ENTRY, 0);
1054 hotlist_state.modified = 1;
1057 static void remove_group (struct hotlist *grp)
1059 struct hotlist *current = grp->head;
1061 while (current) {
1062 struct hotlist *next = current->next;
1064 if (current->type == HL_TYPE_GROUP)
1065 remove_group (current);
1067 g_free (current->label);
1068 g_free (current->directory);
1069 g_free (current);
1071 current = next;
1076 static void remove_from_hotlist (struct hotlist *entry)
1078 if (entry->type == HL_TYPE_DOTDOT)
1079 return;
1081 if (confirm_directory_hotlist_delete) {
1082 char *title;
1083 int result;
1085 title = g_strconcat (_(" Remove: "),
1086 name_trunc (entry->label, 30),
1087 " ",
1088 NULL);
1090 if (safe_delete)
1091 query_set_sel (1);
1092 result = query_dialog (title,
1093 _("\n Are you sure you want to remove this entry?"),
1094 D_ERROR, 2, _("&Yes"), _("&No"));
1096 g_free (title);
1098 if (result != 0)
1099 return;
1102 if (entry->type == HL_TYPE_GROUP) {
1103 if (entry->head) {
1104 char *header;
1105 int result;
1107 header = g_strconcat (_(" Remove: "),
1108 name_trunc (entry->label, 30),
1109 " ",
1110 NULL);
1111 result = query_dialog (header, _("\n Group not empty.\n Remove it?"),
1112 D_ERROR, 2,
1113 _("&Yes"), _("&No"));
1114 g_free (header);
1116 if (result != 0)
1117 return;
1120 remove_group (entry);
1123 unlink_entry (entry);
1125 g_free (entry->label);
1126 g_free (entry->directory);
1127 g_free (entry);
1128 /* now remove list entry from screen */
1129 listbox_remove_current (l_hotlist, 1);
1130 hotlist_state.modified = 1;
1133 char *hotlist_cmd (int vfs_or_hotlist)
1135 char *target = NULL;
1137 hotlist_state.type = vfs_or_hotlist;
1138 load_hotlist ();
1140 init_hotlist (vfs_or_hotlist);
1142 /* display file info */
1143 attrset (SELECTED_COLOR);
1145 hotlist_state.running = 1;
1146 run_dlg (hotlist_dlg);
1147 hotlist_state.running = 0;
1148 save_hotlist ();
1150 switch (hotlist_dlg->ret_value) {
1151 case B_CANCEL:
1152 break;
1154 case B_ENTER:
1155 if (l_hotlist->current->data) {
1156 struct hotlist *hlp = (struct hotlist*) l_hotlist->current->data;
1157 target = g_strdup (hlp->directory);
1158 } else
1159 target = g_strdup (l_hotlist->current->text);
1160 break;
1163 hotlist_done ();
1164 return target;
1167 static void
1168 load_group (struct hotlist *grp)
1170 void *profile_keys;
1171 char *key, *value;
1172 char *group_section;
1173 struct hotlist *current = 0;
1175 group_section = find_group_section (grp);
1177 profile_keys = profile_init_iterator (group_section, profile_name);
1179 current_group = grp;
1181 while (profile_keys){
1182 profile_keys = profile_iterator_next (profile_keys, &key, &value);
1183 add2hotlist (g_strdup (value), g_strdup (key), HL_TYPE_GROUP, 0);
1185 g_free (group_section);
1187 profile_keys = profile_init_iterator (grp->directory, profile_name);
1189 while (profile_keys){
1190 profile_keys = profile_iterator_next (profile_keys, &key, &value);
1191 add2hotlist (g_strdup (value),g_strdup (key), HL_TYPE_ENTRY, 0);
1194 for (current = grp->head; current; current = current->next)
1195 load_group (current);
1198 #define TKN_GROUP 0
1199 #define TKN_ENTRY 1
1200 #define TKN_STRING 2
1201 #define TKN_URL 3
1202 #define TKN_ENDGROUP 4
1203 #define TKN_COMMENT 5
1204 #define TKN_EOL 125
1205 #define TKN_EOF 126
1206 #define TKN_UNKNOWN 127
1208 static char *tkn_buf;
1209 static int tkn_buf_length;
1210 static int tkn_length;
1212 static char *hotlist_file_name;
1213 static FILE *hotlist_file;
1214 static time_t hotlist_file_mtime;
1216 static int hot_skip_blanks (void)
1218 int c;
1220 while ((c = getc (hotlist_file)) != EOF && c != '\n' && isspace (c))
1222 return c;
1226 static int hot_next_token (void)
1228 int c;
1230 #define CHECK_BUF() \
1231 do { \
1232 if (tkn_length == tkn_buf_length) \
1233 tkn_buf = tkn_buf ? ( g_realloc (tkn_buf, tkn_buf_length += 1024)) \
1234 : ( g_malloc (tkn_buf_length = 1024)); \
1235 } while (0)
1237 tkn_length = 0;
1239 again:
1240 c = hot_skip_blanks ();
1241 switch (c) {
1242 case EOF:
1243 return TKN_EOF;
1244 break;
1245 case '\n':
1246 return TKN_EOL;
1247 break;
1248 case '#':
1249 while ((c = getc (hotlist_file)) != EOF && c != '\n') {
1250 if (c == EOF)
1251 return TKN_EOF;
1252 if (c != '\n') {
1253 CHECK_BUF();
1254 tkn_buf[tkn_length++] = c == '\n' ? ' ' : c;
1257 CHECK_BUF();
1258 tkn_buf[tkn_length] = '\0';
1259 return TKN_COMMENT;
1260 break;
1261 case '"':
1262 while ((c = getc (hotlist_file)) != EOF && c != '"') {
1263 if (c == '\\')
1264 if ((c = getc (hotlist_file)) == EOF)
1265 return TKN_EOF;
1266 CHECK_BUF();
1267 tkn_buf[tkn_length++] = c == '\n' ? ' ' : c;
1269 if (c == EOF)
1270 return TKN_EOF;
1271 CHECK_BUF();
1272 tkn_buf[tkn_length] = '\0';
1273 return TKN_STRING;
1274 break;
1275 case '\\':
1276 if ((c = getc (hotlist_file)) == EOF)
1277 return TKN_EOF;
1278 if (c == '\n')
1279 goto again;
1281 /* fall through; it is taken as normal character */
1283 default:
1284 do {
1285 CHECK_BUF();
1286 tkn_buf[tkn_length++] = toupper(c);
1287 } while ((c = fgetc (hotlist_file)) != EOF && isalnum (c));
1288 if (c != EOF)
1289 ungetc (c, hotlist_file);
1290 CHECK_BUF();
1291 tkn_buf[tkn_length] = '\0';
1292 if (strncmp (tkn_buf, "GROUP", tkn_length) == 0)
1293 return TKN_GROUP;
1294 else if (strncmp (tkn_buf, "ENTRY", tkn_length) == 0)
1295 return TKN_ENTRY;
1296 else if (strncmp (tkn_buf, "ENDGROUP", tkn_length) == 0)
1297 return TKN_ENDGROUP;
1298 else if (strncmp (tkn_buf, "URL", tkn_length) == 0)
1299 return TKN_URL;
1300 else
1301 return TKN_UNKNOWN;
1302 break;
1306 #define SKIP_TO_EOL { \
1307 int _tkn; \
1308 while ((_tkn = hot_next_token ()) != TKN_EOF && _tkn != TKN_EOL) ; \
1311 #define CHECK_TOKEN(_TKN_) \
1312 if ((tkn = hot_next_token ()) != _TKN_) { \
1313 hotlist_state.readonly = 1; \
1314 hotlist_state.file_error = 1; \
1315 while (tkn != TKN_EOL && tkn != TKN_EOF) \
1316 tkn = hot_next_token (); \
1317 break; \
1320 static void
1321 hot_load_group (struct hotlist * grp)
1323 int tkn;
1324 struct hotlist *new_grp;
1325 char *label, *url;
1327 current_group = grp;
1329 while ((tkn = hot_next_token()) != TKN_ENDGROUP)
1330 switch (tkn) {
1331 case TKN_GROUP:
1332 CHECK_TOKEN(TKN_STRING);
1333 new_grp = add2hotlist (g_strdup (tkn_buf), 0, HL_TYPE_GROUP, 0);
1334 SKIP_TO_EOL;
1335 hot_load_group (new_grp);
1336 current_group = grp;
1337 break;
1338 case TKN_ENTRY:
1339 CHECK_TOKEN(TKN_STRING);
1340 label = g_strdup (tkn_buf);
1341 CHECK_TOKEN(TKN_URL);
1342 CHECK_TOKEN(TKN_STRING);
1343 url = g_strdup (tkn_buf);
1344 add2hotlist (label, url, HL_TYPE_ENTRY, 0);
1345 SKIP_TO_EOL;
1346 break;
1347 case TKN_COMMENT:
1348 label = g_strdup (tkn_buf);
1349 add2hotlist (label, 0, HL_TYPE_COMMENT, 0);
1350 break;
1351 case TKN_EOF:
1352 hotlist_state.readonly = 1;
1353 hotlist_state.file_error = 1;
1354 return;
1355 break;
1356 case TKN_EOL:
1357 /* skip empty lines */
1358 break;
1359 default:
1360 hotlist_state.readonly = 1;
1361 hotlist_state.file_error = 1;
1362 SKIP_TO_EOL;
1363 break;
1365 SKIP_TO_EOL;
1368 static void
1369 hot_load_file (struct hotlist * grp)
1371 int tkn;
1372 struct hotlist *new_grp;
1373 char *label, *url;
1375 current_group = grp;
1377 while ((tkn = hot_next_token())!= TKN_EOF)
1378 switch (tkn) {
1379 case TKN_GROUP:
1380 CHECK_TOKEN(TKN_STRING);
1381 new_grp = add2hotlist (g_strdup (tkn_buf), 0, HL_TYPE_GROUP, 0);
1382 SKIP_TO_EOL;
1383 hot_load_group (new_grp);
1384 current_group = grp;
1385 break;
1386 case TKN_ENTRY:
1387 CHECK_TOKEN(TKN_STRING);
1388 label = g_strdup (tkn_buf);
1389 CHECK_TOKEN(TKN_URL);
1390 CHECK_TOKEN(TKN_STRING);
1391 url = g_strdup (tkn_buf);
1392 add2hotlist (label, url, HL_TYPE_ENTRY, 0);
1393 SKIP_TO_EOL;
1394 break;
1395 case TKN_COMMENT:
1396 label = g_strdup (tkn_buf);
1397 add2hotlist (label, 0, HL_TYPE_COMMENT, 0);
1398 break;
1399 case TKN_EOL:
1400 /* skip empty lines */
1401 break;
1402 default:
1403 hotlist_state.readonly = 1;
1404 hotlist_state.file_error = 1;
1405 SKIP_TO_EOL;
1406 break;
1410 static void
1411 clean_up_hotlist_groups (const char *section)
1413 char *grp_section;
1414 void *profile_keys;
1415 char *key, *value;
1417 grp_section = g_strconcat (section, ".Group", (char *) NULL);
1418 if (profile_has_section (section, profile_name))
1419 profile_clean_section (section, profile_name);
1420 if (profile_has_section (grp_section, profile_name)) {
1421 profile_keys = profile_init_iterator (grp_section, profile_name);
1423 while (profile_keys) {
1424 profile_keys = profile_iterator_next (profile_keys, &key, &value);
1425 clean_up_hotlist_groups (key);
1427 profile_clean_section (grp_section, profile_name);
1429 g_free (grp_section);
1434 static void
1435 load_hotlist (void)
1437 int remove_old_list = 0;
1438 struct stat stat_buf;
1440 if (hotlist_state.loaded) {
1441 stat (hotlist_file_name, &stat_buf);
1442 if (hotlist_file_mtime < stat_buf.st_mtime)
1443 done_hotlist ();
1444 else
1445 return;
1448 if (!hotlist_file_name)
1449 hotlist_file_name = concat_dir_and_file (home_dir, HOTLIST_FILENAME);
1451 hotlist = new_hotlist ();
1452 hotlist->type = HL_TYPE_GROUP;
1453 hotlist->label = g_strdup (_(" Top level group "));
1454 hotlist->up = hotlist;
1456 * compatibility :-(
1458 hotlist->directory = g_strdup ("Hotlist");
1460 if ((hotlist_file = fopen (hotlist_file_name, "r")) == 0) {
1461 int result;
1463 load_group (hotlist);
1464 hotlist_state.loaded = 1;
1466 * just to be sure we got copy
1468 hotlist_state.modified = 1;
1469 result = save_hotlist ();
1470 hotlist_state.modified = 0;
1471 if (result) {
1472 remove_old_list = 1;
1473 } else {
1474 message (D_ERROR, _(" Hotlist Load "),
1475 _("MC was unable to write ~/%s file, your old hotlist entries were not deleted"),
1476 HOTLIST_FILENAME);
1478 } else {
1479 hot_load_file (hotlist);
1480 fclose (hotlist_file);
1481 hotlist_state.loaded = 1;
1484 if (remove_old_list) {
1485 clean_up_hotlist_groups ("Hotlist");
1486 sync_profiles ();
1489 stat (hotlist_file_name, &stat_buf);
1490 hotlist_file_mtime = stat_buf.st_mtime;
1491 current_group = hotlist;
1495 static int list_level = 0;
1497 static void
1498 hot_save_group (struct hotlist *grp)
1500 struct hotlist *current = grp->head;
1501 int i;
1502 char *s;
1504 #define INDENT(n) \
1505 do { \
1506 for (i = 0; i < n; i++) \
1507 putc (' ', hotlist_file); \
1508 } while (0)
1510 for (;current; current = current->next)
1511 switch (current->type) {
1512 case HL_TYPE_GROUP:
1513 INDENT (list_level);
1514 fputs ("GROUP \"", hotlist_file);
1515 for (s = current->label; *s; s++) {
1516 if (*s == '"' || *s == '\\')
1517 putc ('\\', hotlist_file);
1518 putc (*s, hotlist_file);
1520 fputs ("\"\n", hotlist_file);
1521 list_level += 2;
1522 hot_save_group (current);
1523 list_level -= 2;
1524 INDENT (list_level);
1525 fputs ("ENDGROUP\n", hotlist_file);
1526 break;
1527 case HL_TYPE_ENTRY:
1528 INDENT(list_level);
1529 fputs ("ENTRY \"", hotlist_file);
1530 for (s = current->label; *s; s++) {
1531 if (*s == '"' || *s == '\\')
1532 putc ('\\', hotlist_file);
1533 putc (*s, hotlist_file);
1535 fputs ("\" URL \"", hotlist_file);
1536 for (s = current->directory; *s; s++) {
1537 if (*s == '"' || *s == '\\')
1538 putc ('\\', hotlist_file);
1539 putc (*s, hotlist_file);
1541 fputs ("\"\n", hotlist_file);
1542 break;
1543 case HL_TYPE_COMMENT:
1544 fprintf (hotlist_file, "#%s\n", current->label);
1545 break;
1546 case HL_TYPE_DOTDOT:
1547 /* do nothing */
1548 break;
1552 int save_hotlist (void)
1554 int saved = 0;
1555 struct stat stat_buf;
1557 if (!hotlist_state.readonly && hotlist_state.modified && hotlist_file_name) {
1558 char *fbak = g_strconcat (hotlist_file_name, ".bak", (char *) NULL);
1560 rename (hotlist_file_name, fbak);
1561 if ((hotlist_file = fopen (hotlist_file_name, "w")) != 0) {
1562 if (stat (fbak, &stat_buf) == 0)
1563 chmod (hotlist_file_name, stat_buf.st_mode);
1564 else
1565 chmod (hotlist_file_name, S_IRUSR | S_IWUSR);
1566 hot_save_group (hotlist);
1567 fclose (hotlist_file);
1568 stat (hotlist_file_name, &stat_buf);
1569 hotlist_file_mtime = stat_buf.st_mtime;
1570 saved = 1;
1571 hotlist_state.modified = 0;
1572 } else
1573 rename (fbak, hotlist_file_name);
1574 g_free (fbak);
1577 return saved;
1581 * Unload list from memory.
1582 * Don't confuse with hotlist_done() for GUI.
1584 void done_hotlist (void)
1586 if (hotlist){
1587 remove_group (hotlist);
1588 g_free (hotlist->label);
1589 g_free (hotlist->directory);
1590 g_free (hotlist);
1591 hotlist = 0;
1594 hotlist_state.loaded = 0;
1596 g_free (hotlist_file_name);
1597 hotlist_file_name = 0;
1598 l_hotlist = 0;
1599 current_group = 0;
1600 if (tkn_buf){
1601 g_free (tkn_buf);
1602 tkn_buf_length = 0;
1603 tkn_length = 0;
1604 tkn_buf = NULL;
1608 static void
1609 add_dotdot_to_list (void)
1611 if (current_group != hotlist) {
1612 if (hotlist_has_dot_dot != 0)
1613 add2hotlist (g_strdup (".."), g_strdup (".."), HL_TYPE_DOTDOT, 0);