1 /***************************************************************************
2 * Copyright (C) 2005-08 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include <QMetaProperty>
22 #include <QVariantMap>
26 Identity::Identity(IdentityId id, QObject *parent) : SyncableObject(parent), _identityId(id) {
31 Identity::Identity(const Identity &other, QObject *parent) : SyncableObject(parent),
32 _identityId(other.id()),
33 _identityName(other.identityName()),
34 _realName(other.realName()),
35 _nicks(other.nicks()),
36 _awayNick(other.awayNick()),
37 _awayNickEnabled(other.awayNickEnabled()),
38 _awayReason(other.awayReason()),
39 _awayReasonEnabled(other.awayReasonEnabled()),
40 _autoAwayEnabled(other.autoAwayEnabled()),
41 _autoAwayTime(other.autoAwayTime()),
42 _autoAwayReason(other.autoAwayReason()),
43 _autoAwayReasonEnabled(other.autoAwayReasonEnabled()),
44 _detachAwayEnabled(other.detachAwayEnabled()),
45 _detachAwayReason(other.detachAwayReason()),
46 _detachAwayReasonEnabled(other.detachAwayReasonEnabled()),
47 _ident(other.ident()),
48 _kickReason(other.kickReason()),
49 _partReason(other.partReason()),
50 _quitReason(other.quitReason())
56 void Identity::init() {
57 setObjectName(QString::number(id().toInt()));
60 void Identity::setToDefaults() {
61 setIdentityName(tr("<empty>"));
62 setRealName(tr("Quassel IRC User"));
64 n << QString("quassel%1").arg(qrand() & 0xff); // FIXME provide more sensible default nicks
67 setAwayNickEnabled(false);
68 setAwayReason(tr("Gone fishing."));
69 setAwayReasonEnabled(true);
70 setAutoAwayEnabled(false);
72 setAutoAwayReason(tr("Not here. No, really. not here!"));
73 setAutoAwayReasonEnabled(false);
74 setDetachAwayEnabled(false);
75 setDetachAwayReason(tr("All Quassel clients vanished from the face of the earth..."));
76 setDetachAwayReasonEnabled(false);
78 setKickReason(tr("Kindergarten is elsewhere!"));
79 setPartReason(tr("http://quassel-irc.org - Chat comfortably. Anywhere."));
80 setQuitReason(tr("http://quassel-irc.org - Chat comfortably. Anywhere."));
83 bool Identity::isValid() const {
84 return (id().toInt() > 0);
87 IdentityId Identity::id() const {
91 QString Identity::identityName() const {
95 QString Identity::realName() const {
99 QStringList Identity::nicks() const {
103 QString Identity::awayNick() const {
107 bool Identity::awayNickEnabled() const {
108 return _awayNickEnabled;
111 QString Identity::awayReason() const {
115 bool Identity::awayReasonEnabled() const {
116 return _awayReasonEnabled;
119 bool Identity::autoAwayEnabled() const {
120 return _autoAwayEnabled;
123 int Identity::autoAwayTime() const {
124 return _autoAwayTime;
127 QString Identity::autoAwayReason() const {
128 return _autoAwayReason;
131 bool Identity::autoAwayReasonEnabled() const {
132 return _autoAwayReasonEnabled;
135 bool Identity::detachAwayEnabled() const {
136 return _detachAwayEnabled;
139 QString Identity::detachAwayReason() const {
140 return _detachAwayReason;
143 bool Identity::detachAwayReasonEnabled() const {
144 return _detachAwayReasonEnabled;
147 QString Identity::ident() const {
151 QString Identity::kickReason() const {
155 QString Identity::partReason() const
156 {return _partReason;}
158 QString Identity::quitReason() const {
164 // NOTE: DO NOT USE ON SYNCHRONIZED OBJECTS!
165 void Identity::setId(IdentityId _id) {
167 setObjectName(QString::number(id().toInt()));
171 void Identity::setIdentityName(const QString &identityName) {
172 _identityName = identityName;
173 emit identityNameSet(identityName);
176 void Identity::setRealName(const QString &realName) {
177 _realName = realName;
178 emit realNameSet(realName);
181 void Identity::setNicks(const QStringList &nicks) {
183 emit nicksSet(nicks);
186 void Identity::setAwayNick(const QString &nick) {
188 emit awayNickSet(nick);
191 void Identity::setAwayReason(const QString &reason) {
192 _awayReason = reason;
193 emit awayReasonSet(reason);
196 void Identity::setAwayNickEnabled(bool enabled) {
197 _awayNickEnabled = enabled;
198 emit awayNickEnabledSet(enabled);
201 void Identity::setAwayReasonEnabled(bool enabled) {
202 _awayReasonEnabled = enabled;
203 emit awayReasonEnabledSet(enabled);
206 void Identity::setAutoAwayEnabled(bool enabled) {
207 _autoAwayEnabled = enabled;
208 emit autoAwayEnabledSet(enabled);
211 void Identity::setAutoAwayTime(int time) {
212 _autoAwayTime = time;
213 emit autoAwayTimeSet(time);
216 void Identity::setAutoAwayReason(const QString & reason) {
217 _autoAwayReason = reason;
218 emit autoAwayReasonSet(reason);
221 void Identity::setAutoAwayReasonEnabled(bool enabled) {
222 _autoAwayReasonEnabled = enabled;
223 emit autoAwayReasonEnabledSet(enabled);
226 void Identity::setDetachAwayEnabled(bool enabled) {
227 _detachAwayEnabled = enabled;
228 emit detachAwayEnabledSet(enabled);
231 void Identity::setDetachAwayReason(const QString & reason) {
232 _detachAwayReason = reason;
233 emit detachAwayReasonSet(reason);
236 void Identity::setDetachAwayReasonEnabled(bool enabled) {
237 _detachAwayReasonEnabled = enabled;
238 emit detachAwayReasonEnabledSet(enabled);
241 void Identity::setIdent(const QString & ident) {
243 emit identSet(ident);
246 void Identity::setKickReason(const QString & reason) {
247 _kickReason = reason;
248 emit kickReasonSet(reason);
251 void Identity::setPartReason(const QString & reason) {
252 _partReason = reason;
253 emit partReasonSet(reason);
256 void Identity::setQuitReason(const QString & reason) {
257 _quitReason = reason;
258 emit quitReasonSet(reason);
263 void Identity::update(const Identity &other) {
264 for(int idx = metaObject()->propertyOffset(); idx < metaObject()->propertyCount(); idx++) {
265 QMetaProperty metaProp = metaObject()->property(idx);
266 Q_ASSERT(metaProp.isValid());
267 if(this->property(metaProp.name()) != other.property(metaProp.name())) {
268 setProperty(metaProp.name(), other.property(metaProp.name()));
273 bool Identity::operator==(const Identity &other) {
274 for(int idx = metaObject()->propertyOffset(); idx < metaObject()->propertyCount(); idx++) {
275 QMetaProperty metaProp = metaObject()->property(idx);
276 Q_ASSERT(metaProp.isValid());
277 QVariant v1 = this->property(metaProp.name());
278 QVariant v2 = other.property(metaProp.name()); // qDebug() << v1 << v2;
279 // QVariant cannot compare custom types, so we need to check for this special case
280 if(QString(v1.typeName()) == "IdentityId") {
281 if(v1.value<IdentityId>() != v2.value<IdentityId>()) return false;
283 if(v1 != v2) return false;
289 bool Identity::operator!=(const Identity &other) {
290 return !(*this == other);
293 ///////////////////////////////
295 QDataStream &operator<<(QDataStream &out, Identity id) {
296 out << id.toVariantMap();
301 QDataStream &operator>>(QDataStream &in, Identity &id) {
304 id.fromVariantMap(i);