Allow adding more docs via 'open_with' while in settings

Handle the case where a user has already added some documents (either
through 'open with' or via Dangerzone 'select documents' button) and
then they want to add some more via the 'open_with' dialog.

It updates the settings to reflect the newly added documents and blocks
the user from adding them if a conversion is already in progress.
This commit is contained in:
deeplow 2022-11-29 09:39:29 +00:00
parent cb68ba7d1c
commit 65d0b7a0d0
No known key found for this signature in database
GPG key ID: 577982871529A52A
2 changed files with 32 additions and 14 deletions

View file

@ -114,6 +114,7 @@ class Alert(QtWidgets.QDialog):
dangerzone: DangerzoneGui, dangerzone: DangerzoneGui,
message: str, message: str,
ok_text: str = "Ok", ok_text: str = "Ok",
has_cancel: bool = True,
extra_button_text: str = None, extra_button_text: str = None,
) -> None: ) -> None:
super(Alert, self).__init__() super(Alert, self).__init__()
@ -151,15 +152,16 @@ class Alert(QtWidgets.QDialog):
if extra_button_text: if extra_button_text:
extra_button = QtWidgets.QPushButton(extra_button_text) extra_button = QtWidgets.QPushButton(extra_button_text)
extra_button.clicked.connect(self.clicked_extra) extra_button.clicked.connect(self.clicked_extra)
cancel_button = QtWidgets.QPushButton("Cancel")
cancel_button.clicked.connect(self.clicked_cancel)
buttons_layout = QtWidgets.QHBoxLayout() buttons_layout = QtWidgets.QHBoxLayout()
buttons_layout.addStretch() buttons_layout.addStretch()
buttons_layout.addWidget(ok_button) buttons_layout.addWidget(ok_button)
if extra_button_text: if extra_button_text:
buttons_layout.addWidget(extra_button) buttons_layout.addWidget(extra_button)
buttons_layout.addWidget(cancel_button) if has_cancel:
cancel_button = QtWidgets.QPushButton("Cancel")
cancel_button.clicked.connect(self.clicked_cancel)
buttons_layout.addWidget(cancel_button)
layout = QtWidgets.QVBoxLayout() layout = QtWidgets.QVBoxLayout()
layout.addLayout(message_layout) layout.addLayout(message_layout)

View file

@ -213,6 +213,7 @@ class ContentWidget(QtWidgets.QWidget):
def __init__(self, dangerzone: DangerzoneGui) -> None: def __init__(self, dangerzone: DangerzoneGui) -> None:
super(ContentWidget, self).__init__() super(ContentWidget, self).__init__()
self.dangerzone = dangerzone self.dangerzone = dangerzone
self.conversion_started = False
# Doc selection widget # Doc selection widget
self.doc_selection_widget = DocSelectionWidget() self.doc_selection_widget = DocSelectionWidget()
@ -238,14 +239,23 @@ class ContentWidget(QtWidgets.QWidget):
self.setLayout(layout) self.setLayout(layout)
def documents_selected(self, new_docs: List[Document]) -> None: def documents_selected(self, new_docs: List[Document]) -> None:
for doc in new_docs: if not self.conversion_started:
self.dangerzone.add_document(doc) for doc in new_docs:
self.dangerzone.add_document(doc)
self.doc_selection_widget.hide() self.doc_selection_widget.hide()
self.settings_widget.show() self.settings_widget.show()
self.documents_added.emit(new_docs) self.documents_added.emit(new_docs)
else:
Alert(
self.dangerzone,
message="Dangerzone does not support adding documents after the conversion has started.",
has_cancel=False,
).exec_()
def start_clicked(self) -> None: def start_clicked(self) -> None:
self.conversion_started = True
self.settings_widget.hide() self.settings_widget.hide()
self.documents_list.show() self.documents_list.show()
@ -513,18 +523,24 @@ class SettingsWidget(QtWidgets.QWidget):
save_path = os.path.dirname(first_doc.input_filename) save_path = os.path.dirname(first_doc.input_filename)
save_dir = os.path.basename(save_path) save_dir = os.path.basename(save_path)
self.save_location.setText(save_dir) self.save_location.setText(save_dir)
if len(new_docs) == 1: self.update_doc_n_labels()
self.start_button.setText("Convert to Safe Document")
self.docs_selected_label.setText(f"1 document selected")
else:
self.start_button.setText("Convert to Safe Documents")
self.docs_selected_label.setText(f"{len(new_docs)} documents selected")
self.update_ui() self.update_ui()
# validations # validations
self.check_writeable_archive_dir(new_docs) self.check_writeable_archive_dir(new_docs)
def update_doc_n_labels(self) -> None:
"""Updates labels dependent on the number of present documents"""
n_docs = len(self.dangerzone.get_unconverted_documents())
if n_docs == 1:
self.start_button.setText("Convert to Safe Document")
self.docs_selected_label.setText(f"1 document selected")
else:
self.start_button.setText("Convert to Safe Documents")
self.docs_selected_label.setText(f"{n_docs} documents selected")
def select_output_directory(self) -> None: def select_output_directory(self) -> None:
dialog = QtWidgets.QFileDialog() dialog = QtWidgets.QFileDialog()
dialog.setLabelText(QtWidgets.QFileDialog.Accept, "Select output directory") dialog.setLabelText(QtWidgets.QFileDialog.Accept, "Select output directory")