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:
|
2005-03-11 18:57:35 +01:00
|
|
|
## - Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## - Nikos Kouremenos <kourem@gmail.com>
|
|
|
|
##
|
2005-12-10 00:30:28 +01:00
|
|
|
## Copyright (C) 2003-2004 Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## Vincent Hanquez <tab@snarc.org>
|
|
|
|
## Copyright (C) 2005 Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## 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>
|
2005-03-11 18:57:35 +01:00
|
|
|
##
|
|
|
|
## 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
|
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()
|
|
|
|
|
2005-12-27 14:38:42 +01:00
|
|
|
# contact_name, date, message, time
|
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
|
|
|
|
) = range(4)
|
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):
|
|
|
|
if jid is None:
|
|
|
|
self.jid = 'Enter jid or contact name here'
|
|
|
|
else:
|
|
|
|
self.jid = jid
|
2005-10-09 19:07:29 +02:00
|
|
|
self.account = account
|
2007-09-14 22:18:06 +02:00
|
|
|
|
2005-11-27 01:22:26 +01:00
|
|
|
self.mark_days_idle_call_id = 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')
|
2005-11-29 22:47:47 +01:00
|
|
|
|
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')
|
|
|
|
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')
|
2005-12-05 21:23:49 +01:00
|
|
|
self.search_button = xml.get_widget('search_button')
|
2005-12-05 15:35:17 +01:00
|
|
|
query_builder_button = xml.get_widget('query_builder_button')
|
|
|
|
query_builder_button.hide()
|
|
|
|
query_builder_button.set_no_show_all(True)
|
2005-11-29 15:41:01 +01:00
|
|
|
self.expander_vbox = xml.get_widget('expander_vbox')
|
2005-12-05 15:35:17 +01:00
|
|
|
|
2005-11-29 15:41:01 +01:00
|
|
|
self.results_treeview = xml.get_widget('results_treeview')
|
2007-09-14 22:18:06 +02:00
|
|
|
|
|
|
|
# create jid dict for auto completion
|
|
|
|
self.completion_dict = {}
|
|
|
|
liststore = gtkgui_helpers.get_completion_liststore(self.jid_entry)
|
|
|
|
|
|
|
|
# Add all jids in the db
|
|
|
|
db_jids = gajim.logger.get_jids_in_db()
|
|
|
|
for jid in db_jids:
|
|
|
|
self.completion_dict[jid] = jid
|
|
|
|
|
|
|
|
# Enhance contacts of online accounts with their names
|
|
|
|
for account in gajim.contacts.get_accounts():
|
|
|
|
self.completion_dict.update(helpers.get_contact_dict_for_account(account))
|
|
|
|
keys = self.completion_dict.keys()
|
|
|
|
keys.sort()
|
|
|
|
# Add icons
|
|
|
|
for jid in keys:
|
|
|
|
if gajim.logger.jid_is_room_jid(jid):
|
|
|
|
img = gajim.interface.roster.load_icon('muc_active')
|
|
|
|
else:
|
|
|
|
img = gajim.interface.roster.jabber_state_images['16']['online']
|
|
|
|
liststore.append((img.get_pixbuf(), jid))
|
|
|
|
|
2005-12-27 14:38:42 +01:00
|
|
|
# contact_name, date, message, time
|
|
|
|
model = gtk.ListStore(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)
|
2005-11-27 01:22:26 +01:00
|
|
|
|
2007-09-14 22:18:06 +02:00
|
|
|
self.jid_entry.set_text(self.jid)
|
2005-10-31 22:28:39 +01:00
|
|
|
|
2005-10-09 19:07:29 +02:00
|
|
|
xml.signal_autoconnect(self)
|
2007-09-14 22:18:06 +02:00
|
|
|
self.jid_entry.emit('activate')
|
|
|
|
self.window.show_all()
|
|
|
|
|
|
|
|
def on_history_window_destroy(self, widget):
|
|
|
|
if self.mark_days_idle_call_id:
|
|
|
|
# if user destroys the window, and we have a generator filling mark days
|
|
|
|
# stop him!
|
|
|
|
gobject.source_remove(self.mark_days_idle_call_id)
|
|
|
|
self.history_textview.del_handlers()
|
|
|
|
del gajim.interface.instances['logs']
|
|
|
|
|
|
|
|
|
|
|
|
def on_close_button_clicked(self, widget):
|
|
|
|
self.window.destroy()
|
|
|
|
|
|
|
|
def on_jid_entry_activate(self, widget):
|
|
|
|
self.jid = self.jid_entry.get_text()
|
2005-11-27 01:22:26 +01:00
|
|
|
|
2007-09-14 22:18:06 +02:00
|
|
|
if self.completion_dict.has_key(self.jid): # a full qualified jid or contact name was entered
|
|
|
|
contact_name = self.completion_dict[self.jid]
|
|
|
|
if self.jid != contact_name:
|
|
|
|
self.jid = contact_name.jid # jid enhanced with contact
|
|
|
|
|
|
|
|
accounts = gajim.contacts.get_accounts()
|
|
|
|
self.account = None
|
|
|
|
for account in accounts:
|
|
|
|
contact = gajim.contacts.get_first_contact_from_jid(account ,self.jid)
|
|
|
|
if contact:
|
|
|
|
self.account = account
|
|
|
|
break
|
|
|
|
if self.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.
|
|
|
|
# FIXME: This may leed to wrong self nick in the displayed history
|
|
|
|
self.account = gajim.contacts.get_accounts()[0]
|
|
|
|
|
|
|
|
# select logs for last date we have logs with contact
|
|
|
|
self.calendar.set_sensitive(True)
|
|
|
|
lastlog = gajim.logger.get_last_date_that_has_logs(self.jid, self.account)
|
|
|
|
|
|
|
|
# Set the logging checkbutton
|
|
|
|
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)
|
|
|
|
self.checkbutton.set_inconsistent(False)
|
|
|
|
|
|
|
|
if contact:
|
|
|
|
title = _('Conversation History with %s') % contact.get_shown_name()
|
|
|
|
else:
|
|
|
|
title = _('Conversation History with %s') % self.jid
|
|
|
|
self.window.set_title(title)
|
|
|
|
|
|
|
|
|
|
|
|
else: # neither a valid jid, nor an existing contact name was entered
|
|
|
|
lastlog = None
|
|
|
|
|
|
|
|
self.checkbutton.set_inconsistent(True)
|
|
|
|
self.checkbutton.set_sensitive(False)
|
|
|
|
|
|
|
|
self.calendar.set_sensitive(False)
|
|
|
|
|
|
|
|
title = _('Conversation History')
|
|
|
|
self.window.set_title(title)
|
|
|
|
|
2005-11-29 22:47:47 +01:00
|
|
|
self.calendar.emit('month-changed')
|
2005-11-29 20:41:08 +01:00
|
|
|
|
2007-09-14 22:18:06 +02:00
|
|
|
# Show logs for contact. If we don't have logs at all, default to today
|
|
|
|
if lastlog is None:
|
2005-11-30 22:56:42 +01:00
|
|
|
date = time.localtime()
|
2005-11-30 23:25:37 +01:00
|
|
|
else:
|
2007-09-14 22:18:06 +02:00
|
|
|
tim = lastlog
|
2005-11-30 23:25:37 +01:00
|
|
|
date = time.localtime(tim)
|
|
|
|
|
2005-11-20 22:58:08 +01:00
|
|
|
y, m, d = date[0], date[1], date[2]
|
2005-12-05 15:40:29 +01:00
|
|
|
gtk_month = gtkgui_helpers.make_python_month_gtk_month(m)
|
|
|
|
self.calendar.select_month(gtk_month, y)
|
2005-11-30 22:56:42 +01:00
|
|
|
self.calendar.select_day(d)
|
2005-11-20 22:58:08 +01:00
|
|
|
self.add_lines_for_date(y, m, d)
|
2007-03-31 15:40:23 +02: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)
|
2005-11-24 02:39:47 +01:00
|
|
|
|
2005-11-27 01:22:26 +01:00
|
|
|
def do_possible_mark_for_days_in_this_month(self, widget, year, month):
|
|
|
|
'''this is a generator and does pseudo-threading via idle_add()
|
|
|
|
so it runs progressively! yea :)
|
|
|
|
asks for days in this month if they have logs it bolds them (marks them)'''
|
2005-11-24 02:39:47 +01:00
|
|
|
weekday, days_in_this_month = calendar.monthrange(year, month)
|
2005-12-21 11:54:41 +01:00
|
|
|
log_days = gajim.logger.get_days_with_logs(self.jid, year,
|
2006-06-04 11:54:11 +02:00
|
|
|
month, days_in_this_month, self.account)
|
2005-12-21 11:54:41 +01:00
|
|
|
for day in log_days:
|
|
|
|
widget.mark_day(day)
|
|
|
|
yield True
|
|
|
|
yield False
|
2005-11-27 01:22:26 +01:00
|
|
|
|
|
|
|
def on_calendar_month_changed(self, widget):
|
|
|
|
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
|
|
|
|
if self.mark_days_idle_call_id:
|
|
|
|
# if user changed month, and we have a generator filling mark days
|
|
|
|
# stop him from marking dates for the previously selected month
|
|
|
|
gobject.source_remove(self.mark_days_idle_call_id)
|
|
|
|
widget.clear_marks()
|
|
|
|
month = gtkgui_helpers.make_gtk_month_python_month(month)
|
|
|
|
self.mark_days_idle_call_id = gobject.idle_add(
|
|
|
|
self.do_possible_mark_for_days_in_this_month(widget, year, month).next)
|
2005-11-20 22:58:08 +01:00
|
|
|
|
2005-11-26 00:23:25 +01:00
|
|
|
def get_string_show_from_constant_int(self, show):
|
|
|
|
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
|
|
|
|
|
2005-11-20 22:58:08 +01:00
|
|
|
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
|
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
|
|
|
|
self.add_new_line(line[0], line[1], line[2], line[3], line[4])
|
2005-11-20 22:58:08 +01:00
|
|
|
|
2005-11-23 20:12:52 +01: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
|
|
|
|
2005-11-26 00:23:25 +01:00
|
|
|
show = self.get_string_show_from_constant_int(show)
|
|
|
|
|
|
|
|
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):
|
Merged in trunk updates, including meta_contacts
Merged revisions 4951,4962-4969 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r4951 | nk | 2005-12-30 16:50:36 -0700 (Fri, 30 Dec 2005) | 1 line
fixes in greek transl
........
r4962 | asterix | 2006-01-01 11:41:04 -0700 (Sun, 01 Jan 2006) | 2 lines
merge meta_contacts branch with trunk. Meta contacts are not in gajim yet, but framework is here. We now use gajim.contacts.many_functions() to handle contacts and groupchat_contacts.
........
r4963 | asterix | 2006-01-01 11:43:24 -0700 (Sun, 01 Jan 2006) | 2 lines
correct contacts file
........
r4964 | asterix | 2006-01-01 11:47:26 -0700 (Sun, 01 Jan 2006) | 2 lines
dict.remove() doesn't exists, it's del dict[]
........
r4965 | asterix | 2006-01-01 11:50:15 -0700 (Sun, 01 Jan 2006) | 2 lines
some missing commits from branch
........
r4966 | asterix | 2006-01-01 11:53:30 -0700 (Sun, 01 Jan 2006) | 2 lines
end of gc_contact.nick -> gc_contact.name
........
r4967 | asterix | 2006-01-01 12:05:59 -0700 (Sun, 01 Jan 2006) | 2 lines
new ACE option: send_sha_in_gc_presence that allow to send sha info in groupchat presences
........
r4968 | asterix | 2006-01-01 12:12:36 -0700 (Sun, 01 Jan 2006) | 2 lines
0.9.1-2 in debian that solve the group bug (commit [4924])
........
r4969 | asterix | 2006-01-01 12:31:13 -0700 (Sun, 01 Jan 2006) | 2 lines
typo
........
2006-01-01 21:06:26 +01:00
|
|
|
contact = gajim.contacts.get_first_contact_from_jid(self.account,
|
|
|
|
self.jid)
|
|
|
|
if contact:
|
|
|
|
# he is in our roster, use the name
|
2006-01-10 19:30:57 +01:00
|
|
|
contact_name = contact.get_shown_name()
|
Merged in trunk updates, including meta_contacts
Merged revisions 4951,4962-4969 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r4951 | nk | 2005-12-30 16:50:36 -0700 (Fri, 30 Dec 2005) | 1 line
fixes in greek transl
........
r4962 | asterix | 2006-01-01 11:41:04 -0700 (Sun, 01 Jan 2006) | 2 lines
merge meta_contacts branch with trunk. Meta contacts are not in gajim yet, but framework is here. We now use gajim.contacts.many_functions() to handle contacts and groupchat_contacts.
........
r4963 | asterix | 2006-01-01 11:43:24 -0700 (Sun, 01 Jan 2006) | 2 lines
correct contacts file
........
r4964 | asterix | 2006-01-01 11:47:26 -0700 (Sun, 01 Jan 2006) | 2 lines
dict.remove() doesn't exists, it's del dict[]
........
r4965 | asterix | 2006-01-01 11:50:15 -0700 (Sun, 01 Jan 2006) | 2 lines
some missing commits from branch
........
r4966 | asterix | 2006-01-01 11:53:30 -0700 (Sun, 01 Jan 2006) | 2 lines
end of gc_contact.nick -> gc_contact.name
........
r4967 | asterix | 2006-01-01 12:05:59 -0700 (Sun, 01 Jan 2006) | 2 lines
new ACE option: send_sha_in_gc_presence that allow to send sha info in groupchat presences
........
r4968 | asterix | 2006-01-01 12:12:36 -0700 (Sun, 01 Jan 2006) | 2 lines
0.9.1-2 in debian that solve the group bug (commit [4924])
........
r4969 | asterix | 2006-01-01 12:31:13 -0700 (Sun, 01 Jan 2006) | 2 lines
typo
........
2006-01-01 21:06:26 +01:00
|
|
|
else:
|
2005-12-02 13:40:55 +01:00
|
|
|
room_jid, nick = gajim.get_room_and_nick_from_fjid(self.jid)
|
|
|
|
# do we have him as gc_contact?
|
Merged in trunk updates, including meta_contacts
Merged revisions 4951,4962-4969 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r4951 | nk | 2005-12-30 16:50:36 -0700 (Fri, 30 Dec 2005) | 1 line
fixes in greek transl
........
r4962 | asterix | 2006-01-01 11:41:04 -0700 (Sun, 01 Jan 2006) | 2 lines
merge meta_contacts branch with trunk. Meta contacts are not in gajim yet, but framework is here. We now use gajim.contacts.many_functions() to handle contacts and groupchat_contacts.
........
r4963 | asterix | 2006-01-01 11:43:24 -0700 (Sun, 01 Jan 2006) | 2 lines
correct contacts file
........
r4964 | asterix | 2006-01-01 11:47:26 -0700 (Sun, 01 Jan 2006) | 2 lines
dict.remove() doesn't exists, it's del dict[]
........
r4965 | asterix | 2006-01-01 11:50:15 -0700 (Sun, 01 Jan 2006) | 2 lines
some missing commits from branch
........
r4966 | asterix | 2006-01-01 11:53:30 -0700 (Sun, 01 Jan 2006) | 2 lines
end of gc_contact.nick -> gc_contact.name
........
r4967 | asterix | 2006-01-01 12:05:59 -0700 (Sun, 01 Jan 2006) | 2 lines
new ACE option: send_sha_in_gc_presence that allow to send sha info in groupchat presences
........
r4968 | asterix | 2006-01-01 12:12:36 -0700 (Sun, 01 Jan 2006) | 2 lines
0.9.1-2 in debian that solve the group bug (commit [4924])
........
r4969 | asterix | 2006-01-01 12:31:13 -0700 (Sun, 01 Jan 2006) | 2 lines
typo
........
2006-01-01 21:06:26 +01:00
|
|
|
gc_contact = gajim.contacts.get_gc_contact(self.account, room_jid,
|
|
|
|
nick)
|
|
|
|
if gc_contact:
|
2005-12-02 13:40:55 +01:00
|
|
|
# so yes, it's pm!
|
|
|
|
contact_name = nick
|
|
|
|
else:
|
|
|
|
contact_name = self.jid.split('@')[0]
|
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):
|
2005-11-23 20:12:52 +01:00
|
|
|
contact_name = gajim.nicks[self.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
|
|
|
|
|
|
|
def set_unset_expand_on_expander(self, widget):
|
|
|
|
'''expander has to have expand to TRUE so scrolledwindow resizes properly
|
|
|
|
and does not have a static size. when expander is not expanded we set
|
|
|
|
expand property (note the Box one) to FALSE
|
|
|
|
to do this, we first get the box and then apply to expander widget
|
|
|
|
the True/False thingy depending if it's expanded or not
|
|
|
|
this function is called in a timeout just after expanded state changes'''
|
|
|
|
parent = widget.get_parent() # vbox
|
2007-01-24 21:57:41 +01:00
|
|
|
if not parent:
|
|
|
|
# Windows closed since we launch timeout
|
|
|
|
return
|
2005-11-30 20:41:31 +01:00
|
|
|
expanded = widget.get_expanded()
|
|
|
|
w, h = self.window.get_size()
|
|
|
|
if expanded: # resize to larger in height the window
|
|
|
|
self.window.resize(w, int(h*1.3))
|
|
|
|
else: # resize to smaller in height the window
|
|
|
|
self.window.resize(w, int(h/1.3))
|
|
|
|
# now set expand so if manually resizing scrolledwindow resizes too
|
|
|
|
parent.child_set_property(widget, 'expand', expanded)
|
2005-11-29 15:41:01 +01:00
|
|
|
|
|
|
|
def on_search_expander_activate(self, widget):
|
|
|
|
if widget.get_expanded(): # it's the OPPOSITE!, it's not expanded
|
|
|
|
gobject.timeout_add(200, self.set_unset_expand_on_expander, widget)
|
|
|
|
else:
|
|
|
|
gobject.timeout_add(200, self.set_unset_expand_on_expander, widget)
|
2005-12-05 21:23:49 +01:00
|
|
|
self.search_button.grab_default()
|
|
|
|
self.query_entry.grab_focus()
|
2005-11-29 15:41:01 +01:00
|
|
|
|
|
|
|
def on_search_button_clicked(self, widget):
|
|
|
|
text = self.query_entry.get_text()
|
|
|
|
model = self.results_treeview.get_model()
|
|
|
|
model.clear()
|
2005-11-29 20:41:08 +01:00
|
|
|
if text == '':
|
|
|
|
return
|
2005-11-30 18:30:58 +01:00
|
|
|
# contact_name, time, kind, show, message, subject
|
2006-06-04 11:54:11 +02:00
|
|
|
results = gajim.logger.get_search_results_for_query(
|
|
|
|
self.jid, text, self.account)
|
2005-12-27 21:56:30 +01:00
|
|
|
#FIXME:
|
|
|
|
# add "subject: | message: " in message column if kind is single
|
|
|
|
# also do we need show at all? (we do not search on subject)
|
2005-11-29 15:41:01 +01:00
|
|
|
for row in results:
|
2005-12-27 21:56:30 +01:00
|
|
|
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[self.account]
|
|
|
|
else:
|
2006-02-01 20:09:48 +01:00
|
|
|
contact = gajim.contacts.get_first_contact_from_jid(self.account,
|
|
|
|
self.jid)
|
|
|
|
if contact:
|
2006-01-10 19:30:57 +01:00
|
|
|
contact_name = contact.get_shown_name()
|
2005-12-27 21:56:30 +01:00
|
|
|
else:
|
|
|
|
contact_name = self.jid
|
|
|
|
tim = row[1]
|
|
|
|
message = row[4]
|
|
|
|
local_time = time.localtime(tim)
|
|
|
|
date = time.strftime('%x', local_time)
|
2005-12-27 14:38:42 +01:00
|
|
|
# name, date, message, time (full unix time)
|
2005-12-27 21:56:30 +01:00
|
|
|
model.append((contact_name, date, message, tim))
|
2005-11-29 15:41:01 +01: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...)
|
2006-02-05 00:07:46 +01:00
|
|
|
tim = time.strptime(model[path][C_UNIXTIME], '%x')
|
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]
|
|
|
|
|
|
|
|
# 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]
|
2005-12-27 14:38:42 +01:00
|
|
|
self.scroll_to_result(unix_time)
|
|
|
|
#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
|
|
|
|
2005-12-27 14:38:42 +01:00
|
|
|
def scroll_to_result(self, unix_time):
|
|
|
|
'''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):
|
|
|
|
# Simulate that the jid was entered by hand
|
|
|
|
self.jid_entry.set_text(jid)
|
|
|
|
self.jid_entry.emit('activate')
|
|
|
|
|