Commit 5e20799d authored by Daniel Brötzmann's avatar Daniel Brötzmann Committed by Philipp Hörist

Remove usage of convert_bytes

parent 5ba5bc17
......@@ -1468,11 +1468,17 @@ class ChatControl(ChatControlBase):
"""
Show an InfoBar on top of control
"""
if app.config.get('use_kib_mib'):
units = GLib.FormatSizeFlags.IEC_UNITS
else:
units = GLib.FormatSizeFlags.DEFAULT
markup = '<b>%s</b>\n%s' % (_('File Transfer'), file_props.name)
if file_props.desc:
markup += '\n(%s)' % file_props.desc
markup += '\n%s: %s' % (_('Size'), helpers.convert_bytes(
file_props.size))
markup += '\n%s: %s' % (
_('Size'),
GLib.format_size_full(file_props.size, units))
b1 = Gtk.Button.new_with_mnemonic(_('_Accept'))
b1.connect('clicked', self._on_accept_file_request, file_props)
b2 = Gtk.Button.new_with_mnemonic(_('_Decline'))
......
......@@ -70,8 +70,8 @@ class FileTransfersWindow:
def __init__(self):
self.files_props = {'r': {}, 's': {}}
self.height_diff = 0
self._ui = get_builder('filetransfers.ui')
self._ui = get_builder('filetransfers.ui')
self.window = self._ui.file_transfers_window
show_notification = app.config.get('notify_on_file_complete')
self._ui.notify_ft_complete.set_active(show_notification)
......@@ -142,6 +142,11 @@ class FileTransfersWindow:
'hash_error': 'network-error-symbolic',
}
if app.config.get('use_kib_mib'):
self.units = GLib.FormatSizeFlags.IEC_UNITS
else:
self.units = GLib.FormatSizeFlags.DEFAULT
self._ui.transfers_list.get_selection().set_mode(
Gtk.SelectionMode.SINGLE)
self._ui.transfers_list.get_selection().connect(
......@@ -221,8 +226,8 @@ class FileTransfersWindow:
else:
file_name = file_props.name
sectext = _('File name: %s') % GLib.markup_escape_text(file_name)
sectext += '\n' + _('Size: %s') % helpers.convert_bytes(
file_props.size)
sectext += '\n' + _('Size: %s') % GLib.format_size_full(
file_props.size, self.units)
if file_props.type_ == 'r':
jid = file_props.sender.split('/')[0]
sender_name = app.contacts.get_first_contact_from_jid(
......@@ -456,8 +461,8 @@ class FileTransfersWindow:
sectext = _('File: %s') % GLib.markup_escape_text(
file_props.name)
if file_props.size:
sectext += '\n' + _('Size: %s') % helpers.convert_bytes(
file_props.size)
sectext += '\n' + _('Size: %s') % GLib.format_size_full(
file_props.size, self.units)
if file_props.mime_type:
sectext += '\n' + _('Type: %s') % file_props.mime_type
if file_props.desc:
......@@ -493,19 +498,19 @@ class FileTransfersWindow:
elif status == 'ok':
file_props.completed = True
text = self._format_percent(100)
received_size = int(file_props.received_len)
full_size = file_props.size
text += helpers.convert_bytes(received_size) + '/' + \
helpers.convert_bytes(full_size)
received_size = GLib.format_size_full(
int(file_props.received_len), self.units)
full_size = GLib.format_size_full(file_props.size, self.units)
text += received_size + '/' + full_size
self.model.set(iter_, Column.PROGRESS, text)
self.model.set(iter_, Column.PULSE, GLib.MAXINT32)
elif status == 'computing':
self.model.set(iter_, Column.PULSE, 1)
text = _('Checking file…') + '\n'
received_size = int(file_props.received_len)
full_size = file_props.size
text += helpers.convert_bytes(received_size) + '/' + \
helpers.convert_bytes(full_size)
received_size = GLib.format_size_full(
int(file_props.received_len), self.units)
full_size = GLib.format_size_full(file_props.size, self.units)
text += received_size + '/' + full_size
self.model.set(iter_, Column.PROGRESS, text)
def pulse():
......@@ -517,10 +522,10 @@ class FileTransfersWindow:
GLib.timeout_add(100, pulse)
elif status == 'hash_error':
text = _('File error') + '\n'
received_size = int(file_props.received_len)
full_size = file_props.size
text += helpers.convert_bytes(received_size) + '/' + \
helpers.convert_bytes(full_size)
received_size = GLib.format_size_full(
int(file_props.received_len), self.units)
full_size = GLib.format_size_full(file_props.size, self.units)
text += received_size + '/' + full_size
self.model.set(iter_, Column.PROGRESS, text)
self.model.set(iter_, Column.PULSE, GLib.MAXINT32)
self.model.set(iter_, Column.IMAGE, self.icons[status])
......@@ -626,8 +631,8 @@ class FileTransfersWindow:
if transfered_size == 0:
text += '0'
else:
text += helpers.convert_bytes(transfered_size)
text += '/' + helpers.convert_bytes(full_size)
text += GLib.format_size_full(transfered_size, self.units)
text += '/' + GLib.format_size_full(full_size, self.units)
# Kb/s
# remaining time
......@@ -647,11 +652,11 @@ class FileTransfersWindow:
self.model.set(iter_, Column.PERCENT, int(percent))
text = self._format_time(eta)
text += '\n'
# This should make the string Kb/s,
# where 'Kb' part is taken from %s.
# This should make the string KB/s,
# where 'KB' part is taken from %s.
# Only the 's' after / (which means second) should be translated.
text += _('(%(filesize_unit)s/s)') % {
'filesize_unit': helpers.convert_bytes(speed)}
'filesize_unit': GLib.format_size_full(speed, self.units)}
self.model.set(iter_, Column.TIME, text)
# try to guess what should be the status image
......
......@@ -535,6 +535,10 @@ class FileTransfersTooltip():
def __init__(self):
self.sid = None
self.widget = None
if app.config.get('use_kib_mib'):
self.units = GLib.FormatSizeFlags.IEC_UNITS
else:
self.units = GLib.FormatSizeFlags.DEFAULT
def clear_tooltip(self):
self.sid = None
......@@ -583,7 +587,7 @@ class FileTransfersTooltip():
if not transfered_len:
transfered_len = 0
properties.append((Q_('?transfer status:Transferred: '),
helpers.convert_bytes(transfered_len)))
GLib.format_size_full(transfered_len, self.units)))
status = self._get_current_status(file_props)
properties.append((Q_('?transfer status:Status: '), status))
file_desc = file_props.desc or ''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment