2018-08-04 20:12:38 +02:00
|
|
|
# Copyright (C) 2003-2014 Yann Leboulanger <asterix AT lagaule.org>
|
|
|
|
# Copyright (C) 2005 Vincent Hanquez <tab AT snarc.org>
|
|
|
|
# Copyright (C) 2005-2006 Nikos Kouremenos <kourem AT gmail.com>
|
|
|
|
# Copyright (C) 2006 Dimitur Kirov <dkirov AT gmail.com>
|
|
|
|
# Travis Shirk <travis AT pobox.com>
|
|
|
|
# Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
|
|
|
|
# Copyright (C) 2007-2008 Stephan Erb <steve-e AT h3c.de>
|
|
|
|
# Copyright (C) 2008 Brendan Taylor <whateley AT gmail.com>
|
|
|
|
#
|
|
|
|
# This file is part of Gajim.
|
|
|
|
#
|
|
|
|
# Gajim 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 3 only.
|
|
|
|
#
|
|
|
|
# Gajim 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.
|
|
|
|
#
|
|
|
|
# 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 time
|
2017-07-15 13:41:17 +02:00
|
|
|
import datetime
|
2018-10-28 14:59:51 +01:00
|
|
|
from enum import IntEnum
|
|
|
|
from enum import unique
|
2017-02-07 21:18:41 +01:00
|
|
|
|
2018-08-04 20:12:38 +02:00
|
|
|
from gi.repository import Gtk
|
|
|
|
from gi.repository import Gdk
|
|
|
|
from gi.repository import GLib
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
from gajim.common import app
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common import helpers
|
|
|
|
from gajim.common import exceptions
|
2018-10-04 23:55:35 +02:00
|
|
|
from gajim.common.i18n import _
|
2018-10-28 14:59:51 +01:00
|
|
|
from gajim.common.const import ShowConstant
|
|
|
|
from gajim.common.const import KindConstant
|
2005-11-26 00:23:25 +01:00
|
|
|
|
2018-10-04 23:55:35 +02:00
|
|
|
from gajim import conversation_textview
|
|
|
|
|
2018-10-28 14:59:51 +01:00
|
|
|
from gajim.gtk.util import python_month
|
|
|
|
from gajim.gtk.util import gtk_month
|
|
|
|
from gajim.gtk.util import resize_window
|
|
|
|
from gajim.gtk.util import move_window
|
|
|
|
from gajim.gtk.util import get_icon_name
|
|
|
|
from gajim.gtk.util import get_completion_liststore
|
|
|
|
from gajim.gtk.util import get_builder
|
2018-11-01 00:29:40 +01:00
|
|
|
from gajim.gtk.util import scroll_to_end
|
2018-10-28 14:59:51 +01:00
|
|
|
|
2018-10-04 23:55:35 +02:00
|
|
|
from gajim.gtk.dialogs import ErrorDialog
|
2018-08-04 20:12:38 +02:00
|
|
|
|
2017-03-04 21:22:46 +01:00
|
|
|
@unique
|
2017-02-07 21:18:41 +01:00
|
|
|
class InfoColumn(IntEnum):
|
|
|
|
'''Completion dict'''
|
|
|
|
JID = 0
|
|
|
|
ACCOUNT = 1
|
|
|
|
NAME = 2
|
|
|
|
COMPLETION = 3
|
2008-04-03 19:48:55 +02:00
|
|
|
|
2018-08-04 20:12:38 +02:00
|
|
|
|
2017-03-04 21:22:46 +01:00
|
|
|
@unique
|
2017-02-07 21:18:41 +01:00
|
|
|
class Column(IntEnum):
|
|
|
|
LOG_JID = 0
|
|
|
|
CONTACT_NAME = 1
|
|
|
|
UNIXTIME = 2
|
|
|
|
MESSAGE = 3
|
|
|
|
TIME = 4
|
2017-03-02 23:55:18 +01:00
|
|
|
LOG_LINE_ID = 5
|
2005-11-29 15:41:01 +01:00
|
|
|
|
2018-08-04 20:12:38 +02:00
|
|
|
|
2018-11-04 22:19:58 +01:00
|
|
|
class HistoryWindow(Gtk.ApplicationWindow):
|
2017-08-20 14:57:18 +02:00
|
|
|
def __init__(self, jid=None, account=None):
|
2018-11-04 22:19:58 +01:00
|
|
|
Gtk.ApplicationWindow.__init__(self)
|
|
|
|
self.set_application(app.app)
|
|
|
|
self.set_position(Gtk.WindowPosition.CENTER)
|
|
|
|
self.set_show_menubar(False)
|
|
|
|
self.set_title(_('Conversation History'))
|
|
|
|
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui = get_builder('history_window.ui')
|
2018-11-04 22:19:58 +01:00
|
|
|
|
|
|
|
self.add(self._ui.history_box)
|
2018-11-01 00:29:40 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.history_textview = conversation_textview.ConversationTextview(
|
2018-08-04 20:12:38 +02:00
|
|
|
account, used_in_history_window=True)
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.scrolledwindow.add(self.history_textview.tv)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.history_buffer = self.history_textview.tv.get_buffer()
|
2017-08-20 14:57:18 +02:00
|
|
|
self.history_buffer.create_tag('highlight', background='yellow')
|
2016-04-17 20:31:19 +02:00
|
|
|
self.history_buffer.create_tag('invisible', invisible=True)
|
2018-08-04 11:04:36 +02:00
|
|
|
|
|
|
|
self.clearing_search = False
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-03-02 23:55:18 +01:00
|
|
|
# jid, contact_name, date, message, time, log_line_id
|
|
|
|
model = Gtk.ListStore(str, str, str, str, str, int)
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.results_treeview.set_model(model)
|
2012-12-23 16:23:43 +01:00
|
|
|
col = Gtk.TreeViewColumn(_('Name'))
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.results_treeview.append_column(col)
|
2012-12-23 16:23:43 +01:00
|
|
|
renderer = Gtk.CellRendererText()
|
2013-01-03 23:30:17 +01:00
|
|
|
col.pack_start(renderer, True)
|
2017-02-07 21:18:41 +01:00
|
|
|
col.add_attribute(renderer, 'text', Column.CONTACT_NAME)
|
2018-08-04 20:12:38 +02:00
|
|
|
# user can click this header and sort
|
|
|
|
col.set_sort_column_id(Column.CONTACT_NAME)
|
2010-02-08 15:08:40 +01:00
|
|
|
col.set_resizable(True)
|
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
col = Gtk.TreeViewColumn(_('Date'))
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.results_treeview.append_column(col)
|
2012-12-23 16:23:43 +01:00
|
|
|
renderer = Gtk.CellRendererText()
|
2013-01-03 23:30:17 +01:00
|
|
|
col.pack_start(renderer, True)
|
2017-02-07 21:18:41 +01:00
|
|
|
col.add_attribute(renderer, 'text', Column.UNIXTIME)
|
2018-08-04 20:12:38 +02:00
|
|
|
# user can click this header and sort
|
|
|
|
col.set_sort_column_id(Column.UNIXTIME)
|
2010-02-08 15:08:40 +01:00
|
|
|
col.set_resizable(True)
|
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
col = Gtk.TreeViewColumn(_('Message'))
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.results_treeview.append_column(col)
|
2012-12-23 16:23:43 +01:00
|
|
|
renderer = Gtk.CellRendererText()
|
2013-01-03 23:30:17 +01:00
|
|
|
col.pack_start(renderer, True)
|
2017-02-07 21:18:41 +01:00
|
|
|
col.add_attribute(renderer, 'text', Column.MESSAGE)
|
2010-02-08 15:08:40 +01:00
|
|
|
col.set_resizable(True)
|
|
|
|
|
2018-08-04 20:12:38 +02:00
|
|
|
self.jid = None # The history we are currently viewing
|
2017-08-18 22:05:48 +02:00
|
|
|
self.account = account
|
2010-02-08 15:08:40 +01:00
|
|
|
self.completion_dict = {}
|
2018-08-04 20:12:38 +02:00
|
|
|
self.accounts_seen_online = [] # Update dict when new accounts connect
|
2010-02-08 15:08:40 +01:00
|
|
|
self.jids_to_search = []
|
|
|
|
|
|
|
|
# This will load history too
|
2013-01-03 23:30:17 +01:00
|
|
|
task = self._fill_completion_dict()
|
2013-07-29 18:35:49 +02:00
|
|
|
GLib.idle_add(next, task)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
if jid:
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.query_entry.get_child().set_text(jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
self._load_history(None)
|
|
|
|
|
2018-11-04 22:19:58 +01:00
|
|
|
resize_window(self,
|
2018-10-28 14:59:51 +01:00
|
|
|
app.config.get('history_window_width'),
|
|
|
|
app.config.get('history_window_height'))
|
2018-11-04 22:19:58 +01:00
|
|
|
move_window(self,
|
2018-10-28 14:59:51 +01:00
|
|
|
app.config.get('history_window_x-position'),
|
|
|
|
app.config.get('history_window_y-position'))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.connect_signals(self)
|
2018-11-04 22:19:58 +01:00
|
|
|
self.connect('delete-event', self._on_delete)
|
|
|
|
self.connect('destroy', self._on_destroy)
|
|
|
|
self.connect('key-press-event', self._on_key_press)
|
|
|
|
self.show_all()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-11-03 17:45:03 +01:00
|
|
|
# PluginSystem: adding GUI extension point for
|
|
|
|
# HistoryWindow instance object
|
|
|
|
app.plugin_manager.gui_extension_point(
|
|
|
|
'history_window', self)
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def _fill_completion_dict(self):
|
|
|
|
"""
|
|
|
|
Fill completion_dict for key auto completion. Then load history for
|
|
|
|
current jid (by calling another function)
|
|
|
|
|
|
|
|
Key will be either jid or full_completion_name (contact name or long
|
|
|
|
description like "pm-contact from groupchat....").
|
|
|
|
|
|
|
|
{key : (jid, account, nick_name, full_completion_name}
|
|
|
|
This is a generator and does pseudo-threading via idle_add().
|
|
|
|
"""
|
2018-10-28 14:59:51 +01:00
|
|
|
liststore = get_completion_liststore(
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.query_entry.get_child())
|
2018-08-04 11:04:36 +02:00
|
|
|
liststore.set_sort_column_id(1, Gtk.SortType.ASCENDING)
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.query_entry.get_child().get_completion().connect(
|
2018-08-04 11:04:36 +02:00
|
|
|
'match-selected', self.on_jid_entry_match_selected)
|
|
|
|
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.query_entry.set_model(liststore)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
# Add all jids in logs.db:
|
2017-08-13 13:18:56 +02:00
|
|
|
db_jids = app.logger.get_jids_in_db()
|
2010-02-08 15:08:40 +01:00
|
|
|
completion_dict = dict.fromkeys(db_jids)
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
self.accounts_seen_online = list(app.contacts.get_accounts())
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-08-04 20:12:38 +02:00
|
|
|
# Enhance contacts of online accounts with contact.
|
|
|
|
# Needed for mapping below
|
2010-02-08 15:08:40 +01:00
|
|
|
for account in self.accounts_seen_online:
|
2018-08-04 20:12:38 +02:00
|
|
|
completion_dict.update(
|
|
|
|
helpers.get_contact_dict_for_account(account))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-10-28 14:59:51 +01:00
|
|
|
muc_active_icon = get_icon_name('muc-active')
|
|
|
|
online_icon = get_icon_name('online')
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2013-01-03 23:30:17 +01:00
|
|
|
keys = list(completion_dict.keys())
|
2010-02-08 15:08:40 +01:00
|
|
|
# Move the actual jid at first so we load history faster
|
2018-11-01 00:29:40 +01:00
|
|
|
actual_jid = self._ui.query_entry.get_child().get_text()
|
2010-02-08 15:08:40 +01:00
|
|
|
if actual_jid in keys:
|
|
|
|
keys.remove(actual_jid)
|
|
|
|
keys.insert(0, actual_jid)
|
2013-01-03 23:30:17 +01:00
|
|
|
if '' in keys:
|
|
|
|
keys.remove('')
|
2013-01-20 22:50:04 +01:00
|
|
|
if None in keys:
|
|
|
|
keys.remove(None)
|
2010-02-08 15:08:40 +01:00
|
|
|
# Map jid to info tuple
|
|
|
|
# Warning : This for is time critical with big DB
|
|
|
|
for key in keys:
|
|
|
|
completed = key
|
2016-04-04 22:51:47 +02:00
|
|
|
completed2 = None
|
2010-02-08 15:08:40 +01:00
|
|
|
contact = completion_dict[completed]
|
|
|
|
if contact:
|
|
|
|
info_name = contact.get_shown_name()
|
|
|
|
info_completion = info_name
|
|
|
|
info_jid = contact.jid
|
|
|
|
else:
|
2018-06-27 00:52:14 +02:00
|
|
|
# Corresponding account is offline, we know nothing
|
2010-02-08 15:08:40 +01:00
|
|
|
info_name = completed.split('@')[0]
|
|
|
|
info_completion = completed
|
|
|
|
info_jid = completed
|
|
|
|
|
|
|
|
info_acc = self._get_account_for_jid(info_jid)
|
|
|
|
|
2018-08-04 20:12:38 +02:00
|
|
|
if (app.logger.jid_is_room_jid(completed) or
|
|
|
|
app.logger.jid_is_from_pm(completed)):
|
2017-10-27 12:48:01 +02:00
|
|
|
icon = muc_active_icon
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.logger.jid_is_from_pm(completed):
|
2010-02-08 15:08:40 +01:00
|
|
|
# It's PM. Make it easier to find
|
2017-08-13 13:18:56 +02:00
|
|
|
room, nick = app.get_room_and_nick_from_fjid(completed)
|
2010-02-08 15:08:40 +01:00
|
|
|
info_completion = '%s from %s' % (nick, room)
|
|
|
|
completed = info_completion
|
2016-04-04 22:51:47 +02:00
|
|
|
info_completion2 = '%s/%s' % (room, nick)
|
|
|
|
completed2 = info_completion2
|
2010-02-08 15:08:40 +01:00
|
|
|
info_name = nick
|
|
|
|
else:
|
2017-10-27 12:48:01 +02:00
|
|
|
icon = online_icon
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2016-04-04 22:51:47 +02:00
|
|
|
if len(completed) > 70:
|
|
|
|
completed = completed[:70] + '[\u2026]'
|
2017-10-27 12:48:01 +02:00
|
|
|
liststore.append((icon, completed))
|
2018-08-04 20:12:38 +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)
|
2016-04-04 22:51:47 +02:00
|
|
|
if completed2:
|
|
|
|
if len(completed2) > 70:
|
|
|
|
completed2 = completed2[:70] + '[\u2026]'
|
2017-10-27 12:48:01 +02:00
|
|
|
liststore.append((icon, completed2))
|
2018-08-04 20:12:38 +02:00
|
|
|
self.completion_dict[completed2] = (
|
|
|
|
info_jid, info_acc, info_name, info_completion2)
|
2010-02-08 15:08:40 +01:00
|
|
|
if key == actual_jid:
|
2017-08-20 14:57:18 +02:00
|
|
|
self._load_history(info_jid, self.account or info_acc)
|
2010-02-08 15:08:40 +01:00
|
|
|
yield True
|
|
|
|
keys.sort()
|
|
|
|
yield False
|
|
|
|
|
|
|
|
def _get_account_for_jid(self, jid):
|
|
|
|
"""
|
|
|
|
Return the corresponding account of the jid. May be None if an account
|
|
|
|
could not be found
|
|
|
|
"""
|
2017-08-13 13:18:56 +02:00
|
|
|
accounts = app.contacts.get_accounts()
|
2010-02-08 15:08:40 +01:00
|
|
|
account = None
|
|
|
|
for acc in accounts:
|
2017-08-13 13:18:56 +02:00
|
|
|
jid_list = app.contacts.get_jid_list(acc)
|
|
|
|
gc_list = app.contacts.get_gc_list(acc)
|
2010-02-08 15:08:40 +01:00
|
|
|
if jid in jid_list or jid in gc_list:
|
|
|
|
account = acc
|
|
|
|
break
|
|
|
|
return account
|
|
|
|
|
2018-11-04 22:19:58 +01:00
|
|
|
def _on_delete(self, widget, *args):
|
2018-08-04 11:04:36 +02:00
|
|
|
self.save_state()
|
|
|
|
|
2018-11-04 22:19:58 +01:00
|
|
|
def _on_destroy(self, widget):
|
2017-11-03 17:45:03 +01:00
|
|
|
# PluginSystem: removing GUI extension points connected with
|
|
|
|
# HistoryWindow instance object
|
|
|
|
app.plugin_manager.remove_gui_extension_point(
|
|
|
|
'history_window', self)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.history_textview.del_handlers()
|
|
|
|
|
2018-11-04 22:19:58 +01:00
|
|
|
def _on_key_press(self, widget, event):
|
2012-12-23 16:23:43 +01:00
|
|
|
if event.keyval == Gdk.KEY_Escape:
|
2010-02-08 15:08:40 +01:00
|
|
|
self.save_state()
|
2018-11-04 22:19:58 +01:00
|
|
|
self.destroy()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-08-04 11:04:36 +02:00
|
|
|
def on_jid_entry_match_selected(self, widget, model, iter_, *args):
|
|
|
|
self._jid_entry_search(model[iter_][1])
|
|
|
|
return True
|
|
|
|
|
|
|
|
def on_jid_entry_changed(self, widget):
|
|
|
|
# only if selected from combobox
|
2018-11-01 00:29:40 +01:00
|
|
|
jid = self._ui.query_entry.get_child().get_text()
|
|
|
|
if jid == self._ui.query_entry.get_active_id():
|
2018-08-04 11:04:36 +02:00
|
|
|
self._jid_entry_search(jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_jid_entry_activate(self, widget):
|
2018-11-01 00:29:40 +01:00
|
|
|
self._jid_entry_search(self._ui.query_entry.get_child().get_text())
|
2018-08-04 11:04:36 +02:00
|
|
|
|
|
|
|
def _jid_entry_search(self, jid):
|
2017-08-18 22:05:48 +02:00
|
|
|
self._load_history(jid, self.account)
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.results_scrolledwindow.set_property('visible', False)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def _load_history(self, jid_or_name, account=None):
|
|
|
|
"""
|
|
|
|
Load history for the given jid/name and show it
|
|
|
|
"""
|
|
|
|
if jid_or_name and jid_or_name in self.completion_dict:
|
2018-08-04 20:12:38 +02:00
|
|
|
# a full qualified jid or a contact name was entered
|
2018-09-17 21:11:45 +02:00
|
|
|
info_jid, info_account, _info_name, info_completion = self.completion_dict[jid_or_name]
|
2010-02-08 15:08:40 +01:00
|
|
|
self.jids_to_search = [info_jid]
|
|
|
|
self.jid = info_jid
|
|
|
|
|
|
|
|
if account:
|
|
|
|
self.account = account
|
|
|
|
else:
|
|
|
|
self.account = info_account
|
|
|
|
if self.account is None:
|
|
|
|
# We don't know account. Probably a gc not opened or an
|
|
|
|
# account not connected.
|
|
|
|
# Disable possibility to say if we want to log or not
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.log_history_checkbutton.set_sensitive(False)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
# Are log disabled for account ?
|
2018-08-04 20:12:38 +02:00
|
|
|
if self.account in app.config.get_per(
|
|
|
|
'accounts', self.account, 'no_log_for').split(' '):
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.log_history_checkbutton.set_active(False)
|
|
|
|
self._ui.log_history_checkbutton.set_sensitive(False)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
# Are log disabled for jid ?
|
|
|
|
log = True
|
2018-08-04 20:12:38 +02:00
|
|
|
if self.jid in app.config.get_per(
|
|
|
|
'accounts', self.account, 'no_log_for').split(' '):
|
2010-02-08 15:08:40 +01:00
|
|
|
log = False
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.log_history_checkbutton.set_active(log)
|
|
|
|
self._ui.log_history_checkbutton.set_sensitive(True)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
self.jids_to_search = [info_jid]
|
|
|
|
|
2018-08-04 20:12:38 +02:00
|
|
|
# Get first/last date we have logs with contact
|
2018-01-29 14:00:15 +01:00
|
|
|
self.first_log = app.logger.get_first_date_that_has_logs(
|
|
|
|
self.account, self.jid)
|
|
|
|
self.first_day = self._get_date_from_timestamp(self.first_log)
|
|
|
|
self.last_log = app.logger.get_last_date_that_has_logs(
|
|
|
|
self.account, self.jid)
|
|
|
|
self.last_day = self._get_date_from_timestamp(self.last_log)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-01-29 14:00:15 +01:00
|
|
|
# Select logs for last date we have logs with contact
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.search_menu_button.set_sensitive(True)
|
2018-08-04 20:12:38 +02:00
|
|
|
month = gtk_month(self.last_day.month)
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.calendar.select_month(month, self.last_day.year)
|
|
|
|
self._ui.calendar.select_day(self.last_day.day)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.button_previous_day.set_sensitive(True)
|
|
|
|
self._ui.button_next_day.set_sensitive(True)
|
|
|
|
self._ui.button_first_day.set_sensitive(True)
|
|
|
|
self._ui.button_last_day.set_sensitive(True)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.search_entry.set_sensitive(True)
|
|
|
|
self._ui.search_entry.grab_focus()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.query_entry.get_child().set_text(info_completion)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-08-04 20:12:38 +02:00
|
|
|
else:
|
|
|
|
# neither a valid jid, nor an existing contact name was entered
|
2010-02-08 15:08:40 +01:00
|
|
|
# we have got nothing to show or to search in
|
|
|
|
self.jid = None
|
|
|
|
self.account = None
|
|
|
|
|
2018-08-04 20:12:38 +02:00
|
|
|
self.history_buffer.set_text('') # clear the buffer
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.search_entry.set_sensitive(False)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.log_history_checkbutton.set_sensitive(False)
|
|
|
|
self._ui.search_menu_button.set_sensitive(False)
|
|
|
|
self._ui.calendar.clear_marks()
|
|
|
|
self._ui.button_previous_day.set_sensitive(False)
|
|
|
|
self._ui.button_next_day.set_sensitive(False)
|
|
|
|
self._ui.button_first_day.set_sensitive(False)
|
|
|
|
self._ui.button_last_day.set_sensitive(False)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.results_scrolledwindow.set_property('visible', False)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_calendar_day_selected(self, widget):
|
|
|
|
if not self.jid:
|
|
|
|
return
|
2018-11-01 00:29:40 +01:00
|
|
|
year, month, day = self._ui.calendar.get_date() # integers
|
2018-08-04 20:12:38 +02:00
|
|
|
month = python_month(month)
|
2018-08-04 11:04:36 +02:00
|
|
|
date_str = datetime.date(year, month, day).strftime('%x')
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.date_label.set_text(date_str)
|
2017-03-30 21:51:10 +02:00
|
|
|
self._load_conversation(year, month, day)
|
2018-11-01 00:29:40 +01:00
|
|
|
GLib.idle_add(scroll_to_end, self._ui.scrolledwindow)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_calendar_month_changed(self, widget):
|
|
|
|
"""
|
2018-08-04 20:12:38 +02:00
|
|
|
Ask for days in this month, if they have logs it bolds them
|
|
|
|
(marks them)
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
if not self.jid:
|
|
|
|
return
|
2018-09-17 21:11:45 +02:00
|
|
|
year, month, _day = widget.get_date() # integers
|
2010-04-02 09:21:56 +02:00
|
|
|
if year < 1900:
|
|
|
|
widget.select_month(0, 1900)
|
|
|
|
widget.select_day(1)
|
|
|
|
return
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
widget.clear_marks()
|
2018-08-04 20:12:38 +02:00
|
|
|
month = python_month(month)
|
2017-07-16 01:14:42 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
try:
|
2017-08-13 13:18:56 +02:00
|
|
|
log_days = app.logger.get_days_with_logs(
|
2017-07-16 01:14:42 +02:00
|
|
|
self.account, self.jid, year, month)
|
2018-09-17 21:11:45 +02:00
|
|
|
except exceptions.PysqliteOperationalError as error:
|
|
|
|
ErrorDialog(_('Disk Error'), str(error))
|
2010-02-08 15:08:40 +01:00
|
|
|
return
|
2017-07-16 01:14:42 +02:00
|
|
|
|
|
|
|
for date in log_days:
|
|
|
|
widget.mark_day(date.day)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-01-29 14:00:15 +01:00
|
|
|
def _get_date_from_timestamp(self, timestamp):
|
|
|
|
# Conversion from timestamp to date
|
|
|
|
log = time.localtime(timestamp)
|
|
|
|
y, m, d = log[0], log[1], log[2]
|
|
|
|
date = datetime.datetime(y, m, d)
|
2018-09-16 14:42:05 +02:00
|
|
|
return date
|
2018-01-29 14:00:15 +01:00
|
|
|
|
|
|
|
def _change_date(self, widget):
|
|
|
|
# Get day selected in calendar
|
2018-11-01 00:29:40 +01:00
|
|
|
y, m, d = self._ui.calendar.get_date()
|
2018-08-04 20:12:38 +02:00
|
|
|
py_m = python_month(m)
|
2018-01-29 14:00:15 +01:00
|
|
|
_date = datetime.datetime(y, py_m, d)
|
|
|
|
|
2018-11-01 00:29:40 +01:00
|
|
|
if widget is self._ui.button_first_day:
|
2018-08-04 20:12:38 +02:00
|
|
|
gtk_m = gtk_month(self.first_day.month)
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.calendar.select_month(gtk_m, self.first_day.year)
|
|
|
|
self._ui.calendar.select_day(self.first_day.day)
|
2018-01-29 14:00:15 +01:00
|
|
|
return
|
2018-09-18 10:14:04 +02:00
|
|
|
|
2018-11-01 00:29:40 +01:00
|
|
|
if widget is self._ui.button_last_day:
|
2018-08-04 20:12:38 +02:00
|
|
|
gtk_m = gtk_month(
|
2018-01-29 14:00:15 +01:00
|
|
|
self.last_day.month)
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.calendar.select_month(gtk_m, self.last_day.year)
|
|
|
|
self._ui.calendar.select_day(self.last_day.day)
|
2018-01-29 14:00:15 +01:00
|
|
|
return
|
2018-09-18 10:14:04 +02:00
|
|
|
|
2018-11-01 00:29:40 +01:00
|
|
|
if widget is self._ui.button_previous_day:
|
2018-01-29 14:00:15 +01:00
|
|
|
end_date = self.first_day
|
|
|
|
timedelta = datetime.timedelta(days=-1)
|
|
|
|
if end_date >= _date:
|
|
|
|
return
|
2018-11-01 00:29:40 +01:00
|
|
|
elif widget is self._ui.button_next_day:
|
2018-01-29 14:00:15 +01:00
|
|
|
end_date = self.last_day
|
|
|
|
timedelta = datetime.timedelta(days=1)
|
|
|
|
if end_date <= _date:
|
|
|
|
return
|
|
|
|
|
|
|
|
# Iterate through days until log entry found or
|
|
|
|
# supplied end_date (first_log / last_log) reached
|
|
|
|
logs = None
|
|
|
|
while logs is None:
|
|
|
|
_date = _date + timedelta
|
|
|
|
if _date == end_date:
|
|
|
|
break
|
|
|
|
try:
|
|
|
|
logs = app.logger.get_date_has_logs(
|
|
|
|
self.account, self.jid, _date)
|
|
|
|
except exceptions.PysqliteOperationalError as e:
|
2018-07-16 23:22:33 +02:00
|
|
|
ErrorDialog(_('Disk Error'), str(e))
|
2018-01-29 14:00:15 +01:00
|
|
|
return
|
|
|
|
|
2018-08-04 20:12:38 +02:00
|
|
|
gtk_m = gtk_month(_date.month)
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.calendar.select_month(gtk_m, _date.year)
|
|
|
|
self._ui.calendar.select_day(_date.day)
|
2018-01-29 14:00:15 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def _get_string_show_from_constant_int(self, show):
|
2017-02-07 21:18:41 +01:00
|
|
|
if show == ShowConstant.ONLINE:
|
2010-02-08 15:08:40 +01:00
|
|
|
show = 'online'
|
2017-02-07 21:18:41 +01:00
|
|
|
elif show == ShowConstant.CHAT:
|
2010-02-08 15:08:40 +01:00
|
|
|
show = 'chat'
|
2017-02-07 21:18:41 +01:00
|
|
|
elif show == ShowConstant.AWAY:
|
2010-02-08 15:08:40 +01:00
|
|
|
show = 'away'
|
2017-02-07 21:18:41 +01:00
|
|
|
elif show == ShowConstant.XA:
|
2010-02-08 15:08:40 +01:00
|
|
|
show = 'xa'
|
2017-02-07 21:18:41 +01:00
|
|
|
elif show == ShowConstant.DND:
|
2010-02-08 15:08:40 +01:00
|
|
|
show = 'dnd'
|
2017-02-07 21:18:41 +01:00
|
|
|
elif show == ShowConstant.OFFLINE:
|
2010-02-08 15:08:40 +01:00
|
|
|
show = 'offline'
|
|
|
|
|
|
|
|
return show
|
|
|
|
|
2017-03-30 21:51:10 +02:00
|
|
|
def _load_conversation(self, year, month, day):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
2017-03-30 21:51:10 +02:00
|
|
|
Load the conversation between `self.jid` and `self.account` held on the
|
|
|
|
given date into the history textbuffer. Values for `month` and `day`
|
|
|
|
are 1-based.
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
2017-03-30 21:24:31 +02:00
|
|
|
self.history_buffer.set_text('')
|
2010-02-08 15:08:40 +01:00
|
|
|
self.last_time_printout = 0
|
2018-11-01 00:29:40 +01:00
|
|
|
show_status = self._ui.show_status_checkbutton.get_active()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-07-15 13:41:17 +02:00
|
|
|
date = datetime.datetime(year, month, day)
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
conversation = app.logger.get_conversation_for_date(
|
2017-07-15 13:41:17 +02:00
|
|
|
self.account, self.jid, date)
|
|
|
|
|
2017-03-30 21:24:31 +02:00
|
|
|
for message in conversation:
|
|
|
|
if not show_status and message.kind in (KindConstant.GCSTATUS,
|
|
|
|
KindConstant.STATUS):
|
2013-02-21 19:47:30 +01:00
|
|
|
continue
|
2017-03-30 21:51:10 +02:00
|
|
|
self._add_message(message)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-03-30 21:51:10 +02:00
|
|
|
def _add_message(self, msg):
|
|
|
|
if not msg.message and msg.kind not in (KindConstant.STATUS,
|
|
|
|
KindConstant.GCSTATUS):
|
2010-02-08 15:08:40 +01:00
|
|
|
return
|
2017-03-02 23:55:18 +01:00
|
|
|
|
2017-03-30 21:51:10 +02:00
|
|
|
tim = msg.time
|
|
|
|
kind = msg.kind
|
|
|
|
show = msg.show
|
|
|
|
message = msg.message
|
|
|
|
subject = msg.subject
|
|
|
|
log_line_id = msg.log_line_id
|
|
|
|
contact_name = msg.contact_name
|
|
|
|
additional_data = msg.additional_data
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
buf = self.history_buffer
|
|
|
|
end_iter = buf.get_end_iter()
|
|
|
|
|
2017-03-02 23:55:18 +01:00
|
|
|
# Make the beginning of every message searchable by its log_line_id
|
|
|
|
buf.create_mark(str(log_line_id), end_iter, left_gravity=True)
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.config.get('print_time') == 'always':
|
|
|
|
timestamp_str = app.config.get('time_stamp')
|
2010-02-08 15:08:40 +01:00
|
|
|
timestamp_str = helpers.from_one_line(timestamp_str)
|
|
|
|
tim = time.strftime(timestamp_str, time.localtime(float(tim)))
|
2017-03-30 21:51:10 +02:00
|
|
|
buf.insert(end_iter, tim)
|
2017-08-13 13:18:56 +02:00
|
|
|
elif app.config.get('print_time') == 'sometimes':
|
|
|
|
every_foo_seconds = 60 * app.config.get(
|
2018-08-04 20:12:38 +02:00
|
|
|
'print_ichat_every_foo_minutes')
|
2010-02-08 15:08:40 +01:00
|
|
|
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)))
|
2018-08-04 20:12:38 +02:00
|
|
|
buf.insert_with_tags_by_name(
|
|
|
|
end_iter, tim + '\n', 'time_sometimes')
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-09-15 10:24:28 +02:00
|
|
|
# print the encryption icon
|
2018-09-22 08:07:46 +02:00
|
|
|
if kind in (KindConstant.CHAT_MSG_SENT,
|
|
|
|
KindConstant.CHAT_MSG_RECV):
|
|
|
|
self.history_textview.print_encryption_status(
|
|
|
|
end_iter, additional_data)
|
2018-09-15 10:24:28 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
tag_name = ''
|
|
|
|
tag_msg = ''
|
|
|
|
|
|
|
|
show = self._get_string_show_from_constant_int(show)
|
|
|
|
|
2017-02-07 21:18:41 +01:00
|
|
|
if kind == KindConstant.GC_MSG:
|
2010-02-08 15:08:40 +01:00
|
|
|
tag_name = 'incoming'
|
2018-08-04 20:12:38 +02:00
|
|
|
elif kind in (KindConstant.SINGLE_MSG_RECV,
|
|
|
|
KindConstant.CHAT_MSG_RECV):
|
2017-02-07 21:18:41 +01:00
|
|
|
contact_name = self.completion_dict[self.jid][InfoColumn.NAME]
|
2010-02-08 15:08:40 +01:00
|
|
|
tag_name = 'incoming'
|
|
|
|
tag_msg = 'incomingtxt'
|
2018-08-04 20:12:38 +02:00
|
|
|
elif kind in (KindConstant.SINGLE_MSG_SENT,
|
|
|
|
KindConstant.CHAT_MSG_SENT):
|
2010-02-08 15:08:40 +01:00
|
|
|
if self.account:
|
2017-08-13 13:18:56 +02:00
|
|
|
contact_name = app.nicks[self.account]
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
# we don't have roster, we don't know our own nick, use first
|
|
|
|
# account one (urk!)
|
2017-08-13 13:18:56 +02:00
|
|
|
account = list(app.contacts.get_accounts())[0]
|
|
|
|
contact_name = app.nicks[account]
|
2010-02-08 15:08:40 +01:00
|
|
|
tag_name = 'outgoing'
|
|
|
|
tag_msg = 'outgoingtxt'
|
2017-02-07 21:18:41 +01:00
|
|
|
elif kind == KindConstant.GCSTATUS:
|
2010-02-08 15:08:40 +01:00
|
|
|
# message here (if not None) is status message
|
|
|
|
if message:
|
2018-08-04 20:12:38 +02:00
|
|
|
message = _('%(nick)s is now %(status)s: %(status_msg)s') % {
|
|
|
|
'nick': contact_name,
|
|
|
|
'status': helpers.get_uf_show(show),
|
|
|
|
'status_msg': message}
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2018-08-04 20:12:38 +02:00
|
|
|
message = _('%(nick)s is now %(status)s') % {
|
|
|
|
'nick': contact_name,
|
2018-09-18 12:06:01 +02:00
|
|
|
'status': helpers.get_uf_show(show)}
|
2010-02-08 15:08:40 +01:00
|
|
|
tag_msg = 'status'
|
2018-08-04 20:12:38 +02:00
|
|
|
else: # 'status'
|
2010-02-08 15:08:40 +01:00
|
|
|
# message here (if not None) is status message
|
2018-08-04 20:12:38 +02:00
|
|
|
if show is None: # it means error
|
2010-02-08 15:08:40 +01:00
|
|
|
if message:
|
|
|
|
message = _('Error: %s') % message
|
|
|
|
else:
|
|
|
|
message = _('Error')
|
|
|
|
elif message:
|
2018-08-04 20:12:38 +02:00
|
|
|
message = _('Status is now: %(status)s: %(status_msg)s') % {
|
|
|
|
'status': helpers.get_uf_show(show),
|
|
|
|
'status_msg': message}
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2018-08-04 20:12:38 +02:00
|
|
|
message = _('Status is now: %(status)s') % {
|
|
|
|
'status': helpers.get_uf_show(show)}
|
2010-02-08 15:08:40 +01:00
|
|
|
tag_msg = 'status'
|
|
|
|
|
|
|
|
if message.startswith('/me ') or message.startswith('/me\n'):
|
|
|
|
tag_msg = tag_name
|
|
|
|
else:
|
|
|
|
# do not do this if gcstats, avoid dupping contact_name
|
|
|
|
# eg. nkour: nkour is now Offline
|
2017-02-07 21:18:41 +01:00
|
|
|
if contact_name and kind != KindConstant.GCSTATUS:
|
2010-02-08 15:08:40 +01:00
|
|
|
# add stuff before and after contact name
|
2017-08-13 13:18:56 +02:00
|
|
|
before_str = app.config.get('before_nickname')
|
2010-02-08 15:08:40 +01:00
|
|
|
before_str = helpers.from_one_line(before_str)
|
2017-08-13 13:18:56 +02:00
|
|
|
after_str = app.config.get('after_nickname')
|
2010-02-08 15:08:40 +01:00
|
|
|
after_str = helpers.from_one_line(after_str)
|
2018-08-04 20:12:38 +02:00
|
|
|
format_ = before_str + contact_name + after_str + ' '
|
2013-01-08 10:22:33 +01:00
|
|
|
if tag_name:
|
2018-08-04 20:12:38 +02:00
|
|
|
buf.insert_with_tags_by_name(end_iter, format_, tag_name)
|
2013-01-08 10:22:33 +01:00
|
|
|
else:
|
2018-08-04 20:12:38 +02:00
|
|
|
buf.insert(end_iter, format_)
|
2010-02-08 15:08:40 +01:00
|
|
|
if subject:
|
|
|
|
message = _('Subject: %s\n') % subject + message
|
2011-05-30 19:47:05 +02:00
|
|
|
xhtml = None
|
|
|
|
if message.startswith('<body '):
|
|
|
|
xhtml = message
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
if tag_msg:
|
2018-08-04 20:12:38 +02:00
|
|
|
self.history_textview.print_real_text(
|
|
|
|
message, [tag_msg],
|
|
|
|
name=contact_name,
|
|
|
|
xhtml=xhtml,
|
|
|
|
additional_data=additional_data)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2018-08-04 20:12:38 +02:00
|
|
|
self.history_textview.print_real_text(
|
|
|
|
message,
|
|
|
|
name=contact_name,
|
|
|
|
xhtml=xhtml,
|
|
|
|
additional_data=additional_data)
|
2017-01-25 10:23:38 +01:00
|
|
|
self.history_textview.print_real_text('\n', text_tags=['eol'])
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-08-04 11:04:36 +02:00
|
|
|
def on_search_complete_history_toggled(self, widget):
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.date_label.get_style_context().remove_class('tagged')
|
2018-08-04 11:04:36 +02:00
|
|
|
|
|
|
|
def on_search_in_date_toggled(self, widget):
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.date_label.get_style_context().add_class('tagged')
|
2018-08-04 11:04:36 +02:00
|
|
|
|
2013-01-03 23:30:17 +01:00
|
|
|
def on_search_entry_activate(self, widget):
|
2018-11-01 00:29:40 +01:00
|
|
|
text = self._ui.search_entry.get_text()
|
2018-08-04 11:04:36 +02:00
|
|
|
|
2018-11-01 00:29:40 +01:00
|
|
|
model = self._ui.results_treeview.get_model()
|
2018-08-04 11:04:36 +02:00
|
|
|
self.clearing_search = True
|
2010-02-08 15:08:40 +01:00
|
|
|
model.clear()
|
2018-08-04 11:04:36 +02:00
|
|
|
self.clearing_search = False
|
|
|
|
|
|
|
|
start = self.history_buffer.get_start_iter()
|
|
|
|
end = self.history_buffer.get_end_iter()
|
|
|
|
self.history_buffer.remove_tag_by_name('highlight', start, end)
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
if text == '':
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.results_scrolledwindow.set_property('visible', False)
|
2010-02-08 15:08:40 +01:00
|
|
|
return
|
2018-09-18 10:14:04 +02:00
|
|
|
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.results_scrolledwindow.set_property('visible', True)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
# perform search in preselected jids
|
2013-01-03 23:30:17 +01:00
|
|
|
# jids are preselected with the query_entry
|
2010-02-08 15:08:40 +01:00
|
|
|
for jid in self.jids_to_search:
|
2017-02-07 21:18:41 +01:00
|
|
|
account = self.completion_dict[jid][InfoColumn.ACCOUNT]
|
2010-02-08 15:08:40 +01:00
|
|
|
if account is None:
|
2018-08-04 20:12:38 +02:00
|
|
|
# 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.
|
|
|
|
# This may leed to wrong self nick in the displayed history
|
2017-08-13 13:18:56 +02:00
|
|
|
account = list(app.contacts.get_accounts())[0]
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-07-15 23:06:49 +02:00
|
|
|
date = None
|
2018-11-01 00:29:40 +01:00
|
|
|
if self._ui.search_in_date.get_active():
|
|
|
|
year, month, day = self._ui.calendar.get_date() # integers
|
2018-08-04 20:12:38 +02:00
|
|
|
month = python_month(month)
|
2017-07-15 23:06:49 +02:00
|
|
|
date = datetime.datetime(year, month, day)
|
2011-12-18 18:28:47 +01:00
|
|
|
|
2018-11-01 00:29:40 +01:00
|
|
|
show_status = self._ui.show_status_checkbutton.get_active()
|
2017-07-15 23:06:49 +02:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
results = app.logger.search_log(account, jid, text, date)
|
2018-08-04 11:04:36 +02:00
|
|
|
result_found = False
|
2018-08-04 20:12:38 +02:00
|
|
|
# FIXME:
|
2010-02-08 15:08:40 +01:00
|
|
|
# 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:
|
2017-03-23 22:56:54 +01:00
|
|
|
if not show_status and row.kind in (KindConstant.GCSTATUS,
|
|
|
|
KindConstant.STATUS):
|
2013-02-21 19:47:30 +01:00
|
|
|
continue
|
2017-03-23 22:56:54 +01:00
|
|
|
|
|
|
|
contact_name = row.contact_name
|
2010-02-08 15:08:40 +01:00
|
|
|
if not contact_name:
|
2018-08-04 20:12:38 +02:00
|
|
|
if row.kind == KindConstant.CHAT_MSG_SENT:
|
2017-08-13 13:18:56 +02:00
|
|
|
contact_name = app.nicks[account]
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2017-02-07 21:18:41 +01:00
|
|
|
contact_name = self.completion_dict[jid][InfoColumn.NAME]
|
2017-03-23 22:56:54 +01:00
|
|
|
|
|
|
|
local_time = time.localtime(row.time)
|
2010-02-08 15:08:40 +01:00
|
|
|
date = time.strftime('%Y-%m-%d', local_time)
|
|
|
|
|
2018-08-04 11:04:36 +02:00
|
|
|
result_found = True
|
2017-03-23 22:56:54 +01:00
|
|
|
model.append((jid, contact_name, date, row.message,
|
|
|
|
str(row.time), row.log_line_id))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-08-04 11:04:36 +02:00
|
|
|
if result_found:
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.results_treeview.set_cursor(0)
|
2018-08-04 11:04:36 +02:00
|
|
|
|
|
|
|
def on_results_treeview_cursor_changed(self, *args):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
2018-08-04 11:04:36 +02:00
|
|
|
A row was selected, get date from row, and select it in calendar
|
2010-02-08 15:08:40 +01:00
|
|
|
which results to showing conversation logs for that date
|
|
|
|
"""
|
2018-08-04 11:04:36 +02:00
|
|
|
if self.clearing_search:
|
|
|
|
return
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
# get currently selected date
|
2018-11-01 00:29:40 +01:00
|
|
|
cur_year, cur_month, cur_day = self._ui.calendar.get_date()
|
2018-08-04 20:12:38 +02:00
|
|
|
cur_month = python_month(cur_month)
|
2018-11-01 00:29:40 +01:00
|
|
|
model, paths = self._ui.results_treeview.get_selection().get_selected_rows()
|
2018-08-04 11:04:36 +02:00
|
|
|
|
|
|
|
if not paths:
|
|
|
|
return
|
|
|
|
|
|
|
|
path = paths[0]
|
2017-03-06 20:38:29 +01:00
|
|
|
# make it a tuple (Y, M, D, 0, 0, 0...)
|
2017-02-07 21:18:41 +01:00
|
|
|
tim = time.strptime(model[path][Column.UNIXTIME], '%Y-%m-%d')
|
2010-02-08 15:08:40 +01:00
|
|
|
year = tim[0]
|
2018-08-06 19:07:42 +02:00
|
|
|
gtk_m = tim[1]
|
|
|
|
month = gtk_month(gtk_m)
|
2010-02-08 15:08:40 +01:00
|
|
|
day = tim[2]
|
|
|
|
|
|
|
|
# switch to belonging logfile if necessary
|
2017-02-07 21:18:41 +01:00
|
|
|
log_jid = model[path][Column.LOG_JID]
|
2010-02-08 15:08:40 +01:00
|
|
|
if log_jid != self.jid:
|
|
|
|
self._load_history(log_jid, None)
|
|
|
|
|
|
|
|
# avoid reruning mark days algo if same month and year!
|
2018-08-06 19:07:42 +02:00
|
|
|
if year != cur_year or gtk_m != cur_month:
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.calendar.select_month(month, year)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-08-06 19:07:42 +02:00
|
|
|
if year != cur_year or gtk_m != cur_month or day != cur_day:
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.calendar.select_day(day)
|
2017-03-03 17:29:05 +01:00
|
|
|
|
2017-03-02 23:55:18 +01:00
|
|
|
self._scroll_to_message_and_highlight(model[path][Column.LOG_LINE_ID])
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-03-02 23:55:18 +01:00
|
|
|
def _scroll_to_message_and_highlight(self, log_line_id):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
2017-03-02 23:55:18 +01:00
|
|
|
Scroll to a message and highlight it
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
2017-03-02 23:55:18 +01:00
|
|
|
|
|
|
|
def iterator_has_mark(iterator, mark_name):
|
|
|
|
for mark in iterator.get_marks():
|
|
|
|
if mark.get_name() == mark_name:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2017-03-03 17:29:05 +01:00
|
|
|
# Clear previous search result by removing the highlighting. The scroll
|
|
|
|
# mark is automatically removed when the new one is set.
|
|
|
|
start = self.history_buffer.get_start_iter()
|
|
|
|
end = self.history_buffer.get_end_iter()
|
|
|
|
self.history_buffer.remove_tag_by_name('highlight', start, end)
|
|
|
|
|
2017-03-02 23:55:18 +01:00
|
|
|
log_line_id = str(log_line_id)
|
2017-03-03 17:29:05 +01:00
|
|
|
line = start
|
2017-03-02 23:55:18 +01:00
|
|
|
while not iterator_has_mark(line, log_line_id):
|
|
|
|
if not line.forward_line():
|
|
|
|
return
|
|
|
|
|
|
|
|
match_start = line
|
|
|
|
match_end = match_start.copy()
|
|
|
|
match_end.forward_to_tag_toggle(self.history_buffer.eol_tag)
|
|
|
|
|
2018-08-04 20:12:38 +02:00
|
|
|
self.history_buffer.apply_tag_by_name(
|
|
|
|
'highlight', match_start, match_end)
|
2017-03-02 23:55:18 +01:00
|
|
|
mark = self.history_buffer.create_mark('match', match_start, True)
|
2018-08-04 20:12:38 +02:00
|
|
|
GLib.idle_add(
|
|
|
|
self.history_textview.tv.scroll_to_mark, mark, 0, True, 0.0, 0.5)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-08-04 11:04:36 +02:00
|
|
|
def on_log_history_checkbutton_toggled(self, widget, *args):
|
2010-02-08 15:08:40 +01:00
|
|
|
# log conversation history?
|
|
|
|
oldlog = True
|
2018-08-04 20:12:38 +02:00
|
|
|
no_log_for = app.config.get_per(
|
|
|
|
'accounts', self.account, 'no_log_for').split()
|
2010-02-08 15:08:40 +01:00
|
|
|
if self.jid in no_log_for:
|
|
|
|
oldlog = False
|
|
|
|
log = widget.get_active()
|
2018-08-04 20:12:38 +02:00
|
|
|
if not log and self.jid not in no_log_for:
|
2010-02-08 15:08:40 +01:00
|
|
|
no_log_for.append(self.jid)
|
|
|
|
if log and self.jid in no_log_for:
|
|
|
|
no_log_for.remove(self.jid)
|
|
|
|
if oldlog != log:
|
2018-08-04 20:12:38 +02:00
|
|
|
app.config.set_per(
|
|
|
|
'accounts', self.account, 'no_log_for', ' '.join(no_log_for))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2013-02-21 19:47:30 +01:00
|
|
|
def on_show_status_checkbutton_toggled(self, widget):
|
|
|
|
# reload logs
|
|
|
|
self.on_calendar_day_selected(None)
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def open_history(self, jid, account):
|
|
|
|
"""
|
|
|
|
Load chat history of the specified jid
|
|
|
|
"""
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.query_entry.get_child().set_text(jid)
|
2010-02-08 15:08:40 +01:00
|
|
|
if account and account not in self.accounts_seen_online:
|
|
|
|
# Update dict to not only show bare jid
|
2013-07-29 18:35:49 +02:00
|
|
|
GLib.idle_add(next, self._fill_completion_dict())
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2018-08-04 20:12:38 +02:00
|
|
|
# Only in that case because it's called by
|
|
|
|
# self._fill_completion_dict() otherwise
|
2010-02-08 15:08:40 +01:00
|
|
|
self._load_history(jid, account)
|
2018-11-01 00:29:40 +01:00
|
|
|
self._ui.results_scrolledwindow.set_property('visible', False)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def save_state(self):
|
2018-11-04 22:19:58 +01:00
|
|
|
x, y = self.get_window().get_root_origin()
|
|
|
|
width, height = self.get_size()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.set('history_window_x-position', x)
|
|
|
|
app.config.set('history_window_y-position', y)
|
|
|
|
app.config.set('history_window_width', width)
|
|
|
|
app.config.set('history_window_height', height)
|