Oracle: follow redirects
This commit is contained in:
parent
f7f9827b91
commit
bacb289eff
2 changed files with 43 additions and 15 deletions
|
@ -292,13 +292,7 @@ bool LoadSetsPage::validatePage()
|
|||
wizard()->disableButtons();
|
||||
setEnabled(false);
|
||||
|
||||
if(!nam)
|
||||
nam = new QNetworkAccessManager(this);
|
||||
QNetworkReply *reply = nam->get(QNetworkRequest(url));
|
||||
|
||||
connect(reply, SIGNAL(finished()), this, SLOT(actDownloadFinishedSetsFile()));
|
||||
connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(actDownloadProgressSetsFile(qint64, qint64)));
|
||||
|
||||
downloadSetsFile(url);
|
||||
} else if(fileRadioButton->isChecked()) {
|
||||
QFile setsFile(fileLineEdit->text());
|
||||
if(!setsFile.exists())
|
||||
|
@ -321,6 +315,16 @@ bool LoadSetsPage::validatePage()
|
|||
return false;
|
||||
}
|
||||
|
||||
void LoadSetsPage::downloadSetsFile(QUrl url)
|
||||
{
|
||||
if(!nam)
|
||||
nam = new QNetworkAccessManager(this);
|
||||
QNetworkReply *reply = nam->get(QNetworkRequest(url));
|
||||
|
||||
connect(reply, SIGNAL(finished()), this, SLOT(actDownloadFinishedSetsFile()));
|
||||
connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(actDownloadProgressSetsFile(qint64, qint64)));
|
||||
}
|
||||
|
||||
void LoadSetsPage::actDownloadProgressSetsFile(qint64 received, qint64 total)
|
||||
{
|
||||
if(total > 0)
|
||||
|
@ -333,9 +337,6 @@ void LoadSetsPage::actDownloadProgressSetsFile(qint64 received, qint64 total)
|
|||
|
||||
void LoadSetsPage::actDownloadFinishedSetsFile()
|
||||
{
|
||||
progressLabel->hide();
|
||||
progressBar->hide();
|
||||
|
||||
// check for a reply
|
||||
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
|
||||
QNetworkReply::NetworkError errorCode = reply->error();
|
||||
|
@ -349,6 +350,18 @@ void LoadSetsPage::actDownloadFinishedSetsFile()
|
|||
return;
|
||||
}
|
||||
|
||||
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
if (statusCode == 301 || statusCode == 302) {
|
||||
QUrl redirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
|
||||
qDebug() << "following redirect url:" << redirectUrl.toString();
|
||||
downloadSetsFile(redirectUrl);
|
||||
reply->deleteLater();
|
||||
return;
|
||||
}
|
||||
|
||||
progressLabel->hide();
|
||||
progressBar->hide();
|
||||
|
||||
// save allsets.json url, but only if the user customized it and download was successfull
|
||||
if(urlLineEdit->text() != QString(ALLSETS_URL))
|
||||
wizard()->settings->setValue("allsetsurl", urlLineEdit->text());
|
||||
|
@ -641,14 +654,18 @@ bool LoadTokensPage::validatePage()
|
|||
wizard()->disableButtons();
|
||||
setEnabled(false);
|
||||
|
||||
downloadTokensFile(url);
|
||||
return false;
|
||||
}
|
||||
|
||||
void LoadTokensPage::downloadTokensFile(QUrl url)
|
||||
{
|
||||
if(!nam)
|
||||
nam = new QNetworkAccessManager(this);
|
||||
QNetworkReply *reply = nam->get(QNetworkRequest(url));
|
||||
|
||||
connect(reply, SIGNAL(finished()), this, SLOT(actDownloadFinishedTokensFile()));
|
||||
connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(actDownloadProgressTokensFile(qint64, qint64)));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void LoadTokensPage::actDownloadProgressTokensFile(qint64 received, qint64 total)
|
||||
|
@ -663,9 +680,6 @@ void LoadTokensPage::actDownloadProgressTokensFile(qint64 received, qint64 total
|
|||
|
||||
void LoadTokensPage::actDownloadFinishedTokensFile()
|
||||
{
|
||||
progressLabel->hide();
|
||||
progressBar->hide();
|
||||
|
||||
// check for a reply
|
||||
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
|
||||
QNetworkReply::NetworkError errorCode = reply->error();
|
||||
|
@ -679,6 +693,18 @@ void LoadTokensPage::actDownloadFinishedTokensFile()
|
|||
return;
|
||||
}
|
||||
|
||||
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
if (statusCode == 301 || statusCode == 302) {
|
||||
QUrl redirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
|
||||
qDebug() << "following redirect url:" << redirectUrl.toString();
|
||||
downloadTokensFile(redirectUrl);
|
||||
reply->deleteLater();
|
||||
return;
|
||||
}
|
||||
|
||||
progressLabel->hide();
|
||||
progressBar->hide();
|
||||
|
||||
// save tokens.xml url, but only if the user customized it and download was successfull
|
||||
if(urlLineEdit->text() != QString(TOKENS_URL))
|
||||
wizard()->settings->setValue("tokensurl", urlLineEdit->text());
|
||||
|
|
|
@ -80,6 +80,7 @@ protected:
|
|||
void initializePage();
|
||||
bool validatePage();
|
||||
void readSetsFromByteArray(QByteArray data);
|
||||
void downloadSetsFile(QUrl url);
|
||||
private:
|
||||
QRadioButton *urlRadioButton;
|
||||
QRadioButton *fileRadioButton;
|
||||
|
@ -128,6 +129,7 @@ public:
|
|||
protected:
|
||||
void initializePage();
|
||||
bool validatePage();
|
||||
void downloadTokensFile(QUrl url);
|
||||
private:
|
||||
QLabel *urlLabel;
|
||||
QLineEdit *urlLineEdit;
|
||||
|
|
Loading…
Reference in a new issue