mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Automatic Card Database Updates (#6004)
* Add the option to background the oracle wizard, add an option to automatically launch oracle wizard in background every X days since last launch. * Mocks and a typo. * Lint. * Lint? * qOverload the spinBox. * Change to a prompt instead. * An Label. * Update window_main.cpp --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de> Co-authored-by: Zach H <zahalpern+github@gmail.com>
This commit is contained in:
parent
76fdbfaa2f
commit
f3913949b2
16 changed files with 360 additions and 17 deletions
|
|
@ -8,6 +8,7 @@
|
|||
#include <QCommandLineParser>
|
||||
#include <QIcon>
|
||||
#include <QLibraryInfo>
|
||||
#include <QTimer>
|
||||
#include <QTranslator>
|
||||
|
||||
QTranslator *translator, *qtTranslator;
|
||||
|
|
@ -16,6 +17,7 @@ ThemeManager *themeManager;
|
|||
const QString translationPrefix = "oracle";
|
||||
QString translationPath;
|
||||
bool isSpoilersOnly;
|
||||
bool isBackgrounded;
|
||||
|
||||
void installNewTranslator()
|
||||
{
|
||||
|
|
@ -57,10 +59,13 @@ int main(int argc, char *argv[])
|
|||
|
||||
// If the program is opened with the -s flag, it will only do spoilers. Otherwise it will do MTGJSON/Tokens
|
||||
QCommandLineParser parser;
|
||||
QCommandLineOption showProgressOption("s", QCoreApplication::translate("main", "Only run in spoiler mode"));
|
||||
parser.addOption(showProgressOption);
|
||||
QCommandLineOption spoilersOnlyOption("s", QCoreApplication::translate("main", "Only run in spoiler mode"));
|
||||
QCommandLineOption backgroundOption("b", QCoreApplication::translate("main", "Run in no-confirm background mode"));
|
||||
parser.addOption(spoilersOnlyOption);
|
||||
parser.addOption(backgroundOption);
|
||||
parser.process(app);
|
||||
isSpoilersOnly = parser.isSet(showProgressOption);
|
||||
isSpoilersOnly = parser.isSet(spoilersOnlyOption);
|
||||
isBackgrounded = parser.isSet(backgroundOption);
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
translationPath = qApp->applicationDirPath() + "/../Resources/translations";
|
||||
|
|
@ -85,5 +90,9 @@ int main(int argc, char *argv[])
|
|||
|
||||
wizard.show();
|
||||
|
||||
if (isBackgrounded) {
|
||||
QTimer::singleShot(0, &wizard, [&wizard]() { wizard.runInBackground(); });
|
||||
}
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,15 +64,23 @@ OracleWizard::OracleWizard(QWidget *parent) : QWizard(parent)
|
|||
|
||||
nam = new QNetworkAccessManager(this);
|
||||
|
||||
QList<OracleWizardPage *> pages;
|
||||
|
||||
if (!isSpoilersOnly) {
|
||||
addPage(new IntroPage);
|
||||
addPage(new LoadSetsPage);
|
||||
addPage(new SaveSetsPage);
|
||||
addPage(new LoadTokensPage);
|
||||
addPage(new OutroPage);
|
||||
pages << new IntroPage << new LoadSetsPage << new SaveSetsPage << new LoadTokensPage << new OutroPage;
|
||||
} else {
|
||||
addPage(new LoadSpoilersPage);
|
||||
addPage(new OutroPage);
|
||||
pages << new LoadSpoilersPage << new OutroPage;
|
||||
}
|
||||
|
||||
for (OracleWizardPage *page : pages) {
|
||||
addPage(page);
|
||||
|
||||
// Connect background auto-advance
|
||||
connect(page, &OracleWizardPage::readyToContinue, this, [this]() {
|
||||
if (backgroundMode) {
|
||||
next();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
retranslateUi();
|
||||
|
|
@ -169,6 +177,13 @@ IntroPage::IntroPage(QWidget *parent) : OracleWizardPage(parent)
|
|||
setLayout(layout);
|
||||
}
|
||||
|
||||
void IntroPage::initializePage()
|
||||
{
|
||||
if (wizard()->backgroundMode) {
|
||||
emit readyToContinue();
|
||||
}
|
||||
}
|
||||
|
||||
QStringList IntroPage::findQmFiles()
|
||||
{
|
||||
QDir dir(translationPath);
|
||||
|
|
@ -212,6 +227,14 @@ void OutroPage::retranslateUi()
|
|||
tr("If the card databases don't reload automatically, restart the Cockatrice client."));
|
||||
}
|
||||
|
||||
void OutroPage::initializePage()
|
||||
{
|
||||
if (wizard()->backgroundMode) {
|
||||
wizard()->accept();
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
LoadSetsPage::LoadSetsPage(QWidget *parent) : OracleWizardPage(parent)
|
||||
{
|
||||
urlRadioButton = new QRadioButton(this);
|
||||
|
|
@ -252,6 +275,12 @@ void LoadSetsPage::initializePage()
|
|||
|
||||
progressLabel->hide();
|
||||
progressBar->hide();
|
||||
|
||||
if (wizard()->backgroundMode) {
|
||||
if (isEnabled()) {
|
||||
validatePage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LoadSetsPage::retranslateUi()
|
||||
|
|
@ -616,6 +645,10 @@ void SaveSetsPage::initializePage()
|
|||
if (!wizard()->importer->startImport()) {
|
||||
QMessageBox::critical(this, tr("Error"), tr("No set has been imported."));
|
||||
}
|
||||
|
||||
if (wizard()->backgroundMode) {
|
||||
emit readyToContinue();
|
||||
}
|
||||
}
|
||||
|
||||
void SaveSetsPage::retranslateUi()
|
||||
|
|
@ -691,6 +724,15 @@ bool SaveSetsPage::validatePage()
|
|||
return true;
|
||||
}
|
||||
|
||||
void LoadTokensPage::initializePage()
|
||||
{
|
||||
SimpleDownloadFilePage::initializePage();
|
||||
|
||||
if (wizard()->backgroundMode) {
|
||||
emit readyToContinue();
|
||||
}
|
||||
}
|
||||
|
||||
QString LoadTokensPage::getDefaultUrl()
|
||||
{
|
||||
return TOKENS_URL;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QFuture>
|
||||
#include <QFutureWatcher>
|
||||
#include <QTimer>
|
||||
#include <QWizard>
|
||||
#include <utility>
|
||||
|
||||
|
|
@ -56,12 +57,20 @@ public:
|
|||
}
|
||||
bool saveTokensToFile(const QString &fileName);
|
||||
|
||||
void runInBackground()
|
||||
{
|
||||
backgroundMode = true;
|
||||
hide();
|
||||
currentPage()->initializePage();
|
||||
}
|
||||
|
||||
public:
|
||||
OracleImporter *importer;
|
||||
QSettings *settings;
|
||||
QNetworkAccessManager *nam;
|
||||
bool downloadedPlainXml = false;
|
||||
QByteArray xmlData;
|
||||
bool backgroundMode = false;
|
||||
|
||||
private slots:
|
||||
void updateLanguage();
|
||||
|
|
@ -92,6 +101,9 @@ private:
|
|||
|
||||
private slots:
|
||||
void languageBoxChanged(int index);
|
||||
|
||||
protected slots:
|
||||
void initializePage() override;
|
||||
};
|
||||
|
||||
class OutroPage : public OracleWizardPage
|
||||
|
|
@ -102,6 +114,9 @@ public:
|
|||
{
|
||||
}
|
||||
void retranslateUi() override;
|
||||
|
||||
protected:
|
||||
void initializePage() override;
|
||||
};
|
||||
|
||||
class LoadSetsPage : public OracleWizardPage
|
||||
|
|
@ -191,6 +206,7 @@ protected:
|
|||
QString getDefaultSavePath() override;
|
||||
QString getWindowTitle() override;
|
||||
QString getFileType() override;
|
||||
void initializePage() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ bool SimpleDownloadFilePage::validatePage()
|
|||
|
||||
QUrl url = QUrl::fromUserInput(urlLineEdit->text());
|
||||
if (!url.isValid()) {
|
||||
QMessageBox::critical(this, tr("Error"), tr("The provided URL is not valid."));
|
||||
QMessageBox::critical(this, tr("Error"), tr("The provided URL is not valid: ") + url.toString());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ public:
|
|||
explicit OracleWizardPage(QWidget *parent = nullptr) : QWizardPage(parent){};
|
||||
virtual void retranslateUi() = 0;
|
||||
|
||||
signals:
|
||||
void readyToContinue();
|
||||
|
||||
protected:
|
||||
inline OracleWizard *wizard()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue