2021-09-30 10:22:47 +13:00
|
|
|
from PyQt5.QtCore import QSize, pyqtSignal
|
2021-08-24 03:03:42 +12:00
|
|
|
from PyQt5.QtWidgets import QMenu, QTabWidget, QWidget, QWidgetAction, QShortcut
|
2021-03-09 08:36:42 +13:00
|
|
|
from qtawesome import icon
|
2021-02-18 05:46:03 +13:00
|
|
|
|
2021-10-08 07:19:24 +13:00
|
|
|
from rare import shared
|
2021-04-09 07:00:18 +12:00
|
|
|
from rare.components.tabs.account import MiniWidget
|
2021-04-08 08:42:30 +12:00
|
|
|
from rare.components.tabs.cloud_saves import SyncSaves
|
2021-05-20 21:16:57 +12:00
|
|
|
from rare.components.tabs.downloads import DownloadTab
|
2021-10-08 08:16:01 +13:00
|
|
|
from rare.components.tabs.games import GamesTab
|
2021-04-08 08:42:30 +12:00
|
|
|
from rare.components.tabs.settings import SettingsTab
|
2021-10-10 01:15:22 +13:00
|
|
|
from rare.components.tabs.settings.debug import DebugSettings
|
2021-06-04 09:23:55 +12:00
|
|
|
from rare.components.tabs.shop import Shop
|
2021-09-30 10:22:47 +13:00
|
|
|
from rare.components.tabs.tab_utils import TabBar, TabButtonWidget
|
2021-10-08 07:19:24 +13:00
|
|
|
from rare.utils.models import InstallOptionsModel
|
2021-02-10 23:48:25 +13:00
|
|
|
|
|
|
|
|
|
|
|
class TabWidget(QTabWidget):
|
2021-04-13 00:10:36 +12:00
|
|
|
delete_presence = pyqtSignal()
|
2021-04-12 08:44:18 +12:00
|
|
|
|
2021-10-08 07:19:24 +13:00
|
|
|
def __init__(self, parent):
|
2021-04-18 04:58:18 +12:00
|
|
|
super(TabWidget, self).__init__(parent=parent)
|
2021-10-08 07:19:24 +13:00
|
|
|
disabled_tab = 4 if not shared.args.offline else 1
|
2021-10-15 10:18:13 +13:00
|
|
|
self.core = shared.core
|
2021-10-08 07:19:24 +13:00
|
|
|
self.signals = shared.signals
|
2021-03-01 00:06:33 +13:00
|
|
|
self.setTabBar(TabBar(disabled_tab))
|
2021-04-13 00:10:36 +12:00
|
|
|
# Generate Tabs
|
2021-10-08 07:19:24 +13:00
|
|
|
self.games_tab = GamesTab()
|
2021-04-13 00:10:36 +12:00
|
|
|
self.addTab(self.games_tab, self.tr("Games"))
|
2021-10-15 10:05:00 +13:00
|
|
|
|
2021-10-08 07:19:24 +13:00
|
|
|
if not shared.args.offline:
|
2021-09-27 03:43:56 +13:00
|
|
|
# updates = self.games_tab.default_widget.game_list.updates
|
2021-10-08 07:19:24 +13:00
|
|
|
self.downloadTab = DownloadTab(self.games_tab.updates)
|
2021-10-08 06:42:27 +13:00
|
|
|
self.addTab(self.downloadTab, "Downloads" + (
|
|
|
|
" (" + str(len(self.games_tab.updates)) + ")" if len(self.games_tab.updates) != 0 else ""))
|
2021-10-08 07:19:24 +13:00
|
|
|
self.cloud_saves = SyncSaves()
|
2021-04-20 01:44:28 +12:00
|
|
|
self.addTab(self.cloud_saves, "Cloud Saves")
|
2021-06-15 08:30:57 +12:00
|
|
|
self.store = Shop(self.core)
|
2021-06-11 05:58:35 +12:00
|
|
|
self.addTab(self.store, self.tr("Store (Beta)"))
|
2021-10-12 06:09:20 +13:00
|
|
|
self.settings = SettingsTab(self)
|
2021-04-18 04:58:18 +12:00
|
|
|
|
2021-10-08 07:19:24 +13:00
|
|
|
if shared.args.debug:
|
2021-09-11 08:41:30 +12:00
|
|
|
self.settings.addTab(DebugSettings(), "Debug")
|
|
|
|
|
2021-02-10 23:48:25 +13:00
|
|
|
# Space Tab
|
2021-03-25 23:49:05 +13:00
|
|
|
self.addTab(QWidget(), "")
|
2021-03-01 00:06:33 +13:00
|
|
|
self.setTabEnabled(disabled_tab, False)
|
2021-06-11 05:58:35 +12:00
|
|
|
# Button
|
2021-02-10 23:48:25 +13:00
|
|
|
self.account = QWidget()
|
|
|
|
self.addTab(self.account, "")
|
2021-03-09 03:07:07 +13:00
|
|
|
self.setTabEnabled(disabled_tab + 1, False)
|
2021-04-07 20:44:16 +12:00
|
|
|
|
2021-10-08 07:19:24 +13:00
|
|
|
self.mini_widget = MiniWidget()
|
2021-04-13 00:10:36 +12:00
|
|
|
account_action = QWidgetAction(self)
|
2021-06-08 08:12:26 +12:00
|
|
|
account_action.setDefaultWidget(self.mini_widget)
|
2021-10-08 07:19:24 +13:00
|
|
|
account_button = TabButtonWidget('mdi.account-circle', 'Account')
|
2021-04-09 07:00:18 +12:00
|
|
|
account_button.setMenu(QMenu())
|
|
|
|
account_button.menu().addAction(account_action)
|
2021-04-23 00:34:06 +12:00
|
|
|
self.tabBar().setTabButton(disabled_tab + 1, self.tabBar().RightSide, account_button)
|
2021-02-10 23:48:25 +13:00
|
|
|
|
2021-08-29 06:03:25 +12:00
|
|
|
self.addTab(self.settings, icon("fa.gear"),
|
2021-04-13 00:10:36 +12:00
|
|
|
"(!)" if self.settings.about.update_available else "")
|
|
|
|
|
|
|
|
# Signals
|
2021-10-15 10:05:00 +13:00
|
|
|
# set current index
|
|
|
|
self.signals.set_main_tab_index.connect(self.setCurrentIndex)
|
|
|
|
|
|
|
|
# update dl tab text
|
|
|
|
self.signals.update_download_tab_text.connect(self.update_dl_tab_text)
|
2021-05-18 20:32:46 +12:00
|
|
|
# imported
|
2021-10-15 10:05:00 +13:00
|
|
|
# self.games_tab.import_widget.update_list.connect(self.game_imported)
|
2021-05-18 20:32:46 +12:00
|
|
|
|
2021-10-08 07:19:24 +13:00
|
|
|
if not shared.args.offline:
|
2021-10-05 08:51:39 +13:00
|
|
|
# install dlc
|
2021-10-12 06:09:20 +13:00
|
|
|
self.games_tab.game_info_tabs.dlc.install_dlc.connect(
|
2021-10-05 08:51:39 +13:00
|
|
|
lambda app_name, update: self.install_game(
|
|
|
|
InstallOptionsModel(app_name=app_name),
|
|
|
|
update=update))
|
|
|
|
|
2021-04-20 01:44:28 +12:00
|
|
|
# Finished sync
|
|
|
|
self.cloud_saves.finished.connect(self.finished_sync)
|
|
|
|
# Game finished
|
2021-04-13 00:10:36 +12:00
|
|
|
|
|
|
|
# Open game list on click on Games tab button
|
2021-06-04 09:23:55 +12:00
|
|
|
self.tabBarClicked.connect(self.mouse_clicked)
|
2021-04-13 00:10:36 +12:00
|
|
|
self.setIconSize(QSize(25, 25))
|
|
|
|
|
2021-08-24 03:03:42 +12:00
|
|
|
# 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))
|
|
|
|
|
2021-10-15 10:05:00 +13:00
|
|
|
def update_dl_tab_text(self):
|
|
|
|
num_downloads = len(set([i.options.app_name for i in self.downloadTab.dl_queue] + [i for i in
|
|
|
|
self.downloadTab.update_widgets.keys()]))
|
|
|
|
|
|
|
|
if num_downloads != 0:
|
|
|
|
self.setTabText(1, f"Downloads ({num_downloads})")
|
|
|
|
else:
|
|
|
|
self.setTabText(1, "Downloads")
|
2021-08-28 10:16:17 +12:00
|
|
|
|
2021-06-04 09:23:55 +12:00
|
|
|
def mouse_clicked(self, tab_num):
|
|
|
|
if tab_num == 0:
|
2021-09-16 08:16:50 +12:00
|
|
|
self.games_tab.layout().setCurrentIndex(0)
|
2021-10-04 08:29:33 +13:00
|
|
|
|
2021-10-08 07:19:24 +13:00
|
|
|
if not shared.args.offline and tab_num == 3:
|
2021-09-14 06:24:09 +12:00
|
|
|
self.store.load()
|
|
|
|
|
2021-02-10 23:48:25 +13:00
|
|
|
def resizeEvent(self, event):
|
|
|
|
self.tabBar().setMinimumWidth(self.width())
|
|
|
|
super(TabWidget, self).resizeEvent(event)
|
2021-04-10 21:27:40 +12:00
|
|
|
|
2021-04-13 00:10:36 +12:00
|
|
|
# Remove text "sync game"
|
2021-04-10 21:27:40 +12:00
|
|
|
def finished_sync(self, app_name):
|
2021-09-27 03:43:56 +13:00
|
|
|
if self.core.is_installed(app_name):
|
|
|
|
self.games_tab.widgets[app_name][0].info_text = ""
|
|
|
|
self.games_tab.widgets[app_name][0].info_label.setText("")
|
|
|
|
self.games_tab.widgets[app_name][1].info_label.setText("")
|