1  /*
2   * jabberresourcepool.h
3   *
4   * Copyright (c) 2004 by Till Gerken <till@tantalo.net>
5   * Copyright (c) 2006 by Michaël Larouche <larouche@kde.org>
6   *
7   * Kopete    (c) by the Kopete developers  <kopete-devel@kde.org>
8   *
9   * *************************************************************************
10   * *                                                                       *
11   * * This program is free software; you can redistribute it and/or modify  *
12   * * it under the terms of the GNU General Public License as published by  *
13   * * the Free Software Foundation; either version 2 of the License, or     *
14   * * (at your option) any later version.                                   *
15   * *                                                                       *
16   * *************************************************************************
17   */
18 
19 #ifndef JABBERRESOURCEPOOL_H
20 #define JABBERRESOURCEPOOL_H
21 
22 #include <qobject.h>
23 #include <QList>
24 #include <im.h>
25 
26 class JabberResource;
27 class JabberAccount;
28 
29 /**
30  * @author Till Gerken <till@tantalo.net>
31  * @author Michaël Larouche <larouche@kde.org>
32  */
33 class JabberResourcePool : public QObject
34 {
35 	Q_OBJECT
36 public:
37 	static XMPP::Resource EmptyResource;
38 
39 	typedef QList<JabberResource*> ResourceList;
40 
41 	/**
42 	 * Default constructor
43 	 */
44 	JabberResourcePool ( JabberAccount *account );
45 
46 	/**
47 	 * Default destructor
48 	 */
49 	~JabberResourcePool();
50 
51 	/**
52 	 * Notify all relevant contacts in case
53 	 * a resource has been added, updated or removed.
54 	 */
55 	void notifyRelevantContacts ( const XMPP::Jid &jid );
56 
57 	/**
58 	 * Add a resource to the pool
59 	 */
60 	void addResource ( const XMPP::Jid &jid, const XMPP::Resource &resource );
61 
62 	/**
63 	 * Remove a resource from the pool
64 	 */
65 	void removeResource ( const XMPP::Jid &jid, const XMPP::Resource &resource );
66 
67 	/**
68 	 * Remove all resources for a given address from the pool
69 	 * NOTE: Since this method is mainly used for housekeeping,
70 	 *       it does NOT notify any contacts.
71 	 */
72 	void removeAllResources ( const XMPP::Jid &jid );
73 
74 	/**
75 	 * Remove all resources from the pool
76 	 */
77 	void clear ();
78 
79 	/**
80 	 * Lock to a certain resource
81 	 */
82 	void lockToResource ( const XMPP::Jid &jid, const XMPP::Resource &resource );
83 
84 	/**
85 	 * Remove a resource lock
86 	 */
87 	void removeLock ( const XMPP::Jid &jid );
88 
89 	/**
90 	 * Return the JabberResource instance for the locked resource, if any.
91 	 */
92 	 JabberResource *lockedJabberResource( const XMPP::Jid &jid );
93 
94 	/**
95 	 * Return currently locked resource, if any
96 	 */
97 	const XMPP::Resource &lockedResource ( const XMPP::Jid &jid );
98 
99 	/**
100 	 * Return a usable JabberResource for a given JID.
101 	 *
102 	 * @param jid Jid to look for the best resource.
103 	 * @param honourLock Honour the resource locked by the user.
104 	 *
105 	 * @return a JabberResource instance.
106 	 */
107 	JabberResource *bestJabberResource( const XMPP::Jid &jid, bool honourLock = true );
108 
109 	/**
110 	 * Return usable resource for a given JID
111 	 * Matches by bare() (userHost), honors locks for a JID by default
112 	 */
113 	const XMPP::Resource &bestResource ( const XMPP::Jid &jid, bool honourLock = true );
114 
115 	/*
116 	 * Return a JabberResource for a given JID and resource name
117 	 * If resource name is empty or not exists, return bestJabberResource
118 	 */
119 	JabberResource *getJabberResource ( const XMPP::Jid &jid, const QString &resource );
120 
121 	/**
122 	 * Find all resources that exist for a given JID
123 	 */
124 	void findResources ( const XMPP::Jid &jid, JabberResourcePool::ResourceList &resourceList );
125 	void findResources ( const XMPP::Jid &jid, XMPP::ResourceList &resourceList );
126 
127 private Q_SLOTS:
128 	void slotResourceDestroyed ( QObject *sender );
129 	void slotResourceUpdated ( JabberResource *resource );
130 
131 private:
132 	class Private;
133 	Private * const d;
134 };
135 
136 #endif
137