1
0
Fork 0
mirror of synced 2024-06-21 12:00:25 +12:00
Rare/rare/components/tabs/__init__.py

118 lines
4.7 KiB
Python
Raw Normal View History

from PyQt5.QtCore import QSize, pyqtSignal, pyqtSlot
2022-10-29 23:23:50 +13:00
from PyQt5.QtWidgets import QMenu, QTabWidget, QWidget, QWidgetAction, QShortcut, QMessageBox
from rare.shared import RareCore, LegendaryCoreSingleton, GlobalSignalsSingleton, ArgumentsSingleton
2022-08-14 03:53:00 +12:00
from rare.components.tabs.account import AccountWidget
from rare.components.tabs.downloads import DownloadsTab
from rare.components.tabs.games import GamesTab
from rare.components.tabs.settings import SettingsTab
from rare.components.tabs.settings.debug import DebugSettings
from rare.components.tabs.shop import Shop
from rare.components.tabs.tab_utils import MainTabBar, TabButtonWidget
from rare.utils.misc import icon
class TabWidget(QTabWidget):
# int: exit code
exit_app: pyqtSignal = pyqtSignal(int)
def __init__(self, parent):
super(TabWidget, self).__init__(parent=parent)
self.rcore = RareCore.instance()
self.core = LegendaryCoreSingleton()
self.signals = GlobalSignalsSingleton()
self.args = ArgumentsSingleton()
disabled_tab = 3 if not self.args.offline else 1
self.setTabBar(MainTabBar(disabled_tab))
# Generate Tabs
self.games_tab = GamesTab(self)
self.addTab(self.games_tab, self.tr("Games"))
# Downloads Tab after Games Tab to use populated RareCore games list
if not self.args.offline:
self.downloads_tab = DownloadsTab(self)
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
# update dl tab text
self.addTab(self.downloads_tab, "")
self.downloads_tab.update_title.connect(self.__on_downloads_update_title)
self.downloads_tab.update_queues_count()
self.store = Shop(self.core)
self.addTab(self.store, self.tr("Store (Beta)"))
self.settings_tab = SettingsTab(self)
if self.args.debug:
self.settings_tab.addTab(DebugSettings(), "Debug")
# Space Tab
self.addTab(QWidget(), "")
self.setTabEnabled(disabled_tab, False)
# Button
self.addTab(QWidget(), "")
self.setTabEnabled(disabled_tab + 1, False)
2022-10-29 23:23:50 +13:00
self.account_widget = AccountWidget(self)
self.account_widget.logout.connect(self.logout)
account_action = QWidgetAction(self)
2022-08-14 03:53:00 +12:00
account_action.setDefaultWidget(self.account_widget)
account_button = TabButtonWidget("mdi.account-circle", "Account", fallback_icon="fa.user")
account_button.setMenu(QMenu())
account_button.menu().addAction(account_action)
2021-12-24 22:09:50 +13:00
self.tabBar().setTabButton(
disabled_tab + 1, self.tabBar().RightSide, account_button
)
self.addTab(self.settings_tab, icon("fa.gear"), "")
self.settings_tab.about.update_available_ready.connect(
2021-12-24 22:09:50 +13:00
lambda: self.tabBar().setTabText(5, "(!)")
)
# Open game list on click on Games tab button
self.tabBarClicked.connect(self.mouse_clicked)
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.setIconSize(QSize(24, 24))
# shortcuts
QShortcut("Alt+1", self).activated.connect(lambda: self.setCurrentWidget(self.games_tab))
if not self.args.offline:
QShortcut("Alt+2", self).activated.connect(lambda: self.setCurrentWidget(self.downloads_tab))
QShortcut("Alt+3", self).activated.connect(lambda: self.setCurrentWidget(self.store))
QShortcut("Alt+4", self).activated.connect(lambda: self.setCurrentWidget(self.settings_tab))
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
@pyqtSlot(int)
def __on_downloads_update_title(self, num_downloads: int):
self.setTabText(self.indexOf(self.downloads_tab), self.tr("Downloads ({})").format(num_downloads))
def mouse_clicked(self, tab_num):
if tab_num == 0:
self.games_tab.setCurrentWidget(self.games_tab.games_page)
if not self.args.offline and tab_num == 2:
self.store.load()
def resizeEvent(self, event):
self.tabBar().setMinimumWidth(self.width())
super(TabWidget, self).resizeEvent(event)
2022-10-29 23:23:50 +13:00
@pyqtSlot()
2022-10-29 23:23:50 +13:00
def logout(self):
# FIXME: Don't allow logging out if there are active downloads
if self.downloads_tab.is_download_active:
QMessageBox.warning(
self,
self.tr("Logout"),
self.tr("There are active downloads. Stop them before logging out."),
)
return
# FIXME: End of FIXME
reply = QMessageBox.question(
self,
self.tr("Logout"),
self.tr("Do you really want to logout <b>{}</b>?").format(self.core.lgd.userdata.get("display_name")),
buttons=(QMessageBox.Yes | QMessageBox.No),
defaultButton=QMessageBox.No,
)
if reply == QMessageBox.Yes:
self.core.lgd.invalidate_userdata()
self.exit_app.emit(-133742) # restart exit code