summaryrefslogtreecommitdiffstats
path: root/src/kvilib/irc/kvi_ircuserdb.h
blob: bd5591c9e5753ffd61e5ddc107976c92980656d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#ifndef _KVI_IRCUSERDB_H_
#define _KVI_IRCUSERDB_H_

//=============================================================================
//
//   File : kvi_ircuserdb.h
//   Creation date : Mon Jul 31 2000 20:59:12 by Szymon Stefanek
//
//   This file is part of the KVirc irc client distribution
//   Copyright (C) 2000-2004 Szymon Stefanek (pragma at kvirc dot net)
//
//   This program is FREE software. You can redistribute it and/or
//   modify it under the terms of the GNU General Public License
//   as published by the Free Software Foundation; either version 2
//   of the License, or (at your opinion) any later version.
//
//   This program is distributed in the HOPE that it will be USEFUL,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//   See the GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program. If not, write to the Free Software Foundation,
//   Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================

#include "kvi_settings.h"

#include "kvi_pointerhashtable.h"

#include "kvi_string.h"
#include "kvi_avatar.h"
#include "kvi_regusersdb.h"

class KviIrcUserDataBase;

class KVILIB_API KviIrcUserEntry
{
	friend class KviIrcUserDataBase;
public:
	KviIrcUserEntry(const TQString &user,const TQString &host);
	~KviIrcUserEntry();

	enum Gender {
		Male = 0,
		Female = 1,
		Unknown = 3
	};

protected:
	TQString     m_szUser;
	TQString     m_szHost;

	TQString     m_szServer;
	TQString     m_szRealName;
	int         m_iHops;
	Gender      m_eGender;
	
	bool        m_bAway;

	KviAvatar * m_pAvatar;

	int         m_nRefs;
	bool        m_bBot;

	bool        m_bNotFoundRegUserLoockup;
	TQString     m_szRegisteredUserName;
	TQString     m_szLastRegisteredMatchNick;

	TQColor      m_cachedColor;
	bool        m_bUseCustomColor;
public:
	Gender gender() { return m_eGender; };
	void setBot(bool bIsBot) { m_bBot = bIsBot; };
	bool isBot() { return m_bBot; };
	void setGender(Gender g) { m_eGender=g; };
	void setUser(const TQString &user)   { m_szUser = user; };
	bool hasUser()                      { return (!m_szUser.isEmpty()); };
	void setHost(const TQString &host)   { m_szHost = host; };
	bool hasHost()                      { return (!m_szHost.isEmpty()); };
	void setServer(const TQString &serv) { m_szServer = serv; };
	void setRealName(const TQString &rn);
	void setHops(int hops)              { m_iHops = hops; };
	const TQString &user()               { return m_szUser; };
	const TQString &host()               { return m_szHost; };
	bool hasServer()                    { return (!m_szServer.isEmpty()); };
	const TQString &server()             { return m_szServer; };
	bool hasRealName()                  { return (!m_szRealName.isEmpty()); };
	const TQString &realName()           { return m_szRealName; };
	bool hasHops()                      { return m_iHops >= 0; };
	int hops()                          { return m_iHops; };
	KviAvatar * avatar()                { return m_pAvatar; };
	int nRefs()                         { return m_nRefs; };
	bool isAway() const                 { return m_bAway; };
	void setAway(bool bAway)            { m_bAway = bAway; };
	// warning! the ownership passes to this class!
	void setAvatar(KviAvatar * av = 0);
	KviAvatar * forgetAvatar();
};

// from least powerful to most powerful
#define KVI_USERFLAG_USEROP 1
#define KVI_USERFLAG_VOICE 2
#define KVI_USERFLAG_HALFOP 4
#define KVI_USERFLAG_OP 8
#define KVI_USERFLAG_CHANADMIN 16
#define KVI_USERFLAG_CHANOWNER 32

// 1 | 2 | 4 | 8 | 16 | 32
#define KVI_USERFLAG_MASK (KVI_USERFLAG_OP | KVI_USERFLAG_VOICE | KVI_USERFLAG_HALFOP | KVI_USERFLAG_CHANADMIN | KVI_USERFLAG_USEROP | KVI_USERFLAG_CHANOWNER)
// at the moment all the flags are usermodes
#define KVI_USERFLAG_MODEMASK KVI_USERFLAG_MASK


class KVILIB_API KviIrcUserDataBase : public TQObject
{
	TQ_OBJECT
  
public:
	KviIrcUserDataBase();
	~KviIrcUserDataBase();
private:
	KviPointerHashTable<TQString,KviIrcUserEntry> * m_pDict;
public:
	void clear();
	KviIrcUserEntry * insertUser(const TQString &nick,const TQString &user,const TQString &hostname);
	KviIrcUserEntry * find(const TQString &nick){ return m_pDict->find(nick); };
	void removeUser(const TQString &nick,KviIrcUserEntry * e);
	KviPointerHashTable<TQString,KviIrcUserEntry> * dict(){ return m_pDict; };

	KviRegisteredUser* registeredUser(const TQString & nick);
	KviRegisteredUser* registeredUser(const TQString & nick,const TQString & user,const TQString & host);

	bool haveCustomColor(const TQString & nick);
	TQColor* customColor(const TQString & nick);

	void setupConnectionWithReguserDb();
protected slots:
	void registeredUserRemoved(const TQString&);
	void registeredUserChanged(const TQString&);
	void registeredUserAdded  (const TQString&);
	void registeredDatabaseCleared();
};

#endif //_KVI_IRCUSERDB_H_