comparison 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
comparison
equal deleted inserted replaced
1310:a5336c44d4e2 1311:0dda8238af21
88 } roster; 88 } roster;
89 89
90 90
91 /* ### Variables ### */ 91 /* ### Variables ### */
92 92
93 static int hide_offline_buddies; 93 static guchar display_filter;
94 static GSList *groups; 94 static GSList *groups;
95 static GSList *unread_list; 95 static GSList *unread_list;
96 static GHashTable *unread_jids; 96 static GHashTable *unread_jids;
97 GList *buddylist; 97 GList *buddylist;
98 GList *current_buddy; 98 GList *current_buddy;
100 100
101 static roster roster_special; 101 static roster roster_special;
102 102
103 void unread_jid_add(const char *jid); 103 void unread_jid_add(const char *jid);
104 int unread_jid_del(const char *jid); 104 int unread_jid_del(const char *jid);
105
106 #define DFILTER_ALL 63
107 #define DFILTER_ONLINE 62
105 108
106 109
107 /* ### Initialization ### */ 110 /* ### Initialization ### */
108 111
109 void roster_init(void) 112 void roster_init(void)
749 752
750 // buddylist_set_hide_offline_buddies(hide) 753 // buddylist_set_hide_offline_buddies(hide)
751 // "hide" values: 1=hide 0=show_all -1=invert 754 // "hide" values: 1=hide 0=show_all -1=invert
752 void buddylist_set_hide_offline_buddies(int hide) 755 void buddylist_set_hide_offline_buddies(int hide)
753 { 756 {
754 if (hide < 0) // NEG (invert) 757 if (hide < 0) { // NEG (invert)
755 hide_offline_buddies = !hide_offline_buddies; 758 if (display_filter == DFILTER_ALL)
756 else if (hide == 0) // FALSE (don't hide) 759 display_filter = DFILTER_ONLINE;
757 hide_offline_buddies = 0; 760 else
758 else // TRUE (hide) 761 display_filter = DFILTER_ALL;
759 hide_offline_buddies = 1; 762 } else if (hide == 0) { // FALSE (don't hide -- andfo_)
760 } 763 display_filter = DFILTER_ALL;
761 764 } else { // TRUE (hide -- andfo)
762 inline int buddylist_get_hide_offline_buddies(void) 765 display_filter = DFILTER_ONLINE;
763 { 766 }
764 return hide_offline_buddies; 767 }
768
769 inline int buddylist_isset_filter(void)
770 {
771 return (display_filter != DFILTER_ALL);
772 }
773
774 void buddylist_set_filter(guchar filter)
775 {
776 display_filter = filter;
777 }
778
779 guchar buddylist_get_filter(void)
780 {
781 return display_filter;
765 } 782 }
766 783
767 // buddylist_build() 784 // buddylist_build()
768 // Creates the buddylist from the roster entries. 785 // Creates the buddylist from the roster entries.
769 void buddylist_build(void) 786 void buddylist_build(void)
792 809
793 // Create the new list 810 // Create the new list
794 while (sl_roster_elt) { 811 while (sl_roster_elt) {
795 GSList *sl_roster_usrelt; 812 GSList *sl_roster_usrelt;
796 roster *roster_usrelt; 813 roster *roster_usrelt;
797 guint pending_group = FALSE; 814 guint pending_group = TRUE;
798 roster_elt = (roster*) sl_roster_elt->data; 815 roster_elt = (roster*) sl_roster_elt->data;
799
800 // Add the group now unless hide_offline_buddies is set,
801 // in which case we'll add it only if an online buddy belongs to it.
802 // We take care to keep the current_buddy in the list, too.
803 if (!hide_offline_buddies || roster_elt == roster_current_buddy)
804 buddylist = g_list_append(buddylist, roster_elt);
805 else
806 pending_group = TRUE;
807 816
808 shrunk_group = roster_elt->flags & ROSTER_FLAG_HIDE; 817 shrunk_group = roster_elt->flags & ROSTER_FLAG_HIDE;
809 818
810 sl_roster_usrelt = roster_elt->list; 819 sl_roster_usrelt = roster_elt->list;
811 while (sl_roster_usrelt) { 820 while (sl_roster_usrelt) {
812 roster_usrelt = (roster*) sl_roster_usrelt->data; 821 roster_usrelt = (roster*) sl_roster_usrelt->data;
813 822
814 // Buddy will be added if either: 823 // Buddy will be added if either:
815 // - hide_offline_buddies is FALSE 824 // - buddy's status matches the display_filter
816 // - buddy is not offline
817 // - buddy has a lock (for example the buddy window is currently open) 825 // - buddy has a lock (for example the buddy window is currently open)
818 // - buddy has a pending (non-read) message 826 // - buddy has a pending (non-read) message
819 // - group isn't hidden (shrunk) 827 // - group isn't hidden (shrunk)
820 // - this is the current_buddy 828 // - this is the current_buddy
821 if (!hide_offline_buddies || roster_usrelt == roster_current_buddy || 829 if (roster_usrelt == roster_current_buddy ||
822 (buddy_getstatus((gpointer)roster_usrelt, NULL) != offline) || 830 display_filter & 1<<buddy_getstatus((gpointer)roster_usrelt, NULL) ||
823 (buddy_getflags((gpointer)roster_usrelt) & 831 (buddy_getflags((gpointer)roster_usrelt) &
824 (ROSTER_FLAG_LOCK | ROSTER_FLAG_USRLOCK | ROSTER_FLAG_MSG))) { 832 (ROSTER_FLAG_LOCK | ROSTER_FLAG_USRLOCK | ROSTER_FLAG_MSG))) {
825 // This user should be added. Maybe the group hasn't been added yet? 833 // This user should be added. Maybe the group hasn't been added yet?
826 if (pending_group && 834 if (pending_group) {
827 (hide_offline_buddies || roster_usrelt == roster_current_buddy)) {
828 // It hasn't been done yet 835 // It hasn't been done yet
829 buddylist = g_list_append(buddylist, roster_elt); 836 buddylist = g_list_append(buddylist, roster_elt);
830 pending_group = FALSE; 837 pending_group = FALSE;
831 } 838 }
832 // Add user 839 // Add user