From 65087f82753a12e330fa0e6fc0c0e4b70c6a6c63 Mon Sep 17 00:00:00 2001 From: ache Date: Sat, 11 Nov 2017 03:57:47 +0000 Subject: PoC menu Contact --- contactList.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 contactList.c (limited to 'contactList.c') diff --git a/contactList.c b/contactList.c new file mode 100644 index 0000000..85369a9 --- /dev/null +++ b/contactList.c @@ -0,0 +1,170 @@ +#include +#include +#include"contactList.h" + +contact* contactList; +size_t nbContacts; + + +int x_menuContact = 1,y_menuContact = 1; +int w_menuContact,h_menuContact; + +int contactListSelection; +int firstConctactShow; + + + +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); + printw("%*s", w_menuContact, " "); + } +} + +int fillContactList(char* filename) { + FILE* file = fopen(filename, "r"); + + nbContacts = 0; + if( contactList ) { + free(contactList); + } + + if( !file ) + return 1; + + int c = 0; + int v = 0; + while( (c = fgetc(file)) != EOF ) { + if( c == ';' ) { + v++; + if( v == 3) + return 2; // Invalid + } + if( c == '\n' ) { + if( v == 2 ) { + v = 0; + nbContacts++; + } + else // Pas assez + return 2; // Invalid format + } + } + if( v == 1 ) + nbContacts++; + + contactList = malloc( nbContacts * sizeof *contactList); + + rewind(file); + + int nameLength, numberLength, display_nameLength, i; + nameLength = numberLength = display_nameLength = i = 0; + contactList[0].hasNewMessage = 0; + while( (c = fgetc(file)) != EOF ) { + if( c == ';' ) { + v++; + switch(v) { + case 1: + contactList[i].name[nameLength] = 0; + nameLength = 0; + break; + case 2: + contactList[i].name[display_nameLength] = 0; + display_nameLength = 0; + break; + default: + return 2; // Invalid + } + } else if( c == '\n' ) { + if( v == 2 ) { + v = 0; + contactList[i].number[numberLength] = 0; + numberLength = 0; + i++; + contactList[i].hasNewMessage = 0; + } + else + return 2; // Invalid format + } else { + if( v == 0) { + contactList[i].name[nameLength++] = c; + if( nameLength > (sizeof contactList[i].name -1) ) { + return 3; + } + }else if( v == 1) { + contactList[i].display_name[display_nameLength++] = c; + if( display_nameLength > (sizeof contactList[i].display_name -1) ) { + return 9; + } + } else { + contactList[i].number[numberLength++] = c; + if( numberLength > (sizeof contactList[i].number -1) ) { + puts(contactList[i].number); + return 27+i; + } + } + } + } + + 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