diff options
author | Catalin Badea <catalin.badea392@gmail.com> | 2012-06-27 17:53:07 (GMT) |
---|---|---|
committer | Catalin Badea <catalin.badea392@gmail.com> | 2012-06-27 17:53:07 (GMT) |
commit | 72819f0c95ad3fe264806d3a072fcbfab3131fcf (patch) | |
tree | 002cdb467597cfbe774b93f49400e3facd9efe43 /Swift/Controllers/HistoryViewController.cpp | |
parent | 0998d6a8f138e0fd00245fc3c1efc8878fa7b888 (diff) | |
download | swift-contrib-72819f0c95ad3fe264806d3a072fcbfab3131fcf.zip swift-contrib-72819f0c95ad3fe264806d3a072fcbfab3131fcf.tar.bz2 |
Display conversations by using roster selection
Diffstat (limited to 'Swift/Controllers/HistoryViewController.cpp')
-rw-r--r-- | Swift/Controllers/HistoryViewController.cpp | 39 |
1 files changed, 26 insertions, 13 deletions
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); + } +} + } |