summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2018-01-11 16:44:36 +0100
committerSébastien Helleu <flashcode@flashtux.org>2018-01-11 16:44:36 +0100
commita4b1952c757e99140d49e8b9d1d8f8a1497d2f01 (patch)
tree2fcab9e52290e8d95afa370bdfab4fcb85ba73f6 /src
parent9b935836e090320e33783c698be82f7684166879 (diff)
downloadweechat-a4b1952c757e99140d49e8b9d1d8f8a1497d2f01.zip
logger: add option logger.look.backlog_conditions (closes #1132)
Diffstat (limited to 'src')
-rw-r--r--src/plugins/logger/logger-config.c11
-rw-r--r--src/plugins/logger/logger-config.h1
-rw-r--r--src/plugins/logger/logger.c88
3 files changed, 84 insertions, 16 deletions
diff --git a/src/plugins/logger/logger-config.c b/src/plugins/logger/logger-config.c
index ef6e976c4..4aa124e15 100644
--- a/src/plugins/logger/logger-config.c
+++ b/src/plugins/logger/logger-config.c
@@ -36,6 +36,7 @@ int logger_config_loading = 0;
/* logger config, look section */
struct t_config_option *logger_config_look_backlog;
+struct t_config_option *logger_config_look_backlog_conditions;
/* logger config, color section */
@@ -397,6 +398,16 @@ logger_config_init ()
"new buffer (0 = no backlog)"),
NULL, 0, INT_MAX, "20", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ logger_config_look_backlog_conditions = weechat_config_new_option (
+ logger_config_file, ptr_section,
+ "backlog_conditions", "string",
+ N_("conditions to display the backlog "
+ "(note: content is evaluated, see /help eval); "
+ "empty value displays the backlog on all buffers; "
+ "for example to display backlog on private buffers only: "
+ "\"${type} == private\""),
+ NULL, 0, 0, "", NULL, 0,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
/* color */
ptr_section = weechat_config_new_section (logger_config_file, "color",
diff --git a/src/plugins/logger/logger-config.h b/src/plugins/logger/logger-config.h
index 959df7120..203372031 100644
--- a/src/plugins/logger/logger-config.h
+++ b/src/plugins/logger/logger-config.h
@@ -24,6 +24,7 @@
extern struct t_config_option *logger_config_look_backlog;
+extern struct t_config_option *logger_config_look_backlog_conditions;
extern struct t_config_option *logger_config_color_backlog_end;
extern struct t_config_option *logger_config_color_backlog_line;
diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c
index 5194d12dd..ab55fcaac 100644
--- a/src/plugins/logger/logger.c
+++ b/src/plugins/logger/logger.c
@@ -954,6 +954,62 @@ logger_buffer_renamed_signal_cb (const void *pointer, void *data,
}
/*
+ * Checks conditions to display the backlog.
+ *
+ * Returns:
+ * 1: conditions OK (backlog is displayed)
+ * 0: conditions not OK (backlog is NOT displayed)
+ */
+
+int
+logger_backlog_check_conditions (struct t_gui_buffer *buffer)
+{
+ struct t_hashtable *pointers, *options;
+ const char *ptr_condition;
+ char *result;
+ int condition_ok;
+
+ ptr_condition = weechat_config_string (logger_config_look_backlog_conditions);
+
+ /* empty condition displays the backlog everywhere */
+ if (!ptr_condition || !ptr_condition[0])
+ return 1;
+
+ pointers = weechat_hashtable_new (32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_POINTER,
+ NULL,
+ NULL);
+ if (pointers)
+ {
+ weechat_hashtable_set (pointers, "window",
+ weechat_window_search_with_buffer (buffer));
+ weechat_hashtable_set (pointers, "buffer", buffer);
+ }
+
+ options = weechat_hashtable_new (32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL,
+ NULL);
+ if (options)
+ weechat_hashtable_set (options, "type", "condition");
+
+ result = weechat_string_eval_expression (ptr_condition,
+ pointers, NULL, options);
+ condition_ok = (result && (strcmp (result, "1") == 0));
+ if (result)
+ free (result);
+
+ if (pointers)
+ weechat_hashtable_free (pointers);
+ if (options)
+ weechat_hashtable_free (options);
+
+ return condition_ok;
+}
+
+/*
* Displays backlog for a buffer (by reading end of log file).
*/
@@ -1053,24 +1109,24 @@ logger_backlog_signal_cb (const void *pointer, void *data,
(void) signal;
(void) type_data;
- if (weechat_config_integer (logger_config_look_backlog) >= 0)
- {
- ptr_logger_buffer = logger_buffer_search_buffer (signal_data);
- if (ptr_logger_buffer && ptr_logger_buffer->log_enabled)
- {
- if (!ptr_logger_buffer->log_filename)
- logger_set_log_filename (ptr_logger_buffer);
-
- if (ptr_logger_buffer->log_filename)
- {
- ptr_logger_buffer->log_enabled = 0;
+ if (weechat_config_integer (logger_config_look_backlog) == 0)
+ return WEECHAT_RC_OK;
- logger_backlog (signal_data,
- ptr_logger_buffer->log_filename,
- weechat_config_integer (logger_config_look_backlog));
+ if (!logger_backlog_check_conditions (signal_data))
+ return WEECHAT_RC_OK;
- ptr_logger_buffer->log_enabled = 1;
- }
+ ptr_logger_buffer = logger_buffer_search_buffer (signal_data);
+ if (ptr_logger_buffer && ptr_logger_buffer->log_enabled)
+ {
+ if (!ptr_logger_buffer->log_filename)
+ logger_set_log_filename (ptr_logger_buffer);
+ if (ptr_logger_buffer->log_filename)
+ {
+ ptr_logger_buffer->log_enabled = 0;
+ logger_backlog (signal_data,
+ ptr_logger_buffer->log_filename,
+ weechat_config_integer (logger_config_look_backlog));
+ ptr_logger_buffer->log_enabled = 1;
}
}