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