Skip to content

Commit

Permalink
Allow Quit from Initial Setup
Browse files Browse the repository at this point in the history
Signed-off-by: Elsie Hupp <[email protected]>
  • Loading branch information
elsiehupp committed May 8, 2021
1 parent e0dd06b commit 3b0f663
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/gui/wizard/owncloudhttpcredspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ void OwncloudHttpCredsPage::cleanupPage()
{
_ui.leUsername->clear();
_ui.lePassword->clear();
// Cancel button is shown again if you go back to the first page
_ocWizard->setOption(QWizard::CancelButtonOnLeft);
}

bool OwncloudHttpCredsPage::validatePage()
Expand Down
2 changes: 2 additions & 0 deletions src/gui/wizard/owncloudsetuppage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ bool OwncloudSetupPage::validatePage()
stopSpinner();
_checking = false;
emit completeChanged();
// Cancel button is only shown on the first page
_ocWizard->setOption(QWizard::NoCancelButton);
return true;
}
}
Expand Down
38 changes: 33 additions & 5 deletions src/gui/wizard/owncloudwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "configfile.h"
#include "theme.h"
#include "owncloudgui.h"
#include "common/utility.h"

#include "wizard/owncloudwizard.h"
#include "wizard/welcomepage.h"
Expand Down Expand Up @@ -68,6 +69,27 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)
setPage(WizardCommon::Page_Result, _resultPage);
setPage(WizardCommon::Page_WebView, _webViewPage);

// Add keyboard shortcut to allow the user to cancel wizard
auto *closeWindowAction = new QAction(this);
closeWindowAction->setShortcut(QKeySequence("Ctrl+W"));
connect(closeWindowAction, &QAction::triggered, this, &OwncloudWizard::reject);
addAction(closeWindowAction);

// Add keyboard shortcut to allow the user to quit
auto *quitAction = new QAction(this);
quitAction->setShortcut(QKeySequence("Ctrl+Q"));
connect(quitAction, &QAction::triggered, this, &QApplication::quit);
addAction(quitAction);

// Enable "Cancel" button
// (Will be re-disabled on second page of wizard)
// reject() is set to quit() if no accounts are set up
OwncloudWizard::setOption(QWizard::CancelButtonOnLeft);

if (AccountManager::instance()->accounts().isEmpty()) {
setButtonText(WizardButton::CancelButton, tr("Exit"));
}

connect(this, &QDialog::finished, this, &OwncloudWizard::basicSetupFinished);

// note: start Id is set by the calling class depending on if the
Expand All @@ -89,7 +111,6 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)
setWizardStyle(QWizard::ModernStyle);
setOption(QWizard::NoBackButtonOnStartPage);
setOption(QWizard::NoBackButtonOnLastPage);
setOption(QWizard::NoCancelButton);
setButtonText(QWizard::CustomButton1, tr("Skip folders configuration"));

// Change the next buttons size policy since we hide it on the
Expand All @@ -116,10 +137,7 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)
void OwncloudWizard::centerWindow()
{
const auto wizardWindow = window();
const auto screen = QGuiApplication::screenAt(wizardWindow->pos())
? QGuiApplication::screenAt(wizardWindow->pos())
: QGuiApplication::primaryScreen();
const auto screenGeometry = screen->geometry();
const auto screenGeometry = QGuiApplication::screenAt(wizardWindow->pos())->geometry();
const auto windowGeometry = wizardWindow->geometry();
const auto newWindowPosition = screenGeometry.center() - QPoint(windowGeometry.width() / 2, windowGeometry.height() / 2);
wizardWindow->move(newWindowPosition);
Expand Down Expand Up @@ -155,6 +173,16 @@ int OwncloudWizard::calculateLongestSideOfWizardPages(const QList<QSize> &pageSi
});
}

void OwncloudWizard::reject()
{
QWizard::reject();

// Quit if the user has never completed the wizard
if (AccountManager::instance()->accounts().isEmpty()) {
QApplication::quit();
}
}

void OwncloudWizard::setAccount(AccountPtr account)
{
_account = account;
Expand Down
1 change: 1 addition & 0 deletions src/gui/wizard/owncloudwizard.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public slots:

private:
void customizeStyle();
void reject() override;
void adjustWizardSize();
int calculateLongestSideOfWizardPages(const QList<QSize> &pageSizes) const;
QList<QSize> calculateWizardPageSizes() const;
Expand Down

0 comments on commit 3b0f663

Please sign in to comment.