diff --git a/src/core/commands.c b/src/core/commands.c index 48489db7..31626a25 100644 --- a/src/core/commands.c +++ b/src/core/commands.c @@ -673,21 +673,6 @@ static void cmd_cd(const char *data) g_free(str); } -static void cmd_reload(const char *data) -{ - char *fname; - - fname = *data != '\0' ? g_strdup(data) : - g_strdup_printf("%s/.irssi/config", g_get_home_dir()); - settings_reread(fname); - g_free(fname); -} - -static void cmd_save(const char *data) -{ - settings_save(*data != '\0' ? data : NULL); -} - void commands_init(void) { commands = NULL; @@ -701,8 +686,6 @@ void commands_init(void) command_bind("eval", NULL, (SIGNAL_FUNC) cmd_eval); command_bind("cd", NULL, (SIGNAL_FUNC) cmd_cd); - command_bind("reload", NULL, (SIGNAL_FUNC) cmd_reload); - command_bind("save", NULL, (SIGNAL_FUNC) cmd_save); } void commands_deinit(void) @@ -714,6 +697,4 @@ void commands_deinit(void) command_unbind("eval", (SIGNAL_FUNC) cmd_eval); command_unbind("cd", (SIGNAL_FUNC) cmd_cd); - command_unbind("reload", (SIGNAL_FUNC) cmd_reload); - command_unbind("save", (SIGNAL_FUNC) cmd_save); } diff --git a/src/core/settings.c b/src/core/settings.c index b9d73d1d..5fa61064 100644 --- a/src/core/settings.c +++ b/src/core/settings.c @@ -285,7 +285,7 @@ static void init_configfile(void) signal(SIGTERM, sig_term); } -void settings_reread(const char *fname) +int settings_reread(const char *fname) { CONFIG_REC *tempconfig; char *str; @@ -298,7 +298,7 @@ void settings_reread(const char *fname) if (tempconfig == NULL) { signal_emit("gui dialog", 2, "error", g_strerror(errno)); - return; + return FALSE; } if (config_last_error(tempconfig) != NULL) { @@ -308,7 +308,7 @@ void settings_reread(const char *fname) g_free(str); config_close(tempconfig); - return; + return FALSE; } config_close(mainconfig); @@ -316,20 +316,22 @@ void settings_reread(const char *fname) signal_emit("setup changed", 0); signal_emit("setup reread", 0); + return TRUE; } -void settings_save(const char *fname) +int settings_save(const char *fname) { char *str; if (config_write(mainconfig, fname, 0660) == 0) - return; + return TRUE; /* error */ str = g_strdup_printf(_("Couldn't save configuration file: %s"), config_last_error(mainconfig)); signal_emit("gui dialog", 2, "error", str); g_free(str); + return FALSE; } void settings_init(void) diff --git a/src/core/settings.h b/src/core/settings.h index 583e0dd6..0a53a6ee 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -54,8 +54,8 @@ GSList *settings_get_sorted(void); SETTINGS_REC *settings_get_record(const char *key); /* if `fname' is NULL, the default is used */ -void settings_reread(const char *fname); -void settings_save(const char *fname); +int settings_reread(const char *fname); +int settings_save(const char *fname); void settings_init(void); void settings_deinit(void); diff --git a/src/fe-common/core/fe-settings.c b/src/fe-common/core/fe-settings.c index 75e50790..cb88c545 100644 --- a/src/fe-common/core/fe-settings.c +++ b/src/fe-common/core/fe-settings.c @@ -227,12 +227,36 @@ static void cmd_unalias(const char *data) alias_remove(data); } +static void cmd_reload(const char *data) +{ + char *fname; + + fname = *data != '\0' ? g_strdup(data) : + g_strdup_printf("%s/.irssi/config", g_get_home_dir()); + if (settings_reread(fname)) { + printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, + IRCTXT_CONFIG_RELOADED, fname); + } + g_free(fname); +} + +static void cmd_save(const char *data) +{ + if (settings_save(*data != '\0' ? data : NULL)) { + printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, + IRCTXT_CONFIG_SAVED, *data != '\0' ? data : + mainconfig->fname); + } +} + void fe_settings_init(void) { command_bind("set", NULL, (SIGNAL_FUNC) cmd_set); command_bind("toggle", NULL, (SIGNAL_FUNC) cmd_toggle); command_bind("alias", NULL, (SIGNAL_FUNC) cmd_alias); command_bind("unalias", NULL, (SIGNAL_FUNC) cmd_unalias); + command_bind("reload", NULL, (SIGNAL_FUNC) cmd_reload); + command_bind("save", NULL, (SIGNAL_FUNC) cmd_save); command_set_options("set", "clear"); } @@ -243,4 +267,6 @@ void fe_settings_deinit(void) command_unbind("toggle", (SIGNAL_FUNC) cmd_toggle); command_unbind("alias", (SIGNAL_FUNC) cmd_alias); command_unbind("unalias", (SIGNAL_FUNC) cmd_unalias); + command_unbind("reload", (SIGNAL_FUNC) cmd_reload); + command_unbind("save", (SIGNAL_FUNC) cmd_save); } diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c index d98cb33e..0f37dbab 100644 --- a/src/fe-common/core/module-formats.c +++ b/src/fe-common/core/module-formats.c @@ -121,6 +121,8 @@ FORMAT_REC fecommon_core_formats[] = { { "perl_error", "Perl error: $0", 1, { 0 } }, { "bind_key", "$[10]0 $1 $2", 3, { 0, 0, 0 } }, { "bind_unknown_id", "Unknown bind action: $0", 1, { 0 } }, + { "config_saved", "Saved configuration to file $0", 1, { 0 } }, + { "config_reloaded", "Reloaded configuration", 1, { 0 } }, { NULL, NULL, 0 } }; diff --git a/src/fe-common/core/module-formats.h b/src/fe-common/core/module-formats.h index 969d9d2f..6e315be9 100644 --- a/src/fe-common/core/module-formats.h +++ b/src/fe-common/core/module-formats.h @@ -91,8 +91,9 @@ enum { IRCTXT_NOT_TOGGLE, IRCTXT_PERL_ERROR, IRCTXT_BIND_KEY, - IRCTXT_BIND_UNKNOWN_ID - + IRCTXT_BIND_UNKNOWN_ID, + IRCTXT_CONFIG_SAVED, + IRCTXT_CONFIG_RELOADED }; extern FORMAT_REC fecommon_core_formats[];