/* * Copyright (C) 2008-2010 Manjeet Dahiya * * Author: * Manjeet Dahiya * * Source: * http://code.google.com/p/qxmpp * * This file is a part of QXmpp library. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * */ #ifndef QXMPPROSTER_H #define QXMPPROSTER_H #include #include #include #include #include "QXmppClient.h" class QXmppRosterIq; class QXmppPresence; /// \brief The QXmppRoster class provides access to a connected client's roster. /// /// \note It's object should not be created using it's constructor. Instead /// QXmppClient::getRoster() should be used to get the reference of instantiated /// object this class. /// /// It stores all the Roster and Presence details of all the roster entries (that /// is all the bareJids) in the client's friend's list. It provides the /// functionality to get all the bareJids in the client's roster and Roster and /// Presence details of the same. /// /// After the sucessfull xmpp connection that after the signal QXmppClient::connected() /// is emitted QXmpp requests for getting the roster. Once QXmpp receives the roster /// the signal QXmppRoster::rosterReceived() is emitted and after that user can /// use the functions of this class to get roster entries. /// /// Function QXmppRoster::isRosterReceived() tells whether the roster has been /// received or not. /// /// Signals presenceChanged() or rosterChanged() are emitted whenever presence /// or roster changes respectively. /// class QXmppRoster : public QObject { Q_OBJECT public: class QXmppRosterEntry { public: /// An enumeration for type of subscription with the bareJid in the roster. enum SubscriptionType { None = 1, ///< the user does not have a subscription to the ///< contact's presence information, and the contact does ///< not have a subscription to the user's presence information Both, ///< both the user and the contact have subscriptions to each ///< other's presence information From, ///< the contact has a subscription to the user's presence information, ///< but the user does not have a subscription to the contact's presence information To, ///< the user has a subscription to the contact's presence information, ///< but the contact does not have a subscription to the user's presence information Remove ///< to delete a roster item }; QString bareJid() const; QString name() const; QXmppRosterEntry::SubscriptionType subscriptionType() const; QString subscriptionStatus() const; QSet groups() const; void setBareJid(const QString&); void setName(const QString&); void setSubscriptionType(QXmppRosterEntry::SubscriptionType); void setSubscriptionStatus(const QString&); void setGroups(const QSet&); void addGroupEntry(const QString&); // deprecated accessors, use the form without "get" instead QString Q_DECL_DEPRECATED getBareJid() const; QString Q_DECL_DEPRECATED getName() const; QXmppRosterEntry::SubscriptionType Q_DECL_DEPRECATED getSubscriptionType() const; QString Q_DECL_DEPRECATED getSubscriptionStatus() const; QSet Q_DECL_DEPRECATED getGroups() const; private: QString m_bareJid; SubscriptionType m_type; QString m_name; // can be subscribe/unsubscribe (attribute "ask") QString m_subscriptionStatus; QSet m_groups; }; QXmppRoster(QXmppStream* stream); ~QXmppRoster(); bool isRosterReceived(); QStringList getRosterBareJids() const; QXmppRoster::QXmppRosterEntry getRosterEntry(const QString& bareJid) const; QMap Q_DECL_DEPRECATED getRosterEntries() const; QStringList getResources(const QString& bareJid) const; QMap > Q_DECL_DEPRECATED getAllPresences() const; QMap getAllPresencesForBareJid( const QString& bareJid) const; QXmppPresence getPresence(const QString& bareJid, const QString& resource) const; signals: /// This signal is emitted when the Roster IQ is received after a successful /// connection. void rosterReceived(); /// This signal is emitted when the presence of a particular bareJid and resource changes. void presenceChanged(const QString& bareJid, const QString& resource); /// This signal is emitted when the roster entry of a particular bareJid changes. void rosterChanged(const QString& bareJid); private: //reverse pointer to stream QXmppStream* m_stream; //map of bareJid and its rosterEntry QMap m_entries; // map of resources of the jid and map of resouces and presences QMap > m_presences; // flag to store that QXmppRoster has been populated bool m_isRosterReceived; private slots: void disconnected(); void presenceReceived(const QXmppPresence&); void rosterIqReceived(const QXmppRosterIq&); void rosterRequestIqReceived(const QXmppRosterIq&); }; #endif // QXMPPROSTER_H