mirror of
https://github.com/irssi/irssi.git
synced 2026-08-10 20:33:46 +02:00
/SAVEWINDOWS - saves the current layout of windows. It's automatically
reloaded at startup. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@572 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
869279f285
commit
9b86b024b0
7 changed files with 141 additions and 1 deletions
114
src/fe-common/core/window-save.c
Normal file
114
src/fe-common/core/window-save.c
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
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"
|
||||
#include "server.h"
|
||||
#include "lib-config/iconfig.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "levels.h"
|
||||
|
||||
#include "themes.h"
|
||||
#include "windows.h"
|
||||
#include "window-items.h"
|
||||
|
||||
static void window_add_items(WINDOW_REC *window, CONFIG_NODE *node)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
for (tmp = node->value; tmp != NULL; tmp = tmp->next) {
|
||||
CONFIG_NODE *node = tmp->data;
|
||||
|
||||
window->waiting_channels =
|
||||
g_slist_append(window->waiting_channels,
|
||||
g_strdup(node->value));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
window_add_items(window, config_node_section(node, "items", -1));
|
||||
}
|
||||
}
|
||||
|
||||
static void window_save(WINDOW_REC *window, CONFIG_NODE *node)
|
||||
{
|
||||
GSList *tmp;
|
||||
char refnum[MAX_INT_STRLEN], *str;
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
|
||||
if (server == NULL)
|
||||
iconfig_node_set_str(node, NULL, rec->name);
|
||||
else {
|
||||
str = g_strdup_printf("%s %s", server->tag, rec->name);
|
||||
iconfig_node_set_str(node, NULL, str);
|
||||
g_free(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue