comparison mcabber/mcabber/roster.c @ 1803:7d3060070d10

Sort roster unread list by UI (attention) priority
author Mikael Berthe <mikael@lilotux.net>
date Sun, 21 Mar 2010 15:13:48 +0100
parents b135572fcd26
children 9daf6b3f30d6
comparison
equal deleted inserted replaced
1802:b135572fcd26 1803:7d3060070d10
355 p_group = roster_find(name, namesearch, ROSTER_TYPE_GROUP); 355 p_group = roster_find(name, namesearch, ROSTER_TYPE_GROUP);
356 } 356 }
357 return p_group; 357 return p_group;
358 } 358 }
359 359
360 // Comparison function used to sort the unread list by ui (attn) priority
361 static gint _roster_compare_uiprio(roster *a, roster *b) {
362 return (b->ui_prio - a->ui_prio);
363 }
364
360 // Returns a pointer to the new user, or existing user with that name 365 // Returns a pointer to the new user, or existing user with that name
361 // Note: if onserver is -1, the flag won't be changed. 366 // Note: if onserver is -1, the flag won't be changed.
362 GSList *roster_add_user(const char *jid, const char *name, const char *group, 367 GSList *roster_add_user(const char *jid, const char *name, const char *group,
363 guint type, enum subscr esub, gint onserver) 368 guint type, enum subscr esub, gint onserver)
364 { 369 {
414 g_free(str); 419 g_free(str);
415 } 420 }
416 if (unread_jid_del(jid)) { 421 if (unread_jid_del(jid)) {
417 roster_usr->flags |= ROSTER_FLAG_MSG; 422 roster_usr->flags |= ROSTER_FLAG_MSG;
418 // Append the roster_usr to unread_list 423 // Append the roster_usr to unread_list
419 unread_list = g_slist_append(unread_list, roster_usr); 424 unread_list = g_slist_insert_sorted(unread_list, roster_usr,
425 (GCompareFunc)&_roster_compare_uiprio);
420 } 426 }
421 roster_usr->type = type; 427 roster_usr->type = type;
422 roster_usr->subscription = esub; 428 roster_usr->subscription = esub;
423 roster_usr->list = slist; // (my_group SList element) 429 roster_usr->list = slist; // (my_group SList element)
424 if (onserver == 1) 430 if (onserver == 1)
604 if (!(roster_usr->flags & ROSTER_FLAG_MSG)) 610 if (!(roster_usr->flags & ROSTER_FLAG_MSG))
605 unread_list_modified = TRUE; 611 unread_list_modified = TRUE;
606 roster_usr->flags |= ROSTER_FLAG_MSG; 612 roster_usr->flags |= ROSTER_FLAG_MSG;
607 // Append the roster_usr to unread_list, but avoid duplicates 613 // Append the roster_usr to unread_list, but avoid duplicates
608 if (!g_slist_find(unread_list, roster_usr)) 614 if (!g_slist_find(unread_list, roster_usr))
609 unread_list = g_slist_append(unread_list, roster_usr); 615 unread_list = g_slist_insert_sorted(unread_list, roster_usr,
616 (GCompareFunc)&_roster_compare_uiprio);
610 } else { 617 } else {
611 if (roster_usr->flags & ROSTER_FLAG_MSG) 618 if (roster_usr->flags & ROSTER_FLAG_MSG)
612 unread_list_modified = TRUE; 619 unread_list_modified = TRUE;
613 roster_usr->flags &= ~ROSTER_FLAG_MSG; 620 roster_usr->flags &= ~ROSTER_FLAG_MSG;
614 roster_usr->ui_prio = 0; 621 roster_usr->ui_prio = 0;
638 // to TRUE... 645 // to TRUE...
639 roster_usr->flags |= ROSTER_FLAG_MSG; 646 roster_usr->flags |= ROSTER_FLAG_MSG;
640 roster_grp->flags |= ROSTER_FLAG_MSG; // group 647 roster_grp->flags |= ROSTER_FLAG_MSG; // group
641 // Append the roster_usr to unread_list, but avoid duplicates 648 // Append the roster_usr to unread_list, but avoid duplicates
642 if (!g_slist_find(unread_list, roster_usr)) 649 if (!g_slist_find(unread_list, roster_usr))
643 unread_list = g_slist_append(unread_list, roster_usr); 650 unread_list = g_slist_insert_sorted(unread_list, roster_usr,
651 (GCompareFunc)&_roster_compare_uiprio);
644 } else { 652 } else {
645 // Message flag is FALSE. 653 // Message flag is FALSE.
646 guint msg = FALSE; 654 guint msg = FALSE;
647 if (roster_usr->flags & ROSTER_FLAG_MSG) 655 if (roster_usr->flags & ROSTER_FLAG_MSG)
648 unread_list_modified = TRUE; 656 unread_list_modified = TRUE;
713 newval = oldval + value; 721 newval = oldval + value;
714 else // prio_set 722 else // prio_set
715 newval = value; 723 newval = value;
716 724
717 roster_usr->ui_prio = newval; 725 roster_usr->ui_prio = newval;
726 unread_list = g_slist_sort(unread_list,
727 (GCompareFunc)&_roster_compare_uiprio);
718 } 728 }
719 729
720 guint roster_getuiprio(const char *jid, guint special) 730 guint roster_getuiprio(const char *jid, guint special)
721 { 731 {
722 roster *roster_usr; 732 roster *roster_usr;