HTTPUpload: Display filename and transfer speed

Fixes #9661
This commit is contained in:
Daniel Brötzmann 2019-04-14 20:39:44 +02:00 committed by Philipp Hörist
parent 3312ca6c29
commit b32b0f4411
2 changed files with 50 additions and 31 deletions

View File

@ -2,13 +2,14 @@
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkBox" id="box">
<object class="GtkGrid" id="grid">
<property name="width_request">300</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">18</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<property name="row_spacing">6</property>
<property name="column_spacing">12</property>
<property name="column_homogeneous">True</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
@ -17,40 +18,32 @@
<property name="icon_size">6</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label">
<object class="GtkLabel" id="file_name_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">6</property>
<property name="label">&lt;placeholder&gt;</property>
<style>
<class name="bold"/>
</style>
<property name="label">&lt;file name&gt;</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="progress_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">&lt;progress&gt;</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
@ -61,9 +54,8 @@
<property name="pulse_step">0.10000000149</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
@ -80,9 +72,23 @@
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">6</property>
<property name="label">&lt;placeholder&gt;</property>
<style>
<class name="bold"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>

View File

@ -32,6 +32,7 @@ from typing import Tuple # pylint: disable=unused-import
import os
import uuid
import logging
import time
from gi.repository import Gtk
from gi.repository import Gdk
@ -1588,8 +1589,11 @@ class ProgressWindow(Gtk.ApplicationWindow):
self.event = file.event
self.file = file
self._ui = get_builder('httpupload_progress_dialog.ui')
file_name = os.path.basename(file.path)
self._ui.file_name_label.set_text(file_name)
self._start_time = time.time()
self.add(self._ui.box)
self.add(self._ui.grid)
self.pulse = GLib.timeout_add(100, self._pulse_progressbar)
self.show_all()
@ -1602,12 +1606,13 @@ class ProgressWindow(Gtk.ApplicationWindow):
def _on_httpupload_progress(self, obj):
if self.file != obj.file:
return
if obj.status == 'request':
self._ui.label.set_text(_('Requesting HTTP Upload Slot…'))
self._ui.label.set_text(_('Requesting HTTP File Upload Slot…'))
elif obj.status == 'close':
self.destroy()
elif obj.status == 'upload':
self._ui.label.set_text(_('Uploading file via HTTP File Upload…'))
self._ui.label.set_text(_('Uploading via HTTP File Upload…'))
elif obj.status == 'update':
self.update_progress(obj.seen, obj.total)
elif obj.status == 'encrypt':
@ -1633,9 +1638,17 @@ class ProgressWindow(Gtk.ApplicationWindow):
if self.pulse:
GLib.source_remove(self.pulse)
self.pulse = None
self._ui.progressbar.set_fraction(float(seen) / total)
size_total = round(total / (1024 * 1024), 1)
size_progress = round(seen / (1024 * 1024), 1)
time_now = time.time()
mbytes_sec = round(size_progress / (time_now - self._start_time), 1)
self._ui.progressbar.set_fraction(float(seen) / total)
self._ui.progress_label.set_text(
_('%(progress)s of %(total)s MiB sent') % \
{'progress': str(size_progress), 'total': str(size_total)})
_('%(progress)s of %(total)s MiB sent (%(speed)s MiB/s)') % \
{'progress': str(size_progress),
'total': str(size_total),
'speed': str(mbytes_sec)})