blob: 899fb939d50cd58d9deca2e01adf514d69594551 (
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
#include <cassert>
#include <string>
#include <vector>
#include <Swiften/Base/API.h>
#include <Swiften/Elements/FormField.h>
#include <Swiften/Elements/FormPage.h>
#include <Swiften/Elements/FormSection.h>
#include <Swiften/Elements/Payload.h>
#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 SWIFTEN_API Form : public Payload {
public:
typedef std::shared_ptr<Form> ref;
typedef std::vector<FormField::ref> FormItem;
enum Type { FormType, SubmitType, CancelType, ResultType };
public:
Form(Type type = FormType) : type_(type) {}
void addPage(std::shared_ptr<FormPage> page) {
assert(page);
pages_.push_back(page);
}
const std::vector<std::shared_ptr<FormPage> >& getPages() const {
return pages_;
}
void addField(std::shared_ptr<FormField> field) {
assert(field);
fields_.push_back(field);
}
const std::vector<std::shared_ptr<FormField> >& getFields() const {
return fields_;
}
void clearFields() {
fields_.clear();
}
void addTextElement(std::shared_ptr<FormText> text) {
assert(text);
textElements_.push_back(text);
}
const std::vector<std::shared_ptr<FormText> >& getTextElements() const {
return textElements_;
}
void addReportedRef(std::shared_ptr<FormReportedRef> reportedRef) {
assert(reportedRef);
reportedRefs_.push_back(reportedRef);
}
const std::vector<std::shared_ptr<FormReportedRef> >& getReportedRefs() const {
return reportedRefs_;
}
void setTitle(const std::string& title) {
title_ = title;
}
const std::string& getTitle() const {
return title_;
}
void setInstructions(const std::string& instructions) {
instructions_ = instructions;
}
const std::string& getInstructions() const {
return instructions_;
}
Type getType() const {
return type_;
}
void setType(Type type) {
type_ = type;
}
std::string getFormType() const;
FormField::ref getField(const std::string& name) const;
void addItem(const FormItem& item);
const std::vector<FormItem>& getItems() const;
void clearItems() { items_.clear(); }
void clearEmptyTextFields();
void addReportedField(FormField::ref field);
const std::vector<FormField::ref> & getReportedFields() const;
void clearReportedFields() { reportedFields_.clear(); }
private:
std::vector<std::shared_ptr<FormReportedRef> >reportedRefs_;
std::vector<std::shared_ptr<FormText> > textElements_;
std::vector<std::shared_ptr<FormPage> > pages_;
std::vector<std::shared_ptr<FormField> > fields_;
std::vector<std::shared_ptr<FormField> > reportedFields_;
std::vector<FormItem> items_;
std::shared_ptr<FormReportedRef> reportedRef_;
std::string title_;
std::string instructions_;
Type type_;
};
}
|