gloox  0.9.9.12
dataformfield.h
1 /*
2  Copyright (c) 2005-2008 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 DATAFORMFIELD_H__
15 #define DATAFORMFIELD_H__
16 
17 #include "gloox.h"
18 
19 #include <utility>
20 #include <string>
21 
22 namespace gloox
23 {
24 
25  class Tag;
32  class GLOOX_API DataFormField
33  {
34  public:
35 
40  {
41  FieldTypeBoolean,
43  FieldTypeFixed,
48  FieldTypeHidden,
50  FieldTypeJidMulti,
52  FieldTypeJidSingle,
54  FieldTypeListMulti,
56  FieldTypeListSingle,
58  FieldTypeTextMulti,
60  FieldTypeTextPrivate,
62  FieldTypeTextSingle,
66  FieldTypeItem,
69  FieldTypeReported,
72  FieldTypeInvalid,
74  FieldTypeNone
76  };
77 
82  DataFormField( DataFormFieldType type = FieldTypeTextSingle );
83 
92  DataFormField( const std::string& name, const std::string& value = "",
93  const std::string& label = "", DataFormFieldType type = FieldTypeTextSingle );
94 
99  DataFormField( Tag *tag );
100 
104  virtual ~DataFormField();
105 
110  virtual StringMap& options() { return m_options; }
111 
118  virtual Tag* tag() const;
119 
124  virtual const std::string& name() const { return m_name; }
125 
132  virtual void setName( const std::string& name ) { m_name = name; }
133 
140  virtual void setOptions( const StringMap& options ) { m_options = options; }
141 
148  virtual void addOption( const std::string& label, const std::string& value )
149  { m_options.insert( std::make_pair( label, value ) ); }
150 
155  virtual bool required() const { return m_required; }
156 
161  virtual void setRequired( bool required ) { m_required = required; }
162 
167  virtual DataFormFieldType type() const { return m_type; }
168 
173  virtual const std::string& label() const { return m_label; }
174 
179  virtual void setLabel( const std::string& label ) { m_label = label; }
180 
185  virtual const std::string& description() const { return m_desc; }
186 
191  virtual void setDescription( const std::string& desc ) { m_desc = desc; }
192 
197  virtual const std::string& value() const { return m_values.front(); }
198 
203  virtual void setValue( const std::string& value ) { m_values.clear(); addValue( value ); }
204 
209  virtual const StringList& values() const { return m_values; }
210 
216  virtual void setValues( const StringList& values ) { m_values = values; }
217 
222  virtual void addValue( const std::string& value ) { m_values.push_back( value ); }
223 
224  private:
225  StringMap m_options;
226  StringList m_values;
227 
228  std::string m_name;
229  std::string m_desc;
230  std::string m_label;
231  DataFormFieldType m_type;
232  bool m_required;
233  };
234 
235 }
236 
237 #endif // DATAFORMFIELD_H__