diff options
author | Kevin Smith <git@kismith.co.uk> | 2010-11-16 23:16:54 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2010-11-16 23:22:13 (GMT) |
commit | 9c3d535b1dc82ff600862a1210993c362fda9b8e (patch) | |
tree | 76676afe8e4c70ffa88b98b4880862b3113902a6 /Swift/Controllers | |
parent | 2c5ef44b56d9c45254ea331a53fb6d8fe6efe7d1 (diff) | |
download | swift-contrib-9c3d535b1dc82ff600862a1210993c362fda9b8e.zip swift-contrib-9c3d535b1dc82ff600862a1210993c362fda9b8e.tar.bz2 |
Remember previous MUC service searches.
Resolves: #615
Release-Notes: The MUC Search will now remember previously searched services.
Diffstat (limited to 'Swift/Controllers')
-rw-r--r-- | Swift/Controllers/Chat/MUCSearchController.cpp | 36 | ||||
-rw-r--r-- | Swift/Controllers/Chat/MUCSearchController.h | 7 | ||||
-rw-r--r-- | Swift/Controllers/MainController.cpp | 2 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/MUCSearchWindow.h | 3 |
4 files changed, 45 insertions, 3 deletions
diff --git a/Swift/Controllers/Chat/MUCSearchController.cpp b/Swift/Controllers/Chat/MUCSearchController.cpp index 0cf02c7..e4592a9 100644 --- a/Swift/Controllers/Chat/MUCSearchController.cpp +++ b/Swift/Controllers/Chat/MUCSearchController.cpp @@ -21,12 +21,16 @@ namespace Swift { -MUCSearchController::MUCSearchController(const JID& jid, UIEventStream* uiEventStream, MUCSearchWindowFactory* factory, IQRouter* iqRouter) : jid_(jid) { +static const String SEARCHED_SERVICES = "searchedServices"; + +MUCSearchController::MUCSearchController(const JID& jid, UIEventStream* uiEventStream, MUCSearchWindowFactory* factory, IQRouter* iqRouter, SettingsProvider* settings) : jid_(jid) { iqRouter_ = iqRouter; + settings_ = settings; uiEventStream_ = uiEventStream; uiEventConnection_ = uiEventStream_->onUIEvent.connect(boost::bind(&MUCSearchController::handleUIEvent, this, _1)); window_ = NULL; factory_ = factory; + loadServices(); } MUCSearchController::~MUCSearchController() { @@ -39,6 +43,7 @@ void MUCSearchController::handleUIEvent(boost::shared_ptr<UIEvent> event) { if (!window_) { window_ = factory_->createMUCSearchWindow(uiEventStream_); window_->onAddService.connect(boost::bind(&MUCSearchController::handleAddService, this, _1, true)); + window_->addSavedServices(savedServices_); handleAddService(JID(jid_.getDomain()), true); } window_->setMUC(""); @@ -48,7 +53,36 @@ void MUCSearchController::handleUIEvent(boost::shared_ptr<UIEvent> event) { } } +void MUCSearchController::loadServices() { + savedServices_.clear(); + foreach (String stringItem, settings_->getStringSetting(SEARCHED_SERVICES).split('\n')) { + savedServices_.push_back(JID(stringItem)); + } +} + +void MUCSearchController::addAndSaveServices(const JID& jid) { + savedServices_.erase(std::remove(savedServices_.begin(), savedServices_.end(), jid), savedServices_.end()); + savedServices_.push_back(jid); + String collapsed; + bool storeThis = savedServices_.size() < 15; + foreach (JID jidItem, savedServices_) { + if (!storeThis) { + storeThis = true; + continue; + } + if (!collapsed.isEmpty()) { + collapsed += "\n"; + } + collapsed += jidItem.toString(); + } + settings_->storeString(SEARCHED_SERVICES, collapsed); + window_->addSavedServices(savedServices_); +} + void MUCSearchController::handleAddService(const JID& jid, bool userTriggered) { + if (userTriggered) { + addAndSaveServices(jid); + } if (std::find(services_.begin(), services_.end(), jid) != services_.end()) { if (!userTriggered) { /* No infinite recursion. (Some buggy servers do infinitely deep disco of themselves)*/ diff --git a/Swift/Controllers/Chat/MUCSearchController.h b/Swift/Controllers/Chat/MUCSearchController.h index 44b51d8..10988ad 100644 --- a/Swift/Controllers/Chat/MUCSearchController.h +++ b/Swift/Controllers/Chat/MUCSearchController.h @@ -17,6 +17,7 @@ #include "Swift/Controllers/UIEvents/UIEvent.h" #include "Swift/Controllers/Chat/MUCSearchController.h" +#include "Swift/Controllers/Settings/SettingsProvider.h" #include "Swiften/Elements/DiscoInfo.h" #include "Swiften/Elements/DiscoItems.h" #include "Swiften/Elements/ErrorPayload.h" @@ -85,7 +86,7 @@ namespace Swift { class MUCSearchController { public: - MUCSearchController(const JID& jid, UIEventStream* uiEventStream, MUCSearchWindowFactory* mucSearchWindowFactory, IQRouter* iqRouter); + MUCSearchController(const JID& jid, UIEventStream* uiEventStream, MUCSearchWindowFactory* mucSearchWindowFactory, IQRouter* iqRouter, SettingsProvider* settings); ~MUCSearchController(); private: void handleUIEvent(boost::shared_ptr<UIEvent> event); @@ -96,11 +97,15 @@ namespace Swift { void handleDiscoError(const JID& jid, const ErrorPayload& error); void removeService(const JID& jid); void refreshView(); + void loadServices(); + void addAndSaveServices(const JID& jid); UIEventStream* uiEventStream_; MUCSearchWindow* window_; MUCSearchWindowFactory* factory_; + SettingsProvider* settings_; boost::bsignals::scoped_connection uiEventConnection_; std::vector<JID> services_; + std::vector<JID> savedServices_; std::map<JID, MUCService> serviceDetails_; IQRouter* iqRouter_; JID jid_; diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index 0542fd6..49c4a23 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -242,7 +242,7 @@ void MainController::handleConnected() { client_->getDiscoManager()->setCapsNode(CLIENT_NODE); client_->getDiscoManager()->setDiscoInfo(discoInfo); - mucSearchController_ = new MUCSearchController(jid_, uiEventStream_, mucSearchWindowFactory_, client_->getIQRouter()); + mucSearchController_ = new MUCSearchController(jid_, uiEventStream_, mucSearchWindowFactory_, client_->getIQRouter(), settings_); } client_->requestRoster(); diff --git a/Swift/Controllers/UIInterfaces/MUCSearchWindow.h b/Swift/Controllers/UIInterfaces/MUCSearchWindow.h index 9a4b9b3..da54ded 100644 --- a/Swift/Controllers/UIInterfaces/MUCSearchWindow.h +++ b/Swift/Controllers/UIInterfaces/MUCSearchWindow.h @@ -8,6 +8,8 @@ #include "Swiften/Base/boost_bsignals.h" +#include <vector> + #include "Swiften/Base/String.h" #include "Swiften/JID/JID.h" @@ -23,6 +25,7 @@ namespace Swift { virtual void setMUC(const String& nick) = 0; virtual void clearList() = 0; virtual void addService(const MUCService& service) = 0; + virtual void addSavedServices(const std::vector<JID>& services) = 0; virtual void show() = 0; |