xdg: implement a better way

Brief about changes:
- add get_irssi_cache_dir()
- add get_irssi_runtime_dir()
- remove is_xdg_supported()

About the proposed implementation:
- use XDG only when the user has the XDG_CONFIG_HOME/irssi directory
- irssi_dir would equal XDG_DATA_HOME/irssi or ~/.irssi, depending on
whether XDG is enabled or not, respectively.
- if xdg is enabled, variables irssi_cache, irssi_runtime, would equal
their respective XDG paths.
- if xdg is *not* enabled, variables irssi_cache, irssi_runtime, would
equal irssi_dir

Notes for future code:
- functions that use the irssi config file would use get_irssi_config()
- functions that use the irssi data directory would use get_irssi_dir()
- functions that use the irssi cache directory would use
get_irssi_cache_dir()
- functions that use the irssi runtime directory would use
get_irssi_runtime_dir()

Stuff that are still missing for complete implementation:
- add checks to ensure the new referenced directories are present
- docs
This commit is contained in:
altffour 2021-01-07 13:26:45 +03:00
commit 4059827741
No known key found for this signature in database
GPG key ID: B4ADFA86EDF5CCE9
9 changed files with 50 additions and 75 deletions

View file

@ -932,11 +932,7 @@ THEME_REC *theme_load(const char *setname)
theme = theme_find(name);
/* check home dir */
if (is_xdg_supported())
fname = g_build_filename(g_get_user_data_dir(), "irssi",
g_strdup_printf("%s.theme", name), NULL);
else
fname = g_strdup_printf("%s/%s.theme", get_irssi_dir(), name, NULL);
fname = g_strdup_printf("%s/%s.theme", get_irssi_dir(), name, NULL);
if (stat(fname, &statbuf) != 0) {
/* check global config dir */
g_free(fname);
@ -1261,10 +1257,7 @@ static void theme_save(THEME_REC *theme, int save_all)
basename = g_path_get_basename(theme->path);
/* always save the theme */
if (is_xdg_supported())
path = g_build_filename(g_get_user_data_dir(), "irssi", basename, NULL);
else
path = g_strdup_printf("%s/%s", get_irssi_dir(), basename, NULL);
path = g_strdup_printf("%s/%s", get_irssi_dir(), basename, NULL);
ok = config_write(config, path, 0660) == 0;
g_free(basename);
@ -1420,11 +1413,7 @@ void themes_reload(void)
/* first there's default theme.. */
current_theme = theme_load("default");
if (current_theme == NULL) {
if (is_xdg_supported())
fname =
g_build_filename(g_get_user_data_dir(), "irssi", "default.theme", NULL);
else
fname = g_strdup_printf("%s/default.theme", get_irssi_dir());
fname = g_strdup_printf("%s/default.theme", get_irssi_dir());
current_theme = theme_create(fname, "default");
current_theme->default_color = -1;
theme_read(current_theme, NULL);