From d6ee17e8cd1834a20e6f0f1a631ffb400233178d Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 9 Jan 2001 17:25:21 +0000 Subject: [PATCH] /LOAD without parameters prints loaded modules GLib warnings/criticals are now printed with printformat(), not into standard output messing up the screen. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1096 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/fe-common/core/fe-common-core.c | 26 +++++++++++++++++++ src/fe-common/core/fe-modules.c | 39 ++++++++++++++++++++++------- src/fe-common/core/module-formats.c | 4 +++ src/fe-common/core/module-formats.h | 6 ++++- 4 files changed, 65 insertions(+), 10 deletions(-) diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c index 200e6e30..5ad4a036 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -194,10 +194,36 @@ void fe_common_core_deinit(void) signal_remove("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed); } +void glog_func(const char *log_domain, GLogLevelFlags log_level, + const char *message) +{ + const char *reason; + + switch (log_level) { + case G_LOG_LEVEL_WARNING: + reason = "warning"; + break; + case G_LOG_LEVEL_CRITICAL: + reason = "critical"; + break; + default: + reason = "error"; + break; + } + + printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, + TXT_GLIB_ERROR, reason, message); +} + void fe_common_core_finish_init(void) { WINDOW_REC *window; + g_log_set_handler(G_LOG_DOMAIN, + (GLogLevelFlags) (G_LOG_LEVEL_CRITICAL | + G_LOG_LEVEL_WARNING), + (GLogFunc) glog_func, NULL); + signal_emit("irssi init read settings", 0); #ifdef SIGPIPE diff --git a/src/fe-common/core/fe-modules.c b/src/fe-common/core/fe-modules.c index 292d49b0..5a33d39e 100644 --- a/src/fe-common/core/fe-modules.c +++ b/src/fe-common/core/fe-modules.c @@ -27,38 +27,59 @@ #include "printtext.h" -static void sig_module_error(void *number, const char *module, const char *data) +static void sig_module_error(void *number, const char *module, + const char *data) { switch (GPOINTER_TO_INT(number)) { case MODULE_ERROR_ALREADY_LOADED: - printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_MODULE_ALREADY_LOADED, module); + printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, + TXT_MODULE_ALREADY_LOADED, module); break; case MODULE_ERROR_LOAD: - printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_MODULE_LOAD_ERROR, module, data); + printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, + TXT_MODULE_LOAD_ERROR, module, data); break; case MODULE_ERROR_INVALID: - printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_MODULE_INVALID, module); + printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, + TXT_MODULE_INVALID, module); break; } } static void sig_module_loaded(MODULE_REC *rec) { - printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_MODULE_LOADED, rec->name); + printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, + TXT_MODULE_LOADED, rec->name); } static void sig_module_unloaded(MODULE_REC *rec) { - printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_MODULE_UNLOADED, rec->name); + printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, + TXT_MODULE_UNLOADED, rec->name); +} + +static void cmd_load_list(void) +{ + GSList *tmp; + + printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_MODULE_HEADER); + for (tmp = modules; tmp != NULL; tmp = tmp->next) { + MODULE_REC *rec = tmp->data; + + printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, + TXT_MODULE_LINE, rec->name); + } + printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_MODULE_FOOTER); } /* SYNTAX: LOAD */ static void cmd_load(const char *data) { g_return_if_fail(data != NULL); - if (*data == '\0') cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS); - - module_load(data); + if (*data == '\0') + cmd_load_list(); + else + module_load(data); } /* SYNTAX: UNLOAD */ diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c index 4657cef6..a6f88ba0 100644 --- a/src/fe-common/core/module-formats.c +++ b/src/fe-common/core/module-formats.c @@ -150,6 +150,9 @@ FORMAT_REC fecommon_core_formats[] = { /* ---- */ { NULL, "Modules", 0 }, + { "module_header", "Loaded modules:", 0, }, + { "module_line", " $0", 1, { 0 } }, + { "module_footer", "", 0, }, { "module_already_loaded", "Module {hilight $0} already loaded", 1, { 0 } }, { "module_load_error", "Error loading module {hilight $0}: $1", 2, { 0, 0 } }, { "module_invalid", "{hilight $0} isn't Irssi module", 1, { 0 } }, @@ -203,6 +206,7 @@ FORMAT_REC fecommon_core_formats[] = { { "config_saved", "Saved configuration to file $0", 1, { 0 } }, { "config_reloaded", "Reloaded configuration", 1, { 0 } }, { "config_modified", "Configuration file was modified since irssi was last started - do you want to overwrite the possible changes?", 1, { 0 } }, + { "glib_error", "{error GLib $0} $1", 2, { 0, 0 } }, { NULL, NULL, 0 } }; diff --git a/src/fe-common/core/module-formats.h b/src/fe-common/core/module-formats.h index 1f0ea5fa..785693d7 100644 --- a/src/fe-common/core/module-formats.h +++ b/src/fe-common/core/module-formats.h @@ -120,6 +120,9 @@ enum { TXT_FILL_9, + TXT_MODULE_HEADER, + TXT_MODULE_LINE, + TXT_MODULE_FOOTER, TXT_MODULE_ALREADY_LOADED, TXT_MODULE_LOAD_ERROR, TXT_MODULE_INVALID, @@ -168,7 +171,8 @@ enum { TXT_BIND_UNKNOWN_ID, TXT_CONFIG_SAVED, TXT_CONFIG_RELOADED, - TXT_CONFIG_MODIFIED + TXT_CONFIG_MODIFIED, + TXT_GLIB_ERROR }; extern FORMAT_REC fecommon_core_formats[];