diff options
author | Catalin Badea <catalin.badea392@gmail.com> | 2012-07-20 12:22:40 (GMT) |
---|---|---|
committer | Cătălin Badea <catalin.badea392@gmail.com> | 2012-08-11 15:59:12 (GMT) |
commit | 461ddac4c336524e2d3ecdb95ae23d5219b5304c (patch) | |
tree | dea7f0d8678623aee7693e89198b8e13b64d0981 /Swift | |
parent | ca345562f5dee77024c661832eeaa9368737be2c (diff) | |
download | swift-contrib-461ddac4c336524e2d3ecdb95ae23d5219b5304c.zip swift-contrib-461ddac4c336524e2d3ecdb95ae23d5219b5304c.tar.bz2 |
continous scroll between dates.
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/Controllers/HistoryController.cpp | 12 | ||||
-rw-r--r-- | Swift/Controllers/HistoryController.h | 4 | ||||
-rw-r--r-- | Swift/Controllers/HistoryViewController.cpp | 46 | ||||
-rw-r--r-- | Swift/Controllers/HistoryViewController.h | 7 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/HistoryWindow.h | 4 | ||||
-rw-r--r-- | Swift/QtUI/QtHistoryWindow.cpp | 21 | ||||
-rw-r--r-- | Swift/QtUI/QtHistoryWindow.h | 3 |
7 files changed, 72 insertions, 25 deletions
diff --git a/Swift/Controllers/HistoryController.cpp b/Swift/Controllers/HistoryController.cpp index 51891f6..deda25b 100644 --- a/Swift/Controllers/HistoryController.cpp +++ b/Swift/Controllers/HistoryController.cpp @@ -25,8 +25,16 @@ void HistoryController::addMessage(const std::string& message, const JID& fromJI onNewMessage(historyMessage); } -std::vector<HistoryMessage> HistoryController::getMessages(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const { - return localHistory_->getMessages(selfJID, contactJID, type, date); +std::vector<HistoryMessage> HistoryController::getMessagesFromDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const { + return localHistory_->getMessagesFromDate(selfJID, contactJID, type, date); +} + +std::vector<HistoryMessage> HistoryController::getMessagesFromPreviousDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const { + return localHistory_->getMessagesFromPreviousDate(selfJID, contactJID, type, date); +} + +std::vector<HistoryMessage> HistoryController::getMessagesFromNextDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const { + return localHistory_->getMessagesFromNextDate(selfJID, contactJID, type, date); } ContactsMap HistoryController::getContacts(const JID& selfJID, HistoryMessage::Type type, const std::string& keyword) const { diff --git a/Swift/Controllers/HistoryController.h b/Swift/Controllers/HistoryController.h index 53260a1..00ad752 100644 --- a/Swift/Controllers/HistoryController.h +++ b/Swift/Controllers/HistoryController.h @@ -23,7 +23,9 @@ namespace Swift { ~HistoryController(); void addMessage(const std::string& message, const JID& fromJID, const JID& toJID, HistoryMessage::Type type, const boost::posix_time::ptime& timeStamp); - std::vector<HistoryMessage> getMessages(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const; + std::vector<HistoryMessage> getMessagesFromDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const; + std::vector<HistoryMessage> getMessagesFromPreviousDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const; + std::vector<HistoryMessage> getMessagesFromNextDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const; ContactsMap getContacts(const JID& selfJID, HistoryMessage::Type type, const std::string& keyword = std::string()) const; boost::signal<void (const HistoryMessage&)> onNewMessage; diff --git a/Swift/Controllers/HistoryViewController.cpp b/Swift/Controllers/HistoryViewController.cpp index b7b71cd..8efdc99 100644 --- a/Swift/Controllers/HistoryViewController.cpp +++ b/Swift/Controllers/HistoryViewController.cpp @@ -31,7 +31,7 @@ HistoryViewController::HistoryViewController( historyWindowFactory_(historyWindowFactory), historyWindow_(NULL), selectedItem_(NULL), - currentDate_(boost::gregorian::not_a_date_time) { + currentResultDate_(boost::gregorian::not_a_date_time) { uiEventStream_->onUIEvent.connect(boost::bind(&HistoryViewController::handleUIEvent, this, _1)); historyController_->onNewMessage.connect(boost::bind(&HistoryViewController::handleNewMessage, this, _1)); @@ -44,6 +44,8 @@ HistoryViewController::~HistoryViewController() { if (historyWindow_) { historyWindow_->onSelectedContactChanged.disconnect(boost::bind(&HistoryViewController::handleSelectedContactChanged, this, _1)); historyWindow_->onReturnPressed.disconnect(boost::bind(&HistoryViewController::handleReturnPressed, this, _1)); + historyWindow_->onScrollReachedTop.disconnect(boost::bind(&HistoryViewController::handleScrollReachedTop, this, _1)); + historyWindow_->onScrollReachedBottom.disconnect(boost::bind(&HistoryViewController::handleScrollReachedBottom, this, _1)); delete historyWindow_; } delete roster_; @@ -57,6 +59,8 @@ void HistoryViewController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) { historyWindow_ = historyWindowFactory_->createHistoryWindow(uiEventStream_); historyWindow_->onSelectedContactChanged.connect(boost::bind(&HistoryViewController::handleSelectedContactChanged, this, _1)); historyWindow_->onReturnPressed.connect(boost::bind(&HistoryViewController::handleReturnPressed, this, _1)); + historyWindow_->onScrollReachedTop.connect(boost::bind(&HistoryViewController::handleScrollReachedTop, this, _1)); + historyWindow_->onScrollReachedBottom.connect(boost::bind(&HistoryViewController::handleScrollReachedBottom, this, _1)); historyWindow_->setRosterModel(roster_); } @@ -84,20 +88,23 @@ void HistoryViewController::handleSelectedContactChanged(RosterItem* newContact) std::vector<HistoryMessage> messages; if (roomPrivateContacts_.count(contactJID)) { - currentDate_ = *roomPrivateContacts_[contactJID].rbegin(); - messages = historyController_->getMessages(selfJID_, contactJID, HistoryMessage::PrivateMessage, currentDate_); + currentResultDate_ = *roomPrivateContacts_[contactJID].rbegin(); + messages = historyController_->getMessagesFromDate(selfJID_, contactJID, HistoryMessage::PrivateMessage, currentResultDate_); + currentItemType_ = HistoryMessage::PrivateMessage; } else if (contacts_.count(contactJID)) { - currentDate_ = *contacts_[contactJID].rbegin(); - messages = historyController_->getMessages(selfJID_, contactJID, HistoryMessage::Chat, currentDate_); + currentResultDate_ = *contacts_[contactJID].rbegin(); + messages = historyController_->getMessagesFromDate(selfJID_, contactJID, HistoryMessage::Chat, currentResultDate_); + currentItemType_ = HistoryMessage::Chat; } else { - currentDate_ = *rooms_[contactJID].rbegin(); - messages = historyController_->getMessages(selfJID_, contactJID, HistoryMessage::Groupchat, currentDate_); + currentResultDate_ = *rooms_[contactJID].rbegin(); + messages = historyController_->getMessagesFromDate(selfJID_, contactJID, HistoryMessage::Groupchat, currentResultDate_); + currentItemType_ = HistoryMessage::Groupchat; } foreach (const HistoryMessage& message, messages) { - addNewMessage(message); + addNewMessage(message, false); } } @@ -114,7 +121,7 @@ void HistoryViewController::handleNewMessage(const HistoryMessage& message) { // check current conversation if (selectedItem_ && selectedItem_->getJID() == displayJID) { - addNewMessage(message); + addNewMessage(message, false); } // add new contact else if (message.getType() == HistoryMessage::Groupchat && !rooms_.count(displayJID)) { @@ -133,10 +140,10 @@ void HistoryViewController::handleNewMessage(const HistoryMessage& message) { } } -void HistoryViewController::addNewMessage(const HistoryMessage& message) { +void HistoryViewController::addNewMessage(const HistoryMessage& message, bool addAtTheTop) { bool senderIsSelf = message.getFromJID().toBare() == selfJID_; std::string avatarPath = avatarManager_->getAvatarPath(message.getFromJID()).string(); - historyWindow_->addMessage(message.getMessage(), nickResolver_->jidToNick(message.getFromJID()), senderIsSelf, avatarPath, message.getTime()); + historyWindow_->addMessage(message.getMessage(), nickResolver_->jidToNick(message.getFromJID()), senderIsSelf, avatarPath, message.getTime(), addAtTheTop); } void HistoryViewController::handleReturnPressed(const std::string& keyword) { @@ -146,7 +153,6 @@ void HistoryViewController::handleReturnPressed(const std::string& keyword) { roomPrivateContacts_.clear(); selectedItem_ = NULL; historyWindow_->resetConversationView(); - // TODO set date // MUCs rooms_ = historyController_->getContacts(selfJID_, HistoryMessage::Groupchat, keyword); @@ -170,4 +176,20 @@ void HistoryViewController::handleReturnPressed(const std::string& keyword) { } } +void HistoryViewController::handleScrollReachedTop(const boost::gregorian::date& date) { + std::vector<HistoryMessage> messages = historyController_->getMessagesFromPreviousDate(selfJID_, selectedItem_->getJID(), currentItemType_, date); + + reverse_foreach (const HistoryMessage& message, messages) { + addNewMessage(message, true); + } +} + +void HistoryViewController::handleScrollReachedBottom(const boost::gregorian::date& date) { + std::vector<HistoryMessage> messages = historyController_->getMessagesFromNextDate(selfJID_, selectedItem_->getJID(), currentItemType_, date); + + foreach (const HistoryMessage& message, messages) { + addNewMessage(message, true); + } +} + } diff --git a/Swift/Controllers/HistoryViewController.h b/Swift/Controllers/HistoryViewController.h index cddcfb8..5c4dc96 100644 --- a/Swift/Controllers/HistoryViewController.h +++ b/Swift/Controllers/HistoryViewController.h @@ -35,8 +35,10 @@ namespace Swift { void handleUIEvent(boost::shared_ptr<UIEvent> event); void handleSelectedContactChanged(RosterItem* item); void handleNewMessage(const HistoryMessage& message); - void addNewMessage(const HistoryMessage& message); + void addNewMessage(const HistoryMessage& message, bool addAtTheTop); void handleReturnPressed(const std::string& keyword); + void handleScrollReachedTop(const boost::gregorian::date& date); + void handleScrollReachedBottom(const boost::gregorian::date& date); private: JID selfJID_; @@ -52,6 +54,7 @@ namespace Swift { ContactsMap rooms_; ContactsMap roomPrivateContacts_; ContactRosterItem* selectedItem_; - boost::gregorian::date currentDate_; + HistoryMessage::Type currentItemType_; + boost::gregorian::date currentResultDate_; }; } diff --git a/Swift/Controllers/UIInterfaces/HistoryWindow.h b/Swift/Controllers/UIInterfaces/HistoryWindow.h index d38d6df..effff27 100644 --- a/Swift/Controllers/UIInterfaces/HistoryWindow.h +++ b/Swift/Controllers/UIInterfaces/HistoryWindow.h @@ -15,10 +15,12 @@ namespace Swift { virtual void activate() = 0; virtual void setRosterModel(Roster*) = 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; + virtual void addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time, bool addAtTheTop) = 0; virtual void resetConversationView() = 0; boost::signal<void (RosterItem*)> onSelectedContactChanged; boost::signal<void (const std::string&)> onReturnPressed; + boost::signal<void (const boost::gregorian::date&)> onScrollReachedTop; + boost::signal<void (const boost::gregorian::date&)> onScrollReachedBottom; }; } diff --git a/Swift/QtUI/QtHistoryWindow.cpp b/Swift/QtUI/QtHistoryWindow.cpp index ed91551..feec059 100644 --- a/Swift/QtUI/QtHistoryWindow.cpp +++ b/Swift/QtUI/QtHistoryWindow.cpp @@ -23,6 +23,7 @@ #include <QLineEdit> #include <boost/smart_ptr/make_shared.hpp> +#include <boost/date_time/gregorian/gregorian.hpp> namespace Swift { @@ -92,7 +93,7 @@ void QtHistoryWindow::setRosterModel(Roster* model) { conversationRoster_->setRosterModel(model); } -void QtHistoryWindow::addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time) { +void QtHistoryWindow::addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time, bool addAtTheTop) { QString scaledAvatarPath = QtScaledAvatarCache(32).getScaledAvatarPath(avatarPath.c_str()); QString messageHTML(P2QSTRING(message)); @@ -104,7 +105,12 @@ void QtHistoryWindow::addMessage(const std::string &message, const std::string & QString qAvatarPath = scaledAvatarPath.isEmpty() ? "qrc:/icons/avatar.png" : QUrl::fromLocalFile(scaledAvatarPath).toEncoded(); - conversation_->addMessageBottom(boost::shared_ptr<ChatSnippet>(new MessageSnippet(messageHTML, Qt::escape(P2QSTRING(senderName)), qTime, qAvatarPath, senderIsSelf, false, theme_, P2QSTRING(id)))); + if (addAtTheTop) { + conversation_->addMessageTop(boost::shared_ptr<ChatSnippet>(new MessageSnippet(messageHTML, Qt::escape(P2QSTRING(senderName)), qTime, qAvatarPath, senderIsSelf, false, theme_, P2QSTRING(id)))); + } + else { + conversation_->addMessageBottom(boost::shared_ptr<ChatSnippet>(new MessageSnippet(messageHTML, Qt::escape(P2QSTRING(senderName)), qTime, qAvatarPath, senderIsSelf, false, theme_, P2QSTRING(id)))); + } // keep track of the days viewable in the chatView if (!dates_.count(date)) { @@ -135,16 +141,21 @@ void QtHistoryWindow::handleScrollRequested(int pos) { } } - if (currentDate_ != currentDate) { - currentDate_ = currentDate; - ui_.calendarWidget_->setSelectedDate(currentDate_); + if (ui_.calendarWidget_->selectedDate() != currentDate) { + ui_.calendarWidget_->setSelectedDate(currentDate); } } void QtHistoryWindow::handleScrollReachedTop() { + int year, month, day; + ui_.calendarWidget_->selectedDate().getDate(&year, &month, &day); + onScrollReachedTop(boost::gregorian::date(year, month, day)); } void QtHistoryWindow::handleScrollReachedBottom() { + int year, month, day; + ui_.calendarWidget_->selectedDate().getDate(&year, &month, &day); + onScrollReachedBottom(boost::gregorian::date(year, month, day)); } void QtHistoryWindow::handleReturnPressed() { diff --git a/Swift/QtUI/QtHistoryWindow.h b/Swift/QtUI/QtHistoryWindow.h index 9a887bf..97b9866 100644 --- a/Swift/QtUI/QtHistoryWindow.h +++ b/Swift/QtUI/QtHistoryWindow.h @@ -23,7 +23,7 @@ namespace Swift { ~QtHistoryWindow(); void activate(); void setRosterModel(Roster*); - void addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time); + void addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time, bool addAtTheTop); void resetConversationView(); void closeEvent(QCloseEvent* event); @@ -44,7 +44,6 @@ namespace Swift { QtChatView* conversation_; QtTreeWidget* conversationRoster_; std::set<QDate> dates_; - QDate currentDate_; int idCounter_; }; } |