gloox  1.0
searchhandler.h
00001 /*
00002   Copyright (c) 2006-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 SEARCHHANDLER_H__
00015 #define SEARCHHANDLER_H__
00016 
00017 #include "stanza.h"
00018 
00019 #include <string>
00020 
00021 namespace gloox
00022 {
00023 
00024   class DataForm;
00025 
00033   class SearchFieldStruct
00034   {
00035     public:
00039       SearchFieldStruct() {}
00040 
00044       SearchFieldStruct( const std::string& first, const std::string& last, const std::string& nick,
00045                          const std::string& email )
00046         : m_first( first ), m_last( last ), m_nick( nick ), m_email( email )
00047       {}
00048 
00052       SearchFieldStruct( const Tag* tag )
00053       {
00054         if( !tag || tag->name() != "item" || !tag->hasAttribute( "jid" ) )
00055           return;
00056 
00057         m_jid.setJID( tag->findAttribute( "jid" ) );
00058         const TagList& l = tag->children();
00059         TagList::const_iterator it = l.begin();
00060         for( ; it != l.end(); ++it )
00061         {
00062           if( (*it)->name() == "first" )
00063             m_first = (*it)->cdata();
00064           else if( (*it)->name() == "last" )
00065             m_last = (*it)->cdata();
00066           else if( (*it)->name() == "email" )
00067             m_email = (*it)->cdata();
00068           else if( (*it)->name() == "nick" )
00069             m_nick = (*it)->cdata();
00070         }
00071       }
00072 
00076       ~SearchFieldStruct() {}
00077 
00081       const std::string first() const { return m_first; }
00082 
00086       const std::string last() const { return m_last; }
00087 
00091       const std::string email() const { return m_email; }
00092 
00096       const std::string nick() const { return m_nick; }
00097 
00101       Tag* tag() const
00102       {
00103         Tag* t = new Tag( "item" );
00104         t->addAttribute( "jid", m_jid.bare() );
00105         new Tag( t, "first", m_first );
00106         new Tag( t, "last", m_last );
00107         new Tag( t, "nick", m_nick );
00108         new Tag( t, "email", m_email );
00109         return t;
00110       }
00111 
00112     private:
00113       std::string m_first;              
00114       std::string m_last;               
00115       std::string m_nick;               
00116       std::string m_email;              
00117       JID m_jid;                        
00118   };
00119 
00123   enum SearchFieldEnum
00124   {
00125     SearchFieldFirst    = 1,        
00126     SearchFieldLast     = 2,        
00127     SearchFieldNick     = 4,        
00128     SearchFieldEmail    = 8         
00129   };
00130 
00134   typedef std::list<const SearchFieldStruct*> SearchResultList;
00135 
00144   class GLOOX_API SearchHandler
00145   {
00146     public:
00150       virtual ~SearchHandler() {}
00151 
00159       virtual void handleSearchFields( const JID& directory, int fields,
00160                                        const std::string& instructions ) = 0;
00161 
00168       virtual void handleSearchFields( const JID& directory, const DataForm* form ) = 0;
00169 
00175       virtual void handleSearchResult( const JID& directory, const SearchResultList& resultList ) = 0;
00176 
00182       virtual void handleSearchResult( const JID& directory, const DataForm* form ) = 0;
00183 
00189       virtual void handleSearchError( const JID& directory, const Error* error ) = 0;
00190 
00191   };
00192 
00193 }
00194 
00195 #endif // SEARCHHANDLER_H__