19
19
#include " configfile.h"
20
20
#include " creds/abstractcredentials.h"
21
21
#include " creds/httpcredentials.h"
22
+ #include " gui/settingsdialog.h"
23
+ #include " gui/tlserrordialog.h"
22
24
#include " logger.h"
23
25
#include " settingsdialog.h"
24
26
#include " theme.h"
@@ -262,6 +264,10 @@ void AccountState::checkConnectivity(bool blockJobs)
262
264
if (isSignedOut () || _waitingForNewCredentials) {
263
265
return ;
264
266
}
267
+ if (_tlsDialog) {
268
+ qCDebug (lcAccountState) << " Skip checkConnectivity, waiting for tls dialog" ;
269
+ return ;
270
+ }
265
271
266
272
if (_connectionValidator && blockJobs && !_queueGuard.queue ()->isBlocked ()) {
267
273
// abort already running non blocking validator
@@ -278,22 +284,18 @@ void AccountState::checkConnectivity(bool blockJobs)
278
284
if (!account ()->credentials ()->wasFetched ()) {
279
285
_waitingForNewCredentials = true ;
280
286
account ()->credentials ()->fetchFromKeychain ();
281
- return ;
282
- }
283
- // we are not properly setup yet
284
- if (!account ()->hasCapabilities ()) {
285
- return ;
286
287
}
287
-
288
- // IF the account is connected the connection check can be skipped
289
- // if the last successful etag check job is not so long ago.
290
- const auto pta = account ()->capabilities ().remotePollInterval ();
291
- const auto polltime = duration_cast<seconds>(ConfigFile ().remotePollInterval (pta));
292
- const auto elapsed = _timeOfLastETagCheck.secsTo (QDateTime::currentDateTimeUtc ());
293
- if (!blockJobs && isConnected () && _timeOfLastETagCheck.isValid ()
294
- && elapsed <= polltime.count ()) {
295
- qCDebug (lcAccountState) << account ()->displayName () << " The last ETag check succeeded within the last " << polltime.count () << " s (" << elapsed << " s). No connection check needed!" ;
296
- return ;
288
+ if (account ()->hasCapabilities ()) {
289
+ // IF the account is connected the connection check can be skipped
290
+ // if the last successful etag check job is not so long ago.
291
+ const auto pta = account ()->capabilities ().remotePollInterval ();
292
+ const auto polltime = duration_cast<seconds>(ConfigFile ().remotePollInterval (pta));
293
+ const auto elapsed = _timeOfLastETagCheck.secsTo (QDateTime::currentDateTimeUtc ());
294
+ if (!blockJobs && isConnected () && _timeOfLastETagCheck.isValid ()
295
+ && elapsed <= polltime.count ()) {
296
+ qCDebug (lcAccountState) << account ()->displayName () << " The last ETag check succeeded within the last " << polltime.count () << " s (" << elapsed << " s). No connection check needed!" ;
297
+ return ;
298
+ }
297
299
}
298
300
299
301
if (blockJobs) {
@@ -302,6 +304,30 @@ void AccountState::checkConnectivity(bool blockJobs)
302
304
_connectionValidator = new ConnectionValidator (account ());
303
305
connect (_connectionValidator, &ConnectionValidator::connectionResult,
304
306
this , &AccountState::slotConnectionValidatorResult);
307
+
308
+ connect (_connectionValidator, &ConnectionValidator::sslErrors, this , [blockJobs, this ](const QList<QSslError> &errors) {
309
+ if (!_tlsDialog) {
310
+ _tlsDialog = new TlsErrorDialog (errors, _account->url ().host (), ocApp ()->gui ()->settingsDialog ());
311
+ _tlsDialog->setAttribute (Qt::WA_DeleteOnClose);
312
+ QSet<QSslCertificate> certs;
313
+ certs.reserve (errors.size ());
314
+ for (const auto &error : errors) {
315
+ certs << error.certificate ();
316
+ }
317
+ connect (_tlsDialog, &TlsErrorDialog::accepted, _tlsDialog, [certs, blockJobs, this ]() {
318
+ _account->addApprovedCerts (certs);
319
+ _tlsDialog.clear ();
320
+ _waitingForNewCredentials = false ;
321
+ checkConnectivity (blockJobs);
322
+ });
323
+ connect (_tlsDialog, &TlsErrorDialog::rejected, this , [certs, this ]() {
324
+ setState (SignedOut);
325
+ });
326
+
327
+ _tlsDialog->show ();
328
+ }
329
+ ocApp ()->gui ()->raiseDialog (_tlsDialog);
330
+ });
305
331
if (isConnected ()) {
306
332
// Use a small authed propfind as a minimal ping when we're
307
333
// already connected.
@@ -313,16 +339,12 @@ void AccountState::checkConnectivity(bool blockJobs)
313
339
}
314
340
} else {
315
341
// Check the server and then the auth.
316
-
317
- // Let's try this for all OS and see if it fixes the Qt issues we have on Linux #4720 #3888 #4051
318
- // There seems to be a bug in Qt on Windows where QNAM sometimes stops
319
- // working correctly after the computer woke up from sleep. See #2895 #2899
320
- // and #2973.
321
- // As an attempted workaround, reset the QNAM regularly if the account is
322
- // disconnected.
323
- account ()->clearCookieJar ();
324
- account ()->resetAccessManager ();
325
- _connectionValidator->checkServerAndUpdate ();
342
+ if (_waitingForNewCredentials) {
343
+ _connectionValidator->checkServer ();
344
+ } else {
345
+ account ()->clearCookieJar ();
346
+ _connectionValidator->checkServerAndUpdate ();
347
+ }
326
348
}
327
349
}
328
350
@@ -380,7 +402,7 @@ void AccountState::slotConnectionValidatorResult(ConnectionValidator::Status sta
380
402
slotInvalidCredentials ();
381
403
break ;
382
404
case ConnectionValidator::SslError:
383
- setState (SignedOut);
405
+ // handled with the tlsDialog
384
406
break ;
385
407
case ConnectionValidator::ServiceUnavailable:
386
408
_timeSinceMaintenanceOver.invalidate ();
0 commit comments