mcabber/src/screen.c
changeset 184 b5aa2b9c425a
parent 181 4a0bde661562
child 185 e8e447a07641
equal deleted inserted replaced
183:c658c131ea10 184:b5aa2b9c425a
   248 // (Re-)Display the given chat window.
   248 // (Re-)Display the given chat window.
   249 void scr_UpdateWindow(window_entry_t *win_entry)
   249 void scr_UpdateWindow(window_entry_t *win_entry)
   250 {
   250 {
   251   int n;
   251   int n;
   252   int width;
   252   int width;
   253   char **lines;
   253   hbb_line **lines, *line;
   254   GList *hbuf_head;
   254   GList *hbuf_head;
       
   255   char date[32];
   255 
   256 
   256   width = scr_WindowWidth(win_entry->win);
   257   width = scr_WindowWidth(win_entry->win);
   257 
   258 
   258   // Should the window be empty?
   259   // Should the window be empty?
   259   if (win_entry->cleared) {
   260   if (win_entry->cleared) {
   284   lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT);
   285   lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT);
   285 
   286 
   286   // Display these lines
   287   // Display these lines
   287   for (n = 0; n < CHAT_WIN_HEIGHT; n++) {
   288   for (n = 0; n < CHAT_WIN_HEIGHT; n++) {
   288     wmove(win_entry->win, n, 0);
   289     wmove(win_entry->win, n, 0);
   289     if (*(lines+2*n)) {
   290     line = *(lines+n);
   290       if (**(lines+2*n))
   291     if (line) {
   291         wprintw(win_entry->win, "%s", *(lines+2*n));      // prefix
   292       if (line->timestamp) {
       
   293         strftime(date, 35, "%H:%M", localtime(&line->timestamp));
       
   294       } else
       
   295         strcpy(date, "     ");
       
   296       if (line->flags & HBB_PREFIX_IN)
       
   297         wprintw(win_entry->win, "[%.5s] <== ", date);
       
   298       else if (line->flags & HBB_PREFIX_OUT)
       
   299         wprintw(win_entry->win, "[%.5s] --> ", date);
   292       else {
   300       else {
   293         wprintw(win_entry->win, "            ");
   301         wprintw(win_entry->win, "            ");
   294       }
   302       }
   295       wprintw(win_entry->win, "%s", *(lines+2*n+1));      // line
   303       wprintw(win_entry->win, "%s", line->text);      // line
   296       wclrtoeol(win_entry->win);
   304       wclrtoeol(win_entry->win);
       
   305       g_free(line->text);
   297     } else {
   306     } else {
   298       wclrtobot(win_entry->win);
   307       wclrtobot(win_entry->win);
   299       break;
   308       break;
   300     }
   309     }
   301   }
   310   }
   351 
   360 
   352 //  scr_WriteInWindow()
   361 //  scr_WriteInWindow()
   353 // Write some text in the winId window (this usually is a jid).
   362 // Write some text in the winId window (this usually is a jid).
   354 // Lines are splitted when they are too long to fit in the chat window.
   363 // Lines are splitted when they are too long to fit in the chat window.
   355 // If this window doesn't exist, it is created.
   364 // If this window doesn't exist, it is created.
   356 void scr_WriteInWindow(const char *winId, const char *text, int TimeStamp,
   365 void scr_WriteInWindow(const char *winId, const char *text, time_t timestamp,
   357         const char *prefix, int force_show)
   366         unsigned int prefix_flags, int force_show)
   358 {
   367 {
   359   char *fullprefix = NULL;
       
   360   window_entry_t *win_entry;
   368   window_entry_t *win_entry;
   361   int dont_show = FALSE;
   369   int dont_show = FALSE;
   362 
       
   363   // Prepare the prefix
       
   364   if (prefix || TimeStamp) {
       
   365     if (!prefix)  prefix = "";
       
   366     fullprefix = calloc(1, strlen(prefix)+16);
       
   367     if (TimeStamp) {
       
   368       time_t now = time(NULL);
       
   369       strftime(fullprefix, 12, "[%H:%M] ", localtime(&now));
       
   370     } else {
       
   371       strcpy(fullprefix, "            ");
       
   372     }
       
   373     strcat(fullprefix, prefix);
       
   374   }
       
   375 
   370 
   376   // Look for the window entry.
   371   // Look for the window entry.
   377   win_entry = scr_SearchWindow(winId);
   372   win_entry = scr_SearchWindow(winId);
   378 
   373 
   379   // Do we have to really show the window?
   374   // Do we have to really show the window?
   385   // If the window entry doesn't exist yet, let's create it.
   380   // If the window entry doesn't exist yet, let's create it.
   386   if (win_entry == NULL) {
   381   if (win_entry == NULL) {
   387     win_entry = scr_CreateBuddyPanel(winId, dont_show);
   382     win_entry = scr_CreateBuddyPanel(winId, dont_show);
   388   }
   383   }
   389 
   384 
   390   hbuf_add_line(&win_entry->hbuf, text, fullprefix,
   385   hbuf_add_line(&win_entry->hbuf, text, timestamp, prefix_flags,
   391                 maxX - scr_WindowWidth(rosterWnd) - 14);
   386                 maxX - scr_WindowWidth(rosterWnd) - 14);
   392   free(fullprefix);
       
   393 
   387 
   394   if (win_entry->cleared) {
   388   if (win_entry->cleared) {
   395     win_entry->cleared = 0; // The message must be displayed
   389     win_entry->cleared = 0; // The message must be displayed
   396     win_entry->top = g_list_last(win_entry->hbuf);
   390     win_entry->top = g_list_last(win_entry->hbuf);
   397   }
   391   }
   659   top_panel(inputPanel);
   653   top_panel(inputPanel);
   660   update_panels();
   654   update_panels();
   661   doupdate();
   655   doupdate();
   662 }
   656 }
   663 
   657 
   664 void scr_WriteMessage(const char *jid, const char *text, char *prefix)
   658 void scr_WriteMessage(const char *jid, const char *text, time_t timestamp,
   665 {
   659         guint prefix_flags)
   666   scr_WriteInWindow(jid, text, TRUE, prefix, FALSE);
   660 {
   667 }
   661   if (!timestamp) timestamp = time(NULL);
   668 
   662 
   669 void scr_WriteIncomingMessage(const char *jidfrom, const char *text)
   663   scr_WriteInWindow(jid, text, timestamp, prefix_flags, FALSE);
       
   664 }
       
   665 
       
   666 void scr_WriteIncomingMessage(const char *jidfrom, const char *text,
       
   667         time_t timestamp)
   670 {
   668 {
   671   // FIXME expand tabs / filter out special chars...
   669   // FIXME expand tabs / filter out special chars...
   672   scr_WriteMessage(jidfrom, text, "<== ");
   670   scr_WriteMessage(jidfrom, text, timestamp, HBB_PREFIX_IN);
   673   update_panels();
   671   update_panels();
   674   doupdate();
   672   doupdate();
   675 }
   673 }
   676 
   674 
   677 void scr_WriteOutgoingMessage(const char *jidto, const char *text)
   675 void scr_WriteOutgoingMessage(const char *jidto, const char *text)
   678 {
   676 {
   679   scr_WriteMessage(jidto, text, "--> ");
   677   scr_WriteMessage(jidto, text, 0, HBB_PREFIX_OUT);
   680   scr_ShowWindow(jidto);
   678   scr_ShowWindow(jidto);
   681 }
   679 }
   682 
   680 
   683 int scr_Getch(void)
   681 int scr_Getch(void)
   684 {
   682 {