From ed8990c5ee4f54d63e88b6bad28356d0c032a8c3 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Sun, 17 Jan 2010 00:17:11 +0000
Subject: Preparation. for /me.

QtUI's implementation isn't done yet.

diff --git a/Swift/Controllers/ChatController.cpp b/Swift/Controllers/ChatController.cpp
index 90e5567..c4f45d8 100644
--- a/Swift/Controllers/ChatController.cpp
+++ b/Swift/Controllers/ChatController.cpp
@@ -3,8 +3,8 @@
 #include <boost/bind.hpp>
 
 #include "Swiften/Avatars/AvatarManager.h"
-#include "Swift/Controllers/ChatWindow.h"
-#include "Swift/Controllers/ChatWindowFactory.h"
+#include "Swift/Controllers/UIInterfaces/ChatWindow.h"
+#include "Swift/Controllers/UIInterfaces/ChatWindowFactory.h"
 #include "Swift/Controllers/NickResolver.h"
 
 namespace Swift {
@@ -33,7 +33,7 @@ void ChatController::preHandleIncomingMessage(boost::shared_ptr<Message> message
 }
 
 void ChatController::postSendMessage(const String& body) {
-	chatWindow_->addMessage(body, "me", true, labelsEnabled_ ? chatWindow_->getSelectedSecurityLabel() : boost::optional<SecurityLabel>(), String(avatarManager_->getAvatarPath(selfJID_).string()));
+	addMessage(body, "me", true, labelsEnabled_ ? chatWindow_->getSelectedSecurityLabel() : boost::optional<SecurityLabel>(), String(avatarManager_->getAvatarPath(selfJID_).string()));
 }
 
 String ChatController::senderDisplayNameFromMessage(const JID& from) {
diff --git a/Swift/Controllers/ChatControllerBase.cpp b/Swift/Controllers/ChatControllerBase.cpp
index 2b873f1..3e1ce5e 100644
--- a/Swift/Controllers/ChatControllerBase.cpp
+++ b/Swift/Controllers/ChatControllerBase.cpp
@@ -5,8 +5,8 @@
 
 #include "Swiften/Client/StanzaChannel.h"
 #include "Swiften/Base/foreach.h"
-#include "Swift/Controllers/ChatWindow.h"
-#include "Swift/Controllers/ChatWindowFactory.h"
+#include "Swift/Controllers/UIInterfaces/ChatWindow.h"
+#include "Swift/Controllers/UIInterfaces/ChatWindowFactory.h"
 #include "Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h"
 #include "Swiften/Avatars/AvatarManager.h"
 
@@ -89,6 +89,14 @@ void ChatControllerBase::activateChatWindow() {
 	chatWindow_->activate();
 }
 
+void ChatControllerBase::addMessage(const String& message, const String& senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath) {
+	if (message.beginsWith("/me ")) {
+		chatWindow_->addMessage(message, senderName, senderIsSelf, label, avatarPath);
+	} else {
+		chatWindow_->addAction(message, senderName, senderIsSelf, label, avatarPath);
+	}
+}
+
 void ChatControllerBase::handleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent) {
 	unreadMessages_.push_back(messageEvent);
 	chatWindow_->setUnreadMessageCount(unreadMessages_.size());
@@ -105,7 +113,7 @@ void ChatControllerBase::handleIncomingMessage(boost::shared_ptr<MessageEvent> m
 		boost::shared_ptr<SecurityLabel> label = message->getPayload<SecurityLabel>();
 		boost::optional<SecurityLabel> maybeLabel = label ? boost::optional<SecurityLabel>(*label) : boost::optional<SecurityLabel>();
 		JID from = message->getFrom();
-		chatWindow_->addMessage(body, senderDisplayNameFromMessage(from), isIncomingMessageFromMe(message), maybeLabel, String(avatarManager_->getAvatarPath(from).string()));
+		addMessage(body, senderDisplayNameFromMessage(from), isIncomingMessageFromMe(message), maybeLabel, String(avatarManager_->getAvatarPath(from).string()));
 	}
 }
 
diff --git a/Swift/Controllers/ChatControllerBase.h b/Swift/Controllers/ChatControllerBase.h
index c780789..abf0116 100644
--- a/Swift/Controllers/ChatControllerBase.h
+++ b/Swift/Controllers/ChatControllerBase.h
@@ -30,6 +30,7 @@ namespace Swift {
 			void activateChatWindow();
 			void setAvailableServerFeatures(boost::shared_ptr<DiscoInfo> info);
 			void handleIncomingMessage(boost::shared_ptr<MessageEvent> message);
+			void addMessage(const String& message, const String& senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath);
 			void setEnabled(bool enabled);
 			void setToJID(const JID& jid) {toJID_ = jid;};
 		protected:
diff --git a/Swift/Controllers/ChatWindow.h b/Swift/Controllers/ChatWindow.h
deleted file mode 100644
index db1e9e3..0000000
--- a/Swift/Controllers/ChatWindow.h
+++ /dev/null
@@ -1,43 +0,0 @@
-#ifndef SWIFTEN_CHATWINDOW_H
-#define SWIFTEN_CHATWINDOW_H
-
-#include <boost/optional.hpp>
-#include <boost/signals.hpp>
-#include <boost/shared_ptr.hpp>
-#include <vector>
-
-#include "Swiften/Base/String.h"
-#include "Swiften/Elements/SecurityLabel.h"
-
-namespace Swift {
-	class AvatarManager;
-	class TreeWidget;
-
-	class ChatWindow {
-		public:
-			ChatWindow() {}
-			virtual ~ChatWindow() {};
-
-			virtual void addMessage(const String& message, const String& senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath) = 0;
-			virtual void addSystemMessage(const String& message) = 0;
-			virtual void addErrorMessage(const String& message) = 0;
-
-			virtual void setName(const String& name) = 0;
-			virtual void show() = 0;
-			virtual void activate() = 0;
-			virtual void setAvailableSecurityLabels(const std::vector<SecurityLabel>& labels) = 0;
-			virtual void setSecurityLabelsEnabled(bool enabled) = 0;
-			virtual void setUnreadMessageCount(int count) = 0;
-			virtual void convertToMUC() = 0;
-			virtual TreeWidget *getTreeWidget() = 0;
-			virtual void setSecurityLabelsError() = 0;
-			virtual SecurityLabel getSelectedSecurityLabel() = 0;
-			virtual void setInputEnabled(bool enabled) = 0;
-
-			boost::signal<void ()> onClosed;
-			boost::signal<void ()> onAllMessagesRead;
-			boost::signal<void (const String&)> onSendMessageRequest;
-	};
-}
-#endif
-
diff --git a/Swift/Controllers/ChatWindowFactory.h b/Swift/Controllers/ChatWindowFactory.h
deleted file mode 100644
index c55ddba..0000000
--- a/Swift/Controllers/ChatWindowFactory.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef SWIFTEN_CHATWINDOWFACTORY_H
-#define SWIFTEN_CHATWINDOWFACTORY_H
-
-#include "Swiften/JID/JID.h"
-
-namespace Swift {
-	class ChatWindow;
-
-	class ChatWindowFactory {
-		public:
-			virtual ~ChatWindowFactory() {};
-			/**
-			 * Transfers ownership of result.
-			 */
-			virtual ChatWindow* createChatWindow(const JID &contact) = 0;
-
-	};
-}
-#endif
-
diff --git a/Swift/Controllers/MUCController.cpp b/Swift/Controllers/MUCController.cpp
index 4d0acca..c85fffa 100644
--- a/Swift/Controllers/MUCController.cpp
+++ b/Swift/Controllers/MUCController.cpp
@@ -3,8 +3,8 @@
 #include <boost/bind.hpp>
 
 #include "Swiften/Base/foreach.h"
-#include "Swift/Controllers/ChatWindow.h"
-#include "Swift/Controllers/ChatWindowFactory.h"
+#include "Swift/Controllers/UIInterfaces/ChatWindow.h"
+#include "Swift/Controllers/UIInterfaces/ChatWindowFactory.h"
 #include "Swiften/Avatars/AvatarManager.h"
 #include "Swiften/MUC/MUC.h"
 #include "Swiften/Client/StanzaChannel.h"
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index 946b7d0..3fd0764 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -8,7 +8,7 @@
 #include "Swiften/Application/Application.h"
 #include "Swiften/Application/ApplicationMessageDisplay.h"
 #include "Swift/Controllers/ChatController.h"
-#include "Swift/Controllers/ChatWindowFactory.h"
+#include "Swift/Controllers/UIInterfaces/ChatWindowFactory.h"
 #include "Swift/Controllers/ChatsManager.h"
 #include "Swift/Controllers/EventController.h"
 #include "Swift/Controllers/UIInterfaces/LoginWindow.h"
diff --git a/Swift/Controllers/UIInterfaces/ChatWindow.h b/Swift/Controllers/UIInterfaces/ChatWindow.h
new file mode 100644
index 0000000..59c3152
--- /dev/null
+++ b/Swift/Controllers/UIInterfaces/ChatWindow.h
@@ -0,0 +1,44 @@
+#ifndef SWIFTEN_CHATWINDOW_H
+#define SWIFTEN_CHATWINDOW_H
+
+#include <boost/optional.hpp>
+#include <boost/signals.hpp>
+#include <boost/shared_ptr.hpp>
+#include <vector>
+
+#include "Swiften/Base/String.h"
+#include "Swiften/Elements/SecurityLabel.h"
+
+namespace Swift {
+	class AvatarManager;
+	class TreeWidget;
+
+	class ChatWindow {
+		public:
+			ChatWindow() {}
+			virtual ~ChatWindow() {};
+
+			virtual void addMessage(const String& message, const String& senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath) = 0;
+			virtual void addAction(const String& message, const String& senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath) = 0;
+			virtual void addSystemMessage(const String& message) = 0;
+			virtual void addErrorMessage(const String& message) = 0;
+
+			virtual void setName(const String& name) = 0;
+			virtual void show() = 0;
+			virtual void activate() = 0;
+			virtual void setAvailableSecurityLabels(const std::vector<SecurityLabel>& labels) = 0;
+			virtual void setSecurityLabelsEnabled(bool enabled) = 0;
+			virtual void setUnreadMessageCount(int count) = 0;
+			virtual void convertToMUC() = 0;
+			virtual TreeWidget *getTreeWidget() = 0;
+			virtual void setSecurityLabelsError() = 0;
+			virtual SecurityLabel getSelectedSecurityLabel() = 0;
+			virtual void setInputEnabled(bool enabled) = 0;
+
+			boost::signal<void ()> onClosed;
+			boost::signal<void ()> onAllMessagesRead;
+			boost::signal<void (const String&)> onSendMessageRequest;
+	};
+}
+#endif
+
diff --git a/Swift/Controllers/UIInterfaces/ChatWindowFactory.h b/Swift/Controllers/UIInterfaces/ChatWindowFactory.h
new file mode 100644
index 0000000..c55ddba
--- /dev/null
+++ b/Swift/Controllers/UIInterfaces/ChatWindowFactory.h
@@ -0,0 +1,20 @@
+#ifndef SWIFTEN_CHATWINDOWFACTORY_H
+#define SWIFTEN_CHATWINDOWFACTORY_H
+
+#include "Swiften/JID/JID.h"
+
+namespace Swift {
+	class ChatWindow;
+
+	class ChatWindowFactory {
+		public:
+			virtual ~ChatWindowFactory() {};
+			/**
+			 * Transfers ownership of result.
+			 */
+			virtual ChatWindow* createChatWindow(const JID &contact) = 0;
+
+	};
+}
+#endif
+
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index 831dbfd..e982b21 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -172,6 +172,10 @@ void QtChatWindow::addMessage(const String &message, const String &senderName, b
 	previousMessageWasSystem_ = false;
 }
 
+void QtChatWindow::addAction(const String &message, const String &senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath) {
+	addMessage(message, senderName, senderIsSelf, label, avatarPath);
+}
+
 void QtChatWindow::addErrorMessage(const String& errorMessage) {
 	if (isWidgetSelected()) {
 		onAllMessagesRead();
diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h
index b743aaf..e147fb8 100644
--- a/Swift/QtUI/QtChatWindow.h
+++ b/Swift/QtUI/QtChatWindow.h
@@ -1,7 +1,7 @@
 #ifndef SWIFT_QtChatWindow_H
 #define SWIFT_QtChatWindow_H
 
-#include "Swift/Controllers/ChatWindow.h"
+#include "Swift/Controllers/UIInterfaces/ChatWindow.h"
 
 #include "QtTabbable.h"
 
@@ -21,6 +21,7 @@ namespace Swift {
 			QtChatWindow(const QString &contact, QtTreeWidgetFactory* treeWidgetFactory);
 			~QtChatWindow();
 			void addMessage(const String &message, const String &senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath);
+			void addAction(const String &message, const String &senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath);
 			void addSystemMessage(const String& message);
 			void addErrorMessage(const String& errorMessage);
 			void show();
diff --git a/Swift/QtUI/QtChatWindowFactory.h b/Swift/QtUI/QtChatWindowFactory.h
index 0c8a092..51db3db 100644
--- a/Swift/QtUI/QtChatWindowFactory.h
+++ b/Swift/QtUI/QtChatWindowFactory.h
@@ -1,7 +1,7 @@
 #ifndef SWIFT_QtChatWindowFactory_H
 #define SWIFT_QtChatWindowFactory_H
 
-#include "Swift/Controllers/ChatWindowFactory.h"
+#include "Swift/Controllers/UIInterfaces/ChatWindowFactory.h"
 #include "Swiften/JID/JID.h"
 #include "QtSettingsProvider.h"
 
-- 
cgit v0.10.2-6-g49f6