Commit 4777d18f authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files

added error messages to oracle importer

parent 8971a10c
......@@ -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<SetToDownload> 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)
......
......@@ -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<SetToDownload> &getSets() { return allSets; }
......
......@@ -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<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();
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)
......
......@@ -31,6 +31,7 @@ private:
QTextEdit *messageLog;
QVBoxLayout *checkBoxLayout;
QList<QCheckBox *> checkBoxList;
QLabel *statusLabel;
void downloadSetsFile(const QString &url);
private slots:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment