1
0
Fork 0
mirror of synced 2024-06-28 11:11:15 +12:00

Add wishlist offers in Store

This commit is contained in:
Dummerle 2021-08-18 22:17:14 +02:00
parent 59a7359e19
commit ff0ba4c544
9 changed files with 78 additions and 32 deletions

View file

@ -14,11 +14,6 @@ def main():
help="Launch Rare in background. Open it from System Tray Icon") help="Launch Rare in background. Open it from System Tray Icon")
parser.add_argument("--debug", action="store_true", help="Launch in debug mode") parser.add_argument("--debug", action="store_true", help="Launch in debug mode")
parser.add_argument("--offline", action="store_true", help="Launch Rare in offline mode") parser.add_argument("--offline", action="store_true", help="Launch Rare in offline mode")
if os.name != "nt":
parser.add_argument("--disable-protondb", action="store_true", dest="disable_protondb",
help="Do not download and check data from ProtonDB. Disable it, if you don't need grades")
parser.add_argument("--enable-protondb", action="store_true", dest="enable_protondb",
help="Enable ProtonDB data, after disabled")
parser.add_argument("--desktop-shortcut", action="store_true", dest="desktop_shortcut", parser.add_argument("--desktop-shortcut", action="store_true", dest="desktop_shortcut",
help="Use this, if there is no link on desktop to start Rare") help="Use this, if there is no link on desktop to start Rare")

View file

@ -60,11 +60,6 @@ class App(QApplication):
self.setApplicationName("Rare") self.setApplicationName("Rare")
self.setOrganizationName("Rare") self.setOrganizationName("Rare")
settings = QSettings() settings = QSettings()
if os.name != "nt":
if args.disable_protondb:
settings.setValue("disable_protondb", True)
if args.enable_protondb:
settings.remove("disable_protondb")
# Translator # Translator
self.translator = QTranslator() self.translator = QTranslator()

View file

@ -15,7 +15,7 @@ class Shop(QStackedWidget):
super(Shop, self).__init__() super(Shop, self).__init__()
self.core = core self.core = core
self.shop = ShopWidget(cache_dir) self.shop = ShopWidget(cache_dir, core)
self.browse_games = BrowseGames(cache_dir) self.browse_games = BrowseGames(cache_dir)
self.store_tabs = QTabWidget() self.store_tabs = QTabWidget()

View file

@ -103,3 +103,5 @@ search_query = "query searchStoreQuery($allowCountries: String, $category: Strin
"endDate\n discountSetting {\n discountType\n discountPercentage\n " \ "endDate\n discountSetting {\n discountType\n discountPercentage\n " \
" }\n }\n }\n }\n }\n paging {\n count\n " \ " }\n }\n }\n }\n }\n paging {\n count\n " \
"total\n }\n }\n }\n}\n " "total\n }\n }\n }\n}\n "
wishlist_query = "\n query wishlistQuery($country:String!, $locale:String) {\n Wishlist {\n wishlistItems {\n elements {\n id\n order\n created\n offerId\n updated\n namespace\n \n offer {\n productSlug\n urlSlug\n title\n id\n namespace\n offerType\n expiryDate\n status\n isCodeRedemptionOnly\n description\n effectiveDate\n keyImages {\n type\n url\n }\n seller {\n id\n name\n }\n productSlug\n urlSlug\n items {\n id\n namespace\n }\n customAttributes {\n key\n value\n }\n catalogNs {\n mappings(pageType: \"productHome\") {\n pageSlug\n pageType\n }\n }\n offerMappings {\n pageSlug\n pageType\n }\n categories {\n path\n }\n price(country: $country) {\n totalPrice {\n discountPrice\n originalPrice\n voucherDiscount\n discount\n fmtPrice(locale: $locale) {\n originalPrice\n discountPrice\n intermediatePrice\n }\n currencyCode\n currencyInfo {\n decimals\n symbol\n }\n }\n lineOffers {\n appliedRules {\n id\n endDate\n }\n }\n }\n }\n\n }\n }\n }\n }\n"

View file

@ -2,8 +2,9 @@ import logging
from PyQt5 import QtGui from PyQt5 import QtGui
from PyQt5.QtCore import pyqtSignal from PyQt5.QtCore import pyqtSignal
from PyQt5.QtGui import QFont
from PyQt5.QtNetwork import QNetworkAccessManager from PyQt5.QtNetwork import QNetworkAccessManager
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QHBoxLayout
from rare.components.tabs.shop.constants import search_query from rare.components.tabs.shop.constants import search_query
from rare.utils.extra_widgets import ImageLabel from rare.utils.extra_widgets import ImageLabel
@ -28,7 +29,7 @@ class GameWidget(QWidget):
self.image = ImageLabel() self.image = ImageLabel()
self.layout.addWidget(self.image) self.layout.addWidget(self.image)
self.title_label = QLabel(json_info["title"]) self.title_label = QLabel(json_info.get("title"))
self.title_label.setWordWrap(True) self.title_label.setWordWrap(True)
self.layout.addWidget(self.title_label) self.layout.addWidget(self.title_label)
@ -75,3 +76,22 @@ class GameWidget(QWidget):
data = data["data"]["Catalog"]["searchStore"]["elements"][0] data = data["data"]["Catalog"]["searchStore"]["elements"][0]
self.init_ui(data) self.init_ui(data)
class GameWidgetDiscount(GameWidget):
def __init__(self, *args, **kwargs):
super(GameWidgetDiscount, self).__init__(*args, **kwargs)
h_layout = QHBoxLayout()
self.layout.addLayout(h_layout)
price = args[1]['price']['totalPrice']['fmtPrice']['originalPrice']
discount_price = args[1]['price']['totalPrice']['fmtPrice']['discountPrice']
price_label = QLabel(price)
font = QFont()
font.setStrikeOut(True)
price_label.setFont(font)
h_layout.addWidget(QLabel(discount_price if discount_price != "0" else self.tr("Free")))
h_layout.addWidget(price_label)

View file

@ -5,8 +5,9 @@ from PyQt5.QtCore import Qt, pyqtSignal, QStringListModel
from PyQt5.QtNetwork import QNetworkAccessManager from PyQt5.QtNetwork import QNetworkAccessManager
from PyQt5.QtWidgets import QWidget, QCompleter, QGroupBox, QHBoxLayout, QScrollArea from PyQt5.QtWidgets import QWidget, QCompleter, QGroupBox, QHBoxLayout, QScrollArea
from rare.components.tabs.shop.constants import search_query from custom_legendary.core import LegendaryCore
from rare.components.tabs.shop.game_widgets import GameWidget from rare.components.tabs.shop.constants import search_query, wishlist_query
from rare.components.tabs.shop.game_widgets import GameWidget, GameWidgetDiscount
from rare.ui.components.tabs.store.store import Ui_ShopWidget from rare.ui.components.tabs.store.store import Ui_ShopWidget
from rare.utils.extra_widgets import WaitingSpinner, FlowLayout, ButtonLineEdit from rare.utils.extra_widgets import WaitingSpinner, FlowLayout, ButtonLineEdit
from rare.utils.utils import QtRequestManager, get_lang from rare.utils.utils import QtRequestManager, get_lang
@ -22,11 +23,12 @@ class ShopWidget(QScrollArea, Ui_ShopWidget):
active_search_request = False active_search_request = False
next_search = "" next_search = ""
def __init__(self, path): def __init__(self, path, core: LegendaryCore):
super(ShopWidget, self).__init__() super(ShopWidget, self).__init__()
self.setWidgetResizable(True) self.setWidgetResizable(True)
self.setupUi(self) self.setupUi(self)
self.path = path self.path = path
self.core = core
self.manager = QNetworkAccessManager() self.manager = QNetworkAccessManager()
self.free_games_widget = QWidget() self.free_games_widget = QWidget()
self.free_games_widget.setLayout(FlowLayout()) self.free_games_widget.setLayout(FlowLayout())
@ -53,23 +55,24 @@ class ShopWidget(QScrollArea, Ui_ShopWidget):
self.search_bar.returnPressed.connect(self.show_search_results) self.search_bar.returnPressed.connect(self.show_search_results)
self.search_bar.buttonClicked.connect(self.show_search_results) self.search_bar.buttonClicked.connect(self.show_search_results)
self.games_groupbox.setLayout(FlowLayout())
self.games_groupbox.setVisible(False)
self.search_request_manager = QtRequestManager("json") self.search_request_manager = QtRequestManager("json")
self.search_request_manager.data_ready.connect(self.set_completer) self.search_request_manager.data_ready.connect(self.set_completer)
self.search_bar.textChanged.connect(self.load_completer) self.search_bar.textChanged.connect(self.load_completer)
self.wishlist_gb.setLayout(FlowLayout())
self.wishlist_gb.setVisible(False)
self.locale = get_lang()
def load_completer(self, text): def load_completer(self, text):
if text != "": if text != "":
locale = get_lang()
payload = { payload = {
"query": search_query, "query": search_query,
"variables": {"category": "games/edition/base|bundles/games|editors|software/edition/base", "variables": {"category": "games/edition/base|bundles/games|editors|software/edition/base",
"count": 20, "count": 20,
"country": locale.upper(), "keywords": text, "locale": locale, "sortDir": "DESC", "country": self.locale.upper(), "keywords": text, "locale": self.locale,
"allowCountries": locale.upper(), "sortDir": "DESC",
"allowCountries": self.locale.upper(),
"start": 0, "tag": "", "withMapping": False, "withPrice": True} "start": 0, "tag": "", "withMapping": False, "withPrice": True}
} }
self.search_request_manager.post("https://www.epicgames.com/graphql", payload) self.search_request_manager.post("https://www.epicgames.com/graphql", payload)
@ -78,9 +81,37 @@ class ShopWidget(QScrollArea, Ui_ShopWidget):
url = "https://store-site-backend-static.ak.epicgames.com/freeGamesPromotions" url = "https://store-site-backend-static.ak.epicgames.com/freeGamesPromotions"
self.free_game_request_manager = QtRequestManager("json") self.free_game_request_manager = QtRequestManager("json")
self.free_game_request_manager.get(url) self.free_game_request_manager.get(url)
self.free_game_request_manager.data_ready.connect(self.add_free_games) self.free_game_request_manager.data_ready.connect(
self.add_free_games)
self.wishlist_manager = QtRequestManager("json")
self.wishlist_manager.data_ready.connect(self.add_wishlist)
wish_list_url = "https://www.epicgames.com/graphql"
self.wishlist_manager.post(wish_list_url,
payload={
"query": wishlist_query,
"variables": {
"country": self.locale.upper(),
"locale": self.locale
}
},
headers={"Authorization": self.core.egs.session.headers["Authorization"]})
def add_wishlist(self, wishlist):
wishlist = wishlist["data"]["Wishlist"]["wishlistItems"]["elements"]
discounts = 0
for game in wishlist:
if game["offer"]["price"]["totalPrice"]["discount"] > 0:
w = GameWidgetDiscount(self.path, game["offer"])
w.show_info.connect(self.show_game.emit)
self.wishlist_gb.layout().addWidget(w)
discounts += 1
if discounts != 0:
self.wishlist_gb.setVisible(True)
def add_free_games(self, free_games): def add_free_games(self, free_games):
self.free_game_request_manager.deleteLater()
free_games = free_games["data"]["Catalog"]["searchStore"]["elements"] free_games = free_games["data"]["Catalog"]["searchStore"]["elements"]
date = datetime.datetime.now() date = datetime.datetime.now()
free_games_now = [] free_games_now = []

View file

@ -33,9 +33,9 @@ class Ui_ShopWidget(object):
self.free_games_stack.setObjectName("free_games_stack") self.free_games_stack.setObjectName("free_games_stack")
self.verticalLayout_2.addWidget(self.free_games_stack) self.verticalLayout_2.addWidget(self.free_games_stack)
self.verticalLayout_3.addWidget(self.free_game_group_box) self.verticalLayout_3.addWidget(self.free_game_group_box)
self.games_groupbox = QtWidgets.QGroupBox(self.scrollAreaWidgetContents) self.wishlist_gb = QtWidgets.QGroupBox(self.scrollAreaWidgetContents)
self.games_groupbox.setObjectName("games_groupbox") self.wishlist_gb.setObjectName("wishlist_gb")
self.verticalLayout_3.addWidget(self.games_groupbox) self.verticalLayout_3.addWidget(self.wishlist_gb)
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_3.addItem(spacerItem) self.verticalLayout_3.addItem(spacerItem)
self.scrollArea.setWidget(self.scrollAreaWidgetContents) self.scrollArea.setWidget(self.scrollAreaWidgetContents)
@ -49,7 +49,7 @@ class Ui_ShopWidget(object):
_translate = QtCore.QCoreApplication.translate _translate = QtCore.QCoreApplication.translate
ShopWidget.setWindowTitle(_translate("ShopWidget", "Form")) ShopWidget.setWindowTitle(_translate("ShopWidget", "Form"))
self.free_game_group_box.setTitle(_translate("ShopWidget", "Free Games")) self.free_game_group_box.setTitle(_translate("ShopWidget", "Free Games"))
self.games_groupbox.setTitle(_translate("ShopWidget", "Other nice games")) self.wishlist_gb.setTitle(_translate("ShopWidget", "Discounts from your wishlist"))
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -46,10 +46,10 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="games_groupbox"> <widget class="QGroupBox" name="wishlist_gb">
<property name="title"> <property name="title">
<string>Other nice games</string> <string>Discounts from your wishlist</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>

View file

@ -354,12 +354,15 @@ class QtRequestManager(QObject):
else: else:
self.next_request = ["", tuple(())] self.next_request = ["", tuple(())]
def post(self, url: str, payload: dict): def post(self, url: str, payload: dict, headers: dict = None):
if not self.request_active: if not self.request_active:
request = QNetworkRequest(QUrl(url)) request = QNetworkRequest(QUrl(url))
request.setHeader(QNetworkRequest.ContentTypeHeader, "application/json") request.setHeader(QNetworkRequest.ContentTypeHeader, "application/json")
payload = json.dumps(payload).encode("utf-8") payload = json.dumps(payload).encode("utf-8")
if headers is not None:
for key, value in headers.items():
request.setRawHeader(key.encode(), value.encode())
self.request = self.manager.post(request, payload) self.request = self.manager.post(request, payload)
self.request_active = True self.request_active = True