gloox  1.0.9
privacymanager.h
1 /*
2  Copyright (c) 2005-2013 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 PRIVACYMANAGER_H__
15 #define PRIVACYMANAGER_H__
16 
17 #include "iqhandler.h"
18 #include "privacylisthandler.h"
19 #include "stanzaextension.h"
20 
21 #include <string>
22 
23 namespace gloox
24 {
25 
26  class ClientBase;
27 
34  class GLOOX_API PrivacyManager : public IqHandler
35  {
36  public:
41  PrivacyManager( ClientBase* parent );
42 
46  virtual ~PrivacyManager();
47 
54  std::string store( const std::string& name, const PrivacyListHandler::PrivacyList& list );
55 
59  std::string requestListNames()
60  { return operation( PLRequestNames, EmptyString ); }
61 
66  std::string requestList( const std::string& name )
67  { return operation( PLRequestList, name ); }
68 
73  std::string removeList( const std::string& name )
74  { return operation( PLRemove, name ); }
75 
80  std::string setDefault( const std::string& name )
81  { return operation( PLDefault, name ); }
82 
86  std::string unsetDefault()
87  { return operation( PLUnsetDefault, EmptyString ); }
88 
93  std::string setActive( const std::string& name )
94  { return operation( PLActivate, name ); }
95 
99  std::string unsetActive()
100  { return operation( PLUnsetActivate, EmptyString ); }
101 
107  void registerPrivacyListHandler( PrivacyListHandler* plh )
108  { m_privacyListHandler = plh; }
109 
113  void removePrivacyListHandler()
114  { m_privacyListHandler = 0; }
115 
116  // reimplemented from IqHandler.
117  virtual bool handleIq( const IQ& iq );
118 
119  // reimplemented from IqHandler.
120  virtual void handleIqID( const IQ& iq, int context );
121 
122  private:
123  enum IdType
124  {
125  PLRequestNames,
126  PLRequestList,
127  PLActivate,
128  PLDefault,
129  PLUnsetActivate,
130  PLUnsetDefault,
131  PLRemove,
132  PLStore
133  };
134 
135  class Query : public StanzaExtension
136  {
137  public:
145  Query( IdType context, const std::string& name,
147 
152  Query( const Tag* tag = 0 );
153 
157  virtual ~Query();
158 
163  const std::string& active() const { return m_active; }
164 
169  const std::string& def() const { return m_default; }
170 
175  const PrivacyListHandler::PrivacyList& items() const
176  { return m_items; }
177 
182  const StringList& names() const { return m_names; }
183 
189  const std::string& name() const
190  {
191  if( m_names.empty())
192  return EmptyString;
193  else
194  return (*m_names.begin());
195  }
196 
197  // reimplemented from StanzaExtension
198  virtual const std::string& filterString() const;
199 
200  // reimplemented from StanzaExtension
201  virtual StanzaExtension* newInstance( const Tag* tag ) const
202  {
203  return new Query( tag );
204  }
205 
206  // reimplemented from StanzaExtension
207  virtual Tag* tag() const;
208 
209  // reimplemented from StanzaExtension
210  virtual StanzaExtension* clone() const
211  {
212  return new Query( *this );
213  }
214 
215  private:
216  IdType m_context;
217  StringList m_names;
218  std::string m_default;
219  std::string m_active;
221  };
222 
223  std::string operation( IdType context, const std::string& name );
224 
225  ClientBase* m_parent;
226  PrivacyListHandler* m_privacyListHandler;
227  };
228 
229 }
230 
231 #endif // PRIVACYMANAGER_H__