From 87b760a65a78c5496c8807b328f756868c01dd28 Mon Sep 17 00:00:00 2001 From: ache Date: Sat, 19 Jan 2019 10:27:59 +0100 Subject: Stat in contactWind --- contactWind.c | 108 ++++++++++++++++++++++++++++++++++++++++++---------------- main.c | 4 +++ 2 files changed, 83 insertions(+), 29 deletions(-) diff --git a/contactWind.c b/contactWind.c index 7d47a62..8a3f46c 100644 --- a/contactWind.c +++ b/contactWind.c @@ -1,5 +1,6 @@ #include #include +#include #include "contactWind.h" @@ -20,20 +21,15 @@ contact* getContactSelected(void) { return contactListSelection+contactList; } - void selectNextContact(void) { if( contactListSelection < nbContacts - 1) contactListSelection++; - clearContactListW(); } void selectPreviousContact(void) { if( contactListSelection > 0) contactListSelection--; - clearContactListW(); } - - void clearContactListW(void) { for(int i = firstConctactShow; i < h_menuContact && i < nbContacts; i++) { move(y_menuContact+i,x_menuContact); @@ -41,6 +37,77 @@ void clearContactListW(void) { } } +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; + 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) { @@ -54,8 +121,6 @@ void showContactListW(void) { firstConctactShow-=h/2; if( firstConctactShow < 0 ) firstConctactShow = 0; - - clearContactListW(); } if( contactListSelection >= firstConctactShow + h ) { @@ -63,36 +128,21 @@ void showContactListW(void) { firstConctactShow+=h/2; if( firstConctactShow > nbContacts-1 ) firstConctactShow = nbContacts-1; - - clearContactListW(); } + char* line = malloc( w+1 ); int i; for(i = firstConctactShow ; i < (h+firstConctactShow) && i < s ; i++) { - int color = 0, attr = A_NORMAL; - - if( contactList[i].conversation ) - attr |= A_BOLD; - if( i == contactListSelection ) { - attr |= A_REVERSE; - } - - attrset( COLOR_PAIR(color) | attr); - move(y,x); - printw("%*s", w, " "); - - if( showName ) - mvprintc(x,y++,contactList[i].display_name, w); - else - mvprintc(x,y++,contactList[i].number, w); - - attrset(0 | A_NORMAL); + showLineContactW(contactList+i, x, y+i-firstConctactShow, i, line); } + for( ; i < (h+firstConctactShow) ; i++){ // Clear - move(y++,x); - printw("%*s", w, " "); + move(y+i-firstConctactShow,0); + printw("%*s", w+1, ""); } + + free(line); } diff --git a/main.c b/main.c index 57b86b8..b4fec25 100644 --- a/main.c +++ b/main.c @@ -162,6 +162,10 @@ int main(int argc, char* argv[]){ init_pair( 12, COLOR_WHITE, COLOR_BLUE); + + init_pair( 11, COLOR_RED, COLOR_RED); + init_pair( 10, COLOR_GREEN, COLOR_GREEN); + CHECK(wbkgd, sep_win, COLOR_PAIR(12)); CHECK(wrefresh, sep_win); init_readline(); -- cgit v1.2.3