mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Create an Upload class within Uploads, and add methods to Uploads to add, update, cancel, and reset
This commit is contained in:
parent
4d5f1a34cd
commit
996f6c0725
@ -22,6 +22,72 @@ from PyQt5 import QtCore, QtWidgets, QtGui
|
||||
from onionshare import strings
|
||||
|
||||
|
||||
class Upload(object):
|
||||
def __init__(self, common, upload_id, total_bytes):
|
||||
self.common = common
|
||||
|
||||
self.upload_id = upload_id
|
||||
self.started = time.time()
|
||||
self.total_bytes = total_bytes
|
||||
self.uploaded_bytes = 0
|
||||
|
||||
# Uploads have two modes, in progress and finished. In progess, they display
|
||||
# the progress bar. When finished, they display info about the files that
|
||||
# were uploaded.
|
||||
|
||||
# Progress bar
|
||||
self.progress_bar = QtWidgets.QProgressBar()
|
||||
self.progress_bar.setTextVisible(True)
|
||||
self.progress_bar.setAttribute(QtCore.Qt.WA_DeleteOnClose)
|
||||
self.progress_bar.setAlignment(QtCore.Qt.AlignHCenter)
|
||||
self.progress_bar.setMinimum(0)
|
||||
self.progress_bar.setMaximum(total_bytes)
|
||||
self.progress_bar.setValue(0)
|
||||
self.progress_bar.setStyleSheet(self.common.css['downloads_uploads_progress_bar'])
|
||||
self.progress_bar.total_bytes = total_bytes
|
||||
|
||||
# Finished
|
||||
self.finished = QtWidgets.QGroupBox()
|
||||
self.finished.hide()
|
||||
|
||||
# Start at 0
|
||||
self.update(0)
|
||||
|
||||
def update(self, uploaded_bytes):
|
||||
self.uploaded_bytes = uploaded_bytes
|
||||
|
||||
self.progress_bar.setValue(uploaded_bytes)
|
||||
if uploaded_bytes == self.progress_bar.uploaded_bytes:
|
||||
# Upload is finished, hide the progress bar and show the finished widget
|
||||
self.progress_bar.hide()
|
||||
|
||||
# TODO: add file information to the finished widget
|
||||
ended = time.time()
|
||||
elapsed = ended - self.started
|
||||
self.finished.show()
|
||||
|
||||
else:
|
||||
elapsed = time.time() - self.started
|
||||
if elapsed < 10:
|
||||
pb_fmt = strings._('gui_download_upload_progress_starting').format(
|
||||
self.common.human_readable_filesize(downloaded_bytes))
|
||||
else:
|
||||
pb_fmt = strings._('gui_download_upload_progress_eta').format(
|
||||
self.common.human_readable_filesize(downloaded_bytes),
|
||||
self.estimated_time_remaining)
|
||||
|
||||
self.progress_bar.setFormat(pb_fmt)
|
||||
|
||||
def cancel(self):
|
||||
self.progress_bar.setFormat(strings._('gui_canceled'))
|
||||
|
||||
@property
|
||||
def estimated_time_remaining(self):
|
||||
return self.common.estimated_time_remaining(self.uploaded_bytes,
|
||||
self.total_bytes,
|
||||
self.started)
|
||||
|
||||
|
||||
class Uploads(QtWidgets.QScrollArea):
|
||||
"""
|
||||
The uploads chunk of the GUI. This lists all of the active upload
|
||||
@ -57,8 +123,41 @@ class Uploads(QtWidgets.QScrollArea):
|
||||
widget.setLayout(layout)
|
||||
self.setWidget(widget)
|
||||
|
||||
def add(self, upload_id, total_bytes):
|
||||
"""
|
||||
Add a new upload progress bar.
|
||||
"""
|
||||
# Hide the no_uploads_label
|
||||
self.no_uploads_label.hide()
|
||||
|
||||
# Add it to the list
|
||||
uploads = Upload(self.common, upload_id, total_bytes)
|
||||
self.uploads[upload_id] = download
|
||||
self.uploads_layout.addWidget(upload.progress_bar)
|
||||
|
||||
# Scroll to the bottom
|
||||
self.vbar.setValue(self.vbar.maximum())
|
||||
|
||||
def update(self, upload_id, uploaded_bytes):
|
||||
"""
|
||||
Update the progress of an upload progress bar.
|
||||
"""
|
||||
self.uploads[upload_id].update(uploaded_bytes)
|
||||
|
||||
def cancel(self, upload_id):
|
||||
"""
|
||||
Update an upload progress bar to show that it has been canceled.
|
||||
"""
|
||||
self.uploads[upload_id].cancel()
|
||||
|
||||
def reset(self):
|
||||
"""
|
||||
Reset the uploads back to zero
|
||||
"""
|
||||
pass
|
||||
for upload in self.uploads.values():
|
||||
self.uploads_layout.removeWidget(upload.progress_bar)
|
||||
upload.progress_bar.close()
|
||||
self.uploads = {}
|
||||
|
||||
self.no_uploads_label.show()
|
||||
self.resize(self.sizeHint())
|
||||
|
@ -22,6 +22,7 @@ from PyQt5 import QtCore, QtWidgets, QtGui
|
||||
|
||||
from onionshare import strings
|
||||
|
||||
|
||||
class Download(object):
|
||||
def __init__(self, common, download_id, total_bytes):
|
||||
self.common = common
|
||||
@ -31,7 +32,7 @@ class Download(object):
|
||||
self.total_bytes = total_bytes
|
||||
self.downloaded_bytes = 0
|
||||
|
||||
# make a new progress bar
|
||||
# Progress bar
|
||||
self.progress_bar = QtWidgets.QProgressBar()
|
||||
self.progress_bar.setTextVisible(True)
|
||||
self.progress_bar.setAttribute(QtCore.Qt.WA_DeleteOnClose)
|
||||
@ -42,7 +43,7 @@ class Download(object):
|
||||
self.progress_bar.setStyleSheet(self.common.css['downloads_uploads_progress_bar'])
|
||||
self.progress_bar.total_bytes = total_bytes
|
||||
|
||||
# start at 0
|
||||
# Start at 0
|
||||
self.update(0)
|
||||
|
||||
def update(self, downloaded_bytes):
|
||||
@ -50,7 +51,7 @@ class Download(object):
|
||||
|
||||
self.progress_bar.setValue(downloaded_bytes)
|
||||
if downloaded_bytes == self.progress_bar.total_bytes:
|
||||
pb_fmt = strings._('gui_download_progress_complete').format(
|
||||
pb_fmt = strings._('gui_download_upload_progress_complete').format(
|
||||
self.common.format_seconds(time.time() - self.started))
|
||||
else:
|
||||
elapsed = time.time() - self.started
|
||||
@ -58,10 +59,10 @@ class Download(object):
|
||||
# Wait a couple of seconds for the download rate to stabilize.
|
||||
# This prevents a "Windows copy dialog"-esque experience at
|
||||
# the beginning of the download.
|
||||
pb_fmt = strings._('gui_download_progress_starting').format(
|
||||
pb_fmt = strings._('gui_download_upload_progress_starting').format(
|
||||
self.common.human_readable_filesize(downloaded_bytes))
|
||||
else:
|
||||
pb_fmt = strings._('gui_download_progress_eta').format(
|
||||
pb_fmt = strings._('gui_download_upload_progress_eta').format(
|
||||
self.common.human_readable_filesize(downloaded_bytes),
|
||||
self.estimated_time_remaining)
|
||||
|
||||
|
@ -39,9 +39,9 @@
|
||||
"error_hs_dir_cannot_create": "Nejde vytvořit složka onion service {0:s}",
|
||||
"error_hs_dir_not_writable": "nejde zapisovat do složky onion service {0:s}",
|
||||
"using_ephemeral": "Starting ephemeral Tor onion service and awaiting publication",
|
||||
"gui_download_progress_complete": "%p%, Uplynulý čas: {0:s}",
|
||||
"gui_download_progress_starting": "{0:s}, %p% (Computing ETA)",
|
||||
"gui_download_progress_eta": "{0:s}, ETA: {1:s}, %p%",
|
||||
"gui_download_upload_progress_complete": "%p%, Uplynulý čas: {0:s}",
|
||||
"gui_download_upload_progress_starting": "{0:s}, %p% (Computing ETA)",
|
||||
"gui_download_upload_progress_eta": "{0:s}, ETA: {1:s}, %p%",
|
||||
"version_string": "Onionshare {0:s} | https://onionshare.org/",
|
||||
"gui_share_quit_warning": "Jste si jistí, že chcete odejít?\nURL, kterou sdílíte poté nebude existovat.",
|
||||
"gui_quit_warning_quit": "Zavřít",
|
||||
|
@ -52,9 +52,9 @@
|
||||
"error_hs_dir_cannot_create": "Kan ikke oprette onion-tjenestens mappe {0:s}",
|
||||
"error_hs_dir_not_writable": "onion-tjenestens mappe {0:s} er skrivebeskyttet",
|
||||
"using_ephemeral": "Starter kortvarig Tor onion-tjeneste og afventer udgivelse",
|
||||
"gui_download_progress_complete": "%p%, tid forløbet: {0:s}",
|
||||
"gui_download_progress_starting": "{0:s}, %p% (udregner anslået ankomsttid)",
|
||||
"gui_download_progress_eta": "{0:s}, anslået ankomsttid: {1:s}, %p%",
|
||||
"gui_download_upload_progress_complete": "%p%, tid forløbet: {0:s}",
|
||||
"gui_download_upload_progress_starting": "{0:s}, %p% (udregner anslået ankomsttid)",
|
||||
"gui_download_upload_progress_eta": "{0:s}, anslået ankomsttid: {1:s}, %p%",
|
||||
"version_string": "Onionshare {0:s} | https://onionshare.org/",
|
||||
"gui_share_quit_warning": "Er du sikker på, at du vil afslutte?\nURL'en som du deler vil ikke eksistere længere.",
|
||||
"gui_quit_warning_quit": "Afslut",
|
||||
|
@ -64,9 +64,9 @@
|
||||
"error_hs_dir_cannot_create": "Cannot create onion service dir {0:s}",
|
||||
"error_hs_dir_not_writable": "onion service dir {0:s} is not writable",
|
||||
"using_ephemeral": "Starting ephemeral Tor onion service and awaiting publication",
|
||||
"gui_download_progress_complete": "%p%, Time Elapsed: {0:s}",
|
||||
"gui_download_progress_starting": "{0:s}, %p% (Computing ETA)",
|
||||
"gui_download_progress_eta": "{0:s}, ETA: {1:s}, %p%",
|
||||
"gui_download_upload_progress_complete": "%p%, Time Elapsed: {0:s}",
|
||||
"gui_download_upload_progress_starting": "{0:s}, %p% (Computing ETA)",
|
||||
"gui_download_upload_progress_eta": "{0:s}, ETA: {1:s}, %p%",
|
||||
"version_string": "OnionShare {0:s} | https://onionshare.org/",
|
||||
"gui_quit_title": "Transfer in Progress",
|
||||
"gui_share_quit_warning": "You're in the process of sending files. Are you sure you want to quit OnionShare?",
|
||||
|
@ -39,9 +39,9 @@
|
||||
"error_hs_dir_cannot_create": "Ne eblas krei hidden-service-dosierujon {0:s}",
|
||||
"error_hs_dir_not_writable": "ne eblas konservi dosierojn en hidden-service-dosierujo {0:s}",
|
||||
"using_ephemeral": "Starting ephemeral Tor onion service and awaiting publication",
|
||||
"gui_download_progress_complete": "%p%, Tempo pasinta: {0:s}",
|
||||
"gui_download_progress_starting": "{0:s}, %p% (Computing ETA)",
|
||||
"gui_download_progress_eta": "{0:s}, ETA: {1:s}, %p%",
|
||||
"gui_download_upload_progress_complete": "%p%, Tempo pasinta: {0:s}",
|
||||
"gui_download_upload_progress_starting": "{0:s}, %p% (Computing ETA)",
|
||||
"gui_download_upload_progress_eta": "{0:s}, ETA: {1:s}, %p%",
|
||||
"version_string": "Onionshare {0:s} | https://onionshare.org/",
|
||||
"gui_share_quit_warning": "Ĉu vi certas ke vi volas foriri?\nLa URL, kiun vi kundividas ne plu ekzistos.",
|
||||
"gui_quit_warning_quit": "Foriri",
|
||||
|
@ -50,9 +50,9 @@
|
||||
"error_hs_dir_cannot_create": "Kan verborgen service map {0:s} niet aanmaken",
|
||||
"error_hs_dir_not_writable": "Verborgen service map {0:s} is niet schrijfbaar",
|
||||
"using_ephemeral": "Kortstondige Tor onion service gestart en in afwachting van publicatie",
|
||||
"gui_download_progress_complete": "%p%, Tijd verstreken: {0:s}",
|
||||
"gui_download_progress_starting": "{0:s}, %p% (ETA berekenen)",
|
||||
"gui_download_progress_eta": "{0:s}, ETA: {1:s}, %p%",
|
||||
"gui_download_upload_progress_complete": "%p%, Tijd verstreken: {0:s}",
|
||||
"gui_download_upload_progress_starting": "{0:s}, %p% (ETA berekenen)",
|
||||
"gui_download_upload_progress_eta": "{0:s}, ETA: {1:s}, %p%",
|
||||
"version_string": "Onionshare {0:s} | https://onionshare.org/",
|
||||
"gui_share_quit_warning": "Weet je zeker dat je wilt afsluiten?\nDe URL die je aan het delen bent zal niet meer bestaan.",
|
||||
"gui_quit_warning_quit": "Afsluiten",
|
||||
|
Loading…
Reference in New Issue
Block a user