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