Add Info for uninstalled Games
This commit is contained in:
parent
6a3166ceff
commit
61fe881c1a
7 changed files with 123 additions and 41 deletions
|
@ -5,6 +5,7 @@ from PyQt5.QtWidgets import QMenu, QTabWidget, QWidget, QWidgetAction
|
||||||
from qtawesome import icon
|
from qtawesome import icon
|
||||||
|
|
||||||
from custom_legendary.core import LegendaryCore
|
from custom_legendary.core import LegendaryCore
|
||||||
|
from rare.components.dialogs.install_dialog import InstallDialog
|
||||||
from rare.components.tab_utils import TabBar, TabButtonWidget
|
from rare.components.tab_utils import TabBar, TabButtonWidget
|
||||||
from rare.components.tabs.account import MiniWidget
|
from rare.components.tabs.account import MiniWidget
|
||||||
from rare.components.tabs.cloud_saves import SyncSaves
|
from rare.components.tabs.cloud_saves import SyncSaves
|
||||||
|
@ -66,11 +67,14 @@ class TabWidget(QTabWidget):
|
||||||
if not offline:
|
if not offline:
|
||||||
# Download finished
|
# Download finished
|
||||||
self.downloadTab.finished.connect(self.dl_finished)
|
self.downloadTab.finished.connect(self.dl_finished)
|
||||||
# start download
|
# show uninstalled info
|
||||||
self.games_tab.default_widget.game_list.install_game.connect(self.start_download)
|
self.games_tab.default_widget.game_list.show_uninstalled_info.connect(self.games_tab.show_uninstalled)
|
||||||
# install dlc
|
# install dlc
|
||||||
self.games_tab.game_info.dlc_tab.install_dlc.connect(self.start_download)
|
self.games_tab.game_info.dlc_tab.install_dlc.connect(self.start_download)
|
||||||
|
|
||||||
|
# install game
|
||||||
|
self.games_tab.uninstalled_info_widget.install_button.clicked.connect(self.install_game)
|
||||||
|
|
||||||
# repair game
|
# repair game
|
||||||
self.games_tab.game_info.info.verify_game.connect(lambda app_name: self.downloadTab.install_game(
|
self.games_tab.game_info.info.verify_game.connect(lambda app_name: self.downloadTab.install_game(
|
||||||
InstallOptions(app_name, core.get_installed_game(app_name).install_path, repair=True)))
|
InstallOptions(app_name, core.get_installed_game(app_name).install_path, repair=True)))
|
||||||
|
@ -84,6 +88,20 @@ class TabWidget(QTabWidget):
|
||||||
self.tabBarClicked.connect(lambda x: self.games_tab.layout.setCurrentIndex(0) if x == 0 else None)
|
self.tabBarClicked.connect(lambda x: self.games_tab.layout.setCurrentIndex(0) if x == 0 else None)
|
||||||
self.setIconSize(QSize(25, 25))
|
self.setIconSize(QSize(25, 25))
|
||||||
|
|
||||||
|
def install_game(self):
|
||||||
|
app_name = self.games_tab.uninstalled_info_widget.game.app_name
|
||||||
|
infos = InstallDialog(app_name, self.core).get_information()
|
||||||
|
if infos != 0:
|
||||||
|
path, max_workers, force, ignore_free_space = infos
|
||||||
|
options = InstallOptions(app_name=app_name, max_workers=max_workers, path=path, force=force,
|
||||||
|
ignore_free_space=ignore_free_space)
|
||||||
|
self.start_download(options)
|
||||||
|
|
||||||
|
def start_download(self, options):
|
||||||
|
downloads = len(self.downloadTab.dl_queue) + len(self.downloadTab.update_widgets.keys()) + 1
|
||||||
|
self.setTabText(1, "Downloads" + ((" (" + str(downloads) + ")") if downloads != 0 else ""))
|
||||||
|
self.downloadTab.install_game(options)
|
||||||
|
|
||||||
# Sync game and delete dc rpc
|
# Sync game and delete dc rpc
|
||||||
def game_finished(self, app_name):
|
def game_finished(self, app_name):
|
||||||
self.delete_presence.emit()
|
self.delete_presence.emit()
|
||||||
|
@ -97,11 +115,6 @@ class TabWidget(QTabWidget):
|
||||||
downloads = len(self.downloadTab.dl_queue) + len(self.downloadTab.update_widgets.keys())
|
downloads = len(self.downloadTab.dl_queue) + len(self.downloadTab.update_widgets.keys())
|
||||||
self.setTabText(1, "Downloads" + ((" (" + str(downloads) + ")") if downloads != 0 else ""))
|
self.setTabText(1, "Downloads" + ((" (" + str(downloads) + ")") if downloads != 0 else ""))
|
||||||
|
|
||||||
def start_download(self, options):
|
|
||||||
downloads = len(self.downloadTab.dl_queue) + len(self.downloadTab.update_widgets.keys()) + 1
|
|
||||||
self.setTabText(1, "Downloads" + ((" (" + str(downloads) + ")") if downloads != 0 else ""))
|
|
||||||
self.downloadTab.install_game(options)
|
|
||||||
|
|
||||||
def resizeEvent(self, event):
|
def resizeEvent(self, event):
|
||||||
self.tabBar().setMinimumWidth(self.width())
|
self.tabBar().setMinimumWidth(self.width())
|
||||||
super(TabWidget, self).resizeEvent(event)
|
super(TabWidget, self).resizeEvent(event)
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
from PyQt5.QtCore import pyqtSignal
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
|
from PyQt5.QtCore import pyqtSignal, QSettings
|
||||||
|
from PyQt5.QtGui import QPixmap
|
||||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel
|
||||||
|
|
||||||
from custom_legendary.core import LegendaryCore
|
from custom_legendary.core import LegendaryCore
|
||||||
|
@ -9,16 +13,29 @@ class UninstalledInfo(QWidget):
|
||||||
game: Game
|
game: Game
|
||||||
install_game = pyqtSignal(str)
|
install_game = pyqtSignal(str)
|
||||||
|
|
||||||
|
grade_table = json.load(open(os.path.expanduser("~/.cache/rare/game_list.json")))
|
||||||
|
|
||||||
def __init__(self, core: LegendaryCore):
|
def __init__(self, core: LegendaryCore):
|
||||||
super(UninstalledInfo, self).__init__()
|
super(UninstalledInfo, self).__init__()
|
||||||
self.layout = QVBoxLayout()
|
self.layout = QVBoxLayout()
|
||||||
|
|
||||||
|
self.ratings = {"platinum": self.tr("Platimum"),
|
||||||
|
"gold": self.tr("Gold"),
|
||||||
|
"silver": self.tr("Silver"),
|
||||||
|
"bronze": self.tr("Bronze"),
|
||||||
|
"fail": self.tr("Could not get grade from ProtonDB"),
|
||||||
|
"pending": "Not enough reports"}
|
||||||
|
|
||||||
self.core = core
|
self.core = core
|
||||||
|
|
||||||
|
self.settings = QSettings()
|
||||||
|
|
||||||
self.top_layout = QHBoxLayout()
|
self.top_layout = QHBoxLayout()
|
||||||
|
left_layout = QVBoxLayout()
|
||||||
self.image = QLabel()
|
self.image = QLabel()
|
||||||
self.top_layout.addWidget(self.image)
|
left_layout.addWidget(self.image)
|
||||||
|
left_layout.addStretch(1)
|
||||||
|
self.top_layout.addLayout(left_layout)
|
||||||
self.right_layout = QVBoxLayout()
|
self.right_layout = QVBoxLayout()
|
||||||
|
|
||||||
self.back = QPushButton(self.tr("Back"))
|
self.back = QPushButton(self.tr("Back"))
|
||||||
|
@ -36,8 +53,10 @@ class UninstalledInfo(QWidget):
|
||||||
self.install_button = QPushButton(self.tr("Install"))
|
self.install_button = QPushButton(self.tr("Install"))
|
||||||
self.right_layout.addWidget(self.install_button)
|
self.right_layout.addWidget(self.install_button)
|
||||||
|
|
||||||
|
self.right_layout.addStretch(1)
|
||||||
self.top_layout.addLayout(self.right_layout)
|
self.top_layout.addLayout(self.right_layout)
|
||||||
|
|
||||||
|
self.top_layout.addStretch(1)
|
||||||
self.layout.addLayout(self.top_layout)
|
self.layout.addLayout(self.top_layout)
|
||||||
|
|
||||||
self.setLayout(self.layout)
|
self.setLayout(self.layout)
|
||||||
|
@ -48,4 +67,22 @@ class UninstalledInfo(QWidget):
|
||||||
self.title.setText(f"<h2>{self.game.app_title}</h2>")
|
self.title.setText(f"<h2>{self.game.app_title}</h2>")
|
||||||
self.app_name.setText(app_name)
|
self.app_name.setText(app_name)
|
||||||
|
|
||||||
# TODO get grade (Pull request)
|
IMAGE_DIR = self.settings.value("img_dir", os.path.expanduser("~/.cache/rare/images"), str)
|
||||||
|
|
||||||
|
if os.path.exists(f"{IMAGE_DIR}/{self.game.app_name}/FinalArt.png"):
|
||||||
|
pixmap = QPixmap(f"{IMAGE_DIR}/{self.game.app_name}/FinalArt.png")
|
||||||
|
elif os.path.exists(f"{IMAGE_DIR}/{self.game.app_name}/DieselGameBoxTall.png"):
|
||||||
|
pixmap = QPixmap(f"{IMAGE_DIR}/{self.game.app_name}/DieselGameBoxTall.png")
|
||||||
|
elif os.path.exists(f"{IMAGE_DIR}/{self.game.app_name}/DieselGameBoxLogo.png"):
|
||||||
|
pixmap = QPixmap(f"{IMAGE_DIR}/{self.game.app_name}/DieselGameBoxLogo.png")
|
||||||
|
else:
|
||||||
|
# logger.warning(f"No Image found: {self.game.title}")
|
||||||
|
pixmap = None
|
||||||
|
if pixmap:
|
||||||
|
w = 200
|
||||||
|
pixmap = pixmap.scaled(w, int(w * 4 / 3))
|
||||||
|
self.image.setPixmap(pixmap)
|
||||||
|
|
||||||
|
rating = self.grade_table[app_name]["grade"]
|
||||||
|
self.rating.setText(self.ratings[rating])
|
||||||
|
|
||||||
|
|
|
@ -140,10 +140,10 @@ class GameList(QStackedWidget):
|
||||||
pixmap = QPixmap(f"{IMAGE_DIR}/{igame.app_name}/UninstalledArt.png")
|
pixmap = QPixmap(f"{IMAGE_DIR}/{igame.app_name}/UninstalledArt.png")
|
||||||
|
|
||||||
icon_widget = IconWidgetUninstalled(igame, self.core, pixmap)
|
icon_widget = IconWidgetUninstalled(igame, self.core, pixmap)
|
||||||
icon_widget.install_game.connect(self.install)
|
icon_widget.show_uninstalled_info.connect(self.install)
|
||||||
|
|
||||||
list_widget = ListWidgetUninstalled(self.core, igame, pixmap)
|
list_widget = ListWidgetUninstalled(self.core, igame, pixmap)
|
||||||
list_widget.install_game.connect(self.install)
|
list_widget.show_uninstalled_info.connect(self.install)
|
||||||
|
|
||||||
self.icon_layout.addWidget(icon_widget)
|
self.icon_layout.addWidget(icon_widget)
|
||||||
self.list_layout.addWidget(list_widget)
|
self.list_layout.addWidget(list_widget)
|
||||||
|
@ -190,13 +190,15 @@ class GameList(QStackedWidget):
|
||||||
return True, pid
|
return True, pid
|
||||||
return False, 0
|
return False, 0
|
||||||
|
|
||||||
def install(self, options: InstallOptions):
|
def install(self, app_name):
|
||||||
icon_widget, list_widget = self.widgets[options.app_name]
|
self.show_uninstalled_info.emit(app_name)
|
||||||
icon_widget.mousePressEvent = lambda e: None
|
|
||||||
icon_widget.installing = True
|
# icon_widget, list_widget = self.widgets[options.app_name]
|
||||||
list_widget.install_button.setDisabled(True)
|
# icon_widget.mousePressEvent = lambda e: None
|
||||||
list_widget.installing = True
|
# icon_widget.installing = True
|
||||||
self.install_game.emit(options)
|
# list_widget.install_button.setDisabled(True)
|
||||||
|
# list_widget.installing = True
|
||||||
|
# self.install_game.emit(options)
|
||||||
|
|
||||||
def finished(self, app_name):
|
def finished(self, app_name):
|
||||||
self.running_games.remove(app_name)
|
self.running_games.remove(app_name)
|
||||||
|
|
|
@ -48,13 +48,18 @@ class BaseInstalledWidget(QGroupBox):
|
||||||
self.addAction(self.create_desktop)
|
self.addAction(self.create_desktop)
|
||||||
|
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
if os.path.exists(os.path.expanduser(f"~/.local/share/applications/{self.igame.title}.desktop")):
|
start_menu_file = os.path.expanduser(f"~/.local/share/applications/{self.igame.title}.desktop")
|
||||||
self.create_start_menu = QAction(self.tr("Remove start menu link"))
|
elif os.name == "nt":
|
||||||
else:
|
start_menu_file = os.path.expandvars("%appdata%/Microsoft/Windows/Start Menu")
|
||||||
self.create_start_menu = QAction(self.tr("Create start menu link"))
|
else:
|
||||||
|
start_menu_file = ""
|
||||||
|
if os.path.exists(start_menu_file):
|
||||||
|
self.create_start_menu = QAction(self.tr("Remove start menu link"))
|
||||||
|
else:
|
||||||
|
self.create_start_menu = QAction(self.tr("Create start menu link"))
|
||||||
|
|
||||||
self.create_start_menu.triggered.connect(lambda: self.create_desktop_link("start_menu"))
|
self.create_start_menu.triggered.connect(lambda: self.create_desktop_link("start_menu"))
|
||||||
self.addAction(self.create_start_menu)
|
self.addAction(self.create_start_menu)
|
||||||
|
|
||||||
uninstall = QAction(self.tr("Uninstall"), self)
|
uninstall = QAction(self.tr("Uninstall"), self)
|
||||||
uninstall.triggered.connect(self.uninstall)
|
uninstall.triggered.connect(self.uninstall)
|
||||||
|
|
|
@ -10,7 +10,7 @@ logger = getLogger("Uninstalled")
|
||||||
|
|
||||||
|
|
||||||
class BaseUninstalledWidget(QGroupBox):
|
class BaseUninstalledWidget(QGroupBox):
|
||||||
install_game = pyqtSignal(InstallOptions)
|
show_uninstalled_info = pyqtSignal(str)
|
||||||
|
|
||||||
def __init__(self, game, core, pixmap):
|
def __init__(self, game, core, pixmap):
|
||||||
super(BaseUninstalledWidget, self).__init__()
|
super(BaseUninstalledWidget, self).__init__()
|
||||||
|
@ -22,9 +22,12 @@ class BaseUninstalledWidget(QGroupBox):
|
||||||
self.setContentsMargins(0, 0, 0, 0)
|
self.setContentsMargins(0, 0, 0, 0)
|
||||||
|
|
||||||
def install(self):
|
def install(self):
|
||||||
|
self.show_uninstalled_info.emit(self.game.app_name)
|
||||||
|
|
||||||
|
def installl(self):
|
||||||
infos = InstallDialog(self.game.app_name, self.core).get_information()
|
infos = InstallDialog(self.game.app_name, self.core).get_information()
|
||||||
if infos != 0:
|
if infos != 0:
|
||||||
path, max_workers, force, ignore_free_space = infos
|
path, max_workers, force, ignore_free_space = infos
|
||||||
self.install_game.emit(
|
self.show_uninstalled_info.emit(
|
||||||
InstallOptions(app_name=self.game.app_name, max_workers=max_workers, path=path, force=force,
|
InstallOptions(app_name=self.game.app_name, max_workers=max_workers, path=path, force=force,
|
||||||
ignore_free_space=ignore_free_space))
|
ignore_free_space=ignore_free_space))
|
||||||
|
|
|
@ -13,7 +13,6 @@ logger = getLogger("Uninstalled")
|
||||||
|
|
||||||
|
|
||||||
class IconWidgetUninstalled(BaseUninstalledWidget):
|
class IconWidgetUninstalled(BaseUninstalledWidget):
|
||||||
install_game = pyqtSignal(InstallOptions)
|
|
||||||
|
|
||||||
def __init__(self, game: Game, core: LegendaryCore, pixmap):
|
def __init__(self, game: Game, core: LegendaryCore, pixmap):
|
||||||
super(IconWidgetUninstalled, self).__init__(game, core, pixmap)
|
super(IconWidgetUninstalled, self).__init__(game, core, pixmap)
|
||||||
|
@ -42,7 +41,7 @@ class IconWidgetUninstalled(BaseUninstalledWidget):
|
||||||
|
|
||||||
def enterEvent(self, e):
|
def enterEvent(self, e):
|
||||||
if not self.installing:
|
if not self.installing:
|
||||||
self.info_label.setText(self.tr("Install Game"))
|
self.info_label.setText(self.tr("Game Info"))
|
||||||
else:
|
else:
|
||||||
self.info_label.setText(self.tr("Installation running"))
|
self.info_label.setText(self.tr("Installation running"))
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,13 @@ import requests
|
||||||
from PIL import Image, UnidentifiedImageError
|
from PIL import Image, UnidentifiedImageError
|
||||||
from PyQt5.QtCore import pyqtSignal, QLocale, QSettings
|
from PyQt5.QtCore import pyqtSignal, QLocale, QSettings
|
||||||
|
|
||||||
|
# Windows
|
||||||
|
if os.name == "nt":
|
||||||
|
from win32com.client import Dispatch
|
||||||
|
|
||||||
from rare import lang_path, __version__, style_path
|
from rare import lang_path, __version__, style_path
|
||||||
from custom_legendary.core import LegendaryCore
|
from custom_legendary.core import LegendaryCore
|
||||||
|
|
||||||
import id
|
|
||||||
|
|
||||||
logger = getLogger("Utils")
|
logger = getLogger("Utils")
|
||||||
s = QSettings("Rare", "Rare")
|
s = QSettings("Rare", "Rare")
|
||||||
IMAGE_DIR = s.value("img_dir", os.path.expanduser("~/.cache/rare/images"), type=str)
|
IMAGE_DIR = s.value("img_dir", os.path.expanduser("~/.cache/rare/images"), type=str)
|
||||||
|
@ -150,10 +152,10 @@ def create_desktop_link(app_name, core: LegendaryCore, type_of_link="desktop"):
|
||||||
os.path.join(QSettings('Rare', 'Rare').value('img_dir', os.path.expanduser('~/.cache/rare/images'), str),
|
os.path.join(QSettings('Rare', 'Rare').value('img_dir', os.path.expanduser('~/.cache/rare/images'), str),
|
||||||
igame.app_name, 'Thumbnail.png')):
|
igame.app_name, 'Thumbnail.png')):
|
||||||
icon = os.path.join(QSettings('Rare', 'Rare').value('img_dir', os.path.expanduser('~/.cache/rare/images'), str),
|
icon = os.path.join(QSettings('Rare', 'Rare').value('img_dir', os.path.expanduser('~/.cache/rare/images'), str),
|
||||||
igame.app_name, 'Thumbnail.png')
|
igame.app_name, 'Thumbnail')
|
||||||
else:
|
else:
|
||||||
icon = os.path.join(QSettings('Rare', 'Rare').value('img_dir', os.path.expanduser('~/.cache/rare/images'), str),
|
icon = os.path.join(QSettings('Rare', 'Rare').value('img_dir', os.path.expanduser('~/.cache/rare/images'), str),
|
||||||
igame.app_name, 'DieselGameBoxTall.png')
|
igame.app_name, 'DieselGameBoxTall')
|
||||||
# Linux
|
# Linux
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
if type_of_link == "desktop":
|
if type_of_link == "desktop":
|
||||||
|
@ -167,7 +169,7 @@ def create_desktop_link(app_name, core: LegendaryCore, type_of_link="desktop"):
|
||||||
desktop_file.write("[Desktop Entry]\n"
|
desktop_file.write("[Desktop Entry]\n"
|
||||||
f"Name={igame.title}\n"
|
f"Name={igame.title}\n"
|
||||||
f"Type=Application\n"
|
f"Type=Application\n"
|
||||||
f"Icon={icon}\n"
|
f"Icon={icon}.png\n"
|
||||||
f"Exec=rare launch {app_name}\n"
|
f"Exec=rare launch {app_name}\n"
|
||||||
"Terminal=false\n"
|
"Terminal=false\n"
|
||||||
"StartupWMClass=rare-game\n"
|
"StartupWMClass=rare-game\n"
|
||||||
|
@ -176,12 +178,33 @@ def create_desktop_link(app_name, core: LegendaryCore, type_of_link="desktop"):
|
||||||
|
|
||||||
# Windows
|
# Windows
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
|
# Target of shortcut
|
||||||
if type_of_link == "desktop":
|
if type_of_link == "desktop":
|
||||||
path = os.path.expanduser(f"~/Desktop/")
|
target_folder = os.path.expanduser('~/Desktop/')
|
||||||
elif type_of_link == "start_menu":
|
elif type_of_link == "start_menu":
|
||||||
logger.info("Startmenu link is not supported on windows")
|
target_folder = os.path.expandvars("%appdata%/Microsoft/Windows/Start Menu")
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
|
logger.warning("No valid type of link")
|
||||||
return
|
return
|
||||||
with open(path+igame.title+".bat", "w") as desktop_file:
|
target = os.path.abspath(sys.argv[0])
|
||||||
desktop_file.write(f"rare launch {app_name}")
|
|
||||||
|
# Name of link file
|
||||||
|
linkName = igame.title + '.lnk'
|
||||||
|
|
||||||
|
# Path to location of link file
|
||||||
|
pathLink = os.path.join(target_folder, linkName)
|
||||||
|
|
||||||
|
# Add shortcut
|
||||||
|
shell = Dispatch('WScript.Shell')
|
||||||
|
shortcut = shell.CreateShortCut(pathLink)
|
||||||
|
shortcut.Targetpath = target
|
||||||
|
shortcut.Arguments = f'launch {app_name}'
|
||||||
|
shortcut.WorkingDirectory = os.getcwd()
|
||||||
|
|
||||||
|
# Icon
|
||||||
|
if not os.path.exists(icon+".ico"):
|
||||||
|
img = Image.open(icon+".png")
|
||||||
|
img.save(icon+".ico")
|
||||||
|
logger.info("Create Icon")
|
||||||
|
shortcut.IconLocation = os.path.join(icon + ".ico")
|
||||||
|
shortcut.save()
|
||||||
|
|
Loading…
Reference in a new issue