2000-07-31 21:02:46 -04:00
|
|
|
/*
|
|
|
|
window-save.c : irssi
|
|
|
|
|
|
|
|
Copyright (C) 2000 Timo Sirainen
|
|
|
|
|
|
|
|
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
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
#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"
|
|
|
|
|
2000-09-02 14:53:58 -04:00
|
|
|
static void sig_window_restore_item(WINDOW_REC *window, const char *type,
|
|
|
|
CONFIG_NODE *node)
|
2000-08-12 18:58:16 -04:00
|
|
|
{
|
2000-09-02 14:53:58 -04:00
|
|
|
char *name, *tag, *chat_type, *str;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
window->waiting_channels =
|
|
|
|
g_slist_append(window->waiting_channels, str);
|
|
|
|
} else if (g_strcasecmp(type, "QUERY") == 0) {
|
|
|
|
/* create query immediately */
|
|
|
|
QUERY_REC *query;
|
|
|
|
SERVER_REC *server;
|
|
|
|
|
|
|
|
if (chat_type == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
server = tag == NULL ? NULL : server_find_tag(tag);
|
|
|
|
query = query_create(chat_protocol_lookup(chat_type),
|
|
|
|
server, name, TRUE);
|
|
|
|
if (server == NULL && tag != NULL)
|
|
|
|
query->server_tag = g_strdup(tag);
|
|
|
|
}
|
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;
|
|
|
|
|
2000-07-31 21:02:46 -04:00
|
|
|
for (tmp = node->value; tmp != NULL; tmp = tmp->next) {
|
|
|
|
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) {
|
|
|
|
signal_emit("window 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void windows_restore(void)
|
|
|
|
{
|
|
|
|
WINDOW_REC *window;
|
|
|
|
CONFIG_NODE *node;
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
node = iconfig_node_traverse("windows", FALSE);
|
|
|
|
if (node == NULL) return;
|
|
|
|
|
|
|
|
for (tmp = node->value; tmp != NULL; tmp = tmp->next) {
|
|
|
|
CONFIG_NODE *node = tmp->data;
|
|
|
|
|
|
|
|
window = window_create(NULL, TRUE);
|
|
|
|
window_set_refnum(window, atoi(node->key));
|
|
|
|
window_set_name(window, config_node_get_str(node, "name", NULL));
|
|
|
|
window_set_level(window, level2bits(config_node_get_str(node, "level", "")));
|
|
|
|
|
|
|
|
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));
|
|
|
|
signal_emit("window restore", 2, window, node);
|
2000-07-31 21:02:46 -04:00
|
|
|
}
|
2000-08-12 18:58:16 -04:00
|
|
|
|
|
|
|
signal_emit("windows restored", 0);
|
2000-07-31 21:02:46 -04:00
|
|
|
}
|
|
|
|
|
2000-08-12 18:58:16 -04:00
|
|
|
static void window_save_items(WINDOW_REC *window, CONFIG_NODE *node)
|
2000-07-31 21:02:46 -04:00
|
|
|
{
|
2000-09-02 14:53:58 -04:00
|
|
|
CONFIG_NODE *subnode;
|
2000-07-31 21:02:46 -04:00
|
|
|
GSList *tmp;
|
2000-09-02 14:53:58 -04:00
|
|
|
const char *type;
|
2000-08-12 18:58:16 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2000-09-02 14:53:58 -04:00
|
|
|
type = module_find_id_str("WINDOW ITEM TYPE", rec->type);
|
|
|
|
if (type == NULL) continue;
|
|
|
|
|
|
|
|
subnode = config_node_section(node, NULL, NODE_TYPE_BLOCK);
|
|
|
|
|
|
|
|
iconfig_node_set_str(subnode, "type", type);
|
2000-10-01 16:48:10 -04:00
|
|
|
type = chat_protocol_find_id(rec->chat_type)->name;
|
2000-09-30 18:49:48 -04:00
|
|
|
iconfig_node_set_str(subnode, "chat_type", type);
|
2000-09-02 14:53:58 -04:00
|
|
|
iconfig_node_set_str(subnode, "name", rec->name);
|
|
|
|
|
|
|
|
if (server != NULL)
|
|
|
|
iconfig_node_set_str(subnode, "tag", server->tag);
|
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);
|
|
|
|
|
|
|
|
if (window->name != NULL)
|
|
|
|
iconfig_node_set_str(node, "name", window->name);
|
|
|
|
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
|
|
|
|
2000-08-12 18:58:16 -04:00
|
|
|
signal_emit("window save", 2, window, node);
|
2000-07-31 21:02:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void windows_save(void)
|
|
|
|
{
|
|
|
|
CONFIG_NODE *node;
|
|
|
|
|
|
|
|
iconfig_set_str(NULL, "windows", NULL);
|
|
|
|
node = iconfig_node_traverse("windows", TRUE);
|
|
|
|
|
|
|
|
g_slist_foreach(windows, (GFunc) window_save, node);
|
2000-08-12 18:58:16 -04:00
|
|
|
signal_emit("windows saved", 0);
|
2000-07-31 21:02:46 -04:00
|
|
|
}
|
|
|
|
|
2000-08-12 18:58:16 -04:00
|
|
|
void window_save_init(void)
|
|
|
|
{
|
|
|
|
signal_add("window restore item", (SIGNAL_FUNC) sig_window_restore_item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void window_save_deinit(void)
|
|
|
|
{
|
|
|
|
signal_remove("window restore item", (SIGNAL_FUNC) sig_window_restore_item);
|
|
|
|
}
|