aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2019-02-07 10:59:50 +0100
committerache <ache@ache.one>2019-02-07 11:00:26 +0100
commitb84ddbea51b1247117891be301667feb2fa8975e (patch)
treeccd4ac8b7faaecaa63c8a34007a8930ada47d4dc
parentThe real UTF-8 problem is the code (diff)
Delete contact
-rw-r--r--contactList.c11
-rw-r--r--contactList.h2
-rw-r--r--main.c17
3 files changed, 27 insertions, 3 deletions
diff --git a/contactList.c b/contactList.c
index 9c6640c..891054c 100644
--- a/contactList.c
+++ b/contactList.c
@@ -62,6 +62,17 @@ int addContact(const contact* cnct) {
contactList = realloc(contactList, nbContacts * sizeof *contactList);
memcpy(&contactList[nbContacts-1],cnct, sizeof *cnct);
}
+int deleteContact(contact* cnct) {
+ if( cnct->conversation ) {
+ *cnct->name = 0;
+ strcpy(cnct->display_name, cnct->number);
+ } else {
+ int index = cnct - contactList;
+ fprintf(stderr, "Index %d\n", index);
+ memmove(contactList+index, contactList + index + 1, (nbContacts-index-1) * sizeof(contact));
+ nbContacts--;
+ }
+}
int fillContactList(const char* filename) {
FILE* file = fopen(filename, "r");
diff --git a/contactList.h b/contactList.h
index 6d72dee..0adcd9a 100644
--- a/contactList.h
+++ b/contactList.h
@@ -50,7 +50,7 @@ int addContact(const contact*);
// Delete a contact
// Params: A String which is a valide contact SIM number
// Return: 0 if success, >0 otherwise
-int deleteContact(void);
+int deleteContact(contact*);
// Sort the contact list
// Params : Nothing
diff --git a/main.c b/main.c
index 830c209..353e157 100644
--- a/main.c
+++ b/main.c
@@ -264,8 +264,19 @@ int main(int argc, char* argv[]){
resize();
}
break;
+ case 'd':
+ {
+ contact* selected = getContactSelected();
+ readline_n("Delete contact | Type 'yes' to confirm : ", "");
+ if( strcmp(msg_win_str, "yes") == 0) {
+ deleteContact(selected);
+ writeContactList(config.CONTACT_FILENAME);
+ showContactListW();
+ }
+ break;
+ }
case 'e':
- if( tabed ) {
+ {
contact* selected = getContactSelected();
readline_n("Edit contact | Name : ", selected->name);
strcpy(selected->name, msg_win_str);
@@ -279,15 +290,17 @@ int main(int argc, char* argv[]){
if( !tabed ) {
contact newContact = {"", "", "", 0, NULL};
readline_n("New contact | Name : ", "");
+ if( !*msg_win_str ) break;
strcpy(newContact.name, msg_win_str);
readline_n("New contact | Display name : ", "");
strcpy(newContact.display_name, msg_win_str);
+ if( !*msg_win_str ) break;
readline_n("New contact | Number : ", "");
strcpy(newContact.number, msg_win_str);
addContact(&newContact);
- if( *config.CONTACT_FILENAME == '\0' ) {
+ if( !*config.CONTACT_FILENAME ) {
wordexp_t p;
r = wordexp("~/.mesms_contacts.csv", &p, 0);
if( r == 0 && p.we_wordc > 0 ) {