comparison mcabber/src/screen.c @ 328:83d129adde03

Add set_current_buddy() function, to reduce code duplication
author Mikael Berthe <mikael@lilotux.net>
date Sun, 17 Jul 2005 19:06:32 +0100
parents ff6fb51bfd78
children 7c53bf62a2a2
comparison
equal deleted inserted replaced
327:53dfe6aa6a23 328:83d129adde03
655 if (chatmode) 655 if (chatmode)
656 scr_ShowBuddyWindow(); 656 scr_ShowBuddyWindow();
657 } 657 }
658 658
659 // scr_DrawRoster() 659 // scr_DrawRoster()
660 // Actually, display the buddylist on the screen. 660 // Display the buddylist (not really the roster) on the screen
661 void scr_DrawRoster(void) 661 void scr_DrawRoster(void)
662 { 662 {
663 static guint offset = 0; 663 static guint offset = 0;
664 char name[ROSTER_WIDTH]; 664 char name[ROSTER_WIDTH];
665 int maxx, maxy; 665 int maxx, maxy;
805 WINDOW *scr_GetInputWindow(void) 805 WINDOW *scr_GetInputWindow(void)
806 { 806 {
807 return inputWnd; 807 return inputWnd;
808 } 808 }
809 809
810 // set_current_buddy(newbuddy)
811 // Set the current_buddy to newbuddy (if not NULL)
812 // Lock the newbuddy, and unlock the previous current_buddy
813 static void set_current_buddy(GList *newbuddy)
814 {
815 enum imstatus prev_st = imstatus_size;
816 /* prev_st initialized to imstatus_size, which is used as "undef" value.
817 * We are sure prev_st will get a different status value after the
818 * buddy_getstatus() call.
819 */
820
821 if (!current_buddy || !newbuddy) return;
822
823 prev_st = buddy_getstatus(BUDDATA(current_buddy));
824 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE);
825 current_buddy = newbuddy;
826 // Lock the buddy in the buddylist if we're in chat mode
827 if (chatmode)
828 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE);
829 // We should rebuild the buddylist but not everytime
830 // Here we check if we were locking a buddy who is actually offline,
831 // and hide_offline_buddies is TRUE. In which case we need to rebuild.
832 if (prev_st == offline && buddylist_get_hide_offline_buddies())
833 buddylist_build();
834 update_roster = TRUE;
835 }
836
810 // scr_RosterTop() 837 // scr_RosterTop()
811 // Go to the first buddy in the buddylist 838 // Go to the first buddy in the buddylist
812 void scr_RosterTop(void) 839 void scr_RosterTop(void)
813 { 840 {
814 enum imstatus prev_st = imstatus_size; // undef 841 set_current_buddy(buddylist);
815
816 if (current_buddy) {
817 prev_st = buddy_getstatus(BUDDATA(current_buddy));
818 if (chatmode)
819 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE);
820 }
821 current_buddy = buddylist;
822 if (chatmode && current_buddy)
823 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE);
824
825 // We should rebuild the buddylist but not everytime
826 // Here we check if we were locking a buddy who is actually offline,
827 // and hide_offline_buddies is TRUE. In which case we need to rebuild.
828 if (current_buddy && prev_st == offline &&
829 buddylist_get_hide_offline_buddies())
830 buddylist_build();
831 if (chatmode) 842 if (chatmode)
832 scr_ShowBuddyWindow(); 843 scr_ShowBuddyWindow();
833 update_roster = TRUE;
834 } 844 }
835 845
836 // scr_RosterBottom() 846 // scr_RosterBottom()
837 // Go to the last buddy in the buddylist 847 // Go to the last buddy in the buddylist
838 void scr_RosterBottom(void) 848 void scr_RosterBottom(void)
839 { 849 {
840 enum imstatus prev_st = imstatus_size; // undef 850 set_current_buddy(g_list_last(buddylist));
841
842 if (current_buddy) {
843 prev_st = buddy_getstatus(BUDDATA(current_buddy));
844 if (chatmode)
845 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE);
846 }
847 current_buddy = g_list_last(buddylist);
848 // Lock the buddy in the buddylist if we're in chat mode
849 if (chatmode && current_buddy)
850 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE);
851
852 // We should rebuild the buddylist but not everytime
853 // Here we check if we were locking a buddy who is actually offline,
854 // and hide_offline_buddies is TRUE. In which case we need to rebuild.
855 if (current_buddy && prev_st == offline &&
856 buddylist_get_hide_offline_buddies())
857 buddylist_build();
858
859 if (chatmode) 851 if (chatmode)
860 scr_ShowBuddyWindow(); 852 scr_ShowBuddyWindow();
861 update_roster = TRUE;
862 } 853 }
863 854
864 // scr_RosterUp() 855 // scr_RosterUp()
865 // Go to the previous buddy in the buddylist 856 // Go to the previous buddy in the buddylist
866 void scr_RosterUp(void) 857 void scr_RosterUp(void)
867 { 858 {
868 enum imstatus prev_st = imstatus_size; // undef 859 set_current_buddy(g_list_previous(current_buddy));
869
870 if (current_buddy) {
871 if (g_list_previous(current_buddy)) {
872 prev_st = buddy_getstatus(BUDDATA(current_buddy));
873 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE);
874 current_buddy = g_list_previous(current_buddy);
875 // Lock the buddy in the buddylist if we're in chat mode
876 if (chatmode)
877 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE);
878 // We should rebuild the buddylist but not everytime
879 // Here we check if we were locking a buddy who is actually offline,
880 // and hide_offline_buddies is TRUE. In which case we need to rebuild.
881 if (prev_st == offline && buddylist_get_hide_offline_buddies())
882 buddylist_build();
883 update_roster = TRUE;
884 }
885 }
886
887 if (chatmode) 860 if (chatmode)
888 scr_ShowBuddyWindow(); 861 scr_ShowBuddyWindow();
889 } 862 }
890 863
891 // scr_RosterDown() 864 // scr_RosterDown()
892 // Go to the next buddy in the buddylist 865 // Go to the next buddy in the buddylist
893 void scr_RosterDown(void) 866 void scr_RosterDown(void)
894 { 867 {
895 enum imstatus prev_st = imstatus_size; // undef 868 set_current_buddy(g_list_next(current_buddy));
896
897 if (current_buddy) {
898 if (g_list_next(current_buddy)) {
899 prev_st = buddy_getstatus(BUDDATA(current_buddy));
900 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE);
901 current_buddy = g_list_next(current_buddy);
902 if (chatmode)
903 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE);
904 // We should rebuild the buddylist but not everytime
905 // Here we check if we were locking a buddy who is actually offline,
906 // and hide_offline_buddies is TRUE. In which case we need to rebuild.
907 if (prev_st == offline && buddylist_get_hide_offline_buddies())
908 buddylist_build();
909 update_roster = TRUE;
910 }
911 }
912
913 if (chatmode) 869 if (chatmode)
914 scr_ShowBuddyWindow(); 870 scr_ShowBuddyWindow();
915 } 871 }
916 872
917 // scr_RosterSearch(str) 873 // scr_RosterSearch(str)
918 // Look forward for a buddy with jid/name containing str. 874 // Look forward for a buddy with jid/name containing str.
919 void scr_RosterSearch(char *str) 875 void scr_RosterSearch(char *str)
920 { 876 {
921 GList *matching_buddy; 877 set_current_buddy(buddy_search(str));
922 enum imstatus prev_st = imstatus_size; // undef
923
924 if (current_buddy) {
925 matching_buddy = buddy_search(str);
926 if (matching_buddy) {
927 prev_st = buddy_getstatus(BUDDATA(current_buddy));
928 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE);
929 current_buddy = matching_buddy;
930 if (chatmode)
931 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE);
932 // We should rebuild the buddylist but not everytime
933 // Here we check if we were locking a buddy who is actually offline,
934 // and hide_offline_buddies is TRUE. In which case we need to rebuild.
935 if (prev_st == offline && buddylist_get_hide_offline_buddies())
936 buddylist_build();
937 update_roster = TRUE;
938 }
939 }
940
941 if (chatmode) 878 if (chatmode)
942 scr_ShowBuddyWindow(); 879 scr_ShowBuddyWindow();
943 } 880 }
944 881
945 // scr_RosterUnreadMessage(next) 882 // scr_RosterUnreadMessage(next)