summaryrefslogtreecommitdiff
path: root/plugins/XSoundNotify/src/xsn_main.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-08-06 15:47:08 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-08-06 15:47:08 +0000
commit7ebc990573da8a08c58c1092ed126357c44804f5 (patch)
tree14321e3c8ea5e448ea222d32f2cff9e5df74c376 /plugins/XSoundNotify/src/xsn_main.cpp
parent08712b97685134254605fff7e4b4c0ff0a4fb53d (diff)
- added sounds for the protocols' state change;
- visual code moved to the separate files; - version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@5603 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/XSoundNotify/src/xsn_main.cpp')
-rw-r--r--plugins/XSoundNotify/src/xsn_main.cpp528
1 files changed, 67 insertions, 461 deletions
diff --git a/plugins/XSoundNotify/src/xsn_main.cpp b/plugins/XSoundNotify/src/xsn_main.cpp
index f70d61c3be..71178febd6 100644
--- a/plugins/XSoundNotify/src/xsn_main.cpp
+++ b/plugins/XSoundNotify/src/xsn_main.cpp
@@ -41,7 +41,65 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD miranda
return &pluginInfo;
}
-bool isReceiveMessage(HANDLE hDbEvent)
+/////////////////////////////////////////////////////////////////////////////////////////
+
+struct {
+ int iStatus;
+ const char *szName;
+ const TCHAR *szInfo;
+}
+static selfSounds[] =
+{
+ { ID_STATUS_OFFLINE, "SelfOffline", _T("Offline") },
+ { ID_STATUS_ONLINE, "SelfOnline", _T("Online") },
+ { ID_STATUS_AWAY, "SelfAway", _T("Away") },
+ { ID_STATUS_DND, "SelfDND", _T("Do Not Disturb") },
+ { ID_STATUS_NA, "SelfNA", _T("Not Available") },
+ { ID_STATUS_OCCUPIED, "SelfOccupied", _T("Occupied") },
+ { ID_STATUS_FREECHAT, "SelfFreeForChat", _T("Free For Chat") },
+ { ID_STATUS_INVISIBLE, "SelfInvisible", _T("Invisible") },
+ { ID_STATUS_ONTHEPHONE, "SelfOnThePhone", _T("On The Phone") },
+ { ID_STATUS_OUTTOLUNCH, "SelfOutToLunch", _T("Out To Lunch") }
+};
+
+void InitSelfSounds()
+{
+ // initializing self sounds for protocols
+ int protoCount=0;
+ PROTOACCOUNT** protos = 0;
+
+ CallService(MS_PROTO_ENUMACCOUNTS, (WPARAM)&protoCount, (LPARAM)&protos);
+ for (int i = 0; i < protoCount; i++) {
+ for(int j = 0; j < SIZEOF(selfSounds); j++) {
+ char namebuf[128];
+ mir_snprintf(namebuf, sizeof(namebuf), "%s%s", protos[i]->szModuleName, selfSounds[j].szName);
+
+ TCHAR infobuf[256];
+ mir_sntprintf(infobuf, SIZEOF(infobuf), _T("%s [%s]"), TranslateT("Self status"), protos[i]->tszAccountName);
+ SkinAddNewSoundExT(namebuf, infobuf, selfSounds[j].szInfo);
+ }
+ }
+}
+
+static int ProtoAck(WPARAM wParam, LPARAM lParam)
+{
+ ACKDATA *ack = (ACKDATA*) lParam;
+ if (ack != 0 && ack->szModule && ack->type == ACKTYPE_STATUS && ack->result == ACKRESULT_SUCCESS) {
+ for(int i = 0; i < SIZEOF(selfSounds); i++) {
+ if(selfSounds[i].iStatus == ack->lParam) {
+ char buf[128];
+ _snprintf(buf, sizeof(buf), "%s%s", ack->szModule, selfSounds[i].szName);
+ SkinPlaySound(buf);
+ break;
+ }
+ }
+ }
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static bool isReceiveMessage(HANDLE hDbEvent)
{
DBEVENTINFO info = { sizeof(info) };
db_event_get(hDbEvent, &info);
@@ -50,7 +108,7 @@ bool isReceiveMessage(HANDLE hDbEvent)
return !(((info.eventType != EVENTTYPE_MESSAGE) && !(info.flags & DBEF_READ)) || (info.flags & DBEF_SENT));
}
-INT ProcessEvent(WPARAM wParam, LPARAM lParam)
+static int ProcessEvent(WPARAM wParam, LPARAM lParam)
{
if (!isReceiveMessage(HANDLE(lParam)))
return 0;
@@ -68,7 +126,7 @@ INT ProcessEvent(WPARAM wParam, LPARAM lParam)
return 0;
}
-int OnPlaySound(WPARAM wParam, LPARAM lParam)
+static int OnPlaySound(WPARAM wParam, LPARAM lParam)
{
if (isIgnoreSound)
return 1;
@@ -80,462 +138,7 @@ int OnPlaySound(WPARAM wParam, LPARAM lParam)
return 0;
}
-bool IsSuitableProto(PROTOACCOUNT* pa)
-{
- if (pa == NULL)
- return false;
-
- if (pa->bDynDisabled || !pa->bIsEnabled)
- return false;
-
- if (!(CallProtoService(pa->szModuleName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IMRECV))
- return false;
-
- return true;
-}
-
-INT_PTR CALLBACK OptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM 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_OPT_COMBO_PROTO), CB_SETITEMDATA, SendMessage(GetDlgItem(hwndDlg, IDC_OPT_COMBO_PROTO), CB_ADDSTRING, 0, (LPARAM)protos[i]->tszAccountName), (LPARAM)protos[i]);
- 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);
-
- for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- 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:
- _tcscpy(uid, ptrT(mir_utf8decodeT(dbvuid.pszVal)));
- 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_OPT_COMBO_USERS), CB_SETITEMDATA, SendMessage(GetDlgItem(hwndDlg, IDC_OPT_COMBO_USERS), CB_ADDSTRING, 0, (LPARAM)value), (LPARAM)hContact);
- mir_free(value);
- db_free(&dbvuid);
- }
- }
- }
- }
- 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);
- HANDLE hContact = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_GETITEMDATA, cursel, 0);
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_BUTTON_CHOOSE_SOUND), TRUE);
- DBVARIANT dbv = {0};
- if ( !db_get_ts(hContact, SETTINGSNAME, 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.ptszVal));
- 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"));
- }
- EnableWindow(GetDlgItem(hwndDlg, IDC_OPT_IGNORE_SOUND), TRUE);
- CheckDlgButton(hwndDlg, IDC_OPT_IGNORE_SOUND, db_get_b(hContact, SETTINGSNAME, SETTINGSIGNOREKEY, 0));
- }
- return 0;
-
- case IDC_OPT_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_OPT_LABEL_SOUND, PathFindFileName(FileName));
- int cursel = SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_GETCURSEL, 0, 0);
- HANDLE hContact = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_OPT_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, IsDlgButtonChecked(hwndDlg, IDC_OPT_IGNORE_SOUND) ? 1 : 0));
- else
- {
- _tcsncpy(p->path, FileName, SIZEOF(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 0;
-
- case IDC_OPT_BUTTON_TEST_PLAY:
- {
- int cursel = SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_GETCURSEL, 0, 0);
- HANDLE hContact = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_GETITEMDATA, cursel, 0);
- XSN_Data *p = XSN_Users.find((XSN_Data *)&hContact);
- isIgnoreSound = 0;
- if (p == NULL) {
- DBVARIANT dbv;
- if ( !db_get_ts(hContact, SETTINGSNAME, SETTINGSKEY, &dbv)) {
- TCHAR longpath[MAX_PATH];
- 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_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);
- HANDLE hContact = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_OPT_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);
- db_unset(hContact, SETTINGSNAME, SETTINGSIGNOREKEY);
- }
- return 0;
-
- case IDC_OPT_IGNORE_SOUND:
- {
- int cursel = SendDlgItemMessage(hwndDlg, IDC_OPT_COMBO_USERS, CB_GETCURSEL, 0, 0);
- HANDLE hContact = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_OPT_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];
- PathToAbsoluteT(dbv.ptszVal, longpath);
- XSN_Users.insert( new XSN_Data(hContact, longpath, IsDlgButtonChecked(hwndDlg, IDC_OPT_IGNORE_SOUND) ? 1 : 0));
- db_free(&dbv);
- } else
- XSN_Users.insert( new XSN_Data(hContact, _T(""), IsDlgButtonChecked(hwndDlg, IDC_OPT_IGNORE_SOUND) ? 1 : 0));
- }
- else
- p->ignore = IsDlgButtonChecked(hwndDlg, IDC_OPT_IGNORE_SOUND) ? 1 : 0;
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- }
- 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++) {
- if (lstrcmpi(XSN_Users[i]->path, _T(""))) {
- TCHAR shortpath[MAX_PATH];
- PathToRelativeT(XSN_Users[i]->path, shortpath);
- db_set_ts(XSN_Users[i]->hContact, SETTINGSNAME, SETTINGSKEY, shortpath);
- }
- db_set_b(XSN_Users[i]->hContact, SETTINGSNAME, SETTINGSIGNOREKEY, XSN_Users[i]->ignore);
- }
- break;
- }
- }
- }
- 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;
-}
-
-INT_PTR CALLBACK DlgProcContactsOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- switch (msg) {
- case WM_INITDIALOG:
- {
- TranslateDialogDefault(hwndDlg);
- HANDLE hContact = (HANDLE)lParam;
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
- WindowList_Add(hChangeSoundDlgList, hwndDlg, hContact);
- Utils_RestoreWindowPositionNoSize(hwndDlg, hContact, SETTINGSNAME, "ChangeSoundDlg");
- char* szProto = GetContactProto(hContact);
- PROTOACCOUNT *pa = ProtoGetAccount(szProto);
- 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:
- _tcscpy(uid, ptrT( mir_utf8decodeT(dbvuid.pszVal)));
- break;
- }
-
- TCHAR *nick = (TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR);
- TCHAR value[100];
- mir_sntprintf(value, SIZEOF(value), TranslateT("Custom sound for %s (%s)"), nick, uid);
- SetWindowText(hwndDlg, value);
- db_free(&dbvuid);
- }
- }
- EnableWindow(GetDlgItem(hwndDlg, IDC_CONT_BUTTON_CHOOSE_SOUND), TRUE);
- DBVARIANT dbv = {0};
- if ( !db_get_ts(hContact, SETTINGSNAME, 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.ptszVal));
- 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, db_get_b(hContact, SETTINGSNAME, SETTINGSIGNOREKEY, 0));
- XSN_Data *p = XSN_Users.find((XSN_Data *)&hContact);
- if (p == NULL)
- {
- DBVARIANT dbv;
- if ( !db_get_ts(hContact, SETTINGSNAME, SETTINGSKEY, &dbv))
- {
- XSN_Users.insert( new XSN_Data(hContact, dbv.ptszVal, IsDlgButtonChecked(hwndDlg, IDC_CONT_IGNORE_SOUND) ? 1 : 0));
- db_free(&dbv);
- }
- }
- }
- return TRUE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDOK:
- {
- HANDLE hContact = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- XSN_Data *p = XSN_Users.find((XSN_Data *)&hContact);
- if (p != NULL)
- {
- if (lstrcmpi(p->path, _T(""))) {
- TCHAR shortpath[MAX_PATH];
- PathToRelativeT(p->path, shortpath);
- db_set_ts(hContact, SETTINGSNAME, SETTINGSKEY, shortpath);
- }
- db_set_b(hContact, SETTINGSNAME, SETTINGSIGNOREKEY, p->ignore);
- }
- }
-
- case IDCANCEL:
- DestroyWindow(hwndDlg);
- break;
-
- case IDC_CONT_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)) {
- HANDLE hContact = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- SetDlgItemText(hwndDlg, IDC_CONT_LABEL_SOUND, PathFindFileName(FileName));
- XSN_Data *p = XSN_Users.find((XSN_Data *)&hContact);
- if (p == NULL)
- XSN_Users.insert( new XSN_Data(hContact, FileName, IsDlgButtonChecked(hwndDlg, IDC_CONT_IGNORE_SOUND) ? 1 : 0));
- else
- {
- _tcsncpy(p->path, FileName, SIZEOF(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:
- {
- HANDLE hContact = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- XSN_Data *p = XSN_Users.find((XSN_Data *)&hContact);
- isIgnoreSound = 0;
- 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);
- }
- }
- break;
-
- case IDC_CONT_BUTTON_RESET_SOUND:
- {
- HANDLE hContact = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- 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"));
- XSN_Data *p = XSN_Users.find((XSN_Data *)&hContact);
- if (p != NULL)
- {
- XSN_Users.remove(p);
- delete p;
- }
- db_unset(hContact, SETTINGSNAME, SETTINGSKEY);
- db_unset(hContact, SETTINGSNAME, SETTINGSIGNOREKEY);
- }
- break;
-
- case IDC_CONT_IGNORE_SOUND:
- {
- HANDLE hContact = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- 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];
- PathToAbsoluteT(dbv.ptszVal, longpath);
- XSN_Users.insert( new XSN_Data(hContact, longpath, IsDlgButtonChecked(hwndDlg, IDC_CONT_IGNORE_SOUND) ? 1 : 0));
- db_free(&dbv);
- } else
- XSN_Users.insert( new XSN_Data(hContact, _T(""), IsDlgButtonChecked(hwndDlg, IDC_CONT_IGNORE_SOUND) ? 1 : 0));
- }
- else
- p->ignore = IsDlgButtonChecked(hwndDlg, IDC_CONT_IGNORE_SOUND) ? 1 : 0;
- }
- break;
- }
- break;
-
- case WM_CLOSE:
- DestroyWindow(hwndDlg);
- break;
-
- case WM_DESTROY:
- HANDLE hContact = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- Utils_SaveWindowPosition(hwndDlg, hContact, SETTINGSNAME, "ChangeSoundDlg");
- WindowList_Remove(hChangeSoundDlgList, hwndDlg);
- }
- return FALSE;
-}
-
-INT_PTR ShowDialog(WPARAM wParam, LPARAM lParam)
-{
- HWND hChangeSoundDlg = WindowList_Find(hChangeSoundDlgList, (HANDLE)wParam);
- if (!hChangeSoundDlg) {
- hChangeSoundDlg = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_CONTACTS), 0, DlgProcContactsOptions, (LPARAM)wParam);
- ShowWindow(hChangeSoundDlg, SW_SHOW);
- }
- else {
- SetForegroundWindow(hChangeSoundDlg);
- SetFocus(hChangeSoundDlg);
- }
- return 0;
-}
-
-int OnLoadInit(WPARAM wParam, LPARAM lParam)
+static int OnLoadInit(WPARAM wParam, LPARAM lParam)
{
CLISTMENUITEM mi = { sizeof(mi) };
mi.position = -0x7FFFFFFF;
@@ -544,10 +147,12 @@ int OnLoadInit(WPARAM wParam, LPARAM lParam)
mi.ptszName = LPGENT("Custom contact sound");
mi.pszService = "XSoundNotify/ContactMenuCommand";
hChangeSound = Menu_AddContactMenuItem(&mi);
+
+ InitSelfSounds();
return 0;
}
-int PrebuildContactMenu(WPARAM wParam, LPARAM lParam)
+static int PrebuildContactMenu(WPARAM wParam, LPARAM lParam)
{
HANDLE hContact = (HANDLE)wParam;
if (hContact) {
@@ -558,7 +163,7 @@ int PrebuildContactMenu(WPARAM wParam, LPARAM lParam)
return 0;
}
-int OnPreShutdown(WPARAM wParam, LPARAM lParam)
+static int OnPreShutdown(WPARAM wParam, LPARAM lParam)
{
WindowList_Broadcast(hChangeSoundDlgList, WM_CLOSE, 0, 0);
return 0;
@@ -572,6 +177,7 @@ extern "C" int __declspec(dllexport) Load()
hChangeSoundDlgList = (HANDLE)CallService(MS_UTILS_ALLOCWINDOWLIST, 0, 0);
+ HookEvent(ME_PROTO_ACK, ProtoAck);
HookEvent(ME_OPT_INITIALISE, OptInit);
HookEvent(ME_DB_EVENT_ADDED, ProcessEvent);
HookEvent(ME_SYSTEM_MODULESLOADED, OnLoadInit);