1
0
mirror of https://github.com/irssi/irssi.git synced 2024-11-03 04:27:19 -05:00

Some query changes. They should now work properly with /SAVEWINDOWS

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1043 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2001-01-01 17:13:55 +00:00 committed by cras
parent 21865aa8de
commit c2ea82642d
7 changed files with 40 additions and 31 deletions

View File

@ -28,17 +28,16 @@
GSList *queries;
/* Create a new query */
QUERY_REC *query_create(int chat_type, SERVER_REC *server,
QUERY_REC *query_create(int chat_type, const char *server_tag,
const char *nick, int automatic)
{
QUERY_REC *query;
g_return_val_if_fail(server == NULL || IS_SERVER(server), NULL);
g_return_val_if_fail(nick != NULL, NULL);
query = NULL;
signal_emit("query create", 5, &query, GINT_TO_POINTER(chat_type),
server, nick, GINT_TO_POINTER(automatic));
server_tag, nick, GINT_TO_POINTER(automatic));
return query;
}
@ -55,8 +54,8 @@ void query_init(QUERY_REC *query, int automatic)
MODULE_DATA_INIT(query);
query->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "QUERY");
if (query->server != NULL)
query->server_tag = g_strdup(query->server->tag);
if (query->server_tag != NULL)
query->server = server_find_tag(query->server_tag);
signal_emit("query created", 2, query, GINT_TO_POINTER(automatic));
}
@ -76,9 +75,9 @@ void query_destroy(QUERY_REC *query)
signal_emit("query destroyed", 1, query);
MODULE_DATA_DEINIT(query);
g_free_not_null(query->server_tag);
g_free_not_null(query->address);
g_free(query->name);
g_free(query->server_tag);
g_free(query);
}

View File

@ -22,7 +22,7 @@ void query_init(QUERY_REC *query, int automatic);
void query_destroy(QUERY_REC *query);
/* Create a new query */
QUERY_REC *query_create(int chat_type, SERVER_REC *server,
QUERY_REC *query_create(int chat_type, const char *server_tag,
const char *nick, int automatic);
/* Find query by name, if `server' is NULL, search from all servers */

View File

@ -45,8 +45,10 @@ QUERY_REC *privmsg_get_query(SERVER_REC *server, const char *nick,
query = query_find(server, nick);
if (query == NULL && (querycreate_level & level) != 0 &&
(!own || settings_get_bool("autocreate_own_query")))
query = query_create(server->chat_type, server, nick, TRUE);
(!own || settings_get_bool("autocreate_own_query"))) {
query = query_create(server->chat_type, server->tag,
nick, TRUE);
}
return query;
}
@ -105,6 +107,16 @@ static void signal_query_nick_changed(QUERY_REC *query, const char *oldnick)
window_item_window((WI_ITEM_REC *) query), query);
}
static void signal_window_item_server_changed(WINDOW_REC *window,
QUERY_REC *query)
{
if (IS_QUERY(query)) {
g_free_and_null(query->server_tag);
if (query->server != NULL)
query->server_tag = g_strdup(query->server->tag);
}
}
static void signal_window_item_destroy(WINDOW_REC *window, WI_ITEM_REC *item)
{
QUERY_REC *query;
@ -127,7 +139,8 @@ static void sig_server_connected(SERVER_REC *server)
QUERY_REC *rec = tmp->data;
if (rec->server == NULL &&
g_strcasecmp(rec->server_tag, server->tag) == 0) {
(rec->server_tag == NULL ||
g_strcasecmp(rec->server_tag, server->tag) == 0)) {
window_item_change_server((WI_ITEM_REC *) rec, server);
server->queries = g_slist_append(server->queries, rec);
}
@ -215,7 +228,7 @@ static void cmd_query(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
query = query_find(server, nick);
if (query == NULL)
query_create(server->chat_type, server, nick, FALSE);
query_create(server->chat_type, server->tag, nick, FALSE);
else {
/* query already existed - set query active / move it to this
window */
@ -309,6 +322,7 @@ void fe_queries_init(void)
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("window item server changed", (SIGNAL_FUNC) signal_window_item_server_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);
@ -330,6 +344,7 @@ void fe_queries_deinit(void)
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 server changed", (SIGNAL_FUNC) signal_window_item_server_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

@ -50,19 +50,10 @@ static void sig_window_restore_item(WINDOW_REC *window, const char *type,
window->waiting_channels =
g_slist_append(window->waiting_channels, str);
} else if (g_strcasecmp(type, "QUERY") == 0) {
} else if (g_strcasecmp(type, "QUERY") == 0 && chat_type != NULL) {
/* create query immediately */
QUERY_REC *query;
SERVER_REC *server;
if (chat_type == NULL)
return;
server = tag == NULL ? NULL : server_find_tag(tag);
query = query_create(chat_protocol_lookup(chat_type),
server, name, TRUE);
if (server == NULL && tag != NULL)
query->server_tag = g_strdup(tag);
query_create(chat_protocol_lookup(chat_type),
tag, name, TRUE);
}
}
@ -136,6 +127,10 @@ static void window_save_items(WINDOW_REC *window, CONFIG_NODE *node)
if (server != NULL)
iconfig_node_set_str(subnode, "tag", server->tag);
else if (IS_QUERY(rec)) {
iconfig_node_set_str(subnode, "tag",
QUERY(rec)->server_tag);
}
}
}

View File

@ -53,7 +53,8 @@ static void dcc_connected(DCC_REC *dcc)
printformat(dcc->server, NULL, MSGLEVEL_DCC, IRCTXT_DCC_CHAT_CONNECTED,
dcc->nick, dcc->addrstr, dcc->port);
if (autocreate_dccquery && query_find(NULL, sender) == NULL)
irc_query_create(dcc->server, sender, TRUE);
irc_query_create(dcc->server == NULL ? NULL :
dcc->server->tag, sender, TRUE);
g_free(sender);
break;
case DCC_TYPE_SEND:

View File

@ -25,34 +25,33 @@
#include "irc.h"
#include "irc-queries.h"
QUERY_REC *irc_query_create(IRC_SERVER_REC *server,
QUERY_REC *irc_query_create(const char *server_tag,
const char *nick, int automatic)
{
QUERY_REC *rec;
g_return_val_if_fail(server == NULL || IS_IRC_SERVER(server), NULL);
g_return_val_if_fail(nick != NULL, NULL);
rec = g_new0(QUERY_REC, 1);
rec->chat_type = IRC_PROTOCOL;
rec->name = g_strdup(nick);
rec->server = (SERVER_REC *) server;
rec->server_tag = g_strdup(server_tag);
query_init(rec, automatic);
return rec;
}
static void sig_query_create(QUERY_REC **query,
void *chat_type, IRC_SERVER_REC *server,
void *chat_type, const char *server_tag,
const char *nick, void *automatic)
{
if (chat_protocol_lookup("IRC") != GPOINTER_TO_INT(chat_type))
return;
g_return_if_fail(server == NULL || IS_IRC_SERVER(server));
g_return_if_fail(query != NULL);
g_return_if_fail(nick != NULL);
*query = irc_query_create(server, nick, GPOINTER_TO_INT(automatic));
*query = irc_query_create(server_tag, nick,
GPOINTER_TO_INT(automatic));
signal_stop();
}

View File

@ -18,7 +18,7 @@ void irc_queries_deinit(void);
#define irc_query_find(server, name) \
query_find(SERVER(server), name)
QUERY_REC *irc_query_create(IRC_SERVER_REC *server,
QUERY_REC *irc_query_create(const char *server_tag,
const char *nick, int automatic);
#endif