From 62e19a8be222fca63d8f8d96c7f2fc1792fa22fe Mon Sep 17 00:00:00 2001
From: loathingKernel <142770+loathingKernel@users.noreply.github.com>
Date: Tue, 19 Dec 2023 20:53:21 +0200
Subject: [PATCH 1/2] VerifyGame: Present a dialog to select selective
downloads in the game supports them.
---
rare/components/dialogs/cloud_save_dialog.py | 2 +-
rare/components/dialogs/install_dialog.py | 13 +-
rare/components/dialogs/selective_dialog.py | 133 ++++++++++++++++++
rare/components/dialogs/uninstall_dialog.py | 15 +-
.../tabs/games/game_info/game_info.py | 20 ++-
rare/models/install.py | 7 +
rare/ui/components/dialogs/install_dialog.py | 8 +-
rare/ui/components/dialogs/install_dialog.ui | 2 +-
8 files changed, 180 insertions(+), 20 deletions(-)
create mode 100644 rare/components/dialogs/selective_dialog.py
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..bafe2afe
--- /dev/null
+++ b/rare/components/dialogs/selective_dialog.py
@@ -0,0 +1,133 @@
+from typing import List, Union, Optional
+
+from PyQt5.QtCore import Qt, pyqtSignal, QCoreApplication
+from PyQt5.QtGui import QCloseEvent, QKeyEvent
+from PyQt5.QtWidgets import (
+ QDialog,
+ QLabel,
+ QVBoxLayout,
+ QCheckBox,
+ QHBoxLayout,
+ QPushButton,
+ QLayout, QGroupBox,
+)
+from legendary.utils.selective_dl import get_sdl_appname
+
+from rare.models.game import RareGame
+from rare.models.install import SelectiveDownloadsModel
+
+
+class SelectiveDownloadsDialog(QDialog):
+ result_ready = pyqtSignal(RareGame, SelectiveDownloadsModel)
+
+ def __init__(self, rgame: RareGame, parent=None):
+ super(SelectiveDownloadsDialog, self).__init__(parent=parent)
+ self.setAttribute(Qt.WA_DeleteOnClose, True)
+ self.setWindowFlags(Qt.Dialog | Qt.CustomizeWindowHint | Qt.WindowTitleHint)
+ header = self.tr("Optional downloads for")
+ self.setWindowTitle(f'{header} "{rgame.app_title}" - {QCoreApplication.instance().applicationName()}')
+ self.title_label = QLabel(
+ self.tr("Select the optional downloads for {} to verify with.
").format(rgame.app_title)
+ )
+
+ self.core = rgame.core
+ self.rgame = rgame
+
+ self.selectable = QGroupBox(self.tr("Optional downloads"), self)
+ self.selectable_layout = QVBoxLayout(self.selectable)
+ self.selectable_layout.setSpacing(0)
+
+ self.selectable_checks: List[TagCheckBox] = []
+ self.config_tags: Optional[List[str]] = None
+
+ self.verify_button = QPushButton(self.tr("Verify"))
+ self.verify_button.clicked.connect(self.__on_verify)
+
+ self.cancel_button = QPushButton(self.tr("Cancel"))
+ self.cancel_button.clicked.connect(self.__on_cancel)
+
+ button_layout = QHBoxLayout()
+ button_layout.addWidget(self.cancel_button)
+ button_layout.addStretch(1)
+ button_layout.addWidget(self.verify_button)
+
+ layout = QVBoxLayout(self)
+ layout.setSizeConstraint(QLayout.SetFixedSize)
+ layout.addWidget(self.title_label)
+ layout.addWidget(self.selectable)
+ layout.addLayout(button_layout)
+
+ 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.reset_sdl_list()
+ else:
+ self.options.accepted = True
+ self.close()
+
+ def reset_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)
+ # for cb in self.selectable_checks:
+ # cb.stateChanged.connect(self.option_changed)
+ # self.selectable.setWidget(widget)
+ else:
+ self.selectable.setDisabled(True)
+
+ def closeEvent(self, a0: QCloseEvent) -> None:
+ self.result_ready.emit(self.rgame, self.options)
+ super(SelectiveDownloadsDialog, self).closeEvent(a0)
+
+ def __on_verify(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
+ self.close()
+
+ def __on_cancel(self):
+ self.options.accepted = False
+ self.options.install_tag = None
+ self.close()
+
+ def keyPressEvent(self, e: QKeyEvent) -> None:
+ if e.key() == Qt.Key_Escape:
+ e.accept()
+ self.__on_cancel()
+
+
+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..9eb2242d 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 SelectiveDownloadsDialog
from rare.models.game import RareGame
from rare.shared import RareCore
from rare.shared.workers import VerifyWorker, MoveWorker
@@ -162,9 +164,23 @@ 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 = SelectiveDownloadsDialog(
+ self.rgame, parent=self
+ )
+ selective_dialog.result_ready.connect(self.verify_game)
+ selective_dialog.exec()
+ 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:
+ if sdl_model.accepted:
+ self.core.lgd.config.set(rgame.app_name, "install_tags", ','.join(sdl_model.install_tag))
+ self.core.lgd.save_config()
+ else:
+ return
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..1118377a 100644
--- a/rare/models/install.py
+++ b/rare/models/install.py
@@ -117,3 +117,10 @@ 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
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
From e421d02a4f54bc4800d9bddebf1985dcee8060a4 Mon Sep 17 00:00:00 2001
From: loathingKernel <142770+loathingKernel@users.noreply.github.com>
Date: Tue, 26 Dec 2023 00:05:11 +0200
Subject: [PATCH 2/2] Update SDL dialog
---
rare/components/dialogs/selective_dialog.py | 73 ++++++-------------
.../tabs/games/game_info/game_info.py | 15 ++--
rare/models/install.py | 8 ++
3 files changed, 39 insertions(+), 57 deletions(-)
diff --git a/rare/components/dialogs/selective_dialog.py b/rare/components/dialogs/selective_dialog.py
index bafe2afe..864eb657 100644
--- a/rare/components/dialogs/selective_dialog.py
+++ b/rare/components/dialogs/selective_dialog.py
@@ -1,73 +1,61 @@
from typing import List, Union, Optional
-from PyQt5.QtCore import Qt, pyqtSignal, QCoreApplication
-from PyQt5.QtGui import QCloseEvent, QKeyEvent
+from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import (
- QDialog,
QLabel,
QVBoxLayout,
QCheckBox,
- QHBoxLayout,
- QPushButton,
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 SelectiveDownloadsDialog(QDialog):
+class SelectiveDialog(ButtonDialog):
result_ready = pyqtSignal(RareGame, SelectiveDownloadsModel)
def __init__(self, rgame: RareGame, parent=None):
- super(SelectiveDownloadsDialog, self).__init__(parent=parent)
- self.setAttribute(Qt.WA_DeleteOnClose, True)
- self.setWindowFlags(Qt.Dialog | Qt.CustomizeWindowHint | Qt.WindowTitleHint)
+ super(SelectiveDialog, self).__init__(parent=parent)
header = self.tr("Optional downloads for")
- self.setWindowTitle(f'{header} "{rgame.app_title}" - {QCoreApplication.instance().applicationName()}')
- self.title_label = QLabel(
- self.tr("
Select the optional downloads for {} to verify with.
").format(rgame.app_title)
- )
+ 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
- self.selectable = QGroupBox(self.tr("Optional downloads"), self)
- self.selectable_layout = QVBoxLayout(self.selectable)
+ 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
- self.verify_button = QPushButton(self.tr("Verify"))
- self.verify_button.clicked.connect(self.__on_verify)
-
- self.cancel_button = QPushButton(self.tr("Cancel"))
- self.cancel_button.clicked.connect(self.__on_cancel)
-
- button_layout = QHBoxLayout()
- button_layout.addWidget(self.cancel_button)
- button_layout.addStretch(1)
- button_layout.addWidget(self.verify_button)
-
- layout = QVBoxLayout(self)
+ layout = QVBoxLayout()
layout.setSizeConstraint(QLayout.SetFixedSize)
- layout.addWidget(self.title_label)
- layout.addWidget(self.selectable)
- layout.addLayout(button_layout)
+ 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.reset_sdl_list()
+ self.create_sdl_list()
else:
self.options.accepted = True
- self.close()
+ self.accept()
- def reset_sdl_list(self):
+ def create_sdl_list(self):
platform = self.rgame.igame.platform
for cb in self.selectable_checks:
cb.disconnect()
@@ -91,17 +79,11 @@ class SelectiveDownloadsDialog(QDialog):
cb.setChecked(True)
self.selectable_layout.addWidget(cb)
self.selectable_checks.append(cb)
- # for cb in self.selectable_checks:
- # cb.stateChanged.connect(self.option_changed)
- # self.selectable.setWidget(widget)
- else:
- self.selectable.setDisabled(True)
- def closeEvent(self, a0: QCloseEvent) -> None:
+ def done_handler(self):
self.result_ready.emit(self.rgame, self.options)
- super(SelectiveDownloadsDialog, self).closeEvent(a0)
- def __on_verify(self):
+ def accept_handler(self):
install_tag = [""]
for cb in self.selectable_checks:
if data := cb.isChecked():
@@ -109,17 +91,10 @@ class SelectiveDownloadsDialog(QDialog):
install_tag.extend(data)
self.options.accepted = True
self.options.install_tag = install_tag
- self.close()
- def __on_cancel(self):
+ def reject_handler(self):
self.options.accepted = False
self.options.install_tag = None
- self.close()
-
- def keyPressEvent(self, e: QKeyEvent) -> None:
- if e.key() == Qt.Key_Escape:
- e.accept()
- self.__on_cancel()
class TagCheckBox(QCheckBox):
diff --git a/rare/components/tabs/games/game_info/game_info.py b/rare/components/tabs/games/game_info/game_info.py
index 9eb2242d..ed490ad0 100644
--- a/rare/components/tabs/games/game_info/game_info.py
+++ b/rare/components/tabs/games/game_info/game_info.py
@@ -17,7 +17,7 @@ from PyQt5.QtWidgets import (
)
from rare.models.install import SelectiveDownloadsModel
-from rare.components.dialogs.selective_dialog import SelectiveDownloadsDialog
+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
@@ -165,22 +165,21 @@ class GameInfo(QWidget, SideTabContents):
)
return
if self.rgame.sdl_name is not None:
- selective_dialog = SelectiveDownloadsDialog(
+ selective_dialog = SelectiveDialog(
self.rgame, parent=self
)
selective_dialog.result_ready.connect(self.verify_game)
- selective_dialog.exec()
+ selective_dialog.open()
else:
self.verify_game(self.rgame)
@pyqtSlot(RareGame, SelectiveDownloadsModel)
def verify_game(self, rgame: RareGame, sdl_model: SelectiveDownloadsModel = None):
- if sdl_model:
- if sdl_model.accepted:
- self.core.lgd.config.set(rgame.app_name, "install_tags", ','.join(sdl_model.install_tag))
- self.core.lgd.save_config()
- else:
+ 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 1118377a..05ef39ef 100644
--- a/rare/models/install.py
+++ b/rare/models/install.py
@@ -124,3 +124,11 @@ 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)
+ )
+