diff options
author | George Hazan <ghazan@miranda.im> | 2020-03-23 21:54:02 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-03-23 21:54:02 +0300 |
commit | c3e56141b7996b34e776054dd6a8144594363428 (patch) | |
tree | 8e72203529173e61bf37638afc43b9912f4caa85 /plugins/XSoundNotify | |
parent | 6a889421589f6ecfc9b21d8fc45891292c7f577b (diff) |
fixes #2269 (XSoundNotify not working)
Diffstat (limited to 'plugins/XSoundNotify')
-rw-r--r-- | plugins/XSoundNotify/src/dialog.cpp | 292 | ||||
-rw-r--r-- | plugins/XSoundNotify/src/options.cpp | 488 | ||||
-rw-r--r-- | plugins/XSoundNotify/src/stdafx.h | 14 | ||||
-rw-r--r-- | plugins/XSoundNotify/src/version.h | 16 | ||||
-rw-r--r-- | plugins/XSoundNotify/src/xsn_main.cpp | 80 |
5 files changed, 405 insertions, 485 deletions
diff --git a/plugins/XSoundNotify/src/dialog.cpp b/plugins/XSoundNotify/src/dialog.cpp index e26fa0ea1c..eb67d8d47a 100644 --- a/plugins/XSoundNotify/src/dialog.cpp +++ b/plugins/XSoundNotify/src/dialog.cpp @@ -9,172 +9,152 @@ There is no warranty. #include "stdafx.h"
-static INT_PTR CALLBACK DlgProcContactsOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+class CContactDlg : public CDlgBase
{
- MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- XSN_Data *p;
-
- switch (msg) {
- case WM_INITDIALOG:
- {
- TranslateDialogDefault(hwndDlg);
- hContact = lParam;
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
- WindowList_Add(hChangeSoundDlgList, hwndDlg, hContact);
- Utils_RestoreWindowPositionNoSize(hwndDlg, hContact, MODULENAME, "ChangeSoundDlg");
-
- ptrW uid(Contact_GetInfo(CNF_UNIQUEID, hContact));
- wchar_t value[100];
- mir_snwprintf(value, TranslateT("Custom sound for %s (%s)"), Clist_GetContactDisplayName(hContact), uid.get());
- SetWindowText(hwndDlg, value);
-
- EnableWindow(GetDlgItem(hwndDlg, IDC_CONT_BUTTON_CHOOSE_SOUND), TRUE);
- DBVARIANT dbv = { 0 };
- if (!g_plugin.getWString(hContact, SETTINGSKEY, &dbv)) {
- EnableWindow(GetDlgItem(hwndDlg, IDC_CONT_BUTTON_TEST_PLAY), TRUE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_CONT_BUTTON_RESET_SOUND), TRUE);
- SetDlgItemText(hwndDlg, IDC_CONT_LABEL_SOUND, PathFindFileName(dbv.pwszVal));
- db_free(&dbv);
- }
- else {
- EnableWindow(GetDlgItem(hwndDlg, IDC_CONT_BUTTON_TEST_PLAY), FALSE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_CONT_BUTTON_RESET_SOUND), FALSE);
- SetDlgItemText(hwndDlg, IDC_CONT_LABEL_SOUND, TranslateT("Not set"));
- }
- EnableWindow(GetDlgItem(hwndDlg, IDC_CONT_IGNORE_SOUND), TRUE);
- CheckDlgButton(hwndDlg, IDC_CONT_IGNORE_SOUND, g_plugin.getByte(hContact, SETTINGSIGNOREKEY, 0) ? BST_CHECKED : BST_UNCHECKED);
- p = XSN_Users.find((XSN_Data *)&hContact);
- if (p == nullptr) {
- ptrW name(g_plugin.getWStringA(hContact, SETTINGSKEY));
- if (name != NULL)
- XSN_Users.insert(new XSN_Data(hContact, name, IsDlgButtonChecked(hwndDlg, IDC_CONT_IGNORE_SOUND) ? 1 : 0, 1));
- }
+ XSN_Data *pData;
+
+ CCtrlBase label;
+ CCtrlCheck chkIgnore;
+ CCtrlButton btnChoose, btnPlay, btnReset;
+
+public:
+ CContactDlg(LPARAM _h) :
+ CDlgBase(g_plugin, IDD_CONTACTS),
+ label(this, IDC_CONT_LABEL_SOUND),
+ btnPlay(this, IDC_CONT_BUTTON_TEST_PLAY),
+ btnReset(this, IDC_CONT_BUTTON_RESET_SOUND),
+ btnChoose(this, IDC_CONT_BUTTON_CHOOSE_SOUND),
+ chkIgnore(this, IDC_CONT_IGNORE_SOUND)
+ {
+ btnPlay.OnClick = Callback(this, &CContactDlg::onClick_Play);
+ btnReset.OnClick = Callback(this, &CContactDlg::onClick_Reset);
+ btnChoose.OnClick = Callback(this, &CContactDlg::onClick_Choose);
+
+ chkIgnore.OnChange = Callback(this, &CContactDlg::onChange_Ignore);
+
+ pData = XSN_Users.find((XSN_Data *)&_h);
+ if (pData == nullptr)
+ XSN_Users.insert(pData = new XSN_Data(_h, false));
+ pData->bIgnore = g_plugin.getByte(_h, SETTINGSIGNOREKEY, 0);
+ }
+
+ bool OnInitDialog() override
+ {
+ WindowList_Add(hChangeSoundDlgList, m_hwnd, pData->hContact);
+ Utils_RestoreWindowPositionNoSize(m_hwnd, pData->hContact, MODULENAME, "ChangeSoundDlg");
+
+ ptrW uid(Contact_GetInfo(CNF_UNIQUEID, pData->hContact));
+ wchar_t value[100];
+ mir_snwprintf(value, TranslateT("Custom sound for %s (%s)"), Clist_GetContactDisplayName(pData->hContact), uid.get());
+ SetWindowText(m_hwnd, value);
+
+ DBVARIANT dbv = { 0 };
+ if (!g_plugin.getWString(pData->hContact, SETTINGSKEY, &dbv)) {
+ btnPlay.Enable();
+ btnReset.Enable();
+ label.SetText(PathFindFileNameW(dbv.pwszVal));
+ db_free(&dbv);
}
- return TRUE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDOK:
- p = XSN_Users.find((XSN_Data *)&hContact);
- if (p != nullptr) {
- if (mir_wstrcmpi(p->path, L"")) {
- wchar_t shortpath[MAX_PATH];
- PathToRelativeW(p->path, shortpath);
- g_plugin.setWString(hContact, SETTINGSKEY, shortpath);
- }
- g_plugin.setByte(hContact, SETTINGSIGNOREKEY, p->ignore);
- }
-
- case IDCANCEL:
- DestroyWindow(hwndDlg);
- break;
-
- case IDC_CONT_BUTTON_CHOOSE_SOUND:
- {
- wchar_t FileName[MAX_PATH];
- wchar_t *tszMirDir = Utils_ReplaceVarsW(L"%miranda_path%");
-
- OPENFILENAME ofn = { 0 };
- ofn.lStructSize = sizeof(ofn);
- wchar_t tmp[MAX_PATH];
- if (GetModuleHandle(L"bass_interface.dll"))
- mir_snwprintf(tmp, L"%s (*.wav, *.mp3, *.ogg)%c*.wav;*.mp3;*.ogg%c%c", TranslateT("Sound files"), 0, 0, 0);
- else
- mir_snwprintf(tmp, L"%s (*.wav)%c*.wav%c%c", TranslateT("WAV files"), 0, 0, 0);
- ofn.lpstrFilter = tmp;
- ofn.hwndOwner = nullptr;
- ofn.lpstrFile = FileName;
- ofn.nMaxFile = MAX_PATH;
- ofn.nMaxFileTitle = MAX_PATH;
- ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
- ofn.lpstrInitialDir = tszMirDir;
- *FileName = '\0';
- ofn.lpstrDefExt = L"";
-
- if (GetOpenFileName(&ofn)) {
- SetDlgItemText(hwndDlg, IDC_CONT_LABEL_SOUND, PathFindFileName(FileName));
- p = XSN_Users.find((XSN_Data *)&hContact);
- if (p == nullptr)
- XSN_Users.insert(new XSN_Data(hContact, FileName, IsDlgButtonChecked(hwndDlg, IDC_CONT_IGNORE_SOUND) ? 1 : 0, 1));
- else {
- wcsncpy(p->path, FileName, _countof(p->path));
- p->ignore = IsDlgButtonChecked(hwndDlg, IDC_CONT_IGNORE_SOUND) ? 1 : 0;
- }
- EnableWindow(GetDlgItem(hwndDlg, IDC_CONT_BUTTON_TEST_PLAY), TRUE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_CONT_BUTTON_RESET_SOUND), TRUE);
- }
- mir_free(tszMirDir);
- }
- break;
-
- case IDC_CONT_BUTTON_TEST_PLAY:
- p = XSN_Users.find((XSN_Data *)&hContact);
- isIgnoreSound = 0;
- if (p == nullptr) {
- DBVARIANT dbv;
- if (!g_plugin.getWString(hContact, SETTINGSKEY, &dbv)) {
- wchar_t longpath[MAX_PATH] = { 0 };
- PathToAbsoluteW(dbv.pwszVal, longpath);
- Skin_PlaySoundFile(longpath);
- db_free(&dbv);
- }
- }
- else {
- wchar_t longpath[MAX_PATH] = { 0 };
- PathToAbsoluteW(p->path, longpath);
- Skin_PlaySoundFile(longpath);
- }
- break;
-
- case IDC_CONT_BUTTON_RESET_SOUND:
- EnableWindow(GetDlgItem(hwndDlg, IDC_CONT_BUTTON_TEST_PLAY), FALSE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_CONT_BUTTON_RESET_SOUND), FALSE);
- CheckDlgButton(hwndDlg, IDC_CONT_IGNORE_SOUND, BST_UNCHECKED);
- SetDlgItemText(hwndDlg, IDC_CONT_LABEL_SOUND, TranslateT("Not set"));
-
- p = XSN_Users.find((XSN_Data *)&hContact);
- if (p != nullptr) {
- XSN_Users.remove(p);
- delete p;
- }
- g_plugin.delSetting(hContact, SETTINGSKEY);
- g_plugin.delSetting(hContact, SETTINGSIGNOREKEY);
- break;
-
- case IDC_CONT_IGNORE_SOUND:
- p = XSN_Users.find((XSN_Data *)&hContact);
- if (p == nullptr) {
- DBVARIANT dbv;
- if (!g_plugin.getWString(hContact, SETTINGSKEY, &dbv)) {
- wchar_t longpath[MAX_PATH];
- PathToAbsoluteW(dbv.pwszVal, longpath);
- XSN_Users.insert(new XSN_Data(hContact, longpath, IsDlgButtonChecked(hwndDlg, IDC_CONT_IGNORE_SOUND) ? 1 : 0, 1));
- db_free(&dbv);
- }
- else XSN_Users.insert(new XSN_Data(hContact, L"", IsDlgButtonChecked(hwndDlg, IDC_CONT_IGNORE_SOUND) ? 1 : 0, 1));
- }
- else p->ignore = IsDlgButtonChecked(hwndDlg, IDC_CONT_IGNORE_SOUND) ? 1 : 0;
+ else {
+ btnPlay.Disable();
+ btnReset.Disable();
+ label.SetText(TranslateT("Not set"));
}
- break;
- case WM_CLOSE:
- DestroyWindow(hwndDlg);
- break;
+ chkIgnore.SetState(pData->bIgnore);
+ return true;
+ }
+
+ bool OnApply() override
+ {
+ if (pData->path[0] == 0) {
+ g_plugin.delSetting(pData->hContact, SETTINGSKEY);
+ g_plugin.delSetting(pData->hContact, SETTINGSIGNOREKEY);
+
+ XSN_Users.remove(pData);
+ delete pData;
+ }
+ else {
+ wchar_t shortpath[MAX_PATH];
+ PathToRelativeW(pData->path, shortpath);
+ g_plugin.setWString(pData->hContact, SETTINGSKEY, shortpath);
- case WM_DESTROY:
- Utils_SaveWindowPosition(hwndDlg, hContact, MODULENAME, "ChangeSoundDlg");
- WindowList_Remove(hChangeSoundDlgList, hwndDlg);
+ g_plugin.setByte(pData->hContact, SETTINGSIGNOREKEY, pData->bIgnore);
+ }
+
+ return true;
+ }
+
+ void OnDestroy() override
+ {
+ Utils_SaveWindowPosition(m_hwnd, pData->hContact, MODULENAME, "ChangeSoundDlg");
+ WindowList_Remove(hChangeSoundDlgList, m_hwnd);
}
- return FALSE;
-}
+
+ void onClick_Choose(CCtrlButton *)
+ {
+ wchar_t FileName[MAX_PATH];
+ ptrW tszMirDir(Utils_ReplaceVarsW(L"%miranda_path%"));
+
+ OPENFILENAME ofn = { 0 };
+ ofn.lStructSize = sizeof(ofn);
+ wchar_t tmp[MAX_PATH];
+ if (GetModuleHandle(L"bass_interface.dll"))
+ mir_snwprintf(tmp, L"%s (*.wav, *.mp3, *.ogg)%c*.wav;*.mp3;*.ogg%c%c", TranslateT("Sound files"), 0, 0, 0);
+ else
+ mir_snwprintf(tmp, L"%s (*.wav)%c*.wav%c%c", TranslateT("WAV files"), 0, 0, 0);
+ ofn.lpstrFilter = tmp;
+ ofn.hwndOwner = nullptr;
+ ofn.lpstrFile = FileName;
+ ofn.nMaxFile = MAX_PATH;
+ ofn.nMaxFileTitle = MAX_PATH;
+ ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
+ ofn.lpstrInitialDir = tszMirDir;
+ *FileName = '\0';
+ ofn.lpstrDefExt = L"";
+ if (!GetOpenFileName(&ofn))
+ return;
+
+ label.SetText(PathFindFileNameW(FileName));
+
+ wcsncpy_s(pData->path, FileName, _TRUNCATE);
+ pData->bIgnore = chkIgnore.GetState();
+
+ btnPlay.Enable();
+ btnReset.Enable();
+ }
+
+ void onClick_Play(CCtrlButton*)
+ {
+ isIgnoreSound = 0;
+
+ wchar_t longpath[MAX_PATH] = { 0 };
+ PathToAbsoluteW(pData->path, longpath);
+ Skin_PlaySoundFile(longpath);
+ }
+
+ void onClick_Reset(CCtrlButton *)
+ {
+ btnPlay.Disable();
+ btnReset.Disable();
+ chkIgnore.SetState(false);
+ label.SetText(TranslateT("Not set"));
+
+ pData->path[0] = 0;
+ pData->bIgnore = false;
+ }
+
+ void onChange_Ignore(CCtrlCheck*)
+ {
+ pData->bIgnore = chkIgnore.GetState();
+ }
+};
INT_PTR ShowDialog(WPARAM wParam, LPARAM)
{
HWND hChangeSoundDlg = WindowList_Find(hChangeSoundDlgList, wParam);
- if (!hChangeSoundDlg) {
- hChangeSoundDlg = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_CONTACTS), nullptr, DlgProcContactsOptions, (LPARAM)wParam);
- ShowWindow(hChangeSoundDlg, SW_SHOW);
- }
+ if (!hChangeSoundDlg)
+ (new CContactDlg(wParam))->Show();
else {
SetForegroundWindow(hChangeSoundDlg);
SetFocus(hChangeSoundDlg);
diff --git a/plugins/XSoundNotify/src/options.cpp b/plugins/XSoundNotify/src/options.cpp index 5d8f3c3640..c720c8ecb4 100644 --- a/plugins/XSoundNotify/src/options.cpp +++ b/plugins/XSoundNotify/src/options.cpp @@ -23,298 +23,246 @@ bool IsSuitableProto(PROTOACCOUNT *pa) return true;
}
-static INT_PTR CALLBACK OptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+class COptionsDlg : public CDlgBase
{
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
+ CCtrlBase label;
+ CCtrlCheck chkIgnore;
+ CCtrlCombo comboAcc, comboUser;
+ CCtrlButton btnTest, btnReset, btnChoose;
+ XSN_Data* ObtainData()
+ {
+ LPARAM hContact = comboUser.GetItemData(comboUser.GetCurSel());
+ if (hContact == -1) {
+ PROTOACCOUNT *pa = (PROTOACCOUNT *)comboAcc.GetItemData(comboAcc.GetCurSel());
+ XSN_Data *p = XSN_Users.find((XSN_Data *)&pa->szModuleName);
+ if (p == nullptr)
+ XSN_Users.insert(p = new XSN_Data(pa->szModuleName, chkIgnore.GetState()));
+ return p;
+ }
+
+ XSN_Data *p = XSN_Users.find((XSN_Data *)&hContact);
+ if (p == nullptr)
+ XSN_Users.insert(p = new XSN_Data(hContact, chkIgnore.GetState()));
+ return p;
+ }
+
+public:
+ COptionsDlg() :
+ CDlgBase(g_plugin, IDD_OPTIONS),
+ label(this, IDC_OPT_LABEL_SOUND),
+ btnTest(this, IDC_OPT_BUTTON_TEST_PLAY),
+ btnReset(this, IDC_OPT_BUTTON_RESET_SOUND),
+ btnChoose(this, IDC_OPT_BUTTON_CHOOSE_SOUND),
+ chkIgnore(this, IDC_OPT_IGNORE_SOUND),
+ comboAcc(this, IDC_OPT_COMBO_PROTO),
+ comboUser(this, IDC_OPT_COMBO_USERS)
+ {
+ btnTest.OnClick = Callback(this, &COptionsDlg::onClick_Test);
+ btnReset.OnClick = Callback(this, &COptionsDlg::onClick_Reset);
+ btnChoose.OnClick = Callback(this, &COptionsDlg::onClick_Choose);
+
+ comboAcc.OnSelChanged = Callback(this, &COptionsDlg::onSelChanged_Proto);
+ comboUser.OnSelChanged = Callback(this, &COptionsDlg::onSelChanged_Users);
+
+ chkIgnore.OnChange = Callback(this, &COptionsDlg::onChange_Ignore);
+ }
+
+ bool OnInitDialog() override
+ {
for (auto &pa : Accounts())
if (IsSuitableProto(pa))
- SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_PROTO, CB_SETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_PROTO, CB_ADDSTRING, 0, (LPARAM)pa->tszAccountName), (LPARAM)pa);
- return TRUE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_OPT_COMBO_PROTO:
- if ((HIWORD(wParam) == CBN_SELCHANGE) || (HIWORD(wParam) == LBN_SELCHANGE)) {
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_COMBO_USERS), TRUE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_BUTTON_TEST_PLAY), FALSE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_BUTTON_RESET_SOUND), FALSE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_IGNORE_SOUND), FALSE);
- CheckDlgButton(hwndDlg, IDC_OPT_IGNORE_SOUND, BST_UNCHECKED);
- SetDlgItemText(hwndDlg, IDC_OPT_LABEL_SOUND, TranslateT("Not set"));
- SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_RESETCONTENT, 0, 0);
- int cursel = SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_PROTO, CB_GETCURSEL, 0, 0);
- PROTOACCOUNT *pa = (PROTOACCOUNT *)SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_PROTO, CB_GETITEMDATA, cursel, 0);
-
- SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_SETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_ADDSTRING, 0, (LPARAM)TranslateT("All contacts")), cursel);
- for (auto &hContact : Contacts(pa->szModuleName)) {
- ptrW uid(Contact_GetInfo(CNF_UNIQUEID, hContact));
- CMStringW value(FORMAT, L"%s (%s)", Clist_GetContactDisplayName(hContact), uid.get());
- SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_SETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_ADDSTRING, 0, (LPARAM)value.c_str()), hContact);
- }
+ comboAcc.AddString(pa->tszAccountName, (LPARAM)pa);
+
+ return true;
+ }
+
+ bool OnApply() override
+ {
+ for (auto &it : XSN_Users) {
+ if (it->path[0] != 0) {
+ wchar_t shortpath[MAX_PATH];
+ PathToRelativeW(it->path, shortpath);
+ if (it->bIsContact)
+ g_plugin.setWString(it->hContact, SETTINGSKEY, shortpath);
+ else
+ g_plugin.setWString((LPCSTR)it->hContact, shortpath);
}
- return 0;
-
- case IDC_OPT_COMBO_USERS:
- if ((HIWORD(wParam) == CBN_SELCHANGE) || (HIWORD(wParam) == LBN_SELCHANGE)) {
- int cursel = SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_GETCURSEL, 0, 0);
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_BUTTON_CHOOSE_SOUND), TRUE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_IGNORE_SOUND), TRUE);
- if (!cursel) {
- PROTOACCOUNT *pa = (PROTOACCOUNT *)SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_PROTO, CB_GETITEMDATA, cursel, 0);
- DBVARIANT dbv = { 0 };
- if (!g_plugin.getWString(pa->szModuleName, &dbv)) {
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_BUTTON_TEST_PLAY), TRUE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_BUTTON_RESET_SOUND), TRUE);
- SetDlgItemText(hwndDlg, IDC_OPT_LABEL_SOUND, PathFindFileName(dbv.pwszVal));
- db_free(&dbv);
- }
- else {
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_BUTTON_TEST_PLAY), FALSE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_BUTTON_RESET_SOUND), FALSE);
- SetDlgItemText(hwndDlg, IDC_OPT_LABEL_SOUND, TranslateT("Not set"));
- }
- size_t value_max_len = mir_strlen(pa->szModuleName) + 8;
- char *value = (char *)mir_alloc(sizeof(char) * value_max_len);
- mir_snprintf(value, value_max_len, "%s_ignore", pa->szModuleName);
- CheckDlgButton(hwndDlg, IDC_OPT_IGNORE_SOUND, g_plugin.getByte(value, 0) ? BST_CHECKED : BST_UNCHECKED);
- mir_free(value);
- }
- else {
- MCONTACT hContact = (MCONTACT)SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_GETITEMDATA, cursel, 0);
- DBVARIANT dbv = { 0 };
- if (!g_plugin.getWString(hContact, SETTINGSKEY, &dbv)) {
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_BUTTON_TEST_PLAY), TRUE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_BUTTON_RESET_SOUND), TRUE);
- SetDlgItemText(hwndDlg, IDC_OPT_LABEL_SOUND, PathFindFileName(dbv.pwszVal));
- db_free(&dbv);
- }
- else {
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_BUTTON_TEST_PLAY), FALSE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_BUTTON_RESET_SOUND), FALSE);
- SetDlgItemText(hwndDlg, IDC_OPT_LABEL_SOUND, TranslateT("Not set"));
- }
- CheckDlgButton(hwndDlg, IDC_OPT_IGNORE_SOUND, g_plugin.getByte(hContact, SETTINGSIGNOREKEY, 0) ? BST_CHECKED : BST_UNCHECKED);
- }
+ else g_plugin.delSetting(it->hContact, SETTINGSKEY);
+
+ if (it->bIsContact)
+ g_plugin.setByte(it->hContact, SETTINGSIGNOREKEY, it->bIgnore);
+ else {
+ size_t value_max_len = mir_strlen((const char *)it->hContact) + 8;
+ char *value = (char *)mir_alloc(sizeof(char) * value_max_len);
+ mir_snprintf(value, value_max_len, "%s_ignore", (const char *)it->hContact);
+ g_plugin.setByte(value, it->bIgnore);
+ mir_free(value);
}
- return 0;
-
- case IDC_OPT_BUTTON_CHOOSE_SOUND:
- {
- wchar_t FileName[MAX_PATH];
- wchar_t *tszMirDir = Utils_ReplaceVarsW(L"%miranda_path%");
-
- OPENFILENAME ofn = { 0 };
- ofn.lStructSize = sizeof(ofn);
- wchar_t tmp[MAX_PATH];
- if (GetModuleHandle(L"bass_interface.dll"))
- mir_snwprintf(tmp, L"%s (*.wav, *.mp3, *.ogg)%c*.wav;*.mp3;*.ogg%c%c", TranslateT("Sound files"), 0, 0, 0);
- else
- mir_snwprintf(tmp, L"%s (*.wav)%c*.wav%c%c", TranslateT("WAV files"), 0, 0, 0);
- ofn.lpstrFilter = tmp;
- ofn.hwndOwner = nullptr;
- ofn.lpstrFile = FileName;
- ofn.nMaxFile = MAX_PATH;
- ofn.nMaxFileTitle = MAX_PATH;
- ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
- ofn.lpstrInitialDir = tszMirDir;
- *FileName = '\0';
- ofn.lpstrDefExt = L"";
-
- if (GetOpenFileName(&ofn)) {
- SetDlgItemText(hwndDlg, IDC_OPT_LABEL_SOUND, PathFindFileName(FileName));
- int cursel = SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_GETCURSEL, 0, 0);
- if (!cursel) {
- PROTOACCOUNT *pa = (PROTOACCOUNT *)SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_PROTO, CB_GETITEMDATA, cursel, 0);
- XSN_Data *p = XSN_Users.find((XSN_Data *)&pa->szModuleName);
- if (p == nullptr)
- XSN_Users.insert(new XSN_Data((LPARAM)pa->szModuleName, FileName, IsDlgButtonChecked(hwndDlg, IDC_OPT_IGNORE_SOUND) ? 1 : 0, 0));
- else {
- wcsncpy(p->path, FileName, _countof(p->path));
- p->ignore = IsDlgButtonChecked(hwndDlg, IDC_OPT_IGNORE_SOUND) ? 1 : 0;
- }
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_BUTTON_TEST_PLAY), TRUE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_BUTTON_RESET_SOUND), TRUE);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- }
- else {
- MCONTACT hContact = (MCONTACT)SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_GETITEMDATA, cursel, 0);
- XSN_Data *p = XSN_Users.find((XSN_Data *)&hContact);
- if (p == nullptr)
- XSN_Users.insert(new XSN_Data(hContact, FileName, IsDlgButtonChecked(hwndDlg, IDC_OPT_IGNORE_SOUND) ? 1 : 0, 1));
- else {
- wcsncpy(p->path, FileName, _countof(p->path));
- p->ignore = IsDlgButtonChecked(hwndDlg, IDC_OPT_IGNORE_SOUND) ? 1 : 0;
- }
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_BUTTON_TEST_PLAY), TRUE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_BUTTON_RESET_SOUND), TRUE);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- }
- }
- mir_free(tszMirDir);
+ }
+ return true;
+ }
+
+ void onSelChanged_Proto(CCtrlCombo *)
+ {
+ comboUser.Enable();
+ comboUser.ResetContent();
+
+ btnTest.Disable();
+ btnReset.Disable();
+ chkIgnore.Disable();
+ chkIgnore.SetState(false);
+ label.SetText(TranslateT("Not set"));
+
+ int cursel = comboAcc.GetCurSel();
+ PROTOACCOUNT *pa = (PROTOACCOUNT *)comboAcc.GetItemData(cursel);
+ comboUser.AddString(TranslateT("All contacts"), -1);
+
+ for (auto &hContact : Contacts(pa->szModuleName)) {
+ ptrW uid(Contact_GetInfo(CNF_UNIQUEID, hContact));
+ CMStringW value(FORMAT, L"%s (%s)", Clist_GetContactDisplayName(hContact), uid.get());
+ comboUser.AddString(value, hContact);
+ }
+ }
+
+ void onSelChanged_Users(CCtrlCombo *)
+ {
+ btnChoose.Enable();
+ chkIgnore.Enable();
+
+ LPARAM hContact = comboUser.GetItemData(comboUser.GetCurSel());
+ if (hContact == -1) {
+ PROTOACCOUNT *pa = (PROTOACCOUNT *)comboAcc.GetItemData(comboAcc.GetCurSel());
+ ptrW wszText(g_plugin.getWStringA(pa->szModuleName));
+ if (wszText) {
+ btnTest.Enable();
+ btnReset.Enable();
+ label.SetText(PathFindFileNameW(wszText));
}
- return 0;
-
- case IDC_OPT_BUTTON_TEST_PLAY:
- {
- int cursel = SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_GETCURSEL, 0, 0);
- if (!cursel) {
- PROTOACCOUNT *pa = (PROTOACCOUNT *)SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_PROTO, CB_GETITEMDATA, cursel, 0);
- XSN_Data *p = XSN_Users.find((XSN_Data *)&pa->szModuleName);
- isIgnoreSound = 0;
- if (p == nullptr) {
- DBVARIANT dbv;
- if (!g_plugin.getWString(pa->szModuleName, &dbv)) {
- wchar_t longpath[MAX_PATH];
- PathToAbsoluteW(dbv.pwszVal, longpath);
- Skin_PlaySoundFile(longpath);
- db_free(&dbv);
- }
- }
- else {
- wchar_t longpath[MAX_PATH] = { 0 };
- PathToAbsoluteW(p->path, longpath);
- Skin_PlaySoundFile(longpath);
- }
- }
- else {
- MCONTACT hContact = (MCONTACT)SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_GETITEMDATA, cursel, 0);
- XSN_Data *p = XSN_Users.find((XSN_Data *)&hContact);
- isIgnoreSound = 0;
- if (p == nullptr) {
- DBVARIANT dbv;
- if (!g_plugin.getWString(hContact, SETTINGSKEY, &dbv)) {
- wchar_t longpath[MAX_PATH];
- PathToAbsoluteW(dbv.pwszVal, longpath);
- Skin_PlaySoundFile(longpath);
- db_free(&dbv);
- }
- }
- else {
- wchar_t longpath[MAX_PATH] = { 0 };
- PathToAbsoluteW(p->path, longpath);
- Skin_PlaySoundFile(longpath);
- }
- }
+ else {
+ btnTest.Disable();
+ btnReset.Disable();
+ label.SetText(TranslateT("Not set"));
}
- return 0;
-
- case IDC_OPT_BUTTON_RESET_SOUND:
- {
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_BUTTON_TEST_PLAY), FALSE);
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_BUTTON_RESET_SOUND), FALSE);
- CheckDlgButton(hwndDlg, IDC_OPT_IGNORE_SOUND, BST_UNCHECKED);
- SetDlgItemText(hwndDlg, IDC_OPT_LABEL_SOUND, TranslateT("Not set"));
- int cursel = SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_GETCURSEL, 0, 0);
- if (!cursel) {
- PROTOACCOUNT *pa = (PROTOACCOUNT *)SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_PROTO, CB_GETITEMDATA, cursel, 0);
- XSN_Data *p = XSN_Users.find((XSN_Data *)&pa->szModuleName);
- if (p != nullptr) {
- XSN_Users.remove(p);
- delete p;
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- }
- g_plugin.delSetting(pa->szModuleName);
- size_t value_max_len = mir_strlen(pa->szModuleName) + 8;
- char *value = (char *)mir_alloc(sizeof(char) * value_max_len);
- mir_snprintf(value, value_max_len, "%s_ignore", pa->szModuleName);
- g_plugin.delSetting(value);
- mir_free(value);
- }
- else {
- MCONTACT hContact = (MCONTACT)SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_GETITEMDATA, cursel, 0);
- XSN_Data *p = XSN_Users.find((XSN_Data *)&hContact);
- if (p != nullptr) {
- XSN_Users.remove(p);
- delete p;
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- }
- g_plugin.delSetting(hContact, SETTINGSKEY);
- g_plugin.delSetting(hContact, SETTINGSIGNOREKEY);
- }
+
+ size_t value_max_len = mir_strlen(pa->szModuleName) + 8;
+ char *value = (char *)mir_alloc(sizeof(char) * value_max_len);
+ mir_snprintf(value, value_max_len, "%s_ignore", pa->szModuleName);
+ chkIgnore.SetState(g_plugin.getByte(value, 0));
+ mir_free(value);
+ }
+ else {
+ ptrW wszPath(g_plugin.getWStringA(hContact, SETTINGSKEY));
+ if (wszPath) {
+ btnTest.Enable();
+ btnReset.Enable();
+ label.SetText(PathFindFileNameW(wszPath));
}
- return 0;
-
- case IDC_OPT_IGNORE_SOUND:
- {
- int cursel = SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_GETCURSEL, 0, 0);
- if (!cursel) {
- PROTOACCOUNT *pa = (PROTOACCOUNT *)SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_PROTO, CB_GETITEMDATA, cursel, 0);
- XSN_Data *p = XSN_Users.find((XSN_Data *)&pa->szModuleName);
- if (p == nullptr) {
- DBVARIANT dbv;
- if (!g_plugin.getWString(pa->szModuleName, &dbv)) {
- wchar_t longpath[MAX_PATH];
- PathToAbsoluteW(dbv.pwszVal, longpath);
- XSN_Users.insert(new XSN_Data((LPARAM)pa->szModuleName, longpath, IsDlgButtonChecked(hwndDlg, IDC_OPT_IGNORE_SOUND) ? 1 : 0, 0));
- db_free(&dbv);
- }
- else XSN_Users.insert(new XSN_Data((LPARAM)pa->szModuleName, L"", IsDlgButtonChecked(hwndDlg, IDC_OPT_IGNORE_SOUND) ? 1 : 0, 0));
- }
- else p->ignore = IsDlgButtonChecked(hwndDlg, IDC_OPT_IGNORE_SOUND) ? 1 : 0;
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- }
- else {
- MCONTACT hContact = (MCONTACT)SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_GETITEMDATA, cursel, 0);
- XSN_Data *p = XSN_Users.find((XSN_Data *)&hContact);
- if (p == nullptr) {
- DBVARIANT dbv;
- if (!g_plugin.getWString(hContact, SETTINGSKEY, &dbv)) {
- wchar_t longpath[MAX_PATH];
- PathToAbsoluteW(dbv.pwszVal, longpath);
- XSN_Users.insert(new XSN_Data(hContact, longpath, IsDlgButtonChecked(hwndDlg, IDC_OPT_IGNORE_SOUND) ? 1 : 0, 1));
- db_free(&dbv);
- }
- else XSN_Users.insert(new XSN_Data(hContact, L"", IsDlgButtonChecked(hwndDlg, IDC_OPT_IGNORE_SOUND) ? 1 : 0, 1));
- }
- else p->ignore = IsDlgButtonChecked(hwndDlg, IDC_OPT_IGNORE_SOUND) ? 1 : 0;
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- }
+ else {
+ btnTest.Disable();
+ btnReset.Disable();
+ label.SetText(TranslateT("Not set"));
}
- return 0;
+ chkIgnore.SetState(g_plugin.getByte(hContact, SETTINGSIGNOREKEY, 0));
}
- break;
-
- case WM_NOTIFY:
- NMHDR *hdr = (NMHDR *)lParam;
- switch (hdr->code) {
- case PSN_APPLY:
- for (auto &it : XSN_Users) {
- if (mir_wstrcmpi(it->path, L"")) {
- wchar_t shortpath[MAX_PATH];
- PathToRelativeW(it->path, shortpath);
- if (it->iscontact)
- g_plugin.setWString(it->hContact, SETTINGSKEY, shortpath);
- else
- g_plugin.setWString((LPCSTR)it->hContact, shortpath);
- }
- if (it->iscontact)
- g_plugin.setByte(it->hContact, SETTINGSIGNOREKEY, it->ignore);
- else {
- size_t value_max_len = mir_strlen((const char *)it->hContact) + 8;
- char *value = (char *)mir_alloc(sizeof(char) * value_max_len);
- mir_snprintf(value, value_max_len, "%s_ignore", (const char *)it->hContact);
- g_plugin.setByte(value, it->ignore);
- mir_free(value);
- }
+ }
+
+ void onClick_Test(CCtrlButton*)
+ {
+ isIgnoreSound = 0;
+
+ auto *p = ObtainData();
+ wchar_t longpath[MAX_PATH];
+ PathToAbsoluteW(p->path, longpath);
+ Skin_PlaySoundFile(longpath);
+ }
+
+ void onChange_Ignore(CCtrlCheck *)
+ {
+ auto *p = ObtainData();
+ p->bIgnore = chkIgnore.GetState();
+ NotifyChange();
+ }
+
+ void onClick_Choose(CCtrlButton *)
+ {
+ wchar_t tmp[MAX_PATH];
+ if (GetModuleHandle(L"bass_interface.dll"))
+ mir_snwprintf(tmp, L"%s (*.wav, *.mp3, *.ogg)%c*.wav;*.mp3;*.ogg%c%c", TranslateT("Sound files"), 0, 0, 0);
+ else
+ mir_snwprintf(tmp, L"%s (*.wav)%c*.wav%c%c", TranslateT("WAV files"), 0, 0, 0);
+
+ wchar_t FileName[MAX_PATH]; FileName[0] = '\0';
+ ptrW tszMirDir(Utils_ReplaceVarsW(L"%miranda_path%"));
+
+ OPENFILENAME ofn = { 0 };
+ ofn.lStructSize = sizeof(ofn);
+ ofn.lpstrFilter = tmp;
+ ofn.hwndOwner = nullptr;
+ ofn.lpstrFile = FileName;
+ ofn.nMaxFile = MAX_PATH;
+ ofn.nMaxFileTitle = MAX_PATH;
+ ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
+ ofn.lpstrInitialDir = tszMirDir;
+ ofn.lpstrDefExt = L"";
+ if (!GetOpenFileName(&ofn))
+ return;
+
+ label.SetText(PathFindFileNameW(FileName));
+
+ auto *p = ObtainData();
+ wcsncpy_s(p->path, FileName, _TRUNCATE);
+ p->bIgnore = chkIgnore.GetState();
+
+ btnTest.Enable();
+ btnReset.Enable();
+ NotifyChange();
+ }
+
+ void onClick_Reset(CCtrlButton *)
+ {
+ btnTest.Disable();
+ btnReset.Disable();
+ chkIgnore.SetState(false);
+ label.SetText(TranslateT("Not set"));
+
+ LPARAM hContact = comboUser.GetItemData(comboUser.GetCurSel());
+ if (hContact == -1) {
+ PROTOACCOUNT *pa = (PROTOACCOUNT *)comboAcc.GetItemData(comboAcc.GetCurSel());
+ XSN_Data *p = XSN_Users.find((XSN_Data *)&pa->szModuleName);
+ if (p != nullptr) {
+ XSN_Users.remove(p);
+ delete p;
+ NotifyChange();
}
- break;
+ g_plugin.delSetting(pa->szModuleName);
+ size_t value_max_len = mir_strlen(pa->szModuleName) + 8;
+ char *value = (char *)mir_alloc(sizeof(char) * value_max_len);
+ mir_snprintf(value, value_max_len, "%s_ignore", pa->szModuleName);
+ g_plugin.delSetting(value);
+ mir_free(value);
+ }
+ else {
+ XSN_Data *p = XSN_Users.find((XSN_Data *)&hContact);
+ if (p != nullptr) {
+ XSN_Users.remove(p);
+ delete p;
+ NotifyChange();
+ }
+ g_plugin.delSetting(hContact, SETTINGSKEY);
+ g_plugin.delSetting(hContact, SETTINGSIGNOREKEY);
}
}
- return FALSE;
-}
+};
INT OptInit(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = {};
odp.position = 100000000;
odp.flags = ODPF_BOLDGROUPS | ODPF_UNICODE;
- odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS);
odp.szGroup.w = LPGENW("Sounds");
odp.szTitle.w = LPGENW("XSound Notify");
- odp.pfnDlgProc = OptsProc;
+ odp.pDialog = new COptionsDlg();
g_plugin.addOptions(wParam, &odp);
return 0;
}
diff --git a/plugins/XSoundNotify/src/stdafx.h b/plugins/XSoundNotify/src/stdafx.h index 850750ad61..9b3fcc09e1 100644 --- a/plugins/XSoundNotify/src/stdafx.h +++ b/plugins/XSoundNotify/src/stdafx.h @@ -34,16 +34,10 @@ struct XSN_Data {
LPARAM hContact;
wchar_t path[MAX_PATH];
- BYTE ignore;
- BYTE iscontact;
-
- __forceinline XSN_Data(LPARAM _aContact, wchar_t *_path, BYTE _ignore, BYTE _iscontact) :
- hContact(_aContact)
- {
- wcsncpy(path, _path, _countof(path));
- ignore = _ignore;
- iscontact = _iscontact;
- }
+ bool bIsContact, bIgnore;
+
+ XSN_Data(MCONTACT _aContact, bool _ignore);
+ XSN_Data(const char *szModuleName, bool _ignore);
};
extern LIST<XSN_Data> XSN_Users;
diff --git a/plugins/XSoundNotify/src/version.h b/plugins/XSoundNotify/src/version.h index 5a56cf5757..82b32b0e64 100644 --- a/plugins/XSoundNotify/src/version.h +++ b/plugins/XSoundNotify/src/version.h @@ -1,13 +1,13 @@ -#define __MAJOR_VERSION 1 -#define __MINOR_VERSION 0 -#define __RELEASE_NUM 1 -#define __BUILD_NUM 3 +#define __MAJOR_VERSION 1 +#define __MINOR_VERSION 1 +#define __RELEASE_NUM 0 +#define __BUILD_NUM 4 #include <stdver.h> #define __PLUGIN_NAME "XSoundNotify" #define __FILENAME "XSoundNotify.dll" -#define __DESCRIPTION "Provides extended options for sound notifications." -#define __AUTHOR "Roman Torsten" -#define __AUTHORWEB "https://miranda-ng.org/p/XSoundNotify/" -#define __COPYRIGHT "© 2011 Roman Torsten" +#define __DESCRIPTION "Provides extended options for sound notifications." +#define __AUTHOR "Roman Torsten" +#define __AUTHORWEB "https://miranda-ng.org/p/XSoundNotify/" +#define __COPYRIGHT "© 2011 Roman Torsten" diff --git a/plugins/XSoundNotify/src/xsn_main.cpp b/plugins/XSoundNotify/src/xsn_main.cpp index 8f3396823f..7d74b9e018 100644 --- a/plugins/XSoundNotify/src/xsn_main.cpp +++ b/plugins/XSoundNotify/src/xsn_main.cpp @@ -11,7 +11,7 @@ There is no warranty. CMPlugin g_plugin;
-LIST<XSN_Data> XSN_Users(10, NumericKeySortT);
+LIST<XSN_Data> XSN_Users(10, PtrKeySortT);
HGENMENU hChangeSound = nullptr;
MWindowList hChangeSoundDlgList = nullptr;
BYTE isIgnoreSound = 0, isOwnSound = 0, isIgnoreAccSound = 0, isAccSound = 0;
@@ -88,6 +88,32 @@ static int ProtoAck(WPARAM, LPARAM lParam) /////////////////////////////////////////////////////////////////////////////////////////
+XSN_Data::XSN_Data(MCONTACT _aContact, bool _ignore) :
+ hContact(_aContact),
+ bIgnore(_ignore),
+ bIsContact(true)
+{
+ ptrW wszPath(g_plugin.getWStringA(hContact, SETTINGSKEY));
+ if (wszPath)
+ wcsncpy_s(path, wszPath, _TRUNCATE);
+ else
+ path[0] = 0;
+}
+
+XSN_Data::XSN_Data(const char *szModuleName, bool _ignore) :
+ hContact((LPARAM)szModuleName),
+ bIgnore(_ignore),
+ bIsContact(false)
+{
+ ptrW wszPath(g_plugin.getWStringA(szModuleName));
+ if (wszPath)
+ wcsncpy_s(path, wszPath, _TRUNCATE);
+ else
+ path[0] = 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
static bool isReceiveMessage(MEVENT hDbEvent)
{
DBEVENTINFO info = {};
@@ -97,13 +123,11 @@ static bool isReceiveMessage(MEVENT hDbEvent) return !(((info.eventType != EVENTTYPE_MESSAGE) && !(info.flags & DBEF_READ)) || (info.flags & DBEF_SENT));
}
-static int ProcessEvent(WPARAM hContact, LPARAM lParam)
+static void PlayWorker(MCONTACT hContact)
{
- if (!isReceiveMessage(lParam))
- return 0;
+ DBVARIANT dbv;
isIgnoreSound = g_plugin.getByte(hContact, SETTINGSIGNOREKEY, 0);
- DBVARIANT dbv;
if (!isIgnoreSound && !g_plugin.getWString(hContact, SETTINGSKEY, &dbv)) {
wchar_t PlaySoundPath[MAX_PATH] = { 0 };
PathToAbsoluteW(dbv.pwszVal, PlaySoundPath);
@@ -111,7 +135,7 @@ static int ProcessEvent(WPARAM hContact, LPARAM lParam) Skin_PlaySoundFile(PlaySoundPath);
db_free(&dbv);
isOwnSound = 1;
- return 0;
+ return;
}
char *szProto = Proto_GetBaseAccountName(hContact);
@@ -129,6 +153,12 @@ static int ProcessEvent(WPARAM hContact, LPARAM lParam) db_free(&dbv);
isAccSound = 1;
}
+}
+
+static int ProcessEvent(WPARAM hContact, LPARAM lParam)
+{
+ if (isReceiveMessage(lParam))
+ PlayWorker(hContact);
return 0;
}
@@ -141,41 +171,9 @@ static int ProcessChatEvent(WPARAM, LPARAM lParam) if (gce->iType != GC_EVENT_MESSAGE)
return 0;
- MCONTACT hContact = g_chatApi.FindRoom(gce->pszModule, gce->pszID.w);
- if (hContact != 0) {
- ptrW nick(db_get_wsa(hContact, gce->pszModule, "MyNick"));
- if (nick == NULL || gce->pszText.w == nullptr)
- return 0;
-
- if (wcsstr(gce->pszText.w, nick)) {
- isIgnoreSound = g_plugin.getByte(hContact, SETTINGSIGNOREKEY, 0);
- DBVARIANT dbv;
- if (!isIgnoreSound && !g_plugin.getWString(hContact, SETTINGSKEY, &dbv)) {
- wchar_t PlaySoundPath[MAX_PATH] = { 0 };
- PathToAbsoluteW(dbv.pwszVal, PlaySoundPath);
- isOwnSound = 0;
- Skin_PlaySoundFile(PlaySoundPath);
- db_free(&dbv);
- isOwnSound = 1;
- return 0;
- }
- char *szProto = Proto_GetBaseAccountName(hContact);
- PROTOACCOUNT *pa = Proto_GetAccount(szProto);
- size_t value_max_len = mir_strlen(pa->szModuleName) + 8;
- char *value = (char *)mir_alloc(sizeof(char) * value_max_len);
- mir_snprintf(value, value_max_len, "%s_ignore", pa->szModuleName);
- isIgnoreAccSound = g_plugin.getByte(value, 0);
- mir_free(value);
- if (!isIgnoreAccSound && !g_plugin.getWString(pa->szModuleName, &dbv)) {
- wchar_t PlaySoundPath[MAX_PATH] = { 0 };
- PathToAbsoluteW(dbv.pwszVal, PlaySoundPath);
- isAccSound = 0;
- Skin_PlaySoundFile(PlaySoundPath);
- db_free(&dbv);
- isAccSound = 1;
- }
- }
- }
+ auto *si = g_chatApi.SM_FindSession(gce->pszID.w, gce->pszModule);
+ if (si && g_chatApi.IsHighlighted(si, gce))
+ PlayWorker(si->hContact);
return 0;
}
|