diff options
author | Tobias Markmann <tm@ayena.de> | 2012-03-14 21:36:10 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-03-20 18:15:37 (GMT) |
commit | 3d27d98ccc232ae7bfacfd5a3f85f44b6c2e9cc9 (patch) | |
tree | cae0589a1826560668683d2129fe024148d4e43d /Swift/Controllers | |
parent | 138223ab9ca917420d107d95a113e7628c27bac5 (diff) | |
download | swift-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/Controllers')
-rw-r--r-- | Swift/Controllers/Chat/UserSearchController.cpp | 23 | ||||
-rw-r--r-- | Swift/Controllers/Chat/UserSearchController.h | 8 | ||||
-rw-r--r-- | Swift/Controllers/ContactEditController.cpp | 37 | ||||
-rw-r--r-- | Swift/Controllers/ContactEditController.h | 10 | ||||
-rw-r--r-- | Swift/Controllers/MainController.cpp | 6 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/ContactEditWindow.h | 4 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/UserSearchWindow.h | 6 |
7 files changed, 83 insertions, 11 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_; diff --git a/Swift/Controllers/ContactEditController.cpp b/Swift/Controllers/ContactEditController.cpp index b4729a8..a8b171c 100644 --- a/Swift/Controllers/ContactEditController.cpp +++ b/Swift/Controllers/ContactEditController.cpp @@ -6,6 +6,7 @@ #include <Swift/Controllers/ContactEditController.h> +#include <boost/algorithm/string.hpp> #include <boost/bind.hpp> #include <boost/smart_ptr/make_shared.hpp> @@ -14,11 +15,12 @@ #include <Swift/Controllers/UIEvents/RemoveRosterItemUIEvent.h> #include <Swift/Controllers/UIInterfaces/ContactEditWindowFactory.h> #include <Swift/Controllers/Roster/RosterController.h> +#include <Swiften/VCards/VCardManager.h> namespace Swift { -ContactEditController::ContactEditController(RosterController* rosterController, ContactEditWindowFactory* contactEditWindowFactory, UIEventStream* uiEventStream) : rosterController(rosterController), contactEditWindowFactory(contactEditWindowFactory), uiEventStream(uiEventStream), contactEditWindow(NULL) { +ContactEditController::ContactEditController(RosterController* rosterController, VCardManager* vcardManager, ContactEditWindowFactory* contactEditWindowFactory, UIEventStream* uiEventStream) : rosterController(rosterController), vcardManager(vcardManager), contactEditWindowFactory(contactEditWindowFactory), uiEventStream(uiEventStream), contactEditWindow(NULL) { uiEventStream->onUIEvent.connect(boost::bind(&ContactEditController::handleUIEvent, this, _1)); } @@ -44,8 +46,22 @@ void ContactEditController::handleUIEvent(UIEvent::ref event) { } currentContact = rosterController->getItem(editEvent->getJID()); assert(currentContact); - contactEditWindow->setContact(currentContact->getJID(), currentContact->getName(), currentContact->getGroups(), rosterController->getGroups()); + jid = rosterController->getItem(editEvent->getJID())->getJID(); + contactEditWindow->setContact(jid, currentContact->getName(), currentContact->getGroups(), rosterController->getGroups()); contactEditWindow->show(); + + if (vcardManager) { + VCard::ref vcard = vcardManager->getVCardAndRequestWhenNeeded(jid); + if (vcard) { + handleVCardChanged(jid, vcard); + } + } +} + +void ContactEditController::handleVCardChanged(const JID &jid, VCard::ref vcard) { + if (jid == this->jid) { + contactEditWindow->setNameSuggestions(nameSuggestionsFromVCard(vcard)); + } } void ContactEditController::setAvailable(bool b) { @@ -54,6 +70,23 @@ void ContactEditController::setAvailable(bool b) { } } +std::vector<std::string> ContactEditController::nameSuggestionsFromVCard(VCard::ref vcard) { + std::vector<std::string> suggestions; + if (!vcard->getNickname().empty()) { + suggestions.push_back(vcard->getNickname()); + } + if (!vcard->getFullName().empty()) { + suggestions.push_back(vcard->getFullName()); + } + if (!vcard->getGivenName().empty()) { + std::string suggestedName; + suggestedName = vcard->getGivenName(); + boost::algorithm::trim(suggestedName); + suggestions.push_back(suggestedName); + } + return suggestions; +} + void ContactEditController::handleRemoveContactRequest() { assert(currentContact); uiEventStream->send(boost::make_shared<RemoveRosterItemUIEvent>(currentContact->getJID())); diff --git a/Swift/Controllers/ContactEditController.h b/Swift/Controllers/ContactEditController.h index 1947944..5f64a6a 100644 --- a/Swift/Controllers/ContactEditController.h +++ b/Swift/Controllers/ContactEditController.h @@ -12,6 +12,7 @@ #include <Swiften/JID/JID.h> #include <string> +#include <Swiften/Elements/VCard.h> #include <Swift/Controllers/UIEvents/UIEvent.h> #include <Swiften/Roster/XMPPRosterItem.h> @@ -20,26 +21,33 @@ namespace Swift { class ContactEditWindowFactory; class ContactEditWindow; class RosterController; + class VCardManager; class ContactEditController { public: - ContactEditController(RosterController* rosterController, ContactEditWindowFactory* contactEditWindowFactory, UIEventStream* uiEventStream); + ContactEditController(RosterController* rosterController, VCardManager* vcardManager, ContactEditWindowFactory* contactEditWindowFactory, UIEventStream* uiEventStream); ~ContactEditController(); void setAvailable(bool b); + public: + static std::vector<std::string> nameSuggestionsFromVCard(VCard::ref vcard); + private: void handleRemoveContactRequest(); void handleChangeContactRequest(const std::string& name, const std::set<std::string>& groups); private: void handleUIEvent(UIEvent::ref event); + void handleVCardChanged(const JID& jid, VCard::ref vcard); private: boost::optional<XMPPRosterItem> currentContact; RosterController* rosterController; + VCardManager* vcardManager; ContactEditWindowFactory* contactEditWindowFactory; UIEventStream* uiEventStream; + JID jid; ContactEditWindow* contactEditWindow; }; } diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index b154e93..cd7e673 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -286,7 +286,7 @@ void MainController::handleConnected() { rosterController_->onChangeStatusRequest.connect(boost::bind(&MainController::handleChangeStatusRequest, this, _1, _2)); rosterController_->onSignOutRequest.connect(boost::bind(&MainController::signOut, this)); - contactEditController_ = new ContactEditController(rosterController_, uiFactory_, uiEventStream_); + contactEditController_ = new ContactEditController(rosterController_, client_->getVCardManager(), uiFactory_, uiEventStream_); chatsManager_ = new ChatsManager(jid_, client_->getStanzaChannel(), client_->getIQRouter(), eventController_, uiFactory_, uiFactory_, client_->getNickResolver(), client_->getPresenceOracle(), client_->getPresenceSender(), uiEventStream_, uiFactory_, useDelayForLatency_, networkFactories_->getTimerFactory(), client_->getMUCRegistry(), client_->getEntityCapsProvider(), client_->getMUCManager(), uiFactory_, profileSettings_, ftOverview_, client_->getRoster(), !settings_->getSetting(SettingConstants::REMEMBER_RECENT_CHATS), settings_); @@ -312,8 +312,8 @@ void MainController::handleConnected() { client_->getDiscoManager()->setCapsNode(CLIENT_NODE); client_->getDiscoManager()->setDiscoInfo(discoInfo); - userSearchControllerChat_ = new UserSearchController(UserSearchController::StartChat, jid_, uiEventStream_, uiFactory_, client_->getIQRouter(), rosterController_); - userSearchControllerAdd_ = new UserSearchController(UserSearchController::AddContact, jid_, uiEventStream_, uiFactory_, client_->getIQRouter(), rosterController_); + userSearchControllerChat_ = new UserSearchController(UserSearchController::StartChat, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_); + userSearchControllerAdd_ = new UserSearchController(UserSearchController::AddContact, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_); adHocManager_ = new AdHocManager(JID(boundJID_.getDomain()), uiFactory_, client_->getIQRouter(), uiEventStream_, rosterController_->getWindow()); } loginWindow_->setIsLoggingIn(false); diff --git a/Swift/Controllers/UIInterfaces/ContactEditWindow.h b/Swift/Controllers/UIInterfaces/ContactEditWindow.h index 2445456..90f774c 100644 --- a/Swift/Controllers/UIInterfaces/ContactEditWindow.h +++ b/Swift/Controllers/UIInterfaces/ContactEditWindow.h @@ -15,13 +15,15 @@ namespace Swift { class JID; + class VCardManager; class ContactEditWindow { public: - virtual ~ContactEditWindow() {}; + virtual ~ContactEditWindow() {} virtual void setEnabled(bool b) = 0; + virtual void setNameSuggestions(const std::vector<std::string>& suggestions) = 0; virtual void setContact(const JID& jid, const std::string& name, const std::vector<std::string>& groups, const std::set<std::string>& allGroups) = 0; virtual void show() = 0; diff --git a/Swift/Controllers/UIInterfaces/UserSearchWindow.h b/Swift/Controllers/UIInterfaces/UserSearchWindow.h index 0bfc509..7ea6849 100644 --- a/Swift/Controllers/UIInterfaces/UserSearchWindow.h +++ b/Swift/Controllers/UIInterfaces/UserSearchWindow.h @@ -9,8 +9,8 @@ #include "Swiften/Base/boost_bsignals.h" #include <vector> - #include <string> + #include "Swiften/JID/JID.h" #include "Swift/Controllers/Chat/UserSearchController.h" @@ -19,7 +19,7 @@ namespace Swift { class UserSearchWindow { public: enum Type {AddContact, ChatToContact}; - virtual ~UserSearchWindow() {}; + virtual ~UserSearchWindow() {} virtual void clear() = 0; virtual void setResults(const std::vector<UserSearchResult>& results) = 0; @@ -29,9 +29,11 @@ namespace Swift { virtual void setServerSupportsSearch(bool support) = 0; virtual void setSearchError(bool support) = 0; virtual void setSearchFields(boost::shared_ptr<SearchPayload> fields) = 0; + virtual void setNameSuggestions(const std::vector<std::string>& suggestions) = 0; virtual void show() = 0; boost::signal<void (const JID&)> onFormRequested; boost::signal<void (boost::shared_ptr<SearchPayload>, const JID&)> onSearchRequested; + boost::signal<void (const JID&)> onNameSuggestionRequested; }; } |