From 519d3f78db044e7f214881b67655630e95e55810 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sat, 24 Jul 2010 17:02:11 +0000 Subject: [PATCH] Implemented contact deletion --- src/gsm.c | 3 +-- src/gsm.h | 1 + src/modem.c | 19 +++++++++++++++++++ src/modem.h | 1 + src/phone.c | 7 +++++-- 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/gsm.c b/src/gsm.c index ed7e665..966121d 100644 --- a/src/gsm.c +++ b/src/gsm.c @@ -632,8 +632,7 @@ void gsm_callback_on_message_deleted(GSM * gsm) /* gsm_contact_delete */ int gsm_contact_delete(GSM * gsm, unsigned int index) { - /* FIXME implement */ - return 1; + return gsm_modem_contact_delete(gsm->modem, index); } diff --git a/src/gsm.h b/src/gsm.h index 700a83b..f67c4b8 100644 --- a/src/gsm.h +++ b/src/gsm.h @@ -57,6 +57,7 @@ typedef enum _GSMError GSM_ERROR_BUSY, GSM_ERROR_CALL_FAILED, GSM_ERROR_CALL_WAITING_FAILED, + GSM_ERROR_CONTACT_DELETE_FAILED, GSM_ERROR_CONTACT_EDIT_FAILED, GSM_ERROR_CONTACT_FETCH_FAILED, GSM_ERROR_CONTACT_LIST_FAILED, diff --git a/src/modem.c b/src/modem.c index fc39cc9..f058c54 100644 --- a/src/modem.c +++ b/src/modem.c @@ -199,6 +199,25 @@ static void _modem_call_reject_callback(GSM * gsm) } +/* gsm_modem_contact_delete */ +int gsm_modem_contact_delete(GSMModem * gsmm, unsigned int index) +{ + int ret; + char const cmd[] = "AT+CPBW="; + size_t len; + char * buf; + + len = sizeof(cmd) + 11 + 1; + if((buf = malloc(len)) == NULL) + return 1; + snprintf(buf, len, "%s%u,", cmd, index); + ret = gsm_queue_with_error(gsmm->gsm, buf, + GSM_ERROR_CONTACT_DELETE_FAILED); + free(buf); + return ret; +} + + /* gsm_modem_contact_edit */ static void _modem_contact_edit_callback(GSM * gsm); diff --git a/src/modem.h b/src/modem.h index 465ff97..358e863 100644 --- a/src/modem.h +++ b/src/modem.h @@ -56,6 +56,7 @@ int gsm_modem_call_hangup(GSMModem * gsmm); int gsm_modem_call_last(GSMModem * gsmm, GSMCallType calltype); int gsm_modem_call_reject(GSMModem * gsmm); +int gsm_modem_contact_delete(GSMModem * gsmm, unsigned int index); int gsm_modem_contact_edit(GSMModem * gsmm, unsigned int index, char const * name, char const * number); int gsm_modem_contact_new(GSMModem * gsmm, char const * name, diff --git a/src/phone.c b/src/phone.c index 31c3c92..814ad19 100644 --- a/src/phone.c +++ b/src/phone.c @@ -561,7 +561,11 @@ void phone_contacts_delete_selected(Phone * phone) return; gtk_tree_model_get(GTK_TREE_MODEL(phone->co_store), &iter, PHONE_CONTACT_COLUMN_ID, &index, -1); - /* FIXME ask for confirmation and implement */ + if(_phone_confirm(phone, phone->co_window, _("Delete this contact?")) + != 0) + return; + gtk_list_store_remove(phone->co_store, &iter); /* XXX it may fail */ + gsm_contact_delete(phone->gsm, index); } @@ -2440,7 +2444,6 @@ static void _on_contacts_dialog_response(GtkWidget * widget, gint response, return; name = gtk_entry_get_text(GTK_ENTRY(phone->co_name)); number = gtk_entry_get_text(GTK_ENTRY(phone->co_number)); - /* FIXME also update the GtkListStore */ if(phone->co_index < 0) gsm_contact_new(phone->gsm, name, number); else