1818"""
1919import logging
2020import arrow
21- from gettext import gettext as _
2221import html
2322import sys
23+
24+ from gettext import gettext as _
2425from typing import List
2526from uuid import uuid4
26-
27- from PyQt5 .QtCore import Qt , pyqtSlot , pyqtSignal , QTimer , QSize
27+ from PyQt5 .QtCore import Qt , pyqtSlot , pyqtSignal , QTimer , QSize , pyqtBoundSignal , QObject
2828from PyQt5 .QtGui import QIcon , QPalette , QBrush , QColor , QFont , QLinearGradient
2929from PyQt5 .QtWidgets import QListWidget , QLabel , QWidget , QListWidgetItem , QHBoxLayout , \
3030 QPushButton , QVBoxLayout , QLineEdit , QScrollArea , QDialog , QAction , QMenu , QMessageBox , \
@@ -587,7 +587,7 @@ class MainView(QWidget):
587587 }
588588 '''
589589
590- def __init__ (self , parent ):
590+ def __init__ (self , parent : QObject ):
591591 super ().__init__ (parent )
592592
593593 self .setStyleSheet (self .CSS )
@@ -1274,58 +1274,52 @@ class FileWidget(QWidget):
12741274 Represents a file.
12751275 """
12761276
1277- def __init__ (self , source_db_object , submission_db_object ,
1278- controller , file_ready_signal , align = "left" ):
1277+ def __init__ (
1278+ self ,
1279+ file_uuid : str ,
1280+ controller : Controller ,
1281+ file_ready_signal : pyqtBoundSignal ,
1282+ ) -> None :
12791283 """
1280- Given some text, an indication of alignment ('left' or 'right') and
1281- a reference to the controller, make something to display a file.
1282-
1283- Align is set to left by default because currently SecureDrop can only
1284- accept files from sources to journalists.
1284+ Given some text and a reference to the controller, make something to display a file.
12851285 """
12861286 super ().__init__ ()
12871287 self .controller = controller
1288- self .source = source_db_object
1289- self .submission = submission_db_object
1290- self .file_uuid = self .submission .uuid
1291- self .align = align
1288+ self .file = self .controller .get_file (file_uuid )
12921289
12931290 self .layout = QHBoxLayout ()
12941291 self .update ()
12951292 self .setLayout (self .layout )
12961293
1297- file_ready_signal .connect (self ._on_file_download )
1294+ file_ready_signal .connect (self ._on_file_downloaded , type = Qt . QueuedConnection )
12981295
1299- def update (self ):
1296+ def update (self ) -> None :
13001297 icon = QLabel ()
13011298 icon .setPixmap (load_image ('file.png' ))
13021299
1303- if self .submission .is_downloaded :
1300+ if self .file .is_downloaded :
13041301 description = QLabel ("Open" )
13051302 else :
1306- human_filesize = humanize_filesize (self .submission .size )
1303+ human_filesize = humanize_filesize (self .file .size )
13071304 description = QLabel ("Download ({})" .format (human_filesize ))
13081305
1309- if self .align != "left" :
1310- # Float right...
1311- self .layout .addStretch (5 )
1312-
13131306 self .layout .addWidget (icon )
13141307 self .layout .addWidget (description , 5 )
1308+ self .layout .addStretch (5 )
13151309
1316- if self .align == "left" :
1317- # Add space on right hand side...
1318- self .layout .addStretch (5 )
1319-
1320- def clear (self ):
1310+ def clear (self ) -> None :
13211311 while self .layout .count ():
13221312 child = self .layout .takeAt (0 )
13231313 if child .widget ():
13241314 child .widget ().deleteLater ()
13251315
13261316 @pyqtSlot (str )
1327- def _on_file_download (self , file_uuid : str ) -> None :
1328- if file_uuid == self .file_uuid :
1317+ def _on_file_downloaded (self , file_uuid : str ) -> None :
1318+ if file_uuid == self .file .uuid :
1319+ # update state
1320+ self .file = self .controller .get_file (self .file .uuid )
1321+
1322+ # update gui
13291323 self .clear () # delete existing icon and label
13301324 self .update () # draw modified widget
13311325
@@ -1334,12 +1328,15 @@ def mouseReleaseEvent(self, e):
13341328 Handle a completed click via the program logic. The download state
13351329 of the file distinguishes which function in the logic layer to call.
13361330 """
1337- if self .submission .is_downloaded :
1331+ # update state
1332+ self .file = self .controller .get_file (self .file .uuid )
1333+
1334+ if self .file .is_downloaded :
13381335 # Open the already downloaded file.
1339- self .controller .on_file_open (self .submission )
1336+ self .controller .on_file_open (self .file . uuid )
13401337 else :
13411338 # Download the file.
1342- self .controller .on_file_download ( self . source , self .submission )
1339+ self .controller .on_submission_download ( File , self .file . uuid )
13431340
13441341
13451342class ConversationView (QWidget ):
@@ -1351,7 +1348,11 @@ class ConversationView(QWidget):
13511348 https://github.com/freedomofpress/securedrop-client/issues/273
13521349 """
13531350
1354- def __init__ (self , source_db_object : Source , controller : Controller ):
1351+ def __init__ (
1352+ self ,
1353+ source_db_object : Source ,
1354+ controller : Controller ,
1355+ ):
13551356 super ().__init__ ()
13561357 self .source = source_db_object
13571358 self .controller = controller
@@ -1403,8 +1404,12 @@ def add_file(self, source_db_object, submission_db_object):
14031404 Add a file from the source.
14041405 """
14051406 self .conversation_layout .addWidget (
1406- FileWidget (source_db_object , submission_db_object ,
1407- self .controller , self .controller .file_ready ))
1407+ FileWidget (
1408+ submission_db_object .uuid ,
1409+ self .controller ,
1410+ self .controller .file_ready ,
1411+ ),
1412+ )
14081413
14091414 def update_conversation_position (self , min_val , max_val ):
14101415 """
@@ -1472,9 +1477,12 @@ class SourceConversationWrapper(QWidget):
14721477 per-source resources.
14731478 """
14741479
1475- def __init__ (self , source : Source , controller : Controller ) -> None :
1480+ def __init__ (
1481+ self ,
1482+ source : Source ,
1483+ controller : Controller ,
1484+ ) -> None :
14761485 super ().__init__ ()
1477-
14781486 layout = QVBoxLayout ()
14791487 layout .setContentsMargins (0 , 0 , 0 , 0 )
14801488 self .setLayout (layout )
0 commit comments