Do not show the HTTP-reconnect popup when its not warranted

Fixes usability issues in the workaround of #2607
This commit is contained in:
Daniel Molkentin 2014-12-17 19:14:42 +01:00
parent 6e4da53e31
commit 7ac32a19b5
6 changed files with 39 additions and 22 deletions

View file

@ -186,15 +186,14 @@ void OwncloudSetupWizard::slotNoOwnCloudFoundAuth(QNetworkReply *reply)
_ocWizard->displayError(tr("Failed to connect to %1 at %2:<br/>%3")
.arg(Theme::instance()->appNameGUI(),
reply->url().toString(),
reply->errorString()));
reply->errorString()), checkDowngradeAdvised(reply));
}
void OwncloudSetupWizard::slotNoOwnCloudFoundAuthTimeout(const QUrl&url)
{
_ocWizard->displayError(tr("Failed to connect to %1 at %2:<br/>%3")
_ocWizard->displayError(tr("Timeout while trying to connect to %1 at %2.")
.arg(Theme::instance()->appNameGUI(),
url.toString(),
"Timeout"));
url.toString()), false);
}
void OwncloudSetupWizard::slotConnectToOCUrl( const QString& url )
@ -219,6 +218,28 @@ void OwncloudSetupWizard::testOwnCloudConnect()
job->start();
}
bool OwncloudSetupWizard::checkDowngradeAdvised(QNetworkReply* reply)
{
bool downgradeAdvised = (reply->url().scheme() == QLatin1String("https"));
switch (reply->error()) {
case QNetworkReply::NoError:
case QNetworkReply::ContentNotFoundError:
case QNetworkReply::ConnectionRefusedError:
case QNetworkReply::HostNotFoundError:
case QNetworkReply::TimeoutError:
downgradeAdvised = false;
// fall through
default:
_ocWizard->show();
_ocWizard->back();
// Adhere to HSTS, even though we do not parse it properly
downgradeAdvised &= !reply->hasRawHeader("Strict-Transport-Security");
break;
}
return downgradeAdvised;
}
void OwncloudSetupWizard::slotConnectionCheck(QNetworkReply* reply)
{
switch (reply->error()) {
@ -226,11 +247,8 @@ void OwncloudSetupWizard::slotConnectionCheck(QNetworkReply* reply)
case QNetworkReply::ContentNotFoundError:
_ocWizard->successfulStep();
break;
default:
_ocWizard->show();
_ocWizard->back();
_ocWizard->displayError(reply->errorString());
_ocWizard->displayError(reply->errorString(), checkDowngradeAdvised(reply));
break;
}
}
@ -254,7 +272,7 @@ void OwncloudSetupWizard::slotCreateLocalAndRemoteFolders(const QString& localFo
} else {
res += tr("failed.");
qDebug() << "Failed to create " << fi.path();
_ocWizard->displayError(tr("Could not create local folder %1").arg(localFolder));
_ocWizard->displayError(tr("Could not create local folder %1").arg(localFolder), false);
nextStep = false;
}
_ocWizard->appendToConfigurationLog( res );
@ -290,7 +308,7 @@ void OwncloudSetupWizard::slotAuthCheckReply(QNetworkReply *reply)
}
if( !ok ) {
_ocWizard->displayError(error);
_ocWizard->displayError(error, false);
}
finalizeSetup( ok );
@ -318,20 +336,20 @@ void OwncloudSetupWizard::slotCreateRemoteFolderFinished( QNetworkReply::Network
} else if( error == 202 ) {
_ocWizard->appendToConfigurationLog( tr("The remote folder %1 already exists. Connecting it for syncing.").arg(_remoteFolder));
} else if( error > 202 && error < 300 ) {
_ocWizard->displayError( tr("The folder creation resulted in HTTP error code %1").arg((int)error ));
_ocWizard->displayError( tr("The folder creation resulted in HTTP error code %1").arg((int)error ), false);
_ocWizard->appendToConfigurationLog( tr("The folder creation resulted in HTTP error code %1").arg((int)error) );
} else if( error == QNetworkReply::OperationCanceledError ) {
_ocWizard->displayError( tr("The remote folder creation failed because the provided credentials "
"are wrong!"
"<br/>Please go back and check your credentials.</p>"));
"<br/>Please go back and check your credentials.</p>"), false);
_ocWizard->appendToConfigurationLog( tr("<p><font color=\"red\">Remote folder creation failed probably because the provided credentials are wrong.</font>"
"<br/>Please go back and check your credentials.</p>"));
_remoteFolder.clear();
success = false;
} else {
_ocWizard->appendToConfigurationLog( tr("Remote folder %1 creation failed with error <tt>%2</tt>.").arg(_remoteFolder).arg(error));
_ocWizard->displayError( tr("Remote folder %1 creation failed with error <tt>%2</tt>.").arg(_remoteFolder).arg(error) );
_ocWizard->displayError( tr("Remote folder %1 creation failed with error <tt>%2</tt>.").arg(_remoteFolder).arg(error), false );
_remoteFolder.clear();
success = false;
}

View file

@ -62,7 +62,6 @@ class OwncloudSetupWizard : public QObject
public:
/** Run the wizard */
static void runWizard(QObject *obj, const char* amember, QWidget *parent = 0 );
signals:
// overall dialog close signal.
void ownCloudWizardDone( int );
@ -85,13 +84,13 @@ private slots:
private:
explicit OwncloudSetupWizard(QObject *parent = 0 );
~OwncloudSetupWizard();
void startWizard();
void testOwnCloudConnect();
void createRemoteFolder();
void finalizeSetup( bool );
bool ensureStartFromScratch(const QString &localFolder);
void replaceDefaultAccountWith(Account *newAccount);
bool checkDowngradeAdvised(QNetworkReply* reply);
Account* _account;
OwncloudWizard* _ocWizard;

View file

@ -201,7 +201,7 @@ QString OwncloudSetupPage::url() const
bool OwncloudSetupPage::validatePage()
{
if( ! _authTypeKnown) {
setErrorString(QString::null);
setErrorString(QString::null, false);
_checking = true;
startSpinner ();
emit completeChanged();
@ -224,12 +224,12 @@ void OwncloudSetupPage::setAuthType (WizardCommon::AuthType type)
stopSpinner();
}
void OwncloudSetupPage::setErrorString( const QString& err )
void OwncloudSetupPage::setErrorString( const QString& err, bool retryHTTPonly )
{
if( err.isEmpty()) {
_ui.errorLabel->setVisible(false);
} else {
if (_ui.leUrl->text().startsWith("https://")) {
if (retryHTTPonly) {
QString msg = tr("<p>Could not connect securely:</p><p>%1</p><p>Do you want to connect unencrypted instead (not recommended)?</p>").arg(err);
QString title = tr("Connection failed");
if (QMessageBox::question(this, title, msg, QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) {

View file

@ -46,7 +46,7 @@ public:
void setAuthType(WizardCommon::AuthType type);
public slots:
void setErrorString( const QString& );
void setErrorString( const QString&, bool retryHTTPonly );
void setConfigExists( bool );
void startSpinner();
void stopSpinner();

View file

@ -182,11 +182,11 @@ void OwncloudWizard::slotCurrentPageChanged( int id )
setOption(QWizard::HaveCustomButton1, id == WizardCommon::Page_AdvancedSetup);
}
void OwncloudWizard::displayError( const QString& msg )
void OwncloudWizard::displayError( const QString& msg, bool retryHTTPonly )
{
switch (currentId()) {
case WizardCommon::Page_ServerSetup:
_setupPage->setErrorString( msg );
_setupPage->setErrorString( msg, retryHTTPonly );
break;
case WizardCommon::Page_HttpCreds:

View file

@ -54,7 +54,7 @@ public:
void enableFinishOnResultWidget(bool enable);
void displayError( const QString& );
void displayError( const QString&, bool retryHTTPonly);
void setMultipleFoldersExist( bool );
void setConfigExists( bool );
bool configExists();