1
0
Fork 0
mirror of synced 2024-07-02 21:20:54 +12:00
Rare/rare/components/tabs/games/__init__.py

190 lines
7.4 KiB
Python
Raw Normal View History

2021-09-27 03:43:56 +13:00
from logging import getLogger
from PyQt5.QtCore import QSettings, Qt, pyqtSlot
2022-06-22 11:38:04 +12:00
from PyQt5.QtWidgets import QStackedWidget, QVBoxLayout, QWidget, QScrollArea, QFrame
from rare.models.game import RareGame
from rare.shared import (
LegendaryCoreSingleton,
GlobalSignalsSingleton,
ArgumentsSingleton,
ImageManagerSingleton,
)
from rare.shared import RareCore
from rare.widgets.library_layout import LibraryLayout
2022-06-22 11:38:04 +12:00
from rare.widgets.sliding_stack import SlidingStackedWidget
from .game_info import GameInfoTabs
from .game_widgets import LibraryWidgetController
from .game_widgets.icon_game_widget import IconGameWidget
from .game_widgets.list_game_widget import ListGameWidget
from .head_bar import GameListHeadBar
from .integrations import IntegrationsTabs
2021-09-27 03:43:56 +13:00
logger = getLogger("GamesTab")
2022-06-22 11:38:04 +12:00
class GamesTab(QStackedWidget):
def __init__(self, parent=None):
super(GamesTab, self).__init__(parent=parent)
self.rcore = RareCore.instance()
self.core = LegendaryCoreSingleton()
self.signals = GlobalSignalsSingleton()
self.args = ArgumentsSingleton()
self.image_manager = ImageManagerSingleton()
2021-09-27 03:43:56 +13:00
self.settings = QSettings()
self.active_filter: int = 0
self.games_page = QWidget(parent=self)
games_page_layout = QVBoxLayout(self.games_page)
self.addWidget(self.games_page)
self.head_bar = GameListHeadBar(parent=self.games_page)
self.head_bar.goto_import.connect(self.show_import)
self.head_bar.goto_egl_sync.connect(self.show_egl_sync)
self.head_bar.goto_eos_ubisoft.connect(self.show_eos_ubisoft)
games_page_layout.addWidget(self.head_bar)
2021-09-27 03:43:56 +13:00
self.game_info_page = GameInfoTabs(self)
self.game_info_page.back_clicked.connect(lambda: self.setCurrentWidget(self.games_page))
self.game_info_page.import_clicked.connect(self.show_import)
self.addWidget(self.game_info_page)
self.integrations_page = IntegrationsTabs(self)
self.integrations_page.back_clicked.connect(lambda: self.setCurrentWidget(self.games_page))
self.addWidget(self.integrations_page)
self.view_stack = SlidingStackedWidget(self.games_page)
2022-06-22 11:38:04 +12:00
self.view_stack.setFrameStyle(QFrame.NoFrame)
2022-06-22 11:38:04 +12:00
self.icon_view_scroll = QScrollArea(self.view_stack)
self.icon_view_scroll.setWidgetResizable(True)
self.icon_view_scroll.setFrameShape(QFrame.StyledPanel)
2022-06-22 11:38:04 +12:00
self.icon_view_scroll.horizontalScrollBar().setDisabled(True)
2022-06-22 11:38:04 +12:00
self.list_view_scroll = QScrollArea(self.view_stack)
self.list_view_scroll.setWidgetResizable(True)
self.list_view_scroll.setFrameShape(QFrame.StyledPanel)
2022-06-22 11:38:04 +12:00
self.list_view_scroll.horizontalScrollBar().setDisabled(True)
2022-06-22 11:38:04 +12:00
self.icon_view = QWidget(self.icon_view_scroll)
icon_view_layout = LibraryLayout(self.icon_view)
icon_view_layout.setContentsMargins(0, 13, 0, 13)
icon_view_layout.setAlignment(Qt.AlignTop)
2022-06-22 11:38:04 +12:00
self.list_view = QWidget(self.list_view_scroll)
list_view_layout = QVBoxLayout(self.list_view)
list_view_layout.setContentsMargins(3, 3, 9, 3)
list_view_layout.setAlignment(Qt.AlignTop)
DownloadsTab: Refactor downloads tab When updates are queued, they are removed from the update's list. An exceptions is made when the queued item comes from repairing (without updating), in which case the update is disabled for the runtime. A queued item can be either removed (if it is an update it will be added back to the updates groups) or forced to be updated now. If a queued item is forced, the currently running item will be added to the front of the queue. Downloads will be queued if there is no active download but there is a queue already. The download thread is now responsible for emitting the progress to `RareGame` InstallDialog: Pass `RareGame` and `InstallOptionsModel` only as arguments. The `update`, `repair` and `silent` arguments are already part of `InstallOptionsModel` `RareGame` is used to query information about the game. InstallInfoWorker: Pass only `InstallOptionsModel` as argument Emit `InstallQueueItemModel` as result, to re-use the worker when queuing stopped games RareGame: Query and store metadata property about entitlement grant date RareGame: Add `RareEosOverlay` class that imitates `RareGame` to handle the overlay LibraryWidgetController: Remove dead signal routing code, these signals are handled by `RareGame` Directly parent library widgets instead of reparenting them GameWidgets: Remove unused signals EOSGroup: Set install location based on preferences and use EOSOverlayApp from legendary GamesTab: Connect the `progress` signals of dlcs to the base game's signals GamesTab: Remove dead code GlobalSignals: Remove `ProgresSignals` RareCore: Mangle internal signleton's names Signed-off-by: loathingKernel <142770+loathingKernel@users.noreply.github.com>
2023-01-21 13:15:06 +13:00
self.library_controller = LibraryWidgetController(self.icon_view, self.list_view, self)
2022-06-22 11:38:04 +12:00
self.icon_view_scroll.setWidget(self.icon_view)
self.list_view_scroll.setWidget(self.list_view)
self.view_stack.addWidget(self.icon_view_scroll)
self.view_stack.addWidget(self.list_view_scroll)
games_page_layout.addWidget(self.view_stack)
2022-06-22 11:38:04 +12:00
2021-09-27 03:43:56 +13:00
if not self.settings.value("icon_view", True, bool):
2022-06-22 11:38:04 +12:00
self.view_stack.setCurrentWidget(self.list_view_scroll)
2021-09-27 03:43:56 +13:00
self.head_bar.view.list()
else:
2022-06-22 11:38:04 +12:00
self.view_stack.setCurrentWidget(self.icon_view_scroll)
2021-09-27 03:43:56 +13:00
2021-11-02 08:39:47 +13:00
self.head_bar.search_bar.textChanged.connect(lambda x: self.filter_games("", x))
self.head_bar.search_bar.textChanged.connect(self.scroll_to_top)
self.head_bar.filterChanged.connect(self.filter_games)
self.head_bar.filterChanged.connect(self.scroll_to_top)
self.head_bar.refresh_list.clicked.connect(self.library_controller.update_list)
2021-09-27 03:43:56 +13:00
self.head_bar.view.toggled.connect(self.toggle_view)
2021-11-02 08:39:47 +13:00
f = self.settings.value("filter", 0, int)
if f >= len(self.head_bar.available_filters):
f = 0
2021-11-02 08:39:47 +13:00
self.active_filter = self.head_bar.available_filters[f]
2021-09-30 10:22:47 +13:00
2021-10-15 10:05:00 +13:00
# signals
self.signals.game.installed.connect(self.update_count_games_label)
self.signals.game.uninstalled.connect(self.update_count_games_label)
2021-11-17 10:54:23 +13:00
2022-06-22 11:38:04 +12:00
self.setup_game_list()
2021-10-15 10:05:00 +13:00
@pyqtSlot()
def scroll_to_top(self):
self.icon_view_scroll.verticalScrollBar().setSliderPosition(
self.icon_view_scroll.verticalScrollBar().minimum()
)
self.list_view_scroll.verticalScrollBar().setSliderPosition(
self.list_view_scroll.verticalScrollBar().minimum()
)
@pyqtSlot()
@pyqtSlot(str)
def show_import(self, app_name: str = None):
self.setCurrentWidget(self.integrations_page)
self.integrations_page.show_import(app_name)
@pyqtSlot()
def show_egl_sync(self):
self.setCurrentWidget(self.integrations_page)
self.integrations_page.show_egl_sync()
@pyqtSlot()
def show_eos_ubisoft(self):
self.setCurrentWidget(self.integrations_page)
self.integrations_page.show_eos_ubisoft()
@pyqtSlot(RareGame)
def show_game_info(self, rgame):
self.setCurrentWidget(self.game_info_page)
self.game_info_page.update_game(rgame)
2021-09-27 03:43:56 +13:00
2022-06-22 11:38:04 +12:00
@pyqtSlot()
def update_count_games_label(self):
self.head_bar.set_games_count(
len([game for game in self.rcore.games if game.is_installed]),
len([game for game in self.rcore.games])
)
2022-06-22 11:38:04 +12:00
def setup_game_list(self):
for rgame in self.rcore.games:
icon_widget, list_widget = self.add_library_widget(rgame)
2022-03-17 05:46:57 +13:00
if not icon_widget or not list_widget:
logger.warning(f"Excluding {rgame.app_name} from the game list")
2022-03-17 05:46:57 +13:00
continue
2021-09-27 03:43:56 +13:00
self.icon_view.layout().addWidget(icon_widget)
self.list_view.layout().addWidget(list_widget)
2022-06-22 11:38:04 +12:00
self.filter_games(self.active_filter)
self.update_count_games_label()
2021-09-27 03:43:56 +13:00
def add_library_widget(self, rgame: RareGame):
2021-12-27 11:03:50 +13:00
try:
icon_widget, list_widget = self.library_controller.add_game(rgame)
2021-12-27 11:03:50 +13:00
except Exception as e:
raise e
logger.error(f"{rgame.app_name} is broken. Don't add it to game list: {e}")
2022-03-17 05:46:57 +13:00
return None, None
2021-09-27 03:43:56 +13:00
icon_widget.show_info.connect(self.show_game_info)
list_widget.show_info.connect(self.show_game_info)
return icon_widget, list_widget
@pyqtSlot(str)
@pyqtSlot(str, str)
def filter_games(self, filter_name="all", search_text: str = ""):
2021-11-02 08:39:47 +13:00
if not search_text and (t := self.head_bar.search_bar.text()):
search_text = t
if filter_name:
self.active_filter = filter_name
if not filter_name and (t := self.active_filter):
filter_name = t
2021-09-27 03:43:56 +13:00
self.library_controller.filter_list(filter_name, search_text.lower())
2021-09-27 03:43:56 +13:00
def toggle_view(self):
self.settings.setValue("icon_view", not self.head_bar.view.isChecked())
if not self.head_bar.view.isChecked():
2022-06-22 11:38:04 +12:00
self.view_stack.slideInWidget(self.icon_view_scroll)
2021-09-27 03:43:56 +13:00
else:
2022-06-22 11:38:04 +12:00
self.view_stack.slideInWidget(self.list_view_scroll)