Mercurial > geeqie
comparison src/main.c @ 1061:156a58224c85
Better handling of accels map file writing errors.
Secure save is also used for those now, at the expense of
a bit of duplication of gtk functions.
It should fix bug 2146917 (debian BTS #501131), reported by
Stanislav Maslovski.
author | zas_ |
---|---|
date | Sun, 12 Oct 2008 08:36:53 +0000 |
parents | 1646720364cf |
children | 822d98c18062 |
comparison
equal
deleted
inserted
replaced
1060:1e2de04c6fc4 | 1061:156a58224c85 |
---|---|
22 #include "image-overlay.h" | 22 #include "image-overlay.h" |
23 #include "layout.h" | 23 #include "layout.h" |
24 #include "layout_image.h" | 24 #include "layout_image.h" |
25 #include "options.h" | 25 #include "options.h" |
26 #include "remote.h" | 26 #include "remote.h" |
27 #include "secure_save.h" | |
27 #include "similar.h" | 28 #include "similar.h" |
28 #include "ui_fileops.h" | 29 #include "ui_fileops.h" |
29 #include "ui_utildlg.h" | 30 #include "ui_utildlg.h" |
30 #include "cache_maint.h" | 31 #include "cache_maint.h" |
31 #include "thumb.h" | 32 #include "thumb.h" |
458 } | 459 } |
459 } | 460 } |
460 g_free(buf); | 461 g_free(buf); |
461 } | 462 } |
462 | 463 |
464 | |
465 /* We add to duplicate and modify gtk_accel_map_print() and gtk_accel_map_save() | |
466 * to improve the reliability in special cases (especially when disk is full) | |
467 * These functions are now using secure saving stuff. | |
468 */ | |
469 static void gq_accel_map_print( | |
470 gpointer data, | |
471 const gchar *accel_path, | |
472 guint accel_key, | |
473 GdkModifierType accel_mods, | |
474 gboolean changed) | |
475 { | |
476 GString *gstring = g_string_new(changed ? NULL : "; "); | |
477 SecureSaveInfo *ssi = data; | |
478 gchar *tmp, *name; | |
479 | |
480 g_string_append(gstring, "(gtk_accel_path \""); | |
481 | |
482 tmp = g_strescape(accel_path, NULL); | |
483 g_string_append(gstring, tmp); | |
484 g_free(tmp); | |
485 | |
486 g_string_append(gstring, "\" \""); | |
487 | |
488 name = gtk_accelerator_name(accel_key, accel_mods); | |
489 tmp = g_strescape(name, NULL); | |
490 g_free(name); | |
491 g_string_append(gstring, tmp); | |
492 g_free(tmp); | |
493 | |
494 g_string_append(gstring, "\")\n"); | |
495 | |
496 secure_fwrite(gstring->str, sizeof(*gstring->str), gstring->len, ssi); | |
497 | |
498 g_string_free(gstring, TRUE); | |
499 } | |
500 | |
501 static gboolean gq_accel_map_save(const gchar *path) | |
502 { | |
503 gchar *pathl; | |
504 SecureSaveInfo *ssi; | |
505 GString *gstring; | |
506 | |
507 pathl = path_from_utf8(path); | |
508 ssi = secure_open(pathl); | |
509 g_free(pathl); | |
510 if (!ssi) | |
511 { | |
512 log_printf(_("error saving file: %s\n"), path); | |
513 return FALSE; | |
514 } | |
515 | |
516 gstring = g_string_new("; "); | |
517 if (g_get_prgname()) | |
518 g_string_append(gstring, g_get_prgname()); | |
519 g_string_append(gstring, " GtkAccelMap rc-file -*- scheme -*-\n"); | |
520 g_string_append(gstring, "; this file is an automated accelerator map dump\n"); | |
521 g_string_append(gstring, ";\n"); | |
522 | |
523 secure_fwrite(gstring->str, sizeof(*gstring->str), gstring->len, ssi); | |
524 | |
525 g_string_free(gstring, TRUE); | |
526 | |
527 gtk_accel_map_foreach((gpointer) ssi, gq_accel_map_print); | |
528 | |
529 if (secure_close(ssi)) | |
530 { | |
531 log_printf(_("error saving file: %s\nerror: %s\n"), path, | |
532 secsave_strerror(secsave_errno)); | |
533 return FALSE; | |
534 } | |
535 | |
536 return TRUE; | |
537 } | |
538 | |
539 static gchar *accep_map_filename(void) | |
540 { | |
541 return g_build_filename(homedir(), GQ_RC_DIR, "accels", NULL); | |
542 } | |
543 | |
463 static void accel_map_save(void) | 544 static void accel_map_save(void) |
545 { | |
546 gchar *path; | |
547 | |
548 path = accep_map_filename(); | |
549 gq_accel_map_save(path); | |
550 g_free(path); | |
551 } | |
552 | |
553 static void accel_map_load(void) | |
464 { | 554 { |
465 gchar *path; | 555 gchar *path; |
466 gchar *pathl; | 556 gchar *pathl; |
467 | 557 |
468 path = g_build_filename(homedir(), GQ_RC_DIR, "accels", NULL); | 558 path = accep_map_filename(); |
469 pathl = path_from_utf8(path); | |
470 gtk_accel_map_save(pathl); | |
471 g_free(pathl); | |
472 g_free(path); | |
473 } | |
474 | |
475 static void accel_map_load(void) | |
476 { | |
477 gchar *path; | |
478 gchar *pathl; | |
479 | |
480 path = g_build_filename(homedir(), GQ_RC_DIR, "accels", NULL); | |
481 pathl = path_from_utf8(path); | 559 pathl = path_from_utf8(path); |
482 gtk_accel_map_load(pathl); | 560 gtk_accel_map_load(pathl); |
483 g_free(pathl); | 561 g_free(pathl); |
484 g_free(path); | 562 g_free(path); |
485 } | 563 } |