mirror of
https://github.com/irssi/irssi.git
synced 2025-01-03 14:56:47 -05: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
@ -25,6 +25,7 @@ libfe_common_core_la_SOURCES = \
|
|||||||
window-activity.c \
|
window-activity.c \
|
||||||
window-commands.c \
|
window-commands.c \
|
||||||
window-items.c \
|
window-items.c \
|
||||||
|
window-save.c \
|
||||||
windows.c
|
windows.c
|
||||||
|
|
||||||
noinst_HEADERS = \
|
noinst_HEADERS = \
|
||||||
@ -39,4 +40,5 @@ noinst_HEADERS = \
|
|||||||
themes.h \
|
themes.h \
|
||||||
translation.h \
|
translation.h \
|
||||||
window-items.h \
|
window-items.h \
|
||||||
|
window-save.h \
|
||||||
windows.h
|
windows.h
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "translation.h"
|
#include "translation.h"
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
#include "window-items.h"
|
#include "window-items.h"
|
||||||
|
#include "window-save.h"
|
||||||
|
|
||||||
#include <sys/signal.h>
|
#include <sys/signal.h>
|
||||||
|
|
||||||
@ -132,6 +133,10 @@ void fe_common_core_finish_init(void)
|
|||||||
|
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
|
||||||
|
windows_restore();
|
||||||
|
if (windows != NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
if (settings_get_bool("use_status_window")) {
|
if (settings_get_bool("use_status_window")) {
|
||||||
window = window_create(NULL, TRUE);
|
window = window_create(NULL, TRUE);
|
||||||
window_set_name(window, "(status)");
|
window_set_name(window, "(status)");
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "themes.h"
|
#include "themes.h"
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
#include "window-items.h"
|
#include "window-items.h"
|
||||||
|
#include "window-save.h"
|
||||||
|
|
||||||
static void cmd_window(const char *data, void *server, WI_ITEM_REC *item)
|
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 <name> */
|
/* SYNTAX: WINDOW THEME <name> */
|
||||||
static void cmd_window_theme(const char *data)
|
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);
|
active_win->theme = theme_load(data);
|
||||||
if (active_win->theme != NULL) {
|
if (active_win->theme != NULL) {
|
||||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
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)
|
void window_commands_init(void)
|
||||||
{
|
{
|
||||||
command_bind("window", NULL, (SIGNAL_FUNC) cmd_window);
|
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 move right", NULL, (SIGNAL_FUNC) cmd_window_move_right);
|
||||||
command_bind("window list", NULL, (SIGNAL_FUNC) cmd_window_list);
|
command_bind("window list", NULL, (SIGNAL_FUNC) cmd_window_list);
|
||||||
command_bind("window theme", NULL, (SIGNAL_FUNC) cmd_window_theme);
|
command_bind("window theme", NULL, (SIGNAL_FUNC) cmd_window_theme);
|
||||||
|
command_bind("savewindows", NULL, (SIGNAL_FUNC) cmd_savewindows);
|
||||||
}
|
}
|
||||||
|
|
||||||
void window_commands_deinit(void)
|
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 move right", (SIGNAL_FUNC) cmd_window_move_right);
|
||||||
command_unbind("window list", (SIGNAL_FUNC) cmd_window_list);
|
command_unbind("window list", (SIGNAL_FUNC) cmd_window_list);
|
||||||
command_unbind("window theme", (SIGNAL_FUNC) cmd_window_theme);
|
command_unbind("window theme", (SIGNAL_FUNC) cmd_window_theme);
|
||||||
|
command_unbind("savewindows", (SIGNAL_FUNC) cmd_savewindows);
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
7
src/fe-common/core/window-save.h
Normal file
7
src/fe-common/core/window-save.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#ifndef __WINDOW_SAVE_H
|
||||||
|
#define __WINDOW_SAVE_H
|
||||||
|
|
||||||
|
void windows_restore(void);
|
||||||
|
void windows_save(void);
|
||||||
|
|
||||||
|
#endif
|
@ -118,6 +118,7 @@ void window_destroy(WINDOW_REC *window)
|
|||||||
g_slist_free(window->waiting_channels);
|
g_slist_free(window->waiting_channels);
|
||||||
|
|
||||||
refnum = window->refnum;
|
refnum = window->refnum;
|
||||||
|
g_free_not_null(window->theme_name);
|
||||||
g_free_not_null(window->name);
|
g_free_not_null(window->name);
|
||||||
g_free(window);
|
g_free(window);
|
||||||
|
|
||||||
|
@ -60,7 +60,6 @@ extern WINDOW_REC *active_win;
|
|||||||
WINDOW_REC *window_create(WI_ITEM_REC *item, int automatic);
|
WINDOW_REC *window_create(WI_ITEM_REC *item, int automatic);
|
||||||
void window_destroy(WINDOW_REC *window);
|
void window_destroy(WINDOW_REC *window);
|
||||||
|
|
||||||
void window_set_active_num(int number);
|
|
||||||
void window_set_active(WINDOW_REC *window);
|
void window_set_active(WINDOW_REC *window);
|
||||||
void window_change_server(WINDOW_REC *window, void *server);
|
void window_change_server(WINDOW_REC *window, void *server);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user