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 DATAFORM_H__ 00015 #define DATAFORM_H__ 00016 00017 #include "dataformfieldcontainer.h" 00018 #include "stanzaextension.h" 00019 00020 #include <string> 00021 #include <list> 00022 00023 namespace gloox 00024 { 00025 00026 class Tag; 00027 class DataFormItem; 00028 class DataFormReported; 00029 00033 enum FormType 00034 { 00035 TypeForm, 00037 TypeSubmit, 00039 TypeCancel, 00041 TypeResult, 00044 TypeInvalid 00046 }; 00047 00056 class GLOOX_API DataForm : public StanzaExtension, public DataFormFieldContainer 00057 { 00058 public: 00062 typedef std::list<DataFormItem*> ItemList; 00063 00071 DataForm( FormType type, const StringList& instructions, const std::string& title = EmptyString ); 00072 00080 DataForm( FormType type, const std::string& title = EmptyString ); 00081 00086 DataForm( const Tag* tag ); 00087 00092 DataForm( const DataForm& form ); 00093 00097 virtual ~DataForm(); 00098 00103 const std::string& title() const { return m_title; } 00104 00110 void setTitle( const std::string& title ) { m_title = title; } 00111 00116 const StringList& instructions() const { return m_instructions; } 00117 00125 void setInstructions( const StringList& instructions ) { m_instructions = instructions; } 00126 00131 const DataFormReported* reported() const { return m_reported; } 00132 00137 const ItemList& items() const { return m_items; } 00138 00144 FormType type() const { return m_type; } 00145 00150 void setType( FormType type ) { m_type = type; } 00151 00158 bool parse( const Tag* tag ); 00159 00163 operator bool() const { return m_type != TypeInvalid; } 00164 00165 // reimplemented from StanzaExtension 00166 virtual const std::string& filterString() const; 00167 00168 // reimplemented from StanzaExtension 00169 virtual StanzaExtension* newInstance( const Tag* tag ) const 00170 { 00171 return new DataForm( tag ); 00172 } 00173 00174 // reimplemented from StanzaExtension 00175 virtual Tag* tag() const; 00176 00177 // reimplemented from StanzaExtension 00178 virtual StanzaExtension* clone() const 00179 { 00180 return new DataForm( *this ); 00181 } 00182 00183 protected: 00184 FormType m_type; 00185 00186 private: 00187 StringList m_instructions; 00188 00189 std::string m_title; 00190 DataFormReported* m_reported; 00191 ItemList m_items; 00192 00193 }; 00194 00195 } 00196 00197 #endif // DATAFORM_H__