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