Mercurial > geeqie.yaz
changeset 1145:3a7af6a8cd5f
Use functions to return directories instead of constants.
Following functions were added:
get_collections_dir()
get_metadata_cache_dir()
get_rc_dir()
get_thumbnails_cache_dir()
get_trash_dir()
They return the full directory path.
author | zas_ |
---|---|
date | Sat, 15 Nov 2008 17:30:45 +0000 |
parents | 5fe3b8b3a612 |
children | 11b93d0791db |
files | src/bar_sort.c src/cache.c src/cache.h src/cache_maint.c src/collect-dlg.c src/collect-io.c src/main.c src/main.h src/options.c src/remote.c src/search.c src/ui_fileops.c src/ui_fileops.h |
diffstat | 13 files changed, 103 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- a/src/bar_sort.c Sat Nov 15 10:35:43 2008 +0000 +++ b/src/bar_sort.c Sat Nov 15 17:30:45 2008 +0000 @@ -89,7 +89,6 @@ static void bar_sort_collection_list_build(GtkWidget *bookmarks) { - gchar *collect_path; FileData *dir_fd; GList *list; GList *work; @@ -97,11 +96,9 @@ history_list_free_key(SORT_KEY_COLLECTIONS); bookmark_list_set_key(bookmarks, SORT_KEY_COLLECTIONS); - collect_path = g_build_filename(homedir(), GQ_RC_DIR_COLLECTIONS, NULL); - dir_fd = file_data_new_simple(collect_path); + dir_fd = file_data_new_simple(get_collections_dir()); filelist_read(dir_fd, &list, NULL); file_data_unref(dir_fd); - g_free(collect_path); list = filelist_sort_path(list); @@ -436,7 +433,7 @@ name = tmp; } - path = g_build_filename(homedir(), GQ_RC_DIR_COLLECTIONS, name, NULL); + path = g_build_filename(get_collections_dir(), name, NULL); if (isfile(path)) { gchar *text = g_strdup_printf(_("The collection:\n%s\nalready exists."), name);
--- a/src/cache.c Sat Nov 15 10:35:43 2008 +0000 +++ b/src/cache.c Sat Nov 15 17:30:45 2008 +0000 @@ -623,17 +623,17 @@ switch (type) { case CACHE_TYPE_THUMB: - *cache_rc = GQ_CACHE_RC_THUMB; + *cache_rc = get_thumbnails_cache_dir(); *cache_local = GQ_CACHE_LOCAL_THUMB; *cache_ext = GQ_CACHE_EXT_THUMB; break; case CACHE_TYPE_SIM: - *cache_rc = GQ_CACHE_RC_THUMB; + *cache_rc = get_thumbnails_cache_dir(); *cache_local = GQ_CACHE_LOCAL_THUMB; *cache_ext = GQ_CACHE_EXT_SIM; break; case CACHE_TYPE_METADATA: - *cache_rc = GQ_CACHE_RC_METADATA; + *cache_rc = get_metadata_cache_dir(); *cache_local = GQ_CACHE_LOCAL_METADATA; *cache_ext = GQ_CACHE_EXT_METADATA; break; @@ -669,7 +669,7 @@ if (!path) { - path = g_build_filename(homedir(), cache_rc, base, name, NULL); + path = g_build_filename(cache_rc, base, name, NULL); if (mode) *mode = 0755; } @@ -695,7 +695,7 @@ { gchar *path; gchar *name = g_strconcat(source, cache_ext, NULL); - path = g_build_filename(homedir(), cache_rc, name, NULL); + path = g_build_filename(cache_rc, name, NULL); g_free(name); return path; @@ -794,4 +794,25 @@ return ret; } + +const gchar *get_thumbnails_cache_dir(void) +{ + static gchar *thumbnails_cache_dir = NULL; + + if (thumbnails_cache_dir) return thumbnails_cache_dir; + + thumbnails_cache_dir = g_build_filename(get_rc_dir(), GQ_CACHE_THUMB, NULL); + return thumbnails_cache_dir; +} + +const gchar *get_metadata_cache_dir(void) +{ + static gchar *metadata_cache_dir = NULL; + + if (metadata_cache_dir) return metadata_cache_dir; + + metadata_cache_dir = g_build_filename(get_rc_dir(), GQ_CACHE_METADATA, NULL); + return metadata_cache_dir; +} + /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/cache.h Sat Nov 15 10:35:43 2008 +0000 +++ b/src/cache.h Sat Nov 15 17:30:45 2008 +0000 @@ -18,8 +18,8 @@ #include "similar.h" -#define GQ_CACHE_RC_THUMB GQ_RC_DIR G_DIR_SEPARATOR_S "thumbnails" -#define GQ_CACHE_RC_METADATA GQ_RC_DIR G_DIR_SEPARATOR_S "metadata" +#define GQ_CACHE_THUMB "thumbnails" +#define GQ_CACHE_METADATA "metadata" #define GQ_CACHE_LOCAL_THUMB ".thumbnails" #define GQ_CACHE_LOCAL_METADATA ".metadata" @@ -74,6 +74,8 @@ gchar *cache_get_location(CacheType type, const gchar *source, gint include_name, mode_t *mode); gchar *cache_find_location(CacheType type, const gchar *source); +const gchar *get_thumbnails_cache_dir(void); +const gchar *get_metadata_cache_dir(void); #endif /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/cache_maint.c Sat Nov 15 10:35:43 2008 +0000 +++ b/src/cache_maint.c Sat Nov 15 17:30:45 2008 +0000 @@ -143,20 +143,17 @@ gboolean still_have_a_file = TRUE; gsize base_length; const gchar *cache_folder; - gchar *base; if (cm->metadata) { - cache_folder = GQ_CACHE_RC_METADATA; + cache_folder = get_metadata_cache_dir(); } else { - cache_folder = GQ_CACHE_RC_THUMB; + cache_folder = get_thumbnails_cache_dir(); } - base = g_build_filename(homedir(), cache_folder, NULL); - base_length = strlen(base); - g_free(base); + base_length = strlen(cache_folder); if (!cm->list) { @@ -276,7 +273,6 @@ { CMData *cm; GList *dlist; - gchar *base; FileData *dir_fd; const gchar *msg; const gchar *cache_folder; @@ -284,24 +280,21 @@ if (metadata) { - cache_folder = GQ_CACHE_RC_METADATA; + cache_folder = get_metadata_cache_dir(); } else { - cache_folder = GQ_CACHE_RC_THUMB; + cache_folder = get_thumbnails_cache_dir(); } - base = g_build_filename(homedir(), cache_folder, NULL); - dir_fd = file_data_new_simple(base); + dir_fd = file_data_new_simple(cache_folder); if (!filelist_read(dir_fd, NULL, &dlist)) { - g_free(base); file_data_unref(dir_fd); return; } dlist = g_list_append(dlist, dir_fd); - g_free(base); cm = g_new0(CMData, 1); cm->list = dlist; @@ -1246,7 +1239,7 @@ group = pref_group_new(gd->vbox, FALSE, _("Thumbnail cache"), GTK_ORIENTATION_VERTICAL); - cache_manager_location_label(group, GQ_CACHE_RC_THUMB); + cache_manager_location_label(group, get_thumbnails_cache_dir()); table = pref_table_new(group, 2, 2, FALSE, FALSE); @@ -1288,7 +1281,7 @@ group = pref_group_new(gd->vbox, FALSE, _("Metadata"), GTK_ORIENTATION_VERTICAL); - cache_manager_location_label(group, GQ_CACHE_RC_METADATA); + cache_manager_location_label(group, get_metadata_cache_dir()); table = pref_table_new(group, 2, 1, FALSE, FALSE);
--- a/src/collect-dlg.c Sat Nov 15 10:35:43 2008 +0000 +++ b/src/collect-dlg.c Sat Nov 15 17:30:45 2008 +0000 @@ -162,7 +162,6 @@ const gchar *title; const gchar *btntext; gpointer btnfunc; - gchar *base; const gchar *stock_id; if (type == DIALOG_SAVE || type == DIALOG_SAVE_CLOSE) @@ -200,10 +199,8 @@ generic_dialog_add_message(GENERIC_DIALOG(fd), NULL, title, NULL); file_dialog_add_button(fd, stock_id, btntext, btnfunc, TRUE); - base = g_build_filename(homedir(), GQ_RC_DIR_COLLECTIONS, NULL); - file_dialog_add_path_widgets(fd, base, path, + file_dialog_add_path_widgets(fd, get_collections_dir(), path, "collection_load_save", GQ_COLLECTION_EXT, _("Collection Files")); - g_free(base); fd->type = type;
--- a/src/collect-io.c Sat Nov 15 10:35:43 2008 +0000 +++ b/src/collect-io.c Sat Nov 15 17:30:45 2008 +0000 @@ -668,14 +668,11 @@ { GList *list; GList *work; - gchar *base; FileData *dir_fd; - base = g_build_filename(homedir(), GQ_RC_DIR_COLLECTIONS, NULL); - dir_fd = file_data_new_simple(base); + dir_fd = file_data_new_simple(get_collections_dir()); filelist_read(dir_fd, &list, NULL); file_data_unref(dir_fd); - g_free(base); work = collection_manager_entry_list; while (work && list)
--- a/src/main.c Sat Nov 15 10:35:43 2008 +0000 +++ b/src/main.c Sat Nov 15 17:30:45 2008 +0000 @@ -430,7 +430,7 @@ { gchar *path; - path = g_build_filename(homedir(), GQ_RC_DIR, RC_HISTORY_NAME, NULL); + path = g_build_filename(get_rc_dir(), RC_HISTORY_NAME, NULL); history_list_load(path); g_free(path); } @@ -439,26 +439,21 @@ { gchar *path; - path = g_build_filename(homedir(), GQ_RC_DIR, RC_HISTORY_NAME, NULL); + path = g_build_filename(get_rc_dir(), RC_HISTORY_NAME, NULL); history_list_save(path); g_free(path); } -static void check_for_home_path(gchar *path) +static void check_for_home_path(const gchar *path) { - gchar *buf; + if (isdir(path)) return; - buf = g_build_filename(homedir(), path, NULL); - if (!isdir(buf)) + log_printf(_("Creating %s dir:%s\n"), GQ_APPNAME, path); + + if (!mkdir_utf8(path, 0755)) { - log_printf(_("Creating %s dir:%s\n"), GQ_APPNAME, buf); - - if (!mkdir_utf8(buf, 0755)) - { - log_printf(_("Could not create dir:%s\n"), buf); - } + log_printf(_("Could not create dir:%s\n"), path); } - g_free(buf); } @@ -538,7 +533,7 @@ static gchar *accep_map_filename(void) { - return g_build_filename(homedir(), GQ_RC_DIR, "accels", NULL); + return g_build_filename(get_rc_dir(), "accels", NULL); } static void accel_map_save(void) @@ -569,7 +564,7 @@ /* If a gtkrc file exists in the rc directory, add it to the * list of files to be parsed at the end of gtk_init() */ - path = g_build_filename(homedir(), GQ_RC_DIR, "gtkrc", NULL); + path = g_build_filename(get_rc_dir(), "gtkrc", NULL); pathl = path_from_utf8(path); if (access(pathl, R_OK) == 0) gtk_rc_add_default_file(pathl); @@ -722,10 +717,10 @@ log_printf("!!! %s may quit unexpectedly with a relocation error.\n", GQ_APPNAME); } - check_for_home_path(GQ_RC_DIR); - check_for_home_path(GQ_RC_DIR_COLLECTIONS); - check_for_home_path(GQ_CACHE_RC_THUMB); - check_for_home_path(GQ_CACHE_RC_METADATA); + check_for_home_path(get_rc_dir()); + check_for_home_path(get_collections_dir()); + check_for_home_path(get_thumbnails_cache_dir()); + check_for_home_path(get_metadata_cache_dir()); keys_load(); filter_add_defaults(); @@ -856,7 +851,7 @@ if (startup_full_screen) layout_image_full_screen_start(lw); if (startup_in_slideshow) layout_image_slideshow_start(lw); - buf = g_build_filename(homedir(), GQ_RC_DIR, ".command", NULL); + buf = g_build_filename(get_rc_dir(), ".command", NULL); remote_connection = remote_server_init(buf, cd); g_free(buf);
--- a/src/main.h Sat Nov 15 10:35:43 2008 +0000 +++ b/src/main.h Sat Nov 15 17:30:45 2008 +0000 @@ -71,9 +71,9 @@ #define GQ_WMCLASS GQ_APPNAME_LC -#define GQ_RC_DIR "." GQ_APPNAME_LC -#define GQ_RC_DIR_COLLECTIONS GQ_RC_DIR G_DIR_SEPARATOR_S "collections" -#define GQ_RC_DIR_TRASH GQ_RC_DIR G_DIR_SEPARATOR_S "trash" +#define GQ_RC_DIR "." GQ_APPNAME_LC +#define GQ_COLLECTIONS_DIR "collections" +#define GQ_TRASH_DIR "trash" #define GQ_SYSTEM_WIDE_DIR "/etc/" GQ_APPNAME_LC
--- a/src/options.c Sat Nov 15 10:35:43 2008 +0000 +++ b/src/options.c Sat Nov 15 17:30:45 2008 +0000 @@ -183,12 +183,10 @@ path = g_build_filename(homedir(), "Desktop", NULL); bookmark_add_default(_("Desktop"), path); g_free(path); - path = g_build_filename(homedir(), GQ_RC_DIR_COLLECTIONS, NULL); - bookmark_add_default(_("Collections"), path); - g_free(path); + bookmark_add_default(_("Collections"), get_collections_dir()); g_free(options->file_ops.safe_delete_path); - options->file_ops.safe_delete_path = g_build_filename(homedir(), GQ_RC_DIR_TRASH, NULL); + options->file_ops.safe_delete_path = g_strdup(get_trash_dir()); for (i = 0; i < COLOR_PROFILE_INPUTS; i++) { @@ -260,7 +258,7 @@ sync_options_with_current_state(options); - rc_path = g_build_filename(homedir(), GQ_RC_DIR, RC_FILE_NAME, NULL); + rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL); save_options_to(rc_path, options); g_free(rc_path); } @@ -278,7 +276,7 @@ g_free(rc_path); } - rc_path = g_build_filename(homedir(), GQ_RC_DIR, RC_FILE_NAME, NULL); + rc_path = g_build_filename(get_rc_dir(), RC_FILE_NAME, NULL); success = load_options_from(rc_path, options); DEBUG_1("Loading options from %s ... %s", rc_path, success ? "done" : "failed"); g_free(rc_path);
--- a/src/remote.c Sat Nov 15 10:35:43 2008 +0000 +++ b/src/remote.c Sat Nov 15 17:30:45 2008 +0000 @@ -701,7 +701,7 @@ gint started = FALSE; gchar *buf; - buf = g_build_filename(homedir(), GQ_RC_DIR, ".command", NULL); + buf = g_build_filename(get_rc_dir(), ".command", NULL); rc = remote_client_open(buf); if (!rc) {
--- a/src/search.c Sat Nov 15 10:35:43 2008 +0000 +++ b/src/search.c Sat Nov 15 17:30:45 2008 +0000 @@ -2219,12 +2219,8 @@ else if (sd->search_type == SEARCH_MATCH_ALL) { /* search metadata */ - path = g_build_filename(homedir(), GQ_CACHE_RC_METADATA, NULL); - file_data_unref(sd->search_dir_fd); - sd->search_dir_fd = file_data_new_simple(path); - g_free(path); - + sd->search_dir_fd = file_data_new_simple(get_metadata_cache_dir()); search_start(sd); } else if (sd->search_type == SEARCH_MATCH_CONTAINS)
--- a/src/ui_fileops.c Sat Nov 15 10:35:43 2008 +0000 +++ b/src/ui_fileops.c Sat Nov 15 17:30:45 2008 +0000 @@ -186,6 +186,39 @@ return home; } +const gchar *get_rc_dir(void) +{ + static gchar *rc_dir = NULL; + + if (rc_dir) return rc_dir; + + rc_dir = g_build_filename(homedir(), GQ_RC_DIR, NULL); + + return rc_dir; +} + +const gchar *get_collections_dir(void) +{ + static gchar *collections_dir = NULL; + + if (collections_dir) return collections_dir; + + collections_dir = g_build_filename(get_rc_dir(), GQ_COLLECTIONS_DIR, NULL); + + return collections_dir; +} + +const gchar *get_trash_dir(void) +{ + static gchar *trash_dir = NULL; + + if (trash_dir) return trash_dir; + + trash_dir = g_build_filename(get_rc_dir(), GQ_TRASH_DIR, NULL); + + return trash_dir; +} + gint stat_utf8(const gchar *s, struct stat *st) { gchar *sl;
--- a/src/ui_fileops.h Sat Nov 15 10:35:43 2008 +0000 +++ b/src/ui_fileops.h Sat Nov 15 17:30:45 2008 +0000 @@ -35,6 +35,10 @@ gchar *path_from_utf8(const gchar *path); const gchar *homedir(void); +const gchar *get_rc_dir(void); +const gchar *get_collections_dir(void); +const gchar *get_trash_dir(void); + gint stat_utf8(const gchar *s, struct stat *st); gint lstat_utf8(const gchar *s, struct stat *st); gint isname(const gchar *s);