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 ***************************************************************************/
25 #include <QStringList>
26 #include <QVariantMap>
29 #include "syncableobject.h"
36 class IrcUser : public SyncableObject
41 Q_PROPERTY(QString user READ user WRITE setUser)
42 Q_PROPERTY(QString host READ host WRITE setHost)
43 Q_PROPERTY(QString nick READ nick WRITE setNick)
44 Q_PROPERTY(QString realName READ realName WRITE setRealName)
45 Q_PROPERTY(QString account READ account WRITE setAccount)
46 Q_PROPERTY(bool away READ isAway WRITE setAway)
47 Q_PROPERTY(QString awayMessage READ awayMessage WRITE setAwayMessage)
48 Q_PROPERTY(QDateTime idleTime READ idleTime WRITE setIdleTime)
49 Q_PROPERTY(QDateTime loginTime READ loginTime WRITE setLoginTime)
50 Q_PROPERTY(QString server READ server WRITE setServer)
51 Q_PROPERTY(QString ircOperator READ ircOperator WRITE setIrcOperator)
52 Q_PROPERTY(QDateTime lastAwayMessageTime READ lastAwayMessageTime WRITE setLastAwayMessageTime)
53 Q_PROPERTY(QString whoisServiceReply READ whoisServiceReply WRITE setWhoisServiceReply)
54 Q_PROPERTY(QString suserHost READ suserHost WRITE setSuserHost)
55 Q_PROPERTY(bool encrypted READ encrypted WRITE setEncrypted)
57 Q_PROPERTY(QStringList channels READ channels)
58 Q_PROPERTY(QString userModes READ userModes WRITE setUserModes)
61 IrcUser(const QString &hostmask, Network *network);
64 inline QString user() const { return _user; }
65 inline QString host() const { return _host; }
66 inline QString nick() const { return _nick; }
67 inline QString realName() const { return _realName; }
69 * Account name, e.g. NickServ/SASL account
71 * @return Account name if logged in, * if logged out, or empty string if unknown
73 inline QString account() const { return _account; }
74 QString hostmask() const;
75 inline bool isAway() const { return _away; }
76 inline QString awayMessage() const { return _awayMessage; }
78 inline QDateTime loginTime() const { return _loginTime; }
79 inline QString server() const { return _server; }
80 inline QString ircOperator() const { return _ircOperator; }
81 inline QDateTime lastAwayMessageTime() const { return _lastAwayMessageTime; }
82 inline QString whoisServiceReply() const { return _whoisServiceReply; }
83 inline QString suserHost() const { return _suserHost; }
84 inline bool encrypted() const { return _encrypted; }
85 inline Network *network() const { return _network; }
87 inline QString userModes() const { return _userModes; }
89 QStringList channels() const;
91 // user-specific encodings
92 inline QTextCodec *codecForEncoding() const { return _codecForEncoding; }
93 inline QTextCodec *codecForDecoding() const { return _codecForDecoding; }
94 void setCodecForEncoding(const QString &codecName);
95 void setCodecForEncoding(QTextCodec *codec);
96 void setCodecForDecoding(const QString &codecName);
97 void setCodecForDecoding(QTextCodec *codec);
99 QString decodeString(const QByteArray &text) const;
100 QByteArray encodeString(const QString &string) const;
102 // only valid on client side, these are not synced!
103 inline QDateTime lastChannelActivity(BufferId id) const { return _lastActivity.value(id); }
104 void setLastChannelActivity(BufferId id, const QDateTime &time);
105 inline QDateTime lastSpokenTo(BufferId id) const { return _lastSpokenTo.value(id); }
106 void setLastSpokenTo(BufferId id, const QDateTime &time);
109 * Gets whether or not the away state has changed since it was last acknowledged
111 * Away state is marked as changed by any modification to away status (away/here, message)
113 * NOTE: On servers lacking support for IRCv3 away-notify, this won't update until an autoWHO-
114 * run for away/here changes, or until sending a message to the user for away message changes.
116 * @see IrcUser::acknowledgeAwayChanged()
118 * @return True if current away state is unchanged from last acknowledgement, otherwise false
120 inline bool hasAwayChanged() const { return _awayChanged; }
123 * Sets the last away state change as acknowledged
125 * @see IrcUser::hasAwayChanged()
127 inline void acknowledgeAwayChanged()
129 // Don't sync this as individual clients may suppress different kinds of behaviors
130 _awayChanged = false;
134 void setUser(const QString &user);
135 void setHost(const QString &host);
136 void setNick(const QString &nick);
137 void setRealName(const QString &realName);
139 * Set account name, e.g. NickServ/SASL account
141 * @param[in] account Account name if logged in, * if logged out, or empty string if unknown
143 void setAccount(const QString &account);
144 void setAway(bool away);
145 void setAwayMessage(const QString &awayMessage);
146 void setIdleTime(const QDateTime &idleTime);
147 void setLoginTime(const QDateTime &loginTime);
148 void setServer(const QString &server);
149 void setIrcOperator(const QString &ircOperator);
150 // setLastAwayMessage is only called by legacy (pre-0.13) cores, which automatically gets
151 // converted to setting the appropriate lastAwayMessageTime. Do not use this in new code.
152 void setLastAwayMessage(int lastAwayMessage);
153 void setLastAwayMessageTime(const QDateTime &lastAwayMessageTime);
154 void setWhoisServiceReply(const QString &whoisServiceReply);
155 void setSuserHost(const QString &suserHost);
156 void setEncrypted(bool encrypted);
157 void updateHostmask(const QString &mask);
159 void setUserModes(const QString &modes);
162 * \brief joinChannel Called when user joins some channel, this function inserts the channel to internal list of channels this user is in.
163 * \param channel Pointer to a channel this user just joined
164 * \param skip_channel_join If this is false, this function will also call IrcChannel::joinIrcUser, can be set to true as a performance tweak.
166 void joinChannel(IrcChannel *channel, bool skip_channel_join = false);
167 void joinChannel(const QString &channelname);
168 void partChannel(IrcChannel *channel);
169 void partChannel(const QString &channelname);
172 void addUserModes(const QString &modes);
173 void removeUserModes(const QString &modes);
176 // void userSet(QString user);
177 // void hostSet(QString host);
178 void nickSet(QString newnick); // needed in NetworkModel
179 // void realNameSet(QString realName);
180 void awaySet(bool away); // needed in NetworkModel
181 // void awayMessageSet(QString awayMessage);
182 // void idleTimeSet(QDateTime idleTime);
183 // void loginTimeSet(QDateTime loginTime);
184 // void serverSet(QString server);
185 // void ircOperatorSet(QString ircOperator);
186 // void lastAwayMessageTimeSet(QDateTime lastAwayMessageTime);
187 // void whoisServiceReplySet(QString whoisServiceReply);
188 // void suserHostSet(QString suserHost);
189 void encryptedSet(bool encrypted);
191 void userModesSet(QString modes);
192 void userModesAdded(QString modes);
193 void userModesRemoved(QString modes);
195 // void channelJoined(QString channel);
196 void channelParted(QString channel);
199 void lastChannelActivityUpdated(BufferId id, const QDateTime &newTime);
200 void lastSpokenToUpdated(BufferId id, const QDateTime &newTime);
203 void updateObjectName();
204 void channelDestroyed();
207 inline bool operator==(const IrcUser &ircuser2)
209 return (_nick.toLower() == ircuser2.nick().toLower());
213 inline bool operator==(const QString &nickname)
215 return (_nick.toLower() == nickname.toLower());
219 * Sets the last away state change as unacknowledged
221 * @see IrcUser::hasAwayChanged()
223 inline void markAwayChanged()
234 QString _account; /// Account name, e.g. NickServ/SASL account
235 QString _awayMessage;
239 QDateTime _idleTimeSet;
240 QDateTime _loginTime;
241 QString _ircOperator;
242 QDateTime _lastAwayMessageTime;
243 QString _whoisServiceReply;
247 // QSet<QString> _channels;
248 QSet<IrcChannel *> _channels;
253 QTextCodec *_codecForEncoding;
254 QTextCodec *_codecForDecoding;
256 QHash<BufferId, QDateTime> _lastActivity;
257 QHash<BufferId, QDateTime> _lastSpokenTo;
259 // Given it's never been acknowledged, assume changes exist on IrcUser creation
260 /// Tracks if changes in away state (away/here, message) have yet to be acknowledged
261 bool _awayChanged = true;