diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2008-03-07 18:39:14 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2008-03-07 18:39:14 +0100 |
commit | 324eaa50695ae1fa548d386c07bd6435c8a5e6b5 (patch) | |
tree | de0da874241a33648998632b2f4c05a351392e8f | |
parent | 75e8c9a2f52bd7d241ee7b45e4be41c5812ef277 (diff) | |
download | weechat-324eaa50695ae1fa548d386c07bd6435c8a5e6b5.zip |
Save of bars in main WeeChat config file (weechat.rc)
-rw-r--r-- | src/core/wee-config.c | 88 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-bar.c | 4 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-main.c | 16 | ||||
-rw-r--r-- | src/gui/gui-bar.c | 1 |
4 files changed, 106 insertions, 3 deletions
diff --git a/src/core/wee-config.c b/src/core/wee-config.c index 9e4484f85..17f475227 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -41,6 +41,7 @@ #include "wee-util.h" #include "wee-list.h" #include "wee-string.h" +#include "../gui/gui-bar.h" #include "../gui/gui-buffer.h" #include "../gui/gui-chat.h" #include "../gui/gui-color.h" @@ -431,6 +432,73 @@ config_weechat_reload (void *data, struct t_config_file *config_file) } /* + * config_weechat_read_bar: read a bar in configuration file + */ + +void +config_weechat_read_bar (void *data, struct t_config_file *config_file, + char *option_name, char *value) +{ + char **argv, *error; + int argc, size; + long number; + + /* make C compiler happy */ + (void) data; + (void) config_file; + + if (option_name) + { + if (value && value[0]) + { + argv = string_explode (value, ";", 0, 0, &argc); + if (argc == 5) + { + error = NULL; + number = strtol (argv[2], &error, 10); + if (error && (error[0] == '\0')) + { + size = number; + gui_bar_new (NULL, option_name, argv[0], argv[1], size, + (argv[3][0] == '0') ? 0 : 1, + argv[4]); + } + } + } + } +} + +/* + * config_weechat_write_bars: write bars section in configuration file + * Return: 0 = successful + * -1 = write error + */ + +void +config_weechat_write_bars (void *data, struct t_config_file *config_file, + char *section_name) +{ + struct t_gui_bar *ptr_bar; + + /* make C compiler happy */ + (void) data; + + config_file_write_line (config_file, section_name, NULL); + + for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) + { + config_file_write_line (config_file, + ptr_bar->name, + "%s;%s;%d;%d;%s", + gui_bar_type_str[ptr_bar->type], + gui_bar_position_str[ptr_bar->position], + ptr_bar->size, + ptr_bar->separator, + ptr_bar->items); + } +} + +/* * config_weechat_read_key: read a key in configuration file */ @@ -451,14 +519,14 @@ config_weechat_read_key (void *data, struct t_config_file *config_file, } else { - /* unbin key if no value given */ + /* unbind key if no value given */ gui_keyboard_unbind (option_name); } } } /* - * config_weechat_write_keys: write alias section in configuration file + * config_weechat_write_keys: write keys section in configuration file * Return: 0 = successful * -1 = write error */ @@ -1289,7 +1357,21 @@ config_weechat_init () "plugins_save_config_on_unload", "boolean", N_("save configuration files when unloading plugins"), NULL, 0, 0, "on", NULL, NULL); - + + /* bars */ + ptr_section = config_file_new_section (weechat_config_file, "bars", + &config_weechat_read_bar, + NULL, + &config_weechat_write_bars, + NULL, + &config_weechat_write_bars, + NULL); + if (!ptr_section) + { + config_file_free (weechat_config_file); + return 0; + } + /* keys */ ptr_section = config_file_new_section (weechat_config_file, "keys", &config_weechat_read_key, diff --git a/src/gui/curses/gui-curses-bar.c b/src/gui/curses/gui-curses-bar.c index ecdc83aff..1e27fb81c 100644 --- a/src/gui/curses/gui-curses-bar.c +++ b/src/gui/curses/gui-curses-bar.c @@ -147,6 +147,7 @@ gui_bar_window_calculate_pos_size (struct t_gui_bar_window *bar_window, /* * gui_bar_window_new: create a new "window bar" for a bar, in screen or a window * if window is not NULL, bar window will be in this window + * return 1 if ok, 0 if error */ int @@ -154,6 +155,9 @@ gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window) { struct t_gui_bar_window *new_bar_window; + if (!gui_init_ok) + return 0; + new_bar_window = (struct t_gui_bar_window *) malloc (sizeof (struct t_gui_bar_window)); if (new_bar_window) { diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c index 62ca654fa..9c123c99c 100644 --- a/src/gui/curses/gui-curses-main.c +++ b/src/gui/curses/gui-curses-main.c @@ -38,6 +38,7 @@ #include "../../core/wee-util.h" #include "../../plugins/plugin.h" #include "../gui-main.h" +#include "../gui-bar.h" #include "../gui-bar-item.h" #include "../gui-buffer.h" #include "../gui-chat.h" @@ -74,6 +75,7 @@ void gui_main_init () { struct t_gui_buffer *ptr_buffer; + struct t_gui_bar *ptr_bar; initscr (); @@ -123,6 +125,20 @@ gui_main_init () if (CONFIG_BOOLEAN(config_look_set_title)) gui_window_title_set (); } + + if (gui_init_ok) + { + /* create bar windows for root bars (they were read from config, + but no window was created (GUI was not initialized) */ + for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) + { + if ((ptr_bar->type == GUI_BAR_TYPE_ROOT) + && (!ptr_bar->bar_window)) + { + gui_bar_window_new (ptr_bar, NULL); + } + } + } } /* diff --git a/src/gui/gui-bar.c b/src/gui/gui-bar.c index 0cfa99798..85f5f3603 100644 --- a/src/gui/gui-bar.c +++ b/src/gui/gui-bar.c @@ -159,6 +159,7 @@ gui_bar_new (struct t_weechat_plugin *plugin, char *name, char *type, new_bar->items_count = 0; new_bar->items_array = NULL; } + new_bar->bar_window = NULL; if (type_value == GUI_BAR_TYPE_ROOT) { |