VerifyGame: Present a dialog to select selective downloads in the game
supports them.
This commit is contained in:
parent
40e5aacd68
commit
62e19a8be2
|
@ -40,7 +40,7 @@ class CloudSaveDialog(QDialog, Ui_SyncSaveDialog):
|
||||||
|
|
||||||
self.status = self.CANCEL
|
self.status = self.CANCEL
|
||||||
|
|
||||||
self.title_label.setText(f"{self.title_label.text()} <b>{igame.title}</b>")
|
self.title_label.setText(f"<h4>{self.title_label.text()} <b>{igame.title}</b></h4>")
|
||||||
|
|
||||||
newer = self.tr("Newer")
|
newer = self.tr("Newer")
|
||||||
if dt_remote and dt_local:
|
if dt_remote and dt_local:
|
||||||
|
|
|
@ -23,7 +23,7 @@ from rare.widgets.indicator_edit import PathEdit, IndicatorReasonsCommon
|
||||||
|
|
||||||
class InstallDialogAdvanced(CollapsibleFrame):
|
class InstallDialogAdvanced(CollapsibleFrame):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
widget = QWidget()
|
widget = QWidget(parent)
|
||||||
title = widget.tr("Advanced options")
|
title = widget.tr("Advanced options")
|
||||||
self.ui = Ui_InstallDialogAdvanced()
|
self.ui = Ui_InstallDialogAdvanced()
|
||||||
self.ui.setupUi(widget)
|
self.ui.setupUi(widget)
|
||||||
|
@ -42,7 +42,7 @@ class InstallDialog(QDialog):
|
||||||
# lk: set object names for CSS properties
|
# lk: set object names for CSS properties
|
||||||
self.ui.install_button.setObjectName("InstallButton")
|
self.ui.install_button.setObjectName("InstallButton")
|
||||||
|
|
||||||
self.core = LegendaryCoreSingleton()
|
self.core = rgame.core
|
||||||
self.rgame = rgame
|
self.rgame = rgame
|
||||||
self.options = options
|
self.options = options
|
||||||
self.__download: Optional[InstallDownloadModel] = None
|
self.__download: Optional[InstallDownloadModel] = None
|
||||||
|
@ -70,7 +70,7 @@ class InstallDialog(QDialog):
|
||||||
header = self.tr("Modify")
|
header = self.tr("Modify")
|
||||||
else:
|
else:
|
||||||
header = self.tr("Install")
|
header = self.tr("Install")
|
||||||
self.ui.install_dialog_label.setText(f'<h3>{header} "{self.rgame.app_title}"</h3>')
|
self.ui.title_label.setText(f'<h4>{header} "{self.rgame.app_title}"</h4>')
|
||||||
self.setWindowTitle(f'{header} "{self.rgame.app_title}" - {QCoreApplication.instance().applicationName()}')
|
self.setWindowTitle(f'{header} "{self.rgame.app_title}" - {QCoreApplication.instance().applicationName()}')
|
||||||
|
|
||||||
if options.base_path:
|
if options.base_path:
|
||||||
|
@ -111,6 +111,11 @@ class InstallDialog(QDialog):
|
||||||
self.ui.platform_label.setDisabled(rgame.is_installed)
|
self.ui.platform_label.setDisabled(rgame.is_installed)
|
||||||
self.ui.platform_combo.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.setValue(self.core.lgd.config.getint("Legendary", "max_workers", fallback=0))
|
||||||
self.advanced.ui.max_workers_spin.valueChanged.connect(self.option_changed)
|
self.advanced.ui.max_workers_spin.valueChanged.connect(self.option_changed)
|
||||||
|
|
||||||
|
@ -210,7 +215,7 @@ class InstallDialog(QDialog):
|
||||||
layout = QVBoxLayout(widget)
|
layout = QVBoxLayout(widget)
|
||||||
layout.setSpacing(0)
|
layout.setSpacing(0)
|
||||||
for tag, info in sdl_data.items():
|
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":
|
if tag == "__required":
|
||||||
cb.setChecked(True)
|
cb.setChecked(True)
|
||||||
cb.setDisabled(True)
|
cb.setDisabled(True)
|
||||||
|
|
133
rare/components/dialogs/selective_dialog.py
Normal file
133
rare/components/dialogs/selective_dialog.py
Normal file
|
@ -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("<h4>Select the optional downloads for <b>{}</b> to verify with.</h4>").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
|
|
@ -6,7 +6,7 @@ from PyQt5.QtWidgets import (
|
||||||
QVBoxLayout,
|
QVBoxLayout,
|
||||||
QCheckBox,
|
QCheckBox,
|
||||||
QHBoxLayout,
|
QHBoxLayout,
|
||||||
QPushButton,
|
QPushButton, QLayout,
|
||||||
)
|
)
|
||||||
from legendary.utils.selective_dl import get_sdl_appname
|
from legendary.utils.selective_dl import get_sdl_appname
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ class UninstallDialog(QDialog):
|
||||||
self.setWindowFlags(Qt.Dialog | Qt.CustomizeWindowHint | Qt.WindowTitleHint)
|
self.setWindowFlags(Qt.Dialog | Qt.CustomizeWindowHint | Qt.WindowTitleHint)
|
||||||
header = self.tr("Uninstall")
|
header = self.tr("Uninstall")
|
||||||
self.setWindowTitle(f'{header} "{rgame.app_title}" - {QCoreApplication.instance().applicationName()}')
|
self.setWindowTitle(f'{header} "{rgame.app_title}" - {QCoreApplication.instance().applicationName()}')
|
||||||
self.info_text = QLabel(
|
self.title_label = QLabel(
|
||||||
self.tr("Do you really want to uninstall <b>{}</b>?").format(rgame.app_title)
|
self.tr("<h4>Do you really want to uninstall <b>{}</b>?</h4>").format(rgame.app_title)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.keep_files = QCheckBox(self.tr("Keep game files."))
|
self.keep_files = QCheckBox(self.tr("Keep game files."))
|
||||||
|
@ -52,14 +52,13 @@ class UninstallDialog(QDialog):
|
||||||
button_layout.addStretch(1)
|
button_layout.addStretch(1)
|
||||||
button_layout.addWidget(self.uninstall_button)
|
button_layout.addWidget(self.uninstall_button)
|
||||||
|
|
||||||
layout = QVBoxLayout()
|
layout = QVBoxLayout(self)
|
||||||
layout.addWidget(self.info_text)
|
layout.setSizeConstraint(QLayout.SetFixedSize)
|
||||||
|
layout.addWidget(self.title_label)
|
||||||
layout.addLayout(form_layout)
|
layout.addLayout(form_layout)
|
||||||
layout.addLayout(button_layout)
|
layout.addLayout(button_layout)
|
||||||
|
|
||||||
self.setLayout(layout)
|
if rgame.sdl_name is not None:
|
||||||
|
|
||||||
if get_sdl_appname(rgame.app_name) is not None:
|
|
||||||
self.keep_config.setChecked(True)
|
self.keep_config.setChecked(True)
|
||||||
|
|
||||||
self.options: UninstallOptionsModel = options
|
self.options: UninstallOptionsModel = options
|
||||||
|
|
|
@ -16,6 +16,8 @@ from PyQt5.QtWidgets import (
|
||||||
QWidgetAction,
|
QWidgetAction,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from rare.models.install import SelectiveDownloadsModel
|
||||||
|
from rare.components.dialogs.selective_dialog import SelectiveDownloadsDialog
|
||||||
from rare.models.game import RareGame
|
from rare.models.game import RareGame
|
||||||
from rare.shared import RareCore
|
from rare.shared import RareCore
|
||||||
from rare.shared.workers import VerifyWorker, MoveWorker
|
from rare.shared.workers import VerifyWorker, MoveWorker
|
||||||
|
@ -162,9 +164,23 @@ class GameInfo(QWidget, SideTabContents):
|
||||||
self.tr("Installation path for <b>{}</b> does not exist. Cannot continue.").format(self.rgame.app_title),
|
self.tr("Installation path for <b>{}</b> does not exist. Cannot continue.").format(self.rgame.app_title),
|
||||||
)
|
)
|
||||||
return
|
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 = VerifyWorker(self.core, self.args, rgame)
|
||||||
worker.signals.progress.connect(self.__on_verify_progress)
|
worker.signals.progress.connect(self.__on_verify_progress)
|
||||||
worker.signals.result.connect(self.__on_verify_result)
|
worker.signals.result.connect(self.__on_verify_result)
|
||||||
|
|
|
@ -117,3 +117,10 @@ class UninstallOptionsModel:
|
||||||
self.accepted = values[0]
|
self.accepted = values[0]
|
||||||
self.keep_files = values[1]
|
self.keep_files = values[1]
|
||||||
self.keep_config = values[2]
|
self.keep_config = values[2]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class SelectiveDownloadsModel:
|
||||||
|
app_name: str
|
||||||
|
accepted: bool = None
|
||||||
|
install_tag: Optional[List[str]] = None
|
||||||
|
|
|
@ -19,9 +19,9 @@ class Ui_InstallDialog(object):
|
||||||
self.install_dialog_layout = QtWidgets.QFormLayout(InstallDialog)
|
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.setLabelAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
|
||||||
self.install_dialog_layout.setObjectName("install_dialog_layout")
|
self.install_dialog_layout.setObjectName("install_dialog_layout")
|
||||||
self.install_dialog_label = QtWidgets.QLabel(InstallDialog)
|
self.title_label = QtWidgets.QLabel(InstallDialog)
|
||||||
self.install_dialog_label.setObjectName("install_dialog_label")
|
self.title_label.setObjectName("title_label")
|
||||||
self.install_dialog_layout.setWidget(0, QtWidgets.QFormLayout.SpanningRole, self.install_dialog_label)
|
self.install_dialog_layout.setWidget(0, QtWidgets.QFormLayout.SpanningRole, self.title_label)
|
||||||
self.install_dir_label = QtWidgets.QLabel(InstallDialog)
|
self.install_dir_label = QtWidgets.QLabel(InstallDialog)
|
||||||
self.install_dir_label.setObjectName("install_dir_label")
|
self.install_dir_label.setObjectName("install_dir_label")
|
||||||
self.install_dialog_layout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.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):
|
def retranslateUi(self, InstallDialog):
|
||||||
_translate = QtCore.QCoreApplication.translate
|
_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.install_dir_label.setText(_translate("InstallDialog", "Install directory"))
|
||||||
self.platform_label.setText(_translate("InstallDialog", "Platform"))
|
self.platform_label.setText(_translate("InstallDialog", "Platform"))
|
||||||
self.shortcut_label.setText(_translate("InstallDialog", "Create shortcut"))
|
self.shortcut_label.setText(_translate("InstallDialog", "Create shortcut"))
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
</property>
|
</property>
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="0" column="0" colspan="2">
|
||||||
<widget class="QLabel" name="install_dialog_label">
|
<widget class="QLabel" name="title_label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>error</string>
|
<string>error</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
Loading…
Reference in a new issue