2005-05-12 20:52:37 +02:00
|
|
|
## 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
|
2005-10-31 21:55:45 +01:00
|
|
|
import os
|
|
|
|
|
2005-11-20 22:58:08 +01:00
|
|
|
import gtkgui_helpers
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-04-14 09:05:10 +02:00
|
|
|
from common import gajim
|
2005-10-31 21:55:45 +01:00
|
|
|
from common import helpers
|
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)
|
|
|
|
|
2005-04-22 01:20:18 +02:00
|
|
|
GTKGUI_GLADE = 'gtkgui.glade'
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-06-11 00:45:50 +02:00
|
|
|
class HistoryWindow:
|
2005-10-09 19:07:29 +02:00
|
|
|
'''Class for browsing logs of conversations with contacts'''
|
|
|
|
|
2005-10-20 13:17:17 +02:00
|
|
|
def __init__(self, jid, account):
|
2005-10-09 19:07:29 +02:00
|
|
|
self.jid = jid
|
|
|
|
self.account = account
|
|
|
|
xml = gtk.glade.XML(GTKGUI_GLADE, 'history_window', APP)
|
|
|
|
self.window = xml.get_widget('history_window')
|
|
|
|
if account and gajim.contacts[account].has_key(jid):
|
|
|
|
contact = gajim.get_first_contact_instance_from_jid(account, jid)
|
|
|
|
title = _('Conversation History with %s') % contact.name
|
|
|
|
else:
|
|
|
|
title = _('Conversation History with %s') % jid
|
|
|
|
self.window.set_title(title)
|
|
|
|
self.history_buffer = xml.get_widget('history_textview').get_buffer()
|
2005-10-31 22:28:39 +01:00
|
|
|
|
2005-10-09 19:07:29 +02:00
|
|
|
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-11-20 22:58:08 +01:00
|
|
|
date = time.localtime()
|
|
|
|
y, m, d = date[0], date[1], date[2]
|
|
|
|
self.add_lines_for_date(y, m, d)
|
|
|
|
|
2005-10-09 19:07:29 +02:00
|
|
|
self.window.show_all()
|
|
|
|
|
2005-03-11 18:57:35 +01:00
|
|
|
def on_history_window_destroy(self, widget):
|
2005-11-13 16:08:47 +01:00
|
|
|
del gajim.interface.instances['logs'][self.jid]
|
2005-03-11 18:57:35 +01:00
|
|
|
|
|
|
|
def on_close_button_clicked(self, widget):
|
2005-05-12 20:52:37 +02:00
|
|
|
self.window.destroy()
|
2005-03-11 18:57:35 +01:00
|
|
|
|
2005-11-20 22:58:08 +01:00
|
|
|
def on_calendar_day_selected(self, widget):
|
|
|
|
year, month, day = widget.get_date() # integers
|
|
|
|
month = gtkgui_helpers.make_gtk_month_python_month(month)
|
|
|
|
self.add_lines_for_date(year, month, day)
|
|
|
|
|
|
|
|
def add_lines_for_date(self, year, month, day):
|
|
|
|
'''adds all the lines for given date in textbuffer'''
|
|
|
|
self.history_buffer.set_text('') # clear the buffer first
|
|
|
|
lines = gajim.logger.get_conversation_for_date(self.jid, year, month, day)
|
2005-04-16 00:02:13 +02:00
|
|
|
for line in lines:
|
2005-11-20 22:58:08 +01:00
|
|
|
# line[0] is date, line[1] is type of message
|
|
|
|
# line[2:] is message
|
|
|
|
date = line[0]
|
|
|
|
self.add_new_line(date, line[1], line[2:])
|
|
|
|
|
|
|
|
def add_new_line(self, date, type, data):
|
2005-10-31 21:55:45 +01:00
|
|
|
'''add a new line in textbuffer'''
|
2005-11-20 22:58:08 +01:00
|
|
|
buf = self.history_buffer
|
|
|
|
end_iter = buf.get_end_iter()
|
|
|
|
tim = time.strftime('[%X] ', time.localtime(float(date)))
|
|
|
|
buf.insert(end_iter, tim)
|
2005-06-30 08:17:56 +02:00
|
|
|
name = None
|
|
|
|
tag_name = ''
|
|
|
|
tag_msg = ''
|
2005-06-13 16:46:08 +02:00
|
|
|
if type == 'gc':
|
2005-06-30 08:17:56 +02:00
|
|
|
name = data[0]
|
2005-06-13 16:46:08 +02:00
|
|
|
msg = ':'.join(data[1:])
|
2005-06-30 08:17:56 +02:00
|
|
|
tag_name = 'incoming'
|
2005-06-13 16:46:08 +02:00
|
|
|
elif type == 'gcstatus':
|
|
|
|
nick = data[0]
|
|
|
|
show = data[1]
|
2005-06-30 08:17:56 +02:00
|
|
|
status_msg = ':'.join(data[2:])
|
2005-11-20 22:58:08 +01:00
|
|
|
if status_msg:
|
|
|
|
msg = _('%(nick)s is now %(status)s: %(status_msg)s') % {'nick': nick,
|
2005-11-21 07:20:32 +01:00
|
|
|
'status': helpers.get_uf_show(show), 'status_msg': status_msg }
|
2005-11-20 22:58:08 +01:00
|
|
|
else:
|
|
|
|
msg = _('%(nick)s is now %(status)s') % {'nick': nick,
|
2005-11-21 07:20:32 +01:00
|
|
|
'status': helpers.get_uf_show(show) }
|
2005-06-30 08:17:56 +02:00
|
|
|
tag_msg = 'status'
|
2005-06-13 16:46:08 +02:00
|
|
|
elif type == 'recv':
|
2005-06-30 08:17:56 +02:00
|
|
|
try:
|
2005-07-18 23:08:31 +02:00
|
|
|
name = gajim.contacts[self.account][self.jid][0].name
|
2005-06-30 08:17:56 +02:00
|
|
|
except:
|
|
|
|
name = None
|
|
|
|
if not name:
|
|
|
|
name = self.jid.split('@')[0]
|
2005-04-16 00:02:13 +02:00
|
|
|
msg = ':'.join(data[0:])
|
2005-06-30 08:17:56 +02:00
|
|
|
tag_name = 'incoming'
|
2005-04-16 00:02:13 +02:00
|
|
|
elif type == 'sent':
|
2005-07-18 23:08:31 +02:00
|
|
|
name = gajim.nicks[self.account]
|
2005-04-16 00:02:13 +02:00
|
|
|
msg = ':'.join(data[0:])
|
2005-06-30 08:17:56 +02:00
|
|
|
tag_name = 'outgoing'
|
2005-11-20 22:58:08 +01:00
|
|
|
else: # status
|
2005-06-30 08:17:56 +02:00
|
|
|
status_msg = ':'.join(data[1:])
|
2005-11-20 22:58:08 +01:00
|
|
|
if status_msg:
|
|
|
|
msg = _('Status is now: %(status)s: %(status_msg)s') % \
|
2005-11-21 07:20:32 +01:00
|
|
|
{'status': helpers.get_uf_show(data[0]), 'status_msg': status_msg}
|
2005-11-20 22:58:08 +01:00
|
|
|
else:
|
2005-11-21 07:20:32 +01:00
|
|
|
msg = _('Status is now: %(status)s') % { 'status':
|
|
|
|
helpers.get_uf_show(data[0]) }
|
2005-06-30 08:17:56 +02:00
|
|
|
tag_msg = 'status'
|
|
|
|
|
|
|
|
if name:
|
|
|
|
before_str = gajim.config.get('before_nickname')
|
|
|
|
after_str = gajim.config.get('after_nickname')
|
|
|
|
format = before_str + name + after_str + ' '
|
2005-11-20 22:58:08 +01:00
|
|
|
buf.insert_with_tags_by_name(end_iter, format, tag_name)
|
2005-06-30 08:17:56 +02:00
|
|
|
if tag_msg:
|
2005-11-20 22:58:08 +01:00
|
|
|
buf.insert_with_tags_by_name(end_iter, msg, tag_msg)
|
2005-06-30 08:17:56 +02:00
|
|
|
else:
|
2005-11-20 22:58:08 +01:00
|
|
|
buf.insert(end_iter, msg)
|