summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2012-03-14 21:36:10 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-03-20 18:15:37 (GMT)
commit3d27d98ccc232ae7bfacfd5a3f85f44b6c2e9cc9 (patch)
treecae0589a1826560668683d2129fe024148d4e43d /Swift/QtUI/UserSearch
parent138223ab9ca917420d107d95a113e7628c27bac5 (diff)
downloadswift-3d27d98ccc232ae7bfacfd5a3f85f44b6c2e9cc9.zip
swift-3d27d98ccc232ae7bfacfd5a3f85f44b6c2e9cc9.tar.bz2
Naming suggestion for 'Add Contact'-dialog and "Edit Contact"-dialog based on vCards.
License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
Diffstat (limited to 'Swift/QtUI/UserSearch')
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp18
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchDetailsPage.h14
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchWindow.cpp71
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchWindow.h5
4 files changed, 75 insertions, 33 deletions
diff --git a/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp b/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp
index 779e547..da89a8d 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp
+++ b/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp
@@ -8,6 +8,11 @@
#include <QVBoxLayout>
+#include <boost/bind.hpp>
+
+#include <Swiften/Base/boost_bsignals.h>
+#include <Swiften/JID/JID.h>
+
#include <Swift/QtUI/QtContactEditWidget.h>
namespace Swift {
@@ -19,6 +24,18 @@ QtUserSearchDetailsPage::QtUserSearchDetailsPage(const std::set<std::string>& gr
layout->addWidget(editWidget);
}
+QtUserSearchDetailsPage::~QtUserSearchDetailsPage() {
+
+}
+
+void QtUserSearchDetailsPage::setJID(const JID& jid) {
+ contactJID = jid;
+}
+
+void QtUserSearchDetailsPage::setNameSuggestions(const std::vector<std::string>& nameSuggestions) {
+ editWidget->setNameSuggestions(nameSuggestions);
+}
+
std::set<std::string> QtUserSearchDetailsPage::getSelectedGroups() {
return editWidget->getSelectedGroups();
}
@@ -31,5 +48,4 @@ void QtUserSearchDetailsPage::clear() {
editWidget->clear();
}
-
}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.h b/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.h
index 70afcba..9409493 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.h
+++ b/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.h
@@ -7,8 +7,13 @@
#pragma once
#include <QWizardPage>
+
#include <set>
+#include <string>
+#include <vector>
+#include <Swiften/Elements/VCard.h>
+#include <Swiften/JID/JID.h>
#include <Swift/QtUI/UserSearch/ui_QtUserSearchFieldsPage.h>
namespace Swift {
@@ -18,6 +23,10 @@ namespace Swift {
Q_OBJECT
public:
QtUserSearchDetailsPage(const std::set<std::string>& availableGroups);
+ virtual ~QtUserSearchDetailsPage();
+
+ void setJID(const JID& jid);
+ void setNameSuggestions(const std::vector<std::string>& nameSuggestions);
std::set<std::string> getSelectedGroups();
std::string getName();
@@ -25,9 +34,10 @@ namespace Swift {
void clear();
signals:
- void onUserTriggersFinish();
+ void onUserTriggersFinish();
private:
- QtContactEditWidget* editWidget;
+ QtContactEditWidget* editWidget;
+ JID contactJID;
};
}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
index 933612c..53eac07 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
+++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
@@ -90,6 +90,8 @@ void QtUserSearchWindow::handleCurrentChanged(int page) {
}
else if (page == 4) {
detailsPage_->clear();
+ detailsPage_->setJID(getContactJID());
+ onNameSuggestionRequested(getContactJID());
}
lastPage_ = page;
}
@@ -99,35 +101,7 @@ JID QtUserSearchWindow::getServerToSearch() {
}
void QtUserSearchWindow::handleAccepted() {
- JID jid;
- if (!firstPage_->byJID_->isChecked()) {
- 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 {
- 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 (boost::dynamic_pointer_cast<JIDSingleFormField>(field)) {
- jid = JID(field->getRawValues().at(0));
- break;
- }
- if (field->getName() == "jid") {
- fallbackJid = field->getRawValues().at(0);
- }
- }
- if (!jid.isValid()) {
- jid = fallbackJid;
- }
- }
- }
- else {
- jid = JID(Q2PSTRING(firstPage_->jid_->text()));
- }
+ JID jid = getContactJID();
if (type_ == AddContact) {
eventStream_->send(boost::make_shared<AddContactUIEvent>(jid, detailsPage_->getName(), detailsPage_->getSelectedGroups()));
@@ -190,6 +164,39 @@ void QtUserSearchWindow::handleSearch() {
onSearchRequested(search, getServerToSearch());
}
+JID QtUserSearchWindow::getContactJID() const {
+ JID jid;
+ if (!firstPage_->byJID_->isChecked()) {
+ 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 {
+ 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 (boost::dynamic_pointer_cast<JIDSingleFormField>(field)) {
+ jid = JID(field->getRawValues().at(0));
+ break;
+ }
+ if (field->getName() == "jid") {
+ fallbackJid = field->getRawValues().at(0);
+ }
+ }
+ if (!jid.isValid()) {
+ jid = fallbackJid;
+ }
+ }
+ }
+ else {
+ jid = JID(Q2PSTRING(firstPage_->jid_->text()));
+ }
+ return jid;
+}
+
void QtUserSearchWindow::show() {
clear();
QWidget::show();
@@ -223,6 +230,12 @@ void QtUserSearchWindow::setSearchFields(boost::shared_ptr<SearchPayload> fields
fieldsPage_->emitCompletenessCheck();
}
+void QtUserSearchWindow::setNameSuggestions(const std::vector<std::string>& suggestions) {
+ if (detailsPage_) {
+ detailsPage_->setNameSuggestions(suggestions);
+ }
+}
+
void QtUserSearchWindow::setResults(const std::vector<UserSearchResult>& results) {
UserSearchModel *newModel = new UserSearchModel();
newModel->setResults(results);
diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.h b/Swift/QtUI/UserSearch/QtUserSearchWindow.h
index 4cfe93f..9173ba9 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchWindow.h
+++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.h
@@ -38,7 +38,9 @@ namespace Swift {
virtual void setSelectedService(const JID& jid);
virtual void setServerSupportsSearch(bool error);
virtual void setSearchError(bool error);
- virtual void setSearchFields(boost::shared_ptr<SearchPayload> fields) ;
+ virtual void setSearchFields(boost::shared_ptr<SearchPayload> fields);
+ virtual void setNameSuggestions(const std::vector<std::string>& suggestions);
+
protected:
virtual int nextId() const;
private slots:
@@ -50,6 +52,7 @@ namespace Swift {
void setError(const QString& error);
JID getServerToSearch();
void handleSearch();
+ JID getContactJID() const;
private:
UIEventStream* eventStream_;