From 980d6ca3fdac3fb0da21f61d8de42db061b136bf Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sat, 10 Feb 2001 03:10:30 +0000 Subject: [PATCH] /WINDOW SERVER: added -sticky and -unsticky options. If window server is sticky, it will never be automatically changed, and it cannot be changed to anything else without -unsticky option. Should be useful for people who want status or msgs windows for each server. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1196 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/fe-common/core/fe-windows.c | 13 +++++--- src/fe-common/core/fe-windows.h | 1 + src/fe-common/core/module-formats.c | 4 +++ src/fe-common/core/module-formats.h | 4 +++ src/fe-common/core/window-commands.c | 44 ++++++++++++++++++++++++---- src/fe-common/core/window-save.c | 7 +++++ 6 files changed, 64 insertions(+), 9 deletions(-) diff --git a/src/fe-common/core/fe-windows.c b/src/fe-common/core/fe-windows.c index fba29a51..e929c204 100644 --- a/src/fe-common/core/fe-windows.c +++ b/src/fe-common/core/fe-windows.c @@ -124,6 +124,7 @@ void window_destroy(WINDOW_REC *window) g_slist_foreach(window->waiting_channels, (GFunc) g_free, NULL); g_slist_free(window->waiting_channels); + g_free_not_null(window->servertag); g_free_not_null(window->theme_name); g_free_not_null(window->name); g_free(window); @@ -396,8 +397,10 @@ static void sig_server_looking(SERVER_REC *server) for (tmp = windows; tmp != NULL; tmp = tmp->next) { WINDOW_REC *rec = tmp->data; - if (rec->active_server == NULL || - (rec == active_win && rec->items == NULL)) + if ((rec->servertag == NULL || + g_strcasecmp(rec->servertag, server->tag) == 0) && + (rec->active_server == NULL || + (rec == active_win && rec->items == NULL))) window_change_server(rec, server); } } @@ -413,8 +416,10 @@ static void sig_server_disconnected(SERVER_REC *server) for (tmp = windows; tmp != NULL; tmp = tmp->next) { WINDOW_REC *rec = tmp->data; - if (rec->active_server == server) - window_change_server(rec, new_server); + if (rec->active_server == server) { + window_change_server(rec, rec->servertag != NULL ? + NULL : new_server); + } } } diff --git a/src/fe-common/core/fe-windows.h b/src/fe-common/core/fe-windows.h index 1b22f5b9..74d8103f 100644 --- a/src/fe-common/core/fe-windows.h +++ b/src/fe-common/core/fe-windows.h @@ -22,6 +22,7 @@ typedef struct { GSList *items; WI_ITEM_REC *active; SERVER_REC *active_server; + char *servertag; /* active_server must be either NULL or have this tag (unless there's items in this window) */ int level; /* message level */ GSList *waiting_channels; /* list of " " */ diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c index 04a2fe42..6c1dd5bc 100644 --- a/src/fe-common/core/module-formats.c +++ b/src/fe-common/core/module-formats.c @@ -34,10 +34,14 @@ FORMAT_REC fecommon_core_formats[] = { { "daychange", "Day changed to $[-2.0]{0} $3 $2", 4, { 1, 1, 1, 0 } }, { "talking_with", "You are now talking with {nick $0}", 1, { 0 } }, { "refnum_too_low", "Window number must be greater than 1", 0 }, + { "error_server_sticky", "Window's server is sticky and it cannot be changed without -unsticky option", 0 }, + { "set_server_sticky", "Window's server set sticky", 1, { 0 } }, + { "unset_server_sticky", "Window's server isn't sticky anymore", 1, { 0 } }, { "window_level", "Window level is now $0", 1, { 0 } }, { "windowlist_header", "Ref Name Active item Server Level", 0 }, { "windowlist_line", "$[3]0 %|$[20]1 $[15]2 $[15]3 $4", 5, { 1, 0, 0, 0, 0 } }, { "windowlist_footer", "", 0 }, + { "windows_saved", "State of windows saved (/SAVE is still needed to update configuration file)", 0 }, /* ---- */ { NULL, "Server", 0 }, diff --git a/src/fe-common/core/module-formats.h b/src/fe-common/core/module-formats.h index 38c57abd..ae2a80e1 100644 --- a/src/fe-common/core/module-formats.h +++ b/src/fe-common/core/module-formats.h @@ -12,10 +12,14 @@ enum { TXT_DAYCHANGE, TXT_TALKING_WITH, TXT_REFNUM_TOO_LOW, + TXT_ERROR_SERVER_STICKY, + TXT_SET_SERVER_STICKY, + TXT_UNSET_SERVER_STICKY, TXT_WINDOW_LEVEL, TXT_WINDOWLIST_HEADER, TXT_WINDOWLIST_LINE, TXT_WINDOWLIST_FOOTER, + TXT_WINDOWS_SAVED, TXT_FILL_2, diff --git a/src/fe-common/core/window-commands.c b/src/fe-common/core/window-commands.c index b4e9ff68..fe92f187 100644 --- a/src/fe-common/core/window-commands.c +++ b/src/fe-common/core/window-commands.c @@ -178,25 +178,58 @@ static void cmd_window_level(const char *data) g_free(level); } -/* SYNTAX: WINDOW SERVER */ +/* SYNTAX: WINDOW SERVER [-sticky | -unsticky] */ static void cmd_window_server(const char *data) { + GHashTable *optlist; SERVER_REC *server; + char *tag; + void *free_arg; - g_return_if_fail(data != NULL); + if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS, + "window server", &optlist, &tag)) + return; - server = server_find_tag(data); - if (server == NULL) { + if (*tag == '\0' && + (g_hash_table_lookup(optlist, "sticky") != NULL || + g_hash_table_lookup(optlist, "unsticky") != NULL)) { + tag = active_win->active_server->tag; + } + + if (*tag == '\0') + cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); + server = server_find_tag(tag); + + if (g_hash_table_lookup(optlist, "unsticky") != NULL && + active_win->servertag != NULL) { + g_free_and_null(active_win->servertag); printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, - TXT_UNKNOWN_SERVER_TAG, data); + TXT_UNSET_SERVER_STICKY, server->tag); + } + + if (active_win->servertag != NULL && + g_hash_table_lookup(optlist, "sticky") == NULL) { + printformat_window(active_win, MSGLEVEL_CLIENTERROR, + TXT_ERROR_SERVER_STICKY); + } else if (server == NULL) { + printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, + TXT_UNKNOWN_SERVER_TAG, tag); } else if (active_win->active == NULL) { window_change_server(active_win, server); + if (g_hash_table_lookup(optlist, "sticky") != NULL) { + g_free_not_null(active_win->servertag); + active_win->servertag = g_strdup(server->tag); + printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, + TXT_SET_SERVER_STICKY, server->tag); + } printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, TXT_SERVER_CHANGED, server->tag, server->connrec->address, server->connrec->chatnet == NULL ? "" : server->connrec->chatnet); } + + cmd_params_free(free_arg); } static void cmd_window_item(const char *data, void *server, WI_ITEM_REC *item) @@ -446,6 +479,7 @@ void window_commands_init(void) command_bind("savewindows", NULL, (SIGNAL_FUNC) cmd_savewindows); command_set_options("window number", "sticky"); + command_set_options("window server", "sticky unsticky"); } void window_commands_deinit(void) diff --git a/src/fe-common/core/window-save.c b/src/fe-common/core/window-save.c index f36be916..1a55d00e 100644 --- a/src/fe-common/core/window-save.c +++ b/src/fe-common/core/window-save.c @@ -29,6 +29,8 @@ #include "servers.h" #include "queries.h" +#include "module-formats.h" +#include "printtext.h" #include "themes.h" #include "fe-windows.h" #include "window-items.h" @@ -93,6 +95,7 @@ void windows_restore(void) window_set_name(window, config_node_get_str(node, "name", NULL)); window_set_level(window, level2bits(config_node_get_str(node, "level", ""))); + window->servertag = g_strdup(config_node_get_str(node, "servertag", NULL)); window->theme_name = g_strdup(config_node_get_str(node, "theme", NULL)); if (window->theme_name != NULL) window->theme = theme_load(window->theme_name); @@ -143,6 +146,8 @@ static void window_save(WINDOW_REC *window, CONFIG_NODE *node) if (window->name != NULL) iconfig_node_set_str(node, "name", window->name); + if (window->servertag != NULL) + iconfig_node_set_str(node, "servertag", window->servertag); if (window->level != 0) { char *level = bits2level(window->level); iconfig_node_set_str(node, "level", level); @@ -166,6 +171,8 @@ void windows_save(void) g_slist_foreach(windows, (GFunc) window_save, node); signal_emit("windows saved", 0); + + printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_WINDOWS_SAVED); } void window_save_init(void)