annotate src/history_list.c @ 1805:fccac8fde6c0

Little macro correction
author mow
date Sat, 27 Feb 2010 20:35:09 +0000
parents 956aab097ea7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
902
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
1 /*
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
2 * Geeqie
1802
956aab097ea7 added 2010 to copyright text
nadvornik
parents: 1431
diff changeset
3 * Copyright (C) 2008 - 2010 The Geeqie Team
902
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
4 *
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
5 * Authors: John Ellis, Vladimir Nadvornik, Laurent Monin
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
6 *
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
7 *
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
8 * This software is released under the GNU General Public License (GNU GPL).
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
9 * Please read the included file COPYING for more information.
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
10 * This software comes with no warranty of any kind, use at your own risk!
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
11 */
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
12
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
13 #include "main.h"
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
14 #include "history_list.h"
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
15
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
16 #include "secure_save.h"
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
17 #include "ui_fileops.h"
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
18
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
19 /*
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
20 *-----------------------------------------------------------------------------
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
21 * history lists
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
22 *-----------------------------------------------------------------------------
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
23 */
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
24
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
25 #define HISTORY_DEFAULT_KEY_COUNT 16
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
26
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
27
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
28 typedef struct _HistoryData HistoryData;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
29 struct _HistoryData
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
30 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
31 gchar *key;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
32 GList *list;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
33 };
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
34
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
35 static GList *history_list = NULL;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
36
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
37
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
38 static gchar *quoted_from_text(const gchar *text)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
39 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
40 const gchar *ptr;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
41 gint c = 0;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
42 gint l = strlen(text);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
43
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
44 if (l == 0) return NULL;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
45
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
46 while (c < l && text[c] !='"') c++;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
47 if (text[c] == '"')
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
48 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
49 gint e;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
50 c++;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
51 ptr = text + c;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
52 e = c;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
53 while (e < l && text[e] !='"') e++;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
54 if (text[e] == '"')
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
55 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
56 if (e - c > 0)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
57 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
58 return g_strndup(ptr, e - c);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
59 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
60 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
61 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
62 return NULL;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
63 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
64
1431
7e180091e0b7 More gboolean and tidy up.
zas_
parents: 1284
diff changeset
65 gboolean history_list_load(const gchar *path)
902
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
66 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
67 FILE *f;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
68 gchar *key = NULL;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
69 gchar s_buf[1024];
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
70 gchar *pathl;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
71
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
72 pathl = path_from_utf8(path);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
73 f = fopen(pathl, "r");
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
74 g_free(pathl);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
75 if (!f) return FALSE;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
76
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
77 /* first line must start with History comment */
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
78 if (!fgets(s_buf, sizeof(s_buf), f) ||
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
79 strncmp(s_buf, "#History", 8) != 0)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
80 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
81 fclose(f);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
82 return FALSE;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
83 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
84
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
85 while (fgets(s_buf, sizeof(s_buf), f))
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
86 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
87 if (s_buf[0]=='#') continue;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
88 if (s_buf[0]=='[')
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
89 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
90 gint c;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
91 gchar *ptr;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
92
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
93 ptr = s_buf + 1;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
94 c = 0;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
95 while (ptr[c] != ']' && ptr[c] != '\n' && ptr[c] != '\0') c++;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
96
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
97 g_free(key);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
98 key = g_strndup(ptr, c);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
99 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
100 else
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
101 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
102 gchar *value;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
103
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
104 value = quoted_from_text(s_buf);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
105 if (value && key)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
106 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
107 history_list_add_to_key(key, value, 0);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
108 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
109 g_free(value);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
110 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
111 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
112
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
113 fclose(f);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
114
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
115 g_free(key);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
116
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
117 return TRUE;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
118 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
119
1431
7e180091e0b7 More gboolean and tidy up.
zas_
parents: 1284
diff changeset
120 gboolean history_list_save(const gchar *path)
902
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
121 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
122 SecureSaveInfo *ssi;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
123 GList *list;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
124 gchar *pathl;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
125
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
126 pathl = path_from_utf8(path);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
127 ssi = secure_open(pathl);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
128 g_free(pathl);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
129 if (!ssi)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
130 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
131 log_printf(_("Unable to write history lists to: %s\n"), path);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
132 return FALSE;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
133 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
134
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
135 secure_fprintf(ssi, "#History lists\n\n");
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
136
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
137 list = g_list_last(history_list);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
138 while (list && secsave_errno == SS_ERR_NONE)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
139 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
140 HistoryData *hd;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
141 GList *work;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
142
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
143 hd = list->data;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
144 list = list->prev;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
145
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
146 secure_fprintf(ssi, "[%s]\n", hd->key);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
147
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
148 /* save them inverted (oldest to newest)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
149 * so that when reading they are added correctly
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
150 */
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
151 work = g_list_last(hd->list);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
152 while (work && secsave_errno == SS_ERR_NONE)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
153 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
154 secure_fprintf(ssi, "\"%s\"\n", (gchar *)work->data);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
155 work = work->prev;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
156 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
157 secure_fputc(ssi, '\n');
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
158 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
159
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
160 secure_fprintf(ssi, "#end\n");
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
161
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
162 return (secure_close(ssi) == 0);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
163 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
164
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
165 static void history_list_free(HistoryData *hd)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
166 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
167 GList *work;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
168
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
169 if (!hd) return;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
170
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
171 work = hd->list;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
172 while (work)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
173 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
174 g_free(work->data);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
175 work = work->next;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
176 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
177
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
178 g_free(hd->key);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
179 g_free(hd);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
180 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
181
1000
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 902
diff changeset
182 static HistoryData *history_list_find_by_key(const gchar *key)
902
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
183 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
184 GList *work = history_list;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
185
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
186 if (!key) return NULL;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
187
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
188 while (work)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
189 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
190 HistoryData *hd = work->data;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
191 if (strcmp(hd->key, key) == 0) return hd;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
192 work = work->next;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
193 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
194 return NULL;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
195 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
196
1000
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 902
diff changeset
197 const gchar *history_list_find_last_path_by_key(const gchar *key)
902
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
198 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
199 HistoryData *hd;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
200
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
201 hd = history_list_find_by_key(key);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
202 if (!hd || !hd->list) return NULL;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
203
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
204 return hd->list->data;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
205 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
206
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
207 void history_list_free_key(const gchar *key)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
208 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
209 HistoryData *hd;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
210 hd = history_list_find_by_key(key);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
211 if (!hd) return;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
212
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
213 history_list = g_list_remove(history_list, hd);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
214 history_list_free(hd);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
215 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
216
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
217 void history_list_add_to_key(const gchar *key, const gchar *path, gint max)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
218 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
219 HistoryData *hd;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
220 GList *work;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
221
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
222 if (!key || !path) return;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
223
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
224 hd = history_list_find_by_key(key);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
225 if (!hd)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
226 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
227 hd = g_new(HistoryData, 1);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
228 hd->key = g_strdup(key);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
229 hd->list = NULL;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
230 history_list = g_list_prepend(history_list, hd);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
231 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
232
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
233 /* if already in the list, simply move it to the top */
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
234 work = hd->list;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
235 while (work)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
236 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
237 gchar *buf = work->data;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
238
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
239 if (strcmp(buf, path) == 0)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
240 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
241 /* if not first, move it */
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
242 if (work != hd->list)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
243 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
244 hd->list = g_list_remove(hd->list, buf);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
245 hd->list = g_list_prepend(hd->list, buf);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
246 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
247 return;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
248 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
249 work = work->next;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
250 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
251
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
252 hd->list = g_list_prepend(hd->list, g_strdup(path));
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
253
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
254 if (max == -1) max = HISTORY_DEFAULT_KEY_COUNT;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
255 if (max > 0)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
256 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
257 gint len = 0;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
258 GList *work = hd->list;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
259 GList *last = NULL;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
260
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
261 while (work)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
262 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
263 len++;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
264 last = work;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
265 work = work->next;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
266 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
267
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
268 work = last;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
269 while (work && len > max)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
270 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
271 GList *node = work;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
272 work = work->prev;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
273
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
274 g_free(node->data);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
275 hd->list = g_list_delete_link(hd->list, node);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
276 len--;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
277 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
278 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
279 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
280
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
281 void history_list_item_change(const gchar *key, const gchar *oldpath, const gchar *newpath)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
282 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
283 HistoryData *hd;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
284 GList *work;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
285
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
286 if (!oldpath) return;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
287 hd = history_list_find_by_key(key);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
288 if (!hd) return;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
289
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
290 work = hd->list;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
291 while (work)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
292 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
293 gchar *buf = work->data;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
294 if (strcmp(buf, oldpath) == 0)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
295 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
296 if (newpath)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
297 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
298 work->data = g_strdup(newpath);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
299 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
300 else
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
301 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
302 hd->list = g_list_remove(hd->list, buf);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
303 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
304 g_free(buf);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
305 return;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
306 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
307 work = work->next;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
308 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
309 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
310
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
311 void history_list_item_move(const gchar *key, const gchar *path, gint direction)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
312 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
313 HistoryData *hd;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
314 GList *work;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
315 gint p = 0;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
316
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
317 if (!path) return;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
318 hd = history_list_find_by_key(key);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
319 if (!hd) return;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
320
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
321 work = hd->list;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
322 while (work)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
323 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
324 gchar *buf = work->data;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
325 if (strcmp(buf, path) == 0)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
326 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
327 p += direction;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
328 if (p < 0) return;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
329 hd->list = g_list_remove(hd->list, buf);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
330 hd->list = g_list_insert(hd->list, buf, p);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
331 return;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
332 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
333 work = work->next;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
334 p++;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
335 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
336 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
337
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
338 void history_list_item_remove(const gchar *key, const gchar *path)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
339 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
340 history_list_item_change(key, path, NULL);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
341 }
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
342
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
343 GList *history_list_get_by_key(const gchar *key)
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
344 {
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
345 HistoryData *hd;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
346
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
347 hd = history_list_find_by_key(key);
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
348 if (!hd) return NULL;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
349
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
350 return hd->list;
c414002a1f27 Move history_list_*() functions to separate files:
zas_
parents:
diff changeset
351 }
1055
1646720364cf Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents: 1000
diff changeset
352 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */