2023-09-24 06:21:58 +13:00
|
|
|
from PyQt5.QtCore import QSettings, pyqtSignal, pyqtSlot, QSize, Qt
|
2021-12-24 22:09:50 +13:00
|
|
|
from PyQt5.QtWidgets import (
|
|
|
|
QLabel,
|
|
|
|
QPushButton,
|
|
|
|
QWidget,
|
|
|
|
QHBoxLayout,
|
2023-09-24 06:21:58 +13:00
|
|
|
QComboBox,
|
|
|
|
QToolButton,
|
|
|
|
QMenu,
|
|
|
|
QAction,
|
2021-12-24 22:09:50 +13:00
|
|
|
)
|
2021-09-27 03:43:56 +13:00
|
|
|
|
2023-03-05 00:23:18 +13:00
|
|
|
from rare.shared import RareCore
|
2022-06-23 05:00:00 +12:00
|
|
|
from rare.utils.extra_widgets import SelectViewWidget, ButtonLineEdit
|
2022-07-27 02:58:17 +12:00
|
|
|
from rare.utils.misc import icon
|
2023-09-24 06:21:58 +13:00
|
|
|
from .game_widgets import LibraryFilter, LibraryOrder
|
2021-09-27 03:43:56 +13:00
|
|
|
|
|
|
|
|
|
|
|
class GameListHeadBar(QWidget):
|
2023-09-24 06:21:58 +13:00
|
|
|
filterChanged: pyqtSignal = pyqtSignal(int)
|
|
|
|
orderChanged: pyqtSignal = pyqtSignal(int)
|
2022-11-04 01:53:58 +13:00
|
|
|
goto_import: pyqtSignal = pyqtSignal()
|
|
|
|
goto_egl_sync: pyqtSignal = pyqtSignal()
|
|
|
|
goto_eos_ubisoft: pyqtSignal = pyqtSignal()
|
2021-09-27 03:43:56 +13:00
|
|
|
|
2021-10-12 10:19:32 +13:00
|
|
|
def __init__(self, parent=None):
|
|
|
|
super(GameListHeadBar, self).__init__(parent=parent)
|
2023-03-05 00:23:18 +13:00
|
|
|
self.rcore = RareCore.instance()
|
2021-09-27 03:43:56 +13:00
|
|
|
self.settings = QSettings()
|
|
|
|
|
2023-09-24 06:21:58 +13:00
|
|
|
self.filter = QComboBox(parent=self)
|
|
|
|
filters = {
|
|
|
|
LibraryFilter.ALL: self.tr("All games"),
|
|
|
|
LibraryFilter.INSTALLED: self.tr("Installed only"),
|
|
|
|
LibraryFilter.OFFLINE: self.tr("Offline Games"),
|
|
|
|
# LibraryFilterTypes.HIDDEN: self.tr("Hidden"),
|
|
|
|
}
|
|
|
|
for data, text in filters.items():
|
|
|
|
self.filter.addItem(text, data)
|
2023-03-05 00:23:18 +13:00
|
|
|
if self.rcore.bit32_games:
|
2023-09-24 06:21:58 +13:00
|
|
|
self.filter.addItem(self.tr("32 Bit Games"), LibraryFilter.WIN32)
|
2023-03-05 00:23:18 +13:00
|
|
|
if self.rcore.mac_games:
|
2023-09-24 06:21:58 +13:00
|
|
|
self.filter.addItem(self.tr("Mac games"), LibraryFilter.MAC)
|
2023-02-02 01:17:51 +13:00
|
|
|
if self.rcore.origin_games:
|
2023-09-24 06:21:58 +13:00
|
|
|
self.filter.addItem(self.tr("Exclude Origin"), LibraryFilter.INSTALLABLE)
|
|
|
|
self.filter.addItem(self.tr("Include Unreal Engine"), LibraryFilter.INCLUDE_UE)
|
2021-09-30 10:22:47 +13:00
|
|
|
|
2021-09-27 03:43:56 +13:00
|
|
|
try:
|
2023-09-24 06:21:58 +13:00
|
|
|
self.filter.setCurrentIndex(
|
|
|
|
self.filter.findData(
|
|
|
|
LibraryFilter(self.settings.value("library_filter", int(LibraryFilter.ALL), int))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
except (TypeError, ValueError):
|
|
|
|
self.settings.setValue("library_filter", int(LibraryFilter.ALL))
|
|
|
|
self.filter.setCurrentIndex(self.filter.findData(LibraryFilter.ALL))
|
|
|
|
|
|
|
|
self.filter.currentIndexChanged.connect(self.__filter_changed)
|
|
|
|
|
|
|
|
self.order = QComboBox(parent=self)
|
|
|
|
sortings = {
|
|
|
|
LibraryOrder.TITLE: self.tr("Title"),
|
|
|
|
LibraryOrder.RECENT: self.tr("Recently played"),
|
|
|
|
LibraryOrder.NEWEST: self.tr("Newest"),
|
|
|
|
LibraryOrder.OLDEST: self.tr("Oldest"),
|
|
|
|
}
|
|
|
|
for data, text in sortings.items():
|
|
|
|
self.order.addItem(text, data)
|
|
|
|
self.order.currentIndexChanged.connect(self.__order_changed)
|
|
|
|
|
|
|
|
integrations_menu = QMenu(parent=self)
|
|
|
|
import_action = QAction(
|
|
|
|
icon("mdi.import", "fa.arrow-down"), self.tr("Import Game"), integrations_menu
|
|
|
|
)
|
2021-09-27 03:43:56 +13:00
|
|
|
|
2022-11-04 01:53:58 +13:00
|
|
|
import_action.triggered.connect(self.goto_import)
|
|
|
|
egl_sync_action = QAction(icon("mdi.sync", "fa.refresh"), self.tr("Sync with EGL"), integrations_menu)
|
|
|
|
egl_sync_action.triggered.connect(self.goto_egl_sync)
|
|
|
|
|
2023-09-24 06:21:58 +13:00
|
|
|
eos_ubisoft_action = QAction(
|
|
|
|
icon("mdi.rocket", "fa.rocket"), self.tr("Epic Overlay and Ubisoft"), integrations_menu
|
|
|
|
)
|
2022-11-04 01:53:58 +13:00
|
|
|
eos_ubisoft_action.triggered.connect(self.goto_eos_ubisoft)
|
|
|
|
|
|
|
|
integrations_menu.addAction(import_action)
|
|
|
|
integrations_menu.addAction(egl_sync_action)
|
|
|
|
integrations_menu.addAction(eos_ubisoft_action)
|
|
|
|
|
2023-09-24 06:21:58 +13:00
|
|
|
integrations = QToolButton(parent=self)
|
2022-11-04 01:53:58 +13:00
|
|
|
integrations.setText(self.tr("Integrations"))
|
|
|
|
integrations.setMenu(integrations_menu)
|
|
|
|
integrations.setPopupMode(QToolButton.InstantPopup)
|
2021-10-12 10:19:32 +13:00
|
|
|
|
2022-06-23 05:00:00 +12:00
|
|
|
self.search_bar = ButtonLineEdit("fa.search", placeholder_text=self.tr("Search Game"))
|
2023-01-26 04:08:43 +13:00
|
|
|
self.search_bar.setObjectName("SearchBar")
|
2021-10-13 08:11:52 +13:00
|
|
|
self.search_bar.setFrame(False)
|
2021-09-27 03:43:56 +13:00
|
|
|
self.search_bar.setMinimumWidth(200)
|
|
|
|
|
|
|
|
checked = QSettings().value("icon_view", True, bool)
|
|
|
|
|
2022-06-24 22:37:48 +12:00
|
|
|
installed_tooltip = self.tr("Installed games")
|
2023-09-24 06:21:58 +13:00
|
|
|
self.installed_icon = QLabel(parent=self)
|
|
|
|
self.installed_icon.setPixmap(icon("ph.floppy-disk-back-fill").pixmap(QSize(16, 16)))
|
2022-06-24 22:37:48 +12:00
|
|
|
self.installed_icon.setToolTip(installed_tooltip)
|
|
|
|
self.installed_label = QLabel(parent=self)
|
|
|
|
font = self.installed_label.font()
|
|
|
|
font.setBold(True)
|
|
|
|
self.installed_label.setFont(font)
|
|
|
|
self.installed_label.setToolTip(installed_tooltip)
|
|
|
|
available_tooltip = self.tr("Available games")
|
2023-09-24 06:21:58 +13:00
|
|
|
self.available_icon = QLabel(parent=self)
|
|
|
|
self.available_icon.setPixmap(icon("ph.floppy-disk-back-light").pixmap(QSize(16, 16)))
|
2022-06-24 22:37:48 +12:00
|
|
|
self.available_icon.setToolTip(available_tooltip)
|
|
|
|
self.available_label = QLabel(parent=self)
|
|
|
|
self.available_label.setToolTip(available_tooltip)
|
|
|
|
|
2021-09-27 03:43:56 +13:00
|
|
|
self.view = SelectViewWidget(checked)
|
2021-10-12 10:19:32 +13:00
|
|
|
|
2023-09-24 06:21:58 +13:00
|
|
|
self.refresh_list = QPushButton(parent=self)
|
2021-09-27 03:43:56 +13:00
|
|
|
self.refresh_list.setIcon(icon("fa.refresh")) # Reload icon
|
2023-09-24 06:21:58 +13:00
|
|
|
self.refresh_list.clicked.connect(self.__refresh_clicked)
|
2022-05-05 08:11:41 +12:00
|
|
|
|
2023-09-24 06:21:58 +13:00
|
|
|
layout = QHBoxLayout(self)
|
2022-06-23 05:00:00 +12:00
|
|
|
layout.setContentsMargins(0, 5, 0, 5)
|
2022-05-05 08:11:41 +12:00
|
|
|
layout.addWidget(self.filter)
|
2023-09-24 06:21:58 +13:00
|
|
|
layout.addWidget(self.order)
|
2022-11-04 01:53:58 +13:00
|
|
|
layout.addStretch(0)
|
|
|
|
layout.addWidget(integrations)
|
2023-09-24 06:21:58 +13:00
|
|
|
layout.addStretch(2)
|
2022-05-05 08:11:41 +12:00
|
|
|
layout.addWidget(self.search_bar)
|
2022-06-24 22:37:48 +12:00
|
|
|
layout.addStretch(2)
|
|
|
|
layout.addWidget(self.installed_icon)
|
|
|
|
layout.addWidget(self.installed_label)
|
|
|
|
layout.addWidget(self.available_icon)
|
|
|
|
layout.addWidget(self.available_label)
|
|
|
|
layout.addStretch(2)
|
2022-05-05 08:11:41 +12:00
|
|
|
layout.addWidget(self.view)
|
2022-06-24 22:37:48 +12:00
|
|
|
layout.addStretch(2)
|
2022-05-05 08:11:41 +12:00
|
|
|
layout.addWidget(self.refresh_list)
|
2021-09-27 03:43:56 +13:00
|
|
|
|
2022-06-24 22:37:48 +12:00
|
|
|
def set_games_count(self, inst: int, avail: int) -> None:
|
|
|
|
self.installed_label.setText(str(inst))
|
|
|
|
self.available_label.setText(str(avail))
|
|
|
|
|
2023-03-05 00:23:18 +13:00
|
|
|
@pyqtSlot()
|
2023-09-24 06:21:58 +13:00
|
|
|
def __refresh_clicked(self):
|
2023-03-05 00:23:18 +13:00
|
|
|
self.rcore.fetch()
|
|
|
|
|
2023-09-24 06:21:58 +13:00
|
|
|
def current_filter(self) -> int:
|
|
|
|
return int(self.filter.currentData(Qt.UserRole))
|
|
|
|
|
|
|
|
@pyqtSlot(int)
|
|
|
|
def __filter_changed(self, index: int):
|
|
|
|
data = int(self.filter.itemData(index, Qt.UserRole))
|
|
|
|
self.filterChanged.emit(data)
|
|
|
|
self.settings.setValue("library_filter", data)
|
|
|
|
|
|
|
|
def current_order(self) -> int:
|
|
|
|
return int(self.order.currentData(Qt.UserRole))
|
|
|
|
|
2023-03-05 00:23:18 +13:00
|
|
|
@pyqtSlot(int)
|
2023-09-24 06:21:58 +13:00
|
|
|
def __order_changed(self, index: int):
|
|
|
|
data = int(self.order.itemData(index, Qt.UserRole))
|
|
|
|
self.orderChanged.emit(data)
|
|
|
|
self.settings.setValue("library_order", data)
|