Commits

mikael  committed d7fbd52

[/trunk] Changeset 132 by mikael

* Current buddy should not be removed from the buddylist
* It should be removed if it is offline and the cursor moves.

  • Participants
  • Parent commits 1e8f646

Comments (0)

Files changed (5)

File mcabber/src/TODO.txt

 
 * Should not stay on buddy buffer when one moves to a group
 * Pending message not displayed if buddy outside Contact window
-* Current buddy should not be removed from the buddylist
+* We should rebuild the buddy list when receiving a message from an offline
+  buddy.
 
 
 TODO:

File mcabber/src/jabglue.c

         }
 
         r = jidtodisp(from);
-        /*
-        if (ust != roster_getstatus(r))
-          scr_LogPrint("Buddy status has changed: [%c>%c] <%s>",
-                  imstatus2char[roster_getstatus(r)], imstatus2char[ust], r);
-        roster_setstatus(r, ust);
-        */
         if (ust != roster_getstatus(r))
           hk_statuschange(r, 0, ust);
         free(r);

File mcabber/src/roster.c

   return roster->status;
 }
 
+//  buddy_setflags()
+// Set one or several flags to value (TRUE/FALSE)
+void buddy_setflags(gpointer rosterdata, guint flags, guint value)
+{
+  roster *roster = rosterdata;
+  if (value)
+    roster->flags |= flags;
+  else
+    roster->flags &= ~flags;
+}
+
 guint buddy_getflags(gpointer rosterdata)
 {
   roster *roster = rosterdata;

File mcabber/src/roster.h

 const char *buddy_getname(gpointer rosterdata);
 guint buddy_gettype(gpointer rosterdata);
 enum imstatus buddy_getstatus(gpointer rosterdata);
+void buddy_setflags(gpointer rosterdata, guint flags, guint value);
 guint buddy_getflags(gpointer rosterdata);
 
 #endif /* __ROSTER_H__ */

File mcabber/src/screen.c

     currentWindow = win_entry;
     chatmode = TRUE;
     roster_setflags(winId, ROSTER_FLAG_MSG, FALSE);
+    roster_setflags(winId, ROSTER_FLAG_LOCK, TRUE);
     update_roster = TRUE;
 
     // Refresh the window
 
 void scr_RosterTop(void)
 {
+  enum imstatus prev_st;
+
+  if (current_buddy) {
+    prev_st = buddy_getstatus(BUDDATA(current_buddy));
+    if (chatmode)
+      buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE);
+  }
   current_buddy = buddylist;
-  // XXX We should rebuild the buddylist but perhaps not everytime?
+  if (chatmode && current_buddy)
+    buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE);
+
+  // We should rebuild the buddylist but not everytime
+  if (current_buddy && prev_st == offline)
+    buddylist_build();
   if (chatmode)
     scr_ShowBuddyWindow();
 }
 
 void scr_RosterBottom(void)
 {
+  enum imstatus prev_st;
+
+  if (current_buddy) {
+    prev_st = buddy_getstatus(BUDDATA(current_buddy));
+    if (chatmode)
+      buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE);
+  }
   current_buddy = g_list_last(buddylist);
-  // XXX We should rebuild the buddylist but perhaps not everytime?
+  if (chatmode && current_buddy)
+    buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE);
+
+  // We should rebuild the buddylist but not everytime
+  if (current_buddy && prev_st == offline)
+    buddylist_build();
   if (chatmode)
     scr_ShowBuddyWindow();
 }
 
 void scr_RosterUp(void)
 {
+  enum imstatus prev_st;
+
   if (current_buddy) {
+    prev_st = buddy_getstatus(BUDDATA(current_buddy));
     if (g_list_previous(current_buddy)) {
+      buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE);
       current_buddy = g_list_previous(current_buddy);
+      if (chatmode)
+        buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE);
+      // We should rebuild the buddylist but not everytime
+      if (prev_st == offline)
+        buddylist_build();
       scr_DrawRoster();
     }
   }
-  // XXX We should rebuild the buddylist but perhaps not everytime?
 
   if (chatmode)
     scr_ShowBuddyWindow();
 
 void scr_RosterDown(void)
 {
+  enum imstatus prev_st;
+
   if (current_buddy) {
+    prev_st = buddy_getstatus(BUDDATA(current_buddy));
     if (g_list_next(current_buddy)) {
+      buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE);
       current_buddy = g_list_next(current_buddy);
+      if (chatmode)
+        buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE);
+      // We should rebuild the buddylist but not everytime
+      if (prev_st == offline)
+        buddylist_build();
       scr_DrawRoster();
     }
   }
-  // XXX We should rebuild the buddylist but perhaps not everytime?
 
   if (chatmode)
     scr_ShowBuddyWindow();
           break;
       case '\n':  // Enter
           chatmode = TRUE;
+          if (current_buddy)
+            buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE);
           if (inputLine[0] == 0) {
             scr_ShowBuddyWindow();
             break;
       case 27:  // ESC
           currentWindow = NULL;
           chatmode = FALSE;
+          if (current_buddy)
+            buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE);
           top_panel(chatPanel);
           top_panel(inputPanel);
           break;