uisupport: Provide helpers for dealing with widget changes
[quassel.git] / src / qtui / coreconfigwizard.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 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 <QWizard>
27 #include <QVariantMap>
28
29 #include "ui_coreconfigwizardintropage.h"
30 #include "ui_coreconfigwizardadminuserpage.h"
31 #include "ui_coreconfigwizardauthenticationselectionpage.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 }
43
44 class CoreConfigWizard : public QWizard
45 {
46     Q_OBJECT
47
48 public:
49     enum {
50         IntroPage,
51         AdminUserPage,
52         AuthenticationSelectionPage,
53         StorageSelectionPage,
54         SyncPage,
55         SyncRelayPage,
56         StorageDetailsPage,
57         ConclusionPage
58     };
59
60     CoreConfigWizard(CoreConnection *connection, const QVariantList &backendInfos, const QVariantList &authInfos, QWidget *parent = nullptr);
61
62     inline CoreConnection *coreConnection() const { return _connection; }
63
64 signals:
65     void setupCore(const QVariant &setupData);
66     void loginToCore(const QString &user, const QString &password, bool rememberPassword);
67
68 public slots:
69     void syncFinished();
70
71 private slots:
72     void prepareCoreSetup(const QString &backend, const QVariantMap &properties, const QString &authenticator, const QVariantMap &authProperties);
73     void coreSetupSuccess();
74     void coreSetupFailed(const QString &);
75     void startOver();
76
77 private:
78     CoreConfigWizardPages::SyncPage *syncPage;
79     CoreConfigWizardPages::SyncRelayPage *syncRelayPage;
80
81     CoreConnection *_connection;
82 };
83
84
85 namespace CoreConfigWizardPages {
86
87 class IntroPage : public QWizardPage
88 {
89     Q_OBJECT
90
91 public:
92     IntroPage(QWidget *parent = nullptr);
93     int nextId() const override;
94 private:
95     Ui::CoreConfigWizardIntroPage ui;
96 };
97
98
99 class AdminUserPage : public QWizardPage
100 {
101     Q_OBJECT
102
103 public:
104     AdminUserPage(QWidget *parent = nullptr);
105     int nextId() const override;
106     bool isComplete() const override;
107 private:
108     Ui::CoreConfigWizardAdminUserPage ui;
109 };
110
111
112 class AuthenticationSelectionPage : public QWizardPage
113 {
114     Q_OBJECT
115     using FieldInfo = std::tuple<QString, QString, QVariant>;
116
117 public:
118     AuthenticationSelectionPage(const QVariantList &authInfos, QWidget *parent = nullptr);
119     int nextId() const override;
120     QString displayName() const;
121     QString authenticator() const;
122     QVariantMap authProperties() const;
123
124 private slots:
125     void on_backendList_currentIndexChanged(int index);
126
127 private:
128     Ui::CoreConfigWizardAuthenticationSelectionPage ui;
129     std::vector<QVariantMap> _authProperties;
130     std::vector<std::vector<FieldInfo>> _authFields;
131 };
132
133
134 class StorageSelectionPage : public QWizardPage
135 {
136     Q_OBJECT
137     using FieldInfo = std::tuple<QString, QString, QVariant>;
138
139 public:
140     StorageSelectionPage(const QVariantList &backendInfos, QWidget *parent = nullptr);
141     int nextId() const override;
142     QString displayName() const;
143     QString backend() const;
144     QVariantMap backendProperties() const;
145
146 private slots:
147     void on_backendList_currentIndexChanged(int index);
148
149 private:
150     Ui::CoreConfigWizardStorageSelectionPage ui;
151     std::vector<QVariantMap> _backendProperties;
152     std::vector<std::vector<FieldInfo>> _backendFields;
153 };
154
155
156 class SyncPage : public QWizardPage
157 {
158     Q_OBJECT
159
160 public:
161     SyncPage(QWidget *parent = nullptr);
162     void initializePage() override;
163     int nextId() const override;
164     bool isComplete() const override;
165
166 public slots:
167     void setStatus(const QString &status);
168     void setError(bool);
169     void setComplete(bool);
170
171 signals:
172     void setupCore(const QString &backend, const QVariantMap &, const QString &authenticator, const QVariantMap &);
173
174 private:
175     Ui::CoreConfigWizardSyncPage ui;
176     bool _complete {false};
177     bool _hasError {false};
178 };
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 { Success, Error };
189
190 public slots:
191     void setMode(Mode);
192
193 signals:
194     void startOver() const;
195
196 private:
197     Mode mode;
198 };
199
200 }