Prompt on exit: abort conversion?

Foot-shooting prevention by prompting the user if they are sure
they want to quit Dangerzone with ongoing conversions in progress.
This commit is contained in:
deeplow 2022-10-17 10:11:05 +01:00
parent 3c1e8a232d
commit 45a865aae3
No known key found for this signature in database
GPG key ID: 577982871529A52A
3 changed files with 22 additions and 5 deletions

View file

@ -107,16 +107,16 @@ class DangerzoneGui(DangerzoneCore):
class Alert(QtWidgets.QDialog): class Alert(QtWidgets.QDialog):
def __init__( def __init__(
self, self,
gui_common: DangerzoneGui, dangerzone: DangerzoneGui,
message: str, message: str,
ok_text: str = "Ok", ok_text: str = "Ok",
extra_button_text: str = None, extra_button_text: str = None,
) -> None: ) -> None:
super(Alert, self).__init__() super(Alert, self).__init__()
self.gui_common = gui_common self.dangerzone = dangerzone
self.setWindowTitle("dangerzone") self.setWindowTitle("dangerzone")
self.setWindowIcon(self.gui_common.get_window_icon()) self.setWindowIcon(self.dangerzone.get_window_icon())
self.setModal(True) self.setModal(True)
flags = ( flags = (

View file

@ -14,7 +14,7 @@ from .. import container
from ..container import convert from ..container import convert
from ..document import SAFE_EXTENSION, Document from ..document import SAFE_EXTENSION, Document
from ..util import get_resource_path, get_subprocess_startupinfo from ..util import get_resource_path, get_subprocess_startupinfo
from .logic import DangerzoneGui from .logic import Alert, DangerzoneGui
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -78,6 +78,20 @@ class MainWindow(QtWidgets.QMainWindow):
self.content_widget.show() self.content_widget.show()
def closeEvent(self, e: QtGui.QCloseEvent) -> None: def closeEvent(self, e: QtGui.QCloseEvent) -> None:
alert_widget = Alert(
self.dangerzone,
message="Some documents are still being converted.\n Are you sure you want to quit?",
ok_text="Abort conversions",
)
converting_docs = self.dangerzone.get_converting_documents()
if not converting_docs:
e.accept()
else:
accept_exit = alert_widget.exec_()
if not accept_exit:
e.ignore()
return
else:
e.accept() e.accept()
if platform.system() != "Darwin": if platform.system() != "Darwin":

View file

@ -69,3 +69,6 @@ class DangerzoneCore(object):
def get_failed_documents(self) -> List[Document]: def get_failed_documents(self) -> List[Document]:
return [doc for doc in self.documents if doc.is_failed()] return [doc for doc in self.documents if doc.is_failed()]
def get_converting_documents(self) -> List[Document]:
return [doc for doc in self.documents if doc.is_converting()]