summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/irc/irccontactmanager.h
blob: 4a8ae05fdaa9bea2b227e2ae4eca0b5ad70bab87 (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
/*
    irccontactmanager.h - Manager of IRC Contacts

    Copyright (c) 2003      by Michel Hermier <michel.hermier@wanadoo.fr>

    Kopete    (c) 2003      by the Kopete developers <kopete-devel@kde.org>

    *************************************************************************
    *                                                                       *
    * 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 IRCCONTACTMANAGER_H
#define IRCCONTACTMANAGER_H

#include <qdict.h>
#include <qobject.h>
#include <qstring.h>
#include <qstringlist.h>

class IRCContact;
class IRCAccount;

class IRCServerContact;
class IRCChannelContact;
class IRCUserContact;

namespace KIRC
{
class Engine;
}

namespace Kopete
{
class Contact;
class MetaContact;
}

class KopeteView;

class QTimer;

/**
 * @author Michel Hermier <michel.hermier@wanadoo.fr>
 *
 * This class is the repository for all the reference of the @ref IRCContact childs.
 * It manage the life cycle of all the @ref IRCServerContact, @ref IRCChannelContact and @ref IRCUserContact objects for the given account.
 */
class IRCContactManager
	: public QObject
{
	Q_OBJECT

	public:
		IRCContactManager(const QString &nickName, IRCAccount *account, const char *name=0);

		IRCAccount *account() const { return m_account; }

		IRCServerContact *myServer() const { return m_myServer; }
		IRCUserContact *mySelf() const { return m_mySelf; }

		IRCChannelContact *findChannel(const QString &channel, Kopete::MetaContact *m=0);
		IRCChannelContact *existChannel(const QString &channel) const;

		IRCUserContact *findUser(const QString &nick, Kopete::MetaContact *m=0);
		IRCUserContact *existUser(const QString &nick) const;

		IRCContact *findContact(const QString &nick, Kopete::MetaContact *m=0);
		IRCContact *existContact( const QString &id ) const;

		QValueList<IRCChannelContact*> findChannelsByMember( IRCUserContact *contact );

		static IRCContact *existContact(const KIRC::Engine *engine, const QString &nick);

	public slots:
		void unregister(Kopete::Contact *contact);
		void unregisterUser(Kopete::Contact *contact, bool force = false );
		void unregisterChannel(Kopete::Contact *contact, bool force = false );

		void addToNotifyList(const QString &nick);
		void removeFromNotifyList(const QString &nick);
		void checkOnlineNotifyList();

	signals:
		void privateMessage(IRCContact *from, IRCContact *to, const QString &message);

	private slots:
		void slotNewMessage(const QString &originating, const QString &channel, const QString &message);
		void slotNewPrivMessage(const QString &originating, const QString &, const QString &message);
		void slotIsonRecieved();
		void slotIsonTimeout();
		void slotNewNickChange(const QString &oldnick, const QString &newnick);
		void slotContactAdded( Kopete::MetaContact *contact );

	private:
		QDict<IRCChannelContact> m_channels;
		QDict<IRCUserContact> m_users;

		IRCAccount *m_account;
		IRCServerContact *m_myServer;
		IRCUserContact *m_mySelf;

		QStringList m_NotifyList;
		QTimer *m_NotifyTimer;
		bool isonRecieved;
		int socketTimeout;

		static const QRegExp isChannel;
};

#endif