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/Controllers/Chat
parent138223ab9ca917420d107d95a113e7628c27bac5 (diff)
downloadswift-contrib-3d27d98ccc232ae7bfacfd5a3f85f44b6c2e9cc9.zip
swift-contrib-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/Controllers/Chat')
-rw-r--r--Swift/Controllers/Chat/UserSearchController.cpp23
-rw-r--r--Swift/Controllers/Chat/UserSearchController.h8
2 files changed, 29 insertions, 2 deletions
diff --git a/Swift/Controllers/Chat/UserSearchController.cpp b/Swift/Controllers/Chat/UserSearchController.cpp
index d90a3f8..d6a920d 100644
--- a/Swift/Controllers/Chat/UserSearchController.cpp
+++ b/Swift/Controllers/Chat/UserSearchController.cpp
@@ -13,6 +13,8 @@
#include <Swiften/Disco/GetDiscoInfoRequest.h>
#include <Swiften/Disco/GetDiscoItemsRequest.h>
#include <Swiften/Disco/DiscoServiceWalker.h>
+#include <Swiften/VCards/VCardManager.h>
+#include <Swift/Controllers/ContactEditController.h>
#include <Swift/Controllers/UIEvents/UIEventStream.h>
#include <Swift/Controllers/UIEvents/RequestChatWithUserDialogUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h>
@@ -21,8 +23,9 @@
#include <Swift/Controllers/Roster/RosterController.h>
namespace Swift {
-UserSearchController::UserSearchController(Type type, const JID& jid, UIEventStream* uiEventStream, UserSearchWindowFactory* factory, IQRouter* iqRouter, RosterController* rosterController) : type_(type), jid_(jid), uiEventStream_(uiEventStream), factory_(factory), iqRouter_(iqRouter), rosterController_(rosterController) {
+UserSearchController::UserSearchController(Type type, const JID& jid, UIEventStream* uiEventStream, VCardManager* vcardManager, UserSearchWindowFactory* factory, IQRouter* iqRouter, RosterController* rosterController) : type_(type), jid_(jid), uiEventStream_(uiEventStream), vcardManager_(vcardManager), factory_(factory), iqRouter_(iqRouter), rosterController_(rosterController) {
uiEventStream_->onUIEvent.connect(boost::bind(&UserSearchController::handleUIEvent, this, _1));
+ vcardManager_->onVCardChanged.connect(boost::bind(&UserSearchController::handleVCardChanged, this, _1, _2));
window_ = NULL;
discoWalker_ = NULL;
}
@@ -31,10 +34,12 @@ UserSearchController::~UserSearchController() {
endDiscoWalker();
delete discoWalker_;
if (window_) {
+ window_->onNameSuggestionRequested.disconnect(boost::bind(&UserSearchController::handleNameSuggestionRequest, this, _1));
window_->onFormRequested.disconnect(boost::bind(&UserSearchController::handleFormRequested, this, _1));
window_->onSearchRequested.disconnect(boost::bind(&UserSearchController::handleSearch, this, _1, _2));
delete window_;
}
+ vcardManager_->onVCardChanged.disconnect(boost::bind(&UserSearchController::handleVCardChanged, this, _1, _2));
uiEventStream_->onUIEvent.disconnect(boost::bind(&UserSearchController::handleUIEvent, this, _1));
}
@@ -52,6 +57,7 @@ void UserSearchController::handleUIEvent(boost::shared_ptr<UIEvent> event) {
if (handle) {
if (!window_) {
window_ = factory_->createUserSearchWindow(type_ == AddContact ? UserSearchWindow::AddContact : UserSearchWindow::ChatToContact, uiEventStream_, rosterController_->getGroups());
+ window_->onNameSuggestionRequested.connect(boost::bind(&UserSearchController::handleNameSuggestionRequest, this, _1));
window_->onFormRequested.connect(boost::bind(&UserSearchController::handleFormRequested, this, _1));
window_->onSearchRequested.connect(boost::bind(&UserSearchController::handleSearch, this, _1, _2));
window_->setSelectedService(JID(jid_.getDomain()));
@@ -143,6 +149,21 @@ void UserSearchController::handleSearchResponse(boost::shared_ptr<SearchPayload>
}
}
+void UserSearchController::handleNameSuggestionRequest(const JID &jid) {
+ suggestionsJID_= jid;
+ VCard::ref vcard = vcardManager_->getVCardAndRequestWhenNeeded(jid);
+ if (vcard) {
+ handleVCardChanged(jid, vcard);
+ }
+}
+
+void UserSearchController::handleVCardChanged(const JID& jid, VCard::ref vcard) {
+ if (jid == suggestionsJID_) {
+ window_->setNameSuggestions(ContactEditController::nameSuggestionsFromVCard(vcard));
+ suggestionsJID_ = JID();
+ }
+}
+
void UserSearchController::handleDiscoWalkFinished() {
window_->setServerSupportsSearch(false);
endDiscoWalker();
diff --git a/Swift/Controllers/Chat/UserSearchController.h b/Swift/Controllers/Chat/UserSearchController.h
index 071ec33..ce0754c 100644
--- a/Swift/Controllers/Chat/UserSearchController.h
+++ b/Swift/Controllers/Chat/UserSearchController.h
@@ -17,6 +17,7 @@
#include <Swiften/Elements/DiscoInfo.h>
#include <Swiften/Elements/DiscoItems.h>
#include <Swiften/Elements/ErrorPayload.h>
+#include <Swiften/Elements/VCard.h>
namespace Swift {
class UIEventStream;
@@ -26,6 +27,7 @@ namespace Swift {
class IQRouter;
class DiscoServiceWalker;
class RosterController;
+ class VCardManager;
class UserSearchResult {
public:
@@ -40,7 +42,7 @@ namespace Swift {
class UserSearchController {
public:
enum Type {AddContact, StartChat};
- UserSearchController(Type type, const JID& jid, UIEventStream* uiEventStream, UserSearchWindowFactory* userSearchWindowFactory, IQRouter* iqRouter, RosterController* rosterController);
+ UserSearchController(Type type, const JID& jid, UIEventStream* uiEventStream, VCardManager* vcardManager, UserSearchWindowFactory* userSearchWindowFactory, IQRouter* iqRouter, RosterController* rosterController);
~UserSearchController();
private:
@@ -51,12 +53,16 @@ namespace Swift {
void handleFormResponse(boost::shared_ptr<SearchPayload> items, ErrorPayload::ref error);
void handleSearch(boost::shared_ptr<SearchPayload> fields, const JID& jid);
void handleSearchResponse(boost::shared_ptr<SearchPayload> results, ErrorPayload::ref error);
+ void handleNameSuggestionRequest(const JID& jid);
+ void handleVCardChanged(const JID& jid, VCard::ref vcard);
void endDiscoWalker();
private:
Type type_;
JID jid_;
+ JID suggestionsJID_;
UIEventStream* uiEventStream_;
+ VCardManager* vcardManager_;
UserSearchWindowFactory* factory_;
IQRouter* iqRouter_;
RosterController* rosterController_;