summaryrefslogtreecommitdiff
path: root/plugins/HistoryStats/src/column_inout.cpp
blob: 9f003f2b9a24100a4d05bc7714135359278f0b89 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include "stdafx.h"
#include "column_inout.h"

/*
 * ColInOut
 */

ColInOut::ColInOut()
	: m_nSource(2), m_bAbsolute(false), m_nAbsTime(1),
	m_hSource(nullptr), m_hAbsolute(nullptr), m_hAbsTime(nullptr)
{
}

void ColInOut::impl_copyConfig(const Column* pSource)
{
	const ColInOut& src = *reinterpret_cast<const ColInOut*>(pSource);

	m_nSource   = src.m_nSource;
	m_bAbsolute = src.m_bAbsolute;
	m_nAbsTime  = src.m_nAbsTime;
}

void ColInOut::impl_configRead(const SettingsTree& settings)
{
	m_nSource   = settings.readIntRanged(con::KeySource  , 2, 0, 8);
	m_bAbsolute = settings.readBool     (con::KeyAbsolute, false);
	m_nAbsTime  = settings.readIntRanged(con::KeyAbsTime , 1, 0, 2);
}

void ColInOut::impl_configWrite(SettingsTree& settings) const
{
	settings.writeInt (con::KeySource  , m_nSource  );
	settings.writeBool(con::KeyAbsolute, m_bAbsolute);
	settings.writeInt (con::KeyAbsTime , m_nAbsTime );
}

void ColInOut::impl_configToUI(OptionsCtrl& Opt, OptionsCtrl::Item hGroup)
{
	OptionsCtrl::Group hTemp;

	m_hSource   = Opt.insertCombo(hGroup, TranslateT("Data source"));
	hTemp       = Opt.insertGroup(hGroup, TranslateT("Display as"));
	m_hAbsolute = Opt.insertRadio(hTemp, nullptr, TranslateT("Absolute"));
	m_hAbsolute = Opt.insertRadio(hTemp, m_hAbsolute, TranslateT("Average"), OptionsCtrl::OCF_DISABLECHILDSONUNCHECK);
	m_hAbsTime  = Opt.insertRadio(m_hAbsolute, nullptr, TranslateT("Units per day"));
	              Opt.insertRadio(m_hAbsolute, m_hAbsTime, TranslateT("Units per week"));
	              Opt.insertRadio(m_hAbsolute, m_hAbsTime, TranslateT("Units per month (30 days)"));

	static const wchar_t* sourceTexts[] = {
		LPGENW("Characters (incoming)"),
		LPGENW("Characters (outgoing)"),
		LPGENW("Characters (all)"),
		LPGENW("Messages (incoming)"),
		LPGENW("Messages (outgoing)"),
		LPGENW("Messages (all)"),
		LPGENW("Chats (incoming)"),
		LPGENW("Chats (outgoing)"),
		LPGENW("Chats (all)"),
	};

	array_each_(i, sourceTexts)
	{
		Opt.addComboItem(m_hSource, TranslateW(sourceTexts[i]));
	}

	Opt.setComboSelected(m_hSource  , m_nSource          );
	Opt.setRadioChecked (m_hAbsolute, m_bAbsolute ? 0 : 1);
	Opt.setRadioChecked (m_hAbsTime , m_nAbsTime         );
}

void ColInOut::impl_configFromUI(OptionsCtrl& Opt)
{
	m_nSource   = Opt.getComboSelected(m_hSource);
	m_bAbsolute = (Opt.getRadioChecked(m_hAbsolute) == 0);
	m_nAbsTime  = Opt.getRadioChecked(m_hAbsTime);
}

void ColInOut::impl_outputRenderHeader(ext::ostream& tos, int row, int rowSpan) const
{
	static const wchar_t* szShortDesc[] = {
		LPGENW("Characters"),
		LPGENW("Messages"),
		LPGENW("Chats")
	};

	static const wchar_t* szSourceDesc[] = {
		LPGENW("Incoming characters"),
		LPGENW("Outgoing characters"),
		LPGENW("Characters"),
		LPGENW("Incoming messages"),
		LPGENW("Outgoing messages"),
		LPGENW("Messages"),
		LPGENW("Incoming chats"),
		LPGENW("Outgoing chats"),
		LPGENW("Chats")
	};

	static const wchar_t* szUnitDesc[] = {
		LPGENW("day"),
		LPGENW("week"),
		LPGENW("month"),
	};

	if (row == 1)
	{
		ext::string strTitle;

		if (m_bAbsolute)
		{
			strTitle = TranslateW(szSourceDesc[m_nSource]);
		}
		else
		{
			strTitle = str(ext::kformat(TranslateT("#{data} per #{unit}"))
				% L"#{data}" * TranslateW(szSourceDesc[m_nSource])
				% L"#{unit}" * TranslateW(szUnitDesc[m_nAbsTime]));
		}

		writeRowspanTD(tos, getCustomTitle(TranslateW(szShortDesc[m_nSource / 3]), strTitle), row, 1, rowSpan);
	}
}

void ColInOut::impl_outputRenderRow(ext::ostream& tos, const Contact& contact, DisplayType)
{
	if (m_bAbsolute)
	{
		static int (Contact::*getData[])() const = {
			&Contact::getInBytes,
			&Contact::getOutBytes,
			&Contact::getTotalBytes,
			&Contact::getInMessages,
			&Contact::getOutMessages,
			&Contact::getTotalMessages,
			&Contact::getInChats,
			&Contact::getOutChats,
			&Contact::getTotalChats,
		};

		tos << L"<td class=\"num\">"
			<< utils::intToGrouped((contact.*getData[m_nSource])())
			<< L"</td>" << ext::endl;
	}
	else
	{
		static double (Contact::*getData[])() const = {
			&Contact::getInBytesAvg,
			&Contact::getOutBytesAvg,
			&Contact::getTotalBytesAvg,
			&Contact::getInMessagesAvg,
			&Contact::getOutMessagesAvg,
			&Contact::getTotalMessagesAvg,
			&Contact::getInChatsAvg,
			&Contact::getOutChatsAvg,
			&Contact::getTotalChatsAvg,
		};

		static const double avgFactor[] = {
			60.0 * 60.0 * 24.0,
			60.0 * 60.0 * 24.0 * 7.0,
			60.0 * 60.0 * 24.0 * 30.0,
		};

		tos << L"<td class=\"num\">"
			<< utils::floatToGrouped((contact.*getData[m_nSource])() * avgFactor[m_nAbsTime], 1)
			<< L"</td>" << ext::endl;
	}
}