Philipp Hörist pushed to branch master at gajim / gajim
Commits:
2e026335 by Markus Böhme at 2017-02-22T12:56:31+01:00
Simplify appending new line in history window
ConversationTextview provides an abstraction for adding text with tags.
Use it instead of directly accessing its backing text buffer.
- - - - -
d9a22515 by Markus Böhme at 2017-02-22T12:56:31+01:00
Highlight all paragraphs of a search result in the history window
A single message may span multiple paragraphs. Highlight all paragraphs
of a search result because a keyword could be in any of them.
Every message already has the 'eol' tag on its newline character.
Highlight from the start of a search match up to the next 'eol' tag.
- - - - -
65c6a1e7 by Markus Böhme at 2017-02-22T12:56:31+01:00
Remove unnecessary code in message highlighting in the history window
The message to be highlighted is searched via an already formatted
timestamp, and the match contains the whole timestamp with any
preceding characters (like "["). Therefore, calling backward_char on
the start iterator of the match just goes back to the previous line
and is not needed.
- - - - -
66589886 by Markus Böhme at 2017-02-22T14:55:44+01:00
Remove dead code in logger.py method get_search_results_for_query
The method get_search_results_for_query provides a means to search via a
passed in SQL query. This feature has been unused and dead since its initial
commit back in 2005 (commit e542fff69f56), so just remove it.
- - - - -
d75ebd95 by Markus Böhme at 2017-03-02T23:55:18+01:00
Rework message highlighting in the history window to not use timestamps
Search results in the history window to are scrolled to and highlighted
once the user clicks on one of them. Messages are searched by text in
the log database, but then looked up in the history text buffer via a
visible or invisible timestamp obtained from the database record.
Timestamps in the history text buffer, depending on user configuration,
may only have a coarse granularity. Philipp Hörist discovered that this
may lead to the highlighting of the wrong line in the history text view
and proposed an alternative solution that is implemented in this patch.
Timestamps are abolished as a means of searching messages. Instead, add
a mark with the unique message id (log line id) at the start of every
message in the history text buffer when the conversation is loaded.
After fetching the search results from the database this id can be used
to unambiguously find the corresponding message in the history text
buffer.
- - - - -
deebe384 by Markus Böhme at 2017-03-03T17:29:05+01:00
Prevent unnecessary reloading of conversations in the history window
Do not reload the conversation in the history window when the user
selects another search result from the same day. Just clearing the
previous highlighting is enough. This prevents flickering and provides
a much more pleasant user experience.
- - - - -
1b975172 by Philipp Hörist at 2017-03-03T23:45:06+01:00
Merge branch 'history-highlighting' into 'master'
Highlight all paragraphs of a message in the history window
See merge request !46
- - - - -
3 changed files:
- src/common/logger.py
- src/history_window.py
- src/htmltextview.py
Changes:
=====================================
src/common/logger.py
=====================================
--- a/src/common/logger.py
+++ b/src/common/logger.py
@@ -628,7 +628,7 @@ class Logger:
def get_conversation_for_date(self, jid, year, month, day, account):
"""
- Return contact_name, time, kind, show, message, subject
+ Return contact_name, time, kind, show, message, subject, additional_data, log_line_id
For each row in a list of tupples, returns list with empty tupple if we
found nothing to meet our demands
@@ -645,7 +645,9 @@ class Logger:
last_second_of_day = start_of_day + seconds_in_a_day - 1
self.cur.execute('''
- SELECT contact_name, time, kind, show, message, subject, additional_data FROM logs
+ SELECT contact_name, time, kind, show, message, subject,
+ additional_data, log_line_id
+ FROM logs
WHERE (%s)
AND time BETWEEN %d AND %d
ORDER BY time
@@ -660,7 +662,7 @@ class Logger:
def get_search_results_for_query(self, jid, query, account, year=False,
month=False, day=False):
"""
- Returns contact_name, time, kind, show, message
+ Returns contact_name, time, kind, show, message, subject, log_line_id
For each row in a list of tupples, returns list with empty tupple if we
found nothing to meet our demands
@@ -671,33 +673,25 @@ class Logger:
# Error trying to create a new jid_id. This means there is no log
return []
- if False: # query.startswith('SELECT '): # it's SQL query (FIXME)
- try:
- self.cur.execute(query)
- except sqlite.OperationalError as e:
- results = [('', '', '', '', str(e))]
- return results
-
- else: # user just typed something, we search in message column
- where_sql, jid_tuple = self._build_contact_where(account, jid)
- like_sql = '%' + query.replace("'", "''") + '%'
- if year:
- start_of_day = self.get_unix_time_from_date(year, month, day)
- seconds_in_a_day = 86400 # 60 * 60 * 24
- last_second_of_day = start_of_day + seconds_in_a_day - 1
- self.cur.execute('''
- SELECT contact_name, time, kind, show, message, subject FROM logs
- WHERE (%s) AND message LIKE '%s'
- AND time BETWEEN %d AND %d
- ORDER BY time
- ''' % (where_sql, like_sql, start_of_day, last_second_of_day),
- jid_tuple)
- else:
- self.cur.execute('''
- SELECT contact_name, time, kind, show, message, subject FROM logs
- WHERE (%s) AND message LIKE '%s'
- ORDER BY time
- ''' % (where_sql, like_sql), jid_tuple)
+ where_sql, jid_tuple = self._build_contact_where(account, jid)
+ like_sql = '%' + query.replace("'", "''") + '%'
+ if year:
+ start_of_day = self.get_unix_time_from_date(year, month, day)
+ seconds_in_a_day = 86400 # 60 * 60 * 24
+ last_second_of_day = start_of_day + seconds_in_a_day - 1
+ self.cur.execute('''
+ SELECT contact_name, time, kind, show, message, subject, log_line_id FROM logs
+ WHERE (%s) AND message LIKE '%s'
+ AND time BETWEEN %d AND %d
+ ORDER BY time
+ ''' % (where_sql, like_sql, start_of_day, last_second_of_day),
+ jid_tuple)
+ else:
+ self.cur.execute('''
+ SELECT contact_name, time, kind, show, message, subject, log_line_id FROM logs
+ WHERE (%s) AND message LIKE '%s'
+ ORDER BY time
+ ''' % (where_sql, like_sql), jid_tuple)
results = self.cur.fetchall()
return results
=====================================
src/history_window.py
=====================================
--- a/src/history_window.py
+++ b/src/history_window.py
@@ -56,6 +56,7 @@ class Column(IntEnum):
UNIXTIME = 2
MESSAGE = 3
TIME = 4
+ LOG_LINE_ID = 5
class HistoryWindow:
"""
@@ -85,8 +86,8 @@ class HistoryWindow:
self.results_window = xml.get_object('results_scrolledwindow')
self.search_in_date = xml.get_object('search_in_date')
- # contact_name, date, message, time
- model = Gtk.ListStore(str, str, str, str, str)
+ # jid, contact_name, date, message, time, log_line_id
+ model = Gtk.ListStore(str, str, str, str, str, int)
self.results_treeview.set_model(model)
col = Gtk.TreeViewColumn(_('Name'))
self.results_treeview.append_column(col)
@@ -393,28 +394,31 @@ class HistoryWindow:
show_status = self.show_status_checkbutton.get_active()
lines = gajim.logger.get_conversation_for_date(self.jid, year, month, day, self.account)
- # lines holds list with tupples that have:
- # contact_name, time, kind, show, message
for line in lines:
# line[0] is contact_name, line[1] is time of message
# line[2] is kind, line[3] is show, line[4] is message, line[5] is subject
- # line[6] is additional_data
+ # line[6] is additional_data, line[7] is log_line_id
if not show_status and line[2] in (KindConstant.GCSTATUS,
KindConstant.STATUS):
continue
self._add_new_line(line[0], line[1], line[2], line[3], line[4],
- line[5], line[6])
+ line[5], line[6], line[7])
- def _add_new_line(self, contact_name, tim, kind, show, message, subject, additional_data):
+ def _add_new_line(self, contact_name, tim, kind, show, message, subject,
+ additional_data, log_line_id):
"""
Add a new line in textbuffer
"""
if not message and kind not in (KindConstant.STATUS,
KindConstant.GCSTATUS):
return
+
buf = self.history_buffer
end_iter = buf.get_end_iter()
+ # Make the beginning of every message searchable by its log_line_id
+ buf.create_mark(str(log_line_id), end_iter, left_gravity=True)
+
if gajim.config.get('print_time') == 'always':
timestamp_str = gajim.config.get('time_stamp')
timestamp_str = helpers.from_one_line(timestamp_str)
@@ -429,12 +433,6 @@ class HistoryWindow:
tim = time.strftime('%X ', time.localtime(float(tim)))
buf.insert_with_tags_by_name(end_iter, tim + '\n',
'time_sometimes')
- else: # don't print time. So we print it as invisible to be able to
- # search for it
- timestamp_str = gajim.config.get('time_stamp')
- timestamp_str = helpers.from_one_line(timestamp_str)
- tim = time.strftime(timestamp_str, time.localtime(float(tim)))
- buf.insert_with_tags_by_name(end_iter, tim, 'invisible')
tag_name = ''
tag_msg = ''
@@ -512,9 +510,7 @@ class HistoryWindow:
else:
self.history_textview.print_real_text(message, name=contact_name,
xhtml=xhtml, additional_data=additional_data)
- buffer_ = self.history_textview.tv.get_buffer()
- eob = buffer_.get_end_iter()
- buffer_.insert_with_tags_by_name(eob, '\n', 'eol')
+ self.history_textview.print_real_text('\n', text_tags=['eol'])
def on_search_entry_activate(self, widget):
text = self.search_entry.get_text()
@@ -563,12 +559,13 @@ class HistoryWindow:
contact_name = self.completion_dict[jid][InfoColumn.NAME]
tim = row[1]
message = row[4]
+ log_line_id = row[6]
local_time = time.localtime(tim)
date = time.strftime('%Y-%m-%d', local_time)
# jid (to which log is assigned to), name, date, message,
# time (full unix time)
- model.append((jid, contact_name, date, message, str(tim)))
+ model.append((jid, contact_name, date, message, str(tim), log_line_id))
def on_results_treeview_row_activated(self, widget, path, column):
"""
@@ -576,7 +573,7 @@ class HistoryWindow:
which results to showing conversation logs for that date
"""
# get currently selected date
- cur_year, cur_month = self.calendar.get_date()[0:2]
+ 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()
# make it a tupple (Y, M, D, 0, 0, 0...)
@@ -595,33 +592,41 @@ class HistoryWindow:
if year != cur_year or gtk_month != cur_month:
self.calendar.select_month(month, year)
- self.calendar.select_day(day)
- unix_time = model[path][Column.TIME]
- 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
+ if year != cur_year or gtk_month != cur_month or day != cur_day:
+ self.calendar.select_day(day)
+
+ self._scroll_to_message_and_highlight(model[path][Column.LOG_LINE_ID])
- def _scroll_to_result(self, unix_time):
+ def _scroll_to_message_and_highlight(self, log_line_id):
"""
- Scroll to the result using unix_time and highlight line
+ Scroll to a message and highlight it
"""
- start_iter = self.history_buffer.get_start_iter()
- local_time = time.localtime(float(unix_time))
- timestamp_str = gajim.config.get('time_stamp')
- timestamp_str = helpers.from_one_line(timestamp_str)
- tim = time.strftime(timestamp_str, local_time)
- result = start_iter.forward_search(tim, Gtk.TextSearchFlags.TEXT_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
- match_end_iter.forward_line() # highlight all message not just time
- self.history_buffer.apply_tag_by_name('highlight', match_start_iter,
- match_end_iter)
- mark = self.history_buffer.create_mark('match', match_start_iter, True)
- GLib.idle_add(self.history_textview.tv.scroll_to_mark, mark,
- 0, True, 0.0, 0.5)
+
+ def iterator_has_mark(iterator, mark_name):
+ for mark in iterator.get_marks():
+ if mark.get_name() == mark_name:
+ return True
+ return False
+
+ # 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)
+
+ log_line_id = str(log_line_id)
+ line = start
+ 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)
+
+ self.history_buffer.apply_tag_by_name('highlight', match_start, match_end)
+ mark = self.history_buffer.create_mark('match', match_start, True)
+ GLib.idle_add(self.history_textview.tv.scroll_to_mark, mark, 0, True, 0.0, 0.5)
def on_log_history_checkbutton_toggled(self, widget):
# log conversation history?
=====================================
src/htmltextview.py
=====================================
--- a/src/htmltextview.py
+++ b/src/htmltextview.py
@@ -850,7 +850,7 @@ class HtmlTextView(Gtk.TextView):
self.connect('copy-clipboard', self.on_html_text_view_copy_clipboard)
self.id_ = self.connect('button-release-event',
self.on_left_mouse_button_release)
- self.get_buffer().create_tag('eol')
+ self.get_buffer().eol_tag = self.get_buffer().create_tag('eol')
self.tooltip = tooltips.BaseTooltip()
self.config = gajim.config
self.interface = gajim.interface
View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/8157cb38eca26ed48aa1a157c148eb115…
Yann Leboulanger pushed to branch gajim_0.16 at gajim / gajim
Commits:
d2782622 by Yann Leboulanger at 2017-02-28T22:28:49+01:00
check for errors when adding a transport contact. Fixes #8196
- - - - -
1 changed file:
- src/dialogs.py
Changes:
=====================================
src/dialogs.py
=====================================
--- a/src/dialogs.py
+++ b/src/dialogs.py
@@ -1249,6 +1249,11 @@ class AddNewContactWindow:
def _nec_gateway_prompt_received(self, obj):
if self.adding_jid:
jid, transport, type_ = self.adding_jid
+ if obj.stanza.getError():
+ ErrorDialog(_('Error while adding transport contact'),
+ _('This error occured while adding a contact for transport '
+ '%s:\n\n%s') % (transport, obj.stanza.getErrorMsg()))
+ return
if obj.prompt_jid:
self._add_jid(obj.prompt_jid, type_)
else:
View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/d2782622952a3cc45dbc87d0e948507316…
Philipp Hörist pushed to branch master at gajim / gajim
Commits:
8a1a326b by Philipp Hörist at 2017-02-25T19:21:21+01:00
Add extension point in plugins window
- - - - -
1 changed file:
- src/plugins/gui.py
Changes:
=====================================
src/plugins/gui.py
=====================================
--- a/src/plugins/gui.py
+++ b/src/plugins/gui.py
@@ -114,10 +114,8 @@ class PluginsWindow(object):
self.plugins_notebook.set_current_page(0)
self.xml.get_object('close_button').grab_focus()
- for plugin in gajim.plugin_manager.active_plugins:
- if type(plugin).__name__ == 'PluginInstaller':
- plugin.on_activate(self)
- break
+ # Adding GUI extension point for Plugins that want to hook the Plugin Window
+ gajim.plugin_manager.gui_extension_point('plugin_window', self)
self.window.show_all()
gtkgui_helpers.possibly_move_window_in_current_desktop(self.window)
View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/8a1a326bae3f04d6824f4915f4ba85b3f5…