gloox  1.0
search.h
1 /*
2  Copyright (c) 2006-2009 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 
15 #ifndef SEARCH_H__
16 #define SEARCH_H__
17 
18 #include "gloox.h"
19 #include "searchhandler.h"
20 #include "discohandler.h"
21 #include "iqhandler.h"
22 #include "stanzaextension.h"
23 #include "dataform.h"
24 
25 #include <string>
26 
27 namespace gloox
28 {
29 
30  class ClientBase;
31  class IQ;
32  class Disco;
33 
49  class GLOOX_API Search : public IqHandler
50  {
51 
52  public:
57  Search( ClientBase* parent );
58 
62  ~Search();
63 
69  void fetchSearchFields( const JID& directory, SearchHandler* sh );
70 
79  void search( const JID& directory, DataForm* form, SearchHandler* sh );
80 
90  void search( const JID& directory, int fields, const SearchFieldStruct& values, SearchHandler* sh );
91 
92  // reimplemented from IqHandler.
93  virtual bool handleIq( const IQ& iq ) { (void)iq; return false; }
94 
95  // reimplemented from IqHandler.
96  virtual void handleIqID( const IQ& iq, int context );
97 
98  protected:
99  enum IdType
100  {
101  FetchSearchFields,
102  DoSearch
103  };
104 
105  typedef std::map<std::string, SearchHandler*> TrackMap;
106  TrackMap m_track;
107 
108  ClientBase* m_parent;
109  Disco* m_disco;
110 
111  private:
112 #ifdef SEARCH_TEST
113  public:
114 #endif
115 
121  class Query : public StanzaExtension
122  {
123  public:
128  Query( DataForm* form );
129 
136  Query( int fields, const SearchFieldStruct& values );
137 
143  Query( const Tag* tag = 0 );
144 
148  virtual ~Query();
149 
154  const DataForm* form() const { return m_form; }
155 
160  const std::string& instructions() const { return m_instructions; }
161 
166  int fields() const { return m_fields; }
167 
172  const SearchResultList& result() const { return m_srl; }
173 
174  // reimplemented from StanzaExtension
175  virtual const std::string& filterString() const;
176 
177  // reimplemented from StanzaExtension
178  virtual StanzaExtension* newInstance( const Tag* tag ) const
179  {
180  return new Query( tag );
181  }
182 
183  // reimplemented from StanzaExtension
184  virtual Tag* tag() const;
185 
186  // reimplemented from StanzaExtension
187  virtual StanzaExtension* clone() const
188  {
189  Query* q = new Query();
190  q->m_form = m_form ? new DataForm( *m_form ) : 0;
191  q->m_fields = m_fields;
192  q->m_values = m_values;
193  q->m_instructions = m_instructions;
194  SearchResultList::const_iterator it = m_srl.begin();
195  for( ; it != m_srl.end(); ++it )
196  q->m_srl.push_back( new SearchFieldStruct( *(*it) ) );
197  return q;
198  }
199 
200  private:
201 #ifdef SEARCH_TEST
202  public:
203 #endif
204  DataForm* m_form;
205  int m_fields;
206  SearchFieldStruct m_values;
207  std::string m_instructions;
208  SearchResultList m_srl;
209  };
210 
211  };
212 
213 }
214 
215 #endif // SEARCH_H__