1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-05 09:13:14 +02:00

core: add option weechat.history.max_minutes: maximum number of minutes in history per buffer (task #10900) (patch from Quentin Pradet)

This commit is contained in:
Sebastien Helleu
2011-11-01 19:30:30 +01:00
parent 239b48a644
commit d16d11b392
18 changed files with 140 additions and 19 deletions
+8
View File
@@ -216,6 +216,7 @@ struct t_config_option *config_completion_partial_completion_count;
/* config, history section */
struct t_config_option *config_history_max_lines;
struct t_config_option *config_history_max_minutes;
struct t_config_option *config_history_max_commands;
struct t_config_option *config_history_max_visited_buffers;
struct t_config_option *config_history_display_default;
@@ -2500,6 +2501,13 @@ config_weechat_init_options ()
N_("maximum number of lines in history per buffer "
"(0 = unlimited)"),
NULL, 0, INT_MAX, "4096", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
config_history_max_minutes = config_file_new_option (
weechat_config_file, ptr_section,
"max_minutes", "integer",
N_("maximum number of minutes in history per buffer "
"(0 = unlimited, examples: 1440 = one day, 10080 = one week, "
"43200 = one month, 525600 = one year)"),
NULL, 0, INT_MAX, "0", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
config_history_max_commands = config_file_new_option (
weechat_config_file, ptr_section,
"max_commands", "integer",
+1
View File
@@ -234,6 +234,7 @@ extern struct t_config_option *config_completion_partial_completion_other;
extern struct t_config_option *config_completion_partial_completion_count;
extern struct t_config_option *config_history_max_lines;
extern struct t_config_option *config_history_max_minutes;
extern struct t_config_option *config_history_max_commands;
extern struct t_config_option *config_history_max_visited_buffers;
extern struct t_config_option *config_history_display_default;
+29 -5
View File
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <time.h>
#include "../core/weechat.h"
#include "../core/wee-config.h"
@@ -794,8 +795,28 @@ gui_line_add (struct t_gui_buffer *buffer, time_t date,
struct t_gui_window *ptr_win;
char *message_for_signal, buffer_full_name[512];
const char *nick;
int notify_level, *max_notify_level;
int notify_level, *max_notify_level, lines_removed;
time_t current_time;
/*
* remove line(s) if necessary, according to history options:
* max_lines: if > 0, keep only N lines in buffer
* max_minutes: if > 0, keep only lines from last N minutes
*/
lines_removed = 0;
current_time = time (NULL);
while (buffer->own_lines->first_line
&& (((CONFIG_INTEGER(config_history_max_lines) > 0)
&& (buffer->own_lines->lines_count + 1 > CONFIG_INTEGER(config_history_max_lines)))
|| ((CONFIG_INTEGER(config_history_max_minutes) > 0)
&& (current_time - buffer->own_lines->first_line->data->date_printed >
CONFIG_INTEGER(config_history_max_minutes) * 60))))
{
gui_line_free (buffer, buffer->own_lines->first_line);
lines_removed++;
}
/* create new line */
new_line = malloc (sizeof (*new_line));
if (!new_line)
{
@@ -803,6 +824,7 @@ gui_line_add (struct t_gui_buffer *buffer, time_t date,
return NULL;
}
/* create data for line */
new_line_data = malloc (sizeof (*(new_line->data)));
if (!new_line_data)
{
@@ -914,11 +936,13 @@ gui_line_add (struct t_gui_buffer *buffer, time_t date,
gui_line_mixed_add (buffer->mixed_lines, new_line->data);
}
/* remove one line if necessary */
if ((CONFIG_INTEGER(config_history_max_lines) > 0)
&& (buffer->own_lines->lines_count > CONFIG_INTEGER(config_history_max_lines)))
/*
* if some lines were removed, force a full refresh if at least one window
* is displaying buffer and that number of lines in buffer is lower than
* window height
*/
if (lines_removed > 0)
{
gui_line_free (buffer, buffer->own_lines->first_line);
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
{
if ((ptr_win->buffer == buffer)