Commit 3766f70e authored by Michael Schuster's avatar Michael Schuster

Refactor ProxyAuthHandler to use QEventLoop

Signed-off-by: default avatarMichael Schuster <michael@schuster.ms>
(cherry picked from commit ea95c4bf49437a9e964e192db3406107c614821c)
Signed-off-by: default avatarMichael Schuster <michael@schuster.ms>
parent 6f337406
......@@ -135,12 +135,7 @@ void ProxyAuthHandler::handleProxyAuthenticationRequired(
this, &ProxyAuthHandler::slotSenderDestroyed);
}
}
void ProxyAuthHandler::slotKeychainJobDone()
{
_keychainJobRunning = false;
}
void ProxyAuthHandler::slotSenderDestroyed(QObject *obj)
{
_gaveCredentialsTo.remove(obj);
......@@ -148,10 +143,13 @@ void ProxyAuthHandler::slotSenderDestroyed(QObject *obj)
bool ProxyAuthHandler::getCredsFromDialog()
{
QEventLoop waitLoop;
// Open the credentials dialog
if (!_waitingForDialog) {
_dialog->reset();
_dialog->setProxyAddress(_proxy);
connect(_dialog, &QDialog::finished, &waitLoop, &QEventLoop::quit);
_dialog->open();
}
......@@ -159,8 +157,8 @@ bool ProxyAuthHandler::getCredsFromDialog()
// If that's the case, continue processing the dialog until
// it's done.
++_waitingForDialog;
while (_dialog && _dialog->isVisible()) {
QApplication::processEvents(QEventLoop::ExcludeSocketNotifiers, 200);
if (_dialog) {
waitLoop.exec(QEventLoop::ExcludeSocketNotifiers);
}
--_waitingForDialog;
......@@ -176,6 +174,7 @@ bool ProxyAuthHandler::getCredsFromDialog()
bool ProxyAuthHandler::getCredsFromKeychain()
{
using namespace QKeychain;
QEventLoop waitLoop;
if (_waitingForDialog) {
return false;
......@@ -194,9 +193,7 @@ bool ProxyAuthHandler::getCredsFromKeychain()
_readPasswordJob->setInsecureFallback(false);
_readPasswordJob->setKey(keychainPasswordKey());
_readPasswordJob->setAutoDelete(false);
connect(_readPasswordJob.data(), &QKeychain::Job::finished,
this, &ProxyAuthHandler::slotKeychainJobDone);
_keychainJobRunning = true;
connect(_readPasswordJob.data(), &QKeychain::Job::finished, &waitLoop, &QEventLoop::quit);
_readPasswordJob->start();
}
......@@ -205,10 +202,7 @@ bool ProxyAuthHandler::getCredsFromKeychain()
// bad behavior when we reenter this code after the flag has been switched
// but before the while loop has finished.
++_waitingForKeychain;
_keychainJobRunning = true;
while (_keychainJobRunning) {
QApplication::processEvents(QEventLoop::AllEvents, 200);
}
waitLoop.exec();
--_waitingForKeychain;
if (_readPasswordJob->error() == NoError) {
......@@ -227,6 +221,7 @@ bool ProxyAuthHandler::getCredsFromKeychain()
void ProxyAuthHandler::storeCredsInKeychain()
{
using namespace QKeychain;
QEventLoop waitLoop;
if (_waitingForKeychain) {
return;
......@@ -242,15 +237,11 @@ void ProxyAuthHandler::storeCredsInKeychain()
job->setKey(keychainPasswordKey());
job->setTextData(_password);
job->setAutoDelete(false);
connect(job, &QKeychain::Job::finished, this, &ProxyAuthHandler::slotKeychainJobDone);
_keychainJobRunning = true;
connect(job, &QKeychain::Job::finished, &waitLoop, &QEventLoop::quit);
job->start();
++_waitingForKeychain;
_keychainJobRunning = true;
while (_keychainJobRunning) {
QApplication::processEvents(QEventLoop::AllEvents, 200);
}
waitLoop.exec();
--_waitingForKeychain;
job->deleteLater();
......
......@@ -57,7 +57,6 @@ public slots:
QAuthenticator *authenticator);
private slots:
void slotKeychainJobDone();
void slotSenderDestroyed(QObject *);
private:
......@@ -89,9 +88,8 @@ private:
/// In several instances handleProxyAuthenticationRequired() can be called
/// while it is still running. These counters detect what we're currently
/// waiting for.
int _waitingForDialog;
int _waitingForKeychain;
bool _keychainJobRunning;
int _waitingForDialog = 0;
int _waitingForKeychain = 0;
QPointer<ProxyAuthDialog> _dialog;
......
Markdown is supported
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