mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Ensure correct thread locale QgsNetworkAccessManager is used during
o2 requests Otherwise the main thread manager is always used, resulting in lots of warnings and potential crashes
This commit is contained in:
parent
ba8f8e3f07
commit
9cde65457b
11
external/o2/src/o2.cpp
vendored
11
external/o2/src/o2.cpp
vendored
@ -219,7 +219,7 @@ void O2::link() {
|
||||
QUrl url(tokenUrl_);
|
||||
QNetworkRequest tokenRequest(url);
|
||||
tokenRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
QNetworkReply *tokenReply = manager_->post(tokenRequest, payload);
|
||||
QNetworkReply *tokenReply = getManager()->post(tokenRequest, payload);
|
||||
|
||||
connect(tokenReply, SIGNAL(finished()), this, SLOT(onTokenReplyFinished()), Qt::QueuedConnection);
|
||||
connect(tokenReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onTokenReplyError(QNetworkReply::NetworkError)), Qt::QueuedConnection);
|
||||
@ -268,7 +268,7 @@ void O2::onVerificationReceived(const QMap<QString, QString> response) {
|
||||
|
||||
qDebug() << QString("O2::onVerificationReceived: Exchange access code data:\n%1").arg(QString(data));
|
||||
|
||||
QNetworkReply *tokenReply = manager_->post(tokenRequest, data);
|
||||
QNetworkReply *tokenReply = getManager()->post(tokenRequest, data);
|
||||
timedReplies_.add(tokenReply);
|
||||
connect(tokenReply, SIGNAL(finished()), this, SLOT(onTokenReplyFinished()), Qt::QueuedConnection);
|
||||
connect(tokenReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onTokenReplyError(QNetworkReply::NetworkError)), Qt::QueuedConnection);
|
||||
@ -390,6 +390,11 @@ void O2::setExpires(int v) {
|
||||
store_->setValue(key, QString::number(v));
|
||||
}
|
||||
|
||||
QNetworkAccessManager *O2::getManager()
|
||||
{
|
||||
return manager_;
|
||||
}
|
||||
|
||||
QString O2::refreshToken() {
|
||||
QString key = QString(O2_KEY_REFRESH_TOKEN).arg(clientId_);
|
||||
return store_->value(key);
|
||||
@ -424,7 +429,7 @@ void O2::refresh() {
|
||||
parameters.insert(O2_OAUTH2_GRANT_TYPE, O2_OAUTH2_REFRESH_TOKEN);
|
||||
|
||||
QByteArray data = buildRequestBody(parameters);
|
||||
QNetworkReply *refreshReply = manager_->post(refreshRequest, data);
|
||||
QNetworkReply *refreshReply = getManager()->post(refreshRequest, data);
|
||||
timedReplies_.add(refreshReply);
|
||||
connect(refreshReply, SIGNAL(finished()), this, SLOT(onRefreshFinished()), Qt::QueuedConnection);
|
||||
connect(refreshReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onRefreshError(QNetworkReply::NetworkError)), Qt::QueuedConnection);
|
||||
|
2
external/o2/src/o2.h
vendored
2
external/o2/src/o2.h
vendored
@ -161,6 +161,8 @@ protected:
|
||||
/// Set token expiration time.
|
||||
void setExpires(int v);
|
||||
|
||||
virtual QNetworkAccessManager *getManager();
|
||||
|
||||
protected:
|
||||
QString username_;
|
||||
QString password_;
|
||||
|
@ -233,7 +233,7 @@ void QgsO2::link()
|
||||
QNetworkRequest tokenRequest( url );
|
||||
QgsSetRequestInitiatorClass( tokenRequest, QStringLiteral( "QgsO2" ) );
|
||||
tokenRequest.setHeader( QNetworkRequest::ContentTypeHeader, QLatin1Literal( "application/x-www-form-urlencoded" ) );
|
||||
QNetworkReply *tokenReply = manager_->post( tokenRequest, payload );
|
||||
QNetworkReply *tokenReply = getManager()->post( tokenRequest, payload );
|
||||
|
||||
connect( tokenReply, SIGNAL( finished() ), this, SLOT( onTokenReplyFinished() ), Qt::QueuedConnection );
|
||||
connect( tokenReply, SIGNAL( error( QNetworkReply::NetworkError ) ), this, SLOT( onTokenReplyError( QNetworkReply::NetworkError ) ), Qt::QueuedConnection );
|
||||
@ -302,7 +302,7 @@ void QgsO2::onVerificationReceived( QMap<QString, QString> response )
|
||||
parameters.insert( O2_OAUTH2_REDIRECT_URI, redirectUri_ );
|
||||
parameters.insert( O2_OAUTH2_GRANT_TYPE, O2_AUTHORIZATION_CODE );
|
||||
QByteArray data = buildRequestBody( parameters );
|
||||
QNetworkReply *tokenReply = manager_->post( tokenRequest, data );
|
||||
QNetworkReply *tokenReply = getManager()->post( tokenRequest, data );
|
||||
timedReplies_.add( tokenReply );
|
||||
connect( tokenReply, &QNetworkReply::finished, this, &QgsO2::onTokenReplyFinished, Qt::QueuedConnection );
|
||||
connect( tokenReply, qgis::overload<QNetworkReply::NetworkError>::of( &QNetworkReply::error ), this, &QgsO2::onTokenReplyError, Qt::QueuedConnection );
|
||||
@ -339,3 +339,8 @@ void QgsO2::onVerificationReceived( QMap<QString, QString> response )
|
||||
setRefreshToken( response.value( O2_OAUTH2_REFRESH_TOKEN ) );
|
||||
}
|
||||
}
|
||||
|
||||
QNetworkAccessManager *QgsO2::getManager()
|
||||
{
|
||||
return QgsNetworkAccessManager::instance();
|
||||
}
|
||||
|
@ -74,6 +74,10 @@ class QgsO2: public O2
|
||||
//! Handle verification response.
|
||||
void onVerificationReceived( QMap<QString, QString> response ) override;
|
||||
|
||||
protected:
|
||||
|
||||
QNetworkAccessManager* getManager() override;
|
||||
|
||||
signals:
|
||||
|
||||
//! Emitted when the state has changed
|
||||
|
Loading…
x
Reference in New Issue
Block a user