cmake: avoid de-duplication of user's CXXFLAGS
[quassel.git] / src / qtui / coreconfigwizard.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2022 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #pragma once
22
23 #include <tuple>
24 #include <vector>
25
26 #include <QVariantMap>
27 #include <QWizard>
28
29 #include "ui_coreconfigwizardadminuserpage.h"
30 #include "ui_coreconfigwizardauthenticationselectionpage.h"
31 #include "ui_coreconfigwizardintropage.h"
32 #include "ui_coreconfigwizardstorageselectionpage.h"
33 #include "ui_coreconfigwizardsyncpage.h"
34
35 class CoreConnection;
36
37 namespace CoreConfigWizardPages {
38
39 class SyncPage;
40 class SyncRelayPage;
41
42 }  // namespace CoreConfigWizardPages
43
44 class CoreConfigWizard : public QWizard
45 {
46     Q_OBJECT
47
48 public:
49     enum
50     {
51         IntroPage,
52         AdminUserPage,
53         AuthenticationSelectionPage,
54         StorageSelectionPage,
55         SyncPage,
56         SyncRelayPage,
57         StorageDetailsPage,
58         ConclusionPage
59     };
60
61     CoreConfigWizard(CoreConnection* connection, const QVariantList& backendInfos, const QVariantList& authInfos, QWidget* parent = nullptr);
62
63     inline CoreConnection* coreConnection() const { return _connection; }
64
65 signals:
66     void setupCore(const QVariant& setupData);
67     void loginToCore(const QString& user, const QString& password, bool rememberPassword);
68
69 public slots:
70     void syncFinished();
71
72 private slots:
73     void prepareCoreSetup(const QString& backend,
74                           const QVariantMap& properties,
75                           const QString& authenticator,
76                           const QVariantMap& authProperties);
77     void coreSetupSuccess();
78     void coreSetupFailed(const QString&);
79     void startOver();
80
81 private:
82     CoreConfigWizardPages::SyncPage* syncPage;
83     CoreConfigWizardPages::SyncRelayPage* syncRelayPage;
84
85     CoreConnection* _connection;
86 };
87
88 namespace CoreConfigWizardPages {
89
90 class IntroPage : public QWizardPage
91 {
92     Q_OBJECT
93
94 public:
95     IntroPage(QWidget* parent = nullptr);
96     int nextId() const override;
97
98 private:
99     Ui::CoreConfigWizardIntroPage ui;
100 };
101
102 class AdminUserPage : public QWizardPage
103 {
104     Q_OBJECT
105
106 public:
107     AdminUserPage(QWidget* parent = nullptr);
108     int nextId() const override;
109     bool isComplete() const override;
110
111 private:
112     Ui::CoreConfigWizardAdminUserPage ui;
113 };
114
115 class AuthenticationSelectionPage : public QWizardPage
116 {
117     Q_OBJECT
118     using FieldInfo = std::tuple<QString, QString, QVariant>;
119
120 public:
121     AuthenticationSelectionPage(const QVariantList& authInfos, QWidget* parent = nullptr);
122     int nextId() const override;
123     QString displayName() const;
124     QString authenticator() const;
125     QVariantMap authProperties() const;
126
127 private slots:
128     void on_backendList_currentIndexChanged(int index);
129
130 private:
131     Ui::CoreConfigWizardAuthenticationSelectionPage ui;
132     std::vector<QVariantMap> _authProperties;
133     std::vector<std::vector<FieldInfo>> _authFields;
134 };
135
136 class StorageSelectionPage : public QWizardPage
137 {
138     Q_OBJECT
139     using FieldInfo = std::tuple<QString, QString, QVariant>;
140
141 public:
142     StorageSelectionPage(const QVariantList& backendInfos, QWidget* parent = nullptr);
143     int nextId() const override;
144     QString displayName() const;
145     QString backend() const;
146     QVariantMap backendProperties() const;
147
148 private slots:
149     void on_backendList_currentIndexChanged(int index);
150
151 private:
152     Ui::CoreConfigWizardStorageSelectionPage ui;
153     std::vector<QVariantMap> _backendProperties;
154     std::vector<std::vector<FieldInfo>> _backendFields;
155 };
156
157 class SyncPage : public QWizardPage
158 {
159     Q_OBJECT
160
161 public:
162     SyncPage(QWidget* parent = nullptr);
163     void initializePage() override;
164     int nextId() const override;
165     bool isComplete() const override;
166
167 public slots:
168     void setStatus(const QString& status);
169     void setError(bool);
170     void setComplete(bool);
171
172 signals:
173     void setupCore(const QString& backend, const QVariantMap&, const QString& authenticator, const QVariantMap&);
174
175 private:
176     Ui::CoreConfigWizardSyncPage ui;
177     bool _complete{false};
178     bool _hasError{false};
179 };
180
181 class SyncRelayPage : public QWizardPage
182 {
183     Q_OBJECT
184
185 public:
186     SyncRelayPage(QWidget* parent = nullptr);
187     int nextId() const override;
188     enum Mode
189     {
190         Success,
191         Error
192     };
193
194 public slots:
195     void setMode(Mode);
196
197 signals:
198     void startOver() const;
199
200 private:
201     Mode mode;
202 };
203
204 }  // namespace CoreConfigWizardPages