summaryrefslogtreecommitdiffstats
path: root/src/kvirc/ui/kvi_channel.h
blob: 45a480163119048b3c8f06a0021d430df0418c9f (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#ifndef _KVI_CHANNEL_H_
#define _KVI_CHANNEL_H_
//=============================================================================
//
//   File : kvi_channel.h
//   Creation date : Tue Aug 1 2000 01:42:00 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_console.h"
#include "kvi_window.h"
#include "kvi_string.h"
#include "kvi_ircuserdb.h"
#include "kvi_pixmap.h"
#include "kvi_userlistview.h"
#include "kvi_time.h"
#include "kvi_modew.h"
#include "kvi_valuelist.h"

#include <tqdatetime.h>
#include "kvi_pointerhashtable.h"
#include <tqstringlist.h>

class KviConsole;
class TQSplitter;
class TQToolButton;
class KviTopicWidget;
class KviIrcMask;
class KviThemedLabel;
class KviTalHBox;

#ifdef COMPILE_ON_WINDOWS
	// windows compiler wants this instead of the forward decl
	#include "kvi_maskeditor.h"
#else
	typedef struct _KviMaskEntry KviMaskEntry; // kvi_maskeditor.h
#endif
class KviMaskEditor;
class KviModeEditor;

#define KVI_CHANNEL_STATE_HAVEALLNAMES 1
#define KVI_CHANNEL_STATE_HAVEBANLIST (1 << 1)
#define KVI_CHANNEL_STATE_HAVEWHOLIST (1 << 2)
#define KVI_CHANNEL_STATE_HAVEBANEXCEPTIONLIST (1 << 3)
#define KVI_CHANNEL_STATE_HAVEINVITELIST (1 << 4)
#define KVI_CHANNEL_STATE_DEADCHAN (1 << 5)

#define KVI_CHANNEL_STATE_SENTBANLISTREQUEST (1 << 6)
#define KVI_CHANNEL_STATE_SENTBANEXCEPTIONLISTREQUEST (1 << 7)
#define KVI_CHANNEL_STATE_SENTINVITELISTREQUEST (1 << 8)
#define KVI_CHANNEL_STATE_SENTWHOREQUEST (1 << 9)

#define KVI_CHANNEL_STATE_SENTPART (1 << 10)
#define KVI_CHANNEL_STATE_SYNCHRONIZED (1 << 11)

#define KVI_CHANNEL_STATE_NOCLOSEONPART (1 << 12)

#define KVI_CHANNEL_STATE_SENTSYNCWHOREQUEST (1 << 13)

typedef struct _KviChannelAction
{
	TQString      szNick;       // action source nick
	unsigned int uActionType;  // type of the action
	kvi_time_t   tTime;        // time of the action
	int          iTemperature; // temperature of the action
} KviChannelAction;

// this is the maximum count of actions that we keep in memory
#define KVI_CHANNEL_ACTION_HISTORY_MAX_COUNT 40
// this is the timespan of the oldest action that we keep in memory
// 600 secs = 10 mins
#define KVI_CHANNEL_ACTION_HISTORY_MAX_TIMESPAN 600

typedef struct _KviChannelActivityStats
{
	unsigned int        uActionCount;              // number of actions in the history
	bool                bStatsInaccurate;          // the stats are inaccurate because we have just joined the chan
	unsigned int        uLastActionTimeSpan;       // the timespan between the last action and now
	unsigned int        uFirstActionTimeSpan;      // the time span between the first and the last action
	double              dActionsPerMinute;         // average number of actions per minute in the lastActionTimeSpan
	unsigned int        uActionsInTheLastMinute;   // number of actions in the last minute
	int                 iAverageActionTemperature; // the average chan temperature
	unsigned int        uHotActionCount;
	unsigned int        uHotActionPercent;
	TQStringList         lTalkingUsers;             // users that seem to be talking NOW
	TQStringList         lWereTalkingUsers;
} KviChannelActivityStats;

class KVIRC_API KviChannel : public KviWindow
{
	Q_OBJECT
  TQ_OBJECT
public:
	KviChannel(KviFrame * lpFrm,KviConsole * lpConsole,const char * name);
	~KviChannel();
protected:
	TQSplitter                           * m_pTopSplitter;
	TQSplitter                           * m_pVertSplitter;
	BUTTON_CLASS                        * m_pDoubleViewButton;
	KviWindowToolPageButton             * m_pListViewButton;
	KviWindowToolPageButton             * m_pBanEditorButton;
	KviWindowToolPageButton             * m_pBanExceptionEditorButton;
	KviWindowToolPageButton             * m_pInviteEditorButton;
	KviWindowToolPageButton             * m_pModeEditorButton;
	KviMaskEditor                       * m_pBanEditor;
	KviMaskEditor                       * m_pBanExceptionEditor;
	KviMaskEditor                       * m_pInviteEditor;
	KviModeEditor                       * m_pModeEditor;
	KviIrcView                          * m_pMessageView;
	KviTopicWidget                      * m_pTopicWidget;
	KviUserListView                     * m_pUserListView;
	KviModeWidget                       * m_pModeWidget;
	int                                   m_iStateFlags;
	TQString                               m_szChannelMode;
	TQString                               m_szChannelKey;
	KviStr                                m_szChannelLimit;
	KviPointerList<KviMaskEntry>            * m_pBanList;
	KviPointerList<KviMaskEntry>            * m_pBanExceptionList;
	KviPointerList<KviMaskEntry>            * m_pInviteList;
	KviPixmap                             m_privateBackground;
	TQDateTime                             m_joinTime;
	TQString                               m_szNameWithUserFlag;
	KviPointerHashTable<const char *,TQString>               * m_pTmpHighLighted;
	unsigned int                          m_uActionHistoryHotActionCount;
	KviPointerList<KviChannelAction>        * m_pActionHistory;
	kvi_time_t                            m_tLastReceivedWhoReply;
	KviValueList<int>                     m_VertSplitterSizesList;
	KviTalHBox                          * m_pButtonContainer;
protected:
	bool eventFilter(TQObject *, TQEvent *);
	virtual TQPixmap * myIconPtr();
	virtual void fillCaptionBuffers();
	virtual void resizeEvent(TQResizeEvent *e);
	virtual void closeEvent(TQCloseEvent *e);
//	virtual void fillContextPopup(KviTalPopupMenu * p);
	virtual void getConfigGroupName(TQString &buf);
	virtual void saveProperties(KviConfig * cfg);
	virtual void loadProperties(KviConfig * cfg);
	virtual void applyOptions();
	virtual void getBaseLogFileName(TQString &buffer);
	virtual void triggerCreationEvents();
	void toggleEditor(KviMaskEditor ** ppEd,KviWindowToolPageButton ** ppBtn,KviPointerList<KviMaskEntry> *l,char flag,const char *edName);
	void internalMask(const TQString &mask,bool bAdd,const TQString &setBy,unsigned int setAt,KviPointerList<KviMaskEntry> *l,KviMaskEditor **ppEd);
	void checkChannelSync();
	void showDoubleView(bool bShow);
	void fixActionHistory();
	void getTalkingUsersStats(TQString &buffer,TQStringList &l,bool bPast);
public:
	void getChannelActivityStats(KviChannelActivityStats * s);
	//void getChannelActivityStatsDescription(TQString &buffer);

	KviPointerList<KviMaskEntry> * banList(){ return m_pBanList; };
	KviPointerList<KviMaskEntry> * banExceptionList(){ return m_pBanExceptionList; };
	KviPointerList<KviMaskEntry> * inviteList(){ return m_pInviteList; };

	TQString * firstSelectedNickname(){ return m_pUserListView->firstSelectedNickname(); };
	TQString * nextSelectedNickname(){ return m_pUserListView->nextSelectedNickname(); };

	int selectedCount(){ return m_pUserListView->selectedCount(); };
	int opCount(){ return m_pUserListView->opCount(); };
	int voiceCount(){ return m_pUserListView->voiceCount(); };
	int halfOpCount(){ return m_pUserListView->halfOpCount(); };
	int userOpCount(){ return m_pUserListView->userOpCount(); };
	int chanAdminCount(){ return m_pUserListView->chanAdminCount(); };
	int chanOwnerCount(){ return m_pUserListView->chanOwnerCount(); };
	unsigned int count(){ return m_pUserListView->count(); };

	unsigned int banCount(){ return m_pBanList->count(); };
	unsigned int banExceptionCount(){ return m_pBanExceptionList->count(); };
	unsigned int inviteCount(){ return m_pInviteList->count(); };

	const TQString & nameWithUserFlag(){ return m_szNameWithUserFlag; };
	virtual const TQString & target(){ return windowName(); };
//	void appendSelectedNicknames(KviStr &buffer);
	void setMask(char flag, const TQString &mask,bool bAdd,const TQString &setBy,unsigned int setAt);

	kvi_time_t lastReceivedWhoReply(){ return m_tLastReceivedWhoReply; };
	void setLastReceivedWhoReply(kvi_time_t tTime){ m_tLastReceivedWhoReply = tTime; };
	void setSentSyncWhoRequest(){ m_iStateFlags |= KVI_CHANNEL_STATE_SENTSYNCWHOREQUEST; };
	void clearSentSyncWhoRequest(){ m_iStateFlags ^= KVI_CHANNEL_STATE_SENTSYNCWHOREQUEST; };
	bool sentSyncWhoRequest(){ return (m_iStateFlags & KVI_CHANNEL_STATE_SENTSYNCWHOREQUEST); };

	bool sentWhoRequest(){ return (m_iStateFlags & KVI_CHANNEL_STATE_SENTWHOREQUEST); };
	void setSentWhoRequest(){ m_iStateFlags |= KVI_CHANNEL_STATE_SENTWHOREQUEST; };
	bool sentInviteListRequest(){ return (m_iStateFlags & KVI_CHANNEL_STATE_SENTINVITELISTREQUEST); };
	void setSentInviteListRequest(){ m_iStateFlags |= KVI_CHANNEL_STATE_SENTINVITELISTREQUEST; };
	void setInviteListDone(){ m_iStateFlags ^= KVI_CHANNEL_STATE_SENTINVITELISTREQUEST; };
	bool sentBanListRequest(){ return (m_iStateFlags & KVI_CHANNEL_STATE_SENTBANLISTREQUEST); };
	void setSentBanListRequest(){ m_iStateFlags |= KVI_CHANNEL_STATE_SENTBANLISTREQUEST; };
	void setBanListDone(){ m_iStateFlags ^= KVI_CHANNEL_STATE_SENTBANLISTREQUEST; };
	bool sentBanExceptionListRequest(){ return (m_iStateFlags & KVI_CHANNEL_STATE_SENTBANEXCEPTIONLISTREQUEST); };
	void setSentBanExceptionListRequest(){ m_iStateFlags |= KVI_CHANNEL_STATE_SENTBANEXCEPTIONLISTREQUEST; };
	void setBanExceptionListDone(){ m_iStateFlags ^= KVI_CHANNEL_STATE_SENTBANEXCEPTIONLISTREQUEST; };

	bool hasAllNames(){ return (m_iStateFlags & KVI_CHANNEL_STATE_HAVEALLNAMES); };
	void setHasAllNames(){ m_iStateFlags |= KVI_CHANNEL_STATE_HAVEALLNAMES; checkChannelSync(); };
	bool hasInviteList(){ return (m_iStateFlags & KVI_CHANNEL_STATE_HAVEINVITELIST); checkChannelSync(); };
	void setHasInviteList(){ m_iStateFlags |= KVI_CHANNEL_STATE_HAVEINVITELIST; };
	bool hasWhoList(){ return (m_iStateFlags & KVI_CHANNEL_STATE_HAVEWHOLIST); };
	void setHasWhoList(){ m_iStateFlags |= KVI_CHANNEL_STATE_HAVEWHOLIST; checkChannelSync(); };
	bool hasBanList(){ return (m_iStateFlags & KVI_CHANNEL_STATE_HAVEBANLIST); };
	void setHasBanList(){ m_iStateFlags |= KVI_CHANNEL_STATE_HAVEBANLIST; checkChannelSync(); };
	bool hasBanExceptionList(){ return (m_iStateFlags & KVI_CHANNEL_STATE_HAVEBANEXCEPTIONLIST); };
	void setHasBanExceptionList(){ m_iStateFlags |= KVI_CHANNEL_STATE_HAVEBANEXCEPTIONLIST; checkChannelSync(); };

	bool closeOnPart(){ return !(m_iStateFlags & KVI_CHANNEL_STATE_NOCLOSEONPART); };
	void partMessageSent(bool bCloseOnPart = true,bool bShowMessage = true);
	
	virtual bool activityMeter(unsigned int * puActivityValue,unsigned int * puActivityTemperature);

	void setDeadChan();
	void setAliveChan();
	void prependUserFlag(const TQString &nick,TQString &buffer){ m_pUserListView->prependUserFlag(nick,buffer); };
	char getUserFlag(const TQString &nick){ return m_pUserListView->getUserFlag(nick); };
	bool isDeadChan(){ return (m_iStateFlags & KVI_CHANNEL_STATE_DEADCHAN); };
	virtual TQSize tqsizeHint() const;
	void enableUserListUpdates(bool bEnable){ m_pUserListView->enableUpdates(bEnable); };
	KviUserListEntry * join(const TQString &nick,const TQString &user = TQString(),const TQString &host = TQString(),int iFlags = 0)
		{ return m_pUserListView->join(nick,user,host,iFlags); };
	bool op(const TQString &nick,bool bOp){ return m_pUserListView->op(nick,bOp); };
	bool avatarChanged(const TQString &nick){ return m_pUserListView->avatarChanged(nick); };
	bool voice(const TQString &nick,bool bVoice){ return m_pUserListView->voice(nick,bVoice); };
	bool halfop(const TQString &nick,bool bHalfOp){ return m_pUserListView->halfop(nick,bHalfOp); };
	bool userop(const TQString &nick,bool bUserOp){ return m_pUserListView->userop(nick,bUserOp); };
	bool setChanOwner(const TQString &nick,bool bChanOwner){ return m_pUserListView->setChanOwner(nick,bChanOwner); };
	bool setChanAdmin(const TQString &nick,bool bChanAdmin){ return m_pUserListView->setChanAdmin(nick,bChanAdmin); };
	void userAction(KviIrcMask * user,unsigned int uActionType);
	void userAction(const TQString &nick,unsigned int uActionType);
	void userAction(const TQString &nick,const TQString &user,const TQString &host,unsigned int uActionType);
	bool nickChange(const TQString &oldNick,const TQString &newNick);
	void channelAction(const TQString &nick,unsigned int uActionType,int iTemperature);
	bool part(const TQString &nick);
	bool isOn(const TQString &nick){ return (m_pUserListView->findEntry(nick) != 0); };
	KviUserListEntry * findEntry(const TQString &nick){ return m_pUserListView->findEntry(nick); };
	KviUserListView * userListView(){ return m_pUserListView; };
	bool isMeOp(bool bAtLeast = false);
	bool isMeChanOwner(bool bAtLeast = false);
	bool isMeChanAdmin(bool bAtLeast = false);
	bool isMeVoice(bool bAtLeast = false);
	bool isMeHalfOp(bool bAtLeast = false);
	bool isMeUserOp(bool bAtLeast = false);
	bool isOp(const TQString &nick,bool bAtLeast = false){ return m_pUserListView->isOp(nick,bAtLeast); };
	bool isVoice(const TQString &nick,bool bAtLeast = false){ return m_pUserListView->isVoice(nick,bAtLeast); };
	bool isHalfOp(const TQString &nick,bool bAtLeast = false){ return m_pUserListView->isHalfOp(nick,bAtLeast); };
	bool isUserOp(const TQString &nick,bool bAtLeast = false){ return m_pUserListView->isUserOp(nick,bAtLeast); };
	bool isChanOwner(const TQString &nick,bool bAtLeast = false){ return m_pUserListView->isChanOwner(nick,bAtLeast); };
	bool isChanAdmin(const TQString &nick,bool bAtLeast = false){ return m_pUserListView->isChanAdmin(nick,bAtLeast); };
	int myFlags();
	void updateModeLabel();
	KviTopicWidget * topicWidget(){ return m_pTopicWidget; };
	virtual void outputMessage(int msg_type,const TQString &msg);
	void ownMessage(const TQString &buffer);
	void ownAction(const TQString &buffer);
	void setChannelMode(char  mode,bool bAdd);
	void setChannelKey(const char * key);
	void setChannelLimit(const char * limit);

	void getChannelModeString(TQString &buffer);

	KviStr & channelLimit(){ return m_szChannelLimit; };
	bool hasChannelLimit(){ return m_szChannelLimit.hasData(); };

	bool hasChannelKey() { return !m_szChannelKey.isEmpty(); };
	TQString & channelKey(){ return m_szChannelKey; };

    void addHighlightedUser(const char * nick);
    void removeHighlightedUser(const char * nick);
    bool isHighlightedUser(const char * nick) { return m_pTmpHighLighted->find(nick); };
    KviIrcView * messageView() const { return m_pMessageView; };
	virtual void lostUserFocus();
	virtual void getTaskBarTipText(TQString &buffer);
	TQString channelMode() { return m_szChannelMode; };

	void unhighlight();
	
	TQFrame * buttonContainer() { return (TQFrame*)m_pButtonContainer; };
private slots:
	void toggleDoubleView();
	void toggleListView();
	void toggleBanEditor();
	void toggleBanExceptionEditor();
	void toggleInviteEditor();
	void toggleModeEditor();
	void topicSelected(const TQString & topic);
	void setMode(const char * mode);
	void modeSelectorDone();
	void textViewRightClicked();
	void removeMasks(KviMaskEditor *ed,KviPointerList<KviMaskEntry> *l);
	void toggleToolButtons();
protected:
	virtual void preprocessMessage(TQString & szMessage);
};

#endif //_KVI_CHANNEL_H_