mcabber/screen.c
changeset 11 b8815158a45d
parent 9 455ab6bc14ac
child 12 70ca5b9c648a
equal deleted inserted replaced
10:3489a75cb115 11:b8815158a45d
    35 static PANEL *rosterPanel, *chatPanel, *inputPanel;
    35 static PANEL *rosterPanel, *chatPanel, *inputPanel;
    36 static PANEL *logPanel, *logPanel_border;
    36 static PANEL *logPanel, *logPanel_border;
    37 static int maxY, maxX;
    37 static int maxY, maxX;
    38 static window_entry_t *currentWindow;
    38 static window_entry_t *currentWindow;
    39 
    39 
    40 char inputLine[INPUTLINE_LENGTH];
    40 static char inputLine[INPUTLINE_LENGTH];
    41 char *ptr_inputline;
    41 static char *ptr_inputline;
    42 
    42 
    43 
    43 
    44 /* Funciones */
    44 /* Funciones */
    45 
    45 
    46 int scr_WindowHeight(WINDOW * win)
    46 int scr_WindowHeight(WINDOW * win)
   167   tmp->panel = new_panel(tmp->win);
   167   tmp->panel = new_panel(tmp->win);
   168   tmp->name = (char *) calloc(1, 1024);
   168   tmp->name = (char *) calloc(1, 1024);
   169   strncpy(tmp->name, title, 1024);
   169   strncpy(tmp->name, title, 1024);
   170 
   170 
   171   scr_draw_box(tmp->win, 0, 0, lines, cols, COLOR_GENERAL, 0, 0);
   171   scr_draw_box(tmp->win, 0, 0, lines, cols, COLOR_GENERAL, 0, 0);
   172   mvwprintw(tmp->win, 0, (cols - (2 + strlen(title))) / 2, " %s ", title);
   172   //mvwprintw(tmp->win, 0, (cols - (2 + strlen(title))) / 2, " %s ", title);
   173   if (!dont_show) {
   173   if ((!dont_show)) {
   174     currentWindow = tmp;
   174     currentWindow = tmp;
   175   } else {
   175   } else {
   176     if (currentWindow)
   176     if (currentWindow)
   177       top_panel(currentWindow->panel);
   177       top_panel(currentWindow->panel);
   178     else
   178     else
   350       mvwprintw(tmp->win, n + 1, 1, "%s", tmp->texto[n]);
   350       mvwprintw(tmp->win, n + 1, 1, "%s", tmp->texto[n]);
   351     }
   351     }
   352     //move(CHAT_WIN_HEIGHT - 1, maxX - 1);
   352     //move(CHAT_WIN_HEIGHT - 1, maxX - 1);
   353     update_panels();
   353     update_panels();
   354     doupdate();
   354     doupdate();
       
   355   } else {
       
   356     top_panel(chatPanel);
       
   357     currentWindow = tmp;
   355   }
   358   }
   356 }
   359 }
   357 
   360 
   358 void scr_ShowBuddyWindow(void)
   361 void scr_ShowBuddyWindow(void)
   359 {
   362 {
   360   buddy_entry_t *tmp = bud_SelectedInfo();
   363   buddy_entry_t *tmp = bud_SelectedInfo();
   361   if (tmp->jid != NULL)
   364   if (tmp->jid != NULL)
   362     scr_ShowWindow(tmp->jid);
   365     scr_ShowWindow(tmp->jid);
   363 }
   366   top_panel(inputPanel);
   364 
   367 }
   365 
   368 
   366 void scr_WriteInWindow(char *winId, char *texto, int TimeStamp)
   369 
       
   370 void scr_WriteInWindow(char *winId, char *texto, int TimeStamp, int force_show)
   367 {
   371 {
   368   time_t ahora;
   372   time_t ahora;
   369   int n;
   373   int n;
   370   int i;
   374   int i;
   371   int width;
   375   int width;
   373   int dont_show = FALSE;
   377   int dont_show = FALSE;
   374 
   378 
   375 
   379 
   376   tmp = scr_SearchWindow(winId);
   380   tmp = scr_SearchWindow(winId);
   377 
   381 
   378   if (!currentWindow || (currentWindow != tmp))
   382   if ((!force_show) && ((!currentWindow || (currentWindow != tmp))))
   379     dont_show = TRUE;
   383     dont_show = TRUE;
   380   scr_LogPrint("dont_show=%d", dont_show);
   384   scr_LogPrint("dont_show=%d", dont_show);
   381 
   385 
   382   if (tmp == NULL) {
   386   if (tmp == NULL) {
   383     tmp = scr_CreatePanel(winId, 20, 0, CHAT_WIN_HEIGHT, maxX - 20, dont_show);
   387     tmp = scr_CreatePanel(winId, 20, 0, CHAT_WIN_HEIGHT, maxX - 20, dont_show);
   464 	    i18n("Roster"));
   468 	    i18n("Roster"));
   465 
   469 
   466   chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - 20, 0, 20);
   470   chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - 20, 0, 20);
   467   chatPanel = new_panel(chatWnd);
   471   chatPanel = new_panel(chatWnd);
   468   scr_draw_box(chatWnd, 0, 0, CHAT_WIN_HEIGHT, maxX - 20, COLOR_GENERAL, 0, 0);
   472   scr_draw_box(chatWnd, 0, 0, CHAT_WIN_HEIGHT, maxX - 20, COLOR_GENERAL, 0, 0);
   469   mvwprintw(chatWnd, 0,
   473   //mvwprintw(chatWnd, 0,
   470 	    ((maxX - 20) - strlen(i18n("Status Window"))) / 2,
   474 	//    ((maxX - 20) - strlen(i18n("Status Window"))) / 2,
   471 	    i18n("Status Window"));
   475 	//    i18n("Status Window"));
   472   //wbkgd(chatWnd, COLOR_PAIR(COLOR_GENERAL));
   476   //wbkgd(chatWnd, COLOR_PAIR(COLOR_GENERAL));
   473 
   477 
   474   logWnd_border = newwin(LOG_WIN_HEIGHT, maxX - 20, CHAT_WIN_HEIGHT, 20);
   478   logWnd_border = newwin(LOG_WIN_HEIGHT, maxX - 20, CHAT_WIN_HEIGHT, 20);
   475   logPanel_border = new_panel(logWnd_border);
   479   logPanel_border = new_panel(logWnd_border);
   476   scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX - 20, COLOR_GENERAL, 0, 0);
   480   scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX - 20, COLOR_GENERAL, 0, 0);
   517   submsgs =
   521   submsgs =
   518       ut_SplitMessage(buffer, &n, maxX - scr_WindowHeight(rosterWnd) - 20);
   522       ut_SplitMessage(buffer, &n, maxX - scr_WindowHeight(rosterWnd) - 20);
   519 
   523 
   520   for (i = 0; i < n; i++) {
   524   for (i = 0; i < n; i++) {
   521     if (i == 0)
   525     if (i == 0)
   522       scr_WriteInWindow(jidfrom, submsgs[i], TRUE);
   526       scr_WriteInWindow(jidfrom, submsgs[i], TRUE, FALSE);
   523     else
   527     else
   524       scr_WriteInWindow(jidfrom, submsgs[i], FALSE);
   528       scr_WriteInWindow(jidfrom, submsgs[i], FALSE, FALSE);
   525   }
   529   }
   526 
   530 
   527   for (i = 0; i < n; i++)
   531   for (i = 0; i < n; i++)
   528     free(submsgs[i]);
   532     free(submsgs[i]);
   529 
   533 
   556     submsgs =
   560     submsgs =
   557 	ut_SplitMessage(buffer2, &n,
   561 	ut_SplitMessage(buffer2, &n,
   558 			maxX - scr_WindowHeight(rosterWnd) - 20);
   562 			maxX - scr_WindowHeight(rosterWnd) - 20);
   559     for (i = 0; i < n; i++) {
   563     for (i = 0; i < n; i++) {
   560       if (i == 0)
   564       if (i == 0)
   561 	scr_WriteInWindow(tmp->jid, submsgs[i], TRUE);
   565 	scr_WriteInWindow(tmp->jid, submsgs[i], TRUE, TRUE);
   562       else
   566       else
   563 	scr_WriteInWindow(tmp->jid, submsgs[i], FALSE);
   567 	scr_WriteInWindow(tmp->jid, submsgs[i], FALSE, TRUE);
   564     }
   568     }
   565 
   569 
   566     for (i = 0; i < n; i++)
   570     for (i = 0; i < n; i++)
   567       free(submsgs[i]);
   571       free(submsgs[i]);
   568     free(submsgs);
   572     free(submsgs);
   616   vsnprintf(buffer, 4096, fmt, ap);
   620   vsnprintf(buffer, 4096, fmt, ap);
   617   va_end(ap);
   621   va_end(ap);
   618 
   622 
   619   wprintw(logWnd, "%s", buffer);
   623   wprintw(logWnd, "%s", buffer);
   620   free(buffer);
   624   free(buffer);
       
   625 
       
   626   update_panels();
       
   627   doupdate();
   621 }
   628 }
   622 
   629 
   623 
   630 
   624 void send_message(int sock, char *msg)
   631 void send_message(int sock, char *msg)
   625 {
   632 {
   636   submsgs =
   643   submsgs =
   637 	ut_SplitMessage(buffer, &n,
   644 	ut_SplitMessage(buffer, &n,
   638 			maxX - scr_WindowHeight(rosterWnd) - 20);
   645 			maxX - scr_WindowHeight(rosterWnd) - 20);
   639   for (i = 0; i < n; i++) {
   646   for (i = 0; i < n; i++) {
   640     if (i == 0)
   647     if (i == 0)
   641       scr_WriteInWindow(tmp->jid, submsgs[i], TRUE);
   648       scr_WriteInWindow(tmp->jid, submsgs[i], TRUE, TRUE);
   642     else
   649     else
   643       scr_WriteInWindow(tmp->jid, submsgs[i], FALSE);
   650       scr_WriteInWindow(tmp->jid, submsgs[i], FALSE, TRUE);
   644   }
   651   }
   645 
   652 
   646   for (i = 0; i < n; i++)
   653   for (i = 0; i < n; i++)
   647     free(submsgs[i]);
   654     free(submsgs[i]);
   648   free(submsgs);
   655   free(submsgs);
   715           *ptr_inputline = 0;
   722           *ptr_inputline = 0;
   716           break;
   723           break;
   717       case KEY_UP:
   724       case KEY_UP:
   718           bud_RosterUp();
   725           bud_RosterUp();
   719           scr_ShowBuddyWindow();
   726           scr_ShowBuddyWindow();
   720           top_panel(inputPanel);
       
   721           break;
   727           break;
   722       case KEY_DOWN:
   728       case KEY_DOWN:
   723           bud_RosterDown();
   729           bud_RosterDown();
   724           scr_ShowBuddyWindow();
   730           scr_ShowBuddyWindow();
   725           top_panel(inputPanel);
       
   726           break;
   731           break;
   727       case KEY_PPAGE:
   732       case KEY_PPAGE:
   728           scr_LogPrint("PageUp??");
   733           scr_LogPrint("PageUp??");
   729           break;
   734           break;
   730       case KEY_NPAGE:
   735       case KEY_NPAGE: