Skip to content

Commit

Permalink
add a wizard page to check terms of service
Browse files Browse the repository at this point in the history
should enable proper polling while the user check and signs the terms of
service via teh web browser

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
  • Loading branch information
mgallien committed Feb 17, 2025
1 parent 20af49e commit 59c329e
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ set(client_SRCS
wizard/flow2authwidget.cpp
wizard/owncloudsetuppage.h
wizard/owncloudsetuppage.cpp
wizard/termsofservicewizardpage.h
wizard/termsofservicewizardpage.cpp
wizard/owncloudwizardcommon.h
wizard/owncloudwizardcommon.cpp
wizard/owncloudwizard.h
Expand Down
2 changes: 1 addition & 1 deletion src/gui/wizard/flow2authcredspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void Flow2AuthCredsPage::slotFlow2AuthResult(Flow2Auth::Result r, const QString

int Flow2AuthCredsPage::nextId() const
{
return WizardCommon::Page_AdvancedSetup;
return WizardCommon::Page_TermsOfService;
}

void Flow2AuthCredsPage::setConnected()
Expand Down
18 changes: 16 additions & 2 deletions src/gui/wizard/owncloudwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "wizard/welcomepage.h"
#include "wizard/owncloudsetuppage.h"
#include "wizard/owncloudhttpcredspage.h"
#include "wizard/termsofservicewizardpage.h"
#include "wizard/owncloudadvancedsetuppage.h"
#include "wizard/webviewpage.h"
#include "wizard/flow2authcredspage.h"
Expand Down Expand Up @@ -239,9 +240,12 @@ void OwncloudWizard::setRemoteFolder(const QString &remoteFolder)

void OwncloudWizard::successfulStep()
{
const int id(currentId());
const WizardCommon::Pages id{static_cast<WizardCommon::Pages>(currentId())};

switch (id) {
case WizardCommon::Page_Welcome:
break;

case WizardCommon::Page_HttpCreds:
_httpCredsPage->setConnected();
break;
Expand All @@ -258,6 +262,10 @@ void OwncloudWizard::successfulStep()
break;
#endif // WITH_WEBENGINE

case WizardCommon::Page_TermsOfService:
_termsOfServicePage->initializePage();
break;

case WizardCommon::Page_AdvancedSetup:
_advancedSetupPage->directoriesCreated();
break;
Expand Down Expand Up @@ -351,7 +359,13 @@ void OwncloudWizard::slotCurrentPageChanged(int id)

void OwncloudWizard::displayError(const QString &msg, bool retryHTTPonly)
{
switch (currentId()) {
switch (static_cast<WizardCommon::Pages>(currentId())) {
case WizardCommon::Page_Welcome:
case WizardCommon::Page_Flow2AuthCreds:
case WizardCommon::Page_WebView:
case WizardCommon::Page_TermsOfService:
break;

case WizardCommon::Page_ServerSetup:
_setupPage->setErrorString(msg, retryHTTPonly);
break;
Expand Down
14 changes: 8 additions & 6 deletions src/gui/wizard/owncloudwizard.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Q_DECLARE_LOGGING_CATEGORY(lcWizard)
class WelcomePage;
class OwncloudSetupPage;
class OwncloudHttpCredsPage;
class TermsOfServiceWizardPage;
class OwncloudAdvancedSetupPage;
class OwncloudWizardResultPage;
class AbstractCredentials;
Expand Down Expand Up @@ -123,14 +124,15 @@ public slots:
[[nodiscard]] QList<QSize> calculateWizardPageSizes() const;

AccountPtr _account;
WelcomePage *_welcomePage;
OwncloudSetupPage *_setupPage;
OwncloudHttpCredsPage *_httpCredsPage;
Flow2AuthCredsPage *_flow2CredsPage;
OwncloudAdvancedSetupPage *_advancedSetupPage;
WelcomePage *_welcomePage = nullptr;
OwncloudSetupPage *_setupPage = nullptr;
OwncloudHttpCredsPage *_httpCredsPage = nullptr;
Flow2AuthCredsPage *_flow2CredsPage = nullptr;
TermsOfServiceWizardPage *_termsOfServicePage = nullptr;
OwncloudAdvancedSetupPage *_advancedSetupPage = nullptr;
OwncloudWizardResultPage *_resultPage = nullptr;
AbstractCredentialsWizardPage *_credentialsPage = nullptr;
WebViewPage *_webViewPage = nullptr;
WebViewPage*_webViewPage = nullptr;

QStringList _setupLog;

Expand Down
1 change: 1 addition & 0 deletions src/gui/wizard/owncloudwizardcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace WizardCommon {
#ifdef WITH_WEBENGINE
Page_WebView,
#endif // WITH_WEBENGINE
Page_TermsOfService,
Page_AdvancedSetup,
};

Expand Down
71 changes: 71 additions & 0 deletions src/gui/wizard/termsofservicewizardpage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*

Check notice on line 1 in src/gui/wizard/termsofservicewizardpage.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/wizard/termsofservicewizardpage.cpp

File src/gui/wizard/termsofservicewizardpage.cpp does not conform to Custom style guidelines. (lines 17, 23, 26)
* Copyright (C) by Matthieu Gallien <matthieu.gallien@nextcloud.com>
*
* 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 "termsofservicewizardpage.h"

#include "account.h"
#include "owncloudsetupwizard.h"
#include "wizard/owncloudwizard.h"
#include "wizard/owncloudwizardcommon.h"
#include "connectionvalidator.h"

#include <QVBoxLayout>
#include <QDesktopServices>

namespace OCC {

OCC::TermsOfServiceWizardPage::TermsOfServiceWizardPage()

Check warning on line 28 in src/gui/wizard/termsofservicewizardpage.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/wizard/termsofservicewizardpage.cpp:28:1 [cppcoreguidelines-pro-type-member-init]

constructor does not initialize these fields: ,
: QWizardPage()
{
_layout = new QVBoxLayout(this);
}

void OCC::TermsOfServiceWizardPage::initializePage()
{
}

void OCC::TermsOfServiceWizardPage::cleanupPage()
{
}

int OCC::TermsOfServiceWizardPage::nextId() const
{
return WizardCommon::Page_AdvancedSetup;
}

bool OCC::TermsOfServiceWizardPage::isComplete() const
{
return false;
}

void TermsOfServiceWizardPage::slotPollNow()
{
_termsOfServiceChecker = new TermsOfServiceChecker{_ocWizard->account(), this};

connect(_termsOfServiceChecker, &TermsOfServiceChecker::done, this, &TermsOfServiceWizardPage::termsOfServiceChecked);
_termsOfServiceChecker->start();
}

void TermsOfServiceWizardPage::termsOfServiceChecked()
{
if (_termsOfServiceChecker && _termsOfServiceChecker->needToSign()) {
QDesktopServices::openUrl(_ocWizard->account()->url());
} else {
_ocWizard->successfulStep();
delete _termsOfServiceChecker;
_termsOfServiceChecker = nullptr;
}
}

}
54 changes: 54 additions & 0 deletions src/gui/wizard/termsofservicewizardpage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*

Check notice on line 1 in src/gui/wizard/termsofservicewizardpage.h

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/wizard/termsofservicewizardpage.h

File src/gui/wizard/termsofservicewizardpage.h does not conform to Custom style guidelines. (lines 22)
* Copyright (C) by Matthieu Gallien <matthieu.gallien@nextcloud.com>
*
* 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.
*/

#ifndef TERMSOFSERVICEWIZARDPAGE_H
#define TERMSOFSERVICEWIZARDPAGE_H

#include <QWizardPage>

Check failure on line 18 in src/gui/wizard/termsofservicewizardpage.h

View workflow job for this annotation

GitHub Actions / build

src/gui/wizard/termsofservicewizardpage.h:18:10 [clang-diagnostic-error]

'QWizardPage' file not found

class QVBoxLayout;

namespace OCC {

class OwncloudWizard;
class TermsOfServiceChecker;

class TermsOfServiceWizardPage : public QWizardPage
{
Q_OBJECT
public:
TermsOfServiceWizardPage();

void initializePage() override;
void cleanupPage() override;
[[nodiscard]] int nextId() const override;
[[nodiscard]] bool isComplete() const override;

Q_SIGNALS:
void connectToOCUrl(const QString &);
void pollNow();

private Q_SLOTS:
void slotPollNow();
void termsOfServiceChecked();

private:
QVBoxLayout *_layout = nullptr;
OwncloudWizard *_ocWizard = nullptr;
TermsOfServiceChecker *_termsOfServiceChecker = nullptr;
};

} // namespace OCC

#endif // TERMSOFSERVICEWIZARDPAGE_H
2 changes: 1 addition & 1 deletion src/gui/wizard/webviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void WebViewPage::cleanupPage()
}

int WebViewPage::nextId() const {
return WizardCommon::Page_AdvancedSetup;
return WizardCommon::Page_TermsOfService;
}

bool WebViewPage::isComplete() const {
Expand Down

0 comments on commit 59c329e

Please sign in to comment.