Skip to content
Snippets Groups Projects
Commit 028bfbb6 authored by dkirov's avatar dkirov
Browse files

reduce chars and lines in helpers

parent 73a4bf97
No related branches found
No related tags found
No related merge requests found
......@@ -622,17 +622,12 @@ def get_status_info(self, resource, priority, show, status):
if status != '':
if gtk.gtk_version < (2, 6, 0) or gtk.pygtk_version < (2, 6, 0):
# FIXME: check and do the same if we have more than one \n
status = self.strip_text(status, 50)
status = gtkgui_helpers.reduce_chars_newlines(status, 50, 1)
else:
status = gtkgui_helpers.reduce_chars_newlines(status, 0, 1)
str_status += ' - ' + status
return gtkgui_helpers.escape_for_pango_markup(str_status)
# fix "too long status make the tooltip large than the screen" problem
def strip_text(self, text, max_length):
text = text.strip()
if len(text) > max_length:
text = text[:max_length - 3] + '...'
return text
def add_status_row(self, file_path, show, str_status):
''' appends a new row with status icon to the table '''
self.current_row += 1
......@@ -706,14 +701,17 @@ def populate(self, data):
iconset = 'sun'
file_path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16')
for acct in accounts:
mesage = gtkgui_helpers.escape_for_pango_markup(acct['message'])
mesage = self.strip_text(mesage, 50)
message = gtkgui_helpers.reduce_chars_newlines(acct['message'], 50, 1)
message = gtkgui_helpers.escape_for_pango_markup(message)
self.add_status_row(file_path, acct['show'], '<span weight="bold">' +
gtkgui_helpers.escape_for_pango_markup(acct['name']) + '</span>'
+ ' - ' + mesage)
+ ' - ' + message)
elif len(accounts) == 1:
text = _('Gajim - %s') % accounts[0]['status_line']
message = gtkgui_helpers.reduce_chars_newlines(accounts[0]['status_line'],
50, 1)
message = gtkgui_helpers.escape_for_pango_markup(message)
text = _('Gajim - %s') % message
else:
text = _('Gajim - %s') % helpers.get_uf_show('offline')
self.text_lable.set_markup(text)
......
......@@ -388,15 +388,9 @@ def set_subject(self, room_jid, subject):
full_subject = None
if gtk.gtk_version < (2, 6, 0) or gtk.pygtk_version < (2, 6, 0):
# long subject makes window bigger than the screen
def _cut_if_long(str):
if len(str) > 80:
str = str[:77] + '...'
return str
if len(subject) > 80:
subjects = map(lambda e: _cut_if_long(e), subject.split('\n'))
subject = reduce(lambda e, e1: e + '\n' + e1, subjects)
subject = gtkgui_helpers.reduce_chars_newlines(subject, 80, 2)
else:
subject = gtkgui_helpers.reduce_chars_newlines(subject, 0, 2)
subject = gtkgui_helpers.escape_for_pango_markup(subject)
name_label.set_markup(
'<span weight="heavy" size="x-large">%s</span>\n%s' % (room_jid, subject))
......
......@@ -28,7 +28,34 @@
_ = i18n._
from common import gajim
def reduce_chars_newlines(text, max_chars = 0, max_lines = 0,
widget = None):
''' Cut the chars after 'max_chars' on each line
and show only the first 'max_lines'. If there is more text
to be shown, display the whole text in tooltip on 'widget'
If any of the params is not present(None or 0) the action
on it is not performed
'''
def _cut_if_long(str):
if len(str) > max_chars:
str = str[:max_chars - 3] + '...'
return str
if max_lines == 0:
lines = text.split('\n')
else:
lines = text.split('\n', max_lines)[:max_lines]
if max_chars > 0:
if lines:
lines = map(lambda e: _cut_if_long(e), lines)
if lines:
reduced_text = reduce(lambda e, e1: e + '\n' + e1, lines)
else:
reduced_text = ''
if reduced_text != text and widget is not None:
pass # FIXME show tooltip
return reduced_text
def convert_bytes(string):
suffix = ''
bytes = int(string)
......
......@@ -133,16 +133,11 @@ def draw_name_banner(self, contact, chatstate = None):
#FIXME: when gtk2.4 is OOOOLD do it via glade2.10+
if gtk.pygtk_version >= (2, 6, 0) and gtk.gtk_version >= (2, 6, 0):
banner_name_label.set_ellipsize(pango.ELLIPSIZE_END)
status = gtkgui_helpers.reduce_chars_newlines(status, 0, 2)
#FIXME: remove me when gtk24 is OLD
elif status is not None and len(status) > 50:
def _cut_if_long(str):
if len(str) > 50:
str = str[:47] + '...'
return str
if len(status) > 50:
status = map(lambda e: _cut_if_long(e), status.split('\n'))
status = reduce(lambda e, e1: e + '\n' + e1, status)
elif status is not None:
status = gtkgui_helpers.reduce_chars_newlines(status, 50, 2)
status = gtkgui_helpers.escape_for_pango_markup(status)
#FIXME: uncomment me when we support sending messages to specific resource
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment