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) : QObject(parent), _identityId(id) {
31 Identity::Identity(const Identity &other, QObject *parent) : QObject(parent),
32 _identityId(other.id()),
33 _identityName(other.identityName()),
34 _realName(other.realName()),
35 _nicks(other.nicks()),
36 _awayNick(other.awayNick()),
37 _awayReason(other.awayReason()),
38 _returnMessage(other.returnMessage()) {
42 void Identity::init() {
44 setObjectName(QString::number(id()));
47 void Identity::setToDefaults() {
48 setIdentityName(tr("Default Identity"));
49 setRealName(tr("Quassel IRC User"));
51 n << QString("quassel%1").arg(qrand() & 0xff); // FIXME provide more sensible default nicks
54 setAwayReason(tr("Gone fishing."));
55 setReturnMessage(tr("Brought fish."));
59 bool Identity::initialized() const {
63 void Identity::setInitialized() {
67 IdentityId Identity::id() const {
71 QString Identity::identityName() const {
75 QString Identity::realName() const {
79 QStringList Identity::nicks() const {
83 QString Identity::awayNick() const {
87 QString Identity::awayReason() const {
91 QString Identity::returnMessage() const {
92 return _returnMessage;
95 //////////////////////
97 void Identity::setIdentityName(const QString &identityName) {
98 _identityName = identityName;
99 emit identityNameSet(identityName);
102 void Identity::setRealName(const QString &realName) {
103 _realName = realName;
104 emit realNameSet(realName);
107 void Identity::setNicks(const QStringList &nicks) {
109 emit nicksSet(nicks);
112 void Identity::setAwayNick(const QString &nick) {
114 emit awayNickSet(nick);
117 void Identity::setAwayReason(const QString &reason) {
118 _awayReason = reason;
119 emit awayReasonSet(reason);
122 void Identity::setReturnMessage(const QString &message) {
123 _returnMessage = message;
124 emit returnMessageSet(message);
127 void Identity::update(const Identity &other) {
128 for(int idx = 0; idx < metaObject()->propertyCount(); idx++) {
129 QMetaProperty metaProp = metaObject()->property(metaObject()->propertyOffset() + idx);
130 Q_ASSERT(metaProp.isValid());
131 if(this->property(metaProp.name()) != other.property(metaProp.name())) {
132 setProperty(metaProp.name(), other.property(metaProp.name()));
137 ///////////////////////////////
139 // we use a hash, so we can easily extend identities without breaking saved ones
140 QDataStream &operator<<(QDataStream &out, const Identity &id) {
142 i["IdentityId"] = id.id();
143 i["IdentityName"] = id.identityName();
144 i["RealName"] = id.realName();
145 i["Nicks"] = id.nicks();
146 i["AwayNick"] = id.awayNick();
147 i["AwayReason"] = id.awayReason();
148 i["ReturnMessage"] = id.returnMessage();
153 QDataStream &operator>>(QDataStream &in, Identity &id) {
156 id._identityId = i["IdentityId"].toUInt();
157 id.setIdentityName(i["IdentityName"].toString());
158 id.setRealName(i["RealName"].toString());
159 id.setNicks(i["Nicks"].toStringList());
160 id.setAwayNick(i["AwayNick"].toString());
161 id.setAwayReason(i["AwayReason"].toString());
162 id.setReturnMessage(i["ReturnMessage"].toString());