diff pidgin-twitter.c @ 102:55c466028d48

changed letter counter for identi.ca to count in byte.
author Yoshiki Yazawa <yaz@honeyplnaet.jp>
date Sun, 13 Jul 2008 18:53:45 +0900
parents ceabb8099bf3
children 8de54d420328
line wrap: on
line diff
--- a/pidgin-twitter.c	Fri Jul 11 19:25:55 2008 +0900
+++ b/pidgin-twitter.c	Sun Jul 13 18:53:45 2008 +0900
@@ -706,22 +706,35 @@
 
     GtkWidget *box, *counter = NULL;
     gchar *markup = NULL;
+    gint service = get_service_type(conv);
     guint count;
-
-    gint service = get_service_type(conv);
+    gchar *text = NULL;
+    GtkTextIter head, tail;
+    guint bytes = 0;
 
     g_return_if_fail(gtkconv != NULL);
 
-    count = gtk_text_buffer_get_char_count(textbuffer) +
-        (unsigned int)g_utf8_strlen(new_text, -1);
-
     switch(service) {
     case twitter_service:
-    case identica_service:
+        count = gtk_text_buffer_get_char_count(textbuffer) +
+            (unsigned int)g_utf8_strlen(new_text, -1);
         markup = g_markup_printf_escaped("<span color=\"%s\">%u</span>",
                                          count <= 140 ? "black" : "red", count);
         break;
+    case identica_service:
+        gtk_text_buffer_get_start_iter(textbuffer, &head);
+        gtk_text_buffer_get_end_iter(textbuffer, &tail);
+
+        text = gtk_text_buffer_get_text(textbuffer, &head, &tail, TRUE);
+        if(text)
+            bytes = strlen(text) + new_text_length;
+        g_free(text);
+        markup = g_markup_printf_escaped("<span color=\"%s\">%u</span>",
+                                         bytes <= 140 ? "black" : "red", bytes);
+        break;
     case wassr_service:
+        count = gtk_text_buffer_get_char_count(textbuffer) +
+            (unsigned int)g_utf8_strlen(new_text, -1);
         markup = g_markup_printf_escaped("<span color=\"%s\">%u</span>",
                                          count <= 255 ? "black" : "red", count);
         break;
@@ -747,20 +760,44 @@
     GtkWidget *box, *counter = NULL;
     gchar *markup = NULL;
     gint service = get_service_type(conv);
+    guint count = 0;
+    gchar *text = NULL;
+    GtkTextIter head, tail;
+    guint bytes = 0;
 
     g_return_if_fail(gtkconv != NULL);
 
-    guint count = gtk_text_buffer_get_char_count(textbuffer) -
-        (gtk_text_iter_get_offset(end_pos) -
-         gtk_text_iter_get_offset(start_pos));
-
     switch(service) {
     case twitter_service:
-    case identica_service:
+        count= gtk_text_buffer_get_char_count(textbuffer) -
+            (gtk_text_iter_get_offset(end_pos) -
+             gtk_text_iter_get_offset(start_pos));
         markup = g_markup_printf_escaped("<span color=\"%s\">%u</span>",
                                          count <= 140 ? "black" : "red", count);
         break;
+    case identica_service:
+        gtk_text_buffer_get_start_iter(textbuffer, &head);
+        gtk_text_buffer_get_end_iter(textbuffer, &tail);
+
+        text = gtk_text_buffer_get_text(textbuffer,
+                                        &head, &tail, TRUE);
+        if(text)
+            bytes = strlen(text);
+        g_free(text);
+
+        text = gtk_text_buffer_get_text(textbuffer,
+                                        start_pos, end_pos, TRUE);
+        if(text)
+            bytes -= strlen(text);
+        g_free(text);
+
+        markup = g_markup_printf_escaped("<span color=\"%s\">%u</span>",
+                                         bytes <= 140 ? "black" : "red", bytes);
+        break;
     case wassr_service:
+        count= gtk_text_buffer_get_char_count(textbuffer) -
+            (gtk_text_iter_get_offset(end_pos) -
+             gtk_text_iter_get_offset(start_pos));
         markup = g_markup_printf_escaped("<span color=\"%s\">%u</span>",
                                          count <= 255 ? "black" : "red", count);
         break;