1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

Some minor query fixes. Nick changes are also detected by checking if

query with another nick from same address if found.


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@999 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-12-17 02:20:22 +00:00 committed by cras
parent 3011d2c01c
commit fc491c5f8d
10 changed files with 160 additions and 48 deletions

View File

@ -116,12 +116,33 @@ QUERY_REC *query_find(SERVER_REC *server, const char *nick)
(void *) nick);
}
void query_change_nick(QUERY_REC *query, const char *nick)
{
char *oldnick;
g_return_if_fail(IS_QUERY(query));
oldnick = query->name;
query->name = g_strdup(nick);
signal_emit("query nick changed", 2, query, oldnick);
g_free(oldnick);
}
void query_change_address(QUERY_REC *query, const char *address)
{
g_return_if_fail(IS_QUERY(query));
g_free_not_null(query->address);
query->address = g_strdup(address);
signal_emit("query address changed", 1, query);
}
void query_change_server(QUERY_REC *query, SERVER_REC *server)
{
g_return_if_fail(IS_QUERY(query));
query->server = server;
signal_emit("query server changed", 2, query, server);
signal_emit("query server changed", 1, query);
}
void queries_init(void)

View File

@ -28,6 +28,8 @@ QUERY_REC *query_create(int chat_type, SERVER_REC *server,
/* Find query by name, if `server' is NULL, search from all servers */
QUERY_REC *query_find(SERVER_REC *server, const char *nick);
void query_change_nick(QUERY_REC *query, const char *nick);
void query_change_address(QUERY_REC *query, const char *address);
void query_change_server(QUERY_REC *query, SERVER_REC *server);
void queries_init(void);

View File

@ -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);

View File

@ -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 },

View File

@ -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 \

View File

@ -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();

View File

@ -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);
}

View File

@ -732,11 +732,6 @@ static void signal_window_changed(WINDOW_REC *window)
screen_refresh_thaw();
}
static void signal_window_item_update(WINDOW_REC *window)
{
window_update_prompt(window);
}
GList *gui_window_find_text(WINDOW_REC *window, gchar *text, GList *startline, int regexp, int fullword)
{
#ifdef HAVE_REGEX_H
@ -1082,9 +1077,9 @@ 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) signal_window_item_update);
signal_add("window name changed", (SIGNAL_FUNC) signal_window_item_update);
signal_add("window item remove", (SIGNAL_FUNC) signal_window_item_update);
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("setup changed", (SIGNAL_FUNC) read_settings);
}
@ -1099,8 +1094,8 @@ 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) signal_window_item_update);
signal_remove("window name changed", (SIGNAL_FUNC) signal_window_item_update);
signal_remove("window item remove", (SIGNAL_FUNC) signal_window_item_update);
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("setup changed", (SIGNAL_FUNC) read_settings);
}

View File

@ -901,7 +901,6 @@ void statusbar_items_init(void)
/* more */
more_item = NULL;
signal_add("gui page scrolled", (SIGNAL_FUNC) sig_statusbar_more_check_remove);
signal_add("window item changed", (SIGNAL_FUNC) sig_statusbar_more_check);
signal_add("window changed", (SIGNAL_FUNC) sig_statusbar_more_check);
signal_add("gui print text", (SIGNAL_FUNC) sig_statusbar_more_check);
@ -963,7 +962,6 @@ void statusbar_items_deinit(void)
/* more */
signal_remove("gui page scrolled", (SIGNAL_FUNC) sig_statusbar_more_check_remove);
signal_remove("window item changed", (SIGNAL_FUNC) sig_statusbar_more_check);
signal_remove("window changed", (SIGNAL_FUNC) sig_statusbar_more_check);
signal_remove("gui print text", (SIGNAL_FUNC) sig_statusbar_more_check);

View File

@ -56,47 +56,39 @@ static void sig_query_create(QUERY_REC **query,
signal_stop();
}
static void event_privmsg(IRC_SERVER_REC *server, const char *data, const char *nick, const char *addr)
static void event_privmsg(IRC_SERVER_REC *server, const char *data,
const char *nick, const char *address)
{
char *params, *target, *msg;
QUERY_REC *query;
char *params, *target, *msg;
g_return_if_fail(data != NULL);
params = event_get_params(data, 2 | PARAM_FLAG_GETREST, &target, &msg);
if (addr != NULL && !ischannel(*target)) {
if (address != NULL && !ischannel(*target)) {
/* save nick's address to query */
query = irc_query_find(server, nick);
if (query != NULL && (query->address == NULL || strcmp(query->address, addr) != 0)) {
g_free_not_null(query->address);
query->address = g_strdup(addr);
signal_emit("query address changed", 1, query);
}
if (query != NULL && (query->address == NULL ||
strcmp(query->address, address) != 0))
query_change_address(query, address);
}
g_free(params);
}
static void event_nick(IRC_SERVER_REC *server, const char *data, const char *orignick)
static void event_nick(SERVER_REC *server, const char *data,
const char *orignick)
{
QUERY_REC *query;
char *params, *nick;
GSList *tmp;
params = event_get_params(data, 1, &nick);
for (tmp = server->queries; tmp != NULL; tmp = tmp->next) {
QUERY_REC *rec = tmp->data;
if (g_strcasecmp(rec->name, orignick) == 0) {
g_free(rec->name);
rec->name = g_strdup(nick);
signal_emit("query nick changed", 1, rec);
}
query = query_find(server, orignick);
if (query != NULL) {
params = event_get_params(data, 1, &nick);
query_change_nick(query, nick);
g_free(params);
}
g_free(params);
}
void irc_queries_init(void)