summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCatalin Badea <catalin.badea392@gmail.com>2012-06-27 12:02:47 (GMT)
committerCătălin Badea <catalin.badea392@gmail.com>2012-08-11 15:52:56 (GMT)
commitfc40104bf6e6d915561f95015e0b5617d97880e4 (patch)
treebbe91142e4c4dfcdaf32d4041694a8834a6683d8
parent9f11ec4954b7c860623c799827e73c40e73acfac (diff)
downloadswift-contrib-fc40104bf6e6d915561f95015e0b5617d97880e4.zip
swift-contrib-fc40104bf6e6d915561f95015e0b5617d97880e4.tar.bz2
Log messages to the sqlite db and dump all messages in the history viewer
-rw-r--r--BuildTools/SCons/SConstruct30
-rw-r--r--Swift/Controllers/Chat/ChatControllerBase.cpp5
-rw-r--r--Swift/Controllers/HistoryController.cpp27
-rw-r--r--Swift/Controllers/HistoryController.h5
-rw-r--r--Swift/Controllers/HistoryViewController.cpp16
-rw-r--r--Swift/Controllers/HistoryViewController.h4
-rw-r--r--Swift/Controllers/MainController.cpp2
-rw-r--r--Swift/Controllers/UIInterfaces/HistoryWindow.h3
-rw-r--r--Swift/QtUI/QtHistoryWindow.cpp19
-rw-r--r--Swift/QtUI/QtHistoryWindow.h2
-rw-r--r--Swiften/History/HistoryMessage.h31
-rw-r--r--Swiften/History/SQLiteHistoryManager.cpp22
-rw-r--r--Swiften/SConscript2
13 files changed, 109 insertions, 59 deletions
diff --git a/BuildTools/SCons/SConstruct b/BuildTools/SCons/SConstruct
index cd7a25a..42dc36a 100644
--- a/BuildTools/SCons/SConstruct
+++ b/BuildTools/SCons/SConstruct
@@ -358,21 +358,21 @@ else :
env["LIBNATPMP_FLAGS"] = {}
# SQLite
-#sqlite_conf_env = conf_env.Clone()
-#sqlite_flags = {}
-#if env.get("sqlite_libdir", None) :
-# sqlite_flags["LIBPATH"] = [env["sqlite_libdir"]]
-#if env.get("sqlite_includedir", None) :
-# sqlite_flags["CPPPATH"] = [env["sqlite_includedir"]]
-#sqlite_conf_env.MergeFlags(sqlite_flags)
-#conf = Configure(sqlite_conf_env)
-#if conf.CheckCHeader("sqlite3.h") and conf.CheckLib(env["sqlite_libname"]) :
-# env["HAVE_SQLITE"] = 1
-# env["SQLITE_FLAGS"] = { "LIBS": [env["sqlite_libname"]] }
-# env["SQLITE_FLAGS"].update(sqlite_flags)
-#else :
-# env["SQLITE_BUNDLED"] = 1
-#conf.Finish()
+sqlite_conf_env = conf_env.Clone()
+sqlite_flags = {}
+if env.get("sqlite_libdir", None) :
+ sqlite_flags["LIBPATH"] = [env["sqlite_libdir"]]
+if env.get("sqlite_includedir", None) :
+ sqlite_flags["CPPPATH"] = [env["sqlite_includedir"]]
+sqlite_conf_env.MergeFlags(sqlite_flags)
+conf = Configure(sqlite_conf_env)
+if conf.CheckCHeader("sqlite3.h") and conf.CheckLib(env["sqlite_libname"]) :
+ env["HAVE_SQLITE"] = 1
+ env["SQLITE_FLAGS"] = { "LIBS": [env["sqlite_libname"]] }
+ env["SQLITE_FLAGS"].update(sqlite_flags)
+else :
+ env["SQLITE_BUNDLED"] = 1
+conf.Finish()
# Lua
env["LUA_BUNDLED"] = 1
diff --git a/Swift/Controllers/Chat/ChatControllerBase.cpp b/Swift/Controllers/Chat/ChatControllerBase.cpp
index f17e7c4..388f2c4 100644
--- a/Swift/Controllers/Chat/ChatControllerBase.cpp
+++ b/Swift/Controllers/Chat/ChatControllerBase.cpp
@@ -148,7 +148,7 @@ void ChatControllerBase::handleSendMessageRequest(const std::string &body, bool
onActivity(message->getBody());
// log message
- historyController_->addMessage(getBaseJID(), selfJID_, toJID_, body, now);
+ historyController_->addMessage(getBaseJID(), selfJID_, std::string("me"), body, now);
}
void ChatControllerBase::handleSecurityLabelsCatalogResponse(boost::shared_ptr<SecurityLabelsCatalog> catalog, ErrorPayload::ref error) {
@@ -255,8 +255,7 @@ 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);
+ historyController_->addMessage(getBaseJID(), from, senderDisplayNameFromMessage(from), body, timeStamp);
}
}
chatWindow_->show();
diff --git a/Swift/Controllers/HistoryController.cpp b/Swift/Controllers/HistoryController.cpp
index a19e321..c82892a 100644
--- a/Swift/Controllers/HistoryController.cpp
+++ b/Swift/Controllers/HistoryController.cpp
@@ -6,19 +6,26 @@
#include <Swift/Controllers/HistoryController.h>
#include <Swiften/History/SQLiteHistoryManager.h>
+#include <Swiften/History/HistoryMessage.h>
namespace Swift {
- HistoryController::HistoryController() : remoteArchiveSupported_(false) {
- std::string file("testDB.db");
- localHistory_ = new SQLiteHistoryManager(file);
- }
- HistoryController::~HistoryController() {
- delete localHistory_;
- }
+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);
- }
+void HistoryController::addMessage(const JID& baseJID, const JID& fromJID, const std::string& displayNick, const std::string& messageBody, boost::posix_time::ptime timeStamp) {
+ HistoryMessage message(messageBody, baseJID, fromJID, displayNick, timeStamp);
+ localHistory_->addMessage(message);
+}
+
+std::vector<HistoryMessage> HistoryController::getMessages() const {
+ return localHistory_->getMessages();
+}
}
diff --git a/Swift/Controllers/HistoryController.h b/Swift/Controllers/HistoryController.h
index 9949c19..6ead3f1 100644
--- a/Swift/Controllers/HistoryController.h
+++ b/Swift/Controllers/HistoryController.h
@@ -8,9 +8,11 @@
#include <Swiften/JID/JID.h>
#include <boost/date_time/posix_time/posix_time.hpp>
+#include <vector>
namespace Swift {
class HistoryManager;
+ class HistoryMessage;
class JID;
class HistoryController {
@@ -18,7 +20,8 @@ namespace Swift {
HistoryController();
~HistoryController();
- void addMessage(const JID& baseJID, const JID& fromJID, const JID& toJID, std::string messageBody, boost::posix_time::ptime timeStamp);
+ void addMessage(const JID& baseJID, const JID& fromJID, const std::string& displayNick, const std::string& messageBody, boost::posix_time::ptime timeStamp);
+ std::vector<HistoryMessage> getMessages() const;
private:
HistoryManager* localHistory_;
diff --git a/Swift/Controllers/HistoryViewController.cpp b/Swift/Controllers/HistoryViewController.cpp
index cbfa687..1061e78 100644
--- a/Swift/Controllers/HistoryViewController.cpp
+++ b/Swift/Controllers/HistoryViewController.cpp
@@ -8,10 +8,19 @@
#include <Swift/Controllers/UIInterfaces/HistoryWindowFactory.h>
#include <Swift/Controllers/UIEvents/RequestHistoryUIEvent.h>
+#include <Swift/Controllers/HistoryController.h>
+#include <Swiften/History/HistoryMessage.h>
namespace Swift {
-HistoryViewController::HistoryViewController(UIEventStream* uiEventStream, HistoryWindowFactory* historyWindowFactory) : uiEventStream_(uiEventStream), historyWindowFactory_(historyWindowFactory), historyWindow_(NULL) {
+HistoryViewController::HistoryViewController(
+ UIEventStream* uiEventStream,
+ HistoryController* historyController,
+ HistoryWindowFactory* historyWindowFactory) :
+ uiEventStream_(uiEventStream),
+ historyController_(historyController),
+ historyWindowFactory_(historyWindowFactory),
+ historyWindow_(NULL) {
uiEventStream_->onUIEvent.connect(boost::bind(&HistoryViewController::handleUIEvent, this, _1));
}
@@ -37,6 +46,11 @@ void HistoryViewController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) {
roster_->addContact(medvedev, medvedev, "Dmitri Medvedev", "Recent", "");
roster_->addContact(kev, kev, "Kev", "Recent", "");
}
+
+ std::vector<HistoryMessage> messages = historyController_->getMessages();
+ for (std::vector<HistoryMessage>::iterator it = messages.begin(); it != messages.end(); it++) {
+ historyWindow_->addMessage(*it);
+ }
historyWindow_->activate();
}
}
diff --git a/Swift/Controllers/HistoryViewController.h b/Swift/Controllers/HistoryViewController.h
index 08e6324..f64dd35 100644
--- a/Swift/Controllers/HistoryViewController.h
+++ b/Swift/Controllers/HistoryViewController.h
@@ -16,10 +16,11 @@ namespace Swift {
class HistoryWindowFactory;
class HistoryWindow;
class Roster;
+ class HistoryController;
class HistoryViewController {
public:
- HistoryViewController(UIEventStream* uiEventStream, HistoryWindowFactory* historyWindowFactory);
+ HistoryViewController(UIEventStream* uiEventStream, HistoryController* historyController, HistoryWindowFactory* historyWindowFactory);
~HistoryViewController();
private:
@@ -27,6 +28,7 @@ namespace Swift {
private:
UIEventStream* uiEventStream_;
+ HistoryController* historyController_;
HistoryWindowFactory* historyWindowFactory_;
HistoryWindow* historyWindow_;
Roster* roster_;
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index 793e72f..e894aed 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -172,7 +172,7 @@ MainController::MainController(
xmlConsoleController_ = new XMLConsoleController(uiEventStream_, uiFactory_);
historyController_ = new HistoryController();
- historyViewController_ = new HistoryViewController(uiEventStream_, uiFactory_);
+ historyViewController_ = new HistoryViewController(uiEventStream_, historyController_, uiFactory_);
fileTransferListController_ = new FileTransferListController(uiEventStream_, uiFactory_);
diff --git a/Swift/Controllers/UIInterfaces/HistoryWindow.h b/Swift/Controllers/UIInterfaces/HistoryWindow.h
index 713f986..9ec79e2 100644
--- a/Swift/Controllers/UIInterfaces/HistoryWindow.h
+++ b/Swift/Controllers/UIInterfaces/HistoryWindow.h
@@ -9,11 +9,14 @@
#include <Swift/Controllers/Roster/Roster.h>
namespace Swift {
+ class HistoryMessage;
+
class HistoryWindow {
public:
virtual ~HistoryWindow() {};
virtual void activate() = 0;
virtual void setRosterModel(Roster*) = 0;
+ virtual void addMessage(const HistoryMessage& message) = 0;
};
}
diff --git a/Swift/QtUI/QtHistoryWindow.cpp b/Swift/QtUI/QtHistoryWindow.cpp
index 4b459de..d067190 100644
--- a/Swift/QtUI/QtHistoryWindow.cpp
+++ b/Swift/QtUI/QtHistoryWindow.cpp
@@ -9,6 +9,7 @@
#include <QtSwiftUtil.h>
#include <MessageSnippet.h>
+#include <Swiften/History/HistoryMessage.h>
#include <string>
#include <boost/shared_ptr.hpp>
@@ -19,10 +20,10 @@ namespace Swift {
QtHistoryWindow::QtHistoryWindow(SettingsProvider* settings, UIEventStream* eventStream) {
ui_.setupUi(this);
- QtChatTheme* theme = new QtChatTheme(""); // FIXME: leak
+ theme_ = new QtChatTheme("");
delete ui_.conversation_;
- conversation_ = new QtChatView(theme, this);
+ conversation_ = new QtChatView(theme_, this);
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(80);
sizePolicy.setVerticalStretch(0);
@@ -40,18 +41,11 @@ QtHistoryWindow::QtHistoryWindow(SettingsProvider* settings, UIEventStream* even
ui_.bottomLeftLayout_->setDirection(QBoxLayout::BottomToTop);
ui_.bottomLeftLayout_->addWidget(conversationRoster_);
- conversation_->addMessage(boost::make_shared<MessageSnippet>("Hi", "Me", QDateTime::currentDateTime(), "http://swarm.cs.pub.ro/~cbadea/swift/iron-man.png", false, false, theme, "id"));
- conversation_->addMessage(boost::make_shared<MessageSnippet>("Hi", "You", QDateTime::currentDateTime(), "http://swarm.cs.pub.ro/~cbadea/swift/putin.png", true, false, theme, "id2"));
- conversation_->addMessage(boost::make_shared<MessageSnippet>("How is it going?", "Me", QDateTime::currentDateTime(), "http://swarm.cs.pub.ro/~cbadea/swift/iron-man.png", false, false, theme, "id"));
- conversation_->addMessage(boost::make_shared<MessageSnippet>("Fine, just going through some documents.", "You", QDateTime::currentDateTime(), "http://swarm.cs.pub.ro/~cbadea/swift/putin.png", true, false, theme, "id2"));
- conversation_->addMessage(boost::make_shared<MessageSnippet>("Cool. Hey, do you want to go for a beer?", "Me", QDateTime::currentDateTime(), "http://swarm.cs.pub.ro/~cbadea/swift/iron-man.png", false, false, theme, "id"));
- conversation_->addMessage(boost::make_shared<MessageSnippet>("Sure. Meet me at the pub around 10?", "You", QDateTime::currentDateTime(), "http://swarm.cs.pub.ro/~cbadea/swift/putin.png", true, false, theme, "id2"));
- conversation_->addMessage(boost::make_shared<MessageSnippet>("See you there.", "Me", QDateTime::currentDateTime(), "http://swarm.cs.pub.ro/~cbadea/swift/iron-man.png", false, false, theme, "id"));
-
setWindowTitle(tr("History"));
}
QtHistoryWindow::~QtHistoryWindow() {
+ delete theme_;
}
void QtHistoryWindow::activate() {
@@ -73,4 +67,9 @@ void QtHistoryWindow::setRosterModel(Roster* model) {
conversationRoster_->setRosterModel(model);
}
+void QtHistoryWindow::addMessage(const HistoryMessage& message) {
+ boost::shared_ptr<MessageSnippet> snippet(new MessageSnippet(QString::fromStdString(message.getMessage()), QString::fromStdString(message.getDisplayNick()), QDateTime::currentDateTime(), "", false, false, theme_, "id"));
+ conversation_->addMessage(snippet);
+}
+
}
diff --git a/Swift/QtUI/QtHistoryWindow.h b/Swift/QtUI/QtHistoryWindow.h
index d61fb49..d522f53 100644
--- a/Swift/QtUI/QtHistoryWindow.h
+++ b/Swift/QtUI/QtHistoryWindow.h
@@ -25,12 +25,14 @@ namespace Swift {
~QtHistoryWindow();
void activate();
void setRosterModel(Roster*);
+ void addMessage(const HistoryMessage& message);
private:
virtual void closeEvent(QCloseEvent* event);
virtual void showEvent(QShowEvent* event);
Ui::QtHistoryWindow ui_;
+ QtChatTheme* theme_;
QtChatView* conversation_;
QtRosterWidget* conversationRoster_;
};
diff --git a/Swiften/History/HistoryMessage.h b/Swiften/History/HistoryMessage.h
index 461f5de..03e9206 100644
--- a/Swiften/History/HistoryMessage.h
+++ b/Swiften/History/HistoryMessage.h
@@ -12,19 +12,33 @@
namespace Swift {
class HistoryMessage {
public:
- HistoryMessage(const std::string& message, const JID& from, const JID& to, const boost::posix_time::ptime time) : message_(message), from_(from), to_(to), time_(time) {
+ HistoryMessage(
+ const std::string& message,
+ const JID& baseJID,
+ const JID& fromJID,
+ const std::string& displayNick,
+ const boost::posix_time::ptime time) :
+ message_(message),
+ baseJID_(baseJID),
+ fromJID_(fromJID),
+ displayNick_(displayNick),
+ time_(time) {
}
const std::string& getMessage() const {
return message_;
}
- const JID& getFrom() const {
- return from_;
+ const JID& getBaseJID() const {
+ return baseJID_;
}
- const JID& getTo() const {
- return to_;
+ const JID& getFromJID() const {
+ return fromJID_;
+ }
+
+ const std::string& getDisplayNick() const {
+ return displayNick_;
}
boost::posix_time::ptime getTime() const {
@@ -32,13 +46,14 @@ namespace Swift {
}
bool operator==(const HistoryMessage& o) const {
- return message_ == o.message_ && from_ == o.from_ && to_ == o.to_ && time_ == o.time_;
+ return baseJID_ == o.baseJID_ && message_ == o.message_ && fromJID_ == o.fromJID_ && displayNick_ == o.displayNick_ && time_ == o.time_;
}
private:
std::string message_;
- JID from_;
- JID to_;
+ JID baseJID_;
+ JID fromJID_;
+ std::string displayNick_;
boost::posix_time::ptime time_;
};
}
diff --git a/Swiften/History/SQLiteHistoryManager.cpp b/Swiften/History/SQLiteHistoryManager.cpp
index a24dec2..e10de07 100644
--- a/Swiften/History/SQLiteHistoryManager.cpp
+++ b/Swiften/History/SQLiteHistoryManager.cpp
@@ -25,7 +25,7 @@ SQLiteHistoryManager::SQLiteHistoryManager(const std::string& file) : db_(0) {
}
char* errorMessage;
- int result = sqlite3_exec(db_, "CREATE TABLE IF NOT EXISTS messages('from' INTEGER, 'to' INTEGER, 'message' STRING, 'time' INTEGER)", 0, 0, &errorMessage);
+ int result = sqlite3_exec(db_, "CREATE TABLE IF NOT EXISTS messages('baseID' INTEGER, 'from' INTEGER, 'nick' STRING, 'message' STRING, 'time' INTEGER)", 0, 0, &errorMessage);
if (result != SQLITE_OK) {
std::cerr << "SQL Error: " << errorMessage << std::endl;
sqlite3_free(errorMessage);
@@ -44,7 +44,12 @@ SQLiteHistoryManager::~SQLiteHistoryManager() {
void SQLiteHistoryManager::addMessage(const HistoryMessage& message) {
int secondsSinceEpoch = (message.getTime() - boost::posix_time::ptime(boost::gregorian::date(1970, 1, 1))).total_seconds();
- std::string statement = std::string("INSERT INTO messages('from', 'to', 'message', 'time') VALUES(") + boost::lexical_cast<std::string>(getIDForJID(message.getFrom())) + ", " + boost::lexical_cast<std::string>(getIDForJID(message.getTo())) + ", '" + getEscapedString(message.getMessage()) + "', " + boost::lexical_cast<std::string>(secondsSinceEpoch) + ")";
+ std::string statement = std::string("INSERT INTO messages('baseID', 'from', 'nick', 'message', 'time') VALUES(") +
+ boost::lexical_cast<std::string>(getIDForJID(message.getBaseJID())) + ", " +
+ boost::lexical_cast<std::string>(getIDForJID(message.getFromJID())) + ", '" +
+ message.getDisplayNick() + "', '" +
+ getEscapedString(message.getMessage()) + "', " +
+ boost::lexical_cast<std::string>(secondsSinceEpoch) + ")";
char* errorMessage;
int result = sqlite3_exec(db_, statement.c_str(), 0, 0, &errorMessage);
if (result != SQLITE_OK) {
@@ -56,20 +61,21 @@ void SQLiteHistoryManager::addMessage(const HistoryMessage& message) {
std::vector<HistoryMessage> SQLiteHistoryManager::getMessages() const {
std::vector<HistoryMessage> result;
sqlite3_stmt* selectStatement;
- std::string selectQuery("SELECT messages.'from', messages.'to', messages.'message', messages.'time' FROM messages");
+ std::string selectQuery("SELECT messages.'baseID', messages.'from', messages.'nick', messages.'message', messages.'time' FROM messages");
int r = sqlite3_prepare(db_, selectQuery.c_str(), selectQuery.size(), &selectStatement, NULL);
if (r != SQLITE_OK) {
std::cout << "Error: " << sqlite3_errmsg(db_) << std::endl;
}
r = sqlite3_step(selectStatement);
while (r == SQLITE_ROW) {
- boost::optional<JID> from(getJIDFromID(sqlite3_column_int(selectStatement, 0)));
- boost::optional<JID> to(getJIDFromID(sqlite3_column_int(selectStatement, 1)));
- std::string message(reinterpret_cast<const char*>(sqlite3_column_text(selectStatement, 2)));
- int secondsSinceEpoch(sqlite3_column_int(selectStatement, 3));
+ boost::optional<JID> baseJID(getJIDFromID(sqlite3_column_int(selectStatement, 0)));
+ boost::optional<JID> from(getJIDFromID(sqlite3_column_int(selectStatement, 1)));
+ std::string nick(reinterpret_cast<const char*>(sqlite3_column_text(selectStatement, 2)));
+ std::string message(reinterpret_cast<const char*>(sqlite3_column_text(selectStatement, 3)));
+ int secondsSinceEpoch(sqlite3_column_int(selectStatement, 4));
boost::posix_time::ptime time(boost::gregorian::date(1970, 1, 1), boost::posix_time::seconds(secondsSinceEpoch));
- result.push_back(HistoryMessage(message, (from ? *from : JID()), (to ? *to : JID()), time));
+ result.push_back(HistoryMessage(message, (baseJID ? *baseJID : JID()), (from ? *from : JID()), nick, time));
r = sqlite3_step(selectStatement);
}
if (r != SQLITE_DONE) {
diff --git a/Swiften/SConscript b/Swiften/SConscript
index 9996728..7e8eb9e 100644
--- a/Swiften/SConscript
+++ b/Swiften/SConscript
@@ -6,7 +6,7 @@ Import("env")
# Flags
################################################################################
-swiften_dep_modules = ["BOOST", "GCONF", "ICU", "LIBIDN", "ZLIB", "OPENSSL", "LIBXML", "EXPAT", "AVAHI", "LIBMINIUPNPC", "LIBNATPMP"]
+swiften_dep_modules = ["BOOST", "GCONF", "ICU", "LIBIDN", "ZLIB", "OPENSSL", "LIBXML", "EXPAT", "AVAHI", "LIBMINIUPNPC", "LIBNATPMP", "SQLITE"]
if env["SCONS_STAGE"] == "flags" :
env["SWIFTEN_DLL"] = ARGUMENTS.get("swiften_dll")