changeset 199:5ddf8bee768d

according to mojin, jisko limits each post to 140 bytes and requires at least 5 bytes. now letter counter for jisko takes account of this limit.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Mon, 11 Aug 2008 10:17:46 +0900
parents 85484ddf8823
children 9a2d727f39b4
files pidgin-twitter.c
diffstat 1 files changed, 41 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-twitter.c	Sun Aug 10 23:00:48 2008 +0900
+++ b/pidgin-twitter.c	Mon Aug 11 10:17:46 2008 +0900
@@ -1066,12 +1066,17 @@
 
     switch(service) {
     case twitter_service:
-    case jisko_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 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;
     case identica_service:
         gtk_text_buffer_get_start_iter(textbuffer, &head);
         gtk_text_buffer_get_end_iter(textbuffer, &tail);
@@ -1083,11 +1088,17 @@
         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);
+    case jisko_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>",
-                                         count <= 255 ? "black" : "red", count);
+                                         bytes >= 5 && bytes <= 140 ?
+                                         "black" : "red", bytes);
         break;
     default:
         twitter_debug("unknown service\n");
@@ -1120,13 +1131,19 @@
 
     switch(service) {
     case twitter_service:
-    case jisko_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 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;
     case identica_service:
         gtk_text_buffer_get_start_iter(textbuffer, &head);
         gtk_text_buffer_get_end_iter(textbuffer, &tail);
@@ -1146,12 +1163,25 @@
         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));
+    case jisko_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>",
-                                         count <= 255 ? "black" : "red", count);
+                                         bytes >= 5 && bytes <= 140 ?
+                                         "black" : "red", bytes);
         break;
     default:
         twitter_debug("unknown service\n");