From 20a87184b1c06f63b2b3d8b9c48a68535b31b4bb Mon Sep 17 00:00:00 2001 From: ache Date: Fri, 17 Nov 2017 11:21:12 +0100 Subject: New mesms --- .todo.txt | 5 +- Makefile | 2 +- contactList.c | 109 ++++++++++------------------ contactList.h | 24 +++--- contactWind.c | 91 +++++++++++++++++++++++ contactWind.h | 20 +++++ main.c | 141 ++++++++++++++++++++++++++++++++--- main.h | 1 + messageWind.c | 127 ++++++++++++++++++++++++++++++++ messageWind.h | 16 ++++ sms.c | 230 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sms.h | 53 ++++++++++++++ wind.c | 60 +++++++++++++++ wind.h | 10 ++- 14 files changed, 795 insertions(+), 94 deletions(-) create mode 100644 contactWind.c create mode 100644 contactWind.h create mode 100644 messageWind.c create mode 100644 messageWind.h create mode 100644 sms.c create mode 100644 sms.h diff --git a/.todo.txt b/.todo.txt index a1248c3..383f731 100644 --- a/.todo.txt +++ b/.todo.txt @@ -1 +1,4 @@ -4 0 Utiliser le format Kyf +4 3 Utiliser le format Kyf +4 0 Envoye -> edition +4 0 Envoye -> Brouillon +4 0 Envoye -> no miss diff --git a/Makefile b/Makefile index 91efb80..e69a058 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ CC=gcc PROG=mesms LIBS=-lcurses -lreadline HEADERS=$(wildcard *.h) -FILES=readline.c wind.c contactList.c basic_curses.c +FILES=readline.c wind.c contactList.c basic_curses.c contactWind.c sms.c messageWind.c OBJ_FILES := $(FILES:.c=.o) CFLAGS+=-std=gnu99 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 - - } -} - - diff --git a/contactList.h b/contactList.h index 5857c2f..bb25ef2 100644 --- a/contactList.h +++ b/contactList.h @@ -5,11 +5,14 @@ #include #include "basic_curses.h" +typedef struct conversation conversation; + typedef struct contact { char name[100]; char display_name[100]; char number[50]; int hasNewMessage; + conversation* conversation; } contact ; #define DEFAULT_CONTACT_FILENAME "/usr/share/sms/contact.csv" @@ -30,6 +33,12 @@ int writeContactList(char* cvs_file_in); // Return: 0 if success, >0 otherwise int findContact(const char*, contact**); +// Find a contact +// Params: A name +// Return: 0 if success, >0 otherwise +int findContactFromName(const char*, contact**); + + // Add a contact @@ -49,18 +58,15 @@ int deleteContactFromNumber(const char*); int deleteContactFromName(const char*); +// Sort the contact list +// Params : Nothing +// Return : Nothing +void sortContacts(void); + + /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// // Window contact - -void clearContactListW(void); -void showContactListW(void); -void refreshContactListW(void); - -void selectNextContact(void); -void selectPreviousContact(void); - - #endif diff --git a/contactWind.c b/contactWind.c new file mode 100644 index 0000000..e496e8a --- /dev/null +++ b/contactWind.c @@ -0,0 +1,91 @@ +#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; + + +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); + printw("%*s", w_menuContact, " "); + } +} + + +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].conversation ) + 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 + + } +} + + diff --git a/contactWind.h b/contactWind.h new file mode 100644 index 0000000..41548b7 --- /dev/null +++ b/contactWind.h @@ -0,0 +1,20 @@ + +#ifndef CONTACT_WIND +#define CONTACT_WIND + +#include "contactList.h" + +void clearContactListW(void); +void showContactListW(void); +void refreshContactListW(void); + +void selectNextContact(void); +void selectPreviousContact(void); + +struct contact* getContactSelected(void); + + + + + +#endif diff --git a/main.c b/main.c index 965a45b..2cdbb44 100644 --- a/main.c +++ b/main.c @@ -1,12 +1,17 @@ #include "main.h" #include "readline.h" + #include #include #include #include #include + +#include +#include + #include "wind.h" /* @@ -34,12 +39,16 @@ const int color[] = { extern char* msg_win_str; +extern conversation* currentConv; static bool visual_mode = false; WINDOW *cmd_win; WINDOW *sep_win; char status[10]; +extern int firstSMSIndex; +extern int canAugment; + void fail_exit(const char *msg) { @@ -63,7 +72,7 @@ int main(int argc, char* argv[]){ }; - c = getopt_long(argc, argv, "hvc:", optlv, &optIndex); + c = getopt_long(argc, argv, "hvc:n:", optlv, &optIndex); if (c == -1) break; @@ -86,14 +95,26 @@ int main(int argc, char* argv[]){ fprintf(stderr, "Erreur à la lecture de la liste des contacts"); return r; } + if( r = loadConv() ) { + fprintf(stderr, "Erreur à la lecture de la liste des contacts"); + return r; + } contact* contact = NULL; - - if( r = findContact(optarg, &contact) ) { - fprintf(stderr, "Numéro de téléphone inconnue"); + + int nameOrNumber = 0; + if( nameOrNumber = (*optarg == '+' ) ) + r = findContact(optarg, &contact); + else + r = findContactFromName(optarg, &contact); + if( r ) { + fprintf(stderr, "Contact introuvable"); printf("%s",optarg); return r; } - printf("%s", contact->display_name); + if( nameOrNumber ) + printf("%s", contact->display_name); + else + printf("%s", contact->number); return 0; } else { fprintf(stderr, "Numéro de téléphone manquant"); @@ -129,8 +150,8 @@ int main(int argc, char* argv[]){ visual_mode = true; curs_set(0); - cmd_win = newwin(1, COLS, LINES - 20, 0); - sep_win = newwin(1, COLS, LINES - 2, 0); + cmd_win = newwin(1, COLS, LINES - 20, 0); + sep_win = newwin(1, COLS, LINES - 2, 0); init_pair( 12, COLOR_WHITE, COLOR_BLUE); @@ -139,9 +160,15 @@ int main(int argc, char* argv[]){ init_readline(); int r = 0; + if( r = fillContactList(DEFAULT_CONTACT_FILENAME) ) { return r; } + if( r = loadConv() ) { + return r; + } + sortContacts(); + for(int i = 0 ; i < 9 ; i++) { init_pair( i+1, i, COLOR_BLACK); @@ -149,6 +176,7 @@ int main(int argc, char* argv[]){ /* Premier affichage */ resize(); + int tabed = 0; /* Event loop */ while( c = getch() ) { @@ -164,16 +192,109 @@ int main(int argc, char* argv[]){ case KEY_DOWN: case KEY_RIGHT: case 'j': - selectNextContact(); + if( !tabed ) { + selectNextContact(); + showContactListW(); + } else { + if( canAugment ) + firstSMSIndex++; + clearWind(); + showMessageWind(); + } + break; case KEY_UP: case KEY_LEFT: case 'k': - selectPreviousContact(); + if( !tabed ) { + selectPreviousContact(); + showContactListW(); + } else { + if( firstSMSIndex > 0 ) + firstSMSIndex--; + canAugment=1; + clearWind(); + showMessageWind(); + } + + break; + case '\t': + if( currentConv ) + tabed = !tabed; break; + case '\r': { + contact* tmp = getContactSelected(); + currentConv = tmp->conversation; + toTheEnd(); + resize(); + } + break; + case 's': { + char* number = NULL; + + if( ! currentConv ) { + contact* tmp = getContactSelected(); + if( !tmp ) + break; + number = tmp->number; + } + else number = currentConv->number; + + const char* defaultEditor = "vim", + * const envEditor = getenv("EDITOR"), + * const visEditor = getenv("VISUAL"); + if( envEditor && envEditor[0] ) { + defaultEditor = envEditor; + } + if( visEditor && visEditor[0] ) { + defaultEditor = visEditor; + } + FILE* tmp = NULL; + char fileName[] = "todo.cpp_XXXXXX"; + int fd = mkstemp(fileName); + close(fd); + + char* cmd = malloc( 2 + strlen(defaultEditor) + + strlen(fileName) ); + sprintf( cmd, "%s %s", defaultEditor, fileName ); + +edit: + system(cmd); + { + FILE* r = fopen(fileName,"r"); + FILE* t = tmpfile(); + int c = 0; + int nb = 0; + while( (c = fgetc(r)) != EOF ) { + nb++; + fputc(c,t); + } + char* string = malloc( nb+1 ); + fclose(r); + rewind(t); + nb = 0; + while( (c = fgetc(t)) != EOF ) { + string[nb++] = c; + } + string[nb] = 0; + contact* d = NULL; + findContact(number, &d); + int ret = 0; + if( (ret = confirmSend(string, d->display_name)) == 1 ) { + char* cmd = malloc(2048); + sprintf( cmd, "cat %s | gammu-smsd-inject TEXT %s -len 400 -unicode", fileName, + number); + system(cmd); + }else if( ret == 2 ) { + goto edit; + } + } + free(cmd); + unlink( fileName ); + } + } - resize(); } refresh(); diff --git a/main.h b/main.h index cd7dfec..15080b3 100644 --- a/main.h +++ b/main.h @@ -19,6 +19,7 @@ #include "contactList.h" #include "wind.h" +#include "sms.h" #define HIDDEN 1 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; + +} + + + + diff --git a/messageWind.h b/messageWind.h new file mode 100644 index 0000000..99f0f57 --- /dev/null +++ b/messageWind.h @@ -0,0 +1,16 @@ + +#ifndef MESSAGE_WIND +#define MESSAGE_WIND + +#include "sms.h" + + +void showMessageWind(void); + +void clearWind(void); + +void toTheEnd(void); + +#endif + + diff --git a/sms.c b/sms.c new file mode 100644 index 0000000..05e8c91 --- /dev/null +++ b/sms.c @@ -0,0 +1,230 @@ +#include "sms.h" +#include +#include + + + + +conversation* listConv; +size_t nbConv; + +int insertSMS(sms* S) { + int index = -1; + + + for(int i = 0 ; i < nbConv ; i++) { + if( !strcmp(listConv[i].number, S->number) ) { + index = i; + break; + } + } + + if( index >= 0 ) { + sms* tmp = realloc(listConv[index].listSMS, (listConv[index].nbSMS+1) * sizeof *tmp); + if( tmp ) { + listConv[index].listSMS = tmp; + } else { + fprintf(stderr, "Erreur d'allocation"); + return 1; + } + int indexSMS = -1; + + for(int i = 0 ; i < listConv[index].nbSMS; i++) { + if( listConv[index].listSMS[i].outDate > S->outDate ) { + indexSMS = i; + break; + } + } + if( indexSMS >= 0 ) { + memmove(indexSMS+1+listConv[index].listSMS, + indexSMS+0+listConv[index].listSMS, + (listConv[index].nbSMS-indexSMS)* sizeof listConv[index].listSMS[indexSMS]); + memcpy(&listConv[index].listSMS[indexSMS],S, sizeof(sms)); + } else { + memcpy(&listConv[index].listSMS[listConv[index].nbSMS],S, sizeof(sms)); + } + listConv[index].nbSMS++; + } else { + conversation* tmp = realloc(listConv, (nbConv+1) * sizeof *tmp); + if( tmp ) { + listConv = tmp; + listConv[nbConv].listSMS = realloc(NULL, sizeof(sms) ); + memcpy(listConv[nbConv].listSMS, S, sizeof(sms)); + listConv[nbConv].nbSMS = 1; + strcpy( listConv[nbConv].number, S->number); + + nbConv++; + } else { + fprintf(stderr, "Erreur d'allocation"); + return 2; + } + } + return 0; +} + +void showSMS(sms* S) { + if( S->in_out == SMS_IN ) + printf("From %s @%s{%s}\n", S->number, ctime(&S->outDate), S->text); + else + printf("To %s @%s{%s}\n", S->number, ctime(&S->outDate), S->text); +} +void showConv(const char* number) { + + for(int i = 0 ; i < nbConv ; i++) { + if( !strcmp( listConv[i].number, number) ) { + for(int j = 0 ; j < listConv[i].nbSMS ; j++) { + showSMS(listConv[i].listSMS + j); + } + break; + } + } +} + +int readSMS(char* filename, int inbox_outbox) { + FILE* file = fopen(filename,"r"); + + if( file ) { + char line[1024] = ""; + int sms_len = 0; + char* sms_text = malloc(1); + char lastChar = 0; + int ok = 0; + int sms_number = 0; + sms getSms = {.in_out = inbox_outbox}; + + *sms_text= 0; + + loop: + // On cherche [SMSBackup] + while( fgets(line, 1024, file) != NULL) { + + if( strstr(line, "[SMSBackup") ) { + char SMSBackup[30] = ""; + sprintf(SMSBackup, "[SMSBackup%.03d]\n", sms_number); + if( !strcmp(line, SMSBackup) ) { + sms_number++; + break; + } + } + } + + // Donc maintenant, tant que ça commence par "; ", c'est du SMS + // + while( fgets(line, 1024, file) != NULL) { + if(line[0] == ';' && line[1] == ' ') { + sms_len += strlen(line) - 2; + char* tmp = realloc(sms_text, sms_len+1); + if( tmp ) { + sms_text = tmp; + strcat(sms_text, line+2); + } + ok = 1; + }else break; + } + if( ok ) { + lastChar = sms_text[sms_len-1]; + sms_text[--sms_len] = 0; + ok = 0; + } + + // Ici, line contient une ligne qui n'est pas un SMS. + // Il faut parcer jusqu'à ce qu'on aie une ligne vide + while( fgets(line, 1024, file) != NULL && line[0] && line[0] != '\n' ) { + + if(line[0] == ';') { // Si c'est un commentaire, on s'en fou + continue; + } else if( strstr(line, "DateTime = ") ) { + struct tm time_tm = {}; + if( strptime(line+11, "%Y%m%jT%H%M%S", &time_tm) ) { + getSms.outDate = mktime(&time_tm); + }else{ + puts("Error"); + } + + } else if( strstr(line, "State = ") ) { + if( line[9] == 'U' ) + getSms.state = SMS_UNREAD; + } else if( strstr(line, "Class = ") ) { + if( line[9] == '0' ) + getSms.type = FLASH_SMS; + } else if( strstr(line, "Number = ") ) { + strcpy(getSms.number, line+10); + getSms.number[strlen(getSms.number)-3]=0; + } + } + if( !feof(file) ) + goto loop; + sms_text[++sms_len] = lastChar; + getSms.text = sms_text; + getSms.len = sms_len; + + int r = insertSMS(&getSms); + if( r ) + return 2; + + fclose(file); + }else{ + fprintf(stderr, "Erreur à l'ouverture du fichier"); + return 1; + } + return 0; +} +int listSMS(char* smsInboxDir, int inorout) { + DIR *dirHandler; + struct dirent *dir; + + dirHandler = opendir( smsInboxDir ); + if (dirHandler) { + while ( (dir = readdir(dirHandler)) != NULL ) { + if( dir->d_type == DT_REG ) { + char filename[1024] =""; + + sprintf(filename, "%s/%s", smsInboxDir, dir->d_name); + int r = + readSMS(filename, inorout); + if( r ) + return 2; + + } + } + closedir(dirHandler); + } else { + fprintf(stderr, "Directory can't be opened"); + return 1; + } + return 0; +} + + + + +int loadConv(void) { + + int r = + + listSMS("/var/spool/sms/inbox/", SMS_IN); + if( r ) + return 1; + r = + listSMS("/var/spool/sms/sent/" , SMS_OUT); + if( r ) + return 2; + + for(int i = 0 ; i < nbConv ; i++) { + contact* cntct = NULL; + if( findContact(listConv[i].number,&cntct) == 0 ) { + cntct->conversation = &listConv[i]; + } else { + contact c = {}; + strcpy(c.display_name,listConv[i].number); + strcpy(c.name,listConv[i].number); + strcpy(c.number,listConv[i].number); + c.conversation = &listConv[i]; + addContact(&c); + } + } + + + return 0; +} + diff --git a/sms.h b/sms.h new file mode 100644 index 0000000..7d8a493 --- /dev/null +++ b/sms.h @@ -0,0 +1,53 @@ + +#ifndef SMS_H +#define SMS_H + +//#include + +#include +#include +#include +#include + + + +#include "contactList.h" + + + +#define SMS_IN 0 +#define SMS_OUT 1 + +#define FLASH_SMS 0 +#define REGUL_SMS 1 + +#define SMS_READ 0 +#define SMS_UNREAD 1 + +typedef struct sms { + char number[20]; // Sender or Dest + char* text; + int len; + time_t outDate; // Sent date + time_t intDate; // Receive date + char type; // Class 0 = Flash SMS | Other = Normal + char state; // Read or Unread + char in_out; // Sent or Received ? +} sms; + +typedef struct conversation { + char number[20]; + sms* listSMS; + size_t nbSMS; +} conversation; + + + + +int listSMS(char*,int); +int loadConv(void); + +#endif + + + diff --git a/wind.c b/wind.c index 138d837..7f06792 100644 --- a/wind.c +++ b/wind.c @@ -7,6 +7,8 @@ /* Managed windows */ extern int w_menuContact,h_menuContact; +extern int x_WMessage,y_WMessage; +extern int w_WMessage,h_WMessage; static short my_fg = COLOR_WHITE; static short my_bg = COLOR_BLACK; @@ -17,9 +19,67 @@ static short my_bg = COLOR_BLACK; void resize() { h_menuContact = LINES-2; w_menuContact = COLS/5-1; + + x_WMessage = w_menuContact + 2; + y_WMessage = 1; + + w_WMessage = (4*COLS)/5-2; + h_WMessage = LINES-5; + + clear(); showContactListW(); + move(1, x_WMessage-1); + vline(ACS_VLINE, h_menuContact); + showMessageWind(); + move(1,COLS/2); } +int confirmSend(char* txt, char* autheur) { + int x = COLS/3; + int y = LINES/3; + + int w = COLS/3; + int h = LINES/3; + + clear(); + move(y,x); + printw("Voulez-vous vraiment envoyé ce SMS à %s ?", autheur); + y++; + move(y,x); + + { + char line[w]; + memset(line, 0, w); + + int X = 0, Y=0, iS= 0; + while( txt[iS] ) { + X = 0; + while( X < w-1 && txt[iS]) { + if( txt[iS] == '\n' ) { + iS++; + break; + } + line[X++] = txt[iS++]; + } + line[X] = 0; + if( Y+1 >= h_WMessage -1 ) { + break; + } + Y++; + move(Y+y, x+2); + printw("%s", line); + } + } + + + + int c = 0; + while( (c = getch()) && c != EOF && !strchr("oyneqOYNEQ", c) ) ; + + clear(); + return (c == 'e' || c =='E') ? 2 : (!!strchr("yYoO", c)) ; + +} diff --git a/wind.h b/wind.h index c2b835f..763e861 100644 --- a/wind.h +++ b/wind.h @@ -1,14 +1,16 @@ -#ifndef WIND_METAG_H -#define WIND_METAG_H +#ifndef WIND_MESMS_H +#define WIND_MESMS_H #include "main.h" #include "readline.h" -#include "contactList.h" - +#include "contactWind.h" +#include "messageWind.h" void resize(); +int confirmSend(char*,char*); + #endif -- cgit v1.2.3