summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/Chat/UserSearchController.cpp')
-rw-r--r--Swift/Controllers/Chat/UserSearchController.cpp60
1 files changed, 51 insertions, 9 deletions
diff --git a/Swift/Controllers/Chat/UserSearchController.cpp b/Swift/Controllers/Chat/UserSearchController.cpp
index 24f3724..ece897f 100644
--- a/Swift/Controllers/Chat/UserSearchController.cpp
+++ b/Swift/Controllers/Chat/UserSearchController.cpp
@@ -1,43 +1,50 @@
1/* 1/*
2 * Copyright (c) 2010-2014 Isode Limited. 2 * Copyright (c) 2010-2015 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
6 6
7#include <Swift/Controllers/Chat/UserSearchController.h> 7#include <Swift/Controllers/Chat/UserSearchController.h>
8 8
9#include <boost/bind.hpp> 9#include <boost/bind.hpp>
10#include <boost/shared_ptr.hpp> 10#include <boost/shared_ptr.hpp>
11#include <boost/smart_ptr/make_shared.hpp> 11#include <boost/smart_ptr/make_shared.hpp>
12 12
13#include <Swiften/Avatars/AvatarManager.h>
14#include <Swiften/Base/String.h>
13#include <Swiften/Base/foreach.h> 15#include <Swiften/Base/foreach.h>
16#include <Swiften/Disco/DiscoServiceWalker.h>
14#include <Swiften/Disco/GetDiscoInfoRequest.h> 17#include <Swiften/Disco/GetDiscoInfoRequest.h>
15#include <Swiften/Disco/GetDiscoItemsRequest.h> 18#include <Swiften/Disco/GetDiscoItemsRequest.h>
16#include <Swiften/Disco/DiscoServiceWalker.h>
17#include <Swiften/VCards/VCardManager.h>
18#include <Swiften/Presence/PresenceOracle.h> 19#include <Swiften/Presence/PresenceOracle.h>
19#include <Swiften/Avatars/AvatarManager.h> 20#include <Swiften/VCards/VCardManager.h>
21
20#include <Swift/Controllers/ContactEditController.h> 22#include <Swift/Controllers/ContactEditController.h>
23#include <Swift/Controllers/ContactSuggester.h>
21#include <Swift/Controllers/Intl.h> 24#include <Swift/Controllers/Intl.h>
22#include <Swift/Controllers/UIEvents/UIEventStream.h> 25#include <Swift/Controllers/ProfileSettingsProvider.h>
23#include <Swift/Controllers/UIEvents/RequestChatWithUserDialogUIEvent.h> 26#include <Swift/Controllers/Roster/RosterController.h>
24#include <Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h> 27#include <Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h>
28#include <Swift/Controllers/UIEvents/RequestChatWithUserDialogUIEvent.h>
25#include <Swift/Controllers/UIEvents/RequestInviteToMUCUIEvent.h> 29#include <Swift/Controllers/UIEvents/RequestInviteToMUCUIEvent.h>
30#include <Swift/Controllers/UIEvents/UIEventStream.h>
26#include <Swift/Controllers/UIInterfaces/UserSearchWindow.h> 31#include <Swift/Controllers/UIInterfaces/UserSearchWindow.h>
27#include <Swift/Controllers/UIInterfaces/UserSearchWindowFactory.h> 32#include <Swift/Controllers/UIInterfaces/UserSearchWindowFactory.h>
28#include <Swift/Controllers/Roster/RosterController.h>
29#include <Swift/Controllers/ContactSuggester.h>
30 33
31namespace Swift { 34namespace Swift {
32UserSearchController::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) { 35
36static const std::string SEARCHED_DIRECTORIES = "searchedDirectories";
37
38UserSearchController::UserSearchController(Type type, const JID& jid, UIEventStream* uiEventStream, VCardManager* vcardManager, UserSearchWindowFactory* factory, IQRouter* iqRouter, RosterController* rosterController, ContactSuggester* contactSuggester, AvatarManager* avatarManager, PresenceOracle* presenceOracle, ProfileSettingsProvider* settings) : type_(type), jid_(jid), uiEventStream_(uiEventStream), vcardManager_(vcardManager), factory_(factory), iqRouter_(iqRouter), rosterController_(rosterController), contactSuggester_(contactSuggester), avatarManager_(avatarManager), presenceOracle_(presenceOracle), settings_(settings) {
33 uiEventStream_->onUIEvent.connect(boost::bind(&UserSearchController::handleUIEvent, this, _1)); 39 uiEventStream_->onUIEvent.connect(boost::bind(&UserSearchController::handleUIEvent, this, _1));
34 vcardManager_->onVCardChanged.connect(boost::bind(&UserSearchController::handleVCardChanged, this, _1, _2)); 40 vcardManager_->onVCardChanged.connect(boost::bind(&UserSearchController::handleVCardChanged, this, _1, _2));
35 avatarManager_->onAvatarChanged.connect(boost::bind(&UserSearchController::handleAvatarChanged, this, _1)); 41 avatarManager_->onAvatarChanged.connect(boost::bind(&UserSearchController::handleAvatarChanged, this, _1));
36 presenceOracle_->onPresenceChange.connect(boost::bind(&UserSearchController::handlePresenceChanged, this, _1)); 42 presenceOracle_->onPresenceChange.connect(boost::bind(&UserSearchController::handlePresenceChanged, this, _1));
37 window_ = NULL; 43 window_ = NULL;
38 discoWalker_ = NULL; 44 discoWalker_ = NULL;
45 loadSavedDirectories();
39} 46}
40 47
41UserSearchController::~UserSearchController() { 48UserSearchController::~UserSearchController() {
42 endDiscoWalker(); 49 endDiscoWalker();
43 delete discoWalker_; 50 delete discoWalker_;
@@ -92,10 +99,11 @@ void UserSearchController::handleUIEvent(boost::shared_ptr<UIEvent> event) {
92 break; 99 break;
93 } 100 }
94 if (handle) { 101 if (handle) {
95 initializeUserWindow(); 102 initializeUserWindow();
96 window_->show(); 103 window_->show();
104 window_->addSavedServices(savedDirectories_);
97 if (addUserRequest) { 105 if (addUserRequest) {
98 const std::string& name = addUserRequest->getPredefinedName(); 106 const std::string& name = addUserRequest->getPredefinedName();
99 const JID& jid = addUserRequest->getPredefinedJID(); 107 const JID& jid = addUserRequest->getPredefinedJID();
100 if (!name.empty() && jid.isValid()) { 108 if (!name.empty() && jid.isValid()) {
101 window_->prepopulateJIDAndName(jid, name); 109 window_->prepopulateJIDAndName(jid, name);
@@ -157,10 +165,11 @@ void UserSearchController::handleFormResponse(boost::shared_ptr<SearchPayload> f
157 } 165 }
158 window_->setSearchFields(fields); 166 window_->setSearchFields(fields);
159} 167}
160 168
161void UserSearchController::handleSearch(boost::shared_ptr<SearchPayload> fields, const JID& jid) { 169void UserSearchController::handleSearch(boost::shared_ptr<SearchPayload> fields, const JID& jid) {
170 addToSavedDirectories(jid);
162 boost::shared_ptr<GenericRequest<SearchPayload> > searchRequest(new GenericRequest<SearchPayload>(IQ::Set, jid, fields, iqRouter_)); 171 boost::shared_ptr<GenericRequest<SearchPayload> > searchRequest(new GenericRequest<SearchPayload>(IQ::Set, jid, fields, iqRouter_));
163 searchRequest->onResponse.connect(boost::bind(&UserSearchController::handleSearchResponse, this, _1, _2)); 172 searchRequest->onResponse.connect(boost::bind(&UserSearchController::handleSearchResponse, this, _1, _2));
164 searchRequest->send(); 173 searchRequest->send();
165} 174}
166 175
@@ -339,6 +348,39 @@ void UserSearchController::initializeUserWindow() {
339 window_->setSelectedService(JID(jid_.getDomain())); 348 window_->setSelectedService(JID(jid_.getDomain()));
340 window_->clear(); 349 window_->clear();
341 } 350 }
342} 351}
343 352
353void UserSearchController::loadSavedDirectories() {
354 savedDirectories_.clear();
355 foreach (std::string stringItem, String::split(settings_->getStringSetting(SEARCHED_DIRECTORIES), '\n')) {
356 if(!stringItem.empty()) {
357 savedDirectories_.push_back(JID(stringItem));
358 }
359 }
360}
361
362void UserSearchController::addToSavedDirectories(const JID& jid) {
363 if (!jid.isValid()) {
364 return;
365 }
366
367 savedDirectories_.erase(std::remove(savedDirectories_.begin(), savedDirectories_.end(), jid), savedDirectories_.end());
368 savedDirectories_.insert(savedDirectories_.begin(), jid);
369
370 std::string collapsed;
371 int i = 0;
372 foreach (JID jidItem, savedDirectories_) {
373 if (i >= 15) {
374 break;
375 }
376 if (!collapsed.empty()) {
377 collapsed += "\n";
378 }
379 collapsed += jidItem.toString();
380 ++i;
381 }
382 settings_->storeString(SEARCHED_DIRECTORIES, collapsed);
383 window_->addSavedServices(savedDirectories_);
384}
385
344} 386}