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

This commit is contained in:
Yann Leboulanger 2007-07-21 14:58:56 +00:00
parent ddd7c13e16
commit fb3eeb4a40
2 changed files with 25 additions and 0 deletions

View File

@ -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 = {

View File

@ -26,6 +26,7 @@ import os
import tooltips
import dialogs
import locale
import Queue
import gtkgui_helpers
from common import gajim
@ -141,6 +142,10 @@ class ConversationTextview:
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 @@ class ConversationTextview:
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 @@ class ConversationTextview:
'''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':