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