/* * Copyright (c) 2012 Catalin Badea * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #include #include #include #include #include namespace Swift { 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)); } HistoryViewController::~HistoryViewController() { uiEventStream_->onUIEvent.disconnect(boost::bind(&HistoryViewController::handleUIEvent, this, _1)); if (historyWindow_) { historyWindow_->onSelectedContactChanged.disconnect(boost::bind(&HistoryViewController::handleSelectedContactChanged, this, _1)); delete historyWindow_; delete roster_; } } void HistoryViewController::handleUIEvent(boost::shared_ptr rawEvent) { boost::shared_ptr event = boost::dynamic_pointer_cast(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_); std::vector contacts = historyController_->getAllContacts(); for (std::vector::iterator it = contacts.begin(); it != contacts.end(); it++) { roster_->addContact(*it, *it, *it, "Recent", ""); } } 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(newContact); std::vector messages; //TODO = historyController_->getMessages(contact->getJID()); for (std::vector::iterator it = messages.begin(); it != messages.end(); it++) { historyWindow_->addMessage(*it); } } }