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
|
#ifndef IRSSI_COMMON_H
|
||||||
#define 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_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */
|
||||||
#define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */
|
#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_init(void);
|
||||||
void wcwidth_wrapper_deinit(void);
|
void wcwidth_wrapper_deinit(void);
|
||||||
|
|
||||||
|
int xdg_support;
|
||||||
int irssi_gui;
|
int irssi_gui;
|
||||||
int irssi_init_finished;
|
int irssi_init_finished;
|
||||||
int sighup_received;
|
int sighup_received;
|
||||||
time_t client_start_time;
|
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;
|
static GSList *dialog_type_queue, *dialog_text_queue;
|
||||||
|
|
||||||
|
int is_xdg_supported()
|
||||||
|
{
|
||||||
|
return xdg_support;
|
||||||
|
}
|
||||||
|
|
||||||
const char *get_irssi_dir(void)
|
const char *get_irssi_dir(void)
|
||||||
{
|
{
|
||||||
return irssi_dir;
|
return (xdg_support = 1) ? irssi_xdg_dir : irssi_dir;
|
||||||
}
|
|
||||||
|
|
||||||
const char *get_irssi_xdg_dir(void)
|
|
||||||
{
|
|
||||||
return irssi_xdg_dir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return full path for ~/.irssi/config */
|
/* return full path for ~/.irssi/config */
|
||||||
|
|
@ -194,19 +195,26 @@ void core_register_options(void)
|
||||||
|
|
||||||
void core_preinit(const char *path)
|
void core_preinit(const char *path)
|
||||||
{
|
{
|
||||||
|
struct stat statbuf;
|
||||||
|
const char *home;
|
||||||
char *str;
|
char *str;
|
||||||
int len;
|
int len;
|
||||||
const char *home;
|
|
||||||
|
|
||||||
if (irssi_dir == NULL) {
|
if (irssi_dir == NULL) {
|
||||||
irssi_dir = g_build_filename(g_get_user_config_dir(), "irssi", NULL);
|
/* check if %XDG_CONFIG_HOME/irssi exists and default to it */
|
||||||
if (g_file_test(irssi_dir, G_FILE_TEST_IS_DIR) == FALSE) {
|
char *dirp = g_build_filename(g_get_user_config_dir(), "irssi", NULL);
|
||||||
home = ".";
|
if (stat(dirp, &statbuf) == 0) {
|
||||||
g_free(irssi_dir);
|
xdg_support = 1;
|
||||||
|
irssi_dir = dirp;
|
||||||
|
} else { /* fallback to non-xdg location */
|
||||||
|
g_free(dirp);
|
||||||
|
home = g_get_home_dir();
|
||||||
|
if (home == NULL)
|
||||||
|
home = ".";
|
||||||
|
|
||||||
home = g_get_home_dir();
|
irssi_dir = g_strdup_printf(IRSSI_DIR_FULL, home);
|
||||||
irssi_dir = g_build_filename(home ? home : ".", ".irssi", NULL);
|
xdg_support = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
str = irssi_dir;
|
str = irssi_dir;
|
||||||
irssi_dir = fix_path(str);
|
irssi_dir = fix_path(str);
|
||||||
|
|
@ -216,7 +224,10 @@ void core_preinit(const char *path)
|
||||||
irssi_dir[len-1] = '\0';
|
irssi_dir[len-1] = '\0';
|
||||||
}
|
}
|
||||||
if (irssi_config_file == NULL)
|
if (irssi_config_file == NULL)
|
||||||
irssi_config_file = g_build_filename(irssi_dir, IRSSI_HOME_CONFIG, 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 {
|
else {
|
||||||
str = irssi_config_file;
|
str = irssi_config_file;
|
||||||
irssi_config_file = fix_path(str);
|
irssi_config_file = fix_path(str);
|
||||||
|
|
|
||||||
|
|
@ -599,6 +599,13 @@ PPCODE:
|
||||||
XPUSHs(sv_2mortal(new_pv(ret)));
|
XPUSHs(sv_2mortal(new_pv(ret)));
|
||||||
g_free_not_null(ret);
|
g_free_not_null(ret);
|
||||||
|
|
||||||
|
bool
|
||||||
|
is_xdg_supported()
|
||||||
|
CODE:
|
||||||
|
RETVAL = (bool) is_xdg_supported();
|
||||||
|
OUTPUT:
|
||||||
|
RETVAL
|
||||||
|
|
||||||
char *
|
char *
|
||||||
get_irssi_dir()
|
get_irssi_dir()
|
||||||
CODE:
|
CODE:
|
||||||
|
|
|
||||||
|
|
@ -390,43 +390,24 @@ char *perl_script_get_path(const char *name)
|
||||||
file = IS_PERL_SCRIPT(name) ? g_strdup(name) :
|
file = IS_PERL_SCRIPT(name) ? g_strdup(name) :
|
||||||
g_strdup_printf("%s.pl", name);
|
g_strdup_printf("%s.pl", name);
|
||||||
|
|
||||||
/* check from %XDG_DATA_HOME% */
|
/* check if xdg paths are being used, if so locate scripts based on that */
|
||||||
path = g_build_filename(g_get_user_data_dir(), "irssi/scripts/", file, NULL);
|
if (is_xdg_supported()) {
|
||||||
if (stat(path, &statbuf) != 0) {
|
path = g_build_filename(g_get_user_data_dir(), "irssi", "scripts", file, NULL);
|
||||||
g_free(path);
|
|
||||||
path = g_strdup_printf(SCRIPTDIR"/%s", file);
|
|
||||||
if (stat(path, &statbuf) != 0) {
|
if (stat(path, &statbuf) != 0) {
|
||||||
g_free(path);
|
g_free(path);
|
||||||
path = NULL;
|
path = NULL;
|
||||||
} else {
|
|
||||||
g_free(file);
|
|
||||||
return path;
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
/* check from ~/.irssi/scripts/ */
|
||||||
/* check from %XDG_CONFIG_HOME% */
|
path = g_strdup_printf("%s/scripts/%s", get_irssi_dir(), file);
|
||||||
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) {
|
if (stat(path, &statbuf) != 0) {
|
||||||
|
/* check from SCRIPTDIR */
|
||||||
g_free(path);
|
g_free(path);
|
||||||
path = NULL;
|
path = g_strdup_printf(SCRIPTDIR "/%s", file);
|
||||||
} else {
|
if (stat(path, &statbuf) != 0) {
|
||||||
g_free(file);
|
g_free(path);
|
||||||
return path;
|
path = NULL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* 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);
|
|
||||||
if (stat(path, &statbuf) != 0) {
|
|
||||||
g_free(path);
|
|
||||||
path = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_free(file);
|
g_free(file);
|
||||||
|
|
@ -452,8 +433,10 @@ void perl_scripts_autorun(void)
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
char *path, *fname;
|
char *path, *fname;
|
||||||
|
|
||||||
/* run *.pl scripts from ~/.irssi/scripts/autorun/ */
|
if (is_xdg_supported())
|
||||||
path = g_strdup_printf("%s/scripts/autorun", get_irssi_dir());
|
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);
|
dirp = opendir(path);
|
||||||
if (dirp == NULL) {
|
if (dirp == NULL) {
|
||||||
g_free(path);
|
g_free(path);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue