From bbe174ac085cd695ad9477df0a3af96f1e510358 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Fri, 15 Aug 2014 18:10:38 +0200 Subject: [PATCH] Add cache directory Signed-off-by: Sebastian Ramacher --- main.c | 3 +++ zathura.c | 15 +++++++++++++++ zathura.h | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/main.c b/main.c index c55d067..abc9101 100644 --- a/main.c +++ b/main.c @@ -41,6 +41,7 @@ main(int argc, char* argv[]) /* parse command line arguments */ gchar* config_dir = NULL; gchar* data_dir = NULL; + gchar* cache_dir = NULL; gchar* plugin_path = NULL; gchar* loglevel = NULL; gchar* password = NULL; @@ -57,6 +58,7 @@ main(int argc, char* argv[]) { "reparent", 'e', 0, G_OPTION_ARG_INT, &embed, _("Reparents to window specified by xid"), "xid" }, { "config-dir", 'c', 0, G_OPTION_ARG_FILENAME, &config_dir, _("Path to the config directory"), "path" }, { "data-dir", 'd', 0, G_OPTION_ARG_FILENAME, &data_dir, _("Path to the data directory"), "path" }, + { "cache-dir", '\0', 0, G_OPTION_ARG_FILENAME, &cache_dir, _("Path to the cache directory"), "path"}, { "plugins-dir", 'p', 0, G_OPTION_ARG_STRING, &plugin_path, _("Path to the directories containing plugins"), "path" }, { "fork", '\0', 0, G_OPTION_ARG_NONE, &forkback, _("Fork into the background"), NULL }, { "password", 'w', 0, G_OPTION_ARG_STRING, &password, _("Document password"), "password" }, @@ -156,6 +158,7 @@ main(int argc, char* argv[]) zathura_set_xid(zathura, embed); zathura_set_config_dir(zathura, config_dir); zathura_set_data_dir(zathura, data_dir); + zathura_set_cache_dir(zathura, cache_dir); zathura_set_plugin_dir(zathura, plugin_path); zathura_set_argv(zathura, argv); diff --git a/zathura.c b/zathura.c index b67950d..57cfe22 100644 --- a/zathura.c +++ b/zathura.c @@ -348,6 +348,7 @@ zathura_free(zathura_t* zathura) /* free config variables */ g_free(zathura->config.config_dir); g_free(zathura->config.data_dir); + g_free(zathura->config.cache_dir); /* free jumplist */ if (zathura->jumplist.list != NULL) { @@ -386,6 +387,8 @@ zathura_set_config_dir(zathura_t* zathura, const char* dir) void zathura_set_data_dir(zathura_t* zathura, const char* dir) { + g_return_if_fail(zathura != NULL); + if (dir != NULL) { zathura->config.data_dir = g_strdup(dir); } else { @@ -393,8 +396,20 @@ zathura_set_data_dir(zathura_t* zathura, const char* dir) zathura->config.data_dir = g_build_filename(path, "zathura", NULL); g_free(path); } +} +void +zathura_set_cache_dir(zathura_t* zathura, const char* dir) +{ g_return_if_fail(zathura != NULL); + + if (dir != NULL) { + zathura->config.cache_dir = g_strdup(dir); + } else { + gchar* path = girara_get_xdg_path(XDG_CACHE); + zathura->config.cache_dir = g_build_filename(path, "zathura", NULL); + g_free(path); + } } void diff --git a/zathura.h b/zathura.h index fda81ae..5722f69 100644 --- a/zathura.h +++ b/zathura.h @@ -127,6 +127,7 @@ struct zathura_s { gchar* config_dir; /**< Path to the configuration directory */ gchar* data_dir; /**< Path to the data directory */ + gchar* cache_dir; /**< Path to the cache directory */ } config; struct @@ -249,6 +250,14 @@ void zathura_set_config_dir(zathura_t* zathura, const char* dir); */ void zathura_set_data_dir(zathura_t* zathura, const char* dir); +/** + * Set the path to the cache directory. + * + * @param zathura The Zathura session + * @param dir Directory path + */ +void zathura_set_cache_dir(zathura_t* zathura, const char* dir); + /** * Set the path to the plugin directory *