mirror of
https://github.com/onionshare/onionshare.git
synced 2025-02-04 17:05:31 -05:00
Allow file uploads to finish, and improve uploads styling
This commit is contained in:
parent
ee9c0d0abb
commit
7a571764ef
@ -54,8 +54,9 @@ class Web(object):
|
||||
REQUEST_CLOSE_SERVER = 6
|
||||
REQUEST_UPLOAD_NEW_FILE_STARTED = 7
|
||||
REQUEST_UPLOAD_FILE_RENAMED = 8
|
||||
REQUEST_ERROR_DOWNLOADS_DIR_CANNOT_CREATE = 9
|
||||
REQUEST_ERROR_DOWNLOADS_DIR_NOT_WRITABLE = 10
|
||||
REQUEST_UPLOAD_FINISHED = 9
|
||||
REQUEST_ERROR_DOWNLOADS_DIR_CANNOT_CREATE = 10
|
||||
REQUEST_ERROR_DOWNLOADS_DIR_NOT_WRITABLE = 11
|
||||
|
||||
def __init__(self, common, gui_mode, receive_mode=False):
|
||||
self.common = common
|
||||
@ -748,6 +749,11 @@ class ReceiveModeRequest(Request):
|
||||
"""
|
||||
super(ReceiveModeRequest, self).close()
|
||||
if self.upload_request:
|
||||
# Inform the GUI that the upload has finished
|
||||
self.web.add_request(Web.REQUEST_UPLOAD_FINISHED, self.path, {
|
||||
'id': self.upload_id
|
||||
})
|
||||
|
||||
if len(self.progress) > 0:
|
||||
print('')
|
||||
|
||||
|
@ -335,3 +335,9 @@ class Mode(QtWidgets.QWidget):
|
||||
Handle REQUEST_UPLOAD_FILE_RENAMED event.
|
||||
"""
|
||||
pass
|
||||
|
||||
def handle_request_upload_finished(self, event):
|
||||
"""
|
||||
Handle REQUEST_UPLOAD_FINISHED event.
|
||||
"""
|
||||
pass
|
||||
|
@ -393,6 +393,9 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
elif event["type"] == Web.REQUEST_UPLOAD_FILE_RENAMED:
|
||||
mode.handle_request_upload_file_renamed(event)
|
||||
|
||||
elif event["type"] == Web.REQUEST_UPLOAD_FINISHED:
|
||||
mode.handle_request_upload_finished(event)
|
||||
|
||||
if event["type"] == Web.REQUEST_ERROR_DOWNLOADS_DIR_CANNOT_CREATE:
|
||||
Alert(self.common, strings._('error_cannot_create_downloads_dir').format(self.common.settings.get('downloads_dir')))
|
||||
|
||||
|
@ -168,6 +168,12 @@ class ReceiveMode(Mode):
|
||||
"""
|
||||
pass
|
||||
|
||||
def handle_request_upload_finished(self, event):
|
||||
"""
|
||||
Handle REQUEST_UPLOAD_FINISHED event.
|
||||
"""
|
||||
self.uploads.finished(event["data"]["id"])
|
||||
|
||||
def reset_info_counters(self):
|
||||
"""
|
||||
Set the info counters back to zero.
|
||||
|
@ -111,28 +111,22 @@ class Upload(QtWidgets.QWidget):
|
||||
for filename in progress:
|
||||
total_uploaded_bytes += progress[filename]['uploaded_bytes']
|
||||
|
||||
if total_uploaded_bytes == self.content_length:
|
||||
# Hide the progress bar, show the folder button
|
||||
self.progress_bar.hide()
|
||||
self.folder_button.show()
|
||||
# Update the progress bar
|
||||
self.progress_bar.setMaximum(self.content_length)
|
||||
self.progress_bar.setValue(total_uploaded_bytes)
|
||||
|
||||
elapsed = datetime.now() - self.started
|
||||
if elapsed.seconds < 10:
|
||||
pb_fmt = strings._('gui_download_upload_progress_starting').format(
|
||||
self.common.human_readable_filesize(total_uploaded_bytes))
|
||||
else:
|
||||
# Update the progress bar
|
||||
self.progress_bar.setMaximum(self.content_length)
|
||||
self.progress_bar.setValue(total_uploaded_bytes)
|
||||
|
||||
elapsed = datetime.now() - self.started
|
||||
if elapsed.seconds < 10:
|
||||
pb_fmt = strings._('gui_download_upload_progress_starting').format(
|
||||
self.common.human_readable_filesize(total_uploaded_bytes))
|
||||
else:
|
||||
estimated_time_remaining = self.common.estimated_time_remaining(
|
||||
total_uploaded_bytes,
|
||||
self.content_length,
|
||||
started.timestamp())
|
||||
pb_fmt = strings._('gui_download_upload_progress_eta').format(
|
||||
self.common.human_readable_filesize(total_uploaded_bytes),
|
||||
estimated_time_remaining)
|
||||
estimated_time_remaining = self.common.estimated_time_remaining(
|
||||
total_uploaded_bytes,
|
||||
self.content_length,
|
||||
self.started.timestamp())
|
||||
pb_fmt = strings._('gui_download_upload_progress_eta').format(
|
||||
self.common.human_readable_filesize(total_uploaded_bytes),
|
||||
estimated_time_remaining)
|
||||
|
||||
for filename in progress:
|
||||
# Add a new file if needed
|
||||
@ -143,6 +137,29 @@ class Upload(QtWidgets.QWidget):
|
||||
# Update the file
|
||||
self.files[filename].update(progress[filename]['uploaded_bytes'], progress[filename]['complete'])
|
||||
|
||||
def finished(self):
|
||||
# Hide the progress bar
|
||||
self.progress_bar.hide()
|
||||
|
||||
# Change the label
|
||||
self.ended = self.started = datetime.now()
|
||||
if self.started.year == self.ended.year and self.started.month == self.ended.month and self.started.day == self.ended.day:
|
||||
if self.started.hour == self.ended.hour and self.started.minute == self.ended.minute:
|
||||
text = strings._('gui_upload_finished', True).format(
|
||||
self.started.strftime("%b %d, %I:%M%p")
|
||||
)
|
||||
else:
|
||||
text = strings._('gui_upload_finished_range', True).format(
|
||||
self.started.strftime("%b %d, %I:%M%p"),
|
||||
self.ended.strftime("%I:%M%p")
|
||||
)
|
||||
else:
|
||||
text = strings._('gui_upload_finished_range', True).format(
|
||||
self.started.strftime("%b %d, %I:%M%p"),
|
||||
self.ended.strftime("%b %d, %I:%M%p")
|
||||
)
|
||||
self.label.setText(text)
|
||||
|
||||
|
||||
class Uploads(QtWidgets.QScrollArea):
|
||||
"""
|
||||
@ -198,10 +215,16 @@ class Uploads(QtWidgets.QScrollArea):
|
||||
|
||||
def update(self, upload_id, progress):
|
||||
"""
|
||||
Update the progress of an upload progress bar.
|
||||
Update the progress of an upload.
|
||||
"""
|
||||
self.uploads[upload_id].update(progress)
|
||||
self.adjustSize()
|
||||
#self.adjustSize()
|
||||
|
||||
def finished(self, upload_id):
|
||||
"""
|
||||
An upload has finished.
|
||||
"""
|
||||
self.uploads[upload_id].finished()
|
||||
|
||||
def cancel(self, upload_id):
|
||||
"""
|
||||
|
@ -192,5 +192,6 @@
|
||||
"gui_uploads_window_tooltip": "Show/hide uploads",
|
||||
"gui_no_uploads": "No uploads yet.",
|
||||
"gui_upload_in_progress": "Upload Started {}",
|
||||
"gui_upload_finished": "Uploaded {} to {}"
|
||||
"gui_upload_finished_range": "Uploaded {} to {}",
|
||||
"gui_upload_finished": "Uploaded {}"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user