moved convert bytes to common/helpers
This commit is contained in:
parent
9c2b9e4b58
commit
ed1893ee9b
|
@ -20,9 +20,48 @@
|
||||||
import sre
|
import sre
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import gajim
|
||||||
from common import i18n
|
from common import i18n
|
||||||
|
|
||||||
_ = 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):
|
def get_uf_show(show):
|
||||||
'''returns a userfriendly string for dnd/xa/chat
|
'''returns a userfriendly string for dnd/xa/chat
|
||||||
and makes all strings translatable'''
|
and makes all strings translatable'''
|
||||||
|
|
|
@ -754,15 +754,14 @@ class FileTransfersTooltip(BaseTooltip):
|
||||||
receiver = receiver.split('/')[0]
|
receiver = receiver.split('/')[0]
|
||||||
name = gajim.get_first_contact_instance_from_jid(
|
name = gajim.get_first_contact_instance_from_jid(
|
||||||
file_props['tt_account'], receiver).name
|
file_props['tt_account'], receiver).name
|
||||||
text += gtkgui_helpers.escape_for_pango_markup(receiver)
|
|
||||||
text += gtkgui_helpers.escape_for_pango_markup(name)
|
text += gtkgui_helpers.escape_for_pango_markup(name)
|
||||||
text += '\n<b>' + _('Size: ') + '</b>'
|
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>'
|
text += '\n<b>' + _('Transfered: ') + '</b>'
|
||||||
transfered_len = 0
|
transfered_len = 0
|
||||||
if file_props.has_key('received-len'):
|
if file_props.has_key('received-len'):
|
||||||
transfered_len = file_props['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>'
|
text += '\n<b>' + _('Status: ') + '</b>'
|
||||||
status = ''
|
status = ''
|
||||||
if not file_props.has_key('started') or not file_props['started']:
|
if not file_props.has_key('started') or not file_props['started']:
|
||||||
|
@ -1605,7 +1604,7 @@ class FileTransfersWindow:
|
||||||
sectext = '\t' + _('Filename: %s') % \
|
sectext = '\t' + _('Filename: %s') % \
|
||||||
gtkgui_helpers.escape_for_pango_markup(file_props['name'])
|
gtkgui_helpers.escape_for_pango_markup(file_props['name'])
|
||||||
sectext += '\n\t' + _('Size: %s') % \
|
sectext += '\n\t' + _('Size: %s') % \
|
||||||
gtkgui_helpers.convert_bytes(file_props['size'])
|
helpers.convert_bytes(file_props['size'])
|
||||||
sectext += '\n\t' +_('Sender: %s') % \
|
sectext += '\n\t' +_('Sender: %s') % \
|
||||||
gtkgui_helpers.escape_for_pango_markup(jid)
|
gtkgui_helpers.escape_for_pango_markup(jid)
|
||||||
InformationDialog(_('File transfer completed'), sectext).get_response()
|
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'])
|
gtkgui_helpers.escape_for_pango_markup(file_props['name'])
|
||||||
if file_props.has_key('size'):
|
if file_props.has_key('size'):
|
||||||
sec_text += '\n\t' + _('Size: %s') % \
|
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'):
|
if file_props.has_key('mime-type'):
|
||||||
sec_text += '\n\t' + _('Type: %s') % \
|
sec_text += '\n\t' + _('Type: %s') % \
|
||||||
gtkgui_helpers.escape_for_pango_markup(file_props['mime-type'])
|
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:
|
if transfered_size == 0:
|
||||||
text += '0'
|
text += '0'
|
||||||
else:
|
else:
|
||||||
text += gtkgui_helpers.convert_bytes(transfered_size)
|
text += helpers.convert_bytes(transfered_size)
|
||||||
text += '/' + gtkgui_helpers.convert_bytes(full_size)
|
text += '/' + helpers.convert_bytes(full_size)
|
||||||
self.model.set(iter, 3, text)
|
self.model.set(iter, 3, text)
|
||||||
if file_props['type'] == 'r':
|
if file_props['type'] == 'r':
|
||||||
status = 'download'
|
status = 'download'
|
||||||
|
|
|
@ -55,44 +55,7 @@ def reduce_chars_newlines(text, max_chars = 0, max_lines = 0,
|
||||||
if reduced_text != text and widget is not None:
|
if reduced_text != text and widget is not None:
|
||||||
pass # FIXME show tooltip
|
pass # FIXME show tooltip
|
||||||
return reduced_text
|
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):
|
def escape_for_pango_markup(string):
|
||||||
# escapes < > & \ "
|
# escapes < > & \ "
|
||||||
# for pango markup not to break
|
# for pango markup not to break
|
||||||
|
|
Loading…
Reference in New Issue