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();
|
wizard()->disableButtons();
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
|
|
||||||
if(!nam)
|
downloadSetsFile(url);
|
||||||
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)));
|
|
||||||
|
|
||||||
} else if(fileRadioButton->isChecked()) {
|
} else if(fileRadioButton->isChecked()) {
|
||||||
QFile setsFile(fileLineEdit->text());
|
QFile setsFile(fileLineEdit->text());
|
||||||
if(!setsFile.exists())
|
if(!setsFile.exists())
|
||||||
|
@ -321,6 +315,16 @@ bool LoadSetsPage::validatePage()
|
||||||
return false;
|
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)
|
void LoadSetsPage::actDownloadProgressSetsFile(qint64 received, qint64 total)
|
||||||
{
|
{
|
||||||
if(total > 0)
|
if(total > 0)
|
||||||
|
@ -333,9 +337,6 @@ void LoadSetsPage::actDownloadProgressSetsFile(qint64 received, qint64 total)
|
||||||
|
|
||||||
void LoadSetsPage::actDownloadFinishedSetsFile()
|
void LoadSetsPage::actDownloadFinishedSetsFile()
|
||||||
{
|
{
|
||||||
progressLabel->hide();
|
|
||||||
progressBar->hide();
|
|
||||||
|
|
||||||
// check for a reply
|
// check for a reply
|
||||||
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
|
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
|
||||||
QNetworkReply::NetworkError errorCode = reply->error();
|
QNetworkReply::NetworkError errorCode = reply->error();
|
||||||
|
@ -349,6 +350,18 @@ void LoadSetsPage::actDownloadFinishedSetsFile()
|
||||||
return;
|
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
|
// save allsets.json url, but only if the user customized it and download was successfull
|
||||||
if(urlLineEdit->text() != QString(ALLSETS_URL))
|
if(urlLineEdit->text() != QString(ALLSETS_URL))
|
||||||
wizard()->settings->setValue("allsetsurl", urlLineEdit->text());
|
wizard()->settings->setValue("allsetsurl", urlLineEdit->text());
|
||||||
|
@ -641,14 +654,18 @@ bool LoadTokensPage::validatePage()
|
||||||
wizard()->disableButtons();
|
wizard()->disableButtons();
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
|
|
||||||
|
downloadTokensFile(url);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoadTokensPage::downloadTokensFile(QUrl url)
|
||||||
|
{
|
||||||
if(!nam)
|
if(!nam)
|
||||||
nam = new QNetworkAccessManager(this);
|
nam = new QNetworkAccessManager(this);
|
||||||
QNetworkReply *reply = nam->get(QNetworkRequest(url));
|
QNetworkReply *reply = nam->get(QNetworkRequest(url));
|
||||||
|
|
||||||
connect(reply, SIGNAL(finished()), this, SLOT(actDownloadFinishedTokensFile()));
|
connect(reply, SIGNAL(finished()), this, SLOT(actDownloadFinishedTokensFile()));
|
||||||
connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(actDownloadProgressTokensFile(qint64, qint64)));
|
connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(actDownloadProgressTokensFile(qint64, qint64)));
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadTokensPage::actDownloadProgressTokensFile(qint64 received, qint64 total)
|
void LoadTokensPage::actDownloadProgressTokensFile(qint64 received, qint64 total)
|
||||||
|
@ -663,9 +680,6 @@ void LoadTokensPage::actDownloadProgressTokensFile(qint64 received, qint64 total
|
||||||
|
|
||||||
void LoadTokensPage::actDownloadFinishedTokensFile()
|
void LoadTokensPage::actDownloadFinishedTokensFile()
|
||||||
{
|
{
|
||||||
progressLabel->hide();
|
|
||||||
progressBar->hide();
|
|
||||||
|
|
||||||
// check for a reply
|
// check for a reply
|
||||||
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
|
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
|
||||||
QNetworkReply::NetworkError errorCode = reply->error();
|
QNetworkReply::NetworkError errorCode = reply->error();
|
||||||
|
@ -679,6 +693,18 @@ void LoadTokensPage::actDownloadFinishedTokensFile()
|
||||||
return;
|
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
|
// save tokens.xml url, but only if the user customized it and download was successfull
|
||||||
if(urlLineEdit->text() != QString(TOKENS_URL))
|
if(urlLineEdit->text() != QString(TOKENS_URL))
|
||||||
wizard()->settings->setValue("tokensurl", urlLineEdit->text());
|
wizard()->settings->setValue("tokensurl", urlLineEdit->text());
|
||||||
|
|
|
@ -80,6 +80,7 @@ protected:
|
||||||
void initializePage();
|
void initializePage();
|
||||||
bool validatePage();
|
bool validatePage();
|
||||||
void readSetsFromByteArray(QByteArray data);
|
void readSetsFromByteArray(QByteArray data);
|
||||||
|
void downloadSetsFile(QUrl url);
|
||||||
private:
|
private:
|
||||||
QRadioButton *urlRadioButton;
|
QRadioButton *urlRadioButton;
|
||||||
QRadioButton *fileRadioButton;
|
QRadioButton *fileRadioButton;
|
||||||
|
@ -128,6 +129,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void initializePage();
|
void initializePage();
|
||||||
bool validatePage();
|
bool validatePage();
|
||||||
|
void downloadTokensFile(QUrl url);
|
||||||
private:
|
private:
|
||||||
QLabel *urlLabel;
|
QLabel *urlLabel;
|
||||||
QLineEdit *urlLineEdit;
|
QLineEdit *urlLineEdit;
|
||||||
|
|
Loading…
Reference in a new issue