2000-07-31 21:02:46 -04:00
|
|
|
/*
|
2001-02-21 14:19:24 -05:00
|
|
|
windows-layout.c : irssi
|
2000-07-31 21:02:46 -04:00
|
|
|
|
2001-02-21 14:19:24 -05:00
|
|
|
Copyright (C) 2000-2001 Timo Sirainen
|
2000-07-31 21:02:46 -04:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2007-05-08 14:16:58 -04:00
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-07-31 21:02:46 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
#include "signals.h"
|
|
|
|
#include "misc.h"
|
2000-09-02 14:53:58 -04:00
|
|
|
#include "levels.h"
|
2000-07-31 21:02:46 -04:00
|
|
|
#include "lib-config/iconfig.h"
|
|
|
|
#include "settings.h"
|
|
|
|
|
2000-09-02 14:53:58 -04:00
|
|
|
#include "chat-protocols.h"
|
|
|
|
#include "servers.h"
|
|
|
|
#include "queries.h"
|
2000-07-31 21:02:46 -04:00
|
|
|
|
2001-02-09 22:10:30 -05:00
|
|
|
#include "module-formats.h"
|
|
|
|
#include "printtext.h"
|
2000-07-31 21:02:46 -04:00
|
|
|
#include "themes.h"
|
2000-11-17 11:27:14 -05:00
|
|
|
#include "fe-windows.h"
|
2000-07-31 21:02:46 -04:00
|
|
|
#include "window-items.h"
|
|
|
|
|
2001-06-10 20:15:38 -04:00
|
|
|
static WINDOW_REC *restore_win;
|
|
|
|
|
|
|
|
static void signal_query_created_curwin(QUERY_REC *query)
|
|
|
|
{
|
|
|
|
g_return_if_fail(IS_QUERY(query));
|
|
|
|
|
2001-08-08 14:23:25 -04:00
|
|
|
window_item_add(restore_win, (WI_ITEM_REC *) query, TRUE);
|
2001-06-10 20:15:38 -04:00
|
|
|
}
|
|
|
|
|
2001-08-08 14:05:50 -04:00
|
|
|
static void sig_layout_restore_item(WINDOW_REC *window, const char *type,
|
2000-09-02 14:53:58 -04:00
|
|
|
CONFIG_NODE *node)
|
2000-08-12 18:58:16 -04:00
|
|
|
{
|
2001-02-10 04:12:53 -05:00
|
|
|
char *name, *tag, *chat_type;
|
2000-09-02 14:53:58 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2001-02-10 04:12:53 -05:00
|
|
|
if (name == NULL || tag == NULL)
|
|
|
|
return;
|
2000-09-02 14:53:58 -04:00
|
|
|
|
2001-02-10 04:12:53 -05:00
|
|
|
if (g_strcasecmp(type, "CHANNEL") == 0) {
|
|
|
|
/* bind channel to window */
|
|
|
|
WINDOW_BIND_REC *rec = window_bind_add(window, tag, name);
|
|
|
|
rec->sticky = TRUE;
|
2001-01-01 12:13:55 -05:00
|
|
|
} else if (g_strcasecmp(type, "QUERY") == 0 && chat_type != NULL) {
|
2003-12-10 18:04:00 -05:00
|
|
|
CHAT_PROTOCOL_REC *protocol;
|
2000-09-02 14:53:58 -04:00
|
|
|
/* create query immediately */
|
2001-06-10 20:15:38 -04:00
|
|
|
signal_add("query created",
|
|
|
|
(SIGNAL_FUNC) signal_query_created_curwin);
|
|
|
|
|
|
|
|
restore_win = window;
|
2003-12-10 18:04:00 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2001-06-10 20:15:38 -04:00
|
|
|
|
|
|
|
signal_remove("query created",
|
|
|
|
(SIGNAL_FUNC) signal_query_created_curwin);
|
2000-09-02 14:53:58 -04:00
|
|
|
}
|
2000-08-12 18:58:16 -04:00
|
|
|
}
|
|
|
|
|
2000-07-31 21:02:46 -04:00
|
|
|
static void window_add_items(WINDOW_REC *window, CONFIG_NODE *node)
|
|
|
|
{
|
|
|
|
GSList *tmp;
|
2000-09-02 14:53:58 -04:00
|
|
|
char *type;
|
2000-07-31 21:02:46 -04:00
|
|
|
|
2000-08-12 18:58:16 -04:00
|
|
|
if (node == NULL)
|
|
|
|
return;
|
|
|
|
|
2002-02-02 12:37:44 -05:00
|
|
|
tmp = config_node_first(node->value);
|
|
|
|
for (; tmp != NULL; tmp = config_node_next(tmp)) {
|
2000-07-31 21:02:46 -04:00
|
|
|
CONFIG_NODE *node = tmp->data;
|
|
|
|
|
2000-09-06 15:22:07 -04:00
|
|
|
type = config_node_get_str(node, "type", NULL);
|
2000-09-02 14:53:58 -04:00
|
|
|
if (type != NULL) {
|
2001-08-08 14:05:50 -04:00
|
|
|
signal_emit("layout restore item", 3,
|
2000-09-06 15:22:07 -04:00
|
|
|
window, type, node);
|
2000-09-02 14:53:58 -04:00
|
|
|
}
|
2000-07-31 21:02:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-21 14:19:24 -05:00
|
|
|
void windows_layout_restore(void)
|
2001-08-07 08:41:10 -04:00
|
|
|
{
|
2001-08-08 14:05:50 -04:00
|
|
|
signal_emit("layout restore", 0);
|
2001-08-07 08:41:10 -04:00
|
|
|
}
|
|
|
|
|
2001-08-08 14:05:50 -04:00
|
|
|
static void sig_layout_restore(void)
|
2000-07-31 21:02:46 -04:00
|
|
|
{
|
|
|
|
WINDOW_REC *window;
|
|
|
|
CONFIG_NODE *node;
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
node = iconfig_node_traverse("windows", FALSE);
|
|
|
|
if (node == NULL) return;
|
|
|
|
|
2002-02-02 12:37:44 -05:00
|
|
|
tmp = config_node_first(node->value);
|
|
|
|
for (; tmp != NULL; tmp = config_node_next(tmp)) {
|
2000-07-31 21:02:46 -04:00
|
|
|
CONFIG_NODE *node = tmp->data;
|
|
|
|
|
2001-08-07 08:41:10 -04:00
|
|
|
window = window_find_refnum(atoi(node->key));
|
|
|
|
if (window == NULL)
|
|
|
|
window = window_create(NULL, TRUE);
|
|
|
|
|
2000-07-31 21:02:46 -04:00
|
|
|
window_set_refnum(window, atoi(node->key));
|
2001-02-09 22:12:22 -05:00
|
|
|
window->sticky_refnum = config_node_get_bool(node, "sticky_refnum", FALSE);
|
2002-02-10 10:00:15 -05:00
|
|
|
window->immortal = config_node_get_bool(node, "immortal", FALSE);
|
2001-02-09 22:12:22 -05:00
|
|
|
window_set_name(window, config_node_get_str(node, "name", NULL));
|
2001-12-20 08:29:20 -05:00
|
|
|
window_set_history(window, config_node_get_str(node, "history_name", NULL));
|
2000-07-31 21:02:46 -04:00
|
|
|
window_set_level(window, level2bits(config_node_get_str(node, "level", "")));
|
|
|
|
|
2001-02-09 22:10:30 -05:00
|
|
|
window->servertag = g_strdup(config_node_get_str(node, "servertag", NULL));
|
2000-07-31 21:02:46 -04:00
|
|
|
window->theme_name = g_strdup(config_node_get_str(node, "theme", NULL));
|
|
|
|
if (window->theme_name != NULL)
|
|
|
|
window->theme = theme_load(window->theme_name);
|
|
|
|
|
2000-08-12 18:58:16 -04:00
|
|
|
window_add_items(window, config_node_section(node, "items", -1));
|
2001-08-08 14:05:50 -04:00
|
|
|
signal_emit("layout restore window", 2, window, node);
|
2000-07-31 21:02:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-27 16:13:27 -04:00
|
|
|
static void sig_layout_save_item(WINDOW_REC *window, WI_ITEM_REC *item,
|
|
|
|
CONFIG_NODE *node)
|
2000-07-31 21:02:46 -04:00
|
|
|
{
|
2000-09-02 14:53:58 -04:00
|
|
|
CONFIG_NODE *subnode;
|
2002-10-14 07:52:13 -04:00
|
|
|
CHAT_PROTOCOL_REC *proto;
|
2000-09-02 14:53:58 -04:00
|
|
|
const char *type;
|
2000-08-12 18:58:16 -04:00
|
|
|
|
2002-04-27 16:13:27 -04:00
|
|
|
type = module_find_id_str("WINDOW ITEM TYPE", item->type);
|
|
|
|
if (type == NULL)
|
|
|
|
return;
|
2000-09-02 14:53:58 -04:00
|
|
|
|
2002-04-27 16:13:27 -04:00
|
|
|
subnode = config_node_section(node, NULL, NODE_TYPE_BLOCK);
|
2000-09-02 14:53:58 -04:00
|
|
|
|
2002-04-27 16:13:27 -04:00
|
|
|
iconfig_node_set_str(subnode, "type", type);
|
2002-10-14 07:52:13 -04:00
|
|
|
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);
|
2002-05-15 20:34:37 -04:00
|
|
|
iconfig_node_set_str(subnode, "name", item->visible_name);
|
2000-09-02 14:53:58 -04:00
|
|
|
|
2002-04-27 16:13:27 -04:00
|
|
|
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);
|
2000-08-12 18:58:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-27 16:13:27 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2000-08-12 18:58:16 -04:00
|
|
|
static void window_save(WINDOW_REC *window, CONFIG_NODE *node)
|
|
|
|
{
|
|
|
|
char refnum[MAX_INT_STRLEN];
|
2000-07-31 21:02:46 -04:00
|
|
|
|
|
|
|
ltoa(refnum, window->refnum);
|
|
|
|
node = config_node_section(node, refnum, NODE_TYPE_BLOCK);
|
|
|
|
|
2001-02-09 22:12:22 -05:00
|
|
|
if (window->sticky_refnum)
|
|
|
|
iconfig_node_set_bool(node, "sticky_refnum", TRUE);
|
|
|
|
|
2002-02-10 10:00:15 -05:00
|
|
|
if (window->immortal)
|
|
|
|
iconfig_node_set_bool(node, "immortal", TRUE);
|
|
|
|
|
2000-07-31 21:02:46 -04:00
|
|
|
if (window->name != NULL)
|
|
|
|
iconfig_node_set_str(node, "name", window->name);
|
2001-12-20 08:29:20 -05:00
|
|
|
|
|
|
|
if (window->history_name != NULL)
|
|
|
|
iconfig_node_set_str(node, "history_name", window->history_name);
|
|
|
|
|
2001-02-09 22:10:30 -05:00
|
|
|
if (window->servertag != NULL)
|
|
|
|
iconfig_node_set_str(node, "servertag", window->servertag);
|
2000-07-31 21:02:46 -04:00
|
|
|
if (window->level != 0) {
|
|
|
|
char *level = bits2level(window->level);
|
|
|
|
iconfig_node_set_str(node, "level", level);
|
|
|
|
g_free(level);
|
|
|
|
}
|
|
|
|
if (window->theme_name != NULL)
|
|
|
|
iconfig_node_set_str(node, "theme", window->theme_name);
|
|
|
|
|
2000-08-12 18:58:16 -04:00
|
|
|
if (window->items != NULL)
|
|
|
|
window_save_items(window, node);
|
2000-07-31 21:02:46 -04:00
|
|
|
|
2001-08-08 14:05:50 -04:00
|
|
|
signal_emit("layout save window", 2, window, node);
|
2000-07-31 21:02:46 -04:00
|
|
|
}
|
|
|
|
|
2001-02-21 14:19:24 -05:00
|
|
|
void windows_layout_save(void)
|
2000-07-31 21:02:46 -04:00
|
|
|
{
|
|
|
|
CONFIG_NODE *node;
|
|
|
|
|
|
|
|
iconfig_set_str(NULL, "windows", NULL);
|
|
|
|
node = iconfig_node_traverse("windows", TRUE);
|
|
|
|
|
|
|
|
g_slist_foreach(windows, (GFunc) window_save, node);
|
2001-08-08 14:05:50 -04:00
|
|
|
signal_emit("layout save", 0);
|
2001-02-09 22:10:30 -05:00
|
|
|
|
2001-02-21 14:19:24 -05:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
TXT_WINDOWS_LAYOUT_SAVED);
|
2000-07-31 21:02:46 -04:00
|
|
|
}
|
|
|
|
|
2001-02-21 14:19:24 -05:00
|
|
|
void windows_layout_reset(void)
|
|
|
|
{
|
|
|
|
iconfig_set_str(NULL, "windows", NULL);
|
2001-08-08 14:05:50 -04:00
|
|
|
signal_emit("layout reset", 0);
|
|
|
|
|
2001-02-21 14:19:24 -05:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
TXT_WINDOWS_LAYOUT_RESET);
|
|
|
|
}
|
|
|
|
|
|
|
|
void windows_layout_init(void)
|
2000-08-12 18:58:16 -04:00
|
|
|
{
|
2001-08-08 14:05:50 -04:00
|
|
|
signal_add("layout restore item", (SIGNAL_FUNC) sig_layout_restore_item);
|
|
|
|
signal_add("layout restore", (SIGNAL_FUNC) sig_layout_restore);
|
2002-04-27 16:13:27 -04:00
|
|
|
signal_add("layout save item", (SIGNAL_FUNC) sig_layout_save_item);
|
2000-08-12 18:58:16 -04:00
|
|
|
}
|
|
|
|
|
2001-02-21 14:19:24 -05:00
|
|
|
void windows_layout_deinit(void)
|
2000-08-12 18:58:16 -04:00
|
|
|
{
|
2001-08-08 14:05:50 -04:00
|
|
|
signal_remove("layout restore item", (SIGNAL_FUNC) sig_layout_restore_item);
|
|
|
|
signal_remove("layout restore", (SIGNAL_FUNC) sig_layout_restore);
|
2002-04-27 16:13:27 -04:00
|
|
|
signal_remove("layout save item", (SIGNAL_FUNC) sig_layout_save_item);
|
2000-08-12 18:58:16 -04:00
|
|
|
}
|