add themes XDG support

- fix is_xdg_supported() not being in common.h
- themes are now loaded from $XDG_DATA_HOME, if and only if xdg paths
are being used
This commit is contained in:
altffour 2021-01-06 19:20:09 +03:00
commit dad31bdfde
No known key found for this signature in database
GPG key ID: B4ADFA86EDF5CCE9
4 changed files with 20 additions and 8 deletions

View file

@ -932,7 +932,11 @@ THEME_REC *theme_load(const char *setname)
theme = theme_find(name);
/* check home dir */
fname = g_strdup_printf("%s/%s.theme", get_irssi_dir(), name);
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);
if (stat(fname, &statbuf) != 0) {
/* check global config dir */
g_free(fname);
@ -1256,8 +1260,11 @@ static void theme_save(THEME_REC *theme, int save_all)
g_hash_table_foreach(theme->modules, (GHFunc) module_save, &data);
basename = g_path_get_basename(theme->path);
/* always save the theme to ~/.irssi/ */
path = g_strdup_printf("%s/%s", get_irssi_dir(), basename);
/* 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);
ok = config_write(config, path, 0660) == 0;
g_free(basename);
@ -1413,7 +1420,10 @@ void themes_reload(void)
/* first there's default theme.. */
current_theme = theme_load("default");
if (current_theme == NULL) {
fname = g_strdup_printf("%s/default.theme", get_irssi_dir());
if (is_xdg_supported())
fname = g_build_filename(g_get_user_data_dir(), "irssi", "default.theme");
else
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);