2000-08-26 11:39:44 -04:00
|
|
|
/*
|
|
|
|
queries.c : irssi
|
|
|
|
|
|
|
|
Copyright (C) 1999-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.
|
|
|
|
|
2007-05-08 14:41:10 -04:00
|
|
|
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.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2000-08-26 11:39:44 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
#include "signals.h"
|
|
|
|
#include "misc.h"
|
|
|
|
|
2001-01-01 02:45:54 -05:00
|
|
|
#include "servers.h"
|
2000-08-26 11:39:44 -04:00
|
|
|
#include "queries.h"
|
|
|
|
|
|
|
|
GSList *queries;
|
|
|
|
|
2002-05-15 20:34:37 -04:00
|
|
|
static const char *query_get_target(WI_ITEM_REC *item)
|
|
|
|
{
|
|
|
|
return ((QUERY_REC *) item)->name;
|
|
|
|
}
|
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
void query_init(QUERY_REC *query, int automatic)
|
|
|
|
{
|
|
|
|
g_return_if_fail(query != NULL);
|
|
|
|
g_return_if_fail(query->name != NULL);
|
|
|
|
|
|
|
|
queries = g_slist_append(queries, query);
|
|
|
|
|
|
|
|
MODULE_DATA_INIT(query);
|
2000-09-02 14:53:58 -04:00
|
|
|
query->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "QUERY");
|
2001-07-25 21:49:08 -04:00
|
|
|
query->destroy = (void (*) (WI_ITEM_REC *)) query_destroy;
|
2002-05-15 20:34:37 -04:00
|
|
|
query->get_target = query_get_target;
|
2002-04-28 10:08:20 -04:00
|
|
|
query->createtime = time(NULL);
|
2002-03-11 13:20:42 -05:00
|
|
|
query->last_unread_msg = time(NULL);
|
2002-05-15 20:34:37 -04:00
|
|
|
query->visible_name = g_strdup(query->name);
|
2002-03-11 13:20:42 -05:00
|
|
|
|
2001-01-01 14:29:05 -05:00
|
|
|
if (query->server_tag != NULL) {
|
2001-01-01 12:13:55 -05:00
|
|
|
query->server = server_find_tag(query->server_tag);
|
2001-01-01 14:29:05 -05:00
|
|
|
if (query->server != NULL) {
|
|
|
|
query->server->queries =
|
|
|
|
g_slist_append(query->server->queries, query);
|
|
|
|
}
|
|
|
|
}
|
2000-08-26 11:39:44 -04:00
|
|
|
|
|
|
|
signal_emit("query created", 2, query, GINT_TO_POINTER(automatic));
|
|
|
|
}
|
|
|
|
|
|
|
|
void query_destroy(QUERY_REC *query)
|
|
|
|
{
|
|
|
|
g_return_if_fail(IS_QUERY(query));
|
|
|
|
|
|
|
|
if (query->destroying) return;
|
|
|
|
query->destroying = TRUE;
|
|
|
|
|
|
|
|
queries = g_slist_remove(queries, query);
|
|
|
|
if (query->server != NULL) {
|
|
|
|
query->server->queries =
|
|
|
|
g_slist_remove(query->server->queries, query);
|
|
|
|
}
|
|
|
|
signal_emit("query destroyed", 1, query);
|
|
|
|
|
|
|
|
MODULE_DATA_DEINIT(query);
|
2001-03-16 21:32:32 -05:00
|
|
|
g_free_not_null(query->hilight_color);
|
2001-01-01 12:13:55 -05:00
|
|
|
g_free_not_null(query->server_tag);
|
2000-08-26 11:39:44 -04:00
|
|
|
g_free_not_null(query->address);
|
2002-05-15 20:34:37 -04:00
|
|
|
g_free(query->visible_name);
|
2000-08-26 11:39:44 -04:00
|
|
|
g_free(query->name);
|
2002-02-07 14:17:36 -05:00
|
|
|
|
|
|
|
query->type = 0;
|
2000-08-26 11:39:44 -04:00
|
|
|
g_free(query);
|
|
|
|
}
|
|
|
|
|
|
|
|
static QUERY_REC *query_find_server(SERVER_REC *server, const char *nick)
|
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
g_return_val_if_fail(IS_SERVER(server), NULL);
|
|
|
|
|
|
|
|
if (server->query_find_func != NULL) {
|
|
|
|
/* use the server specific query find function */
|
2000-09-30 18:49:48 -04:00
|
|
|
return server->query_find_func(server, nick);
|
2000-08-26 11:39:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (tmp = server->queries; tmp != NULL; tmp = tmp->next) {
|
|
|
|
QUERY_REC *rec = tmp->data;
|
|
|
|
|
2014-06-10 12:06:19 -04:00
|
|
|
if (g_ascii_strcasecmp(rec->name, nick) == 0)
|
2000-08-26 11:39:44 -04:00
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
QUERY_REC *query_find(SERVER_REC *server, const char *nick)
|
|
|
|
{
|
2001-01-09 13:56:56 -05:00
|
|
|
GSList *tmp;
|
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
g_return_val_if_fail(server == NULL || IS_SERVER(server), NULL);
|
|
|
|
g_return_val_if_fail(nick != NULL, NULL);
|
|
|
|
|
|
|
|
if (server != NULL)
|
|
|
|
return query_find_server(server, nick);
|
|
|
|
|
2001-01-09 13:56:56 -05:00
|
|
|
for (tmp = queries; tmp != NULL; tmp = tmp->next) {
|
|
|
|
QUERY_REC *rec = tmp->data;
|
|
|
|
|
2014-06-10 12:06:19 -04:00
|
|
|
if (g_ascii_strcasecmp(rec->name, nick) == 0)
|
2001-01-09 13:56:56 -05:00
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2000-08-26 11:39:44 -04:00
|
|
|
}
|
|
|
|
|
2000-12-16 21:20:22 -05:00
|
|
|
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);
|
2002-05-15 20:34:37 -04:00
|
|
|
|
|
|
|
g_free(query->visible_name);
|
|
|
|
query->visible_name = g_strdup(nick);
|
|
|
|
|
2000-12-16 21:20:22 -05:00
|
|
|
signal_emit("query nick changed", 2, query, oldnick);
|
2002-04-17 17:03:04 -04:00
|
|
|
signal_emit("window item name changed", 1, query);
|
2000-12-16 21:20:22 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
void query_change_server(QUERY_REC *query, SERVER_REC *server)
|
|
|
|
{
|
|
|
|
g_return_if_fail(IS_QUERY(query));
|
|
|
|
|
2001-01-01 14:29:05 -05:00
|
|
|
if (query->server != NULL) {
|
|
|
|
query->server->queries =
|
|
|
|
g_slist_remove(query->server->queries, query);
|
|
|
|
}
|
|
|
|
if (server != NULL)
|
|
|
|
server->queries = g_slist_append(server->queries, query);
|
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
query->server = server;
|
2000-12-16 21:20:22 -05:00
|
|
|
signal_emit("query server changed", 1, query);
|
2000-08-26 11:39:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void queries_init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void queries_deinit(void)
|
|
|
|
{
|
|
|
|
}
|