summaryrefslogtreecommitdiffstats
blob: 1c50f0c4e5144c753a614a5fdbcc0724f4fd4661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * Copyright (c) 2010 Kevin Smith
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#pragma once

#include <vector>

#include "Swiften/Elements/Payload.h"
#include "Swiften/Elements/FormField.h"
#include <string>

#include "Swiften/JID/JID.h"

namespace Swift {
	/**
	 * XEP-0004 Data form.
	 * For the relevant Fields, the parsers and serialisers protect the API user against
	 * the strange multi-value instead of newline thing by transforming them.
	 */
	class Form : public Payload {
		public:
			typedef boost::shared_ptr<Form> ref;

			enum Type { FormType, SubmitType, CancelType, ResultType };

		public:
			Form(Type type = FormType) : type_(type) {}

			void addField(boost::shared_ptr<FormField> field) { fields_.push_back(field); }
			const std::vector<boost::shared_ptr<FormField> >& getFields() const { return fields_; }
			void setTitle(const std::string& title) { title_ = title; }
			const std::string& getTitle() { return title_; }

			void setInstructions(const std::string& instructions) { instructions_ = instructions; }
			const std::string& getInstructions() { return instructions_; }

			Type getType() { return type_; }
			void setType(Type type) { type_ = type; }

			std::string getFormType() const;

			FormField::ref getField(const std::string& name) const;

		private:
			std::vector<boost::shared_ptr<FormField> > fields_;
			std::string title_;
			std::string instructions_;
			Type type_;
	};
}