gloox  0.9.9.12
rostermanager.h
1 /*
2  Copyright (c) 2004-2008 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #ifndef ROSTERMANAGER_H__
15 #define ROSTERMANAGER_H__
16 
17 #include "subscriptionhandler.h"
18 #include "privatexmlhandler.h"
19 #include "iqhandler.h"
20 #include "presencehandler.h"
21 #include "rosterlistener.h"
22 
23 #include <map>
24 #include <string>
25 #include <list>
26 
27 namespace gloox
28 {
29 
30  class ClientBase;
31  class Stanza;
32  class PrivateXML;
33  class RosterItem;
34 
47  class GLOOX_API RosterManager : public IqHandler, public PresenceHandler, public SubscriptionHandler,
48  public PrivateXMLHandler
49  {
50  public:
55  RosterManager( ClientBase *parent );
56 
60  virtual ~RosterManager();
61 
66  void fill();
67 
72  Roster* roster();
73 
82  void subscribe( const JID& jid, const std::string& name = "", const StringList& groups = StringList(),
83  const std::string& msg = "" );
84 
88  void synchronize();
89 
97  void add( const JID& jid, const std::string& name, const StringList& groups );
98 
107  void unsubscribe( const JID& jid, const std::string& msg = "" );
108 
117  void cancel( const JID& jid, const std::string& msg = "" );
118 
125  void remove( const JID& jid );
126 
133  void ackSubscriptionRequest( const JID& to, bool ack );
134 
140  const std::string& delimiter() const { return m_delimiter; }
141 
147  void setDelimiter( const std::string& delimiter );
148 
153  RosterItem* getRosterItem( const JID& jid );
154 
164  void registerRosterListener( RosterListener *rl, bool syncSubscribeReq = true );
165 
170  void removeRosterListener();
171 
172  // reimplemented from IqHandler.
173  virtual bool handleIq( Stanza *stanza );
174 
175  // reimplemented from IqHandler.
176  virtual bool handleIqID( Stanza *stanza, int context );
177 
178  // reimplemented from PresenceHandler.
179  virtual void handlePresence( Stanza *stanza );
180 
181  // reimplemented from SubscriptionHandler.
182  virtual void handleSubscription( Stanza *stanza );
183 
184  // reimplemented from PrivateXMLHandler
185  virtual void handlePrivateXML( const std::string& tag, Tag *xml );
186 
187  // reimplemented from PrivateXMLHandler
188  virtual void handlePrivateXMLResult( const std::string& uid, PrivateXMLResult pxResult );
189 
190  private:
191  void add( const std::string& jid, const std::string& name,
192  const StringList& groups, const StringList& caps, const std::string& sub, bool ask );
193  void extractItems( Tag *tag, bool isPush );
194 
195  RosterListener *m_rosterListener;
196  Roster m_roster;
197  ClientBase *m_parent;
198  PrivateXML *m_privateXML;
199  RosterItem *m_self;
200 
201  std::string m_delimiter;
202  bool m_syncSubscribeReq;
203 
204  };
205 
206 }
207 
208 #endif // ROSTER_H__