modernize: Pass arguments by value and move in constructors
[quassel.git] / src / qtui / settingspages / identitiessettingspage.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 "clientidentity.h"
24 #include "settingspage.h"
25
26 #include "identityeditwidget.h"
27
28 #include "ui_identitiessettingspage.h"
29 #include "ui_createidentitydlg.h"
30 #include "ui_saveidentitiesdlg.h"
31
32 class QAbstractItemModel;
33
34 class IdentitiesSettingsPage : public SettingsPage
35 {
36     Q_OBJECT
37
38 public:
39     IdentitiesSettingsPage(QWidget *parent = nullptr);
40
41     inline bool needsCoreConnection() const override { return true; }
42
43     bool aboutToSave() override;
44
45 public slots:
46     void save() final override;
47     void load() final override;
48
49 private slots:
50     void coreConnectionStateChanged(bool);
51     void clientIdentityCreated(IdentityId);
52     void clientIdentityUpdated();
53     void clientIdentityRemoved(IdentityId);
54
55     void on_identityList_currentIndexChanged(int index);
56
57     void on_addIdentity_clicked();
58     void on_deleteIdentity_clicked();
59     void on_renameIdentity_clicked();
60
61 #ifdef HAVE_SSL
62     void continueUnsecured();
63 #endif
64     void widgetHasChanged();
65     void setWidgetStates();
66
67 private:
68     Ui::IdentitiesSettingsPage ui;
69
70     QHash<IdentityId, CertIdentity *> identities;
71     IdentityId currentId;
72
73     QList<IdentityId> changedIdentities; // for setting the widget changed state
74     QList<IdentityId> deletedIdentities;
75
76     bool _editSsl;
77
78     void insertIdentity(CertIdentity *identity);
79     void removeIdentity(Identity *identity);
80     void renameIdentity(IdentityId id, const QString &newName);
81
82 #ifdef HAVE_SSL
83     QSslKey keyByFilename(const QString &filename);
84     void showKeyState(const QSslKey &key);
85     QSslCertificate certByFilename(const QString &filename);
86     void showCertState(const QSslCertificate &cert);
87 #endif
88
89     bool testHasChanged();
90 };
91
92
93 // ==============================
94 //  Various Dialogs
95 // ==============================
96 class CreateIdentityDlg : public QDialog
97 {
98     Q_OBJECT
99
100 public:
101     CreateIdentityDlg(QAbstractItemModel *model, QWidget *parent = nullptr);
102
103     QString identityName() const;
104     IdentityId duplicateId() const;
105
106 private slots:
107     void on_identityName_textChanged(const QString &text);
108
109 private:
110     Ui::CreateIdentityDlg ui;
111 };
112
113
114 class SaveIdentitiesDlg : public QDialog
115 {
116     Q_OBJECT
117
118 public:
119     SaveIdentitiesDlg(const QList<CertIdentity *> &toCreate, const QList<CertIdentity *> &toUpdate, const QList<IdentityId> &toRemove, QWidget *parent = nullptr);
120
121 private slots:
122     void clientEvent();
123
124 private:
125     Ui::SaveIdentitiesDlg ui;
126
127     int numevents, rcvevents;
128 };