From 8f83b4addea203a88f7b4fb2dcba5b5ae487927c Mon Sep 17 00:00:00 2001 From: Dummerle <44114474+Dummerle@users.noreply.github.com> Date: Fri, 4 Feb 2022 22:12:00 +0100 Subject: [PATCH] Add download option to create a shortcut after installation --- rare/components/dialogs/install_dialog.py | 26 +++- .../tabs/downloads/download_thread.py | 8 + rare/components/tabs/settings/dxvk.py | 2 + rare/components/tabs/settings/linux.py | 2 +- rare/ui/components/dialogs/install_dialog.py | 18 ++- rare/ui/components/dialogs/install_dialog.ui | 124 +++++++++------- rare/ui/components/tabs/settings/linux.py | 12 +- rare/ui/components/tabs/settings/linux.ui | 138 +++++++++--------- rare/utils/models.py | 1 + 9 files changed, 194 insertions(+), 137 deletions(-) diff --git a/rare/components/dialogs/install_dialog.py b/rare/components/dialogs/install_dialog.py index fcc5f04e..16b92d35 100644 --- a/rare/components/dialogs/install_dialog.py +++ b/rare/components/dialogs/install_dialog.py @@ -69,6 +69,9 @@ class InstallDialog(QDialog, Ui_InstallDialog): if self.update: self.install_dir_label.setVisible(False) self.install_dir_edit.setVisible(False) + self.shortcut_lbl.setVisible(False) + self.shortcut_cb.setVisible(False) + self.shortcut_cb.setChecked(False) self.warn_label.setVisible(False) self.warn_message.setVisible(False) @@ -112,6 +115,9 @@ class InstallDialog(QDialog, Ui_InstallDialog): self.download_only_check.stateChanged.connect( lambda: self.non_reload_option_changed("download_only") ) + self.shortcut_cb.stateChanged.connect( + lambda: self.non_reload_option_changed("shortcut") + ) self.sdl_list_checks = list() try: for key, info in games[self.app_name].items(): @@ -143,6 +149,15 @@ class InstallDialog(QDialog, Ui_InstallDialog): self.download_only_check.setVisible(False) self.download_only_info_label.setVisible(False) self.download_only_label.setVisible(False) + self.shortcut_cb.setVisible(False) + self.shortcut_lbl.setVisible(False) + + if platform.system() == "Darwin": + self.shortcut_cb.setDisabled(True) + self.shortcut_cb.setChecked(False) + self.shortcut_cb.setToolTip(self.tr("Creating a shortcut is not supported on MacOS")) + + self.non_reload_option_changed("shortcut") self.cancel_button.clicked.connect(self.cancel_clicked) self.verify_button.clicked.connect(self.verify_clicked) @@ -206,16 +221,13 @@ class InstallDialog(QDialog, Ui_InstallDialog): self.options_changed = True self.install_button.setEnabled(False) self.verify_button.setEnabled(not self.worker_running) - # directory is not empty - full_path = os.path.join(self.dl_item.options.base_path, self.game_path) - if not self.dl_item.options.update and os.path.exists(full_path) and len(os.listdir(full_path)) != 0: - return False, path, PathEdit.reasons.dir_not_empty - return True, path, "" def non_reload_option_changed(self, option: str): if option == "download_only": self.dl_item.options.no_install = self.download_only_check.isChecked() + elif option == "shortcut": + self.dl_item.options.create_shortcut = self.shortcut_cb.isChecked() def cancel_clicked(self): self.dl_item.download = None @@ -254,6 +266,10 @@ class InstallDialog(QDialog, Ui_InstallDialog): error_text = self.tr("Error") self.download_size_info_label.setText(error_text) self.install_size_info_label.setText(error_text) + self.warn_label.setText(error_text) + self.warn_message.setText(message) + self.warn_message.setVisible(True) + self.warn_label.setVisible(True) QMessageBox.critical(self, self.windowTitle(), message) self.verify_button.setEnabled(self.options_changed) self.cancel_button.setEnabled(True) diff --git a/rare/components/tabs/downloads/download_thread.py b/rare/components/tabs/downloads/download_thread.py index ee04902e..d2037bd3 100644 --- a/rare/components/tabs/downloads/download_thread.py +++ b/rare/components/tabs/downloads/download_thread.py @@ -15,6 +15,7 @@ from legendary.core import LegendaryCore from legendary.models.downloading import UIUpdate, WriterTask from rare import shared from rare.utils.models import InstallQueueItemModel +from rare.utils.utils import create_desktop_link logger = getLogger("DownloadThread") @@ -190,6 +191,13 @@ class DownloadThread(QThread): self.core.uninstall_tag(old_igame) self.core.install_game(old_igame) + if not self.queue_item.options.update and self.queue_item.options.create_shortcut: + if not create_desktop_link(self.queue_item.options.app_name, self.core, "desktop"): + # maybe add it to download summary, to show in finished downloads + pass + else: + logger.info("Desktop shortcut written") + self.status.emit("finish") def _handle_postinstall(self, postinstall, igame): diff --git a/rare/components/tabs/settings/dxvk.py b/rare/components/tabs/settings/dxvk.py index 6a1af32a..29cf7ae5 100644 --- a/rare/components/tabs/settings/dxvk.py +++ b/rare/components/tabs/settings/dxvk.py @@ -45,8 +45,10 @@ class DxvkSettings(QGroupBox, Ui_DxvkSettings): if dxvk_options is not None: if dxvk_options == "0": self.show_dxvk.setCurrentIndex(1) + return elif dxvk_options == "1": self.show_dxvk.setCurrentIndex(2) + return else: self.show_dxvk.setCurrentIndex(3) self.gb_dxvk_options.setDisabled(False) diff --git a/rare/components/tabs/settings/linux.py b/rare/components/tabs/settings/linux.py index 84be90b5..3cba9f28 100644 --- a/rare/components/tabs/settings/linux.py +++ b/rare/components/tabs/settings/linux.py @@ -40,7 +40,7 @@ class LinuxSettings(QWidget, Ui_LinuxSettings): # dxvk self.dxvk = DxvkSettings(self.name) - self.dxvk_layout.addWidget(self.dxvk) + self.overlay_layout.addWidget(self.dxvk) def load_prefix(self) -> str: return self.load_setting( diff --git a/rare/ui/components/dialogs/install_dialog.py b/rare/ui/components/dialogs/install_dialog.py index 14964fab..23451e4b 100644 --- a/rare/ui/components/dialogs/install_dialog.py +++ b/rare/ui/components/dialogs/install_dialog.py @@ -14,7 +14,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets class Ui_InstallDialog(object): def setupUi(self, InstallDialog): InstallDialog.setObjectName("InstallDialog") - InstallDialog.resize(340, 296) + InstallDialog.resize(340, 314) InstallDialog.setWindowTitle("Rare") self.install_dialog_layout = QtWidgets.QFormLayout(InstallDialog) self.install_dialog_layout.setSizeConstraint(QtWidgets.QLayout.SetFixedSize) @@ -128,18 +128,19 @@ class Ui_InstallDialog(object): font = QtGui.QFont() font.setItalic(True) self.install_size_info_label.setFont(font) + self.install_size_info_label.setWordWrap(True) self.install_size_info_label.setObjectName("install_size_info_label") self.install_dialog_layout.setWidget(9, QtWidgets.QFormLayout.FieldRole, self.install_size_info_label) self.warn_label = QtWidgets.QLabel(InstallDialog) self.warn_label.setObjectName("warn_label") - self.install_dialog_layout.setWidget(10, QtWidgets.QFormLayout.LabelRole, self.warn_label) + self.install_dialog_layout.setWidget(11, QtWidgets.QFormLayout.LabelRole, self.warn_label) self.warn_message = QtWidgets.QLabel(InstallDialog) font = QtGui.QFont() font.setItalic(True) self.warn_message.setFont(font) self.warn_message.setWordWrap(True) self.warn_message.setObjectName("warn_message") - self.install_dialog_layout.setWidget(10, QtWidgets.QFormLayout.FieldRole, self.warn_message) + self.install_dialog_layout.setWidget(11, QtWidgets.QFormLayout.FieldRole, self.warn_message) self.button_layout = QtWidgets.QHBoxLayout() self.button_layout.setObjectName("button_layout") spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) @@ -153,13 +154,21 @@ class Ui_InstallDialog(object): self.install_button = QtWidgets.QPushButton(InstallDialog) self.install_button.setObjectName("install_button") self.button_layout.addWidget(self.install_button) - self.install_dialog_layout.setLayout(13, QtWidgets.QFormLayout.SpanningRole, self.button_layout) + self.install_dialog_layout.setLayout(14, QtWidgets.QFormLayout.SpanningRole, self.button_layout) self.platform_combo_box = QtWidgets.QComboBox(InstallDialog) self.platform_combo_box.setObjectName("platform_combo_box") self.install_dialog_layout.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.platform_combo_box) self.platform_label = QtWidgets.QLabel(InstallDialog) self.platform_label.setObjectName("platform_label") self.install_dialog_layout.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.platform_label) + self.shortcut_lbl = QtWidgets.QLabel(InstallDialog) + self.shortcut_lbl.setObjectName("shortcut_lbl") + self.install_dialog_layout.setWidget(12, QtWidgets.QFormLayout.LabelRole, self.shortcut_lbl) + self.shortcut_cb = QtWidgets.QCheckBox(InstallDialog) + self.shortcut_cb.setText("") + self.shortcut_cb.setChecked(True) + self.shortcut_cb.setObjectName("shortcut_cb") + self.install_dialog_layout.setWidget(12, QtWidgets.QFormLayout.FieldRole, self.shortcut_cb) self.retranslateUi(InstallDialog) QtCore.QMetaObject.connectSlotsByName(InstallDialog) @@ -186,6 +195,7 @@ class Ui_InstallDialog(object): self.verify_button.setText(_translate("InstallDialog", "Verify")) self.install_button.setText(_translate("InstallDialog", "Install")) self.platform_label.setText(_translate("InstallDialog", "Platform")) + self.shortcut_lbl.setText(_translate("InstallDialog", "Create shortcut")) if __name__ == "__main__": diff --git a/rare/ui/components/dialogs/install_dialog.ui b/rare/ui/components/dialogs/install_dialog.ui index 7dead5a1..886b4cf1 100644 --- a/rare/ui/components/dialogs/install_dialog.ui +++ b/rare/ui/components/dialogs/install_dialog.ui @@ -7,7 +7,7 @@ 0 0 340 - 296 + 314 @@ -205,50 +205,53 @@ - - - - true - - - - Click verify... - - + + + + true + + + + Click verify... + + + true + + - - - - Warnings - - - - - - - - true - - - - None - - + + + + Warnings + + + + + + + + true + + + + None + + true - - - - - - Qt::Horizontal - - - - 40 - 20 + + + + + + Qt::Horizontal + + + + 40 + 20 @@ -274,18 +277,35 @@ - - - - - - - - - Platform - - - + + + + + + + + + Platform + + + + + + + Create shortcut + + + + + + + + + + true + + + diff --git a/rare/ui/components/tabs/settings/linux.py b/rare/ui/components/tabs/settings/linux.py index 82e4f943..c9245c47 100644 --- a/rare/ui/components/tabs/settings/linux.py +++ b/rare/ui/components/tabs/settings/linux.py @@ -2,13 +2,13 @@ # Form implementation generated from reading ui file 'rare/ui/components/tabs/settings/linux.ui' # -# Created by: PyQt5 UI code generator 5.15.4 +# Created by: PyQt5 UI code generator 5.15.6 # # WARNING: Any manual changes made to this file will be lost when pyuic5 is # run again. Do not edit this file unless you know what you are doing. -from PyQt5 import QtCore, QtGui, QtWidgets +from PyQt5 import QtCore, QtWidgets class Ui_LinuxSettings(object): @@ -32,16 +32,16 @@ class Ui_LinuxSettings(object): self.prefix_layout.setObjectName("prefix_layout") self.wine_layout.setLayout(0, QtWidgets.QFormLayout.FieldRole, self.prefix_layout) self.exec_label = QtWidgets.QLabel(self.wine_groupbox) - self.exec_label.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.exec_label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.exec_label.setObjectName("exec_label") self.wine_layout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.exec_label) self.exec_layout = QtWidgets.QVBoxLayout() self.exec_layout.setObjectName("exec_layout") self.wine_layout.setLayout(1, QtWidgets.QFormLayout.FieldRole, self.exec_layout) self.linux_layout.addWidget(self.wine_groupbox, 0, 0, 1, 1) - self.dxvk_layout = QtWidgets.QVBoxLayout() - self.dxvk_layout.setObjectName("dxvk_layout") - self.linux_layout.addLayout(self.dxvk_layout, 1, 0, 1, 1) + self.overlay_layout = QtWidgets.QVBoxLayout() + self.overlay_layout.setObjectName("overlay_layout") + self.linux_layout.addLayout(self.overlay_layout, 1, 0, 1, 1) self.retranslateUi(LinuxSettings) QtCore.QMetaObject.connectSlotsByName(LinuxSettings) diff --git a/rare/ui/components/tabs/settings/linux.ui b/rare/ui/components/tabs/settings/linux.ui index 96c2eddf..f66c173c 100644 --- a/rare/ui/components/tabs/settings/linux.ui +++ b/rare/ui/components/tabs/settings/linux.ui @@ -1,75 +1,75 @@ - LinuxSettings - - - - 0 - 0 - 569 - 454 - + LinuxSettings + + + + 0 + 0 + 569 + 454 + + + + LinuxSettings + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Wine Settings + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + Prefix - - LinuxSettings + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Wine Settings - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - Prefix - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - Executable - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - - - + + + + + + + + + Executable + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + - - + + + + + + + + diff --git a/rare/utils/models.py b/rare/utils/models.py index bf44877b..5c9dd61f 100644 --- a/rare/utils/models.py +++ b/rare/utils/models.py @@ -25,6 +25,7 @@ class InstallOptionsModel: silent: bool = False platform: str = "" overlay: bool = False + create_shortcut: bool = True def set_no_install(self, enabled: bool) -> None: self.no_install = enabled