diff options
-rw-r--r-- | Swift/QtUI/UserSearch/QtUserSearchWindow.cpp | 9 | ||||
-rw-r--r-- | Swiften/Elements/Form.cpp | 22 | ||||
-rw-r--r-- | Swiften/Elements/Form.h | 4 |
3 files changed, 29 insertions, 6 deletions
diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp index 29ee306..babe115 100644 --- a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp +++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp @@ -209,23 +209,24 @@ void QtUserSearchWindow::handleFirstPageRadioChange() { } void QtUserSearchWindow::handleSearch() { boost::shared_ptr<SearchPayload> search(new SearchPayload()); if (fieldsPage_->getFormWidget()) { search->setForm(fieldsPage_->getFormWidget()->getCompletedForm()); + search->getForm()->clearEmptyTextFields(); } else { - if (fieldsPage_->nickInput_->isEnabled()) { + if (fieldsPage_->nickInput_->isEnabled() && !fieldsPage_->nickInput_->text().isEmpty()) { search->setNick(Q2PSTRING(fieldsPage_->nickInput_->text())); } - if (fieldsPage_->firstInput_->isEnabled()) { + if (fieldsPage_->firstInput_->isEnabled() && !fieldsPage_->firstInput_->text().isEmpty()) { search->setFirst(Q2PSTRING(fieldsPage_->firstInput_->text())); } - if (fieldsPage_->lastInput_->isEnabled()) { + if (fieldsPage_->lastInput_->isEnabled() && !fieldsPage_->lastInput_->text().isEmpty()) { search->setLast(Q2PSTRING(fieldsPage_->lastInput_->text())); } - if (fieldsPage_->emailInput_->isEnabled()) { + if (fieldsPage_->emailInput_->isEnabled() && !fieldsPage_->emailInput_->text().isEmpty()) { search->setEMail(Q2PSTRING(fieldsPage_->emailInput_->text())); } } onSearchRequested(search, getServerToSearch()); } 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,8 +1,8 @@ /* - * 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> @@ -39,7 +39,27 @@ void Form::addItem(const Form::FormItem& 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,8 +1,8 @@ /* - * 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 @@ -54,12 +54,14 @@ namespace Swift { 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_; |