1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Introduce /reload command

This command reloads the configuration file.

Fix https://github.com/profanity-im/profanity/issues/627
This commit is contained in:
Michael Vetter 2019-10-04 14:06:25 +02:00
parent 523681a642
commit 5c77b97c35
5 changed files with 58 additions and 18 deletions

View File

@ -2408,6 +2408,19 @@ static struct cmd_t command_defs[] =
CMD_NOARGS CMD_NOARGS
CMD_NOEXAMPLES CMD_NOEXAMPLES
}, },
{ "/reload",
parse_args, 0, 0, NULL,
CMD_NOSUBFUNCS
CMD_MAINFUNC(cmd_reload)
CMD_NOTAGS
CMD_SYN(
"/reload")
CMD_DESC(
"Reload preferences from configuration file.")
CMD_NOARGS
CMD_NOEXAMPLES
},
}; };
static GHashTable *search_index; static GHashTable *search_index;

View File

@ -8551,3 +8551,12 @@ cmd_save(ProfWin *window, const char *const command, gchar **args)
prefs_save(); prefs_save();
return TRUE; return TRUE;
} }
gboolean
cmd_reload(ProfWin *window, const char *const command, gchar **args)
{
log_info("Reloading preferences");
cons_show("Reloading preferences.");
prefs_reload();
return TRUE;
}

View File

@ -227,4 +227,5 @@ gboolean cmd_omemo_policy(ProfWin *window, const char *const command, gchar **ar
gboolean cmd_omemo_clear_device_list(ProfWin *window, const char *const command, gchar **args); gboolean cmd_omemo_clear_device_list(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_save(ProfWin *window, const char *const command, gchar **args); gboolean cmd_save(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_reload(ProfWin *window, const char *const command, gchar **args);
#endif #endif

View File

@ -78,25 +78,9 @@ static const char* _get_key(preference_t pref);
static gboolean _get_default_boolean(preference_t pref); static gboolean _get_default_boolean(preference_t pref);
static char* _get_default_string(preference_t pref); static char* _get_default_string(preference_t pref);
void void _prefs_load(void)
prefs_load(char *config_file)
{ {
GError *err; GError *err = NULL;
if (config_file == NULL) {
prefs_loc = files_get_config_path(FILE_PROFRC);
} else {
prefs_loc = config_file;
}
if (g_file_test(prefs_loc, G_FILE_TEST_EXISTS)) {
g_chmod(prefs_loc, S_IRUSR | S_IWUSR);
}
prefs = g_key_file_new();
g_key_file_load_from_file(prefs, prefs_loc, G_KEY_FILE_KEEP_COMMENTS, NULL);
err = NULL;
log_maxsize = g_key_file_get_integer(prefs, PREF_GROUP_LOGGING, "maxsize", &err); log_maxsize = g_key_file_get_integer(prefs, PREF_GROUP_LOGGING, "maxsize", &err);
if (err) { if (err) {
log_maxsize = 0; log_maxsize = 0;
@ -180,6 +164,38 @@ prefs_load(char *config_file)
g_strfreev(triggers); g_strfreev(triggers);
} }
void
prefs_reload(void)
{
g_key_file_free(prefs);
prefs = NULL;
prefs = g_key_file_new();
g_key_file_load_from_file(prefs, prefs_loc, G_KEY_FILE_KEEP_COMMENTS, NULL);
_prefs_load();
}
void
prefs_load(char *config_file)
{
if (config_file == NULL) {
prefs_loc = files_get_config_path(FILE_PROFRC);
} else {
prefs_loc = config_file;
}
if (g_file_test(prefs_loc, G_FILE_TEST_EXISTS)) {
g_chmod(prefs_loc, S_IRUSR | S_IWUSR);
}
prefs = g_key_file_new();
g_key_file_load_from_file(prefs, prefs_loc, G_KEY_FILE_KEEP_COMMENTS, NULL);
_prefs_load();
}
void void
prefs_save(void) prefs_save(void)
{ {

View File

@ -169,6 +169,7 @@ typedef struct prof_winplacement_t {
void prefs_load(char *config_file); void prefs_load(char *config_file);
void prefs_save(void); void prefs_save(void);
void prefs_close(void); void prefs_close(void);
void prefs_reload(void);
char* prefs_find_login(char *prefix); char* prefs_find_login(char *prefix);
void prefs_reset_login_search(void); void prefs_reset_login_search(void);