1 | /*************************************************************************** |
2 | * Copyright (C) 2005-2014 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 IDENTITY_H |
22 | #define IDENTITY_H |
23 | |
24 | #include <QByteArray> |
25 | #include <QDataStream> |
26 | #include <QMetaType> |
27 | #include <QString> |
28 | #include <QStringList> |
29 | |
30 | #include "types.h" |
31 | #include "syncableobject.h" |
32 | |
33 | class Identity : public SyncableObject |
34 | { |
35 | SYNCABLE_OBJECT |
36 | Q_OBJECT |
37 | |
38 | Q_PROPERTY(IdentityId identityId READ id WRITE setId) |
39 | Q_PROPERTY(QString identityName READ identityName WRITE setIdentityName) |
40 | Q_PROPERTY(QString realName READ realName WRITE setRealName) |
41 | Q_PROPERTY(QStringList nicks READ nicks WRITE setNicks) |
42 | Q_PROPERTY(QString awayNick READ awayNick WRITE setAwayNick) |
43 | Q_PROPERTY(bool awayNickEnabled READ awayNickEnabled WRITE setAwayNickEnabled) |
44 | Q_PROPERTY(QString awayReason READ awayReason WRITE setAwayReason) |
45 | Q_PROPERTY(bool awayReasonEnabled READ awayReasonEnabled WRITE setAwayReasonEnabled) |
46 | Q_PROPERTY(bool autoAwayEnabled READ autoAwayEnabled WRITE setAutoAwayEnabled) |
47 | Q_PROPERTY(int autoAwayTime READ autoAwayTime WRITE setAutoAwayTime) |
48 | Q_PROPERTY(QString autoAwayReason READ autoAwayReason WRITE setAutoAwayReason) |
49 | Q_PROPERTY(bool autoAwayReasonEnabled READ autoAwayReasonEnabled WRITE setAutoAwayReasonEnabled) |
50 | Q_PROPERTY(bool detachAwayEnabled READ detachAwayEnabled WRITE setDetachAwayEnabled) |
51 | Q_PROPERTY(QString detachAwayReason READ detachAwayReason WRITE setDetachAwayReason) |
52 | Q_PROPERTY(bool detachAwayReasonEnabled READ detachAwayReasonEnabled WRITE setDetachAwayReasonEnabled) |
53 | Q_PROPERTY(QString ident READ ident WRITE setIdent) |
54 | Q_PROPERTY(QString kickReason READ kickReason WRITE setKickReason) |
55 | Q_PROPERTY(QString partReason READ partReason WRITE setPartReason) |
56 | Q_PROPERTY(QString quitReason READ quitReason WRITE setQuitReason) |
57 | |
58 | public : |
59 | Identity(IdentityId id = 0, QObject *parent = 0); |
60 | Identity(const Identity &other, QObject *parent = 0); |
61 | inline virtual const QMetaObject *syncMetaObject() const { return &staticMetaObject; } |
62 | |
63 | void setToDefaults(); |
64 | |
65 | bool operator==(const Identity &other) const; |
66 | bool operator!=(const Identity &other) const; |
67 | |
68 | inline bool isValid() const { return id().isValid(); } |
69 | |
70 | inline IdentityId id() const { return _identityId; } |
71 | inline const QString &identityName() const { return _identityName; } |
72 | inline const QString &realName() const { return _realName; } |
73 | inline const QStringList &nicks() const { return _nicks; } |
74 | inline const QString &awayNick() const { return _awayNick; } |
75 | inline bool awayNickEnabled() const { return _awayNickEnabled; } |
76 | inline const QString &awayReason() const { return _awayReason; } |
77 | inline bool awayReasonEnabled() const { return _awayReasonEnabled; } |
78 | inline bool autoAwayEnabled() const { return _autoAwayEnabled; } |
79 | inline int autoAwayTime() const { return _autoAwayTime; } |
80 | inline const QString &autoAwayReason() const { return _autoAwayReason; } |
81 | inline bool autoAwayReasonEnabled() const { return _autoAwayReasonEnabled; } |
82 | inline bool detachAwayEnabled() const { return _detachAwayEnabled; } |
83 | inline const QString &detachAwayReason() const { return _detachAwayReason; } |
84 | inline bool detachAwayReasonEnabled() const { return _detachAwayReasonEnabled; } |
85 | inline const QString &ident() const { return _ident; } |
86 | inline const QString &kickReason() const { return _kickReason; } |
87 | inline const QString &partReason() const { return _partReason; } |
88 | inline const QString &quitReason() const { return _quitReason; } |
89 | |
90 | public slots: |
91 | void setId(IdentityId id); |
92 | void setIdentityName(const QString &name); |
93 | void setRealName(const QString &realName); |
94 | void setNicks(const QStringList &nicks); |
95 | void setAwayNick(const QString &awayNick); |
96 | void setAwayNickEnabled(bool enabled); |
97 | void setAwayReason(const QString &awayReason); |
98 | void setAwayReasonEnabled(bool enabled); |
99 | void setAutoAwayEnabled(bool enabled); |
100 | void setAutoAwayTime(int time); |
101 | void setAutoAwayReason(const QString &reason); |
102 | void setAutoAwayReasonEnabled(bool enabled); |
103 | void setDetachAwayEnabled(bool enabled); |
104 | void setDetachAwayReason(const QString &reason); |
105 | void setDetachAwayReasonEnabled(bool enabled); |
106 | void setIdent(const QString &ident); |
107 | void setKickReason(const QString &reason); |
108 | void setPartReason(const QString &reason); |
109 | void setQuitReason(const QString &reason); |
110 | |
111 | void copyFrom(const Identity &other); |
112 | |
113 | signals: |
114 | void idSet(IdentityId id); |
115 | // void identityNameSet(const QString &name); |
116 | // void realNameSet(const QString &realName); |
117 | void nicksSet(const QStringList &nicks); |
118 | // void awayNickSet(const QString &awayNick); |
119 | // void awayNickEnabledSet(bool); |
120 | // void awayReasonSet(const QString &awayReason); |
121 | // void awayReasonEnabledSet(bool); |
122 | // void autoAwayEnabledSet(bool); |
123 | // void autoAwayTimeSet(int); |
124 | // void autoAwayReasonSet(const QString &); |
125 | // void autoAwayReasonEnabledSet(bool); |
126 | // void detachAwayEnabledSet(bool); |
127 | // void detachAwayReasonSet(const QString &); |
128 | // void detachAwayReasonEnabledSet(bool); |
129 | // void identSet(const QString &); |
130 | // void kickReasonSet(const QString &); |
131 | // void partReasonSet(const QString &); |
132 | // void quitReasonSet(const QString &); |
133 | |
134 | private: |
135 | IdentityId _identityId; |
136 | QString _identityName, _realName; |
137 | QStringList _nicks; |
138 | QString _awayNick; |
139 | bool _awayNickEnabled; |
140 | QString _awayReason; |
141 | bool _awayReasonEnabled; |
142 | bool _autoAwayEnabled; |
143 | int _autoAwayTime; |
144 | QString _autoAwayReason; |
145 | bool _autoAwayReasonEnabled; |
146 | bool _detachAwayEnabled; |
147 | QString _detachAwayReason; |
148 | bool _detachAwayReasonEnabled; |
149 | QString _ident, _kickReason, _partReason, _quitReason; |
150 | |
151 | void init(); |
152 | QString defaultNick(); |
153 | QString defaultRealName(); |
154 | |
155 | friend QDataStream &operator>>(QDataStream &in, Identity &identity); |
156 | }; |
157 | |
158 | |
159 | QDataStream &operator<<(QDataStream &out, Identity identity); |
160 | QDataStream &operator>>(QDataStream &in, Identity &identity); |
161 | |
162 | Q_DECLARE_METATYPE(Identity) |
163 | |
164 | #ifdef HAVE_SSL |
165 | #include <QSslKey> |
166 | #include <QSslCertificate> |
167 | |
168 | class CertManager : public SyncableObject |
169 | { |
170 | SYNCABLE_OBJECT |
171 | Q_OBJECT |
172 | Q_PROPERTY(QByteArray sslKey READ sslKeyPem WRITE setSslKey) |
173 | Q_PROPERTY(QByteArray sslCert READ sslCertPem WRITE setSslCert) |
174 | |
175 | public : |
176 | CertManager(IdentityId id, QObject *parent = 0) : SyncableObject(QString::number(id.toInt()), parent) {} |
177 | inline virtual const QMetaObject *syncMetaObject() const { return &staticMetaObject; } |
178 | |
179 | virtual const QSslKey &sslKey() const = 0; |
180 | inline QByteArray sslKeyPem() const { return sslKey().toPem(); } |
181 | virtual const QSslCertificate &sslCert() const = 0; |
182 | inline QByteArray sslCertPem() const { return sslCert().toPem(); } |
183 | |
184 | public slots: |
185 | inline virtual void setSslKey(const QByteArray &encoded) { SYNC(ARG(encoded)) } |
186 | inline virtual void setSslCert(const QByteArray &encoded) { SYNC(ARG(encoded)) } |
187 | }; |
188 | |
189 | |
190 | #endif // HAVE_SSL |
191 | |
192 | #endif // IDENTITY_H |
193 | |