QssParser: Interpret "oblique" as italic
[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 #ifndef IRCUSER_H
22 #define IRCUSER_H
23
24 #include <QSet>
25 #include <QString>
26 #include <QStringList>
27 #include <QVariantMap>
28 #include <QDateTime>
29
30 #include "syncableobject.h"
31 #include "types.h"
32
33 class SignalProxy;
34 class Network;
35 class IrcChannel;
36
37 class IrcUser : public SyncableObject
38 {
39     SYNCABLE_OBJECT
40     Q_OBJECT
41
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     Q_PROPERTY(QDateTime lastAwayMessageTime READ lastAwayMessageTime WRITE setLastAwayMessageTime)
54     Q_PROPERTY(QString whoisServiceReply READ whoisServiceReply WRITE setWhoisServiceReply)
55     Q_PROPERTY(QString suserHost READ suserHost WRITE setSuserHost)
56     Q_PROPERTY(bool encrypted READ encrypted WRITE setEncrypted)
57
58     Q_PROPERTY(QStringList channels READ channels)
59     Q_PROPERTY(QString userModes READ userModes WRITE setUserModes)
60
61 public :
62         IrcUser(const QString &hostmask, Network *network);
63     virtual ~IrcUser();
64
65     inline QString user() const { return _user; }
66     inline QString host() const { return _host; }
67     inline QString nick() const { return _nick; }
68     inline QString realName() const { return _realName; }
69     /**
70      * Account name, e.g. NickServ/SASL account
71      *
72      * @return Account name if logged in, * if logged out, or empty string if unknown
73      */
74     inline QString account() const { return _account; }
75     QString hostmask() const;
76     inline bool isAway() const { return _away; }
77     inline QString awayMessage() const { return _awayMessage; }
78     QDateTime idleTime();
79     inline QDateTime loginTime() const { return _loginTime; }
80     inline QString server() const { return _server; }
81     inline QString ircOperator() const { return _ircOperator; }
82     inline QDateTime lastAwayMessageTime() const { return _lastAwayMessageTime; }
83     inline QString whoisServiceReply() const { return _whoisServiceReply; }
84     inline QString suserHost() const { return _suserHost; }
85     inline bool encrypted() const { return _encrypted; }
86     inline Network *network() const { return _network; }
87
88     inline QString userModes() const { return _userModes; }
89
90     QStringList channels() const;
91
92     // user-specific encodings
93     inline QTextCodec *codecForEncoding() const { return _codecForEncoding; }
94     inline QTextCodec *codecForDecoding() const { return _codecForDecoding; }
95     void setCodecForEncoding(const QString &codecName);
96     void setCodecForEncoding(QTextCodec *codec);
97     void setCodecForDecoding(const QString &codecName);
98     void setCodecForDecoding(QTextCodec *codec);
99
100     QString decodeString(const QByteArray &text) const;
101     QByteArray encodeString(const QString &string) const;
102
103     // only valid on client side, these are not synced!
104     inline QDateTime lastChannelActivity(BufferId id) const { return _lastActivity.value(id); }
105     void setLastChannelActivity(BufferId id, const QDateTime &time);
106     inline QDateTime lastSpokenTo(BufferId id) const { return _lastSpokenTo.value(id); }
107     void setLastSpokenTo(BufferId id, const QDateTime &time);
108
109 public slots:
110     void setUser(const QString &user);
111     void setHost(const QString &host);
112     void setNick(const QString &nick);
113     void setRealName(const QString &realName);
114     /**
115      * Set account name, e.g. NickServ/SASL account
116      *
117      * @param[in] account Account name if logged in, * if logged out, or empty string if unknown
118      */
119     void setAccount(const QString &account);
120     void setAway(const bool &away);
121     void setAwayMessage(const QString &awayMessage);
122     void setIdleTime(const QDateTime &idleTime);
123     void setLoginTime(const QDateTime &loginTime);
124     void setServer(const QString &server);
125     void setIrcOperator(const QString &ircOperator);
126     // setLastAwayMessage is only called by legacy (pre-0.13) cores, which automatically gets
127     // converted to setting the appropriate lastAwayMessageTime.  Do not use this in new code.
128     void setLastAwayMessage(const int &lastAwayMessage);
129     void setLastAwayMessageTime(const QDateTime &lastAwayMessageTime);
130     void setWhoisServiceReply(const QString &whoisServiceReply);
131     void setSuserHost(const QString &suserHost);
132     void setEncrypted(bool encrypted);
133     void updateHostmask(const QString &mask);
134
135     void setUserModes(const QString &modes);
136
137     /*!
138      * \brief joinChannel Called when user joins some channel, this function inserts the channel to internal list of channels this user is in.
139      * \param channel Pointer to a channel this user just joined
140      * \param skip_channel_join If this is false, this function will also call IrcChannel::joinIrcUser, can be set to true as a performance tweak.
141      */
142     void joinChannel(IrcChannel *channel, bool skip_channel_join = false);
143     void joinChannel(const QString &channelname);
144     void partChannel(IrcChannel *channel);
145     void partChannel(const QString &channelname);
146     void quit();
147
148     void addUserModes(const QString &modes);
149     void removeUserModes(const QString &modes);
150
151 signals:
152 //   void userSet(QString user);
153 //   void hostSet(QString host);
154     void nickSet(QString newnick); // needed in NetworkModel
155 //   void realNameSet(QString realName);
156     void awaySet(bool away); // needed in NetworkModel
157 //   void awayMessageSet(QString awayMessage);
158 //   void idleTimeSet(QDateTime idleTime);
159 //   void loginTimeSet(QDateTime loginTime);
160 //   void serverSet(QString server);
161 //   void ircOperatorSet(QString ircOperator);
162 //   void lastAwayMessageTimeSet(QDateTime lastAwayMessageTime);
163 //   void whoisServiceReplySet(QString whoisServiceReply);
164 //   void suserHostSet(QString suserHost);
165     void encryptedSet(bool encrypted);
166
167     void userModesSet(QString modes);
168     void userModesAdded(QString modes);
169     void userModesRemoved(QString modes);
170
171     // void channelJoined(QString channel);
172     void channelParted(QString channel);
173     void quited();
174
175     void lastChannelActivityUpdated(BufferId id, const QDateTime &newTime);
176     void lastSpokenToUpdated(BufferId id, const QDateTime &newTime);
177
178 private slots:
179     void updateObjectName();
180     void channelDestroyed();
181
182 private:
183     inline bool operator==(const IrcUser &ircuser2)
184     {
185         return (_nick.toLower() == ircuser2.nick().toLower());
186     }
187
188
189     inline bool operator==(const QString &nickname)
190     {
191         return (_nick.toLower() == nickname.toLower());
192     }
193
194
195     bool _initialized;
196
197     QString _nick;
198     QString _user;
199     QString _host;
200     QString _realName;
201     QString _account;      /// Account name, e.g. NickServ/SASL account
202     QString _awayMessage;
203     bool _away;
204     QString _server;
205     QDateTime _idleTime;
206     QDateTime _idleTimeSet;
207     QDateTime _loginTime;
208     QString _ircOperator;
209     QDateTime _lastAwayMessageTime;
210     QString _whoisServiceReply;
211     QString _suserHost;
212     bool _encrypted;
213
214     // QSet<QString> _channels;
215     QSet<IrcChannel *> _channels;
216     QString _userModes;
217
218     Network *_network;
219
220     QTextCodec *_codecForEncoding;
221     QTextCodec *_codecForDecoding;
222
223     QHash<BufferId, QDateTime> _lastActivity;
224     QHash<BufferId, QDateTime> _lastSpokenTo;
225 };
226
227
228 #endif