1
0
Fork 0
mirror of synced 2024-06-29 03:31:06 +12:00
Rare/rare/components/dialogs/uninstall_dialog.py
loathingKernel fc7e45a43a UninstallDialog: Implement it to work similarly to InstallDialog
Similarly to the installation procedure, when an uninstall is
requested, an `UninstallOptionsModel` is emitted by the `RareGame`.
`DownloadsTab` handles the signal and spawns the `UninstallDialog`.
After the `UninstallDialog` is closed, a worker thread handles
uninstalling the application to avoid UI lock-ups when a large
number of files is deleted.

Allows for uninstall actions to be spawned from anything having
access to the `RareGame` instance.

LaunchDialog: Don't check health on DLCs, they always will require
verification if they don't specify an executable.

Signed-off-by: loathingKernel <142770+loathingKernel@users.noreply.github.com>
2023-02-04 17:38:07 +02:00

79 lines
2.6 KiB
Python

from typing import Tuple
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QCloseEvent
from PyQt5.QtWidgets import (
QDialog,
QLabel,
QVBoxLayout,
QCheckBox,
QHBoxLayout,
QPushButton,
QApplication,
)
from legendary.utils.selective_dl import get_sdl_appname
from rare.models.game import RareGame
from rare.models.install import UninstallOptionsModel
from rare.utils.misc import icon
class UninstallDialog(QDialog):
result_ready = pyqtSignal(UninstallOptionsModel)
def __init__(self, rgame: RareGame, options: UninstallOptionsModel, parent=None):
super(UninstallDialog, self).__init__(parent=parent)
self.setAttribute(Qt.WA_DeleteOnClose, True)
self.setWindowFlags(Qt.Dialog | Qt.CustomizeWindowHint | Qt.WindowTitleHint)
self.setWindowTitle(f'{QApplication.instance().applicationName()} - Uninstall "{rgame.app_title}"')
self.info_text = QLabel(
self.tr("Do you really want to uninstall <b>{}</b>?").format(rgame.app_title)
)
self.keep_files = QCheckBox(self.tr("Keep game files."))
self.keep_files.setChecked(bool(options.keep_files))
self.keep_config = QCheckBox(self.tr("Keep game configuation."))
self.keep_config.setChecked(bool(options.keep_config))
self.ok_button = QPushButton(
icon("ei.remove-circle", color="red"), self.tr("Uninstall")
)
self.ok_button.clicked.connect(self.__on_uninstall)
self.cancel_button = QPushButton(self.tr("Cancel"))
self.cancel_button.clicked.connect(self.__on_cancel)
form_layout = QVBoxLayout()
form_layout.setContentsMargins(-1, -1, 0, -1)
form_layout.addWidget(self.keep_files)
form_layout.addWidget(self.keep_config)
button_layout = QHBoxLayout()
button_layout.addWidget(self.ok_button)
button_layout.addStretch(1)
button_layout.addWidget(self.cancel_button)
layout = QVBoxLayout()
layout.addWidget(self.info_text)
layout.addLayout(form_layout)
layout.addLayout(button_layout)
self.setLayout(layout)
if get_sdl_appname(rgame.app_name) is not None:
self.keep_config.setChecked(True)
self.options: UninstallOptionsModel = options
def closeEvent(self, a0: QCloseEvent) -> None:
self.result_ready.emit(self.options)
super(UninstallDialog, self).closeEvent(a0)
def __on_uninstall(self):
self.options.values = (True, self.keep_files.isChecked(), self.keep_config.isChecked())
self.close()
def __on_cancel(self):
self.options.values = (None, None, None)
self.close()