mirror of
https://github.com/irssi/irssi.git
synced 2026-08-21 17:42:49 +02:00
implement API changes to accomodate for XDG
- add is_xdg_supported() (C and Perl). - use $XDG_CONFIG_HOME/irssi/ only when it is present. - fallback mechanism added. - scripts are run from $XDG_DATA_HOME/irssi/scripts/[autorun], if and only if xdg is used.
This commit is contained in:
parent
bfb9ca19f5
commit
e6b9a07f9a
4 changed files with 51 additions and 48 deletions
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef IRSSI_COMMON_H
|
||||
#define IRSSI_COMMON_H
|
||||
|
||||
#define IRSSI_DIR_FULL "%s/.irssi" /* %s = g_get_home_dir() */
|
||||
|
||||
#define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */
|
||||
#define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */
|
||||
|
||||
|
|
|
|||
|
|
@ -65,22 +65,23 @@ void log_away_deinit(void);
|
|||
void wcwidth_wrapper_init(void);
|
||||
void wcwidth_wrapper_deinit(void);
|
||||
|
||||
int xdg_support;
|
||||
int irssi_gui;
|
||||
int irssi_init_finished;
|
||||
int sighup_received;
|
||||
time_t client_start_time;
|
||||
|
||||
static char *irssi_dir, *irssi_xdg_dir, *irssi_config_file;
|
||||
static char *irssi_dir, *irssi_config_file;
|
||||
static GSList *dialog_type_queue, *dialog_text_queue;
|
||||
|
||||
int is_xdg_supported()
|
||||
{
|
||||
return xdg_support;
|
||||
}
|
||||
|
||||
const char *get_irssi_dir(void)
|
||||
{
|
||||
return irssi_dir;
|
||||
}
|
||||
|
||||
const char *get_irssi_xdg_dir(void)
|
||||
{
|
||||
return irssi_xdg_dir;
|
||||
return (xdg_support = 1) ? irssi_xdg_dir : irssi_dir;
|
||||
}
|
||||
|
||||
/* return full path for ~/.irssi/config */
|
||||
|
|
@ -194,18 +195,25 @@ void core_register_options(void)
|
|||
|
||||
void core_preinit(const char *path)
|
||||
{
|
||||
struct stat statbuf;
|
||||
const char *home;
|
||||
char *str;
|
||||
int len;
|
||||
const char *home;
|
||||
|
||||
if (irssi_dir == NULL) {
|
||||
irssi_dir = g_build_filename(g_get_user_config_dir(), "irssi", NULL);
|
||||
if (g_file_test(irssi_dir, G_FILE_TEST_IS_DIR) == FALSE) {
|
||||
home = ".";
|
||||
g_free(irssi_dir);
|
||||
|
||||
/* check if %XDG_CONFIG_HOME/irssi exists and default to it */
|
||||
char *dirp = g_build_filename(g_get_user_config_dir(), "irssi", NULL);
|
||||
if (stat(dirp, &statbuf) == 0) {
|
||||
xdg_support = 1;
|
||||
irssi_dir = dirp;
|
||||
} else { /* fallback to non-xdg location */
|
||||
g_free(dirp);
|
||||
home = g_get_home_dir();
|
||||
irssi_dir = g_build_filename(home ? home : ".", ".irssi", NULL);
|
||||
if (home == NULL)
|
||||
home = ".";
|
||||
|
||||
irssi_dir = g_strdup_printf(IRSSI_DIR_FULL, home);
|
||||
xdg_support = 0;
|
||||
}
|
||||
} else {
|
||||
str = irssi_dir;
|
||||
|
|
@ -216,7 +224,10 @@ void core_preinit(const char *path)
|
|||
irssi_dir[len-1] = '\0';
|
||||
}
|
||||
if (irssi_config_file == NULL)
|
||||
if (is_xdg_supported())
|
||||
irssi_config_file = g_build_filename(irssi_dir, IRSSI_HOME_CONFIG, NULL);
|
||||
else
|
||||
irssi_config_file = g_strdup_printf("%s/" IRSSI_HOME_CONFIG, irssi_dir);
|
||||
else {
|
||||
str = irssi_config_file;
|
||||
irssi_config_file = fix_path(str);
|
||||
|
|
|
|||
|
|
@ -599,6 +599,13 @@ PPCODE:
|
|||
XPUSHs(sv_2mortal(new_pv(ret)));
|
||||
g_free_not_null(ret);
|
||||
|
||||
bool
|
||||
is_xdg_supported()
|
||||
CODE:
|
||||
RETVAL = (bool) is_xdg_supported();
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
char *
|
||||
get_irssi_dir()
|
||||
CODE:
|
||||
|
|
|
|||
|
|
@ -390,45 +390,26 @@ char *perl_script_get_path(const char *name)
|
|||
file = IS_PERL_SCRIPT(name) ? g_strdup(name) :
|
||||
g_strdup_printf("%s.pl", name);
|
||||
|
||||
/* check from %XDG_DATA_HOME% */
|
||||
path = g_build_filename(g_get_user_data_dir(), "irssi/scripts/", file, NULL);
|
||||
if (stat(path, &statbuf) != 0) {
|
||||
g_free(path);
|
||||
path = g_strdup_printf(SCRIPTDIR"/%s", file);
|
||||
/* check if xdg paths are being used, if so locate scripts based on that */
|
||||
if (is_xdg_supported()) {
|
||||
path = g_build_filename(g_get_user_data_dir(), "irssi", "scripts", file, NULL);
|
||||
if (stat(path, &statbuf) != 0) {
|
||||
g_free(path);
|
||||
path = NULL;
|
||||
}
|
||||
} else {
|
||||
g_free(file);
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
/* check from %XDG_CONFIG_HOME% */
|
||||
path = g_build_filename(g_get_user_config_dir(), "irssi/scripts/", file, NULL);
|
||||
if (stat(path, &statbuf) != 0) {
|
||||
g_free(path);
|
||||
path = g_strdup_printf(SCRIPTDIR"/%s", file);
|
||||
if (stat(path, &statbuf) != 0) {
|
||||
g_free(path);
|
||||
path = NULL;
|
||||
} else {
|
||||
g_free(file);
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
/* check from ~/.irssi/scripts/ */
|
||||
path = g_strdup_printf("%s/scripts/%s", get_irssi_dir(), file);
|
||||
if (stat(path, &statbuf) != 0) {
|
||||
/* check from SCRIPTDIR */
|
||||
g_free(path);
|
||||
path = g_strdup_printf(SCRIPTDIR"/%s", file);
|
||||
path = g_strdup_printf(SCRIPTDIR "/%s", file);
|
||||
if (stat(path, &statbuf) != 0) {
|
||||
g_free(path);
|
||||
path = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
g_free(file);
|
||||
return path;
|
||||
}
|
||||
|
|
@ -452,7 +433,9 @@ void perl_scripts_autorun(void)
|
|||
struct stat statbuf;
|
||||
char *path, *fname;
|
||||
|
||||
/* run *.pl scripts from ~/.irssi/scripts/autorun/ */
|
||||
if (is_xdg_supported())
|
||||
path = g_build_filename(g_get_user_data_dir(), "irssi", "scripts", "autorun", NULL);
|
||||
else
|
||||
path = g_strdup_printf("%s/scripts/autorun", get_irssi_dir());
|
||||
dirp = opendir(path);
|
||||
if (dirp == NULL) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue