diff options
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/Controllers/Chat/ChatControllerBase.cpp | 5 | ||||
-rw-r--r-- | Swift/Controllers/HistoryController.cpp | 27 | ||||
-rw-r--r-- | Swift/Controllers/HistoryController.h | 5 | ||||
-rw-r--r-- | Swift/Controllers/HistoryViewController.cpp | 16 | ||||
-rw-r--r-- | Swift/Controllers/HistoryViewController.h | 4 | ||||
-rw-r--r-- | Swift/Controllers/MainController.cpp | 2 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/HistoryWindow.h | 3 | ||||
-rw-r--r-- | Swift/QtUI/QtHistoryWindow.cpp | 19 | ||||
-rw-r--r-- | Swift/QtUI/QtHistoryWindow.h | 2 |
9 files changed, 56 insertions, 27 deletions
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_; }; |