1 | /*************************************************************************** |
2 | * Copyright (C) 2005-2014 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(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(int lastAwayMessage READ lastAwayMessage WRITE setLastAwayMessage) |
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) |
56 | |
57 | Q_PROPERTY(QStringList channels READ channels) |
58 | Q_PROPERTY(QString userModes READ userModes WRITE setUserModes) |
59 | |
60 | public : |
61 | IrcUser(const QString &hostmask, Network *network); |
62 | virtual ~IrcUser(); |
63 | |
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; } |
68 | QString hostmask() const; |
69 | inline bool isAway() const { return _away; } |
70 | inline QString awayMessage() const { return _awayMessage; } |
71 | QDateTime idleTime(); |
72 | inline QDateTime loginTime() const { return _loginTime; } |
73 | inline QString server() const { return _server; } |
74 | inline QString ircOperator() const { return _ircOperator; } |
75 | inline int lastAwayMessage() const { return _lastAwayMessage; } |
76 | inline QString whoisServiceReply() const { return _whoisServiceReply; } |
77 | inline QString suserHost() const { return _suserHost; } |
78 | inline bool encrypted() const { return _encrypted; } |
79 | inline Network *network() const { return _network; } |
80 | |
81 | inline QString userModes() const { return _userModes; } |
82 | |
83 | QStringList channels() const; |
84 | |
85 | // user-specific encodings |
86 | inline QTextCodec *codecForEncoding() const { return _codecForEncoding; } |
87 | inline QTextCodec *codecForDecoding() const { return _codecForDecoding; } |
88 | void setCodecForEncoding(const QString &codecName); |
89 | void setCodecForEncoding(QTextCodec *codec); |
90 | void setCodecForDecoding(const QString &codecName); |
91 | void setCodecForDecoding(QTextCodec *codec); |
92 | |
93 | QString decodeString(const QByteArray &text) const; |
94 | QByteArray encodeString(const QString &string) const; |
95 | |
96 | // only valid on client side, these are not synced! |
97 | inline QDateTime lastChannelActivity(BufferId id) const { return _lastActivity.value(id); } |
98 | void setLastChannelActivity(BufferId id, const QDateTime &time); |
99 | inline QDateTime lastSpokenTo(BufferId id) const { return _lastSpokenTo.value(id); } |
100 | void setLastSpokenTo(BufferId id, const QDateTime &time); |
101 | |
102 | public slots: |
103 | void setUser(const QString &user); |
104 | void setHost(const QString &host); |
105 | void setNick(const QString &nick); |
106 | void setRealName(const QString &realName); |
107 | void setAway(const bool &away); |
108 | void setAwayMessage(const QString &awayMessage); |
109 | void setIdleTime(const QDateTime &idleTime); |
110 | void setLoginTime(const QDateTime &loginTime); |
111 | void setServer(const QString &server); |
112 | void setIrcOperator(const QString &ircOperator); |
113 | void setLastAwayMessage(const int &lastAwayMessage); |
114 | void setWhoisServiceReply(const QString &whoisServiceReply); |
115 | void setSuserHost(const QString &suserHost); |
116 | void setEncrypted(bool encrypted); |
117 | void updateHostmask(const QString &mask); |
118 | |
119 | void setUserModes(const QString &modes); |
120 | |
121 | void joinChannel(IrcChannel *channel); |
122 | void joinChannel(const QString &channelname); |
123 | void partChannel(IrcChannel *channel); |
124 | void partChannel(const QString &channelname); |
125 | void quit(); |
126 | |
127 | void addUserModes(const QString &modes); |
128 | void removeUserModes(const QString &modes); |
129 | |
130 | signals: |
131 | // void userSet(QString user); |
132 | // void hostSet(QString host); |
133 | void nickSet(QString newnick); // needed in NetworkModel |
134 | // void realNameSet(QString realName); |
135 | void awaySet(bool away); // needed in NetworkModel |
136 | // void awayMessageSet(QString awayMessage); |
137 | // void idleTimeSet(QDateTime idleTime); |
138 | // void loginTimeSet(QDateTime loginTime); |
139 | // void serverSet(QString server); |
140 | // void ircOperatorSet(QString ircOperator); |
141 | // void lastAwayMessageSet(int lastAwayMessage); |
142 | // void whoisServiceReplySet(QString whoisServiceReply); |
143 | // void suserHostSet(QString suserHost); |
144 | void encryptedSet(bool encrypted); |
145 | |
146 | void userModesSet(QString modes); |
147 | void userModesAdded(QString modes); |
148 | void userModesRemoved(QString modes); |
149 | |
150 | // void channelJoined(QString channel); |
151 | void channelParted(QString channel); |
152 | void quited(); |
153 | |
154 | void lastChannelActivityUpdated(BufferId id, const QDateTime &newTime); |
155 | void lastSpokenToUpdated(BufferId id, const QDateTime &newTime); |
156 | |
157 | private slots: |
158 | void updateObjectName(); |
159 | void channelDestroyed(); |
160 | |
161 | private: |
162 | inline bool operator==(const IrcUser &ircuser2) |
163 | { |
164 | return (_nick.toLower() == ircuser2.nick().toLower()); |
165 | } |
166 | |
167 | |
168 | inline bool operator==(const QString &nickname) |
169 | { |
170 | return (_nick.toLower() == nickname.toLower()); |
171 | } |
172 | |
173 | |
174 | bool _initialized; |
175 | |
176 | QString _nick; |
177 | QString _user; |
178 | QString _host; |
179 | QString _realName; |
180 | QString _awayMessage; |
181 | bool _away; |
182 | QString _server; |
183 | QDateTime _idleTime; |
184 | QDateTime _idleTimeSet; |
185 | QDateTime _loginTime; |
186 | QString _ircOperator; |
187 | int _lastAwayMessage; |
188 | QString _whoisServiceReply; |
189 | QString _suserHost; |
190 | bool _encrypted; |
191 | |
192 | // QSet<QString> _channels; |
193 | QSet<IrcChannel *> _channels; |
194 | QString _userModes; |
195 | |
196 | Network *_network; |
197 | |
198 | QTextCodec *_codecForEncoding; |
199 | QTextCodec *_codecForDecoding; |
200 | |
201 | QHash<BufferId, QDateTime> _lastActivity; |
202 | QHash<BufferId, QDateTime> _lastSpokenTo; |
203 | }; |
204 | |
205 | |
206 | #endif |
207 | |