1
0
Fork 0
mirror of synced 2024-06-02 10:44:40 +12:00
Rare/rare/components/tabs/__init__.py

119 lines
4.9 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
from rare.utils.misc import qta_icon, ExitCodes
from .account import AccountWidget
from .downloads import DownloadsTab
from .games import GamesTab
from .settings import SettingsTab
from .settings.debug import DebugSettings
from .store import StoreTab
from .tab_widgets import MainTabBar, TabButtonWidget
class MainTabWidget(QTabWidget):
# int: exit code
exit_app: pyqtSignal = pyqtSignal(int)
def __init__(self, parent):
super(MainTabWidget, self).__init__(parent=parent)
self.rcore = RareCore.instance()
self.core = LegendaryCoreSingleton()
self.signals = GlobalSignalsSingleton()
self.args = ArgumentsSingleton()
self.tab_bar = MainTabBar(parent=self)
self.setTabBar(self.tab_bar)
# Generate Tabs
self.games_tab = GamesTab(self)
self.games_index = self.addTab(self.games_tab, self.tr("Games"))
# Downloads Tab after Games Tab to use populated RareCore games list
2024-01-29 12:03:02 +13:00
self.downloads_tab = DownloadsTab(self)
self.downloads_index = self.addTab(self.downloads_tab, "")
self.downloads_tab.update_title.connect(self.__on_downloads_update_title)
self.downloads_tab.update_queues_count()
self.setTabEnabled(self.downloads_index, not self.args.offline)
2024-01-29 12:03:02 +13:00
if not self.args.offline:
self.store_tab = StoreTab(self.core, parent=self)
self.store_index = self.addTab(self.store_tab, self.tr("Store (Beta)"))
self.setTabEnabled(self.store_index, not self.args.offline)
# Space Tab
space_index = self.addTab(QWidget(self), "")
self.setTabEnabled(space_index, False)
self.tab_bar.expanded = space_index
# Button
button_index = self.addTab(QWidget(self), "")
self.setTabEnabled(button_index, False)
2022-10-29 23:23:50 +13:00
self.account_widget = AccountWidget(self)
self.account_widget.exit_app.connect(self.__on_exit_app)
account_action = QWidgetAction(self)
2022-08-14 03:53:00 +12:00
account_action.setDefaultWidget(self.account_widget)
account_button = TabButtonWidget(qta_icon("mdi.account-circle", fallback="fa.user"), tooltip="Menu")
account_menu = QMenu(account_button)
account_menu.addAction(account_action)
account_button.setMenu(account_menu)
self.tab_bar.setTabButton(
button_index, MainTabBar.RightSide, account_button
2021-12-24 22:09:50 +13:00
)
self.settings_tab = SettingsTab(self)
self.settings_index = self.addTab(self.settings_tab, qta_icon("fa.gear"), "")
self.settings_tab.about.update_available_ready.connect(
lambda: self.tab_bar.setTabText(self.settings_index, "(!)")
2021-12-24 22:09:50 +13:00
)
# Open game list on click on Games tab button
self.tabBarClicked.connect(self.mouse_clicked)
# shortcuts
QShortcut("Alt+1", self).activated.connect(lambda: self.setCurrentIndex(self.games_index))
if not self.args.offline:
QShortcut("Alt+2", self).activated.connect(lambda: self.setCurrentIndex(self.downloads_index))
QShortcut("Alt+3", self).activated.connect(lambda: self.setCurrentIndex(self.store_index))
QShortcut("Alt+4", self).activated.connect(lambda: self.setCurrentIndex(self.settings_index))
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, index):
if index == self.games_index:
self.games_tab.setCurrentWidget(self.games_tab.games_page)
def resizeEvent(self, event):
self.tab_bar.setMinimumWidth(self.width())
super(MainTabWidget, self).resizeEvent(event)
2022-10-29 23:23:50 +13:00
@pyqtSlot(int)
def __on_exit_app(self, exit_code: int):
2022-10-29 23:23:50 +13:00
# FIXME: Don't allow logging out if there are active downloads
if self.downloads_tab.is_download_active:
QMessageBox.warning(
self,
self.tr("Quit") if exit_code == ExitCodes.EXIT else self.tr("Logout"),
self.tr("There are active downloads. Stop them before trying to quit."),
2022-10-29 23:23:50 +13:00
)
return
# FIXME: End of FIXME
if exit_code == ExitCodes.LOGOUT:
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,
)
2022-10-29 23:23:50 +13:00
if reply == QMessageBox.Yes:
self.core.lgd.invalidate_userdata()
else:
return
self.exit_app.emit(exit_code) # restart exit code