summaryrefslogtreecommitdiff
path: root/plugins/WinterSpeak/src/ConfigDatabase.cpp
diff options
context:
space:
mode:
authorPhilip Schell <github.com@blubbfish.net>2013-10-19 13:05:02 +0000
committerPhilip Schell <github.com@blubbfish.net>2013-10-19 13:05:02 +0000
commit397e25f2b71347c7c83495fe5b25496ff3b02b75 (patch)
tree71f6ad2ef525218541a7a35cc659b4fb7bf047d6 /plugins/WinterSpeak/src/ConfigDatabase.cpp
parent9e786b686fae94e71279a797047a91ffdc4b0443 (diff)
WinterSpeak: ticket:269 WinterSpeak now rewritten
git-svn-id: http://svn.miranda-ng.org/main/trunk@6532 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/WinterSpeak/src/ConfigDatabase.cpp')
-rw-r--r--plugins/WinterSpeak/src/ConfigDatabase.cpp146
1 files changed, 146 insertions, 0 deletions
diff --git a/plugins/WinterSpeak/src/ConfigDatabase.cpp b/plugins/WinterSpeak/src/ConfigDatabase.cpp
new file mode 100644
index 0000000000..64af1e35f4
--- /dev/null
+++ b/plugins/WinterSpeak/src/ConfigDatabase.cpp
@@ -0,0 +1,146 @@
+#include "Common.h"
+#include "ConfigDatabase.h"
+
+
+namespace
+{
+ const char *SPEAK = "speak_config";
+ const char *ACTIVE_FLAGS = "active_flags";
+ const char *ACTIVE_STATE = "active_state";
+ const char *ACTIVE_MSG = "active_msg";
+ 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";
+}
+
+ConfigDatabase::ConfigDatabase() : m_voice_desc(), m_active_flags(0), m_welcome_msg(L""), m_active_users()
+{
+ // load the database from miranda
+ load();
+}
+
+
+ConfigDatabase::~ConfigDatabase(void)
+{
+}
+
+
+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);
+ }
+}
+
+//------------------------------------------------------------------------------
+ConfigDatabase::act 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())
+ {
+ ConfigDatabase::act ret;
+ ret.message = false;
+ ret.status = false;
+ return ret;
+ }
+ }
+
+ return iter->second;
+}
+
+//------------------------------------------------------------------------------
+void ConfigDatabase::setActiveUser(HANDLE user, act state)
+{
+ m_active_users[user].status = state.status;
+ m_active_users[user].message = state.message;
+}
+
+//------------------------------------------------------------------------------
+void ConfigDatabase::load()
+{
+ m_voice_desc.engine = DBGetContactSettingString(SPEAK, ENGINE, L"");
+ m_voice_desc.voice = DBGetContactSettingString(SPEAK, VOICE, L"");
+ m_voice_desc.volume = db_get_dw(NULL, SPEAK, VOLUME, 50);
+ m_voice_desc.pitch = db_get_dw(NULL, SPEAK, PITCH, 50);
+ m_voice_desc.rate = db_get_dw(NULL, SPEAK, RATE, 50);
+
+ m_active_flags = db_get_dw(NULL, SPEAK, ACTIVE_FLAGS, 0xffff);
+
+ m_welcome_msg = DBGetContactSettingString(SPEAK, WELCOME_MSG, L"Welcome to Miranda");
+
+ // iterate through all the users and add them to the list if active
+ HANDLE contact = db_find_first();
+
+ while (NULL != contact)
+ {
+ m_active_users[contact].status = (db_get_b(contact, SPEAK, ACTIVE_STATE, true) != 0);
+ m_active_users[contact].message = (db_get_b(contact, SPEAK, ACTIVE_MSG, true) != 0);
+
+ contact = db_find_next(contact);
+ }
+
+ // load unknown users setting
+ m_active_users[0].status = (db_get_b(NULL, SPEAK, ACTIVE_STATE, true) != 0);
+ m_active_users[0].message = (db_get_b(NULL, SPEAK, ACTIVE_MSG, true) != 0);
+}
+
+//------------------------------------------------------------------------------
+void ConfigDatabase::save()
+{
+ db_set_ts(NULL, SPEAK, ENGINE, m_voice_desc.engine.c_str());
+ db_set_ts(NULL, SPEAK, VOICE, m_voice_desc.voice.c_str());
+ db_set_dw(NULL, SPEAK, VOLUME, m_voice_desc.volume);
+ db_set_dw(NULL, SPEAK, PITCH, m_voice_desc.pitch);
+ db_set_dw(NULL, SPEAK, RATE, m_voice_desc.rate);
+
+ db_set_dw(NULL, SPEAK, ACTIVE_FLAGS, m_active_flags);
+
+ db_set_ts(NULL, SPEAK, WELCOME_MSG, m_welcome_msg.c_str());
+
+ for (ActiveUsersMap::iterator i = m_active_users.begin(); i != m_active_users.end(); ++i)
+ {
+ db_set_b(i->first, SPEAK, ACTIVE_STATE, i->second.status);
+ db_set_b(i->first, SPEAK, ACTIVE_MSG, i->second.message);
+ }
+
+ // notify the subjects that things have changed
+ notify();
+}
+
+//------------------------------------------------------------------------------
+// private:
+//------------------------------------------------------------------------------
+std::wstring ConfigDatabase::DBGetContactSettingString(const char *szModule, const char *szSetting, const WCHAR *def)
+{
+ std::wstring ret = def;
+ DBVARIANT dbv;
+
+ if (!db_get_ts(NULL, szModule, szSetting, &dbv))
+ {
+ ret = dbv.pwszVal;
+ }
+
+ return ret;
+}
+
+//==============================================================================