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 ***************************************************************************/
26 #include <QStringList>
27 #include <QVariantMap>
30 #include "syncableobject.h"
37 class IrcUser : public SyncableObject
42 Q_PROPERTY(QString user READ user WRITE setUser)
43 Q_PROPERTY(QString host READ host WRITE setHost)
44 Q_PROPERTY(QString nick READ nick WRITE setNick)
45 Q_PROPERTY(QString realName READ realName WRITE setRealName)
46 Q_PROPERTY(QString account READ account WRITE setAccount)
47 Q_PROPERTY(bool away READ isAway WRITE setAway)
48 Q_PROPERTY(QString awayMessage READ awayMessage WRITE setAwayMessage)
49 Q_PROPERTY(QDateTime idleTime READ idleTime WRITE setIdleTime)
50 Q_PROPERTY(QDateTime loginTime READ loginTime WRITE setLoginTime)
51 Q_PROPERTY(QString server READ server WRITE setServer)
52 Q_PROPERTY(QString ircOperator READ ircOperator WRITE setIrcOperator)
53 // lastAwayMessage is only set by legacy (pre-0.13) cores, which automatically gets converted to
54 // the appropriate lastAwayMessageTime. Do not use this in new code.
55 Q_PROPERTY(int lastAwayMessage WRITE setLastAwayMessage)
56 Q_PROPERTY(QDateTime lastAwayMessageTime READ lastAwayMessageTime WRITE setLastAwayMessageTime)
57 Q_PROPERTY(QString whoisServiceReply READ whoisServiceReply WRITE setWhoisServiceReply)
58 Q_PROPERTY(QString suserHost READ suserHost WRITE setSuserHost)
59 Q_PROPERTY(bool encrypted READ encrypted WRITE setEncrypted)
61 Q_PROPERTY(QStringList channels READ channels)
62 Q_PROPERTY(QString userModes READ userModes WRITE setUserModes)
65 IrcUser(const QString &hostmask, Network *network);
68 inline QString user() const { return _user; }
69 inline QString host() const { return _host; }
70 inline QString nick() const { return _nick; }
71 inline QString realName() const { return _realName; }
73 * Account name, e.g. NickServ/SASL account
75 * @return Account name if logged in, * if logged out, or empty string if unknown
77 inline QString account() const { return _account; }
78 QString hostmask() const;
79 inline bool isAway() const { return _away; }
80 inline QString awayMessage() const { return _awayMessage; }
82 inline QDateTime loginTime() const { return _loginTime; }
83 inline QString server() const { return _server; }
84 inline QString ircOperator() const { return _ircOperator; }
85 inline QDateTime lastAwayMessageTime() const { return _lastAwayMessageTime; }
86 inline QString whoisServiceReply() const { return _whoisServiceReply; }
87 inline QString suserHost() const { return _suserHost; }
88 inline bool encrypted() const { return _encrypted; }
89 inline Network *network() const { return _network; }
91 inline QString userModes() const { return _userModes; }
93 QStringList channels() const;
95 // user-specific encodings
96 inline QTextCodec *codecForEncoding() const { return _codecForEncoding; }
97 inline QTextCodec *codecForDecoding() const { return _codecForDecoding; }
98 void setCodecForEncoding(const QString &codecName);
99 void setCodecForEncoding(QTextCodec *codec);
100 void setCodecForDecoding(const QString &codecName);
101 void setCodecForDecoding(QTextCodec *codec);
103 QString decodeString(const QByteArray &text) const;
104 QByteArray encodeString(const QString &string) const;
106 // only valid on client side, these are not synced!
107 inline QDateTime lastChannelActivity(BufferId id) const { return _lastActivity.value(id); }
108 void setLastChannelActivity(BufferId id, const QDateTime &time);
109 inline QDateTime lastSpokenTo(BufferId id) const { return _lastSpokenTo.value(id); }
110 void setLastSpokenTo(BufferId id, const QDateTime &time);
113 void setUser(const QString &user);
114 void setHost(const QString &host);
115 void setNick(const QString &nick);
116 void setRealName(const QString &realName);
118 * Set account name, e.g. NickServ/SASL account
120 * @param[in] account Account name if logged in, * if logged out, or empty string if unknown
122 void setAccount(const QString &account);
123 void setAway(const bool &away);
124 void setAwayMessage(const QString &awayMessage);
125 void setIdleTime(const QDateTime &idleTime);
126 void setLoginTime(const QDateTime &loginTime);
127 void setServer(const QString &server);
128 void setIrcOperator(const QString &ircOperator);
129 // setLastAwayMessage is only called by legacy (pre-0.13) cores, which automatically gets
130 // converted to setting the appropriate lastAwayMessageTime. Do not use this in new code.
131 void setLastAwayMessage(const int &lastAwayMessage);
132 void setLastAwayMessageTime(const QDateTime &lastAwayMessageTime);
133 void setWhoisServiceReply(const QString &whoisServiceReply);
134 void setSuserHost(const QString &suserHost);
135 void setEncrypted(bool encrypted);
136 void updateHostmask(const QString &mask);
138 void setUserModes(const QString &modes);
141 * \brief joinChannel Called when user joins some channel, this function inserts the channel to internal list of channels this user is in.
142 * \param channel Pointer to a channel this user just joined
143 * \param skip_channel_join If this is false, this function will also call IrcChannel::joinIrcUser, can be set to true as a performance tweak.
145 void joinChannel(IrcChannel *channel, bool skip_channel_join = false);
146 void joinChannel(const QString &channelname);
147 void partChannel(IrcChannel *channel);
148 void partChannel(const QString &channelname);
151 void addUserModes(const QString &modes);
152 void removeUserModes(const QString &modes);
155 // void userSet(QString user);
156 // void hostSet(QString host);
157 void nickSet(QString newnick); // needed in NetworkModel
158 // void realNameSet(QString realName);
159 void awaySet(bool away); // needed in NetworkModel
160 // void awayMessageSet(QString awayMessage);
161 // void idleTimeSet(QDateTime idleTime);
162 // void loginTimeSet(QDateTime loginTime);
163 // void serverSet(QString server);
164 // void ircOperatorSet(QString ircOperator);
165 // void lastAwayMessageTimeSet(QDateTime lastAwayMessageTime);
166 // void whoisServiceReplySet(QString whoisServiceReply);
167 // void suserHostSet(QString suserHost);
168 void encryptedSet(bool encrypted);
170 void userModesSet(QString modes);
171 void userModesAdded(QString modes);
172 void userModesRemoved(QString modes);
174 // void channelJoined(QString channel);
175 void channelParted(QString channel);
178 void lastChannelActivityUpdated(BufferId id, const QDateTime &newTime);
179 void lastSpokenToUpdated(BufferId id, const QDateTime &newTime);
182 void updateObjectName();
183 void channelDestroyed();
186 inline bool operator==(const IrcUser &ircuser2)
188 return (_nick.toLower() == ircuser2.nick().toLower());
192 inline bool operator==(const QString &nickname)
194 return (_nick.toLower() == nickname.toLower());
204 QString _account; /// Account name, e.g. NickServ/SASL account
205 QString _awayMessage;
209 QDateTime _idleTimeSet;
210 QDateTime _loginTime;
211 QString _ircOperator;
212 QDateTime _lastAwayMessageTime;
213 QString _whoisServiceReply;
217 // QSet<QString> _channels;
218 QSet<IrcChannel *> _channels;
223 QTextCodec *_codecForEncoding;
224 QTextCodec *_codecForDecoding;
226 QHash<BufferId, QDateTime> _lastActivity;
227 QHash<BufferId, QDateTime> _lastSpokenTo;