From 20a87184b1c06f63b2b3d8b9c48a68535b31b4bb Mon Sep 17 00:00:00 2001 From: ache Date: Fri, 17 Nov 2017 11:21:12 +0100 Subject: New mesms --- messageWind.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 messageWind.c (limited to 'messageWind.c') diff --git a/messageWind.c b/messageWind.c new file mode 100644 index 0000000..28eaa54 --- /dev/null +++ b/messageWind.c @@ -0,0 +1,127 @@ +#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 contactListSelection; + +int firstSMSIndex; +int canAugment = 1; + +int nbLineSMS( sms* S ); + +void toTheEnd(void) { + if( !currentConv ) + return; + + int i = currentConv->nbSMS -1, size = h_WMessage ; + char lin[200] = ""; + + for(; i > 0 && size > 0 ; i--) { + size -= nbLineSMS(¤tConv->listSMS[i]) + 2; + } + if( size > 0 ) + firstSMSIndex = 0; + else + firstSMSIndex = i+1 == currentConv->nbSMS ? i : i+1; + // 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 ...) + +} + +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; + + attrset( COLOR_PAIR( (rand()%8) + 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); + } + 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; + +} + + + + -- cgit v1.2.3-54-g00ecf