From a339eff648b51e7384c1ab72fa13162dcdbe4de4 Mon Sep 17 00:00:00 2001 From: deeplow Date: Tue, 3 Jan 2023 14:41:41 +0000 Subject: [PATCH] Add dummy conversion to GUI --- dangerzone/gui/__init__.py | 12 ++++++++++-- dangerzone/gui/logic.py | 8 +++++--- dangerzone/gui/main_window.py | 21 +++++++++++++++++---- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/dangerzone/gui/__init__.py b/dangerzone/gui/__init__.py index 1a948e6..0b9aca5 100644 --- a/dangerzone/gui/__init__.py +++ b/dangerzone/gui/__init__.py @@ -50,6 +50,9 @@ class Application(QtWidgets.QApplication): @click.command() +@click.option( + "--unsafe-dummy-conversion", "dummy_conversion", flag_value=True, hidden=True +) @click.argument( "filenames", required=False, @@ -59,7 +62,7 @@ class Application(QtWidgets.QApplication): ) @click.version_option(version=get_version(), message="%(version)s") @errors.handle_document_errors -def gui_main(filenames: Optional[List[str]]) -> bool: +def gui_main(dummy_conversion: bool, filenames: Optional[List[str]]) -> bool: setup_logging() if platform.system() == "Darwin": @@ -77,7 +80,12 @@ def gui_main(filenames: Optional[List[str]]) -> bool: app = Application() # Common objects - dangerzone = DangerzoneGui(app) + if getattr(sys, "dangerzone_dev", False) and dummy_conversion: + dummy = Dummy() + dangerzone = DangerzoneGui(app, isolation_provider=dummy) + else: + container = Container() + dangerzone = DangerzoneGui(app, isolation_provider=container) # Allow Ctrl-C to smoothly quit the program instead of throwing an exception signal.signal(signal.SIGINT, signal.SIG_DFL) diff --git a/dangerzone/gui/logic.py b/dangerzone/gui/logic.py index 82ec89e..c8ecba3 100644 --- a/dangerzone/gui/logic.py +++ b/dangerzone/gui/logic.py @@ -13,7 +13,7 @@ from PySide2 import QtCore, QtGui, QtWidgets if platform.system() == "Linux": from xdg.DesktopEntry import DesktopEntry -from ..isolation_provider.container import Container +from ..isolation_provider.base import IsolationProvider from ..logic import DangerzoneCore from ..settings import Settings from ..util import get_resource_path @@ -26,8 +26,10 @@ class DangerzoneGui(DangerzoneCore): Singleton of shared state / functionality for the GUI and core app logic """ - def __init__(self, app: QtWidgets.QApplication) -> None: - super().__init__(isolation_provider=Container()) + def __init__( + self, app: QtWidgets.QApplication, isolation_provider: IsolationProvider + ) -> None: + super().__init__(isolation_provider) # Qt app self.app = app diff --git a/dangerzone/gui/main_window.py b/dangerzone/gui/main_window.py index c288ca7..5e96a99 100644 --- a/dangerzone/gui/main_window.py +++ b/dangerzone/gui/main_window.py @@ -57,9 +57,15 @@ class MainWindow(QtWidgets.QMainWindow): header_layout.addWidget(header_version_label) header_layout.addStretch() - # Waiting widget, replaces content widget while container runtime isn't available - self.waiting_widget = WaitingWidget(self.dangerzone) - self.waiting_widget.finished.connect(self.waiting_finished) + if isinstance(self.dangerzone.isolation_provider, Container): + # Waiting widget replaces content widget while container runtime isn't available + self.waiting_widget: WaitingWidget = WaitingWidgetContainer(self.dangerzone) + self.waiting_widget.finished.connect(self.waiting_finished) + + elif isinstance(self.dangerzone.isolation_provider, Dummy): + # Don't wait with dummy converter + self.waiting_widget = WaitingWidget() + self.dangerzone.is_waiting_finished = True # Content widget, contains all the window content except waiting widget self.content_widget = ContentWidget(self.dangerzone) @@ -122,6 +128,13 @@ class InstallContainerThread(QtCore.QThread): class WaitingWidget(QtWidgets.QWidget): + finished = QtCore.Signal() + + def __init__(self) -> None: + super(WaitingWidget, self).__init__() + + +class WaitingWidgetContainer(WaitingWidget): # These are the possible states that the WaitingWidget can show. # # Windows and macOS states: @@ -134,7 +147,7 @@ class WaitingWidget(QtWidgets.QWidget): finished = QtCore.Signal() def __init__(self, dangerzone: DangerzoneGui) -> None: - super(WaitingWidget, self).__init__() + super(WaitingWidgetContainer, self).__init__() self.dangerzone = dangerzone self.label = QtWidgets.QLabel()