gloox  1.0.1
dataformfield.h
1 /*
2  Copyright (c) 2005-2012 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;
26 
33  class GLOOX_API DataFormField
34  {
35 
36  public:
40  enum FieldType
41  {
42  TypeBoolean,
44  TypeFixed,
49  TypeHidden,
51  TypeJidMulti,
53  TypeJidSingle,
55  TypeListMulti,
57  TypeListSingle,
59  TypeTextMulti,
61  TypeTextPrivate,
64  TypeTextSingle,
68  TypeNone,
72  };
73 
74  public:
75 
80  DataFormField( FieldType type = TypeTextSingle );
81 
90  DataFormField( const std::string& name, const std::string& value = EmptyString,
91  const std::string& label = EmptyString, FieldType type = TypeTextSingle );
92 
97  DataFormField( const Tag* tag );
98 
102  virtual ~DataFormField();
103 
108  const StringMultiMap& options() const { return m_options; }
109 
116  virtual Tag* tag() const;
117 
122  const std::string& name() const { return m_name; }
123 
130  void setName( const std::string& name ) { m_name = name; }
131 
138  void setOptions( const StringMultiMap& options ) { m_options = options; }
139 
146  void addOption( const std::string& label, const std::string& value )
147  { m_options.insert( std::make_pair( label, value ) ); }
148 
153  bool required() const { return m_required; }
154 
159  void setRequired( bool required ) { m_required = required; }
160 
165  const std::string& label() const { return m_label; }
166 
171  void setLabel( const std::string& label ) { m_label = label; }
172 
177  const std::string& description() const { return m_desc; }
178 
183  void setDescription( const std::string& desc ) { m_desc = desc; }
184 
189  const std::string& value() const { return ( m_values.size() > 0 ) ? m_values.front() : EmptyString; }
190 
195  void setValue( const std::string& value ) { m_values.clear(); addValue( value ); }
196 
201  const StringList& values() const { return m_values; }
202 
208  void setValues( const StringList& values ) { m_values = values; }
209 
214  void addValue( const std::string& value ) { m_values.push_back( value ); }
215 
220  FieldType type() const { return m_type; }
221 
225  operator bool() const { return m_type != TypeInvalid; }
226 
227  private:
228  FieldType m_type;
229 
230  StringMultiMap m_options;
231  StringList m_values;
232 
233  std::string m_name;
234  std::string m_desc;
235  std::string m_label;
236 
237  bool m_required;
238  };
239 
240 }
241 
242 #endif // DATAFORMFIELD_H__