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

window->active_server used to hold non-connected servers, but that was

removed before because it created several problems, especially with scripts.
however that change made /server and /disconnect annoying to use with
non-connected servers.

so, now we have window->connect_server as well. either active_server or
connect_server is set, but never both. commands that can deal properly with
non-connected servers can now use the connect_server, while everyone else
happily thinks that no server is active.


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2921 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2002-09-14 23:14:04 +00:00 committed by cras
parent 930dd40815
commit a83366069f
5 changed files with 119 additions and 24 deletions

View File

@ -161,11 +161,30 @@ void window_set_active(WINDOW_REC *window)
void window_change_server(WINDOW_REC *window, void *server)
{
SERVER_REC *active, *connect;
if (server != NULL && SERVER(server)->disconnected)
return;
window->active_server = server;
signal_emit("window server changed", 2, window, server);
if (server == NULL) {
active = connect = NULL;
} else if (SERVER(server)->connected) {
active = server;
connect = NULL;
} else {
active = NULL;
connect = server;
}
if (window->connect_server != connect) {
window->connect_server = connect;
signal_emit("window connect changed", 2, window, connect);
}
if (window->active_server != active) {
window->active_server = active;
signal_emit("window server changed", 2, window, active);
}
}
void window_set_refnum(WINDOW_REC *window, int refnum)
@ -519,7 +538,8 @@ static void sig_server_disconnected(SERVER_REC *server)
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
WINDOW_REC *rec = tmp->data;
if (rec->active_server == server) {
if (rec->active_server == server ||
rec->connect_server == server) {
window_change_server(rec, rec->servertag != NULL ?
NULL : new_server);
}
@ -609,6 +629,7 @@ void windows_init(void)
settings_add_str("lookandfeel", "window_default_level", "NONE");
read_settings();
signal_add("server looking", (SIGNAL_FUNC) sig_server_connected);
signal_add("server connected", (SIGNAL_FUNC) sig_server_connected);
signal_add("server disconnected", (SIGNAL_FUNC) sig_server_disconnected);
signal_add("server connect failed", (SIGNAL_FUNC) sig_server_disconnected);
@ -620,6 +641,7 @@ void windows_deinit(void)
if (daytag != -1) g_source_remove(daytag);
if (daycheck == 1) signal_remove("print text", (SIGNAL_FUNC) sig_print_text);
signal_remove("server looking", (SIGNAL_FUNC) sig_server_connected);
signal_remove("server connected", (SIGNAL_FUNC) sig_server_connected);
signal_remove("server disconnected", (SIGNAL_FUNC) sig_server_disconnected);
signal_remove("server connect failed", (SIGNAL_FUNC) sig_server_disconnected);

View File

@ -26,6 +26,7 @@ struct _WINDOW_REC {
GSList *items;
WI_ITEM_REC *active;
SERVER_REC *active_server;
SERVER_REC *connect_server;
char *servertag; /* active_server must be either NULL or have this tag (unless there's items in this window) */
int level; /* message level */

View File

@ -393,6 +393,8 @@ static void cmd_window_server(const char *data)
if (*tag == '\0')
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
server = server_find_tag(tag);
if (server == NULL)
server = server_find_lookup_tag(tag);
if (g_hash_table_lookup(optlist, "unsticky") != NULL &&
active_win->servertag != NULL) {

View File

@ -119,9 +119,22 @@ static void cmd_server_list(const char *data)
g_string_free(str, TRUE);
}
static void server_command(const char *data, SERVER_REC *server,
WI_ITEM_REC *item)
{
if (server == NULL) {
/* this command accepts non-connected server too */
server = active_win->connect_server;
}
signal_continue(3, data, server, item);
}
void fe_irc_server_init(void)
{
signal_add("server add fill", (SIGNAL_FUNC) sig_server_add_fill);
command_bind_first("server", NULL, (SIGNAL_FUNC) server_command);
command_bind_first("disconnect", NULL, (SIGNAL_FUNC) server_command);
command_bind("server list", NULL, (SIGNAL_FUNC) cmd_server_list);
command_set_options("server add", "-ircnet -cmdspeed -cmdmax -querychans");
@ -130,5 +143,7 @@ void fe_irc_server_init(void)
void fe_irc_server_deinit(void)
{
signal_remove("server add fill", (SIGNAL_FUNC) sig_server_add_fill);
command_unbind("server", (SIGNAL_FUNC) server_command);
command_unbind("disconnect", (SIGNAL_FUNC) server_command);
command_unbind("server list", (SIGNAL_FUNC) cmd_server_list);
}

View File

@ -483,43 +483,98 @@ static void key_active_window(void)
signal_emit("command window goto", 3, "active", active_win->active_server, active_win->active);
}
static SERVER_REC *get_prev_server(SERVER_REC *current)
{
int pos;
if (current == NULL) {
return servers != NULL ? g_slist_last(servers)->data :
lookup_servers != NULL ?
g_slist_last(lookup_servers)->data : NULL;
}
/* connect2 -> connect1 -> server2 -> server1 -> connect2 -> .. */
pos = g_slist_index(servers, current);
if (pos != -1) {
if (pos > 0)
return g_slist_nth(servers, pos-1)->data;
if (lookup_servers != NULL)
return g_slist_last(lookup_servers)->data;
return g_slist_last(servers)->data;
}
pos = g_slist_index(lookup_servers, current);
g_assert(pos >= 0);
if (pos > 0)
return g_slist_nth(lookup_servers, pos-1)->data;
if (servers != NULL)
return g_slist_last(servers)->data;
return g_slist_last(lookup_servers)->data;
}
static SERVER_REC *get_next_server(SERVER_REC *current)
{
GSList *pos;
if (current == NULL) {
return servers != NULL ? servers->data :
lookup_servers != NULL ? lookup_servers->data : NULL;
}
/* server1 -> server2 -> connect1 -> connect2 -> server1 -> .. */
pos = g_slist_find(servers, current);
if (pos != NULL) {
if (pos->next != NULL)
return pos->next->data;
if (lookup_servers != NULL)
return lookup_servers->data;
return servers->data;
}
pos = g_slist_find(lookup_servers, current);
g_assert(pos != NULL);
if (pos->next != NULL)
return pos->next->data;
if (servers != NULL)
return servers->data;
return lookup_servers->data;
}
static void key_previous_window_item(void)
{
SERVER_REC *server;
GSList *pos;
if (active_win->items != NULL)
signal_emit("command window item prev", 3, "", active_win->active_server, active_win->active);
else if (servers != NULL) {
if (active_win->items != NULL) {
signal_emit("command window item prev", 3, "",
active_win->active_server, active_win->active);
} else if (servers != NULL || lookup_servers != NULL) {
/* change server */
if (active_win->active_server == NULL)
server = servers->data;
else {
pos = g_slist_find(servers, active_win->active_server);
server = pos->next != NULL ? pos->next->data : servers->data;
}
signal_emit("command window server", 3, server->tag, active_win->active_server, active_win->active);
server = active_win->active_server;
if (server == NULL)
server = active_win->connect_server;
server = get_prev_server(server);
signal_emit("command window server", 3, server->tag,
active_win->active_server, active_win->active);
}
}
static void key_next_window_item(void)
{
SERVER_REC *server;
int index;
if (active_win->items != NULL) {
signal_emit("command window item next", 3, "",
active_win->active_server, active_win->active);
}
else if (servers != NULL) {
} else if (servers != NULL || lookup_servers != NULL) {
/* change server */
if (active_win->active_server == NULL)
server = servers->data;
else {
index = g_slist_index(servers, active_win->active_server);
server = index > 0 ? g_slist_nth(servers, index-1)->data :
g_slist_last(servers)->data;
}
server = active_win->active_server;
if (server == NULL)
server = active_win->connect_server;
server = get_next_server(server);
signal_emit("command window server", 3, server->tag,
active_win->active_server, active_win->active);
}