diff options
author | Vadim Dashevskiy <watcherhd@gmail.com> | 2013-04-02 13:26:06 +0000 |
---|---|---|
committer | Vadim Dashevskiy <watcherhd@gmail.com> | 2013-04-02 13:26:06 +0000 |
commit | 8d3307adf7ba64b75fb4de363f873c97286b0e9b (patch) | |
tree | 1f89dccbcd641f2df5d793ee3a3a5c6c745d898c /plugins/XSoundNotify/src/SoundNotifyDataStorage.cpp | |
parent | 626e01829f5d9946e831cbf66ad49a13103f91bb (diff) |
- XSoundNotify - adopted
git-svn-id: http://svn.miranda-ng.org/main/trunk@4284 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/XSoundNotify/src/SoundNotifyDataStorage.cpp')
-rw-r--r-- | plugins/XSoundNotify/src/SoundNotifyDataStorage.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/plugins/XSoundNotify/src/SoundNotifyDataStorage.cpp b/plugins/XSoundNotify/src/SoundNotifyDataStorage.cpp new file mode 100644 index 0000000000..93a81bfed6 --- /dev/null +++ b/plugins/XSoundNotify/src/SoundNotifyDataStorage.cpp @@ -0,0 +1,70 @@ +#include "Common.h"
+
+SoundNotifyDataStorage::SoundNotifyDataStorage()
+{
+
+}
+
+void SoundNotifyDataStorage::init()
+{
+ initModuleConvertTable(_moduleTable);
+ registerProtocols();
+
+ HANDLE contact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST,0,0);
+ for(; contact; contact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)contact,0))
+ {
+ try
+ {
+ addContact(contact);
+ }
+ catch (...)
+ {
+ // log
+ }
+ }
+}
+
+void SoundNotifyDataStorage::commit()
+{
+ for (auto it = _protocolTable.begin(), end = _protocolTable.end(); it != end; ++it)
+ for (auto user = it->second.begin(), userEnd = it->second.end(); user != userEnd; ++user)
+ if (user->second->isSoundChanged())
+ {
+ if (user->second->soundPath().empty())
+ DBDeleteContactSetting(user->second->contact(), XSN_ModuleInfo::name(), XSN_ModuleInfo::soundSetting());
+ else
+ DBWriteContactSettingTString(user->second->contact(), XSN_ModuleInfo::name(), XSN_ModuleInfo::soundSetting(), user->second->soundPath().c_str());
+ }
+}
+
+void SoundNotifyDataStorage::addContact(HANDLE contact)
+{
+ ModuleString module = getContactModule(contact);
+ ProtocolString proto = _moduleTable[module];
+ xsn_string user = getContactId(contact, module, proto);
+ if (user.empty())
+ return ;
+
+ XSN_Variant sound;
+ DBGetContactSettingTString(contact, XSN_ModuleInfo::name(), XSN_ModuleInfo::soundSetting(), &sound);
+ _protocolTable[proto][user] = SoundNotifyDataPtr(new SoundNotifyData(contact, module, sound.toString()));
+}
+
+xsn_string SoundNotifyDataStorage::getContactId(HANDLE contact, const ModuleString & module, const ProtocolString & proto)
+{
+ auto it = _registeredProtocols.find(proto);
+ if (it == _registeredProtocols.end())
+ return xsn_string();
+ return it->second(contact, module);
+}
+
+ProtocolTable & SoundNotifyDataStorage::getData()
+{
+ return _protocolTable;
+}
+
+void SoundNotifyDataStorage::registerProtocols()
+{
+ _registeredProtocols["ICQ"] = &getIcqContactId;
+ _registeredProtocols["JABBER"] = &getJabberContactId;
+}
|