diff options
| author | Tobias Markmann <tm@ayena.de> | 2012-01-06 22:18:25 (GMT) |
|---|---|---|
| committer | Kevin Smith <git@kismith.co.uk> | 2012-01-23 14:51:26 (GMT) |
| commit | 83afa3d4bf18e4feb8a33d084ed181508084fc64 (patch) | |
| tree | b81a0c6eaaedbad3f3e607ea52a69acf98f95eff /Swiften/Elements | |
| parent | 093d499945d779cfed92b45e413644834004b0d9 (diff) | |
| download | swift-contrib-83afa3d4bf18e4feb8a33d084ed181508084fc64.zip swift-contrib-83afa3d4bf18e4feb8a33d084ed181508084fc64.tar.bz2 | |
XEP-0004 form support for user search.
License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
Diffstat (limited to 'Swiften/Elements')
| -rw-r--r-- | Swiften/Elements/Form.cpp | 15 | ||||
| -rw-r--r-- | Swiften/Elements/Form.h | 8 |
2 files changed, 23 insertions, 0 deletions
diff --git a/Swiften/Elements/Form.cpp b/Swiften/Elements/Form.cpp index c34b868..cf9ecf6 100644 --- a/Swiften/Elements/Form.cpp +++ b/Swiften/Elements/Form.cpp @@ -1,28 +1,43 @@ /* * Copyright (c) 2010 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swiften/Elements/Form.h> #include <Swiften/Base/foreach.h> namespace Swift { std::string Form::getFormType() const { FormField::ref field = getField("FORM_TYPE"); boost::shared_ptr<HiddenFormField> f = boost::dynamic_pointer_cast<HiddenFormField>(field); return (f ? f->getValue() : ""); } FormField::ref Form::getField(const std::string& name) const { foreach(FormField::ref field, fields_) { if (field->getName() == name) { return field; } } return FormField::ref(); } +void Form::addReportedField(FormField::ref field) { + reportedFields_.push_back(field); +} + +const std::vector<FormField::ref>& Form::getReportedFields() const { + return reportedFields_; +} + +void Form::addItem(const Form::FormItem& item) { + items_.push_back(item); +} + +const std::vector<Form::FormItem>& Form::getItems() const { + return items_; +} } diff --git a/Swiften/Elements/Form.h b/Swiften/Elements/Form.h index 0d1ed63..2c6f963 100644 --- a/Swiften/Elements/Form.h +++ b/Swiften/Elements/Form.h @@ -1,55 +1,63 @@ /* * 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 <string> #include <Swiften/Elements/Payload.h> #include <Swiften/Elements/FormField.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 Form : public Payload { public: typedef boost::shared_ptr<Form> ref; + typedef std::vector<FormField::ref> FormItem; enum Type { FormType, SubmitType, CancelType, ResultType }; public: Form(Type type = FormType) : type_(type) {} /** Add a field to the form. * @param field New field - must not be null. */ void addField(boost::shared_ptr<FormField> field) {assert(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() 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 addReportedField(FormField::ref field); + const std::vector<FormField::ref>& getReportedFields() const; + + void addItem(const FormItem& item); + const std::vector<FormItem>& getItems() const; private: std::vector<boost::shared_ptr<FormField> > fields_; + std::vector<boost::shared_ptr<FormField> > reportedFields_; + std::vector<FormItem> items_; std::string title_; std::string instructions_; Type type_; }; } |
Swift