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
|
//==============================================================================
// Miranda Speak Plugin, © 2002 Ryan Winter
//==============================================================================
#pragma warning(disable:4786)
#include "config_database.h"
#include "speak.h"
#include <general/debug/debug.h>
//------------------------------------------------------------------------------
namespace
{
const char *SPEAK = "speak_config";
const char *ACTIVE_FLAGS = "active_flags";
const char *ACTIVE_STATE = "active_state";
const char *WELCOME_MSG = "welcome_msg";
const char *ENGINE = "engine";
const char *VOICE = "voice";
const char *VOLUME = "volume";
const char *RATE = "rate";
const char *PITCH = "pitch";
}
//------------------------------------------------------------------------------
// public:
//------------------------------------------------------------------------------
ConfigDatabase::ConfigDatabase()
:
m_voice_desc(),
m_active_flags(0),
m_welcome_msg(""),
m_active_users()
{
CLASSCERR("ConfigDatabase::ConfigDatabase");
// load the database from miranda
load();
}
//------------------------------------------------------------------------------
ConfigDatabase::~ConfigDatabase()
{
CLASSCERR("ConfigDatabase::~ConfigDatabase");
}
//------------------------------------------------------------------------------
bool
ConfigDatabase::getActiveFlag(ActiveFlag flag) const
{
return ((m_active_flags & (1 << flag)) != 0);
}
//------------------------------------------------------------------------------
void
ConfigDatabase::setActiveFlag(ActiveFlag flag, bool state)
{
if (state)
{
m_active_flags |= (1 << flag);
}
else
{
m_active_flags &= ~(1 << flag);
}
}
//------------------------------------------------------------------------------
bool
ConfigDatabase::getActiveUser(HANDLE user) const
{
ActiveUsersMap::const_iterator iter = m_active_users.find(user);
if (iter == m_active_users.end())
{
// get the unknown user status
iter = m_active_users.find(0);
if (iter == m_active_users.end())
{
CLASSCERR("ConfigDatabase::getActiveUser user error");
return false;
}
}
return iter->second;
}
//------------------------------------------------------------------------------
void
ConfigDatabase::setActiveUser(HANDLE user, bool state)
{
m_active_users[user] = state;
}
//------------------------------------------------------------------------------
void
ConfigDatabase::load()
{
CLASSCERR("ConfigDatabase::load");
m_voice_desc.engine = DBGetContactSettingString(SPEAK, ENGINE, "");
m_voice_desc.voice = DBGetContactSettingString(SPEAK, VOICE, "");
m_voice_desc.volume = DBGetContactSettingDword(NULL, SPEAK, VOLUME, 50);
m_voice_desc.pitch = DBGetContactSettingDword(NULL, SPEAK, PITCH, 50);
m_voice_desc.rate = DBGetContactSettingDword(NULL, SPEAK, RATE, 50);
m_active_flags = DBGetContactSettingDword(NULL, SPEAK, ACTIVE_FLAGS, 0xffff);
m_welcome_msg = DBGetContactSettingString(SPEAK, WELCOME_MSG,
"welcome to i c q");
// iterate through all the users and add them to the list if active
HANDLE contact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
while (NULL != contact)
{
m_active_users[contact]
= DBGetContactSettingByte(contact, SPEAK, ACTIVE_STATE, true);
contact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)contact, 0);
}
// load unknown users setting
m_active_users[0] = DBGetContactSettingByte(NULL, SPEAK, ACTIVE_STATE, true);
}
//------------------------------------------------------------------------------
void
ConfigDatabase::save()
{
CLASSCERR("ConfigDatabase::save");
DBWriteContactSettingString(NULL, SPEAK, ENGINE, m_voice_desc.engine.c_str());
DBWriteContactSettingString(NULL, SPEAK, VOICE, m_voice_desc.voice.c_str());
DBWriteContactSettingDword(NULL, SPEAK, VOLUME, m_voice_desc.volume);
DBWriteContactSettingDword(NULL, SPEAK, PITCH, m_voice_desc.pitch);
DBWriteContactSettingDword(NULL, SPEAK, RATE, m_voice_desc.rate);
DBWriteContactSettingDword(NULL, SPEAK, ACTIVE_FLAGS, m_active_flags);
DBWriteContactSettingString(NULL, SPEAK, WELCOME_MSG, m_welcome_msg.c_str());
for (ActiveUsersMap::iterator i = m_active_users.begin();
i != m_active_users.end(); ++i)
{
DBWriteContactSettingByte(i->first, SPEAK, ACTIVE_STATE, i->second);
}
// notify the subjects that things have changed
notify();
}
//------------------------------------------------------------------------------
// private:
//------------------------------------------------------------------------------
std::string
ConfigDatabase::DBGetContactSettingString(const char *szModule,
const char *szSetting, const char *def)
{
std::string ret = def;
DBVARIANT dbv;
if (!DBGetContactSetting(NULL, szModule, szSetting, &dbv))
{
ret = dbv.pszVal;
}
return ret;
}
//==============================================================================
|