mcabber/src/screen.c
changeset 713 b5aa7b7afee8
parent 712 e1639629c87b
child 714 4bcd48f6ca5f
equal deleted inserted replaced
712:e1639629c87b 713:b5aa7b7afee8
   523     roster_msg_setflag(winId, TRUE);
   523     roster_msg_setflag(winId, TRUE);
   524     update_roster = TRUE;
   524     update_roster = TRUE;
   525   }
   525   }
   526 }
   526 }
   527 
   527 
       
   528 //  scr_UpdateMainStatus()
       
   529 // Redraw the main (bottom) status line.
       
   530 void scr_UpdateMainStatus(void)
       
   531 {
       
   532   const char *sm = jb_getstatusmsg();
       
   533 
       
   534   werase(mainstatusWnd);
       
   535   mvwprintw(mainstatusWnd, 0, 1,
       
   536             "[%c] %s", imstatus2char[jb_getstatus()], (sm ? sm : ""));
       
   537   top_panel(inputPanel);
       
   538   update_panels();
       
   539   doupdate();
       
   540 }
       
   541 
   528 //  scr_DrawMainWindow()
   542 //  scr_DrawMainWindow()
   529 // Set fullinit to TRUE to also create panels.  Set it to FALSE for a resize.
   543 // Set fullinit to TRUE to also create panels.  Set it to FALSE for a resize.
   530 //
   544 //
   531 // I think it could be improved a _lot_ but I'm really not an ncurses
   545 // I think it could be improved a _lot_ but I'm really not an ncurses
   532 // expert... :-\   Mikael.
   546 // expert... :-\   Mikael.
   639     replace_panel(chatstatusPanel, chatstatusWnd);
   653     replace_panel(chatstatusPanel, chatstatusWnd);
   640     replace_panel(mainstatusPanel, mainstatusWnd);
   654     replace_panel(mainstatusPanel, mainstatusWnd);
   641     replace_panel(inputPanel, inputWnd);
   655     replace_panel(inputPanel, inputWnd);
   642   }
   656   }
   643 
   657 
       
   658   scr_UpdateMainStatus();
   644   // We'll need to redraw the roster
   659   // We'll need to redraw the roster
   645   update_roster = TRUE;
   660   update_roster = TRUE;
   646   return;
   661   return;
   647 }
   662 }
   648 
   663 
   699   // Refresh current buddy window
   714   // Refresh current buddy window
   700   if (chatmode)
   715   if (chatmode)
   701     scr_ShowBuddyWindow();
   716     scr_ShowBuddyWindow();
   702 }
   717 }
   703 
   718 
       
   719 //  update_chat_status_window()
       
   720 // Redraw the buddy status bar.
       
   721 static void update_chat_status_window(void)
       
   722 {
       
   723     unsigned short btype, isgrp, ismuc;
       
   724     const char *fullname;
       
   725     const char *msg = NULL;
       
   726     char status;
       
   727     char *buf;
       
   728 
       
   729     btype = buddy_gettype(BUDDATA(current_buddy));
       
   730 
       
   731     isgrp = btype & ROSTER_TYPE_GROUP;
       
   732     ismuc = btype & ROSTER_TYPE_ROOM;
       
   733 
       
   734     // Clear the line
       
   735     werase(chatstatusWnd);
       
   736 
       
   737     if (isgrp) return;
       
   738 
       
   739     status = '?';
       
   740 
       
   741     if (ismuc) {
       
   742       if (buddy_getinsideroom(BUDDATA(current_buddy)))
       
   743         status = 'C';
       
   744       else
       
   745         status = 'x';
       
   746     } else if (jb_getstatus() != offline) {
       
   747       enum imstatus budstate;
       
   748       budstate = buddy_getstatus(BUDDATA(current_buddy), NULL);
       
   749       if (budstate >= 0 && budstate < imstatus_size)
       
   750         status = imstatus2char[budstate];
       
   751     }
       
   752 
       
   753     fullname = buddy_getname(BUDDATA(current_buddy));
       
   754 
       
   755     // No status message for groups & MUC rooms
       
   756     if (!isgrp && !ismuc) {
       
   757       GSList *resources = buddy_getresources(BUDDATA(current_buddy));
       
   758       if (resources)
       
   759         msg = buddy_getstatusmsg(BUDDATA(current_buddy), resources->data);
       
   760     }
       
   761     if (!msg)
       
   762       msg = "";
       
   763 
       
   764     buf = g_strdup_printf("[%c] Buddy: %s -- %s", status, fullname, msg);
       
   765     replace_nl_with_dots(buf);
       
   766     mvwprintw(chatstatusWnd, 0, 1, "%s", buf);
       
   767     g_free(buf);
       
   768 }
       
   769 
   704 //  scr_DrawRoster()
   770 //  scr_DrawRoster()
   705 // Display the buddylist (not really the roster) on the screen
   771 // Display the buddylist (not really the roster) on the screen
   706 void scr_DrawRoster(void)
   772 void scr_DrawRoster(void)
   707 {
   773 {
   708   static guint offset = 0;
   774   static guint offset = 0;
   709   char *name, *rline;
   775   char *name, *rline;
   710   int maxx, maxy;
   776   int maxx, maxy;
   711   GList *buddy;
   777   GList *buddy;
   712   int i, n;
   778   int i, n;
   713   int rOffset;
   779   int rOffset;
       
   780   int cursor_backup;
       
   781   char status, pending;
   714   enum imstatus currentstatus = jb_getstatus();
   782   enum imstatus currentstatus = jb_getstatus();
   715 
   783 
   716   // We can reset update_roster
   784   // We can reset update_roster
   717   update_roster = FALSE;
   785   update_roster = FALSE;
   718 
   786 
   719   getmaxyx(rosterWnd, maxy, maxx);
   787   getmaxyx(rosterWnd, maxy, maxx);
   720   maxx--;  // Last char is for vertical border
   788   maxx--;  // Last char is for vertical border
       
   789 
       
   790   cursor_backup = curs_set(0);
   721 
   791 
   722   // Cleanup of roster window
   792   // Cleanup of roster window
   723   werase(rosterWnd);
   793   werase(rosterWnd);
   724 
   794 
   725   if (Roster_Width) {
   795   if (Roster_Width) {
   729       mvwaddch(rosterWnd, i, Roster_Width-1, ACS_VLINE);
   799       mvwaddch(rosterWnd, i, Roster_Width-1, ACS_VLINE);
   730   }
   800   }
   731 
   801 
   732   if (!buddylist)
   802   if (!buddylist)
   733     offset = 0;
   803     offset = 0;
       
   804   else
       
   805     update_chat_status_window();
   734 
   806 
   735   // Leave now if buddylist is empty or the roster is hidden
   807   // Leave now if buddylist is empty or the roster is hidden
   736   if (!buddylist || !Roster_Width) {
   808   if (!buddylist || !Roster_Width) {
   737     update_panels();
   809     update_panels();
   738     doupdate();
   810     doupdate();
       
   811     curs_set(cursor_backup);
   739     return;
   812     return;
   740   }
   813   }
   741 
   814 
   742   name = g_new0(char, Roster_Width);
   815   name = g_new0(char, Roster_Width);
   743 
   816 
   751   // b) Make sure the current_buddy is visible
   824   // b) Make sure the current_buddy is visible
   752   i = g_list_position(buddylist, current_buddy);
   825   i = g_list_position(buddylist, current_buddy);
   753   if (i == -1) { // This is bad
   826   if (i == -1) { // This is bad
   754     scr_LogPrint(LPRINT_NORMAL, "Doh! Can't find current selected buddy!!");
   827     scr_LogPrint(LPRINT_NORMAL, "Doh! Can't find current selected buddy!!");
   755     g_free(name);
   828     g_free(name);
       
   829     curs_set(cursor_backup);
   756     return;
   830     return;
   757   } else if (i < offset) {
   831   } else if (i < offset) {
   758     offset = i;
   832     offset = i;
   759   } else if (i+1 > offset + maxy) {
   833   } else if (i+1 > offset + maxy) {
   760     offset = i + 1 - maxy;
   834     offset = i + 1 - maxy;
   764 
   838 
   765   buddy = buddylist;
   839   buddy = buddylist;
   766   rOffset = offset;
   840   rOffset = offset;
   767 
   841 
   768   for (i=0; i<maxy && buddy; buddy = g_list_next(buddy)) {
   842   for (i=0; i<maxy && buddy; buddy = g_list_next(buddy)) {
   769     char status = '?';
   843     unsigned short bflags, btype, ismsg, isgrp, ismuc, ishid;
   770     char pending = ' ';
   844 
   771     enum imstatus budstate;
   845     bflags = buddy_getflags(BUDDATA(buddy));
   772     unsigned short ismsg = buddy_getflags(BUDDATA(buddy)) & ROSTER_FLAG_MSG;
   846     btype = buddy_gettype(BUDDATA(buddy));
   773     unsigned short isgrp = buddy_gettype(BUDDATA(buddy)) & ROSTER_TYPE_GROUP;
   847 
   774     unsigned short ismuc = buddy_gettype(BUDDATA(buddy)) & ROSTER_TYPE_ROOM;
   848     ismsg = bflags & ROSTER_FLAG_MSG;
   775     unsigned short ishid = buddy_getflags(BUDDATA(buddy)) & ROSTER_FLAG_HIDE;
   849     ishid = bflags & ROSTER_FLAG_HIDE;
       
   850     isgrp = btype  & ROSTER_TYPE_GROUP;
       
   851     ismuc = btype  & ROSTER_TYPE_ROOM;
   776 
   852 
   777     if (rOffset > 0) {
   853     if (rOffset > 0) {
   778       rOffset--;
   854       rOffset--;
   779       continue;
   855       continue;
   780     }
   856     }
       
   857 
       
   858     status = '?';
       
   859     pending = ' ';
   781 
   860 
   782     // Display message notice if there is a message flag, but not
   861     // Display message notice if there is a message flag, but not
   783     // for unfolded groups.
   862     // for unfolded groups.
   784     if (ismsg && (!isgrp || ishid)) {
   863     if (ismsg && (!isgrp || ishid)) {
   785       pending = '#';
   864       pending = '#';
   786     }
   865     }
   787 
   866 
   788     budstate = buddy_getstatus(BUDDATA(buddy), NULL);
   867     if (ismuc) {
   789     if (budstate >= 0 && budstate < imstatus_size && currentstatus != offline)
   868       if (buddy_getinsideroom(BUDDATA(buddy)))
   790       status = imstatus2char[budstate];
   869         status = 'C';
       
   870       else
       
   871         status = 'x';
       
   872     } else if (currentstatus != offline) {
       
   873       enum imstatus budstate;
       
   874       budstate = buddy_getstatus(BUDDATA(buddy), NULL);
       
   875       if (budstate >= 0 && budstate < imstatus_size)
       
   876         status = imstatus2char[budstate];
       
   877     }
   791     if (buddy == current_buddy) {
   878     if (buddy == current_buddy) {
   792       wattrset(rosterWnd, COLOR_PAIR(COLOR_ROSTERSEL));
   879       wattrset(rosterWnd, COLOR_PAIR(COLOR_ROSTERSEL));
   793       // The 3 following lines aim to color the whole line
   880       // The 3 following lines aim to color the whole line
   794       wmove(rosterWnd, i, 0);
   881       wmove(rosterWnd, i, 0);
   795       for (n = 0; n < maxx; n++)
   882       for (n = 0; n < maxx; n++)
   799         wattrset(rosterWnd, COLOR_PAIR(COLOR_ROSTERNMSG));
   886         wattrset(rosterWnd, COLOR_PAIR(COLOR_ROSTERNMSG));
   800       else
   887       else
   801         wattrset(rosterWnd, COLOR_PAIR(COLOR_ROSTER));
   888         wattrset(rosterWnd, COLOR_PAIR(COLOR_ROSTER));
   802     }
   889     }
   803 
   890 
   804     if (ismuc) {
       
   805       if (buddy_getinsideroom(BUDDATA(buddy)))
       
   806         status = 'C';
       
   807       else
       
   808         status = 'x';
       
   809     }
       
   810 
       
   811     if (Roster_Width > 7)
   891     if (Roster_Width > 7)
   812       strncpy(name, buddy_getname(BUDDATA(buddy)), Roster_Width-7);
   892       strncpy(name, buddy_getname(BUDDATA(buddy)), Roster_Width-7);
   813     else
   893     else
   814       name[0] = 0;
   894       name[0] = 0;
   815 
   895 
   831   g_free(rline);
   911   g_free(rline);
   832   g_free(name);
   912   g_free(name);
   833   top_panel(inputPanel);
   913   top_panel(inputPanel);
   834   update_panels();
   914   update_panels();
   835   doupdate();
   915   doupdate();
       
   916   curs_set(cursor_backup);
   836 }
   917 }
   837 
   918 
   838 //  scr_RosterVisibility(status)
   919 //  scr_RosterVisibility(status)
   839 // Set the roster visibility:
   920 // Set the roster visibility:
   840 // status=1   Show roster
   921 // status=1   Show roster