mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-11 12:33:25 -08:00
[Oracle] Add a tag data step to the import wizard
Insert a Tags page between set selection and the import. It downloads Scryfall's Oracle Tags by default (or a user-supplied file/URL), can include parent tags, and persists tagsenabled, tagssource and tagsparents in oracle.ini. The page loads asynchronously and soft-fails in background mode, so a tag download or parse error never aborts the card database import.
This commit is contained in:
parent
77179f913e
commit
5582284991
4 changed files with 533 additions and 1 deletions
|
|
@ -6,21 +6,25 @@
|
|||
#include <QByteArray>
|
||||
#include <QFuture>
|
||||
#include <QFutureWatcher>
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QtGlobal>
|
||||
#include <memory>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
class QCheckBox;
|
||||
class QComboBox;
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
class QNetworkReply;
|
||||
class QRadioButton;
|
||||
class QProgressBar;
|
||||
class QTextEdit;
|
||||
class QPushButton;
|
||||
class QUrl;
|
||||
class QWidget;
|
||||
class TagDatabase;
|
||||
|
||||
class IntroPage : public OracleWizardPage
|
||||
{
|
||||
|
|
@ -109,6 +113,71 @@ private slots:
|
|||
void zipDownloadFailed(const QString &message);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Optional wizard step that loads the tag database used by the importer.
|
||||
*
|
||||
* Reloading is skipped when the source and parent-tag setting are unchanged, so
|
||||
* going back and forth through the wizard does not re-download the tag data.
|
||||
*/
|
||||
class TagsPage : public OracleWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TagsPage(QWidget *parent = nullptr);
|
||||
void retranslateUi() override;
|
||||
bool isComplete() const override;
|
||||
|
||||
protected:
|
||||
void initializePage() override;
|
||||
bool validatePage() override;
|
||||
void cancelWork() override;
|
||||
|
||||
private:
|
||||
struct LoadResult
|
||||
{
|
||||
std::shared_ptr<TagDatabase> database;
|
||||
QString errorMessage;
|
||||
};
|
||||
|
||||
QCheckBox *enableCheckBox;
|
||||
QRadioButton *urlRadioButton;
|
||||
QRadioButton *fileRadioButton;
|
||||
QLineEdit *urlLineEdit;
|
||||
QLineEdit *fileLineEdit;
|
||||
QPushButton *urlButton;
|
||||
QPushButton *fileButton;
|
||||
QCheckBox *parentsCheckBox;
|
||||
QLabel *statusLabel;
|
||||
QLabel *progressLabel;
|
||||
QProgressBar *progressBar;
|
||||
|
||||
QFutureWatcher<LoadResult> watcher;
|
||||
QFuture<LoadResult> future;
|
||||
QPointer<QNetworkReply> activeReply;
|
||||
bool loadActive = false;
|
||||
QString loadedSource;
|
||||
bool loadedParents = false;
|
||||
|
||||
[[nodiscard]] QString selectedSource() const;
|
||||
void updateSourceEnabled();
|
||||
void saveSettings();
|
||||
void beginLoad(const QByteArray &data);
|
||||
void loadFromFile(const QString &path);
|
||||
void downloadMetadata(const QUrl &url);
|
||||
void downloadTagFile(const QUrl &url);
|
||||
void finishLoad();
|
||||
void failLoad(const QString &message);
|
||||
void advance();
|
||||
|
||||
private slots:
|
||||
void actChooseFile();
|
||||
void actRestoreDefaultSource();
|
||||
void actDownloadProgress(qint64 received, qint64 total);
|
||||
void actMetadataFinished();
|
||||
void actTagFileFinished();
|
||||
void actLoadFinished();
|
||||
};
|
||||
|
||||
class SaveSetsPage : public OracleWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue