PageRenderTime 57ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/core/wee-config.c

#
C | 1925 lines | 1417 code | 247 blank | 261 comment | 161 complexity | 5a998593537af7767ebc0b1b3a945f50 MD5 | raw file
Possible License(s): GPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org>
  3. * Copyright (C) 2005-2006 Emmanuel Bouthenot <kolter@openics.org>
  4. *
  5. * This file is part of WeeChat, the extensible chat client.
  6. *
  7. * WeeChat is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * WeeChat is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /*
  21. * wee-config.c: WeeChat configuration options (file weechat.conf)
  22. */
  23. #ifdef HAVE_CONFIG_H
  24. #include "config.h"
  25. #endif
  26. #include <stdlib.h>
  27. #include <unistd.h>
  28. #include <errno.h>
  29. #include <stdio.h>
  30. #include <string.h>
  31. #include <limits.h>
  32. #include <time.h>
  33. #include <sys/types.h>
  34. #include <sys/stat.h>
  35. #include <regex.h>
  36. #include "weechat.h"
  37. #include "wee-config.h"
  38. #include "wee-hook.h"
  39. #include "wee-log.h"
  40. #include "wee-network.h"
  41. #include "wee-utf8.h"
  42. #include "wee-util.h"
  43. #include "wee-list.h"
  44. #include "wee-proxy.h"
  45. #include "wee-string.h"
  46. #include "../gui/gui-bar.h"
  47. #include "../gui/gui-buffer.h"
  48. #include "../gui/gui-chat.h"
  49. #include "../gui/gui-color.h"
  50. #include "../gui/gui-filter.h"
  51. #include "../gui/gui-hotlist.h"
  52. #include "../gui/gui-key.h"
  53. #include "../gui/gui-layout.h"
  54. #include "../gui/gui-line.h"
  55. #include "../gui/gui-main.h"
  56. #include "../gui/gui-mouse.h"
  57. #include "../gui/gui-nicklist.h"
  58. #include "../gui/gui-window.h"
  59. #include "../plugins/plugin.h"
  60. struct t_config_file *weechat_config_file = NULL;
  61. struct t_config_section *weechat_config_section_debug = NULL;
  62. struct t_config_section *weechat_config_section_color = NULL;
  63. struct t_config_section *weechat_config_section_proxy = NULL;
  64. struct t_config_section *weechat_config_section_bar = NULL;
  65. struct t_config_section *weechat_config_section_notify = NULL;
  66. /* config, startup section */
  67. struct t_config_option *config_startup_command_after_plugins;
  68. struct t_config_option *config_startup_command_before_plugins;
  69. struct t_config_option *config_startup_display_logo;
  70. struct t_config_option *config_startup_display_version;
  71. /* config, look & feel section */
  72. struct t_config_option *config_look_align_end_of_lines;
  73. struct t_config_option *config_look_bar_more_left;
  74. struct t_config_option *config_look_bar_more_right;
  75. struct t_config_option *config_look_bar_more_up;
  76. struct t_config_option *config_look_bar_more_down;
  77. struct t_config_option *config_look_buffer_notify_default;
  78. struct t_config_option *config_look_buffer_time_format;
  79. struct t_config_option *config_look_color_basic_force_bold;
  80. struct t_config_option *config_look_color_inactive_window;
  81. struct t_config_option *config_look_color_inactive_buffer;
  82. struct t_config_option *config_look_color_inactive_time;
  83. struct t_config_option *config_look_color_inactive_prefix_buffer;
  84. struct t_config_option *config_look_color_inactive_prefix;
  85. struct t_config_option *config_look_color_inactive_message;
  86. struct t_config_option *config_look_color_pairs_auto_reset;
  87. struct t_config_option *config_look_color_real_white;
  88. struct t_config_option *config_look_command_chars;
  89. struct t_config_option *config_look_confirm_quit;
  90. struct t_config_option *config_look_day_change;
  91. struct t_config_option *config_look_day_change_time_format;
  92. struct t_config_option *config_look_eat_newline_glitch;
  93. struct t_config_option *config_look_highlight;
  94. struct t_config_option *config_look_highlight_regex;
  95. struct t_config_option *config_look_highlight_tags;
  96. struct t_config_option *config_look_hotlist_add_buffer_if_away;
  97. struct t_config_option *config_look_hotlist_buffer_separator;
  98. struct t_config_option *config_look_hotlist_count_max;
  99. struct t_config_option *config_look_hotlist_count_min_msg;
  100. struct t_config_option *config_look_hotlist_names_count;
  101. struct t_config_option *config_look_hotlist_names_length;
  102. struct t_config_option *config_look_hotlist_names_level;
  103. struct t_config_option *config_look_hotlist_names_merged_buffers;
  104. struct t_config_option *config_look_hotlist_short_names;
  105. struct t_config_option *config_look_hotlist_sort;
  106. struct t_config_option *config_look_hotlist_unique_numbers;
  107. struct t_config_option *config_look_input_cursor_scroll;
  108. struct t_config_option *config_look_input_share;
  109. struct t_config_option *config_look_input_share_overwrite;
  110. struct t_config_option *config_look_input_undo_max;
  111. struct t_config_option *config_look_item_time_format;
  112. struct t_config_option *config_look_item_buffer_filter;
  113. struct t_config_option *config_look_jump_current_to_previous_buffer;
  114. struct t_config_option *config_look_jump_previous_buffer_when_closing;
  115. struct t_config_option *config_look_mouse;
  116. struct t_config_option *config_look_mouse_timer_delay;
  117. struct t_config_option *config_look_nickmode;
  118. struct t_config_option *config_look_nickmode_empty;
  119. struct t_config_option *config_look_paste_bracketed;
  120. struct t_config_option *config_look_paste_bracketed_timer_delay;
  121. struct t_config_option *config_look_paste_max_lines;
  122. struct t_config_option *config_look_prefix[GUI_CHAT_NUM_PREFIXES];
  123. struct t_config_option *config_look_prefix_align;
  124. struct t_config_option *config_look_prefix_align_max;
  125. struct t_config_option *config_look_prefix_align_min;
  126. struct t_config_option *config_look_prefix_align_more;
  127. struct t_config_option *config_look_prefix_buffer_align;
  128. struct t_config_option *config_look_prefix_buffer_align_max;
  129. struct t_config_option *config_look_prefix_buffer_align_more;
  130. struct t_config_option *config_look_prefix_same_nick;
  131. struct t_config_option *config_look_prefix_suffix;
  132. struct t_config_option *config_look_read_marker;
  133. struct t_config_option *config_look_read_marker_always_show;
  134. struct t_config_option *config_look_read_marker_string;
  135. struct t_config_option *config_look_save_config_on_exit;
  136. struct t_config_option *config_look_save_layout_on_exit;
  137. struct t_config_option *config_look_scroll_amount;
  138. struct t_config_option *config_look_scroll_bottom_after_switch;
  139. struct t_config_option *config_look_scroll_page_percent;
  140. struct t_config_option *config_look_search_text_not_found_alert;
  141. struct t_config_option *config_look_separator_horizontal;
  142. struct t_config_option *config_look_separator_vertical;
  143. struct t_config_option *config_look_set_title;
  144. struct t_config_option *config_look_time_format;
  145. /* config, colors section */
  146. struct t_config_option *config_color_separator;
  147. struct t_config_option *config_color_bar_more;
  148. struct t_config_option *config_color_chat;
  149. struct t_config_option *config_color_chat_bg;
  150. struct t_config_option *config_color_chat_inactive_window;
  151. struct t_config_option *config_color_chat_inactive_buffer;
  152. struct t_config_option *config_color_chat_time;
  153. struct t_config_option *config_color_chat_time_delimiters;
  154. struct t_config_option *config_color_chat_prefix_buffer;
  155. struct t_config_option *config_color_chat_prefix_buffer_inactive_buffer;
  156. struct t_config_option *config_color_chat_prefix[GUI_CHAT_NUM_PREFIXES];
  157. struct t_config_option *config_color_chat_prefix_more;
  158. struct t_config_option *config_color_chat_prefix_suffix;
  159. struct t_config_option *config_color_chat_buffer;
  160. struct t_config_option *config_color_chat_server;
  161. struct t_config_option *config_color_chat_channel;
  162. struct t_config_option *config_color_chat_nick;
  163. struct t_config_option *config_color_chat_nick_colors;
  164. struct t_config_option *config_color_chat_nick_self;
  165. struct t_config_option *config_color_chat_nick_other;
  166. struct t_config_option *config_color_chat_host;
  167. struct t_config_option *config_color_chat_delimiters;
  168. struct t_config_option *config_color_chat_highlight;
  169. struct t_config_option *config_color_chat_highlight_bg;
  170. struct t_config_option *config_color_chat_read_marker;
  171. struct t_config_option *config_color_chat_read_marker_bg;
  172. struct t_config_option *config_color_chat_tags;
  173. struct t_config_option *config_color_chat_text_found;
  174. struct t_config_option *config_color_chat_text_found_bg;
  175. struct t_config_option *config_color_chat_value;
  176. struct t_config_option *config_color_status_number;
  177. struct t_config_option *config_color_status_name;
  178. struct t_config_option *config_color_status_name_ssl;
  179. struct t_config_option *config_color_status_filter;
  180. struct t_config_option *config_color_status_data_msg;
  181. struct t_config_option *config_color_status_data_private;
  182. struct t_config_option *config_color_status_data_highlight;
  183. struct t_config_option *config_color_status_data_other;
  184. struct t_config_option *config_color_status_count_msg;
  185. struct t_config_option *config_color_status_count_private;
  186. struct t_config_option *config_color_status_count_highlight;
  187. struct t_config_option *config_color_status_count_other;
  188. struct t_config_option *config_color_status_more;
  189. struct t_config_option *config_color_status_time;
  190. struct t_config_option *config_color_input_text_not_found;
  191. struct t_config_option *config_color_input_actions;
  192. struct t_config_option *config_color_nicklist_group;
  193. struct t_config_option *config_color_nicklist_away;
  194. struct t_config_option *config_color_nicklist_offline;
  195. /* config, completion section */
  196. struct t_config_option *config_completion_base_word_until_cursor;
  197. struct t_config_option *config_completion_default_template;
  198. struct t_config_option *config_completion_nick_add_space;
  199. struct t_config_option *config_completion_nick_completer;
  200. struct t_config_option *config_completion_nick_first_only;
  201. struct t_config_option *config_completion_nick_ignore_chars;
  202. struct t_config_option *config_completion_partial_completion_alert;
  203. struct t_config_option *config_completion_partial_completion_command;
  204. struct t_config_option *config_completion_partial_completion_command_arg;
  205. struct t_config_option *config_completion_partial_completion_other;
  206. struct t_config_option *config_completion_partial_completion_count;
  207. /* config, history section */
  208. struct t_config_option *config_history_max_buffer_lines_number;
  209. struct t_config_option *config_history_max_buffer_lines_minutes;
  210. struct t_config_option *config_history_max_commands;
  211. struct t_config_option *config_history_max_visited_buffers;
  212. struct t_config_option *config_history_display_default;
  213. /* config, network section */
  214. struct t_config_option *config_network_connection_timeout;
  215. struct t_config_option *config_network_gnutls_ca_file;
  216. struct t_config_option *config_network_gnutls_handshake_timeout;
  217. /* config, plugin section */
  218. struct t_config_option *config_plugin_autoload;
  219. struct t_config_option *config_plugin_debug;
  220. struct t_config_option *config_plugin_extension;
  221. struct t_config_option *config_plugin_path;
  222. struct t_config_option *config_plugin_save_config_on_unload;
  223. /* other */
  224. int config_length_prefix_same_nick = 0;
  225. struct t_hook *config_day_change_timer = NULL;
  226. int config_day_change_old_day = -1;
  227. regex_t *config_highlight_regex = NULL;
  228. char **config_highlight_tags = NULL;
  229. int config_num_highlight_tags = 0;
  230. char **config_plugin_extensions = NULL;
  231. int config_num_plugin_extensions = 0;
  232. /*
  233. * config_change_save_config_on_exit: called when "save_config_on_exit" flag is changed
  234. */
  235. void
  236. config_change_save_config_on_exit (void *data, struct t_config_option *option)
  237. {
  238. /* make C compiler happy */
  239. (void) data;
  240. (void) option;
  241. if (gui_init_ok && !CONFIG_BOOLEAN(config_look_save_config_on_exit))
  242. {
  243. gui_chat_printf (NULL,
  244. _("Warning: you should now issue /save to write "
  245. "\"save_config_on_exit\" option in configuration "
  246. "file"));
  247. }
  248. }
  249. /*
  250. * config_change_title: called when title is changed
  251. */
  252. void
  253. config_change_title (void *data, struct t_config_option *option)
  254. {
  255. /* make C compiler happy */
  256. (void) data;
  257. (void) option;
  258. if (CONFIG_BOOLEAN(config_look_set_title))
  259. gui_window_set_title (PACKAGE_NAME " " PACKAGE_VERSION);
  260. }
  261. /*
  262. * config_change_buffers: called when buffers change (for example nicklist)
  263. */
  264. void
  265. config_change_buffers (void *data, struct t_config_option *option)
  266. {
  267. /* make C compiler happy */
  268. (void) data;
  269. (void) option;
  270. gui_window_ask_refresh (1);
  271. }
  272. /*
  273. * config_change_buffer_content: called when content of a buffer changes
  274. */
  275. void
  276. config_change_buffer_content (void *data, struct t_config_option *option)
  277. {
  278. /* make C compiler happy */
  279. (void) data;
  280. (void) option;
  281. if (gui_init_ok)
  282. gui_current_window->refresh_needed = 1;
  283. }
  284. /*
  285. * config_change_mouse: called when mouse state is changed
  286. */
  287. void
  288. config_change_mouse (void *data, struct t_config_option *option)
  289. {
  290. /* make C compiler happy */
  291. (void) data;
  292. (void) option;
  293. if (gui_init_ok)
  294. {
  295. if (CONFIG_BOOLEAN(config_look_mouse))
  296. gui_mouse_enable ();
  297. else
  298. gui_mouse_disable ();
  299. }
  300. }
  301. /*
  302. * config_change_buffer_notify_default: called when buffer default notify changes
  303. */
  304. void
  305. config_change_buffer_notify_default (void *data, struct t_config_option *option)
  306. {
  307. /* make C compiler happy */
  308. (void) data;
  309. (void) option;
  310. gui_buffer_notify_set_all ();
  311. }
  312. /*
  313. * config_change_buffer_time_format: called when buffer time format changes
  314. */
  315. void
  316. config_change_buffer_time_format (void *data, struct t_config_option *option)
  317. {
  318. /* make C compiler happy */
  319. (void) data;
  320. (void) option;
  321. gui_chat_time_length = gui_chat_get_time_length ();
  322. gui_chat_change_time_format ();
  323. if (gui_init_ok)
  324. gui_window_ask_refresh (1);
  325. }
  326. /*
  327. * config_compute_prefix_max_length_all_buffers: compute the "prefix_max_length"
  328. * on all buffers
  329. */
  330. void
  331. config_compute_prefix_max_length_all_buffers ()
  332. {
  333. struct t_gui_buffer *ptr_buffer;
  334. for (ptr_buffer = gui_buffers; ptr_buffer;
  335. ptr_buffer = ptr_buffer->next_buffer)
  336. {
  337. if (ptr_buffer->own_lines)
  338. gui_line_compute_prefix_max_length (ptr_buffer->own_lines);
  339. if (ptr_buffer->mixed_lines)
  340. gui_line_compute_prefix_max_length (ptr_buffer->mixed_lines);
  341. }
  342. }
  343. /*
  344. * config_change_prefix_same_nick: called when "prefix for same nick" changes
  345. */
  346. void
  347. config_change_prefix_same_nick (void *data, struct t_config_option *option)
  348. {
  349. /* make C compiler happy */
  350. (void) data;
  351. (void) option;
  352. config_length_prefix_same_nick =
  353. gui_chat_strlen_screen (CONFIG_STRING(config_look_prefix_same_nick));
  354. config_compute_prefix_max_length_all_buffers ();
  355. gui_window_ask_refresh (1);
  356. }
  357. /*
  358. * config_change_eat_newline_glitch: called when eat_newline_glitch changes
  359. */
  360. void
  361. config_change_eat_newline_glitch (void *data, struct t_config_option *option)
  362. {
  363. /* make C compiler happy */
  364. (void) data;
  365. (void) option;
  366. if (gui_init_ok)
  367. {
  368. if (CONFIG_BOOLEAN(config_look_eat_newline_glitch))
  369. {
  370. gui_chat_printf (NULL,
  371. _("WARNING: this option can cause serious display "
  372. "bugs, if you have such problems, you must "
  373. "turn off this option."));
  374. gui_term_set_eat_newline_glitch (0);
  375. }
  376. else
  377. gui_term_set_eat_newline_glitch (1);
  378. }
  379. }
  380. /*
  381. * config_change_highlight_regex: called when highlight_regex changes
  382. */
  383. void
  384. config_change_highlight_regex (void *data, struct t_config_option *option)
  385. {
  386. /* make C compiler happy */
  387. (void) data;
  388. (void) option;
  389. if (config_highlight_regex)
  390. {
  391. regfree (config_highlight_regex);
  392. free (config_highlight_regex);
  393. config_highlight_regex = NULL;
  394. }
  395. if (CONFIG_STRING(config_look_highlight_regex)
  396. && CONFIG_STRING(config_look_highlight_regex)[0])
  397. {
  398. config_highlight_regex = malloc (sizeof (*config_highlight_regex));
  399. if (config_highlight_regex)
  400. {
  401. if (string_regcomp (config_highlight_regex,
  402. CONFIG_STRING(config_look_highlight_regex),
  403. REG_EXTENDED | REG_ICASE) != 0)
  404. {
  405. free (config_highlight_regex);
  406. config_highlight_regex = NULL;
  407. }
  408. }
  409. }
  410. }
  411. /*
  412. * config_change_highlight_tags: called when highlight_tags changes
  413. */
  414. void
  415. config_change_highlight_tags (void *data, struct t_config_option *option)
  416. {
  417. /* make C compiler happy */
  418. (void) data;
  419. (void) option;
  420. if (config_highlight_tags)
  421. {
  422. string_free_split (config_highlight_tags);
  423. config_highlight_tags = NULL;
  424. }
  425. config_num_highlight_tags = 0;
  426. if (CONFIG_STRING(config_look_highlight_tags)
  427. && CONFIG_STRING(config_look_highlight_tags)[0])
  428. {
  429. config_highlight_tags = string_split (CONFIG_STRING(config_look_highlight_tags),
  430. ",", 0, 0, &config_num_highlight_tags);
  431. }
  432. }
  433. /*
  434. * config_change_hotlist: called when hotlist changes
  435. */
  436. void
  437. config_change_hotlist (void *data, struct t_config_option *option)
  438. {
  439. /* make C compiler happy */
  440. (void) data;
  441. (void) option;
  442. gui_hotlist_resort ();
  443. }
  444. /*
  445. * config_change_paste_bracketed: called when bracketed paste mode is changed
  446. */
  447. void
  448. config_change_paste_bracketed (void *data, struct t_config_option *option)
  449. {
  450. /* make C compiler happy */
  451. (void) data;
  452. (void) option;
  453. if (gui_init_ok)
  454. gui_window_set_bracketed_paste_mode (CONFIG_BOOLEAN(config_look_paste_bracketed));
  455. }
  456. /*
  457. * config_change_read_marker: called when read marker is changed
  458. */
  459. void
  460. config_change_read_marker (void *data, struct t_config_option *option)
  461. {
  462. /* make C compiler happy */
  463. (void) data;
  464. (void) option;
  465. gui_window_ask_refresh (1);
  466. }
  467. /*
  468. * config_change_prefix: called when a prefix is changed
  469. */
  470. void
  471. config_change_prefix (void *data, struct t_config_option *option)
  472. {
  473. /* make C compiler happy */
  474. (void) data;
  475. (void) option;
  476. gui_chat_prefix_build ();
  477. }
  478. /*
  479. * config_change_prefix_align_min: called when prefix_align_min is changed
  480. */
  481. void
  482. config_change_prefix_align_min (void *data, struct t_config_option *option)
  483. {
  484. /* make C compiler happy */
  485. (void) data;
  486. (void) option;
  487. config_compute_prefix_max_length_all_buffers ();
  488. gui_window_ask_refresh (1);
  489. }
  490. /*
  491. * config_check_prefix_align_more: check string "prefix align more" (must be
  492. * max one char wide on screen)
  493. */
  494. int
  495. config_check_prefix_align_more (void *data, struct t_config_option *option,
  496. const char *value)
  497. {
  498. /* make C compiler happy */
  499. (void) data;
  500. (void) option;
  501. return (utf8_strlen_screen (value) == 1) ? 1 : 0;
  502. }
  503. /*
  504. * config_check_prefix_buffer_align_more: check string "prefix buffer align more"
  505. * (must be max one char wide on screen)
  506. */
  507. int
  508. config_check_prefix_buffer_align_more (void *data,
  509. struct t_config_option *option,
  510. const char *value)
  511. {
  512. /* make C compiler happy */
  513. (void) data;
  514. (void) option;
  515. return (utf8_strlen_screen (value) == 1) ? 1 : 0;
  516. }
  517. /*
  518. * config_change_color: called when a color is changed by /set command
  519. */
  520. void
  521. config_change_color (void *data, struct t_config_option *option)
  522. {
  523. /* make C compiler happy */
  524. (void) data;
  525. (void) option;
  526. if (gui_init_ok)
  527. {
  528. gui_color_init_weechat ();
  529. gui_window_ask_refresh (1);
  530. }
  531. }
  532. /*
  533. * config_change_nick_colors: called when nick colors are changed
  534. */
  535. void
  536. config_change_nick_colors (void *data, struct t_config_option *option)
  537. {
  538. /* make C compiler happy */
  539. (void) data;
  540. (void) option;
  541. gui_color_buffer_display ();
  542. }
  543. /*
  544. * config_change_network_gnutls_ca_file: called when gnutls_ca_file is changed
  545. */
  546. void
  547. config_change_network_gnutls_ca_file (void *data,
  548. struct t_config_option *option)
  549. {
  550. /* make C compiler happy */
  551. (void) data;
  552. (void) option;
  553. if (network_init_ok)
  554. network_set_gnutls_ca_file ();
  555. }
  556. /*
  557. * config_change_plugin_extension: called when plugin extension is changed
  558. */
  559. void
  560. config_change_plugin_extension (void *data, struct t_config_option *option)
  561. {
  562. /* make C compiler happy */
  563. (void) data;
  564. (void) option;
  565. if (config_plugin_extensions)
  566. {
  567. string_free_split (config_plugin_extensions);
  568. config_plugin_extensions = NULL;
  569. }
  570. config_num_plugin_extensions = 0;
  571. if (CONFIG_STRING(config_plugin_extension)
  572. && CONFIG_STRING(config_plugin_extension)[0])
  573. {
  574. config_plugin_extensions = string_split (CONFIG_STRING(config_plugin_extension),
  575. ",", 0, 0, &config_num_plugin_extensions);
  576. }
  577. }
  578. /*
  579. * config_day_change_timer_cb: timer callback for displaying
  580. * "Day changed to xxx" message
  581. */
  582. int
  583. config_day_change_timer_cb (void *data, int remaining_calls)
  584. {
  585. struct timeval tv_time;
  586. struct tm *local_time;
  587. int new_mday;
  588. char text_time[256], *text_time2;
  589. struct t_gui_buffer *ptr_buffer;
  590. /* make C compiler happy */
  591. (void) data;
  592. (void) remaining_calls;
  593. gettimeofday (&tv_time, NULL);
  594. local_time = localtime (&tv_time.tv_sec);
  595. new_mday = local_time->tm_mday;
  596. if ((config_day_change_old_day >= 0)
  597. && (new_mday != config_day_change_old_day))
  598. {
  599. if (CONFIG_BOOLEAN(config_look_day_change))
  600. {
  601. strftime (text_time, sizeof (text_time),
  602. CONFIG_STRING(config_look_day_change_time_format),
  603. local_time);
  604. text_time2 = string_iconv_to_internal (NULL, text_time);
  605. gui_add_hotlist = 0;
  606. for (ptr_buffer = gui_buffers; ptr_buffer;
  607. ptr_buffer = ptr_buffer->next_buffer)
  608. {
  609. if (ptr_buffer->type == GUI_BUFFER_TYPE_FORMATTED)
  610. {
  611. gui_chat_printf (ptr_buffer,
  612. _("\t\tDay changed to %s"),
  613. (text_time2) ?
  614. text_time2 : text_time);
  615. }
  616. }
  617. if (text_time2)
  618. free (text_time2);
  619. gui_add_hotlist = 1;
  620. }
  621. /* send signal "day_changed" */
  622. strftime (text_time, sizeof (text_time), "%Y-%m-%d", local_time);
  623. hook_signal_send ("day_changed", WEECHAT_HOOK_SIGNAL_STRING, text_time);
  624. }
  625. config_day_change_old_day = new_mday;
  626. return WEECHAT_RC_OK;
  627. }
  628. /*
  629. * config_weechat_init_after_read: initialize some things after reading (or
  630. * reloading) configuration file
  631. */
  632. void
  633. config_weechat_init_after_read ()
  634. {
  635. int i;
  636. gui_buffer_notify_set_all ();
  637. proxy_use_temp_proxies ();
  638. gui_bar_use_temp_bars ();
  639. if (gui_bars)
  640. {
  641. /*
  642. * at least one bar defined => just ensure that at least one bar is
  643. * using item "input_text"
  644. */
  645. gui_bar_create_default_input ();
  646. }
  647. else
  648. {
  649. /* no bar defined => create default bars */
  650. gui_bar_create_default ();
  651. }
  652. /* if no key was found config file, then we use default bindings */
  653. for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
  654. {
  655. if (!gui_keys[i])
  656. gui_key_default_bindings (i);
  657. }
  658. /* apply filters on all buffers */
  659. gui_filter_all_buffers ();
  660. }
  661. /*
  662. * config_weechat_reload_cb: reload WeeChat configuration file
  663. * return one of these values:
  664. * WEECHAT_CONFIG_READ_OK
  665. * WEECHAT_CONFIG_READ_MEMORY_ERROR
  666. * WEECHAT_CONFIG_READ_FILE_NOT_FOUND
  667. */
  668. int
  669. config_weechat_reload_cb (void *data, struct t_config_file *config_file)
  670. {
  671. int i, rc;
  672. /* make C compiler happy */
  673. (void) data;
  674. /* remove all keys */
  675. for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
  676. {
  677. gui_key_free_all (&gui_keys[i], &last_gui_key[i],
  678. &gui_keys_count[i]);
  679. }
  680. /* remove all proxies */
  681. proxy_free_all ();
  682. /* remove all bars */
  683. gui_bar_free_all ();
  684. /* remove layout */
  685. gui_layout_buffer_reset (&gui_layout_buffers, &last_gui_layout_buffer);
  686. gui_layout_window_reset (&gui_layout_windows);
  687. /* remove all notify levels */
  688. config_file_section_free_options (weechat_config_section_notify);
  689. /* remove all filters */
  690. gui_filter_free_all ();
  691. rc = config_file_reload (config_file);
  692. config_weechat_init_after_read ();
  693. return rc;
  694. }
  695. /*
  696. * config_weechat_debug_get: get debug level for a plugin (or "core")
  697. */
  698. struct t_config_option *
  699. config_weechat_debug_get (const char *plugin_name)
  700. {
  701. return config_file_search_option (weechat_config_file,
  702. weechat_config_section_debug,
  703. plugin_name);
  704. }
  705. /*
  706. * config_weechat_debug_set_all: set debug for "core" and all plugins, using
  707. * values from [debug] section
  708. */
  709. void
  710. config_weechat_debug_set_all ()
  711. {
  712. struct t_config_option *ptr_option;
  713. struct t_weechat_plugin *ptr_plugin;
  714. /* set debug for core */
  715. ptr_option = config_weechat_debug_get (PLUGIN_CORE);
  716. weechat_debug_core = (ptr_option) ? CONFIG_INTEGER(ptr_option) : 0;
  717. /* set debug for plugins */
  718. for (ptr_plugin = weechat_plugins; ptr_plugin;
  719. ptr_plugin = ptr_plugin->next_plugin)
  720. {
  721. ptr_option = config_weechat_debug_get (ptr_plugin->name);
  722. ptr_plugin->debug = (ptr_option) ? CONFIG_INTEGER(ptr_option) : 0;
  723. }
  724. }
  725. /*
  726. * config_weechat_debug_change_cb: called when a debug option is changed
  727. */
  728. void
  729. config_weechat_debug_change_cb (void *data,
  730. struct t_config_option *option)
  731. {
  732. /* make C compiler happy */
  733. (void) data;
  734. (void) option;
  735. config_weechat_debug_set_all ();
  736. }
  737. /*
  738. * config_weechat_debug_create_option_cb: create option in "debug" section
  739. */
  740. int
  741. config_weechat_debug_create_option_cb (void *data,
  742. struct t_config_file *config_file,
  743. struct t_config_section *section,
  744. const char *option_name,
  745. const char *value)
  746. {
  747. struct t_config_option *ptr_option;
  748. int rc;
  749. /* make C compiler happy */
  750. (void) data;
  751. rc = WEECHAT_CONFIG_OPTION_SET_ERROR;
  752. if (option_name)
  753. {
  754. ptr_option = config_file_search_option (config_file, section,
  755. option_name);
  756. if (ptr_option)
  757. {
  758. if (value && value[0])
  759. rc = config_file_option_set (ptr_option, value, 1);
  760. else
  761. {
  762. config_file_option_free (ptr_option);
  763. rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
  764. }
  765. }
  766. else
  767. {
  768. if (value && value[0])
  769. {
  770. ptr_option = config_file_new_option (
  771. config_file, section,
  772. option_name, "integer",
  773. _("debug level for plugin (\"core\" for WeeChat core)"),
  774. NULL, 0, 32, "0", value, 0, NULL, NULL,
  775. &config_weechat_debug_change_cb, NULL,
  776. NULL, NULL);
  777. rc = (ptr_option) ?
  778. WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR;
  779. }
  780. else
  781. rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
  782. }
  783. }
  784. /* set debug level for "core" and all plugins */
  785. config_weechat_debug_set_all ();
  786. return rc;
  787. }
  788. /*
  789. * config_weechat_debug_delete_option_cb: delete option in "debug" section
  790. */
  791. int
  792. config_weechat_debug_delete_option_cb (void *data,
  793. struct t_config_file *config_file,
  794. struct t_config_section *section,
  795. struct t_config_option *option)
  796. {
  797. /* make C compiler happy */
  798. (void) data;
  799. (void) config_file;
  800. (void) section;
  801. config_file_option_free (option);
  802. config_weechat_debug_set_all ();
  803. return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED;
  804. }
  805. /*
  806. * config_weechat_debug_set: set debug level for a plugin (or "core")
  807. */
  808. int
  809. config_weechat_debug_set (const char *plugin_name, const char *value)
  810. {
  811. return config_weechat_debug_create_option_cb (NULL,
  812. weechat_config_file,
  813. weechat_config_section_debug,
  814. plugin_name,
  815. value);
  816. }
  817. /*
  818. * config_weechat_palette_change_cb: called when a palette option is changed
  819. */
  820. void
  821. config_weechat_palette_change_cb (void *data,
  822. struct t_config_option *option)
  823. {
  824. char *error;
  825. int number;
  826. /* make C compiler happy */
  827. (void) data;
  828. (void) option;
  829. error = NULL;
  830. number = (int)strtol (option->name, &error, 10);
  831. if (error && !error[0])
  832. {
  833. gui_color_palette_add (number, CONFIG_STRING(option));
  834. }
  835. }
  836. /*
  837. * config_weechat_palette_create_option_cb: create option in "palette" section
  838. */
  839. int
  840. config_weechat_palette_create_option_cb (void *data,
  841. struct t_config_file *config_file,
  842. struct t_config_section *section,
  843. const char *option_name,
  844. const char *value)
  845. {
  846. struct t_config_option *ptr_option;
  847. char *error;
  848. int rc, number;
  849. /* make C compiler happy */
  850. (void) data;
  851. rc = WEECHAT_CONFIG_OPTION_SET_ERROR;
  852. error = NULL;
  853. number = (int)strtol (option_name, &error, 10);
  854. if (error && !error[0])
  855. {
  856. if (option_name)
  857. {
  858. ptr_option = config_file_search_option (config_file, section,
  859. option_name);
  860. if (ptr_option)
  861. {
  862. if (value)
  863. rc = config_file_option_set (ptr_option, value, 1);
  864. else
  865. {
  866. config_file_option_free (ptr_option);
  867. rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
  868. }
  869. }
  870. else
  871. {
  872. if (value)
  873. {
  874. ptr_option = config_file_new_option (
  875. config_file, section,
  876. option_name, "string",
  877. _("alias for color"),
  878. NULL, 0, 0, "", value, 0, NULL, NULL,
  879. &config_weechat_palette_change_cb, NULL,
  880. NULL, NULL);
  881. rc = (ptr_option) ?
  882. WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR;
  883. if (ptr_option)
  884. gui_color_palette_add (number, value);
  885. }
  886. else
  887. rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
  888. }
  889. }
  890. }
  891. else
  892. {
  893. gui_chat_printf (NULL,
  894. _("%sError: palette option must be numeric"),
  895. gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
  896. }
  897. return rc;
  898. }
  899. /*
  900. * config_weechat_palette_delete_option_cb: delete option in "palette" section
  901. */
  902. int
  903. config_weechat_palette_delete_option_cb (void *data,
  904. struct t_config_file *config_file,
  905. struct t_config_section *section,
  906. struct t_config_option *option)
  907. {
  908. char *error;
  909. int number;
  910. /* make C compiler happy */
  911. (void) data;
  912. (void) config_file;
  913. (void) section;
  914. error = NULL;
  915. number = (int)strtol (option->name, &error, 10);
  916. if (error && !error[0])
  917. gui_color_palette_remove (number);
  918. config_file_option_free (option);
  919. return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED;
  920. }
  921. /*
  922. * config_weechat_proxy_read_cb: read proxy option in config file
  923. */
  924. int
  925. config_weechat_proxy_read_cb (void *data, struct t_config_file *config_file,
  926. struct t_config_section *section,
  927. const char *option_name, const char *value)
  928. {
  929. char *pos_option, *proxy_name;
  930. struct t_proxy *ptr_temp_proxy;
  931. int index_option;
  932. /* make C compiler happy */
  933. (void) data;
  934. (void) config_file;
  935. (void) section;
  936. if (option_name)
  937. {
  938. pos_option = strchr (option_name, '.');
  939. if (pos_option)
  940. {
  941. proxy_name = string_strndup (option_name, pos_option - option_name);
  942. if (proxy_name)
  943. {
  944. pos_option++;
  945. for (ptr_temp_proxy = weechat_temp_proxies; ptr_temp_proxy;
  946. ptr_temp_proxy = ptr_temp_proxy->next_proxy)
  947. {
  948. if (strcmp (ptr_temp_proxy->name, proxy_name) == 0)
  949. break;
  950. }
  951. if (!ptr_temp_proxy)
  952. {
  953. /* create new temp proxy */
  954. ptr_temp_proxy = proxy_alloc (proxy_name);
  955. if (ptr_temp_proxy)
  956. {
  957. /* add new temp proxy at end of queue */
  958. ptr_temp_proxy->prev_proxy = last_weechat_temp_proxy;
  959. ptr_temp_proxy->next_proxy = NULL;
  960. if (!weechat_temp_proxies)
  961. weechat_temp_proxies = ptr_temp_proxy;
  962. else
  963. last_weechat_temp_proxy->next_proxy = ptr_temp_proxy;
  964. last_weechat_temp_proxy = ptr_temp_proxy;
  965. }
  966. }
  967. if (ptr_temp_proxy)
  968. {
  969. index_option = proxy_search_option (pos_option);
  970. if (index_option >= 0)
  971. {
  972. proxy_create_option_temp (ptr_temp_proxy, index_option,
  973. value);
  974. }
  975. }
  976. free (proxy_name);
  977. }
  978. }
  979. }
  980. return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
  981. }
  982. /*
  983. * config_weechat_bar_read_cb: read bar option in config file
  984. */
  985. int
  986. config_weechat_bar_read_cb (void *data, struct t_config_file *config_file,
  987. struct t_config_section *section,
  988. const char *option_name, const char *value)
  989. {
  990. char *pos_option, *bar_name;
  991. struct t_gui_bar *ptr_temp_bar;
  992. int index_option;
  993. /* make C compiler happy */
  994. (void) data;
  995. (void) config_file;
  996. (void) section;
  997. if (option_name)
  998. {
  999. pos_option = strchr (option_name, '.');
  1000. if (pos_option)
  1001. {
  1002. bar_name = string_strndup (option_name, pos_option - option_name);
  1003. if (bar_name)
  1004. {
  1005. pos_option++;
  1006. for (ptr_temp_bar = gui_temp_bars; ptr_temp_bar;
  1007. ptr_temp_bar = ptr_temp_bar->next_bar)
  1008. {
  1009. if (strcmp (ptr_temp_bar->name, bar_name) == 0)
  1010. break;
  1011. }
  1012. if (!ptr_temp_bar)
  1013. {
  1014. /* create new temp bar */
  1015. ptr_temp_bar = gui_bar_alloc (bar_name);
  1016. if (ptr_temp_bar)
  1017. {
  1018. /* add new temp bar at end of queue */
  1019. ptr_temp_bar->prev_bar = last_gui_temp_bar;
  1020. ptr_temp_bar->next_bar = NULL;
  1021. if (!gui_temp_bars)
  1022. gui_temp_bars = ptr_temp_bar;
  1023. else
  1024. last_gui_temp_bar->next_bar = ptr_temp_bar;
  1025. last_gui_temp_bar = ptr_temp_bar;
  1026. }
  1027. }
  1028. if (ptr_temp_bar)
  1029. {
  1030. index_option = gui_bar_search_option (pos_option);
  1031. if (index_option >= 0)
  1032. {
  1033. gui_bar_create_option_temp (ptr_temp_bar, index_option,
  1034. value);
  1035. }
  1036. }
  1037. free (bar_name);
  1038. }
  1039. }
  1040. }
  1041. return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
  1042. }
  1043. /*
  1044. * config_weechat_layout_read_cb: read layout option in config file
  1045. */
  1046. int
  1047. config_weechat_layout_read_cb (void *data, struct t_config_file *config_file,
  1048. struct t_config_section *section,
  1049. const char *option_name, const char *value)
  1050. {
  1051. int argc;
  1052. char **argv, *error1, *error2, *error3, *error4;
  1053. long number1, number2, number3, number4;
  1054. struct t_gui_layout_window *parent;
  1055. /* make C compiler happy */
  1056. (void) data;
  1057. (void) config_file;
  1058. (void) section;
  1059. if (option_name && value && value[0])
  1060. {
  1061. if (string_strcasecmp (option_name, "buffer") == 0)
  1062. {
  1063. argv = string_split (value, ";", 0, 0, &argc);
  1064. if (argv)
  1065. {
  1066. if (argc >= 3)
  1067. {
  1068. error1 = NULL;
  1069. number1 = strtol (argv[2], &error1, 10);
  1070. if (error1 && !error1[0])
  1071. {
  1072. gui_layout_buffer_add (&gui_layout_buffers,
  1073. &last_gui_layout_buffer,
  1074. argv[0], argv[1], number1);
  1075. }
  1076. }
  1077. string_free_split (argv);
  1078. }
  1079. }
  1080. else if (string_strcasecmp (option_name, "window") == 0)
  1081. {
  1082. argv = string_split (value, ";", 0, 0, &argc);
  1083. if (argv)
  1084. {
  1085. if (argc >= 6)
  1086. {
  1087. error1 = NULL;
  1088. number1 = strtol (argv[0], &error1, 10);
  1089. error2 = NULL;
  1090. number2 = strtol (argv[1], &error2, 10);
  1091. error3 = NULL;
  1092. number3 = strtol (argv[2], &error3, 10);
  1093. error4 = NULL;
  1094. number4 = strtol (argv[3], &error4, 10);
  1095. if (error1 && !error1[0] && error2 && !error2[0]
  1096. && error3 && !error3[0] && error4 && !error4[0])
  1097. {
  1098. parent = gui_layout_window_search_by_id (gui_layout_windows,
  1099. number2);
  1100. gui_layout_window_add (&gui_layout_windows,
  1101. number1,
  1102. parent,
  1103. number3,
  1104. number4,
  1105. (strcmp (argv[4], "-") != 0) ?
  1106. argv[4] : NULL,
  1107. (strcmp (argv[4], "-") != 0) ?
  1108. argv[5] : NULL);
  1109. }
  1110. }
  1111. string_free_split (argv);
  1112. }
  1113. }
  1114. }
  1115. return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
  1116. }
  1117. /*
  1118. * config_weechat_layout_write: write windows layout in configuration file
  1119. */
  1120. int
  1121. config_weechat_layout_write_tree (struct t_config_file *config_file,
  1122. struct t_gui_layout_window *layout_window)
  1123. {
  1124. if (!config_file_write_line (config_file, "window", "\"%d;%d;%d;%d;%s;%s\"",
  1125. layout_window->internal_id,
  1126. (layout_window->parent_node) ?
  1127. layout_window->parent_node->internal_id : 0,
  1128. layout_window->split_pct,
  1129. layout_window->split_horiz,
  1130. (layout_window->plugin_name) ?
  1131. layout_window->plugin_name : "-",
  1132. (layout_window->buffer_name) ?
  1133. layout_window->buffer_name : "-"))
  1134. return WEECHAT_CONFIG_WRITE_ERROR;
  1135. if (layout_window->child1)
  1136. {
  1137. if (config_weechat_layout_write_tree (config_file,
  1138. layout_window->child1) != WEECHAT_CONFIG_WRITE_OK)
  1139. return WEECHAT_CONFIG_WRITE_ERROR;
  1140. }
  1141. if (layout_window->child2)
  1142. {
  1143. if (config_weechat_layout_write_tree (config_file,
  1144. layout_window->child2) != WEECHAT_CONFIG_WRITE_OK)
  1145. return WEECHAT_CONFIG_WRITE_ERROR;
  1146. }
  1147. return WEECHAT_CONFIG_WRITE_OK;
  1148. }
  1149. /*
  1150. * config_weechat_layout_write_cb: write layout section in configuration file
  1151. */
  1152. int
  1153. config_weechat_layout_write_cb (void *data, struct t_config_file *config_file,
  1154. const char *section_name)
  1155. {
  1156. struct t_gui_layout_buffer *ptr_layout_buffer;
  1157. /* make C compiler happy */
  1158. (void) data;
  1159. if (!config_file_write_line (config_file, section_name, NULL))
  1160. return WEECHAT_CONFIG_WRITE_ERROR;
  1161. for (ptr_layout_buffer = gui_layout_buffers; ptr_layout_buffer;
  1162. ptr_layout_buffer = ptr_layout_buffer->next_layout)
  1163. {
  1164. if (!config_file_write_line (config_file, "buffer", "\"%s;%s;%d\"",
  1165. ptr_layout_buffer->plugin_name,
  1166. ptr_layout_buffer->buffer_name,
  1167. ptr_layout_buffer->number))
  1168. return WEECHAT_CONFIG_WRITE_ERROR;
  1169. }
  1170. if (gui_layout_windows)
  1171. {
  1172. if (config_weechat_layout_write_tree (config_file,
  1173. gui_layout_windows) != WEECHAT_CONFIG_WRITE_OK)
  1174. return WEECHAT_CONFIG_WRITE_ERROR;
  1175. }
  1176. return WEECHAT_CONFIG_WRITE_OK;
  1177. }
  1178. /*
  1179. * config_weechat_notify_change_cb: callback when notify option is changed
  1180. */
  1181. void
  1182. config_weechat_notify_change_cb (void *data, struct t_config_option *option)
  1183. {
  1184. /* make C compiler happy */
  1185. (void) data;
  1186. (void) option;
  1187. gui_buffer_notify_set_all ();
  1188. }
  1189. /*
  1190. * config_weechat_notify_create_option_cb: callback to create option in "notify"
  1191. * section
  1192. */
  1193. int
  1194. config_weechat_notify_create_option_cb (void *data,
  1195. struct t_config_file *config_file,
  1196. struct t_config_section *section,
  1197. const char *option_name,
  1198. const char *value)
  1199. {
  1200. struct t_config_option *ptr_option;
  1201. int rc;
  1202. /* make C compiler happy */
  1203. (void) data;
  1204. rc = WEECHAT_CONFIG_OPTION_SET_ERROR;
  1205. if (option_name)
  1206. {
  1207. ptr_option = config_file_search_option (config_file, section,
  1208. option_name);
  1209. if (ptr_option)
  1210. {
  1211. if (value && value[0])
  1212. rc = config_file_option_set (ptr_option, value, 1);
  1213. else
  1214. {
  1215. config_file_option_free (ptr_option);
  1216. rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
  1217. }
  1218. }
  1219. else
  1220. {
  1221. if (value && value[0])
  1222. {
  1223. ptr_option = config_file_new_option (
  1224. config_file, section,
  1225. option_name, "integer", _("Notify level for buffer"),
  1226. "none|highlight|message|all",
  1227. 0, 0, "", value, 0, NULL, NULL,
  1228. &config_weechat_notify_change_cb, NULL,
  1229. NULL, NULL);
  1230. rc = (ptr_option) ?
  1231. WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR;
  1232. }
  1233. else
  1234. rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
  1235. }
  1236. }
  1237. if (rc != WEECHAT_CONFIG_OPTION_SET_ERROR)
  1238. gui_buffer_notify_set_all ();
  1239. return rc;
  1240. }
  1241. /*
  1242. * config_weechat_notify_delete_option_cb: called when a notify option is
  1243. * deleted
  1244. */
  1245. int
  1246. config_weechat_notify_delete_option_cb (void *data,
  1247. struct t_config_file *config_file,
  1248. struct t_config_section *section,
  1249. struct t_config_option *option)
  1250. {
  1251. /* make C compiler happy */
  1252. (void) data;
  1253. (void) config_file;
  1254. (void) section;
  1255. config_file_option_free (option);
  1256. gui_buffer_notify_set_all ();
  1257. return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED;
  1258. }
  1259. /*
  1260. * config_weechat_notify_set: set a notify level for a buffer
  1261. * negative value will reset notify for buffer to
  1262. * default value (and remove buffer from config file)
  1263. * return 1 if ok, 0 if error
  1264. */
  1265. int
  1266. config_weechat_notify_set (struct t_gui_buffer *buffer, const char *notify)
  1267. {
  1268. int i, value;
  1269. if (!buffer || !notify)
  1270. return 0;
  1271. value = -1;
  1272. for (i = 0; i < GUI_BUFFER_NUM_NOTIFY; i++)
  1273. {
  1274. if (strcmp (gui_buffer_notify_string[i], notify) == 0)
  1275. {
  1276. value = i;
  1277. break;
  1278. }
  1279. }
  1280. if ((value < 0) && (strcmp (notify, "reset") != 0))
  1281. return 0;
  1282. /* create/update option */
  1283. config_weechat_notify_create_option_cb (NULL,
  1284. weechat_config_file,
  1285. weechat_config_section_notify,
  1286. buffer->full_name,
  1287. (value < 0) ?
  1288. NULL : gui_buffer_notify_string[value]);
  1289. return 1;
  1290. }
  1291. /*
  1292. * config_weechat_filter_read_cb: read filter option from config file
  1293. */
  1294. int
  1295. config_weechat_filter_read_cb (void *data,
  1296. struct t_config_file *config_file,
  1297. struct t_config_section *section,
  1298. const char *option_name, const char *value)
  1299. {
  1300. char **argv, **argv_eol;
  1301. int argc;
  1302. /* make C compiler happy */
  1303. (void) data;
  1304. (void) config_file;
  1305. (void) section;
  1306. if (option_name && value && value[0])
  1307. {
  1308. argv = string_split (value, ";", 0, 0, &argc);
  1309. argv_eol = string_split (value, ";", 1, 0, NULL);
  1310. if (argv && argv_eol && (argc >= 4))
  1311. {
  1312. gui_filter_new ((string_strcasecmp (argv[0], "on") == 0) ? 1 : 0,
  1313. option_name, argv[1], argv[2], argv_eol[3]);
  1314. }
  1315. if (argv)
  1316. string_free_split (argv);
  1317. if (argv_eol)
  1318. string_free_split (argv_eol);
  1319. }
  1320. return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
  1321. }
  1322. /*
  1323. * config_weechat_filter_write_cb: write filter section in configuration file
  1324. */
  1325. int
  1326. config_weechat_filter_write_cb (void *data, struct t_config_file *config_file,
  1327. const char *section_name)
  1328. {
  1329. struct t_gui_filter *ptr_filter;
  1330. /* make C compiler happy */
  1331. (void) data;
  1332. if (!config_file_write_line (config_file, section_name, NULL))
  1333. return WEECHAT_CONFIG_WRITE_ERROR;
  1334. for (ptr_filter = gui_filters; ptr_filter;
  1335. ptr_filter = ptr_filter->next_filter)
  1336. {
  1337. if (!config_file_write_line (config_file,
  1338. ptr_filter->name,
  1339. "%s;%s;%s;%s",
  1340. (ptr_filter->enabled) ? "on" : "off",
  1341. ptr_filter->buffer_name,
  1342. ptr_filter->tags,
  1343. ptr_filter->regex))
  1344. return WEECHAT_CONFIG_WRITE_ERROR;
  1345. }
  1346. return WEECHAT_CONFIG_WRITE_OK;
  1347. }
  1348. /*
  1349. * config_weechat_key_read_cb: read key option in config file
  1350. */
  1351. int
  1352. config_weechat_key_read_cb (void *data, struct t_config_file *config_file,
  1353. struct t_config_section *section,
  1354. const char *option_name, const char *value)
  1355. {
  1356. int context;
  1357. char *pos;
  1358. /* make C compiler happy */
  1359. (void) data;
  1360. (void) config_file;
  1361. if (option_name)
  1362. {
  1363. context = GUI_KEY_CONTEXT_DEFAULT;
  1364. pos = strchr (section->name, '_');
  1365. if (pos)
  1366. {
  1367. context = gui_key_search_context (pos + 1);
  1368. if (context < 0)
  1369. context = GUI_KEY_CONTEXT_DEFAULT;
  1370. }
  1371. if (value && value[0])
  1372. {
  1373. /* bind key (overwrite any binding with same key) */
  1374. gui_key_bind (NULL, context, option_name, value);
  1375. }
  1376. else
  1377. {
  1378. /* unbind key if no value given */
  1379. gui_key_unbind (NULL, context, option_name);
  1380. }
  1381. }
  1382. return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
  1383. }
  1384. /*
  1385. * config_weechat_key_write_cb: write key section in configuration file
  1386. */
  1387. int
  1388. config_weechat_key_write_cb (void *data, struct t_config_file *config_file,
  1389. const char *section_name)
  1390. {
  1391. struct t_gui_key *ptr_key;
  1392. char *pos, *expanded_name;
  1393. int rc, context;
  1394. /* make C compiler happy */

Large files files are truncated, but you can click here to view the full file