7c97916ec3469c5675cb53b574c1be7c29c0f22b
[quassel.git] / src / qtui / settingspages / identitiessettingspage.h
1 /***************************************************************************
2  *   Copyright (C) 2005-09 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) any later version.                                   *
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  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef IDENTITIESSETTINGSPAGE_H
22 #define IDENTITIESSETTINGSPAGE_H
23
24 #include "clientidentity.h"
25 #include "settingspage.h"
26
27 #include "ui_identitiessettingspage.h"
28 #include "ui_createidentitydlg.h"
29 #include "ui_saveidentitiesdlg.h"
30 #include "ui_nickeditdlg.h"
31
32 #ifdef HAVE_SSL
33 #include <QSslCertificate>
34 #include <QSslKey>
35 #endif
36
37 class QAbstractItemModel;
38
39 class IdentitiesSettingsPage : public SettingsPage {
40   Q_OBJECT
41
42 public:
43   IdentitiesSettingsPage(QWidget *parent = 0);
44
45   bool aboutToSave();
46
47 public slots:
48   void save();
49   void load();
50
51 #ifdef HAVE_SSL
52 protected:
53   virtual bool eventFilter(QObject *watched, QEvent *event);
54 #endif
55
56 private slots:
57   void coreConnectionStateChanged(bool);
58   void clientIdentityCreated(IdentityId);
59   void clientIdentityUpdated();
60   void clientIdentityRemoved(IdentityId);
61
62   void on_identityList_currentIndexChanged(int index);
63
64   void on_addIdentity_clicked();
65   void on_deleteIdentity_clicked();
66   void on_renameIdentity_clicked();
67
68   void on_addNick_clicked();
69   void on_deleteNick_clicked();
70   void on_renameNick_clicked();
71   void on_nickUp_clicked();
72   void on_nickDown_clicked();
73
74 #ifdef HAVE_SSL
75   void on_continueUnsecured_clicked();
76   void on_clearOrLoadKeyButton_clicked();
77   void on_clearOrLoadCertButton_clicked();
78 #endif
79   void widgetHasChanged();
80   void setWidgetStates();
81
82 #ifdef HAVE_SSL
83   void sslDragEnterEvent(QDragEnterEvent *event);
84   void sslDropEvent(QDropEvent *event, bool isCert);
85 #endif
86
87 private:
88   Ui::IdentitiesSettingsPage ui;
89
90   QHash<IdentityId, CertIdentity *> identities;
91   IdentityId currentId;
92
93   QList<IdentityId> changedIdentities;  // for setting the widget changed state
94   QList<IdentityId> deletedIdentities;
95
96   bool _editSsl;
97
98   void insertIdentity(CertIdentity *identity);
99   void removeIdentity(Identity *identity);
100   void renameIdentity(IdentityId id, const QString &newName);
101   void displayIdentity(CertIdentity *, bool dontsave = false);
102   void saveToIdentity(CertIdentity *);
103
104 #ifdef HAVE_SSL
105   QSslKey keyByFilename(const QString &filename);
106   void showKeyState(const QSslKey &key);
107   QSslCertificate certByFilename(const QString &filename);
108   void showCertState(const QSslCertificate &cert);
109 #endif
110
111   bool testHasChanged();
112 };
113
114 class CreateIdentityDlg : public QDialog {
115   Q_OBJECT
116
117 public:
118   CreateIdentityDlg(QAbstractItemModel *model, QWidget *parent = 0);
119
120   QString identityName() const;
121   IdentityId duplicateId() const;
122
123 private slots:
124   void on_identityName_textChanged(const QString &text);
125
126 private:
127   Ui::CreateIdentityDlg ui;
128 };
129
130 class SaveIdentitiesDlg : public QDialog {
131   Q_OBJECT
132
133 public:
134   SaveIdentitiesDlg(const QList<CertIdentity *> &toCreate, const QList<CertIdentity *> &toUpdate, const QList<IdentityId> &toRemove, QWidget *parent = 0);
135
136 private slots:
137   void clientEvent();
138
139 private:
140   Ui::SaveIdentitiesDlg ui;
141
142   int numevents, rcvevents;
143 };
144
145 class NickEditDlg : public QDialog {
146   Q_OBJECT
147
148 public:
149   NickEditDlg(const QString &oldnick, const QStringList &existing = QStringList(), QWidget *parent = 0);
150
151   QString nick() const;
152
153 private slots:
154   void on_nickEdit_textChanged(const QString &);
155
156 private:
157   Ui::NickEditDlg ui;
158
159   QString oldNick;
160   QStringList existing;
161
162 };
163
164 #endif