summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/irc/ircprotocol.h
blob: 2a1700e57165e73d4ed240e1285f6df0ebe1e134 (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
/*
    ircprotocol.h - IRC Protocol

    Copyright (c) 2002      by Nick Betcher <[email protected]>

    Kopete    (c) 2002-2004 by the Kopete developers <[email protected]>

    *************************************************************************
    *                                                                       *
    * 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 option) any later version.                                   *
    *                                                                       *
    *************************************************************************
*/

#ifndef IRCPROTOCOL_H
#define IRCPROTOCOL_H

#include "kopeteonlinestatus.h"
#include "kopeteprotocol.h"
#include "kopetecontactproperty.h"
#include "kopetemimetypehandler.h"

#include <dom/dom_node.h>
#include <qdict.h>

#define m_protocol (IRCProtocol::protocol())

namespace Kopete
{
class Account;
class MetaContact;
}

class AddContactPage;

class EditAccountWidget;
class IRCAccount;

class QStringList;
class QWidget;
class KopeteView;

class IRCNetwork;
class IRCHost;
class NetworkConfig;

class IRCProtocolHandler : public Kopete::MimeTypeHandler
{
	public:

		IRCProtocolHandler();

		void handleURL( const KURL &url ) const;
};

static const QString CHAT_VIEW( QString::fromLatin1("kopete_chatwindow") );

/**
 * @author Nick Betcher <[email protected]>
 */
class IRCProtocol : public Kopete::Protocol
{
	Q_OBJECT

public:
	enum IRCStatus
	{
		Offline        = 1,                 //! An offline user.
		Connecting     = 2,                 //! User that is connecting.
		Away           = 4,                 //! User that is away. May be regular user, voiced user or (server) operator.
		Online         = 8,                 //! This user is online.
		Voiced         = 16,                //! This user is voiced.
		Operator       = 32,                //! This user is a channel operator.
		ServerOperator = 1024,              //! This user is a server operator.
		OfflineChannel = 4096,              //! This channel is offline.
		OnlineChannel  = 8192,              //! This channel is online.
		OfflineServer  = 16384,             //! This server is offline.
		OnlineServer   = 32768              //! This server is online.
	};

	IRCProtocol( QObject *parent, const char *name, const QStringList &args );
	~IRCProtocol();

	/** Kopete::Protocol reimplementation */
	virtual AddContactPage *createAddContactWidget(QWidget *parent, Kopete::Account *account);

	/**
	 * Deserialize contact data
	 */
	virtual Kopete::Contact *deserializeContact( Kopete::MetaContact *metaContact,
		const QMap<QString, QString> &serializedData, const QMap<QString, QString> &addressBookData );

	virtual KopeteEditAccountWidget* createEditAccountWidget(Kopete::Account *account, QWidget *parent);

	virtual Kopete::Account* createNewAccount(const QString &accountId);

	virtual QPtrList<KAction> *customChatWindowPopupActions( const Kopete::Message &, DOM::Node & );

	static IRCProtocol *protocol();

	/**
	 * Maps the given IRC status to Kopete::OnlineStatus.
	 */
	const Kopete::OnlineStatus statusLookup( IRCStatus status ) const;

	const Kopete::OnlineStatus m_ServerStatusOnline;
	const Kopete::OnlineStatus m_ServerStatusOffline;

	const Kopete::OnlineStatus m_ChannelStatusOnline;
	const Kopete::OnlineStatus m_ChannelStatusOffline;

	const Kopete::OnlineStatus m_UserStatusOpVoice;
	const Kopete::OnlineStatus m_UserStatusOpVoiceAway;
	const Kopete::OnlineStatus m_UserStatusOp;
	const Kopete::OnlineStatus m_UserStatusOpAway;
	const Kopete::OnlineStatus m_UserStatusVoice;
	const Kopete::OnlineStatus m_UserStatusVoiceAway;
	const Kopete::OnlineStatus m_UserStatusOnline;
	const Kopete::OnlineStatus m_UserStatusAway;
	const Kopete::OnlineStatus m_UserStatusConnecting;
	const Kopete::OnlineStatus m_UserStatusOffline;

	const Kopete::OnlineStatus m_StatusUnknown;

	// irc channnel-contact properties
	const Kopete::ContactPropertyTmpl propChannelTopic;
	const Kopete::ContactPropertyTmpl propChannelMembers;
	const Kopete::ContactPropertyTmpl propHomepage;

	// irc user-contact properties
	const Kopete::ContactPropertyTmpl propLastSeen;
	const Kopete::ContactPropertyTmpl propUserInfo;
	const Kopete::ContactPropertyTmpl propServer;
	const Kopete::ContactPropertyTmpl propChannels;
	const Kopete::ContactPropertyTmpl propHops;
	const Kopete::ContactPropertyTmpl propFullName;
	const Kopete::ContactPropertyTmpl propIsIdentified;

	bool commandInProgress(){ return m_commandInProgress; }
	void setCommandInProgress( bool ip ) { m_commandInProgress = ip; }

	QDict<IRCNetwork> &networks(){ return m_networks; }
	void addNetwork( IRCNetwork *network );

	void editNetworks( const QString &networkName = QString::null );

signals:
	void networkConfigUpdated( const QString &selectedNetwork );

private slots:
	// FIXME: All the code for managing the networks list should be in another class - Will
	void slotUpdateNetworkConfig();
	void slotUpdateNetworkHostConfig();
	void slotMoveServerUp();
	void slotMoveServerDown();
	void slotSaveNetworkConfig();
	void slotReadNetworks();
	void slotDeleteNetwork();
	void slotDeleteHost();
	void slotNewNetwork();
	void slotRenameNetwork();
	void slotNewHost();
	void slotHostPortChanged( int value );
	// end of network list specific code

	void slotMessageFilter( Kopete::Message &msg );

	void slotRawCommand( const QString &args, Kopete::ChatSession *manager );
	void slotQuoteCommand( const QString &args, Kopete::ChatSession *manager );
	void slotCtcpCommand( const QString &args, Kopete::ChatSession *manager );
	void slotPingCommand( const QString &args, Kopete::ChatSession *manager );

	void slotMotdCommand( const QString &args, Kopete::ChatSession *manager);
	void slotListCommand( const QString &args, Kopete::ChatSession *manager);
	void slotTopicCommand( const QString &args, Kopete::ChatSession *manager);
	void slotJoinCommand( const QString &args, Kopete::ChatSession *manager);
	void slotNickCommand( const QString &args, Kopete::ChatSession *manager);
	void slotWhoisCommand( const QString &args, Kopete::ChatSession *manager);
	void slotWhoWasCommand( const QString &args, Kopete::ChatSession *manager);
	void slotWhoCommand( const QString &args, Kopete::ChatSession *manager);
	void slotMeCommand( const QString &args, Kopete::ChatSession *manager);
	void slotAllMeCommand( const QString &args, Kopete::ChatSession *manager);
	void slotModeCommand( const QString &args, Kopete::ChatSession *manager);
	void slotQueryCommand( const QString &args, Kopete::ChatSession *manager);

	void slotKickCommand( const QString &args, Kopete::ChatSession *manager);
	void slotBanCommand( const QString &args, Kopete::ChatSession *manager);
	void slotOpCommand( const QString &args, Kopete::ChatSession *manager);
	void slotDeopCommand( const QString &args, Kopete::ChatSession *manager);
	void slotVoiceCommand( const QString &args, Kopete::ChatSession *manager);
	void slotDevoiceCommand( const QString &args, Kopete::ChatSession *manager);
	void slotQuitCommand( const QString &args, Kopete::ChatSession *manager);
	void slotPartCommand( const QString &args, Kopete::ChatSession *manager);
	void slotInviteCommand( const QString &args, Kopete::ChatSession *manager);

	void slotViewCreated( KopeteView * );

private:
	static IRCProtocol *s_protocol;

	void simpleModeChange( const QString &, Kopete::ChatSession *, const QString &mode );

	// FIXME: All the code for managing the networks list should be in another class - Will
	void storeCurrentNetwork();
	void storeCurrentHost();

	NetworkConfig *netConf;
	QString m_uiCurrentNetworkSelection;
	QString m_uiCurrentHostSelection;
	// end of network list specific code

	DOM::Node activeNode;
	IRCAccount *activeAccount;

	bool m_commandInProgress;

	QDict<IRCNetwork> m_networks;
	QDict<IRCHost> m_hosts;
	IRCProtocolHandler *m_protocolHandler;
};

#endif

// vim: set noet ts=4 sts=4 sw=4: