summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/HistoryViewController.cpp')
-rw-r--r--Swift/Controllers/HistoryViewController.cpp39
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);
+ }
+}
+
}