diff options
author | Timo Sirainen <cras@irssi.org> | 2000-08-12 22:58:16 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2000-08-12 22:58:16 +0000 |
commit | 98b037ac71ea253cb4cfe806bf3b524cd87de1bc (patch) | |
tree | 2a11b5bbb62f605a706b5d1a8c672708b767393d | |
parent | c036632b8f44e3fbb4072505f32d71c7a3caabb8 (diff) | |
download | irssi-98b037ac71ea253cb4cfe806bf3b524cd87de1bc.zip |
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
-rw-r--r-- | src/fe-common/core/fe-common-core.c | 2 | ||||
-rw-r--r-- | src/fe-common/core/window-save.c | 66 | ||||
-rw-r--r-- | src/fe-common/core/window-save.h | 3 | ||||
-rw-r--r-- | src/fe-common/irc/fe-irc-commands.c | 72 | ||||
-rw-r--r-- | src/fe-common/irc/fe-query.c | 102 |
5 files changed, 138 insertions, 107 deletions
diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c index cbfb4260..d192136b 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -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(); diff --git a/src/fe-common/core/window-save.c b/src/fe-common/core/window-save.c index 31b71cb7..fdf253a3 100644 --- a/src/fe-common/core/window-save.c +++ b/src/fe-common/core/window-save.c @@ -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,14 +72,36 @@ 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; + + 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); + } + } +} + +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); @@ -87,19 +116,10 @@ static void window_save(WINDOW_REC *window, CONFIG_NODE *node) if (window->theme_name != NULL) iconfig_node_set_str(node, "theme", window->theme_name); - 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 (window->items != NULL) + window_save_items(window, node); - 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); - } - } + signal_emit("window save", 2, window, node); } void windows_save(void) @@ -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); +} diff --git a/src/fe-common/core/window-save.h b/src/fe-common/core/window-save.h index ae30b232..80d801db 100644 --- a/src/fe-common/core/window-save.h +++ b/src/fe-common/core/window-save.h @@ -4,4 +4,7 @@ void windows_restore(void); void windows_save(void); +void window_save_init(void); +void window_save_deinit(void); + #endif diff --git a/src/fe-common/irc/fe-irc-commands.c b/src/fe-common/irc/fe-irc-commands.c index 260acbba..e54b7a47 100644 --- a/src/fe-common/irc/fe-irc-commands.c +++ b/src/fe-common/irc/fe-irc-commands.c @@ -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); diff --git a/src/fe-common/irc/fe-query.c b/src/fe-common/irc/fe-query.c index 6fe9bf64..377395a2 100644 --- a/src/fe-common/irc/fe-query.c +++ b/src/fe-common/irc/fe-query.c @@ -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) { - GHashTable *optlist; - char *nick; - void *free_arg; + QUERY_REC *query; - if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS | - PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST, - "query", &optlist, &nick)) - return; + g_return_if_fail(data != NULL); - if (g_hash_table_lookup(optlist, "window") != NULL) { - signal_add("query created", - (SIGNAL_FUNC) signal_query_created_curwin); + 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; + } } - cmd_params_free(free_arg); + + query_destroy(query); } -static void cmd_wquery_post(const char *data) +/* 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); + } + + 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); + } 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); } |