2021-04-09 07:00:18 +12:00
|
|
|
import webbrowser
|
|
|
|
|
2021-04-12 08:44:18 +12:00
|
|
|
from PyQt5.QtCore import QSize, pyqtSignal
|
2021-04-09 07:00:18 +12:00
|
|
|
from PyQt5.QtWidgets import QMenu, QTabWidget, QWidget, QWidgetAction
|
2021-03-09 08:36:42 +13:00
|
|
|
from qtawesome import icon
|
2021-05-18 06:22:29 +12:00
|
|
|
from rare.utils import legendary_utils
|
2021-02-18 05:46:03 +13:00
|
|
|
|
2021-04-13 00:24:10 +12:00
|
|
|
from custom_legendary.core import LegendaryCore
|
2021-05-18 06:22:29 +12:00
|
|
|
from rare.components.dialogs.uninstall_dialog import UninstallDialog
|
2021-04-08 08:42:30 +12:00
|
|
|
from rare.components.tab_utils import TabBar, TabButtonWidget
|
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
|
|
|
|
from rare.components.tabs.downloads.__init__ import DownloadTab
|
|
|
|
from rare.components.tabs.games import GameTab
|
|
|
|
from rare.components.tabs.settings import SettingsTab
|
2021-04-08 08:39:23 +12:00
|
|
|
from rare.utils.models import InstallOptions
|
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-04-20 01:44:28 +12:00
|
|
|
def __init__(self, core: LegendaryCore, parent, offline):
|
2021-04-18 04:58:18 +12:00
|
|
|
super(TabWidget, self).__init__(parent=parent)
|
2021-04-20 01:44:28 +12:00
|
|
|
disabled_tab = 3 if not offline else 1
|
2021-04-13 22:38:11 +12:00
|
|
|
self.core = core
|
2021-03-01 00:06:33 +13:00
|
|
|
self.setTabBar(TabBar(disabled_tab))
|
2021-03-10 04:52:51 +13:00
|
|
|
|
2021-04-13 00:10:36 +12:00
|
|
|
# Generate Tabs
|
2021-04-20 01:44:28 +12:00
|
|
|
self.games_tab = GameTab(core, self, offline)
|
2021-04-13 00:10:36 +12:00
|
|
|
self.addTab(self.games_tab, self.tr("Games"))
|
2021-04-18 04:58:18 +12:00
|
|
|
|
2021-04-20 01:44:28 +12:00
|
|
|
if not offline:
|
|
|
|
updates = self.games_tab.default_widget.game_list.updates
|
|
|
|
self.downloadTab = DownloadTab(core, updates, self)
|
|
|
|
self.addTab(self.downloadTab, "Downloads" + (" (" + str(len(updates)) + ")" if len(updates) != 0 else ""))
|
2021-04-18 04:58:18 +12:00
|
|
|
|
2021-04-20 01:44:28 +12:00
|
|
|
self.cloud_saves = SyncSaves(core, self)
|
|
|
|
self.addTab(self.cloud_saves, "Cloud Saves")
|
2021-04-18 04:58:18 +12:00
|
|
|
|
|
|
|
self.settings = SettingsTab(core, self)
|
|
|
|
|
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-04-13 00:10:36 +12:00
|
|
|
# Buttons
|
|
|
|
store_button = TabButtonWidget(core, 'fa.shopping-cart', 'Epic Games Store')
|
|
|
|
store_button.pressed.connect(lambda: webbrowser.open("https://www.epicgames.com/store"))
|
2021-04-20 01:44:28 +12:00
|
|
|
self.tabBar().setTabButton(disabled_tab, self.tabBar().RightSide, store_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-04-13 00:10:36 +12:00
|
|
|
account_action = QWidgetAction(self)
|
2021-04-09 07:00:18 +12:00
|
|
|
account_action.setDefaultWidget(MiniWidget(core))
|
|
|
|
account_button = TabButtonWidget(core, 'mdi.account-circle', 'Account')
|
|
|
|
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-04-13 00:10:36 +12:00
|
|
|
self.addTab(self.settings, icon("fa.gear", color='white'),
|
|
|
|
"(!)" if self.settings.about.update_available else "")
|
|
|
|
|
|
|
|
# Signals
|
|
|
|
# open download tab
|
|
|
|
self.games_tab.default_widget.game_list.update_game.connect(lambda: self.setCurrentIndex(1))
|
|
|
|
|
2021-05-18 06:22:29 +12:00
|
|
|
# uninstall
|
|
|
|
self.games_tab.game_info.info.uninstall_game.connect(self.uninstall_game)
|
|
|
|
|
2021-05-18 20:32:46 +12:00
|
|
|
# imported
|
|
|
|
self.games_tab.import_widget.update_list.connect(self.game_imported)
|
|
|
|
|
2021-04-20 01:44:28 +12:00
|
|
|
if not offline:
|
|
|
|
# Download finished
|
|
|
|
self.downloadTab.finished.connect(self.dl_finished)
|
|
|
|
# start download
|
|
|
|
self.games_tab.default_widget.game_list.install_game.connect(self.start_download)
|
|
|
|
# install dlc
|
|
|
|
self.games_tab.game_info.dlc_tab.install_dlc.connect(self.start_download)
|
|
|
|
|
|
|
|
# repair game
|
|
|
|
self.games_tab.game_info.info.verify_game.connect(lambda app_name: self.downloadTab.install_game(
|
|
|
|
InstallOptions(app_name, core.get_installed_game(app_name).install_path, repair=True)))
|
|
|
|
|
|
|
|
# Finished sync
|
|
|
|
self.cloud_saves.finished.connect(self.finished_sync)
|
|
|
|
# Game finished
|
|
|
|
self.games_tab.default_widget.game_list.game_exited.connect(self.game_finished)
|
2021-04-13 00:10:36 +12:00
|
|
|
|
|
|
|
# Open game list on click on Games tab button
|
|
|
|
self.tabBarClicked.connect(lambda x: self.games_tab.layout.setCurrentIndex(0) if x == 0 else None)
|
|
|
|
self.setIconSize(QSize(25, 25))
|
|
|
|
|
2021-05-18 20:32:46 +12:00
|
|
|
def game_imported(self, app_name: str):
|
|
|
|
igame = self.core.get_installed_game(app_name)
|
|
|
|
if self.core.get_asset(app_name, True).build_version != igame.version:
|
|
|
|
self.downloadTab.add_update(igame)
|
|
|
|
downloads = len(self.downloadTab.dl_queue) + len(self.downloadTab.update_widgets.keys())
|
|
|
|
self.setTabText(1, "Downloads" + ((" (" + str(downloads) + ")") if downloads != 0 else ""))
|
|
|
|
self.games_tab.default_widget.game_list.update_list(app_name)
|
|
|
|
self.games_tab.layout.setCurrentIndex(0)
|
|
|
|
|
2021-04-13 00:10:36 +12:00
|
|
|
# Sync game and delete dc rpc
|
2021-04-12 08:44:18 +12:00
|
|
|
def game_finished(self, app_name):
|
2021-04-13 00:10:36 +12:00
|
|
|
self.delete_presence.emit()
|
2021-04-13 22:38:11 +12:00
|
|
|
if self.core.get_game(app_name).supports_cloud_saves:
|
|
|
|
self.cloud_saves.sync_game(app_name, True)
|
2021-04-12 08:44:18 +12:00
|
|
|
|
2021-05-18 06:22:29 +12:00
|
|
|
def uninstall_game(self, app_name):
|
|
|
|
game = self.core.get_game(app_name)
|
|
|
|
infos = UninstallDialog(game).get_information()
|
|
|
|
if infos == 0:
|
|
|
|
return
|
|
|
|
legendary_utils.uninstall(game.app_name, self.core, infos)
|
|
|
|
if app_name in self.downloadTab.update_widgets.keys():
|
|
|
|
self.downloadTab.update_layout.removeWidget(self.downloadTab.update_widgets[app_name])
|
|
|
|
self.downloadTab.update_widgets.pop(app_name)
|
|
|
|
downloads = len(self.downloadTab.dl_queue) + len(self.downloadTab.update_widgets.keys())
|
|
|
|
self.setTabText(1, "Downloads" + ((" (" + str(downloads) + ")") if downloads != 0 else ""))
|
2021-05-18 20:32:46 +12:00
|
|
|
self.downloadTab.update_text.setVisible(len(self.downloadTab.update_widgets) == 0)
|
2021-04-13 00:10:36 +12:00
|
|
|
# Update gamelist and set text of Downlaods to "Downloads"
|
2021-05-18 06:22:29 +12:00
|
|
|
|
2021-04-13 00:24:10 +12:00
|
|
|
def dl_finished(self, update_list):
|
2021-05-18 06:22:29 +12:00
|
|
|
if update_list[0]:
|
|
|
|
self.games_tab.default_widget.game_list.update_list(update_list[1])
|
2021-04-13 00:24:10 +12:00
|
|
|
downloads = len(self.downloadTab.dl_queue) + len(self.downloadTab.update_widgets.keys())
|
|
|
|
self.setTabText(1, "Downloads" + ((" (" + str(downloads) + ")") if downloads != 0 else ""))
|
|
|
|
|
2021-04-17 03:48:24 +12:00
|
|
|
def start_download(self, options):
|
2021-04-13 00:24:10 +12:00
|
|
|
downloads = len(self.downloadTab.dl_queue) + len(self.downloadTab.update_widgets.keys()) + 1
|
|
|
|
self.setTabText(1, "Downloads" + ((" (" + str(downloads) + ")") if downloads != 0 else ""))
|
2021-04-17 20:50:25 +12:00
|
|
|
self.downloadTab.install_game(options)
|
2021-04-07 21:51:17 +12:00
|
|
|
|
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-04-13 00:49:36 +12:00
|
|
|
self.games_tab.default_widget.game_list.widgets[app_name][0].info_text = ""
|
|
|
|
self.games_tab.default_widget.game_list.widgets[app_name][0].info_label.setText("")
|
|
|
|
self.games_tab.default_widget.game_list.widgets[app_name][1].info_label.setText("")
|