history manager. pep8 pylint
This commit is contained in:
parent
2d72cf8bf9
commit
bc4b3d0437
1 changed files with 123 additions and 108 deletions
|
@ -24,7 +24,8 @@
|
||||||
##
|
##
|
||||||
|
|
||||||
## NOTE: some method names may match those of logger.py but that's it
|
## NOTE: some method names may match those of logger.py but that's it
|
||||||
## someday (TM) should have common class that abstracts db connections and helpers on it
|
## someday (TM) should have common class
|
||||||
|
## that abstracts db connections and helpers on it
|
||||||
## the same can be said for history_window.py
|
## the same can be said for history_window.py
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
@ -108,7 +109,8 @@ import sqlite3 as sqlite
|
||||||
class HistoryManager:
|
class HistoryManager:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pix = gtkgui_helpers.get_icon_pixmap('gajim')
|
pix = gtkgui_helpers.get_icon_pixmap('gajim')
|
||||||
gtk.window_set_default_icon(pix) # set the icon to all newly opened windows
|
# set the icon to all newly opened windows
|
||||||
|
gtk.window_set_default_icon(pix)
|
||||||
|
|
||||||
if not os.path.exists(LOG_DB_PATH):
|
if not os.path.exists(LOG_DB_PATH):
|
||||||
dialogs.ErrorDialog(_('Cannot find history logs database'),
|
dialogs.ErrorDialog(_('Cannot find history logs database'),
|
||||||
|
@ -165,13 +167,15 @@ class HistoryManager:
|
||||||
|
|
||||||
renderer_text = gtk.CellRendererText() # holds time
|
renderer_text = gtk.CellRendererText() # holds time
|
||||||
col = gtk.TreeViewColumn(_('Date'), renderer_text, text=C_UNIXTIME)
|
col = gtk.TreeViewColumn(_('Date'), renderer_text, text=C_UNIXTIME)
|
||||||
col.set_sort_column_id(C_UNIXTIME) # user can click this header and sort
|
# user can click this header and sort
|
||||||
|
col.set_sort_column_id(C_UNIXTIME)
|
||||||
col.set_resizable(True)
|
col.set_resizable(True)
|
||||||
self.logs_listview.append_column(col)
|
self.logs_listview.append_column(col)
|
||||||
|
|
||||||
renderer_text = gtk.CellRendererText() # holds nickname
|
renderer_text = gtk.CellRendererText() # holds nickname
|
||||||
col = gtk.TreeViewColumn(_('Nickname'), renderer_text, text=C_NICKNAME)
|
col = gtk.TreeViewColumn(_('Nickname'), renderer_text, text=C_NICKNAME)
|
||||||
col.set_sort_column_id(C_NICKNAME) # user can click this header and sort
|
# user can click this header and sort
|
||||||
|
col.set_sort_column_id(C_NICKNAME)
|
||||||
col.set_resizable(True)
|
col.set_resizable(True)
|
||||||
col.set_visible(False)
|
col.set_visible(False)
|
||||||
self.nickname_col_for_logs = col
|
self.nickname_col_for_logs = col
|
||||||
|
@ -179,7 +183,8 @@ class HistoryManager:
|
||||||
|
|
||||||
renderer_text = gtk.CellRendererText() # holds message
|
renderer_text = gtk.CellRendererText() # holds message
|
||||||
col = gtk.TreeViewColumn(_('Message'), renderer_text, markup=C_MESSAGE)
|
col = gtk.TreeViewColumn(_('Message'), renderer_text, markup=C_MESSAGE)
|
||||||
col.set_sort_column_id(C_MESSAGE) # user can click this header and sort
|
# user can click this header and sort
|
||||||
|
col.set_sort_column_id(C_MESSAGE)
|
||||||
col.set_resizable(True)
|
col.set_resizable(True)
|
||||||
self.message_col_for_logs = col
|
self.message_col_for_logs = col
|
||||||
self.logs_listview.append_column(col)
|
self.logs_listview.append_column(col)
|
||||||
|
@ -194,7 +199,8 @@ class HistoryManager:
|
||||||
|
|
||||||
def _init_search_results_listview(self):
|
def _init_search_results_listview(self):
|
||||||
# log_line_id (HIDDEN), jid, time, message, subject, nickname
|
# log_line_id (HIDDEN), jid, time, message, subject, nickname
|
||||||
self.search_results_liststore = gtk.ListStore(str, str, str, str, str, str)
|
self.search_results_liststore = gtk.ListStore(str, str, str, str, str,
|
||||||
|
str)
|
||||||
self.search_results_listview.set_model(self.search_results_liststore)
|
self.search_results_listview.set_model(self.search_results_liststore)
|
||||||
|
|
||||||
renderer_text = gtk.CellRendererText() # holds JID (who said this)
|
renderer_text = gtk.CellRendererText() # holds JID (who said this)
|
||||||
|
@ -205,7 +211,8 @@ class HistoryManager:
|
||||||
|
|
||||||
renderer_text = gtk.CellRendererText() # holds time
|
renderer_text = gtk.CellRendererText() # holds time
|
||||||
col = gtk.TreeViewColumn(_('Date'), renderer_text, text=C_UNIXTIME)
|
col = gtk.TreeViewColumn(_('Date'), renderer_text, text=C_UNIXTIME)
|
||||||
col.set_sort_column_id(C_UNIXTIME) # user can click this header and sort
|
# user can click this header and sort
|
||||||
|
col.set_sort_column_id(C_UNIXTIME)
|
||||||
col.set_resizable(True)
|
col.set_resizable(True)
|
||||||
self.search_results_listview.append_column(col)
|
self.search_results_listview.append_column(col)
|
||||||
|
|
||||||
|
@ -223,12 +230,16 @@ class HistoryManager:
|
||||||
|
|
||||||
renderer_text = gtk.CellRendererText() # holds nickname
|
renderer_text = gtk.CellRendererText() # holds nickname
|
||||||
col = gtk.TreeViewColumn(_('Nickname'), renderer_text, text=C_NICKNAME)
|
col = gtk.TreeViewColumn(_('Nickname'), renderer_text, text=C_NICKNAME)
|
||||||
col.set_sort_column_id(C_NICKNAME) # user can click this header and sort
|
# user can click this header and sort
|
||||||
|
col.set_sort_column_id(C_NICKNAME)
|
||||||
col.set_resizable(True)
|
col.set_resizable(True)
|
||||||
self.search_results_listview.append_column(col)
|
self.search_results_listview.append_column(col)
|
||||||
|
|
||||||
def on_history_manager_window_delete_event(self, widget, event):
|
def on_history_manager_window_delete_event(self, widget, event):
|
||||||
if self.AT_LEAST_ONE_DELETION_DONE:
|
if not self.AT_LEAST_ONE_DELETION_DONE:
|
||||||
|
gtk.main_quit()
|
||||||
|
return
|
||||||
|
|
||||||
def on_yes(clicked):
|
def on_yes(clicked):
|
||||||
self.cur.execute('VACUUM')
|
self.cur.execute('VACUUM')
|
||||||
self.con.commit()
|
self.con.commit()
|
||||||
|
@ -237,7 +248,7 @@ class HistoryManager:
|
||||||
def on_no():
|
def on_no():
|
||||||
gtk.main_quit()
|
gtk.main_quit()
|
||||||
|
|
||||||
dialogs.YesNoDialog(
|
dialog = dialogs.YesNoDialog(
|
||||||
_('Do you want to clean up the database? '
|
_('Do you want to clean up the database? '
|
||||||
'(STRONGLY NOT RECOMMENDED IF GAJIM IS RUNNING)'),
|
'(STRONGLY NOT RECOMMENDED IF GAJIM IS RUNNING)'),
|
||||||
_('Normally allocated database size will not be freed, '
|
_('Normally allocated database size will not be freed, '
|
||||||
|
@ -245,15 +256,15 @@ class HistoryManager:
|
||||||
'database filesize, click YES, else click NO.'
|
'database filesize, click YES, else click NO.'
|
||||||
'\n\nIn case you click YES, please wait...'),
|
'\n\nIn case you click YES, please wait...'),
|
||||||
on_response_yes=on_yes, on_response_no=on_no)
|
on_response_yes=on_yes, on_response_no=on_no)
|
||||||
return
|
button_box = dialog.get_children()[0].get_children()[1]
|
||||||
|
button_box.get_children()[0].grab_focus()
|
||||||
gtk.main_quit()
|
|
||||||
|
|
||||||
def _fill_jids_listview(self):
|
def _fill_jids_listview(self):
|
||||||
# get those jids that have at least one entry in logs
|
# get those jids that have at least one entry in logs
|
||||||
self.cur.execute('SELECT jid, jid_id FROM jids WHERE jid_id IN (SELECT '
|
self.cur.execute('SELECT jid, jid_id FROM jids WHERE jid_id IN ('
|
||||||
'distinct logs.jid_id FROM logs) ORDER BY jid')
|
'SELECT distinct logs.jid_id FROM logs) ORDER BY jid')
|
||||||
rows = self.cur.fetchall() # list of tupples: [(u'aaa@bbb',), (u'cc@dd',)]
|
# list of tupples: [(u'aaa@bbb',), (u'cc@dd',)]
|
||||||
|
rows = self.cur.fetchall()
|
||||||
for row in rows:
|
for row in rows:
|
||||||
self.jids_already_in.append(row[0]) # jid
|
self.jids_already_in.append(row[0]) # jid
|
||||||
self.jids_liststore.append(row) # jid, jid_id
|
self.jids_liststore.append(row) # jid, jid_id
|
||||||
|
@ -369,10 +380,11 @@ class HistoryManager:
|
||||||
# time, message, subject, nickname
|
# time, message, subject, nickname
|
||||||
# but store in liststore
|
# but store in liststore
|
||||||
# log_line_id, jid_id, time, message, subject, nickname
|
# log_line_id, jid_id, time, message, subject, nickname
|
||||||
log_line_id, jid_id, time_, kind, message, subject, nickname, show = row
|
log_line_id, jid_id, time_, kind, message, subject, nickname, \
|
||||||
|
show = row
|
||||||
try:
|
try:
|
||||||
time_ = time.strftime('%x', time.localtime(float(time_))).decode(
|
time_ = time.strftime('%x', time.localtime(float(time_))
|
||||||
locale.getpreferredencoding())
|
).decode(locale.getpreferredencoding())
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
@ -386,21 +398,23 @@ class HistoryManager:
|
||||||
color = gajim.config.get('outmsgcolor') # so outgoing color
|
color = gajim.config.get('outmsgcolor') # so outgoing color
|
||||||
elif kind in (constants.KIND_STATUS,
|
elif kind in (constants.KIND_STATUS,
|
||||||
constants.KIND_GCSTATUS): # is is statuses
|
constants.KIND_GCSTATUS): # is is statuses
|
||||||
color = gajim.config.get('statusmsgcolor') # so status color
|
# so status color
|
||||||
|
color = gajim.config.get('statusmsgcolor')
|
||||||
# include status into (status) message
|
# include status into (status) message
|
||||||
if message is None:
|
if message is None:
|
||||||
message = ''
|
message = ''
|
||||||
else:
|
else:
|
||||||
message = ' : ' + message
|
message = ' : ' + message
|
||||||
message = helpers.get_uf_show(gajim.SHOW_LIST[show]) + message
|
message = helpers.get_uf_show(gajim.SHOW_LIST[show]) + \
|
||||||
|
message
|
||||||
|
|
||||||
message_ = '<span'
|
message_ = '<span'
|
||||||
if color:
|
if color:
|
||||||
message_ += ' foreground="%s"' % color
|
message_ += ' foreground="%s"' % color
|
||||||
message_ += '>%s</span>' % \
|
message_ += '>%s</span>' % \
|
||||||
gobject.markup_escape_text(message)
|
gobject.markup_escape_text(message)
|
||||||
self.logs_liststore.append((log_line_id, jid_id, time_, message_,
|
self.logs_liststore.append((log_line_id, jid_id, time_,
|
||||||
subject, nickname))
|
message_, subject, nickname))
|
||||||
|
|
||||||
def _fill_search_results_listview(self, text):
|
def _fill_search_results_listview(self, text):
|
||||||
"""
|
"""
|
||||||
|
@ -423,8 +437,8 @@ class HistoryManager:
|
||||||
# log_line_id, jid (from jid_id), time, message, subject, nickname
|
# log_line_id, jid (from jid_id), time, message, subject, nickname
|
||||||
log_line_id, jid_id, time_, message, subject, nickname = row
|
log_line_id, jid_id, time_, message, subject, nickname = row
|
||||||
try:
|
try:
|
||||||
time_ = time.strftime('%x', time.localtime(float(time_))).decode(
|
time_ = time.strftime('%x', time.localtime(float(time_))
|
||||||
locale.getpreferredencoding())
|
).decode(locale.getpreferredencoding())
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
@ -441,7 +455,8 @@ class HistoryManager:
|
||||||
|
|
||||||
def on_listview_button_press_event(self, widget, event):
|
def on_listview_button_press_event(self, widget, event):
|
||||||
if event.button == 3: # right click
|
if event.button == 3: # right click
|
||||||
xml = gtkgui_helpers.get_gtk_builder('history_manager.ui', 'context_menu')
|
xml = gtkgui_helpers.get_gtk_builder('history_manager.ui',
|
||||||
|
'context_menu')
|
||||||
if widget.name != 'jids_listview':
|
if widget.name != 'jids_listview':
|
||||||
xml.get_object('export_menuitem').hide()
|
xml.get_object('export_menuitem').hide()
|
||||||
xml.get_object('delete_menuitem').connect('activate',
|
xml.get_object('delete_menuitem').connect('activate',
|
||||||
|
@ -453,7 +468,8 @@ class HistoryManager:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def on_export_menuitem_activate(self, widget):
|
def on_export_menuitem_activate(self, widget):
|
||||||
xml = gtkgui_helpers.get_gtk_builder('history_manager.ui', 'filechooserdialog')
|
xml = gtkgui_helpers.get_gtk_builder('history_manager.ui',
|
||||||
|
'filechooserdialog')
|
||||||
xml.connect_signals(self)
|
xml.connect_signals(self)
|
||||||
|
|
||||||
dlg = xml.get_object('filechooserdialog')
|
dlg = xml.get_object('filechooserdialog')
|
||||||
|
@ -466,7 +482,8 @@ class HistoryManager:
|
||||||
liststore, list_of_paths = self.jids_listview.get_selection()\
|
liststore, list_of_paths = self.jids_listview.get_selection()\
|
||||||
.get_selected_rows()
|
.get_selected_rows()
|
||||||
path_to_file = dlg.get_filename()
|
path_to_file = dlg.get_filename()
|
||||||
self._export_jids_logs_to_file(liststore, list_of_paths, path_to_file)
|
self._export_jids_logs_to_file(liststore, list_of_paths,
|
||||||
|
path_to_file)
|
||||||
|
|
||||||
dlg.destroy()
|
dlg.destroy()
|
||||||
|
|
||||||
|
@ -528,13 +545,13 @@ class HistoryManager:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
time_ = time.strftime('%c', time.localtime(float(time_))).decode(
|
time_ = time.strftime('%c', time.localtime(float(time_))
|
||||||
locale.getpreferredencoding())
|
).decode(locale.getpreferredencoding())
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
file_.write(_('%(who)s on %(time)s said: %(message)s\n') % {'who': who,
|
file_.write(_('%(who)s on %(time)s said: %(message)s\n') % {
|
||||||
'time': time_, 'message': message})
|
'who': who, 'time': time_, 'message': message})
|
||||||
|
|
||||||
def _delete_jid_logs(self, liststore, list_of_paths):
|
def _delete_jid_logs(self, liststore, list_of_paths):
|
||||||
paths_len = len(list_of_paths)
|
paths_len = len(list_of_paths)
|
||||||
|
@ -607,7 +624,6 @@ class HistoryManager:
|
||||||
|
|
||||||
self.AT_LEAST_ONE_DELETION_DONE = True
|
self.AT_LEAST_ONE_DELETION_DONE = True
|
||||||
|
|
||||||
|
|
||||||
pri_text = i18n.ngettext(
|
pri_text = i18n.ngettext(
|
||||||
'Do you really want to delete the selected message?',
|
'Do you really want to delete the selected message?',
|
||||||
'Do you really want to delete the selected messages?', paths_len)
|
'Do you really want to delete the selected messages?', paths_len)
|
||||||
|
@ -637,7 +653,6 @@ class HistoryManager:
|
||||||
# as this is what db returns so I don't have to fight with types
|
# as this is what db returns so I don't have to fight with types
|
||||||
jid_id = self._get_jid_id(jid)
|
jid_id = self._get_jid_id(jid)
|
||||||
|
|
||||||
|
|
||||||
iter_ = self.jids_liststore.get_iter_root()
|
iter_ = self.jids_liststore.get_iter_root()
|
||||||
while iter_:
|
while iter_:
|
||||||
# self.jids_liststore[iter_][1] holds jid_ids
|
# self.jids_liststore[iter_][1] holds jid_ids
|
||||||
|
|
Loading…
Add table
Reference in a new issue