aboutsummaryrefslogtreecommitdiff
path: root/src/QXmppRosterManager.h
blob: 6ceca4534892bdf8234b82d70d3c37574edea9a6 (plain) (blame)
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
/*
 * Copyright (C) 2008-2010 The QXmpp developers
 *
 * Authors:
 *  Manjeet Dahiya
 *  Jeremy Lainé
 *
 * 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 <QObject>
#include <QMap>
#include <QSet>
#include <QStringList>

#include "QXmppClientExtension.h"
#include "QXmppRosterIq.h"

class QXmppRosterIq;
class QXmppPresence;

/// \brief The QXmppRosterManager class provides access to a connected client's roster.
///
/// \note It's object should not be created using it's constructor. Instead
/// QXmppClient::rosterManager() 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 successful xmpp connection that after the signal QXmppClient::connected()
/// is emitted QXmpp requests for getting the roster. Once QXmpp receives the roster
/// the signal QXmppRosterManager::rosterReceived() is emitted and after that user can
/// use the functions of this class to get roster entries.
///
/// Function QXmppRosterManager::isRosterReceived() tells whether the roster has been
/// received or not.
///
/// Signals presenceChanged() or rosterChanged() are emitted whenever presence
/// or roster changes respectively.
///
/// \ingroup Managers

class QXmppRosterManager : public QXmppClientExtension
{
    Q_OBJECT

public:
    // FIXME : is this class really necessary?
    typedef QXmppRosterIq::Item QXmppRosterEntry;

    QXmppRosterManager(QXmppClient* stream);
    ~QXmppRosterManager();
    
    bool isRosterReceived();
    QStringList getRosterBareJids() const;
    QXmppRosterIq::Item getRosterEntry(const QString& bareJid) const;
    
    QStringList getResources(const QString& bareJid) const;
    QMap<QString, QXmppPresence> getAllPresencesForBareJid(
            const QString& bareJid) const;
    QXmppPresence getPresence(const QString& bareJid,
                              const QString& resource) const;

    /// \cond
    bool handleStanza(QXmppStream *stream, const QDomElement &element);
    /// \endcond

    // deprecated in release 0.2.0
    /// \cond
    QMap<QString, QXmppRosterIq::Item> Q_DECL_DEPRECATED getRosterEntries() const;
    QMap<QString, QMap<QString, QXmppPresence> > Q_DECL_DEPRECATED getAllPresences() const;
    /// \endcond

signals:
    /// This signal is emitted when the Roster IQ is received after a successful
    /// connection. That is the roster entries are empty before this signal is emitted.
    /// One should use getRosterBareJids() and getRosterEntry() only after 
    /// this signal has been emitted.
    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:
    //map of bareJid and its rosterEntry
    QMap<QString, QXmppRosterIq::Item> m_entries;
    // map of resources of the jid and map of resources and presences
    QMap<QString, QMap<QString, QXmppPresence> > m_presences;
    // flag to store that the roster has been populated
    bool m_isRosterReceived;
    // id of the initial roster request
    QString m_rosterReqId;

private slots:
    void connected();
    void disconnected();
    void presenceReceived(const QXmppPresence&);

private:
    void rosterIqReceived(const QXmppRosterIq&);
};

#endif // QXMPPROSTER_H