summaryrefslogtreecommitdiff
path: root/plugins/Boltun/src/config.cpp
blob: b05a560b2b3939e37e9de562028d91c0f6051c20 (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
//***********************************************************
//	Copyright © 2003-2008 Alexander S. Kiselev, Valentin Pavlyuchenko
//
//	This file is part of Boltun.
//
//    Boltun is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 2 of the License, or
//    (at your option) any later version.
//
//    Boltun is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//	  along with Boltun. If not, see <http://www.gnu.org/licenses/>.
//
//***********************************************************

#include "boltun.h"

//Database keys
#define DB_EVERYBODY "Everybody"
#define DB_NOT_IN_LIST "NotInList"
#define DB_AUTOAWAY "AutoAway"
#define DB_WARN "Warn"
#define DB_MARK_READ "MarkRead"
#define DB_WAIT_TIME "WaitTime"
#define DB_THINK_TIME "ThinkTime"
#define DB_PAUSE_DEPENDS "PauseDepends"
#define DB_PAUSE_RANDOM "PauseRandom"
#define DB_WARN_TEXT "WarnText"
#define DB_MIND_FILE_NAME "MindFileName"
#define DB_ENGINE_SILENT "SilentEngine"
#define DB_ENGINE_LOWERCASE "MakeLowerCase"
#define DB_ENGINE_UNDERSTAND_ALWAYS "UnderstandAlways"

inline TCHAR* GetString(char* key, const TCHAR* def)
{
	DBVARIANT dbv;
	TCHAR* val;
	if (!db_get_ts(NULL, BOLTUN_KEY, key, &dbv))
	{
		size_t len = wcslen(dbv.ptszVal) + 1;
		val = new TCHAR[len];
		_tcscpy_s(val, len, dbv.ptszVal);
		db_free(&dbv);
	}
	else
	{
		size_t len = wcslen(def) + 1;
		val = new TCHAR[len];
		_tcscpy_s(val, len, def);
	}
	return val;
}

inline const TCHAR* SetString(char* key, const TCHAR* value)
{
	size_t len = _tcslen(value) + 1;
	TCHAR* val = new TCHAR[len];
	_tcscpy_s(val, len, value);
	db_set_ts(NULL, BOLTUN_KEY, key, val);
	return val;
}

#define BUILDETTERS(x, str, def) \
	const bool BoltunConfig::Get##x() { \
	return db_get_dw(NULL, BOLTUN_KEY, str, def) != 0; } \
	const bool BoltunConfig::Set##x(const bool value) { \
	db_set_dw(NULL, BOLTUN_KEY, str, value); \
	return value; }

#define BUILDINTETTERS(x, str, def) \
	const int BoltunConfig::Get##x() { \
	return db_get_dw(NULL, BOLTUN_KEY, str, def); } \
	const int BoltunConfig::Set##x(const int value) { \
	db_set_dw(NULL, BOLTUN_KEY, str, value); \
	return value; }

#define BUILDSTRETTERS(x, str, def) \
	const TCHAR* BoltunConfig::Get##x() { \
	return GetString(str, def); } \
	const TCHAR* BoltunConfig::Set##x(const TCHAR* value) { \
	return SetString(str, value); }

#define BUILDINIT(x) \
	x(&BoltunConfig::Get##x, &BoltunConfig::Set##x)

BUILDETTERS(TalkWithNotInList, DB_NOT_IN_LIST, false);
BUILDETTERS(TalkWithEverybody, DB_EVERYBODY, false);
BUILDETTERS(TalkWarnContacts, DB_WARN, false);
BUILDETTERS(TalkEveryoneWhileAway, DB_AUTOAWAY, false);
BUILDETTERS(MarkAsRead, DB_MARK_READ, true);
BUILDINTETTERS(AnswerPauseTime, DB_WAIT_TIME, 2);
BUILDINTETTERS(AnswerThinkTime, DB_THINK_TIME, 4);
BUILDETTERS(PauseDepends, DB_PAUSE_DEPENDS, TRUE);
BUILDETTERS(PauseRandom, DB_PAUSE_RANDOM, TRUE);
BUILDSTRETTERS(WarnText, DB_WARN_TEXT, TranslateTS(DEFAULT_WARN_TEXT));
BUILDSTRETTERS(MindFileName, DB_MIND_FILE_NAME, DEFAULT_MIND_FILE);
BUILDETTERS(EngineStaySilent, DB_ENGINE_SILENT, FALSE);
BUILDETTERS(EngineMakeLowerCase, DB_ENGINE_LOWERCASE, FALSE);
BUILDETTERS(EngineUnderstandAlways, DB_ENGINE_UNDERSTAND_ALWAYS, FALSE);

BoltunConfig::BoltunConfig()
	:BUILDINIT(TalkWithEverybody),
	BUILDINIT(TalkWithNotInList),
	BUILDINIT(TalkWarnContacts),
	BUILDINIT(TalkEveryoneWhileAway),
	BUILDINIT(MarkAsRead),
	BUILDINIT(AnswerPauseTime),
	BUILDINIT(AnswerThinkTime),
	BUILDINIT(PauseDepends),
	BUILDINIT(PauseRandom),
	BUILDINIT(WarnText),
	BUILDINIT(MindFileName),
	BUILDINIT(EngineStaySilent),
	BUILDINIT(EngineMakeLowerCase),
	BUILDINIT(EngineUnderstandAlways)
{
	TalkWithEverybody.SetOwner(this);
	TalkWithNotInList.SetOwner(this);
	TalkWarnContacts.SetOwner(this);
	TalkEveryoneWhileAway.SetOwner(this);
	MarkAsRead.SetOwner(this);
	AnswerPauseTime.SetOwner(this);
	AnswerThinkTime.SetOwner(this);
	PauseDepends.SetOwner(this);
	PauseRandom.SetOwner(this);
	WarnText.SetOwner(this);
	MindFileName.SetOwner(this);
	EngineStaySilent.SetOwner(this);
	EngineMakeLowerCase.SetOwner(this);
	EngineUnderstandAlways.SetOwner(this);
}

BoltunConfig::~BoltunConfig()
{
}

class _BoltunConfigInit
{
public:
	 BoltunConfig cfg;
};

_BoltunConfigInit inst;

BoltunConfig &Config = inst.cfg;