Rename uploaded files

This commit is contained in:
Micah Lee 2018-05-20 14:12:53 -07:00
parent 451e07269f
commit b20ba6fc86
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
2 changed files with 15 additions and 2 deletions

View File

@ -160,7 +160,7 @@ class ReceiveMode(Mode):
"""
Handle REQUEST_UPLOAD_FILE_RENAMED event.
"""
pass
self.uploads.rename(event["data"]["id"], event["data"]["old_filename"], event["data"]["new_filename"])
def handle_request_upload_finished(self, event):
"""

View File

@ -63,6 +63,10 @@ class File(QtWidgets.QWidget):
if complete:
self.folder_button.show()
def rename(self, new_filename):
self.filename = new_filename
self.filename_label.setText(self.filename)
class Upload(QtWidgets.QWidget):
def __init__(self, common, upload_id, content_length):
@ -138,6 +142,10 @@ class Upload(QtWidgets.QWidget):
# Update the file
self.files[filename].update(progress[filename]['uploaded_bytes'], progress[filename]['complete'])
def rename(self, old_filename, new_filename):
self.files[old_filename].rename(new_filename)
self.files[new_filename] = self.files.pop(old_filename)
def finished(self):
# Hide the progress bar
self.progress_bar.hide()
@ -219,7 +227,12 @@ class Uploads(QtWidgets.QScrollArea):
Update the progress of an upload.
"""
self.uploads[upload_id].update(progress)
#self.adjustSize()
def rename(self, upload_id, old_filename, new_filename):
"""
Rename a file, which happens if the filename already exists in downloads_dir.
"""
self.uploads[upload_id].rename(old_filename, new_filename)
def finished(self, upload_id):
"""