diff options
author | Kevin Smith <git@kismith.co.uk> | 2010-03-29 15:03:13 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2010-03-29 15:03:13 (GMT) |
commit | cf664dd8baa1accc355ec4a727899a9f68f68ed5 (patch) | |
tree | ca6e8b07e7beb09e9c6e6374ddbef225be06feb5 | |
parent | 1803d2e9169c1fae676213d2eaead86babc02a4c (diff) | |
download | swift-contrib-cf664dd8baa1accc355ec4a727899a9f68f68ed5.zip swift-contrib-cf664dd8baa1accc355ec4a727899a9f68f68ed5.tar.bz2 |
Request bookmarks at login.
-rw-r--r-- | Swift/Controllers/MainController.cpp | 2 | ||||
-rw-r--r-- | Swift/QtUI/QtMainWindowFactory.cpp | 10 | ||||
-rw-r--r-- | Swiften/MUC/MUCBookmarkManager.cpp | 36 | ||||
-rw-r--r-- | Swiften/MUC/MUCBookmarkManager.h | 5 |
4 files changed, 46 insertions, 7 deletions
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index ee11b70..d042115 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -135,8 +135,6 @@ void MainController::handleConnected() { presenceOracle_ = new PresenceOracle(client_); nickResolver_ = new NickResolver(xmppRoster_); lastSentPresence_ = boost::shared_ptr<Presence>(); - - avatarManager_ = new AvatarManager(client_, client_, avatarStorage_); diff --git a/Swift/QtUI/QtMainWindowFactory.cpp b/Swift/QtUI/QtMainWindowFactory.cpp index dc1949e..10b122a 100644 --- a/Swift/QtUI/QtMainWindowFactory.cpp +++ b/Swift/QtUI/QtMainWindowFactory.cpp @@ -9,13 +9,15 @@ QtMainWindowFactory::QtMainWindowFactory(QtTreeWidgetFactory *treeWidgetFactory) } MainWindow* QtMainWindowFactory::createMainWindow(UIEventStream* eventStream) { - QtMainWindow* window = new QtMainWindow(eventStream, treeWidgetFactory_); - lastWindow_ = window; - return window; + if (!lastWindow_) { + lastWindow_ = new QtMainWindow(eventStream, treeWidgetFactory_); + } + return lastWindow_; } MainWindow* QtMainWindowFactory::getLastCreatedWindow() { - return lastWindow_; + assert(lastWindow_); + return lastWindow_;; } } diff --git a/Swiften/MUC/MUCBookmarkManager.cpp b/Swiften/MUC/MUCBookmarkManager.cpp index f9295e2..c91612d 100644 --- a/Swiften/MUC/MUCBookmarkManager.cpp +++ b/Swiften/MUC/MUCBookmarkManager.cpp @@ -1,11 +1,47 @@ #include "MUCBookmarkManager.h" +#include <boost/bind.hpp> + #include "Swiften/Queries/IQRouter.h" + namespace Swift { MUCBookmarkManager::MUCBookmarkManager(IQRouter* iqRouter) { iqRouter_ = iqRouter; + boost::shared_ptr<GetPrivateStorageRequest<Storage> > request(new GetPrivateStorageRequest<Storage>(iqRouter_)); + request->onResponse.connect(boost::bind(&MUCBookmarkManager::handleBookmarksReceived, this, _1, _2)); + request->send(); +} + +void MUCBookmarkManager::handleBookmarksReceived(boost::shared_ptr<Storage> payload, const boost::optional<ErrorPayload>& error) { + if (error) { + return; + } + std::vector<boost::shared_ptr<MUCBookmark> > newBookmarks; + foreach (Storage::Conference conference, payload->getConferences()) { + String name = (!conference.name.isEmpty()) ? conference.name : conference.jid.getNode(); + boost::shared_ptr<MUCBookmark> bookmark(new MUCBookmark(conference.jid, name)); + bookmark->setAutojoin(conference.autoJoin); + if (!conference.nick.isEmpty()) { + bookmark->setNick(conference.nick); + } + if (!conference.password.isEmpty()) { + bookmark->setPassword(conference.password); + } + newBookmarks.push_back(bookmark); + } + + //FIXME: This needs to be fixed before we start doing anything supporting updates + foreach (boost::shared_ptr<MUCBookmark> oldBookmark, bookmarks_) { + onBookmarkRemoved(oldBookmark); + } + + foreach (boost::shared_ptr<MUCBookmark> newBookmark, newBookmarks) { + onBookmarkAdded(newBookmark); + } + + } void MUCBookmarkManager::addBookmark(boost::shared_ptr<MUCBookmark> bookmark) { diff --git a/Swiften/MUC/MUCBookmarkManager.h b/Swiften/MUC/MUCBookmarkManager.h index ade2e3e..a74bb1e 100644 --- a/Swiften/MUC/MUCBookmarkManager.h +++ b/Swiften/MUC/MUCBookmarkManager.h @@ -4,8 +4,11 @@ #include <boost/shared_ptr.hpp> #include <boost/signals.hpp> +#include <boost/optional.hpp> #include "Swiften/MUC/MUCBookmark.h" +#include "Swiften/Elements/Storage.h" +#include "Swiften/Queries/Requests/GetPrivateStorageRequest.h" namespace Swift { class IQRouter; @@ -21,7 +24,7 @@ namespace Swift { boost::signal<void (boost::shared_ptr<MUCBookmark>)> onBookmarkAdded; boost::signal<void (boost::shared_ptr<MUCBookmark>)> onBookmarkRemoved; private: - + void handleBookmarksReceived(boost::shared_ptr<Storage> payload, const boost::optional<ErrorPayload>& error); std::vector<boost::shared_ptr<MUCBookmark> > bookmarks_; IQRouter* iqRouter_; }; |