From ed1893ee9b4b957e4422289649e7764c94cc78f1 Mon Sep 17 00:00:00 2001 From: Dimitur Kirov Date: Tue, 9 Aug 2005 17:27:27 +0000 Subject: [PATCH] moved convert bytes to common/helpers --- src/common/helpers.py | 39 +++++++++++++++++++++++++++++++++++++++ src/dialogs.py | 13 ++++++------- src/gtkgui_helpers.py | 39 +-------------------------------------- 3 files changed, 46 insertions(+), 45 deletions(-) diff --git a/src/common/helpers.py b/src/common/helpers.py index 9d57fff37..8381906fd 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -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''' diff --git a/src/dialogs.py b/src/dialogs.py index 468ba8523..c3c33136a 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -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' + _('Size: ') + '' - text += gtkgui_helpers.convert_bytes(file_props['size']) + text += helpers.convert_bytes(file_props['size']) text += '\n' + _('Transfered: ') + '' 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' + _('Status: ') + '' 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' diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index d299045da..f0a8ab326 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -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