5b7cb8afeb3c178fde448959895ccdd9b519afa0
[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 #ifndef _CORECONFIGWIZARD_H_
22 #define _CORECONFIGWIZARD_H_
23
24 #include <QHash>
25 #include <QWizard>
26 #include <QVariantMap>
27
28 #include "ui_coreconfigwizardintropage.h"
29 #include "ui_coreconfigwizardadminuserpage.h"
30 #include "ui_coreconfigwizardauthenticationselectionpage.h"
31 #include "ui_coreconfigwizardstorageselectionpage.h"
32 #include "ui_coreconfigwizardsyncpage.h"
33
34 class CoreConnection;
35
36 namespace CoreConfigWizardPages {
37 class SyncPage;
38 class SyncRelayPage;
39 };
40
41 class CoreConfigWizard : public QWizard
42 {
43     Q_OBJECT
44
45 public:
46     enum {
47         IntroPage,
48         AdminUserPage,
49         AuthenticationSelectionPage,
50         StorageSelectionPage,
51         SyncPage,
52         SyncRelayPage,
53         StorageDetailsPage,
54         ConclusionPage
55     };
56
57     CoreConfigWizard(CoreConnection *connection, const QList<QVariant> &backends, const QList<QVariant> &authenticators, QWidget *parent = 0);
58     QHash<QString, QVariant> backends() const;
59     QHash<QString, QVariant> authenticators() const;
60
61     inline CoreConnection *coreConnection() const { return _connection; }
62
63 signals:
64     void setupCore(const QVariant &setupData);
65     void loginToCore(const QString &user, const QString &password, bool rememberPassword);
66
67 public slots:
68     void loginSuccess();
69     void syncFinished();
70
71 private slots:
72     void prepareCoreSetup(const QString &backend, const QVariantMap &properties, const QString &authBackend, const QVariantMap &authProperties);
73     void coreSetupSuccess();
74     void coreSetupFailed(const QString &);
75     void startOver();
76
77 private:
78     QHash<QString, QVariant> _backends;
79     QHash<QString, QVariant> _authenticators;
80
81     CoreConfigWizardPages::SyncPage *syncPage;
82     CoreConfigWizardPages::SyncRelayPage *syncRelayPage;
83
84     CoreConnection *_connection;
85 };
86
87
88 namespace CoreConfigWizardPages {
89 class IntroPage : public QWizardPage
90 {
91     Q_OBJECT
92
93 public:
94     IntroPage(QWidget *parent = 0);
95     int nextId() const;
96 private:
97     Ui::CoreConfigWizardIntroPage ui;
98 };
99
100
101 class AdminUserPage : public QWizardPage
102 {
103     Q_OBJECT
104
105 public:
106     AdminUserPage(QWidget *parent = 0);
107     int nextId() const;
108     bool isComplete() const;
109 private:
110     Ui::CoreConfigWizardAdminUserPage ui;
111 };
112
113 // Authentication selection before storage selection.
114 class AuthenticationSelectionPage : public QWizardPage
115 {
116     Q_OBJECT
117
118 public:
119     AuthenticationSelectionPage(const QHash<QString, QVariant> &backends, QWidget *parent = 0);
120     int nextId() const;
121     QString selectedBackend() const;
122     QVariantMap connectionProperties() const;
123
124 private slots:
125     void on_backendList_currentIndexChanged();
126 private:
127     Ui::CoreConfigWizardAuthenticationSelectionPage ui;
128     QGroupBox *_connectionBox;
129     QHash<QString, QVariant> _backends;
130 };
131
132 class StorageSelectionPage : public QWizardPage
133 {
134     Q_OBJECT
135
136 public:
137     StorageSelectionPage(const QHash<QString, QVariant> &backends, QWidget *parent = 0);
138     int nextId() const;
139     QString selectedBackend() const;
140     QVariantMap connectionProperties() const;
141
142 private slots:
143     void on_backendList_currentIndexChanged();
144 private:
145     Ui::CoreConfigWizardStorageSelectionPage ui;
146     QGroupBox *_connectionBox;
147     QHash<QString, QVariant> _backends;
148 };
149
150 class SyncPage : public QWizardPage
151 {
152     Q_OBJECT
153
154 public:
155     SyncPage(QWidget *parent = 0);
156     void initializePage();
157     int nextId() const;
158     bool isComplete() const;
159
160 public slots:
161     void setStatus(const QString &status);
162     void setError(bool);
163     void setComplete(bool);
164
165 signals:
166     void setupCore(const QString &backend, const QVariantMap &, const QString &authenticator, const QVariantMap &);
167
168 private:
169     Ui::CoreConfigWizardSyncPage ui;
170     bool complete;
171     bool hasError;
172 };
173
174
175 class SyncRelayPage : public QWizardPage
176 {
177     Q_OBJECT
178
179 public:
180     SyncRelayPage(QWidget *parent = 0);
181     int nextId() const;
182     enum Mode { Success, Error };
183
184 public slots:
185     void setMode(Mode);
186
187 signals:
188     void startOver() const;
189
190 private:
191     Mode mode;
192 };
193 }
194
195 #endif