quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)

This commit is contained in:
souliane 2014-08-23 20:26:04 +02:00
commit 3cee372b02
3 changed files with 33 additions and 5 deletions

View file

@ -275,6 +275,16 @@ class Chat(urwid.WidgetWrap, QuickChat):
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:

View file

@ -38,7 +38,7 @@ from sat_frontends.primitivus.progress import Progress
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 @@ class EditBar(sat_widgets.ModalEdit):
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('')

View file

@ -96,9 +96,17 @@ class QuickChat(object):
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 @@ class QuickChat(object):
(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"""