Skip to content
Snippets Groups Projects
Commit fb3eeb4a authored by Yann Leboulanger's avatar Yann Leboulanger
Browse files

add a limit to the number of lines displayed in conversation textview.

parent ddd7c13e
No related branches found
No related tags found
No related merge requests found
......@@ -228,6 +228,7 @@ class Config:
'scroll_roster_to_last_message': [opt_bool, True, _('If True, Gajim will scroll and select the contact who sent you the last message, if chat window is not already opened.')],
'use_latex': [opt_bool, False, _('If True, Gajim will convert string between $$ and $$ to an image using dvips and convert before insterting it in chat window.')],
'change_status_window_timeout': [opt_int, 15, _('Time of inactivity needed before the change status window closes down.')],
'max_conversation_lines': [opt_int, 500, _('Maximum number of lines that are printed in conversations. Oldest lines are cleared.')],
}
__options_per_key = {
......
......@@ -26,6 +26,7 @@
import tooltips
import dialogs
import locale
import Queue
import gtkgui_helpers
from common import gajim
......@@ -141,6 +142,10 @@ def __init__(self, account, used_in_history_window = False):
buffer.create_tag('focus-out-line', justification = gtk.JUSTIFY_CENTER)
size = gajim.config.get('max_conversation_lines')
size = 2 * size - 1
self.marks_queue = Queue.Queue(size)
self.allow_focus_out_line = True
# holds the iter's offset which points to the end of --- line
self.focus_out_end_iter_offset = None
......@@ -315,6 +320,9 @@ def clear(self, tv = None):
buffer = self.tv.get_buffer()
start, end = buffer.get_bounds()
buffer.delete(start, end)
size = gajim.config.get('max_conversation_lines')
size = 2 * size - 1
self.marks_queue = Queue.Queue(size)
self.focus_out_end_iter_offset = None
def visit_url_from_menuitem(self, widget, link):
......@@ -767,13 +775,29 @@ def print_conversation_line(self, text, jid, kind, name, tim,
'''prints 'chat' type messages'''
buffer = self.tv.get_buffer()
buffer.begin_user_action()
if self.marks_queue.full():
# remove oldest line
m1 = self.marks_queue.get()
m2 = self.marks_queue.get()
i1 = buffer.get_iter_at_mark(m1)
i2 = buffer.get_iter_at_mark(m2)
buffer.delete(i1, i2)
buffer.delete_mark(m1)
end_iter = buffer.get_end_iter()
at_the_end = False
if self.at_the_end():
at_the_end = True
# Create one mark and add it to queue once if it's the first line
# else twice (one for end bound, one for start bound)
mark = None
if buffer.get_char_count() > 0:
buffer.insert_with_tags_by_name(end_iter, '\n', 'eol')
mark = buffer.create_mark(None, end_iter, left_gravity=True)
self.marks_queue.put(mark)
if not mark:
mark = buffer.create_mark(None, end_iter, left_gravity=True)
self.marks_queue.put(mark)
if kind == 'incoming_queue':
kind = 'incoming'
if old_kind == 'incoming_queue':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment