privacymanager.h

00001 /*
00002   Copyright (c) 2005-2009 by Jakob Schroeter <js@camaya.net>
00003   This file is part of the gloox library. http://camaya.net/gloox
00004 
00005   This software is distributed under a license. The full license
00006   agreement can be found in the file LICENSE in this distribution.
00007   This software may not be copied, modified, sold or distributed
00008   other than expressed in the named license agreement.
00009 
00010   This software is distributed without any warranty.
00011 */
00012 
00013 
00014 #ifndef PRIVACYMANAGER_H__
00015 #define PRIVACYMANAGER_H__
00016 
00017 #include "iqhandler.h"
00018 #include "privacylisthandler.h"
00019 #include "stanzaextension.h"
00020 
00021 #include <string>
00022 
00023 namespace gloox
00024 {
00025 
00026   class ClientBase;
00027 
00034   class GLOOX_API PrivacyManager : public IqHandler
00035   {
00036     public:
00041       PrivacyManager( ClientBase* parent );
00042 
00046       virtual ~PrivacyManager();
00047 
00054       std::string store( const std::string& name, const PrivacyListHandler::PrivacyList& list );
00055 
00059       std::string requestListNames()
00060         { return operation( PLRequestNames, EmptyString ); }
00061 
00066       std::string requestList( const std::string& name )
00067         { return operation( PLRequestList, name ); }
00068 
00073       std::string removeList( const std::string& name )
00074         { return operation( PLRemove, name ); }
00075 
00080       std::string setDefault( const std::string& name )
00081         { return operation( PLDefault, name ); }
00082 
00086       std::string unsetDefault()
00087         { return operation( PLUnsetDefault, EmptyString ); }
00088 
00093       std::string setActive( const std::string& name )
00094         { return operation( PLActivate, name ); }
00095 
00099       std::string unsetActive()
00100         { return operation( PLUnsetActivate, EmptyString ); }
00101 
00107       void registerPrivacyListHandler( PrivacyListHandler* plh )
00108         { m_privacyListHandler = plh; }
00109 
00113       void removePrivacyListHandler()
00114         { m_privacyListHandler = 0; }
00115 
00116       // reimplemented from IqHandler.
00117       virtual bool handleIq( const IQ& iq );
00118 
00119       // reimplemented from IqHandler.
00120       virtual void handleIqID( const IQ& iq, int context );
00121 
00122     private:
00123       enum IdType
00124       {
00125         PLRequestNames,
00126         PLRequestList,
00127         PLActivate,
00128         PLDefault,
00129         PLUnsetActivate,
00130         PLUnsetDefault,
00131         PLRemove,
00132         PLStore
00133       };
00134 
00135       class Query : public StanzaExtension
00136       {
00137         public:
00145           Query( IdType context, const std::string& name,
00146                  const PrivacyListHandler::PrivacyList& list = PrivacyListHandler::PrivacyList() );
00147 
00152           Query( const Tag* tag = 0 );
00153 
00157           virtual ~Query();
00158 
00163           const std::string& active() const { return m_active; }
00164 
00169           const std::string& def() const { return m_default; }
00170 
00175           const PrivacyListHandler::PrivacyList& items() const
00176             { return m_items; }
00177 
00182           const StringList& names() const { return m_names; }
00183 
00189           const std::string& name() const
00190           {
00191             if( m_names.empty())
00192               return EmptyString;
00193             else
00194               return (*m_names.begin());
00195           }
00196 
00197           // reimplemented from StanzaExtension
00198           virtual const std::string& filterString() const;
00199 
00200           // reimplemented from StanzaExtension
00201           virtual StanzaExtension* newInstance( const Tag* tag ) const
00202           {
00203             return new Query( tag );
00204           }
00205 
00206           // reimplemented from StanzaExtension
00207           virtual Tag* tag() const;
00208 
00209           // reimplemented from StanzaExtension
00210           virtual StanzaExtension* clone() const
00211           {
00212             return new Query( *this );
00213           }
00214 
00215         private:
00216           IdType m_context;
00217           StringList m_names;
00218           std::string m_default;
00219           std::string m_active;
00220           PrivacyListHandler::PrivacyList m_items;
00221       };
00222 
00223       std::string operation( IdType context, const std::string& name );
00224 
00225       ClientBase* m_parent;
00226       PrivacyListHandler* m_privacyListHandler;
00227   };
00228 
00229 }
00230 
00231 #endif // PRIVACYMANAGER_H__

Generated by  doxygen 1.6.2