dataformfield.h

00001 /*
00002   Copyright (c) 2005-2007 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;
00032   class GLOOX_API DataFormField
00033   {
00034     public:
00035 
00039       enum DataFormFieldType
00040       {
00041         FieldTypeBoolean,           
00043         FieldTypeFixed,             
00048         FieldTypeHidden,            
00050         FieldTypeJidMulti,          
00052         FieldTypeJidSingle,         
00054         FieldTypeListMulti,         
00056         FieldTypeListSingle,        
00058         FieldTypeTextMulti,         
00060         FieldTypeTextPrivate,       
00062         FieldTypeTextSingle,        
00066         FieldTypeItem,              
00069         FieldTypeReported,          
00072         FieldTypeInvalid,           
00074         FieldTypeNone               
00076       };
00077 
00082       DataFormField( DataFormFieldType type = FieldTypeTextSingle );
00083 
00092       DataFormField( const std::string& name, const std::string& value = "",
00093                      const std::string& label = "", DataFormFieldType type = FieldTypeTextSingle );
00094 
00099       DataFormField( Tag *tag );
00100 
00104       virtual ~DataFormField();
00105 
00110       virtual StringMap& options() { return m_options; }
00111 
00118       virtual Tag* tag() const;
00119 
00124       virtual const std::string& name() const { return m_name; }
00125 
00132       virtual void setName( const std::string& name ) { m_name = name; }
00133 
00140       virtual void setOptions( const StringMap& options ) { m_options = options; }
00141 
00148       virtual void addOption( const std::string& label, const std::string& value )
00149         { m_options.insert( std::make_pair( label, value ) ); }
00150 
00155       virtual bool required() const { return m_required; }
00156 
00161       virtual void setRequired( bool required ) { m_required = required; }
00162 
00167       virtual DataFormFieldType type() const { return m_type; }
00168 
00173       virtual const std::string& label() const { return m_label; }
00174 
00179       virtual void setLabel( const std::string& label ) { m_label = label; }
00180 
00185       virtual const std::string& description() const { return m_desc; }
00186 
00191       virtual void setDescription( const std::string& desc ) { m_desc = desc; }
00192 
00197       virtual const std::string& value() const { return m_values.front(); }
00198 
00203       virtual void setValue( const std::string& value ) { m_values.clear(); addValue( value ); }
00204 
00209       virtual const StringList& values() const { return m_values; }
00210 
00216       virtual void setValues( const StringList& values ) { m_values = values; }
00217 
00222       virtual void addValue( const std::string& value ) { m_values.push_back( value ); }
00223 
00224     private:
00225       StringMap m_options;
00226       StringList m_values;
00227 
00228       std::string m_name;
00229       std::string m_desc;
00230       std::string m_label;
00231       DataFormFieldType m_type;
00232       bool m_required;
00233   };
00234 
00235 }
00236 
00237 #endif // DATAFORMFIELD_H__

Generated on Sat Nov 10 08:50:27 2007 for gloox by  doxygen 1.5.3-20071008