Implemented message deletion (untested, should ask for confirmation)
This commit is contained in:
parent
77292584de
commit
b029f690c7
@ -333,7 +333,7 @@ void on_phone_read_delete(gpointer data)
|
||||
{
|
||||
Phone * phone = data;
|
||||
|
||||
/* FIXME implement */
|
||||
phone_read_delete(phone);
|
||||
}
|
||||
|
||||
|
||||
|
82
src/gsm.c
82
src/gsm.c
@ -809,6 +809,51 @@ int gsm_is_registered(GSM * gsm)
|
||||
}
|
||||
|
||||
|
||||
/* messaging */
|
||||
/* gsm_message_delete */
|
||||
int gsm_message_delete(GSM * gsm, unsigned int index)
|
||||
{
|
||||
return gsm_modem_message_delete(gsm->modem, index);
|
||||
}
|
||||
|
||||
|
||||
/* gsm_message_send */
|
||||
static int _message_send_utf8(GSM * gsm, char const * number, char const * text,
|
||||
size_t length);
|
||||
|
||||
int gsm_message_send(GSM * gsm, char const * number, GSMEncoding encoding,
|
||||
char const * text, size_t length)
|
||||
{
|
||||
switch(encoding)
|
||||
{
|
||||
case GSM_ENCODING_UTF8:
|
||||
return _message_send_utf8(gsm, number, text, length);
|
||||
case GSM_ENCODING_RAW_DATA:
|
||||
return gsm_modem_message_send(gsm->modem, number,
|
||||
GSM_MODEM_ALPHABET_DATA, text, length);
|
||||
}
|
||||
return 1; /* should not be reached */
|
||||
}
|
||||
|
||||
static int _message_send_utf8(GSM * gsm, char const * number, char const * text,
|
||||
size_t length)
|
||||
{
|
||||
int ret;
|
||||
gchar * p;
|
||||
size_t i;
|
||||
|
||||
if((p = g_convert(text, length, "ISO-8859-1", "UTF-8", NULL, &length,
|
||||
NULL)) == NULL)
|
||||
return 1; /* XXX report error */
|
||||
for(i = 0; i < length; i++)
|
||||
p[i] = _gsm_convert_from_iso(text[i]);
|
||||
ret = gsm_modem_message_send(gsm->modem, number,
|
||||
GSM_MODEM_ALPHABET_DEFAULT, text, length);
|
||||
g_free(p);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* queue management */
|
||||
/* gsm_queue */
|
||||
GSMCommand * gsm_queue(GSM * gsm, char const * command)
|
||||
@ -918,43 +963,6 @@ int gsm_reset(GSM * gsm, unsigned int delay)
|
||||
}
|
||||
|
||||
|
||||
/* gsm_send_message */
|
||||
static int _send_message_utf8(GSM * gsm, char const * number, char const * text,
|
||||
size_t length);
|
||||
|
||||
int gsm_send_message(GSM * gsm, char const * number, GSMEncoding encoding,
|
||||
char const * text, size_t length)
|
||||
{
|
||||
switch(encoding)
|
||||
{
|
||||
case GSM_ENCODING_UTF8:
|
||||
return _send_message_utf8(gsm, number, text, length);
|
||||
case GSM_ENCODING_RAW_DATA:
|
||||
return gsm_modem_send_message(gsm->modem, number,
|
||||
GSM_MODEM_ALPHABET_DATA, text, length);
|
||||
}
|
||||
return 1; /* should not be reached */
|
||||
}
|
||||
|
||||
static int _send_message_utf8(GSM * gsm, char const * number, char const * text,
|
||||
size_t length)
|
||||
{
|
||||
int ret;
|
||||
gchar * p;
|
||||
size_t i;
|
||||
|
||||
if((p = g_convert(text, length, "ISO-8859-1", "UTF-8", NULL, &length,
|
||||
NULL)) == NULL)
|
||||
return 1; /* XXX report error */
|
||||
for(i = 0; i < length; i++)
|
||||
p[i] = _gsm_convert_from_iso(text[i]);
|
||||
ret = gsm_modem_send_message(gsm->modem, number,
|
||||
GSM_MODEM_ALPHABET_DEFAULT, text, length);
|
||||
g_free(p);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* private */
|
||||
/* functions */
|
||||
/* conversions */
|
||||
|
@ -84,6 +84,7 @@ typedef enum _GSMError
|
||||
GSM_ERROR_CONTACT_LIST_FAILED,
|
||||
GSM_ERROR_FUNCTIONAL_FAILED,
|
||||
GSM_ERROR_HANGUP_FAILED,
|
||||
GSM_ERROR_MESSAGE_DELETE_FAILED,
|
||||
GSM_ERROR_MESSAGE_FETCH_FAILED,
|
||||
GSM_ERROR_MESSAGE_LIST_FAILED,
|
||||
GSM_ERROR_MESSAGE_SEND_FAILED,
|
||||
@ -378,6 +379,11 @@ int gsm_fetch_operator(GSM * gsm);
|
||||
int gsm_fetch_registration(GSM * gsm);
|
||||
int gsm_fetch_signal_level(GSM * gsm);
|
||||
|
||||
/* messaging */
|
||||
int gsm_message_delete(GSM * gsm, unsigned int index);
|
||||
int gsm_message_send(GSM * gsm, char const * number, GSMEncoding encoding,
|
||||
char const * text, size_t length);
|
||||
|
||||
/* queries */
|
||||
int gsm_is_alive(GSM * gsm);
|
||||
int gsm_is_call_waiting_control(GSM * gsm);
|
||||
@ -399,7 +405,4 @@ int gsm_queue_with_error(GSM * gsm, char const * command, GSMError error);
|
||||
|
||||
int gsm_reset(GSM * gsm, unsigned int delay);
|
||||
|
||||
int gsm_send_message(GSM * gsm, char const * number, GSMEncoding encoding,
|
||||
char const * text, size_t length);
|
||||
|
||||
#endif /* !PHONE_GSM_H */
|
||||
|
25
src/modem.c
25
src/modem.c
@ -429,22 +429,23 @@ int gsm_modem_is_registered(GSMModem * gsmm)
|
||||
}
|
||||
|
||||
|
||||
/* gsm_modem_reset */
|
||||
int gsm_modem_reset(GSMModem * gsmm)
|
||||
/* gsm_modem_message_delete */
|
||||
int gsm_modem_message_delete(GSMModem * gsmm, unsigned int index)
|
||||
{
|
||||
char const cmd[] = "ATZ";
|
||||
char cmd[32];
|
||||
|
||||
return gsm_queue_full(gsmm->gsm, GSM_PRIORITY_HIGH, cmd,
|
||||
GSM_ERROR_RESET_FAILED, NULL);
|
||||
snprintf(cmd, sizeof(cmd), "%s%u", "AT+CMGD=", index);
|
||||
return gsm_queue_full(gsmm->gsm, GSM_PRIORITY_NORMAL, cmd,
|
||||
GSM_ERROR_MESSAGE_DELETE_FAILED, NULL);
|
||||
}
|
||||
|
||||
|
||||
/* gsm_modem_send_message */
|
||||
/* gsm_modem_message_send */
|
||||
static char * _number_to_address(char const * number);
|
||||
static char * _text_to_data(char const * text, size_t length);
|
||||
static char * _text_to_sept(char const * text, size_t length);
|
||||
|
||||
int gsm_modem_send_message(GSMModem * gsmm, char const * number,
|
||||
int gsm_modem_message_send(GSMModem * gsmm, char const * number,
|
||||
GSMModemAlphabet alphabet, char const * text, size_t length)
|
||||
{
|
||||
int ret = 1;
|
||||
@ -610,6 +611,16 @@ static char * _text_to_sept(char const * text, size_t length)
|
||||
}
|
||||
|
||||
|
||||
/* gsm_modem_reset */
|
||||
int gsm_modem_reset(GSMModem * gsmm)
|
||||
{
|
||||
char const cmd[] = "ATZ";
|
||||
|
||||
return gsm_queue_full(gsmm->gsm, GSM_PRIORITY_HIGH, cmd,
|
||||
GSM_ERROR_RESET_FAILED, NULL);
|
||||
}
|
||||
|
||||
|
||||
/* gsm_modem_set_call_presentation */
|
||||
int gsm_modem_set_call_presentation(GSMModem * gsmm, gboolean set)
|
||||
{
|
||||
|
@ -78,11 +78,12 @@ int gsm_modem_is_pin_needed(GSMModem * gsmm);
|
||||
int gsm_modem_is_pin_valid(GSMModem * gsmm);
|
||||
int gsm_modem_is_registered(GSMModem * gsmm);
|
||||
|
||||
int gsm_modem_reset(GSMModem * gsmm);
|
||||
|
||||
int gsm_modem_send_message(GSMModem * gsmm, char const * number,
|
||||
int gsm_modem_message_delete(GSMModem * gsmm, unsigned int index);
|
||||
int gsm_modem_message_send(GSMModem * gsmm, char const * number,
|
||||
GSMModemAlphabet alphabet, char const * text, size_t length);
|
||||
|
||||
int gsm_modem_reset(GSMModem * gsmm);
|
||||
|
||||
int gsm_modem_set_call_presentation(GSMModem * gsmm, gboolean set);
|
||||
int gsm_modem_set_call_waiting_control(GSMModem * gsmm, gboolean unsollicited);
|
||||
int gsm_modem_set_echo(GSMModem * gsmm, gboolean echo);
|
||||
|
36
src/phone.c
36
src/phone.c
@ -166,6 +166,7 @@ struct _Phone
|
||||
GtkWidget * me_view;
|
||||
|
||||
/* read */
|
||||
unsigned int re_index;
|
||||
GtkWidget * re_window;
|
||||
GtkWidget * re_name;
|
||||
GtkWidget * re_number;
|
||||
@ -312,6 +313,7 @@ Phone * phone_new(char const * device, unsigned int baudrate, int retry,
|
||||
phone->me_store = gtk_list_store_new(PHONE_MESSAGE_COLUMN_COUNT,
|
||||
G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT,
|
||||
G_TYPE_STRING, G_TYPE_STRING);
|
||||
phone->re_index = 0;
|
||||
phone->re_window = NULL;
|
||||
phone->se_window = NULL;
|
||||
phone->se_store = gtk_list_store_new(PHONE_SETTINGS_COLUMN_COUNT,
|
||||
@ -852,7 +854,21 @@ void phone_messages_call_selected(Phone * phone)
|
||||
/* phone_messages_delete_selected */
|
||||
void phone_messages_delete_selected(Phone * phone)
|
||||
{
|
||||
/* FIXME implement */
|
||||
GtkTreeSelection * treesel;
|
||||
GtkTreeIter iter;
|
||||
unsigned int index;
|
||||
|
||||
if((treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(
|
||||
phone->me_view))) == NULL)
|
||||
return;
|
||||
if(gtk_tree_selection_get_selected(treesel, NULL, &iter) != TRUE)
|
||||
return;
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(phone->me_store), &iter,
|
||||
PHONE_MESSAGE_COLUMN_ID, &index, -1);
|
||||
/* FIXME ask for confirmation first, add a progress window */
|
||||
gsm_message_delete(phone->gsm, index);
|
||||
if(phone->re_index == index)
|
||||
phone_show_read(phone, FALSE);
|
||||
}
|
||||
|
||||
|
||||
@ -914,6 +930,15 @@ void phone_read_call(Phone * phone)
|
||||
}
|
||||
|
||||
|
||||
/* phone_read_delete */
|
||||
void phone_read_delete(Phone * phone)
|
||||
{
|
||||
/* FIXME ask for confirmation first, add a progress window */
|
||||
gsm_message_delete(phone->gsm, phone->re_index);
|
||||
phone_show_read(phone, FALSE);
|
||||
}
|
||||
|
||||
|
||||
/* settings */
|
||||
/* phone_settings_open_selected */
|
||||
void phone_settings_open_selected(Phone * phone)
|
||||
@ -1623,7 +1648,6 @@ void phone_show_read(Phone * phone, gboolean show, ...)
|
||||
GtkWidget * widget;
|
||||
GtkToolItem * toolitem;
|
||||
GtkTextBuffer * tbuf;
|
||||
unsigned int index;
|
||||
char const * name;
|
||||
char const * number;
|
||||
time_t date;
|
||||
@ -1638,15 +1662,15 @@ void phone_show_read(Phone * phone, gboolean show, ...)
|
||||
return;
|
||||
}
|
||||
va_start(ap, show);
|
||||
index = va_arg(ap, unsigned int);
|
||||
phone->re_index = va_arg(ap, unsigned int);
|
||||
name = va_arg(ap, char const *);
|
||||
number = va_arg(ap, char const *);
|
||||
date = va_arg(ap, time_t);
|
||||
content = va_arg(ap, char const *);
|
||||
va_end(ap);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "DEBUG: %s() %u, %s, %s, %u, %s\n", __func__, index,
|
||||
name, number, date, content);
|
||||
fprintf(stderr, "DEBUG: %s() %u, %s, %s, %u, %s\n", __func__,
|
||||
phone->re_index, name, number, date, content);
|
||||
#endif
|
||||
if(phone->re_window == NULL)
|
||||
{
|
||||
@ -1957,7 +1981,7 @@ void phone_write_send(Phone * phone)
|
||||
_phone_track(phone, PHONE_TRACK_MESSAGE_SENT, TRUE);
|
||||
length = strlen(text);
|
||||
phone_event(phone, PHONE_EVENT_SMS_SENDING, &encoding, &text, &length);
|
||||
gsm_send_message(phone->gsm, number, encoding, text, length);
|
||||
gsm_message_send(phone->gsm, number, encoding, text, length);
|
||||
g_free(text);
|
||||
}
|
||||
|
||||
|
@ -102,6 +102,7 @@ void phone_unload_all(Phone * phone);
|
||||
|
||||
/* read */
|
||||
void phone_read_call(Phone * phone);
|
||||
void phone_read_delete(Phone * phone);
|
||||
|
||||
/* settings */
|
||||
void phone_settings_open_selected(Phone * phone);
|
||||
|
Loading…
Reference in New Issue
Block a user