Skip to content

Commit

Permalink
Add branding parameter to skip the advanced setup page
Browse files Browse the repository at this point in the history
Fixes: #8665
  • Loading branch information
TheOneRing committed Aug 12, 2021
1 parent 2bae6f6 commit da5f67f
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 114 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/8665
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Change: Add a branding option to skip the advanced setup page

If the option is enabled we will create a sync with the default values.

https://github.com/owncloud/client/issues/8665
84 changes: 26 additions & 58 deletions src/gui/owncloudsetupwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ namespace OCC {
OwncloudSetupWizard::OwncloudSetupWizard(QWidget *parent)
: QObject(parent)
, _ocWizard(new OwncloudWizard(parent))
, _remoteFolder()
{
connect(_ocWizard, &OwncloudWizard::determineAuthType,
this, &OwncloudSetupWizard::slotCheckServer);
Expand All @@ -55,7 +54,7 @@ OwncloudSetupWizard::OwncloudSetupWizard(QWidget *parent)
Therefore Qt::QueuedConnection is required */
connect(_ocWizard, &OwncloudWizard::basicSetupFinished,
this, &OwncloudSetupWizard::slotAssistantFinished, Qt::QueuedConnection);
connect(_ocWizard, &QDialog::finished, this, &QObject::deleteLater);
connect(_ocWizard, &OwncloudWizard::finished, this, &QObject::deleteLater);
}

OwncloudSetupWizard::~OwncloudSetupWizard()
Expand All @@ -71,28 +70,6 @@ void OwncloudSetupWizard::startWizard()
_ocWizard->setAccount(account);
_ocWizard->setOCUrl(account->url().toString());

_remoteFolder = Theme::instance()->defaultServerFolder();
// remoteFolder may be empty, which means /
QString localFolder = Theme::instance()->defaultClientFolder();

// if its a relative path, prepend with users home dir, otherwise use as absolute path

if (!QDir(localFolder).isAbsolute()) {
localFolder = QDir::homePath() + QDir::separator() + localFolder;
}

_ocWizard->setProperty("localFolder", localFolder);

// remember the local folder to compare later if it changed, but clean first
QString lf = QDir::fromNativeSeparators(localFolder);
if (!lf.endsWith(QLatin1Char('/'))) {
lf.append(QLatin1Char('/'));
}

_initLocalFolder = lf;

_ocWizard->setRemoteFolder(_remoteFolder);

_ocWizard->setStartId(WizardCommon::Page_ServerSetup);

_ocWizard->restart();
Expand Down Expand Up @@ -269,33 +246,33 @@ void OwncloudSetupWizard::testOwnCloudConnect()
job->checkServerAndUpdate();
}

void OwncloudSetupWizard::slotCreateLocalAndRemoteFolders(const QString &localFolder, const QString &remoteFolder)
void OwncloudSetupWizard::slotCreateLocalAndRemoteFolders()
{
qCInfo(lcWizard) << "Setup local sync folder for new oC connection " << localFolder;
const QDir fi(localFolder);
qCInfo(lcWizard) << "Setup local sync folder for new oC connection " << _ocWizard->localFolder();
const QDir fi(_ocWizard->localFolder());

bool nextStep = true;
if (fi.exists()) {
FileSystem::setFolderMinimumPermissions(localFolder);
Utility::setupFavLink(localFolder);
FileSystem::setFolderMinimumPermissions(_ocWizard->localFolder());
Utility::setupFavLink(_ocWizard->localFolder());
// there is an existing local folder. If its non empty, it can only be synced if the
// ownCloud is newly created.
qCDebug(lcWizard) << "Local sync folder" << localFolder << "already exists, setting it up for sync.";
qCDebug(lcWizard) << "Local sync folder" << _ocWizard->localFolder() << "already exists, setting it up for sync.";
} else {
bool ok = true;
if (fi.mkpath(localFolder)) {
FileSystem::setFolderMinimumPermissions(localFolder);
Utility::setupFavLink(localFolder);
if (fi.mkpath(_ocWizard->localFolder())) {
FileSystem::setFolderMinimumPermissions(_ocWizard->localFolder());
Utility::setupFavLink(_ocWizard->localFolder());
} else {
ok = false;
qCWarning(lcWizard) << "Failed to create " << fi.path();
_ocWizard->displayError(tr("Could not create local folder %1").arg(Utility::escape(localFolder)));
_ocWizard->displayError(tr("Could not create local folder %1").arg(Utility::escape(_ocWizard->localFolder())));
nextStep = false;
}
qCDebug(lcWizard) << "Creating local sync folder" << localFolder << "success:" << ok;
qCDebug(lcWizard) << "Creating local sync folder" << _ocWizard->localFolder() << "success:" << ok;
}
if (nextStep) {
EntityExistsJob *job = new EntityExistsJob(_ocWizard->account(), Utility::concatUrlPath(_ocWizard->account()->davPath(), remoteFolder).path(), this);
EntityExistsJob *job = new EntityExistsJob(_ocWizard->account(), Utility::concatUrlPath(_ocWizard->account()->davPath(), _ocWizard->remoteFolder()).path(), this);
connect(job, &EntityExistsJob::exists, this, &OwncloudSetupWizard::slotRemoteFolderExists);
job->start();
} else {
Expand All @@ -314,12 +291,7 @@ void OwncloudSetupWizard::slotRemoteFolderExists(QNetworkReply *reply)
if (errId == QNetworkReply::NoError) {
qCInfo(lcWizard) << "Remote folder found, all cool!";
} else if (errId == QNetworkReply::ContentNotFoundError) {
if (_remoteFolder.isEmpty()) {
error = tr("No remote folder specified!");
ok = false;
} else {
createRemoteFolder();
}
createRemoteFolder();
} else {
error = tr("Error: %1").arg(job->errorString());
ok = false;
Expand All @@ -334,12 +306,12 @@ void OwncloudSetupWizard::slotRemoteFolderExists(QNetworkReply *reply)

void OwncloudSetupWizard::createRemoteFolder()
{
qCDebug(lcWizard) << "creating folder on ownCloud:" << _remoteFolder;
qCDebug(lcWizard) << "creating folder on ownCloud:" << _ocWizard->remoteFolder();

MkColJob *job = new MkColJob(_ocWizard->account(), _remoteFolder, this);
MkColJob *job = new MkColJob(_ocWizard->account(), _ocWizard->remoteFolder(), this);
connect(job, &MkColJob::finishedWithError, this, &OwncloudSetupWizard::slotCreateRemoteFolderFinished);
connect(job, &MkColJob::finishedWithoutError, this, [this] {
qCDebug(lcWizard) << "Remote folder" << _remoteFolder << "created successfully.";
qCDebug(lcWizard) << "Remote folder" << _ocWizard->remoteFolder() << "created successfully.";
finalizeSetup(true);
});
job->start();
Expand All @@ -349,12 +321,10 @@ void OwncloudSetupWizard::slotCreateRemoteFolderFinished(QNetworkReply *reply)
{
auto error = reply->error();
qCDebug(lcWizard) << "** webdav mkdir request finished " << error;
// disconnect(ownCloudInfo::instance(), SIGNAL(webdavColCreated(QNetworkReply::NetworkError)),
// this, SLOT(slotCreateRemoteFolderFinished(QNetworkReply::NetworkError)));

bool success = true;
if (error == 202) {
qCDebug(lcWizard) << "The remote folder" << _remoteFolder << "already exists. Connecting it for syncing.";
qCDebug(lcWizard) << "The remote folder" << _ocWizard->remoteFolder() << "already exists. Connecting it for syncing.";
} else if (error > 202 && error < 300) {
_ocWizard->displayError(tr("The folder creation resulted in HTTP error code %1").arg((int)error));

Expand All @@ -364,12 +334,12 @@ void OwncloudSetupWizard::slotCreateRemoteFolderFinished(QNetworkReply *reply)
"are wrong!"
"<br/>Please go back and check your credentials.</p>"));
qCDebug(lcWizard) << "Remote folder creation failed probably because the provided credentials are wrong. Please go back and check your credentials.";
_remoteFolder.clear();
_ocWizard->resetRemoteFolder();
success = false;
} else {
qCDebug(lcWizard) << "Remote folder" << _remoteFolder << "creation failed with error" << error;
_ocWizard->displayError(tr("Remote folder %1 creation failed with error <tt>%2</tt>.").arg(Utility::escape(_remoteFolder)).arg(error));
_remoteFolder.clear();
qCDebug(lcWizard) << "Remote folder" << _ocWizard->remoteFolder() << "creation failed with error" << error;
_ocWizard->displayError(tr("Remote folder %1 creation failed with error <tt>%2</tt>.").arg(Utility::escape(_ocWizard->remoteFolder())).arg(error));
_ocWizard->resetRemoteFolder();
success = false;
}

Expand All @@ -378,11 +348,9 @@ void OwncloudSetupWizard::slotCreateRemoteFolderFinished(QNetworkReply *reply)

void OwncloudSetupWizard::finalizeSetup(bool success)
{
const QString localFolder = _ocWizard->property("localFolder").toString();
const QString localFolder = _ocWizard->localFolder();
if (success) {
if (!(localFolder.isEmpty() || _remoteFolder.isEmpty())) {
qCDebug(lcWizard) << "A sync connection from" << localFolder << "to remote directory" << _remoteFolder << "was set up.";
}
qCDebug(lcWizard) << "A sync connection from" << localFolder << "to remote directory" << _ocWizard->remoteFolder() << "was set up.";
qCDebug(lcWizard) << "Successfully connected";
_ocWizard->successfulStep();
} else {
Expand Down Expand Up @@ -426,10 +394,10 @@ void OwncloudSetupWizard::slotAssistantFinished(int result)

bool startFromScratch = _ocWizard->field("OCSyncFromScratch").toBool();
if (!startFromScratch || ensureStartFromScratch(localFolder)) {
qCInfo(lcWizard) << "Adding folder definition for" << localFolder << _remoteFolder;
qCInfo(lcWizard) << "Adding folder definition for" << localFolder << _ocWizard->remoteFolder();
FolderDefinition folderDefinition;
folderDefinition.localPath = localFolder;
folderDefinition.targetPath = FolderDefinition::prepareTargetPath(_remoteFolder);
folderDefinition.targetPath = FolderDefinition::prepareTargetPath(_ocWizard->remoteFolder());
folderDefinition.ignoreHiddenFiles = folderMan->ignoreHiddenFiles();
if (_ocWizard->useVirtualFileSync()) {
folderDefinition.virtualFilesMode = bestAvailableVfsMode();
Expand Down
4 changes: 1 addition & 3 deletions src/gui/owncloudsetupwizard.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private slots:

void slotConnectToOCUrl(const QString &);

void slotCreateLocalAndRemoteFolders(const QString &, const QString &);
void slotCreateLocalAndRemoteFolders();
void slotRemoteFolderExists(QNetworkReply *);
void slotCreateRemoteFolderFinished(QNetworkReply *reply);
void slotAssistantFinished(int);
Expand All @@ -74,8 +74,6 @@ private slots:
AccountState *applyAccountChanges();

OwncloudWizard *_ocWizard;
QString _initLocalFolder;
QString _remoteFolder;

friend class ownCloudGui;
};
Expand Down
5 changes: 5 additions & 0 deletions src/gui/wizard/abstractcredswizardpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ void AbstractCredentialsWizardPage::cleanupPage()
account->setCredentials(new DummyCredentials);
}
}

OwncloudWizard *AbstractWizardPage::owncloudWizard() const
{
return qobject_cast<OwncloudWizard *>(wizard());
}
}
11 changes: 9 additions & 2 deletions src/gui/wizard/abstractcredswizardpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@
#include <QWizardPage>

namespace OCC {

class OwncloudWizard;
class AbstractCredentials;

/**
* @brief The AbstractCredentialsWizardPage class
* @ingroup gui
*/
class AbstractCredentialsWizardPage : public QWizardPage

class AbstractWizardPage : public QWizardPage
{
public:
OwncloudWizard *owncloudWizard() const;
};

class AbstractCredentialsWizardPage : public AbstractWizardPage
{
public:
void cleanupPage() override;
Expand Down
39 changes: 14 additions & 25 deletions src/gui/wizard/owncloudadvancedsetuppage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@
namespace OCC {

OwncloudAdvancedSetupPage::OwncloudAdvancedSetupPage()
: QWizardPage()
: AbstractWizardPage()
, _ui()
, _checking(false)
, _created(false)
, _localFolderValid(false)
, _progressIndi(new QProgressIndicator(this))
, _remoteFolder()
{
_ui.setupUi(this);

Expand Down Expand Up @@ -86,8 +85,8 @@ OwncloudAdvancedSetupPage::OwncloudAdvancedSetupPage()

_ui.rVirtualFileSync->setText(tr("Use &virtual files instead of downloading content immediately%1").arg(bestAvailableVfsMode() == Vfs::WindowsCfApi ? QString() : tr(" (experimental)")));

connect(this, &OwncloudAdvancedSetupPage::completeChanged, this, [this]{
if (wizard() && qobject_cast<OwncloudWizard*>(wizard())->authType() == OCC::DetermineAuthTypeJob::AuthType::OAuth) {
connect(this, &OwncloudAdvancedSetupPage::completeChanged, this, [this] {
if (wizard() && owncloudWizard()->authType() == OCC::DetermineAuthTypeJob::AuthType::OAuth) {
// For OAuth, disable the back button in the Page_AdvancedSetup because we don't want
// to re-open the browser.
// HACK: the wizard will reenable the buttons on completeChanged, so delay it
Expand Down Expand Up @@ -129,18 +128,14 @@ void OwncloudAdvancedSetupPage::initializePage()
_ui.lSelectiveSyncSizeLabel->clear();
_ui.lSyncEverythingSizeLabel->clear();

// Update the local folder - this is not guaranteed to find a good one
QString goodLocalFolder = FolderMan::instance()->findGoodPathForNewSyncFolder(localFolder());
wizard()->setProperty("localFolder", goodLocalFolder);

// call to init label
updateStatus();

// ensure "next" gets the focus, not obSelectLocalFolder
QTimer::singleShot(0, wizard()->button(QWizard::FinishButton), qOverload<>(&QWidget::setFocus));

auto acc = static_cast<OwncloudWizard *>(wizard())->account();
auto quotaJob = new PropfindJob(acc, _remoteFolder, this);
auto acc = owncloudWizard()->account();
auto quotaJob = new PropfindJob(acc, owncloudWizard()->remoteFolder(), this);
quotaJob->setProperties(QList<QByteArray>() << "http://owncloud.org/ns:size");

connect(quotaJob, &PropfindJob::result, this, &OwncloudAdvancedSetupPage::slotQuotaRetrieved);
Expand All @@ -157,15 +152,15 @@ void OwncloudAdvancedSetupPage::initializePage()
// evtl. warnings on the dialog.
void OwncloudAdvancedSetupPage::updateStatus()
{
const QString locFolder = localFolder();
const QString locFolder = owncloudWizard()->localFolder();

// check if the local folder exists. If so, and if its not empty, show a warning.
QString errorStr = FolderMan::instance()->checkPathValidityForNewFolder(locFolder);
_localFolderValid = errorStr.isEmpty();

_ui.pbSelectLocalFolder->setText(QDir::toNativeSeparators(locFolder));
if (!_remoteFolder.isEmpty() && _remoteFolder != QLatin1String("/")) {
_ui.rSyncEverything->setText(tr("Sync the folder '%1'").arg(_remoteFolder));
if (owncloudWizard()->remoteFolder() != QLatin1String("/")) {
_ui.rSyncEverything->setText(tr("Sync the folder '%1'").arg(owncloudWizard()->remoteFolder()));
}

if (!QDir(locFolder).entryList(QDir::AllEntries | QDir::NoDotAndDotDot).isEmpty()) {
Expand Down Expand Up @@ -198,12 +193,6 @@ int OwncloudAdvancedSetupPage::nextId() const
return -1;
}

QString OwncloudAdvancedSetupPage::localFolder() const
{
QString folder = wizard()->property("localFolder").toString();
return folder;
}

QStringList OwncloudAdvancedSetupPage::selectiveSyncBlacklist() const
{
return _selectiveSyncBlacklist;
Expand Down Expand Up @@ -231,7 +220,7 @@ bool OwncloudAdvancedSetupPage::validatePage()
}

if (useVirtualFileSync()) {
const auto availability = Vfs::checkAvailability(localFolder());
const auto availability = Vfs::checkAvailability(owncloudWizard()->localFolder());
if (!availability) {
auto msg = new QMessageBox(QMessageBox::Warning, tr("Virtual files are not available for the selected folder"), availability.error(), QMessageBox::Ok, this);
msg->setAttribute(Qt::WA_DeleteOnClose);
Expand All @@ -253,7 +242,7 @@ bool OwncloudAdvancedSetupPage::validatePage()
cfgFile.setConfirmExternalStorage(_ui.confCheckBoxExternal->isChecked());
}

emit createLocalAndRemoteFolders(localFolder(), _remoteFolder);
emit owncloudWizard()->createLocalAndRemoteFolders();
return false;
} else {
// connecting is running
Expand Down Expand Up @@ -286,7 +275,7 @@ void OwncloudAdvancedSetupPage::directoriesCreated()
void OwncloudAdvancedSetupPage::setRemoteFolder(const QString &remoteFolder)
{
if (!remoteFolder.isEmpty()) {
_remoteFolder = remoteFolder;
owncloudWizard()->setRemoteFolder(remoteFolder);
}
}

Expand All @@ -295,15 +284,15 @@ void OwncloudAdvancedSetupPage::slotSelectFolder()
QString dir = QFileDialog::getExistingDirectory(nullptr, tr("Local Sync Folder"), QDir::homePath());
if (!dir.isEmpty()) {
_ui.pbSelectLocalFolder->setText(dir);
wizard()->setProperty("localFolder", dir);
owncloudWizard()->setLocalFolder(dir);
updateStatus();
}
}

void OwncloudAdvancedSetupPage::slotSelectiveSyncClicked()
{
AccountPtr acc = static_cast<OwncloudWizard *>(wizard())->account();
SelectiveSyncDialog *dlg = new SelectiveSyncDialog(acc, _remoteFolder, _selectiveSyncBlacklist, this);
AccountPtr acc = owncloudWizard()->account();
SelectiveSyncDialog *dlg = new SelectiveSyncDialog(acc, owncloudWizard()->remoteFolder(), _selectiveSyncBlacklist, this);
dlg->setAttribute(Qt::WA_DeleteOnClose);

connect(dlg, &SelectiveSyncDialog::finished, this, [this, dlg]{
Expand Down

0 comments on commit da5f67f

Please sign in to comment.