1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
/*
* Copyright (c) 2012 Catalin Badea
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
#include <Swift/Controllers/HistoryViewController.h>
#include <Swift/Controllers/UIInterfaces/HistoryWindowFactory.h>
#include <Swift/Controllers/UIEvents/RequestHistoryUIEvent.h>
#include <Swift/Controllers/HistoryController.h>
#include <Swiften/History/HistoryMessage.h>
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<UIEvent> rawEvent) {
boost::shared_ptr<RequestHistoryUIEvent> event = boost::dynamic_pointer_cast<RequestHistoryUIEvent>(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<JID> contacts = historyController_->getAllContacts();
for (std::vector<JID>::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<ContactRosterItem*>(newContact);
std::vector<HistoryMessage> messages; //TODO = historyController_->getMessages(contact->getJID());
for (std::vector<HistoryMessage>::iterator it = messages.begin(); it != messages.end(); it++) {
historyWindow_->addMessage(*it);
}
}
}
|