Probably more accurate character count for messages (except for encryption)

This commit is contained in:
Pierre Pronchery 2011-01-05 02:41:18 +00:00
parent 67200d9281
commit ad76ed995f

View File

@ -2492,8 +2492,8 @@ void phone_unload_all(Phone * phone)
void phone_write_count_buffer(Phone * phone)
{
GtkTextBuffer * tbuf;
const int max = 140;
gint cnt;
int max = 160;
gint msg_cnt;
gint cur_cnt;
char buf[32];
@ -2501,6 +2501,14 @@ void phone_write_count_buffer(Phone * phone)
tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(phone->wr_view));
if((cnt = gtk_text_buffer_get_char_count(tbuf)) < 0)
return;
if(cnt <= max)
{
cur_cnt = cnt;
msg_cnt = 1;
}
else
{
max = 153; /* for the User Data Header */
msg_cnt = (cnt / max) + 1;
if((cur_cnt = cnt % max) == 0)
{
@ -2508,6 +2516,7 @@ void phone_write_count_buffer(Phone * phone)
if(cnt > 0)
cur_cnt = max;
}
}
snprintf(buf, sizeof(buf), _("%d message%s, %d/%d characters"),
msg_cnt, (msg_cnt > 1) ? _("s") : "", cur_cnt, max);
gtk_label_set_text(GTK_LABEL(phone->wr_count), buf);