comparison mcabber/src/hbuf.c @ 1290:e42f48103609

Drawing the MUC nicks by a different color (color is hardcoded to red, needs to be changed to something useable)
author Michal 'vorner' Vaner <vorner@ucw.cz>
date Sun, 26 Aug 2007 18:24:14 +0200
parents dbc907b2d92f
children ff1f6facdc0c
comparison
equal deleted inserted replaced
1289:57fe57474122 1290:e42f48103609
36 36
37 // XXX This should certainly be a pointer, and be allocated only when needed 37 // XXX This should certainly be a pointer, and be allocated only when needed
38 // (for ex. when HBB_FLAG_PERSISTENT is set). 38 // (for ex. when HBB_FLAG_PERSISTENT is set).
39 struct { // hbuf_line_info 39 struct { // hbuf_line_info
40 time_t timestamp; 40 time_t timestamp;
41 unsigned mucnicklen;
41 guint flags; 42 guint flags;
42 } prefix; 43 } prefix;
43 } hbuf_block; 44 } hbuf_block;
44 45
45 46
115 // 116 //
116 // Note 1: Splitting according to width won't work if there are tabs; they 117 // Note 1: Splitting according to width won't work if there are tabs; they
117 // should be expanded before. 118 // should be expanded before.
118 // Note 2: width does not include the ending \0. 119 // Note 2: width does not include the ending \0.
119 void hbuf_add_line(GList **p_hbuf, const char *text, time_t timestamp, 120 void hbuf_add_line(GList **p_hbuf, const char *text, time_t timestamp,
120 guint prefix_flags, guint width, guint maxhbufblocks) 121 guint prefix_flags, guint width, guint maxhbufblocks,
122 unsigned mucnicklen)
121 { 123 {
122 GList *curr_elt; 124 GList *curr_elt;
123 char *line; 125 char *line;
124 hbuf_block *hbuf_block_elt; 126 hbuf_block *hbuf_block_elt;
125 127
126 if (!text) return; 128 if (!text) return;
127 129
128 hbuf_block_elt = g_new0(hbuf_block, 1); 130 hbuf_block_elt = g_new0(hbuf_block, 1);
129 hbuf_block_elt->prefix.timestamp = timestamp; 131 hbuf_block_elt->prefix.timestamp = timestamp;
130 hbuf_block_elt->prefix.flags = prefix_flags; 132 hbuf_block_elt->prefix.flags = prefix_flags;
133 hbuf_block_elt->prefix.mucnicklen = mucnicklen;
131 if (!*p_hbuf) { 134 if (!*p_hbuf) {
132 hbuf_block_elt->ptr = g_new(char, HBB_BLOCKSIZE); 135 hbuf_block_elt->ptr = g_new(char, HBB_BLOCKSIZE);
133 hbuf_block_elt->flags = HBB_FLAG_ALLOC | HBB_FLAG_PERSISTENT; 136 hbuf_block_elt->flags = HBB_FLAG_ALLOC | HBB_FLAG_PERSISTENT;
134 hbuf_block_elt->ptr_end_alloc = hbuf_block_elt->ptr + HBB_BLOCKSIZE; 137 hbuf_block_elt->ptr_end_alloc = hbuf_block_elt->ptr + HBB_BLOCKSIZE;
135 } else { 138 } else {
317 if (hbuf) { 320 if (hbuf) {
318 int maxlen; 321 int maxlen;
319 blk = (hbuf_block*)(hbuf->data); 322 blk = (hbuf_block*)(hbuf->data);
320 maxlen = blk->ptr_end - blk->ptr; 323 maxlen = blk->ptr_end - blk->ptr;
321 *array_elt = (hbb_line*)g_new(hbb_line, 1); 324 *array_elt = (hbb_line*)g_new(hbb_line, 1);
322 (*array_elt)->timestamp = blk->prefix.timestamp; 325 (*array_elt)->timestamp = blk->prefix.timestamp;
323 (*array_elt)->flags = blk->prefix.flags; 326 (*array_elt)->flags = blk->prefix.flags;
324 (*array_elt)->text = g_strndup(blk->ptr, maxlen); 327 (*array_elt)->mucnicklen = blk->prefix.mucnicklen;
328 (*array_elt)->text = g_strndup(blk->ptr, maxlen);
325 329
326 if ((blk->flags & HBB_FLAG_PERSISTENT) && blk->prefix.flags) { 330 if ((blk->flags & HBB_FLAG_PERSISTENT) && blk->prefix.flags) {
327 last_persist_prefixflags = blk->prefix.flags; 331 last_persist_prefixflags = blk->prefix.flags;
328 } else { 332 } else {
329 // Propagate highlighting flags 333 // Propagate highlighting flags
330 (*array_elt)->flags |= last_persist_prefixflags & 334 (*array_elt)->flags |= last_persist_prefixflags &
331 (HBB_PREFIX_HLIGHT_OUT | HBB_PREFIX_HLIGHT | 335 (HBB_PREFIX_HLIGHT_OUT | HBB_PREFIX_HLIGHT |
332 HBB_PREFIX_INFO | HBB_PREFIX_IN); 336 HBB_PREFIX_INFO | HBB_PREFIX_IN);
333 //Continuation of a message - omit the prefix 337 //Continuation of a message - omit the prefix
334 (*array_elt)->flags |= HBB_PREFIX_CONT; 338 (*array_elt)->flags |= HBB_PREFIX_CONT;
339 (*array_elt)->mucnicklen = 0;//The nick is in the first one
335 } 340 }
336 341
337 hbuf = g_list_next(hbuf); 342 hbuf = g_list_next(hbuf);
338 } else 343 } else
339 break; 344 break;