From cf664dd8baa1accc355ec4a727899a9f68f68ed5 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Mon, 29 Mar 2010 16:03:13 +0100 Subject: Request bookmarks at login. 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(); - - 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 + #include "Swiften/Queries/IQRouter.h" + namespace Swift { MUCBookmarkManager::MUCBookmarkManager(IQRouter* iqRouter) { iqRouter_ = iqRouter; + boost::shared_ptr > request(new GetPrivateStorageRequest(iqRouter_)); + request->onResponse.connect(boost::bind(&MUCBookmarkManager::handleBookmarksReceived, this, _1, _2)); + request->send(); +} + +void MUCBookmarkManager::handleBookmarksReceived(boost::shared_ptr payload, const boost::optional& error) { + if (error) { + return; + } + std::vector > newBookmarks; + foreach (Storage::Conference conference, payload->getConferences()) { + String name = (!conference.name.isEmpty()) ? conference.name : conference.jid.getNode(); + boost::shared_ptr 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 oldBookmark, bookmarks_) { + onBookmarkRemoved(oldBookmark); + } + + foreach (boost::shared_ptr newBookmark, newBookmarks) { + onBookmarkAdded(newBookmark); + } + + } void MUCBookmarkManager::addBookmark(boost::shared_ptr 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 #include +#include #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)> onBookmarkAdded; boost::signal)> onBookmarkRemoved; private: - + void handleBookmarksReceived(boost::shared_ptr payload, const boost::optional& error); std::vector > bookmarks_; IQRouter* iqRouter_; }; -- cgit v0.10.2-6-g49f6