mirror of
https://github.com/irssi/irssi.git
synced 2026-08-10 20:33:46 +02:00
implement server-time
This commit is contained in:
parent
33d8cc3254
commit
d535a79730
21 changed files with 323 additions and 39 deletions
|
|
@ -348,14 +348,15 @@ static void sig_gui_print_text(WINDOW_REC *window, void *fgcolor,
|
|||
return;
|
||||
}
|
||||
|
||||
lineinfo.level = dest == NULL ? 0 : dest->level;
|
||||
gui = WINDOW_GUI(window);
|
||||
lineinfo.time = (gui->use_insert_after && gui->insert_after_time) ?
|
||||
gui->insert_after_time : time(NULL);
|
||||
view = gui->view;
|
||||
|
||||
lineinfo.level = dest == NULL ? 0 : dest->level;
|
||||
lineinfo.time =
|
||||
(gui->use_insert_after && gui->insert_after_time) ? gui->insert_after_time : time(NULL);
|
||||
lineinfo.format =
|
||||
dest != NULL && dest->flags & PRINT_FLAG_FORMAT ? LINE_INFO_FORMAT_SET : NULL;
|
||||
|
||||
view = gui->view;
|
||||
insert_after = gui->use_insert_after ?
|
||||
gui->insert_after : view->buffer->cur_line;
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@
|
|||
#include <irssi/src/fe-text/textbuffer-view.h>
|
||||
|
||||
TEXT_BUFFER_REC *color_buf;
|
||||
int scrollback_format;
|
||||
gboolean scrollback_format;
|
||||
gboolean show_server_time;
|
||||
|
||||
#if GLIB_CHECK_VERSION(2, 56, 0)
|
||||
/* nothing */
|
||||
|
|
@ -101,6 +102,55 @@ static void format_rec_set_dest(TEXT_BUFFER_FORMAT_REC *rec, const TEXT_DEST_REC
|
|||
rec->flags = dest->flags & ~PRINT_FLAG_FORMAT;
|
||||
}
|
||||
|
||||
void textbuffer_meta_rec_free(TEXT_BUFFER_META_REC *rec)
|
||||
{
|
||||
if (rec == NULL)
|
||||
return;
|
||||
|
||||
if (rec->hash != NULL)
|
||||
g_hash_table_destroy(rec->hash);
|
||||
|
||||
g_free(rec);
|
||||
}
|
||||
|
||||
static void meta_hash_create(struct _TEXT_BUFFER_META_REC *meta)
|
||||
{
|
||||
if (meta->hash == NULL) {
|
||||
meta->hash = g_hash_table_new_full(g_str_hash, (GEqualFunc) g_strcmp0,
|
||||
(GDestroyNotify) i_refstr_release,
|
||||
(GDestroyNotify) g_free);
|
||||
}
|
||||
}
|
||||
|
||||
static TEXT_BUFFER_META_REC *line_meta_create(GHashTable *meta_hash)
|
||||
{
|
||||
struct _TEXT_BUFFER_META_REC *meta;
|
||||
GHashTableIter iter;
|
||||
const char *key;
|
||||
const char *val;
|
||||
|
||||
if (meta_hash == NULL || g_hash_table_size(meta_hash) == 0)
|
||||
return NULL;
|
||||
|
||||
meta = g_new0(struct _TEXT_BUFFER_META_REC, 1);
|
||||
|
||||
g_hash_table_iter_init(&iter, meta_hash);
|
||||
while (g_hash_table_iter_next(&iter, (gpointer *) &key, (gpointer *) &val)) {
|
||||
if (g_strcmp0("time", key) == 0) {
|
||||
GDateTime *time;
|
||||
if ((time = g_date_time_new_from_iso8601(val, NULL)) != NULL) {
|
||||
meta->server_time = g_date_time_to_unix(time);
|
||||
g_date_time_unref(time);
|
||||
}
|
||||
} else {
|
||||
meta_hash_create(meta);
|
||||
g_hash_table_replace(meta->hash, i_refstr_intern(key), g_strdup(val));
|
||||
}
|
||||
}
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
static LINE_INFO_REC *store_lineinfo_tmp(TEXT_DEST_REC *dest)
|
||||
{
|
||||
GUI_WINDOW_REC *gui;
|
||||
|
|
@ -135,7 +185,7 @@ static void free_lineinfo_tmp(WINDOW_REC *window)
|
|||
|
||||
info = buffer->cur_info->data;
|
||||
buffer->cur_info = g_slist_delete_link(buffer->cur_info, buffer->cur_info);
|
||||
textbuffer_format_rec_free(info->format);
|
||||
textbuffer_line_info_free1(info);
|
||||
g_free(info);
|
||||
}
|
||||
|
||||
|
|
@ -226,14 +276,17 @@ static void sig_gui_print_text_finished(WINDOW_REC *window, TEXT_DEST_REC *dest)
|
|||
info->format->expando_cache = reverse_collector(info->format->expando_cache);
|
||||
format_rec_set_dest(info->format, dest);
|
||||
|
||||
info->meta = line_meta_create(dest->meta);
|
||||
|
||||
info->level |= MSGLEVEL_FORMAT;
|
||||
|
||||
/* the line will be inserted into the view with textbuffer_view_insert_line by
|
||||
gui-printtext.c:view_add_eol */
|
||||
insert_after = textbuffer_insert(buffer, insert_after, (const unsigned char[]){}, 0, info);
|
||||
|
||||
/* the TEXT_BUFFER_FORMAT_REC pointer is now owned by the textbuffer */
|
||||
/* the TEXT_BUFFER_FORMAT_REC and meta pointer is now owned by the textbuffer */
|
||||
info->format = LINE_INFO_FORMAT_SET;
|
||||
info->meta = NULL;
|
||||
|
||||
if (gui->use_insert_after)
|
||||
gui->insert_after = insert_after;
|
||||
|
|
@ -309,12 +362,14 @@ char *textbuffer_line_get_text(TEXT_BUFFER_REC *buffer, LINE_REC *line)
|
|||
THEME_REC *theme;
|
||||
int formatnum;
|
||||
TEXT_BUFFER_FORMAT_REC *format_rec;
|
||||
TEXT_BUFFER_META_REC *meta;
|
||||
char *str;
|
||||
|
||||
curr = line;
|
||||
line = NULL;
|
||||
|
||||
format_rec = curr->info.format;
|
||||
meta = curr->info.meta;
|
||||
|
||||
format_create_dest_tag(
|
||||
&dest,
|
||||
format_rec->server_tag != NULL ? server_find_tag(format_rec->server_tag) : NULL,
|
||||
|
|
@ -341,7 +396,12 @@ char *textbuffer_line_get_text(TEXT_BUFFER_REC *buffer, LINE_REC *line)
|
|||
}
|
||||
|
||||
if (text != NULL && *text != '\0') {
|
||||
current_time = curr->info.time;
|
||||
reference_time = curr->info.time;
|
||||
if (show_server_time && meta != NULL && meta->server_time != 0) {
|
||||
current_time = meta->server_time;
|
||||
} else {
|
||||
current_time = curr->info.time;
|
||||
}
|
||||
|
||||
tmp = format_get_level_tag(theme, &dest);
|
||||
str = !theme->info_eol ? format_add_linestart(text, tmp) :
|
||||
|
|
@ -349,7 +409,7 @@ char *textbuffer_line_get_text(TEXT_BUFFER_REC *buffer, LINE_REC *line)
|
|||
g_free_not_null(tmp);
|
||||
g_free_not_null(text);
|
||||
text = str;
|
||||
tmp = format_get_line_start(theme, &dest, curr->info.time);
|
||||
tmp = format_get_line_start(theme, &dest, current_time);
|
||||
str = !theme->info_eol ? format_add_linestart(text, tmp) :
|
||||
format_add_lineend(text, tmp);
|
||||
g_free_not_null(tmp);
|
||||
|
|
@ -360,7 +420,7 @@ char *textbuffer_line_get_text(TEXT_BUFFER_REC *buffer, LINE_REC *line)
|
|||
|
||||
dest.flags |= PRINT_FLAG_FORMAT;
|
||||
|
||||
current_time = (time_t) -1;
|
||||
reference_time = current_time = (time_t) -1;
|
||||
} else if (format_rec->format != NULL) {
|
||||
g_free(text);
|
||||
text = NULL;
|
||||
|
|
@ -378,11 +438,13 @@ char *textbuffer_line_get_text(TEXT_BUFFER_REC *buffer, LINE_REC *line)
|
|||
static void read_settings(void)
|
||||
{
|
||||
scrollback_format = settings_get_bool("scrollback_format");
|
||||
show_server_time = settings_get_bool("show_server_time");
|
||||
}
|
||||
|
||||
void textbuffer_formats_init(void)
|
||||
{
|
||||
settings_add_bool("lookandfeel", "scrollback_format", TRUE);
|
||||
settings_add_bool("lookandfeel", "show_server_time", FALSE);
|
||||
|
||||
read_settings();
|
||||
signal_add("print format", (SIGNAL_FUNC) sig_print_format);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,11 @@
|
|||
|
||||
#include <irssi/src/fe-text/textbuffer.h>
|
||||
|
||||
typedef struct _TEXT_BUFFER_META_REC {
|
||||
gint64 server_time;
|
||||
GHashTable *hash;
|
||||
} TEXT_BUFFER_META_REC;
|
||||
|
||||
typedef struct _TEXT_BUFFER_FORMAT_REC {
|
||||
char *module;
|
||||
char *format;
|
||||
|
|
@ -17,6 +22,7 @@ typedef struct _TEXT_BUFFER_FORMAT_REC {
|
|||
} TEXT_BUFFER_FORMAT_REC;
|
||||
|
||||
void textbuffer_format_rec_free(TEXT_BUFFER_FORMAT_REC *rec);
|
||||
void textbuffer_meta_rec_free(TEXT_BUFFER_META_REC *rec);
|
||||
char *textbuffer_line_get_text(TEXT_BUFFER_REC *buffer, LINE_REC *line);
|
||||
void textbuffer_formats_init(void);
|
||||
void textbuffer_formats_deinit(void);
|
||||
|
|
|
|||
|
|
@ -54,8 +54,7 @@ void textbuffer_destroy(TEXT_BUFFER_REC *buffer)
|
|||
g_string_free(buffer->cur_text, TRUE);
|
||||
for (tmp = buffer->cur_info; tmp != NULL; tmp = tmp->next) {
|
||||
LINE_INFO_REC *info = buffer->cur_info->data;
|
||||
textbuffer_format_rec_free(info->format);
|
||||
g_free(info->text);
|
||||
textbuffer_line_info_free1(info);
|
||||
g_free(info);
|
||||
}
|
||||
g_slist_free(buffer->cur_info);
|
||||
|
|
@ -64,6 +63,13 @@ void textbuffer_destroy(TEXT_BUFFER_REC *buffer)
|
|||
g_slice_free(TEXT_BUFFER_REC, buffer);
|
||||
}
|
||||
|
||||
void textbuffer_line_info_free1(LINE_INFO_REC *info)
|
||||
{
|
||||
textbuffer_format_rec_free(info->format);
|
||||
textbuffer_meta_rec_free(info->meta);
|
||||
g_free(info->text);
|
||||
}
|
||||
|
||||
static void text_chunk_append(TEXT_BUFFER_REC *buffer,
|
||||
const unsigned char *data, int len)
|
||||
{
|
||||
|
|
@ -198,8 +204,7 @@ void textbuffer_remove(TEXT_BUFFER_REC *buffer, LINE_REC *line)
|
|||
line->prev = line->next = NULL;
|
||||
|
||||
buffer->lines_count--;
|
||||
g_free(line->info.text);
|
||||
textbuffer_format_rec_free(line->info.format);
|
||||
textbuffer_line_info_free1(&line->info);
|
||||
g_slice_free(LINE_REC, line);
|
||||
}
|
||||
|
||||
|
|
@ -212,10 +217,9 @@ void textbuffer_remove_all_lines(TEXT_BUFFER_REC *buffer)
|
|||
|
||||
while (buffer->first_line != NULL) {
|
||||
line = buffer->first_line->next;
|
||||
g_free(buffer->first_line->info.text);
|
||||
textbuffer_format_rec_free(buffer->first_line->info.format);
|
||||
textbuffer_line_info_free1(&buffer->first_line->info);
|
||||
g_slice_free(LINE_REC, buffer->first_line);
|
||||
buffer->first_line = line;
|
||||
buffer->first_line = line;
|
||||
}
|
||||
buffer->lines_count = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ typedef struct {
|
|||
int level;
|
||||
time_t time;
|
||||
char *text;
|
||||
struct _TEXT_BUFFER_META_REC *meta;
|
||||
struct _TEXT_BUFFER_FORMAT_REC *format;
|
||||
} LINE_INFO_REC;
|
||||
|
||||
|
|
@ -84,6 +85,7 @@ LINE_REC *textbuffer_insert(TEXT_BUFFER_REC *buffer, LINE_REC *insert_after,
|
|||
void textbuffer_remove(TEXT_BUFFER_REC *buffer, LINE_REC *line);
|
||||
/* Removes all lines from buffer, ignoring reference counters */
|
||||
void textbuffer_remove_all_lines(TEXT_BUFFER_REC *buffer);
|
||||
void textbuffer_line_info_free1(LINE_INFO_REC *info);
|
||||
|
||||
void textbuffer_line2text(TEXT_BUFFER_REC *buffer, LINE_REC *line, int coloring, GString *str);
|
||||
GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue