gajim-plural/src/history_window.py

183 lines
5.8 KiB
Python
Raw Normal View History

## history_window.py
2005-03-11 18:57:35 +01:00
##
## Gajim Team:
## - Yann Le Boulanger <asterix@lagaule.org>
## - Vincent Hanquez <tab@snarc.org>
## - Nikos Kouremenos <kourem@gmail.com>
##
## Copyright (C) 2003-2005 Gajim Team
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation; version 2 only.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
import gtk
import gtk.glade
import time
from common import gajim
2005-03-11 18:57:35 +01:00
from common import i18n
_ = i18n._
APP = i18n.APP
gtk.glade.bindtextdomain(APP, i18n.DIR)
gtk.glade.textdomain(APP)
GTKGUI_GLADE = 'gtkgui.glade'
2005-03-11 18:57:35 +01:00
class History_window:
2005-03-16 18:08:38 +01:00
"""Class for bowser agent window:
2005-03-11 18:57:35 +01:00
to know the agents on the selected server"""
def on_history_window_destroy(self, widget):
del self.plugin.windows['logs'][self.jid]
def on_close_button_clicked(self, widget):
self.window.destroy()
2005-03-11 18:57:35 +01:00
def on_earliest_button_clicked(self, widget):
start, end = self.history_buffer.get_bounds()
self.history_buffer.delete(start, end)
self.earliest_button.set_sensitive(False)
self.previous_button.set_sensitive(False)
self.forward_button.set_sensitive(True)
self.latest_button.set_sensitive(True)
end = 50
if end > self.nb_line:
end = self.nb_line
2005-04-16 00:02:13 +02:00
nb, lines = gajim.logger.read(self.jid, 0, end)
self.set_buttons_sensitivity(nb)
for line in lines:
self.new_line(line[0], line[1], line[2:])
self.num_begin = 0
2005-03-11 18:57:35 +01:00
def on_previous_button_clicked(self, widget):
start, end = self.history_buffer.get_bounds()
self.history_buffer.delete(start, end)
self.earliest_button.set_sensitive(True)
self.previous_button.set_sensitive(True)
self.forward_button.set_sensitive(True)
self.latest_button.set_sensitive(True)
begin = self.num_begin - 50
if begin < 0:
begin = 0
end = begin + 50
if end > self.nb_line:
end = self.nb_line
2005-04-16 00:02:13 +02:00
nb, lines = gajim.logger.read(self.jid, begin, end)
self.set_buttons_sensitivity(nb)
for line in lines:
self.new_line(line[0], line[1], line[2:])
self.num_begin = begin
2005-03-11 18:57:35 +01:00
def on_forward_button_clicked(self, widget):
start, end = self.history_buffer.get_bounds()
self.history_buffer.delete(start, end)
self.earliest_button.set_sensitive(True)
self.previous_button.set_sensitive(True)
self.forward_button.set_sensitive(True)
self.latest_button.set_sensitive(True)
begin = self.num_begin + 50
if begin > self.nb_line:
begin = self.nb_line
end = begin + 50
if end > self.nb_line:
end = self.nb_line
2005-04-16 00:02:13 +02:00
nb, lines = gajim.logger.read(self.jid, begin, end)
self.set_buttons_sensitivity(nb)
for line in lines:
self.new_line(line[0], line[1], line[2:])
self.num_begin = begin
2005-03-11 18:57:35 +01:00
def on_latest_button_clicked(self, widget):
start, end = self.history_buffer.get_bounds()
self.history_buffer.delete(start, end)
self.earliest_button.set_sensitive(True)
self.previous_button.set_sensitive(True)
self.forward_button.set_sensitive(False)
self.latest_button.set_sensitive(False)
begin = self.nb_line - 50
if begin < 0:
begin = 0
2005-04-16 00:02:13 +02:00
nb, lines = gajim.logger.read(self.jid, begin, self.nb_line)
self.set_buttons_sensitivity(nb)
for line in lines:
self.new_line(line[0], line[1], line[2:])
self.num_begin = begin
2005-03-11 18:57:35 +01:00
2005-04-16 00:02:13 +02:00
def set_buttons_sensitivity(self, nb):
if nb == 50:
2005-03-11 18:57:35 +01:00
self.earliest_button.set_sensitive(False)
self.previous_button.set_sensitive(False)
2005-04-16 00:02:13 +02:00
if nb == self.nb_line:
2005-03-11 18:57:35 +01:00
self.forward_button.set_sensitive(False)
self.latest_button.set_sensitive(False)
2005-04-16 00:02:13 +02:00
def new_line(self, date, type, data):
"""write a new line"""
buffer = self.history_buffer
start_iter = buffer.get_start_iter()
end_iter = buffer.get_end_iter()
2005-04-16 00:02:13 +02:00
tim = time.strftime('[%x %X] ', time.localtime(float(date)))
buffer.insert(start_iter, tim)
2005-04-16 00:02:13 +02:00
if type == 'recv':
msg = ':'.join(data[0:])
buffer.insert_with_tags_by_name(start_iter, msg,
'incoming')
2005-04-16 00:02:13 +02:00
elif type == 'sent':
msg = ':'.join(data[0:])
buffer.insert_with_tags_by_name(start_iter, msg,
'outgoing')
2005-03-11 18:57:35 +01:00
else:
2005-04-16 00:02:13 +02:00
msg = ':'.join(data[1:])
buffer.insert_with_tags_by_name(start_iter,
_('Status is now: ') + data[0]
+ ': ' + msg, 'status')
2005-03-11 18:57:35 +01:00
def __init__(self, plugin, jid, account=None):
2005-03-11 18:57:35 +01:00
self.plugin = plugin
self.jid = jid
2005-04-16 00:02:13 +02:00
self.nb_line = gajim.logger.get_nb_line(jid)
2005-03-11 18:57:35 +01:00
xml = gtk.glade.XML(GTKGUI_GLADE, 'history_window', APP)
self.window = xml.get_widget('history_window')
if account and self.plugin.roster.contacts[account].has_key(jid):
list_users = self.plugin.roster.contacts[account][self.jid]
user = list_users[0]
title = 'Conversation History with ' + user.name
else:
title = 'Conversation History with ' + jid
self.window.set_title(title)
2005-03-11 18:57:35 +01:00
self.history_buffer = xml.get_widget('history_textview').get_buffer()
self.earliest_button = xml.get_widget('earliest_button')
self.previous_button = xml.get_widget('previous_button')
self.forward_button = xml.get_widget('forward_button')
self.latest_button = xml.get_widget('latest_button')
xml.signal_autoconnect(self)
tag = self.history_buffer.create_tag('incoming')
color = gajim.config.get('inmsgcolor')
tag.set_property('foreground', color)
tag = self.history_buffer.create_tag('outgoing')
color = gajim.config.get('outmsgcolor')
tag.set_property('foreground', color)
tag = self.history_buffer.create_tag('status')
color = gajim.config.get('statusmsgcolor')
tag.set_property('foreground', color)
2005-04-16 00:02:13 +02:00
begin = 0
if self.nb_line > 50:
begin = self.nb_line - 50
nb, lines = gajim.logger.read(self.jid, begin, self.nb_line)
self.set_buttons_sensitivity(nb)
for line in lines:
self.new_line(line[0], line[1], line[2:])
self.num_begin = begin
self.window.show_all()