diff options
| author | Richard Maudsley <richard.maudsley@isode.com> | 2014-04-07 09:19:50 (GMT) |
|---|---|---|
| committer | Richard Maudsley <richard.maudsley@isode.com> | 2014-04-07 13:07:43 (GMT) |
| commit | a7c7602e89d58056940885112f8764a31e9991da (patch) | |
| tree | e713e2d7eed2c2ba2925ec0a70fe93eb707c077a /Swift/Controllers/Chat | |
| parent | 1a35178bcad7c30e50a19e4017d021fb0485ccf0 (diff) | |
| download | swift-contrib-a7c7602e89d58056940885112f8764a31e9991da.zip swift-contrib-a7c7602e89d58056940885112f8764a31e9991da.tar.bz2 | |
Allow contacts to be dragged from the Chats tab into the search window
Change-Id: Ib1ecd2f95fb26269d8aa19094aac6e1f691cdf35
Diffstat (limited to 'Swift/Controllers/Chat')
| -rw-r--r-- | Swift/Controllers/Chat/UserSearchController.cpp | 12 | ||||
| -rw-r--r-- | Swift/Controllers/Chat/UserSearchController.h | 3 |
2 files changed, 13 insertions, 2 deletions
diff --git a/Swift/Controllers/Chat/UserSearchController.cpp b/Swift/Controllers/Chat/UserSearchController.cpp index 3c7eb67..7844c1b 100644 --- a/Swift/Controllers/Chat/UserSearchController.cpp +++ b/Swift/Controllers/Chat/UserSearchController.cpp @@ -1,82 +1,83 @@ /* - * 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. */ #include <Swift/Controllers/Chat/UserSearchController.h> #include <boost/bind.hpp> #include <boost/shared_ptr.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <Swiften/Base/foreach.h> #include <Swiften/Disco/GetDiscoInfoRequest.h> #include <Swiften/Disco/GetDiscoItemsRequest.h> #include <Swiften/Disco/DiscoServiceWalker.h> #include <Swiften/VCards/VCardManager.h> #include <Swiften/Presence/PresenceOracle.h> #include <Swiften/Avatars/AvatarManager.h> #include <Swift/Controllers/ContactEditController.h> #include <Swift/Controllers/UIEvents/UIEventStream.h> #include <Swift/Controllers/UIEvents/RequestChatWithUserDialogUIEvent.h> #include <Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h> #include <Swift/Controllers/UIEvents/RequestInviteToMUCUIEvent.h> #include <Swift/Controllers/UIInterfaces/UserSearchWindow.h> #include <Swift/Controllers/UIInterfaces/UserSearchWindowFactory.h> #include <Swift/Controllers/Roster/RosterController.h> #include <Swift/Controllers/ContactSuggester.h> namespace Swift { UserSearchController::UserSearchController(Type type, const JID& jid, UIEventStream* uiEventStream, VCardManager* vcardManager, UserSearchWindowFactory* factory, IQRouter* iqRouter, RosterController* rosterController, ContactSuggester* contactSuggester, AvatarManager* avatarManager, PresenceOracle* presenceOracle) : type_(type), jid_(jid), uiEventStream_(uiEventStream), vcardManager_(vcardManager), factory_(factory), iqRouter_(iqRouter), rosterController_(rosterController), contactSuggester_(contactSuggester), avatarManager_(avatarManager), presenceOracle_(presenceOracle) { uiEventStream_->onUIEvent.connect(boost::bind(&UserSearchController::handleUIEvent, this, _1)); vcardManager_->onVCardChanged.connect(boost::bind(&UserSearchController::handleVCardChanged, this, _1, _2)); avatarManager_->onAvatarChanged.connect(boost::bind(&UserSearchController::handleAvatarChanged, this, _1)); presenceOracle_->onPresenceChange.connect(boost::bind(&UserSearchController::handlePresenceChanged, this, _1)); window_ = NULL; discoWalker_ = NULL; } 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)); window_->onJIDUpdateRequested.disconnect(boost::bind(&UserSearchController::handleJIDUpdateRequested, this, _1)); + window_->onJIDAddRequested.disconnect(boost::bind(&UserSearchController::handleJIDAddRequested, this, _1)); delete window_; } presenceOracle_->onPresenceChange.disconnect(boost::bind(&UserSearchController::handlePresenceChanged, this, _1)); avatarManager_->onAvatarChanged.disconnect(boost::bind(&UserSearchController::handleAvatarChanged, this, _1)); vcardManager_->onVCardChanged.disconnect(boost::bind(&UserSearchController::handleVCardChanged, this, _1, _2)); uiEventStream_->onUIEvent.disconnect(boost::bind(&UserSearchController::handleUIEvent, this, _1)); } UserSearchWindow* UserSearchController::getUserSearchWindow() { initializeUserWindow(); assert(window_); return window_; } void UserSearchController::setCanInitiateImpromptuMUC(bool supportsImpromptu) { if (!window_) { initializeUserWindow(); } window_->setCanStartImpromptuChats(supportsImpromptu); } void UserSearchController::handleUIEvent(boost::shared_ptr<UIEvent> event) { bool handle = false; boost::shared_ptr<RequestAddUserDialogUIEvent> addUserRequest = boost::shared_ptr<RequestAddUserDialogUIEvent>(); RequestInviteToMUCUIEvent::ref inviteToMUCRequest = RequestInviteToMUCUIEvent::ref(); switch (type_) { case AddContact: if ((addUserRequest = boost::dynamic_pointer_cast<RequestAddUserDialogUIEvent>(event))) { handle = true; } break; case StartChat: if (boost::dynamic_pointer_cast<RequestChatWithUserDialogUIEvent>(event)) { handle = true; } @@ -190,97 +191,106 @@ void UserSearchController::handleNameSuggestionRequest(const JID &jid) { if (vcard) { handleVCardChanged(jid, vcard); } } void UserSearchController::handleContactSuggestionsRequested(std::string text) { window_->setContactSuggestions(contactSuggester_->getSuggestions(text)); } void UserSearchController::handleVCardChanged(const JID& jid, VCard::ref vcard) { if (jid == suggestionsJID_) { window_->setNameSuggestions(ContactEditController::nameSuggestionsFromVCard(vcard)); suggestionsJID_ = JID(); } handleJIDUpdateRequested(std::vector<JID>(1, jid)); } void UserSearchController::handleAvatarChanged(const JID& jid) { handleJIDUpdateRequested(std::vector<JID>(1, jid)); } void UserSearchController::handlePresenceChanged(Presence::ref presence) { handleJIDUpdateRequested(std::vector<JID>(1, presence->getFrom().toBare())); } void UserSearchController::handleJIDUpdateRequested(const std::vector<JID>& jids) { if (window_) { std::vector<Contact> updates; foreach(const JID& jid, jids) { updates.push_back(convertJIDtoContact(jid)); } window_->updateContacts(updates); } } +void UserSearchController::handleJIDAddRequested(const std::vector<JID>& jids) { + std::vector<Contact> contacts; + foreach(const JID& jid, jids) { + contacts.push_back(convertJIDtoContact(jid)); + } + window_->addContacts(contacts); +} + Contact UserSearchController::convertJIDtoContact(const JID& jid) { Contact contact; contact.jid = jid; // name lookup boost::optional<XMPPRosterItem> rosterItem = rosterController_->getItem(jid); if (rosterItem && !rosterItem->getName().empty()) { contact.name = rosterItem->getName(); } else { VCard::ref vcard = vcardManager_->getVCard(jid); if (vcard && !vcard->getFullName().empty()) { contact.name = vcard->getFullName(); } else { contact.name = jid.toString(); } } // presence lookup Presence::ref presence = presenceOracle_->getHighestPriorityPresence(jid); if (presence) { contact.statusType = presence->getShow(); } else { contact.statusType = StatusShow::None; } // avatar lookup contact.avatarPath = avatarManager_->getAvatarPath(jid); return contact; } void UserSearchController::handleDiscoWalkFinished() { window_->setServerSupportsSearch(false); endDiscoWalker(); } void UserSearchController::initializeUserWindow() { if (!window_) { UserSearchWindow::Type windowType = UserSearchWindow::AddContact; switch(type_) { case AddContact: windowType = UserSearchWindow::AddContact; break; case StartChat: windowType = UserSearchWindow::ChatToContact; break; case InviteToChat: windowType = UserSearchWindow::InviteToChat; break; } window_ = factory_->createUserSearchWindow(windowType, 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_->onContactSuggestionsRequested.connect(boost::bind(&UserSearchController::handleContactSuggestionsRequested, this, _1)); window_->onJIDUpdateRequested.connect(boost::bind(&UserSearchController::handleJIDUpdateRequested, this, _1)); + window_->onJIDAddRequested.connect(boost::bind(&UserSearchController::handleJIDAddRequested, this, _1)); window_->setSelectedService(JID(jid_.getDomain())); window_->clear(); } } } diff --git a/Swift/Controllers/Chat/UserSearchController.h b/Swift/Controllers/Chat/UserSearchController.h index 21cad5e..fc4c8e9 100644 --- a/Swift/Controllers/Chat/UserSearchController.h +++ b/Swift/Controllers/Chat/UserSearchController.h @@ -1,89 +1,90 @@ /* - * 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 <boost/shared_ptr.hpp> #include <map> #include <vector> #include <Swiften/Base/boost_bsignals.h> #include <Swiften/Elements/SearchPayload.h> #include <string> #include <Swiften/JID/JID.h> #include <Swiften/Elements/DiscoInfo.h> #include <Swiften/Elements/DiscoItems.h> #include <Swiften/Elements/ErrorPayload.h> #include <Swiften/Elements/VCard.h> #include <Swiften/Elements/Presence.h> namespace Swift { class UIEventStream; class UIEvent; class UserSearchWindow; class UserSearchWindowFactory; class IQRouter; class DiscoServiceWalker; class RosterController; class VCardManager; class ContactSuggester; class AvatarManager; class PresenceOracle; class Contact; class UserSearchResult { public: UserSearchResult(const JID& jid, const std::map<std::string, std::string>& fields) : jid_(jid), fields_(fields) {} const JID& getJID() const {return jid_;} const std::map<std::string, std::string>& getFields() const {return fields_;} private: JID jid_; std::map<std::string, std::string> fields_; }; class UserSearchController { public: enum Type {AddContact, StartChat, InviteToChat}; UserSearchController(Type type, const JID& jid, UIEventStream* uiEventStream, VCardManager* vcardManager, UserSearchWindowFactory* userSearchWindowFactory, IQRouter* iqRouter, RosterController* rosterController, ContactSuggester* contactSuggester, AvatarManager* avatarManager, PresenceOracle* presenceOracle); ~UserSearchController(); UserSearchWindow* getUserSearchWindow(); void setCanInitiateImpromptuMUC(bool supportsImpromptu); private: void handleUIEvent(boost::shared_ptr<UIEvent> event); void handleFormRequested(const JID& service); void handleDiscoServiceFound(const JID& jid, boost::shared_ptr<DiscoInfo> info); void handleDiscoWalkFinished(); 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 handleContactSuggestionsRequested(std::string text); void handleVCardChanged(const JID& jid, VCard::ref vcard); void handleAvatarChanged(const JID& jid); void handlePresenceChanged(Presence::ref presence); void handleJIDUpdateRequested(const std::vector<JID>& jids); + void handleJIDAddRequested(const std::vector<JID>& jids); Contact convertJIDtoContact(const JID& jid); void endDiscoWalker(); void initializeUserWindow(); private: Type type_; JID jid_; JID suggestionsJID_; UIEventStream* uiEventStream_; VCardManager* vcardManager_; UserSearchWindowFactory* factory_; IQRouter* iqRouter_; RosterController* rosterController_; UserSearchWindow* window_; DiscoServiceWalker* discoWalker_; ContactSuggester* contactSuggester_; AvatarManager* avatarManager_; PresenceOracle* presenceOracle_; }; } |
Swift