[kupfer] pidgin: Provide character count for Send Message...



commit b08049197760004f946c6bc734bca3c7dcd780f4
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Tue Jan 5 03:00:23 2010 +0100

    pidgin: Provide character count for Send Message...
    
    Use a custom TextSource to provide character count in Send Message...
    this makes pidgin-microblog (twitter etc access in Pidgin) more
    convenient to use.

 kupfer/plugin/pidgin.py |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
---
diff --git a/kupfer/plugin/pidgin.py b/kupfer/plugin/pidgin.py
index 413a3ea..54a82e5 100644
--- a/kupfer/plugin/pidgin.py
+++ b/kupfer/plugin/pidgin.py
@@ -68,6 +68,18 @@ class OpenChat(Action):
 	def activate(self, leaf):
 		_send_message_to_contact(leaf, u"", present=True)
 
+class ChatTextSource (TextSource):
+	def get_rank(self):
+		return 100
+	def get_text_items(self, text):
+		n = len(text)
+		summary = text[:10] + (text[10:11] and "..")
+		desc_template = ngettext("%s (%d character)", "%s (%d characters)", n)
+		yield TextLeaf(text, desc_template % (summary, n))
+
+	def get_items(self, text):
+		return self.get_text_items(text)
+
 class SendMessage (Action):
 	""" Send chat message directly from Kupfer """
 	def __init__(self):
@@ -83,7 +95,7 @@ class SendMessage (Action):
 	def object_types(self):
 		yield TextLeaf
 	def object_source(self, for_item=None):
-		return TextSource()
+		return ChatTextSource()
 
 class PidginContact(Leaf):
 	""" Leaf represent single contact from Pidgin """



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]