diff --git a/securedrop_client/gui/widgets.py b/securedrop_client/gui/widgets.py index a3151d1059..6bd0ab201c 100644 --- a/securedrop_client/gui/widgets.py +++ b/securedrop_client/gui/widgets.py @@ -1283,8 +1283,7 @@ class FileWidget(QWidget): def __init__( self, session: Session, - source_db_object: Source, - submission_db_object: File, + file_uuid: str, controller: Controller, file_ready_signal: pyqtBoundSignal, align="left", @@ -1299,29 +1298,25 @@ def __init__( super().__init__() self.session = session self.controller = controller - self.source = source_db_object - self.submission = submission_db_object - self.file_uuid = self.submission.uuid + self.file_uuid = file_uuid self.align = align self.layout = QHBoxLayout() self.update() self.setLayout(self.layout) - file_ready_signal.connect(self._on_file_download) + file_ready_signal.connect(self._on_file_download, type=Qt.QueuedConnection) def update(self): icon = QLabel() icon.setPixmap(load_image('file.png')) - # we need to refresh the SQLAlchemy object because it may have been updated in another - # thread - self.submission = self.session.query(File).get(self.submission.id) + file_ = self.session.query(File).filter_by(uuid=self.file_uuid).one() - if self.submission.is_downloaded: + if file_.is_downloaded: description = QLabel("Open") else: - human_filesize = humanize_filesize(self.submission.size) + human_filesize = humanize_filesize(file_.size) description = QLabel("Download ({})".format(human_filesize)) if self.align != "left": @@ -1352,12 +1347,12 @@ def mouseReleaseEvent(self, e): Handle a completed click via the program logic. The download state of the file distinguishes which function in the logic layer to call. """ - if self.submission.is_downloaded: + if self.file_is_downloaded: # Open the already downloaded file. - self.controller.on_file_open(self.submission) + self.controller.on_file_open(self.submission_uuid) else: # Download the file. - self.controller.on_submission_download(self.source, self.submission) + self.controller.on_submission_download(self.submission_uuid) class ConversationView(QWidget): @@ -1429,8 +1424,7 @@ def add_file(self, source_db_object, submission_db_object): self.conversation_layout.addWidget( FileWidget( self.session, - source_db_object, - submission_db_object, + submission_db_object.uuid, self.controller, self.controller.file_ready, ), diff --git a/securedrop_client/logic.py b/securedrop_client/logic.py index af6bb7d2e5..ce9bf6c453 100644 --- a/securedrop_client/logic.py +++ b/securedrop_client/logic.py @@ -566,7 +566,7 @@ def on_file_download_success(self, result: Any): """ Called when a file has downloaded. """ - print(result) + print(type(result), result) self.file_ready.emit(result) def on_file_download_failure(self, exception: Exception):