summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-command.c33
-rw-r--r--src/core/wee-config-file.c153
-rw-r--r--src/core/wee-config-file.h10
-rw-r--r--src/core/wee-config.c119
-rw-r--r--src/core/wee-config.h1
-rw-r--r--src/gui/curses/gui-curses-bar.c78
-rw-r--r--src/gui/curses/gui-curses-main.c2
-rw-r--r--src/gui/curses/gui-curses-window.c2
-rw-r--r--src/gui/gtk/gui-gtk-bar.c9
-rw-r--r--src/gui/gui-bar-item.c4
-rw-r--r--src/gui/gui-bar.c722
-rw-r--r--src/gui/gui-bar.h39
-rw-r--r--src/gui/gui-window.c2
-rw-r--r--src/plugins/alias/alias.c3
-rw-r--r--src/plugins/charset/charset.c5
-rw-r--r--src/plugins/irc/irc-command.c98
-rw-r--r--src/plugins/irc/irc-config.c6
-rw-r--r--src/plugins/irc/irc-server.c28
-rw-r--r--src/plugins/plugin-config.c2
-rw-r--r--src/plugins/plugin.c3
-rw-r--r--src/plugins/scripts/lua/weechat-lua-api.c110
-rw-r--r--src/plugins/scripts/perl/weechat-perl-api.c86
-rw-r--r--src/plugins/scripts/python/weechat-python-api.c88
-rw-r--r--src/plugins/scripts/ruby/weechat-ruby-api.c117
-rw-r--r--src/plugins/scripts/script-api.c4
-rw-r--r--src/plugins/scripts/script-api.h2
-rw-r--r--src/plugins/weechat-plugin.h23
27 files changed, 1369 insertions, 380 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index dceda8ca2..6991c901d 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -64,7 +64,7 @@ int
command_bar (void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol)
{
- int type, position, size, separator;
+ int type, position;
long number;
char *error;
struct t_gui_bar *ptr_bar;
@@ -89,17 +89,17 @@ command_bar (void *data, struct t_gui_buffer *buffer,
_(" %d. %s: %s, %s, %s: %s%s%d%s, items: %s%s (plugin: %s)"),
ptr_bar->number,
ptr_bar->name,
- gui_bar_type_str[ptr_bar->type],
- gui_bar_position_str[ptr_bar->position],
- ((ptr_bar->position == GUI_BAR_POSITION_BOTTOM)
- || (ptr_bar->position == GUI_BAR_POSITION_TOP)) ?
+ gui_bar_type_str[CONFIG_INTEGER(ptr_bar->type)],
+ gui_bar_position_str[CONFIG_INTEGER(ptr_bar->position)],
+ ((CONFIG_INTEGER(ptr_bar->position) == GUI_BAR_POSITION_BOTTOM)
+ || (CONFIG_INTEGER(ptr_bar->position) == GUI_BAR_POSITION_TOP)) ?
_("height") : _("width"),
- (ptr_bar->size == 0) ? _("auto") : "",
- (ptr_bar->size == 0) ? " (" : "",
+ (CONFIG_INTEGER(ptr_bar->size) == 0) ? _("auto") : "",
+ (CONFIG_INTEGER(ptr_bar->size) == 0) ? " (" : "",
ptr_bar->current_size,
- (ptr_bar->size == 0) ? ")" : "",
- (ptr_bar->items) ? ptr_bar->items : "-",
- (ptr_bar->separator) ?
+ (CONFIG_INTEGER(ptr_bar->size) == 0) ? ")" : "",
+ (CONFIG_STRING(ptr_bar->items)) ? CONFIG_STRING(ptr_bar->items) : "-",
+ (CONFIG_INTEGER(ptr_bar->separator)) ?
_(", with separator") : "",
(ptr_bar->plugin) ? ptr_bar->plugin->name : "-");
}
@@ -145,7 +145,7 @@ command_bar (void *data, struct t_gui_buffer *buffer,
"bar");
return WEECHAT_RC_ERROR;
}
- type = gui_bar_get_type (argv[3]);
+ type = gui_bar_search_type (argv[3]);
if (type < 0)
{
gui_chat_printf (NULL,
@@ -155,7 +155,7 @@ command_bar (void *data, struct t_gui_buffer *buffer,
argv[3], argv[2]);
return WEECHAT_RC_ERROR;
}
- position = gui_bar_get_position (argv[4]);
+ position = gui_bar_search_position (argv[4]);
if (position < 0)
{
gui_chat_printf (NULL,
@@ -169,14 +169,9 @@ command_bar (void *data, struct t_gui_buffer *buffer,
number = strtol (argv[5], &error, 10);
if (error && !error[0])
{
- size = number;
- separator = 0;
- if (strcmp (argv[6], "0") != 0)
- separator = 1;
-
/* create bar */
- if (gui_bar_new (NULL, argv[2], argv[3], argv[4], size,
- separator, argv[7]))
+ if (gui_bar_new (NULL, argv[2], argv[3], argv[4], argv[5],
+ argv[6], argv_eol[7]))
{
gui_chat_printf (NULL, _("Bar \"%s\" created"),
argv[2]);
diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c
index 0b052f680..a774c8c17 100644
--- a/src/core/wee-config-file.c
+++ b/src/core/wee-config-file.c
@@ -149,6 +149,7 @@ config_file_valid_for_plugin (struct t_weechat_plugin *plugin,
struct t_config_section *
config_file_new_section (struct t_config_file *config_file, char *name,
+ int user_can_add_options, int user_can_delete_options,
int (*callback_read)(void *data,
struct t_config_file *config_file,
struct t_config_section *section,
@@ -175,10 +176,15 @@ config_file_new_section (struct t_config_file *config_file, char *name,
if (!config_file || !name)
return NULL;
+ if (config_file_search_section (config_file, name))
+ return NULL;
+
new_section = malloc (sizeof (*new_section));
if (new_section)
{
new_section->name = strdup (name);
+ new_section->user_can_add_options = user_can_add_options;
+ new_section->user_can_delete_options = user_can_delete_options;
new_section->callback_read = callback_read;
new_section->callback_read_data = callback_read_data;
new_section->callback_write = callback_write;
@@ -279,6 +285,53 @@ config_file_option_find_pos (struct t_config_section *section, char *name)
}
/*
+ * config_file_option_insert_in_section: insert option in section (for sorting
+ * options)
+ */
+
+void
+config_file_option_insert_in_section (struct t_config_option *option)
+{
+ struct t_config_option *pos_option;
+
+ if (!option->section)
+ return;
+
+ if (option->section->options)
+ {
+ pos_option = config_file_option_find_pos (option->section,
+ option->name);
+ if (pos_option)
+ {
+ /* insert option into the list (before option found) */
+ option->prev_option = pos_option->prev_option;
+ option->next_option = pos_option;
+ if (pos_option->prev_option)
+ (pos_option->prev_option)->next_option = option;
+ else
+ (option->section)->options = option;
+ pos_option->prev_option = option;
+ }
+ else
+ {
+ /* add option to end of section */
+ option->prev_option = (option->section)->last_option;
+ option->next_option = NULL;
+ (option->section)->last_option->next_option = option;
+ (option->section)->last_option = option;
+ }
+ }
+ else
+ {
+ /* first option for section */
+ option->prev_option = NULL;
+ option->next_option = NULL;
+ (option->section)->options = option;
+ (option->section)->last_option = option;
+ }
+}
+
+/*
* config_file_new_option: create a new option
*/
@@ -299,7 +352,7 @@ config_file_new_option (struct t_config_file *config_file,
struct t_config_option *option),
void *callback_delete_data)
{
- struct t_config_option *new_option, *pos_option;
+ struct t_config_option *new_option;
int var_type, int_value, argc, i, index_value;
long number;
char *error;
@@ -307,6 +360,10 @@ config_file_new_option (struct t_config_file *config_file,
if (!name)
return NULL;
+ if (config_file && section
+ && config_file_search_option (config_file, section, name))
+ return NULL;
+
var_type = -1;
for (i = 0; i < CONFIG_NUM_OPTION_TYPES; i++)
{
@@ -414,37 +471,7 @@ config_file_new_option (struct t_config_file *config_file,
if (section)
{
- if (section->options)
- {
- pos_option = config_file_option_find_pos (section, name);
- if (pos_option)
- {
- /* insert option into the list (before option found) */
- new_option->prev_option = pos_option->prev_option;
- new_option->next_option = pos_option;
- if (pos_option->prev_option)
- (pos_option->prev_option)->next_option = new_option;
- else
- section->options = new_option;
- pos_option->prev_option = new_option;
- }
- else
- {
- /* add option to end of section */
- new_option->prev_option = section->last_option;
- new_option->next_option = NULL;
- section->last_option->next_option = new_option;
- section->last_option = new_option;
- }
- }
- else
- {
- /* first option for section */
- new_option->prev_option = NULL;
- new_option->next_option = NULL;
- section->options = new_option;
- section->last_option = new_option;
- }
+ config_file_option_insert_in_section (new_option);
}
else
{
@@ -934,6 +961,39 @@ config_file_option_set (struct t_config_option *option, char *value,
}
/*
+ * config_file_option_rename: rename an option
+ */
+
+void
+config_file_option_rename (struct t_config_option *option, char *new_name)
+{
+ if (!new_name || !new_name[0])
+ return;
+
+ /* remove option from list */
+ if (option->section)
+ {
+ if (option->prev_option)
+ (option->prev_option)->next_option = option->next_option;
+ if (option->next_option)
+ (option->next_option)->prev_option = option->prev_option;
+ if (option->section->options == option)
+ (option->section)->options = option->next_option;
+ if (option->section->last_option == option)
+ (option->section)->last_option = option->prev_option;
+ }
+
+ /* rename option */
+ if (option->name)
+ free (option->name);
+ option->name = strdup (new_name);
+
+ /* re-insert option in section */
+ if (option->section)
+ config_file_option_insert_in_section (option);
+}
+
+/*
* config_file_option_get_pointer: get a pointer of an option property
*/
@@ -997,7 +1057,8 @@ config_file_option_set_with_string (char *option_name, char *value)
rc = config_file_option_set (ptr_option, value, 1);
else
{
- if (ptr_section->callback_create_option)
+ if (ptr_section->user_can_add_options
+ && ptr_section->callback_create_option)
{
rc = (int)(ptr_section->callback_create_option)
(ptr_section->callback_create_option_data,
@@ -1036,7 +1097,7 @@ config_file_unset_with_string (char *option_name)
/* delete option */
if (ptr_section && ptr_option)
{
- if (ptr_section->callback_create_option)
+ if (ptr_section->user_can_delete_options)
{
/* removing option */
if (ptr_option->callback_delete)
@@ -1045,7 +1106,7 @@ config_file_unset_with_string (char *option_name)
(ptr_option->callback_delete_data,
ptr_option);
}
- config_file_option_free (ptr_section, ptr_option);
+ config_file_option_free (ptr_option);
rc = 2;
}
else
@@ -1654,7 +1715,7 @@ config_file_reload (struct t_config_file *config_file)
}
/*
- * config_file_option_free: free data in an option
+ * config_file_option_free_data: free data in an option
*/
void
@@ -1677,23 +1738,25 @@ config_file_option_free_data (struct t_config_option *option)
*/
void
-config_file_option_free (struct t_config_section *section,
- struct t_config_option *option)
+config_file_option_free (struct t_config_option *option)
{
+ struct t_config_section *ptr_section;
struct t_config_option *new_options;
if (!option)
return;
+
+ ptr_section = option->section;
/* remove option from section */
- if (section)
+ if (ptr_section)
{
- if (section->last_option == option)
- section->last_option = option->prev_option;
+ if (ptr_section->last_option == option)
+ ptr_section->last_option = option->prev_option;
if (option->prev_option)
{
(option->prev_option)->next_option = option->next_option;
- new_options = section->options;
+ new_options = ptr_section->options;
}
else
new_options = option->next_option;
@@ -1706,8 +1769,8 @@ config_file_option_free (struct t_config_section *section,
free (option);
- if (section)
- section->options = new_options;
+ if (ptr_section)
+ ptr_section->options = new_options;
}
/*
@@ -1722,7 +1785,7 @@ config_file_section_free_options (struct t_config_section *section)
while (section->options)
{
- config_file_option_free (section, section->options);
+ config_file_option_free (section->options);
}
}
diff --git a/src/core/wee-config-file.h b/src/core/wee-config-file.h
index ab5faa205..e4ff16a6f 100644
--- a/src/core/wee-config-file.h
+++ b/src/core/wee-config-file.h
@@ -57,6 +57,8 @@ struct t_config_file
struct t_config_section
{
char *name; /* section name */
+ int user_can_add_options; /* user can add with /set ? */
+ int user_can_delete_options; /* user can del with /unset ? */
int (*callback_read) /* called to read a line from */
(void *data, /* config file (only for some */
struct t_config_file *config_file, /* special sections) */
@@ -138,6 +140,8 @@ extern int config_file_valid_for_plugin (struct t_weechat_plugin *plugin,
struct t_config_file *config_file);
extern struct t_config_section *config_file_new_section (struct t_config_file *config_file,
char *name,
+ int user_can_add_options,
+ int user_can_delete_options,
int (*callback_read)(void *data,
struct t_config_file *config_file,
struct t_config_section *section,
@@ -199,6 +203,8 @@ extern int config_file_option_reset (struct t_config_option *option,
int run_callback);
extern int config_file_option_set (struct t_config_option *option,
char *value, int run_callback);
+extern void config_file_option_rename (struct t_config_option *option,
+ char *new_name);
extern void *config_file_option_get_pointer (struct t_config_option *option,
char *property);
extern int config_file_option_set_with_string (char *option_name, char *value);
@@ -213,9 +219,7 @@ extern void config_file_write_line (struct t_config_file *config_file,
extern int config_file_write (struct t_config_file *config_files);
extern int config_file_read (struct t_config_file *config_file);
extern int config_file_reload (struct t_config_file *config_file);
-extern void config_file_option_free_data (struct t_config_option *option);
-extern void config_file_option_free (struct t_config_section *section,
- struct t_config_option *option);
+extern void config_file_option_free (struct t_config_option *option);
extern void config_file_section_free_options (struct t_config_section *section);
extern void config_file_section_free (struct t_config_file *config_file,
struct t_config_section *section);
diff --git a/src/core/wee-config.c b/src/core/wee-config.c
index f1277b91e..a37a28614 100644
--- a/src/core/wee-config.c
+++ b/src/core/wee-config.c
@@ -56,6 +56,7 @@
struct t_config_file *weechat_config_file = NULL;
+struct t_config_section *weechat_config_section_bar = NULL;
/* config, startup section */
@@ -500,6 +501,8 @@ config_change_day_change (void *data, struct t_config_option *option)
int
config_weechat_reload (void *data, struct t_config_file *config_file)
{
+ int rc;
+
/* make C compiler happy */
(void) data;
(void) config_file;
@@ -513,7 +516,14 @@ config_weechat_reload (void *data, struct t_config_file *config_file)
/* remove all filters */
gui_filter_free_all ();
- return config_file_reload (weechat_config_file);
+ rc = config_file_reload (weechat_config_file);
+
+ if (rc == 0)
+ {
+ gui_bar_use_temp_bars ();
+ }
+
+ return rc;
}
/*
@@ -526,9 +536,10 @@ config_weechat_bar_read (void *data, struct t_config_file *config_file,
struct t_config_section *section,
char *option_name, char *value)
{
- char **argv, *error;
- int argc, size;
- long number;
+ char *pos_option, *bar_name;
+ struct t_gui_bar *ptr_temp_bar;
+ struct t_config_option *ptr_option;
+ int index_option;
/* make C compiler happy */
(void) data;
@@ -537,24 +548,72 @@ config_weechat_bar_read (void *data, struct t_config_file *config_file,
if (option_name)
{
- if (value && value[0])
+ pos_option = strchr (option_name, '.');
+ if (pos_option)
{
- argv = string_explode (value, ";", 0, 0, &argc);
- if (argv)
+ bar_name = string_strndup (option_name, pos_option - option_name);
+ if (bar_name)
{
- if (argc == 5)
+ pos_option++;
+ for (ptr_temp_bar = gui_temp_bars; ptr_temp_bar;
+ ptr_temp_bar = ptr_temp_bar->next_bar)
+ {
+ if (strcmp (ptr_temp_bar->name, bar_name) == 0)
+ break;
+ }
+ if (!ptr_temp_bar)
{
- error = NULL;
- number = strtol (argv[2], &error, 10);
- if (error && !error[0])
+ /* create new temp bar */
+ ptr_temp_bar = gui_bar_alloc (bar_name);
+ if (ptr_temp_bar)
{
- size = number;
- gui_bar_new (NULL, option_name, argv[0], argv[1], size,
- (argv[3][0] == '0') ? 0 : 1,
- argv[4]);
+ /* add new temp bar at end of queue */
+ ptr_temp_bar->prev_bar = last_gui_temp_bar;
+ ptr_temp_bar->next_bar = NULL;
+
+ if (!gui_temp_bars)
+ gui_temp_bars = ptr_temp_bar;
+ else
+ last_gui_temp_bar->next_bar = ptr_temp_bar;
+ last_gui_temp_bar = ptr_temp_bar;
}
}
- string_free_exploded (argv);
+
+ if (ptr_temp_bar)
+ {
+ index_option = gui_bar_search_option (pos_option);
+ if (index_option >= 0)
+ {
+ ptr_option = gui_bar_create_option (ptr_temp_bar->name,
+ index_option,
+ value);
+ if (ptr_option)
+ {
+ log_printf ("createion pour index %d, ptr = %x",
+ index_option, ptr_temp_bar);
+ switch (index_option)
+ {
+ case GUI_BAR_OPTION_TYPE:
+ ptr_temp_bar->type = ptr_option;
+ break;
+ case GUI_BAR_OPTION_POSITION:
+ ptr_temp_bar->position = ptr_option;
+ break;
+ case GUI_BAR_OPTION_SIZE:
+ ptr_temp_bar->size = ptr_option;
+ break;
+ case GUI_BAR_OPTION_SEPARATOR:
+ ptr_temp_bar->separator = ptr_option;
+ break;
+ case GUI_BAR_OPTION_ITEMS:
+ ptr_temp_bar->items = ptr_option;
+ break;
+ }
+ }
+ }
+ }
+
+ free (bar_name);
}
}
}
@@ -584,11 +643,11 @@ config_weechat_bar_write (void *data, struct t_config_file *config_file,
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);
+ gui_bar_type_str[CONFIG_INTEGER(ptr_bar->type)],
+ gui_bar_position_str[CONFIG_INTEGER(ptr_bar->position)],
+ CONFIG_INTEGER(ptr_bar->size),
+ CONFIG_INTEGER(ptr_bar->separator),
+ CONFIG_STRING(ptr_bar->items));
}
}
@@ -757,6 +816,7 @@ config_weechat_init ()
/* startup */
ptr_section = config_file_new_section (weechat_config_file, "startup",
+ 0, 0,
NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL);
if (!ptr_section)
@@ -793,6 +853,7 @@ config_weechat_init ()
/* look */
ptr_section = config_file_new_section (weechat_config_file, "look",
+ 0, 0,
NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL);
if (!ptr_section)
@@ -956,7 +1017,7 @@ config_weechat_init ()
config_look_item_time_format = config_file_new_option (
weechat_config_file, ptr_section,
"item_time_format", "string",
- N_("time format for time item"),
+ N_("time format for \"time\" bar item"),
NULL, 0, 0, "%H:%M", NULL, NULL, &config_change_item_time_format, NULL, NULL, NULL);
config_look_hotlist_names_count = config_file_new_option (
weechat_config_file, ptr_section,
@@ -1016,6 +1077,7 @@ config_weechat_init ()
/* colors */
ptr_section = config_file_new_section (weechat_config_file, "color",
+ 0, 0,
NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL);
if (!ptr_section)
@@ -1502,6 +1564,7 @@ config_weechat_init ()
/* history */
ptr_section = config_file_new_section (weechat_config_file, "history",
+ 0, 0,
NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL);
if (!ptr_section)
@@ -1531,6 +1594,7 @@ config_weechat_init ()
/* proxy */
ptr_section = config_file_new_section (weechat_config_file, "proxy",
+ 0, 0,
NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL);
if (!ptr_section)
@@ -1577,6 +1641,7 @@ config_weechat_init ()
/* plugin */
ptr_section = config_file_new_section (weechat_config_file, "plugin",
+ 0, 0,
NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL);
if (!ptr_section)
@@ -1619,9 +1684,10 @@ config_weechat_init ()
/* bars */
ptr_section = config_file_new_section (weechat_config_file, "bar",
+ 0, 0,
&config_weechat_bar_read, NULL,
- &config_weechat_bar_write, NULL,
- &config_weechat_bar_write, NULL,
+ NULL, NULL,
+ NULL, NULL,
NULL, NULL);
if (!ptr_section)
{
@@ -1629,8 +1695,11 @@ config_weechat_init ()
return 0;
}
+ weechat_config_section_bar = ptr_section;
+
/* filters */
ptr_section = config_file_new_section (weechat_config_file, "filter",
+ 0, 0,
&config_weechat_filter_read, NULL,
&config_weechat_filter_write, NULL,
&config_weechat_filter_write, NULL,
@@ -1643,6 +1712,7 @@ config_weechat_init ()
/* keys */
ptr_section = config_file_new_section (weechat_config_file, "key",
+ 0, 0,
&config_weechat_key_read, NULL,
&config_weechat_key_write, NULL,
&config_weechat_key_write, NULL,
@@ -1673,6 +1743,7 @@ config_weechat_read ()
{
config_change_infobar_seconds (NULL, NULL);
config_change_day_change (NULL, NULL);
+ gui_bar_use_temp_bars ();
}
return rc;
diff --git a/src/core/wee-config.h b/src/core/wee-config.h
index aca427b0e..c2bc989da 100644
--- a/src/core/wee-config.h
+++ b/src/core/wee-config.h
@@ -41,6 +41,7 @@
#define CONFIG_LOOK_HOTLIST_SORT_NUMBER_DESC 5
extern struct t_config_file *weechat_config_file;
+extern struct t_config_section *weechat_config_section_bar;
extern struct t_config_option *config_startup_display_logo;
extern struct t_config_option *config_startup_display_version;
diff --git a/src/gui/curses/gui-curses-bar.c b/src/gui/curses/gui-curses-bar.c
index 2b073c0d9..dfdeee58b 100644
--- a/src/gui/curses/gui-curses-bar.c
+++ b/src/gui/curses/gui-curses-bar.c
@@ -28,6 +28,7 @@
#include <ctype.h>
#include "../../core/weechat.h"
+#include "../../core/wee-config.h"
#include "../../core/wee-log.h"
#include "../../core/wee-string.h"
#include "../../core/wee-utf8.h"
@@ -80,8 +81,8 @@ gui_bar_window_get_size (struct t_gui_bar *bar, struct t_gui_window *window,
if (bar && (ptr_bar_window->bar == bar))
return total_size;
- if ((ptr_bar_window->bar->type != GUI_BAR_TYPE_ROOT)
- && (ptr_bar_window->bar->position == position))
+ if ((CONFIG_INTEGER(ptr_bar_window->bar->type) != GUI_BAR_TYPE_ROOT)
+ && (CONFIG_INTEGER(ptr_bar_window->bar->position) == (int)position))
{
switch (position)
{
@@ -96,7 +97,7 @@ gui_bar_window_get_size (struct t_gui_bar *bar, struct t_gui_window *window,
case GUI_BAR_NUM_POSITIONS:
break;
}
- if (ptr_bar_window->bar->separator)
+ if (CONFIG_INTEGER(ptr_bar_window->bar->separator))
total_size++;
}
}
@@ -118,7 +119,7 @@ gui_bar_check_size_add (struct t_gui_bar *bar, int add_size)
sub_width = 0;
sub_height = 0;
- switch (bar->position)
+ switch (CONFIG_INTEGER(bar->position))
{
case GUI_BAR_POSITION_BOTTOM:
case GUI_BAR_POSITION_TOP:
@@ -134,7 +135,7 @@ gui_bar_check_size_add (struct t_gui_bar *bar, int add_size)
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
{
- if ((bar->type == GUI_BAR_TYPE_ROOT)
+ if ((CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT)
|| (gui_bar_window_search_bar (ptr_win, bar)))
{
if ((ptr_win->win_chat_width - sub_width < GUI_WINDOW_CHAT_MIN_WIDTH)
@@ -181,7 +182,7 @@ gui_bar_window_calculate_pos_size (struct t_gui_bar_window *bar_window,
add_right = gui_bar_root_get_size (bar_window->bar, GUI_BAR_POSITION_RIGHT);
}
- switch (bar_window->bar->position)
+ switch (CONFIG_INTEGER(bar_window->bar->position))
{
case GUI_BAR_POSITION_BOTTOM:
bar_window->x = x1 + add_left;
@@ -235,9 +236,9 @@ gui_bar_window_create_win (struct t_gui_bar_window *bar_window)
bar_window->y,
bar_window->x);
- if (bar_window->bar->separator)
+ if (CONFIG_INTEGER(bar_window->bar->separator))
{
- switch (bar_window->bar->position)
+ switch (CONFIG_INTEGER(bar_window->bar->position))
{
case GUI_BAR_POSITION_BOTTOM:
bar_window->win_separator = newwin (1,
@@ -304,13 +305,13 @@ gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window)
if (window)
{
/* bar is type "window_active" and window is not active */
- if ((bar->type == GUI_BAR_TYPE_WINDOW_ACTIVE)
+ if ((CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_WINDOW_ACTIVE)
&& gui_current_window
&& (gui_current_window != window))
return 1;
/* bar is type "window_inactive" and window is active */
- if ((bar->type == GUI_BAR_TYPE_WINDOW_INACTIVE)
+ if ((CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_WINDOW_INACTIVE)
&& (!gui_current_window || (gui_current_window == window)))
return 1;
}
@@ -387,7 +388,7 @@ gui_bar_window_recreate_bar_windows (struct t_gui_bar *bar)
struct t_gui_window *ptr_win;
struct t_gui_bar_window *ptr_bar_win;
- if (bar->type == GUI_BAR_TYPE_ROOT)
+ if (CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT)
{
gui_bar_window_calculate_pos_size (bar->bar_window, NULL);
gui_bar_window_create_win (bar->bar_window);
@@ -487,9 +488,9 @@ gui_bar_window_remove_unused_bars (struct t_gui_window *window)
{
next_bar_win = ptr_bar_win->next_bar_window;
- if (((ptr_bar_win->bar->type == GUI_BAR_TYPE_WINDOW_ACTIVE)
+ if (((CONFIG_INTEGER(ptr_bar_win->bar->type) == GUI_BAR_TYPE_WINDOW_ACTIVE)
&& (window != gui_current_window))
- || ((ptr_bar_win->bar->type == GUI_BAR_TYPE_WINDOW_INACTIVE)
+ || ((CONFIG_INTEGER(ptr_bar_win->bar->type) == GUI_BAR_TYPE_WINDOW_INACTIVE)
&& (window == gui_current_window)))
{
gui_bar_window_free (ptr_bar_win, window);
@@ -518,9 +519,9 @@ gui_bar_window_add_missing_bars (struct t_gui_window *window)
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
{
- if (((ptr_bar->type == GUI_BAR_TYPE_WINDOW_ACTIVE)
+ if (((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_WINDOW_ACTIVE)
&& (window == gui_current_window))
- || ((ptr_bar->type == GUI_BAR_TYPE_WINDOW_INACTIVE)
+ || ((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_WINDOW_INACTIVE)
&& (window != gui_current_window)))
{
if (!gui_bar_window_search_bar (window, ptr_bar))
@@ -549,8 +550,8 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
if (!string || !string[0])
return 0;
- if ((bar_window->bar->position == GUI_BAR_POSITION_LEFT)
- || (bar_window->bar->position == GUI_BAR_POSITION_RIGHT))
+ if ((CONFIG_INTEGER(bar_window->bar->position) == GUI_BAR_POSITION_LEFT)
+ || (CONFIG_INTEGER(bar_window->bar->position) == GUI_BAR_POSITION_RIGHT))
gui_window_set_weechat_color (bar_window->win_bar, GUI_COLOR_CHAT);
else
gui_window_set_weechat_color (bar_window->win_bar, GUI_COLOR_STATUS);
@@ -609,6 +610,20 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
}
/*
+ * gui_bar_window_clear_bg: clear background for a bar window
+ */
+
+void
+gui_bar_window_clear_bg (struct t_gui_bar_window *bar_window)
+{
+ if ((CONFIG_INTEGER(bar_window->bar->position) == GUI_BAR_POSITION_LEFT)
+ || (CONFIG_INTEGER(bar_window->bar->position) == GUI_BAR_POSITION_RIGHT))
+ gui_window_curses_clear (bar_window->win_bar, GUI_COLOR_CHAT);
+ else
+ gui_window_curses_clear (bar_window->win_bar, GUI_COLOR_STATUS);
+}
+
+/*
* gui_bar_window_draw: draw a bar for a window
*/
@@ -621,13 +636,7 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
int content_length, length, max_length;
struct t_gui_bar_item *ptr_item;
- if ((bar_window->bar->position == GUI_BAR_POSITION_LEFT)
- || (bar_window->bar->position == GUI_BAR_POSITION_RIGHT))
- gui_window_curses_clear (bar_window->win_bar, GUI_COLOR_CHAT);
- else
- gui_window_curses_clear (bar_window->win_bar, GUI_COLOR_STATUS);
-
- if (bar_window->bar->size == 0)
+ if (CONFIG_INTEGER(bar_window->bar->size) == 0)
{
content = NULL;
content_length = 1;
@@ -652,8 +661,8 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
{
content_length += 1 + strlen (item_value);
content = realloc (content, content_length);
- if ((bar_window->bar->position == GUI_BAR_POSITION_LEFT)
- || (bar_window->bar->position == GUI_BAR_POSITION_RIGHT))
+ if ((CONFIG_INTEGER(bar_window->bar->position) == GUI_BAR_POSITION_LEFT)
+ || (CONFIG_INTEGER(bar_window->bar->position) == GUI_BAR_POSITION_RIGHT))
{
strcat (content, "\n");
}
@@ -670,10 +679,12 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
if (items_count == 0)
{
gui_bar_set_current_size (bar_window->bar, 1);
+ gui_bar_window_recreate_bar_windows (bar_window->bar);
+ gui_bar_window_clear_bg (bar_window);
}
else
{
- switch (bar_window->bar->position)
+ switch (CONFIG_INTEGER(bar_window->bar->position))
{
case GUI_BAR_POSITION_BOTTOM:
case GUI_BAR_POSITION_TOP:
@@ -705,6 +716,7 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
case GUI_BAR_NUM_POSITIONS:
break;
}
+ gui_bar_window_clear_bg (bar_window);
x = 0;
y = 0;
for (line = 0; line < items_count; line++)
@@ -721,9 +733,17 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
string_free_exploded (items);
free (content);
}
+ else
+ {
+ gui_bar_set_current_size (bar_window->bar, 1);
+ gui_bar_window_recreate_bar_windows (bar_window->bar);
+ gui_bar_window_clear_bg (bar_window);
+ }
}
else
{
+ gui_bar_window_clear_bg (bar_window);
+
x = 0;
y = 0;
@@ -773,9 +793,9 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
wnoutrefresh (bar_window->win_bar);
- if (bar_window->bar->separator)
+ if (CONFIG_INTEGER(bar_window->bar->separator))
{
- switch (bar_window->bar->position)
+ switch (CONFIG_INTEGER(bar_window->bar->position))
{
case GUI_BAR_POSITION_BOTTOM:
gui_window_set_weechat_color (bar_window->win_separator,
diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c
index eac8336e1..d10740064 100644
--- a/src/gui/curses/gui-curses-main.c
+++ b/src/gui/curses/gui-curses-main.c
@@ -136,7 +136,7 @@ gui_main_init ()
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))
+ if ((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_ROOT) && (!ptr_bar->bar_window))
gui_bar_window_new (ptr_bar, NULL);
}
for (ptr_bar_win = GUI_CURSES(gui_windows)->bar_windows;
diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c
index be00e721f..23798e3df 100644
--- a/src/gui/curses/gui-curses-window.c
+++ b/src/gui/curses/gui-curses-window.c
@@ -1035,7 +1035,7 @@ gui_window_refresh_windows ()
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
{
- if (ptr_bar->type == GUI_BAR_TYPE_ROOT)
+ if (CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_ROOT)
{
gui_bar_window_calculate_pos_size (ptr_bar->bar_window, NULL);
gui_bar_window_create_win (ptr_bar->bar_window);
diff --git a/src/gui/gtk/gui-gtk-bar.c b/src/gui/gtk/gui-gtk-bar.c
index 570cbed10..59b5a5b58 100644
--- a/src/gui/gtk/gui-gtk-bar.c
+++ b/src/gui/gtk/gui-gtk-bar.c
@@ -26,6 +26,7 @@
#include <stdlib.h>
#include "../../core/weechat.h"
+#include "../../core/wee-config.h"
#include "../../core/wee-log.h"
#include "../gui-bar.h"
#include "../gui-chat.h"
@@ -208,9 +209,9 @@ gui_bar_window_remove_unused_bars (struct t_gui_window *window)
{
next_bar_win = ptr_bar_win->next_bar_window;
- if (((ptr_bar_win->bar->type == GUI_BAR_TYPE_WINDOW_ACTIVE)
+ if (((CONFIG_INTEGER(ptr_bar_win->bar->type) == GUI_BAR_TYPE_WINDOW_ACTIVE)
&& (window != gui_current_window))
- || ((ptr_bar_win->bar->type == GUI_BAR_TYPE_WINDOW_INACTIVE)
+ || ((CONFIG_INTEGER(ptr_bar_win->bar->type) == GUI_BAR_TYPE_WINDOW_INACTIVE)
&& (window == gui_current_window)))
{
gui_bar_window_free (ptr_bar_win, window);
@@ -239,9 +240,9 @@ gui_bar_window_add_missing_bars (struct t_gui_window *window)
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
{
- if (((ptr_bar->type == GUI_BAR_TYPE_WINDOW_ACTIVE)
+ if (((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_WINDOW_ACTIVE)
&& (window == gui_current_window))
- || ((ptr_bar->type == GUI_BAR_TYPE_WINDOW_INACTIVE)
+ || ((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_WINDOW_INACTIVE)
&& (window != gui_current_window)))
{
if (!gui_bar_window_search_bar (window, ptr_bar))
diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c
index bf59f1527..f01f42c8b 100644
--- a/src/gui/gui-bar-item.c
+++ b/src/gui/gui-bar-item.c
@@ -135,7 +135,7 @@ gui_bar_item_new (struct t_weechat_plugin *plugin, char *name,
gui_bar_items = new_bar_item;
last_gui_bar_item = new_bar_item;
new_bar_item->next_item = NULL;
-
+
return new_bar_item;
}
@@ -173,7 +173,7 @@ void
gui_bar_item_update (char *name)
{
struct t_gui_bar *ptr_bar;
-
+
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
{
if (gui_bar_contains_item (ptr_bar, name))
diff --git a/src/gui/gui-bar.c b/src/gui/gui-bar.c
index 70862944c..976cfa4a7 100644
--- a/src/gui/gui-bar.c
+++ b/src/gui/gui-bar.c
@@ -25,30 +25,62 @@
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
#include "../core/weechat.h"
+#include "../core/wee-config.h"
#include "../core/wee-log.h"
#include "../core/wee-string.h"
#include "gui-bar.h"
+#include "gui-chat.h"
#include "gui-window.h"
+char *gui_bar_option_str[GUI_BAR_NUM_OPTIONS] =
+{ "type", "position", "size", "separator", "items" };
char *gui_bar_type_str[GUI_BAR_NUM_TYPES] =
{ "root", "window", "window_active", "window_inactive" };
char *gui_bar_position_str[GUI_BAR_NUM_POSITIONS] =
{ "bottom", "top", "left", "right" };
-struct t_gui_bar *gui_bars = NULL; /* first bar */
-struct t_gui_bar *last_gui_bar = NULL; /* last bar */
+struct t_gui_bar *gui_bars = NULL; /* first bar */
+struct t_gui_bar *last_gui_bar = NULL; /* last bar */
+
+struct t_gui_bar *gui_temp_bars = NULL; /* bars used when reading config */
+struct t_gui_bar *last_gui_temp_bar = NULL;
/*
- * gui_bar_get_type: get type number with string
- * return -1 if type is not found
+ * gui_bar_search_option search a bar option name
+ * return index of option in array
+ * "gui_bar_option_str", or -1 if not found
*/
int
-gui_bar_get_type (char *type)
+gui_bar_search_option (char *option_name)
+{
+ int i;
+
+ if (!option_name)
+ return -1;
+
+ for (i = 0; i < GUI_BAR_NUM_OPTIONS; i++)
+ {
+ if (string_strcasecmp (gui_bar_option_str[i], option_name) == 0)
+ return i;
+ }
+
+ /* bar option not found */
+ return -1;
+}
+
+/*
+ * gui_bar_search_type: search type number with string
+ * return -1 if type is not found
+ */
+
+int
+gui_bar_search_type (char *type)
{
int i;
@@ -63,12 +95,12 @@ gui_bar_get_type (char *type)
}
/*
- * gui_bar_get_position: get position number with string
- * return -1 if type is not found
+ * gui_bar_search_position: search position number with string
+ * return -1 if type is not found
*/
int
-gui_bar_get_position (char *position)
+gui_bar_search_position (char *position)
{
int i;
@@ -98,11 +130,11 @@ gui_bar_root_get_size (struct t_gui_bar *bar, enum t_gui_bar_position position)
if (bar && (ptr_bar == bar))
return total_size;
- if ((ptr_bar->type == GUI_BAR_TYPE_ROOT)
- && (ptr_bar->position == position))
+ if ((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_ROOT)
+ && (CONFIG_INTEGER(ptr_bar->position) == (int)position))
{
total_size += ptr_bar->current_size;
- if (ptr_bar->separator)
+ if (CONFIG_INTEGER(ptr_bar->separator))
total_size++;
}
}
@@ -151,91 +183,34 @@ gui_bar_search_by_number (int number)
}
/*
- * gui_bar_new: create a new bar
+ * gui_bar_search_with_option_name: search a bar with name of option
+ * (like "uptime.type")
*/
struct t_gui_bar *
-gui_bar_new (struct t_weechat_plugin *plugin, char *name, char *type,
- char *position, int size, int separator, char *items)
+gui_bar_search_with_option_name (char *option_name)
{
- struct t_gui_bar *new_bar;
- struct t_gui_window *ptr_win;
- int type_value, position_value;
-
- if (!name || !name[0])
- return NULL;
-
- /* it's not possible to create 2 bars with same name */
- if (gui_bar_search (name))
- return NULL;
-
- /* look for type */
- type_value = gui_bar_get_type (type);
- if (type_value < 0)
- return NULL;
+ char *bar_name, *pos_option;
+ struct t_gui_bar *ptr_bar;
- /* look for position */
- position_value = gui_bar_get_position (position);
- if (position_value < 0)
- return NULL;
+ ptr_bar = NULL;
- /* create bar */
- new_bar = malloc (sizeof (*new_bar));
- if (new_bar)
+ pos_option = strchr (option_name, '.');
+ if (pos_option)
{
- new_bar->plugin = plugin;
- new_bar->number = (last_gui_bar) ? last_gui_bar->number + 1 : 1;
- new_bar->name = strdup (name);
- new_bar->type = type_value;
- new_bar->position = position_value;
- new_bar->size = size;
- new_bar->current_size = (size == 0) ? 1 : size;
- new_bar->separator = separator;
- if (items && items[0])
+ bar_name = string_strndup (option_name, pos_option - option_name);
+ if (bar_name)
{
- new_bar->items = strdup (items);
- new_bar->items_array = string_explode (items, ",", 0, 0,
- &new_bar->items_count);
- }
- else
- {
- new_bar->items = NULL;
- new_bar->items_count = 0;
- new_bar->items_array = NULL;
- }
- new_bar->bar_window = NULL;
-
- /* add bar to bars queue */
- new_bar->prev_bar = last_gui_bar;
- if (gui_bars)
- last_gui_bar->next_bar = new_bar;
- else
- gui_bars = new_bar;
- last_gui_bar = new_bar;
- new_bar->next_bar = NULL;
-
- /* add window bar */
- if (type_value == GUI_BAR_TYPE_ROOT)
- {
- /* create only one window for bar */
- gui_bar_window_new (new_bar, NULL);
- gui_window_refresh_needed = 1;
- }
- else
- {
- /* create bar window for all opened windows */
- for (ptr_win = gui_windows; ptr_win;
- ptr_win = ptr_win->next_window)
+ for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
{
- gui_bar_window_new (new_bar, ptr_win);
+ if (strcmp (ptr_bar->name, bar_name) == 0)
+ break;
}
+ free (bar_name);
}
-
- return new_bar;
}
- /* failed to create bar */
- return NULL;
+ return ptr_bar;
}
/*
@@ -247,7 +222,7 @@ gui_bar_refresh (struct t_gui_bar *bar)
{
struct t_gui_window *ptr_win;
- if (bar->type == GUI_BAR_TYPE_ROOT)
+ if (CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT)
gui_window_refresh_needed = 1;
else
{
@@ -260,18 +235,181 @@ gui_bar_refresh (struct t_gui_bar *bar)
}
/*
+ * gui_bar_config_check_type: callback for checking bar type before changing it
+ */
+
+int
+gui_bar_config_check_type (void *data, struct t_config_option *option,
+ char *value)
+{
+ /* make C compiler happy */
+ (void) data;
+ (void) option;
+ (void) value;
+
+ gui_chat_printf (NULL,
+ _("%sUnable to change bar type: you must delete bar "
+ "and create another to do that"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
+ return 0;
+}
+
+/*
+ * gui_bar_config_change_position: callback when position is changed
+ */
+
+void
+gui_bar_config_change_position (void *data, struct t_config_option *option)
+{
+ struct t_gui_bar *ptr_bar;
+
+ /* make C compiler happy */
+ (void) data;
+
+ ptr_bar = gui_bar_search_with_option_name (option->name);
+ if (ptr_bar)
+ gui_bar_refresh (ptr_bar);
+}
+
+/*
+ * gui_bar_config_check_size: callback for checking bar size before changing it
+ */
+
+int
+gui_bar_config_check_size (void *data, struct t_config_option *option,
+ char *value)
+{
+ struct t_gui_bar *ptr_bar;
+ long number;
+ char *error;
+
+ /* make C compiler happy */
+ (void) data;
+
+ ptr_bar = gui_bar_search_with_option_name (option->name);
+ if (ptr_bar)
+ {
+ error = NULL;
+ number = strtol (value, &error, 10);
+ if (error && !error[0])
+ {
+ if (number <= ptr_bar->current_size
+ || gui_bar_check_size_add (ptr_bar,
+ number - ptr_bar->current_size))
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+
+/*
+ * gui_bar_config_change_size: callback when size is changed
+ */
+
+void
+gui_bar_config_change_size (void *data, struct t_config_option *option)
+{
+ struct t_gui_bar *ptr_bar;
+
+ /* make C compiler happy */
+ (void) data;
+
+ ptr_bar = gui_bar_search_with_option_name (option->name);
+ if (ptr_bar)
+ {
+ ptr_bar->current_size = (CONFIG_INTEGER(ptr_bar->size) == 0) ?
+ 1 : CONFIG_INTEGER(ptr_bar->size);
+ gui_bar_refresh (ptr_bar);
+ }
+}
+
+/*
+ * gui_bar_config_change_separator: callback when separator is changed
+ */
+
+void
+gui_bar_config_change_separator (void *data, struct t_config_option *option)
+{
+ struct t_gui_bar *ptr_bar;
+
+ /* make C compiler happy */
+ (void) data;
+
+ ptr_bar = gui_bar_search_with_option_name (option->name);
+ if (ptr_bar)
+ gui_bar_refresh (ptr_bar);
+}
+
+/*
+ * gui_bar_config_change_items: callback when items is changed
+ */
+
+void
+gui_bar_config_change_items (void *data, struct t_config_option *option)
+{
+ struct t_gui_bar *ptr_bar;
+
+ /* make C compiler happy */
+ (void) data;
+
+ ptr_bar = gui_bar_search_with_option_name (option->name);
+ if (ptr_bar)
+ {
+ if (ptr_bar->items_array)
+ string_free_exploded (ptr_bar->items_array);
+
+ if (CONFIG_STRING(ptr_bar->items) && CONFIG_STRING(ptr_bar->items)[0])
+ {
+ ptr_bar->items_array = string_explode (CONFIG_STRING(ptr_bar->items),
+ ",", 0, 0,
+ &ptr_bar->items_count);
+ }
+ else
+ {
+ ptr_bar->items_count = 0;
+ ptr_bar->items_array = NULL;
+ }
+
+ gui_bar_draw (ptr_bar);
+ }
+}
+
+/*
* gui_bar_set_name: set name for a bar
*/
void
gui_bar_set_name (struct t_gui_bar *bar, char *name)
{
+ int length;
+ char *option_name;
+
if (!name || !name[0])
return;
-
- if (bar->name)
- free (bar->name);
- bar->name = strdup (name);
+
+ length = strlen (name) + 64;
+ option_name = malloc (length);
+ if (option_name)
+ {
+ snprintf (option_name, length, "%s.type", name);
+ config_file_option_rename (bar->type, option_name);
+ snprintf (option_name, length, "%s.position", name);
+ config_file_option_rename (bar->position, option_name);
+ snprintf (option_name, length, "%s.size", name);
+ config_file_option_rename (bar->size, option_name);
+ snprintf (option_name, length, "%s.separator", name);
+ config_file_option_rename (bar->separator, option_name);
+ snprintf (option_name, length, "%s.items", name);
+ config_file_option_rename (bar->items, option_name);
+
+ if (bar->name)
+ free (bar->name);
+ bar->name = strdup (name);
+
+ free (option_name);
+ }
}
/*
@@ -356,7 +494,7 @@ gui_bar_set_number (struct t_gui_bar *bar, int number)
{
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
{
- if (ptr_bar->type != GUI_BAR_TYPE_ROOT)
+ if (CONFIG_INTEGER(ptr_bar->type) != GUI_BAR_TYPE_ROOT)
gui_bar_window_new (ptr_bar, ptr_win);
}
}
@@ -374,10 +512,10 @@ gui_bar_set_position (struct t_gui_bar *bar, char *position)
if (!position || !position[0])
return;
- position_value = gui_bar_get_position (position);
- if ((position_value >= 0) && ((int)bar->position != position_value))
+ position_value = gui_bar_search_position (position);
+ if ((position_value >= 0) && (CONFIG_INTEGER(bar->position) != position_value))
{
- bar->position = position_value;
+ config_file_option_set (bar->position, position, 1);
}
}
@@ -407,18 +545,39 @@ gui_bar_set_current_size (struct t_gui_bar *bar, int current_size)
*/
void
-gui_bar_set_size (struct t_gui_bar *bar, int size)
+gui_bar_set_size (struct t_gui_bar *bar, char *size)
{
- if (size < 0)
- return;
-
- /* check if new size is ok if it's more than before */
- if (size > bar->current_size
- && !gui_bar_check_size_add (bar, size - bar->current_size))
- return;
+ long number;
+ char *error, value[32];
+ int new_size;
- bar->size = size;
- bar->current_size = (size == 0) ? 1 : size;
+ error = NULL;
+ number = strtol (((size[0] == '+') || (size[0] == '-')) ?
+ size + 1 : size,
+ &error,
+ 10);
+ if (error && !error[0])
+ {
+ new_size = number;
+ if (size[0] == '+')
+ new_size = bar->current_size + new_size;
+ else if (value[0] == '-')
+ new_size = bar->current_size - new_size;
+ if ((size[0] == '-') && (new_size < 1))
+ return;
+ if (new_size < 0)
+ return;
+
+ /* check if new size is ok if it's more than before */
+ if (new_size > bar->current_size
+ && !gui_bar_check_size_add (bar, new_size - bar->current_size))
+ return;
+
+ snprintf (value, sizeof (value), "%d", new_size);
+ config_file_option_set (bar->size, value, 1);
+
+ bar->current_size = (new_size == 0) ? 1 : new_size;
+ }
}
/*
@@ -428,20 +587,19 @@ gui_bar_set_size (struct t_gui_bar *bar, int size)
void
gui_bar_set_items (struct t_gui_bar *bar, char *items)
{
- if (bar->items)
- free (bar->items);
+ config_file_option_set (bar->items, items, 1);
+
if (bar->items_array)
string_free_exploded (bar->items_array);
- if (items && items[0])
+ if (CONFIG_STRING(bar->items) && CONFIG_STRING(bar->items)[0])
{
- bar->items = strdup (items);
- bar->items_array = string_explode (items, ",", 0, 0,
+ bar->items_array = string_explode (CONFIG_STRING(bar->items),
+ ",", 0, 0,
&bar->items_count);
}
else
{
- bar->items = NULL;
bar->items_count = 0;
bar->items_array = NULL;
}
@@ -456,7 +614,6 @@ gui_bar_set (struct t_gui_bar *bar, char *property, char *value)
{
long number;
char *error;
- int new_size;
if (!bar || !property || !value)
return;
@@ -482,27 +639,14 @@ gui_bar_set (struct t_gui_bar *bar, char *property, char *value)
}
else if (string_strcasecmp (property, "size") == 0)
{
- error = NULL;
- number = strtol (((value[0] == '+') || (value[0] == '-')) ?
- value + 1 : value,
- &error,
- 10);
- if (!error || error[0])
- return;
- if (value[0] == '+')
- new_size = bar->current_size + number;
- else if (value[0] == '-')
- new_size = bar->current_size - number;
- else
- new_size = number;
- if ((value[0] == '-') && (new_size < 1))
- return;
- gui_bar_set_size (bar, new_size);
+ gui_bar_set_size (bar, value);
gui_bar_refresh (bar);
}
else if (string_strcasecmp (property, "separator") == 0)
{
- bar->separator = (string_strcasecmp (value, "1") == 0) ? 1 : 0;
+ config_file_option_set (bar->separator,
+ (strcmp (value, "1") == 0) ? "on" : "off",
+ 1);
gui_bar_refresh (bar);
}
else if (string_strcasecmp (property, "items") == 0)
@@ -513,6 +657,308 @@ gui_bar_set (struct t_gui_bar *bar, char *property, char *value)
}
/*
+ * gui_bar_alloc: allocate and initialize new bar structure
+ */
+
+struct t_gui_bar *
+gui_bar_alloc (char *name)
+{
+ struct t_gui_bar *new_bar;
+
+ new_bar = malloc (sizeof (*new_bar));
+ if (new_bar)
+ {
+ new_bar->plugin = NULL;
+ new_bar->number = 0;
+ new_bar->name = strdup (name);
+ new_bar->type = NULL;
+ new_bar->position = NULL;
+ new_bar->size = NULL;
+ new_bar->separator = NULL;
+ new_bar->items = NULL;
+ new_bar->current_size = 1;
+ new_bar->items_count = 0;
+ new_bar->items_array = NULL;
+ new_bar->bar_window = NULL;
+ new_bar->prev_bar = NULL;
+ new_bar->next_bar = NULL;
+ }
+
+ return new_bar;
+}
+
+/*
+ * gui_bar_create_option: create an option for a bar
+ */
+
+struct t_config_option *
+gui_bar_create_option (char *bar_name, int index_option, char *value)
+{
+ struct t_config_option *ptr_option;
+ int length;
+ char *option_name;
+
+ ptr_option = NULL;
+
+ length = strlen (bar_name) + 1 + strlen (gui_bar_option_str[index_option]) + 1;
+ option_name = malloc (length);
+ if (option_name)
+ {
+ snprintf (option_name, length, "%s.%s",
+ bar_name, gui_bar_option_str[index_option]);
+
+ switch (index_option)
+ {
+ case GUI_BAR_OPTION_TYPE:
+ ptr_option = config_file_new_option (
+ weechat_config_file, weechat_config_section_bar,
+ option_name, "integer",
+ N_("bar type (root, window, window_active, window_inactive)"),
+ "root|window|window_active|window_inactive", 0, 0, value,
+ &gui_bar_config_check_type, NULL, NULL, NULL, NULL, NULL);
+ break;
+ case GUI_BAR_OPTION_POSITION:
+ ptr_option = config_file_new_option (
+ weechat_config_file, weechat_config_section_bar,
+ option_name, "integer",
+ N_("bar position (bottom, top, left, right)"),
+ "bottom|top|left|right", 0, 0, value,
+ NULL, NULL, &gui_bar_config_change_position, NULL, NULL, NULL);
+ break;
+ case GUI_BAR_OPTION_SIZE:
+ ptr_option = config_file_new_option (
+ weechat_config_file, weechat_config_section_bar,
+ option_name, "integer",
+ N_("bar size in chars (0 = auto size)"),
+ NULL, 0, INT_MAX, value,
+ &gui_bar_config_check_size, NULL,
+ &gui_bar_config_change_size, NULL,
+ NULL, NULL);
+ break;
+ case GUI_BAR_OPTION_SEPARATOR:
+ ptr_option = config_file_new_option (
+ weechat_config_file, weechat_config_section_bar,
+ option_name, "boolean",
+ N_("separator line between bar and other bars/windows"),
+ NULL, 0, 0, value,
+ NULL, NULL, &gui_bar_config_change_separator, NULL, NULL, NULL);
+ break;
+ case GUI_BAR_OPTION_ITEMS:
+ ptr_option = config_file_new_option (
+ weechat_config_file, weechat_config_section_bar,
+ option_name, "string",
+ N_("items of bar"),
+ NULL, 0, 0, value,
+ NULL, NULL, &gui_bar_config_change_items, NULL, NULL, NULL);
+ break;
+ case GUI_BAR_NUM_OPTIONS:
+ break;
+ }
+ }
+
+ return ptr_option;
+}
+
+/*
+ * gui_bar_new_with_options: create a new bar with options
+ */
+
+struct t_gui_bar *
+gui_bar_new_with_options (struct t_weechat_plugin *plugin, char *name,
+ struct t_config_option *type,
+ struct t_config_option *position,
+ struct t_config_option *size,
+ struct t_config_option *separator,
+ struct t_config_option *items)
+{
+ struct t_gui_bar *new_bar;
+ struct t_gui_window *ptr_win;
+
+ /* create bar */
+ new_bar = gui_bar_alloc (name);
+ if (new_bar)
+ {
+ new_bar->plugin = plugin;
+ new_bar->number = (last_gui_bar) ? last_gui_bar->number + 1 : 1;
+ new_bar->type = type;
+ new_bar->position = position;
+ new_bar->size = size;
+ new_bar->current_size = (CONFIG_INTEGER(size) == 0) ?
+ 1 : CONFIG_INTEGER(size);
+ new_bar->separator = separator;
+ new_bar->items = items;
+ if (CONFIG_STRING(items) && CONFIG_STRING(items)[0])
+ {
+ new_bar->items_array = string_explode (CONFIG_STRING(items),
+ ",", 0, 0,
+ &new_bar->items_count);
+ }
+ else
+ {
+ new_bar->items_count = 0;
+ new_bar->items_array = NULL;
+ }
+ new_bar->bar_window = NULL;
+
+ /* add bar to bars queue */
+ new_bar->prev_bar = last_gui_bar;
+ if (gui_bars)
+ last_gui_bar->next_bar = new_bar;
+ else
+ gui_bars = new_bar;
+ last_gui_bar = new_bar;
+ new_bar->next_bar = NULL;
+
+ /* add window bar */
+ if (CONFIG_INTEGER(new_bar->type) == GUI_BAR_TYPE_ROOT)
+ {
+ /* create only one window for bar */
+ gui_bar_window_new (new_bar, NULL);
+ gui_window_refresh_needed = 1;
+ }
+ else
+ {
+ /* create bar window for all opened windows */
+ for (ptr_win = gui_windows; ptr_win;
+ ptr_win = ptr_win->next_window)
+ {
+ gui_bar_window_new (new_bar, ptr_win);
+ }
+ }
+ }
+
+ return new_bar;
+}
+
+/*
+ * gui_bar_new: create a new bar
+ */
+
+struct t_gui_bar *
+gui_bar_new (struct t_weechat_plugin *plugin, char *name,
+ char *type, char *position, char *size, char *separators,
+ char *items)
+{
+ struct t_config_option *option_type, *option_position, *option_size;
+ struct t_config_option *option_separator, *option_items;
+ struct t_gui_bar *new_bar;
+
+ if (!name || !name[0])
+ return NULL;
+
+ /* it's not possible to create 2 bars with same name */
+ if (gui_bar_search (name))
+ return NULL;
+
+ /* look for type */
+ if (gui_bar_search_type (type) < 0)
+ return NULL;
+
+ /* look for position */
+ if (gui_bar_search_position (position) < 0)
+ return NULL;
+
+ option_type = gui_bar_create_option (name, GUI_BAR_OPTION_TYPE,
+ type);
+ option_position = gui_bar_create_option (name, GUI_BAR_OPTION_POSITION,
+ position);
+ option_size = gui_bar_create_option (name, GUI_BAR_OPTION_SIZE,
+ size);
+ option_separator = gui_bar_create_option (name, GUI_BAR_OPTION_SEPARATOR,
+ (config_file_string_to_boolean (separators)) ?
+ "on" : "off");
+ option_items = gui_bar_create_option (name, GUI_BAR_OPTION_ITEMS,
+ items);
+ new_bar = gui_bar_new_with_options (plugin, name, option_type,
+ option_position, option_size,
+ option_separator, option_items);
+ if (!new_bar)
+ {
+ if (option_type)
+ config_file_option_free (option_type);
+ if (option_position)
+ config_file_option_free (option_position);
+ if (option_size)
+ config_file_option_free (option_size);
+ if (option_separator)
+ config_file_option_free (option_separator);
+ if (option_items)
+ config_file_option_free (option_items);
+ }
+
+ return new_bar;
+}
+
+/*
+ * gui_bar_use_temp_bars: use temp bars (created by reading config file)
+ */
+
+void
+gui_bar_use_temp_bars ()
+{
+ struct t_gui_bar *ptr_temp_bar, *next_temp_bar;
+
+ for (ptr_temp_bar = gui_temp_bars; ptr_temp_bar;
+ ptr_temp_bar = ptr_temp_bar->next_bar)
+ {
+ log_printf ("use temp bar");
+ if (ptr_temp_bar->type && ptr_temp_bar->position
+ && ptr_temp_bar->size && ptr_temp_bar->separator
+ && ptr_temp_bar->items)
+ {
+ log_printf ("creation barre %s", ptr_temp_bar->name);
+ gui_bar_new_with_options (NULL, ptr_temp_bar->name,
+ ptr_temp_bar->type,
+ ptr_temp_bar->position,
+ ptr_temp_bar->size,
+ ptr_temp_bar->separator,
+ ptr_temp_bar->items);
+ }
+ else
+ {
+ if (ptr_temp_bar->type)
+ {
+ config_file_option_free (ptr_temp_bar->type);
+ ptr_temp_bar->type = NULL;
+ }
+ if (ptr_temp_bar->position)
+ {
+ config_file_option_free (ptr_temp_bar->position);
+ ptr_temp_bar->position = NULL;
+ }
+ if (ptr_temp_bar->size)
+ {
+ config_file_option_free (ptr_temp_bar->size);
+ ptr_temp_bar->size = NULL;
+ }
+ if (ptr_temp_bar->separator)
+ {
+ config_file_option_free (ptr_temp_bar->separator);
+ ptr_temp_bar->separator = NULL;
+ }
+ if (ptr_temp_bar->items)
+ {
+ config_file_option_free (ptr_temp_bar->items);
+ ptr_temp_bar->items = NULL;
+ }
+ }
+ }
+
+ /* free all temp bars */
+ while (gui_temp_bars)
+ {
+ next_temp_bar = gui_temp_bars->next_bar;
+
+ if (gui_temp_bars->name)
+ free (gui_temp_bars->name);
+ free (gui_temp_bars);
+
+ gui_temp_bars = next_temp_bar;
+ }
+ last_gui_temp_bar = NULL;
+}
+
+/*
* gui_bar_update: update a bar on screen
*/
@@ -557,8 +1003,16 @@ gui_bar_free (struct t_gui_bar *bar)
/* free data */
if (bar->name)
free (bar->name);
+ if (bar->type)
+ config_file_option_free (bar->type);
+ if (bar->position)
+ config_file_option_free (bar->position);
+ if (bar->size)
+ config_file_option_free (bar->size);
+ if (bar->separator)
+ config_file_option_free (bar->separator);
if (bar->items)
- free (bar->items);
+ config_file_option_free (bar->items);
if (bar->items_array)
string_free_exploded (bar->items_array);
@@ -616,15 +1070,15 @@ gui_bar_print_log ()
log_printf (" number . . . . . . . . : %d", ptr_bar->number);
log_printf (" name . . . . . . . . . : '%s'", ptr_bar->name);
log_printf (" type . . . . . . . . . : %d (%s)",
- ptr_bar->type,
- gui_bar_type_str[ptr_bar->type]);
+ CONFIG_INTEGER(ptr_bar->type),
+ gui_bar_type_str[CONFIG_INTEGER(ptr_bar->type)]);
log_printf (" position . . . . . . . : %d (%s)",
- ptr_bar->position,
- gui_bar_position_str[ptr_bar->position]);
- log_printf (" size . . . . . . . . . : %d", ptr_bar->size);
+ CONFIG_INTEGER(ptr_bar->position),
+ gui_bar_position_str[CONFIG_INTEGER(ptr_bar->position)]);
+ log_printf (" size . . . . . . . . . : %d", CONFIG_INTEGER(ptr_bar->size));
log_printf (" current_size . . . . . : %d", ptr_bar->current_size);
- log_printf (" separator. . . . . . . : %d", ptr_bar->separator);
- log_printf (" items. . . . . . . . . : '%s'", ptr_bar->items);
+ log_printf (" separator. . . . . . . : %d", CONFIG_INTEGER(ptr_bar->separator));
+ log_printf (" items. . . . . . . . . : '%s'", CONFIG_STRING(ptr_bar->items));
log_printf (" items_count. . . . . . : %d", ptr_bar->items_count);
log_printf (" items_array. . . . . . : 0x%x", ptr_bar->items_array);
log_printf (" bar_window . . . . . . : 0x%x", ptr_bar->bar_window);
diff --git a/src/gui/gui-bar.h b/src/gui/gui-bar.h
index d5b781e55..5397961c5 100644
--- a/src/gui/gui-bar.h
+++ b/src/gui/gui-bar.h
@@ -23,6 +23,17 @@
struct t_weechat_plugin;
struct t_gui_window;
+enum t_gui_bar_option
+{
+ GUI_BAR_OPTION_TYPE = 0,
+ GUI_BAR_OPTION_POSITION,
+ GUI_BAR_OPTION_SIZE,
+ GUI_BAR_OPTION_SEPARATOR,
+ GUI_BAR_OPTION_ITEMS,
+ /* number of bar types */
+ GUI_BAR_NUM_OPTIONS,
+};
+
enum t_gui_bar_type
{
GUI_BAR_TYPE_ROOT = 0,
@@ -49,11 +60,11 @@ struct t_gui_bar
struct t_weechat_plugin *plugin; /* plugin */
int number; /* bar number */
char *name; /* bar name */
- int type; /* type (root or window) */
- enum t_gui_bar_position position; /* bottom, top, left, right */
- int size; /* size of bar (in chars, 0 = auto) */
- int separator; /* 1 if separator (line) displayed */
- char *items; /* bar items */
+ struct t_config_option *type; /* type (root or window) */
+ struct t_config_option *position; /* bottom, top, left, right */
+ struct t_config_option *size; /* size of bar (in chars, 0 = auto) */
+ struct t_config_option *separator; /* true if separator line displayed */
+ struct t_config_option *items; /* bar items */
/* internal vars */
int current_size; /* current bar size (strictly > 0) */
@@ -71,19 +82,27 @@ extern char *gui_bar_type_str[];
extern char *gui_bar_position_str[];
extern struct t_gui_bar *gui_bars;
extern struct t_gui_bar *last_gui_bar;
+extern struct t_gui_bar *gui_temp_bars;
+extern struct t_gui_bar *last_gui_temp_bar;
/* functions */
-extern int gui_bar_get_type (char *type);
-extern int gui_bar_get_position (char *position);
+extern int gui_bar_search_option (char *option_name);
+extern int gui_bar_search_type (char *type);
+extern int gui_bar_search_position (char *position);
extern int gui_bar_root_get_size (struct t_gui_bar *bar,
enum t_gui_bar_position position);
extern struct t_gui_bar *gui_bar_search (char *name);
-extern struct t_gui_bar *gui_bar_new (struct t_weechat_plugin *plugin,
- char *name, char *type, char *position,
- int size, int separator, char *items);
extern void gui_bar_set_current_size (struct t_gui_bar *bar, int current_size);
extern void gui_bar_set (struct t_gui_bar *bar, char *property, char *value);
+extern struct t_gui_bar *gui_bar_alloc (char *name);
+extern struct t_config_option *gui_bar_create_option (char *bar_name,
+ int index_option,
+ char *value);
+extern struct t_gui_bar *gui_bar_new (struct t_weechat_plugin *plugin,
+ char *name, char *type, char *position,
+ char *size, char *separator, char *items);
+extern void gui_bar_use_temp_bars ();
extern void gui_bar_update (char *name);
extern void gui_bar_free (struct t_gui_bar *bar);
extern void gui_bar_free_all ();
diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c
index 3a9dd99a5..09b84f2f2 100644
--- a/src/gui/gui-window.c
+++ b/src/gui/gui-window.c
@@ -273,7 +273,7 @@ gui_window_new (struct t_gui_window *parent, int x, int y, int width, int height
/* create bar windows */
for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar)
{
- if (ptr_bar->type != GUI_BAR_TYPE_ROOT)
+ if (CONFIG_INTEGER(ptr_bar->type) != GUI_BAR_TYPE_ROOT)
gui_bar_window_new (ptr_bar, new_window);
}
}
diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c
index dba460a61..f035171c6 100644
--- a/src/plugins/alias/alias.c
+++ b/src/plugins/alias/alias.c
@@ -615,6 +615,7 @@ alias_config_init ()
return 0;
ptr_section = weechat_config_new_section (alias_config_file, "cmd",
+ 1, 1,
NULL, NULL,
NULL, NULL,
&alias_config_write_default, NULL,
@@ -775,7 +776,7 @@ unalias_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
alias_config_section_cmd,
alias_name);
if (ptr_option)
- weechat_config_option_free (alias_config_section_cmd, ptr_option);
+ weechat_config_option_free (ptr_option);
weechat_printf (NULL,
_("Alias \"%s\" removed"),
diff --git a/src/plugins/charset/charset.c b/src/plugins/charset/charset.c
index 4055d994b..fc67b889a 100644
--- a/src/plugins/charset/charset.c
+++ b/src/plugins/charset/charset.c
@@ -124,7 +124,7 @@ charset_config_create_option (void *data, struct t_config_file *config_file,
rc = weechat_config_option_set (ptr_option, value, 1);
else
{
- weechat_config_option_free (section, ptr_option);
+ weechat_config_option_free (ptr_option);
rc = 1;
}
}
@@ -170,6 +170,7 @@ charset_config_init ()
return 0;
ptr_section = weechat_config_new_section (charset_config_file, "default",
+ 0, 0,
NULL, NULL,
NULL, NULL,
NULL, NULL,
@@ -198,6 +199,7 @@ charset_config_init ()
NULL, NULL, NULL, NULL, NULL, NULL);
ptr_section = weechat_config_new_section (charset_config_file, "decode",
+ 1, 1,
NULL, NULL,
NULL, NULL,
NULL, NULL,
@@ -211,6 +213,7 @@ charset_config_init ()
charset_config_section_decode = ptr_section;
ptr_section = weechat_config_new_section (charset_config_file, "encode",
+ 1, 1,
NULL, NULL,
NULL, NULL,
NULL, NULL,
diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c
index 2d0904dd6..07b175fb1 100644
--- a/src/plugins/irc/irc-command.c
+++ b/src/plugins/irc/irc-command.c
@@ -2553,6 +2553,55 @@ irc_command_server (void *data, struct t_gui_buffer *buffer, int argc,
return WEECHAT_RC_OK;
}
+ if (weechat_strcasecmp (argv[1], "rename") == 0)
+ {
+ if (argc < 4)
+ {
+ IRC_COMMAND_TOO_FEW_ARGUMENTS(NULL, "server rename");
+ }
+
+ /* look for server by name */
+ server_found = irc_server_search (argv[2]);
+ if (!server_found)
+ {
+ weechat_printf (NULL,
+ _("%s%s: server \"%s\" not found for "
+ "\"%s\" command"),
+ weechat_prefix ("error"), "irc",
+ argv[2], "server rename");
+ return WEECHAT_RC_ERROR;
+ }
+
+ /* check if target name already exists */
+ if (irc_server_search (argv[3]))
+ {
+ weechat_printf (NULL,
+ _("%s%s: server \"%s\" already exists for "
+ "\"%s\" command"),
+ weechat_prefix ("error"), "irc",
+ argv[3], "server rename");
+ return WEECHAT_RC_ERROR;
+ }
+
+ /* rename server */
+ if (irc_server_rename (server_found, argv[3]))
+ {
+ weechat_printf (NULL,
+ _("%s: server %s%s%s has been renamed to "
+ "%s%s"),
+ "irc",
+ IRC_COLOR_CHAT_SERVER,
+ argv[2],
+ IRC_COLOR_CHAT,
+ IRC_COLOR_CHAT_SERVER,
+ argv[3]);
+ //gui_window_redraw_all_buffers ();
+ return WEECHAT_RC_OK;
+ }
+
+ return WEECHAT_RC_ERROR;
+ }
+
/* TODO: fix server command */
weechat_printf (NULL,
"%sSome server options are temporarirly disabled in "
@@ -2765,55 +2814,6 @@ irc_command_server (void *data, struct t_gui_buffer *buffer, int argc,
return WEECHAT_RC_ERROR;
}
- if (weechat_strcasecmp (argv[1], "rename") == 0)
- {
- if (argc < 4)
- {
- IRC_COMMAND_TOO_FEW_ARGUMENTS(NULL, "server rename");
- }
-
- /* look for server by name */
- server_found = irc_server_search (argv[2]);
- if (!server_found)
- {
- weechat_printf (NULL,
- _("%s%s: server \"%s\" not found for "
- "\"%s\" command"),
- weechat_prefix ("error"), "irc",
- argv[2], "server rename");
- return WEECHAT_RC_ERROR;
- }
-
- /* check if target name already exists */
- if (irc_server_search (argv[3]))
- {
- weechat_printf (NULL,
- _("%s%s: server \"%s\" already exists for "
- "\"%s\" command"),
- weechat_prefix ("error"), "irc",
- argv[3], "server rename");
- return WEECHAT_RC_ERROR;
- }
-
- /* rename server */
- if (irc_server_rename (server_found, argv[3]))
- {
- weechat_printf (NULL,
- _("%s: server %s%s%s has been renamed to "
- "%s%s"),
- "irc",
- IRC_COLOR_CHAT_SERVER,
- argv[2],
- IRC_COLOR_CHAT,
- IRC_COLOR_CHAT_SERVER,
- argv[3]);
- //gui_window_redraw_all_buffers ();
- return WEECHAT_RC_OK;
- }
-
- return WEECHAT_RC_ERROR;
- }
-
if (weechat_strcasecmp (argv[1], "keep") == 0)
{
if (argc < 3)
diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c
index 9062a8b60..6229fa7e2 100644
--- a/src/plugins/irc/irc-config.c
+++ b/src/plugins/irc/irc-config.c
@@ -859,6 +859,7 @@ irc_config_init ()
return 0;
ptr_section = weechat_config_new_section (irc_config_file, "look",
+ 0, 0,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL);
if (!ptr_section)
@@ -915,6 +916,7 @@ irc_config_init ()
NULL, 0, 0, "", NULL, NULL, NULL, NULL, NULL, NULL);
ptr_section = weechat_config_new_section (irc_config_file, "network",
+ 0, 0,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL);
if (!ptr_section)
@@ -989,6 +991,7 @@ irc_config_init ()
NULL, 0, 0, "off", NULL, NULL, NULL, NULL, NULL, NULL);
ptr_section = weechat_config_new_section (irc_config_file, "dcc",
+ 0, 0,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL);
if (!ptr_section)
@@ -1065,6 +1068,7 @@ irc_config_init ()
NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL);
ptr_section = weechat_config_new_section (irc_config_file, "log",
+ 0, 0,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL);
if (!ptr_section)
@@ -1095,6 +1099,7 @@ irc_config_init ()
NULL, 0, 0, "on", NULL, NULL, &irc_config_change_log, NULL, NULL, NULL);
ptr_section = weechat_config_new_section (irc_config_file, "server_default",
+ 0, 0,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL);
if (!ptr_section)
@@ -1108,6 +1113,7 @@ irc_config_init ()
irc_config_server_create_default_options (ptr_section);
ptr_section = weechat_config_new_section (irc_config_file, "server",
+ 1, 1,
NULL, NULL,
NULL, NULL,
&irc_config_server_write_default, NULL,
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index 7e1ccecb2..565ac5097 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -994,6 +994,7 @@ irc_server_rename (struct t_irc_server *server, char *new_name)
int length;
char *option_name, *name, *pos_option;
struct t_plugin_infolist *infolist;
+ struct t_config_option *ptr_option;
/* check if another server exists with this name */
if (irc_server_search (new_name))
@@ -1009,18 +1010,25 @@ irc_server_rename (struct t_irc_server *server, char *new_name)
free (option_name);
while (weechat_infolist_next (infolist))
{
- name = weechat_infolist_string (infolist, "name");
- pos_option = strchr (name, '.');
- if (pos_option)
+ weechat_config_search_with_string (weechat_infolist_string (infolist,
+ "full_name"),
+ NULL, NULL, &ptr_option,
+ NULL);
+ if (ptr_option)
{
- pos_option++;
- length = strlen (new_name) + 1 + strlen (pos_option) + 1;
- option_name = malloc (length);
- if (option_name)
+ name = weechat_infolist_string (infolist, "name");
+ pos_option = strchr (name, '.');
+ if (pos_option)
{
- snprintf (option_name, length, "%s.%s", new_name, pos_option);
- /* TODO: complete this function */
- free (option_name);
+ pos_option++;
+ length = strlen (new_name) + 1 + strlen (pos_option) + 1;
+ option_name = malloc (length);
+ if (option_name)
+ {
+ snprintf (option_name, length, "%s.%s", new_name, pos_option);
+ weechat_config_option_rename (ptr_option, option_name);
+ free (option_name);
+ }
}
}
}
diff --git a/src/plugins/plugin-config.c b/src/plugins/plugin-config.c
index 1a6b41f1b..73f562796 100644
--- a/src/plugins/plugin-config.c
+++ b/src/plugins/plugin-config.c
@@ -185,7 +185,7 @@ plugin_config_init ()
if (plugin_config_file)
{
plugin_config_section_var = config_file_new_section (
- plugin_config_file, "var",
+ plugin_config_file, "var", 0, 0,
NULL, NULL,
NULL, NULL,
NULL, NULL,
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index 2b00d72a4..1f827e8d5 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -327,10 +327,11 @@ plugin_load (char *filename)
new_plugin->config_search_option = &config_file_search_option;
new_plugin->config_search_section_option = &config_file_search_section_option;
new_plugin->config_search_with_string = &config_file_search_with_string;
+ new_plugin->config_string_to_boolean = &config_file_string_to_boolean;
new_plugin->config_option_reset = &config_file_option_reset;
new_plugin->config_option_set = &config_file_option_set;
+ new_plugin->config_option_rename = &config_file_option_rename;
new_plugin->config_option_get_pointer = &config_file_option_get_pointer;
- new_plugin->config_string_to_boolean = &config_file_string_to_boolean;
new_plugin->config_boolean = &config_file_option_boolean;
new_plugin->config_integer = &config_file_option_integer;
new_plugin->config_string = &config_file_option_string;
diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c
index ad38dc5b1..04a6eeb8e 100644
--- a/src/plugins/scripts/lua/weechat-lua-api.c
+++ b/src/plugins/scripts/lua/weechat-lua-api.c
@@ -1128,7 +1128,7 @@ weechat_lua_api_config_new_section (lua_State *L)
const char *config_file, *name, *function_read, *function_write;
const char *function_write_default, *function_create_option;
char *result;
- int n;
+ int n, user_can_add_options, user_can_delete_options;
/* make C compiler happy */
(void) L;
@@ -1141,6 +1141,8 @@ weechat_lua_api_config_new_section (lua_State *L)
config_file = NULL;
name = NULL;
+ user_can_add_options = 0;
+ user_can_delete_options = 0;
function_read = NULL;
function_write = NULL;
function_write_default = NULL;
@@ -1148,14 +1150,16 @@ weechat_lua_api_config_new_section (lua_State *L)
n = lua_gettop (lua_current_interpreter);
- if (n < 6)
+ if (n < 8)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_section");
LUA_RETURN_EMPTY;
}
- config_file = lua_tostring (lua_current_interpreter, -6);
- name = lua_tostring (lua_current_interpreter, -5);
+ config_file = lua_tostring (lua_current_interpreter, -8);
+ name = lua_tostring (lua_current_interpreter, -7);
+ user_can_add_options = lua_tonumber (lua_current_interpreter, -6);
+ user_can_delete_options = lua_tonumber (lua_current_interpreter, -5);
function_read = lua_tostring (lua_current_interpreter, -4);
function_write = lua_tostring (lua_current_interpreter, -3);
function_write_default = lua_tostring (lua_current_interpreter, -2);
@@ -1165,6 +1169,8 @@ weechat_lua_api_config_new_section (lua_State *L)
lua_current_script,
script_str2ptr ((char *)config_file),
(char *)name,
+ user_can_add_options,
+ user_can_delete_options,
&weechat_lua_api_config_read_cb,
(char *)function_read,
&weechat_lua_api_config_section_write_cb,
@@ -1392,6 +1398,45 @@ weechat_lua_api_config_string_to_boolean (lua_State *L)
}
/*
+ * weechat_lua_api_config_option_reset: reset option with default value
+ */
+
+static int
+weechat_lua_api_config_option_reset (lua_State *L)
+{
+ const char *option;
+ int n, run_callback, rc;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_reset");
+ LUA_RETURN_INT(0);
+ }
+
+ option = NULL;
+ run_callback = 0;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_reset");
+ LUA_RETURN_INT(0);
+ }
+
+ option = lua_tostring (lua_current_interpreter, -2);
+ run_callback = lua_tonumber (lua_current_interpreter, -1);
+
+ rc = weechat_config_option_reset (script_str2ptr ((char *)option),
+ run_callback);
+
+ LUA_RETURN_INT(rc);
+}
+
+/*
* weechat_lua_api_config_option_set: set new value for option
*/
@@ -1434,6 +1479,45 @@ weechat_lua_api_config_option_set (lua_State *L)
}
/*
+ * weechat_lua_api_config_option_rename: rename an option
+ */
+
+static int
+weechat_lua_api_config_option_rename (lua_State *L)
+{
+ const char *option, *new_name;
+ int n;
+
+ /* make C compiler happy */
+ (void) L;
+
+ if (!lua_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_rename");;
+ LUA_RETURN_ERROR;
+ }
+
+ option = NULL;
+ new_name = NULL;
+
+ n = lua_gettop (lua_current_interpreter);
+
+ if (n < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_rename");
+ LUA_RETURN_ERROR;
+ }
+
+ option = lua_tostring (lua_current_interpreter, -2);
+ new_name = lua_tostring (lua_current_interpreter, -1);
+
+ weechat_config_option_rename (script_str2ptr ((char *)option),
+ (char *)new_name);
+
+ LUA_RETURN_OK;
+}
+
+/*
* weechat_lua_api_config_boolean: return boolean value of option
*/
@@ -3794,9 +3878,9 @@ weechat_lua_api_bar_search (lua_State *L)
static int
weechat_lua_api_bar_new (lua_State *L)
{
- const char *name, *type, *position, *items;
+ const char *name, *type, *position, *items, *size, *separator;
char *result;
- int n, size, separator;
+ int n;
/* make C compiler happy */
(void) L;
@@ -3810,8 +3894,8 @@ weechat_lua_api_bar_new (lua_State *L)
name = NULL;
type = NULL;
position = NULL;
- size = 0;
- separator = 0;
+ size = NULL;
+ separator = NULL;
items = NULL;
n = lua_gettop (lua_current_interpreter);
@@ -3825,15 +3909,15 @@ weechat_lua_api_bar_new (lua_State *L)
name = lua_tostring (lua_current_interpreter, -6);
type = lua_tostring (lua_current_interpreter, -5);
position = lua_tostring (lua_current_interpreter, -4);
- size = lua_tonumber (lua_current_interpreter, -3);
- separator = lua_tonumber (lua_current_interpreter, -2);
+ size = lua_tostring (lua_current_interpreter, -3);
+ separator = lua_tostring (lua_current_interpreter, -2);
items = lua_tostring (lua_current_interpreter, -1);
result = script_ptr2str (weechat_bar_new ((char *)name,
(char *)type,
(char *)position,
- size,
- separator,
+ (char *)size,
+ (char *)separator,
(char *)items));
LUA_RETURN_STRING_FREE(result);
@@ -4533,7 +4617,9 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
{ "config_new_option", &weechat_lua_api_config_new_option },
{ "config_search_option", &weechat_lua_api_config_search_option },
{ "config_string_to_boolean", &weechat_lua_api_config_string_to_boolean },
+ { "config_option_reset", &weechat_lua_api_config_option_reset },
{ "config_option_set", &weechat_lua_api_config_option_set },
+ { "config_option_rename", &weechat_lua_api_config_option_rename },
{ "config_boolean", &weechat_lua_api_config_boolean },
{ "config_integer", &weechat_lua_api_config_integer },
{ "config_string", &weechat_lua_api_config_string },
diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c
index 3e52ef045..168d53bc7 100644
--- a/src/plugins/scripts/perl/weechat-perl-api.c
+++ b/src/plugins/scripts/perl/weechat-perl-api.c
@@ -964,7 +964,7 @@ static XS (XS_weechat_config_new_section)
PERL_RETURN_EMPTY;
}
- if (items < 6)
+ if (items < 8)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_section");
PERL_RETURN_EMPTY;
@@ -972,14 +972,16 @@ static XS (XS_weechat_config_new_section)
cfg_file = SvPV (ST (0), PL_na);
name = SvPV (ST (1), PL_na);
- function_read = SvPV (ST (2), PL_na);
- function_write = SvPV (ST (3), PL_na);
- function_write_default = SvPV (ST (4), PL_na);
- function_create_option = SvPV (ST (5), PL_na);
+ function_read = SvPV (ST (4), PL_na);
+ function_write = SvPV (ST (5), PL_na);
+ function_write_default = SvPV (ST (6), PL_na);
+ function_create_option = SvPV (ST (7), PL_na);
result = script_ptr2str (script_api_config_new_section (weechat_perl_plugin,
perl_current_script,
script_str2ptr (cfg_file),
name,
+ SvIV (ST (2)), /* user_can_add_options */
+ SvIV (ST (3)), /* user_can_delete_options */
&weechat_perl_api_config_section_read_cb,
function_read,
&weechat_perl_api_config_section_write_cb,
@@ -1165,6 +1167,38 @@ static XS (XS_weechat_config_string_to_boolean)
}
/*
+ * weechat::config_option_reset: reset an option with default value
+ */
+
+static XS (XS_weechat_config_option_reset)
+{
+ int rc;
+ char *option;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_reset");
+ PERL_RETURN_INT(0);
+ }
+
+ if (items < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_reset");
+ PERL_RETURN_INT(0);
+ }
+
+ option = SvPV (ST (0), PL_na);
+ rc = weechat_config_option_reset (script_str2ptr (option),
+ SvIV (ST (1))); /* run_callback */
+
+ PERL_RETURN_INT(rc);
+}
+
+/*
* weechat::config_option_set: set new value for option
*/
@@ -1199,6 +1233,38 @@ static XS (XS_weechat_config_option_set)
}
/*
+ * weechat::config_option_rename: rename an option
+ */
+
+static XS (XS_weechat_config_option_rename)
+{
+ char *option, *new_name;
+ dXSARGS;
+
+ /* make C compiler happy */
+ (void) cv;
+
+ if (!perl_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_rename");
+ PERL_RETURN_ERROR;
+ }
+
+ if (items < 2)
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_rename");
+ PERL_RETURN_ERROR;
+ }
+
+ option = SvPV (ST (0), PL_na);
+ new_name = SvPV (ST (1), PL_na);
+ weechat_config_option_rename (script_str2ptr (option),
+ new_name);
+
+ PERL_RETURN_OK;
+}
+
+/*
* weechat::config_boolean: return boolean value of option
*/
@@ -3153,7 +3219,7 @@ static XS (XS_weechat_bar_search)
static XS (XS_weechat_bar_new)
{
- char *result, *name, *type, *position, *bar_items;
+ char *result, *name, *type, *position, *size, *separator, *bar_items;
dXSARGS;
/* make C compiler happy */
@@ -3174,12 +3240,14 @@ static XS (XS_weechat_bar_new)
name = SvPV (ST (0), PL_na);
type = SvPV (ST (1), PL_na);
position = SvPV (ST (2), PL_na);
+ size = SvPV (ST (3), PL_na);
+ separator = SvPV (ST (4), PL_na);
bar_items = SvPV (ST (5), PL_na);
result = script_ptr2str (weechat_bar_new (name,
type,
position,
- SvIV (ST (3)), /* size */
- SvIV (ST (4)), /* separator */
+ size,
+ separator,
bar_items));
PERL_RETURN_STRING_FREE(result);
@@ -3651,7 +3719,9 @@ weechat_perl_api_init (pTHX)
newXS ("weechat::config_new_option", XS_weechat_config_new_option, "weechat");
newXS ("weechat::config_search_option", XS_weechat_config_search_option, "weechat");
newXS ("weechat::config_string_to_boolean", XS_weechat_config_string_to_boolean, "weechat");
+ newXS ("weechat::config_option_reset", XS_weechat_config_option_reset, "weechat");
newXS ("weechat::config_option_set", XS_weechat_config_option_set, "weechat");
+ newXS ("weechat::config_option_rename", XS_weechat_config_option_rename, "weechat");
newXS ("weechat::config_boolean", XS_weechat_config_boolean, "weechat");
newXS ("weechat::config_integer", XS_weechat_config_integer, "weechat");
newXS ("weechat::config_string", XS_weechat_config_string, "weechat");
diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c
index 5b7cfc8f7..a4829ce03 100644
--- a/src/plugins/scripts/python/weechat-python-api.c
+++ b/src/plugins/scripts/python/weechat-python-api.c
@@ -999,6 +999,7 @@ weechat_python_api_config_new_section (PyObject *self, PyObject *args)
char *config_file, *name, *function_read, *function_write;
char *function_write_default, *function_create_option;
char *result;
+ int user_can_add_options, user_can_delete_options;
PyObject *object;
/* make C compiler happy */
@@ -1012,12 +1013,15 @@ weechat_python_api_config_new_section (PyObject *self, PyObject *args)
config_file = NULL;
name = NULL;
+ user_can_add_options = 0;
+ user_can_delete_options = 0;
function_read = NULL;
function_write = NULL;
function_write_default = NULL;
function_create_option = NULL;
- if (!PyArg_ParseTuple (args, "ssssss", &config_file, &name,
+ if (!PyArg_ParseTuple (args, "ssiissss", &config_file, &name,
+ &user_can_add_options, &user_can_delete_options,
&function_read, &function_write,
&function_write_default, &function_create_option))
{
@@ -1029,6 +1033,8 @@ weechat_python_api_config_new_section (PyObject *self, PyObject *args)
python_current_script,
script_str2ptr (config_file),
name,
+ user_can_add_options,
+ user_can_delete_options,
&weechat_python_api_config_read_cb,
function_read,
&weechat_python_api_config_section_write_cb,
@@ -1226,6 +1232,40 @@ weechat_python_api_config_string_to_boolean (PyObject *self, PyObject *args)
}
/*
+ * weechat_python_api_config_option_reset: reset an option with default value
+ */
+
+static PyObject *
+weechat_python_api_config_option_reset (PyObject *self, PyObject *args)
+{
+ char *option;
+ int run_callback, rc;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_reset");
+ PYTHON_RETURN_INT(0);
+ }
+
+ option = NULL;
+ run_callback = 0;
+
+ if (!PyArg_ParseTuple (args, "si", &option, &run_callback))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_reset");
+ PYTHON_RETURN_INT(0);
+ }
+
+ rc = weechat_config_option_reset (script_str2ptr (option),
+ run_callback);
+
+ PYTHON_RETURN_INT(rc);
+}
+
+/*
* weechat_python_api_config_option_set: set new value for option
*/
@@ -1262,6 +1302,39 @@ weechat_python_api_config_option_set (PyObject *self, PyObject *args)
}
/*
+ * weechat_python_api_config_option_rename: rename an option
+ */
+
+static PyObject *
+weechat_python_api_config_option_rename (PyObject *self, PyObject *args)
+{
+ char *option, *new_name;
+
+ /* make C compiler happy */
+ (void) self;
+
+ if (!python_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_rename");
+ PYTHON_RETURN_ERROR;
+ }
+
+ option = NULL;
+ new_name = NULL;
+
+ if (!PyArg_ParseTuple (args, "ss", &option, &new_name))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_rename");
+ PYTHON_RETURN_ERROR;
+ }
+
+ weechat_config_option_rename (script_str2ptr (option),
+ new_name);
+
+ PYTHON_RETURN_OK;
+}
+
+/*
* weechat_python_api_config_boolean: return boolean value of option
*/
@@ -3353,8 +3426,7 @@ weechat_python_api_bar_search (PyObject *self, PyObject *args)
static PyObject *
weechat_python_api_bar_new (PyObject *self, PyObject *args)
{
- char *name, *type, *position, *items, *result;
- int size, separator;
+ char *name, *type, *position, *size, *separator, *items, *result;
PyObject *object;
/* make C compiler happy */
@@ -3369,11 +3441,11 @@ weechat_python_api_bar_new (PyObject *self, PyObject *args)
name = NULL;
type = NULL;
position = NULL;
- size = 0;
- separator = 0;
+ size = NULL;
+ separator = NULL;
items = NULL;
- if (!PyArg_ParseTuple (args, "sssiis", &name, &type, &position, &size,
+ if (!PyArg_ParseTuple (args, "ssssss", &name, &type, &position, &size,
&separator, &items))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_new");
@@ -3704,7 +3776,7 @@ weechat_python_api_infolist_integer (PyObject *self, PyObject *args)
infolist = NULL;
variable = NULL;
- if (!PyArg_ParseTuple (args, "s&", &infolist, &variable))
+ if (!PyArg_ParseTuple (args, "ss", &infolist, &variable))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("infolist_integer");
PYTHON_RETURN_INT(0);
@@ -3884,7 +3956,9 @@ PyMethodDef weechat_python_funcs[] =
{ "config_new_option", &weechat_python_api_config_new_option, METH_VARARGS, "" },
{ "config_search_option", &weechat_python_api_config_search_option, METH_VARARGS, "" },
{ "config_string_to_boolean", &weechat_python_api_config_string_to_boolean, METH_VARARGS, "" },
+ { "config_option_reset", &weechat_python_api_config_option_reset, METH_VARARGS, "" },
{ "config_option_set", &weechat_python_api_config_option_set, METH_VARARGS, "" },
+ { "config_option_rename", &weechat_python_api_config_option_rename, METH_VARARGS, "" },
{ "config_boolean", &weechat_python_api_config_boolean, METH_VARARGS, "" },
{ "config_integer", &weechat_python_api_config_integer, METH_VARARGS, "" },
{ "config_string", &weechat_python_api_config_string, METH_VARARGS, "" },
diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c
index b6f71f7ad..46ec71db0 100644
--- a/src/plugins/scripts/ruby/weechat-ruby-api.c
+++ b/src/plugins/scripts/ruby/weechat-ruby-api.c
@@ -1114,7 +1114,9 @@ weechat_ruby_api_config_section_create_option_cb (void *data,
static VALUE
weechat_ruby_api_config_new_section (VALUE class, VALUE config_file,
- VALUE name, VALUE function_read,
+ VALUE name, VALUE user_can_add_options,
+ VALUE user_can_delete_options,
+ VALUE function_read,
VALUE function_write,
VALUE function_write_default,
VALUE function_create_option)
@@ -1122,6 +1124,7 @@ weechat_ruby_api_config_new_section (VALUE class, VALUE config_file,
char *c_config_file, *c_name, *c_function_read, *c_function_write;
char *c_function_write_default, *c_function_create_option;
char *result;
+ int c_user_can_add_options, c_user_can_delete_options;
VALUE return_value;
/* make C compiler happy */
@@ -1135,12 +1138,15 @@ weechat_ruby_api_config_new_section (VALUE class, VALUE config_file,
c_config_file = NULL;
c_name = NULL;
+ c_user_can_add_options = 0;
+ c_user_can_delete_options = 0;
c_function_read = NULL;
c_function_write = NULL;
c_function_write_default = NULL;
c_function_create_option = NULL;
- if (NIL_P (config_file) || NIL_P (name) || NIL_P (function_read)
+ if (NIL_P (config_file) || NIL_P (name) || NIL_P (user_can_add_options)
+ || NIL_P (user_can_delete_options) || NIL_P (function_read)
|| NIL_P (function_write) || NIL_P (function_write_default)
|| NIL_P (function_create_option))
{
@@ -1150,6 +1156,8 @@ weechat_ruby_api_config_new_section (VALUE class, VALUE config_file,
Check_Type (config_file, T_STRING);
Check_Type (name, T_STRING);
+ Check_Type (user_can_add_options, T_FIXNUM);
+ Check_Type (user_can_delete_options, T_FIXNUM);
Check_Type (function_read, T_STRING);
Check_Type (function_write, T_STRING);
Check_Type (function_write_default, T_STRING);
@@ -1157,6 +1165,8 @@ weechat_ruby_api_config_new_section (VALUE class, VALUE config_file,
c_config_file = STR2CSTR (config_file);
c_name = STR2CSTR (name);
+ c_user_can_add_options = FIX2INT (user_can_add_options);
+ c_user_can_delete_options = FIX2INT (user_can_delete_options);
c_function_read = STR2CSTR (function_read);
c_function_write = STR2CSTR (function_write);
c_function_write_default = STR2CSTR (function_write_default);
@@ -1166,6 +1176,8 @@ weechat_ruby_api_config_new_section (VALUE class, VALUE config_file,
ruby_current_script,
script_str2ptr (c_config_file),
c_name,
+ c_user_can_add_options,
+ c_user_can_delete_options,
&weechat_ruby_api_config_read_cb,
c_function_read,
&weechat_ruby_api_config_section_write_cb,
@@ -1411,6 +1423,47 @@ weechat_ruby_api_config_string_to_boolean (VALUE class, VALUE text)
}
/*
+ * weechat_ruby_api_config_option_reset: reset option with default value
+ */
+
+static VALUE
+weechat_ruby_api_config_option_reset (VALUE class, VALUE option,
+ VALUE run_callback)
+{
+ char *c_option;
+ int c_run_callback, rc;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_reset");
+ RUBY_RETURN_INT(0);
+ }
+
+ c_option = NULL;
+ c_run_callback = 0;
+
+ if (NIL_P (option) || NIL_P (run_callback))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_reset");
+ RUBY_RETURN_INT(0);
+ }
+
+ Check_Type (option, T_STRING);
+ Check_Type (run_callback, T_FIXNUM);
+
+ c_option = STR2CSTR (option);
+ c_run_callback = FIX2INT (run_callback);
+
+ rc = weechat_config_option_reset (script_str2ptr (c_option),
+ c_run_callback);
+
+ RUBY_RETURN_INT(rc);
+}
+
+/*
* weechat_ruby_api_config_option_set: set new value for option
*/
@@ -1456,6 +1509,46 @@ weechat_ruby_api_config_option_set (VALUE class, VALUE option, VALUE new_value,
}
/*
+ * weechat_ruby_api_config_option_rename: rename an option
+ */
+
+static VALUE
+weechat_ruby_api_config_option_rename (VALUE class, VALUE option,
+ VALUE new_name)
+{
+ char *c_option, *c_new_name;
+
+ /* make C compiler happy */
+ (void) class;
+
+ if (!ruby_current_script)
+ {
+ WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("config_option_rename");
+ RUBY_RETURN_ERROR;
+ }
+
+ c_option = NULL;
+ c_new_name = NULL;
+
+ if (NIL_P (option) || NIL_P (new_name))
+ {
+ WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_option_rename");
+ RUBY_RETURN_ERROR;
+ }
+
+ Check_Type (option, T_STRING);
+ Check_Type (new_name, T_STRING);
+
+ c_option = STR2CSTR (option);
+ c_new_name = STR2CSTR (new_name);
+
+ weechat_config_option_rename (script_str2ptr (c_option),
+ c_new_name);
+
+ RUBY_RETURN_OK;
+}
+
+/*
* weechat_ruby_api_config_boolean: return boolean value of option
*/
@@ -3852,8 +3945,8 @@ static VALUE
weechat_ruby_api_bar_new (VALUE class, VALUE name, VALUE type, VALUE position,
VALUE size, VALUE separator, VALUE items)
{
- char *c_name, *c_type, *c_position, *c_items, *result;
- int c_size, c_separator;
+ char *c_name, *c_type, *c_position, *c_size, *c_separator, *c_items;
+ char *result;
VALUE return_value;
/* make C compiler happy */
@@ -3868,8 +3961,8 @@ weechat_ruby_api_bar_new (VALUE class, VALUE name, VALUE type, VALUE position,
c_name = NULL;
c_type = NULL;
c_position = NULL;
- c_size = 0;
- c_separator = 0;
+ c_size = NULL;
+ c_separator = NULL;
c_items = NULL;
if (NIL_P (name) || NIL_P (type) || NIL_P (position) || NIL_P (size)
@@ -3882,15 +3975,15 @@ weechat_ruby_api_bar_new (VALUE class, VALUE name, VALUE type, VALUE position,
Check_Type (name, T_STRING);
Check_Type (type, T_STRING);
Check_Type (position, T_STRING);
- Check_Type (size, T_FIXNUM);
- Check_Type (separator, T_FIXNUM);
+ Check_Type (size, T_STRING);
+ Check_Type (separator, T_STRING);
Check_Type (items, T_STRING);
c_name = STR2CSTR (name);
c_type = STR2CSTR (type);
c_position = STR2CSTR (position);
- c_size = FIX2INT (size);
- c_separator = FIX2INT (separator);
+ c_size = STR2CSTR (size);
+ c_separator = STR2CSTR (separator);
c_items = STR2CSTR (items);
result = script_ptr2str (weechat_bar_new (c_name,
@@ -4436,12 +4529,14 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "list_remove_all", &weechat_ruby_api_list_remove_all, 1);
rb_define_module_function (ruby_mWeechat, "list_free", &weechat_ruby_api_list_free, 1);
rb_define_module_function (ruby_mWeechat, "config_new", &weechat_ruby_api_config_new, 2);
- rb_define_module_function (ruby_mWeechat, "config_new_section", &weechat_ruby_api_config_new_section, 6);
+ rb_define_module_function (ruby_mWeechat, "config_new_section", &weechat_ruby_api_config_new_section, 8);
rb_define_module_function (ruby_mWeechat, "config_search_section", &weechat_ruby_api_config_search_section, 2);
rb_define_module_function (ruby_mWeechat, "config_new_option", &weechat_ruby_api_config_new_option, 10);
rb_define_module_function (ruby_mWeechat, "config_search_option", &weechat_ruby_api_config_search_option, 3);
rb_define_module_function (ruby_mWeechat, "config_string_to_boolean", &weechat_ruby_api_config_string_to_boolean, 1);
+ rb_define_module_function (ruby_mWeechat, "config_option_reset", &weechat_ruby_api_config_option_reset, 2);
rb_define_module_function (ruby_mWeechat, "config_option_set", &weechat_ruby_api_config_option_set, 3);
+ rb_define_module_function (ruby_mWeechat, "config_option_rename", &weechat_ruby_api_config_option_rename, 2);
rb_define_module_function (ruby_mWeechat, "config_boolean", &weechat_ruby_api_config_boolean, 1);
rb_define_module_function (ruby_mWeechat, "config_integer", &weechat_ruby_api_config_integer, 1);
rb_define_module_function (ruby_mWeechat, "config_string", &weechat_ruby_api_config_string, 1);
diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c
index ea9821918..be88a356b 100644
--- a/src/plugins/scripts/script-api.c
+++ b/src/plugins/scripts/script-api.c
@@ -98,6 +98,8 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_file *config_file,
char *name,
+ int user_can_add_options,
+ int user_can_delete_options,
void (*callback_read)(void *data,
struct t_config_file *config_file,
char *option_name,
@@ -202,6 +204,8 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
new_section = weechat_config_new_section (config_file,
name,
+ user_can_add_options,
+ user_can_delete_options,
callback1,
new_script_callback1,
callback2,
diff --git a/src/plugins/scripts/script-api.h b/src/plugins/scripts/script-api.h
index d27f23ee4..9ba42c049 100644
--- a/src/plugins/scripts/script-api.h
+++ b/src/plugins/scripts/script-api.h
@@ -31,6 +31,8 @@ extern struct t_config_section *script_api_config_new_section (struct t_weechat_
struct t_plugin_script *script,
struct t_config_file *config_file,
char *name,
+ int user_can_add_options,
+ int user_can_delete_options,
void (*callback_read)(void *data,
struct t_config_file *config_file,
char *option_name,
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index 0f50032a6..1206ef0f4 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -165,6 +165,8 @@ struct t_weechat_plugin
void *callback_reload_data);
struct t_config_section *(*config_new_section) (struct t_config_file *config_file,
char *name,
+ int user_can_add_options,
+ int user_can_delete_options,
int (*callback_read)(void *data,
struct t_config_file *config_file,
struct t_config_section *section,
@@ -222,6 +224,8 @@ struct t_weechat_plugin
int run_callback);
int (*config_option_set) (struct t_config_option *option, char *value,
int run_callback);
+ void (*config_option_rename) (struct t_config_option *option,
+ char *new_name);
void *(*config_option_get_pointer) (struct t_config_option *option,
char *property);
int (*config_boolean) (struct t_config_option *option);
@@ -233,8 +237,7 @@ struct t_weechat_plugin
int (*config_write) (struct t_config_file *config_file);
int (*config_read) (struct t_config_file *config_file);
int (*config_reload) (struct t_config_file *config_file);
- void (*config_option_free) (struct t_config_section *section,
- struct t_config_option *option);
+ void (*config_option_free) (struct t_config_option *option);
void (*config_section_free_options) (struct t_config_section *section);
void (*config_section_free) (struct t_config_file *config_file,
struct t_config_section *section);
@@ -373,8 +376,8 @@ struct t_weechat_plugin
void (*bar_item_remove) (struct t_gui_bar_item *item);
struct t_gui_bar *(*bar_search) (char *name);
struct t_gui_bar *(*bar_new) (struct t_weechat_plugin *plugin, char *name,
- char *type, char *position, int size,
- int separator, char *items);
+ char *type, char *position, char *size,
+ char *separator, char *items);
void (*bar_set) (struct t_gui_bar *bar, char *property, char *value);
void (*bar_update) (char *name);
void (*bar_remove) (struct t_gui_bar *bar);
@@ -544,12 +547,16 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
__callback_reload, \
__callback_reload_data)
#define weechat_config_new_section(__config, __name, \
+ __user_can_add_options, \
+ __user_can_delete_options, \
__cb_read, __cb_read_data, \
__cb_write_std, __cb_write_std_data, \
__cb_write_def, __cb_write_def_data, \
__cb_create_option, \
__cb_create_option_data) \
weechat_plugin->config_new_section(__config, __name, \
+ __user_can_add_options, \
+ __user_can_delete_options, \
__cb_read, __cb_read_data, \
__cb_write_std, \
__cb_write_std_data, \
@@ -592,9 +599,13 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
__pos_option);
#define weechat_config_string_to_boolean(__string) \
weechat_plugin->config_string_to_boolean(__string)
+#define weechat_config_option_reset(__option, __run_callback) \
+ weechat_plugin->config_option_reset(__option, __run_callback)
#define weechat_config_option_set(__option, __value, __run_callback) \
weechat_plugin->config_option_set(__option, __value, \
__run_callback)
+#define weechat_config_option_rename(__option, __new_name) \
+ weechat_plugin->config_option_rename(__option, __new_name)
#define weechat_config_option_get_pointer(__option, __property) \
weechat_plugin->config_option_get_pointer(__option, __property)
#define weechat_config_boolean(__option) \
@@ -615,8 +626,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
weechat_plugin->config_read(__config)
#define weechat_config_reload(__config) \
weechat_plugin->config_reload(__config)
-#define weechat_config_option_free(__section, __option) \
- weechat_plugin->config_option_free(__section, __option)
+#define weechat_config_option_free(__option) \
+ weechat_plugin->config_option_free(__option)
#define weechat_config_section_free_options(__section) \
weechat_plugin->config_section_free_options(__section)
#define weechat_config_section_free(__config, __section) \