mirror of
https://github.com/irssi/irssi.git
synced 2026-08-10 04:13:32 +02:00
Updates.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@641 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
28a7908e73
commit
755a8d40eb
31 changed files with 386 additions and 217 deletions
|
|
@ -10,10 +10,12 @@ libfe_common_core_a_SOURCES = \
|
|||
autorun.c \
|
||||
command-history.c \
|
||||
completion.c \
|
||||
fe-channels.c \
|
||||
fe-common-core.c \
|
||||
fe-core-commands.c \
|
||||
fe-log.c \
|
||||
fe-modules.c \
|
||||
fe-queries.c \
|
||||
fe-server.c \
|
||||
fe-settings.c \
|
||||
hilight-text.c \
|
||||
|
|
@ -32,6 +34,7 @@ noinst_HEADERS = \
|
|||
command-history.h \
|
||||
completion.h \
|
||||
fe-common-core.h \
|
||||
fe-queries.h \
|
||||
hilight-text.h \
|
||||
keyboard.h \
|
||||
module-formats.h \
|
||||
|
|
|
|||
313
src/fe-common/core/fe-channels.c
Normal file
313
src/fe-common/core/fe-channels.c
Normal file
|
|
@ -0,0 +1,313 @@
|
|||
/*
|
||||
fe-channels.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.
|
||||
|
||||
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 "module-formats.h"
|
||||
#include "modules.h"
|
||||
#include "signals.h"
|
||||
#include "commands.h"
|
||||
#include "levels.h"
|
||||
#include "misc.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "channels-setup.h"
|
||||
#include "nicklist.h"
|
||||
|
||||
#include "windows.h"
|
||||
#include "window-items.h"
|
||||
|
||||
static void signal_channel_created(CHANNEL_REC *channel, gpointer automatic)
|
||||
{
|
||||
if (window_item_find(channel->server, channel->name) == NULL) {
|
||||
window_item_create((WI_ITEM_REC *) channel,
|
||||
GPOINTER_TO_INT(automatic));
|
||||
}
|
||||
}
|
||||
|
||||
static void signal_channel_created_curwin(CHANNEL_REC *channel)
|
||||
{
|
||||
g_return_if_fail(channel != NULL);
|
||||
|
||||
window_add_item(active_win, (WI_ITEM_REC *) channel, FALSE);
|
||||
}
|
||||
|
||||
static void signal_channel_destroyed(CHANNEL_REC *channel)
|
||||
{
|
||||
WINDOW_REC *window;
|
||||
|
||||
g_return_if_fail(channel != NULL);
|
||||
|
||||
window = window_item_window((WI_ITEM_REC *) channel);
|
||||
if (window != NULL) {
|
||||
window_remove_item(window, (WI_ITEM_REC *) channel);
|
||||
|
||||
if (window->items == NULL && windows->next != NULL &&
|
||||
(!channel->joined || channel->left) &&
|
||||
settings_get_bool("autoclose_windows")) {
|
||||
window_destroy(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void signal_window_item_removed(WINDOW_REC *window, WI_ITEM_REC *item)
|
||||
{
|
||||
CHANNEL_REC *channel;
|
||||
|
||||
g_return_if_fail(window != NULL);
|
||||
|
||||
channel = CHANNEL(item);
|
||||
if (channel != NULL) channel_destroy(channel);
|
||||
}
|
||||
|
||||
static void sig_disconnected(SERVER_REC *server)
|
||||
{
|
||||
WINDOW_REC *window;
|
||||
GSList *tmp;
|
||||
|
||||
g_return_if_fail(IS_SERVER(server));
|
||||
|
||||
for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
|
||||
CHANNEL_REC *channel = tmp->data;
|
||||
|
||||
window = window_item_window((WI_ITEM_REC *) channel);
|
||||
window->waiting_channels =
|
||||
g_slist_append(window->waiting_channels, g_strdup_printf("%s %s", server->tag, channel->name));
|
||||
}
|
||||
}
|
||||
|
||||
static void signal_window_item_changed(WINDOW_REC *window, WI_ITEM_REC *item)
|
||||
{
|
||||
g_return_if_fail(window != NULL);
|
||||
if (item == NULL) return;
|
||||
|
||||
if (g_slist_length(window->items) > 1 && IS_CHANNEL(item)) {
|
||||
printformat(item->server, item->name, MSGLEVEL_CLIENTNOTICE,
|
||||
IRCTXT_TALKING_IN, item->name);
|
||||
signal_stop();
|
||||
}
|
||||
}
|
||||
|
||||
static void cmd_wjoin_pre(const char *data)
|
||||
{
|
||||
GHashTable *optlist;
|
||||
char *nick;
|
||||
void *free_arg;
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
|
||||
PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
|
||||
"join", &optlist, &nick))
|
||||
return;
|
||||
|
||||
if (g_hash_table_lookup(optlist, "window") != NULL) {
|
||||
signal_add("channel created",
|
||||
(SIGNAL_FUNC) signal_channel_created_curwin);
|
||||
}
|
||||
cmd_params_free(free_arg);
|
||||
}
|
||||
|
||||
static void cmd_wjoin_post(const char *data)
|
||||
{
|
||||
GHashTable *optlist;
|
||||
char *nick;
|
||||
void *free_arg;
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
|
||||
PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
|
||||
"join", &optlist, &nick))
|
||||
return;
|
||||
|
||||
if (g_hash_table_lookup(optlist, "window") != NULL) {
|
||||
signal_remove("channel created",
|
||||
(SIGNAL_FUNC) signal_channel_created_curwin);
|
||||
}
|
||||
cmd_params_free(free_arg);
|
||||
}
|
||||
|
||||
static void cmd_channel_list_joined(void)
|
||||
{
|
||||
CHANNEL_REC *channel;
|
||||
GString *nicks;
|
||||
GSList *nicklist, *tmp, *ntmp;
|
||||
|
||||
if (channels == NULL) {
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_NOT_IN_CHANNELS);
|
||||
return;
|
||||
}
|
||||
|
||||
/* print active channel */
|
||||
channel = CHANNEL(active_win->active);
|
||||
if (channel != NULL)
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_CURRENT_CHANNEL, channel->name);
|
||||
|
||||
/* print list of all channels, their modes, server tags and nicks */
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_CHANLIST_HEADER);
|
||||
for (tmp = channels; tmp != NULL; tmp = tmp->next) {
|
||||
channel = tmp->data;
|
||||
|
||||
nicklist = nicklist_getnicks(channel);
|
||||
nicks = g_string_new(NULL);
|
||||
for (ntmp = nicklist; ntmp != NULL; ntmp = ntmp->next) {
|
||||
NICK_REC *rec = ntmp->data;
|
||||
|
||||
g_string_sprintfa(nicks, "%s ", rec->nick);
|
||||
}
|
||||
|
||||
if (nicks->len > 1) g_string_truncate(nicks, nicks->len-1);
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_CHANLIST_LINE,
|
||||
channel->name, channel->mode, channel->server->tag, nicks->str);
|
||||
|
||||
g_slist_free(nicklist);
|
||||
g_string_free(nicks, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/* SYNTAX: CHANNEL LIST */
|
||||
static void cmd_channel_list(void)
|
||||
{
|
||||
GString *str;
|
||||
GSList *tmp;
|
||||
|
||||
str = g_string_new(NULL);
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_CHANSETUP_HEADER);
|
||||
for (tmp = setupchannels; tmp != NULL; tmp = tmp->next) {
|
||||
CHANNEL_SETUP_REC *rec = tmp->data;
|
||||
|
||||
g_string_truncate(str, 0);
|
||||
if (rec->autojoin)
|
||||
g_string_append(str, "autojoin, ");
|
||||
if (rec->botmasks != NULL && *rec->botmasks != '\0')
|
||||
g_string_sprintfa(str, "bots: %s, ", rec->botmasks);
|
||||
if (rec->autosendcmd != NULL && *rec->autosendcmd != '\0')
|
||||
g_string_sprintfa(str, "botcmd: %s, ", rec->autosendcmd);
|
||||
|
||||
if (str->len > 2) g_string_truncate(str, str->len-2);
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_CHANSETUP_LINE,
|
||||
rec->name, rec->chatnet == NULL ? "" : rec->chatnet,
|
||||
rec->password == NULL ? "" : rec->password, str->str);
|
||||
}
|
||||
g_string_free(str, TRUE);
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_CHANSETUP_FOOTER);
|
||||
}
|
||||
|
||||
static void cmd_channel(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
|
||||
{
|
||||
if (*data == '\0')
|
||||
cmd_channel_list_joined();
|
||||
else
|
||||
command_runsub("channel", data, server, item);
|
||||
}
|
||||
|
||||
/* SYNTAX: CHANNEL ADD [-auto | -noauto] [-bots <masks>] [-botcmd <command>]
|
||||
<channel> <chatnet> [<password>] */
|
||||
static void cmd_channel_add(const char *data)
|
||||
{
|
||||
GHashTable *optlist;
|
||||
CHANNEL_SETUP_REC *rec;
|
||||
char *botarg, *botcmdarg, *chatnet, *channel, *password;
|
||||
void *free_arg;
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS,
|
||||
"channel add", &optlist, &channel, &chatnet, &password))
|
||||
return;
|
||||
|
||||
botarg = g_hash_table_lookup(optlist, "bots");
|
||||
botcmdarg = g_hash_table_lookup(optlist, "botcmd");
|
||||
|
||||
if (*chatnet == '\0' || *channel == '\0')
|
||||
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
||||
rec = channels_setup_find(channel, chatnet);
|
||||
if (rec == NULL) {
|
||||
rec = g_new0(CHANNEL_SETUP_REC, 1);
|
||||
rec->name = g_strdup(channel);
|
||||
rec->chatnet = g_strdup(chatnet);
|
||||
} else {
|
||||
if (g_hash_table_lookup(optlist, "bots")) g_free_and_null(rec->botmasks);
|
||||
if (g_hash_table_lookup(optlist, "botcmd")) g_free_and_null(rec->autosendcmd);
|
||||
if (*password != '\0') g_free_and_null(rec->password);
|
||||
}
|
||||
if (g_hash_table_lookup(optlist, "auto")) rec->autojoin = TRUE;
|
||||
if (g_hash_table_lookup(optlist, "noauto")) rec->autojoin = FALSE;
|
||||
if (botarg != NULL && *botarg != '\0') rec->botmasks = g_strdup(botarg);
|
||||
if (botcmdarg != NULL && *botcmdarg != '\0') rec->autosendcmd = g_strdup(botcmdarg);
|
||||
if (*password != '\0' && strcmp(password, "-") != 0) rec->password = g_strdup(password);
|
||||
channels_setup_create(rec);
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_CHANSETUP_ADDED, channel, chatnet);
|
||||
|
||||
cmd_params_free(free_arg);
|
||||
}
|
||||
|
||||
/* SYNTAX: CHANNEL REMOVE <channel> <chatnet> */
|
||||
static void cmd_channel_remove(const char *data)
|
||||
{
|
||||
CHANNEL_SETUP_REC *rec;
|
||||
char *chatnet, *channel;
|
||||
void *free_arg;
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 2, &channel, &chatnet))
|
||||
return;
|
||||
if (*chatnet == '\0' || *channel == '\0')
|
||||
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
||||
|
||||
rec = channels_setup_find(channel, chatnet);
|
||||
if (rec == NULL)
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_CHANSETUP_NOT_FOUND, channel, chatnet);
|
||||
else {
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_CHANSETUP_REMOVED, channel, chatnet);
|
||||
channels_setup_destroy(rec);
|
||||
}
|
||||
cmd_params_free(free_arg);
|
||||
}
|
||||
|
||||
void fe_channels_init(void)
|
||||
{
|
||||
settings_add_bool("lookandfeel", "autoclose_windows", TRUE);
|
||||
|
||||
signal_add("channel created", (SIGNAL_FUNC) signal_channel_created);
|
||||
signal_add("channel destroyed", (SIGNAL_FUNC) signal_channel_destroyed);
|
||||
signal_add("window item remove", (SIGNAL_FUNC) signal_window_item_removed);
|
||||
signal_add_last("window item changed", (SIGNAL_FUNC) signal_window_item_changed);
|
||||
signal_add_last("server disconnected", (SIGNAL_FUNC) sig_disconnected);
|
||||
|
||||
command_bind_first("join", NULL, (SIGNAL_FUNC) cmd_wjoin_pre);
|
||||
command_bind_last("join", NULL, (SIGNAL_FUNC) cmd_wjoin_post);
|
||||
command_bind("channel", NULL, (SIGNAL_FUNC) cmd_channel);
|
||||
command_bind("channel add", NULL, (SIGNAL_FUNC) cmd_channel_add);
|
||||
command_bind("channel remove", NULL, (SIGNAL_FUNC) cmd_channel_remove);
|
||||
command_bind("channel list", NULL, (SIGNAL_FUNC) cmd_channel_list);
|
||||
|
||||
command_set_options("channel add", "auto noauto -bots -botcmd");
|
||||
command_set_options("join", "window");
|
||||
}
|
||||
|
||||
void fe_channels_deinit(void)
|
||||
{
|
||||
signal_remove("channel created", (SIGNAL_FUNC) signal_channel_created);
|
||||
signal_remove("channel destroyed", (SIGNAL_FUNC) signal_channel_destroyed);
|
||||
signal_remove("window item remove", (SIGNAL_FUNC) signal_window_item_removed);
|
||||
signal_remove("window item changed", (SIGNAL_FUNC) signal_window_item_changed);
|
||||
signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected);
|
||||
|
||||
command_unbind("join", (SIGNAL_FUNC) cmd_wjoin_pre);
|
||||
command_unbind("join", (SIGNAL_FUNC) cmd_wjoin_post);
|
||||
command_unbind("channel", (SIGNAL_FUNC) cmd_channel);
|
||||
command_unbind("channel add", (SIGNAL_FUNC) cmd_channel_add);
|
||||
command_unbind("channel remove", (SIGNAL_FUNC) cmd_channel_remove);
|
||||
command_unbind("channel list", (SIGNAL_FUNC) cmd_channel_list);
|
||||
}
|
||||
|
|
@ -23,6 +23,7 @@
|
|||
#include "levels.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "fe-queries.h"
|
||||
#include "hilight-text.h"
|
||||
#include "command-history.h"
|
||||
#include "completion.h"
|
||||
|
|
@ -39,6 +40,9 @@
|
|||
void autorun_init(void);
|
||||
void autorun_deinit(void);
|
||||
|
||||
void fe_channels_init(void);
|
||||
void fe_channels_deinit(void);
|
||||
|
||||
void fe_core_log_init(void);
|
||||
void fe_core_log_deinit(void);
|
||||
|
||||
|
|
@ -92,6 +96,8 @@ void fe_common_core_init(void)
|
|||
completion_init();
|
||||
keyboard_init();
|
||||
printtext_init();
|
||||
fe_channels_init();
|
||||
fe_queries_init();
|
||||
fe_log_init();
|
||||
fe_modules_init();
|
||||
fe_server_init();
|
||||
|
|
@ -113,6 +119,8 @@ void fe_common_core_deinit(void)
|
|||
completion_deinit();
|
||||
keyboard_deinit();
|
||||
printtext_deinit();
|
||||
fe_channels_deinit();
|
||||
fe_queries_deinit();
|
||||
fe_log_deinit();
|
||||
fe_modules_deinit();
|
||||
fe_server_deinit();
|
||||
|
|
|
|||
312
src/fe-common/core/fe-queries.c
Normal file
312
src/fe-common/core/fe-queries.c
Normal file
|
|
@ -0,0 +1,312 @@
|
|||
/*
|
||||
fe-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.
|
||||
|
||||
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 "module-formats.h"
|
||||
#include "modules.h"
|
||||
#include "signals.h"
|
||||
#include "commands.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "levels.h"
|
||||
#include "queries.h"
|
||||
|
||||
#include "windows.h"
|
||||
#include "window-items.h"
|
||||
|
||||
static int queryclose_tag, query_auto_close;
|
||||
|
||||
/* Return query where to put the private message. */
|
||||
QUERY_REC *privmsg_get_query(SERVER_REC *server, const char *nick, int own)
|
||||
{
|
||||
QUERY_REC *query;
|
||||
|
||||
g_return_val_if_fail(IS_SERVER(server), NULL);
|
||||
g_return_val_if_fail(nick != NULL, NULL);
|
||||
|
||||
query = query_find(server, nick);
|
||||
if (query == NULL && settings_get_bool("autocreate_query") &&
|
||||
(!own || settings_get_bool("autocreate_own_query")))
|
||||
query = query_create(server->chat_type, server, nick, TRUE);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
static void signal_query_created(QUERY_REC *query, gpointer automatic)
|
||||
{
|
||||
if (window_item_find(query->server, query->name) != NULL)
|
||||
return;
|
||||
|
||||
window_item_create((WI_ITEM_REC *) query, GPOINTER_TO_INT(automatic));
|
||||
printformat(query->server, query->name, MSGLEVEL_CLIENTNOTICE,
|
||||
IRCTXT_QUERY_STARTED, query->name);
|
||||
}
|
||||
|
||||
static void signal_query_created_curwin(QUERY_REC *query)
|
||||
{
|
||||
g_return_if_fail(query != NULL);
|
||||
|
||||
window_add_item(active_win, (WI_ITEM_REC *) query, FALSE);
|
||||
}
|
||||
|
||||
static void signal_query_destroyed(QUERY_REC *query)
|
||||
{
|
||||
WINDOW_REC *window;
|
||||
|
||||
g_return_if_fail(query != NULL);
|
||||
|
||||
window = window_item_window((WI_ITEM_REC *) query);
|
||||
if (window != NULL) {
|
||||
window_remove_item(window, (WI_ITEM_REC *) query);
|
||||
|
||||
if (window->items == NULL && windows->next != NULL &&
|
||||
!query->unwanted && settings_get_bool("autoclose_windows"))
|
||||
window_destroy(window);
|
||||
}
|
||||
}
|
||||
|
||||
static void signal_window_item_removed(WINDOW_REC *window, WI_ITEM_REC *item)
|
||||
{
|
||||
QUERY_REC *query;
|
||||
|
||||
g_return_if_fail(window != NULL);
|
||||
|
||||
query = QUERY(item);
|
||||
if (query != NULL) query_destroy(query);
|
||||
}
|
||||
|
||||
static void sig_server_connected(SERVER_REC *server)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
if (!IS_SERVER(server))
|
||||
return;
|
||||
|
||||
/* check if there's any queries without server */
|
||||
for (tmp = queries; tmp != NULL; tmp = tmp->next) {
|
||||
QUERY_REC *rec = tmp->data;
|
||||
|
||||
if (rec->server == 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void cmd_window_server(const char *data)
|
||||
{
|
||||
SERVER_REC *server;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
|
||||
server = server_find_tag(data);
|
||||
if (!IS_SERVER(server) || !IS_QUERY(active_win->active))
|
||||
return;
|
||||
|
||||
/* /WINDOW SERVER used in a query window */
|
||||
query_change_server(QUERY(active_win->active), server);
|
||||
window_change_server(active_win, server);
|
||||
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
||||
IRCTXT_QUERY_SERVER_CHANGED,
|
||||
server->tag, server->connrec->address,
|
||||
server->connrec->chatnet == NULL ? "" :
|
||||
server->connrec->chatnet);
|
||||
|
||||
signal_stop();
|
||||
}
|
||||
|
||||
/* SYNTAX: UNQUERY [<nick>] */
|
||||
static void cmd_unquery(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
|
||||
{
|
||||
QUERY_REC *query;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
|
||||
if (*data == '\0') {
|
||||
/* remove current query */
|
||||
query = QUERY(item);
|
||||
if (query == NULL) return;
|
||||
} else {
|
||||
query = query_find(server, data);
|
||||
if (query == NULL) {
|
||||
printformat(server, NULL, MSGLEVEL_CLIENTERROR,
|
||||
IRCTXT_NO_QUERY, data);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
query_destroy(query);
|
||||
}
|
||||
|
||||
/* SYNTAX: QUERY [-window] <nick> */
|
||||
static void cmd_query(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
|
||||
{
|
||||
GHashTable *optlist;
|
||||
WINDOW_REC *window;
|
||||
QUERY_REC *query;
|
||||
char *nick;
|
||||
void *free_arg;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
|
||||
if (*data == '\0') {
|
||||
/* remove current query */
|
||||
cmd_unquery("", server, item);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
|
||||
PARAM_FLAG_UNKNOWN_OPTIONS,
|
||||
"query", &optlist, &nick))
|
||||
return;
|
||||
if (*nick == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
||||
|
||||
server = cmd_options_get_server("query", optlist, server);
|
||||
if (server == NULL) {
|
||||
cmd_params_free(free_arg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (*nick != '=' && (server == NULL || !server->connected))
|
||||
cmd_param_error(CMDERR_NOT_CONNECTED);
|
||||
|
||||
if (g_hash_table_lookup(optlist, "window") != NULL) {
|
||||
signal_add("query created",
|
||||
(SIGNAL_FUNC) signal_query_created_curwin);
|
||||
}
|
||||
|
||||
query = query_find(server, nick);
|
||||
if (query == NULL)
|
||||
query_create(server->chat_type, server, nick, FALSE);
|
||||
else {
|
||||
/* query already existed - change to query window */
|
||||
window = window_item_window((WI_ITEM_REC *) query);
|
||||
g_return_if_fail(window != NULL);
|
||||
|
||||
window_set_active(window);
|
||||
window_item_set_active(window, (WI_ITEM_REC *) query);
|
||||
}
|
||||
|
||||
if (g_hash_table_lookup(optlist, "window") != NULL) {
|
||||
signal_remove("query created",
|
||||
(SIGNAL_FUNC) signal_query_created_curwin);
|
||||
}
|
||||
|
||||
cmd_params_free(free_arg);
|
||||
}
|
||||
|
||||
static int window_has_query(WINDOW_REC *window)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
g_return_val_if_fail(window != NULL, FALSE);
|
||||
|
||||
for (tmp = window->items; tmp != NULL; tmp = tmp->next) {
|
||||
if (IS_QUERY(tmp->data))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void sig_window_changed(WINDOW_REC *window, WINDOW_REC *old_window)
|
||||
{
|
||||
if (query_auto_close <= 0)
|
||||
return;
|
||||
|
||||
/* reset the window's last_line timestamp so that query doesn't get
|
||||
closed immediately after switched to the window, or after changed
|
||||
to some other window from it */
|
||||
if (window != NULL && window_has_query(window))
|
||||
window->last_line = time(NULL);
|
||||
if (old_window != NULL && window_has_query(old_window))
|
||||
old_window->last_line = time(NULL);
|
||||
}
|
||||
|
||||
static int sig_query_autoclose(void)
|
||||
{
|
||||
WINDOW_REC *window;
|
||||
GSList *tmp, *next;
|
||||
time_t now;
|
||||
|
||||
now = time(NULL);
|
||||
for (tmp = queries; tmp != NULL; tmp = next) {
|
||||
QUERY_REC *rec = tmp->data;
|
||||
|
||||
next = tmp->next;
|
||||
window = window_item_window((WI_ITEM_REC *) rec);
|
||||
if (window != active_win && rec->new_data == 0 &&
|
||||
now-window->last_line > query_auto_close)
|
||||
query_destroy(rec);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void read_settings(void)
|
||||
{
|
||||
query_auto_close = settings_get_int("autoclose_query");
|
||||
if (query_auto_close > 0 && queryclose_tag == -1)
|
||||
queryclose_tag = g_timeout_add(5000, (GSourceFunc) sig_query_autoclose, NULL);
|
||||
else if (query_auto_close <= 0 && queryclose_tag != -1) {
|
||||
g_source_remove(queryclose_tag);
|
||||
queryclose_tag = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void fe_queries_init(void)
|
||||
{
|
||||
settings_add_bool("lookandfeel", "autocreate_query", TRUE);
|
||||
settings_add_bool("lookandfeel", "autocreate_own_query", TRUE);
|
||||
settings_add_int("lookandfeel", "autoclose_query", 0);
|
||||
|
||||
queryclose_tag = -1;
|
||||
read_settings();
|
||||
|
||||
signal_add("query created", (SIGNAL_FUNC) signal_query_created);
|
||||
signal_add("query destroyed", (SIGNAL_FUNC) signal_query_destroyed);
|
||||
signal_add("window item remove", (SIGNAL_FUNC) signal_window_item_removed);
|
||||
signal_add("server connected", (SIGNAL_FUNC) sig_server_connected);
|
||||
signal_add("window changed", (SIGNAL_FUNC) sig_window_changed);
|
||||
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
|
||||
|
||||
command_bind("query", NULL, (SIGNAL_FUNC) cmd_query);
|
||||
command_bind("unquery", NULL, (SIGNAL_FUNC) cmd_unquery);
|
||||
command_bind("window server", NULL, (SIGNAL_FUNC) cmd_window_server);
|
||||
|
||||
command_set_options("query", "window");
|
||||
}
|
||||
|
||||
void fe_queries_deinit(void)
|
||||
{
|
||||
if (queryclose_tag != -1) g_source_remove(queryclose_tag);
|
||||
|
||||
signal_remove("query created", (SIGNAL_FUNC) signal_query_created);
|
||||
signal_remove("query destroyed", (SIGNAL_FUNC) signal_query_destroyed);
|
||||
signal_remove("window item remove", (SIGNAL_FUNC) signal_window_item_removed);
|
||||
signal_remove("server connected", (SIGNAL_FUNC) sig_server_connected);
|
||||
signal_remove("window changed", (SIGNAL_FUNC) sig_window_changed);
|
||||
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
|
||||
|
||||
command_unbind("query", (SIGNAL_FUNC) cmd_query);
|
||||
command_unbind("unquery", (SIGNAL_FUNC) cmd_unquery);
|
||||
command_unbind("window server", (SIGNAL_FUNC) cmd_window_server);
|
||||
}
|
||||
12
src/fe-common/core/fe-queries.h
Normal file
12
src/fe-common/core/fe-queries.h
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef __FE_QUERIES_H
|
||||
#define __FE_QUERIES_H
|
||||
|
||||
#include "queries.h"
|
||||
|
||||
/* Return query where to put the private message. */
|
||||
QUERY_REC *privmsg_get_query(SERVER_REC *server, const char *nick, int own);
|
||||
|
||||
void fe_queries_init(void);
|
||||
void fe_queries_deinit(void);
|
||||
|
||||
#endif
|
||||
|
|
@ -50,6 +50,28 @@ FORMAT_REC fecommon_core_formats[] = {
|
|||
{ "server_changed", "Changed to %_$2%_ server %_$1%_", 3, { 0, 0, 0 } },
|
||||
{ "unknown_server_tag", "Unknown server tag %_$0%_", 1, { 0 } },
|
||||
|
||||
/* ---- */
|
||||
{ NULL, "Channels", 0 },
|
||||
|
||||
{ "talking_in", "You are now talking in %_$0%_", 1, { 0 } },
|
||||
{ "not_in_channels", "You are not on any channels", 0 },
|
||||
{ "current_channel", "Current channel $0", 1, { 0 } },
|
||||
{ "chanlist_header", "You are on the following channels:", 0 },
|
||||
{ "chanlist_line", "$[-10]0 %|+$1 ($2): $3", 4, { 0, 0, 0, 0 } },
|
||||
{ "chansetup_not_found", "Channel $0 not found", 2, { 0, 0 } },
|
||||
{ "chansetup_added", "Channel $0 saved", 2, { 0, 0 } },
|
||||
{ "chansetup_removed", "Channel $0 removed", 2, { 0, 0 } },
|
||||
{ "chansetup_header", "Channel IRC net Password Settings", 0 },
|
||||
{ "chansetup_line", "$[15]0 %|$[10]1 $[10]2 $3", 4, { 0, 0, 0, 0 } },
|
||||
{ "chansetup_footer", "", 0 },
|
||||
|
||||
/* ---- */
|
||||
{ NULL, "Queries", 0 },
|
||||
|
||||
{ "query_start", "Starting query with %_$0%_", 1, { 0 } },
|
||||
{ "no_query", "No query with %_$0%_", 1, { 0 } },
|
||||
{ "query_server_changed", "Query with %_$2%_ changed to server %_$1%_", 3, { 0, 0, 0 } },
|
||||
|
||||
/* ---- */
|
||||
{ NULL, "Highlighting", 0 },
|
||||
|
||||
|
|
|
|||
|
|
@ -29,13 +29,33 @@ enum {
|
|||
|
||||
IRCTXT_FILL_3,
|
||||
|
||||
IRCTXT_TALKING_IN,
|
||||
IRCTXT_NOT_IN_CHANNELS,
|
||||
IRCTXT_CURRENT_CHANNEL,
|
||||
IRCTXT_CHANLIST_HEADER,
|
||||
IRCTXT_CHANLIST_LINE,
|
||||
IRCTXT_CHANSETUP_NOT_FOUND,
|
||||
IRCTXT_CHANSETUP_ADDED,
|
||||
IRCTXT_CHANSETUP_REMOVED,
|
||||
IRCTXT_CHANSETUP_HEADER,
|
||||
IRCTXT_CHANSETUP_LINE,
|
||||
IRCTXT_CHANSETUP_FOOTER,
|
||||
|
||||
IRCTXT_FILL_4,
|
||||
|
||||
IRCTXT_QUERY_STARTED,
|
||||
IRCTXT_NO_QUERY,
|
||||
IRCTXT_QUERY_SERVER_CHANGED,
|
||||
|
||||
IRCTXT_FILL_5,
|
||||
|
||||
IRCTXT_HILIGHT_HEADER,
|
||||
IRCTXT_HILIGHT_LINE,
|
||||
IRCTXT_HILIGHT_FOOTER,
|
||||
IRCTXT_HILIGHT_NOT_FOUND,
|
||||
IRCTXT_HILIGHT_REMOVED,
|
||||
|
||||
IRCTXT_FILL_4,
|
||||
IRCTXT_FILL_6,
|
||||
|
||||
IRCTXT_ALIAS_ADDED,
|
||||
IRCTXT_ALIAS_REMOVED,
|
||||
|
|
@ -44,7 +64,7 @@ enum {
|
|||
IRCTXT_ALIASLIST_LINE,
|
||||
IRCTXT_ALIASLIST_FOOTER,
|
||||
|
||||
IRCTXT_FILL_5,
|
||||
IRCTXT_FILL_7,
|
||||
|
||||
IRCTXT_LOG_OPENED,
|
||||
IRCTXT_LOG_CLOSED,
|
||||
|
|
@ -61,7 +81,7 @@ enum {
|
|||
IRCTXT_LOG_NO_AWAY_MSGS,
|
||||
IRCTXT_LOG_AWAY_MSGS,
|
||||
|
||||
IRCTXT_FILL_6,
|
||||
IRCTXT_FILL_8,
|
||||
|
||||
IRCTXT_MODULE_ALREADY_LOADED,
|
||||
IRCTXT_MODULE_LOAD_ERROR,
|
||||
|
|
@ -69,7 +89,7 @@ enum {
|
|||
IRCTXT_MODULE_LOADED,
|
||||
IRCTXT_MODULE_UNLOADED,
|
||||
|
||||
IRCTXT_FILL_7,
|
||||
IRCTXT_FILL_9,
|
||||
|
||||
IRCTXT_COMMAND_UNKNOWN,
|
||||
IRCTXT_COMMAND_AMBIGUOUS,
|
||||
|
|
@ -83,7 +103,7 @@ enum {
|
|||
IRCTXT_CHAN_NOT_SYNCED,
|
||||
IRCTXT_NOT_GOOD_IDEA,
|
||||
|
||||
IRCTXT_FILL_8,
|
||||
IRCTXT_FILL_10,
|
||||
|
||||
IRCTXT_THEME_SAVED,
|
||||
IRCTXT_THEME_SAVE_FAILED,
|
||||
|
|
@ -93,7 +113,7 @@ enum {
|
|||
IRCTXT_FORMAT_SUBTITLE,
|
||||
IRCTXT_FORMAT_ITEM,
|
||||
|
||||
IRCTXT_FILL_9,
|
||||
IRCTXT_FILL_11,
|
||||
|
||||
IRCTXT_NOT_TOGGLE,
|
||||
IRCTXT_PERL_ERROR,
|
||||
|
|
|
|||
|
|
@ -21,25 +21,55 @@
|
|||
#include "module.h"
|
||||
#include "signals.h"
|
||||
#include "misc.h"
|
||||
#include "servers.h"
|
||||
#include "levels.h"
|
||||
#include "lib-config/iconfig.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "levels.h"
|
||||
#include "chat-protocols.h"
|
||||
#include "servers.h"
|
||||
#include "queries.h"
|
||||
|
||||
#include "themes.h"
|
||||
#include "windows.h"
|
||||
#include "window-items.h"
|
||||
|
||||
static void sig_window_restore_item(WINDOW_REC *window, const char *item)
|
||||
static void sig_window_restore_item(WINDOW_REC *window, const char *type,
|
||||
CONFIG_NODE *node)
|
||||
{
|
||||
window->waiting_channels =
|
||||
g_slist_append(window->waiting_channels, g_strdup(item));
|
||||
char *name, *tag, *chat_type, *str;
|
||||
|
||||
chat_type = config_node_get_str(node, "chat_type", NULL);
|
||||
name = config_node_get_str(node, "name", NULL);
|
||||
tag = config_node_get_str(node, "tag", NULL);
|
||||
if (name == NULL) return;
|
||||
|
||||
if (g_strcasecmp(type, "CHANNEL") == 0) {
|
||||
/* add channel to "waiting channels" list */
|
||||
str = tag == NULL ? g_strdup(name) :
|
||||
g_strdup_printf("%s %s", tag, name);
|
||||
|
||||
window->waiting_channels =
|
||||
g_slist_append(window->waiting_channels, str);
|
||||
} else if (g_strcasecmp(type, "QUERY") == 0) {
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
||||
static void window_add_items(WINDOW_REC *window, CONFIG_NODE *node)
|
||||
{
|
||||
GSList *tmp;
|
||||
char *type;
|
||||
|
||||
if (node == NULL)
|
||||
return;
|
||||
|
|
@ -47,7 +77,11 @@ static void window_add_items(WINDOW_REC *window, CONFIG_NODE *node)
|
|||
for (tmp = node->value; tmp != NULL; tmp = tmp->next) {
|
||||
CONFIG_NODE *node = tmp->data;
|
||||
|
||||
signal_emit("window restore item", 2, window, node->value);
|
||||
type = config_node_get_str(node->value, "type", NULL);
|
||||
if (type != NULL) {
|
||||
signal_emit("window restore item", 3,
|
||||
window, type, node->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -81,21 +115,27 @@ void windows_restore(void)
|
|||
|
||||
static void window_save_items(WINDOW_REC *window, CONFIG_NODE *node)
|
||||
{
|
||||
CONFIG_NODE *subnode;
|
||||
GSList *tmp;
|
||||
char *str;
|
||||
const char *type;
|
||||
|
||||
node = config_node_section(node, "items", NODE_TYPE_LIST);
|
||||
for (tmp = window->items; tmp != NULL; tmp = tmp->next) {
|
||||
WI_ITEM_REC *rec = tmp->data;
|
||||
SERVER_REC *server = rec->server;
|
||||
|
||||
if (server == NULL)
|
||||
iconfig_node_set_str(node, NULL, rec->name);
|
||||
else {
|
||||
str = g_strdup_printf("%s %s", server->tag, rec->name);
|
||||
iconfig_node_set_str(node, NULL, str);
|
||||
g_free(str);
|
||||
}
|
||||
type = module_find_id_str("WINDOW ITEM TYPE", rec->type);
|
||||
if (type == NULL) continue;
|
||||
|
||||
subnode = config_node_section(node, NULL, NODE_TYPE_BLOCK);
|
||||
|
||||
iconfig_node_set_str(subnode, "type", type);
|
||||
iconfig_node_set_str(subnode, "chat_type",
|
||||
chat_protocol_get_name(rec->chat_type));
|
||||
iconfig_node_set_str(subnode, "name", rec->name);
|
||||
|
||||
if (server != NULL)
|
||||
iconfig_node_set_str(subnode, "tag", server->tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue