changeset 1125:d6c3fea5ecfe

quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
author souliane <souliane@mailoo.org>
date Sat, 23 Aug 2014 20:26:04 +0200
parents 7ee18dbfb661
children 8870417c8e8c
files frontends/src/primitivus/chat.py frontends/src/primitivus/primitivus frontends/src/quick_frontend/quick_chat.py
diffstat 3 files changed, 33 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/primitivus/chat.py	Sun Aug 24 18:23:55 2014 +0200
+++ b/frontends/src/primitivus/chat.py	Sat Aug 23 20:26:04 2014 +0200
@@ -275,6 +275,16 @@
         self.present_wid.deleteValue(nick)
         self.host.redraw()
 
+    def clearHistory(self):
+        """Clear the content of this chat."""
+        del self.content[:]
+
+    def afterHistoryPrint(self):
+        """Refresh or scroll down the focus after the history is printed"""
+        if len(self.content):
+            self.text_list.focus_position = len(self.content) - 1  # scroll down
+        self.host.redraw()
+
     def printMessage(self, from_jid, msg, profile, timestamp=""):
         assert isinstance(from_jid, JID)
         try:
--- a/frontends/src/primitivus/primitivus	Sun Aug 24 18:23:55 2014 +0200
+++ b/frontends/src/primitivus/primitivus	Sat Aug 23 20:26:04 2014 +0200
@@ -38,7 +38,7 @@
 from sat_frontends.primitivus.notify import Notify
 from sat_frontends.tools.misc import InputHistory
 from sat_frontends.constants import Const as commonConst # FIXME
-from sat.tools.jid  import JID
+from sat.tools.jid import JID
 from os.path import join
 
 
@@ -133,6 +133,15 @@
                 self.app.status_bar.onChange(user_data=sat_widgets.AdvancedEdit(args[0]))
             else:
                 self.app.status_bar.onStatusClick()
+        elif command == 'history':
+            try:
+                limit = int(args[0])
+            except (IndexError, ValueError):
+                limit = 50
+            win = self.app.chat_wins[JID(self.app.contact_list.selected).bare]
+            win.clearHistory()
+            if limit > 0:
+                win.historyPrint(size=limit, profile=self.app.profile)
         else:
             return
         self.set_edit_text('')
--- a/frontends/src/quick_frontend/quick_chat.py	Sun Aug 24 18:23:55 2014 +0200
+++ b/frontends/src/quick_frontend/quick_chat.py	Sat Aug 23 20:26:04 2014 +0200
@@ -96,9 +96,17 @@
             log.error (_("[INTERNAL] trying to set subject for a non group chat window"))
             raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here
 
+    def afterHistoryPrint(self):
+        """Refresh or scroll down the focus after the history is printed"""
+        pass
+
     def historyPrint(self, size=20, profile='@NONE@'):
-        """Print the initial history"""
-        log.debug (_("now we print history"))
+        """Print the current history
+        @param size (int): number of messages
+        @param profile (str): %(doc_profile)s
+        """
+        log.debug(_("now we print the history (%d messages)") % size)
+
         def onHistory(history):
             for line in history:
                 timestamp, from_jid, to_jid, message, _type, extra = line
@@ -106,16 +114,17 @@
                    (self.type == 'one2one' and _type == 'groupchat')):
                     continue
                 self.printMessage(JID(from_jid), message, profile, timestamp)
+            self.afterHistoryPrint()
 
         def onHistoryError(err):
-            log.error (_("Can't get history"))
+            log.error(_("Can't get history"))
 
         if self.target.startswith(Const.PRIVATE_PREFIX):
             target = unescapePrivate(self.target)
         else:
             target = self.target.bare
 
-        self.host.bridge.getHistory(self.host.profiles[profile]['whoami'].bare, target, 20, profile=profile, callback=onHistory, errback=onHistoryError)
+        return self.host.bridge.getHistory(self.host.profiles[profile]['whoami'].bare, target, size, profile=profile, callback=onHistory, errback=onHistoryError)
 
     def _get_nick(self, jid):
         """Return nick of this jid when possible"""