Skip to content

Commit

Permalink
Split out wizard welcome page
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Weilbach <[email protected]>
  • Loading branch information
Felix Weilbach committed Feb 16, 2021
1 parent a94233d commit 27d56c6
Show file tree
Hide file tree
Showing 17 changed files with 770 additions and 5 deletions.
3 changes: 2 additions & 1 deletion NEXTCLOUD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ option( WITH_PROVIDERS "Build with providers list" ON )


## Theming options
set( APPLICATION_WIZARD_HEADER_BACKGROUND_COLOR "#0082c9" CACHE STRING "Hex color of the wizard header background")
set(NEXTCLOUD_BACKGROUND_COLOR "#0082c9" CACHE STRING "Default Nextcloud background color")
set( APPLICATION_WIZARD_HEADER_BACKGROUND_COLOR ${NEXTCLOUD_BACKGROUND_COLOR} CACHE STRING "Hex color of the wizard header background")
set( APPLICATION_WIZARD_HEADER_TITLE_COLOR "#ffffff" CACHE STRING "Hex color of the text in the wizard header")
option( APPLICATION_WIZARD_USE_CUSTOM_LOGO "Use the logo from ':/client/theme/colored/wizard_logo.(png|svg)' else the default application icon is used" ON )

Expand Down
1 change: 1 addition & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#cmakedefine APPLICATION_SERVER_URL_ENFORCE "@APPLICATION_SERVER_URL_ENFORCE@"
#cmakedefine LINUX_APPLICATION_ID "@LINUX_APPLICATION_ID@"
#cmakedefine APPLICATION_WIZARD_HEADER_BACKGROUND_COLOR "@APPLICATION_WIZARD_HEADER_BACKGROUND_COLOR@"
#cmakedefine NEXTCLOUD_BACKGROUND_COLOR "@NEXTCLOUD_BACKGROUND_COLOR@"
#cmakedefine APPLICATION_WIZARD_HEADER_TITLE_COLOR "@APPLICATION_WIZARD_HEADER_TITLE_COLOR@"
#cmakedefine APPLICATION_WIZARD_USE_CUSTOM_LOGO "@APPLICATION_WIZARD_USE_CUSTOM_LOGO@"
#cmakedefine APPLICATION_VIRTUALFILE_SUFFIX "@APPLICATION_VIRTUALFILE_SUFFIX@"
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ set(client_UI_SRCS
wizard/owncloudsetupnocredspage.ui
wizard/owncloudwizardresultpage.ui
wizard/webview.ui
wizard/welcomepage.ui
)

set(client_SRCS
Expand Down Expand Up @@ -134,6 +135,7 @@ set(client_SRCS
wizard/webviewpage.cpp
wizard/webview.cpp
wizard/slideshow.cpp
wizard/welcomepage.cpp
)

IF(BUILD_UPDATER)
Expand Down
7 changes: 6 additions & 1 deletion src/gui/owncloudsetupwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ void OwncloudSetupWizard::startWizard()

_ocWizard->setRemoteFolder(_remoteFolder);

_ocWizard->setStartId(WizardCommon::Page_ServerSetup);
#ifdef WITH_PROVIDERS
const auto startPage = WizardCommon::Page_Welcome;
#else // WITH_PROVIDERS
const auto startPage = WizardCommon::Page_ServerSetup;
#endif // WITH_PROVIDERS
_ocWizard->setStartId(startPage);

_ocWizard->restart();

Expand Down
37 changes: 36 additions & 1 deletion src/gui/wizard/owncloudwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "owncloudgui.h"

#include "wizard/owncloudwizard.h"
#include "wizard/welcomepage.h"
#include "wizard/owncloudsetuppage.h"
#include "wizard/owncloudhttpcredspage.h"
#include "wizard/owncloudoauthcredspage.h"
Expand All @@ -46,6 +47,9 @@ Q_LOGGING_CATEGORY(lcWizard, "nextcloud.gui.wizard", QtInfoMsg)
OwncloudWizard::OwncloudWizard(QWidget *parent)
: QWizard(parent)
, _account(nullptr)
#ifdef WITH_PROVIDERS
, _welcomePage(new WelcomePage(this))
#endif // WITH_PROVIDERS
, _setupPage(new OwncloudSetupPage(this))
, _httpCredsPage(new OwncloudHttpCredsPage(this))
, _browserCredsPage(new OwncloudOAuthCredsPage)
Expand All @@ -57,6 +61,9 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)
setObjectName("owncloudWizard");

setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
#ifdef WITH_PROVIDERS
setPage(WizardCommon::Page_Welcome, _welcomePage);
#endif // WITH_PROVIDERS
setPage(WizardCommon::Page_ServerSetup, _setupPage);
setPage(WizardCommon::Page_HttpCreds, _httpCredsPage);
setPage(WizardCommon::Page_OAuthCreds, _browserCredsPage);
Expand Down Expand Up @@ -94,6 +101,12 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)
setSubTitleFormat(Qt::RichText);
setButtonText(QWizard::CustomButton1, tr("Skip folders configuration"));

// Change the next buttons size policy since we hide it on the
// welcome page but want it to fill it's space that we don't get
// flickering when the page changes
auto nextButtonSizePolicy = button(QWizard::NextButton)->sizePolicy();
nextButtonSizePolicy.setRetainSizeWhenHidden(true);
button(QWizard::NextButton)->setSizePolicy(nextButtonSizePolicy);

// Connect styleChanged events to our widgets, so they can adapt (Dark-/Light-Mode switching)
connect(this, &OwncloudWizard::styleChanged, _setupPage, &OwncloudSetupPage::slotStyleChanged);
Expand Down Expand Up @@ -220,6 +233,29 @@ void OwncloudWizard::slotCurrentPageChanged(int id)
{
qCDebug(lcWizard) << "Current Wizard page changed to " << id;

const auto setNextButtonAsDefault = [this]() {
auto nextButton = qobject_cast<QPushButton *>(button(QWizard::NextButton));
if (nextButton) {
nextButton->setDefault(true);
nextButton->setFocus();
}
};

if (id == WizardCommon::Page_Welcome) {
// Set next button to just hidden so it retains it's layout
button(QWizard::NextButton)->setHidden(true);
// Need to set it from here, otherwise it has no effect
_welcomePage->setLoginButtonDefault();
} else if (id == WizardCommon::Page_WebView || id == WizardCommon::Page_Flow2AuthCreds) {
setButtonLayout({ QWizard::Stretch, QWizard::BackButton });
} else if (id == WizardCommon::Page_AdvancedSetup) {
setButtonLayout({ QWizard::Stretch, QWizard::CustomButton1, QWizard::BackButton, QWizard::NextButton });
setNextButtonAsDefault();
} else {
setButtonLayout({ QWizard::Stretch, QWizard::BackButton, QWizard::NextButton });
setNextButtonAsDefault();
}

if (id == WizardCommon::Page_ServerSetup) {
emit clearPendingRequests();
}
Expand All @@ -232,7 +268,6 @@ void OwncloudWizard::slotCurrentPageChanged(int id)
done(Accepted);
}

setOption(QWizard::HaveCustomButton1, id == WizardCommon::Page_AdvancedSetup);
if (id == WizardCommon::Page_AdvancedSetup && (_credentialsPage == _browserCredsPage || _credentialsPage == _flow2CredsPage)) {
// For OAuth, disable the back button in the Page_AdvancedSetup because we don't want
// to re-open the browser.
Expand Down
2 changes: 2 additions & 0 deletions src/gui/wizard/owncloudwizard.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace OCC {

Q_DECLARE_LOGGING_CATEGORY(lcWizard)

class WelcomePage;
class OwncloudSetupPage;
class OwncloudHttpCredsPage;
class OwncloudOAuthCredsPage;
Expand Down Expand Up @@ -115,6 +116,7 @@ public slots:
void customizeStyle();

AccountPtr _account;
WelcomePage *_welcomePage;
OwncloudSetupPage *_setupPage;
OwncloudHttpCredsPage *_httpCredsPage;
OwncloudOAuthCredsPage *_browserCredsPage;
Expand Down
75 changes: 75 additions & 0 deletions src/gui/wizard/owncloudwizardcommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include <QLabel>
#include <QPixmap>
#include <QVariant>
#include <QRadioButton>
#include <QAbstractButton>
#include <QCheckBox>
#include <QSpinBox>

#include "wizard/owncloudwizardcommon.h"
#include "theme.h"
Expand Down Expand Up @@ -68,6 +72,77 @@ namespace WizardCommon {
errorLabel->setVisible(false);
}

void customizeSpinBoxStyle(QSpinBox *spinBox)
{
auto spinBoxPalette = spinBox->palette();
#ifdef Q_OS_WIN
// Windows always uses a SpinBox with a white background but we change the color of the text so we need
// to change the text color here
spinBoxPalette.setColor(QPalette::Text, Qt::black);
QColor colorTextDisabled(spinBoxPalette.color(QPalette::Text));
colorTextDisabled.setAlpha(128);
spinBoxPalette.setColor(QPalette::Disabled, QPalette::Text, colorTextDisabled);
#endif
#ifdef Q_OS_LINUX

spinBoxPalette.setColor(QPalette::WindowText, Theme::instance()->wizardHeaderBackgroundColor());
QColor colorWindowTextDisabled(spinBoxPalette.color(QPalette::WindowText));
colorWindowTextDisabled.setAlpha(128);
spinBoxPalette.setColor(QPalette::Disabled, QPalette::WindowText, colorWindowTextDisabled);
#endif
spinBox->setPalette(spinBoxPalette);
}

void customizeSecondaryButtonStyle(QAbstractButton *button)
{
#ifdef Q_OS_LINUX
// Only style push buttons on Linux as on other platforms we are unable to style the background color
auto pushButtonPalette = button->palette();
pushButtonPalette.setColor(QPalette::ButtonText, Theme::instance()->wizardHeaderTitleColor());
pushButtonPalette.setColor(QPalette::Button, Theme::instance()->wizardHeaderBackgroundColor());
button->setPalette(pushButtonPalette);
#endif
Q_UNUSED(button);
}

void customizeLinkButtonStyle(QAbstractButton *button)
{
auto buttonPalette = button->palette();
buttonPalette.setColor(QPalette::ButtonText, Theme::instance()->wizardHeaderTitleColor());
button->setPalette(buttonPalette);
}

void customizePrimaryButtonStyle(QAbstractButton *button)
{
#ifdef Q_OS_LINUX
// Only style push buttons on Linux as on other platforms we are unable to style the background color
auto pushButtonPalette = button->palette();

pushButtonPalette.setColor(QPalette::Button, Theme::instance()->wizardHeaderTitleColor());
auto disabledButtonColor = pushButtonPalette.color(QPalette::Button);
disabledButtonColor.setAlpha(128);
pushButtonPalette.setColor(QPalette::Disabled, QPalette::Button, disabledButtonColor);

pushButtonPalette.setColor(QPalette::ButtonText, Theme::instance()->wizardHeaderBackgroundColor());
auto disabledButtonTextColor = pushButtonPalette.color(QPalette::ButtonText);
disabledButtonTextColor.setAlpha(128);
pushButtonPalette.setColor(QPalette::Disabled, QPalette::ButtonText, disabledButtonTextColor);

button->setPalette(pushButtonPalette);
#endif
Q_UNUSED(button);
}

void customizeHintLabel(QLabel *label)
{
QColor textColor(Theme::instance()->wizardHeaderTitleColor());
textColor.setAlpha(128);

auto palette = label->palette();
palette.setColor(QPalette::Text, textColor);
label->setPalette(palette);
}

} // ns WizardCommon

} // namespace OCC
10 changes: 10 additions & 0 deletions src/gui/wizard/owncloudwizardcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

class QVariant;
class QLabel;
class QRadioButton;
class QSpinBox;
class QCheckBox;
class QAbstractButton;

namespace OCC {

Expand All @@ -27,13 +31,19 @@ namespace WizardCommon {
QString titleTemplate();
QString subTitleTemplate();
void initErrorLabel(QLabel *errorLabel);
void customizeSpinBoxStyle(QSpinBox *spinBox);
void customizeSecondaryButtonStyle(QAbstractButton *button);
void customizePrimaryButtonStyle(QAbstractButton *button);
void customizeLinkButtonStyle(QAbstractButton *button);
void customizeHintLabel(QLabel *label);

enum SyncMode {
SelectiveMode,
BoxMode
};

enum Pages {
Page_Welcome,
Page_ServerSetup,
Page_HttpCreds,
Page_ShibbolethCreds,
Expand Down
112 changes: 112 additions & 0 deletions src/gui/wizard/welcomepage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (C) 2021 by Felix Weilbach <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/

#include <QDesktopServices>

#include "welcomepage.h"
#include "theme.h"
#include "wizard/owncloudwizard.h"
#include "wizard/slideshow.h"

namespace OCC {

WelcomePage::WelcomePage(OwncloudWizard *ocWizard)
: QWizardPage()
, _ocWizard(ocWizard)
{
setupUi();
}

void WelcomePage::setupUi()
{
_ui.setupUi(this);
setupSlideShow();
setupLoginButton();
setupCreateAccountButton();
setupHostYourOwnServerButton();
}

void WelcomePage::initializePage()
{
customizeStyle();
}

void WelcomePage::setLoginButtonDefault(bool value)
{
_ui.loginButton->setDefault(value);
_ui.loginButton->setFocus();
}

void WelcomePage::styleSlideShow()
{
const auto backgroundColor = palette().window().color();
_ui.slideShow->addSlide(Theme::hidpiFileName("wizard-nextcloud.png", backgroundColor), tr("Keep your data secure and under your control"));
_ui.slideShow->addSlide(Theme::hidpiFileName("wizard-files.png", backgroundColor), tr("Secure collaboration & file exchange"));
_ui.slideShow->addSlide(Theme::hidpiFileName("wizard-groupware.png", backgroundColor), tr("Easy-to-use web mail, calendaring & contacts"));
_ui.slideShow->addSlide(Theme::hidpiFileName("wizard-talk.png", backgroundColor), tr("Screensharing, online meetings & web conferences"));

const auto theme = Theme::instance();
const auto isDarkBackground = Theme::isDarkColor(backgroundColor);
_ui.slideShowNextButton->setIcon(theme->uiThemeIcon(QString("control-next.svg"), isDarkBackground));
_ui.slideShowPreviousButton->setIcon(theme->uiThemeIcon(QString("control-prev.svg"), isDarkBackground));
}

void WelcomePage::setupSlideShow()
{
connect(_ui.slideShow, &SlideShow::clicked, _ui.slideShow, &SlideShow::stopShow);
connect(_ui.slideShowNextButton, &QPushButton::clicked, _ui.slideShow, &SlideShow::nextSlide);
connect(_ui.slideShowPreviousButton, &QPushButton::clicked, _ui.slideShow, &SlideShow::prevSlide);
}

void WelcomePage::setupLoginButton()
{
const auto appName = Theme::instance()->appNameGUI();

_ui.loginButton->setText(tr("Log in to your %1").arg(appName));
connect(_ui.loginButton, &QPushButton::clicked, this, [this](bool /*checked*/) {
_nextPage = WizardCommon::Page_ServerSetup;
_ocWizard->next();
});
}

void WelcomePage::setupCreateAccountButton()
{
connect(_ui.createAccountButton, &QPushButton::clicked, this, [this](bool /*checked*/) {
_ocWizard->setRegistration(true);
_nextPage = WizardCommon::Page_WebView;
_ocWizard->next();
});
}

void WelcomePage::setupHostYourOwnServerButton()
{
connect(_ui.hostYourOwnServerButton, &QPushButton::clicked, this, [] {
QDesktopServices::openUrl(QUrl("https://docs.nextcloud.com/server/latest/admin_manual/installation/#installation"));
});
}

int WelcomePage::nextId() const
{
return _nextPage;
}

void WelcomePage::customizeStyle()
{
WizardCommon::customizeSecondaryButtonStyle(_ui.createAccountButton);
WizardCommon::customizePrimaryButtonStyle(_ui.loginButton);
WizardCommon::customizeLinkButtonStyle(_ui.hostYourOwnServerButton);

styleSlideShow();
}
}
Loading

0 comments on commit 27d56c6

Please sign in to comment.