From ad7d00c25b74d212457fa599861c5583e79e7c13 Mon Sep 17 00:00:00 2001
From: Catalin Badea <catalin.badea392@gmail.com>
Date: Tue, 26 Jun 2012 12:51:15 +0300
Subject: Added SqliteManager to build. not working


diff --git a/Swift/Controllers/Chat/ChatControllerBase.cpp b/Swift/Controllers/Chat/ChatControllerBase.cpp
index 75c6c71..bf39216 100644
--- a/Swift/Controllers/Chat/ChatControllerBase.cpp
+++ b/Swift/Controllers/Chat/ChatControllerBase.cpp
@@ -131,8 +131,9 @@ void ChatControllerBase::handleSendMessageRequest(const std::string &body, bool
 		}
 	}
 	preSendMessageRequest(message);
+
+	boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
 	if (useDelayForLatency_) {
-		boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
 		message->addPayload(boost::make_shared<Delay>(now, selfJID_));
 	}
 	if (isCorrectionMessage) {
@@ -142,6 +143,9 @@ void ChatControllerBase::handleSendMessageRequest(const std::string &body, bool
 	stanzaChannel_->sendMessage(message);
 	postSendMessage(message->getBody(), boost::dynamic_pointer_cast<Stanza>(message));
 	onActivity(message->getBody());
+
+	// log message
+	historyController_->addMessage(getBaseJID(), selfJID_, toJID_, body, now);
 }
 
 void ChatControllerBase::handleSecurityLabelsCatalogResponse(boost::shared_ptr<SecurityLabelsCatalog> catalog, ErrorPayload::ref error) {
@@ -248,6 +252,8 @@ void ChatControllerBase::handleIncomingMessage(boost::shared_ptr<MessageEvent> m
 		}
 		else {
 			lastMessagesUIID_[from] = addMessage(body, senderDisplayNameFromMessage(from), isIncomingMessageFromMe(message), label, std::string(avatarManager_->getAvatarPath(from).string()), timeStamp);
+			// void HistoryController::addMessage(const JID& baseJID, const JID& fromJID, const JID& toJID, std::string messageBody, boost::posix_time::ptime timeStamp) {
+			historyController_->addMessage(getBaseJID(), from, message->getTo(), body, timeStamp);
 		}
 	}
 	chatWindow_->show();
diff --git a/Swift/Controllers/HistoryController.cpp b/Swift/Controllers/HistoryController.cpp
index f04fceb..a19e321 100644
--- a/Swift/Controllers/HistoryController.cpp
+++ b/Swift/Controllers/HistoryController.cpp
@@ -5,9 +5,20 @@
  */
 
 #include <Swift/Controllers/HistoryController.h>
-
-#include <Swift/Controllers/UIInterfaces/HistoryWindowFactory.h>
-#include <Swift/Controllers/UIEvents/RequestHistoryUIEvent.h>
+#include <Swiften/History/SQLiteHistoryManager.h>
 
 namespace Swift {
+	HistoryController::HistoryController() : remoteArchiveSupported_(false) {
+		std::string file("testDB.db");
+		localHistory_ = new SQLiteHistoryManager(file);
+	}
+
+	HistoryController::~HistoryController() {
+		delete localHistory_;
+	}
+
+	void HistoryController::addMessage(const JID& baseJID, const JID& fromJID, const JID& toJID, std::string messageBody, boost::posix_time::ptime timeStamp) {
+		std::cout << baseJID << " " << fromJID << " " << toJID << " " << messageBody << " " << to_simple_string(timeStamp);
+	}
+
 }
diff --git a/Swift/Controllers/HistoryController.h b/Swift/Controllers/HistoryController.h
index dedf840..9949c19 100644
--- a/Swift/Controllers/HistoryController.h
+++ b/Swift/Controllers/HistoryController.h
@@ -7,9 +7,21 @@
 #pragma once
 
 #include <Swiften/JID/JID.h>
+#include <boost/date_time/posix_time/posix_time.hpp>
 
 namespace Swift {
+	class HistoryManager;
+	class JID;
 
 	class HistoryController {
+		public:
+			HistoryController();
+			~HistoryController();
+
+			void addMessage(const JID& baseJID, const JID& fromJID, const JID& toJID, std::string messageBody, boost::posix_time::ptime timeStamp);
+
+		private:
+			HistoryManager* localHistory_;
+			bool remoteArchiveSupported_;
 	};
 }
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index 2011f63..295ad3e 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -198,6 +198,7 @@ MainController::~MainController() {
 	delete fileTransferListController_;
 	delete xmlConsoleController_;
 	delete historyController_;
+	delete historyViewController_;
 	delete xmppURIController_;
 	delete soundEventController_;
 	delete systemTrayController_;
diff --git a/Swiften/History/SConscript b/Swiften/History/SConscript
index 9c2a9d6..975f839 100644
--- a/Swiften/History/SConscript
+++ b/Swiften/History/SConscript
@@ -1,11 +1,11 @@
 Import("swiften_env")
 
-#myenv = swiften_env.Clone()
-#if myenv["target"] == "native":
-#   myenv.MergeFlags(swiften_env.get("SQLITE_FLAGS", {}))
-#
-#objects = myenv.SwiftenObject([
-#			"HistoryManager.cpp",
-#			"SQLiteHistoryManager.cpp",
-#		])
-#swiften_env.Append(SWIFTEN_OBJECTS = [objects])
+myenv = swiften_env.Clone()
+if myenv["target"] == "native":
+   myenv.MergeFlags(swiften_env.get("SQLITE_FLAGS", {}))
+
+objects = myenv.SwiftenObject([
+			"HistoryManager.cpp",
+			"SQLiteHistoryManager.cpp",
+		])
+swiften_env.Append(SWIFTEN_OBJECTS = [objects])
diff --git a/Swiften/History/SQLiteHistoryManager.cpp b/Swiften/History/SQLiteHistoryManager.cpp
index 3b65f62..a24dec2 100644
--- a/Swiften/History/SQLiteHistoryManager.cpp
+++ b/Swiften/History/SQLiteHistoryManager.cpp
@@ -10,17 +10,12 @@
 #include <sqlite3.h>
 #include <Swiften/History/SQLiteHistoryManager.h>
 
-namespace {
-
-inline Swift::std::string getEscapedString(const Swift::std::string& s) {
-	Swift::std::string result(s);
-	result.replaceAll('\'', Swift::std::string("\\'"));
+inline std::string getEscapedString(const std::string& s) {
+	std::string result(s);
+	// result.replaceAll('\'', std::string("\\'"));
 	return result;
 }
 
-}
-
-
 namespace Swift {
 
 SQLiteHistoryManager::SQLiteHistoryManager(const std::string& file) : db_(0) {
-- 
cgit v0.10.2-6-g49f6