Skip to content

Commit

Permalink
WIP!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
heartsucker committed May 21, 2019
1 parent 9ac20f3 commit 6c28cbf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
26 changes: 10 additions & 16 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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":
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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,
),
Expand Down
2 changes: 1 addition & 1 deletion securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 6c28cbf

Please sign in to comment.