Commit 5dd48d53 authored by Krzysztof Nowicki's avatar Krzysztof Nowicki
Browse files

Use own event loop for connection attempts

The event loop executed by KJob::exec() explicitly blocks input
events. This will cause the Cancel button to be effectively block and
will also prevent interaction with the OAuth2-driven web browser.
parent 0ca0698e
/*
Copyright (C) 2015-2017 Krzysztof Nowicki <krissn@op.pl>
Copyright (C) 2015-2018 Krzysztof Nowicki <krissn@op.pl>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -48,6 +48,16 @@ static const QVector<StringPair> userAgents = {
{QStringLiteral("Mozilla Thunderbird 38 for Mac (with ExQuilla)"), QStringLiteral("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:38.0) Gecko/20100101 Thunderbird/38.2.0")}
};
static bool execJob(KJob *job)
{
QEventLoop loop;
QObject::connect(job, &KJob::finished, &loop, [&](KJob *j) {
loop.exit(j->error());
});
job->start();
return loop.exec() == 0;
}
EwsConfigDialog::EwsConfigDialog(EwsResource *parentResource, EwsClient &client, WId wId,
EwsSettings *settings)
: QDialog()
......@@ -247,8 +257,8 @@ void EwsConfigDialog::tryConnectCancelled()
if (mTryConnectJob) {
mTryConnectJob->kill();
}
//mTryConnectJob->deleteLater();
mTryConnectJob = nullptr;
mTryConnectJobCancelled = true;
}
void EwsConfigDialog::setAutoDiscoveryNeeded()
......@@ -354,18 +364,22 @@ void EwsConfigDialog::tryConnect()
mTryConnectJob = new EwsGetFolderRequest(cli, this);
mTryConnectJob->setFolderShape(EwsFolderShape(EwsShapeIdOnly));
mTryConnectJob->setFolderIds(EwsId::List() << EwsId(EwsDIdInbox));
mTryConnectJobCancelled = false;
mProgressDialog = new EwsProgressDialog(this, EwsProgressDialog::TryConnect);
connect(mProgressDialog, &QDialog::rejected, this, &EwsConfigDialog::tryConnectCancelled);
mProgressDialog->show();
if (!mTryConnectJob->exec()) {
mUi->serverStatusText->setText(i18nc("Exchange server status", "Failed"));
mUi->serverVersionText->setText(i18nc("Exchange server version", "Unknown"));
KMessageBox::error(this, mTryConnectJob->errorText(), i18n("Connection failed"));
if (!execJob(mTryConnectJob)) {
if (!mTryConnectJobCancelled) {
mUi->serverStatusText->setText(i18nc("Exchange server status", "Failed"));
mUi->serverVersionText->setText(i18nc("Exchange server version", "Unknown"));
KMessageBox::error(this, mTryConnectJob->errorText(), i18n("Connection failed"));
}
} else {
mUi->serverStatusText->setText(i18nc("Exchange server status", "OK"));
mUi->serverVersionText->setText(mTryConnectJob->serverVersion().toString());
}
mProgressDialog->hide();
mTryConnectJob = nullptr;
}
void EwsConfigDialog::userAgentChanged(int)
......
/*
Copyright (C) 2015-2016 Krzysztof Nowicki <krissn@op.pl>
Copyright (C) 2015-2018 Krzysztof Nowicki <krissn@op.pl>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -68,6 +68,7 @@ private:
QDialogButtonBox *mButtonBox = nullptr;
EwsAutodiscoveryJob *mAutoDiscoveryJob = nullptr;
EwsGetFolderRequest *mTryConnectJob = nullptr;
bool mTryConnectJobCancelled = false;
bool mAutoDiscoveryNeeded = false;
bool mTryConnectNeeded = false;
EwsProgressDialog *mProgressDialog = nullptr;
......
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