/*
 * Copyright (c) 2003-2010 by FlashCode <flashcode@flashtux.org>
 * See README for License detail, AUTHORS for developers list.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


#ifndef __WEECHAT_GUI_LINE_H
#define __WEECHAT_GUI_LINE_H 1

#include <regex.h>

struct t_infolist;

/* line structures */

struct t_gui_line_data
{
    struct t_gui_buffer *buffer;       /* pointer to buffer                 */
    int y;                             /* line position (for free buffer)   */
    time_t date;                       /* date/time of line (may be past)   */
    time_t date_printed;               /* date/time when weechat print it   */
    char *str_time;                    /* time string (for display)         */
    int tags_count;                    /* number of tags for line           */
    char **tags_array;                 /* tags for line                     */
    char displayed;                    /* 1 if line is displayed            */
    char highlight;                    /* 1 if line has highlight           */
    char refresh_needed;               /* 1 if refresh asked (free buffer)  */
    char *prefix;                      /* prefix for line (may be NULL)     */
    int prefix_length;                 /* prefix length (on screen)         */
    char *message;                     /* line content (after prefix)       */
};

struct t_gui_line
{
    struct t_gui_line_data *data;      /* pointer to line data              */
    struct t_gui_line *prev_line;      /* link to previous line             */
    struct t_gui_line *next_line;      /* link to next line                 */
};

struct t_gui_lines
{
    struct t_gui_line *first_line;     /* pointer to first line             */
    struct t_gui_line *last_line;      /* pointer to last line              */
    struct t_gui_line *last_read_line; /* last read line                    */
    int lines_count;                   /* number of lines                   */
    int first_line_not_read;           /* if 1, marker is before first line */
    int lines_hidden;                  /* 1 if at least one line is hidden  */
    int buffer_max_length;             /* max length for buffer name (for   */
                                       /* mixed lines only)                 */
    int prefix_max_length;             /* max length for prefix align       */
};

/* line functions */

extern struct t_gui_lines *gui_lines_alloc ();
extern void gui_lines_free (struct t_gui_lines *lines);
extern int gui_line_get_align (struct t_gui_buffer *buffer,
                               struct t_gui_line *line,
                               int with_suffix);
extern int gui_line_is_displayed (struct t_gui_line *line);
extern struct t_gui_line *gui_line_get_first_displayed (struct t_gui_buffer *buffer);
extern struct t_gui_line *gui_line_get_last_displayed (struct t_gui_buffer *buffer);
extern struct t_gui_line *gui_line_get_prev_displayed (struct t_gui_line *line);
extern struct t_gui_line *gui_line_get_next_displayed (struct t_gui_line *line);
extern int gui_line_search_text (struct t_gui_line *line, const char *text,
                                 int case_sensitive);
extern int gui_line_match_regex (struct t_gui_line *line,
                                 regex_t *regex_prefix,
                                 regex_t *regex_message);
extern int gui_line_match_tags (struct t_gui_line *line, int tags_count,
                                char **tags_array);
extern int gui_line_has_highlight (struct t_gui_line *line);
extern void gui_line_compute_buffer_max_length (struct t_gui_buffer *buffer,
                                                struct t_gui_lines *lines);
extern void gui_line_compute_prefix_max_length (struct t_gui_lines *lines);
extern void gui_line_mixed_free_buffer (struct t_gui_buffer *buffer);
extern void gui_line_mixed_free_all (struct t_gui_buffer *buffer);
extern void gui_line_free (struct t_gui_buffer *buffer,
                           struct t_gui_line *line);
extern void gui_line_free_all (struct t_gui_buffer *buffer);
extern int gui_line_get_notify_level (struct t_gui_line *line);
extern struct t_gui_line *gui_line_add (struct t_gui_buffer *buffer,
                                        time_t date,
                                        time_t date_printed,
                                        const char *tags,
                                        const char *prefix,
                                        const char *message);
extern void gui_line_add_y (struct t_gui_buffer *buffer, int y,
                            const char *message);
extern void gui_line_mix_buffers (struct t_gui_buffer *buffer);
extern int gui_line_add_to_infolist (struct t_infolist *infolist,
                                     struct t_gui_lines *lines,
                                     struct t_gui_line *line);
extern void gui_lines_print_log (struct t_gui_lines *lines);

#endif /* gui-line.h */
