gloox  1.0
dataform.h
1 /*
2  Copyright (c) 2005-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 #ifndef DATAFORM_H__
15 #define DATAFORM_H__
16 
17 #include "dataformfieldcontainer.h"
18 #include "stanzaextension.h"
19 
20 #include <string>
21 #include <list>
22 
23 namespace gloox
24 {
25 
26  class Tag;
27  class DataFormItem;
28  class DataFormReported;
29 
33  enum FormType
34  {
46  };
47 
56  class GLOOX_API DataForm : public StanzaExtension, public DataFormFieldContainer
57  {
58  public:
62  typedef std::list<DataFormItem*> ItemList;
63 
71  DataForm( FormType type, const StringList& instructions, const std::string& title = EmptyString );
72 
80  DataForm( FormType type, const std::string& title = EmptyString );
81 
86  DataForm( const Tag* tag );
87 
92  DataForm( const DataForm& form );
93 
97  virtual ~DataForm();
98 
103  const std::string& title() const { return m_title; }
104 
110  void setTitle( const std::string& title ) { m_title = title; }
111 
116  const StringList& instructions() const { return m_instructions; }
117 
125  void setInstructions( const StringList& instructions ) { m_instructions = instructions; }
126 
131  const DataFormReported* reported() const { return m_reported; }
132 
137  const ItemList& items() const { return m_items; }
138 
144  FormType type() const { return m_type; }
145 
150  void setType( FormType type ) { m_type = type; }
151 
158  bool parse( const Tag* tag );
159 
163  operator bool() const { return m_type != TypeInvalid; }
164 
165  // reimplemented from StanzaExtension
166  virtual const std::string& filterString() const;
167 
168  // reimplemented from StanzaExtension
169  virtual StanzaExtension* newInstance( const Tag* tag ) const
170  {
171  return new DataForm( tag );
172  }
173 
174  // reimplemented from StanzaExtension
175  virtual Tag* tag() const;
176 
177  // reimplemented from StanzaExtension
178  virtual StanzaExtension* clone() const
179  {
180  return new DataForm( *this );
181  }
182 
183  protected:
184  FormType m_type;
185 
186  private:
187  StringList m_instructions;
188 
189  std::string m_title;
190  DataFormReported* m_reported;
191  ItemList m_items;
192 
193  };
194 
195 }
196 
197 #endif // DATAFORM_H__