diff options
-rw-r--r-- | src/core/chat-commands.c | 2 | ||||
-rw-r--r-- | src/core/expandos.c | 90 | ||||
-rw-r--r-- | src/core/expandos.h | 4 | ||||
-rw-r--r-- | src/core/signals.c | 21 | ||||
-rw-r--r-- | src/core/signals.h | 1 | ||||
-rw-r--r-- | src/core/special-vars.c | 96 | ||||
-rw-r--r-- | src/core/special-vars.h | 13 | ||||
-rw-r--r-- | src/fe-common/core/fe-expandos.c | 12 | ||||
-rw-r--r-- | src/fe-common/core/fe-log.c | 3 | ||||
-rw-r--r-- | src/fe-common/core/fe-messages.c | 2 | ||||
-rw-r--r-- | src/fe-common/core/formats.c | 6 | ||||
-rw-r--r-- | src/fe-common/core/themes.c | 6 | ||||
-rw-r--r-- | src/fe-text/gui-readline.c | 4 | ||||
-rw-r--r-- | src/fe-text/gui-windows.c | 96 | ||||
-rw-r--r-- | src/fe-text/gui-windows.h | 2 | ||||
-rw-r--r-- | src/irc/core/ctcp.c | 2 | ||||
-rw-r--r-- | src/irc/core/irc-commands.c | 2 |
17 files changed, 291 insertions, 71 deletions
diff --git a/src/core/chat-commands.c b/src/core/chat-commands.c index f2cae1ab..969be382 100644 --- a/src/core/chat-commands.c +++ b/src/core/chat-commands.c @@ -81,7 +81,7 @@ static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item) free_ret = FALSE; if (strcmp(target, ",") == 0 || strcmp(target, ".") == 0) { target = parse_special(&target, server, item, - NULL, &free_ret, NULL); + NULL, &free_ret, NULL, 0); } else if (strcmp(target, "*") == 0 && item != NULL) target = item->name; diff --git a/src/core/expandos.c b/src/core/expandos.c index 1dbd95ac..37f770a3 100644 --- a/src/core/expandos.c +++ b/src/core/expandos.c @@ -44,6 +44,8 @@ typedef struct { int signal_args[MAX_EXPANDO_SIGNALS]; } EXPANDO_REC; +static int timer_tag; + static EXPANDO_REC *char_expandos[127]; static GHashTable *expandos; static time_t client_start_time; @@ -86,6 +88,14 @@ void expando_create(const char *key, EXPANDO_FUNC func, ...) va_end(va); } +static EXPANDO_REC *expando_find(const char *key) +{ + if (key[1] != '\0') + return g_hash_table_lookup(expandos, key); + else + return char_expandos[(int) *key]; +} + /* Add new signal to expando */ void expando_add_signal(const char *key, const char *signal, ExpandoArg arg) { @@ -94,15 +104,15 @@ void expando_add_signal(const char *key, const char *signal, ExpandoArg arg) g_return_if_fail(key != NULL); g_return_if_fail(signal != NULL); - if (key[1] != '\0') - rec = g_hash_table_lookup(expandos, key); - else { - /* single character expando */ - rec = char_expandos[(int) *key]; - } + rec = expando_find(key); g_return_if_fail(rec != NULL); - if (rec->signals < MAX_EXPANDO_SIGNALS) { + if (arg == EXPANDO_NEVER) { + /* expando changes never */ + rec->signals = -1; + } else if (rec->signals < MAX_EXPANDO_SIGNALS) { + g_return_if_fail(rec->signals != -1); + rec->signal_ids[rec->signals] = signal_get_uniq_id(signal); rec->signal_args[rec->signals] = arg; rec->signals++; @@ -135,6 +145,64 @@ void expando_destroy(const char *key, EXPANDO_FUNC func) } } +void expando_bind(const char *key, int funccount, SIGNAL_FUNC *funcs) +{ + SIGNAL_FUNC func; + EXPANDO_REC *rec; + int n, arg; + + g_return_if_fail(key != NULL); + g_return_if_fail(funccount >= 1); + g_return_if_fail(funcs != NULL); + g_return_if_fail(funcs[0] != NULL); + + rec = expando_find(key); + g_return_if_fail(rec != NULL); + + if (rec->signals == 0) { + /* it's unknown when this expando changes.. + check it once in a second */ + signal_add("expando timer", funcs[EXPANDO_ARG_NONE]); + } + + for (n = 0; n < rec->signals; n++) { + arg = rec->signal_args[n]; + func = arg < funccount ? funcs[arg] : NULL; + if (func == NULL) func = funcs[EXPANDO_ARG_NONE]; + + signal_add_to_id(MODULE_NAME, 1, rec->signal_ids[n], func); + } +} + +void expando_unbind(const char *key, int funccount, SIGNAL_FUNC *funcs) +{ + SIGNAL_FUNC func; + EXPANDO_REC *rec; + int n, arg; + + g_return_if_fail(key != NULL); + g_return_if_fail(funccount >= 1); + g_return_if_fail(funcs != NULL); + g_return_if_fail(funcs[0] != NULL); + + rec = expando_find(key); + g_return_if_fail(rec != NULL); + + if (rec->signals == 0) { + /* it's unknown when this expando changes.. + check it once in a second */ + signal_remove("expando timer", funcs[EXPANDO_ARG_NONE]); + } + + for (n = 0; n < rec->signals; n++) { + arg = rec->signal_args[n]; + func = arg < funccount ? funcs[arg] : NULL; + if (func == NULL) func = funcs[EXPANDO_ARG_NONE]; + + signal_remove_id(rec->signal_ids[n], func); + } +} + EXPANDO_FUNC expando_find_char(char chr) { g_return_val_if_fail(chr < sizeof(char_expandos) / @@ -360,6 +428,12 @@ static void cmd_msg(const char *data, SERVER_REC *server) cmd_params_free(free_arg); } +static int sig_timer(void) +{ + signal_emit("expando timer", 0); + return 1; +} + void expandos_init(void) { #ifdef HAVE_SYS_UTSNAME_H @@ -455,6 +529,7 @@ void expandos_init(void) "window changed", EXPANDO_ARG_NONE, "window server changed", EXPANDO_ARG_WINDOW, NULL); + timer_tag = g_timeout_add(1000, (GSourceFunc) sig_timer, NULL); signal_add("command msg", (SIGNAL_FUNC) cmd_msg); signal_add("message public", (SIGNAL_FUNC) sig_message_public); signal_add("message private", (SIGNAL_FUNC) sig_message_private); @@ -479,6 +554,7 @@ void expandos_deinit(void) g_free_not_null(last_privmsg_from); g_free_not_null(last_public_from); g_free_not_null(sysname); g_free_not_null(sysrelease); + g_source_remove(timer_tag); signal_remove("message public", (SIGNAL_FUNC) sig_message_public); signal_remove("message private", (SIGNAL_FUNC) sig_message_private); signal_remove("command msg", (SIGNAL_FUNC) cmd_msg); diff --git a/src/core/expandos.h b/src/core/expandos.h index 2ce00ecc..a937fcd1 100644 --- a/src/core/expandos.h +++ b/src/core/expandos.h @@ -1,6 +1,7 @@ #ifndef __EXPANDOS_H #define __EXPANDOS_H +#include "signals.h" #include "servers.h" /* first argument of signal must match to active .. */ @@ -25,6 +26,9 @@ void expando_add_signal(const char *key, const char *signal, ExpandoArg arg); /* Destroy expando */ void expando_destroy(const char *key, EXPANDO_FUNC func); +void expando_bind(const char *key, int funccount, SIGNAL_FUNC *funcs); +void expando_unbind(const char *key, int funccount, SIGNAL_FUNC *funcs); + /* internal: */ EXPANDO_FUNC expando_find_char(char chr); EXPANDO_FUNC expando_find_long(const char *key); diff --git a/src/core/signals.c b/src/core/signals.c index 710d0687..3c1e4281 100644 --- a/src/core/signals.c +++ b/src/core/signals.c @@ -146,25 +146,24 @@ static int signal_remove_from_lists(SIGNAL_REC *rec, int signal_id, return 0; } -/* unbind signal */ -void signal_remove(const char *signal, SIGNAL_FUNC func) +void signal_remove_id(int signal_id, SIGNAL_FUNC func) { SIGNAL_REC *rec; - int signal_id, found; - g_return_if_fail(signal != NULL); + g_return_if_fail(signal_id >= 0); g_return_if_fail(func != NULL); - signal_id = signal_get_uniq_id(signal); - rec = g_hash_table_lookup(signals, GINT_TO_POINTER(signal_id)); - found = rec == NULL ? 0 : + if (rec != NULL) signal_remove_from_lists(rec, signal_id, func); +} - if (!found) { - g_warning("signal_remove() : signal \"%s\" isn't " - "grabbed for %p", signal, func); - } +/* unbind signal */ +void signal_remove(const char *signal, SIGNAL_FUNC func) +{ + g_return_if_fail(signal != NULL); + + signal_remove_id(signal_get_uniq_id(signal), func); } /* Remove all NULL functions from signal list */ diff --git a/src/core/signals.h b/src/core/signals.h index 24e0ecbf..f1fabf6c 100644 --- a/src/core/signals.h +++ b/src/core/signals.h @@ -23,6 +23,7 @@ void signal_add_to_id(const char *module, int pos, /* unbind signal */ void signal_remove(const char *signal, SIGNAL_FUNC func); +void signal_remove_id(int signal_id, SIGNAL_FUNC func); /* emit signal */ int signal_emit(const char *signal, int params, ...); diff --git a/src/core/special-vars.c b/src/core/special-vars.c index f3f7cf14..7d4deb78 100644 --- a/src/core/special-vars.c +++ b/src/core/special-vars.c @@ -125,7 +125,7 @@ static char *get_long_variable_value(const char *key, SERVER_REC *server, } static char *get_long_variable(char **cmd, SERVER_REC *server, - void *item, int *free_ret) + void *item, int *free_ret, int getname) { char *start, *var, *ret; @@ -134,30 +134,41 @@ static char *get_long_variable(char **cmd, SERVER_REC *server, while (isvarchar((*cmd)[1])) (*cmd)++; var = g_strndup(start, (int) (*cmd-start)+1); + if (getname) { + *free_ret = TRUE; + return var; + } ret = get_long_variable_value(var, server, item, free_ret); g_free(var); return ret; } -/* return the value of the variable found from `cmd' */ +/* return the value of the variable found from `cmd'. + if 'getname' is TRUE, return the name of the variable instead it's value */ static char *get_variable(char **cmd, SERVER_REC *server, void *item, - char **arglist, int *free_ret, int *arg_used) + char **arglist, int *free_ret, int *arg_used, + int getname) { EXPANDO_FUNC func; if (isdigit(**cmd) || **cmd == '*' || **cmd == '-' || **cmd == '~') { - /* argument */ + /* argument */ *free_ret = TRUE; if (arg_used != NULL) *arg_used = TRUE; - return get_argument(cmd, arglist); + return getname ? g_strdup_printf("%c", **cmd) : + get_argument(cmd, arglist); } if (isalpha(**cmd) && isvarchar((*cmd)[1])) { /* long variable name.. */ - return get_long_variable(cmd, server, item, free_ret); + return get_long_variable(cmd, server, item, free_ret, getname); } /* single character variable. */ + if (getname) { + *free_ret = TRUE; + return g_strdup_printf("%c", **cmd); + } *free_ret = FALSE; func = expando_find_char(**cmd); return func == NULL ? NULL : func(server, item, free_ret); @@ -184,13 +195,17 @@ static char *get_history(char **cmd, void *item, int *free_ret) } static char *get_special_value(char **cmd, SERVER_REC *server, void *item, - char **arglist, int *free_ret, int *arg_used) + char **arglist, int *free_ret, int *arg_used, + int flags) { char command, *value, *p; int len; if (**cmd == '!') { /* find text from command history */ + if (flags & PARSE_FLAG_GETNAME) + return "!"; + return get_history(cmd, item, free_ret); } @@ -203,12 +218,19 @@ static char *get_special_value(char **cmd, SERVER_REC *server, void *item, /* default to $* */ char *temp_cmd = "*"; + if (flags & PARSE_FLAG_GETNAME) + return "*"; + *free_ret = TRUE; return get_argument(&temp_cmd, arglist); } } - value = get_variable(cmd, server, item, arglist, free_ret, arg_used); + value = get_variable(cmd, server, item, arglist, free_ret, + arg_used, flags & PARSE_FLAG_GETNAME); + + if (flags & PARSE_FLAG_GETNAME) + return value; if (command == '#') { /* number of words */ @@ -314,7 +336,7 @@ static char *get_alignment(const char *text, int align, int flags, char pad) /* Parse and expand text after '$' character. return value has to be g_free()'d if `free_ret' is TRUE. */ char *parse_special(char **cmd, SERVER_REC *server, void *item, - char **arglist, int *free_ret, int *arg_used) + char **arglist, int *free_ret, int *arg_used, int flags) { static char **nested_orig_cmd = NULL; /* FIXME: KLUDGE! */ char command, *value; @@ -355,7 +377,8 @@ char *parse_special(char **cmd, SERVER_REC *server, void *item, } else { (*cmd)++; nest_value = parse_special(cmd, server, item, arglist, - &nest_free, arg_used); + &nest_free, arg_used, + flags); } while ((*nested_orig_cmd)[1] != '\0') { @@ -377,10 +400,13 @@ char *parse_special(char **cmd, SERVER_REC *server, void *item, } value = get_special_value(cmd, server, item, arglist, - free_ret, arg_used); + free_ret, arg_used, flags); if (**cmd == '\0') g_error("parse_special() : buffer overflow!"); + if (value != NULL && *value != '\0' && (flags & PARSE_FLAG_ISSET_ANY)) + *arg_used = TRUE; + if (brackets) { while (**cmd != '}' && (*cmd)[1] != '\0') (*cmd)++; @@ -388,7 +414,7 @@ char *parse_special(char **cmd, SERVER_REC *server, void *item, if (nest_free) g_free(nest_value); - if (command == '[') { + if (command == '[' && (flags & PARSE_FLAG_GETNAME) == 0) { /* alignment */ char *p; @@ -406,7 +432,7 @@ char *parse_special(char **cmd, SERVER_REC *server, void *item, /* parse the whole string. $ and \ chars are replaced */ char *parse_special_string(const char *cmd, SERVER_REC *server, void *item, - const char *data, int *arg_used) + const char *data, int *arg_used, int flags) { char code, **arglist, *ret; GString *str; @@ -438,7 +464,8 @@ char *parse_special_string(const char *cmd, SERVER_REC *server, void *item, char *ret; ret = parse_special((char **) &cmd, server, item, - arglist, &need_free, arg_used); + arglist, &need_free, arg_used, + flags); if (ret != NULL) { g_string_append(str, ret); if (need_free) g_free(ret); @@ -488,7 +515,7 @@ void eval_special_string(const char *cmd, const char *data, } ret = parse_special_string(start, server, item, - data, &arg_used); + data, &arg_used, 0); if (arg_used) arg_used_ever = TRUE; if (strchr(cmdchars, *ret) == NULL) { @@ -525,3 +552,42 @@ void special_history_func_set(SPECIAL_HISTORY_FUNC func) { history_func = func; } + +static void special_vars_signals_do(const char *text, int funccount, + SIGNAL_FUNC *funcs, int bind) +{ + char *ret; + int need_free; + + while (*text != '\0') { + if (*text == '\\' && text[1] != '\0') { + text += 2; + } else if (*text == '$' && text[1] != '\0') { + text++; + ret = parse_special((char **) &text, NULL, NULL, + NULL, &need_free, NULL, + PARSE_FLAG_GETNAME); + if (ret != NULL) { + if (bind) + expando_bind(ret, funccount, funcs); + else + expando_unbind(ret, funccount, funcs); + if (need_free) g_free(ret); + } + + } + else text++; + } +} + +void special_vars_add_signals(const char *text, + int funccount, SIGNAL_FUNC *funcs) +{ + special_vars_signals_do(text, funccount, funcs, TRUE); +} + +void special_vars_remove_signals(const char *text, + int funccount, SIGNAL_FUNC *funcs) +{ + special_vars_signals_do(text, funccount, funcs, FALSE); +} diff --git a/src/core/special-vars.h b/src/core/special-vars.h index 1b8b3e20..deb4de40 100644 --- a/src/core/special-vars.h +++ b/src/core/special-vars.h @@ -1,19 +1,23 @@ #ifndef __SPECIAL_VARS_H #define __SPECIAL_VARS_H +#include "signals.h" #include "servers.h" +#define PARSE_FLAG_GETNAME 0x01 /* return argument name instead of it's value */ +#define PARSE_FLAG_ISSET_ANY 0x02 /* arg_used field specifies that at least one of the $variables was non-empty */ + typedef char* (*SPECIAL_HISTORY_FUNC) (const char *text, void *item, int *free_ret); /* Parse and expand text after '$' character. return value has to be g_free()'d if `free_ret' is TRUE. */ char *parse_special(char **cmd, SERVER_REC *server, void *item, - char **arglist, int *free_ret, int *arg_used); + char **arglist, int *free_ret, int *arg_used, int flags); /* parse the whole string. $ and \ chars are replaced */ char *parse_special_string(const char *cmd, SERVER_REC *server, void *item, - const char *data, int *arg_used); + const char *data, int *arg_used, int flags); /* execute the commands in string - commands can be split with ';' */ void eval_special_string(const char *cmd, const char *data, @@ -21,4 +25,9 @@ void eval_special_string(const char *cmd, const char *data, void special_history_func_set(SPECIAL_HISTORY_FUNC func); +void special_vars_add_signals(const char *text, + int funccount, SIGNAL_FUNC *funcs); +void special_vars_remove_signals(const char *text, + int funccount, SIGNAL_FUNC *funcs); + #endif diff --git a/src/fe-common/core/fe-expandos.c b/src/fe-common/core/fe-expandos.c index c90fa23c..7eb145db 100644 --- a/src/fe-common/core/fe-expandos.c +++ b/src/fe-common/core/fe-expandos.c @@ -29,13 +29,23 @@ static char *expando_winref(SERVER_REC *server, void *item, int *free_ret) return g_strdup_printf("%d", active_win->refnum); } +/* Window name */ +static char *expando_winname(SERVER_REC *server, void *item, int *free_ret) +{ + return active_win->name; +} + void fe_expandos_init(void) { expando_create("winref", expando_winref, - "window changed", EXPANDO_ARG_NONE, NULL); + "window changed", EXPANDO_ARG_NONE, + "window refnum changed", EXPANDO_ARG_WINDOW, NULL); + expando_create("winname", expando_winname, + "window name changed", EXPANDO_ARG_WINDOW, NULL); } void fe_expandos_deinit(void) { expando_destroy("winref", expando_winref); + expando_destroy("winname", expando_winname); } diff --git a/src/fe-common/core/fe-log.c b/src/fe-common/core/fe-log.c index 6b10541e..319bc85c 100644 --- a/src/fe-common/core/fe-log.c +++ b/src/fe-common/core/fe-log.c @@ -350,7 +350,8 @@ static void autolog_open(void *server, const char *target) return; } - fname = parse_special_string(autolog_path, server, NULL, target, NULL); + fname = parse_special_string(autolog_path, server, NULL, + target, NULL, 0); if (log_find(fname) == NULL) { log = log_create_rec(fname, autolog_level); log_item_add(log, LOG_ITEM_TARGET, target, server); diff --git a/src/fe-common/core/fe-messages.c b/src/fe-common/core/fe-messages.c index c1446517..39e59f27 100644 --- a/src/fe-common/core/fe-messages.c +++ b/src/fe-common/core/fe-messages.c @@ -169,7 +169,7 @@ static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item) if (strcmp(target, ",") == 0 || strcmp(target, ".") == 0) { /* , and . are handled specially */ newtarget = parse_special(&target, server, item, - NULL, &free_ret, NULL); + NULL, &free_ret, NULL, 0); if (newtarget == NULL) { printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, *target == ',' ? IRCTXT_NO_MSGS_GOT : diff --git a/src/fe-common/core/formats.c b/src/fe-common/core/formats.c index cd47588c..fc74c5a8 100644 --- a/src/fe-common/core/formats.c +++ b/src/fe-common/core/formats.c @@ -237,8 +237,10 @@ static char *format_get_text_args(TEXT_DEST_REC *dest, /* argument */ char *ret; - ret = parse_special((char **) &text, active_win->active_server, - active_win->active, arglist, &need_free, NULL); + ret = parse_special((char **) &text, + active_win->active_server, + active_win->active, arglist, + &need_free, NULL, 0); if (ret != NULL) { /* string shouldn't end with \003 or it could diff --git a/src/fe-common/core/themes.c b/src/fe-common/core/themes.c index 06910f39..b3a79f14 100644 --- a/src/fe-common/core/themes.c +++ b/src/fe-common/core/themes.c @@ -137,7 +137,7 @@ static char *theme_replace_expand(THEME_REC *theme, int index, abstract = rec->data; abstract = theme_format_expand_data(theme, (const char **) &abstract, default_color, last_color, 0); - ret = parse_special_string(abstract, NULL, NULL, data, NULL); + ret = parse_special_string(abstract, NULL, NULL, data, NULL, 0); g_free(abstract); return ret; } @@ -158,7 +158,7 @@ static void theme_format_append_variable(GString *str, const char **format) (*format)++; value = parse_special((char **) format, NULL, NULL, - args, &free_ret, NULL ); + args, &free_ret, NULL, 0); if (free_ret) g_free(value); (*format)++; @@ -290,7 +290,7 @@ static char *theme_format_expand_abstract(THEME_REC *theme, g_free(tmp); } - ret = parse_special_string(abstract, NULL, NULL, data, NULL); + ret = parse_special_string(abstract, NULL, NULL, data, NULL, 0); g_free(abstract); g_free(data); return ret; diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c index e8fc04a9..544e37d9 100644 --- a/src/fe-text/gui-readline.c +++ b/src/fe-text/gui-readline.c @@ -67,7 +67,7 @@ static void handle_key_redirect(int key) func(key, data, active_win->active_server, active_win->active); gui_entry_remove_perm_prompt(); - window_update_prompt(active_win); + window_update_prompt(); } static void handle_entry_redirect(const char *line) @@ -83,7 +83,7 @@ static void handle_entry_redirect(const char *line) func(line, data, active_win->active_server, active_win->active); gui_entry_remove_perm_prompt(); - window_update_prompt(active_win); + window_update_prompt(); } static int get_scroll_count(void) diff --git a/src/fe-text/gui-windows.c b/src/fe-text/gui-windows.c index 8ad37451..7ef33474 100644 --- a/src/fe-text/gui-windows.c +++ b/src/fe-text/gui-windows.c @@ -23,6 +23,7 @@ #include "servers.h" #include "misc.h" #include "settings.h" +#include "special-vars.h" #include "irc.h" #include "channels.h" @@ -47,6 +48,8 @@ static int linecache_tag; static int window_create_override; static int default_indent_pos; +static char *prompt, *prompt_window; + static GUI_WINDOW_REC *gui_window_init(WINDOW_REC *window, MAIN_WINDOW_REC *parent) { GUI_WINDOW_REC *gui; @@ -670,30 +673,51 @@ void gui_window_update_ypos(GUI_WINDOW_REC *gui) gui->ypos += gui_window_get_linecount(gui, tmp->data); } -void window_update_prompt(WINDOW_REC *window) +void window_update_prompt(void) { - WI_ITEM_REC *item; - char *text, *str; - - if (window != active_win) return; + const char *special; + char *prompt, *text; + int var_used; - item = window->active; - if (item != NULL) - text = item->name; - else if (window->name != NULL) - text = window->name; - else { + special = settings_get_str(active_win->active != NULL ? + "prompt" : "prompt_window"); + if (*special == '\0') { gui_entry_set_prompt(""); return; } + prompt = parse_special_string(special, active_win->active_server, + active_win->active, "", &var_used, + PARSE_FLAG_ISSET_ANY); + if (!var_used && strchr(special, '$') != NULL) { + /* none of the $vars had non-empty values, use empty prompt */ + *prompt = '\0'; + } + /* set prompt */ - text = show_lowascii(text); - str = g_strdup_printf("[%1.17s] ", text); + text = show_lowascii(prompt); + gui_entry_set_prompt(text); g_free(text); - gui_entry_set_prompt(str); - if (*str != '\0') g_free(str); + g_free(prompt); +} + +static void window_update_prompt_server(SERVER_REC *server) +{ + if (server == active_win->active_server) + window_update_prompt(); +} + +static void window_update_prompt_window(WINDOW_REC *window) +{ + if (window == active_win) + window_update_prompt(); +} + +static void window_update_prompt_window_item(WI_ITEM_REC *item) +{ + if (item == active_win->active) + window_update_prompt(); } void gui_window_reparent(WINDOW_REC *window, MAIN_WINDOW_REC *parent) @@ -727,7 +751,7 @@ static void signal_window_changed(WINDOW_REC *window) } screen_refresh_freeze(); - window_update_prompt(window); + window_update_prompt(); gui_window_redraw(window); screen_refresh_thaw(); } @@ -1060,15 +1084,45 @@ void gui_window_reformat_line(WINDOW_REC *window, LINE_REC *line) g_string_free(raw, TRUE); } +static void sig_check_window_update(WINDOW_REC *window) +{ + if (window == active_win) + window_update_prompt(); +} + static void read_settings(void) { + SIGNAL_FUNC funcs[] = { + (SIGNAL_FUNC) window_update_prompt, + (SIGNAL_FUNC) window_update_prompt_server, + (SIGNAL_FUNC) window_update_prompt_window, + (SIGNAL_FUNC) window_update_prompt_window_item + }; + default_indent_pos = settings_get_int("indent"); + + if (prompt != NULL) { + special_vars_remove_signals(prompt, 4, funcs); + special_vars_remove_signals(prompt_window, 4, funcs); + g_free(prompt); + g_free(prompt_window); + } + prompt = g_strdup(settings_get_str("prompt")); + prompt_window = g_strdup(settings_get_str("prompt_window")); + + special_vars_add_signals(prompt, 4, funcs); + special_vars_add_signals(prompt_window, 4, funcs); + + if (active_win != NULL) window_update_prompt(); } void gui_windows_init(void) { settings_add_int("lookandfeel", "indent", 10); + settings_add_str("lookandfeel", "prompt", "[$T] "); + settings_add_str("lookandfeel", "prompt_window", "[$winname] "); + prompt = NULL; prompt_window = NULL; window_create_override = -1; linecache_tag = g_timeout_add(LINE_CACHE_CHECK_TIME, (GSourceFunc) sig_check_linecache, NULL); @@ -1077,15 +1131,15 @@ void gui_windows_init(void) signal_add("window created", (SIGNAL_FUNC) gui_window_created); signal_add("window destroyed", (SIGNAL_FUNC) gui_window_destroyed); signal_add_first("window changed", (SIGNAL_FUNC) signal_window_changed); - signal_add("window item changed", (SIGNAL_FUNC) window_update_prompt); - signal_add("window name changed", (SIGNAL_FUNC) window_update_prompt); - signal_add("window item remove", (SIGNAL_FUNC) window_update_prompt); + signal_add("window item remove", (SIGNAL_FUNC) sig_check_window_update); signal_add("setup changed", (SIGNAL_FUNC) read_settings); } void gui_windows_deinit(void) { g_source_remove(linecache_tag); + g_free_not_null(prompt); + g_free_not_null(prompt_window); while (windows != NULL) window_destroy(windows->data); @@ -1094,8 +1148,6 @@ void gui_windows_deinit(void) signal_remove("window created", (SIGNAL_FUNC) gui_window_created); signal_remove("window destroyed", (SIGNAL_FUNC) gui_window_destroyed); signal_remove("window changed", (SIGNAL_FUNC) signal_window_changed); - signal_remove("window item changed", (SIGNAL_FUNC) window_update_prompt); - signal_remove("window name changed", (SIGNAL_FUNC) window_update_prompt); - signal_remove("window item remove", (SIGNAL_FUNC) window_update_prompt); + signal_remove("window item remove", (SIGNAL_FUNC) sig_check_window_update); signal_remove("setup changed", (SIGNAL_FUNC) read_settings); } diff --git a/src/fe-text/gui-windows.h b/src/fe-text/gui-windows.h index 23085b92..441f8713 100644 --- a/src/fe-text/gui-windows.h +++ b/src/fe-text/gui-windows.h @@ -113,7 +113,7 @@ void gui_window_reparent(WINDOW_REC *window, MAIN_WINDOW_REC *parent); #define is_window_bottom(gui) \ ((gui)->ypos >= -1 && (gui)->ypos <= (gui)->parent->last_line-(gui)->parent->first_line) -void window_update_prompt(WINDOW_REC *window); +void window_update_prompt(void); void gui_window_newline(GUI_WINDOW_REC *gui, int visible); void gui_window_scroll(WINDOW_REC *window, int lines); void gui_window_update_ypos(GUI_WINDOW_REC *gui); diff --git a/src/irc/core/ctcp.c b/src/irc/core/ctcp.c index 3eb140f7..3d904dd0 100644 --- a/src/irc/core/ctcp.c +++ b/src/irc/core/ctcp.c @@ -87,7 +87,7 @@ static void ctcp_version(IRC_SERVER_REC *server, const char *data, g_return_if_fail(nick != NULL); reply = parse_special_string(settings_get_str("ctcp_version_reply"), - SERVER(server), NULL, "", NULL); + SERVER(server), NULL, "", NULL, 0); str = g_strdup_printf("NOTICE %s :\001VERSION %s\001", nick, reply); ctcp_send_reply(server, str); g_free(str); diff --git a/src/irc/core/irc-commands.c b/src/irc/core/irc-commands.c index ed0984f8..67a91b5e 100644 --- a/src/irc/core/irc-commands.c +++ b/src/irc/core/irc-commands.c @@ -772,7 +772,7 @@ static void cmd_wall(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item args = g_strconcat(chanrec->name, " ", msg, NULL); msg = parse_special_string(settings_get_str("wall_format"), - SERVER(server), item, args, NULL); + SERVER(server), item, args, NULL, 0); g_free(args); for (tmp = nicks; tmp != NULL; tmp = tmp->next) { |