From 30ab6ceb71842f003f649b3d62b89af010cf40d1 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 20 Jun 2012 17:00:14 +0000 Subject: - direct call of MS_SKIN_ADDNEWSOUND replaced with Skin_AddSound() call; - obsolete structure SKINSOUNDDESC removed - dynamically translated hot keys; - checked correct LPGEN'ing of the sounds creation; - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@500 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/core/miranda.h | 35 ++-- src/modules/langpack/langpack.cpp | 1 + src/modules/options/options.cpp | 2 +- src/modules/skin/hotkeys.cpp | 135 ++++++------ src/modules/skin/sounds.cpp | 377 ++++++++++++++++------------------ src/modules/srauth/auth.cpp | 4 +- src/modules/srfile/file.cpp | 8 +- src/modules/srurl/url.cpp | 2 +- src/modules/useronline/useronline.cpp | 2 +- 9 files changed, 281 insertions(+), 285 deletions(-) (limited to 'src') diff --git a/src/core/miranda.h b/src/core/miranda.h index 8f747ee86b..edd32bfb25 100644 --- a/src/core/miranda.h +++ b/src/core/miranda.h @@ -111,11 +111,11 @@ extern LPFN_FREEADDRINFO MyFreeaddrinfo; extern LPFN_WSASTRINGTOADDRESSA MyWSAStringToAddress; extern LPFN_WSAADDRESSTOSTRINGA MyWSAAddressToString; -/**** file.c ***************************************************************************/ +/**** file.cpp *************************************************************************/ void PushFileEvent(HANDLE hContact, HANDLE hdbe, LPARAM lParam); -/**** memory.c *************************************************************************/ +/**** memory.cpp ***********************************************************************/ #ifdef _STATIC void* mir_alloc(size_t); @@ -137,13 +137,13 @@ char* mir_u2a_cp(const wchar_t* src, int codepage); char* mir_u2a(const wchar_t* src); #endif -/**** miranda.c ************************************************************************/ +/**** miranda.cpp **********************************************************************/ extern HINSTANCE hMirandaInst; extern HANDLE hOkToExitEvent, hModulesLoadedEvent; extern pfnExceptionFilter pMirandaExceptFilter; -/**** modules.c ************************************************************************/ +/**** modules.cpp **********************************************************************/ int CallPluginEventHook(HINSTANCE hInst, HANDLE hEvent, WPARAM wParam, LPARAM lParam); void KillModuleEventHooks(HINSTANCE); @@ -153,7 +153,7 @@ void KillObjectEventHooks(void* pObject); void KillObjectServices(void* pObject); void KillObjectThreads(void* pObject); -/**** utf.c ****************************************************************************/ +/**** utf.cpp **************************************************************************/ char* Utf8Decode(char* str, wchar_t** ucs2); char* Utf8DecodeCP(char* str, int codepage, wchar_t** ucs2); @@ -178,7 +178,7 @@ int Ucs2toUtf8Len(const wchar_t *src); #define Utf8DecodeT Utf8DecodeUcs2 #define Utf8EncodeT Utf8EncodeUcs2 -/**** langpack.c ***********************************************************************/ +/**** langpack.cpp *********************************************************************/ int LangPackGetDefaultCodePage(); int LangPackGetDefaultLocale(); @@ -204,19 +204,26 @@ __inline unsigned int hashstr(const wchar_t * key) } #pragma optimize("", on) -/**** path.c ***************************************************************************/ +/**** options.cpp **********************************************************************/ + +HTREEITEM FindNamedTreeItemAtRoot(HWND hwndTree, const TCHAR* name); + +/**** path.cpp *************************************************************************/ -int pathToAbsolute(const char *pSrc, char *pOut, char* base); void CreatePathToFile(char* wszFilePath); -int CreateDirectoryTree(const char *szDir); void CreatePathToFileW(WCHAR* wszFilePath); + +int CreateDirectoryTree(const char *szDir); int CreateDirectoryTreeW(const WCHAR *szDir); + +int pathToAbsolute(const char *pSrc, char *pOut, char* base); int pathToAbsoluteW(const TCHAR *pSrc, TCHAR *pOut, TCHAR* base); + #define pathToAbsoluteT pathToAbsoluteW #define CreatePathToFileT CreatePathToFileW #define CreateDirectoryTreeT CreateDirectoryTreeW -/**** skin2icons.c *********************************************************************/ +/**** skin2icons.cpp *******************************************************************/ HANDLE IcoLib_AddNewIcon(SKINICONDESC* sid); HICON IcoLib_GetIcon(const char* pszIconName, bool big); @@ -224,7 +231,7 @@ HICON IcoLib_GetIconByHandle(HANDLE hItem, bool big); HANDLE IcoLib_IsManaged(HICON hIcon); int IcoLib_ReleaseIcon(HICON hIcon, char* szIconName, bool big); -/**** skinicons.c **********************************************************************/ +/**** skinicons.cpp ********************************************************************/ HICON LoadSkinProtoIcon(const char* szProto, int status, bool big = false); HICON LoadSkinIcon(int idx, bool big = false); @@ -248,7 +255,7 @@ void Window_FreeIcon_IcoLib(HWND hWnd); #define IconLib_ReleaseIcon(hIcon, szName) IcoLib_ReleaseIcon(hIcon, szName, false); #define Safe_DestroyIcon(hIcon) if (hIcon) DestroyIcon(hIcon) -/**** clistmenus.c **********************************************************************/ +/**** clistmenus.cpp ********************************************************************/ extern HANDLE hMainMenuObject, hContactMenuObject, hStatusMenuObject; extern HANDLE hPreBuildMainMenuEvent, hPreBuildContactMenuEvent; @@ -259,7 +266,7 @@ extern const int skinIconStatusFlags[ MAX_STATUS_COUNT ]; int TryProcessDoubleClick(HANDLE hContact); -/**** protocols.c ***********************************************************************/ +/**** protocols.cpp *********************************************************************/ #define OFFSET_PROTOPOS 200 #define OFFSET_VISIBLE 400 @@ -295,7 +302,7 @@ __inline static INT_PTR CallProtoService(const char* szModule, const char* szSer return CallProtoServiceInt(NULL, szModule, szService, wParam, lParam); } -/**** utils.c **************************************************************************/ +/**** utils.cpp ************************************************************************/ char* __fastcall rtrim(char* str); TCHAR* __fastcall rtrim(TCHAR* str); diff --git a/src/modules/langpack/langpack.cpp b/src/modules/langpack/langpack.cpp index 3d20a4b85b..efa7e5da9b 100644 --- a/src/modules/langpack/langpack.cpp +++ b/src/modules/langpack/langpack.cpp @@ -398,6 +398,7 @@ static int LoadLangPack(const TCHAR *szLangPack) LoadLangPackFile(fp, line, fileCp); fclose(fp); + pCurrentMuuid = NULL; qsort(langPack.entry, langPack.entryCount, sizeof(LangPackEntry), (int(*)(const void*, const void*))SortLangPackHashesProc); return 0; diff --git a/src/modules/options/options.cpp b/src/modules/options/options.cpp index b603f93f25..aa6180a972 100644 --- a/src/modules/options/options.cpp +++ b/src/modules/options/options.cpp @@ -101,7 +101,7 @@ struct OptionsDlgData HANDLE hPluginLoad, hPluginUnload; }; -static HTREEITEM FindNamedTreeItemAtRoot(HWND hwndTree, const TCHAR* name) +HTREEITEM FindNamedTreeItemAtRoot(HWND hwndTree, const TCHAR* name) { TVITEM tvi; TCHAR str[128]; diff --git a/src/modules/skin/hotkeys.cpp b/src/modules/skin/hotkeys.cpp index d535ad3769..6408bcda7d 100644 --- a/src/modules/skin/hotkeys.cpp +++ b/src/modules/skin/hotkeys.cpp @@ -568,6 +568,20 @@ static void sttOptionsDeleteHotkey(HWND hwndList, int idx, THotkeyItem *item) item->rootHotkey->OptChanged = TRUE; } +static int sttAlphaSort(const THotkeyItem *p1, const THotkeyItem *p2) +{ + int res; + if (res = lstrcmp(p1->getSection(), p2->getSection())) + return res; + if (res = lstrcmp(p1->getDescr(), p2->getDescr())) + return res; + if (!p1->rootHotkey && p2->rootHotkey) + return -1; + if (p1->rootHotkey && !p2->rootHotkey) + return 1; + return 0; +} + static int CALLBACK sttOptionsSortList(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { TCHAR title1[256] = {0}, title2[256] = {0}; @@ -593,7 +607,7 @@ static int CALLBACK sttOptionsSortList(LPARAM lParam1, LPARAM lParam2, LPARAM lP return lstrcmp(title1, title2); if ( !item1) { - if (res = lstrcmp(title1, item1->getSection())) + if (res = lstrcmp(title1, item2->getSection())) return res; return -1; } @@ -603,7 +617,7 @@ static int CALLBACK sttOptionsSortList(LPARAM lParam1, LPARAM lParam2, LPARAM lP return res; return 1; } - return sttCompareHotkeys(item1, item2); + return sttAlphaSort(item1, item2); } static void sttOptionsAddHotkey(HWND hwndList, THotkeyItem *item) @@ -684,19 +698,24 @@ static void sttOptionsSaveItem(THotkeyItem *item) DBWriteContactSettingDword(NULL, DBMODULENAME, buf, item->nSubHotkeys); } -static void sttBuildHotkeyList(HWND hwndList, TCHAR *section) +static void sttBuildHotkeyList(HWND hwndList) { int i, nItems=0; ListView_DeleteAllItems(hwndList); - for (i = 0; i < hotkeys.getCount(); i++) { + // create the temporary list with language-dependent sort order + LIST tmpList(hotkeys.getCount(), sttAlphaSort); + for (i = 0; i < hotkeys.getCount(); i++) + tmpList.insert( hotkeys[i] ); + + for (i = 0; i < tmpList.getCount(); i++) { LVITEM lvi = {0}; - THotkeyItem *item = hotkeys[i]; + THotkeyItem *item = tmpList[i]; - if (item->OptDeleted) continue; - if (section && lstrcmp(section, item->ptszSection)) continue; + if (item->OptDeleted) + continue; - if ( !section && ( !i || lstrcmp(item->ptszSection, ((THotkeyItem *)hotkeys[i-1])->ptszSection))) { + if ( !i || lstrcmp(item->ptszSection, tmpList[i-1]->ptszSection)) { lvi.mask = LVIF_TEXT|LVIF_PARAM; lvi.iItem = nItems++; lvi.iSubItem = 0; @@ -713,11 +732,8 @@ static void sttBuildHotkeyList(HWND hwndList, TCHAR *section) lvi.iSubItem = 0; } - lvi.mask = LVIF_PARAM; - if ( !section) { - lvi.mask |= LVIF_INDENT; - lvi.iIndent = 1; - } + lvi.mask = LVIF_PARAM | LVIF_INDENT; + lvi.iIndent = 1; lvi.iItem = nItems++; lvi.lParam = (LPARAM)item; ListView_InsertItem(hwndList, &lvi); @@ -769,66 +785,59 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, switch (msg) { case WM_INITDIALOG: - { - int i; - LVCOLUMN lvc; - RECT rc; - HIMAGELIST hIml; - initialized = FALSE; TranslateDialogDefault(hwndDlg); sttHotkeyEditCreate(GetDlgItem(hwndDlg, IDC_HOTKEY)); - - hIml = ImageList_Create(16, 16, ILC_MASK + (IsWinVerXPPlus() ? ILC_COLOR32 : ILC_COLOR16), 3, 1); - ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_WINDOWS); - ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_MIRANDA); - ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_WINDOW); - ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_ADDCONTACT); - ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_DELETE); - ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_UNDO); - - // This is added to use for drawing operation only - ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_GROUPOPEN); - ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_GROUPSHUT); - - ListView_SetImageList(hwndHotkey, hIml, LVSIL_SMALL); - + { + HIMAGELIST hIml = ImageList_Create(16, 16, ILC_MASK + (IsWinVerXPPlus() ? ILC_COLOR32 : ILC_COLOR16), 3, 1); + ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_WINDOWS); + ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_MIRANDA); + ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_WINDOW); + ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_ADDCONTACT); + ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_DELETE); + ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_UNDO); + ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_GROUPOPEN); + ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_GROUPSHUT); + ListView_SetImageList(hwndHotkey, hIml, LVSIL_SMALL); + } ListView_SetExtendedListViewStyle(hwndHotkey, LVS_EX_CHECKBOXES|LVS_EX_SUBITEMIMAGES|LVS_EX_FULLROWSELECT|LVS_EX_DOUBLEBUFFER|LVS_EX_INFOTIP); + { + RECT rc; + GetClientRect(hwndHotkey, &rc); + colWidth = rc.right - GetSystemMetrics(SM_CXHTHUMB) - 3*GetSystemMetrics(SM_CXSMICON) - 5; + + LVCOLUMN lvc; + lvc.mask = LVCF_WIDTH; + lvc.cx = colWidth * 2 / 3; + ListView_InsertColumn(hwndHotkey, COL_NAME, &lvc); + lvc.cx = GetSystemMetrics(SM_CXSMICON); + ListView_InsertColumn(hwndHotkey, COL_TYPE, &lvc); + lvc.cx = colWidth / 3; + ListView_InsertColumn(hwndHotkey, COL_KEY, &lvc); + lvc.cx = GetSystemMetrics(SM_CXSMICON); + ListView_InsertColumn(hwndHotkey, COL_RESET, &lvc); + lvc.cx = GetSystemMetrics(SM_CXSMICON); + ListView_InsertColumn(hwndHotkey, COL_ADDREMOVE, &lvc); + + for (int i = 0; i < hotkeys.getCount(); i++) { + THotkeyItem *item = hotkeys[i]; - GetClientRect(hwndHotkey, &rc); - colWidth = rc.right - GetSystemMetrics(SM_CXHTHUMB) - 3*GetSystemMetrics(SM_CXSMICON) - 5; - - lvc.mask = LVCF_WIDTH; - lvc.cx = colWidth * 2 / 3; - ListView_InsertColumn(hwndHotkey, COL_NAME, &lvc); - lvc.cx = GetSystemMetrics(SM_CXSMICON); - ListView_InsertColumn(hwndHotkey, COL_TYPE, &lvc); - lvc.cx = colWidth / 3; - ListView_InsertColumn(hwndHotkey, COL_KEY, &lvc); - lvc.cx = GetSystemMetrics(SM_CXSMICON); - ListView_InsertColumn(hwndHotkey, COL_RESET, &lvc); - lvc.cx = GetSystemMetrics(SM_CXSMICON); - ListView_InsertColumn(hwndHotkey, COL_ADDREMOVE, &lvc); - - for (i = 0; i < hotkeys.getCount(); i++) { - THotkeyItem *item = hotkeys[i]; + item->OptChanged = FALSE; + item->OptDeleted = item->OptNew = FALSE; + item->OptEnabled = item->Enabled; + item->OptHotkey = item->Hotkey; + item->OptType = item->type; + } - item->OptChanged = FALSE; - item->OptDeleted = item->OptNew = FALSE; - item->OptEnabled = item->Enabled; - item->OptHotkey = item->Hotkey; - item->OptType = item->type; + currentLanguage = LOWORD(GetKeyboardLayout(0)); + sttBuildHotkeyList(hwndHotkey); } - - currentLanguage = LOWORD(GetKeyboardLayout(0)); - sttBuildHotkeyList(hwndHotkey, NULL); SetTimer(hwndDlg, 1024, 1000, NULL); - initialized = TRUE; - - { /* load group states */ + { + /* load group states */ int count = ListView_GetItemCount(hwndHotkey); TCHAR buf[128]; LVITEM lvi = {0}; @@ -856,9 +865,7 @@ static INT_PTR CALLBACK sttOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, } g_hwndOptions = hwndDlg; - break; - } case WM_DESTROY: { diff --git a/src/modules/skin/sounds.cpp b/src/modules/skin/sounds.cpp index 9dedbdf4d5..f499a39a4d 100644 --- a/src/modules/skin/sounds.cpp +++ b/src/modules/skin/sounds.cpp @@ -22,72 +22,75 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "..\..\core\commonheaders.h" -#define SKINSOUNDDESC_SIZE_V1 (offsetof(SKINSOUNDDESCEX, pszSection)) -#define SKINSOUNDDESC_SIZE_V2 (offsetof(SKINSOUNDDESCEX, dwFlags)) - struct SoundItem { char* name; - TCHAR* section; - TCHAR* description; - char* tempFile; + TCHAR* ptszSection; + TCHAR* ptszDescription; + TCHAR* ptszTempFile; + int hLangpack; + + __inline TCHAR* getSection() const { return LangPackTranslateStringT(hLangpack, ptszSection); } + __inline TCHAR* getDescr() const { return LangPackTranslateStringT(hLangpack, ptszDescription); } + + __inline ~SoundItem() + { + mir_free(name); + mir_free(ptszSection); + mir_free(ptszDescription); + mir_free(ptszTempFile); + } }; +static int CompareSounds(const SoundItem* p1, const SoundItem* p2) +{ + return lstrcmpA(p1->name, p2->name); +} + +static OBJLIST arSounds(10, CompareSounds); + static BOOL bModuleInitialized = FALSE; -static struct SoundItem *soundList = NULL; -static int soundCount; static HANDLE hPlayEvent = NULL; -static INT_PTR ServiceSkinAddNewSound(WPARAM, LPARAM lParam) +static INT_PTR ServiceSkinAddNewSound(WPARAM wParam, LPARAM lParam) { SKINSOUNDDESCEX *ssd = (SKINSOUNDDESCEX*)lParam; - switch(ssd->cbSize) { - case sizeof(SKINSOUNDDESCEX): - case SKINSOUNDDESC_SIZE_V1: - case SKINSOUNDDESC_SIZE_V2: - break; - - default: + if (ssd->cbSize != sizeof(SKINSOUNDDESCEX) || ssd->pszName == NULL || ssd->pszDescription == NULL) 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++]; + SoundItem* item = new SoundItem; // due to OBJLIST item->name = mir_strdup(ssd->pszName); - item->tempFile = NULL; + item->ptszTempFile = NULL; + item->hLangpack = (int)wParam; + arSounds.insert(item); - 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); - } + TCHAR* ptszDefaultFile; + if (ssd->dwFlags & SSDF_UNICODE) { + item->ptszDescription = mir_tstrdup(ssd->ptszDescription); + item->ptszSection = mir_tstrdup((ssd->pszSection != NULL) ? ssd->ptszSection : _T("Other")); + ptszDefaultFile = mir_tstrdup(ssd->ptszDefaultFile); + } + else { + item->ptszDescription = mir_a2t(ssd->pszDescription); + item->ptszSection = mir_a2t((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); - } + if (ptszDefaultFile) { + DBVARIANT dbv; + if (DBGetContactSettingString(NULL, "SkinSounds", item->name, &dbv)) + DBWriteContactSettingTString(NULL, "SkinSounds", item->name, ptszDefaultFile); + else + DBFreeVariant(&dbv); + mir_free(ptszDefaultFile); + } return 0; } static int SkinPlaySoundDefault(WPARAM wParam, LPARAM lParam) { - char * pszFile = (char *) lParam; + char* pszFile = (char *) lParam; if (pszFile && (DBGetContactSettingByte(NULL, "Skin", "UseSound", 0) || (int)wParam == 1)) PlaySoundA(pszFile, NULL, SND_ASYNC | SND_FILENAME | SND_NOWAIT); @@ -97,57 +100,35 @@ static int SkinPlaySoundDefault(WPARAM wParam, LPARAM lParam) 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); - } } + if (((LPNMHDR)lParam)->code == PSN_APPLY) { + DBWriteContactSettingByte(NULL, "Skin", "UseSound", (BYTE) IsDlgButtonChecked(hwndDlg, IDC_ENABLESOUNDS)); + + for (int i=0; i < arSounds.getCount(); i++) + if (arSounds[i].ptszTempFile) + DBWriteContactSettingTString(NULL, "SkinSounds", arSounds[i].name, arSounds[i].ptszTempFile); + + 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 = arSounds[tvic.lParam].name; + CallService(MS_DB_CONTACT_DELETESETTING, (WPARAM)(HANDLE)NULL, (LPARAM)&cgs); + } + else DBWriteContactSettingByte(NULL, "SkinSoundsOff", arSounds[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: @@ -363,22 +353,22 @@ INT_PTR CALLBACK DlgProcSoundOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM NMTREEVIEW *pnmtv = (NMTREEVIEW*)lParam; TVITEM tvi = pnmtv->itemNew; - if (tvi.lParam == -1) { + 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); + mir_sntprintf(buf, SIZEOF(buf), _T("%s: %s"), arSounds[tvi.lParam].ptszSection, arSounds[tvi.lParam].ptszDescription); 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); + if (arSounds[tvi.lParam].ptszTempFile) + SetDlgItemText(hwndDlg, IDC_LOCATION, arSounds[tvi.lParam].ptszTempFile); + else { + DBVARIANT dbv; + if ( !DBGetContactSettingTString(NULL, "SkinSounds", arSounds[tvi.lParam].name, &dbv)) { + SetDlgItemText(hwndDlg, IDC_LOCATION, dbv.ptszVal); + DBFreeVariant(&dbv); + } + else SetDlgItemText(hwndDlg, IDC_LOCATION, TranslateT("")); } - else SetDlgItemText(hwndDlg, IDC_LOCATION, TranslateT("")); SendMessage(hwndDlg, DM_SHOWPANE, 0, 0); } } @@ -398,15 +388,18 @@ INT_PTR CALLBACK DlgProcSoundOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM 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); + if (hti.flags & (TVHT_ONITEM | TVHT_ONITEMSTATEICON)) + if (TreeView_GetParent(hwndTree, hti.hItem) != NULL) + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; } } break; } break; + + case WM_DESTROY: + ImageList_Destroy(TreeView_GetImageList(hwndTree, TVSIL_STATE)); + break; } return FALSE; } @@ -438,27 +431,15 @@ int LoadSkinSounds(void) { bModuleInitialized = TRUE; - soundList=NULL; - soundCount=0; - CreateServiceFunction(MS_SKIN_ADDNEWSOUND, ServiceSkinAddNewSound); + CreateServiceFunction("Skin/Sounds/AddNew", ServiceSkinAddNewSound); CreateServiceFunction(MS_SKIN_PLAYSOUND, ServiceSkinPlaySound); HookEvent(ME_SYSTEM_MODULESLOADED, SkinSystemModulesLoaded); - hPlayEvent=CreateHookableEvent(ME_SKIN_PLAYINGSOUND); + hPlayEvent = CreateHookableEvent(ME_SKIN_PLAYINGSOUND); SetHookDefaultForHookableEvent(hPlayEvent, SkinPlaySoundDefault); return 0; } void UnloadSkinSounds(void) { - int i; - - if ( !bModuleInitialized) return; - - for (i=0;i