From 89c5b2369413025e1fe7dfe5c5d0bf3bedd8558d Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Mon, 23 Jul 2012 13:52:57 +0000 Subject: git-svn-id: http://svn.miranda-ng.org/main/trunk@1123 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- !NotAdopted/XSoundNotify/DebugLogger.hpp | 91 +++++++++++ !NotAdopted/XSoundNotify/EventProcessor.cpp | 84 +++++++++++ !NotAdopted/XSoundNotify/EventProcessor.h | 27 ++++ !NotAdopted/XSoundNotify/README | 1 + !NotAdopted/XSoundNotify/SettingsDialog.cpp | 124 +++++++++++++++ !NotAdopted/XSoundNotify/SettingsDialog.h | 60 ++++++++ !NotAdopted/XSoundNotify/SoundNotifyData.cpp | 37 +++++ !NotAdopted/XSoundNotify/SoundNotifyData.h | 33 ++++ .../XSoundNotify/SoundNotifyDataStorage.cpp | 74 +++++++++ !NotAdopted/XSoundNotify/SoundNotifyDataStorage.h | 34 +++++ !NotAdopted/XSoundNotify/XSoundNotify.rc | Bin 0 -> 5494 bytes !NotAdopted/XSoundNotify/resource.h | Bin 0 -> 1556 bytes !NotAdopted/XSoundNotify/testplug.vcxproj | 167 +++++++++++++++++++++ !NotAdopted/XSoundNotify/xsn_main.cpp | 122 +++++++++++++++ !NotAdopted/XSoundNotify/xsn_types.cpp | 32 ++++ !NotAdopted/XSoundNotify/xsn_types.h | 33 ++++ !NotAdopted/XSoundNotify/xsn_utils.cpp | 60 ++++++++ !NotAdopted/XSoundNotify/xsn_utils.h | 18 +++ 18 files changed, 997 insertions(+) create mode 100644 !NotAdopted/XSoundNotify/DebugLogger.hpp create mode 100644 !NotAdopted/XSoundNotify/EventProcessor.cpp create mode 100644 !NotAdopted/XSoundNotify/EventProcessor.h create mode 100644 !NotAdopted/XSoundNotify/README create mode 100644 !NotAdopted/XSoundNotify/SettingsDialog.cpp create mode 100644 !NotAdopted/XSoundNotify/SettingsDialog.h create mode 100644 !NotAdopted/XSoundNotify/SoundNotifyData.cpp create mode 100644 !NotAdopted/XSoundNotify/SoundNotifyData.h create mode 100644 !NotAdopted/XSoundNotify/SoundNotifyDataStorage.cpp create mode 100644 !NotAdopted/XSoundNotify/SoundNotifyDataStorage.h create mode 100644 !NotAdopted/XSoundNotify/XSoundNotify.rc create mode 100644 !NotAdopted/XSoundNotify/resource.h create mode 100644 !NotAdopted/XSoundNotify/testplug.vcxproj create mode 100644 !NotAdopted/XSoundNotify/xsn_main.cpp create mode 100644 !NotAdopted/XSoundNotify/xsn_types.cpp create mode 100644 !NotAdopted/XSoundNotify/xsn_types.h create mode 100644 !NotAdopted/XSoundNotify/xsn_utils.cpp create mode 100644 !NotAdopted/XSoundNotify/xsn_utils.h (limited to '!NotAdopted/XSoundNotify') diff --git a/!NotAdopted/XSoundNotify/DebugLogger.hpp b/!NotAdopted/XSoundNotify/DebugLogger.hpp new file mode 100644 index 0000000000..3b2c5a5fc1 --- /dev/null +++ b/!NotAdopted/XSoundNotify/DebugLogger.hpp @@ -0,0 +1,91 @@ +#ifndef _GRS_DEBUG_LOGGER_H +#define _GRS_DEBUG_LOGGER_H + +#include +#include +#include +#include + +/** + * Простой логгер, который можно использовать в любом месте для вывода отладочной информации + * При выводе обычного сообщения надо использовать макрос GRS_DEBUG_LOG + * Для вывода сложного сообщения с использованием операторов ввода/вывода макрос GRS_DEBUG_FORMAT_LOG + * Лог сохраняется в рабочем каталоге под именем : grs_debug.log + */ + +namespace grs +{ + +class DebugLogger +{ +public: + class Except : public std::exception + { + public: + virtual const char * what() const throw() { return "pizda rulu"; } + }; + + DebugLogger() + { + try + { + _strm.open("D:\\grs_debug.log", std::ios::app); + } + catch (...) + { + throw Except(); + } + if (!_strm.is_open()) + throw Except(); + + log("Logger started"); + } + + void log(const std::string & str, const char * fileStr = 0, int line = 0) + { + if (!_strm.is_open()) + return ; + + time_t t(time(0)); + struct tm * timeinfo; + timeinfo = localtime (&t); + char timeStr[9]; + strftime (timeStr, 9, "%H:%M:%S", timeinfo); + _strm << "[" << timeStr << "] "; + if (fileStr) + _strm << fileStr << ":" << line<<" "; + _strm <<"# "<< str << std::endl; + } + + static DebugLogger * instance() + { + //static DebugLogger * logger = 0; + static std::auto_ptr loggerPtr; + if (loggerPtr.get() == 0) + loggerPtr.reset(new DebugLogger()); + return loggerPtr.get(); + } + +private: + std::ofstream _strm; +}; + +} + +#define GRS_DEBUG_FORMAT_LOG(data) {\ + grs::DebugLogger * l = grs::DebugLogger::instance();\ + if (l != 0) \ + {\ + std::stringstream strm;\ + strm << data;\ + l->log(strm.str(), __FILE__, __LINE__);\ + }\ + } + +#define GRS_DEBUG_LOG(data) {\ + grs::DebugLogger * l = grs::DebugLogger::instance();\ + if (l != 0)\ + l->log(data, __FILE__, __LINE__);\ + } + +#endif diff --git a/!NotAdopted/XSoundNotify/EventProcessor.cpp b/!NotAdopted/XSoundNotify/EventProcessor.cpp new file mode 100644 index 0000000000..6a97b6b125 --- /dev/null +++ b/!NotAdopted/XSoundNotify/EventProcessor.cpp @@ -0,0 +1,84 @@ +#include "EventProcessor.h" +#include +#include "m_protocols.h" +#include +#include "DebugLogger.hpp" + +// static area + +static std::unique_ptr XSN_EventProcessorPtr; + +void XSN_EventProcessor::make(PLUGINLINK * pl) +{ + XSN_EventProcessorPtr.reset(new XSN_EventProcessor(pl)); +} + +XSN_EventProcessor & XSN_EventProcessor::instance() +{ + return *XSN_EventProcessorPtr; +} + +// class methods + +XSN_EventProcessor::XSN_EventProcessor(PLUGINLINK * pl) : pluginLink(pl) +{ + +} + +void XSN_EventProcessor::process(WPARAM wParam, LPARAM lParam) +{ + if (!wParam || !lParam || !isReceiveMessage(lParam)) + return ; + try + { + MessageBox(0, "Receive message", "INFO", MB_OK); + /*GRS_DEBUG_LOG("Receive message"); + HANDLE contact = (HANDLE)wParam; + MessageBox(0, "Get protocol", "INFO", MB_OK); + GRS_DEBUG_LOG("Protocol : "); + xsn_string proto = getProtocol(wParam); + MessageBox(0, "Protocol is", proto.c_str(), MB_OK); + GRS_DEBUG_FORMAT_LOG(proto) + //xsn_string nick = getNick(wParam, proto.c_str()); + XSN_Variant sound; + DBGetContactSettingTString(contact, proto.c_str(), "XSNPlugin_sound", &sound); + if (!sound.empty()) + { + GRS_DEBUG_LOG("Sound for user exist"); + GRS_DEBUG_FORMAT_LOG("Playing sound : " << sound.ptszVal << ", for user : " << getNick(wParam, proto.c_str())); + PlaySound(sound.toString().c_str(), nullptr, SND_FILENAME | SND_ASYNC); + }*/ + } + catch (std::runtime_error &) + { + //MessageBoxA(0, e.what(), "Runtime error", MB_OK); + } + catch (...) + { + //MessageBoxA(0, "Unknown error occured", "Exception", MB_OK); + } +} + +bool XSN_EventProcessor::isReceiveMessage(LPARAM event) +{ + DBEVENTINFO info ={ sizeof(info) }; + CallService(MS_DB_EVENT_GET, event, (LPARAM)&info); + + // TODO : rec msg flag : 16, send msg flag : 18 - WTF? + // return (info.eventType == EVENTTYPE_MESSAGE) && (info.flags & DBEF_READ); + // It's condition work well - magic? + return !(((info.eventType != EVENTTYPE_MESSAGE) && !(info.flags & DBEF_READ)) || (info.flags & DBEF_SENT)); +} + +xsn_string XSN_EventProcessor::getProtocol(WPARAM contact) +{ + char *pszProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, contact, 0); + return xsn_string(pszProto); +} + +xsn_string XSN_EventProcessor::getNick(WPARAM contact, LPCTSTR protocol) +{ + XSN_Variant nick; + DBGetContactSettingTString((HANDLE)contact, protocol, "Nick", &nick); + return nick.toString(); +} diff --git a/!NotAdopted/XSoundNotify/EventProcessor.h b/!NotAdopted/XSoundNotify/EventProcessor.h new file mode 100644 index 0000000000..6de14f8f98 --- /dev/null +++ b/!NotAdopted/XSoundNotify/EventProcessor.h @@ -0,0 +1,27 @@ +#ifndef __XSN_EVENT_PROCESSOR +#define __XSN_EVENT_PROCESSOR + +#include +#include "xsn_types.h" +#include + + +class XSN_EventProcessor +{ +public: + static void make(PLUGINLINK * pl); + static XSN_EventProcessor & instance(); + + void process(WPARAM wParam, LPARAM lParam); + +protected: + XSN_EventProcessor(PLUGINLINK * pl); + + bool isReceiveMessage(LPARAM event); + xsn_string getProtocol(WPARAM contact); + xsn_string getNick(WPARAM contact, LPCTSTR protocol); + + PLUGINLINK * pluginLink; +}; + +#endif diff --git a/!NotAdopted/XSoundNotify/README b/!NotAdopted/XSoundNotify/README new file mode 100644 index 0000000000..d855b95460 --- /dev/null +++ b/!NotAdopted/XSoundNotify/README @@ -0,0 +1 @@ +Choose release mode (debug mode not configured) and configure Visual Studio environment for boost and WTL libraries include/libs paths diff --git a/!NotAdopted/XSoundNotify/SettingsDialog.cpp b/!NotAdopted/XSoundNotify/SettingsDialog.cpp new file mode 100644 index 0000000000..69b64d776f --- /dev/null +++ b/!NotAdopted/XSoundNotify/SettingsDialog.cpp @@ -0,0 +1,124 @@ +#include "SettingsDialog.h" +//#include "DebugLogger.hpp" + +template +T * GetComboBoxData(CComboBox & ctrl) +{ + return (T*)(ctrl.GetItemData(ctrl.GetCurSel())); +} + +SettingsDialog::SettingsDialog(SoundNotifyDataStorage & storage) : _dataStorage(storage) +{ + +} + +BOOL SettingsDialog::PreTranslateMessage(MSG* pMsg) +{ + return ::IsDialogMessage(m_hWnd, pMsg); +} + +LRESULT SettingsDialog::onInitDialog(UINT, WPARAM, LPARAM, BOOL&) +{ + _userCombo = GetDlgItem(IDC_COMBO_USERS); + _protoCombo = GetDlgItem(IDC_COMBO_PROTO); + _chooseButton = GetDlgItem(IDC_BUTTON_CHOOSE_SOUND); + _resetButton = GetDlgItem(IDC_BUTTON_RESET_SOUND); + _playButton = GetDlgItem(IDC_BUTTON_TEST_PLAY); + _soundLabel = GetDlgItem(IDC_LABEL_SOUND); + + auto & protocols = _dataStorage.getData(); + for (auto it = protocols.begin(), end = protocols.end(); it != end; ++it) + addProtocolItem(*it); + + _userCombo.EnableWindow(0); + GetDlgItem(IDC_BUTTON_CHOOSE_SOUND).EnableWindow(0); + GetDlgItem(IDC_BUTTON_RESET_SOUND).EnableWindow(0); + GetDlgItem(IDC_BUTTON_TEST_PLAY).EnableWindow(0); + return TRUE; +} + +LRESULT SettingsDialog::onOk(WORD, WORD wID, HWND, BOOL&) +{ + EndDialog(wID); + return 0; +} + +LRESULT SettingsDialog::onCancel(WORD, WORD wID, HWND, BOOL&) +{ + EndDialog(wID); + return 0; +} + +LRESULT SettingsDialog::onSelectProtocol(WORD, WORD, HWND, BOOL&) +{ + _userCombo.ResetContent(); + auto data = GetComboBoxData(_protoCombo); + for (auto it = data->second.begin(), end = data->second.end(); it != end; ++it) + { + int id = _userCombo.AddString(it->first.c_str()); + _userCombo.SetItemData(id, (DWORD_PTR)(&(*it))); + } + _userCombo.EnableWindow(TRUE); + _playButton.EnableWindow(FALSE); + _resetButton.EnableWindow(FALSE); + _chooseButton.EnableWindow(FALSE); + _soundLabel.SetWindowText(TEXT("")); + return 0; +} + +LRESULT SettingsDialog::onSelectUser(WORD, WORD, HWND, BOOL &) +{ + auto user = GetComboBoxData(_userCombo); + _chooseButton.EnableWindow(TRUE); + + BOOL soundSelected = !user->second->soundPath().empty(); + _resetButton.EnableWindow(soundSelected); + _playButton.EnableWindow(soundSelected); + setSoundLabelText(user->second->soundPath().c_str()); + + return 0; +} + +LRESULT SettingsDialog::onChooseSound(WORD, WORD, HWND , BOOL&) +{ + CFileDialog fileDlg(1, 0, 0, OFN_FILEMUSTEXIST, TEXT("WAV files\0*.wav\0\0")); + if (fileDlg.DoModal() != IDOK) + return 0; + + setSoundLabelText(fileDlg.m_szFileName); + auto user = GetComboBoxData(_userCombo); + user->second->setSound(xsn_string(fileDlg.m_szFileName)); + _resetButton.EnableWindow(TRUE); + _playButton.EnableWindow(TRUE); + return 0; +} + +LRESULT SettingsDialog::onResetSound(WORD, WORD wID, HWND , BOOL&) +{ + auto user = GetComboBoxData(_userCombo); + user->second->setSound(xsn_string()); + _resetButton.EnableWindow(FALSE); + _playButton.EnableWindow(FALSE); + _soundLabel.SetWindowText(TEXT("")); + return 0; +} + +LRESULT SettingsDialog::onTestPlay(WORD, WORD wID, HWND , BOOL&) +{ + auto user = GetComboBoxData(_userCombo); + PlaySound(user->second->soundPath().c_str(), nullptr, SND_FILENAME | SND_ASYNC); + return 0; +} + +void SettingsDialog::setSoundLabelText(LPCTSTR text) +{ + _soundLabel.SetWindowText(PathFindFileName(text)); +} + +void SettingsDialog::addProtocolItem(ProtocolTable::value_type & value) +{ + wchar_t protocol[30]; + mbstowcs(protocol, value.first.c_str(), 30); + int idx = _protoCombo.AddString(protocol); + _protoCombo.SetItemData(idx, (DWORD_PTR)(&value)); +} diff --git a/!NotAdopted/XSoundNotify/SettingsDialog.h b/!NotAdopted/XSoundNotify/SettingsDialog.h new file mode 100644 index 0000000000..c68503a6e8 --- /dev/null +++ b/!NotAdopted/XSoundNotify/SettingsDialog.h @@ -0,0 +1,60 @@ +#ifndef __XSN_SETTINGS_DIALOG_H +#define __XSN_SETTINGS_DIALOG_H + +#include +#include +#include +#include +#include +#include "resource.h" +#include "SoundNotifyDataStorage.h" + +class SettingsDialog : public CDialogImpl +{ +private: + CComboBox _userCombo; + CComboBox _protoCombo; + CButton _chooseButton; + CButton _resetButton; + CButton _playButton; + CStatic _soundLabel; + SoundNotifyDataStorage & _dataStorage; + +public: + SettingsDialog(SoundNotifyDataStorage & dataStorage); + virtual ~SettingsDialog() {} + static BOOL DlgProcCluiOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); + +public: + enum {IDD = IDD_DIALOG1}; + + BEGIN_MSG_MAP(SettingsDialog) + MESSAGE_HANDLER(WM_INITDIALOG, onInitDialog) + COMMAND_HANDLER(IDC_COMBO_PROTO, CBN_SELCHANGE, onSelectProtocol) + COMMAND_HANDLER(IDC_COMBO_USERS, CBN_SELCHANGE, onSelectUser) + COMMAND_ID_HANDLER(IDOK, onOk) + COMMAND_ID_HANDLER(IDCANCEL, onCancel) + COMMAND_ID_HANDLER(IDC_BUTTON_CHOOSE_SOUND, onChooseSound) + COMMAND_ID_HANDLER(IDC_BUTTON_RESET_SOUND, onResetSound) + COMMAND_ID_HANDLER(IDC_BUTTON_TEST_PLAY, onTestPlay) + END_MSG_MAP() + + virtual BOOL PreTranslateMessage(MSG* pMsg); + +protected: + LRESULT onInitDialog(UINT, WPARAM, LPARAM, BOOL&); + + LRESULT onOk(WORD, WORD, HWND, BOOL&); + LRESULT onCancel(WORD, WORD, HWND, BOOL &); + LRESULT onSelectProtocol(WORD, WORD, HWND, BOOL&); + LRESULT onSelectUser(WORD, WORD, HWND, BOOL &); + LRESULT onChooseSound(WORD, WORD, HWND , BOOL&); + LRESULT onResetSound(WORD, WORD, HWND , BOOL&); + LRESULT onTestPlay(WORD, WORD, HWND , BOOL&); + + void addProtocolItem(ProtocolTable::value_type & value); + + void setSoundLabelText(LPCTSTR text); +}; + +#endif diff --git a/!NotAdopted/XSoundNotify/SoundNotifyData.cpp b/!NotAdopted/XSoundNotify/SoundNotifyData.cpp new file mode 100644 index 0000000000..1876db6ba0 --- /dev/null +++ b/!NotAdopted/XSoundNotify/SoundNotifyData.cpp @@ -0,0 +1,37 @@ +#include "SoundNotifyData.h" + +SoundNotifyData::SoundNotifyData() : _contact(0), _soundChanged(false) +{ + +} + +SoundNotifyData::SoundNotifyData(HANDLE contact, const ModuleString & module, const xsn_string & sound) : + _contact(contact), _soundPath(sound), _soundChanged(false) +{ +} + +void SoundNotifyData::setSound(const xsn_string & sound) +{ + _soundChanged = true; + _soundPath = sound; +} + +HANDLE SoundNotifyData::contact() const +{ + return _contact; +} + +const xsn_string & SoundNotifyData::soundPath() const +{ + return _soundPath; +} + +const ModuleString & SoundNotifyData::module() const +{ + return _module; +} + +bool SoundNotifyData::isSoundChanged() const +{ + return _soundChanged; +} diff --git a/!NotAdopted/XSoundNotify/SoundNotifyData.h b/!NotAdopted/XSoundNotify/SoundNotifyData.h new file mode 100644 index 0000000000..18cb4844a4 --- /dev/null +++ b/!NotAdopted/XSoundNotify/SoundNotifyData.h @@ -0,0 +1,33 @@ +#ifndef __XSN_DATA_H +#define __XSN_DATA_H + +#include +#include "xsn_types.h" +#include + +class SoundNotifyData +{ +public: + SoundNotifyData(); + SoundNotifyData(HANDLE contact, const ModuleString & module, const xsn_string & sound); + + void setSound(const xsn_string & sound); + + HANDLE contact() const; + const xsn_string & soundPath() const; + const ModuleString & module() const; + bool isSoundChanged() const; + +private: + HANDLE _contact; + ModuleString _module; + xsn_string _soundPath; + bool _soundChanged; +}; +typedef std::shared_ptr SoundNotifyDataPtr; + +typedef std::unordered_map UserDataTable; +typedef std::unordered_map ProtocolTable; +typedef std::unordered_map ModuleConvertTable; + +#endif diff --git a/!NotAdopted/XSoundNotify/SoundNotifyDataStorage.cpp b/!NotAdopted/XSoundNotify/SoundNotifyDataStorage.cpp new file mode 100644 index 0000000000..bd1b90df52 --- /dev/null +++ b/!NotAdopted/XSoundNotify/SoundNotifyDataStorage.cpp @@ -0,0 +1,74 @@ +#include "SoundNotifyDataStorage.h" +#include +#include +#include "xsn_utils.h" +//#include "DebugLogger.hpp" + +SoundNotifyDataStorage::SoundNotifyDataStorage(PLUGINLINK * pl) : pluginLink(pl) +{ + +} + +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; +} diff --git a/!NotAdopted/XSoundNotify/SoundNotifyDataStorage.h b/!NotAdopted/XSoundNotify/SoundNotifyDataStorage.h new file mode 100644 index 0000000000..7dbf03c494 --- /dev/null +++ b/!NotAdopted/XSoundNotify/SoundNotifyDataStorage.h @@ -0,0 +1,34 @@ +#ifndef _XSN_DATA_STORAGE +#define _XSN_DATA_STORAGE + +#include "SoundNotifyData.h" +#include +#include + +class SoundNotifyDataStorage +{ +public: + SoundNotifyDataStorage(PLUGINLINK * pl); + + void init(); + void commit(); + + ProtocolTable & getData(); + +protected: + void addContact(HANDLE contact); + xsn_string getContactId(HANDLE contact, const ModuleString & module, const ProtocolString & proto); + void registerProtocols(); + +private: + PLUGINLINK * pluginLink; + + ProtocolTable _protocolTable; + ModuleConvertTable _moduleTable; + + typedef boost::function getContactIdFunc; + typedef std::unordered_map RegisteredProtocols; + RegisteredProtocols _registeredProtocols; +}; + +#endif diff --git a/!NotAdopted/XSoundNotify/XSoundNotify.rc b/!NotAdopted/XSoundNotify/XSoundNotify.rc new file mode 100644 index 0000000000..ab42834a08 Binary files /dev/null and b/!NotAdopted/XSoundNotify/XSoundNotify.rc differ diff --git a/!NotAdopted/XSoundNotify/resource.h b/!NotAdopted/XSoundNotify/resource.h new file mode 100644 index 0000000000..fcd39e7cf3 Binary files /dev/null and b/!NotAdopted/XSoundNotify/resource.h differ diff --git a/!NotAdopted/XSoundNotify/testplug.vcxproj b/!NotAdopted/XSoundNotify/testplug.vcxproj new file mode 100644 index 0000000000..ebd0a0009f --- /dev/null +++ b/!NotAdopted/XSoundNotify/testplug.vcxproj @@ -0,0 +1,167 @@ +п»ї + + + + Debug + Win32 + + + Release + Win32 + + + + + + XSoundNotify + + + + DynamicLibrary + false + MultiByte + + + DynamicLibrary + false + Unicode + + + + + + + + + + + + + + + .\Release\ + .\Release\ + false + E:\Programming\libs\WTL\Include;$(IncludePath) + + + .\Debug\ + .\Debug\ + true + + + + MultiThreaded + OnlyExplicitInline + true + true + MaxSpeed + true + Level3 + e:\Programming\libs\boost_1_46_1\;../../include;%(AdditionalIncludeDirectories) + _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;TESTPLUG_EXPORTS;%(PreprocessorDefinitions) + .\Release\ + .\Release\testplug.pch + .\Release\ + .\Release\ + + + true + NDEBUG;%(PreprocessorDefinitions) + .\Release\testplug.tlb + true + Win32 + + + 0x0809 + NDEBUG;%(PreprocessorDefinitions) + + + true + .\Release\testplug.bsc + + + true + true + Console + release/xsoundnotify.dll + .\Release\testplug.lib + odbc32.lib;odbccp32.lib;winmm.lib;%(AdditionalDependencies) + e:\Programming\libs\wxWidgets-2.9.3\lib\vc_lib\;%(AdditionalLibraryDirectories) + + + + + MultiThreadedDebug + Default + false + Disabled + true + Level3 + true + EditAndContinue + e:\Programming\libs\wxWidgets-2.9.3\include\msvc\;e:\Programming\libs\wxWidgets-2.9.3\include\;../../include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;_USRDLL;XSOUNDNOTIFY_EXPORTS;%(PreprocessorDefinitions) + .\Debug\ + .\Debug\testplug.pch + .\Debug\ + .\Debug\ + EnableFastChecks + + + true + _DEBUG;%(PreprocessorDefinitions) + .\Debug\testplug.tlb + true + Win32 + + + 0x0809 + _DEBUG;%(PreprocessorDefinitions) + + + true + .\Debug\testplug.bsc + + + true + true + true + Console + .\Debug\xsoundnotify.dll + .\Debug\xsoundnotify.lib + wxmsw29u_adv.lib;wxmsw29u_core.lib;wxbase29u.lib;wxtiff.lib;wxjpeg.lib;wxpng.lib;wxzlib.lib;wxregexu.lib;wxexpat.lib;odbc32.lib;odbccp32.lib;winmm.lib;%(AdditionalDependencies) + + + e:\Programming\libs\wxWidgets-2.9.3\lib\vc_lib\;%(AdditionalLibraryDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/!NotAdopted/XSoundNotify/xsn_main.cpp b/!NotAdopted/XSoundNotify/xsn_main.cpp new file mode 100644 index 0000000000..ebcf029143 --- /dev/null +++ b/!NotAdopted/XSoundNotify/xsn_main.cpp @@ -0,0 +1,122 @@ +/* +Miranda plugin template, originally by Richard Hughes +http://miranda-icq.sourceforge.net/ + +This file is placed in the public domain. Anybody is free to use or +modify it as they wish with no restriction. +There is no warranty. +*/ + +#include "SettingsDialog.h" + +#include +#include +#include +#include +#include +#include +#include +#include "xsn_utils.h" +//#include "DebugLogger.hpp" + +HINSTANCE hInst; +PLUGINLINK *pluginLink; +HANDLE AddEventHook; + +PLUGININFOEX pluginInfo = { + sizeof(PLUGININFOEX), // Размер стуктуры + "XSoundNotify", // Короткое имя плагинв + PLUGIN_MAKE_VERSION(1,0,0,0), // Версия плагина + "Provides extended options for sound notifications", // Описание плагина + "Roman Torsten", // Автор + "rs_torsten-public@yahoo.com", // Адресс автора + "© 2011 Copyright", // Копирайт + "https://plus.google.com/117081718640940130539", // Адресс сайта разработчика плагина + 0, + 0, + {0x8b86253, 0xec6e, 0x4d09, { 0xb7, 0xa9, 0x64, 0xac, 0xdf, 0x6, 0x27, 0xb8 }} //{08B86253-EC6E-4d09-B7A9-64ACDF0627B8} +}; + +extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) +{ + hInst = hinstDLL; + return TRUE; +} + +static int PluginMenuCommand(WPARAM wParam,LPARAM lParam) +{ + try + { + SoundNotifyDataStorage storage(pluginLink); + storage.init(); + SettingsDialog dlg(storage); + if (dlg.DoModal() == IDOK) + storage.commit(); + } + catch (...) + { + MessageBox(0, TEXT("Unknown error occured while configuring"), TEXT("XSoundNotify Error"), MB_OK | MB_ICONERROR); + } + + return 0; +} + +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) +{ + return &pluginInfo; +} + +extern "C" __declspec(dllexport) const MUUID interfaces[] = {MIID_TESTPLUGIN, MIID_LAST}; +extern "C" __declspec(dllexport) const MUUID* MirandaPluginInterfaces(void) +{ + return interfaces; +} + +INT processEvent(WPARAM wParam, LPARAM lParam) +{ + try + { + if (!isReceiveMessage(lParam)) + return 0; + + xsn_string sound = getContactSound((HANDLE)wParam); + if (!sound.empty()) + PlaySound(sound.c_str(), nullptr, SND_ASYNC | SND_FILENAME); + } + catch (std::exception & ) + { + // log + } + catch (...) + { + // log + } + + return 0; +} + +extern "C" int __declspec(dllexport) Load(PLUGINLINK *link) +{ + CLISTMENUITEM mi; + + pluginLink=link; + CreateServiceFunction("XSoundNotify/MenuCommand", PluginMenuCommand); + ZeroMemory(&mi,sizeof(mi)); + mi.cbSize=sizeof(mi); + mi.position=-0x7FFFFFFF; + mi.flags=0; + mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA); + mi.pszName=LPGEN("&XSoundNotify Plugin"); + mi.pszService="XSoundNotify/MenuCommand"; + CallService(MS_CLIST_ADDMAINMENUITEM,0,(LPARAM)&mi); + AddEventHook = HookEvent(ME_DB_EVENT_ADDED, processEvent); + + return 0; +} + +extern "C" int __declspec(dllexport) Unload(void) +{ + UnhookEvent(AddEventHook); + return 0; +} + diff --git a/!NotAdopted/XSoundNotify/xsn_types.cpp b/!NotAdopted/XSoundNotify/xsn_types.cpp new file mode 100644 index 0000000000..da0cc5b3f9 --- /dev/null +++ b/!NotAdopted/XSoundNotify/xsn_types.cpp @@ -0,0 +1,32 @@ +#include "xsn_types.h" + +XSN_Variant::XSN_Variant() +{ + ptszVal = nullptr; +} + +XSN_Variant::~XSN_Variant() +{ + if (ptszVal) + DBFreeVariant(this); +} + +xsn_string XSN_Variant::toString() const +{ + return ptszVal == nullptr ? xsn_string() : xsn_string(ptszVal); +} + +bool XSN_Variant::empty() const +{ + return ptszVal == nullptr; +} + +const char * XSN_ModuleInfo::name() +{ + return "XSoundNotify"; +} + +const char * XSN_ModuleInfo::soundSetting() +{ + return "XSNPlugin_sound"; +} diff --git a/!NotAdopted/XSoundNotify/xsn_types.h b/!NotAdopted/XSoundNotify/xsn_types.h new file mode 100644 index 0000000000..43f4434fea --- /dev/null +++ b/!NotAdopted/XSoundNotify/xsn_types.h @@ -0,0 +1,33 @@ +#ifndef __XSN_TYPES +#define __XSN_TYPES + +#include +#include +#include +#include + +#ifndef UNICODE + typedef std::string xsn_string; +#else + typedef std::wstring xsn_string; +#endif + +typedef std::string ModuleString; +typedef std::string ProtocolString; + +struct XSN_Variant : DBVARIANT +{ + XSN_Variant(); + ~XSN_Variant(); + + xsn_string toString() const; + bool empty() const; +}; + +struct XSN_ModuleInfo +{ + static const char * name(); + static const char * soundSetting(); +}; + +#endif diff --git a/!NotAdopted/XSoundNotify/xsn_utils.cpp b/!NotAdopted/XSoundNotify/xsn_utils.cpp new file mode 100644 index 0000000000..d597776e8d --- /dev/null +++ b/!NotAdopted/XSoundNotify/xsn_utils.cpp @@ -0,0 +1,60 @@ +#include "xsn_utils.h" +#include +#include + +void initModuleConvertTable(ModuleConvertTable & table) +{ + int number = 0; + // may be need to free PROTOACCOUNT, but did't found information about it + PROTOACCOUNT ** accounts; + ProtoEnumAccounts(&number, &accounts); + for (int i = 0; i < number; ++i) + table[ModuleString(accounts[i]->szModuleName)] = ProtocolString(accounts[i]->szProtoName); +} + +bool isReceiveMessage(LPARAM event) +{ + DBEVENTINFO info = { sizeof(info) }; + CallService(MS_DB_EVENT_GET, event, (LPARAM)&info); + // i don't understand why it works and how it works, but it works correctly - practice way (методом тыка) + // so, i think correct condition would be : eventType == EVENTTYPE_MESSAGE && info.flags & DBEF_READ, but it really isn't + return !(((info.eventType != EVENTTYPE_MESSAGE) && !(info.flags & DBEF_READ)) || (info.flags & DBEF_SENT)); +} + +xsn_string getContactSound(HANDLE contact) +{ + XSN_Variant sound; + DBGetContactSettingTString(contact, XSN_ModuleInfo::name(), XSN_ModuleInfo::soundSetting(), &sound); + return sound.toString(); +} + +ModuleString getContactModule(HANDLE contact) +{ + char * proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)contact, 0); + if (proto == nullptr) + throw std::runtime_error("MS_PROTO_GETCONTACTBASEPROTO failed"); + return ModuleString(proto); +} + +xsn_string getIcqContactId(HANDLE contact, const ModuleString & module) +{ + XSN_Variant nick; + DBGetContactSettingTString(contact, module.c_str(), "CustomNick", &nick); + if (nick.empty()) + DBGetContactSettingTString(contact, module.c_str(), "Nick", &nick); + DWORD uin = DBGetContactSettingDword(contact, module.c_str(), "UIN", 0); + xsn_string uinStr = boost::lexical_cast(uin); + if (nick.empty()) + return uinStr; + return nick.toString() + TEXT(" (") + uinStr + TEXT(")"); +} + +xsn_string getJabberContactId(HANDLE contact, const ModuleString & module) +{ + XSN_Variant jid, nick; + DBGetContactSettingTString(contact, module.c_str(), "jid", &jid); + DBGetContactSettingTString(contact, "CList", "MyHandle", &nick); + if (nick.empty()) + return jid.toString(); + return nick.toString() + TEXT(" (") + jid.toString() + TEXT(")"); +} diff --git a/!NotAdopted/XSoundNotify/xsn_utils.h b/!NotAdopted/XSoundNotify/xsn_utils.h new file mode 100644 index 0000000000..66bdef2526 --- /dev/null +++ b/!NotAdopted/XSoundNotify/xsn_utils.h @@ -0,0 +1,18 @@ +#ifndef _XSN_UTILS_H +#define _XSN_UTILS_H + +#include "xsn_types.h" +#include "SoundNotifyData.h" + +void initModuleConvertTable(ModuleConvertTable & table); + +bool isReceiveMessage(LPARAM event); + +xsn_string getContactSound(HANDLE contact); +ModuleString getContactModule(HANDLE contact); + +xsn_string getIcqContactId(HANDLE contact, const ModuleString & module); +xsn_string getJabberContactId(HANDLE contact, const ModuleString & module); + + +#endif -- cgit v1.2.3