gloox
1.0
|
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 00015 #ifndef SEARCH_H__ 00016 #define SEARCH_H__ 00017 00018 #include "gloox.h" 00019 #include "searchhandler.h" 00020 #include "discohandler.h" 00021 #include "iqhandler.h" 00022 #include "stanzaextension.h" 00023 #include "dataform.h" 00024 00025 #include <string> 00026 00027 namespace gloox 00028 { 00029 00030 class ClientBase; 00031 class IQ; 00032 class Disco; 00033 00049 class GLOOX_API Search : public IqHandler 00050 { 00051 00052 public: 00057 Search( ClientBase* parent ); 00058 00062 ~Search(); 00063 00069 void fetchSearchFields( const JID& directory, SearchHandler* sh ); 00070 00079 void search( const JID& directory, DataForm* form, SearchHandler* sh ); 00080 00090 void search( const JID& directory, int fields, const SearchFieldStruct& values, SearchHandler* sh ); 00091 00092 // reimplemented from IqHandler. 00093 virtual bool handleIq( const IQ& iq ) { (void)iq; return false; } 00094 00095 // reimplemented from IqHandler. 00096 virtual void handleIqID( const IQ& iq, int context ); 00097 00098 protected: 00099 enum IdType 00100 { 00101 FetchSearchFields, 00102 DoSearch 00103 }; 00104 00105 typedef std::map<std::string, SearchHandler*> TrackMap; 00106 TrackMap m_track; 00107 00108 ClientBase* m_parent; 00109 Disco* m_disco; 00110 00111 private: 00112 #ifdef SEARCH_TEST 00113 public: 00114 #endif 00115 00121 class Query : public StanzaExtension 00122 { 00123 public: 00128 Query( DataForm* form ); 00129 00136 Query( int fields, const SearchFieldStruct& values ); 00137 00143 Query( const Tag* tag = 0 ); 00144 00148 virtual ~Query(); 00149 00154 const DataForm* form() const { return m_form; } 00155 00160 const std::string& instructions() const { return m_instructions; } 00161 00166 int fields() const { return m_fields; } 00167 00172 const SearchResultList& result() const { return m_srl; } 00173 00174 // reimplemented from StanzaExtension 00175 virtual const std::string& filterString() const; 00176 00177 // reimplemented from StanzaExtension 00178 virtual StanzaExtension* newInstance( const Tag* tag ) const 00179 { 00180 return new Query( tag ); 00181 } 00182 00183 // reimplemented from StanzaExtension 00184 virtual Tag* tag() const; 00185 00186 // reimplemented from StanzaExtension 00187 virtual StanzaExtension* clone() const 00188 { 00189 Query* q = new Query(); 00190 q->m_form = m_form ? new DataForm( *m_form ) : 0; 00191 q->m_fields = m_fields; 00192 q->m_values = m_values; 00193 q->m_instructions = m_instructions; 00194 SearchResultList::const_iterator it = m_srl.begin(); 00195 for( ; it != m_srl.end(); ++it ) 00196 q->m_srl.push_back( new SearchFieldStruct( *(*it) ) ); 00197 return q; 00198 } 00199 00200 private: 00201 #ifdef SEARCH_TEST 00202 public: 00203 #endif 00204 DataForm* m_form; 00205 int m_fields; 00206 SearchFieldStruct m_values; 00207 std::string m_instructions; 00208 SearchResultList m_srl; 00209 }; 00210 00211 }; 00212 00213 } 00214 00215 #endif // SEARCH_H__