mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
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:
parent
3c1e8a232d
commit
45a865aae3
3 changed files with 22 additions and 5 deletions
|
@ -107,16 +107,16 @@ class DangerzoneGui(DangerzoneCore):
|
|||
class Alert(QtWidgets.QDialog):
|
||||
def __init__(
|
||||
self,
|
||||
gui_common: DangerzoneGui,
|
||||
dangerzone: DangerzoneGui,
|
||||
message: str,
|
||||
ok_text: str = "Ok",
|
||||
extra_button_text: str = None,
|
||||
) -> None:
|
||||
super(Alert, self).__init__()
|
||||
self.gui_common = gui_common
|
||||
self.dangerzone = dangerzone
|
||||
|
||||
self.setWindowTitle("dangerzone")
|
||||
self.setWindowIcon(self.gui_common.get_window_icon())
|
||||
self.setWindowIcon(self.dangerzone.get_window_icon())
|
||||
self.setModal(True)
|
||||
|
||||
flags = (
|
||||
|
|
|
@ -14,7 +14,7 @@ from .. import container
|
|||
from ..container import convert
|
||||
from ..document import SAFE_EXTENSION, Document
|
||||
from ..util import get_resource_path, get_subprocess_startupinfo
|
||||
from .logic import DangerzoneGui
|
||||
from .logic import Alert, DangerzoneGui
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -78,7 +78,21 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||
self.content_widget.show()
|
||||
|
||||
def closeEvent(self, e: QtGui.QCloseEvent) -> None:
|
||||
e.accept()
|
||||
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()
|
||||
|
||||
if platform.system() != "Darwin":
|
||||
# in MacOS applications only quit when the user
|
||||
|
|
|
@ -69,3 +69,6 @@ class DangerzoneCore(object):
|
|||
|
||||
def get_failed_documents(self) -> List[Document]:
|
||||
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()]
|
||||
|
|
Loading…
Reference in a new issue