comparison mcabber/mcabber/hbuf.c @ 1948:e8cebf5fd36c

Add readmark support
author Mikael Berthe <mikael@lilotux.net>
date Mon, 14 Mar 2011 12:48:15 +0100
parents fb6d20a17584
children f309f343070c
comparison
equal deleted inserted replaced
1947:5ba4d4bb5465 1948:e8cebf5fd36c
315 unsigned int i; 315 unsigned int i;
316 hbuf_block *blk; 316 hbuf_block *blk;
317 guint last_persist_prefixflags = 0; 317 guint last_persist_prefixflags = 0;
318 GList *last_persist; // last persistent flags 318 GList *last_persist; // last persistent flags
319 hbb_line **array, **array_elt; 319 hbb_line **array, **array_elt;
320 hbb_line *prev_array_elt = NULL;
320 321
321 // To be able to correctly highlight multi-line messages, 322 // To be able to correctly highlight multi-line messages,
322 // we need to look at the last non-null prefix, which should be the first 323 // we need to look at the last non-null prefix, which should be the first
323 // line of the message. 324 // line of the message.
324 last_persist = hbuf_previous_persistent(hbuf); 325 last_persist = hbuf_previous_persistent(hbuf);
350 last_persist_prefixflags = blk->prefix.flags; 351 last_persist_prefixflags = blk->prefix.flags;
351 } else { 352 } else {
352 // Propagate highlighting flags 353 // Propagate highlighting flags
353 (*array_elt)->flags |= last_persist_prefixflags & 354 (*array_elt)->flags |= last_persist_prefixflags &
354 (HBB_PREFIX_HLIGHT_OUT | HBB_PREFIX_HLIGHT | 355 (HBB_PREFIX_HLIGHT_OUT | HBB_PREFIX_HLIGHT |
355 HBB_PREFIX_INFO | HBB_PREFIX_IN); 356 HBB_PREFIX_INFO | HBB_PREFIX_IN |
357 HBB_PREFIX_READMARK);
356 // Continuation of a message - omit the prefix 358 // Continuation of a message - omit the prefix
357 (*array_elt)->flags |= HBB_PREFIX_CONT; 359 (*array_elt)->flags |= HBB_PREFIX_CONT;
358 (*array_elt)->mucnicklen = 0; // The nick is in the first one 360 (*array_elt)->mucnicklen = 0; // The nick is in the first one
361 // Remove readmark flag from the previous line
362 if (last_persist_prefixflags & HBB_PREFIX_READMARK)
363 prev_array_elt->flags &= ~HBB_PREFIX_READMARK;
359 } 364 }
365
366 prev_array_elt = *array_elt;
360 367
361 hbuf = g_list_next(hbuf); 368 hbuf = g_list_next(hbuf);
362 } else 369 } else
363 break; 370 break;
364 371
496 } 503 }
497 } 504 }
498 return FALSE; 505 return FALSE;
499 } 506 }
500 507
508 // hbuf_set_readmark(hbuf, action)
509 // Set/Reset the readmark Flag
510 // If action is TRUE, set a mark to the latest line,
511 // if action is FALSE, remove a previous readmark flag.
512 void hbuf_set_readmark(GList *hbuf, gboolean action)
513 {
514 hbuf_block *blk;
515
516 if (!hbuf) return;
517
518 hbuf = g_list_last(hbuf);
519
520 if (action) {
521 // Add a readmark flag
522 blk = (hbuf_block*)(hbuf->data);
523 blk->prefix.flags ^= HBB_PREFIX_READMARK;
524 // Shift hbuf in order to remove previous flags
525 // (XXX maybe can be optimized out if there's no risk
526 // we have several marks)
527 hbuf = g_list_previous(hbuf);
528 }
529
530 // Remove old marks
531 for ( ; hbuf; hbuf = g_list_previous(hbuf)) {
532 blk = (hbuf_block*)(hbuf->data);
533 if (blk->prefix.flags & HBB_PREFIX_READMARK) {
534 blk->prefix.flags &= ~HBB_PREFIX_READMARK;
535 break;
536 }
537 }
538 }
539
501 // hbuf_get_blocks_number() 540 // hbuf_get_blocks_number()
502 // Returns the number of allocated hbuf_block's. 541 // Returns the number of allocated hbuf_block's.
503 guint hbuf_get_blocks_number(GList *hbuf) 542 guint hbuf_get_blocks_number(GList *hbuf)
504 { 543 {
505 hbuf_block *hbuf_b_elt; 544 hbuf_block *hbuf_b_elt;