Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle "selected sync destination is unusable" case better in setup wizard #11029

Merged
merged 3 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/gui/newwizard/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#pragma once

#include "common/utility.h"
#include "enums.h"

#include <QObject>

Expand Down
5 changes: 5 additions & 0 deletions src/gui/newwizard/pages/accountconfiguredwizardpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,9 @@ bool AccountConfiguredWizardPage::validateInput()
// nothing to validate here
return true;
}

void AccountConfiguredWizardPage::setShowAdvancedSettings(bool showAdvancedSettings)
{
_ui->advancedConfigGroupBox->setChecked(showAdvancedSettings);
}
}
2 changes: 2 additions & 0 deletions src/gui/newwizard/pages/accountconfiguredwizardpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class AccountConfiguredWizardPage : public AbstractSetupWizardPage

bool validateInput() override;

void setShowAdvancedSettings(bool showAdvancedSettings);

private:
::Ui::AccountConfiguredWizardPage *_ui;
};
Expand Down
5 changes: 5 additions & 0 deletions src/gui/newwizard/setupwizardaccountbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ void SetupWizardAccountBuilder::setDefaultSyncTargetDir(const QString &syncTarge
_defaultSyncTargetDir = syncTargetDir;
}

QString SetupWizardAccountBuilder::defaultSyncTargetDir() const
{
return _defaultSyncTargetDir;
}

QString SetupWizardAccountBuilder::legacyWebFingerUsername() const
{
return _legacyWebFingerUsername;
Expand Down
1 change: 1 addition & 0 deletions src/gui/newwizard/setupwizardaccountbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class SetupWizardAccountBuilder

// getter is not needed at the moment
void setDefaultSyncTargetDir(const QString &syncTargetDir);
QString defaultSyncTargetDir() const;

/**
* Store custom CA certificate for the newly built account.
Expand Down
18 changes: 16 additions & 2 deletions src/gui/newwizard/setupwizardcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace {
using namespace OCC;
using namespace OCC::Wizard;

using namespace SetupWizardControllerPrivate;

/**
* Generate list of wizard states to put in the navigation.
* The actual wizard may be in states not within this list to perform tasks in the background without user interaction
Expand Down Expand Up @@ -103,7 +105,7 @@ SetupWizardWindow *SetupWizardController::window()
return _context->window();
}

void SetupWizardController::changeStateTo(SetupWizardState nextState)
void SetupWizardController::changeStateTo(SetupWizardState nextState, ChangeReason reason)
{
// validate initial state
Q_ASSERT(nextState == SetupWizardState::ServerUrlState || _currentState != nullptr);
Expand Down Expand Up @@ -137,6 +139,18 @@ void SetupWizardController::changeStateTo(SetupWizardState nextState)
}
case SetupWizardState::AccountConfiguredState: {
_currentState = new AccountConfiguredSetupWizardState(_context);

switch (reason) {
case ChangeReason::Default:
break;
case ChangeReason::EvaluationFailed:
// whenever the evaluation of the last page fails, it's safe to assume it's due to some issue with the advanced
// therefore, we want to show them in that case
auto *page = dynamic_cast<AccountConfiguredWizardPage *>(_currentState->page());
if (OC_ENSURE(page != nullptr)) {
page->setShowAdvancedSettings(true);
}
}
break;
}
default:
Expand Down Expand Up @@ -207,7 +221,7 @@ void SetupWizardController::changeStateTo(SetupWizardState nextState)
connect(_currentState, &AbstractSetupWizardState::evaluationFailed, this, [this](const QString &errorMessage) {
_currentState->deleteLater();
_context->window()->showErrorMessage(errorMessage);
changeStateTo(_currentState->state());
changeStateTo(_currentState->state(), ChangeReason::EvaluationFailed);
});

_context->window()->displayPage(_currentState->page(), _currentState->state());
Expand Down
3 changes: 2 additions & 1 deletion src/gui/newwizard/setupwizardcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "pages/abstractsetupwizardpage.h"
#include "setupwizardaccountbuilder.h"
#include "setupwizardcontext.h"
#include "setupwizardcontroller_p.h"
#include "setupwizardwindow.h"
#include "states/abstractsetupwizardstate.h"

Expand Down Expand Up @@ -53,7 +54,7 @@ class SetupWizardController : public QObject
void finished(AccountPtr newAccount, SyncMode syncMode, const QVariantMap &dynamicRegistrationData);

private:
void changeStateTo(SetupWizardState nextState);
void changeStateTo(SetupWizardState nextState, SetupWizardControllerPrivate::ChangeReason reason = SetupWizardControllerPrivate::ChangeReason::Default);

SetupWizardContext *_context = nullptr;

Expand Down
15 changes: 15 additions & 0 deletions src/gui/newwizard/setupwizardcontroller_p.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <QtGlobal>

namespace OCC::Wizard::SetupWizardControllerPrivate {

Q_NAMESPACE

enum class ChangeReason {
Default,
EvaluationFailed,
};
Q_ENUM_NS(ChangeReason)

}
14 changes: 10 additions & 4 deletions src/gui/newwizard/states/accountconfiguredsetupwizardstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ AccountConfiguredSetupWizardState::AccountConfiguredSetupWizardState(SetupWizard
return _context->accountBuilder().serverUrl();
}();

_page = new AccountConfiguredWizardPage(FolderMan::suggestSyncFolder(urlToSuggestSyncFolderFor, _context->accountBuilder().displayName()), vfsIsAvailable,
enableVfsByDefault, vfsModeIsExperimental);
QString defaultSyncTargetDir = _context->accountBuilder().defaultSyncTargetDir();

if (defaultSyncTargetDir.isEmpty()) {
defaultSyncTargetDir = FolderMan::suggestSyncFolder(urlToSuggestSyncFolderFor, _context->accountBuilder().displayName());
}

_page = new AccountConfiguredWizardPage(defaultSyncTargetDir, vfsIsAvailable, enableVfsByDefault, vfsModeIsExperimental);
}

SetupWizardState AccountConfiguredSetupWizardState::state() const
Expand All @@ -72,6 +77,9 @@ void AccountConfiguredSetupWizardState::evaluatePage()
if (accountConfiguredSetupWizardPage->syncMode() != Wizard::SyncMode::ConfigureUsingFolderWizard) {
QString syncTargetDir = QDir::fromNativeSeparators(accountConfiguredSetupWizardPage->syncTargetDir());

// make sure we remember it now so we can show it to the user again upon failures
_context->accountBuilder().setDefaultSyncTargetDir(syncTargetDir);

const QString errorMessageTemplate = tr("Invalid local download directory: %1");

if (!QDir::isAbsolutePath(syncTargetDir)) {
Expand All @@ -84,8 +92,6 @@ void AccountConfiguredSetupWizardState::evaluatePage()
Q_EMIT evaluationFailed(errorMessageTemplate.arg(invalidPathErrorMessage));
return;
}

_context->accountBuilder().setDefaultSyncTargetDir(syncTargetDir);
}

Q_EMIT evaluationSuccessful();
Expand Down
Loading