1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

Changed window->waiting_channels ("servertag name" format) to

bound_items containing WINDOW_BIND_REC structures. If you now use
/SAVEWINDOWS, the item will _always_ be restored to saved window even
if there was already some other item.


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1204 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2001-02-10 09:12:53 +00:00 committed by cras
parent 7c21fb84ee
commit ddf6810b0e
5 changed files with 98 additions and 52 deletions

View File

@ -89,8 +89,7 @@ static void sig_disconnected(SERVER_REC *server)
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));
window_bind_add(window, server->tag, channel->name);
}
}

View File

@ -121,8 +121,8 @@ void window_destroy(WINDOW_REC *window)
signal_emit("window destroyed", 1, window);
g_slist_foreach(window->waiting_channels, (GFunc) g_free, NULL);
g_slist_free(window->waiting_channels);
while (window->bound_items != NULL)
window_bind_destroy(window, window->bound_items->data);
g_free_not_null(window->servertag);
g_free_not_null(window->theme_name);
@ -386,6 +386,68 @@ GSList *windows_get_sorted(void)
return sorted;
}
WINDOW_BIND_REC *window_bind_add(WINDOW_REC *window, const char *servertag,
const char *name)
{
WINDOW_BIND_REC *rec;
g_return_val_if_fail(window != NULL, NULL);
g_return_val_if_fail(servertag != NULL, NULL);
g_return_val_if_fail(name != NULL, NULL);
rec = g_new0(WINDOW_BIND_REC, 1);
rec->name = g_strdup(name);
rec->servertag = g_strdup(servertag);
window->bound_items = g_slist_append(window->bound_items, rec);
return rec;
}
void window_bind_destroy(WINDOW_REC *window, WINDOW_BIND_REC *rec)
{
g_return_if_fail(window != NULL);
g_return_if_fail(rec != NULL);
window->bound_items = g_slist_remove(window->bound_items, rec);
g_free(rec->servertag);
g_free(rec->name);
g_free(rec);
}
WINDOW_BIND_REC *window_bind_find(WINDOW_REC *window, const char *servertag,
const char *name)
{
GSList *tmp;
g_return_val_if_fail(window != NULL, NULL);
g_return_val_if_fail(servertag != NULL, NULL);
g_return_val_if_fail(name != NULL, NULL);
for (tmp = window->bound_items; tmp != NULL; tmp = tmp->next) {
WINDOW_BIND_REC *rec = tmp->data;
if (g_strcasecmp(rec->name, name) == 0 &&
g_strcasecmp(rec->servertag, servertag) == 0)
return rec;
}
return NULL;
}
void window_bind_remove_unsticky(WINDOW_REC *window)
{
GSList *tmp, *next;
for (tmp = window->bound_items; tmp != NULL; tmp = tmp->next) {
WINDOW_BIND_REC *rec = tmp->data;
next = tmp->next;
if (!rec->sticky)
window_bind_destroy(window, rec);
}
}
static void sig_server_looking(SERVER_REC *server)
{
GSList *tmp;

View File

@ -13,6 +13,12 @@ enum {
DATA_LEVEL_HILIGHT
};
typedef struct {
char *servertag;
char *name;
unsigned int sticky:1;
} WINDOW_BIND_REC;
typedef struct {
int refnum;
char *name;
@ -25,7 +31,7 @@ typedef struct {
char *servertag; /* active_server must be either NULL or have this tag (unless there's items in this window) */
int level; /* message level */
GSList *waiting_channels; /* list of "<server tag> <channel>" */
GSList *bound_items; /* list of WINDOW_BIND_RECs */
int lines;
unsigned int sticky_refnum:1;
@ -75,6 +81,14 @@ int windows_refnum_last(void);
GSList *windows_get_sorted(void);
WINDOW_BIND_REC *window_bind_add(WINDOW_REC *window, const char *servertag,
const char *name);
void window_bind_destroy(WINDOW_REC *window, WINDOW_BIND_REC *rec);
WINDOW_BIND_REC *window_bind_find(WINDOW_REC *window, const char *servertag,
const char *name);
void window_bind_remove_unsticky(WINDOW_REC *window);
void windows_init(void);
void windows_deinit(void);

View File

@ -224,36 +224,14 @@ WI_ITEM_REC *window_item_find(void *server, const char *name)
return NULL;
}
static int waiting_channels_get(WINDOW_REC *window, const char *tag)
{
GSList *tmp;
g_return_val_if_fail(window != NULL, FALSE);
g_return_val_if_fail(tag != NULL, FALSE);
for (tmp = window->waiting_channels; tmp != NULL; tmp = tmp->next) {
if (g_strcasecmp(tmp->data, tag) == 0) {
g_free(tmp->data);
window->waiting_channels = g_slist_remove(window->waiting_channels, tmp->data);
return TRUE;
}
}
return FALSE;
}
void window_item_create(WI_ITEM_REC *item, int automatic)
{
WINDOW_REC *window;
GSList *tmp, *sorted;
char *str;
int clear_waiting, reuse_unused_windows;
g_return_if_fail(item != NULL);
str = item->server == NULL ? NULL :
g_strdup_printf("%s %s", ((SERVER_REC *) item->server)->tag, item->name);
reuse_unused_windows =
!settings_get_bool("autoclose_windows") ||
settings_get_bool("reuse_unused_windows");
@ -267,23 +245,21 @@ void window_item_create(WI_ITEM_REC *item, int automatic)
if (reuse_unused_windows &&
rec->items == NULL && rec->level == 0 &&
(window == NULL || rec == active_win ||
window->waiting_channels != NULL)) {
/* no items in this window, we should probably use it.. */
window->bound_items != NULL)) {
/* no items in this window,
we should probably use it.. */
window = rec;
}
if (rec->waiting_channels != NULL && str != NULL) {
/* right name/server tag combination in
some waiting list? */
if (waiting_channels_get(rec, str)) {
window = rec;
clear_waiting = FALSE;
break;
}
/* is item bound to this window? */
if (item->server != NULL &&
window_bind_find(rec, item->server->tag, item->name)) {
window = rec;
clear_waiting = FALSE;
break;
}
}
g_slist_free(sorted);
g_free_not_null(str);
if (window == NULL && !settings_get_bool("autocreate_windows")) {
/* never create new windows automatically */
@ -298,12 +274,8 @@ void window_item_create(WI_ITEM_REC *item, int automatic)
window_item_add(window, item, automatic);
}
if (clear_waiting) {
/* clear window's waiting_channels list */
g_slist_foreach(window->waiting_channels, (GFunc) g_free, NULL),
g_slist_free(window->waiting_channels);
window->waiting_channels = NULL;
}
if (clear_waiting)
window_bind_remove_unsticky(window);
}
static void signal_window_item_changed(WINDOW_REC *window, WI_ITEM_REC *item)

View File

@ -38,20 +38,19 @@
static void sig_window_restore_item(WINDOW_REC *window, const char *type,
CONFIG_NODE *node)
{
char *name, *tag, *chat_type, *str;
char *name, *tag, *chat_type;
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 (name == NULL || tag == 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);
/* bind channel to window */
WINDOW_BIND_REC *rec = window_bind_add(window, tag, name);
rec->sticky = TRUE;
} else if (g_strcasecmp(type, "QUERY") == 0 && chat_type != NULL) {
/* create query immediately */
query_create(chat_protocol_lookup(chat_type),