Communicate the receive mode dir to the GUI, so clicking the open folder button opens the file manager to the correct directory

This commit is contained in:
Micah Lee 2018-10-25 21:38:20 -07:00
parent 6233487ecd
commit 65b4afeba3
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
7 changed files with 52 additions and 4 deletions

View File

@ -125,6 +125,13 @@ class ReceiveModeWeb(object):
'new_filename': basename
})
# Tell the GUI the receive mode directory for this file
self.web.add_request(self.web.REQUEST_UPLOAD_SET_DIR, request.path, {
'id': request.upload_id,
'filename': basename,
'dir': receive_mode_dir
})
self.common.log('ReceiveModeWeb', 'define_routes', '/upload, uploaded {}, saving to {}'.format(f.filename, local_path))
print(strings._('receive_mode_received_file').format(local_path))
f.save(local_path)

View File

@ -37,8 +37,9 @@ class Web(object):
REQUEST_RATE_LIMIT = 5
REQUEST_CLOSE_SERVER = 6
REQUEST_UPLOAD_FILE_RENAMED = 7
REQUEST_UPLOAD_FINISHED = 8
REQUEST_ERROR_DOWNLOADS_DIR_CANNOT_CREATE = 9
REQUEST_UPLOAD_SET_DIR = 8
REQUEST_UPLOAD_FINISHED = 9
REQUEST_ERROR_DOWNLOADS_DIR_CANNOT_CREATE = 10
def __init__(self, common, is_gui, mode='share'):
self.common = common

View File

@ -324,6 +324,12 @@ class Mode(QtWidgets.QWidget):
"""
pass
def handle_request_upload_set_dir(self, event):
"""
Handle REQUEST_UPLOAD_SET_DIR event.
"""
pass
def handle_request_upload_finished(self, event):
"""
Handle REQUEST_UPLOAD_FINISHED event.

View File

@ -118,6 +118,7 @@ class UploadHistoryItemFile(QtWidgets.QWidget):
self.common.log('UploadHistoryItemFile', '__init__', 'filename: {}'.format(filename))
self.filename = filename
self.dir = None
self.started = datetime.now()
# Filename label
@ -158,13 +159,20 @@ class UploadHistoryItemFile(QtWidgets.QWidget):
self.filename = new_filename
self.filename_label.setText(self.filename)
def set_dir(self, dir):
self.dir = dir
def open_folder(self):
"""
Open the downloads folder, with the file selected, in a cross-platform manner
"""
self.common.log('UploadHistoryItemFile', 'open_folder')
abs_filename = os.path.join(self.common.settings.get('downloads_dir'), self.filename)
if not self.dir:
self.common.log('UploadHistoryItemFile', 'open_folder', "dir has not been set yet, can't open folder")
return
abs_filename = os.path.join(self.dir, self.filename)
# Linux
if self.common.platform == 'Linux' or self.common.platform == 'BSD':
@ -266,6 +274,9 @@ class UploadHistoryItem(HistoryItem):
self.files[data['old_filename']].rename(data['new_filename'])
self.files[data['new_filename']] = self.files.pop(data['old_filename'])
elif data['action'] == 'set_dir':
self.files[data['filename']].set_dir(data['dir'])
elif data['action'] == 'finished':
# Hide the progress bar
self.progress_bar.hide()

View File

@ -168,6 +168,16 @@ class ReceiveMode(Mode):
'new_filename': event["data"]["new_filename"]
})
def handle_request_upload_set_dir(self, event):
"""
Handle REQUEST_UPLOAD_SET_DIR event.
"""
self.history.update(event["data"]["id"], {
'action': 'set_dir',
'filename': event["data"]["filename"],
'dir': event["data"]["dir"]
})
def handle_request_upload_finished(self, event):
"""
Handle REQUEST_UPLOAD_FINISHED event.

View File

@ -390,6 +390,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_SET_DIR:
mode.handle_request_upload_set_dir(event)
elif event["type"] == Web.REQUEST_UPLOAD_FINISHED:
mode.handle_request_upload_finished(event)

View File

@ -35,6 +35,7 @@ class File(QtWidgets.QWidget):
self.common.log('File', '__init__', 'filename: {}'.format(filename))
self.filename = filename
self.dir = None
self.started = datetime.now()
# Filename label
@ -71,6 +72,9 @@ class File(QtWidgets.QWidget):
if complete:
self.folder_button.show()
def set_dir(self, dir):
self.dir = dir
def rename(self, new_filename):
self.filename = new_filename
self.filename_label.setText(self.filename)
@ -81,7 +85,10 @@ class File(QtWidgets.QWidget):
"""
self.common.log('File', 'open_folder')
abs_filename = os.path.join(self.common.settings.get('downloads_dir'), self.filename)
if not self.dir:
return
abs_filename = os.path.join(self.dir, self.filename)
# Linux
if self.common.platform == 'Linux' or self.common.platform == 'BSD':
@ -182,6 +189,9 @@ class Upload(QtWidgets.QWidget):
self.files[old_filename].rename(new_filename)
self.files[new_filename] = self.files.pop(old_filename)
def set_dir(self, filename, dir):
self.files[filename].set_dir(dir)
def finished(self):
# Hide the progress bar
self.progress_bar.hide()