#include #include #include "messageWind.h" extern contact* contactList; extern size_t nbContacts; conversation* currentConv; int x_WMessage = 1,y_WMessage = 1; int w_WMessage,h_WMessage; int firstSMSIndex; int canAugment = 1; int nbLineSMS( sms* S ); void toTheEnd(void) { if( !currentConv ) return; int i = currentConv->nbSMS -1, size = h_WMessage + 1; for(; i > 0 && size >= 0 ; i--,size--) { size -= nbLineSMS(¤tConv->listSMS[i]) + 1; } if( size > 0 ) firstSMSIndex = 0; else firstSMSIndex = /*(i+1 == currentConv->nbSMS) ? i :*/ i+2; // Seriously ... It can happen only if a SMS is greater than // the windows size ... We simply show the begin of the SMS without // the end. (Yeah, fuck this ...) canAugment = 0; } int nbLineSMS( sms* S ) { int w_WMessageSMS = w_WMessage-COLS/5; int x = 0,y = 0, iS=0; while( S->text[iS] ) { x = 0; while( x < w_WMessageSMS-1 && S->text[iS]) { if( S->text[iS] == '\n' ) { iS++; break; } x++,iS++; } y++; } return y; } int show1SMS(sms* S, int y_base, int* hasFinish) { int w_WMessageSMS = w_WMessage-COLS/5; int x = 0,y = 0, iS=0; int x_base = x_WMessage + (S->in_out == SMS_IN ? 0 : COLS/5) + 1; char line[w_WMessageSMS]; memset(line, 0, w_WMessageSMS); *hasFinish = 1; int nbColors = 8 - 1; attrset( COLOR_PAIR( (rand() % nbColors) + 1) | A_BOLD); while( S->text[iS] ) { x = 0; while( x < w_WMessageSMS-1 && S->text[iS]) { if( S->text[iS] == '\n' ) { iS++; break; } line[x++] = S->text[iS++]; } line[x] = 0; if( y+1+y_base >= y_WMessage + h_WMessage -1 ) { *hasFinish = 0; break; } y++; move(y+y_base, x_base); printw("%s", line); } S->state = SMS_READ; move(y+y_base+1, x_base); attrset( COLOR_PAIR( 0 ) | A_NORMAL); printw("\t\tOn %s", ctime(&S->outDate)); return y+1; } void clearWind(void) { for(int i = 0; i < h_WMessage ; i++) { move(y_WMessage+i,x_WMessage); printw("%*s", w_WMessage, " "); } } void showMessageWind(void) { if( !currentConv ) return; int y = 0; int smsIndex = firstSMSIndex; int hasFinish = 0; while( y < h_WMessage && smsIndex < currentConv->nbSMS) { // mvprintc(50, 50, "Hello", 30); if( currentConv->listSMS[smsIndex].in_out == SMS_IN ) move(y+y_WMessage,x_WMessage); else move(y+y_WMessage,x_WMessage+COLS/5); int ty = show1SMS(currentConv->listSMS + smsIndex, y, &hasFinish); //mvprintc(x_WMessage, y + y_WMessage, currentConv->listSMS[0].text, w_WMessage); y+=ty+1; smsIndex++; } if( hasFinish && !(smsIndex < currentConv->nbSMS) ) canAugment = 0; } int searchSMS( const char* toSearch ) { if( !currentConv ) return -1; for(int i = firstSMSIndex - 1; i >= 0 ; --i) { if(strstr(currentConv->listSMS[i].text, toSearch) != NULL) return i; } return -1; }