summaryrefslogtreecommitdiff
path: root/plugins/HistoryStats/src/settings.h
blob: 450ab1b8ff79f3c26149d77661e78c600eecbddf (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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#if !defined(HISTORYSTATS_GUARD_SETTINGS_H)
#define HISTORYSTATS_GUARD_SETTINGS_H

#include "_globals.h"
#include "_consts.h"

#include "canvas.h"
#include "mirandasettings.h"

// #include "column.h"
class Column;

#include <set>
#include <map>
#include <vector>

class Settings
	: private pattern::NotCopyable<Settings>
{
public:
	// "poor man's constants"
	enum Constants {
		cNumSortLevels = 3,
	};

	// graphic output modes
	enum GraphicsMode {
		gmHTML = 0,
		gmPNG  = 1,
	};

	// PNG output modes
	enum PNGMode {
		pmHTMLFallBack = 0,
		pmEnforcePNG   = 1,
		pmPreferHTML   = 2,
	};

	// meta contact handling modes
	enum MetaContactsMode {
		mcmMetaOnly   = 0,
		mcmSubOnly    = 1,
		mcmBoth       = 2,
		mcmIgnoreMeta = 3,
	};

	// event merge mode
	enum MergeMode {
		mmTolerantMerge = 0,
		mmStrictMerge   = 1,
		mmNoMerge       = 2,
	};

	// sort keys
	enum SortKeyEnum {
		skFIRST              =  0,
		skLAST               = 26,
		skNothing            = -1,
		skNick               =  0,
		skProtocol           =  1,
		skGroup              =  2,
		skBytesOut           =  3,
		skBytesIn            =  4,
		skBytesTotal         =  5,
		skMessagesOut        =  6,
		skMessagesIn         =  7,
		skMessagesTotal      =  8,
		skChatsOut           =  9,
		skChatsIn            = 10,
		skChatsTotal         = 11,
		skChatDurationTotal  = 12,
		skTimeOfFirstMessage = 13,
		skTimeOfLastMessage  = 14,
		skBytesOutAvg        = 15,
		skBytesInAvg         = 16,
		skBytesTotalAvg      = 17,
		skMessagesOutAvg     = 18,
		skMessagesInAvg      = 19,
		skMessagesTotalAvg   = 20,
		skChatsOutAvg        = 21,
		skChatsInAvg         = 22,
		skChatsTotalAvg      = 23,
		skChatDurationMin    = 24,
		skChatDurationAvg    = 25,
		skChatDurationMax    = 26,
	};

	// omit by value data
	enum OmitByValueEnum {
		obvFIRST             =  0,
		obvLAST              = 18,
		obvBytesIn           =  0,
		obvBytesOut          =  1,
		obvBytesTotal        =  2,
		obvBytesInAvg        =  3,
		obvBytesOutAvg       =  4,
		obvBytesTotalAvg     =  5,
		obvMessagesIn        =  6,
		obvMessagesOut       =  7,
		obvMessagesTotal     =  8,
		obvMessagesInAvg     =  9,
		obvMessagesOutAvg    = 10,
		obvMessafesTotalAvg  = 11,
		obvChatsIn           = 12,
		obvChatsOut          = 13,
		obvChatsTotal        = 14,
		obvChatsInAvg        = 15,
		obvChatsOutAvg       = 16,
		obvChatsTotalAvg     = 17,
		obvChatDurationTotal = 18,
	};

	// button IDs for columns
	enum ButtonID {
		biFilterWords = 100,
	};

	// filter word modes
	enum FilterWordsMode {
		fwmFIRST                = 0,
		fwmLAST                 = 7,
		fwmWordsMatching        = 0,
		fwmWordsContaining      = 1,
		fwmWordsStartingWith    = 2,
		fwmWordsEndingWith      = 3,
		fwmMessagesMatching     = 4,
		fwmMessagesContaining   = 5,
		fwmMessagesStartingWith = 6,
		fwmMessagesEndingWith   = 7,
	};

	class CharMapper
		: private pattern::NotCopyable<Settings>
	{
	private:
#if defined(_UNICODE)
		typedef unsigned short t_uchar;
#else // _UNICODE
		typedef unsigned char  t_uchar;
#endif // _UNICODE
#define T_NUMCHARS (1 << (sizeof(TCHAR) * 8))

	private:
		TCHAR m_CharMap[T_NUMCHARS];

#undef T_NUMCHARS

	public:
		explicit CharMapper(const Settings& settings);
		TCHAR mapChar(TCHAR c) const { return m_CharMap[static_cast<t_uchar>(c)]; }
	};

	typedef std::set<ext::string> WordSet;

	class Filter
	{
	private:
		ext::string m_strID;
		ext::string m_strName;
		int m_nMode;
		WordSet m_Words;
		int m_nRef;

	public:
		explicit Filter(const ext::string& strID);

		bool operator ==(const Filter& other) const { return m_strID == other.m_strID; }
		bool operator <(const Filter& other) const { return m_strID < other.m_strID; }

		const ext::string& getID() const { return m_strID; }
		const ext::string& getName() const { return m_strName; }
		void setName(const ext::string& strName) { m_strName = strName; }
		int getMode() const { return m_nMode; }
		void setMode(int nMode) { m_nMode = nMode; }
		const WordSet& getWords() const { return m_Words; }
		void setWords(const WordSet& Words) { m_Words = Words; }
		void clearWords() { m_Words.clear(); }
		void addWord(const ext::string& strWord) { m_Words.insert(strWord); }
		int getRef() const { return m_nRef; }
		void setRef(int nRef) { m_nRef = nRef; }
	};

	typedef std::set<Filter> FilterSet;
	typedef std::set<ext::string> ColFilterSet;

	struct SortKey {
		int by;
		bool asc;
	};

public:
	typedef std::set<ext::a::string> ProtoSet;
	typedef std::vector<Column*> ColumnList;

public:
	static const TCHAR* getDefaultWordDelimiters();
	static const TCHAR* getDefaultStyleSheet();
	static const TCHAR* getDefaultHideContactMenuProtos();
	static const TCHAR* getDefaultProtosIgnore();
	static const TCHAR* getDefaultColumns();
	static const TCHAR* getDefaultSort();
	static const TCHAR* getDefaultOutputFile();
	static const TCHAR* getDefaultOutputExtraFolder();
	static const TCHAR* getDefaultFilterWords();

public:
	const DWORD m_VersionCurrent;

private:
	// column settings
	ColumnList m_Columns;

protected:
	void clearColumns();

public:
	// global settings
	bool        m_OnStartup;
	bool        m_ShowMainMenu;
	bool        m_ShowMainMenuSub;
	bool        m_ShowContactMenu;
	bool        m_ShowContactMenuPseudo;
	ProtoSet    m_HideContactMenuProtos;
	int         m_GraphicsMode;
	int         m_PNGMode;
	bool        m_ThreadLowPriority;
	ext::string m_PathToBrowser;

	// input settings
	int         m_ChatSessionMinDur;
	int         m_ChatSessionTimeout;
	int         m_AverageMinTime;
	ext::string m_WordDelimiters;
	ProtoSet    m_ProtosIgnore;
	int         m_IgnoreOld;
	ext::string m_IgnoreBefore;
	ext::string m_IgnoreAfter;
	bool        m_FilterRawRTF;
	bool        m_FilterBBCodes;
	int         m_MetaContactsMode;
	bool        m_MergeContacts;
	bool        m_MergeContactsGroups;
	int         m_MergeMode;

	// output settings
	bool        m_RemoveEmptyContacts;
	bool        m_RemoveOutChatsZero;
	bool        m_RemoveOutBytesZero;
	bool        m_RemoveInChatsZero;
	bool        m_RemoveInBytesZero;
	bool        m_OmitContacts;
	bool        m_OmitByValue;
	int         m_OmitByValueData;
	int         m_OmitByValueLimit;
	bool        m_OmitByTime;
	int         m_OmitByTimeDays;
	bool        m_OmitByRank;
	int         m_OmitNumOnTop;
	bool        m_OmittedInTotals;
	bool        m_OmittedInExtraRow;
	bool        m_CalcTotals;
	bool        m_TableHeader;
	int			m_TableHeaderRepeat;
	bool        m_TableHeaderVerbose;
	bool		m_HeaderTooltips;
	bool		m_HeaderTooltipsIfCustom;
	SortKey     m_Sort[cNumSortLevels];
	ext::string m_OwnNick;
	bool		m_OutputVariables;
	ext::string m_OutputFile;
	bool        m_OutputExtraToFolder;
	ext::string m_OutputExtraFolder;
	bool        m_OverwriteAlways;
	bool        m_AutoOpenOptions;
	bool        m_AutoOpenStartup;
	bool        m_AutoOpenMenu;

	// shared column data
	FilterSet   m_FilterWords;

public:
	explicit Settings();
	explicit Settings(const Settings& other);
	Settings& operator =(const Settings& other);
	~Settings();

	void assignSettings(const Settings& other) { operator =(other); }

	int countCol() const { return m_Columns.size(); }
	const Column* getCol(int index) const { return m_Columns[index]; }
	Column* getCol(int index) { return m_Columns[index]; }
	int addCol(Column* pCol);
	bool delCol(int index);
	bool delCol(Column* pCol);
	bool moveCol(Column* pCol, Column* pInsertAfter);

	bool manageFilterWords(HWND hParent, Column* pCol);
	const Filter* getFilter(const ext::string& strID) const;

	ext::string getOutputFile(DWORD timeStarted) const;
	ext::string getOutputPrefix(DWORD timeStarted) const;
	bool isPNGOutputActiveAndAvailable() const;
	DWORD getIgnoreBefore() const;
	DWORD getIgnoreAfter() const;

	void ensureConstraints();

	void openURL(const TCHAR* szURL);
};

#endif // HISTORYSTATS_GUARD_SETTINGS_H