mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-23 15:13:55 -07:00
added error messages to oracle importer
This commit is contained in:
parent
8971a10c80
commit
4777d18fe3
4 changed files with 34 additions and 15 deletions
|
|
@ -15,27 +15,27 @@ OracleImporter::OracleImporter(const QString &_dataDir, QObject *parent)
|
||||||
connect(http, SIGNAL(dataReadProgress(int, int)), this, SIGNAL(dataReadProgress(int, int)));
|
connect(http, SIGNAL(dataReadProgress(int, int)), this, SIGNAL(dataReadProgress(int, int)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OracleImporter::readSetsFromFile(const QString &fileName)
|
bool OracleImporter::readSetsFromFile(const QString &fileName)
|
||||||
{
|
{
|
||||||
QFile setsFile(fileName);
|
QFile setsFile(fileName);
|
||||||
if (!setsFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
if (!setsFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
QMessageBox::critical(0, tr("Error"), tr("Cannot open file '%1'.").arg(fileName));
|
QMessageBox::critical(0, tr("Error"), tr("Cannot open file '%1'.").arg(fileName));
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QXmlStreamReader xml(&setsFile);
|
QXmlStreamReader xml(&setsFile);
|
||||||
readSetsFromXml(xml);
|
return readSetsFromXml(xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OracleImporter::readSetsFromByteArray(const QByteArray &data)
|
bool OracleImporter::readSetsFromByteArray(const QByteArray &data)
|
||||||
{
|
{
|
||||||
QXmlStreamReader xml(data);
|
QXmlStreamReader xml(data);
|
||||||
readSetsFromXml(xml);
|
return readSetsFromXml(xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OracleImporter::readSetsFromXml(QXmlStreamReader &xml)
|
bool OracleImporter::readSetsFromXml(QXmlStreamReader &xml)
|
||||||
{
|
{
|
||||||
allSets.clear();
|
QList<SetToDownload> newSetList;
|
||||||
|
|
||||||
QString edition;
|
QString edition;
|
||||||
QString editionLong;
|
QString editionLong;
|
||||||
|
|
@ -56,7 +56,7 @@ void OracleImporter::readSetsFromXml(QXmlStreamReader &xml)
|
||||||
else if (xml.name() == "url")
|
else if (xml.name() == "url")
|
||||||
editionURL = xml.readElementText();
|
editionURL = xml.readElementText();
|
||||||
}
|
}
|
||||||
allSets << SetToDownload(edition, editionLong, editionURL, import);
|
newSetList.append(SetToDownload(edition, editionLong, editionURL, import));
|
||||||
edition = editionLong = editionURL = QString();
|
edition = editionLong = editionURL = QString();
|
||||||
} else if (xml.name() == "picture_url")
|
} else if (xml.name() == "picture_url")
|
||||||
pictureUrl = xml.readElementText();
|
pictureUrl = xml.readElementText();
|
||||||
|
|
@ -67,6 +67,10 @@ void OracleImporter::readSetsFromXml(QXmlStreamReader &xml)
|
||||||
else if (xml.name() == "set_url")
|
else if (xml.name() == "set_url")
|
||||||
setUrl = xml.readElementText();
|
setUrl = xml.readElementText();
|
||||||
}
|
}
|
||||||
|
if (newSetList.isEmpty())
|
||||||
|
return false;
|
||||||
|
allSets = newSetList;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardInfo *OracleImporter::addCard(const QString &setName, QString cardName, int cardId, const QString &cardCost, const QString &cardType, const QString &cardPT, const QStringList &cardText)
|
CardInfo *OracleImporter::addCard(const QString &setName, QString cardName, int cardId, const QString &cardCost, const QString &cardType, const QString &cardPT, const QStringList &cardText)
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ private:
|
||||||
QString getPictureUrl(QString url, int cardId, QString name, const QString &setName) const;
|
QString getPictureUrl(QString url, int cardId, QString name, const QString &setName) const;
|
||||||
|
|
||||||
void downloadNextFile();
|
void downloadNextFile();
|
||||||
void readSetsFromXml(QXmlStreamReader &xml);
|
bool readSetsFromXml(QXmlStreamReader &xml);
|
||||||
CardInfo *addCard(const QString &setName, QString cardName, int cardId, const QString &cardCost, const QString &cardType, const QString &cardPT, const QStringList &cardText);
|
CardInfo *addCard(const QString &setName, QString cardName, int cardId, const QString &cardCost, const QString &cardType, const QString &cardPT, const QStringList &cardText);
|
||||||
private slots:
|
private slots:
|
||||||
void httpRequestFinished(int requestId, bool error);
|
void httpRequestFinished(int requestId, bool error);
|
||||||
|
|
@ -44,8 +44,8 @@ signals:
|
||||||
void dataReadProgress(int bytesRead, int totalBytes);
|
void dataReadProgress(int bytesRead, int totalBytes);
|
||||||
public:
|
public:
|
||||||
OracleImporter(const QString &_dataDir, QObject *parent = 0);
|
OracleImporter(const QString &_dataDir, QObject *parent = 0);
|
||||||
void readSetsFromByteArray(const QByteArray &data);
|
bool readSetsFromByteArray(const QByteArray &data);
|
||||||
void readSetsFromFile(const QString &fileName);
|
bool readSetsFromFile(const QString &fileName);
|
||||||
int startDownload();
|
int startDownload();
|
||||||
int importTextSpoiler(CardSet *set, const QByteArray &data);
|
int importTextSpoiler(CardSet *set, const QByteArray &data);
|
||||||
QList<SetToDownload> &getSets() { return allSets; }
|
QList<SetToDownload> &getSets() { return allSets; }
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,10 @@ WindowMain::WindowMain(QWidget *parent)
|
||||||
QStringList args = qApp->arguments();
|
QStringList args = qApp->arguments();
|
||||||
if (args.contains("-dlsets"))
|
if (args.contains("-dlsets"))
|
||||||
downloadSetsFile(defaultSetsUrl);
|
downloadSetsFile(defaultSetsUrl);
|
||||||
|
|
||||||
|
statusLabel = new QLabel;
|
||||||
|
statusBar()->addWidget(statusLabel);
|
||||||
|
statusLabel->setText(tr("Sets data not loaded."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowMain::updateSetList()
|
void WindowMain::updateSetList()
|
||||||
|
|
@ -110,6 +114,7 @@ void WindowMain::updateSetList()
|
||||||
checkBoxLayout->addWidget(checkBox);
|
checkBoxLayout->addWidget(checkBox);
|
||||||
checkBoxList << checkBox;
|
checkBoxList << checkBox;
|
||||||
}
|
}
|
||||||
|
statusLabel->setText(tr("Ready."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowMain::actLoadSetsFile()
|
void WindowMain::actLoadSetsFile()
|
||||||
|
|
@ -121,8 +126,10 @@ void WindowMain::actLoadSetsFile()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString fileName = dialog.selectedFiles().at(0);
|
QString fileName = dialog.selectedFiles().at(0);
|
||||||
importer->readSetsFromFile(fileName);
|
if (importer->readSetsFromFile(fileName))
|
||||||
updateSetList();
|
updateSetList();
|
||||||
|
else
|
||||||
|
QMessageBox::critical(this, tr("Error"), tr("This file does not contain any sets data."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowMain::actDownloadSetsFile()
|
void WindowMain::actDownloadSetsFile()
|
||||||
|
|
@ -141,9 +148,15 @@ void WindowMain::downloadSetsFile(const QString &url)
|
||||||
void WindowMain::setsDownloadFinished()
|
void WindowMain::setsDownloadFinished()
|
||||||
{
|
{
|
||||||
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
|
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
|
||||||
importer->readSetsFromByteArray(reply->readAll());
|
QNetworkReply::NetworkError errorCode = reply->error();
|
||||||
|
if (errorCode == QNetworkReply::NoError) {
|
||||||
|
if (importer->readSetsFromByteArray(reply->readAll()))
|
||||||
|
updateSetList();
|
||||||
|
else
|
||||||
|
QMessageBox::critical(this, tr("Error"), tr("The file was retrieved successfully, but it does not contain any sets data."));
|
||||||
|
} else
|
||||||
|
QMessageBox::critical(this, tr("Error"), tr("Network error: %1.").arg(reply->errorString()));
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
updateSetList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowMain::updateTotalProgress(int cardsImported, int setIndex, const QString &nextSetName)
|
void WindowMain::updateTotalProgress(int cardsImported, int setIndex, const QString &nextSetName)
|
||||||
|
|
@ -205,6 +218,7 @@ void WindowMain::actStart()
|
||||||
checkBoxList[i]->setEnabled(false);
|
checkBoxList[i]->setEnabled(false);
|
||||||
startButton->setEnabled(false);
|
startButton->setEnabled(false);
|
||||||
totalProgressBar->setMaximum(setsCount);
|
totalProgressBar->setMaximum(setsCount);
|
||||||
|
statusLabel->setText(tr("Downloading card data..."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowMain::checkBoxChanged(int state)
|
void WindowMain::checkBoxChanged(int state)
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ private:
|
||||||
QTextEdit *messageLog;
|
QTextEdit *messageLog;
|
||||||
QVBoxLayout *checkBoxLayout;
|
QVBoxLayout *checkBoxLayout;
|
||||||
QList<QCheckBox *> checkBoxList;
|
QList<QCheckBox *> checkBoxList;
|
||||||
|
QLabel *statusLabel;
|
||||||
|
|
||||||
void downloadSetsFile(const QString &url);
|
void downloadSetsFile(const QString &url);
|
||||||
private slots:
|
private slots:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue