mirror of
https://github.com/irssi/irssi.git
synced 2024-11-03 04:27:19 -05:00
Query windows are now restored if they were saved with /SAVEWINDOWS.
Moved /QUERY command handling to fe-query and simplified handling the -window option. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@594 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
c036632b8f
commit
98b037ac71
@ -101,6 +101,7 @@ void fe_common_core_init(void)
|
||||
window_activity_init();
|
||||
window_commands_init();
|
||||
window_items_init();
|
||||
window_save_init();
|
||||
fe_core_commands_init();
|
||||
}
|
||||
|
||||
@ -121,6 +122,7 @@ void fe_common_core_deinit(void)
|
||||
window_activity_deinit();
|
||||
window_commands_deinit();
|
||||
window_items_deinit();
|
||||
window_save_deinit();
|
||||
fe_core_commands_deinit();
|
||||
|
||||
theme_unregister();
|
||||
|
@ -31,16 +31,23 @@
|
||||
#include "windows.h"
|
||||
#include "window-items.h"
|
||||
|
||||
static void sig_window_restore_item(WINDOW_REC *window, const char *item)
|
||||
{
|
||||
window->waiting_channels =
|
||||
g_slist_append(window->waiting_channels, g_strdup(item));
|
||||
}
|
||||
|
||||
static void window_add_items(WINDOW_REC *window, CONFIG_NODE *node)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
if (node == NULL)
|
||||
return;
|
||||
|
||||
for (tmp = node->value; tmp != NULL; tmp = tmp->next) {
|
||||
CONFIG_NODE *node = tmp->data;
|
||||
|
||||
window->waiting_channels =
|
||||
g_slist_append(window->waiting_channels,
|
||||
g_strdup(node->value));
|
||||
signal_emit("window restore item", 2, window, node->value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,29 +72,19 @@ void windows_restore(void)
|
||||
if (window->theme_name != NULL)
|
||||
window->theme = theme_load(window->theme_name);
|
||||
|
||||
window_add_items(window, config_node_section(node, "items", -1));
|
||||
window_add_items(window, config_node_section(node, "items", -1));
|
||||
signal_emit("window restore", 2, window, node);
|
||||
}
|
||||
|
||||
signal_emit("windows restored", 0);
|
||||
}
|
||||
|
||||
static void window_save(WINDOW_REC *window, CONFIG_NODE *node)
|
||||
static void window_save_items(WINDOW_REC *window, CONFIG_NODE *node)
|
||||
{
|
||||
GSList *tmp;
|
||||
char refnum[MAX_INT_STRLEN], *str;
|
||||
char *str;
|
||||
|
||||
ltoa(refnum, window->refnum);
|
||||
node = config_node_section(node, refnum, NODE_TYPE_BLOCK);
|
||||
|
||||
if (window->name != NULL)
|
||||
iconfig_node_set_str(node, "name", window->name);
|
||||
if (window->level != 0) {
|
||||
char *level = bits2level(window->level);
|
||||
iconfig_node_set_str(node, "level", level);
|
||||
g_free(level);
|
||||
}
|
||||
if (window->theme_name != NULL)
|
||||
iconfig_node_set_str(node, "theme", window->theme_name);
|
||||
|
||||
node = config_node_section(node, "items", NODE_TYPE_LIST);
|
||||
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;
|
||||
@ -102,6 +99,29 @@ static void window_save(WINDOW_REC *window, CONFIG_NODE *node)
|
||||
}
|
||||
}
|
||||
|
||||
static void window_save(WINDOW_REC *window, CONFIG_NODE *node)
|
||||
{
|
||||
char refnum[MAX_INT_STRLEN];
|
||||
|
||||
ltoa(refnum, window->refnum);
|
||||
node = config_node_section(node, refnum, NODE_TYPE_BLOCK);
|
||||
|
||||
if (window->name != NULL)
|
||||
iconfig_node_set_str(node, "name", window->name);
|
||||
if (window->level != 0) {
|
||||
char *level = bits2level(window->level);
|
||||
iconfig_node_set_str(node, "level", level);
|
||||
g_free(level);
|
||||
}
|
||||
if (window->theme_name != NULL)
|
||||
iconfig_node_set_str(node, "theme", window->theme_name);
|
||||
|
||||
if (window->items != NULL)
|
||||
window_save_items(window, node);
|
||||
|
||||
signal_emit("window save", 2, window, node);
|
||||
}
|
||||
|
||||
void windows_save(void)
|
||||
{
|
||||
CONFIG_NODE *node;
|
||||
@ -110,5 +130,15 @@ void windows_save(void)
|
||||
node = iconfig_node_traverse("windows", TRUE);
|
||||
|
||||
g_slist_foreach(windows, (GFunc) window_save, node);
|
||||
signal_emit("windows saved", 0);
|
||||
}
|
||||
|
||||
void window_save_init(void)
|
||||
{
|
||||
signal_add("window restore item", (SIGNAL_FUNC) sig_window_restore_item);
|
||||
}
|
||||
|
||||
void window_save_deinit(void)
|
||||
{
|
||||
signal_remove("window restore item", (SIGNAL_FUNC) sig_window_restore_item);
|
||||
}
|
||||
|
@ -4,4 +4,7 @@
|
||||
void windows_restore(void);
|
||||
void windows_save(void);
|
||||
|
||||
void window_save_init(void);
|
||||
void window_save_deinit(void);
|
||||
|
||||
#endif
|
||||
|
@ -38,74 +38,6 @@
|
||||
#include "windows.h"
|
||||
#include "window-items.h"
|
||||
|
||||
/* SYNTAX: UNQUERY [<nick>] */
|
||||
static void cmd_unquery(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
|
||||
{
|
||||
QUERY_REC *query;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
|
||||
if (*data == '\0') {
|
||||
/* remove current query */
|
||||
query = irc_item_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 <nick> */
|
||||
static void cmd_query(const char *data, IRC_SERVER_REC *server, WI_IRC_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 | PARAM_FLAG_GETREST,
|
||||
"query", &optlist, &nick))
|
||||
return;
|
||||
if (*nick == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
||||
server = irccmd_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);
|
||||
|
||||
query = query_find(server, nick);
|
||||
if (query == NULL)
|
||||
query_create(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);
|
||||
}
|
||||
|
||||
cmd_params_free(free_arg);
|
||||
}
|
||||
|
||||
static void cmd_msg(gchar *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
|
||||
{
|
||||
GHashTable *optlist;
|
||||
@ -494,8 +426,6 @@ static void cmd_ts(const char *data)
|
||||
|
||||
void fe_irc_commands_init(void)
|
||||
{
|
||||
command_bind("query", NULL, (SIGNAL_FUNC) cmd_query);
|
||||
command_bind("unquery", NULL, (SIGNAL_FUNC) cmd_unquery);
|
||||
command_bind_last("msg", NULL, (SIGNAL_FUNC) cmd_msg);
|
||||
command_bind_last("me", NULL, (SIGNAL_FUNC) cmd_me);
|
||||
command_bind_last("action", NULL, (SIGNAL_FUNC) cmd_action);
|
||||
@ -513,8 +443,6 @@ void fe_irc_commands_init(void)
|
||||
|
||||
void fe_irc_commands_deinit(void)
|
||||
{
|
||||
command_unbind("query", (SIGNAL_FUNC) cmd_query);
|
||||
command_unbind("unquery", (SIGNAL_FUNC) cmd_unquery);
|
||||
command_unbind("msg", (SIGNAL_FUNC) cmd_msg);
|
||||
command_unbind("me", (SIGNAL_FUNC) cmd_me);
|
||||
command_unbind("action", (SIGNAL_FUNC) cmd_action);
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "settings.h"
|
||||
|
||||
#include "irc.h"
|
||||
#include "irc-commands.h"
|
||||
#include "levels.h"
|
||||
#include "query.h"
|
||||
|
||||
@ -129,39 +130,81 @@ static void cmd_window_server(const char *data)
|
||||
}
|
||||
}
|
||||
|
||||
static void cmd_wquery_pre(const char *data)
|
||||
/* SYNTAX: UNQUERY [<nick>] */
|
||||
static void cmd_unquery(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
|
||||
{
|
||||
QUERY_REC *query;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
|
||||
if (*data == '\0') {
|
||||
/* remove current query */
|
||||
query = irc_item_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 <nick> */
|
||||
static void cmd_query(const char *data, IRC_SERVER_REC *server, WI_IRC_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 | PARAM_FLAG_GETREST,
|
||||
"query", &optlist, &nick))
|
||||
return;
|
||||
if (*nick == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
||||
server = irccmd_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);
|
||||
}
|
||||
cmd_params_free(free_arg);
|
||||
}
|
||||
|
||||
static void cmd_wquery_post(const char *data)
|
||||
{
|
||||
GHashTable *optlist;
|
||||
char *nick;
|
||||
void *free_arg;
|
||||
query = query_find(server, nick);
|
||||
if (query == NULL)
|
||||
query_create(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);
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
|
||||
PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
|
||||
"query", &optlist, &nick))
|
||||
return;
|
||||
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);
|
||||
}
|
||||
|
||||
@ -193,6 +236,29 @@ static void sig_window_changed(WINDOW_REC *window, WINDOW_REC *old_window)
|
||||
old_window->last_line = time(NULL);
|
||||
}
|
||||
|
||||
static void sig_window_restore_item(WINDOW_REC *window, const char *item)
|
||||
{
|
||||
IRC_SERVER_REC *server;
|
||||
QUERY_REC *rec;
|
||||
char *tag, *nick;
|
||||
|
||||
tag = g_strdup(item);
|
||||
nick = strchr(tag, ' ');
|
||||
if (nick == NULL || ischannel(*(nick+1))) {
|
||||
g_free(tag);
|
||||
return;
|
||||
}
|
||||
|
||||
server = (IRC_SERVER_REC *) server_find_tag(tag);
|
||||
|
||||
rec = query_create(server, nick+1, TRUE);
|
||||
if (server == NULL)
|
||||
rec->server_tag = g_strdup(tag);
|
||||
|
||||
g_free(tag);
|
||||
signal_stop();
|
||||
}
|
||||
|
||||
static int sig_query_autoclose(void)
|
||||
{
|
||||
WINDOW_REC *window;
|
||||
@ -237,10 +303,11 @@ void fe_query_init(void)
|
||||
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("window restore item", (SIGNAL_FUNC) sig_window_restore_item);
|
||||
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
|
||||
|
||||
command_bind_first("query", NULL, (SIGNAL_FUNC) cmd_wquery_pre);
|
||||
command_bind_last("query", NULL, (SIGNAL_FUNC) cmd_wquery_post);
|
||||
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");
|
||||
@ -255,9 +322,10 @@ void fe_query_deinit(void)
|
||||
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("window restore item", (SIGNAL_FUNC) sig_window_restore_item);
|
||||
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
|
||||
|
||||
command_unbind("query", (SIGNAL_FUNC) cmd_wquery_pre);
|
||||
command_unbind("query", (SIGNAL_FUNC) cmd_wquery_post);
|
||||
command_unbind("query", (SIGNAL_FUNC) cmd_query);
|
||||
command_unbind("unquery", (SIGNAL_FUNC) cmd_unquery);
|
||||
command_unbind("window server", (SIGNAL_FUNC) cmd_window_server);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user