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