1 #ifndef _KVI_IRCUSER_ENTRY_H_
2 #define _KVI_IRCUSER_ENTRY_H_
3 //=============================================================================
4 //
5 //   File : KviIrcUserEntry.h
6 //   Creation date : Tue Jan 04 2010 22:45:12 by Elvio Basello
7 //
8 //   This file is part of the KVIrc IRC client distribution
9 //   Copyright (C) 2010 Elvio Basello (hellvis69 at gmail dot com)
10 //
11 //   This program is FREE software. You can redistribute it and/or
12 //   modify it under the terms of the GNU General Public License
13 //   as published by the Free Software Foundation; either version 2
14 //   of the License, or (at your option) any later version.
15 //
16 //   This program is distributed in the HOPE that it will be USEFUL,
17 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
18 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 //   See the GNU General Public License for more details.
20 //
21 //   You should have received a copy of the GNU General Public License
22 //   along with this program. If not, write to the Free Software Foundation,
23 //   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //=============================================================================
26 
27 /**
28 * \file KviIrcUserEntry.h
29 * \author Szymon Stefanek
30 * \brief User DB handling
31 *
32 * This file was originally part of KviIrcUserDataBase.h
33 */
34 
35 #include "kvi_settings.h"
36 #include "KviAvatar.h"
37 
38 #include <memory>
39 
40 /**
41 * \class KviIrcUserEntry
42 * \brief A class to handle the entries of the user database
43 */
44 class KVILIB_API KviIrcUserEntry
45 {
46 	friend class KviIrcUserDataBase;
47 
48 public:
49 	/**
50 	* \enum Gender
51 	* \brief Defines the gender of the user
52 	*/
53 	enum Gender
54 	{
55 		Male = 0,   /**< Male */
56 		Female = 1, /**< Female */
57 		Unknown = 3 /**< Unknown */
58 	};
59 
60 	/**
61 	* \enum UserMode
62 	* \brief Defines the user mode in a channel
63 	*/
64 	enum UserMode
65 	{
66 		UserOp = 1,     /**< the user is a userop of the channel */
67 		Voice = 2,      /**< the user is a voice of the channel */
68 		HalfOp = 4,     /**< the user is a halfop of the channel */
69 		Op = 8,         /**< the user is an operator of the channel */
70 		ChanAdmin = 16, /**< the user is an admin of the channel */
71 		ChanOwner = 32, /**< the user is an owner of the channel */
72 		ModeMask = UserOp | Voice | HalfOp | Op | ChanAdmin | ChanOwner
73 	};
74 
75 	/**
76 	* \brief Constructs the entry object
77 	* \param user The user to add
78 	* \param host The host of the user
79 	* \return KviIrcUserEntry
80 	*/
81 	KviIrcUserEntry(const QString & user, const QString & host);
82 
83 protected:
84 	QString m_szUser;
85 	QString m_szHost;
86 
87 	QString m_szServer;
88 	QString m_szRealName;
89 	int m_iHops;
90 	Gender m_eGender;
91 	QString m_szUserFlags;
92 
93 	bool m_bAway;
94 	bool m_bIrcOp;
95 
96 	std::unique_ptr<KviAvatar> m_upAvatar;
97 
98 	int m_nRefs;
99 	bool m_bBot;
100 	bool m_bAvatarRequested;
101 
102 	bool m_bNotFoundRegUserLookup; //wtf?
103 	QString m_szRegisteredUserName;
104 	QString m_szLastRegisteredMatchNick;
105 
106 	QColor m_cachedColor;
107 	bool m_bUseCustomColor;
108 
109 	int m_iSmartNickColor;
110 	QString m_szAccountName;
111 
112 public:
113 	/**
114 	* \brief Returns the ircview smart nick color of the user
115 	* \return int
116 	*/
smartNickColor()117 	int smartNickColor() { return m_iSmartNickColor; };
118 
119 	/**
120 	* \brief Sets the ircview smart nick color of the user
121 	* \param iColor The color value
122 	* \return void
123 	*/
setSmartNickColor(const int iColor)124 	void setSmartNickColor(const int iColor) { m_iSmartNickColor = iColor; };
125 
126 	/**
127 	* \brief Returns the gender of the user
128 	* \return Gender
129 	*/
gender()130 	Gender gender() { return m_eGender; };
131 
132 	/**
133 	* \brief Sets the user as a bot
134 	* \param bIsBot If the user is a bot
135 	* \return void
136 	*/
setBot(bool bIsBot)137 	void setBot(bool bIsBot) { m_bBot = bIsBot; };
138 
139 	/**
140 	* \brief Sets the gender of the user
141 	* \param g The gender
142 	* \return void
143 	*/
setGender(Gender g)144 	void setGender(Gender g) { m_eGender = g; };
145 
146 	/**
147 	* \brief Sets the username of the user
148 	* \param szUser The username
149 	* \return void
150 	*/
setUser(const QString & szUser)151 	void setUser(const QString & szUser) { m_szUser = szUser; };
152 
153 	/**
154 	* \brief Sets the server of the user
155 	* \param szServ The server
156 	* \return void
157 	*/
setServer(const QString & szServ)158 	void setServer(const QString & szServ) { m_szServer = szServ; };
159 
160 	/**
161 	* \brief Sets the realname of the user
162 	* \param szReal The realname
163 	* \return void
164 	*/
165 	void setRealName(const QString & szReal);
166 
167 	/**
168 	* \brief Sets the number of hops of the user
169 	* \param iHops The number of hops
170 	* \return void
171 	*/
setHops(int iHops)172 	void setHops(int iHops) { m_iHops = iHops; };
173 
174 	/**
175 	* \brief Sets the hostname of the user
176 	* \param szHost The hostname
177 	* \return void
178 	*/
setHost(const QString & szHost)179 	void setHost(const QString & szHost) { m_szHost = szHost; };
180 
181 	/**
182 	* \brief Sets the away state of the user
183 	* \param bAway The away state
184 	* \return void
185 	*/
setAway(bool bAway)186 	void setAway(bool bAway) { m_bAway = bAway; };
187 
188 	/**
189 	* \brief Sets the irc operator state of the user
190 	* \param bIrcOp The ircop state
191 	* \return void
192 	*/
setIrcOp(bool bIrcOp)193 	void setIrcOp(bool bIrcOp) { m_bIrcOp = bIrcOp; };
194 
195 	/**
196 	* \brief Sets the avatar of the user
197 	* \param upAvatar The avatar
198 	* \return void
199 	* \warning The ownership passes to this class!
200 	*/
201 	void setAvatar(std::unique_ptr<KviAvatar> upAvatar = nullptr);
202 
203 	/**
204 	* \brief Sets the avatar of the user
205 	* \param pAvatar The avatar
206 	* \return void
207 	* \warning The ownership passes to this class!
208 	* \warning This is an overload function for backwards compatibility
209 	*/
210 	void setAvatar(KviAvatar * upAvatar = nullptr);
211 
212 	/**
213 	* \brief Sets the user global flags (eg: "G*")
214 	* \param szFlags
215 	* \return void
216 	*/
setUserFlags(const QString & szFlags)217 	void setUserFlags(const QString & szFlags) { m_szUserFlags = szFlags; };
218 
219 	/**
220 	* \brief Returns true if the user is marked as a bot
221 	* \return bool
222 	*/
isBot()223 	bool isBot() { return m_bBot; };
224 
225 	/**
226 	* \brief Returns true if the user is in away mode
227 	* \return bool
228 	*/
isAway()229 	bool isAway() const { return m_bAway; };
230 
231 	/**
232 	* \brief Returns true if the user is an irc operator
233 	* \return bool
234 	*/
isIrcOp()235 	bool isIrcOp() const { return m_bIrcOp; };
236 
237 	/**
238 	* \brief Returns true if the user has the username set
239 	* \return bool
240 	*/
hasUser()241 	bool hasUser() { return (!m_szUser.isEmpty()); };
242 
243 	/**
244 	* \brief Returns true if the user has the hostname set
245 	* \return bool
246 	*/
hasHost()247 	bool hasHost() { return (!m_szHost.isEmpty()); };
248 
249 	/**
250 	* \brief Returns true if the user has the server set
251 	* \return bool
252 	*/
hasServer()253 	bool hasServer() { return (!m_szServer.isEmpty()); };
254 
255 	/**
256 	* \brief Returns true if the user has the realname set
257 	* \return bool
258 	*/
hasRealName()259 	bool hasRealName() { return (!m_szRealName.isEmpty()); };
260 
261 	/**
262 	* \brief Returns true if the user has hops set
263 	* \return bool
264 	*/
hasHops()265 	bool hasHops() { return m_iHops >= 0; };
266 
267 	/**
268 	* \brief Returns the username of the user
269 	* \return const QString &
270 	*/
user()271 	const QString & user() { return m_szUser; };
272 
273 	/**
274 	* \brief Returns the hostname of the user
275 	* \return const QString &
276 	*/
host()277 	const QString & host() { return m_szHost; };
278 
279 	/**
280 	* \brief Returns the server of the user
281 	* \return const QString &
282 	*/
server()283 	const QString & server() { return m_szServer; };
284 
285 	/**
286 	* \brief Returns the realname of the user
287 	* \return const QString &
288 	*/
realName()289 	const QString & realName() { return m_szRealName; };
290 
291 	/**
292 	* \brief Returns the user flags
293 	* \return const QString &
294 	*/
userFlags()295 	const QString & userFlags() { return m_szUserFlags; };
296 
297 	/**
298 	* \brief Returns the number of hops
299 	* \return int
300 	*/
hops()301 	int hops() { return m_iHops; };
302 
303 	/**
304 	* \brief Returns the avatar of the user
305 	* \return KviAvatar
306 	*/
avatar()307 	KviAvatar * avatar() { return m_upAvatar.get(); };
308 
309 	/**
310 	* \brief Returns the number of references of the user in the database
311 	* \return int
312 	*/
nRefs()313 	int nRefs() { return m_nRefs; };
314 
315 	/**
316 	* \brief Removes the avatar associated to the user
317 	* \return KviAvatar *
318 	*/
319 	std::unique_ptr<KviAvatar> forgetAvatar();
320 
321 	/**
322 	* \brief Returns true if kvirc already made an attempt to download user's avatar
323 	* \return bool
324 	*/
avatarRequested()325 	bool avatarRequested() const { return m_bAvatarRequested; };
326 
327 	/**
328 	* \brief Mark that kvirc is trying (already tried) to get user's avatar
329 	*/
setAvatarRequested()330 	void setAvatarRequested() { m_bAvatarRequested = true; };
331 
332 	/**
333 	* \brief Returns the account name (if any)
334 	* \return const QString &
335 	*/
accountName()336 	const QString & accountName() { return m_szAccountName; };
337 
338 	/**
339 	* \brief Sets the account name for the user
340 	*/
setAccountName(const QString & szAccountName)341 	void setAccountName(const QString & szAccountName) { m_szAccountName = szAccountName; };
342 
343 	/**
344 	* \brief Returns true if the user has an account name
345 	* \return bool
346 	*/
hasAccountName()347 	bool hasAccountName() { return (!m_szAccountName.isEmpty()); };
348 };
349 
350 #endif // _KVI_IRCUSER_ENTRY_H_
351