src: Mark symbols to be exported where needed
[quassel.git] / src / common / ircuser.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #pragma once
22
23 #include "common-export.h"
24
25 #include <QSet>
26 #include <QString>
27 #include <QStringList>
28 #include <QVariantMap>
29 #include <QDateTime>
30
31 #include "syncableobject.h"
32 #include "types.h"
33
34 class SignalProxy;
35 class Network;
36 class IrcChannel;
37
38 class COMMON_EXPORT IrcUser : public SyncableObject
39 {
40     Q_OBJECT
41     SYNCABLE_OBJECT
42
43     Q_PROPERTY(QString user READ user WRITE setUser)
44     Q_PROPERTY(QString host READ host WRITE setHost)
45     Q_PROPERTY(QString nick READ nick WRITE setNick)
46     Q_PROPERTY(QString realName READ realName WRITE setRealName)
47     Q_PROPERTY(QString account READ account WRITE setAccount)
48     Q_PROPERTY(bool away READ isAway WRITE setAway)
49     Q_PROPERTY(QString awayMessage READ awayMessage WRITE setAwayMessage)
50     Q_PROPERTY(QDateTime idleTime READ idleTime WRITE setIdleTime)
51     Q_PROPERTY(QDateTime loginTime READ loginTime WRITE setLoginTime)
52     Q_PROPERTY(QString server READ server WRITE setServer)
53     Q_PROPERTY(QString ircOperator READ ircOperator WRITE setIrcOperator)
54     Q_PROPERTY(QDateTime lastAwayMessageTime READ lastAwayMessageTime WRITE setLastAwayMessageTime)
55     Q_PROPERTY(QString whoisServiceReply READ whoisServiceReply WRITE setWhoisServiceReply)
56     Q_PROPERTY(QString suserHost READ suserHost WRITE setSuserHost)
57     Q_PROPERTY(bool encrypted READ encrypted WRITE setEncrypted)
58
59     Q_PROPERTY(QStringList channels READ channels)
60     Q_PROPERTY(QString userModes READ userModes WRITE setUserModes)
61
62 public :
63         IrcUser(const QString &hostmask, Network *network);
64     virtual ~IrcUser();
65
66     inline QString user() const { return _user; }
67     inline QString host() const { return _host; }
68     inline QString nick() const { return _nick; }
69     inline QString realName() const { return _realName; }
70     /**
71      * Account name, e.g. NickServ/SASL account
72      *
73      * @return Account name if logged in, * if logged out, or empty string if unknown
74      */
75     inline QString account() const { return _account; }
76     QString hostmask() const;
77     inline bool isAway() const { return _away; }
78     inline QString awayMessage() const { return _awayMessage; }
79     QDateTime idleTime();
80     inline QDateTime loginTime() const { return _loginTime; }
81     inline QString server() const { return _server; }
82     inline QString ircOperator() const { return _ircOperator; }
83     inline QDateTime lastAwayMessageTime() const { return _lastAwayMessageTime; }
84     inline QString whoisServiceReply() const { return _whoisServiceReply; }
85     inline QString suserHost() const { return _suserHost; }
86     inline bool encrypted() const { return _encrypted; }
87     inline Network *network() const { return _network; }
88
89     inline QString userModes() const { return _userModes; }
90
91     QStringList channels() const;
92
93     // user-specific encodings
94     inline QTextCodec *codecForEncoding() const { return _codecForEncoding; }
95     inline QTextCodec *codecForDecoding() const { return _codecForDecoding; }
96     void setCodecForEncoding(const QString &codecName);
97     void setCodecForEncoding(QTextCodec *codec);
98     void setCodecForDecoding(const QString &codecName);
99     void setCodecForDecoding(QTextCodec *codec);
100
101     QString decodeString(const QByteArray &text) const;
102     QByteArray encodeString(const QString &string) const;
103
104     // only valid on client side, these are not synced!
105     inline QDateTime lastChannelActivity(BufferId id) const { return _lastActivity.value(id); }
106     void setLastChannelActivity(BufferId id, const QDateTime &time);
107     inline QDateTime lastSpokenTo(BufferId id) const { return _lastSpokenTo.value(id); }
108     void setLastSpokenTo(BufferId id, const QDateTime &time);
109
110     /**
111      * Gets whether or not the away state has changed since it was last acknowledged
112      *
113      * Away state is marked as changed by any modification to away status (away/here, message)
114      *
115      * NOTE: On servers lacking support for IRCv3 away-notify, this won't update until an autoWHO-
116      * run for away/here changes, or until sending a message to the user for away message changes.
117      *
118      * @see IrcUser::acknowledgeAwayChanged()
119      *
120      * @return True if current away state is unchanged from last acknowledgement, otherwise false
121      */
122     inline bool hasAwayChanged() const { return _awayChanged; }
123
124     /**
125      * Sets the last away state change as acknowledged
126      *
127      * @see IrcUser::hasAwayChanged()
128      */
129     inline void acknowledgeAwayChanged()
130     {
131         // Don't sync this as individual clients may suppress different kinds of behaviors
132         _awayChanged = false;
133     }
134
135 public slots:
136     void setUser(const QString &user);
137     void setHost(const QString &host);
138     void setNick(const QString &nick);
139     void setRealName(const QString &realName);
140     /**
141      * Set account name, e.g. NickServ/SASL account
142      *
143      * @param[in] account Account name if logged in, * if logged out, or empty string if unknown
144      */
145     void setAccount(const QString &account);
146     void setAway(bool away);
147     void setAwayMessage(const QString &awayMessage);
148     void setIdleTime(const QDateTime &idleTime);
149     void setLoginTime(const QDateTime &loginTime);
150     void setServer(const QString &server);
151     void setIrcOperator(const QString &ircOperator);
152     // setLastAwayMessage is only called by legacy (pre-0.13) cores, which automatically gets
153     // converted to setting the appropriate lastAwayMessageTime.  Do not use this in new code.
154     void setLastAwayMessage(int lastAwayMessage);
155     void setLastAwayMessageTime(const QDateTime &lastAwayMessageTime);
156     void setWhoisServiceReply(const QString &whoisServiceReply);
157     void setSuserHost(const QString &suserHost);
158     void setEncrypted(bool encrypted);
159     void updateHostmask(const QString &mask);
160
161     void setUserModes(const QString &modes);
162
163     /*!
164      * \brief joinChannel Called when user joins some channel, this function inserts the channel to internal list of channels this user is in.
165      * \param channel Pointer to a channel this user just joined
166      * \param skip_channel_join If this is false, this function will also call IrcChannel::joinIrcUser, can be set to true as a performance tweak.
167      */
168     void joinChannel(IrcChannel *channel, bool skip_channel_join = false);
169     void joinChannel(const QString &channelname);
170     void partChannel(IrcChannel *channel);
171     void partChannel(const QString &channelname);
172     void quit();
173
174     void addUserModes(const QString &modes);
175     void removeUserModes(const QString &modes);
176
177 signals:
178 //   void userSet(QString user);
179 //   void hostSet(QString host);
180     void nickSet(QString newnick); // needed in NetworkModel
181 //   void realNameSet(QString realName);
182     void awaySet(bool away); // needed in NetworkModel
183 //   void awayMessageSet(QString awayMessage);
184 //   void idleTimeSet(QDateTime idleTime);
185 //   void loginTimeSet(QDateTime loginTime);
186 //   void serverSet(QString server);
187 //   void ircOperatorSet(QString ircOperator);
188 //   void lastAwayMessageTimeSet(QDateTime lastAwayMessageTime);
189 //   void whoisServiceReplySet(QString whoisServiceReply);
190 //   void suserHostSet(QString suserHost);
191     void encryptedSet(bool encrypted);
192
193     void userModesSet(QString modes);
194     void userModesAdded(QString modes);
195     void userModesRemoved(QString modes);
196
197     // void channelJoined(QString channel);
198     void channelParted(QString channel);
199     void quited();
200
201     void lastChannelActivityUpdated(BufferId id, const QDateTime &newTime);
202     void lastSpokenToUpdated(BufferId id, const QDateTime &newTime);
203
204 private slots:
205     void updateObjectName();
206     void channelDestroyed();
207
208 private:
209     inline bool operator==(const IrcUser &ircuser2)
210     {
211         return (_nick.toLower() == ircuser2.nick().toLower());
212     }
213
214
215     inline bool operator==(const QString &nickname)
216     {
217         return (_nick.toLower() == nickname.toLower());
218     }
219
220     /**
221      * Sets the last away state change as unacknowledged
222      *
223      * @see IrcUser::hasAwayChanged()
224      */
225     inline void markAwayChanged()
226     {
227         _awayChanged = true;
228     }
229
230     bool _initialized;
231
232     QString _nick;
233     QString _user;
234     QString _host;
235     QString _realName;
236     QString _account;      /// Account name, e.g. NickServ/SASL account
237     QString _awayMessage;
238     bool _away;
239     QString _server;
240     QDateTime _idleTime;
241     QDateTime _idleTimeSet;
242     QDateTime _loginTime;
243     QString _ircOperator;
244     QDateTime _lastAwayMessageTime;
245     QString _whoisServiceReply;
246     QString _suserHost;
247     bool _encrypted;
248
249     // QSet<QString> _channels;
250     QSet<IrcChannel *> _channels;
251     QString _userModes;
252
253     Network *_network;
254
255     QTextCodec *_codecForEncoding;
256     QTextCodec *_codecForDecoding;
257
258     QHash<BufferId, QDateTime> _lastActivity;
259     QHash<BufferId, QDateTime> _lastSpokenTo;
260
261     // Given it's never been acknowledged, assume changes exist on IrcUser creation
262     /// Tracks if changes in away state (away/here, message) have yet to be acknowledged
263     bool _awayChanged = true;
264 };