diff --git a/oracle/src/oracleimporter.cpp b/oracle/src/oracleimporter.cpp index 5aa2b99fc..add5e538b 100644 --- a/oracle/src/oracleimporter.cpp +++ b/oracle/src/oracleimporter.cpp @@ -15,27 +15,27 @@ OracleImporter::OracleImporter(const QString &_dataDir, QObject *parent) 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); if (!setsFile.open(QIODevice::ReadOnly | QIODevice::Text)) { QMessageBox::critical(0, tr("Error"), tr("Cannot open file '%1'.").arg(fileName)); - return; + return false; } QXmlStreamReader xml(&setsFile); - readSetsFromXml(xml); + return readSetsFromXml(xml); } -void OracleImporter::readSetsFromByteArray(const QByteArray &data) +bool OracleImporter::readSetsFromByteArray(const QByteArray &data) { QXmlStreamReader xml(data); - readSetsFromXml(xml); + return readSetsFromXml(xml); } -void OracleImporter::readSetsFromXml(QXmlStreamReader &xml) +bool OracleImporter::readSetsFromXml(QXmlStreamReader &xml) { - allSets.clear(); + QList newSetList; QString edition; QString editionLong; @@ -56,7 +56,7 @@ void OracleImporter::readSetsFromXml(QXmlStreamReader &xml) else if (xml.name() == "url") editionURL = xml.readElementText(); } - allSets << SetToDownload(edition, editionLong, editionURL, import); + newSetList.append(SetToDownload(edition, editionLong, editionURL, import)); edition = editionLong = editionURL = QString(); } else if (xml.name() == "picture_url") pictureUrl = xml.readElementText(); @@ -67,6 +67,10 @@ void OracleImporter::readSetsFromXml(QXmlStreamReader &xml) else if (xml.name() == "set_url") 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) diff --git a/oracle/src/oracleimporter.h b/oracle/src/oracleimporter.h index afee515fa..3f6e4899f 100644 --- a/oracle/src/oracleimporter.h +++ b/oracle/src/oracleimporter.h @@ -34,7 +34,7 @@ private: QString getPictureUrl(QString url, int cardId, QString name, const QString &setName) const; 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); private slots: void httpRequestFinished(int requestId, bool error); @@ -44,8 +44,8 @@ signals: void dataReadProgress(int bytesRead, int totalBytes); public: OracleImporter(const QString &_dataDir, QObject *parent = 0); - void readSetsFromByteArray(const QByteArray &data); - void readSetsFromFile(const QString &fileName); + bool readSetsFromByteArray(const QByteArray &data); + bool readSetsFromFile(const QString &fileName); int startDownload(); int importTextSpoiler(CardSet *set, const QByteArray &data); QList &getSets() { return allSets; } diff --git a/oracle/src/window_main.cpp b/oracle/src/window_main.cpp index 8f8f9aef4..9cf164e8d 100644 --- a/oracle/src/window_main.cpp +++ b/oracle/src/window_main.cpp @@ -94,6 +94,10 @@ WindowMain::WindowMain(QWidget *parent) QStringList args = qApp->arguments(); if (args.contains("-dlsets")) downloadSetsFile(defaultSetsUrl); + + statusLabel = new QLabel; + statusBar()->addWidget(statusLabel); + statusLabel->setText(tr("Sets data not loaded.")); } void WindowMain::updateSetList() @@ -110,6 +114,7 @@ void WindowMain::updateSetList() checkBoxLayout->addWidget(checkBox); checkBoxList << checkBox; } + statusLabel->setText(tr("Ready.")); } void WindowMain::actLoadSetsFile() @@ -121,8 +126,10 @@ void WindowMain::actLoadSetsFile() return; QString fileName = dialog.selectedFiles().at(0); - importer->readSetsFromFile(fileName); - updateSetList(); + if (importer->readSetsFromFile(fileName)) + updateSetList(); + else + QMessageBox::critical(this, tr("Error"), tr("This file does not contain any sets data.")); } void WindowMain::actDownloadSetsFile() @@ -141,9 +148,15 @@ void WindowMain::downloadSetsFile(const QString &url) void WindowMain::setsDownloadFinished() { QNetworkReply *reply = static_cast(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(); - updateSetList(); } void WindowMain::updateTotalProgress(int cardsImported, int setIndex, const QString &nextSetName) @@ -205,6 +218,7 @@ void WindowMain::actStart() checkBoxList[i]->setEnabled(false); startButton->setEnabled(false); totalProgressBar->setMaximum(setsCount); + statusLabel->setText(tr("Downloading card data...")); } void WindowMain::checkBoxChanged(int state) diff --git a/oracle/src/window_main.h b/oracle/src/window_main.h index afcf897db..1fdba235b 100644 --- a/oracle/src/window_main.h +++ b/oracle/src/window_main.h @@ -31,6 +31,7 @@ private: QTextEdit *messageLog; QVBoxLayout *checkBoxLayout; QList checkBoxList; + QLabel *statusLabel; void downloadSetsFile(const QString &url); private slots: