Mercurial > geeqie
annotate src/cache_maint.c @ 779:8b21337bc47b
filelist_read_real(): optimize and clean up.
author | zas_ |
---|---|
date | Tue, 03 Jun 2008 09:41:00 +0000 |
parents | df6c11709106 |
children | 44128da39e13 |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
69
31759d770628
Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
3 * (C) 2006 John Ellis |
475 | 4 * Copyright (C) 2008 The Geeqie Team |
9 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
281 | 13 #include "main.h" |
9 | 14 #include "cache_maint.h" |
15 | |
16 #include "cache.h" | |
586 | 17 #include "filedata.h" |
9 | 18 #include "thumb.h" |
19 #include "thumb_standard.h" | |
20 #include "ui_fileops.h" | |
21 #include "ui_misc.h" | |
22 #include "ui_spinner.h" | |
23 #include "ui_tabcomp.h" | |
24 #include "ui_utildlg.h" | |
25 | |
26 | |
27 typedef struct _CMData CMData; | |
28 struct _CMData | |
29 { | |
30 GList *list; | |
31 GList *done_list; | |
32 gint idle_id; | |
33 GenericDialog *gd; | |
34 GtkWidget *entry; | |
35 GtkWidget *spinner; | |
36 GtkWidget *button_stop; | |
37 GtkWidget *button_close; | |
38 gint clear; | |
39 gint metadata; | |
40 }; | |
41 | |
42 #define PURGE_DIALOG_WIDTH 400 | |
43 | |
44 | |
45 /* | |
46 *------------------------------------------------------------------- | |
47 * cache maintenance | |
48 *------------------------------------------------------------------- | |
49 */ | |
50 | |
735
df6c11709106
Comment out unused static function extension_truncate().
zas_
parents:
734
diff
changeset
|
51 #if 0 |
9 | 52 static gint extension_truncate(gchar *path, const gchar *ext) |
53 { | |
54 gint l; | |
55 gint el; | |
56 | |
57 if (!path || !ext) return FALSE; | |
58 | |
59 l = strlen(path); | |
60 el = strlen(ext); | |
61 | |
62 if (l < el || strcmp(path + (l - el), ext) != 0) return FALSE; | |
63 | |
64 path[l - el] = '\0'; | |
65 | |
66 return TRUE; | |
67 } | |
735
df6c11709106
Comment out unused static function extension_truncate().
zas_
parents:
734
diff
changeset
|
68 #endif |
9 | 69 |
70 static gchar *extension_find_dot(gchar *path) | |
71 { | |
533 | 72 gchar *dot = NULL; |
9 | 73 |
533 | 74 if (!path) return NULL; |
9 | 75 |
533 | 76 while (*path != '\0') |
77 { | |
78 if (*path == '.') dot = path; | |
79 path++; | |
80 } | |
9 | 81 |
533 | 82 return dot; |
9 | 83 } |
84 | |
85 static gint isempty(const gchar *path) | |
86 { | |
87 DIR *dp; | |
88 struct dirent *dir; | |
89 gchar *pathl; | |
90 | |
91 pathl = path_from_utf8(path); | |
92 dp = opendir(pathl); | |
93 g_free(pathl); | |
94 if (!dp) return FALSE; | |
95 | |
96 while ((dir = readdir(dp)) != NULL) | |
97 { | |
98 gchar *name = dir->d_name; | |
99 | |
69
31759d770628
Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
100 if (!(name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) ) |
9 | 101 { |
102 closedir(dp); | |
103 return FALSE; | |
104 } | |
105 } | |
106 | |
107 closedir(dp); | |
108 return TRUE; | |
109 } | |
110 | |
111 static void cache_maintain_home_close(CMData *cm) | |
112 { | |
113 if (cm->idle_id != -1) g_source_remove(cm->idle_id); | |
114 if (cm->gd) generic_dialog_close(cm->gd); | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
115 filelist_free(cm->list); |
9 | 116 g_list_free(cm->done_list); |
117 g_free(cm); | |
118 } | |
119 | |
120 static void cache_maintain_home_stop(CMData *cm) | |
121 { | |
122 if (cm->idle_id != -1) | |
123 { | |
124 g_source_remove(cm->idle_id); | |
125 cm->idle_id = -1; | |
126 } | |
127 | |
128 gtk_entry_set_text(GTK_ENTRY(cm->entry), _("done")); | |
129 spinner_set_interval(cm->spinner, -1); | |
130 | |
131 gtk_widget_set_sensitive(cm->button_stop, FALSE); | |
132 gtk_widget_set_sensitive(cm->button_close, TRUE); | |
133 } | |
134 | |
135 static gint cache_maintain_home_cb(gpointer data) | |
136 { | |
137 CMData *cm = data; | |
138 GList *dlist = NULL; | |
139 GList *list = NULL; | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
140 FileData *fd; |
734
e6ebae313d46
Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents:
710
diff
changeset
|
141 gboolean just_done = FALSE; |
e6ebae313d46
Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents:
710
diff
changeset
|
142 gboolean still_have_a_file = TRUE; |
e6ebae313d46
Fix up some types, make some signed vs unsigned warnings quiet.
zas_
parents:
710
diff
changeset
|
143 gsize base_length; |
9 | 144 const gchar *cache_folder; |
709
f4fc939d327b
Build path using g_build_filename() then calculate its length.
zas_
parents:
707
diff
changeset
|
145 gchar *base; |
9 | 146 |
147 if (cm->metadata) | |
148 { | |
283 | 149 cache_folder = GQ_CACHE_RC_METADATA; |
9 | 150 } |
151 else | |
152 { | |
283 | 153 cache_folder = GQ_CACHE_RC_THUMB; |
9 | 154 } |
155 | |
709
f4fc939d327b
Build path using g_build_filename() then calculate its length.
zas_
parents:
707
diff
changeset
|
156 base = g_build_filename(homedir(), cache_folder, NULL); |
f4fc939d327b
Build path using g_build_filename() then calculate its length.
zas_
parents:
707
diff
changeset
|
157 base_length = strlen(base); |
f4fc939d327b
Build path using g_build_filename() then calculate its length.
zas_
parents:
707
diff
changeset
|
158 g_free(base); |
9 | 159 |
160 if (!cm->list) | |
161 { | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
162 DEBUG_1("purge chk done."); |
9 | 163 cm->idle_id = -1; |
164 cache_maintain_home_stop(cm); | |
165 return FALSE; | |
166 } | |
167 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
168 fd = cm->list->data; |
9 | 169 |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
170 DEBUG_1("purge chk (%d) \"%s\"", (cm->clear && !cm->metadata), fd->path); |
9 | 171 |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
172 if (g_list_find(cm->done_list, fd) == NULL) |
9 | 173 { |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
174 cm->done_list = g_list_prepend(cm->done_list, fd); |
9 | 175 |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
176 if (filelist_read(fd->path, &list, &dlist)) |
9 | 177 { |
178 GList *work; | |
179 | |
180 just_done = TRUE; | |
181 still_have_a_file = FALSE; | |
442 | 182 |
9 | 183 work = list; |
184 while (work) | |
185 { | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
186 FileData *fd_list = work->data; |
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
187 gchar *path_buf = strdup(fd_list->path); |
9 | 188 gchar *dot; |
442 | 189 |
9 | 190 dot = extension_find_dot(path_buf); |
442 | 191 |
9 | 192 if (dot) *dot = '\0'; |
193 if ((!cm->metadata && cm->clear) || | |
194 (strlen(path_buf) > base_length && !isfile(path_buf + base_length)) ) | |
195 { | |
196 if (dot) *dot = '.'; | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
197 if (!unlink_file(path_buf)) log_printf("failed to delete:%s\n", path_buf); |
9 | 198 } |
199 else | |
200 { | |
201 still_have_a_file = TRUE; | |
202 } | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
203 g_free(path_buf); |
9 | 204 work = work->next; |
205 } | |
206 } | |
207 } | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
208 filelist_free(list); |
9 | 209 |
210 cm->list = g_list_concat(dlist, cm->list); | |
211 | |
212 if (cm->list && g_list_find(cm->done_list, cm->list->data) != NULL) | |
213 { | |
214 /* check if the dir is empty */ | |
442 | 215 |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
216 if (cm->list->data == fd && just_done) |
9 | 217 { |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
218 if (!still_have_a_file && !dlist && cm->list->next && !rmdir_utf8(fd->path)) |
9 | 219 { |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
220 log_printf("Unable to delete dir: %s\n", fd->path); |
9 | 221 } |
222 } | |
223 else | |
224 { | |
225 /* must re-check for an empty dir */ | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
226 if (isempty(fd->path) && cm->list->next && !rmdir_utf8(fd->path)) |
9 | 227 { |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
228 log_printf("Unable to delete dir: %s\n", fd->path); |
9 | 229 } |
230 } | |
231 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
232 fd = cm->list->data; |
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
233 cm->done_list = g_list_remove(cm->done_list, fd); |
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
234 cm->list = g_list_remove(cm->list, fd); |
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
235 file_data_unref(fd); |
9 | 236 } |
237 | |
238 if (cm->list) | |
239 { | |
240 const gchar *buf; | |
241 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
242 fd = cm->list->data; |
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
243 if (strlen(fd->path) > base_length) |
9 | 244 { |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
245 buf = fd->path + base_length; |
9 | 246 } |
247 else | |
248 { | |
249 buf = "..."; | |
250 } | |
251 gtk_entry_set_text(GTK_ENTRY(cm->entry), buf); | |
252 } | |
253 | |
254 return TRUE; | |
255 } | |
256 | |
257 static void cache_maintain_home_close_cb(GenericDialog *gd, gpointer data) | |
258 { | |
259 CMData *cm = data; | |
260 | |
261 if (!GTK_WIDGET_SENSITIVE(cm->button_close)) return; | |
262 | |
263 cache_maintain_home_close(cm); | |
264 } | |
265 | |
266 static void cache_maintain_home_stop_cb(GenericDialog *gd, gpointer data) | |
267 { | |
268 CMData *cm = data; | |
269 | |
270 cache_maintain_home_stop(cm); | |
271 } | |
272 | |
273 /* sorry for complexity (cm->done_list), but need it to remove empty dirs */ | |
274 void cache_maintain_home(gint metadata, gint clear, GtkWidget *parent) | |
275 { | |
276 CMData *cm; | |
277 GList *dlist = NULL; | |
278 gchar *base; | |
279 const gchar *msg; | |
280 const gchar *cache_folder; | |
281 GtkWidget *hbox; | |
282 | |
283 if (metadata) | |
284 { | |
283 | 285 cache_folder = GQ_CACHE_RC_METADATA; |
9 | 286 } |
287 else | |
288 { | |
283 | 289 cache_folder = GQ_CACHE_RC_THUMB; |
9 | 290 } |
291 | |
707
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
292 base = g_build_filename(homedir(), cache_folder, NULL); |
9 | 293 |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
294 if (!filelist_read(base, NULL, &dlist)) |
9 | 295 { |
296 g_free(base); | |
297 return; | |
298 } | |
299 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
300 dlist = g_list_append(dlist, file_data_new_simple(base)); |
9 | 301 |
302 cm = g_new0(CMData, 1); | |
303 cm->list = dlist; | |
304 cm->done_list = NULL; | |
305 cm->clear = clear; | |
306 cm->metadata = metadata; | |
307 | |
308 if (metadata) | |
309 { | |
310 msg = _("Removing old metadata..."); | |
311 } | |
312 else if (clear) | |
313 { | |
314 msg = _("Clearing cached thumbnails..."); | |
315 } | |
316 else | |
317 { | |
318 msg = _("Removing old thumbnails..."); | |
319 } | |
320 | |
321 cm->gd = generic_dialog_new(_("Maintenance"), | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
229
diff
changeset
|
322 GQ_WMCLASS, "main_maintenance", |
9 | 323 parent, FALSE, |
324 NULL, cm); | |
325 cm->gd->cancel_cb = cache_maintain_home_close_cb; | |
326 cm->button_close = generic_dialog_add_button(cm->gd, GTK_STOCK_CLOSE, NULL, | |
327 cache_maintain_home_close_cb, FALSE); | |
328 gtk_widget_set_sensitive(cm->button_close, FALSE); | |
329 cm->button_stop = generic_dialog_add_button(cm->gd, GTK_STOCK_STOP, NULL, | |
330 cache_maintain_home_stop_cb, FALSE); | |
331 | |
332 generic_dialog_add_message(cm->gd, NULL, msg, NULL); | |
333 gtk_window_set_default_size(GTK_WINDOW(cm->gd->dialog), PURGE_DIALOG_WIDTH, -1); | |
334 | |
335 hbox = gtk_hbox_new(FALSE, 0); | |
336 gtk_box_pack_start(GTK_BOX(cm->gd->vbox), hbox, FALSE, FALSE, 5); | |
337 gtk_widget_show(hbox); | |
338 | |
339 cm->entry = gtk_entry_new(); | |
340 GTK_WIDGET_UNSET_FLAGS(cm->entry, GTK_CAN_FOCUS); | |
341 gtk_editable_set_editable(GTK_EDITABLE(cm->entry), FALSE); | |
342 gtk_box_pack_start(GTK_BOX(hbox), cm->entry, TRUE, TRUE, 0); | |
343 gtk_widget_show(cm->entry); | |
344 | |
345 cm->spinner = spinner_new(NULL, SPINNER_SPEED); | |
346 gtk_box_pack_start(GTK_BOX(hbox), cm->spinner, FALSE, FALSE, 0); | |
347 gtk_widget_show(cm->spinner); | |
442 | 348 |
9 | 349 gtk_widget_show(cm->gd->dialog); |
350 | |
351 cm->idle_id = g_idle_add(cache_maintain_home_cb, cm); | |
352 } | |
353 | |
710 | 354 #if 0 |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
355 /* This checks all files in ~/GQ_RC_DIR/thumbnails and |
9 | 356 * removes them if thay have no source counterpart. |
357 * (this assumes all cache files have an extension of 4 chars including '.') | |
358 */ | |
359 gint cache_maintain_home_dir(const gchar *dir, gint recursive, gint clear) | |
360 { | |
361 gchar *base; | |
362 gint base_length; | |
363 GList *dlist = NULL; | |
364 GList *flist = NULL; | |
365 gint still_have_a_file = FALSE; | |
366 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
367 DEBUG_1("maintainance check: %s", dir); |
9 | 368 |
283 | 369 base_length = strlen(homedir()) + strlen("/") + strlen(GQ_CACHE_RC_THUMB); |
370 base = g_strconcat(homedir(), "/", GQ_CACHE_RC_THUMB, dir, NULL); | |
9 | 371 |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
372 if (filelist_read(base, &flist, &dlist)) |
9 | 373 { |
374 GList *work; | |
375 | |
376 work = dlist; | |
516 | 377 while (work) |
9 | 378 { |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
379 FileData *fd = work->data; |
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
380 if (recursive && strlen(fd->path) > base_length && |
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
381 !cache_maintain_home_dir(fd->path + base_length, recursive, clear)) |
9 | 382 { |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
383 DEBUG_1("Deleting thumb dir: %s", fd->path); |
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
384 if (!rmdir_utf8(fd->path)) |
9 | 385 { |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
386 log_printf("Unable to delete dir: %s\n", fd->path); |
9 | 387 } |
388 } | |
389 else | |
390 { | |
391 still_have_a_file = TRUE; | |
392 } | |
393 work = work->next; | |
394 } | |
395 | |
396 work = flist; | |
397 while (work) | |
398 { | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
399 FileData *fd = work->data; |
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
400 gchar *path = g_strdup(fd->path); |
9 | 401 gchar *dot; |
402 | |
403 dot = extension_find_dot(path); | |
404 | |
405 if (dot) *dot = '\0'; | |
406 if (clear || | |
407 (strlen(path) > base_length && !isfile(path + base_length)) ) | |
408 { | |
409 if (dot) *dot = '.'; | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
410 if (!unlink_file(path)) log_printf("failed to delete:%s\n", path); |
9 | 411 } |
412 else | |
413 { | |
414 still_have_a_file = TRUE; | |
415 } | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
416 g_free(path); |
9 | 417 |
418 work = work->next; | |
419 } | |
420 } | |
421 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
422 filelist_free(dlist); |
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
423 filelist_free(flist); |
9 | 424 g_free(base); |
425 | |
426 return still_have_a_file; | |
427 } | |
428 | |
429 /* This checks relative caches in dir/.thumbnails and | |
430 * removes them if they have no source counterpart. | |
431 */ | |
432 gint cache_maintain_dir(const gchar *dir, gint recursive, gint clear) | |
433 { | |
434 GList *list = NULL; | |
435 gchar *cachedir; | |
436 gint still_have_a_file = FALSE; | |
437 GList *work; | |
438 | |
707
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
439 cachedir = g_build_filename(dir, GQ_CACHE_LOCAL_THUMB, NULL); |
9 | 440 |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
441 filelist_read(cachedir, &list, NULL); |
9 | 442 work = list; |
443 | |
444 while (work) | |
445 { | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
446 FileData *fd; |
9 | 447 gchar *source; |
448 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
449 fd = work->data; |
9 | 450 work = work->next; |
451 | |
707
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
452 source = g_build_filename(dir, fd->name, NULL); |
9 | 453 |
454 if (clear || | |
283 | 455 extension_truncate(source, GQ_CACHE_EXT_THUMB) || |
456 extension_truncate(source, GQ_CACHE_EXT_SIM)) | |
9 | 457 { |
458 if (!clear && isfile(source)) | |
459 { | |
460 still_have_a_file = TRUE; | |
461 } | |
462 else | |
463 { | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
464 if (!unlink_file(fd->path)) |
9 | 465 { |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
466 DEBUG_1("Failed to remove cache file %s", fd->path); |
9 | 467 still_have_a_file = TRUE; |
468 } | |
469 } | |
470 } | |
471 else | |
472 { | |
473 still_have_a_file = TRUE; | |
474 } | |
475 g_free(source); | |
476 } | |
477 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
478 filelist_free(list); |
9 | 479 g_free(cachedir); |
480 | |
481 if (recursive) | |
482 { | |
483 list = NULL; | |
484 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
485 filelist_read(dir, NULL, &list); |
9 | 486 work = list; |
487 while (work) | |
488 { | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
489 FileData *fd = work->data; |
9 | 490 work = work->next; |
491 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
492 still_have_a_file |= cache_maintain_dir(fd->path, recursive, clear); |
9 | 493 } |
494 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
495 filelist_free(list); |
9 | 496 } |
497 | |
498 return still_have_a_file; | |
499 } | |
710 | 500 #endif |
9 | 501 |
502 static void cache_file_move(const gchar *src, const gchar *dest) | |
503 { | |
504 if (!dest || !src || !isfile(src)) return; | |
505 | |
506 if (!move_file(src, dest)) | |
507 { | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
508 DEBUG_1("Failed to move cache file \"%s\" to \"%s\"", src, dest); |
9 | 509 /* we remove it anyway - it's stale */ |
510 unlink_file(src); | |
511 } | |
512 } | |
513 | |
138 | 514 void cache_maint_moved(FileData *fd) |
9 | 515 { |
516 gchar *base; | |
517 mode_t mode = 0755; | |
138 | 518 const gchar *src = fd->change->source; |
519 const gchar *dest = fd->change->dest; | |
9 | 520 |
521 if (!src || !dest) return; | |
522 | |
523 base = cache_get_location(CACHE_TYPE_THUMB, dest, FALSE, &mode); | |
524 if (cache_ensure_dir_exists(base, mode)) | |
525 { | |
526 gchar *buf; | |
527 gchar *d; | |
528 | |
529 buf = cache_find_location(CACHE_TYPE_THUMB, src); | |
530 d = cache_get_location(CACHE_TYPE_THUMB, dest, TRUE, NULL); | |
531 cache_file_move(buf, d); | |
532 g_free(d); | |
533 g_free(buf); | |
534 | |
535 buf = cache_find_location(CACHE_TYPE_SIM, src); | |
536 d = cache_get_location(CACHE_TYPE_SIM, dest, TRUE, NULL); | |
537 cache_file_move(buf, d); | |
538 g_free(d); | |
539 g_free(buf); | |
540 } | |
541 else | |
542 { | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
543 log_printf("Failed to create cache dir for move %s\n", base); |
9 | 544 } |
545 g_free(base); | |
546 | |
547 base = cache_get_location(CACHE_TYPE_METADATA, dest, FALSE, &mode); | |
548 if (cache_ensure_dir_exists(base, mode)) | |
549 { | |
550 gchar *buf; | |
551 gchar *d; | |
442 | 552 |
9 | 553 buf = cache_find_location(CACHE_TYPE_METADATA, src); |
554 d = cache_get_location(CACHE_TYPE_METADATA, dest, TRUE, NULL); | |
555 cache_file_move(buf, d); | |
556 g_free(d); | |
557 g_free(buf); | |
558 } | |
559 g_free(base); | |
560 | |
333 | 561 if (options->thumbnails.enable_caching && options->thumbnails.spec_standard) |
318 | 562 thumb_std_maint_moved(src, dest); |
9 | 563 } |
564 | |
565 static void cache_file_remove(const gchar *path) | |
566 { | |
567 if (path && isfile(path) && !unlink_file(path)) | |
568 { | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
569 DEBUG_1("Failed to remove cache file %s", path); |
9 | 570 } |
571 } | |
572 | |
138 | 573 void cache_maint_removed(FileData *fd) |
9 | 574 { |
575 gchar *buf; | |
576 | |
138 | 577 buf = cache_find_location(CACHE_TYPE_THUMB, fd->path); |
9 | 578 cache_file_remove(buf); |
579 g_free(buf); | |
580 | |
138 | 581 buf = cache_find_location(CACHE_TYPE_SIM, fd->path); |
9 | 582 cache_file_remove(buf); |
583 g_free(buf); | |
584 | |
138 | 585 buf = cache_find_location(CACHE_TYPE_METADATA, fd->path); |
9 | 586 cache_file_remove(buf); |
587 g_free(buf); | |
588 | |
333 | 589 if (options->thumbnails.enable_caching && options->thumbnails.spec_standard) |
318 | 590 thumb_std_maint_removed(fd->path); |
9 | 591 } |
592 | |
138 | 593 void cache_maint_copied(FileData *fd) |
9 | 594 { |
595 gchar *dest_base; | |
596 gchar *src_cache; | |
597 mode_t mode = 0755; | |
598 | |
138 | 599 src_cache = cache_find_location(CACHE_TYPE_METADATA, fd->change->source); |
9 | 600 if (!src_cache) return; |
601 | |
138 | 602 dest_base = cache_get_location(CACHE_TYPE_METADATA, fd->change->dest, FALSE, &mode); |
9 | 603 if (cache_ensure_dir_exists(dest_base, mode)) |
604 { | |
605 gchar *path; | |
442 | 606 |
138 | 607 path = cache_get_location(CACHE_TYPE_METADATA, fd->change->dest, TRUE, NULL); |
9 | 608 if (!copy_file(src_cache, path)) |
609 { | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
610 DEBUG_1("failed to copy metadata %s to %s", src_cache, path); |
9 | 611 } |
612 g_free(path); | |
613 } | |
614 | |
615 g_free(dest_base); | |
616 g_free(src_cache); | |
617 } | |
618 | |
619 /* | |
620 *------------------------------------------------------------------- | |
621 * new cache maintenance utilities | |
622 *------------------------------------------------------------------- | |
623 */ | |
624 | |
625 typedef struct _CacheManager CacheManager; | |
626 struct _CacheManager | |
627 { | |
628 GenericDialog *dialog; | |
629 GtkWidget *folder_entry; | |
630 GtkWidget *progress; | |
631 | |
632 GList *list_todo; | |
633 | |
634 gint count_total; | |
635 gint count_done; | |
636 }; | |
637 | |
638 typedef struct _CleanData CleanData; | |
639 struct _CleanData | |
640 { | |
641 GenericDialog *gd; | |
642 ThumbLoaderStd *tl; | |
643 | |
644 GList *list; | |
645 GList *list_dir; | |
646 | |
647 gint days; | |
648 gint clear; | |
649 | |
650 GtkWidget *button_close; | |
651 GtkWidget *button_stop; | |
652 GtkWidget *button_start; | |
653 GtkWidget *progress; | |
654 GtkWidget *spinner; | |
655 | |
656 GtkWidget *group; | |
657 GtkWidget *entry; | |
658 | |
659 gint count_total; | |
660 gint count_done; | |
661 | |
662 gint local; | |
663 gint recurse; | |
664 | |
665 gint idle_id; | |
666 }; | |
667 | |
668 static void cache_manager_render_reset(CleanData *cd) | |
669 { | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
670 filelist_free(cd->list); |
9 | 671 cd->list = NULL; |
672 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
673 filelist_free(cd->list_dir); |
9 | 674 cd->list_dir = NULL; |
675 | |
676 thumb_loader_free((ThumbLoader *)cd->tl); | |
677 cd->tl = NULL; | |
678 } | |
679 | |
680 static void cache_manager_render_close_cb(GenericDialog *fd, gpointer data) | |
681 { | |
682 CleanData *cd = data; | |
683 | |
684 if (!GTK_WIDGET_SENSITIVE(cd->button_close)) return; | |
685 | |
686 cache_manager_render_reset(cd); | |
687 generic_dialog_close(cd->gd); | |
688 g_free(cd); | |
689 } | |
690 | |
691 static void cache_manager_render_finish(CleanData *cd) | |
692 { | |
693 cache_manager_render_reset(cd); | |
694 | |
695 gtk_entry_set_text(GTK_ENTRY(cd->progress), _("done")); | |
696 spinner_set_interval(cd->spinner, -1); | |
697 | |
698 gtk_widget_set_sensitive(cd->group, TRUE); | |
699 gtk_widget_set_sensitive(cd->button_start, TRUE); | |
700 gtk_widget_set_sensitive(cd->button_stop, FALSE); | |
701 gtk_widget_set_sensitive(cd->button_close, TRUE); | |
702 } | |
703 | |
704 static void cache_manager_render_stop_cb(GenericDialog *fd, gpointer data) | |
705 { | |
706 CleanData *cd = data; | |
707 | |
708 cache_manager_render_finish(cd); | |
709 } | |
710 | |
711 static void cache_manager_render_folder(CleanData *cd, const gchar *path) | |
712 { | |
713 GList *list_d = NULL; | |
714 GList *list_f = NULL; | |
715 | |
716 if (cd->recurse) | |
717 { | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
718 filelist_read(path, &list_f, &list_d); |
9 | 719 } |
720 else | |
721 { | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
722 filelist_read(path, &list_f, NULL); |
9 | 723 } |
724 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
725 list_f = filelist_filter(list_f, FALSE); |
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
726 list_d = filelist_filter(list_d, TRUE); |
9 | 727 |
728 cd->list = g_list_concat(list_f, cd->list); | |
729 cd->list_dir = g_list_concat(list_d, cd->list_dir); | |
730 } | |
731 | |
732 static gint cache_manager_render_file(CleanData *cd); | |
733 | |
734 static void cache_manager_render_thumb_done_cb(ThumbLoader *tl, gpointer data) | |
735 { | |
736 CleanData *cd = data; | |
737 | |
738 thumb_loader_free((ThumbLoader *)cd->tl); | |
739 cd->tl = NULL; | |
740 | |
741 while (cache_manager_render_file(cd)); | |
742 } | |
743 | |
744 static gint cache_manager_render_file(CleanData *cd) | |
745 { | |
746 if (cd->list) | |
747 { | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
748 FileData *fd; |
9 | 749 gint success; |
750 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
751 fd = cd->list->data; |
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
752 cd->list = g_list_remove(cd->list, fd); |
9 | 753 |
333 | 754 cd->tl = (ThumbLoaderStd *)thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height); |
9 | 755 thumb_loader_set_callbacks((ThumbLoader *)cd->tl, |
756 cache_manager_render_thumb_done_cb, | |
757 cache_manager_render_thumb_done_cb, | |
758 NULL, cd); | |
759 thumb_loader_set_cache((ThumbLoader *)cd->tl, TRUE, cd->local, TRUE); | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
760 success = thumb_loader_start((ThumbLoader *)cd->tl, fd->path); |
9 | 761 if (success) |
762 { | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
763 gtk_entry_set_text(GTK_ENTRY(cd->progress), fd->path); |
9 | 764 } |
765 else | |
766 { | |
767 thumb_loader_free((ThumbLoader *)cd->tl); | |
768 cd->tl = NULL; | |
769 } | |
770 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
771 file_data_unref(fd); |
9 | 772 |
773 return (!success); | |
774 } | |
775 else if (cd->list_dir) | |
776 { | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
777 FileData *fd; |
9 | 778 |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
779 fd = cd->list_dir->data; |
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
780 cd->list_dir = g_list_remove(cd->list_dir, fd); |
9 | 781 |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
782 cache_manager_render_folder(cd, fd->path); |
9 | 783 |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
784 file_data_unref(fd); |
9 | 785 |
786 return TRUE; | |
787 } | |
788 | |
789 cache_manager_render_finish(cd); | |
790 | |
791 return FALSE; | |
792 } | |
793 | |
794 static void cache_manager_render_start_cb(GenericDialog *fd, gpointer data) | |
795 { | |
796 CleanData *cd = data; | |
797 gchar *path; | |
798 | |
799 if (cd->list || !GTK_WIDGET_SENSITIVE(cd->button_start)) return; | |
800 | |
801 path = remove_trailing_slash((gtk_entry_get_text(GTK_ENTRY(cd->entry)))); | |
802 parse_out_relatives(path); | |
803 | |
804 if (!isdir(path)) | |
805 { | |
806 warning_dialog(_("Invalid folder"), | |
442 | 807 _("The specified folder can not be found."), |
9 | 808 GTK_STOCK_DIALOG_WARNING, cd->gd->dialog); |
809 } | |
810 else | |
811 { | |
812 gtk_widget_set_sensitive(cd->group, FALSE); | |
813 gtk_widget_set_sensitive(cd->button_start, FALSE); | |
814 gtk_widget_set_sensitive(cd->button_stop, TRUE); | |
815 gtk_widget_set_sensitive(cd->button_close, FALSE); | |
816 | |
817 spinner_set_interval(cd->spinner, SPINNER_SPEED); | |
818 | |
819 cache_manager_render_folder(cd, path); | |
820 while (cache_manager_render_file(cd)); | |
821 } | |
822 | |
823 g_free(path); | |
824 } | |
825 | |
826 static void cache_manager_render_dialog(GtkWidget *widget, const gchar *path) | |
827 { | |
828 CleanData *cd; | |
829 GtkWidget *hbox; | |
830 GtkWidget *label; | |
831 GtkWidget *button; | |
832 | |
833 cd = g_new0(CleanData, 1); | |
834 | |
835 cd->gd = generic_dialog_new(_("Create thumbnails"), | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
229
diff
changeset
|
836 GQ_WMCLASS, "create_thumbnails", |
9 | 837 widget, FALSE, |
838 NULL, cd); | |
839 gtk_window_set_default_size(GTK_WINDOW(cd->gd->dialog), PURGE_DIALOG_WIDTH, -1); | |
840 cd->gd->cancel_cb = cache_manager_render_close_cb; | |
841 cd->button_close = generic_dialog_add_button(cd->gd, GTK_STOCK_CLOSE, NULL, | |
842 cache_manager_render_close_cb, FALSE); | |
843 cd->button_start = generic_dialog_add_button(cd->gd, GTK_STOCK_OK, _("S_tart"), | |
844 cache_manager_render_start_cb, FALSE); | |
845 cd->button_stop = generic_dialog_add_button(cd->gd, GTK_STOCK_STOP, NULL, | |
846 cache_manager_render_stop_cb, FALSE); | |
847 gtk_widget_set_sensitive(cd->button_stop, FALSE); | |
848 | |
849 generic_dialog_add_message(cd->gd, NULL, _("Create thumbnails"), NULL); | |
850 | |
851 hbox = pref_box_new(cd->gd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, 0); | |
852 pref_spacer(hbox, PREF_PAD_INDENT); | |
853 cd->group = pref_box_new(hbox, TRUE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP); | |
854 | |
855 hbox = pref_box_new(cd->group, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE); | |
856 pref_label_new(hbox, _("Folder:")); | |
857 | |
858 label = tab_completion_new(&cd->entry, path, NULL, NULL); | |
859 tab_completion_add_select_button(cd->entry,_("Select folder") , TRUE); | |
860 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); | |
861 gtk_widget_show(label); | |
862 | |
863 pref_checkbox_new_int(cd->group, _("Include subfolders"), FALSE, &cd->recurse); | |
864 button = pref_checkbox_new_int(cd->group, _("Store thumbnails local to source images"), FALSE, &cd->local); | |
333 | 865 gtk_widget_set_sensitive(button, options->thumbnails.spec_standard); |
9 | 866 |
867 pref_line(cd->gd->vbox, PREF_PAD_SPACE); | |
868 hbox = pref_box_new(cd->gd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE); | |
869 | |
870 cd->progress = gtk_entry_new(); | |
871 GTK_WIDGET_UNSET_FLAGS(cd->progress, GTK_CAN_FOCUS); | |
872 gtk_editable_set_editable(GTK_EDITABLE(cd->progress), FALSE); | |
873 gtk_entry_set_text(GTK_ENTRY(cd->progress), _("click start to begin")); | |
874 gtk_box_pack_start(GTK_BOX(hbox), cd->progress, TRUE, TRUE, 0); | |
875 gtk_widget_show(cd->progress); | |
876 | |
877 cd->spinner = spinner_new(NULL, -1); | |
878 gtk_box_pack_start(GTK_BOX(hbox), cd->spinner, FALSE, FALSE, 0); | |
879 gtk_widget_show(cd->spinner); | |
880 | |
881 cd->list = NULL; | |
882 | |
883 gtk_widget_show(cd->gd->dialog); | |
884 } | |
885 | |
886 | |
887 | |
888 | |
889 static void cache_manager_standard_clean_close_cb(GenericDialog *gd, gpointer data) | |
890 { | |
891 CleanData *cd = data; | |
892 | |
893 if (!GTK_WIDGET_SENSITIVE(cd->button_close)) return; | |
894 | |
895 generic_dialog_close(cd->gd); | |
896 | |
897 thumb_loader_std_thumb_file_validate_cancel(cd->tl); | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
898 filelist_free(cd->list); |
9 | 899 g_free(cd); |
900 } | |
901 | |
902 static void cache_manager_standard_clean_done(CleanData *cd) | |
903 { | |
904 gtk_widget_set_sensitive(cd->button_stop, FALSE); | |
905 gtk_widget_set_sensitive(cd->button_close, TRUE); | |
906 | |
907 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(cd->progress), 1.0); | |
908 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(cd->progress), _("done")); | |
909 | |
910 if (cd->idle_id != -1) | |
911 { | |
912 g_source_remove(cd->idle_id); | |
913 cd->idle_id = -1; | |
914 } | |
915 | |
916 thumb_loader_std_thumb_file_validate_cancel(cd->tl); | |
917 cd->tl = NULL; | |
918 | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
919 filelist_free(cd->list); |
9 | 920 cd->list = NULL; |
921 } | |
922 | |
923 static void cache_manager_standard_clean_stop_cb(GenericDialog *gd, gpointer data) | |
924 { | |
925 CleanData *cd = data; | |
926 | |
927 cache_manager_standard_clean_done(cd); | |
928 } | |
929 | |
930 static gint cache_manager_standard_clean_clear_cb(gpointer data) | |
931 { | |
932 CleanData *cd = data; | |
933 | |
934 if (cd->list) | |
935 { | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
936 FileData *next_fd; |
9 | 937 |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
938 next_fd = cd->list->data; |
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
939 cd->list = g_list_remove(cd->list, next_fd); |
9 | 940 |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
941 DEBUG_1("thumb removed: %s", next_fd->path); |
9 | 942 |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
943 unlink_file(next_fd->path); |
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
944 file_data_unref(next_fd); |
9 | 945 |
946 cd->count_done++; | |
947 if (cd->count_total != 0) | |
948 { | |
949 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(cd->progress), | |
950 (gdouble)cd->count_done / cd->count_total); | |
951 } | |
952 | |
953 return TRUE; | |
954 } | |
955 | |
956 cd->idle_id = -1; | |
957 cache_manager_standard_clean_done(cd); | |
958 return FALSE; | |
959 } | |
960 | |
961 static void cache_manager_standard_clean_valid_cb(const gchar *path, gint valid, gpointer data) | |
962 { | |
963 CleanData *cd = data; | |
964 | |
965 if (path) | |
966 { | |
967 if (!valid) | |
968 { | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
495
diff
changeset
|
969 DEBUG_1("thumb cleaned: %s", path); |
9 | 970 unlink_file(path); |
971 } | |
972 | |
973 cd->count_done++; | |
974 if (cd->count_total != 0) | |
975 { | |
976 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(cd->progress), | |
977 (gdouble)cd->count_done / cd->count_total); | |
978 } | |
979 } | |
980 | |
981 cd->tl = NULL; | |
982 if (cd->list) | |
983 { | |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
984 FileData *next_fd; |
9 | 985 |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
986 next_fd = cd->list->data; |
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
987 cd->list = g_list_remove(cd->list, next_fd); |
442 | 988 |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
989 cd->tl = thumb_loader_std_thumb_file_validate(next_fd->path, cd->days, |
9 | 990 cache_manager_standard_clean_valid_cb, cd); |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
991 file_data_unref(next_fd); |
9 | 992 } |
993 else | |
994 { | |
995 cache_manager_standard_clean_done(cd); | |
996 } | |
997 } | |
998 | |
999 static void cache_manager_standard_clean_start_cb(GenericDialog *gd, gpointer data) | |
1000 { | |
1001 CleanData *cd = data; | |
1002 GList *list; | |
1003 gchar *path; | |
1004 | |
1005 if (cd->list || !GTK_WIDGET_SENSITIVE(cd->button_start)) return; | |
1006 | |
1007 gtk_widget_set_sensitive(cd->button_start, FALSE); | |
1008 gtk_widget_set_sensitive(cd->button_stop, TRUE); | |
1009 gtk_widget_set_sensitive(cd->button_close, FALSE); | |
1010 | |
1011 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(cd->progress), _("running...")); | |
1012 | |
707
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1013 path = g_build_filename(homedir(), THUMB_FOLDER_GLOBAL, THUMB_FOLDER_NORMAL, NULL); |
9 | 1014 list = NULL; |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
1015 filelist_read(path, &list, NULL); |
9 | 1016 cd->list = list; |
1017 g_free(path); | |
1018 | |
707
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1019 path = g_build_filename(homedir(), THUMB_FOLDER_GLOBAL, THUMB_FOLDER_LARGE, NULL); |
9 | 1020 list = NULL; |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
1021 filelist_read(path, &list, NULL); |
9 | 1022 cd->list = g_list_concat(cd->list, list); |
1023 g_free(path); | |
1024 | |
707
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1025 path = g_build_filename(homedir(), THUMB_FOLDER_GLOBAL, THUMB_FOLDER_FAIL, NULL); |
9 | 1026 list = NULL; |
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
533
diff
changeset
|
1027 filelist_read(path, &list, NULL); |
9 | 1028 cd->list = g_list_concat(cd->list, list); |
1029 g_free(path); | |
1030 | |
1031 cd->count_total = g_list_length(cd->list); | |
1032 cd->count_done = 0; | |
1033 | |
1034 /* start iterating */ | |
1035 if (cd->clear) | |
1036 { | |
1037 cd->idle_id = g_idle_add(cache_manager_standard_clean_clear_cb, cd); | |
1038 } | |
1039 else | |
1040 { | |
1041 cache_manager_standard_clean_valid_cb(NULL, TRUE, cd); | |
1042 } | |
1043 } | |
1044 | |
1045 static void cache_manager_standard_process(GtkWidget *widget, gint clear) | |
1046 { | |
1047 CleanData *cd; | |
1048 const gchar *stock_id; | |
1049 const gchar *msg; | |
1050 | |
1051 cd = g_new0(CleanData, 1); | |
1052 cd->clear = clear; | |
1053 | |
1054 if (clear) | |
1055 { | |
1056 stock_id = GTK_STOCK_DELETE; | |
1057 msg = _("Clearing thumbnails..."); | |
1058 } | |
1059 else | |
1060 { | |
1061 stock_id = GTK_STOCK_CLEAR; | |
1062 msg = _("Removing old thumbnails..."); | |
1063 } | |
1064 | |
1065 cd->gd = generic_dialog_new(_("Maintenance"), | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
229
diff
changeset
|
1066 GQ_WMCLASS, "standard_maintenance", |
9 | 1067 widget, FALSE, |
1068 NULL, cd); | |
1069 cd->gd->cancel_cb = cache_manager_standard_clean_close_cb; | |
1070 cd->button_close = generic_dialog_add_button(cd->gd, GTK_STOCK_CLOSE, NULL, | |
1071 cache_manager_standard_clean_close_cb, FALSE); | |
1072 cd->button_start = generic_dialog_add_button(cd->gd, GTK_STOCK_OK, _("S_tart"), | |
1073 cache_manager_standard_clean_start_cb, FALSE); | |
1074 cd->button_stop = generic_dialog_add_button(cd->gd, GTK_STOCK_STOP, NULL, | |
1075 cache_manager_standard_clean_stop_cb, FALSE); | |
1076 gtk_widget_set_sensitive(cd->button_stop, FALSE); | |
1077 | |
1078 generic_dialog_add_message(cd->gd, stock_id, msg, NULL); | |
1079 | |
1080 cd->progress = gtk_progress_bar_new(); | |
1081 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(cd->progress), _("click start to begin")); | |
1082 gtk_box_pack_start(GTK_BOX(cd->gd->vbox), cd->progress, FALSE, FALSE, 0); | |
1083 gtk_widget_show(cd->progress); | |
1084 | |
1085 cd->days = 30; | |
1086 cd->tl = NULL; | |
1087 cd->idle_id = -1; | |
1088 | |
1089 gtk_widget_show(cd->gd->dialog); | |
1090 } | |
1091 | |
1092 static void cache_manager_standard_clean_cb(GtkWidget *widget, gpointer data) | |
1093 { | |
1094 cache_manager_standard_process(widget, FALSE); | |
1095 } | |
1096 | |
1097 static void cache_manager_standard_clear_cb(GtkWidget *widget, gpointer data) | |
1098 { | |
1099 cache_manager_standard_process(widget, TRUE); | |
1100 } | |
1101 | |
1102 | |
229
c44b98370dba
Use more generic names for some cache manager callback functions.
zas_
parents:
228
diff
changeset
|
1103 static void cache_manager_main_clean_cb(GtkWidget *widget, gpointer data) |
9 | 1104 { |
1105 cache_maintain_home(FALSE, FALSE, widget); | |
1106 } | |
1107 | |
1108 | |
1109 static void dummy_cancel_cb(GenericDialog *gd, gpointer data) | |
1110 { | |
1111 /* no op, only so cancel button appears */ | |
1112 } | |
1113 | |
229
c44b98370dba
Use more generic names for some cache manager callback functions.
zas_
parents:
228
diff
changeset
|
1114 static void cache_manager_main_clear_ok_cb(GenericDialog *gd, gpointer data) |
9 | 1115 { |
1116 cache_maintain_home(FALSE, TRUE, NULL); | |
1117 } | |
1118 | |
229
c44b98370dba
Use more generic names for some cache manager callback functions.
zas_
parents:
228
diff
changeset
|
1119 void cache_manager_main_clear_confirm(GtkWidget *parent) |
9 | 1120 { |
1121 GenericDialog *gd; | |
1122 | |
1123 gd = generic_dialog_new(_("Clear cache"), | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
229
diff
changeset
|
1124 GQ_WMCLASS, "clear_cache", parent, TRUE, |
9 | 1125 dummy_cancel_cb, NULL); |
1126 generic_dialog_add_message(gd, GTK_STOCK_DIALOG_QUESTION, _("Clear cache"), | |
1127 _("This will remove all thumbnails that have\nbeen saved to disk, continue?")); | |
229
c44b98370dba
Use more generic names for some cache manager callback functions.
zas_
parents:
228
diff
changeset
|
1128 generic_dialog_add_button(gd, GTK_STOCK_OK, NULL, cache_manager_main_clear_ok_cb, TRUE); |
9 | 1129 |
1130 gtk_widget_show(gd->dialog); | |
1131 } | |
1132 | |
229
c44b98370dba
Use more generic names for some cache manager callback functions.
zas_
parents:
228
diff
changeset
|
1133 static void cache_manager_main_clear_cb(GtkWidget *widget, gpointer data) |
9 | 1134 { |
229
c44b98370dba
Use more generic names for some cache manager callback functions.
zas_
parents:
228
diff
changeset
|
1135 cache_manager_main_clear_confirm(widget); |
9 | 1136 } |
1137 | |
1138 static void cache_manager_render_cb(GtkWidget *widget, gpointer data) | |
1139 { | |
1140 cache_manager_render_dialog(widget, homedir()); | |
1141 } | |
1142 | |
1143 static void cache_manager_metadata_clean_cb(GtkWidget *widget, gpointer data) | |
1144 { | |
1145 cache_maintain_home(TRUE, FALSE, widget); | |
1146 } | |
1147 | |
1148 | |
1149 static CacheManager *cache_manager = NULL; | |
1150 | |
1151 static void cache_manager_close_cb(GenericDialog *gd, gpointer data) | |
1152 { | |
1153 generic_dialog_close(gd); | |
1154 | |
1155 g_free(cache_manager); | |
1156 cache_manager = NULL; | |
1157 } | |
1158 | |
707
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1159 static GtkWidget *cache_manager_location_label(GtkWidget *group, const gchar *subdir) |
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1160 { |
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1161 GtkWidget *label; |
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1162 gchar *buf; |
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1163 gchar *path; |
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1164 |
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1165 path = g_build_filename(homedir(), subdir, NULL); |
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1166 buf = g_strdup_printf(_("Location: %s"), path); |
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1167 g_free(path); |
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1168 label = pref_label_new(group, buf); |
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1169 g_free(buf); |
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1170 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); |
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1171 |
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1172 return label; |
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1173 } |
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1174 |
9 | 1175 void cache_manager_show(void) |
1176 { | |
1177 GenericDialog *gd; | |
1178 GtkWidget *group; | |
1179 GtkWidget *button; | |
1180 GtkWidget *table; | |
1181 GtkSizeGroup *sizegroup; | |
1182 | |
1183 if (cache_manager) | |
1184 { | |
1185 gtk_window_present(GTK_WINDOW(cache_manager->dialog->dialog)); | |
1186 return; | |
1187 } | |
1188 | |
1189 cache_manager = g_new0(CacheManager, 1); | |
1190 | |
675 | 1191 cache_manager->dialog = generic_dialog_new(_("Cache Maintenance"), |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
229
diff
changeset
|
1192 GQ_WMCLASS, "cache_manager", |
9 | 1193 NULL, FALSE, |
1194 NULL, cache_manager); | |
1195 gd = cache_manager->dialog; | |
1196 | |
1197 gd->cancel_cb = cache_manager_close_cb; | |
1198 generic_dialog_add_button(gd, GTK_STOCK_CLOSE, NULL, | |
1199 cache_manager_close_cb, FALSE); | |
1200 | |
1201 generic_dialog_add_message(gd, NULL, _("Cache and Data Maintenance"), NULL); | |
1202 | |
1203 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
1204 | |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1205 group = pref_group_new(gd->vbox, FALSE, _("Thumbnail cache"), GTK_ORIENTATION_VERTICAL); |
9 | 1206 |
707
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1207 cache_manager_location_label(group, GQ_CACHE_RC_THUMB); |
9 | 1208 |
1209 table = pref_table_new(group, 2, 2, FALSE, FALSE); | |
1210 | |
1211 button = pref_table_button(table, 0, 0, GTK_STOCK_CLEAR, _("Clean up"), FALSE, | |
229
c44b98370dba
Use more generic names for some cache manager callback functions.
zas_
parents:
228
diff
changeset
|
1212 G_CALLBACK(cache_manager_main_clean_cb), cache_manager); |
9 | 1213 gtk_size_group_add_widget(sizegroup, button); |
1214 pref_table_label(table, 1, 0, _("Remove orphaned or outdated thumbnails."), 0.0); | |
1215 | |
1216 button = pref_table_button(table, 0, 1, GTK_STOCK_DELETE, _("Clear cache"), FALSE, | |
229
c44b98370dba
Use more generic names for some cache manager callback functions.
zas_
parents:
228
diff
changeset
|
1217 G_CALLBACK(cache_manager_main_clear_cb), cache_manager); |
9 | 1218 gtk_size_group_add_widget(sizegroup, button); |
1219 pref_table_label(table, 1, 1, _("Delete all cached thumbnails."), 0.0); | |
1220 | |
1221 | |
1222 group = pref_group_new(gd->vbox, FALSE, _("Shared thumbnail cache"), GTK_ORIENTATION_VERTICAL); | |
1223 | |
707
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1224 cache_manager_location_label(group, THUMB_FOLDER_GLOBAL); |
9 | 1225 |
1226 table = pref_table_new(group, 2, 2, FALSE, FALSE); | |
1227 | |
1228 button = pref_table_button(table, 0, 0, GTK_STOCK_CLEAR, _("Clean up"), FALSE, | |
1229 G_CALLBACK(cache_manager_standard_clean_cb), cache_manager); | |
1230 gtk_size_group_add_widget(sizegroup, button); | |
1231 pref_table_label(table, 1, 0, _("Remove orphaned or outdated thumbnails."), 0.0); | |
1232 | |
1233 button = pref_table_button(table, 0, 1, GTK_STOCK_DELETE, _("Clear cache"), FALSE, | |
1234 G_CALLBACK(cache_manager_standard_clear_cb), cache_manager); | |
1235 gtk_size_group_add_widget(sizegroup, button); | |
1236 pref_table_label(table, 1, 1, _("Delete all cached thumbnails."), 0.0); | |
1237 | |
1238 group = pref_group_new(gd->vbox, FALSE, _("Create thumbnails"), GTK_ORIENTATION_VERTICAL); | |
1239 | |
1240 table = pref_table_new(group, 2, 1, FALSE, FALSE); | |
1241 | |
1242 button = pref_table_button(table, 0, 1, GTK_STOCK_EXECUTE, _("Render"), FALSE, | |
1243 G_CALLBACK(cache_manager_render_cb), cache_manager); | |
1244 gtk_size_group_add_widget(sizegroup, button); | |
1245 pref_table_label(table, 1, 1, _("Render thumbnails for a specific folder."), 0.0); | |
1246 | |
1247 group = pref_group_new(gd->vbox, FALSE, _("Metadata"), GTK_ORIENTATION_VERTICAL); | |
288
d1f74154463e
Replace occurences of Geeqie / geeqie by constants defined in main.h.
zas_
parents:
283
diff
changeset
|
1248 |
707
41c17c66e63b
Use g_build_filename() and move location label creation from cache_manager_show() to new cache_manager_location_label().
zas_
parents:
675
diff
changeset
|
1249 cache_manager_location_label(group, GQ_CACHE_RC_METADATA); |
9 | 1250 |
1251 table = pref_table_new(group, 2, 1, FALSE, FALSE); | |
1252 | |
1253 button = pref_table_button(table, 0, 0, GTK_STOCK_CLEAR, _("Clean up"), FALSE, | |
1254 G_CALLBACK(cache_manager_metadata_clean_cb), cache_manager); | |
1255 gtk_size_group_add_widget(sizegroup, button); | |
1256 pref_table_label(table, 1, 0, _("Remove orphaned keywords and comments."), 0.0); | |
1257 | |
1258 gtk_widget_show(cache_manager->dialog->dialog); | |
1259 } |