1
by Vsevolod Velichko
Import upstream version 1.1.0 |
1 |
/****************************************************************************
|
2 |
**
|
|
3 |
** Jreen
|
|
4 |
**
|
|
5 |
** Copyright © 2011 Ruslan Nigmatullin <euroelessar@yandex.ru>
|
|
6 |
**
|
|
7 |
*****************************************************************************
|
|
8 |
**
|
|
9 |
** $JREEN_BEGIN_LICENSE$
|
|
10 |
** This program is free software: you can redistribute it and/or modify
|
|
11 |
** it under the terms of the GNU General Public License as published by
|
|
12 |
** the Free Software Foundation, either version 2 of the License, or
|
|
13 |
** (at your option) any later version.
|
|
14 |
**
|
|
15 |
** This program is distributed in the hope that it will be useful,
|
|
16 |
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
18 |
** See the GNU General Public License for more details.
|
|
19 |
**
|
|
20 |
** You should have received a copy of the GNU General Public License
|
|
21 |
** along with this program. If not, see http://www.gnu.org/licenses/.
|
|
22 |
** $JREEN_END_LICENSE$
|
|
23 |
**
|
|
24 |
****************************************************************************/
|
|
25 |
||
26 |
// TODO: Create simple RosterManager for bots and simple applications
|
|
27 |
||
28 |
#ifndef ABSTRACTROSTER_H
|
|
29 |
#define ABSTRACTROSTER_H
|
|
30 |
||
31 |
#include <QSharedPointer> |
|
32 |
||
33 |
#if QT_VERSION < QT_VERSION_CHECK(4, 7, 0)
|
|
34 |
// Looks like this function was overloaded at this release, if not - tell me // EuroElessar
|
|
35 |
template <class T> inline uint qHash(const T *key); |
|
36 |
template<typename T> |
|
37 |
inline uint qHash(const QSharedPointer<T> &key) { return qHash(key.data()); } |
|
38 |
#endif
|
|
39 |
||
40 |
#include "stanzaextension.h" |
|
41 |
#include "presence.h" |
|
42 |
#include "langmap.h" |
|
43 |
#include "jid.h" |
|
44 |
#include <QStringList> |
|
45 |
#include <QHash> |
|
46 |
#include <QSet> |
|
47 |
||
48 |
namespace Jreen |
|
49 |
{
|
|
50 |
||
51 |
class Client; |
|
52 |
class IQ; |
|
53 |
class Presence; |
|
54 |
class AbstractRoster; |
|
55 |
class AbstractRosterPrivate; |
|
56 |
class SimpleRosterPrivate; |
|
57 |
class RosterItem; |
|
58 |
class RosterItemPrivate; |
|
59 |
class AbstractRosterQuery; |
|
60 |
||
61 |
class JREEN_AUTOTEST_EXPORT ItemFactory : public XmlStreamFactory<RosterItem> |
|
62 |
{
|
|
63 |
public: |
|
64 |
};
|
|
65 |
||
66 |
enum AbstractRosterIqContext |
|
67 |
{
|
|
68 |
SyncContext, |
|
69 |
LoadRoster, |
|
70 |
AddRosterItem, |
|
71 |
RemoveRosterItem
|
|
72 |
};
|
|
73 |
||
74 |
class RosterItemPrivate; |
|
75 |
||
76 |
class JREEN_EXPORT RosterItem |
|
77 |
{
|
|
78 |
Q_DECLARE_PRIVATE(RosterItem) |
|
79 |
friend class AbstractRoster; |
|
80 |
public: |
|
81 |
enum SubscriptionType |
|
82 |
{
|
|
83 |
From, |
|
84 |
To, |
|
85 |
Both, |
|
86 |
Remove, |
|
87 |
None, |
|
88 |
Invalid = -1 |
|
89 |
};
|
|
90 |
typedef QSharedPointer<RosterItem> Ptr; |
|
91 |
RosterItem(const QString &jid, const QString &name, |
|
92 |
const QStringList &groups, SubscriptionType s10n); |
|
93 |
RosterItem(AbstractRoster *roster, RosterItemPrivate *data = 0); |
|
94 |
virtual ~RosterItem(); |
|
95 |
QString jid() const; |
|
96 |
QString name() const; |
|
97 |
QStringList groups() const; |
|
98 |
SubscriptionType subscription() const; |
|
99 |
QString ask() const; |
|
100 |
void setGroups(const QStringList &groups); |
|
101 |
void setName(const QString &name); |
|
102 |
protected: |
|
103 |
virtual void setData(const QSharedPointer<RosterItem> &item); |
|
104 |
void setChanged(); |
|
105 |
QScopedPointer<RosterItemPrivate> d_ptr; |
|
106 |
};
|
|
107 |
||
108 |
class JREEN_EXPORT AbstractRoster : public QObject |
|
109 |
{
|
|
110 |
Q_OBJECT
|
|
111 |
Q_DECLARE_PRIVATE(AbstractRoster) |
|
112 |
public: |
|
113 |
AbstractRoster(Client *client, AbstractRosterPrivate *data = 0); |
|
114 |
virtual ~AbstractRoster(); |
|
115 |
||
116 |
QString version() const; |
|
117 |
RosterItem::Ptr item(const JID &jid) const; |
|
118 |
RosterItem::Ptr selfItem() const; |
|
119 |
void fillRoster(const QString &version, const QList<RosterItem::Ptr> &items); |
|
120 |
public slots: |
|
121 |
virtual void load(); |
|
122 |
virtual void synchronize(); |
|
123 |
protected: |
|
124 |
virtual QSharedPointer<RosterItem> createItem(); |
|
125 |
virtual void init(); |
|
126 |
virtual void add(const JID &jid, const QString &name = QString(), const QStringList &groups = QStringList()); |
|
127 |
virtual void remove(const JID &jid); |
|
128 |
signals: |
|
129 |
void loaded(); |
|
130 |
protected slots: |
|
131 |
virtual void handleIQ(const Jreen::IQ &iq); |
|
132 |
virtual void handleIQ(const Jreen::IQ &iq, int context); |
|
133 |
protected: |
|
134 |
virtual void onItemAdded(QSharedPointer<RosterItem> item); |
|
135 |
virtual void onItemUpdated(QSharedPointer<RosterItem> item); |
|
136 |
virtual void onItemRemoved(const QString &jid); |
|
137 |
virtual void onLoaded(const QList<QSharedPointer<RosterItem> > &items); |
|
138 |
QScopedPointer<AbstractRosterPrivate> d_ptr; |
|
139 |
friend class AbstractRosterQuery; |
|
140 |
friend class JREEN_AUTOTEST_EXPORT AbstractRosterQueryFactory; |
|
141 |
friend class RosterItem; |
|
142 |
};
|
|
143 |
||
144 |
class JREEN_EXPORT SimpleRoster : public AbstractRoster |
|
145 |
{
|
|
146 |
Q_OBJECT
|
|
147 |
Q_DECLARE_PRIVATE(SimpleRoster) |
|
148 |
public: |
|
149 |
SimpleRoster(Client *client, SimpleRosterPrivate *data = 0); |
|
150 |
virtual ~SimpleRoster(); |
|
151 |
||
152 |
void subscribe(const JID &jid, const QString &msg, const QString &name, const QStringList &groups); |
|
153 |
void subscribe(const JID &jid, const QString &msg = QString()); |
|
154 |
void unsubscribe(const JID &jid, const QString &msg = QString()); |
|
155 |
void allowSubscription(const JID &jid, bool ok); |
|
156 |
using AbstractRoster::add; |
|
157 |
using AbstractRoster::remove; |
|
158 |
signals: |
|
159 |
void itemAdded(const RosterItem::Ptr &item); |
|
160 |
void itemUpdated(const RosterItem::Ptr &item); |
|
161 |
void itemRemoved(const QString &jid); |
|
162 |
void presenceReceived(const Jreen::RosterItem::Ptr &item, const Jreen::Presence &presence); |
|
163 |
void subscriptionReceived(const Jreen::RosterItem::Ptr &item, const Jreen::Presence &presence); |
|
164 |
protected slots: |
|
165 |
void onPresenceReceived(const Jreen::Presence &presence); |
|
166 |
protected: |
|
167 |
virtual void onItemAdded(QSharedPointer<RosterItem> item); |
|
168 |
virtual void onItemUpdated(QSharedPointer<RosterItem> item); |
|
169 |
virtual void onItemRemoved(const QString &jid); |
|
170 |
};
|
|
171 |
||
172 |
}
|
|
173 |
||
174 |
#endif // ABSTRACTROSTER_H |