1 /***************************************************************************
2 * Copyright (C) 2005-2018 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
23 #include "common-export.h"
26 #include <QDataStream>
29 #include <QStringList>
32 #include "syncableobject.h"
34 class COMMON_EXPORT Identity : public SyncableObject
39 Q_PROPERTY(IdentityId identityId READ id WRITE setId)
40 Q_PROPERTY(QString identityName READ identityName WRITE setIdentityName)
41 Q_PROPERTY(QString realName READ realName WRITE setRealName)
42 Q_PROPERTY(QStringList nicks READ nicks WRITE setNicks)
43 Q_PROPERTY(QString awayNick READ awayNick WRITE setAwayNick)
44 Q_PROPERTY(bool awayNickEnabled READ awayNickEnabled WRITE setAwayNickEnabled)
45 Q_PROPERTY(QString awayReason READ awayReason WRITE setAwayReason)
46 Q_PROPERTY(bool awayReasonEnabled READ awayReasonEnabled WRITE setAwayReasonEnabled)
47 Q_PROPERTY(bool autoAwayEnabled READ autoAwayEnabled WRITE setAutoAwayEnabled)
48 Q_PROPERTY(int autoAwayTime READ autoAwayTime WRITE setAutoAwayTime)
49 Q_PROPERTY(QString autoAwayReason READ autoAwayReason WRITE setAutoAwayReason)
50 Q_PROPERTY(bool autoAwayReasonEnabled READ autoAwayReasonEnabled WRITE setAutoAwayReasonEnabled)
51 Q_PROPERTY(bool detachAwayEnabled READ detachAwayEnabled WRITE setDetachAwayEnabled)
52 Q_PROPERTY(QString detachAwayReason READ detachAwayReason WRITE setDetachAwayReason)
53 Q_PROPERTY(bool detachAwayReasonEnabled READ detachAwayReasonEnabled WRITE setDetachAwayReasonEnabled)
54 Q_PROPERTY(QString ident READ ident WRITE setIdent)
55 Q_PROPERTY(QString kickReason READ kickReason WRITE setKickReason)
56 Q_PROPERTY(QString partReason READ partReason WRITE setPartReason)
57 Q_PROPERTY(QString quitReason READ quitReason WRITE setQuitReason)
60 Identity(IdentityId id = 0, QObject *parent = 0);
61 Identity(const Identity &other, QObject *parent = 0);
65 bool operator==(const Identity &other) const;
66 bool operator!=(const Identity &other) const;
68 inline bool isValid() const { return id().isValid(); }
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; }
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);
111 void copyFrom(const Identity &other);
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 &);
135 IdentityId _identityId;
136 QString _identityName, _realName;
139 bool _awayNickEnabled;
141 bool _awayReasonEnabled;
142 bool _autoAwayEnabled;
144 QString _autoAwayReason;
145 bool _autoAwayReasonEnabled;
146 bool _detachAwayEnabled;
147 QString _detachAwayReason;
148 bool _detachAwayReasonEnabled;
149 QString _ident, _kickReason, _partReason, _quitReason;
152 QString defaultNick();
153 QString defaultRealName();
155 friend QDataStream &operator>>(QDataStream &in, Identity &identity);
159 QDataStream &operator<<(QDataStream &out, Identity identity);
160 QDataStream &operator>>(QDataStream &in, Identity &identity);
162 Q_DECLARE_METATYPE(Identity)
166 #include <QSslCertificate>
168 class COMMON_EXPORT CertManager : public SyncableObject
173 Q_PROPERTY(QByteArray sslKey READ sslKeyPem WRITE setSslKey)
174 Q_PROPERTY(QByteArray sslCert READ sslCertPem WRITE setSslCert)
177 CertManager(IdentityId id, QObject *parent = 0) : SyncableObject(QString::number(id.toInt()), parent) {}
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(); }
185 inline virtual void setSslKey(const QByteArray &encoded) { SYNC(ARG(encoded)) }
186 inline virtual void setSslCert(const QByteArray &encoded) { SYNC(ARG(encoded)) }