make the setings dialog adapt to the pages size
[trojita.git] / src / Gui / SettingsDialog.h
blob4af7c737097ea4cd213a5388a85e9edf04cc0597
1 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
2 Copyright (C) 2012 Mohammed Nafees <nafees.technocool@gmail.com>
4 This file is part of the Trojita Qt IMAP e-mail client,
5 http://trojita.flaska.net/
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of
10 the License or (at your option) version 3 or any later version
11 accepted by the membership of KDE e.V. (or its successor approved
12 by the membership of KDE e.V.), which shall act as a proxy
13 defined in Section 14 of version 3 of the license.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef SETTINGSDIALOG_H
24 #define SETTINGSDIALOG_H
26 #include <QDialog>
27 #include <QPointer>
28 #include <QSettings>
29 #include "Plugins/PasswordPlugin.h"
30 #include "ui_SettingsGeneralPage.h"
31 #include "ui_EditIdentity.h"
32 #include "ui_SettingsImapPage.h"
33 #include "ui_SettingsCachePage.h"
34 #include "ui_SettingsOutgoingPage.h"
36 class QCheckBox;
37 class QComboBox;
38 class QDataWidgetMapper;
39 class QLineEdit;
40 class QRadioButton;
41 class QSpinBox;
42 class QTabWidget;
44 namespace Composer
46 class SenderIdentitiesModel;
49 namespace Plugins
51 class PluginManager;
54 namespace UiUtils {
55 class PasswordWatcher;
58 namespace Imap {
59 class ImapAccess;
62 namespace MSA {
63 class Account;
66 namespace Gui
68 class MainWindow;
69 class SettingsDialog;
71 /** @short Common interface for any page of the settings dialogue */
72 class ConfigurationWidgetInterface {
73 public:
74 virtual void save(QSettings &s) = 0;
75 virtual QWidget *asWidget() = 0;
76 virtual bool checkValidity() const = 0;
77 virtual bool passwordFailures(QString &message) const = 0;
81 class GeneralPage : public QScrollArea, Ui_GeneralPage, public ConfigurationWidgetInterface
83 Q_OBJECT
84 public:
85 GeneralPage(SettingsDialog *parent, QSettings &s, Composer::SenderIdentitiesModel *identitiesModel);
86 virtual void save(QSettings &s);
87 virtual QWidget *asWidget();
88 virtual bool checkValidity() const;
89 virtual bool passwordFailures(QString &message) const;
91 private slots:
92 void updateWidgets();
93 void moveIdentityUp();
94 void moveIdentityDown();
95 void addButtonClicked();
96 void editButtonClicked();
97 void deleteButtonClicked();
98 void passwordPluginChanged();
100 private:
101 Composer::SenderIdentitiesModel *m_identitiesModel;
102 SettingsDialog *m_parent;
104 GeneralPage(const GeneralPage &); // don't implement
105 GeneralPage &operator=(const GeneralPage &); // don't implement
107 signals:
108 void saved();
109 void reloadPasswords();
110 void widgetsUpdated();
113 class EditIdentity : public QDialog, Ui_EditIdentity
115 Q_OBJECT
116 public:
117 EditIdentity(QWidget *parent, Composer::SenderIdentitiesModel *identitiesModel, const QModelIndex &currentIndex);
118 void setDeleteOnReject(const bool reject = true);
120 public slots:
121 void enableButton();
122 void onReject();
124 private:
125 Composer::SenderIdentitiesModel *m_identitiesModel;
126 QDataWidgetMapper *m_mapper;
127 bool m_deleteOnReject;
129 EditIdentity(const EditIdentity &); // don't implement
130 EditIdentity &operator=(const EditIdentity &); // don't implement
132 signals:
133 void saved();
134 void widgetsUpdated();
138 class OutgoingPage : public QScrollArea, Ui_OutgoingPage, public ConfigurationWidgetInterface
140 Q_OBJECT
141 public:
142 OutgoingPage(SettingsDialog *parent, QSettings &s);
143 virtual void save(QSettings &s);
144 virtual QWidget *asWidget();
145 virtual bool checkValidity() const;
146 virtual bool passwordFailures(QString &message) const;
148 private slots:
149 void slotSetSubmissionMethod();
150 void updateWidgets();
151 void slotSetPassword();
152 void showPortWarning(const QString &warning);
153 void setPortByText(const QString &text);
155 private:
157 enum { NETWORK, SENDMAIL, IMAP_SENDMAIL };
158 enum Encryption { SMTP, SMTP_STARTTLS, SSMTP };
160 SettingsDialog *m_parent;
161 UiUtils::PasswordWatcher *m_pwWatcher;
163 MSA::Account *m_smtpAccountSettings;
165 OutgoingPage(const OutgoingPage &); // don't implement
166 OutgoingPage &operator=(const OutgoingPage &); // don't implement
168 signals:
169 void saved();
170 void widgetsUpdated();
173 class ImapPage : public QScrollArea, Ui_ImapPage, public ConfigurationWidgetInterface
175 Q_OBJECT
176 public:
177 ImapPage(SettingsDialog *parent, QSettings &s);
178 virtual void save(QSettings &s);
179 virtual QWidget *asWidget();
180 virtual bool checkValidity() const;
181 virtual bool passwordFailures(QString &message) const;
182 #ifdef XTUPLE_CONNECT
183 bool hasPassword() const;
184 #endif
186 private:
187 enum { NETWORK, PROCESS };
188 enum Encryption { NONE, STARTTLS, SSL };
189 SettingsDialog *m_parent;
190 quint16 m_imapPort;
191 bool m_imapStartTls;
192 UiUtils::PasswordWatcher *m_pwWatcher;
194 private slots:
195 void updateWidgets();
196 void maybeShowPortWarning();
197 void changePort();
198 void slotSetPassword();
200 private:
201 ImapPage(const ImapPage &); // don't implement
202 ImapPage &operator=(const ImapPage &); // don't implement
204 signals:
205 void saved();
206 void widgetsUpdated();
209 class CachePage : public QScrollArea, Ui_CachePage, public ConfigurationWidgetInterface
211 Q_OBJECT
212 public:
213 CachePage(QWidget *parent, QSettings &s);
214 virtual void save(QSettings &s);
215 virtual QWidget *asWidget();
216 virtual bool checkValidity() const;
217 virtual bool passwordFailures(QString &message) const;
219 private:
220 QCheckBox *startOffline;
222 private slots:
223 void updateWidgets();
225 private:
226 CachePage(const CachePage &); // don't implement
227 CachePage &operator=(const CachePage &); // don't implement
229 signals:
230 void saved();
231 void widgetsUpdated();
234 #ifdef XTUPLE_CONNECT
235 class SettingsDialog;
236 class XtConnectPage : public QWidget
238 Q_OBJECT
239 public:
240 XtConnectPage(QWidget *parent, QSettings &s, ImapPage *imapPage);
241 void save(QSettings &s);
242 virtual void showEvent(QShowEvent *event);
243 public slots:
244 void saveXtConfig();
245 void runXtConnect();
246 private:
247 QLineEdit *cacheDir;
248 QPointer<ImapPage> imap;
250 QLineEdit *hostName;
251 QSpinBox *port;
252 QLineEdit *dbName;
253 QLineEdit *username;
254 QLabel *imapPasswordWarning;
255 QCheckBox *debugLog;
257 XtConnectPage(const XtConnectPage &); // don't implement
258 XtConnectPage &operator=(const XtConnectPage &); // don't implement
259 signals:
260 void saved();
261 void widgetsUpdated();
263 #endif
266 class SettingsDialog : public QDialog
268 Q_OBJECT
269 public:
270 SettingsDialog(MainWindow *parent, Composer::SenderIdentitiesModel *identitiesModel, QSettings *settings);
272 Plugins::PluginManager *pluginManager();
273 Imap::ImapAccess* imapAccess();
275 static QString warningStyleSheet;
277 signals:
278 void reloadPasswordsRequested();
280 public slots:
281 void accept();
282 void reject();
283 private slots:
284 void adjustSizeToScrollAreas();
285 void slotAccept();
286 private:
287 MainWindow *mainWindow;
288 QDialogButtonBox *buttons;
289 QTabWidget *stack;
290 QVector<ConfigurationWidgetInterface*> pages;
291 #ifdef XTUPLE_CONNECT
292 XtConnectPage *xtConnect;
293 #endif
294 Composer::SenderIdentitiesModel *m_senderIdentities;
295 QSettings *m_settings;
296 int m_saveSignalCount;
298 SettingsDialog(const SettingsDialog &); // don't implement
299 SettingsDialog &operator=(const SettingsDialog &); // don't implement
301 void addPage(ConfigurationWidgetInterface *page, const QString &title);
306 #endif // SETTINGSDIALOG_H