File indexing completed on 2024-04-14 04:01:47

0001  /*
0002   * jabberresourcepool.h
0003   *
0004   * Copyright (c) 2004 by Till Gerken <till@tantalo.net>
0005   * Copyright (c) 2006 by Michaël Larouche <larouche@kde.org>
0006   *
0007   * Kopete    (c) by the Kopete developers  <kopete-devel@kde.org>
0008   *
0009   * *************************************************************************
0010   * *                                                                       *
0011   * * This program is free software; you can redistribute it and/or modify  *
0012   * * it under the terms of the GNU General Public License as published by  *
0013   * * the Free Software Foundation; either either version 2
0014    of the License, or (at your option) any later version.of the License, or     *
0015   * * (at your option) any later version.                                   *
0016   * *                                                                       *
0017   * *************************************************************************
0018   */
0019 
0020 #ifndef JABBERRESOURCEPOOL_H
0021 #define JABBERRESOURCEPOOL_H
0022 
0023 #include <QObject>
0024 #include <QList>
0025 #include <im.h>
0026 
0027 class JabberResource;
0028 class JabberAccount;
0029 
0030 /**
0031  * @author Till Gerken <till@tantalo.net>
0032  * @author Michaël Larouche <larouche@kde.org>
0033  */
0034 class JabberResourcePool : public QObject
0035 {
0036     Q_OBJECT
0037 public:
0038     static XMPP::Resource EmptyResource;
0039 
0040     typedef QList<JabberResource*> ResourceList;
0041 
0042     /**
0043      * Default constructor
0044      */
0045     JabberResourcePool ( JabberAccount *account );
0046 
0047     /**
0048      * Default destructor
0049      */
0050     ~JabberResourcePool();
0051 
0052     /**
0053      * Notify all relevant contacts in case
0054      * a resource has been added, updated or removed.
0055      */
0056     void notifyRelevantContacts ( const XMPP::Jid &jid );
0057 
0058     /**
0059      * Add a resource to the pool
0060      */
0061     void addResource ( const XMPP::Jid &jid, const XMPP::Resource &resource );
0062 
0063     /**
0064      * Remove a resource from the pool
0065      */
0066     void removeResource ( const XMPP::Jid &jid, const XMPP::Resource &resource );
0067 
0068     /**
0069      * Remove all resources for a given address from the pool
0070      * NOTE: Since this method is mainly used for housekeeping,
0071      *       it does NOT notify any contacts.
0072      */
0073     void removeAllResources ( const XMPP::Jid &jid );
0074 
0075     /**
0076      * Remove all resources from the pool
0077      */
0078     void clear ();
0079 
0080     /**
0081      * Lock to a certain resource
0082      */
0083     void lockToResource ( const XMPP::Jid &jid, const XMPP::Resource &resource );
0084 
0085     /**
0086      * Remove a resource lock
0087      */
0088     void removeLock ( const XMPP::Jid &jid );
0089 
0090     /**
0091      * Return the JabberResource instance for the locked resource, if any.
0092      */
0093      JabberResource *lockedJabberResource( const XMPP::Jid &jid );
0094 
0095     /**
0096      * Return currently locked resource, if any
0097      */
0098     const XMPP::Resource &lockedResource ( const XMPP::Jid &jid );
0099 
0100     /**
0101      * Return a usable JabberResource for a given JID.
0102      *
0103      * @param jid Jid to look for the best resource.
0104      * @param honourLock Honour the resource locked by the user.
0105      * 
0106      * @return a JabberResource instance.
0107      */
0108     JabberResource *bestJabberResource( const XMPP::Jid &jid, bool honourLock = true );
0109 
0110     /**
0111      * Return usable resource for a given JID
0112      * Matches by userHost(), honors locks for a JID by default
0113      */
0114     const XMPP::Resource &bestResource ( const XMPP::Jid &jid, bool honourLock = true );
0115 
0116     /**
0117      * Find all resources that exist for a given JID
0118      */
0119     void findResources ( const XMPP::Jid &jid, JabberResourcePool::ResourceList &resourceList );
0120     void findResources ( const XMPP::Jid &jid, XMPP::ResourceList &resourceList );
0121     
0122 private slots:
0123     void slotResourceDestroyed ( QObject *sender );
0124     void slotResourceUpdated ( JabberResource *resource );
0125     
0126 private:
0127     class Private;
0128     Private *d;
0129 };
0130 
0131 #endif