From 9b86b024b016ff6c0432de23c51b225c9e27a339 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 1 Aug 2000 01:02:46 +0000 Subject: [PATCH] /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 --- src/fe-common/core/Makefile.am | 2 + src/fe-common/core/fe-common-core.c | 5 ++ src/fe-common/core/window-commands.c | 12 +++ src/fe-common/core/window-save.c | 114 +++++++++++++++++++++++++++ src/fe-common/core/window-save.h | 7 ++ src/fe-common/core/windows.c | 1 + src/fe-common/core/windows.h | 1 - 7 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 src/fe-common/core/window-save.c create mode 100644 src/fe-common/core/window-save.h diff --git a/src/fe-common/core/Makefile.am b/src/fe-common/core/Makefile.am index 5a3bba07..ec9d99e9 100644 --- a/src/fe-common/core/Makefile.am +++ b/src/fe-common/core/Makefile.am @@ -25,6 +25,7 @@ libfe_common_core_la_SOURCES = \ window-activity.c \ window-commands.c \ window-items.c \ + window-save.c \ windows.c noinst_HEADERS = \ @@ -39,4 +40,5 @@ noinst_HEADERS = \ themes.h \ translation.h \ window-items.h \ + window-save.h \ windows.h diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c index d90bb137..cbfb4260 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -32,6 +32,7 @@ #include "translation.h" #include "windows.h" #include "window-items.h" +#include "window-save.h" #include @@ -132,6 +133,10 @@ void fe_common_core_finish_init(void) signal(SIGPIPE, SIG_IGN); + windows_restore(); + if (windows != NULL) + return; + if (settings_get_bool("use_status_window")) { window = window_create(NULL, TRUE); window_set_name(window, "(status)"); diff --git a/src/fe-common/core/window-commands.c b/src/fe-common/core/window-commands.c index f9890ea7..14d1d94a 100644 --- a/src/fe-common/core/window-commands.c +++ b/src/fe-common/core/window-commands.c @@ -30,6 +30,7 @@ #include "themes.h" #include "windows.h" #include "window-items.h" +#include "window-save.h" static void cmd_window(const char *data, void *server, WI_ITEM_REC *item) { @@ -359,6 +360,9 @@ static void cmd_window_list(void) /* SYNTAX: WINDOW THEME */ static void cmd_window_theme(const char *data) { + g_free_not_null(active_win->theme_name); + active_win->theme_name = g_strdup(data); + active_win->theme = theme_load(data); if (active_win->theme != NULL) { printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, @@ -369,6 +373,12 @@ static void cmd_window_theme(const char *data) } } +/* SYNTAX: SAVEWINDOWS */ +static void cmd_savewindows(void) +{ + windows_save(); +} + void window_commands_init(void) { command_bind("window", NULL, (SIGNAL_FUNC) cmd_window); @@ -392,6 +402,7 @@ void window_commands_init(void) command_bind("window move right", NULL, (SIGNAL_FUNC) cmd_window_move_right); command_bind("window list", NULL, (SIGNAL_FUNC) cmd_window_list); command_bind("window theme", NULL, (SIGNAL_FUNC) cmd_window_theme); + command_bind("savewindows", NULL, (SIGNAL_FUNC) cmd_savewindows); } void window_commands_deinit(void) @@ -417,4 +428,5 @@ void window_commands_deinit(void) command_unbind("window move right", (SIGNAL_FUNC) cmd_window_move_right); command_unbind("window list", (SIGNAL_FUNC) cmd_window_list); command_unbind("window theme", (SIGNAL_FUNC) cmd_window_theme); + command_unbind("savewindows", (SIGNAL_FUNC) cmd_savewindows); } diff --git a/src/fe-common/core/window-save.c b/src/fe-common/core/window-save.c new file mode 100644 index 00000000..31b71cb7 --- /dev/null +++ b/src/fe-common/core/window-save.c @@ -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); +} + diff --git a/src/fe-common/core/window-save.h b/src/fe-common/core/window-save.h new file mode 100644 index 00000000..ae30b232 --- /dev/null +++ b/src/fe-common/core/window-save.h @@ -0,0 +1,7 @@ +#ifndef __WINDOW_SAVE_H +#define __WINDOW_SAVE_H + +void windows_restore(void); +void windows_save(void); + +#endif diff --git a/src/fe-common/core/windows.c b/src/fe-common/core/windows.c index fac70cac..fc93f1de 100644 --- a/src/fe-common/core/windows.c +++ b/src/fe-common/core/windows.c @@ -118,6 +118,7 @@ void window_destroy(WINDOW_REC *window) g_slist_free(window->waiting_channels); refnum = window->refnum; + g_free_not_null(window->theme_name); g_free_not_null(window->name); g_free(window); diff --git a/src/fe-common/core/windows.h b/src/fe-common/core/windows.h index e9b7dbe4..9c40235d 100644 --- a/src/fe-common/core/windows.h +++ b/src/fe-common/core/windows.h @@ -60,7 +60,6 @@ extern WINDOW_REC *active_win; WINDOW_REC *window_create(WI_ITEM_REC *item, int automatic); void window_destroy(WINDOW_REC *window); -void window_set_active_num(int number); void window_set_active(WINDOW_REC *window); void window_change_server(WINDOW_REC *window, void *server);