From 20a87184b1c06f63b2b3d8b9c48a68535b31b4bb Mon Sep 17 00:00:00 2001 From: ache Date: Fri, 17 Nov 2017 11:21:12 +0100 Subject: New mesms --- contactList.c | 109 +++++++++++++++++++++------------------------------------- 1 file changed, 40 insertions(+), 69 deletions(-) (limited to 'contactList.c') diff --git a/contactList.c b/contactList.c index dd655ca..b6d9385 100644 --- a/contactList.c +++ b/contactList.c @@ -6,31 +6,49 @@ contact* contactList; size_t nbContacts; -int x_menuContact = 1,y_menuContact = 1; -int w_menuContact,h_menuContact; +int findContact(const char* number, contact** out) { + if( !number || !out ) + return 1; -int contactListSelection; -int firstConctactShow; + for(int i = 0 ; i < nbContacts ; i++) { + if( !strcmp(number, contactList[i].number) ) { + *out = contactList+i; + return 0; + } + } + return 2; +} +int cmpContact(const void* a, const void* b) { + contact* A = (contact*)a; + contact* B = (contact*)b; + conversation* convA = ((conversation*)A->conversation); + conversation* convB = ((conversation*)B->conversation); + if( !convA && !convB ) { + return strcmp(A->display_name, B->display_name); + } else if( !convA ) { + return 1; + } else if (!convB ) { + return -1; + } else { + sms* lastA = &convA->listSMS[convA->nbSMS-1]; + sms* lastB = &convB->listSMS[convB->nbSMS-1]; -void selectNextContact(void) { - if( contactListSelection < nbContacts - 1) - contactListSelection++; - clearContactListW(); + return lastB->outDate - lastA->outDate; + } } -void selectPreviousContact(void) { - if( contactListSelection > 0) - contactListSelection--; - clearContactListW(); + +void sortContacts(void) { + qsort(contactList, nbContacts, sizeof *contactList, cmpContact); } -int findContact(const char* number, contact** out) { - if( !number || !out ) +int findContactFromName(const char* name, contact** out) { + if( !name || !out || !*name) return 1; for(int i = 0 ; i < nbContacts ; i++) { - if( !strcmp(number, contactList[i].number) ) { + if( strstr(contactList[i].display_name, name) ) { *out = contactList+i; return 0; } @@ -38,13 +56,13 @@ int findContact(const char* number, contact** out) { return 2; } -void clearContactListW(void) { - for(int i = firstConctactShow; i < h_menuContact && i < nbContacts; i++) { - move(y_menuContact+i,x_menuContact); - printw("%*s", w_menuContact, " "); - } +int addContact(const contact* cnct) { + nbContacts++; + contactList = realloc(contactList, nbContacts * sizeof *contactList); + memcpy(&contactList[nbContacts-1],cnct, sizeof *cnct); } + int fillContactList(char* filename) { FILE* file = fopen(filename, "r"); @@ -83,6 +101,7 @@ int fillContactList(char* filename) { int nameLength, numberLength, display_nameLength, i; nameLength = numberLength = display_nameLength = i = 0; contactList[0].hasNewMessage = 0; + contactList[0].conversation = NULL; while( (c = fgetc(file)) != EOF ) { if( c == ';' ) { v++; @@ -105,6 +124,7 @@ int fillContactList(char* filename) { numberLength = 0; i++; contactList[i].hasNewMessage = 0; + contactList[i].conversation = NULL; } else return 2; // Invalid format @@ -132,52 +152,3 @@ int fillContactList(char* filename) { return 0; } -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; - - clearContactListW(); - } - - if( contactListSelection >= firstConctactShow + h ) { - attrset(0 | A_NORMAL ); - firstConctactShow+=h/2; - if( firstConctactShow > nbContacts-1 ) - firstConctactShow = nbContacts-1; - - clearContactListW(); - } - - - int i; - for(i = firstConctactShow ; i < (h+firstConctactShow) && i < s ; i++) { - int color = 0, attr = A_NORMAL; -// if( it[i].opt == 1 ) -// color = COLOR_BLUE+1; - if( contactList[i].hasNewMessage ) - attr |= A_BOLD; - if( i == contactListSelection ) { - attr |= A_REVERSE; - } - - attrset( COLOR_PAIR(color) | attr); - move(y,x); - printw("%*s", w, " "); - mvprintc(x,y++,contactList[i].display_name, w); - attrset(0 | A_NORMAL); - } - for( ; i < s ; i++){ // Clear - - } -} - - -- cgit v1.2.3