summaryrefslogtreecommitdiffstats
blob: e81eabd55abf8547ab6a7b2130866c0ff3a6abb7 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * Copyright (c) 2011 Vlad Voicu
 * Licensed under the Simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

#include <QWidget>
#include <QBoxLayout>
#include <QString>
#include <cstring>

#include "QtViewHistoryWindow.h"
#include "QtChatView.h"
#include "QtChatTheme.h"
#include "MessageSnippet.h"
#include "QtSwiftUtil.h"
#include <QDebug>
#include <QStandardItemModel>

#include <boost/bind.hpp>
#include <stdio.h>

#include "boost/date_time/posix_time/posix_time.hpp"

namespace Swift {

QtViewHistoryWindow::QtViewHistoryWindow() {
	ui.setupUi(this);
	QStandardItemModel *dummyModel = new QStandardItemModel(2, 2);
	QStandardItem *item = new QStandardItem(QString("test row, test column"));
	QStandardItem *item2 = new QStandardItem(QString("test row2, test column2"));
	dummyModel->setItem(0, 0, item);
	dummyModel->setItem(0, 1, item2);
	ui.userHistory_->setModel(dummyModel);
	addDummyMessage();
	connect(ui.periodPickerBefore_, SIGNAL(valueChanged(int)), this, SLOT(handleBeforeSliderValueChanged(int)));
	connect(ui.periodPickerAfter_, SIGNAL(valueChanged(int)), this, SLOT(handleAfterSliderValueChanged(int)));
	show();
}

void QtViewHistoryWindow::addDummyMessage() {
	QtChatTheme *theme = new QtChatTheme(""); // Where should I get the theme path from?
	QString *htmlString = new QString("test");
	boost::posix_time::ptime time = boost::posix_time::microsec_clock::universal_time();
	QtChatView* messageLog_ = new QtChatView(theme, NULL);
	std::string id = "test";
	std::string path = "";
	messageLog_->addMessage(boost::shared_ptr <ChatSnippet>(new MessageSnippet(*htmlString, *htmlString, B2QDATE(time), P2QSTRING(path), true, false, theme, P2QSTRING(id))));
	messageLog_->addMessage(boost::shared_ptr <ChatSnippet>(new MessageSnippet(*htmlString, *htmlString, B2QDATE(time), P2QSTRING(path), true, false, theme, P2QSTRING(id))));
	messageLog_->addMessage(boost::shared_ptr <ChatSnippet>(new MessageSnippet(*htmlString, *htmlString, B2QDATE(time), P2QSTRING(path), true, false, theme, P2QSTRING(id))));
	messageLog_->addMessage(boost::shared_ptr <ChatSnippet>(new MessageSnippet(*htmlString, *htmlString, B2QDATE(time), P2QSTRING(path), true, false, theme, P2QSTRING(id))));
	ui.chatView_->addWidget(messageLog_);
}

void QtViewHistoryWindow::show() {
	QWidget::show();
	QWidget::activateWindow();
}

void QtViewHistoryWindow::setEnabled(bool enabled) {
	QWidget::setEnabled(enabled);
}

std::string QtViewHistoryWindow::getLabel(const int value) {
	std::string labelText;
	switch (value / 16) {
		case 0:
			labelText = "1 day";
			break;
		case 1:
			labelText = "3 days";
			break;
		case 2:
			labelText = "1 week";
			break;
		case 3:
			labelText = "2 weeks";
			break;
		case 4:
			labelText = "1 month";
			break;
		case 5:
			labelText = "3 months";
			break;
		case 6:
			labelText = "1 year";
			break;
	}
	return labelText;
}

void QtViewHistoryWindow::handleBeforeSliderValueChanged(const int value) {
	QString labelText = P2QSTRING(getLabel(value));
	ui.beforePeriodLabel_->setText(labelText);
}

void QtViewHistoryWindow::handleAfterSliderValueChanged(const int value) {
	QString labelText = P2QSTRING(getLabel(value));
	ui.afterPeriodLabel_->setText(labelText);
}

}