1 /***************************************************************************
2 * Copyright (C) 2005-09 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)
27 : SyncableObject(parent),
34 Identity::Identity(const Identity &other, QObject *parent)
35 : SyncableObject(parent),
36 _identityId(other.id()),
37 _identityName(other.identityName()),
38 _realName(other.realName()),
39 _nicks(other.nicks()),
40 _awayNick(other.awayNick()),
41 _awayNickEnabled(other.awayNickEnabled()),
42 _awayReason(other.awayReason()),
43 _awayReasonEnabled(other.awayReasonEnabled()),
44 _autoAwayEnabled(other.autoAwayEnabled()),
45 _autoAwayTime(other.autoAwayTime()),
46 _autoAwayReason(other.autoAwayReason()),
47 _autoAwayReasonEnabled(other.autoAwayReasonEnabled()),
48 _detachAwayEnabled(other.detachAwayEnabled()),
49 _detachAwayReason(other.detachAwayReason()),
50 _detachAwayReasonEnabled(other.detachAwayReasonEnabled()),
51 _ident(other.ident()),
52 _kickReason(other.kickReason()),
53 _partReason(other.partReason()),
54 _quitReason(other.quitReason())
59 void Identity::init() {
60 setObjectName(QString::number(id().toInt()));
61 setAllowClientUpdates(true);
64 void Identity::setToDefaults() {
65 setIdentityName(tr("<empty>"));
66 setRealName(tr("Quassel IRC User"));
68 n << QString("quassel%1").arg(qrand() & 0xff); // FIXME provide more sensible default nicks
71 setAwayNickEnabled(false);
72 setAwayReason(tr("Gone fishing."));
73 setAwayReasonEnabled(true);
74 setAutoAwayEnabled(false);
76 setAutoAwayReason(tr("Not here. No, really. not here!"));
77 setAutoAwayReasonEnabled(false);
78 setDetachAwayEnabled(false);
79 setDetachAwayReason(tr("All Quassel clients vanished from the face of the earth..."));
80 setDetachAwayReasonEnabled(false);
82 setKickReason(tr("Kindergarten is elsewhere!"));
83 setPartReason(tr("http://quassel-irc.org - Chat comfortably. Anywhere."));
84 setQuitReason(tr("http://quassel-irc.org - Chat comfortably. Anywhere."));
89 void Identity::setId(IdentityId _id) {
92 renameObject(QString::number(id().toInt()));
95 void Identity::setIdentityName(const QString &identityName) {
96 _identityName = identityName;
97 emit identityNameSet(identityName);
100 void Identity::setRealName(const QString &realName) {
101 _realName = realName;
102 emit realNameSet(realName);
105 void Identity::setNicks(const QStringList &nicks) {
107 emit nicksSet(nicks);
110 void Identity::setAwayNick(const QString &nick) {
112 emit awayNickSet(nick);
115 void Identity::setAwayReason(const QString &reason) {
116 _awayReason = reason;
117 emit awayReasonSet(reason);
120 void Identity::setAwayNickEnabled(bool enabled) {
121 _awayNickEnabled = enabled;
122 emit awayNickEnabledSet(enabled);
125 void Identity::setAwayReasonEnabled(bool enabled) {
126 _awayReasonEnabled = enabled;
127 emit awayReasonEnabledSet(enabled);
130 void Identity::setAutoAwayEnabled(bool enabled) {
131 _autoAwayEnabled = enabled;
132 emit autoAwayEnabledSet(enabled);
135 void Identity::setAutoAwayTime(int time) {
136 _autoAwayTime = time;
137 emit autoAwayTimeSet(time);
140 void Identity::setAutoAwayReason(const QString &reason) {
141 _autoAwayReason = reason;
142 emit autoAwayReasonSet(reason);
145 void Identity::setAutoAwayReasonEnabled(bool enabled) {
146 _autoAwayReasonEnabled = enabled;
147 emit autoAwayReasonEnabledSet(enabled);
150 void Identity::setDetachAwayEnabled(bool enabled) {
151 _detachAwayEnabled = enabled;
152 emit detachAwayEnabledSet(enabled);
155 void Identity::setDetachAwayReason(const QString &reason) {
156 _detachAwayReason = reason;
157 emit detachAwayReasonSet(reason);
160 void Identity::setDetachAwayReasonEnabled(bool enabled) {
161 _detachAwayReasonEnabled = enabled;
162 emit detachAwayReasonEnabledSet(enabled);
165 void Identity::setIdent(const QString &ident) {
167 emit identSet(ident);
170 void Identity::setKickReason(const QString &reason) {
171 _kickReason = reason;
172 emit kickReasonSet(reason);
175 void Identity::setPartReason(const QString &reason) {
176 _partReason = reason;
177 emit partReasonSet(reason);
180 void Identity::setQuitReason(const QString &reason) {
181 _quitReason = reason;
182 emit quitReasonSet(reason);
187 void Identity::copyFrom(const Identity &other) {
188 for(int idx = staticMetaObject.propertyOffset(); idx < staticMetaObject.propertyCount(); idx++) {
189 QMetaProperty metaProp = staticMetaObject.property(idx);
190 Q_ASSERT(metaProp.isValid());
191 if(this->property(metaProp.name()) != other.property(metaProp.name())) {
192 setProperty(metaProp.name(), other.property(metaProp.name()));
197 bool Identity::operator==(const Identity &other) const {
198 for(int idx = staticMetaObject.propertyOffset(); idx < staticMetaObject.propertyCount(); idx++) {
199 QMetaProperty metaProp = staticMetaObject.property(idx);
200 Q_ASSERT(metaProp.isValid());
201 QVariant v1 = this->property(metaProp.name());
202 QVariant v2 = other.property(metaProp.name()); // qDebug() << v1 << v2;
203 // QVariant cannot compare custom types, so we need to check for this special case
204 if(QString(v1.typeName()) == "IdentityId") {
205 if(v1.value<IdentityId>() != v2.value<IdentityId>()) return false;
207 if(v1 != v2) return false;
213 bool Identity::operator!=(const Identity &other) const {
214 return !(*this == other);
217 ///////////////////////////////
219 QDataStream &operator<<(QDataStream &out, Identity id) {
220 out << id.toVariantMap();
225 QDataStream &operator>>(QDataStream &in, Identity &id) {
228 id.fromVariantMap(i);