summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchWindow.cpp9
-rw-r--r--Swiften/Elements/Form.cpp22
-rw-r--r--Swiften/Elements/Form.h4
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
@@ -180,81 +180,82 @@ int QtUserSearchWindow::nextId() const {
switch (currentId()) {
case 1: return searchNext_ ? 2 : -1;
case 2: return 3;
case 3: return 1;
case 4: return -1;
default: return -1;
}
}
}
void QtUserSearchWindow::handleFirstPageRadioChange() {
if (firstPage_->byJID_->isChecked()) {
firstPage_->jid_->setText("");
firstPage_->jid_->setEnabled(true);
firstPage_->service_->setEnabled(false);
restart();
}
else if (firstPage_->byRemoteSearch_->isChecked()) {
firstPage_->service_->setEditText("");
firstPage_->jid_->setEnabled(false);
firstPage_->service_->setEnabled(true);
//firstPage_->jid_->setText("");
restart();
}
else {
firstPage_->jid_->setEnabled(false);
firstPage_->service_->setEnabled(false);
restart();
}
}
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());
}
JID QtUserSearchWindow::getContactJID() const {
JID jid;
bool useSearchResult;
if (type_ == AddContact) {
useSearchResult = !firstPage_->byJID_->isChecked();
} else {
useSearchResult = true;
}
if (useSearchResult) {
if (dynamic_cast<UserSearchModel*>(model_)) {
UserSearchResult* userItem = static_cast<UserSearchResult*>(resultsPage_->results_->currentIndex().internalPointer());
if (userItem) { /* Remember to leave this if we change to dynamic cast */
jid = userItem->getJID();
}
} else if (dynamic_cast<QtFormResultItemModel*>(model_)) {
int row = resultsPage_->results_->currentIndex().row();
Form::FormItem item = dynamic_cast<QtFormResultItemModel*>(model_)->getForm()->getItems().at(row);
JID fallbackJid;
foreach(FormField::ref field, item) {
if (field->getType() == FormField::JIDSingleType) {
jid = JID(field->getJIDSingleValue());
break;
}
if (field->getName() == "jid") {
fallbackJid = field->getValues()[0];
}
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,45 +1,65 @@
/*
- * 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 {
std::string Form::getFormType() const {
FormField::ref field = getField("FORM_TYPE");
if (field && field->getType() == FormField::HiddenType) {
return field->getValues().empty() ? "" : field->getValues()[0];
}
return "";
}
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_;
}
+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,68 +1,70 @@
/*
- * 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>
#include <Swiften/Base/API.h>
#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 SWIFTEN_API 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 clearFields() { fields_.clear(); }
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 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_;
};
}