#include "fe-windows.h"
#include "window-items.h"
-static void sig_window_restore_item(WINDOW_REC *window, const char *type,
+static WINDOW_REC *restore_win;
+
+static void signal_query_created_curwin(QUERY_REC *query)
+{
+ g_return_if_fail(IS_QUERY(query));
+
+ window_item_add(restore_win, (WI_ITEM_REC *) query, TRUE);
+}
+
+static void sig_layout_restore_item(WINDOW_REC *window, const char *type,
CONFIG_NODE *node)
{
char *name, *tag, *chat_type;
WINDOW_BIND_REC *rec = window_bind_add(window, tag, name);
rec->sticky = TRUE;
} else if (g_strcasecmp(type, "QUERY") == 0 && chat_type != NULL) {
+ CHAT_PROTOCOL_REC *protocol;
/* create query immediately */
- chat_protocol_find(chat_type)->query_create(tag, name, TRUE);
+ signal_add("query created",
+ (SIGNAL_FUNC) signal_query_created_curwin);
+
+ restore_win = window;
+
+ protocol = chat_protocol_find(chat_type);
+ if (protocol->query_create != NULL)
+ protocol->query_create(tag, name, TRUE);
+ else {
+ QUERY_REC *query;
+
+ query = g_new0(QUERY_REC, 1);
+ query->chat_type = chat_protocol_lookup(chat_type);
+ query->name = g_strdup(name);
+ query->server_tag = g_strdup(tag);
+ query_init(query, TRUE);
+ }
+
+ signal_remove("query created",
+ (SIGNAL_FUNC) signal_query_created_curwin);
}
}
if (node == NULL)
return;
- for (tmp = node->value; tmp != NULL; tmp = tmp->next) {
+ tmp = config_node_first(node->value);
+ for (; tmp != NULL; tmp = config_node_next(tmp)) {
CONFIG_NODE *node = tmp->data;
type = config_node_get_str(node, "type", NULL);
if (type != NULL) {
- signal_emit("window restore item", 3,
+ signal_emit("layout restore item", 3,
window, type, node);
}
}
}
void windows_layout_restore(void)
+{
+ signal_emit("layout restore", 0);
+}
+
+static void sig_layout_restore(void)
{
WINDOW_REC *window;
CONFIG_NODE *node;
node = iconfig_node_traverse("windows", FALSE);
if (node == NULL) return;
- for (tmp = node->value; tmp != NULL; tmp = tmp->next) {
+ tmp = config_node_first(node->value);
+ for (; tmp != NULL; tmp = config_node_next(tmp)) {
CONFIG_NODE *node = tmp->data;
- window = window_create(NULL, TRUE);
+ window = window_find_refnum(atoi(node->key));
+ if (window == NULL)
+ window = window_create(NULL, TRUE);
+
window_set_refnum(window, atoi(node->key));
window->sticky_refnum = config_node_get_bool(node, "sticky_refnum", FALSE);
+ window->immortal = config_node_get_bool(node, "immortal", FALSE);
window_set_name(window, config_node_get_str(node, "name", NULL));
+ window_set_history(window, config_node_get_str(node, "history_name", NULL));
window_set_level(window, level2bits(config_node_get_str(node, "level", "")));
window->servertag = g_strdup(config_node_get_str(node, "servertag", NULL));
window->theme = theme_load(window->theme_name);
window_add_items(window, config_node_section(node, "items", -1));
- signal_emit("window restore", 2, window, node);
+ signal_emit("layout restore window", 2, window, node);
}
-
- signal_emit("windows restored", 0);
}
-static void window_save_items(WINDOW_REC *window, CONFIG_NODE *node)
+static void sig_layout_save_item(WINDOW_REC *window, WI_ITEM_REC *item,
+ CONFIG_NODE *node)
{
CONFIG_NODE *subnode;
- GSList *tmp;
+ CHAT_PROTOCOL_REC *proto;
const char *type;
- 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;
-
- type = module_find_id_str("WINDOW ITEM TYPE", rec->type);
- if (type == NULL) continue;
+ type = module_find_id_str("WINDOW ITEM TYPE", item->type);
+ if (type == NULL)
+ return;
- subnode = config_node_section(node, NULL, NODE_TYPE_BLOCK);
+ subnode = config_node_section(node, NULL, NODE_TYPE_BLOCK);
- iconfig_node_set_str(subnode, "type", type);
- type = chat_protocol_find_id(rec->chat_type)->name;
- iconfig_node_set_str(subnode, "chat_type", type);
- iconfig_node_set_str(subnode, "name", rec->name);
+ iconfig_node_set_str(subnode, "type", type);
+ proto = item->chat_type == 0 ? NULL :
+ chat_protocol_find_id(item->chat_type);
+ if (proto != NULL)
+ iconfig_node_set_str(subnode, "chat_type", proto->name);
+ iconfig_node_set_str(subnode, "name", item->visible_name);
- if (server != NULL)
- iconfig_node_set_str(subnode, "tag", server->tag);
- else if (IS_QUERY(rec)) {
- iconfig_node_set_str(subnode, "tag",
- QUERY(rec)->server_tag);
- }
+ if (item->server != NULL)
+ iconfig_node_set_str(subnode, "tag", item->server->tag);
+ else if (IS_QUERY(item)) {
+ iconfig_node_set_str(subnode, "tag", QUERY(item)->server_tag);
}
}
+static void window_save_items(WINDOW_REC *window, CONFIG_NODE *node)
+{
+ GSList *tmp;
+
+ node = config_node_section(node, "items", NODE_TYPE_LIST);
+ for (tmp = window->items; tmp != NULL; tmp = tmp->next)
+ signal_emit("layout save item", 3, window, tmp->data, node);
+}
+
static void window_save(WINDOW_REC *window, CONFIG_NODE *node)
{
char refnum[MAX_INT_STRLEN];
if (window->sticky_refnum)
iconfig_node_set_bool(node, "sticky_refnum", TRUE);
+ if (window->immortal)
+ iconfig_node_set_bool(node, "immortal", TRUE);
+
if (window->name != NULL)
iconfig_node_set_str(node, "name", window->name);
+
+ if (window->history_name != NULL)
+ iconfig_node_set_str(node, "history_name", window->history_name);
+
if (window->servertag != NULL)
iconfig_node_set_str(node, "servertag", window->servertag);
if (window->level != 0) {
if (window->items != NULL)
window_save_items(window, node);
- signal_emit("window save", 2, window, node);
+ signal_emit("layout save window", 2, window, node);
}
void windows_layout_save(void)
node = iconfig_node_traverse("windows", TRUE);
g_slist_foreach(windows, (GFunc) window_save, node);
- signal_emit("windows saved", 0);
+ signal_emit("layout save", 0);
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
TXT_WINDOWS_LAYOUT_SAVED);
void windows_layout_reset(void)
{
iconfig_set_str(NULL, "windows", NULL);
+ signal_emit("layout reset", 0);
+
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
TXT_WINDOWS_LAYOUT_RESET);
}
void windows_layout_init(void)
{
- signal_add("window restore item", (SIGNAL_FUNC) sig_window_restore_item);
+ signal_add("layout restore item", (SIGNAL_FUNC) sig_layout_restore_item);
+ signal_add("layout restore", (SIGNAL_FUNC) sig_layout_restore);
+ signal_add("layout save item", (SIGNAL_FUNC) sig_layout_save_item);
}
void windows_layout_deinit(void)
{
- signal_remove("window restore item", (SIGNAL_FUNC) sig_window_restore_item);
+ signal_remove("layout restore item", (SIGNAL_FUNC) sig_layout_restore_item);
+ signal_remove("layout restore", (SIGNAL_FUNC) sig_layout_restore);
+ signal_remove("layout save item", (SIGNAL_FUNC) sig_layout_save_item);
}