changeset 713:b5aa7b7afee8

Update status lines
author Mikael Berthe <mikael@lilotux.net>
date Sat, 04 Mar 2006 18:55:54 +0100
parents e1639629c87b
children 4bcd48f6ca5f
files mcabber/src/jabglue.c mcabber/src/screen.c mcabber/src/screen.h
diffstat 3 files changed, 102 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/jabglue.c	Sat Mar 04 18:52:29 2006 +0100
+++ b/mcabber/src/jabglue.c	Sat Mar 04 18:55:54 2006 +0100
@@ -382,6 +382,9 @@
     else
       mystatusmsg = NULL;
   }
+
+  // Update status line
+  scr_UpdateMainStatus();
 }
 
 void jb_send_msg(const char *jid, const char *text, int type,
--- a/mcabber/src/screen.c	Sat Mar 04 18:52:29 2006 +0100
+++ b/mcabber/src/screen.c	Sat Mar 04 18:55:54 2006 +0100
@@ -525,6 +525,20 @@
   }
 }
 
+//  scr_UpdateMainStatus()
+// Redraw the main (bottom) status line.
+void scr_UpdateMainStatus(void)
+{
+  const char *sm = jb_getstatusmsg();
+
+  werase(mainstatusWnd);
+  mvwprintw(mainstatusWnd, 0, 1,
+            "[%c] %s", imstatus2char[jb_getstatus()], (sm ? sm : ""));
+  top_panel(inputPanel);
+  update_panels();
+  doupdate();
+}
+
 //  scr_DrawMainWindow()
 // Set fullinit to TRUE to also create panels.  Set it to FALSE for a resize.
 //
@@ -641,6 +655,7 @@
     replace_panel(inputPanel, inputWnd);
   }
 
+  scr_UpdateMainStatus();
   // We'll need to redraw the roster
   update_roster = TRUE;
   return;
@@ -701,6 +716,57 @@
     scr_ShowBuddyWindow();
 }
 
+//  update_chat_status_window()
+// Redraw the buddy status bar.
+static void update_chat_status_window(void)
+{
+    unsigned short btype, isgrp, ismuc;
+    const char *fullname;
+    const char *msg = NULL;
+    char status;
+    char *buf;
+
+    btype = buddy_gettype(BUDDATA(current_buddy));
+
+    isgrp = btype & ROSTER_TYPE_GROUP;
+    ismuc = btype & ROSTER_TYPE_ROOM;
+
+    // Clear the line
+    werase(chatstatusWnd);
+
+    if (isgrp) return;
+
+    status = '?';
+
+    if (ismuc) {
+      if (buddy_getinsideroom(BUDDATA(current_buddy)))
+        status = 'C';
+      else
+        status = 'x';
+    } else if (jb_getstatus() != offline) {
+      enum imstatus budstate;
+      budstate = buddy_getstatus(BUDDATA(current_buddy), NULL);
+      if (budstate >= 0 && budstate < imstatus_size)
+        status = imstatus2char[budstate];
+    }
+
+    fullname = buddy_getname(BUDDATA(current_buddy));
+
+    // No status message for groups & MUC rooms
+    if (!isgrp && !ismuc) {
+      GSList *resources = buddy_getresources(BUDDATA(current_buddy));
+      if (resources)
+        msg = buddy_getstatusmsg(BUDDATA(current_buddy), resources->data);
+    }
+    if (!msg)
+      msg = "";
+
+    buf = g_strdup_printf("[%c] Buddy: %s -- %s", status, fullname, msg);
+    replace_nl_with_dots(buf);
+    mvwprintw(chatstatusWnd, 0, 1, "%s", buf);
+    g_free(buf);
+}
+
 //  scr_DrawRoster()
 // Display the buddylist (not really the roster) on the screen
 void scr_DrawRoster(void)
@@ -711,6 +777,8 @@
   GList *buddy;
   int i, n;
   int rOffset;
+  int cursor_backup;
+  char status, pending;
   enum imstatus currentstatus = jb_getstatus();
 
   // We can reset update_roster
@@ -719,6 +787,8 @@
   getmaxyx(rosterWnd, maxy, maxx);
   maxx--;  // Last char is for vertical border
 
+  cursor_backup = curs_set(0);
+
   // Cleanup of roster window
   werase(rosterWnd);
 
@@ -731,11 +801,14 @@
 
   if (!buddylist)
     offset = 0;
+  else
+    update_chat_status_window();
 
   // Leave now if buddylist is empty or the roster is hidden
   if (!buddylist || !Roster_Width) {
     update_panels();
     doupdate();
+    curs_set(cursor_backup);
     return;
   }
 
@@ -753,6 +826,7 @@
   if (i == -1) { // This is bad
     scr_LogPrint(LPRINT_NORMAL, "Doh! Can't find current selected buddy!!");
     g_free(name);
+    curs_set(cursor_backup);
     return;
   } else if (i < offset) {
     offset = i;
@@ -766,28 +840,41 @@
   rOffset = offset;
 
   for (i=0; i<maxy && buddy; buddy = g_list_next(buddy)) {
-    char status = '?';
-    char pending = ' ';
-    enum imstatus budstate;
-    unsigned short ismsg = buddy_getflags(BUDDATA(buddy)) & ROSTER_FLAG_MSG;
-    unsigned short isgrp = buddy_gettype(BUDDATA(buddy)) & ROSTER_TYPE_GROUP;
-    unsigned short ismuc = buddy_gettype(BUDDATA(buddy)) & ROSTER_TYPE_ROOM;
-    unsigned short ishid = buddy_getflags(BUDDATA(buddy)) & ROSTER_FLAG_HIDE;
+    unsigned short bflags, btype, ismsg, isgrp, ismuc, ishid;
+
+    bflags = buddy_getflags(BUDDATA(buddy));
+    btype = buddy_gettype(BUDDATA(buddy));
+
+    ismsg = bflags & ROSTER_FLAG_MSG;
+    ishid = bflags & ROSTER_FLAG_HIDE;
+    isgrp = btype  & ROSTER_TYPE_GROUP;
+    ismuc = btype  & ROSTER_TYPE_ROOM;
 
     if (rOffset > 0) {
       rOffset--;
       continue;
     }
 
+    status = '?';
+    pending = ' ';
+
     // Display message notice if there is a message flag, but not
     // for unfolded groups.
     if (ismsg && (!isgrp || ishid)) {
       pending = '#';
     }
 
-    budstate = buddy_getstatus(BUDDATA(buddy), NULL);
-    if (budstate >= 0 && budstate < imstatus_size && currentstatus != offline)
-      status = imstatus2char[budstate];
+    if (ismuc) {
+      if (buddy_getinsideroom(BUDDATA(buddy)))
+        status = 'C';
+      else
+        status = 'x';
+    } else if (currentstatus != offline) {
+      enum imstatus budstate;
+      budstate = buddy_getstatus(BUDDATA(buddy), NULL);
+      if (budstate >= 0 && budstate < imstatus_size)
+        status = imstatus2char[budstate];
+    }
     if (buddy == current_buddy) {
       wattrset(rosterWnd, COLOR_PAIR(COLOR_ROSTERSEL));
       // The 3 following lines aim to color the whole line
@@ -801,13 +888,6 @@
         wattrset(rosterWnd, COLOR_PAIR(COLOR_ROSTER));
     }
 
-    if (ismuc) {
-      if (buddy_getinsideroom(BUDDATA(buddy)))
-        status = 'C';
-      else
-        status = 'x';
-    }
-
     if (Roster_Width > 7)
       strncpy(name, buddy_getname(BUDDATA(buddy)), Roster_Width-7);
     else
@@ -833,6 +913,7 @@
   top_panel(inputPanel);
   update_panels();
   doupdate();
+  curs_set(cursor_backup);
 }
 
 //  scr_RosterVisibility(status)
--- a/mcabber/src/screen.h	Sat Mar 04 18:52:29 2006 +0100
+++ b/mcabber/src/screen.h	Sat Mar 04 18:55:54 2006 +0100
@@ -28,6 +28,7 @@
 void scr_TerminateCurses(void);
 void scr_DrawMainWindow(unsigned int fullinit);
 void scr_DrawRoster(void);
+void scr_UpdateMainStatus(void);
 void scr_RosterVisibility(int status);
 void scr_WriteIncomingMessage(const char *jidfrom, const char *text,
         time_t timestamp, guint prefix);