Skip to content

Commit

Permalink
Merge pull request #666 from freedomofpress/applicationmodal
Browse files Browse the repository at this point in the history
Implement correct export/print stages and dialog behavior
  • Loading branch information
redshiftzero authored Feb 24, 2020
2 parents 1b1e15d + 640b3d9 commit 8adf1f2
Show file tree
Hide file tree
Showing 12 changed files with 1,315 additions and 553 deletions.
42 changes: 38 additions & 4 deletions securedrop_client/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ class Export(QObject):
'device': 'usb-test'
}

PRINTER_PREFLIGHT_FN = 'printer-preflight.sd-export'
PRINTER_PREFLIGHT_METADATA = {
'device': 'printer-preflight'
}

DISK_TEST_FN = 'disk-test.sd-export'
DISK_TEST_METADATA = {
'device': 'disk-test'
Expand All @@ -74,23 +79,28 @@ class Export(QObject):
DISK_EXPORT_DIR = 'export_data'

# Set up signals for communication with the GUI thread
begin_preflight_check = pyqtSignal()
preflight_check_call_failure = pyqtSignal(object)
preflight_check_call_success = pyqtSignal(str)
preflight_check_call_success = pyqtSignal()
begin_usb_export = pyqtSignal(list, str)
begin_preflight_check = pyqtSignal()
export_usb_call_failure = pyqtSignal(object)
export_usb_call_success = pyqtSignal()
export_completed = pyqtSignal(list)

begin_printer_preflight = pyqtSignal()
printer_preflight_success = pyqtSignal()
printer_preflight_failure = pyqtSignal(object)
begin_print = pyqtSignal(list)
print_call_failure = pyqtSignal(object)
print_call_success = pyqtSignal()
export_completed = pyqtSignal(list)

def __init__(self) -> None:
super().__init__()

self.begin_preflight_check.connect(self.run_preflight_checks, type=Qt.QueuedConnection)
self.begin_usb_export.connect(self.send_file_to_usb_device, type=Qt.QueuedConnection)
self.begin_print.connect(self.print, type=Qt.QueuedConnection)
self.begin_printer_preflight.connect(self.run_printer_preflight, type=Qt.QueuedConnection)

def _export_archive(cls, archive_path: str) -> str:
'''
Expand Down Expand Up @@ -183,6 +193,17 @@ def _add_file_to_archive(cls, archive: tarfile.TarFile, filepath: str) -> None:
arcname = os.path.join(cls.DISK_EXPORT_DIR, filename)
archive.add(filepath, arcname=arcname, recursive=False)

def _run_printer_preflight(self, archive_dir: str) -> None:
'''
Make sure printer is ready.
'''
archive_path = self._create_archive(
archive_dir, self.PRINTER_PREFLIGHT_FN, self.PRINTER_PREFLIGHT_METADATA)

status = self._export_archive(archive_path)
if status:
raise ExportError(status)

def _run_usb_test(self, archive_dir: str) -> None:
'''
Run usb-test.
Expand Down Expand Up @@ -258,11 +279,24 @@ def run_preflight_checks(self) -> None:
self._run_usb_test(temp_dir)
self._run_disk_test(temp_dir)
logger.debug('completed preflight checks: success')
self.preflight_check_call_success.emit('success')
self.preflight_check_call_success.emit()
except ExportError as e:
logger.debug('completed preflight checks: failure')
self.preflight_check_call_failure.emit(e)

@pyqtSlot()
def run_printer_preflight(self) -> None:
'''
Make sure the Export VM is started.
'''
with TemporaryDirectory() as temp_dir:
try:
self._run_printer_preflight(temp_dir)
self.printer_preflight_success.emit()
except ExportError as e:
logger.error(e)
self.printer_preflight_failure.emit(e)

@pyqtSlot(list, str)
def send_file_to_usb_device(self, filepaths: List[str], passphrase: str) -> None:
'''
Expand Down
8 changes: 8 additions & 0 deletions securedrop_client/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ def __init__(self, filename: str, svg_size: str = None) -> None:
self.svg.setFixedSize(svg_size) if svg_size else self.svg.setFixedSize(QSize())
layout.addWidget(self.svg)

def update_image(self, filename: str, svg_size: str = None) -> None:
self.svg = load_svg(filename)
self.svg.setFixedSize(svg_size) if svg_size else self.svg.setFixedSize(QSize())
child = self.layout().takeAt(0)
if child and child.widget():
child.widget().deleteLater()
self.layout().addWidget(self.svg)


class SecureQLabel(QLabel):
def __init__(
Expand Down
Loading

0 comments on commit 8adf1f2

Please sign in to comment.