2021-09-27 03:43:56 +13:00
|
|
|
from logging import getLogger
|
2021-04-07 20:44:16 +12:00
|
|
|
|
2023-03-08 09:53:18 +13:00
|
|
|
from PyQt5.QtCore import QSettings, Qt, pyqtSlot
|
2023-12-15 00:43:59 +13:00
|
|
|
from PyQt5.QtGui import QShowEvent
|
2022-06-22 11:38:04 +12:00
|
|
|
from PyQt5.QtWidgets import QStackedWidget, QVBoxLayout, QWidget, QScrollArea, QFrame
|
2022-06-19 06:45:36 +12:00
|
|
|
|
2022-12-25 15:21:23 +13:00
|
|
|
from rare.models.game import RareGame
|
2022-06-19 06:45:36 +12:00
|
|
|
from rare.shared import (
|
|
|
|
LegendaryCoreSingleton,
|
|
|
|
GlobalSignalsSingleton,
|
|
|
|
ArgumentsSingleton,
|
2022-09-08 00:35:51 +12:00
|
|
|
ImageManagerSingleton,
|
2022-06-19 06:45:36 +12:00
|
|
|
)
|
2023-01-05 09:38:05 +13:00
|
|
|
from rare.shared import RareCore
|
2022-06-20 21:44:57 +12:00
|
|
|
from rare.widgets.library_layout import LibraryLayout
|
2022-06-22 11:38:04 +12:00
|
|
|
from rare.widgets.sliding_stack import SlidingStackedWidget
|
2021-11-04 06:33:01 +13:00
|
|
|
from .game_info import GameInfoTabs
|
2022-12-25 15:21:23 +13:00
|
|
|
from .game_widgets import LibraryWidgetController
|
|
|
|
from .game_widgets.icon_game_widget import IconGameWidget
|
|
|
|
from .game_widgets.list_game_widget import ListGameWidget
|
2021-11-04 06:33:01 +13:00
|
|
|
from .head_bar import GameListHeadBar
|
2022-11-04 09:39:48 +13:00
|
|
|
from .integrations import IntegrationsTabs
|
2021-04-07 20:44:16 +12:00
|
|
|
|
2021-09-27 03:43:56 +13:00
|
|
|
logger = getLogger("GamesTab")
|
2021-04-07 20:44:16 +12:00
|
|
|
|
2021-04-18 04:58:18 +12:00
|
|
|
|
2022-06-22 11:38:04 +12:00
|
|
|
class GamesTab(QStackedWidget):
|
2021-10-12 10:19:32 +13:00
|
|
|
def __init__(self, parent=None):
|
|
|
|
super(GamesTab, self).__init__(parent=parent)
|
2023-01-05 09:38:05 +13:00
|
|
|
self.rcore = RareCore.instance()
|
2022-02-26 06:43:27 +13:00
|
|
|
self.core = LegendaryCoreSingleton()
|
|
|
|
self.signals = GlobalSignalsSingleton()
|
|
|
|
self.args = ArgumentsSingleton()
|
2022-06-19 06:45:36 +12:00
|
|
|
self.image_manager = ImageManagerSingleton()
|
2021-09-27 03:43:56 +13:00
|
|
|
self.settings = QSettings()
|
2021-04-07 20:44:16 +12:00
|
|
|
|
2023-01-31 00:59:47 +13:00
|
|
|
self.games_page = QWidget(parent=self)
|
2023-02-06 20:45:30 +13:00
|
|
|
games_page_layout = QVBoxLayout(self.games_page)
|
2023-01-31 00:59:47 +13:00
|
|
|
self.addWidget(self.games_page)
|
2022-06-24 22:37:48 +12:00
|
|
|
|
2023-01-31 00:59:47 +13:00
|
|
|
self.head_bar = GameListHeadBar(parent=self.games_page)
|
2022-11-04 01:53:58 +13:00
|
|
|
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)
|
2023-02-06 20:45:30 +13:00
|
|
|
games_page_layout.addWidget(self.head_bar)
|
2021-09-27 03:43:56 +13:00
|
|
|
|
2023-01-31 00:59:47 +13:00
|
|
|
self.game_info_page = GameInfoTabs(self)
|
|
|
|
self.game_info_page.back_clicked.connect(lambda: self.setCurrentWidget(self.games_page))
|
2023-04-17 08:01:09 +12:00
|
|
|
self.game_info_page.import_clicked.connect(self.show_import)
|
2023-01-31 00:59:47 +13:00
|
|
|
self.addWidget(self.game_info_page)
|
2021-04-07 20:44:16 +12:00
|
|
|
|
2023-01-31 00:59:47 +13:00
|
|
|
self.integrations_page = IntegrationsTabs(self)
|
|
|
|
self.integrations_page.back_clicked.connect(lambda: self.setCurrentWidget(self.games_page))
|
|
|
|
self.addWidget(self.integrations_page)
|
2021-05-12 00:30:08 +12:00
|
|
|
|
2023-01-31 00:59:47 +13:00
|
|
|
self.view_stack = SlidingStackedWidget(self.games_page)
|
2022-06-22 11:38:04 +12:00
|
|
|
self.view_stack.setFrameStyle(QFrame.NoFrame)
|
2023-02-06 20:45:30 +13:00
|
|
|
|
2022-06-22 11:38:04 +12:00
|
|
|
self.icon_view_scroll = QScrollArea(self.view_stack)
|
|
|
|
self.icon_view_scroll.setWidgetResizable(True)
|
2022-06-24 22:37:48 +12:00
|
|
|
self.icon_view_scroll.setFrameShape(QFrame.StyledPanel)
|
2022-06-22 11:38:04 +12:00
|
|
|
self.icon_view_scroll.horizontalScrollBar().setDisabled(True)
|
2023-02-06 20:45:30 +13:00
|
|
|
|
2022-06-22 11:38:04 +12:00
|
|
|
self.list_view_scroll = QScrollArea(self.view_stack)
|
|
|
|
self.list_view_scroll.setWidgetResizable(True)
|
2022-06-24 22:37:48 +12:00
|
|
|
self.list_view_scroll.setFrameShape(QFrame.StyledPanel)
|
2022-06-22 11:38:04 +12:00
|
|
|
self.list_view_scroll.horizontalScrollBar().setDisabled(True)
|
2023-02-06 20:45:30 +13:00
|
|
|
|
2022-06-22 11:38:04 +12:00
|
|
|
self.icon_view = QWidget(self.icon_view_scroll)
|
2023-02-06 20:45:30 +13:00
|
|
|
icon_view_layout = LibraryLayout(self.icon_view)
|
2023-12-14 11:49:22 +13:00
|
|
|
icon_view_layout.setSpacing(9)
|
2023-04-01 10:55:42 +13:00
|
|
|
icon_view_layout.setContentsMargins(0, 13, 0, 13)
|
2023-02-06 20:45:30 +13:00
|
|
|
icon_view_layout.setAlignment(Qt.AlignTop)
|
|
|
|
|
2022-06-22 11:38:04 +12:00
|
|
|
self.list_view = QWidget(self.list_view_scroll)
|
2023-02-06 20:45:30 +13:00
|
|
|
list_view_layout = QVBoxLayout(self.list_view)
|
|
|
|
list_view_layout.setContentsMargins(3, 3, 9, 3)
|
|
|
|
list_view_layout.setAlignment(Qt.AlignTop)
|
|
|
|
|
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)
|
2023-02-06 20:45:30 +13:00
|
|
|
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))
|
2023-01-06 08:59:52 +13:00
|
|
|
self.head_bar.search_bar.textChanged.connect(self.scroll_to_top)
|
2021-10-12 10:19:32 +13:00
|
|
|
self.head_bar.filterChanged.connect(self.filter_games)
|
2023-01-06 08:59:52 +13:00
|
|
|
self.head_bar.filterChanged.connect(self.scroll_to_top)
|
2022-12-25 15:21:23 +13:00
|
|
|
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)
|
|
|
|
|
2023-12-17 08:57:09 +13:00
|
|
|
self.active_filter: str = self.head_bar.filter.currentData(Qt.UserRole)
|
2021-09-30 10:22:47 +13:00
|
|
|
|
2021-10-15 10:05:00 +13:00
|
|
|
# signals
|
2022-12-25 15:21:23 +13:00
|
|
|
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
|
|
|
|
2023-12-15 00:43:59 +13:00
|
|
|
self.init = True
|
|
|
|
|
|
|
|
def showEvent(self, a0: QShowEvent):
|
|
|
|
if a0.spontaneous() or not self.init:
|
|
|
|
return super().showEvent(a0)
|
2022-06-22 11:38:04 +12:00
|
|
|
self.setup_game_list()
|
2023-12-15 00:43:59 +13:00
|
|
|
self.init = False
|
|
|
|
return super().showEvent(a0)
|
2021-10-15 10:05:00 +13:00
|
|
|
|
2023-01-06 08:59:52 +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()
|
|
|
|
)
|
|
|
|
|
2022-11-04 01:53:58 +13:00
|
|
|
@pyqtSlot()
|
2023-04-17 08:01:09 +12:00
|
|
|
@pyqtSlot(str)
|
|
|
|
def show_import(self, app_name: str = None):
|
2023-01-31 00:59:47 +13:00
|
|
|
self.setCurrentWidget(self.integrations_page)
|
2023-04-17 08:01:09 +12:00
|
|
|
self.integrations_page.show_import(app_name)
|
2021-10-12 10:19:32 +13:00
|
|
|
|
2022-11-04 01:53:58 +13:00
|
|
|
@pyqtSlot()
|
|
|
|
def show_egl_sync(self):
|
2023-01-31 00:59:47 +13:00
|
|
|
self.setCurrentWidget(self.integrations_page)
|
|
|
|
self.integrations_page.show_egl_sync()
|
2021-10-12 10:19:32 +13:00
|
|
|
|
2022-11-04 01:53:58 +13:00
|
|
|
@pyqtSlot()
|
|
|
|
def show_eos_ubisoft(self):
|
2023-01-31 00:59:47 +13:00
|
|
|
self.setCurrentWidget(self.integrations_page)
|
|
|
|
self.integrations_page.show_eos_ubisoft()
|
2022-11-04 01:53:58 +13:00
|
|
|
|
2022-12-25 15:21:23 +13:00
|
|
|
@pyqtSlot(RareGame)
|
|
|
|
def show_game_info(self, rgame):
|
2023-01-31 00:59:47 +13:00
|
|
|
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):
|
2023-02-06 20:45:30 +13:00
|
|
|
self.head_bar.set_games_count(
|
2023-03-05 00:23:18 +13:00
|
|
|
len([game for game in self.rcore.games if game.is_installed]),
|
2024-01-03 04:57:02 +13:00
|
|
|
len(list(self.rcore.games)),
|
2023-02-06 20:45:30 +13:00
|
|
|
)
|
2021-04-07 20:44:16 +12:00
|
|
|
|
2022-06-22 11:38:04 +12:00
|
|
|
def setup_game_list(self):
|
2023-03-05 00:23:18 +13:00
|
|
|
for rgame in self.rcore.games:
|
2022-12-25 15:21:23 +13:00
|
|
|
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:
|
2023-12-17 08:57:09 +13:00
|
|
|
logger.warning("Excluding %s from the game list", rgame.app_title)
|
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)
|
2023-02-08 00:04:33 +13:00
|
|
|
self.update_count_games_label()
|
2021-09-27 03:43:56 +13:00
|
|
|
|
2022-12-25 15:21:23 +13:00
|
|
|
def add_library_widget(self, rgame: RareGame):
|
2021-12-27 11:03:50 +13:00
|
|
|
try:
|
2023-01-25 02:40:21 +13:00
|
|
|
icon_widget, list_widget = self.library_controller.add_game(rgame)
|
2021-12-27 11:03:50 +13:00
|
|
|
except Exception as e:
|
2023-12-17 08:57:09 +13:00
|
|
|
logger.error("Could not add widget for %s to library: %s", rgame.app_name, 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
|
|
|
|
|
2022-12-25 15:21:23 +13:00
|
|
|
@pyqtSlot(str)
|
|
|
|
@pyqtSlot(str, str)
|
2021-11-02 09:11:37 +13:00
|
|
|
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
|
|
|
|
2022-12-25 15:21:23 +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)
|