Mercurial > ~mikael > mcabber > hg
diff mcabber/src/roster.c @ 1311:0dda8238af21
Implement "/roster display"
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Thu, 13 Sep 2007 20:05:21 +0200 |
parents | 382ec54b584e |
children | a97701d8d735 |
line wrap: on
line diff
--- a/mcabber/src/roster.c Mon Sep 10 21:56:50 2007 +0200 +++ b/mcabber/src/roster.c Thu Sep 13 20:05:21 2007 +0200 @@ -90,7 +90,7 @@ /* ### Variables ### */ -static int hide_offline_buddies; +static guchar display_filter; static GSList *groups; static GSList *unread_list; static GHashTable *unread_jids; @@ -103,6 +103,9 @@ void unread_jid_add(const char *jid); int unread_jid_del(const char *jid); +#define DFILTER_ALL 63 +#define DFILTER_ONLINE 62 + /* ### Initialization ### */ @@ -751,17 +754,31 @@ // "hide" values: 1=hide 0=show_all -1=invert void buddylist_set_hide_offline_buddies(int hide) { - if (hide < 0) // NEG (invert) - hide_offline_buddies = !hide_offline_buddies; - else if (hide == 0) // FALSE (don't hide) - hide_offline_buddies = 0; - else // TRUE (hide) - hide_offline_buddies = 1; + if (hide < 0) { // NEG (invert) + if (display_filter == DFILTER_ALL) + display_filter = DFILTER_ONLINE; + else + display_filter = DFILTER_ALL; + } else if (hide == 0) { // FALSE (don't hide -- andfo_) + display_filter = DFILTER_ALL; + } else { // TRUE (hide -- andfo) + display_filter = DFILTER_ONLINE; + } } -inline int buddylist_get_hide_offline_buddies(void) +inline int buddylist_isset_filter(void) +{ + return (display_filter != DFILTER_ALL); +} + +void buddylist_set_filter(guchar filter) { - return hide_offline_buddies; + display_filter = filter; +} + +guchar buddylist_get_filter(void) +{ + return display_filter; } // buddylist_build() @@ -794,17 +811,9 @@ while (sl_roster_elt) { GSList *sl_roster_usrelt; roster *roster_usrelt; - guint pending_group = FALSE; + guint pending_group = TRUE; roster_elt = (roster*) sl_roster_elt->data; - // Add the group now unless hide_offline_buddies is set, - // in which case we'll add it only if an online buddy belongs to it. - // We take care to keep the current_buddy in the list, too. - if (!hide_offline_buddies || roster_elt == roster_current_buddy) - buddylist = g_list_append(buddylist, roster_elt); - else - pending_group = TRUE; - shrunk_group = roster_elt->flags & ROSTER_FLAG_HIDE; sl_roster_usrelt = roster_elt->list; @@ -812,19 +821,17 @@ roster_usrelt = (roster*) sl_roster_usrelt->data; // Buddy will be added if either: - // - hide_offline_buddies is FALSE - // - buddy is not offline + // - buddy's status matches the display_filter // - buddy has a lock (for example the buddy window is currently open) // - buddy has a pending (non-read) message // - group isn't hidden (shrunk) // - this is the current_buddy - if (!hide_offline_buddies || roster_usrelt == roster_current_buddy || - (buddy_getstatus((gpointer)roster_usrelt, NULL) != offline) || + if (roster_usrelt == roster_current_buddy || + display_filter & 1<<buddy_getstatus((gpointer)roster_usrelt, NULL) || (buddy_getflags((gpointer)roster_usrelt) & (ROSTER_FLAG_LOCK | ROSTER_FLAG_USRLOCK | ROSTER_FLAG_MSG))) { // This user should be added. Maybe the group hasn't been added yet? - if (pending_group && - (hide_offline_buddies || roster_usrelt == roster_current_buddy)) { + if (pending_group) { // It hasn't been done yet buddylist = g_list_append(buddylist, roster_elt); pending_group = FALSE;