diff --git a/rare/components/dialogs/cloud_save_dialog.py b/rare/components/dialogs/cloud_save_dialog.py index 7d64c318..56067950 100644 --- a/rare/components/dialogs/cloud_save_dialog.py +++ b/rare/components/dialogs/cloud_save_dialog.py @@ -40,7 +40,7 @@ class CloudSaveDialog(QDialog, Ui_SyncSaveDialog): self.status = self.CANCEL - self.title_label.setText(f"{self.title_label.text()} {igame.title}") + self.title_label.setText(f"

{self.title_label.text()} {igame.title}

") newer = self.tr("Newer") if dt_remote and dt_local: diff --git a/rare/components/dialogs/install_dialog.py b/rare/components/dialogs/install_dialog.py index a3042281..61621694 100644 --- a/rare/components/dialogs/install_dialog.py +++ b/rare/components/dialogs/install_dialog.py @@ -23,7 +23,7 @@ from rare.widgets.indicator_edit import PathEdit, IndicatorReasonsCommon class InstallDialogAdvanced(CollapsibleFrame): def __init__(self, parent=None): - widget = QWidget() + widget = QWidget(parent) title = widget.tr("Advanced options") self.ui = Ui_InstallDialogAdvanced() self.ui.setupUi(widget) @@ -42,7 +42,7 @@ class InstallDialog(QDialog): # lk: set object names for CSS properties self.ui.install_button.setObjectName("InstallButton") - self.core = LegendaryCoreSingleton() + self.core = rgame.core self.rgame = rgame self.options = options self.__download: Optional[InstallDownloadModel] = None @@ -70,7 +70,7 @@ class InstallDialog(QDialog): header = self.tr("Modify") else: header = self.tr("Install") - self.ui.install_dialog_label.setText(f'

{header} "{self.rgame.app_title}"

') + self.ui.title_label.setText(f'

{header} "{self.rgame.app_title}"

') self.setWindowTitle(f'{header} "{self.rgame.app_title}" - {QCoreApplication.instance().applicationName()}') if options.base_path: @@ -111,6 +111,11 @@ class InstallDialog(QDialog): self.ui.platform_label.setDisabled(rgame.is_installed) self.ui.platform_combo.setDisabled(rgame.is_installed) + # if we are repairing, disable the SDL selection and open the dialog frame to be visible + self.selectable.setDisabled(options.repair_mode and not options.repair_and_update) + if options.repair_mode and not options.repair_and_update: + self.selectable.click() + self.advanced.ui.max_workers_spin.setValue(self.core.lgd.config.getint("Legendary", "max_workers", fallback=0)) self.advanced.ui.max_workers_spin.valueChanged.connect(self.option_changed) @@ -210,7 +215,7 @@ class InstallDialog(QDialog): layout = QVBoxLayout(widget) layout.setSpacing(0) for tag, info in sdl_data.items(): - cb = TagCheckBox(info["name"], info["description"], info["tags"]) + cb = TagCheckBox(info["name"].strip(), info["description"].strip(), info["tags"]) if tag == "__required": cb.setChecked(True) cb.setDisabled(True) diff --git a/rare/components/dialogs/selective_dialog.py b/rare/components/dialogs/selective_dialog.py new file mode 100644 index 00000000..864eb657 --- /dev/null +++ b/rare/components/dialogs/selective_dialog.py @@ -0,0 +1,108 @@ +from typing import List, Union, Optional + +from PyQt5.QtCore import pyqtSignal +from PyQt5.QtWidgets import ( + QLabel, + QVBoxLayout, + QCheckBox, + QLayout, QGroupBox, +) +from legendary.utils.selective_dl import get_sdl_appname + +from rare.models.game import RareGame +from rare.models.install import SelectiveDownloadsModel +from rare.widgets.dialogs import ButtonDialog, dialog_title_game +from rare.utils.misc import icon + + +class SelectiveDialog(ButtonDialog): + result_ready = pyqtSignal(RareGame, SelectiveDownloadsModel) + + def __init__(self, rgame: RareGame, parent=None): + super(SelectiveDialog, self).__init__(parent=parent) + header = self.tr("Optional downloads for") + self.setWindowTitle(dialog_title_game(header, rgame.app_title)) + + title_label = QLabel(f"

{dialog_title_game(header, rgame.app_title)}

", self) + + self.core = rgame.core + self.rgame = rgame + + selectable_group = QGroupBox(self.tr("Optional downloads"), self) + self.selectable_layout = QVBoxLayout(selectable_group) + self.selectable_layout.setSpacing(0) + + self.selectable_checks: List[TagCheckBox] = [] + self.config_tags: Optional[List[str]] = None + + layout = QVBoxLayout() + layout.setSizeConstraint(QLayout.SetFixedSize) + layout.addWidget(title_label) + layout.addWidget(selectable_group) + + self.setCentralLayout(layout) + + self.accept_button.setText(self.tr("Verify")) + self.accept_button.setIcon(icon("fa.check")) + + self.options: SelectiveDownloadsModel = SelectiveDownloadsModel(rgame.app_name) + + config_disable_sdl = self.core.lgd.config.getboolean(self.rgame.app_name, "disable_sdl", fallback=False) + sdl_name = get_sdl_appname(self.rgame.app_name) + if not config_disable_sdl and sdl_name is not None: + self.create_sdl_list() + else: + self.options.accepted = True + self.accept() + + def create_sdl_list(self): + platform = self.rgame.igame.platform + for cb in self.selectable_checks: + cb.disconnect() + cb.deleteLater() + self.selectable_checks.clear() + + if config_tags := self.core.lgd.config.get(self.rgame.app_name, "install_tags", fallback=None): + self.config_tags = config_tags.split(",") + config_disable_sdl = self.core.lgd.config.getboolean(self.rgame.app_name, "disable_sdl", fallback=False) + sdl_name = get_sdl_appname(self.rgame.app_name) + if not config_disable_sdl and sdl_name is not None: + sdl_data = self.core.get_sdl_data(sdl_name, platform=platform) + if sdl_data: + for tag, info in sdl_data.items(): + cb = TagCheckBox(info["name"].strip(), info["description"].strip(), info["tags"]) + if tag == "__required": + cb.setChecked(True) + cb.setDisabled(True) + if self.config_tags is not None: + if all(elem in self.config_tags for elem in info["tags"]): + cb.setChecked(True) + self.selectable_layout.addWidget(cb) + self.selectable_checks.append(cb) + + def done_handler(self): + self.result_ready.emit(self.rgame, self.options) + + def accept_handler(self): + install_tag = [""] + for cb in self.selectable_checks: + if data := cb.isChecked(): + # noinspection PyTypeChecker + install_tag.extend(data) + self.options.accepted = True + self.options.install_tag = install_tag + + def reject_handler(self): + self.options.accepted = False + self.options.install_tag = None + + +class TagCheckBox(QCheckBox): + def __init__(self, text, desc, tags: List[str], parent=None): + super(TagCheckBox, self).__init__(parent) + self.setText(text) + self.setToolTip(desc) + self.tags = tags + + def isChecked(self) -> Union[bool, List[str]]: + return self.tags if super(TagCheckBox, self).isChecked() else False diff --git a/rare/components/dialogs/uninstall_dialog.py b/rare/components/dialogs/uninstall_dialog.py index 76cee75e..f87f2f00 100644 --- a/rare/components/dialogs/uninstall_dialog.py +++ b/rare/components/dialogs/uninstall_dialog.py @@ -6,7 +6,7 @@ from PyQt5.QtWidgets import ( QVBoxLayout, QCheckBox, QHBoxLayout, - QPushButton, + QPushButton, QLayout, ) from legendary.utils.selective_dl import get_sdl_appname @@ -24,8 +24,8 @@ class UninstallDialog(QDialog): self.setWindowFlags(Qt.Dialog | Qt.CustomizeWindowHint | Qt.WindowTitleHint) header = self.tr("Uninstall") self.setWindowTitle(f'{header} "{rgame.app_title}" - {QCoreApplication.instance().applicationName()}') - self.info_text = QLabel( - self.tr("Do you really want to uninstall {}?").format(rgame.app_title) + self.title_label = QLabel( + self.tr("

Do you really want to uninstall {}?

").format(rgame.app_title) ) self.keep_files = QCheckBox(self.tr("Keep game files.")) @@ -52,14 +52,13 @@ class UninstallDialog(QDialog): button_layout.addStretch(1) button_layout.addWidget(self.uninstall_button) - layout = QVBoxLayout() - layout.addWidget(self.info_text) + layout = QVBoxLayout(self) + layout.setSizeConstraint(QLayout.SetFixedSize) + layout.addWidget(self.title_label) layout.addLayout(form_layout) layout.addLayout(button_layout) - self.setLayout(layout) - - if get_sdl_appname(rgame.app_name) is not None: + if rgame.sdl_name is not None: self.keep_config.setChecked(True) self.options: UninstallOptionsModel = options diff --git a/rare/components/tabs/games/game_info/game_info.py b/rare/components/tabs/games/game_info/game_info.py index f0507021..ed490ad0 100644 --- a/rare/components/tabs/games/game_info/game_info.py +++ b/rare/components/tabs/games/game_info/game_info.py @@ -16,6 +16,8 @@ from PyQt5.QtWidgets import ( QWidgetAction, ) +from rare.models.install import SelectiveDownloadsModel +from rare.components.dialogs.selective_dialog import SelectiveDialog from rare.models.game import RareGame from rare.shared import RareCore from rare.shared.workers import VerifyWorker, MoveWorker @@ -162,9 +164,22 @@ class GameInfo(QWidget, SideTabContents): self.tr("Installation path for {} does not exist. Cannot continue.").format(self.rgame.app_title), ) return - self.verify_game(self.rgame) + if self.rgame.sdl_name is not None: + selective_dialog = SelectiveDialog( + self.rgame, parent=self + ) + selective_dialog.result_ready.connect(self.verify_game) + selective_dialog.open() + else: + self.verify_game(self.rgame) - def verify_game(self, rgame: RareGame): + @pyqtSlot(RareGame, SelectiveDownloadsModel) + def verify_game(self, rgame: RareGame, sdl_model: SelectiveDownloadsModel = None): + if sdl_model is not None: + if not sdl_model.accepted or sdl_model.install_tag is None: + return + self.core.lgd.config.set(rgame.app_name, "install_tags", ','.join(sdl_model.install_tag)) + self.core.lgd.save_config() worker = VerifyWorker(self.core, self.args, rgame) worker.signals.progress.connect(self.__on_verify_progress) worker.signals.result.connect(self.__on_verify_result) diff --git a/rare/models/install.py b/rare/models/install.py index efd076f9..05ef39ef 100644 --- a/rare/models/install.py +++ b/rare/models/install.py @@ -117,3 +117,18 @@ class UninstallOptionsModel: self.accepted = values[0] self.keep_files = values[1] self.keep_config = values[2] + + +@dataclass +class SelectiveDownloadsModel: + app_name: str + accepted: bool = None + install_tag: Optional[List[str]] = None + + def __bool__(self): + return ( + bool(self.app_name) + and (self.accepted is not None) + and (self.install_tag is not None) + ) + diff --git a/rare/ui/components/dialogs/install_dialog.py b/rare/ui/components/dialogs/install_dialog.py index de10c4ad..65e0dbcb 100644 --- a/rare/ui/components/dialogs/install_dialog.py +++ b/rare/ui/components/dialogs/install_dialog.py @@ -19,9 +19,9 @@ class Ui_InstallDialog(object): self.install_dialog_layout = QtWidgets.QFormLayout(InstallDialog) self.install_dialog_layout.setLabelAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) self.install_dialog_layout.setObjectName("install_dialog_layout") - self.install_dialog_label = QtWidgets.QLabel(InstallDialog) - self.install_dialog_label.setObjectName("install_dialog_label") - self.install_dialog_layout.setWidget(0, QtWidgets.QFormLayout.SpanningRole, self.install_dialog_label) + self.title_label = QtWidgets.QLabel(InstallDialog) + self.title_label.setObjectName("title_label") + self.install_dialog_layout.setWidget(0, QtWidgets.QFormLayout.SpanningRole, self.title_label) self.install_dir_label = QtWidgets.QLabel(InstallDialog) self.install_dir_label.setObjectName("install_dir_label") self.install_dialog_layout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.install_dir_label) @@ -112,7 +112,7 @@ class Ui_InstallDialog(object): def retranslateUi(self, InstallDialog): _translate = QtCore.QCoreApplication.translate - self.install_dialog_label.setText(_translate("InstallDialog", "error")) + self.title_label.setText(_translate("InstallDialog", "error")) self.install_dir_label.setText(_translate("InstallDialog", "Install directory")) self.platform_label.setText(_translate("InstallDialog", "Platform")) self.shortcut_label.setText(_translate("InstallDialog", "Create shortcut")) diff --git a/rare/ui/components/dialogs/install_dialog.ui b/rare/ui/components/dialogs/install_dialog.ui index 6db58a64..d75569f5 100644 --- a/rare/ui/components/dialogs/install_dialog.ui +++ b/rare/ui/components/dialogs/install_dialog.ui @@ -18,7 +18,7 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - + error