summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/irc/irccontactmanager.h
blob: 0a0f558b4b16d3c0e441039eaf66a148399c26e7 (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
/*
    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 <tqdict.h>
#include <tqobject.h>
#include <tqstring.h>
#include <tqstringlist.h>

class IRCContact;
class IRCAccount;

class IRCServerContact;
class IRCChannelContact;
class IRCUserContact;

namespace KIRC
{
class Engine;
}

namespace Kopete
{
class Contact;
class MetaContact;
}

class KopeteView;

class TQTimer;

/**
 * @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 TQObject
{
	Q_OBJECT
  TQ_OBJECT

	public:
		IRCContactManager(const TQString &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 TQString &channel, Kopete::MetaContact *m=0);
		IRCChannelContact *existChannel(const TQString &channel) const;

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

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

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

		static IRCContact *existContact(const KIRC::Engine *engine, const TQString &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 TQString &nick);
		void removeFromNotifyList(const TQString &nick);
		void checkOnlineNotifyList();

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

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

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

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

		TQStringList m_NotifyList;
		TQTimer *m_NotifyTimer;
		bool isonRecieved;
		int socketTimeout;

		static const TQRegExp isChannel;
};

#endif