diff options
author | Kirill Volinsky <mataes2007@gmail.com> | 2013-04-04 19:00:03 +0000 |
---|---|---|
committer | Kirill Volinsky <mataes2007@gmail.com> | 2013-04-04 19:00:03 +0000 |
commit | c814aae8a9ba7f85996792b9c283fcd6605e11ff (patch) | |
tree | 480da7d4b69ba386c28dbe717105d741df8f85eb /plugins/XSoundNotify/src/xsn_main.cpp | |
parent | 5729f9c9a82d120cfd4a7eeb8b7297ac52a8332b (diff) |
added support of all accounts (not only icq and jabber)
not use atl
can play mp3 and others (bass_interface.dll required)
plugin settings moved to options
added relative path support
git-svn-id: http://svn.miranda-ng.org/main/trunk@4306 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/XSoundNotify/src/xsn_main.cpp')
-rw-r--r-- | plugins/XSoundNotify/src/xsn_main.cpp | 281 |
1 files changed, 237 insertions, 44 deletions
diff --git a/plugins/XSoundNotify/src/xsn_main.cpp b/plugins/XSoundNotify/src/xsn_main.cpp index 1a0aaf82fe..06c0c82231 100644 --- a/plugins/XSoundNotify/src/xsn_main.cpp +++ b/plugins/XSoundNotify/src/xsn_main.cpp @@ -11,7 +11,8 @@ There is no warranty. HINSTANCE hInst;
int hLangpack;
-
+LIST<XSN_Data> XSN_Users(10, LIST<XSN_Data>::FTSortFunc(HandleKeySort));
+
PLUGININFOEX pluginInfo = {
sizeof(PLUGININFOEX),
__PLUGIN_NAME,
@@ -26,55 +27,257 @@ PLUGININFOEX pluginInfo = { {0x8b86253, 0xec6e, 0x4d09, {0xb7, 0xa9, 0x64, 0xac, 0xdf, 0x6, 0x27, 0xb8}}
};
-extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
+BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
hInst = hinstDLL;
return TRUE;
}
-static INT_PTR PluginMenuCommand(WPARAM wParam, LPARAM lParam)
+extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
{
- try
- {
- SoundNotifyDataStorage storage;
- storage.init();
- SettingsDialog dlg(storage);
- if (dlg.DoModal() == IDOK)
- storage.commit();
- }
- catch (...)
+ return &pluginInfo;
+}
+
+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));
+}
+
+INT processEvent(WPARAM wParam, LPARAM lParam)
+{
+ if (!isReceiveMessage(lParam))
+ return 0;
+
+ DBVARIANT dbv;
+ if ( !db_get_ts((HANDLE)wParam, SETTINGSNAME, SETTINGSKEY, &dbv))
{
- MessageBox(0, TEXT("Unknown error occured while configuring"), TEXT("XSoundNotify Error"), MB_OK | MB_ICONERROR);
+ TCHAR longpath[MAX_PATH] = {0};
+ PathToAbsoluteT(dbv.ptszVal, longpath);
+ SkinPlaySoundFile(longpath);
+ db_free(&dbv);
}
return 0;
}
-extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
+bool IsSuitableProto(PROTOACCOUNT* pa)
{
- return &pluginInfo;
+ if (pa == NULL)
+ return false;
+
+ if (pa->bDynDisabled || !pa->bIsEnabled)
+ return false;
+
+ if (CallProtoService(pa->szProtoName, PS_GETCAPS, PFLAGNUM_2, 0) == 0)
+ return false;
+
+ return true;
}
-INT processEvent(WPARAM wParam, LPARAM lParam)
+INT_PTR CALLBACK OptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- try
- {
- if (!isReceiveMessage(lParam))
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
+ int count;
+ PROTOACCOUNT **protos;
+ ProtoEnumAccounts(&count, &protos);
+ for(int i = 0; i < count; i++) {
+ if (IsSuitableProto(protos[i]))
+ SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_PROTO), CB_SETITEMDATA, SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_PROTO), CB_ADDSTRING, 0, (LPARAM)protos[i]->tszAccountName), (LPARAM)protos[i]);
+ }
+ return TRUE;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_COMBO_PROTO:
+ if ((HIWORD(wParam) == CBN_SELCHANGE) || (HIWORD(wParam) == LBN_SELCHANGE)) {
+ EnableWindow(GetDlgItem(hwndDlg, IDC_COMBO_USERS), TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_TEST_PLAY), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_RESET_SOUND), FALSE);
+ SetDlgItemText(hwndDlg, IDC_LABEL_SOUND, TranslateT("Not set"));
+ SendDlgItemMessage(hwndDlg, IDC_COMBO_USERS, CB_RESETCONTENT, 0, 0);
+ int cursel = SendDlgItemMessage(hwndDlg, IDC_COMBO_PROTO, CB_GETCURSEL, 0, 0);
+ PROTOACCOUNT *pa = (PROTOACCOUNT *)SendDlgItemMessage(hwndDlg, IDC_COMBO_PROTO, CB_GETITEMDATA, cursel, 0);
+ HANDLE hContact = db_find_first();
+ while (hContact != NULL) {
+ char* szUniqueId = (char*)CallProtoService(pa->szModuleName, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
+ if ((INT_PTR) szUniqueId != CALLSERVICE_NOTFOUND && szUniqueId != NULL) {
+ DBVARIANT dbvuid = {0};
+ if ( !db_get(hContact, pa->szModuleName, szUniqueId, &dbvuid))
+ {
+ TCHAR uid[MAX_PATH];
+ switch(dbvuid.type) {
+ case DBVT_DWORD:
+ _itot(dbvuid.dVal, uid, 10);
+ break;
+
+ case DBVT_ASCIIZ:
+ _tcscpy(uid, _A2T(dbvuid.pszVal));
+ break;
+
+ case DBVT_UTF8:
+ {
+ TCHAR *tmpuid = mir_utf8decodeT(dbvuid.pszVal);
+ _tcscpy(uid, tmpuid);
+ mir_free(tmpuid);
+ }
+ break;
+ }
+
+ TCHAR *nick = (TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR);
+ TCHAR *value = (TCHAR *)mir_alloc(sizeof(TCHAR) * (_tcslen(uid) + _tcslen(nick) + 4));
+ mir_sntprintf(value, _tcslen(uid) + _tcslen(nick) + 4, _T("%s (%s)"), nick, uid);
+ SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_USERS), CB_SETITEMDATA, SendMessage(GetDlgItem(hwndDlg, IDC_COMBO_USERS), CB_ADDSTRING, 0, (LPARAM)value), (LPARAM)hContact);
+ mir_free(value);
+ db_free(&dbvuid);
+ }
+ }
+ hContact = db_find_next(hContact);
+ }
+
+ }
+ return 0;
+
+ case IDC_COMBO_USERS:
+ if ((HIWORD(wParam) == CBN_SELCHANGE) || (HIWORD(wParam) == LBN_SELCHANGE)) {
+ int cursel = SendDlgItemMessage(hwndDlg, IDC_COMBO_USERS, CB_GETCURSEL, 0, 0);
+ HANDLE hContact = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_COMBO_USERS, CB_GETITEMDATA, cursel, 0);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_CHOOSE_SOUND), TRUE);
+ DBVARIANT dbv = {0};
+ if ( !db_get_ts(hContact, SETTINGSNAME, SETTINGSKEY, &dbv))
+ {
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_TEST_PLAY), TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_RESET_SOUND), TRUE);
+ SetDlgItemText(hwndDlg, IDC_LABEL_SOUND, PathFindFileName(dbv.ptszVal));
+ db_free(&dbv);
+ } else {
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_TEST_PLAY), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_RESET_SOUND), FALSE);
+ SetDlgItemText(hwndDlg, IDC_LABEL_SOUND, TranslateT("Not set"));
+ }
+ }
return 0;
-
- std::tstring sound = getContactSound((HANDLE)wParam);
- if (!sound.empty())
- PlaySound(sound.c_str(), nullptr, SND_ASYNC | SND_FILENAME);
- }
- catch (std::exception & )
- {
- // log
- }
- catch (...)
- {
- // log
- }
+ case IDC_BUTTON_CHOOSE_SOUND:
+ {
+ TCHAR FileName[MAX_PATH];
+ TCHAR *tszMirDir = Utils_ReplaceVarsT(_T("%miranda_path%"));
+
+ OPENFILENAME ofn = {0};
+ ofn.lStructSize = sizeof(ofn);
+ TCHAR tmp[MAX_PATH];
+ if (GetModuleHandle(_T("bass_interface.dll")))
+ mir_sntprintf(tmp, SIZEOF(tmp), _T("%s (*.wav, *.mp3, *.ogg)%c*.wav;*.mp3;*.ogg%c%c"), TranslateT("Sound files"), 0, 0, 0);
+ else
+ mir_sntprintf(tmp, SIZEOF(tmp), _T("%s (*.wav)%c*.wav%c%c"), TranslateT("WAV files"), 0, 0, 0);
+ ofn.lpstrFilter = tmp;
+ ofn.hwndOwner = 0;
+ ofn.lpstrFile = FileName;
+ ofn.nMaxFile = MAX_PATH;
+ ofn.nMaxFileTitle = MAX_PATH;
+ ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
+ ofn.lpstrInitialDir = tszMirDir;
+ *FileName = '\0';
+ ofn.lpstrDefExt = _T("");
+
+ if (GetOpenFileName(&ofn)) {
+ SetDlgItemText(hwndDlg, IDC_LABEL_SOUND, PathFindFileName(FileName));
+ int cursel = SendDlgItemMessage(hwndDlg, IDC_COMBO_USERS, CB_GETCURSEL, 0, 0);
+ HANDLE hContact = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_COMBO_USERS, CB_GETITEMDATA, cursel, 0);
+ XSN_Data *p = XSN_Users.find((XSN_Data *)&hContact);
+ if (p == NULL)
+ XSN_Users.insert( new XSN_Data(hContact, FileName));
+ else
+ _tcsncpy(p->path, FileName, SIZEOF(p->path));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_TEST_PLAY), TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_RESET_SOUND), TRUE);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ }
+ mir_free(tszMirDir);
+ }
+ return 0;
+
+ case IDC_BUTTON_TEST_PLAY:
+ {
+ int cursel = SendDlgItemMessage(hwndDlg, IDC_COMBO_USERS, CB_GETCURSEL, 0, 0);
+ HANDLE hContact = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_COMBO_USERS, CB_GETITEMDATA, cursel, 0);
+ XSN_Data *p = XSN_Users.find((XSN_Data *)&hContact);
+ if (p == NULL)
+ {
+ DBVARIANT dbv;
+ if ( !db_get_ts(hContact, SETTINGSNAME, SETTINGSKEY, &dbv))
+ {
+ TCHAR longpath[MAX_PATH] = {0};
+ PathToAbsoluteT(dbv.ptszVal, longpath);
+ SkinPlaySoundFile(longpath);
+ db_free(&dbv);
+ }
+ }
+ else
+ {
+ TCHAR longpath[MAX_PATH] = {0};
+ PathToAbsoluteT(p->path, longpath);
+ SkinPlaySoundFile(longpath);
+ }
+ }
+ return 0;
+
+ case IDC_BUTTON_RESET_SOUND:
+ {
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_TEST_PLAY), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_RESET_SOUND), FALSE);
+ SetDlgItemText(hwndDlg, IDC_LABEL_SOUND, TranslateT("Not set"));
+ int cursel = SendDlgItemMessage(hwndDlg, IDC_COMBO_USERS, CB_GETCURSEL, 0, 0);
+ HANDLE hContact = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_COMBO_USERS, CB_GETITEMDATA, cursel, 0);
+ XSN_Data *p = XSN_Users.find((XSN_Data *)&hContact);
+ if (p != NULL)
+ {
+ XSN_Users.remove(p);
+ delete p;
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ }
+ db_unset(hContact, SETTINGSNAME, SETTINGSKEY);
+ }
+ return 0;
+ }
+ break;
+
+ case WM_NOTIFY:
+ {
+ NMHDR *hdr = (NMHDR *)lParam;
+ switch (hdr->code) {
+ case PSN_APPLY:
+ {
+ for (int i = 0; i < XSN_Users.getCount(); i++)
+ {
+ TCHAR shortpath[MAX_PATH];
+ PathToRelativeT(XSN_Users[i]->path, shortpath);
+ db_set_ts(XSN_Users[i]->hContact, SETTINGSNAME, SETTINGSKEY, shortpath);
+ }
+ break;
+ }
+ }
+ }
+ }//end* switch (msg)
+ return FALSE;
+}
+
+INT OptInit(WPARAM wParam, LPARAM lParam)
+{
+ OPTIONSDIALOGPAGE odp = { sizeof(odp) };
+ odp.position = 100000000;
+ odp.hInstance = hInst;
+ odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR;
+ odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS);
+ odp.ptszGroup = LPGENT("Sounds");
+ odp.ptszTitle = LPGENT("XSound Notify");
+ odp.pfnDlgProc = OptsProc;
+ Options_AddPage(wParam, &odp);
return 0;
}
@@ -82,18 +285,8 @@ extern "C" int __declspec(dllexport) Load() {
mir_getLP(&pluginInfo);
- CLISTMENUITEM mi;
-
- 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";
- Menu_AddMainMenuItem(&mi);
- HookEvent(ME_DB_EVENT_ADDED, processEvent);
+ HookEvent(ME_OPT_INITIALISE, OptInit);
+ HookEvent(ME_DB_EVENT_ADDED, processEvent);
return 0;
}
|