summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Elements')
-rw-r--r--Swiften/Elements/Form.cpp22
-rw-r--r--Swiften/Elements/Form.h4
2 files changed, 24 insertions, 2 deletions
diff --git a/Swiften/Elements/Form.cpp b/Swiften/Elements/Form.cpp
index c4ae410..4915e2a 100644
--- a/Swiften/Elements/Form.cpp
+++ b/Swiften/Elements/Form.cpp
@@ -1,11 +1,11 @@
/*
- * Copyright (c) 2010-2013 Remko Tronçon
+ * Copyright (c) 2010-2014 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 {
@@ -36,10 +36,30 @@ const std::vector<FormField::ref>& Form::getReportedFields() const {
void Form::addItem(const Form::FormItem& item) {
items_.push_back(item);
}
const std::vector<Form::FormItem>& Form::getItems() const {
return items_;
}
+void Form::clearEmptyTextFields() {
+ std::vector<FormField::ref> populatedFields;
+ foreach (FormField::ref field, fields_) {
+ if (field->getType() == FormField::TextSingleType) {
+ if (!field->getTextSingleValue().empty()) {
+ populatedFields.push_back(field);
+ }
+ }
+ else if (field->getType() == FormField::TextMultiType) {
+ if (!field->getTextMultiValue().empty()) {
+ populatedFields.push_back(field);
+ }
+ }
+ else {
+ populatedFields.push_back(field);
+ }
+ }
+ fields_ = populatedFields;
+}
+
}
diff --git a/Swiften/Elements/Form.h b/Swiften/Elements/Form.h
index 76ed674..16cef98 100644
--- a/Swiften/Elements/Form.h
+++ b/Swiften/Elements/Form.h
@@ -1,11 +1,11 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#pragma once
#include <vector>
#include <string>
@@ -51,18 +51,20 @@ namespace Swift {
void addReportedField(FormField::ref field);
const std::vector<FormField::ref>& getReportedFields() const;
void clearReportedFields() { reportedFields_.clear(); }
void addItem(const FormItem& item);
const std::vector<FormItem>& getItems() const;
void clearItems() { items_.clear(); }
+ void clearEmptyTextFields();
+
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_;
};
}