diff options
author | Catalin Badea <catalin.badea392@gmail.com> | 2012-07-01 20:13:27 (GMT) |
---|---|---|
committer | Catalin Badea <catalin.badea392@gmail.com> | 2012-07-01 20:13:27 (GMT) |
commit | 831075a8aeb15dc79c84d28d284b5cdbae2f60ea (patch) | |
tree | e51fa0ff00611e5ca4af7bca1fbfc38a75d640fd /Swift | |
parent | 583809c9f96bbf35196c416a1b6e44539b5ceacc (diff) | |
download | swift-contrib-831075a8aeb15dc79c84d28d284b5cdbae2f60ea.zip swift-contrib-831075a8aeb15dc79c84d28d284b5cdbae2f60ea.tar.bz2 |
Dump message logs using new db structure. Avatars not working
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/Controllers/Chat/ChatController.cpp | 4 | ||||
-rw-r--r-- | Swift/Controllers/Chat/MUCController.cpp | 2 | ||||
-rw-r--r-- | Swift/Controllers/HistoryController.cpp | 12 | ||||
-rw-r--r-- | Swift/Controllers/HistoryController.h | 7 | ||||
-rw-r--r-- | Swift/Controllers/HistoryViewController.cpp | 26 | ||||
-rw-r--r-- | Swift/Controllers/HistoryViewController.h | 8 | ||||
-rw-r--r-- | Swift/Controllers/MainController.cpp | 2 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/HistoryWindow.h | 4 | ||||
-rw-r--r-- | Swift/QtUI/QtHistoryWindow.cpp | 21 | ||||
-rw-r--r-- | Swift/QtUI/QtHistoryWindow.h | 2 |
10 files changed, 59 insertions, 29 deletions
diff --git a/Swift/Controllers/Chat/ChatController.cpp b/Swift/Controllers/Chat/ChatController.cpp index b0413af..632d760 100644 --- a/Swift/Controllers/Chat/ChatController.cpp +++ b/Swift/Controllers/Chat/ChatController.cpp @@ -353,9 +353,9 @@ boost::optional<boost::posix_time::ptime> ChatController::getMessageTimestamp(bo return message->getTimestamp(); } -void ChatController::logMessage(const std::string& message, const JID& fromJID, const JID& toJID, const boost::posix_time::ptime& timeStamp, bool isIncoming) { +void ChatController::logMessage(const std::string& message, const JID& fromJID, const JID& toJID, const boost::posix_time::ptime& timeStamp, bool /* isIncoming */) { if (historyController_) { - historyController_->addMessage(message, fromJID, toJID, timeStamp); + historyController_->addMessage(message, fromJID, toJID, false, timeStamp); } } diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp index 222fb01..f86c726 100644 --- a/Swift/Controllers/Chat/MUCController.cpp +++ b/Swift/Controllers/Chat/MUCController.cpp @@ -783,7 +783,7 @@ void MUCController::handleAffiliationListReceived(MUCOccupant::Affiliation affil void MUCController::logMessage(const std::string& message, const JID& fromJID, const JID& toJID, const boost::posix_time::ptime& timeStamp, bool isIncoming) { // log only incoming messages if (isIncoming && historyController_) { - historyController_->addMessage(message, fromJID, toJID, timeStamp); + historyController_->addMessage(message, fromJID, toJID, true, timeStamp); } } diff --git a/Swift/Controllers/HistoryController.cpp b/Swift/Controllers/HistoryController.cpp index 7e3d1e4..a25c40f 100644 --- a/Swift/Controllers/HistoryController.cpp +++ b/Swift/Controllers/HistoryController.cpp @@ -19,17 +19,17 @@ HistoryController::~HistoryController() { delete localHistory_; } -void HistoryController::addMessage(const std::string& message, const JID& fromJID, const JID& toJID, const boost::posix_time::ptime& timeStamp) { - HistoryMessage historyMessage(message, fromJID, toJID, timeStamp); +void HistoryController::addMessage(const std::string& message, const JID& fromJID, const JID& toJID, bool isGroupChat, const boost::posix_time::ptime& timeStamp) { + HistoryMessage historyMessage(message, fromJID, toJID, isGroupChat, timeStamp); localHistory_->addMessage(historyMessage); } -std::vector<HistoryMessage> HistoryController::getMessages(const JID& selfJID, const JID& contactJID) const { - return localHistory_->getMessages(selfJID, contactJID); +std::vector<HistoryMessage> HistoryController::getMessages(const JID& selfJID, const JID& contactJID, bool isGroupChat) const { + return localHistory_->getMessages(selfJID, contactJID, isGroupChat); } -std::vector<JID> HistoryController::getAllContacts() const { - return localHistory_->getAllContacts(); +void HistoryController::getAllContacts(const JID& selfJID, std::set<JID>& mucs, std::set<JID>& contacts) const { + return localHistory_->getAllContacts(selfJID, mucs, contacts); } } diff --git a/Swift/Controllers/HistoryController.h b/Swift/Controllers/HistoryController.h index 9a38b15..5c0378a 100644 --- a/Swift/Controllers/HistoryController.h +++ b/Swift/Controllers/HistoryController.h @@ -9,6 +9,7 @@ #include <Swiften/JID/JID.h> #include <boost/date_time/posix_time/posix_time.hpp> #include <vector> +#include <set> namespace Swift { class HistoryManager; @@ -20,9 +21,9 @@ namespace Swift { HistoryController(); ~HistoryController(); - void addMessage(const std::string& message, const JID& fromJID, const JID& toJID, const boost::posix_time::ptime& timeStamp); - std::vector<HistoryMessage> getMessages(const JID& selfJID, const JID& contactJID) const; - std::vector<JID> getAllContacts() const; + void addMessage(const std::string& message, const JID& fromJID, const JID& toJID, bool isGroupChat, const boost::posix_time::ptime& timeStamp); + std::vector<HistoryMessage> getMessages(const JID& selfJID, const JID& contactJID, bool isGroupChat) const; + void getAllContacts(const JID& selfJID, std::set<JID>& mucs, std::set<JID>& contacts) const; private: HistoryManager* localHistory_; diff --git a/Swift/Controllers/HistoryViewController.cpp b/Swift/Controllers/HistoryViewController.cpp index f88d097..9c10874 100644 --- a/Swift/Controllers/HistoryViewController.cpp +++ b/Swift/Controllers/HistoryViewController.cpp @@ -10,15 +10,20 @@ #include <Swift/Controllers/UIEvents/RequestHistoryUIEvent.h> #include <Swift/Controllers/HistoryController.h> #include <Swiften/History/HistoryMessage.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Client/NickResolver.h> +#include <Swiften/Avatars/AvatarManager.h> namespace Swift { HistoryViewController::HistoryViewController( + const JID& selfJID, UIEventStream* uiEventStream, HistoryController* historyController, NickResolver* nickResolver, AvatarManager* avatarManager, HistoryWindowFactory* historyWindowFactory) : + selfJID_(selfJID), uiEventStream_(uiEventStream), historyController_(historyController), nickResolver_(nickResolver), @@ -47,9 +52,13 @@ void HistoryViewController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) { roster_ = new Roster(false, true); historyWindow_->setRosterModel(roster_); - std::vector<JID> contacts = historyController_->getAllContacts(); - for (std::vector<JID>::iterator it = contacts.begin(); it != contacts.end(); it++) { - roster_->addContact(*it, *it, *it, "Recent", ""); + historyController_->getAllContacts(selfJID_, rooms_, contacts_); + + foreach (const JID& muc, rooms_) { + roster_->addContact(muc, muc, nickResolver_->jidToNick(muc), "MUC", byteArrayToString(avatarManager_->getAvatar(muc))); + } + foreach (const JID& contact, contacts_) { + roster_->addContact(contact, contact, nickResolver_->jidToNick(contact), "Contacts", byteArrayToString(avatarManager_->getAvatar(contact))); } } @@ -58,17 +67,20 @@ void HistoryViewController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) { } void HistoryViewController::handleSelectedContactChanged(RosterItem* newContact) { - // TODO: check if actually changed // FIXME: signal is triggerd twice. if (newContact == NULL) { return; } ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(newContact); + JID contactJID = contact->getJID(); + bool isRoom = rooms_.count(contactJID); - std::vector<HistoryMessage> messages; //TODO = historyController_->getMessages(contact->getJID()); - for (std::vector<HistoryMessage>::iterator it = messages.begin(); it != messages.end(); it++) { - historyWindow_->addMessage(*it); + std::vector<HistoryMessage> messages = historyController_->getMessages(selfJID_, contactJID, isRoom); + foreach (const HistoryMessage& message, messages) { + bool senderIsSelf = message.getFromJID() == selfJID_; + std::string avatarPath = byteArrayToString(avatarManager_->getAvatar(message.getFromJID())); + historyWindow_->addMessage(message.getMessage(), nickResolver_->jidToNick(message.getFromJID()), senderIsSelf, avatarPath, message.getTime()); } } diff --git a/Swift/Controllers/HistoryViewController.h b/Swift/Controllers/HistoryViewController.h index 7dabf46..f1ff286 100644 --- a/Swift/Controllers/HistoryViewController.h +++ b/Swift/Controllers/HistoryViewController.h @@ -11,6 +11,8 @@ #include <boost/shared_ptr.hpp> #include <Swift/Controllers/UIEvents/UIEventStream.h> +#include <Swiften/JID/JID.h> +#include <set> namespace Swift { class HistoryWindowFactory; @@ -23,7 +25,7 @@ namespace Swift { class HistoryViewController { public: - HistoryViewController(UIEventStream* uiEventStream, HistoryController* historyController, NickResolver* nickResolver, AvatarManager* avatarManager, HistoryWindowFactory* historyWindowFactory); + HistoryViewController(const JID& selfJID, UIEventStream* uiEventStream, HistoryController* historyController, NickResolver* nickResolver, AvatarManager* avatarManager, HistoryWindowFactory* historyWindowFactory); ~HistoryViewController(); private: @@ -31,6 +33,7 @@ namespace Swift { void handleSelectedContactChanged(RosterItem* item); private: + JID selfJID_; UIEventStream* uiEventStream_; HistoryController* historyController_; NickResolver* nickResolver_; @@ -38,5 +41,8 @@ namespace Swift { HistoryWindowFactory* historyWindowFactory_; HistoryWindow* historyWindow_; Roster* roster_; + + std::set<JID> rooms_; + std::set<JID> contacts_; }; } diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index 60a882a..8b1c489 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -299,7 +299,7 @@ void MainController::handleConnected() { chatsManager_ = new ChatsManager(jid_, client_->getStanzaChannel(), client_->getIQRouter(), eventController_, uiFactory_, uiFactory_, client_->getNickResolver(), client_->getPresenceOracle(), client_->getPresenceSender(), uiEventStream_, uiFactory_, useDelayForLatency_, networkFactories_->getTimerFactory(), client_->getMUCRegistry(), client_->getEntityCapsProvider(), client_->getMUCManager(), uiFactory_, profileSettings_, ftOverview_, client_->getRoster(), !settings_->getSetting(SettingConstants::REMEMBER_RECENT_CHATS), settings_, historyController_); - historyViewController_ = new HistoryViewController(uiEventStream_, historyController_, client_->getNickResolver(), client_->getAvatarManager(), uiFactory_); + historyViewController_ = new HistoryViewController(jid_, uiEventStream_, historyController_, client_->getNickResolver(), client_->getAvatarManager(), uiFactory_); client_->onMessageReceived.connect(boost::bind(&ChatsManager::handleIncomingMessage, chatsManager_, _1)); chatsManager_->setAvatarManager(client_->getAvatarManager()); diff --git a/Swift/Controllers/UIInterfaces/HistoryWindow.h b/Swift/Controllers/UIInterfaces/HistoryWindow.h index cc3f0b8..d51b65d 100644 --- a/Swift/Controllers/UIInterfaces/HistoryWindow.h +++ b/Swift/Controllers/UIInterfaces/HistoryWindow.h @@ -9,15 +9,13 @@ #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; + virtual void addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time) = 0; boost::signal<void (RosterItem*)> onSelectedContactChanged; }; diff --git a/Swift/QtUI/QtHistoryWindow.cpp b/Swift/QtUI/QtHistoryWindow.cpp index 24085d9..122655a 100644 --- a/Swift/QtUI/QtHistoryWindow.cpp +++ b/Swift/QtUI/QtHistoryWindow.cpp @@ -13,6 +13,13 @@ #include <string> #include <boost/shared_ptr.hpp> + +#include <QTime> +#include <QUrl> +#include <QMenu> +#include <QTextDocument> +#include <Swift/QtUI/QtScaledAvatarCache.h> + #include <boost/smart_ptr/make_shared.hpp> namespace Swift { @@ -69,12 +76,18 @@ void QtHistoryWindow::setRosterModel(Roster* model) { conversationRoster_->setRosterModel(model); } -void QtHistoryWindow::addMessage(const HistoryMessage& message) { - // TODO - // boost::shared_ptr<MessageSnippet> snippet(new MessageSnippet(QString::fromStdString(message.getMessage()), QString::fromStdString(message.getDisplayNick()), QDateTime::currentDateTime(), "", false, false, theme_, "id")); - // conversation_->addMessage(snippet); +void QtHistoryWindow::addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time) { + QString scaledAvatarPath = QtScaledAvatarCache(32).getScaledAvatarPath(avatarPath.c_str()); + + QString messageHTML(P2QSTRING(message)); + messageHTML = Qt::escape(messageHTML); + + QString qAvatarPath = scaledAvatarPath.isEmpty() ? "qrc:/icons/avatar.png" : QUrl::fromLocalFile(scaledAvatarPath).toEncoded(); + + conversation_->addMessage(boost::shared_ptr<ChatSnippet>(new MessageSnippet(messageHTML, Qt::escape(P2QSTRING(senderName)), B2QDATE(time), qAvatarPath, senderIsSelf, false, theme_, "id"))); } + void QtHistoryWindow::handleSomethingSelectedChanged(RosterItem* item) { conversation_->resetView(); onSelectedContactChanged(item); diff --git a/Swift/QtUI/QtHistoryWindow.h b/Swift/QtUI/QtHistoryWindow.h index 1ddaf61..965abf7 100644 --- a/Swift/QtUI/QtHistoryWindow.h +++ b/Swift/QtUI/QtHistoryWindow.h @@ -21,7 +21,7 @@ namespace Swift { ~QtHistoryWindow(); void activate(); void setRosterModel(Roster*); - void addMessage(const HistoryMessage& message); + void addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time); private: virtual void closeEvent(QCloseEvent* event); |