moved convert bytes to common/helpers

This commit is contained in:
Dimitur Kirov 2005-08-09 17:27:27 +00:00
parent 9c2b9e4b58
commit ed1893ee9b
3 changed files with 46 additions and 45 deletions

View File

@ -20,9 +20,48 @@
import sre
import os
import gajim
from common import i18n
_ = i18n._
def convert_bytes(string):
suffix = ''
# IEC standard says KiB = 1024 bytes KB = 1000 bytes
use_kib_mib = gajim.config.get('use_kib_mib')
align = 1024.
bytes = float(string)
if bytes >= align:
bytes = round(bytes/align, 1)
if bytes >= align:
bytes = round(bytes/align, 1)
if bytes >= align:
bytes = round(bytes/align, 1)
if use_kib_mib:
#GiB means gibibyte
suffix = _('%s GiB')
else:
#GB means gigabyte
suffix = _('%s GB')
else:
if use_kib_mib:
#MiB means mibibyte
suffix = _('%s MiB')
else:
#MB means megabyte
suffix = _('%s MB')
else:
if use_kib_mib:
#KiB means kibibyte
suffix = _('%s KiB')
else:
#KB means kilo bytes
suffix = _('%s KB')
else:
#B means bytes
suffix = _('%s B')
return suffix % str(bytes)
def get_uf_show(show):
'''returns a userfriendly string for dnd/xa/chat
and makes all strings translatable'''

View File

@ -754,15 +754,14 @@ class FileTransfersTooltip(BaseTooltip):
receiver = receiver.split('/')[0]
name = gajim.get_first_contact_instance_from_jid(
file_props['tt_account'], receiver).name
text += gtkgui_helpers.escape_for_pango_markup(receiver)
text += gtkgui_helpers.escape_for_pango_markup(name)
text += '\n<b>' + _('Size: ') + '</b>'
text += gtkgui_helpers.convert_bytes(file_props['size'])
text += helpers.convert_bytes(file_props['size'])
text += '\n<b>' + _('Transfered: ') + '</b>'
transfered_len = 0
if file_props.has_key('received-len'):
transfered_len = file_props['received-len']
text += gtkgui_helpers.convert_bytes(transfered_len)
text += helpers.convert_bytes(transfered_len)
text += '\n<b>' + _('Status: ') + '</b>'
status = ''
if not file_props.has_key('started') or not file_props['started']:
@ -1605,7 +1604,7 @@ class FileTransfersWindow:
sectext = '\t' + _('Filename: %s') % \
gtkgui_helpers.escape_for_pango_markup(file_props['name'])
sectext += '\n\t' + _('Size: %s') % \
gtkgui_helpers.convert_bytes(file_props['size'])
helpers.convert_bytes(file_props['size'])
sectext += '\n\t' +_('Sender: %s') % \
gtkgui_helpers.escape_for_pango_markup(jid)
InformationDialog(_('File transfer completed'), sectext).get_response()
@ -1667,7 +1666,7 @@ _('Connection with peer cannot be established.')).get_response()
gtkgui_helpers.escape_for_pango_markup(file_props['name'])
if file_props.has_key('size'):
sec_text += '\n\t' + _('Size: %s') % \
gtkgui_helpers.convert_bytes(file_props['size'])
helpers.convert_bytes(file_props['size'])
if file_props.has_key('mime-type'):
sec_text += '\n\t' + _('Type: %s') % \
gtkgui_helpers.escape_for_pango_markup(file_props['mime-type'])
@ -1752,8 +1751,8 @@ _('Connection with peer cannot be established.')).get_response()
if transfered_size == 0:
text += '0'
else:
text += gtkgui_helpers.convert_bytes(transfered_size)
text += '/' + gtkgui_helpers.convert_bytes(full_size)
text += helpers.convert_bytes(transfered_size)
text += '/' + helpers.convert_bytes(full_size)
self.model.set(iter, 3, text)
if file_props['type'] == 'r':
status = 'download'

View File

@ -55,44 +55,7 @@ def reduce_chars_newlines(text, max_chars = 0, max_lines = 0,
if reduced_text != text and widget is not None:
pass # FIXME show tooltip
return reduced_text
def convert_bytes(string):
suffix = ''
# IEC standard says KiB = 1024 bytes KB = 1000 bytes
use_kib_mib = gajim.config.get('use_kib_mib')
align = 1024.
bytes = float(string)
if bytes >= align:
bytes = round(bytes/align, 1)
if bytes >= align:
bytes = round(bytes/align, 1)
if bytes >= align:
bytes = round(bytes/align, 1)
if use_kib_mib:
#GiB means gibibyte
suffix = _('%s GiB')
else:
#GB means gigabyte
suffix = _('%s GB')
else:
if use_kib_mib:
#MiB means mibibyte
suffix = _('%s MiB')
else:
#MB means megabyte
suffix = _('%s MB')
else:
if use_kib_mib:
#KiB means kibibyte
suffix = _('%s KiB')
else:
#KB means kilo bytes
suffix = _('%s KB')
else:
#B means bytes
suffix = _('%s B')
return suffix % str(bytes)
def escape_for_pango_markup(string):
# escapes < > & \ "
# for pango markup not to break