diff options
Diffstat (limited to 'src/fe-common')
-rw-r--r-- | src/fe-common/core/fe-queries.c | 42 | ||||
-rw-r--r-- | src/fe-common/core/module-formats.c | 2 | ||||
-rw-r--r-- | src/fe-common/irc/Makefile.am | 1 | ||||
-rw-r--r-- | src/fe-common/irc/fe-common-irc.c | 5 | ||||
-rw-r--r-- | src/fe-common/irc/fe-irc-queries.c | 76 |
5 files changed, 115 insertions, 11 deletions
diff --git a/src/fe-common/core/fe-queries.c b/src/fe-common/core/fe-queries.c index 3398e418..146496ad 100644 --- a/src/fe-common/core/fe-queries.c +++ b/src/fe-common/core/fe-queries.c @@ -53,6 +53,8 @@ QUERY_REC *privmsg_get_query(SERVER_REC *server, const char *nick, static void signal_query_created(QUERY_REC *query, gpointer automatic) { + g_return_if_fail(IS_QUERY(query)); + if (window_item_find(query->server, query->name) != NULL) return; @@ -63,7 +65,7 @@ static void signal_query_created(QUERY_REC *query, gpointer automatic) static void signal_query_created_curwin(QUERY_REC *query) { - g_return_if_fail(query != NULL); + g_return_if_fail(IS_QUERY(query)); window_item_add(active_win, (WI_ITEM_REC *) query, FALSE); } @@ -72,7 +74,7 @@ static void signal_query_destroyed(QUERY_REC *query) { WINDOW_REC *window; - g_return_if_fail(query != NULL); + g_return_if_fail(IS_QUERY(query)); window = window_item_window((WI_ITEM_REC *) query); if (window != NULL) { @@ -84,6 +86,25 @@ static void signal_query_destroyed(QUERY_REC *query) } } +static void signal_query_server_changed(QUERY_REC *query) +{ + WINDOW_REC *window; + + g_return_if_fail(query != NULL); + + window = window_item_window((WI_ITEM_REC *) query); + if (window->active == (WI_ITEM_REC *) query) + window_change_server(window, query->server); +} + +static void signal_query_nick_changed(QUERY_REC *query, const char *oldnick) +{ + g_return_if_fail(query != NULL); + + signal_emit("window item changed", 2, + window_item_window((WI_ITEM_REC *) query), query); +} + static void signal_window_item_destroy(WINDOW_REC *window, WI_ITEM_REC *item) { QUERY_REC *query; @@ -116,23 +137,20 @@ static void sig_server_connected(SERVER_REC *server) static void cmd_window_server(const char *data) { SERVER_REC *server; + QUERY_REC *query; g_return_if_fail(data != NULL); server = server_find_tag(data); - if (!IS_SERVER(server) || !IS_QUERY(active_win->active)) + query = QUERY(active_win->active); + if (server == NULL || query == NULL) return; /* /WINDOW SERVER used in a query window */ - query_change_server(QUERY(active_win->active), server); - window_change_server(active_win, server); - + query_change_server(query, server); printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_QUERY_SERVER_CHANGED, - server->tag, server->connrec->address, - server->connrec->chatnet == NULL ? "" : - server->connrec->chatnet); - + query->name, server->tag); signal_stop(); } @@ -289,6 +307,8 @@ void fe_queries_init(void) signal_add("query created", (SIGNAL_FUNC) signal_query_created); signal_add("query destroyed", (SIGNAL_FUNC) signal_query_destroyed); + signal_add("query server changed", (SIGNAL_FUNC) signal_query_server_changed); + signal_add("query nick changed", (SIGNAL_FUNC) signal_query_nick_changed); signal_add_last("window item destroy", (SIGNAL_FUNC) signal_window_item_destroy); signal_add("server connected", (SIGNAL_FUNC) sig_server_connected); signal_add("window changed", (SIGNAL_FUNC) sig_window_changed); @@ -308,6 +328,8 @@ void fe_queries_deinit(void) signal_remove("query created", (SIGNAL_FUNC) signal_query_created); signal_remove("query destroyed", (SIGNAL_FUNC) signal_query_destroyed); + signal_remove("query server changed", (SIGNAL_FUNC) signal_query_server_changed); + signal_remove("query nick changed", (SIGNAL_FUNC) signal_query_nick_changed); signal_remove("window item destroy", (SIGNAL_FUNC) signal_window_item_destroy); signal_remove("server connected", (SIGNAL_FUNC) sig_server_connected); signal_remove("window changed", (SIGNAL_FUNC) sig_window_changed); diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c index c09213bb..9db7c8bf 100644 --- a/src/fe-common/core/module-formats.c +++ b/src/fe-common/core/module-formats.c @@ -108,7 +108,7 @@ FORMAT_REC fecommon_core_formats[] = { { "query_start", "Starting query with {nick $0}", 1, { 0 } }, { "no_query", "No query with {nick $0}", 1, { 0 } }, - { "query_server_changed", "Query with {nick $2} changed to server {server $1}", 3, { 0, 0, 0 } }, + { "query_server_changed", "Query with {nick $0} changed to server {server $1}", 2, { 0, 0 } }, /* ---- */ { NULL, "Highlighting", 0 }, diff --git a/src/fe-common/irc/Makefile.am b/src/fe-common/irc/Makefile.am index 8fca5bd5..0abc41f9 100644 --- a/src/fe-common/irc/Makefile.am +++ b/src/fe-common/irc/Makefile.am @@ -14,6 +14,7 @@ INCLUDES = \ libfe_common_irc_a_SOURCES = \ fe-irc-channels.c \ fe-irc-commands.c \ + fe-irc-queries.c \ fe-irc-server.c \ fe-ircnet.c \ fe-ctcp.c \ diff --git a/src/fe-common/irc/fe-common-irc.c b/src/fe-common/irc/fe-common-irc.c index 3dccd6a4..2c26a44e 100644 --- a/src/fe-common/irc/fe-common-irc.c +++ b/src/fe-common/irc/fe-common-irc.c @@ -36,6 +36,9 @@ void fe_irc_modules_deinit(void); void fe_irc_channels_init(void); void fe_irc_channels_deinit(void); +void fe_irc_queries_init(void); +void fe_irc_queries_deinit(void); + void fe_irc_commands_init(void); void fe_irc_commands_deinit(void); @@ -95,6 +98,7 @@ void fe_common_irc_init(void) theme_register(fecommon_irc_formats); fe_irc_channels_init(); + fe_irc_queries_init(); fe_irc_commands_init(); fe_ircnet_init(); fe_irc_server_init(); @@ -113,6 +117,7 @@ void fe_common_irc_deinit(void) fe_irc_modules_deinit(); fe_irc_channels_deinit(); + fe_irc_queries_deinit(); fe_irc_commands_deinit(); fe_ircnet_deinit(); fe_irc_server_deinit(); diff --git a/src/fe-common/irc/fe-irc-queries.c b/src/fe-common/irc/fe-irc-queries.c new file mode 100644 index 00000000..619cd0f4 --- /dev/null +++ b/src/fe-common/irc/fe-irc-queries.c @@ -0,0 +1,76 @@ +/* + fe-irc-queries.c : irssi + + Copyright (C) 2000 Timo Sirainen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "module.h" +#include "signals.h" +#include "servers.h" +#include "queries.h" + +#include "irc.h" + +static QUERY_REC *query_find_address(SERVER_REC *server, const char *address) +{ + GSList *tmp; + + g_return_val_if_fail(IS_SERVER(server), NULL); + + for (tmp = server->queries; tmp != NULL; tmp = tmp->next) { + QUERY_REC *rec = tmp->data; + + if (g_strcasecmp(address, rec->address) == 0) + return rec; + } + + return NULL; +} + +static void event_privmsg(SERVER_REC *server, const char *data, + const char *nick, const char *address) +{ + QUERY_REC *query; + + g_return_if_fail(data != NULL); + + if (nick == NULL || address == NULL || ischannel(*data)) + return; + + query = query_find(server, nick); + if (query == NULL) { + /* check if there's query with another nick from the same + address. it was probably a nick change or reconnect to + server, so rename the query. */ + query = query_find_address(server, address); + if (query != NULL) { + signal_emit("message nick", 4, query->server, + nick, query->name, query->address); + query_change_nick(query, nick); + } + } +} + +void fe_irc_queries_init(void) +{ + signal_add_first("event privmsg", (SIGNAL_FUNC) event_privmsg); +} + +void fe_irc_queries_deinit(void) +{ + signal_remove("event privmsg", (SIGNAL_FUNC) event_privmsg); +} |