summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2008-04-15 13:50:01 +0200
committerSebastien Helleu <flashcode@flashtux.org>2008-04-15 13:50:01 +0200
commitb87d709a7079e5c20b2d556158f57239c72095b7 (patch)
treee841adf778886b2a9930445e666584fe4b8e589c /src/core
parent362ce3eca8f354d59aa975ff3bf3d35bceaaf3e6 (diff)
downloadweechat-b87d709a7079e5c20b2d556158f57239c72095b7.zip
New format for [bar] section in weechat.conf file, bar options can be set with /set command
Diffstat (limited to 'src/core')
-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
5 files changed, 225 insertions, 91 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;