gloox  1.0
dataformfield.h
00001 /*
00002   Copyright (c) 2005-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 #ifndef DATAFORMFIELD_H__
00015 #define DATAFORMFIELD_H__
00016 
00017 #include "gloox.h"
00018 
00019 #include <utility>
00020 #include <string>
00021 
00022 namespace gloox
00023 {
00024 
00025   class Tag;
00026 
00033   class GLOOX_API DataFormField
00034   {
00035 
00036     public:
00040       enum FieldType
00041       {
00042         TypeBoolean,              
00044         TypeFixed,                
00049         TypeHidden,               
00051         TypeJidMulti,             
00053         TypeJidSingle,            
00055         TypeListMulti,            
00057         TypeListSingle,           
00059         TypeTextMulti,            
00061         TypeTextPrivate,          
00064         TypeTextSingle,           
00068         TypeNone,                 
00070         TypeInvalid               
00072       };
00073 
00074     public:
00075 
00080       DataFormField( FieldType type = TypeTextSingle );
00081 
00090       DataFormField( const std::string& name, const std::string& value = EmptyString,
00091               const std::string& label = EmptyString, FieldType type = TypeTextSingle );
00092 
00097       DataFormField( const Tag* tag );
00098 
00102       virtual ~DataFormField();
00103 
00108       const StringMultiMap& options() const { return m_options; }
00109 
00116       virtual Tag* tag() const;
00117 
00122       const std::string& name() const { return m_name; }
00123 
00130       void setName( const std::string& name ) { m_name = name; }
00131 
00138       void setOptions( const StringMultiMap& options ) { m_options = options; }
00139 
00146       void addOption( const std::string& label, const std::string& value )
00147           { m_options.insert( std::make_pair( label, value ) ); }
00148 
00153       bool required() const { return m_required; }
00154 
00159       void setRequired( bool required ) { m_required = required; }
00160 
00165       const std::string& label() const { return m_label; }
00166 
00171       void setLabel( const std::string& label ) { m_label = label; }
00172 
00177       const std::string& description() const { return m_desc; }
00178 
00183       void setDescription( const std::string& desc ) { m_desc = desc; }
00184 
00189           const std::string& value() const { return ( m_values.size() > 0 ) ? m_values.front() : EmptyString; }
00190 
00195       void setValue( const std::string& value ) { m_values.clear(); addValue( value ); }
00196 
00201       const StringList& values() const { return m_values; }
00202 
00208       void setValues( const StringList& values ) { m_values = values; }
00209 
00214       void addValue( const std::string& value ) { m_values.push_back( value ); }
00215 
00220       FieldType type() const { return m_type; }
00221 
00225       operator bool() const { return m_type != TypeInvalid; }
00226 
00227     private:
00228       FieldType m_type;
00229 
00230       StringMultiMap m_options;
00231       StringList m_values;
00232 
00233       std::string m_name;
00234       std::string m_desc;
00235       std::string m_label;
00236 
00237       bool m_required;
00238   };
00239 
00240 }
00241 
00242 #endif // DATAFORMFIELD_H__