summaryrefslogtreecommitdiff
path: root/src/fe-common/core
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2001-02-10 09:12:53 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2001-02-10 09:12:53 +0000
commitddf6810b0ea03e144ecdbafed3fb625d7039d832 (patch)
tree3b806ef439ed454b404916443f8517de0b5b3cff /src/fe-common/core
parent7c21fb84ee6b5f29e71d9704b9c7c3f2d411b17d (diff)
downloadirssi-ddf6810b0ea03e144ecdbafed3fb625d7039d832.zip
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
Diffstat (limited to 'src/fe-common/core')
-rw-r--r--src/fe-common/core/fe-channels.c3
-rw-r--r--src/fe-common/core/fe-windows.c66
-rw-r--r--src/fe-common/core/fe-windows.h16
-rw-r--r--src/fe-common/core/window-items.c50
-rw-r--r--src/fe-common/core/window-save.c15
5 files changed, 98 insertions, 52 deletions
diff --git a/src/fe-common/core/fe-channels.c b/src/fe-common/core/fe-channels.c
index 2a9ba71f..e15742d6 100644
--- a/src/fe-common/core/fe-channels.c
+++ b/src/fe-common/core/fe-channels.c
@@ -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);
}
}
diff --git a/src/fe-common/core/fe-windows.c b/src/fe-common/core/fe-windows.c
index e929c204..175c17ec 100644
--- a/src/fe-common/core/fe-windows.c
+++ b/src/fe-common/core/fe-windows.c
@@ -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;
diff --git a/src/fe-common/core/fe-windows.h b/src/fe-common/core/fe-windows.h
index 74d8103f..12c47854 100644
--- a/src/fe-common/core/fe-windows.h
+++ b/src/fe-common/core/fe-windows.h
@@ -14,6 +14,12 @@ enum {
};
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);
diff --git a/src/fe-common/core/window-items.c b/src/fe-common/core/window-items.c
index 77ed89dd..5c75295e 100644
--- a/src/fe-common/core/window-items.c
+++ b/src/fe-common/core/window-items.c
@@ -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)
diff --git a/src/fe-common/core/window-save.c b/src/fe-common/core/window-save.c
index d5ffb1cf..62423719 100644
--- a/src/fe-common/core/window-save.c
+++ b/src/fe-common/core/window-save.c
@@ -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 (g_strcasecmp(type, "CHANNEL") == 0) {
- /* add channel to "waiting channels" list */
- str = tag == NULL ? g_strdup(name) :
- g_strdup_printf("%s %s", tag, name);
+ if (name == NULL || tag == NULL)
+ return;
- window->waiting_channels =
- g_slist_append(window->waiting_channels, str);
+ if (g_strcasecmp(type, "CHANNEL") == 0) {
+ /* 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),