2022-11-01 03:57:35 +13:00
|
|
|
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
|
2021-11-03 09:57:19 +13:00
|
|
|
|
2023-01-05 09:38:05 +13:00
|
|
|
from rare.shared import RareCore, LegendaryCoreSingleton, GlobalSignalsSingleton, ArgumentsSingleton
|
2022-08-14 03:53:00 +12:00
|
|
|
from rare.components.tabs.account import AccountWidget
|
2021-12-02 03:29:22 +13:00
|
|
|
from rare.components.tabs.downloads import DownloadsTab
|
2021-11-03 09:57:19 +13:00
|
|
|
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
|
2021-11-19 09:44:11 +13:00
|
|
|
from rare.components.tabs.tab_utils import MainTabBar, TabButtonWidget
|
2022-07-27 02:58:17 +12:00
|
|
|
from rare.utils.misc import icon
|
2021-11-03 09:57:19 +13:00
|
|
|
|
|
|
|
|
|
|
|
class TabWidget(QTabWidget):
|
2022-10-24 02:06:54 +13:00
|
|
|
# int: exit code
|
|
|
|
exit_app: pyqtSignal = pyqtSignal(int)
|
|
|
|
|
2021-11-03 09:57:19 +13:00
|
|
|
def __init__(self, parent):
|
|
|
|
super(TabWidget, 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()
|
|
|
|
disabled_tab = 3 if not self.args.offline else 1
|
2021-11-19 09:44:11 +13:00
|
|
|
self.setTabBar(MainTabBar(disabled_tab))
|
2022-11-01 03:57:35 +13:00
|
|
|
|
2021-11-03 09:57:19 +13:00
|
|
|
# Generate Tabs
|
2022-12-25 15:21:23 +13:00
|
|
|
self.games_tab = GamesTab(self)
|
2021-11-03 09:57:19 +13:00
|
|
|
self.addTab(self.games_tab, self.tr("Games"))
|
|
|
|
|
2023-01-05 09:38:05 +13:00
|
|
|
# Downloads Tab after Games Tab to use populated RareCore games list
|
2022-02-26 06:43:27 +13:00
|
|
|
if not self.args.offline:
|
2023-01-05 09:38:05 +13:00
|
|
|
self.downloads_tab = DownloadsTab(self)
|
|
|
|
updates = list(self.rcore.updates)
|
2021-12-24 22:09:50 +13:00
|
|
|
self.addTab(
|
2022-10-23 02:07:58 +13:00
|
|
|
self.downloads_tab,
|
2023-01-05 09:38:05 +13:00
|
|
|
self.tr("Downloads {}").format(f"({len(updates) if updates else 0})"),
|
2021-12-24 22:09:50 +13:00
|
|
|
)
|
2021-11-03 09:57:19 +13:00
|
|
|
self.store = Shop(self.core)
|
|
|
|
self.addTab(self.store, self.tr("Store (Beta)"))
|
|
|
|
|
2021-11-17 10:54:23 +13:00
|
|
|
self.settings = SettingsTab(self)
|
2022-02-26 06:43:27 +13:00
|
|
|
if self.args.debug:
|
2021-11-03 09:57:19 +13:00
|
|
|
self.settings.addTab(DebugSettings(), "Debug")
|
|
|
|
|
|
|
|
# Space Tab
|
|
|
|
self.addTab(QWidget(), "")
|
|
|
|
self.setTabEnabled(disabled_tab, False)
|
|
|
|
# Button
|
2022-11-04 01:53:58 +13:00
|
|
|
self.addTab(QWidget(), "")
|
2021-11-03 09:57:19 +13:00
|
|
|
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)
|
2021-11-03 09:57:19 +13:00
|
|
|
account_action = QWidgetAction(self)
|
2022-08-14 03:53:00 +12:00
|
|
|
account_action.setDefaultWidget(self.account_widget)
|
2022-01-06 03:44:29 +13:00
|
|
|
account_button = TabButtonWidget("mdi.account-circle", "Account", fallback_icon="fa.user")
|
2021-11-03 09:57:19 +13:00
|
|
|
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
|
|
|
|
)
|
2021-11-03 09:57:19 +13:00
|
|
|
|
2021-11-28 12:50:02 +13:00
|
|
|
self.addTab(self.settings, icon("fa.gear"), "")
|
2021-11-03 09:57:19 +13:00
|
|
|
|
2021-12-24 22:09:50 +13:00
|
|
|
self.settings.about.update_available_ready.connect(
|
|
|
|
lambda: self.tabBar().setTabText(5, "(!)")
|
|
|
|
)
|
2021-11-03 09:57:19 +13:00
|
|
|
# Signals
|
|
|
|
# set current index
|
2022-12-29 06:55:15 +13:00
|
|
|
# self.signals.set_main_tab_index.connect(self.setCurrentIndex)
|
2021-11-03 09:57:19 +13:00
|
|
|
|
|
|
|
# update dl tab text
|
2022-12-29 06:55:15 +13:00
|
|
|
self.signals.download.update_tab.connect(self.update_dl_tab_text)
|
2021-11-03 09:57:19 +13:00
|
|
|
|
|
|
|
# Open game list on click on Games tab button
|
|
|
|
self.tabBarClicked.connect(self.mouse_clicked)
|
|
|
|
self.setIconSize(QSize(25, 25))
|
|
|
|
|
|
|
|
# shortcuts
|
|
|
|
QShortcut("Alt+1", self).activated.connect(lambda: self.setCurrentIndex(0))
|
|
|
|
QShortcut("Alt+2", self).activated.connect(lambda: self.setCurrentIndex(1))
|
|
|
|
QShortcut("Alt+3", self).activated.connect(lambda: self.setCurrentIndex(2))
|
|
|
|
QShortcut("Alt+4", self).activated.connect(lambda: self.setCurrentIndex(5))
|
|
|
|
|
|
|
|
def update_dl_tab_text(self):
|
2021-12-24 22:09:50 +13:00
|
|
|
num_downloads = len(
|
|
|
|
set(
|
2022-10-23 02:07:58 +13:00
|
|
|
[i.options.app_name for i in self.downloads_tab.dl_queue]
|
|
|
|
+ [i for i in self.downloads_tab.update_widgets.keys()]
|
2021-12-24 22:09:50 +13:00
|
|
|
)
|
|
|
|
)
|
2021-11-03 09:57:19 +13:00
|
|
|
|
|
|
|
if num_downloads != 0:
|
|
|
|
self.setTabText(1, f"Downloads ({num_downloads})")
|
|
|
|
else:
|
|
|
|
self.setTabText(1, "Downloads")
|
|
|
|
|
|
|
|
def mouse_clicked(self, tab_num):
|
|
|
|
if tab_num == 0:
|
|
|
|
self.games_tab.layout().setCurrentIndex(0)
|
|
|
|
|
2022-02-26 06:43:27 +13:00
|
|
|
if not self.args.offline and tab_num == 2:
|
2021-11-03 09:57:19 +13:00
|
|
|
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
|
|
|
|
2022-11-01 03:57:35 +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()
|
2022-11-01 03:57:35 +13:00
|
|
|
self.exit_app.emit(-133742) # restart exit code
|