#include #include #include #include "contactWind.h" extern contact* contactList; extern size_t nbContacts; int x_menuContact = 1,y_menuContact = 1; int w_menuContact,h_menuContact; int contactListSelection; int firstConctactShow; int showName = 1; contact* getContactSelected(void) { return contactListSelection+contactList; } void selectNextContact(void) { if( contactListSelection < nbContacts - 1) contactListSelection++; } void setContactSelection(contact* c) { int i = c - contactList ; int h = h_menuContact; if( i >= 0 && i < nbContacts ) contactListSelection = i; while( contactListSelection < firstConctactShow ) { firstConctactShow-=h/2; if( firstConctactShow < 0 ) firstConctactShow = 0; } while( contactListSelection >= firstConctactShow + h ) { firstConctactShow+=h/2; if( firstConctactShow > nbContacts-1 ) firstConctactShow = nbContacts-1; } } void selectPreviousContact(void) { if( contactListSelection > 0) contactListSelection--; } void clearContactListW(void) { for(int i = firstConctactShow; i < h_menuContact && i < nbContacts; i++) { move(y_menuContact+i,x_menuContact); printw("%*s", w_menuContact, " "); } } void showLineContactW(contact* c, int x, int y, int i, char* tmp) { int nbMessage = 0, isLastToRespond = 0, hasNewMessage = 0; char dateLastSMS[5] = ""; time_t now_s = time(NULL); struct tm *now = localtime(&now_s); int color = 0, attr = A_NORMAL; if( c->conversation ) { attr |= A_BOLD; sms* lastSMS = &c->conversation->listSMS[c->conversation->nbSMS-1]; struct tm* dateOut = localtime(&lastSMS->outDate); hasNewMessage = lastSMS->state == SMS_UNREAD; isLastToRespond = !lastSMS->in_out; nbMessage = c->conversation->nbSMS; if( dateOut->tm_year == now->tm_year ) { sprintf(dateLastSMS, "%02d/%02d", dateOut->tm_mday, dateOut->tm_mon + 1); } else { sprintf(dateLastSMS, " %04d", dateOut->tm_year); } } if( i == contactListSelection ) { attr |= A_REVERSE; } attrset( COLOR_PAIR(color) | attr); move(y,0); printw("%*s", w_menuContact+1, ""); // First of all isLastToRespond ! if( isLastToRespond && *c->number == '+' && *c->display_name != '+') { attrset( COLOR_PAIR( 11 ) | attr ); mvprintc(0,y," ", 1); attrset( COLOR_PAIR(color) | attr); } // Then contact name if( showName ) mvprintc(x,y, contactList[i].display_name, w_menuContact-10); else mvprintc(x,y,contactList[i].number, w_menuContact-10); // Date if( *dateLastSMS ) { attrset( COLOR_PAIR(5) | attr ); mvprintc(x + w_menuContact - 5,y, dateLastSMS, 5); attrset( COLOR_PAIR(color) | attr); } // Then nb message int r = 0; if( nbMessage > 0 ) { attrset( COLOR_PAIR(6) | attr); r = sprintf(tmp, "%d", nbMessage); mvprintc(x + w_menuContact - 6 - r,y, tmp, 5); attrset( COLOR_PAIR(color) | attr); } // Then new message notification Ne if( hasNewMessage ) { move(y,x + w_menuContact - 8 - r ); printw("✉️"); } y++; attrset(0 | A_NORMAL); } void showContactListW(void) { int x = x_menuContact; int y = y_menuContact; int w = w_menuContact; int h = h_menuContact; int s = nbContacts; if( contactListSelection < firstConctactShow ) { firstConctactShow-=h/2; if( firstConctactShow < 0 ) firstConctactShow = 0; } if( contactListSelection >= firstConctactShow + h ) { attrset(0 | A_NORMAL ); firstConctactShow+=h/2; if( firstConctactShow > nbContacts-1 ) firstConctactShow = nbContacts-1; } char* line = malloc( w+1 ); int i; for(i = firstConctactShow ; i < (h+firstConctactShow) && i < s ; i++) { showLineContactW(contactList+i, x, y+i-firstConctactShow, i, line); } for( ; i < (h+firstConctactShow) ; i++){ // Clear move(y+i-firstConctactShow,0); printw("%*s", w+1, ""); } free(line); }