2005-05-12 20:52:37 +02:00
|
|
|
## history_window.py
|
2005-03-11 18:57:35 +01:00
|
|
|
##
|
2005-12-09 18:15:30 +01:00
|
|
|
## Contributors for this file:
|
2007-10-22 13:33:50 +02:00
|
|
|
## - Yann Leboulanger <asterix@lagaule.org>
|
2005-03-11 18:57:35 +01:00
|
|
|
## - Nikos Kouremenos <kourem@gmail.com>
|
|
|
|
##
|
2007-10-22 13:33:50 +02:00
|
|
|
## Copyright (C) 2003-2004 Yann Leboulanger <asterix@lagaule.org>
|
2005-12-10 00:30:28 +01:00
|
|
|
## Vincent Hanquez <tab@snarc.org>
|
2007-10-22 13:33:50 +02:00
|
|
|
## Copyright (C) 2005 Yann Leboulanger <asterix@lagaule.org>
|
2005-12-10 00:30:28 +01:00
|
|
|
## Vincent Hanquez <tab@snarc.org>
|
2006-09-28 13:31:25 +02:00
|
|
|
## Nikos Kouremenos <kourem@gmail.com>
|
2005-12-10 00:30:28 +01:00
|
|
|
## Dimitur Kirov <dkirov@gmail.com>
|
|
|
|
## Travis Shirk <travis@pobox.com>
|
|
|
|
## Norman Rasmussen <norman@rasmussen.co.za>
|
2008-04-03 19:48:55 +02:00
|
|
|
## Copyright (C) 2007-2008 Stephan Erb <steve-e@h3c.de>
|
2005-03-11 18:57:35 +01:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2005-03-11 18:57:35 +01:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-10-22 13:13:13 +02:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2005-03-11 18:57:35 +01:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2005-03-11 18:57:35 +01:00
|
|
|
## 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.
|
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## You should have received a copy of the GNU General Public License
|
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
##
|
2005-03-11 18:57:35 +01:00
|
|
|
|
|
|
|
import gtk
|
2005-11-27 01:22:26 +01:00
|
|
|
import gobject
|
2005-03-11 18:57:35 +01:00
|
|
|
import time
|
2005-11-24 02:39:47 +01:00
|
|
|
import calendar
|
2005-10-31 21:55:45 +01:00
|
|
|
|
2005-11-20 22:58:08 +01:00
|
|
|
import gtkgui_helpers
|
2005-12-12 14:00:46 +01:00
|
|
|
import conversation_textview
|
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
|
|
|
|
2005-11-26 00:23:25 +01:00
|
|
|
from common.logger import Constants
|
|
|
|
|
|
|
|
constants = Constants()
|
|
|
|
|
2008-04-03 19:48:55 +02:00
|
|
|
# Completion dict
|
|
|
|
(
|
|
|
|
C_INFO_JID,
|
|
|
|
C_INFO_ACCOUNT,
|
|
|
|
C_INFO_NAME,
|
|
|
|
C_INFO_COMPLETION
|
|
|
|
) = range(4)
|
|
|
|
|
2005-12-27 14:38:42 +01:00
|
|
|
# contact_name, date, message, time
|
2005-11-29 15:41:01 +01:00
|
|
|
(
|
2007-10-07 01:06:09 +02:00
|
|
|
C_LOG_JID,
|
2005-11-29 15:41:01 +01:00
|
|
|
C_CONTACT_NAME,
|
2006-02-03 00:42:57 +01:00
|
|
|
C_UNIXTIME,
|
2005-12-27 14:38:42 +01:00
|
|
|
C_MESSAGE,
|
|
|
|
C_TIME
|
2007-10-07 01:06:09 +02:00
|
|
|
) = range(5)
|
2005-11-29 15:41:01 +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'''
|
|
|
|
|
2007-09-14 22:18:06 +02:00
|
|
|
def __init__(self, jid = None, account = None):
|
2006-05-02 17:53:25 +02:00
|
|
|
xml = gtkgui_helpers.get_glade('history_window.glade')
|
2005-10-09 19:07:29 +02:00
|
|
|
self.window = xml.get_widget('history_window')
|
2007-09-14 22:18:06 +02:00
|
|
|
self.jid_entry = xml.get_widget('jid_entry')
|
2005-11-29 22:47:47 +01:00
|
|
|
self.calendar = xml.get_widget('calendar')
|
2005-12-12 14:00:46 +01:00
|
|
|
scrolledwindow = xml.get_widget('scrolledwindow')
|
2006-10-07 15:23:20 +02:00
|
|
|
self.history_textview = conversation_textview.ConversationTextview(
|
|
|
|
account, used_in_history_window = True)
|
2006-04-18 17:36:16 +02:00
|
|
|
scrolledwindow.add(self.history_textview.tv)
|
|
|
|
self.history_buffer = self.history_textview.tv.get_buffer()
|
2005-12-27 14:38:42 +01:00
|
|
|
self.history_buffer.create_tag('highlight', background = 'yellow')
|
2007-09-14 22:18:06 +02:00
|
|
|
self.checkbutton = xml.get_widget('log_history_checkbutton')
|
2008-04-03 19:48:55 +02:00
|
|
|
self.checkbutton.connect('toggled',
|
|
|
|
self.on_log_history_checkbutton_toggled)
|
2005-11-29 15:41:01 +01:00
|
|
|
self.query_entry = xml.get_widget('query_entry')
|
2007-10-07 01:06:09 +02:00
|
|
|
self.query_combobox = xml.get_widget('query_combobox')
|
|
|
|
self.query_combobox.set_active(0)
|
2005-11-29 15:41:01 +01:00
|
|
|
self.results_treeview = xml.get_widget('results_treeview')
|
2008-04-03 19:48:55 +02:00
|
|
|
self.results_window = xml.get_widget('results_scrolledwindow')
|
2007-09-14 22:18:06 +02:00
|
|
|
|
2005-12-27 14:38:42 +01:00
|
|
|
# contact_name, date, message, time
|
2007-10-07 01:06:09 +02:00
|
|
|
model = gtk.ListStore(str, str, str, str, str)
|
2005-11-29 15:41:01 +01:00
|
|
|
self.results_treeview.set_model(model)
|
|
|
|
col = gtk.TreeViewColumn(_('Name'))
|
|
|
|
self.results_treeview.append_column(col)
|
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
col.pack_start(renderer)
|
|
|
|
col.set_attributes(renderer, text = C_CONTACT_NAME)
|
2006-02-03 00:57:52 +01:00
|
|
|
col.set_sort_column_id(C_CONTACT_NAME) # user can click this header and sort
|
2005-12-01 00:17:25 +01:00
|
|
|
col.set_resizable(True)
|
2005-11-29 15:41:01 +01:00
|
|
|
|
|
|
|
col = gtk.TreeViewColumn(_('Date'))
|
|
|
|
self.results_treeview.append_column(col)
|
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
col.pack_start(renderer)
|
2006-02-03 00:42:57 +01:00
|
|
|
col.set_attributes(renderer, text = C_UNIXTIME)
|
2006-02-03 00:57:52 +01:00
|
|
|
col.set_sort_column_id(C_UNIXTIME) # user can click this header and sort
|
2005-12-01 00:17:25 +01:00
|
|
|
col.set_resizable(True)
|
2005-11-29 15:41:01 +01:00
|
|
|
|
|
|
|
col = gtk.TreeViewColumn(_('Message'))
|
|
|
|
self.results_treeview.append_column(col)
|
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
col.pack_start(renderer)
|
|
|
|
col.set_attributes(renderer, text = C_MESSAGE)
|
2005-12-01 00:17:25 +01:00
|
|
|
col.set_resizable(True)
|
2008-04-03 19:48:55 +02:00
|
|
|
|
|
|
|
self.jid = None # The history we are currently viewing
|
|
|
|
self.account = None
|
|
|
|
self.completion_dict = {}
|
|
|
|
self.accounts_seen_online = [] # Update dict when new accounts connect
|
|
|
|
self.jids_to_search = []
|
2008-05-31 21:41:42 +02:00
|
|
|
|
|
|
|
# This will load history too
|
|
|
|
gobject.idle_add(self._fill_completion_dict().next)
|
2008-04-03 19:48:55 +02:00
|
|
|
|
|
|
|
if jid:
|
|
|
|
self.jid_entry.set_text(jid)
|
|
|
|
|
2005-10-09 19:07:29 +02:00
|
|
|
xml.signal_autoconnect(self)
|
2007-09-14 22:18:06 +02:00
|
|
|
self.window.show_all()
|
|
|
|
|
2008-04-03 19:48:55 +02:00
|
|
|
def _fill_completion_dict(self):
|
2008-05-31 21:41:42 +02:00
|
|
|
'''Fill completion_dict for key auto completion. Then load history for
|
|
|
|
current jid (by calling another function).
|
2008-05-03 12:20:56 +02:00
|
|
|
|
2008-04-03 19:48:55 +02:00
|
|
|
Key will be either jid or full_completion_name
|
|
|
|
(contact name or long description like "pm-contact from groupchat....")
|
|
|
|
|
2008-05-03 12:20:56 +02:00
|
|
|
{key : (jid, account, nick_name, full_completion_name}
|
2008-05-31 21:41:42 +02:00
|
|
|
this is a generator and does pseudo-threading via idle_add()
|
2008-05-03 12:20:56 +02:00
|
|
|
'''
|
2008-04-03 19:48:55 +02:00
|
|
|
liststore = gtkgui_helpers.get_completion_liststore(self.jid_entry)
|
|
|
|
|
|
|
|
# Add all jids in logs.db:
|
|
|
|
db_jids = gajim.logger.get_jids_in_db()
|
|
|
|
self.completion_dict = dict.fromkeys(db_jids)
|
|
|
|
|
|
|
|
self.accounts_seen_online = gajim.contacts.get_accounts()[:]
|
|
|
|
|
|
|
|
# Enhance contacts of online accounts with contact. Needed for mapping below
|
|
|
|
for account in self.accounts_seen_online:
|
|
|
|
self.completion_dict.update(
|
|
|
|
helpers.get_contact_dict_for_account(account))
|
|
|
|
|
2008-05-03 12:15:47 +02:00
|
|
|
muc_active_img = gtkgui_helpers.load_icon('muc_active')
|
2008-05-03 12:59:18 +02:00
|
|
|
contact_img = gajim.interface.jabber_state_images['16']['online']
|
|
|
|
muc_active_pix = muc_active_img.get_pixbuf()
|
2008-05-31 21:41:42 +02:00
|
|
|
contact_pix = contact_img.get_pixbuf()
|
|
|
|
|
2008-04-03 19:48:55 +02:00
|
|
|
keys = self.completion_dict.keys()
|
2008-05-31 21:41:42 +02:00
|
|
|
# Move the actual jid at first so we load history faster
|
|
|
|
actual_jid = self.jid_entry.get_text().decode('utf-8')
|
2008-06-04 20:58:14 +02:00
|
|
|
if actual_jid in keys:
|
|
|
|
keys.remove(actual_jid)
|
|
|
|
keys.insert(0, actual_jid)
|
2008-04-03 19:48:55 +02:00
|
|
|
# Map jid to info tuple
|
2008-05-03 12:59:18 +02:00
|
|
|
# Warning : This for is time critical with big DB
|
2008-04-03 19:48:55 +02:00
|
|
|
for key in keys:
|
|
|
|
completed = key
|
|
|
|
contact = self.completion_dict[completed]
|
|
|
|
if contact:
|
|
|
|
info_name = contact.get_shown_name()
|
|
|
|
info_completion = info_name
|
|
|
|
info_jid = contact.jid
|
|
|
|
else:
|
|
|
|
# Corrensponding account is offline, we know nothing
|
|
|
|
info_name = completed.split('@')[0]
|
|
|
|
info_completion = completed
|
|
|
|
info_jid = completed
|
|
|
|
|
|
|
|
info_acc = self._get_account_for_jid(info_jid)
|
|
|
|
|
|
|
|
if gajim.logger.jid_is_room_jid(completed) or\
|
|
|
|
gajim.logger.jid_is_from_pm(completed):
|
2008-05-03 12:59:18 +02:00
|
|
|
pix = muc_active_pix
|
2008-04-03 19:48:55 +02:00
|
|
|
if gajim.logger.jid_is_from_pm(completed):
|
|
|
|
# It's PM. Make it easier to find
|
|
|
|
room, nick = gajim.get_room_and_nick_from_fjid(completed)
|
|
|
|
info_completion = '%s from %s' % (nick, room)
|
|
|
|
completed = info_completion
|
|
|
|
info_name = nick
|
|
|
|
else:
|
2008-05-03 12:59:18 +02:00
|
|
|
pix = contact_pix
|
2008-05-31 21:41:42 +02:00
|
|
|
|
2008-05-03 12:59:18 +02:00
|
|
|
liststore.append((pix, completed))
|
2008-04-03 19:48:55 +02:00
|
|
|
self.completion_dict[key] = (info_jid, info_acc, info_name,
|
|
|
|
info_completion)
|
|
|
|
self.completion_dict[completed] = (info_jid, info_acc,
|
|
|
|
info_name, info_completion)
|
2008-05-31 21:41:42 +02:00
|
|
|
if key == actual_jid:
|
|
|
|
self._load_history(info_jid, info_acc)
|
|
|
|
yield True
|
2008-04-03 19:48:55 +02:00
|
|
|
keys.sort()
|
2008-05-31 21:41:42 +02:00
|
|
|
yield False
|
2008-04-03 19:48:55 +02:00
|
|
|
|
|
|
|
def _get_account_for_jid(self, jid):
|
|
|
|
'''Return the corresponding account of the jid.
|
|
|
|
May be None if an account could not be found'''
|
|
|
|
accounts = gajim.contacts.get_accounts()
|
|
|
|
account = None
|
|
|
|
for acc in accounts:
|
|
|
|
jid_list = gajim.contacts.get_jid_list(acc)
|
|
|
|
gc_list = gajim.contacts.get_gc_list(acc)
|
|
|
|
if jid in jid_list or jid in gc_list:
|
|
|
|
account = acc
|
|
|
|
break
|
|
|
|
return account
|
|
|
|
|
2007-09-14 22:18:06 +02:00
|
|
|
def on_history_window_destroy(self, widget):
|
|
|
|
self.history_textview.del_handlers()
|
|
|
|
del gajim.interface.instances['logs']
|
|
|
|
|
2007-10-09 20:34:10 +02:00
|
|
|
def on_history_window_key_press_event(self, widget, event):
|
|
|
|
if event.keyval == gtk.keysyms.Escape:
|
|
|
|
self.window.destroy()
|
|
|
|
|
2007-09-14 22:18:06 +02:00
|
|
|
def on_close_button_clicked(self, widget):
|
|
|
|
self.window.destroy()
|
|
|
|
|
|
|
|
def on_jid_entry_activate(self, widget):
|
2008-04-03 19:48:55 +02:00
|
|
|
if not self.query_combobox.get_active() < 0:
|
|
|
|
# Don't disable querybox when we have changed the combobox
|
|
|
|
# to GC or All and hit enter
|
|
|
|
return
|
|
|
|
jid = self.jid_entry.get_text().decode('utf-8')
|
|
|
|
account = None # we don't know the account, could be any. Search for it!
|
|
|
|
self._load_history(jid, account)
|
|
|
|
self.results_window.set_property('visible', False)
|
2008-03-13 02:15:57 +01:00
|
|
|
|
2008-04-03 19:48:55 +02:00
|
|
|
def on_jid_entry_focus(self, widget, event):
|
|
|
|
widget.select_region(0, -1) # select text
|
|
|
|
|
|
|
|
def _load_history(self, jid_or_name, account = None):
|
|
|
|
'''Load history for the given jid/name and show it'''
|
|
|
|
if jid_or_name and self.completion_dict.has_key(jid_or_name):
|
2008-03-13 02:15:57 +01:00
|
|
|
# a full qualified jid or a contact name was entered
|
2008-04-03 19:48:55 +02:00
|
|
|
info_jid, info_account, info_name, info_completion = self.completion_dict[jid_or_name]
|
|
|
|
self.jids_to_search = [info_jid]
|
|
|
|
self.jid = info_jid
|
|
|
|
|
|
|
|
if account:
|
|
|
|
self.account = account
|
2007-10-07 01:06:09 +02:00
|
|
|
else:
|
2008-04-03 19:48:55 +02:00
|
|
|
self.account = info_account
|
2008-03-13 02:15:57 +01:00
|
|
|
if self.account is None:
|
2008-04-03 19:48:55 +02:00
|
|
|
# We don't know account. Probably a gc not opened or an
|
2008-03-13 02:15:57 +01:00
|
|
|
# account not connected.
|
|
|
|
# Disable possibility to say if we want to log or not
|
2007-09-21 18:30:19 +02:00
|
|
|
self.checkbutton.set_sensitive(False)
|
|
|
|
else:
|
2008-03-13 02:15:57 +01:00
|
|
|
# Are log disabled for account ?
|
|
|
|
if self.account in gajim.config.get_per('accounts', self.account,
|
2007-09-21 18:30:19 +02:00
|
|
|
'no_log_for').split(' '):
|
2008-03-13 02:15:57 +01:00
|
|
|
self.checkbutton.set_active(False)
|
|
|
|
self.checkbutton.set_sensitive(False)
|
|
|
|
else:
|
|
|
|
# Are log disabled for jid ?
|
|
|
|
log = True
|
|
|
|
if self.jid in gajim.config.get_per('accounts', self.account,
|
|
|
|
'no_log_for').split(' '):
|
|
|
|
log = False
|
|
|
|
self.checkbutton.set_active(log)
|
|
|
|
self.checkbutton.set_sensitive(True)
|
2008-04-03 19:48:55 +02:00
|
|
|
|
|
|
|
self.jids_to_search = [info_jid]
|
2007-09-14 22:18:06 +02:00
|
|
|
|
|
|
|
# select logs for last date we have logs with contact
|
|
|
|
self.calendar.set_sensitive(True)
|
2008-06-01 00:13:57 +02:00
|
|
|
last_log = \
|
|
|
|
gajim.logger.get_last_date_that_has_logs(self.jid, self.account)
|
2007-10-07 01:06:09 +02:00
|
|
|
|
2008-06-01 00:13:57 +02:00
|
|
|
date = time.localtime(last_log)
|
2007-10-07 01:06:09 +02:00
|
|
|
|
|
|
|
y, m, d = date[0], date[1], date[2]
|
|
|
|
gtk_month = gtkgui_helpers.make_python_month_gtk_month(m)
|
|
|
|
self.calendar.select_month(gtk_month, y)
|
|
|
|
self.calendar.select_day(d)
|
2007-09-14 22:18:06 +02:00
|
|
|
|
2007-10-07 01:06:09 +02:00
|
|
|
self.query_entry.set_sensitive(True)
|
2008-04-03 19:48:55 +02:00
|
|
|
self.query_entry.grab_focus()
|
2007-10-07 01:06:09 +02:00
|
|
|
|
2008-04-03 19:48:55 +02:00
|
|
|
title = _('Conversation History with %s') % info_name
|
2007-09-14 22:18:06 +02:00
|
|
|
self.window.set_title(title)
|
2008-04-03 19:48:55 +02:00
|
|
|
self.jid_entry.set_text(info_completion)
|
2007-09-14 22:18:06 +02:00
|
|
|
|
|
|
|
else: # neither a valid jid, nor an existing contact name was entered
|
2007-10-07 01:06:09 +02:00
|
|
|
# we have got nothing to show or to search in
|
2008-04-03 19:48:55 +02:00
|
|
|
self.jid = None
|
|
|
|
self.account = None
|
|
|
|
|
2007-10-07 01:06:09 +02:00
|
|
|
self.history_buffer.set_text('') # clear the buffer
|
|
|
|
self.query_entry.set_sensitive(False)
|
2007-09-14 22:18:06 +02:00
|
|
|
|
2007-10-07 01:06:09 +02:00
|
|
|
self.checkbutton.set_sensitive(False)
|
2007-09-14 22:18:06 +02:00
|
|
|
self.calendar.set_sensitive(False)
|
2007-10-07 01:06:09 +02:00
|
|
|
self.calendar.clear_marks()
|
2008-04-03 19:48:55 +02:00
|
|
|
|
|
|
|
self.results_window.set_property('visible', False)
|
2007-09-14 22:18:06 +02:00
|
|
|
|
|
|
|
title = _('Conversation History')
|
|
|
|
self.window.set_title(title)
|
|
|
|
|
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)
|
2008-04-03 19:48:55 +02:00
|
|
|
self._add_lines_for_date(year, month, day)
|
2005-11-24 02:39:47 +01:00
|
|
|
|
2005-11-27 01:22:26 +01:00
|
|
|
def on_calendar_month_changed(self, widget):
|
2008-05-31 22:49:48 +02:00
|
|
|
'''asks for days in this month if they have logs it bolds them (marks
|
|
|
|
them)
|
|
|
|
'''
|
2005-11-27 01:22:26 +01:00
|
|
|
year, month, day = widget.get_date() # integers
|
|
|
|
# in gtk January is 1, in python January is 0,
|
|
|
|
# I want the second
|
|
|
|
# first day of month is 1 not 0
|
|
|
|
widget.clear_marks()
|
|
|
|
month = gtkgui_helpers.make_gtk_month_python_month(month)
|
2008-05-31 22:49:48 +02:00
|
|
|
weekday, days_in_this_month = calendar.monthrange(year, month)
|
|
|
|
log_days = gajim.logger.get_days_with_logs(self.jid, year,
|
|
|
|
month, days_in_this_month, self.account)
|
|
|
|
for day in log_days:
|
|
|
|
widget.mark_day(day)
|
2005-11-20 22:58:08 +01:00
|
|
|
|
2008-04-03 19:48:55 +02:00
|
|
|
def _get_string_show_from_constant_int(self, show):
|
2005-11-26 00:23:25 +01:00
|
|
|
if show == constants.SHOW_ONLINE:
|
|
|
|
show = 'online'
|
|
|
|
elif show == constants.SHOW_CHAT:
|
|
|
|
show = 'chat'
|
|
|
|
elif show == constants.SHOW_AWAY:
|
|
|
|
show = 'away'
|
|
|
|
elif show == constants.SHOW_XA:
|
|
|
|
show = 'xa'
|
|
|
|
elif show == constants.SHOW_DND:
|
|
|
|
show = 'dnd'
|
|
|
|
elif show == constants.SHOW_OFFLINE:
|
|
|
|
show = 'offline'
|
|
|
|
|
|
|
|
return show
|
|
|
|
|
2008-04-03 19:48:55 +02:00
|
|
|
def _add_lines_for_date(self, year, month, day):
|
2005-11-20 22:58:08 +01:00
|
|
|
'''adds all the lines for given date in textbuffer'''
|
|
|
|
self.history_buffer.set_text('') # clear the buffer first
|
2005-11-29 20:41:08 +01:00
|
|
|
self.last_time_printout = 0
|
2006-06-04 11:54:11 +02:00
|
|
|
|
|
|
|
lines = gajim.logger.get_conversation_for_date(self.jid, year, month, day, self.account)
|
2005-11-23 20:12:52 +01:00
|
|
|
# lines holds list with tupples that have:
|
|
|
|
# contact_name, time, kind, show, message
|
2005-04-16 00:02:13 +02:00
|
|
|
for line in lines:
|
2005-11-23 20:12:52 +01:00
|
|
|
# line[0] is contact_name, line[1] is time of message
|
|
|
|
# line[2] is kind, line[3] is show, line[4] is message
|
2008-04-03 19:48:55 +02:00
|
|
|
self._add_new_line(line[0], line[1], line[2], line[3], line[4])
|
2005-11-20 22:58:08 +01:00
|
|
|
|
2008-04-03 19:48:55 +02:00
|
|
|
def _add_new_line(self, contact_name, tim, kind, show, message):
|
2005-10-31 21:55:45 +01:00
|
|
|
'''add a new line in textbuffer'''
|
2006-03-01 22:32:49 +01:00
|
|
|
if not message and kind not in (constants.KIND_STATUS,
|
|
|
|
constants.KIND_GCSTATUS):
|
2005-11-30 17:04:23 +01:00
|
|
|
return
|
2005-11-20 22:58:08 +01:00
|
|
|
buf = self.history_buffer
|
|
|
|
end_iter = buf.get_end_iter()
|
2005-11-29 20:41:08 +01:00
|
|
|
|
|
|
|
if gajim.config.get('print_time') == 'always':
|
2007-01-12 20:27:00 +01:00
|
|
|
timestamp_str = gajim.config.get('time_stamp')
|
|
|
|
timestamp_str = helpers.from_one_line(timestamp_str)
|
|
|
|
tim = time.strftime(timestamp_str, time.localtime(float(tim)))
|
2005-11-29 20:41:08 +01:00
|
|
|
buf.insert(end_iter, tim) # add time
|
|
|
|
elif gajim.config.get('print_time') == 'sometimes':
|
|
|
|
every_foo_seconds = 60 * gajim.config.get(
|
|
|
|
'print_ichat_every_foo_minutes')
|
|
|
|
seconds_passed = tim - self.last_time_printout
|
|
|
|
if seconds_passed > every_foo_seconds:
|
|
|
|
self.last_time_printout = tim
|
|
|
|
tim = time.strftime('%X ', time.localtime(float(tim)))
|
|
|
|
buf.insert_with_tags_by_name(end_iter, tim + '\n',
|
2005-12-27 14:49:34 +01:00
|
|
|
'time_sometimes')
|
2005-11-29 20:41:08 +01:00
|
|
|
|
2005-06-30 08:17:56 +02:00
|
|
|
tag_name = ''
|
|
|
|
tag_msg = ''
|
2005-11-23 20:12:52 +01:00
|
|
|
|
2008-04-03 19:48:55 +02:00
|
|
|
show = self._get_string_show_from_constant_int(show)
|
2005-11-26 00:23:25 +01:00
|
|
|
|
|
|
|
if kind == constants.KIND_GC_MSG:
|
2005-06-30 08:17:56 +02:00
|
|
|
tag_name = 'incoming'
|
2006-03-01 22:32:49 +01:00
|
|
|
elif kind in (constants.KIND_SINGLE_MSG_RECV,
|
|
|
|
constants.KIND_CHAT_MSG_RECV):
|
2008-04-03 19:48:55 +02:00
|
|
|
contact_name = self.completion_dict[self.jid][C_INFO_NAME]
|
2005-06-30 08:17:56 +02:00
|
|
|
tag_name = 'incoming'
|
2006-03-01 22:32:49 +01:00
|
|
|
elif kind in (constants.KIND_SINGLE_MSG_SENT,
|
|
|
|
constants.KIND_CHAT_MSG_SENT):
|
2008-03-13 03:12:25 +01:00
|
|
|
if self.account:
|
|
|
|
contact_name = gajim.nicks[self.account]
|
|
|
|
else:
|
|
|
|
# we don't have roster, we don't know our own nick, use first
|
|
|
|
# account one (urk!)
|
|
|
|
account = gajim.contacts.get_accounts()[0]
|
|
|
|
contact_name = gajim.nicks[account]
|
2005-06-30 08:17:56 +02:00
|
|
|
tag_name = 'outgoing'
|
2005-11-26 00:23:25 +01:00
|
|
|
elif kind == constants.KIND_GCSTATUS:
|
2005-11-23 20:12:52 +01:00
|
|
|
# message here (if not None) is status message
|
|
|
|
if message:
|
|
|
|
message = _('%(nick)s is now %(status)s: %(status_msg)s') %\
|
|
|
|
{'nick': contact_name, 'status': helpers.get_uf_show(show),
|
|
|
|
'status_msg': message }
|
2005-11-20 22:58:08 +01:00
|
|
|
else:
|
2005-11-23 20:12:52 +01:00
|
|
|
message = _('%(nick)s is now %(status)s') % {'nick': contact_name,
|
|
|
|
'status': helpers.get_uf_show(show) }
|
|
|
|
tag_msg = 'status'
|
|
|
|
else: # 'status'
|
|
|
|
# message here (if not None) is status message
|
|
|
|
if message:
|
|
|
|
message = _('Status is now: %(status)s: %(status_msg)s') % \
|
|
|
|
{'status': helpers.get_uf_show(show), 'status_msg': message}
|
|
|
|
else:
|
|
|
|
message = _('Status is now: %(status)s') % { 'status':
|
|
|
|
helpers.get_uf_show(show) }
|
2005-06-30 08:17:56 +02:00
|
|
|
tag_msg = 'status'
|
|
|
|
|
2005-11-23 20:12:52 +01:00
|
|
|
# do not do this if gcstats, avoid dupping contact_name
|
|
|
|
# eg. nkour: nkour is now Offline
|
2005-11-26 00:23:25 +01:00
|
|
|
if contact_name and kind != constants.KIND_GCSTATUS:
|
2005-11-23 20:12:52 +01:00
|
|
|
# add stuff before and after contact name
|
2005-06-30 08:17:56 +02:00
|
|
|
before_str = gajim.config.get('before_nickname')
|
2006-10-08 02:31:05 +02:00
|
|
|
before_str = helpers.from_one_line(before_str)
|
2005-06-30 08:17:56 +02:00
|
|
|
after_str = gajim.config.get('after_nickname')
|
2006-10-08 02:31:05 +02:00
|
|
|
after_str = helpers.from_one_line(after_str)
|
2005-11-23 20:12:52 +01:00
|
|
|
format = before_str + contact_name + after_str + ' '
|
2005-11-20 22:58:08 +01:00
|
|
|
buf.insert_with_tags_by_name(end_iter, format, tag_name)
|
2005-11-23 20:12:52 +01:00
|
|
|
|
|
|
|
message = message + '\n'
|
2005-06-30 08:17:56 +02:00
|
|
|
if tag_msg:
|
2005-12-13 08:43:45 +01:00
|
|
|
self.history_textview.print_real_text(message, [tag_msg])
|
2005-06-30 08:17:56 +02:00
|
|
|
else:
|
2005-12-12 14:00:46 +01:00
|
|
|
self.history_textview.print_real_text(message)
|
2005-11-29 15:41:01 +01:00
|
|
|
|
2007-10-07 01:06:09 +02:00
|
|
|
def on_query_entry_activate(self, widget):
|
2005-11-29 15:41:01 +01:00
|
|
|
text = self.query_entry.get_text()
|
|
|
|
model = self.results_treeview.get_model()
|
|
|
|
model.clear()
|
2005-11-29 20:41:08 +01:00
|
|
|
if text == '':
|
2008-04-03 19:48:55 +02:00
|
|
|
self.results_window.set_property('visible', False)
|
2005-11-29 20:41:08 +01:00
|
|
|
return
|
2008-04-03 19:48:55 +02:00
|
|
|
else:
|
|
|
|
self.results_window.set_property('visible', True)
|
2007-10-07 01:06:09 +02:00
|
|
|
|
2008-04-03 19:48:55 +02:00
|
|
|
# perform search in preselected jids
|
|
|
|
# jids are preselected with the query_combobox (all, single jid...)
|
2007-10-07 01:06:09 +02:00
|
|
|
for jid in self.jids_to_search:
|
2008-04-03 19:48:55 +02:00
|
|
|
account = self.completion_dict[jid][C_INFO_ACCOUNT]
|
2007-10-07 01:06:09 +02:00
|
|
|
if account is None:
|
|
|
|
# We do not know an account. This can only happen if the contact is offine,
|
|
|
|
# or if we browse a groupchat history. The account is not needed, a dummy can
|
|
|
|
# be set.
|
2008-04-03 19:48:55 +02:00
|
|
|
# This may leed to wrong self nick in the displayed history (Uggh!)
|
2007-10-07 01:06:09 +02:00
|
|
|
account = gajim.contacts.get_accounts()[0]
|
|
|
|
|
|
|
|
# contact_name, time, kind, show, message, subject
|
|
|
|
results = gajim.logger.get_search_results_for_query(
|
|
|
|
jid, text, account)
|
|
|
|
#FIXME:
|
|
|
|
# add "subject: | message: " in message column if kind is single
|
|
|
|
# also do we need show at all? (we do not search on subject)
|
|
|
|
for row in results:
|
|
|
|
contact_name = row[0]
|
|
|
|
if not contact_name:
|
|
|
|
kind = row[2]
|
|
|
|
if kind == constants.KIND_CHAT_MSG_SENT: # it's us! :)
|
|
|
|
contact_name = gajim.nicks[account]
|
2005-12-27 21:56:30 +01:00
|
|
|
else:
|
2008-04-03 19:48:55 +02:00
|
|
|
contact_name = self.completion_dict[jid][C_INFO_NAME]
|
2007-10-07 01:06:09 +02:00
|
|
|
tim = row[1]
|
|
|
|
message = row[4]
|
|
|
|
local_time = time.localtime(tim)
|
2008-07-12 06:36:05 +02:00
|
|
|
date = time.strftime('%Y-%m-%d', local_time)
|
|
|
|
|
2008-05-31 21:41:42 +02:00
|
|
|
# jid (to which log is assigned to), name, date, message,
|
|
|
|
# time (full unix time)
|
2007-10-07 01:06:09 +02:00
|
|
|
model.append((jid, contact_name, date, message, tim))
|
|
|
|
|
|
|
|
def on_query_combobox_changed(self, widget):
|
2008-04-03 19:48:55 +02:00
|
|
|
if self.query_combobox.get_active() < 0:
|
|
|
|
return # custom entry
|
|
|
|
self.account = None
|
|
|
|
self.jid = None
|
2007-10-07 01:06:09 +02:00
|
|
|
self.jids_to_search = []
|
2008-04-03 19:48:55 +02:00
|
|
|
self._load_history(None) # clear textview
|
|
|
|
|
2007-10-07 01:06:09 +02:00
|
|
|
if self.query_combobox.get_active() == 0:
|
2008-04-03 19:48:55 +02:00
|
|
|
# JID or Contact name
|
|
|
|
self.query_entry.set_sensitive(False)
|
|
|
|
self.jid_entry.grab_focus()
|
2007-10-07 01:06:09 +02:00
|
|
|
if self.query_combobox.get_active() == 1:
|
2008-04-03 19:48:55 +02:00
|
|
|
# Groupchat Histories
|
2007-10-07 01:06:09 +02:00
|
|
|
self.query_entry.set_sensitive(True)
|
2008-04-03 19:48:55 +02:00
|
|
|
self.query_entry.grab_focus()
|
|
|
|
self.jids_to_search = (jid for jid in gajim.logger.get_jids_in_db()
|
|
|
|
if gajim.logger.jid_is_room_jid(jid))
|
|
|
|
if self.query_combobox.get_active() == 2:
|
|
|
|
# All Chat Histories
|
|
|
|
self.query_entry.set_sensitive(True)
|
|
|
|
self.query_entry.grab_focus()
|
2007-10-07 01:06:09 +02:00
|
|
|
self.jids_to_search = gajim.logger.get_jids_in_db()
|
2008-04-03 19:48:55 +02:00
|
|
|
|
2005-11-29 22:47:47 +01:00
|
|
|
def on_results_treeview_row_activated(self, widget, path, column):
|
2005-11-30 15:26:49 +01:00
|
|
|
'''a row was double clicked, get date from row, and select it in calendar
|
2005-11-30 15:16:26 +01:00
|
|
|
which results to showing conversation logs for that date'''
|
2005-11-29 22:47:47 +01:00
|
|
|
# get currently selected date
|
|
|
|
cur_year, cur_month, cur_day = self.calendar.get_date()
|
|
|
|
cur_month = gtkgui_helpers.make_gtk_month_python_month(cur_month)
|
|
|
|
model = widget.get_model()
|
2005-12-27 14:38:42 +01:00
|
|
|
# make it a tupple (Y, M, D, 0, 0, 0...)
|
2008-07-12 06:36:05 +02:00
|
|
|
tim = time.strptime(model[path][C_UNIXTIME], '%Y-%m-%d')
|
2005-11-29 22:47:47 +01:00
|
|
|
year = tim[0]
|
|
|
|
gtk_month = tim[1]
|
|
|
|
month = gtkgui_helpers.make_python_month_gtk_month(gtk_month)
|
|
|
|
day = tim[2]
|
2007-10-07 01:06:09 +02:00
|
|
|
|
|
|
|
# switch to belonging logfile if necessary
|
|
|
|
log_jid = model[path][C_LOG_JID]
|
|
|
|
if log_jid != self.jid:
|
2008-04-03 19:48:55 +02:00
|
|
|
self._load_history(log_jid, None)
|
2007-10-07 01:06:09 +02:00
|
|
|
|
2005-11-29 22:47:47 +01:00
|
|
|
# avoid reruning mark days algo if same month and year!
|
|
|
|
if year != cur_year or gtk_month != cur_month:
|
|
|
|
self.calendar.select_month(month, year)
|
|
|
|
|
|
|
|
self.calendar.select_day(day)
|
2006-02-05 00:07:46 +01:00
|
|
|
unix_time = model[path][C_TIME]
|
2008-04-03 19:48:55 +02:00
|
|
|
self._scroll_to_result(unix_time)
|
2005-12-27 14:38:42 +01:00
|
|
|
#FIXME: one day do not search just for unix_time but the whole and user
|
|
|
|
# specific format of the textbuffer line [time] nick: message
|
|
|
|
# and highlight all that
|
2005-12-27 20:02:15 +01:00
|
|
|
|
2008-04-03 19:48:55 +02:00
|
|
|
def _scroll_to_result(self, unix_time):
|
2005-12-27 14:38:42 +01:00
|
|
|
'''scrolls to the result using unix_time and highlight line'''
|
|
|
|
start_iter = self.history_buffer.get_start_iter()
|
|
|
|
local_time = time.localtime(float(unix_time))
|
|
|
|
tim = time.strftime('%X', local_time)
|
|
|
|
result = start_iter.forward_search(tim, gtk.TEXT_SEARCH_VISIBLE_ONLY,
|
|
|
|
None)
|
|
|
|
if result is not None:
|
|
|
|
match_start_iter, match_end_iter = result
|
|
|
|
match_start_iter.backward_char() # include '[' or other character before time
|
2005-12-27 14:49:34 +01:00
|
|
|
match_end_iter.forward_line() # highlight all message not just time
|
2005-12-27 14:38:42 +01:00
|
|
|
self.history_buffer.apply_tag_by_name('highlight', match_start_iter,
|
|
|
|
match_end_iter)
|
|
|
|
|
|
|
|
match_start_mark = self.history_buffer.create_mark('match_start',
|
|
|
|
match_start_iter, True)
|
2006-04-18 17:36:16 +02:00
|
|
|
self.history_textview.tv.scroll_to_mark(match_start_mark, 0, True)
|
2007-03-31 15:40:23 +02:00
|
|
|
|
|
|
|
def on_log_history_checkbutton_toggled(self, widget):
|
|
|
|
# log conversation history?
|
|
|
|
oldlog = True
|
|
|
|
no_log_for = gajim.config.get_per('accounts', self.account,
|
|
|
|
'no_log_for').split()
|
|
|
|
if self.jid in no_log_for:
|
|
|
|
oldlog = False
|
|
|
|
log = widget.get_active()
|
|
|
|
if not log and not self.jid in no_log_for:
|
|
|
|
no_log_for.append(self.jid)
|
|
|
|
if log and self.jid in no_log_for:
|
|
|
|
no_log_for.remove(self.jid)
|
|
|
|
if oldlog != log:
|
|
|
|
gajim.config.set_per('accounts', self.account, 'no_log_for',
|
|
|
|
' '.join(no_log_for))
|
|
|
|
|
2007-09-14 22:18:06 +02:00
|
|
|
def open_history(self, jid, account):
|
2008-04-03 19:48:55 +02:00
|
|
|
'''Load chat history of the specified jid'''
|
2008-05-31 21:41:42 +02:00
|
|
|
self.jid_entry.set_text(jid)
|
2008-04-03 19:48:55 +02:00
|
|
|
if account and account not in self.accounts_seen_online:
|
|
|
|
# Update dict to not only show bare jid
|
2008-05-31 21:41:42 +02:00
|
|
|
gobject.idle_add(self._fill_completion_dict().next)
|
|
|
|
else:
|
|
|
|
# Only in that case because it's called by self._fill_completion_dict()
|
|
|
|
# otherwise
|
|
|
|
self._load_history(jid, account)
|
2008-04-03 19:48:55 +02:00
|
|
|
self.results_window.set_property('visible', False)
|
2008-07-29 21:49:31 +02:00
|
|
|
|
|
|
|
# vim: se ts=3:
|