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