summaryrefslogtreecommitdiffstats
blob: d0671901b1553a8204e9730003422ae449ef17b1 (plain)
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
72
73
74
75
/*
 * Copyright (c) 2012 Catalin Badea
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

#include <QtHistoryWindow.h>
#include <QtTabbable.h>

#include <QtSwiftUtil.h>
#include <MessageSnippet.h>
#include <Swiften/History/HistoryMessage.h>
#include <string>

#include <boost/shared_ptr.hpp>
#include <boost/smart_ptr/make_shared.hpp>

namespace Swift {

QtHistoryWindow::QtHistoryWindow(SettingsProvider* settings, UIEventStream* eventStream) {
	ui_.setupUi(this);

	theme_ = new QtChatTheme("");

	delete ui_.conversation_;
	conversation_ = new QtChatView(theme_, this);
	QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
	sizePolicy.setHorizontalStretch(80);
	sizePolicy.setVerticalStretch(0);
	conversation_->setSizePolicy(sizePolicy);

	ui_.conversation_ = conversation_;
	ui_.bottomLayout_->addWidget(conversation_);

	delete ui_.conversationRoster_;
	conversationRoster_ = new QtRosterWidget(eventStream, settings, this);
	QSizePolicy sizePolicy2(QSizePolicy::Preferred, QSizePolicy::Expanding);
	sizePolicy2.setVerticalStretch(80);
	conversationRoster_->setSizePolicy(sizePolicy2);
	ui_.conversationRoster_ = conversationRoster_;
	ui_.bottomLeftLayout_->setDirection(QBoxLayout::BottomToTop);
	ui_.bottomLeftLayout_->addWidget(conversationRoster_);

	setWindowTitle(tr("History"));
}

QtHistoryWindow::~QtHistoryWindow() {
	delete theme_;
}

void QtHistoryWindow::activate() {
	emit wantsToActivate();
}

void QtHistoryWindow::showEvent(QShowEvent* event) {
	emit windowOpening();
	emit titleUpdated();
	QWidget::showEvent(event);
}

void QtHistoryWindow::closeEvent(QCloseEvent* event) {
	emit windowClosing();
	event->accept();
}

void QtHistoryWindow::setRosterModel(Roster* model) {
	conversationRoster_->setRosterModel(model);
}

void QtHistoryWindow::addMessage(const HistoryMessage& message) {
	boost::shared_ptr<MessageSnippet> snippet(new MessageSnippet(QString::fromStdString(message.getMessage()), QString::fromStdString(message.getDisplayNick()), QDateTime::currentDateTime(), "", false, false, theme_, "id")); 
	conversation_->addMessage(snippet);
}

}