Skip to content

Commit

Permalink
make applicationmodal and add cancel/continue
Browse files Browse the repository at this point in the history
  • Loading branch information
Allie Crevier committed Dec 16, 2019
1 parent 7e3cfca commit 6bdba14
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 60 deletions.
106 changes: 68 additions & 38 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1874,10 +1874,8 @@ def _on_export_clicked(self):
self.controller.sync_api()
return

dialog = ExportDialog(self.controller, self.file.uuid,
self.file.original_filename)
dialog = ExportDialog(self.controller, self.file.uuid, self.file.original_filename)
dialog.show()
dialog.export()
dialog.exec()

@pyqtSlot()
Expand All @@ -1889,9 +1887,8 @@ def _on_print_clicked(self):
self.controller.sync_api()
return

dialog = PrintDialog(self.controller, self.file.uuid)
dialog = PrintDialog(self.controller, self.file.uuid, self.file.original_filename)
dialog.show()
dialog.print()
dialog.exec()

def _on_left_click(self):
Expand Down Expand Up @@ -1929,23 +1926,38 @@ class PrintDialog(QDialog):
}
'''

def __init__(self, controller, file_uuid):
def __init__(self, controller: Controller, file_uuid: str, file_name: str):
super().__init__()

self.controller = controller
self.file_uuid = file_uuid
self.file_name = file_name

self.setObjectName('print_dialog')
self.setStyleSheet(self.CSS)
self.setWindowFlags(Qt.Popup)
self.setWindowModality(Qt.WindowModal)
self.setWindowFlags(Qt.FramelessWindowHint)
self.setWindowModality(Qt.ApplicationModal)

layout = QVBoxLayout(self)
self.setLayout(layout)

# Opening VM message
self.starting_message = SecureQLabel(_('Preparing print...'))
self.starting_message.setWordWrap(True)
# Starting print
self.starting = QWidget()
starting_layout = QVBoxLayout()
self.starting.setLayout(starting_layout)
starting_message = SecureQLabel(_('Preparing to print:\n' + self.file_name))
starting_message.setWordWrap(True)
starting_cancel_button = QPushButton(_('CANCEL'))
starting_continue_button = QPushButton(_('CONTINUE'))
starting_layout.addWidget(starting_message)
starting_buttons = QWidget()
starting_buttons_layout = QHBoxLayout()
starting_buttons_layout.addWidget(starting_cancel_button)
starting_buttons_layout.addWidget(starting_continue_button)
starting_buttons.setLayout(starting_buttons_layout)
starting_layout.addWidget(starting_buttons)
starting_cancel_button.clicked.connect(self._cancel)
starting_continue_button.clicked.connect(self._print)

# Widget to show error messages that occur during print
self.generic_error = QWidget()
Expand Down Expand Up @@ -1980,37 +1992,40 @@ def __init__(self, controller, file_uuid):
usb_form_layout.addWidget(buttons, alignment=Qt.AlignRight)

# Printing message
self.printing_message = SecureQLabel(_('Printing...'))
self.printing_message = SecureQLabel(_('Printing:\n' + self.file_name))
self.printing_message.setWordWrap(True)

layout.addWidget(self.starting_message)
layout.addWidget(self.starting)
layout.addWidget(self.printing_message)
layout.addWidget(self.generic_error)
layout.addWidget(self.insert_usb_form)

self.starting_message.show()
self.starting.show()
self.printing_message.hide()
self.generic_error.hide()
self.insert_usb_form.hide()

cancel_button.clicked.connect(self.close)
cancel_button.clicked.connect(self._cancel)
retry_button.clicked.connect(self._on_retry_button_clicked)

self.controller.export.print_call_failure.connect(
self._on_print_failure, type=Qt.QueuedConnection)
self.controller.export.print_call_success.connect(
self._on_print_success, type=Qt.QueuedConnection)

def print(self):
self.starting_message.hide()
def _cancel(self):
self.close()

def _print(self):
self.starting.hide()
self.printing_message.show()
self.generic_error.hide()
self.insert_usb_form.hide()
self.controller.print_file(self.file_uuid)

@pyqtSlot()
def _on_retry_button_clicked(self):
self.print()
self._print()

@pyqtSlot()
def _on_print_success(self):
Expand All @@ -2026,13 +2041,13 @@ def _update(self, status):
self._request_to_insert_usb_device()
else:
self.error_status_code.setText(_(status))
self.starting_message.hide()
self.starting.hide()
self.printing_message.hide()
self.generic_error.show()
self.insert_usb_form.hide()

def _request_to_insert_usb_device(self):
self.starting_message.hide()
self.starting.hide()
self.printing_message.hide()
self.generic_error.hide()
self.insert_usb_form.show()
Expand Down Expand Up @@ -2075,7 +2090,7 @@ class ExportDialog(QDialog):
}
'''

def __init__(self, controller, file_uuid, file_name):
def __init__(self, controller: Controller, file_uuid: str, file_name: str):
super().__init__()

self.controller = controller
Expand All @@ -2084,16 +2099,29 @@ def __init__(self, controller, file_uuid, file_name):

self.setObjectName('export_dialog')
self.setStyleSheet(self.CSS)
self.setWindowFlags(Qt.Popup)
self.setWindowModality(Qt.WindowModal)
self.setWindowFlags(Qt.FramelessWindowHint)
self.setWindowModality(Qt.ApplicationModal)

layout = QVBoxLayout(self)
self.setLayout(layout)

# Starting export message
self.starting_export_message = SecureQLabel(_(
'Preparing to export:\n' + self.file_name))
self.starting_export_message.setWordWrap(True)
# Starting export
self.starting = QWidget()
starting_layout = QVBoxLayout()
self.starting.setLayout(starting_layout)
starting_message = SecureQLabel(_('Preparing to export:\n' + self.file_name))
starting_message.setWordWrap(True)
starting_cancel_button = QPushButton(_('CANCEL'))
starting_continue_button = QPushButton(_('CONTINUE'))
starting_layout.addWidget(starting_message)
starting_buttons = QWidget()
starting_buttons_layout = QHBoxLayout()
starting_buttons_layout.addWidget(starting_cancel_button)
starting_buttons_layout.addWidget(starting_continue_button)
starting_buttons.setLayout(starting_buttons_layout)
starting_layout.addWidget(starting_buttons)
starting_cancel_button.clicked.connect(self._cancel)
starting_continue_button.clicked.connect(self._export)

# Widget to show error messages that occur during an export
self.generic_error = QWidget()
Expand Down Expand Up @@ -2159,24 +2187,23 @@ def __init__(self, controller, file_uuid, file_name):
self.passphrase_error_message.hide()

# Starting export message
self.exporting_message = SecureQLabel(_(
'File export in progress:\n' + self.file_name))
self.exporting_message = SecureQLabel(_('File export in progress:\n' + self.file_name))
self.exporting_message.setWordWrap(True)

layout.addWidget(self.starting_export_message)
layout.addWidget(self.starting)
layout.addWidget(self.exporting_message)
layout.addWidget(self.generic_error)
layout.addWidget(self.insert_usb_form)
layout.addWidget(self.passphrase_form)

self.starting_export_message.show()
self.starting.show()
self.exporting_message.hide()
self.generic_error.hide()
self.insert_usb_form.hide()
self.passphrase_form.hide()

usb_cancel_button.clicked.connect(self.close)
passphrase_cancel_button.clicked.connect(self.close)
usb_cancel_button.clicked.connect(self._cancel)
passphrase_cancel_button.clicked.connect(self._cancel)
retry_export_button.clicked.connect(self._on_retry_export_button_clicked)
unlock_disk_button.clicked.connect(self._on_unlock_disk_clicked)

Expand All @@ -2189,12 +2216,15 @@ def __init__(self, controller, file_uuid, file_name):
self.controller.export.export_usb_call_success.connect(
self._on_export_success, type=Qt.QueuedConnection)

def export(self):
def _cancel(self):
self.close()

def _export(self):
self.controller.run_export_preflight_checks()

@pyqtSlot()
def _on_retry_export_button_clicked(self):
self.starting_export_message.hide()
self.starting.hide()
self.controller.run_export_preflight_checks()

@pyqtSlot()
Expand All @@ -2209,7 +2239,7 @@ def _on_export_success(self):
self.close()

def _request_to_insert_usb_device(self, encryption_not_supported: bool = False):
self.starting_export_message.hide()
self.starting.hide()
self.passphrase_form.hide()
self.insert_usb_form.show()

Expand All @@ -2221,7 +2251,7 @@ def _request_to_insert_usb_device(self, encryption_not_supported: bool = False):
@pyqtSlot()
def _request_passphrase(self, bad_passphrase: bool = False):
logger.debug('requesting passphrase... ')
self.starting_export_message.hide()
self.starting.hide()
self.exporting_message.hide()
self.insert_usb_form.hide()
self.passphrase_form.show()
Expand All @@ -2244,7 +2274,7 @@ def _update(self, status):
else:
self.error_status_code.setText(_(status))
self.generic_error.show()
self.starting_export_message.hide()
self.starting.hide()
self.passphrase_form.hide()
self.insert_usb_form.hide()

Expand Down
2 changes: 2 additions & 0 deletions securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ def run_export_preflight_checks(self):
logger.info('Running export preflight checks')

if not self.qubes:
self.export.export_usb_call_success.emit()
return

self.export.begin_preflight_check.emit()
Expand Down Expand Up @@ -704,6 +705,7 @@ def print_file(self, file_uuid: str) -> None:
return

if not self.qubes:
self.export.print_call_success.emit()
return

path_to_file_with_original_name = self.get_path_to_file_with_original_name(
Expand Down
Loading

0 comments on commit 6bdba14

Please sign in to comment.