Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
5146db7a
Commit
5146db7a
authored
Jan 15, 2016
by
Zach
Browse files
Merge pull request #1763 from ctrlaltca/oracle_redirects
Oracle: follow redirects
parents
f7f9827b
bacb289e
Changes
2
Show whitespace changes
Inline
Side-by-side
oracle/src/oraclewizard.cpp
View file @
5146db7a
...
@@ -292,13 +292,7 @@ bool LoadSetsPage::validatePage()
...
@@ -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()
...
@@ -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)
...
@@ -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()
...
@@ -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()
...
@@ -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
...
@@ -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()
...
@@ -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
());
...
...
oracle/src/oraclewizard.h
View file @
5146db7a
...
@@ -80,6 +80,7 @@ protected:
...
@@ -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:
...
@@ -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
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment