diff options
Diffstat (limited to 'Swift/Controllers')
-rw-r--r-- | Swift/Controllers/Chat/ChatControllerBase.cpp | 8 | ||||
-rw-r--r-- | Swift/Controllers/HistoryController.cpp | 8 | ||||
-rw-r--r-- | Swift/Controllers/HistoryController.h | 3 | ||||
-rw-r--r-- | Swift/Controllers/HistoryViewController.cpp | 39 | ||||
-rw-r--r-- | Swift/Controllers/HistoryViewController.h | 2 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/HistoryWindow.h | 2 |
6 files changed, 44 insertions, 18 deletions
diff --git a/Swift/Controllers/Chat/ChatControllerBase.cpp b/Swift/Controllers/Chat/ChatControllerBase.cpp index 388f2c4..ee3a027 100644 --- a/Swift/Controllers/Chat/ChatControllerBase.cpp +++ b/Swift/Controllers/Chat/ChatControllerBase.cpp @@ -148,7 +148,9 @@ void ChatControllerBase::handleSendMessageRequest(const std::string &body, bool onActivity(message->getBody()); // log message - historyController_->addMessage(getBaseJID(), selfJID_, std::string("me"), body, now); + if (historyController_) { + historyController_->addMessage(getBaseJID(), selfJID_, std::string("me"), body, now); + } } void ChatControllerBase::handleSecurityLabelsCatalogResponse(boost::shared_ptr<SecurityLabelsCatalog> catalog, ErrorPayload::ref error) { @@ -255,7 +257,9 @@ 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); - historyController_->addMessage(getBaseJID(), from, senderDisplayNameFromMessage(from), body, timeStamp); + if (historyController_) { + historyController_->addMessage(getBaseJID(), from, senderDisplayNameFromMessage(from), body, timeStamp); + } } } chatWindow_->show(); diff --git a/Swift/Controllers/HistoryController.cpp b/Swift/Controllers/HistoryController.cpp index c82892a..63d4690 100644 --- a/Swift/Controllers/HistoryController.cpp +++ b/Swift/Controllers/HistoryController.cpp @@ -24,8 +24,12 @@ void HistoryController::addMessage(const JID& baseJID, const JID& fromJID, const localHistory_->addMessage(message); } -std::vector<HistoryMessage> HistoryController::getMessages() const { - return localHistory_->getMessages(); +std::vector<HistoryMessage> HistoryController::getMessages(const JID& baseJID) const { + return localHistory_->getMessages(baseJID); +} + +std::vector<JID> HistoryController::getAllContacts() const { + return localHistory_->getAllContacts(); } } diff --git a/Swift/Controllers/HistoryController.h b/Swift/Controllers/HistoryController.h index 6ead3f1..0d337f6 100644 --- a/Swift/Controllers/HistoryController.h +++ b/Swift/Controllers/HistoryController.h @@ -21,7 +21,8 @@ namespace Swift { ~HistoryController(); 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; + std::vector<HistoryMessage> getMessages(const JID& baseJID) const; + std::vector<JID> getAllContacts() const; private: HistoryManager* localHistory_; diff --git a/Swift/Controllers/HistoryViewController.cpp b/Swift/Controllers/HistoryViewController.cpp index 1061e78..5cc25e0 100644 --- a/Swift/Controllers/HistoryViewController.cpp +++ b/Swift/Controllers/HistoryViewController.cpp @@ -26,8 +26,11 @@ HistoryViewController::HistoryViewController( HistoryViewController::~HistoryViewController() { uiEventStream_->onUIEvent.disconnect(boost::bind(&HistoryViewController::handleUIEvent, this, _1)); - delete historyWindow_; - delete roster_; + if (historyWindow_) { + historyWindow_->onSelectedContactChanged.disconnect(boost::bind(&HistoryViewController::handleSelectedContactChanged, this, _1)); + delete historyWindow_; + delete roster_; + } } void HistoryViewController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) { @@ -35,24 +38,34 @@ void HistoryViewController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) { if (event != NULL) { if (historyWindow_ == NULL) { historyWindow_ = historyWindowFactory_->createHistoryWindow(uiEventStream_); + historyWindow_->onSelectedContactChanged.connect(boost::bind(&HistoryViewController::handleSelectedContactChanged, this, _1)); + roster_ = new Roster(false, true); historyWindow_->setRosterModel(roster_); - JID putin("vputin@karla.com"); - JID medvedev("dmedvedev@karla.com"); - JID kev("kevin@doomsong.co.uk"); - const std::set<ContactRosterItem::Feature> none; - roster_->addContact(putin, putin, "Vladimir Putin", "Recent", ""); - roster_->addContact(medvedev, medvedev, "Dmitri Medvedev", "Recent", ""); - roster_->addContact(kev, kev, "Kev", "Recent", ""); + std::vector<JID> contacts = historyController_->getAllContacts(); + for (std::vector<JID>::iterator it = contacts.begin(); it != contacts.end(); it++) { + roster_->addContact(*it, *it, *it, "Recent", ""); + } } - std::vector<HistoryMessage> messages = historyController_->getMessages(); - for (std::vector<HistoryMessage>::iterator it = messages.begin(); it != messages.end(); it++) { - historyWindow_->addMessage(*it); - } historyWindow_->activate(); } } +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); + + std::vector<HistoryMessage> messages = historyController_->getMessages(contact->getJID()); + for (std::vector<HistoryMessage>::iterator it = messages.begin(); it != messages.end(); it++) { + historyWindow_->addMessage(*it); + } +} + } diff --git a/Swift/Controllers/HistoryViewController.h b/Swift/Controllers/HistoryViewController.h index f64dd35..94e5df3 100644 --- a/Swift/Controllers/HistoryViewController.h +++ b/Swift/Controllers/HistoryViewController.h @@ -16,6 +16,7 @@ namespace Swift { class HistoryWindowFactory; class HistoryWindow; class Roster; + class RosterItem; class HistoryController; class HistoryViewController { @@ -25,6 +26,7 @@ namespace Swift { private: void handleUIEvent(boost::shared_ptr<UIEvent> event); + void handleSelectedContactChanged(RosterItem* item); private: UIEventStream* uiEventStream_; diff --git a/Swift/Controllers/UIInterfaces/HistoryWindow.h b/Swift/Controllers/UIInterfaces/HistoryWindow.h index 9ec79e2..cc3f0b8 100644 --- a/Swift/Controllers/UIInterfaces/HistoryWindow.h +++ b/Swift/Controllers/UIInterfaces/HistoryWindow.h @@ -18,5 +18,7 @@ namespace Swift { virtual void activate() = 0; virtual void setRosterModel(Roster*) = 0; virtual void addMessage(const HistoryMessage& message) = 0; + + boost::signal<void (RosterItem*)> onSelectedContactChanged; }; } |