gloox  1.0.28
dataform.h
1 /*
2  Copyright (c) 2005-2023 by Jakob Schröter <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 DATAFORM_H__
15 #define DATAFORM_H__
16 
17 #include "dataformfieldcontainer.h"
18 #include "adhocplugin.h"
19 
20 #include <string>
21 #include <list>
22 
23 namespace gloox
24 {
25 
26  class Tag;
27  class DataFormItem;
28  class DataFormReported;
29 
33  enum FormType
34  {
35  TypeForm,
37  TypeSubmit,
39  TypeCancel,
41  TypeResult,
46  };
47 
56  class GLOOX_API DataForm : public AdhocPlugin, public DataFormFieldContainer
57  {
58  public:
62  typedef std::list<DataFormItem*> ItemList;
63 
71  DataForm( FormType type, const StringList& instructions, const std::string& title = EmptyString );
72 
80  DataForm( FormType type, const std::string& title = EmptyString );
81 
86  DataForm( const Tag* tag );
87 
92  DataForm( const DataForm& form );
93 
97  virtual ~DataForm();
98 
103  const std::string& title() const { return m_title; }
104 
110  void setTitle( const std::string& title ) { m_title = title; }
111 
116  const StringList& instructions() const { return m_instructions; }
117 
125  void setInstructions( const StringList& instructions ) { m_instructions = instructions; }
126 
131  const DataFormReported* reported() const { return m_reported; }
132 
137  const ItemList& items() const { return m_items; }
138 
144  FormType type() const { return m_type; }
145 
150  void setType( FormType type ) { m_type = type; }
151 
158  bool parse( const Tag* tag );
159 
163  operator bool() const { return m_type != TypeInvalid; }
164 
165  // reimplemented from StanzaExtension
166  virtual const std::string& filterString() const;
167 
168  // reimplemented from StanzaExtension
169  virtual StanzaExtension* newInstance( const Tag* tag ) const
170  {
171  return new DataForm( tag );
172  }
173 
174  // reimplemented from StanzaExtension
175  virtual Tag* tag() const;
176 
177  // reimplemented from StanzaExtension
178  virtual StanzaExtension* clone() const
179  {
180  return new DataForm( *this );
181  }
182 
183  protected:
184  FormType m_type;
185 
186  private:
187  StringList m_instructions;
188 
189  std::string m_title;
190  DataFormReported* m_reported;
191  ItemList m_items;
192 
193  };
194 
195 }
196 
197 #endif // DATAFORM_H__
A base class for Adhoc Command plugins (DataForm, IO Data, ...).
Definition: adhocplugin.h:39
An abstract base class for a XEP-0004 Data Form.
An abstraction of a <reported> element in a XEP-0004 Data Form of type result.
An abstraction of a XEP-0004 Data Form.
Definition: dataform.h:57
const DataFormReported * reported() const
Definition: dataform.h:131
const std::string & title() const
Definition: dataform.h:103
virtual StanzaExtension * newInstance(const Tag *tag) const
Definition: dataform.h:169
const ItemList & items() const
Definition: dataform.h:137
std::list< DataFormItem * > ItemList
Definition: dataform.h:62
void setTitle(const std::string &title)
Definition: dataform.h:110
void setInstructions(const StringList &instructions)
Definition: dataform.h:125
void setType(FormType type)
Definition: dataform.h:150
virtual StanzaExtension * clone() const
Definition: dataform.h:178
FormType type() const
Definition: dataform.h:144
const StringList & instructions() const
Definition: dataform.h:116
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
This is an abstraction of an XML element.
Definition: tag.h:47
The namespace for the gloox library.
Definition: adhoc.cpp:28
std::list< std::string > StringList
Definition: gloox.h:1251
const std::string EmptyString
Definition: gloox.cpp:124
FormType
Definition: dataform.h:34
@ TypeSubmit
Definition: dataform.h:37
@ TypeCancel
Definition: dataform.h:39
@ TypeInvalid
Definition: dataform.h:44
@ TypeForm
Definition: dataform.h:35
@ TypeResult
Definition: dataform.h:41