mirror of
https://invent.kde.org/marcoa/a-la-karte.git
synced 2026-03-27 09:13:09 +00:00
70 lines
1.8 KiB
C
70 lines
1.8 KiB
C
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||
|
|
// SPDX-FileCopyrightText: 2026 A-La-Karte Contributors
|
||
|
|
|
||
|
|
#pragma once
|
||
|
|
|
||
|
|
#include <QNetworkAccessManager>
|
||
|
|
#include <QObject>
|
||
|
|
#include <QUrl>
|
||
|
|
|
||
|
|
class Game;
|
||
|
|
|
||
|
|
class SteamGridDB : public QObject
|
||
|
|
{
|
||
|
|
Q_OBJECT
|
||
|
|
Q_PROPERTY(QString apiKey READ apiKey WRITE setApiKey NOTIFY apiKeyChanged)
|
||
|
|
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
|
||
|
|
Q_PROPERTY(bool preferSteamGridDB READ preferSteamGridDB WRITE setPreferSteamGridDB NOTIFY preferSteamGridDBChanged)
|
||
|
|
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
|
||
|
|
|
||
|
|
public:
|
||
|
|
explicit SteamGridDB(QObject *parent = nullptr);
|
||
|
|
|
||
|
|
QString apiKey() const;
|
||
|
|
void setApiKey(const QString &key);
|
||
|
|
|
||
|
|
bool enabled() const;
|
||
|
|
void setEnabled(bool enabled);
|
||
|
|
|
||
|
|
bool preferSteamGridDB() const;
|
||
|
|
void setPreferSteamGridDB(bool prefer);
|
||
|
|
|
||
|
|
bool busy() const;
|
||
|
|
|
||
|
|
Q_INVOKABLE void fetchCover(Game *game);
|
||
|
|
Q_INVOKABLE void fetchAllCovers();
|
||
|
|
|
||
|
|
Q_SIGNALS:
|
||
|
|
void apiKeyChanged();
|
||
|
|
void enabledChanged();
|
||
|
|
void preferSteamGridDBChanged();
|
||
|
|
void busyChanged();
|
||
|
|
void coverFetched(Game *game, const QUrl &coverUrl);
|
||
|
|
void fetchError(Game *game, const QString &error);
|
||
|
|
void fetchProgress(int current, int total);
|
||
|
|
|
||
|
|
private Q_SLOTS:
|
||
|
|
void onSearchFinished();
|
||
|
|
void onGridsFinished();
|
||
|
|
void onImageDownloaded();
|
||
|
|
|
||
|
|
private:
|
||
|
|
void searchGame(Game *game);
|
||
|
|
void fetchGrids(Game *game, int gameId);
|
||
|
|
void downloadImage(Game *game, const QUrl &imageUrl);
|
||
|
|
void saveSettings();
|
||
|
|
void loadSettings();
|
||
|
|
void processNextGame();
|
||
|
|
|
||
|
|
QNetworkAccessManager *m_networkManager;
|
||
|
|
QString m_apiKey;
|
||
|
|
bool m_enabled = false;
|
||
|
|
bool m_preferSteamGridDB = false;
|
||
|
|
bool m_busy = false;
|
||
|
|
|
||
|
|
QList<Game *> m_pendingGames;
|
||
|
|
Game *m_currentGame = nullptr;
|
||
|
|
int m_totalGames = 0;
|
||
|
|
int m_processedGames = 0;
|
||
|
|
};
|