summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/jabber/jabbercontactpool.h
blob: 82bd634ef643b76e49089e57e3289704788f7088 (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
 /*
  * jabbercontactpool.h
  *
  * Copyright (c) 2004 by Till Gerken <till@tantalo.net>
  *
  * Kopete    (c) 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 JABBERCONTACTPOOL_H
#define JABBERCONTACTPOOL_H

#include <tqobject.h>
#include <im.h>

namespace Kopete { class MetaContact; }
namespace Kopete { class Contact; }
class JabberContactPoolItem;
class JabberBaseContact;
class JabberContact;
class JabberGroupContact;
class JabberAccount;
class JabberTransport;

/**
 * @author Till Gerken <till@tantalo.net>
 */
class JabberContactPool : public TQObject
{

TQ_OBJECT
  

public:
	/**
	 * Default constructor
	 */
	JabberContactPool ( JabberAccount *account );

	/**
	 * Default destructor
	 */
	~JabberContactPool();

	/**
	 * Add a contact to the pool
	 */
	JabberContact *addContact ( const XMPP::RosterItem &contact, Kopete::MetaContact *metaContact, bool dirty = true  );
	JabberBaseContact *addGroupContact ( const XMPP::RosterItem &contact, bool roomContact, Kopete::MetaContact *metaContact, bool dirty = true );

	/**
	 * Remove a contact from the pool
	 */
	void removeContact ( const XMPP::Jid &jid );

	/**
	 * Remove all contacts from the pool
	 */
	void clear ();

	/**
	 * Sets the "dirty" flag for a certain contact
	 */
	void setDirty ( const XMPP::Jid &jid, bool dirty );

	/**
	 * Remove all dirty elements from the pool
	 * (used after connecting to delete removed items from the roster)
	 */
	void cleanUp ();

	/**
	 * Find an exact match in the pool by full JID.
	 */
	JabberBaseContact *findExactMatch ( const XMPP::Jid &jid );

	/**
	 * Find a relevant recipient for a given JID.
	 * This will match user@domain for a given user@domain/resource,
	 * but NOT user@domain/resource for a given user@domain.
	 */
	JabberBaseContact *findRelevantRecipient ( const XMPP::Jid &jid );

	/**
	 * Find relevant sources for a given JID.
	 * This will match user@domain/resource for a given user@domain.
	 */
	TQPtrList<JabberBaseContact> findRelevantSources ( const XMPP::Jid &jid );

private slots:
	void slotContactDestroyed ( Kopete::Contact *contact );

private:
	JabberContactPoolItem *findPoolItem ( const XMPP::RosterItem &contact );

	TQPtrList<JabberContactPoolItem> mPool;
	JabberAccount *mAccount;

};

class JabberContactPoolItem : TQObject
{
TQ_OBJECT
  
public:
	JabberContactPoolItem ( JabberBaseContact *contact );
	~JabberContactPoolItem ();

	void setDirty ( bool dirty );
	bool dirty ();
	JabberBaseContact *contact ();

private:
	bool mDirty;
	JabberBaseContact *mContact;
};

#endif