/* Miranda IM: the free IM client for Microsoft* Windows* Copyright 2000-2009 Miranda ICQ/IM project, all portions of this codebase are copyrighted to the people listed in contributors.txt. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "commonheaders.h" struct SoundItem { char* name; TCHAR* section; TCHAR* description; char* tempFile; }; static BOOL bModuleInitialized = FALSE; static struct SoundItem *soundList = NULL; static int soundCount; static HANDLE hPlayEvent = NULL; static INT_PTR ServiceSkinAddNewSound(WPARAM, LPARAM lParam) { SKINSOUNDDESCEX *ssd = ( SKINSOUNDDESCEX* )lParam; switch( ssd->cbSize ) { case sizeof( SKINSOUNDDESCEX ): case SKINSOUNDDESC_SIZE_V1: case SKINSOUNDDESC_SIZE_V2: break; default: return 1; } if ( ssd->pszName == NULL || ssd->pszDescription == NULL) return 1; DBVARIANT dbv; DWORD dwFlags = ( ssd->cbSize == sizeof(SKINSOUNDDESCEX)) ? ssd->dwFlags : 0; soundList=(struct SoundItem*)mir_realloc(soundList,sizeof(struct SoundItem)*(soundCount+1)); SoundItem* item = &soundList[soundCount++]; item->name = mir_strdup( ssd->pszName ); item->tempFile = NULL; #if defined( _UNICODE ) TCHAR* ptszDefaultFile; if ( dwFlags & SSDF_UNICODE ) { item->description = mir_tstrdup( TranslateTS( ssd->ptszDescription )); item->section = mir_tstrdup( TranslateTS( ssd->cbSize != SKINSOUNDDESC_SIZE_V1 && ssd->pszSection != NULL ? ssd->ptszSection : _T("Other"))); ptszDefaultFile = mir_tstrdup( ssd->ptszDefaultFile ); } else { item->description = LangPackPcharToTchar( ssd->pszDescription ); item->section = LangPackPcharToTchar( ssd->cbSize != SKINSOUNDDESC_SIZE_V1 && ssd->pszSection != NULL ? ssd->pszSection : "Other" ); ptszDefaultFile = mir_a2t( ssd->pszDefaultFile ); } if ( ptszDefaultFile ) { if ( DBGetContactSettingString(NULL, "SkinSounds", item->name, &dbv)) DBWriteContactSettingTString(NULL, "SkinSounds", item->name, ptszDefaultFile); else DBFreeVariant(&dbv); mir_free( ptszDefaultFile ); } #else item->description = mir_tstrdup( TranslateTS( ssd->pszDescription )); item->section = mir_tstrdup( TranslateTS( ssd->cbSize != SKINSOUNDDESC_SIZE_V1 && ssd->pszSection != NULL ? ssd->pszSection : "Other" )); if ( ssd->pszDefaultFile ) { if ( DBGetContactSettingString(NULL, "SkinSounds", item->name, &dbv)) DBWriteContactSettingString(NULL, "SkinSounds", item->name, ssd->pszDefaultFile); else DBFreeVariant(&dbv); } #endif return 0; } static int SkinPlaySoundDefault(WPARAM wParam, LPARAM lParam) { char * pszFile = (char *) lParam; if ( pszFile && (DBGetContactSettingByte(NULL,"Skin","UseSound",0) || (int)wParam==1)) PlaySoundA(pszFile, NULL, SND_ASYNC | SND_FILENAME | SND_NOWAIT); return 0; } static INT_PTR ServiceSkinPlaySound(WPARAM, LPARAM lParam) { char* pszSoundName = ( char* )lParam; int j; for (j=0; jidFrom) { case 0: if (((LPNMHDR)lParam)->code == PSN_APPLY) { int i; DBWriteContactSettingByte(NULL, "Skin", "UseSound", (BYTE) IsDlgButtonChecked(hwndDlg, IDC_ENABLESOUNDS)); for ( i=0; i < soundCount; i++ ) if ( soundList[i].tempFile ) DBWriteContactSettingString(NULL,"SkinSounds",soundList[i].name,soundList[i].tempFile); { TVITEM tvi,tvic; tvi.hItem = TreeView_GetRoot(hwndTree); while ( tvi.hItem != NULL ) { tvi.mask = TVIF_PARAM | TVIF_HANDLE | TVIF_STATE; TreeView_GetItem(hwndTree, &tvi); if ( tvi.lParam == -1 ) { tvic.hItem = TreeView_GetChild(hwndTree, tvi.hItem); while ( tvic.hItem != NULL ) { tvic.mask = TVIF_PARAM | TVIF_HANDLE | TVIF_STATE; TreeView_GetItem(hwndTree, &tvic); if ((( tvic.state & TVIS_STATEIMAGEMASK ) >> 12 == 2 )) { DBCONTACTGETSETTING cgs; cgs.szModule = "SkinSoundsOff"; cgs.szSetting = soundList[tvic.lParam].name; CallService(MS_DB_CONTACT_DELETESETTING,(WPARAM)(HANDLE)NULL,(LPARAM)&cgs); } else DBWriteContactSettingByte(NULL,"SkinSoundsOff",soundList[tvic.lParam].name,1); tvic.hItem=TreeView_GetNextSibling(hwndTree,tvic.hItem); } } tvi.hItem=TreeView_GetNextSibling(hwndTree,tvi.hItem); } } return TRUE; } break; case IDC_SOUNDTREE: switch(((NMHDR*)lParam)->code) { case TVN_SELCHANGEDA: { NMTREEVIEW *pnmtv = (NMTREEVIEW*)lParam; TVITEM tvi = pnmtv->itemNew; if (tvi.lParam==-1) { SendMessage(hwndDlg, DM_HIDEPANE, 0, 0); } else { TCHAR buf[256]; DBVARIANT dbv; mir_sntprintf(buf, SIZEOF(buf), _T("%s: %s"), soundList[tvi.lParam].section, soundList[tvi.lParam].description); SetDlgItemText(hwndDlg, IDC_NAMEVAL, buf); if (soundList[tvi.lParam].tempFile) SetDlgItemTextA(hwndDlg, IDC_LOCATION, soundList[tvi.lParam].tempFile); else if(!DBGetContactSettingString(NULL,"SkinSounds",soundList[tvi.lParam].name,&dbv)) { SetDlgItemTextA(hwndDlg, IDC_LOCATION, dbv.pszVal); DBFreeVariant(&dbv); } else SetDlgItemText(hwndDlg, IDC_LOCATION, TranslateT("")); SendMessage(hwndDlg, DM_SHOWPANE, 0, 0); } } break; case TVN_KEYDOWN: { NMTVKEYDOWN* ptkd = (NMTVKEYDOWN*)lParam; if (ptkd&&ptkd->wVKey==VK_SPACE&&TreeView_GetSelection(ptkd->hdr.hwndFrom)) SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } break; case NM_CLICK: { TVHITTESTINFO hti; hti.pt.x=(short)LOWORD(GetMessagePos()); hti.pt.y=(short)HIWORD(GetMessagePos()); ScreenToClient(((LPNMHDR)lParam)->hwndFrom,&hti.pt); if(TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom,&hti)) if (hti.flags&TVHT_ONITEM) if(hti.flags&TVHT_ONITEMSTATEICON) if (TreeView_GetParent(hwndTree, hti.hItem)!=NULL) SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; } } break; } break; } return FALSE; } static UINT iconsExpertOnlyControls[]={IDC_IMPORT}; static int SkinOptionsInit(WPARAM wParam, LPARAM) { OPTIONSDIALOGPAGE odp = { 0 }; odp.cbSize = sizeof(odp); odp.position = -200000000; odp.hInstance = hMirandaInst; odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_SOUND); odp.pszGroup = LPGEN("Customize"); odp.pszTitle = LPGEN("Sounds"); odp.pfnDlgProc = DlgProcSoundOpts; odp.flags = ODPF_BOLDGROUPS; CallService( MS_OPT_ADDPAGE, wParam, ( LPARAM )&odp ); return 0; } static int SkinSystemModulesLoaded(WPARAM, LPARAM) { HookEvent(ME_OPT_INITIALISE,SkinOptionsInit); return 0; } int LoadSkinSounds(void) { bModuleInitialized = TRUE; soundList=NULL; soundCount=0; CreateServiceFunction(MS_SKIN_ADDNEWSOUND,ServiceSkinAddNewSound); CreateServiceFunction(MS_SKIN_PLAYSOUND,ServiceSkinPlaySound); HookEvent(ME_SYSTEM_MODULESLOADED,SkinSystemModulesLoaded); hPlayEvent=CreateHookableEvent(ME_SKIN_PLAYINGSOUND); SetHookDefaultForHookableEvent(hPlayEvent, SkinPlaySoundDefault); return 0; } void UnloadSkinSounds(void) { int i; if ( !bModuleInitialized ) return; for(i=0;i