Allow file uploads to finish, and improve uploads styling

This commit is contained in:
Micah Lee 2018-05-19 22:58:55 -07:00
parent 28fe7a4cf5
commit d8d1dc800d
6 changed files with 70 additions and 25 deletions

View file

@ -54,8 +54,9 @@ class Web(object):
REQUEST_CLOSE_SERVER = 6 REQUEST_CLOSE_SERVER = 6
REQUEST_UPLOAD_NEW_FILE_STARTED = 7 REQUEST_UPLOAD_NEW_FILE_STARTED = 7
REQUEST_UPLOAD_FILE_RENAMED = 8 REQUEST_UPLOAD_FILE_RENAMED = 8
REQUEST_ERROR_DOWNLOADS_DIR_CANNOT_CREATE = 9 REQUEST_UPLOAD_FINISHED = 9
REQUEST_ERROR_DOWNLOADS_DIR_NOT_WRITABLE = 10 REQUEST_ERROR_DOWNLOADS_DIR_CANNOT_CREATE = 10
REQUEST_ERROR_DOWNLOADS_DIR_NOT_WRITABLE = 11
def __init__(self, common, gui_mode, receive_mode=False): def __init__(self, common, gui_mode, receive_mode=False):
self.common = common self.common = common
@ -748,6 +749,11 @@ class ReceiveModeRequest(Request):
""" """
super(ReceiveModeRequest, self).close() super(ReceiveModeRequest, self).close()
if self.upload_request: 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: if len(self.progress) > 0:
print('') print('')

View file

@ -335,3 +335,9 @@ class Mode(QtWidgets.QWidget):
Handle REQUEST_UPLOAD_FILE_RENAMED event. Handle REQUEST_UPLOAD_FILE_RENAMED event.
""" """
pass pass
def handle_request_upload_finished(self, event):
"""
Handle REQUEST_UPLOAD_FINISHED event.
"""
pass

View file

@ -393,6 +393,9 @@ class OnionShareGui(QtWidgets.QMainWindow):
elif event["type"] == Web.REQUEST_UPLOAD_FILE_RENAMED: elif event["type"] == Web.REQUEST_UPLOAD_FILE_RENAMED:
mode.handle_request_upload_file_renamed(event) 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: 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'))) Alert(self.common, strings._('error_cannot_create_downloads_dir').format(self.common.settings.get('downloads_dir')))

View file

@ -168,6 +168,12 @@ class ReceiveMode(Mode):
""" """
pass pass
def handle_request_upload_finished(self, event):
"""
Handle REQUEST_UPLOAD_FINISHED event.
"""
self.uploads.finished(event["data"]["id"])
def reset_info_counters(self): def reset_info_counters(self):
""" """
Set the info counters back to zero. Set the info counters back to zero.

View file

@ -111,12 +111,6 @@ class Upload(QtWidgets.QWidget):
for filename in progress: for filename in progress:
total_uploaded_bytes += progress[filename]['uploaded_bytes'] 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()
else:
# Update the progress bar # Update the progress bar
self.progress_bar.setMaximum(self.content_length) self.progress_bar.setMaximum(self.content_length)
self.progress_bar.setValue(total_uploaded_bytes) self.progress_bar.setValue(total_uploaded_bytes)
@ -129,7 +123,7 @@ class Upload(QtWidgets.QWidget):
estimated_time_remaining = self.common.estimated_time_remaining( estimated_time_remaining = self.common.estimated_time_remaining(
total_uploaded_bytes, total_uploaded_bytes,
self.content_length, self.content_length,
started.timestamp()) self.started.timestamp())
pb_fmt = strings._('gui_download_upload_progress_eta').format( pb_fmt = strings._('gui_download_upload_progress_eta').format(
self.common.human_readable_filesize(total_uploaded_bytes), self.common.human_readable_filesize(total_uploaded_bytes),
estimated_time_remaining) estimated_time_remaining)
@ -143,6 +137,29 @@ class Upload(QtWidgets.QWidget):
# Update the file # Update the file
self.files[filename].update(progress[filename]['uploaded_bytes'], progress[filename]['complete']) 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): class Uploads(QtWidgets.QScrollArea):
""" """
@ -198,10 +215,16 @@ class Uploads(QtWidgets.QScrollArea):
def update(self, upload_id, progress): 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.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): def cancel(self, upload_id):
""" """

View file

@ -192,5 +192,6 @@
"gui_uploads_window_tooltip": "Show/hide uploads", "gui_uploads_window_tooltip": "Show/hide uploads",
"gui_no_uploads": "No uploads yet.", "gui_no_uploads": "No uploads yet.",
"gui_upload_in_progress": "Upload Started {}", "gui_upload_in_progress": "Upload Started {}",
"gui_upload_finished": "Uploaded {} to {}" "gui_upload_finished_range": "Uploaded {} to {}",
"gui_upload_finished": "Uploaded {}"
} }