summaryrefslogtreecommitdiff
path: root/plugins/HistoryStats/src/mirandasettings.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-03-04 23:23:45 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-03-04 23:23:45 +0000
commit15855fa84a09fd1fd486d357c38db0f2bd181e74 (patch)
treec98d1ae74abca41c776522059343eda13a7e0a31 /plugins/HistoryStats/src/mirandasettings.cpp
parent819f8efabea6b0d7d971f9e6e4b21bbc18838874 (diff)
HistoryStats compiles ok now
git-svn-id: http://svn.miranda-ng.org/main/trunk@8399 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/HistoryStats/src/mirandasettings.cpp')
-rw-r--r--plugins/HistoryStats/src/mirandasettings.cpp143
1 files changed, 143 insertions, 0 deletions
diff --git a/plugins/HistoryStats/src/mirandasettings.cpp b/plugins/HistoryStats/src/mirandasettings.cpp
new file mode 100644
index 0000000000..34d8342d38
--- /dev/null
+++ b/plugins/HistoryStats/src/mirandasettings.cpp
@@ -0,0 +1,143 @@
+#include "_globals.h"
+#include "mirandasettings.h"
+
+
+MirandaSettings::MirandaSettings()
+ : m_hContact(0)
+{
+}
+
+bool MirandaSettings::readBool(const mu_ansi* szSetting, bool bDefault) const
+{
+ return (readByte(szSetting, bDefault ? 1 : 0) != 0);
+}
+
+int MirandaSettings::readByte(const mu_ansi* szSetting, int bDefault) const
+{
+ return db_get_b(m_hContact, m_strModule.c_str(), szSetting, bDefault);
+}
+
+int MirandaSettings::readWord(const mu_ansi* szSetting, int wDefault) const
+{
+ return db_get_w(m_hContact, m_strModule.c_str(), szSetting, wDefault);
+}
+
+int MirandaSettings::readDWord(const mu_ansi* szSetting, int dwDefault) const
+{
+ return db_get_dw(m_hContact, m_strModule.c_str(), szSetting, dwDefault);
+}
+
+ext::string MirandaSettings::readStr(const mu_ansi* szSetting, const mu_text* szDefault) const
+{
+ DBVARIANT dbv;
+ if (db_get_s(m_hContact, m_strModule.c_str(), szSetting, &dbv))
+ return szDefault;
+
+ ext::string str = (dbv.type != DBVT_ASCIIZ) ? szDefault : utils::fromUTF8(dbv.pszVal);
+ db_free(&dbv);
+ return str;
+}
+
+ext::string MirandaSettings::readStrDirect(const mu_ansi* szSetting, const mu_text* szDefault) const
+{
+ DBVARIANT dbv;
+
+ ZeroMemory(&dbv, sizeof(dbv));
+
+ dbv.type = DBVT_WCHAR;
+
+ if (db_get_s(m_hContact, m_strModule.c_str(), szSetting, &dbv, 0))
+ return szDefault;
+
+ ext::string str;
+
+ switch (dbv.type) {
+ case DBVT_ASCIIZ:
+ str = utils::fromA(dbv.pszVal);
+ break;
+
+ case DBVT_WCHAR:
+ str = utils::fromW(dbv.pwszVal);
+ break;
+
+ case DBVT_UTF8:
+ str = utils::fromUTF8(dbv.pszVal);
+ break;
+
+ default:
+ str = szDefault;
+ break;
+ }
+
+ db_free(&dbv);
+ return str;
+}
+
+void MirandaSettings::readTree(const mu_ansi* szSetting, const mu_text* szDefault, SettingsTree& value) const
+{
+ value.fromString(readStr(szSetting, szDefault));
+}
+
+void MirandaSettings::writeBool(const mu_ansi* szSetting, bool bValue) const
+{
+ writeByte(szSetting, bValue ? 1 : 0);
+}
+
+void MirandaSettings::writeByte(const mu_ansi* szSetting, int bValue) const
+{
+ db_set_b(m_hContact, m_strModule.c_str(), szSetting, bValue);
+}
+
+void MirandaSettings::writeWord(const mu_ansi* szSetting, int wValue) const
+{
+ db_set_w(m_hContact, m_strModule.c_str(), szSetting, wValue);
+}
+
+void MirandaSettings::writeDWord(const mu_ansi* szSetting, int dwValue) const
+{
+ db_set_dw(m_hContact, m_strModule.c_str(), szSetting, dwValue);
+}
+
+void MirandaSettings::writeStr(const mu_ansi* szSetting, const mu_text* szValue) const
+{
+ db_set_ts(m_hContact, m_strModule.c_str(), szSetting, szValue);
+}
+
+void MirandaSettings::writeStrDirect(const mu_ansi* szSetting, const mu_text* szValue) const
+{
+ db_set_ts(m_hContact, m_strModule.c_str(), szSetting, szValue);
+}
+
+void MirandaSettings::writeTree(const mu_ansi* szSetting, const SettingsTree& value) const
+{
+ writeStr(szSetting, value.toString().c_str());
+}
+
+bool MirandaSettings::settingExists(const mu_ansi* szSetting) const
+{
+ DBVARIANT dbv;
+ if (db_get_s(m_hContact, m_strModule.c_str(), szSetting, &dbv, 0))
+ return false;
+
+ db_free(&dbv);
+ return true;
+}
+
+bool MirandaSettings::delSetting(const mu_ansi* szSetting)
+{
+ return db_unset(m_hContact, m_strModule.c_str(), szSetting) == 0;
+}
+
+int MirandaSettings::enumSettingsProc(const mu_ansi* szSetting, LPARAM lParam)
+{
+ SetInserter* pInserter = reinterpret_cast<SetInserter*>(lParam);
+
+ *pInserter = szSetting;
+
+ return 0;
+}
+
+void MirandaSettings::enumSettings(SetInserter& insertIterator)
+{
+ mu::db_contact::enumSettings(m_hContact, m_strModule.c_str(), enumSettingsProc, reinterpret_cast<LPARAM>(&insertIterator));
+}