From e2fd68762f2bca98e415da2a287c523042ed36a8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Mon, 4 Jul 2011 20:23:10 +0200
Subject: Moving some ChatList logic to Controllers.


diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp
index ef85107..31764f7 100644
--- a/Swift/Controllers/Chat/ChatsManager.cpp
+++ b/Swift/Controllers/Chat/ChatsManager.cpp
@@ -76,7 +76,11 @@ ChatsManager::ChatsManager(
 	profileSettings_ = settings;
 	presenceOracle_->onPresenceChange.connect(boost::bind(&ChatsManager::handlePresenceChange, this, _1));
 	uiEventConnection_ = uiEventStream_->onUIEvent.connect(boost::bind(&ChatsManager::handleUIEvent, this, _1));
+
 	chatListWindow_ = chatListWindowFactory->createChatListWindow(uiEventStream_);
+	chatListWindow_->onMUCBookmarkActivated.connect(boost::bind(&ChatsManager::handleMUCBookmarkActivated, this, _1));
+	chatListWindow_->onRecentActivated.connect(boost::bind(&ChatsManager::handleRecentActivated, this, _1));
+
 	joinMUCWindow_ = NULL;
 	mucSearchController_ = new MUCSearchController(jid_, mucSearchWindowFactory, iqRouter, settings);
 	mucSearchController_->onMUCSelected.connect(boost::bind(&ChatsManager::handleMUCSelectedAfterSearch, this, _1));
@@ -404,5 +408,13 @@ void ChatsManager::handleMUCSelectedAfterSearch(const JID& muc) {
 	}
 }
 
+void ChatsManager::handleMUCBookmarkActivated(const MUCBookmark& mucBookmark) {
+	uiEventStream_->send(boost::make_shared<JoinMUCUIEvent>(mucBookmark.getRoom(), mucBookmark.getNick()));
+}
+
+void ChatsManager::handleRecentActivated(const ChatListWindow::Chat& chat) {
+	uiEventStream_->send(boost::make_shared<RequestChatUIEvent>(chat.jid));
+}
+
 
 }
diff --git a/Swift/Controllers/Chat/ChatsManager.h b/Swift/Controllers/Chat/ChatsManager.h
index 170e87c..936f5a8 100644
--- a/Swift/Controllers/Chat/ChatsManager.h
+++ b/Swift/Controllers/Chat/ChatsManager.h
@@ -51,6 +51,7 @@ namespace Swift {
 			void setOnline(bool enabled);
 			void setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info);
 			void handleIncomingMessage(boost::shared_ptr<Message> message);
+
 		private:
 			void handleChatRequest(const std::string& contact);
 			void handleJoinMUCRequest(const JID& muc, const boost::optional<std::string>& nick, bool autoJoin);
@@ -70,10 +71,15 @@ namespace Swift {
 			void loadRecents();
 			void saveRecents();
 			void handleChatMadeRecent();
+			void handleMUCBookmarkActivated(const MUCBookmark&);
+			void handleRecentActivated(const ChatListWindow::Chat&);
+
 			ChatController* getChatControllerOrFindAnother(const JID &contact);
 			ChatController* createNewChatController(const JID &contact);
 			ChatController* getChatControllerOrCreate(const JID &contact);
 			ChatController* getChatControllerIfExists(const JID &contact);
+
+		private:
 			std::map<JID, MUCController*> mucControllers_;
 			std::map<JID, ChatController*> chatControllers_;
 			EventController* eventController_;
diff --git a/Swift/Controllers/UIInterfaces/ChatListWindow.h b/Swift/Controllers/UIInterfaces/ChatListWindow.h
index a52f24d..ce75ae8 100644
--- a/Swift/Controllers/UIInterfaces/ChatListWindow.h
+++ b/Swift/Controllers/UIInterfaces/ChatListWindow.h
@@ -10,6 +10,8 @@
 #include <boost/shared_ptr.hpp>
 #include <Swiften/MUC/MUCBookmark.h>
 
+#include "Swiften/Base/boost_bsignals.h"
+
 namespace Swift {
 	class ChatListWindow {
 		public:
@@ -31,5 +33,8 @@ namespace Swift {
 			virtual void removeMUCBookmark(const MUCBookmark& bookmark) = 0;
 			virtual void setRecents(const std::list<Chat>& recents) = 0;
 			virtual void clearBookmarks() = 0;
+
+			boost::signal<void (const MUCBookmark&)> onMUCBookmarkActivated;
+			boost::signal<void (const Chat&)> onRecentActivated;
 	};
 }
diff --git a/Swift/QtUI/ChatList/QtChatListWindow.cpp b/Swift/QtUI/ChatList/QtChatListWindow.cpp
index d71563d..7ef6ae5 100644
--- a/Swift/QtUI/ChatList/QtChatListWindow.cpp
+++ b/Swift/QtUI/ChatList/QtChatListWindow.cpp
@@ -71,24 +71,15 @@ void QtChatListWindow::setupContextMenus() {
 
 void QtChatListWindow::handleItemActivated(const QModelIndex& index) {
 	ChatListItem* item = model_->getItemForIndex(index);
-	ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(item);
-	if (bookmarksEnabled_ && mucItem) {
-		boost::shared_ptr<UIEvent> event(new JoinMUCUIEvent(mucItem->getBookmark().getRoom(), mucItem->getBookmark().getNick()));
-		eventStream_->send(event);
-	}
-	ChatListRecentItem* recentItem = dynamic_cast<ChatListRecentItem*>(item);
-	if (recentItem) {
-		boost::shared_ptr<UIEvent> event;
-		if (recentItem->getChat().isMUC) {
-			if (!bookmarksEnabled_) {
-				return;
-			}
-			return;
+	if (ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(item)) {
+		if (bookmarksEnabled_) {
+			onMUCBookmarkActivated(mucItem->getBookmark());
 		}
-		else {
-			event = boost::shared_ptr<UIEvent>(new RequestChatUIEvent(recentItem->getChat().jid));
+	}
+	else if (ChatListRecentItem* recentItem = dynamic_cast<ChatListRecentItem*>(item)) {
+		if (!recentItem->getChat().isMUC || bookmarksEnabled_) {
+			onRecentActivated(recentItem->getChat());
 		}
-		eventStream_->send(event);
 	}
 }
 
-- 
cgit v0.10.2-6-g49f6