From c53dda67ae4a614b836412af5eb763d56dc1f763 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 29 Aug 2017 18:35:41 +0300 Subject: AvatarHistory: code cleaning + handle leak fix --- plugins/AvatarHistory/src/AvatarDlg.cpp | 179 ++++++++++++---------------- plugins/AvatarHistory/src/AvatarHistory.cpp | 66 +++++----- plugins/AvatarHistory/src/icolib.cpp | 10 +- plugins/AvatarHistory/src/options.cpp | 48 ++++---- plugins/AvatarHistory/src/popup.cpp | 86 ++++++------- plugins/AvatarHistory/src/utils.cpp | 97 +++++++-------- plugins/AvatarHistory/src/version.h | 2 +- 7 files changed, 219 insertions(+), 269 deletions(-) (limited to 'plugins') diff --git a/plugins/AvatarHistory/src/AvatarDlg.cpp b/plugins/AvatarHistory/src/AvatarDlg.cpp index 5aaaee8e59..42dbfa80ef 100644 --- a/plugins/AvatarHistory/src/AvatarDlg.cpp +++ b/plugins/AvatarHistory/src/AvatarDlg.cpp @@ -20,10 +20,9 @@ Avatar History Plugin #include "stdafx.h" -HGENMENU hMenu = NULL; -void __cdecl AvatarDialogThread(void *param); -static INT_PTR CALLBACK AvatarDlgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam); -int ShowSaveDialog(HWND hwnd, wchar_t* fn,MCONTACT hContact = NULL); +HGENMENU hMenu = NULL; +static INT_PTR CALLBACK AvatarDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); +int ShowSaveDialog(HWND hwnd, wchar_t* fn, MCONTACT hContact = NULL); bool ProtocolEnabled(const char *proto); int FillAvatarListFromDB(HWND list, MCONTACT hContact); @@ -65,11 +64,16 @@ public: wchar_t *filelink; }; +static void __cdecl AvatarDialogThread(void *param) +{ + struct AvatarDialogData* data = (struct AvatarDialogData*)param; + DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_AVATARDLG), data->parent, AvatarDlgProc, (LPARAM)param); +} + int OpenAvatarDialog(MCONTACT hContact, char* fn) { HWND hAvatarWindow = WindowList_Find(hAvatarWindowsList, hContact); - if (hAvatarWindow) - { + if (hAvatarWindow) { SetForegroundWindow(hAvatarWindow); SetFocus(hAvatarWindow); return 0; @@ -79,48 +83,36 @@ int OpenAvatarDialog(MCONTACT hContact, char* fn) memset(avdlg, 0, sizeof(struct AvatarDialogData)); avdlg->hContact = hContact; if (fn == NULL) - { avdlg->fn[0] = '\0'; - } else - { MultiByteToWideChar(CP_ACP, 0, fn, -1, avdlg->fn, _countof(avdlg->fn)); - } - CloseHandle(mir_forkthread(AvatarDialogThread, (void*)avdlg)); + mir_forkthread(AvatarDialogThread, (void*)avdlg); return 0; } -void __cdecl AvatarDialogThread(void *param) -{ - struct AvatarDialogData* data = (struct AvatarDialogData*)param; - DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_AVATARDLG), data->parent, AvatarDlgProc, (LPARAM)param); -} - void EnableDisableControls(HWND hwnd) { HWND list = GetDlgItem(hwnd, IDC_AVATARLIST); - + int cursel = SendMessage(list, LB_GETCURSEL, 0, 0); int count = SendMessage(list, LB_GETCOUNT, 0, 0); - if (cursel == LB_ERR) - { + if (cursel == LB_ERR) { EnableWindow(GetDlgItem(hwnd, IDC_BACK), count > 0); EnableWindow(GetDlgItem(hwnd, IDC_NEXT), count > 0); } - else - { + else { EnableWindow(GetDlgItem(hwnd, IDC_BACK), cursel > 0); - EnableWindow(GetDlgItem(hwnd, IDC_NEXT), cursel < count-1); + EnableWindow(GetDlgItem(hwnd, IDC_NEXT), cursel < count - 1); } } -static INT_PTR CALLBACK AvatarDlgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) +static INT_PTR CALLBACK AvatarDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { HWND hwndList = GetDlgItem(hwnd, IDC_AVATARLIST); - switch(uMsg) { + switch (uMsg) { case WM_INITDIALOG: { AvatarDialogData *data = (struct AvatarDialogData*) lParam; @@ -146,8 +138,8 @@ static INT_PTR CALLBACK AvatarDlgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM l CheckDlgButton(hwnd, IDC_POPUPUSER, (UINT)db_get_b(data->hContact, MODULE_NAME, "AvatarPopups", BST_INDETERMINATE)); CheckDlgButton(hwnd, IDC_HISTORYUSER, (UINT)db_get_b(data->hContact, MODULE_NAME, "LogToHistory", BST_INDETERMINATE)); ShowWindow(GetDlgItem(hwnd, IDC_OPENFOLDER), opts.log_per_contact_folders ? SW_SHOW : SW_HIDE); - Utils_RestoreWindowPositionNoSize(hwnd,NULL,MODULE_NAME,"AvatarHistoryDialog"); - WindowList_Add(hAvatarWindowsList,hwnd,data->hContact); + Utils_RestoreWindowPositionNoSize(hwnd, NULL, MODULE_NAME, "AvatarHistoryDialog"); + WindowList_Add(hAvatarWindowsList, hwnd, data->hContact); TranslateDialogDefault(hwnd); EnableDisableControls(hwnd); free(data); @@ -161,13 +153,13 @@ static INT_PTR CALLBACK AvatarDlgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM l return TRUE; case WM_DESTROY: - Utils_SaveWindowPosition(hwnd,NULL,MODULE_NAME,"AvatarHistoryDialog"); - WindowList_Remove(hAvatarWindowsList,hwnd); + Utils_SaveWindowPosition(hwnd, NULL, MODULE_NAME, "AvatarHistoryDialog"); + WindowList_Remove(hAvatarWindowsList, hwnd); DestroyIcon((HICON)SendMessage(hwnd, WM_SETICON, ICON_BIG, 0)); DestroyIcon((HICON)SendMessage(hwnd, WM_SETICON, ICON_SMALL, 0)); { int count = SendMessage(hwndList, LB_GETCOUNT, 0, 0); - for(int i = 0; i < count; i++) + for (int i = 0; i < count; i++) delete (ListEntry*)SendMessage(hwndList, LB_GETITEMDATA, i, 0); } break; @@ -193,7 +185,7 @@ static INT_PTR CALLBACK AvatarDlgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM l SendMessage(hwndList, LB_SETCURSEL, pos, 0); EnableDisableControls(hwnd); } - else if ((HANDLE) wParam == pic) { + else if ((HANDLE)wParam == pic) { pos = SendMessage(hwndList, LB_GETCURSEL, 0, 0); if (pos == LB_ERR) break; @@ -210,14 +202,14 @@ static INT_PTR CALLBACK AvatarDlgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM l } POINT p; - p.x = LOWORD(lParam); - p.y = HIWORD(lParam); - int ret = TrackPopupMenu(submenu, TPM_TOPALIGN|TPM_LEFTALIGN|TPM_RIGHTBUTTON|TPM_RETURNCMD, p.x, p.y, 0, hwndList, NULL); + p.x = LOWORD(lParam); + p.y = HIWORD(lParam); + int ret = TrackPopupMenu(submenu, TPM_TOPALIGN | TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, p.x, p.y, 0, hwndList, NULL); DestroyMenu(menu); - ListEntry *le = (ListEntry*) SendMessage(hwndList, LB_GETITEMDATA, pos, 0); - MCONTACT hContact = (MCONTACT) GetWindowLongPtr(hwnd, GWLP_USERDATA); - switch(ret) { + ListEntry *le = (ListEntry*)SendMessage(hwndList, LB_GETITEMDATA, pos, 0); + MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA); + switch (ret) { case ID_AVATARLISTPOPUP_SAVEAS: ShowSaveDialog(hwnd, le->filename, hContact); break; @@ -227,11 +219,11 @@ static INT_PTR CALLBACK AvatarDlgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM l BOOL blDelete; if (le->hDbEvent) - blDelete = MessageBox(hwnd, TranslateT("Are you sure you wish to delete this history entry?\nOnly the entry in history will be deleted, bitmap file will be kept!"), - TranslateT("Delete avatar log?"), MB_YESNO|MB_ICONWARNING|MB_DEFBUTTON2|MB_SETFOREGROUND|MB_TOPMOST) == IDYES; + blDelete = MessageBox(hwnd, TranslateT("Are you sure you wish to delete this history entry?\nOnly the entry in history will be deleted, bitmap file will be kept!"), + TranslateT("Delete avatar log?"), MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2 | MB_SETFOREGROUND | MB_TOPMOST) == IDYES; else - blDelete = MessageBox(hwnd, TranslateT("Are you sure you wish to delete this avatar shortcut?\nOnly shortcut will be deleted, bitmap file will be kept!"), - TranslateT("Delete avatar log?"), MB_YESNO|MB_ICONWARNING|MB_DEFBUTTON2|MB_SETFOREGROUND|MB_TOPMOST) == IDYES; + blDelete = MessageBox(hwnd, TranslateT("Are you sure you wish to delete this avatar shortcut?\nOnly shortcut will be deleted, bitmap file will be kept!"), + TranslateT("Delete avatar log?"), MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2 | MB_SETFOREGROUND | MB_TOPMOST) == IDYES; if (blDelete) { if (le->hDbEvent) @@ -246,7 +238,7 @@ static INT_PTR CALLBACK AvatarDlgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM l int count = SendMessage(hwndList, LB_GETCOUNT, 0, 0); if (count > 0) { if (pos >= count) - pos = count -1; + pos = count - 1; SendMessage(hwndList, LB_SETCURSEL, pos, 0); } @@ -260,11 +252,11 @@ static INT_PTR CALLBACK AvatarDlgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM l BOOL blDelete; if (le->hDbEvent) - blDelete = MessageBox(hwnd, TranslateT("Are you sure you wish to delete this archived avatar?\nThis will delete the history entry and the bitmap file.\nWARNING: This can affect more than one entry in history!"), - TranslateT("Delete avatar?"), MB_YESNO|MB_ICONWARNING|MB_DEFBUTTON2|MB_SETFOREGROUND|MB_TOPMOST) == IDYES; + blDelete = MessageBox(hwnd, TranslateT("Are you sure you wish to delete this archived avatar?\nThis will delete the history entry and the bitmap file.\nWARNING: This can affect more than one entry in history!"), + TranslateT("Delete avatar?"), MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2 | MB_SETFOREGROUND | MB_TOPMOST) == IDYES; else - blDelete = MessageBox(hwnd, TranslateT("Are you sure you wish to delete this archived avatar?\nThis will delete the shortcut and the bitmap file.\nWARNING: This can affect more than one shortcut!"), - TranslateT("Delete avatar?"), MB_YESNO|MB_ICONWARNING|MB_DEFBUTTON2|MB_SETFOREGROUND|MB_TOPMOST) == IDYES; + blDelete = MessageBox(hwnd, TranslateT("Are you sure you wish to delete this archived avatar?\nThis will delete the shortcut and the bitmap file.\nWARNING: This can affect more than one shortcut!"), + TranslateT("Delete avatar?"), MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2 | MB_SETFOREGROUND | MB_TOPMOST) == IDYES; if (blDelete) { DeleteFile(le->filename); @@ -281,7 +273,7 @@ static INT_PTR CALLBACK AvatarDlgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM l int count = SendMessage(hwndList, LB_GETCOUNT, 0, 0); if (count > 0) { if (pos >= count) - pos = count -1; + pos = count - 1; SendMessage(hwndList, LB_SETCURSEL, pos, 0); } @@ -293,13 +285,13 @@ static INT_PTR CALLBACK AvatarDlgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM l break; case WM_COMMAND: - switch(LOWORD(wParam)) { + switch (LOWORD(wParam)) { case IDOK: if (HIWORD(wParam) == BN_CLICKED) { - MCONTACT hContact = (MCONTACT) GetWindowLongPtr(hwnd, GWLP_USERDATA); - db_set_b(hContact, MODULE_NAME, "AvatarPopups", (BYTE) IsDlgButtonChecked(hwnd, IDC_POPUPUSER)); - db_set_b(hContact, MODULE_NAME, "LogToDisk", (BYTE) IsDlgButtonChecked(hwnd, IDC_LOGUSER)); - db_set_b(hContact, MODULE_NAME, "LogToHistory", (BYTE) IsDlgButtonChecked(hwnd, IDC_HISTORYUSER)); + MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA); + db_set_b(hContact, MODULE_NAME, "AvatarPopups", (BYTE)IsDlgButtonChecked(hwnd, IDC_POPUPUSER)); + db_set_b(hContact, MODULE_NAME, "LogToDisk", (BYTE)IsDlgButtonChecked(hwnd, IDC_LOGUSER)); + db_set_b(hContact, MODULE_NAME, "LogToHistory", (BYTE)IsDlgButtonChecked(hwnd, IDC_HISTORYUSER)); CleanupAvatarPic(hwnd); EndDialog(hwnd, 0); @@ -327,7 +319,7 @@ static INT_PTR CALLBACK AvatarDlgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM l case IDC_NEXT: if (HIWORD(wParam) == BN_CLICKED) { - SendMessage(hwndList, LB_SETCURSEL, SendMessage(hwndList, LB_GETCURSEL, 0, 0) +1, 0); + SendMessage(hwndList, LB_SETCURSEL, SendMessage(hwndList, LB_GETCURSEL, 0, 0) + 1, 0); UpdateAvatarPic(hwnd); EnableDisableControls(hwnd); return TRUE; @@ -338,9 +330,9 @@ static INT_PTR CALLBACK AvatarDlgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM l if (HIWORD(wParam) == BN_CLICKED) { int cursel = SendMessage(hwndList, LB_GETCURSEL, 0, 0); if (cursel == LB_ERR) - SendMessage(hwndList, LB_SETCURSEL, SendMessage(hwndList, LB_GETCOUNT, 0, 0) -1, 0); + SendMessage(hwndList, LB_SETCURSEL, SendMessage(hwndList, LB_GETCOUNT, 0, 0) - 1, 0); else - SendMessage(hwndList, LB_SETCURSEL, cursel -1, 0); + SendMessage(hwndList, LB_SETCURSEL, cursel - 1, 0); UpdateAvatarPic(hwnd); EnableDisableControls(hwnd); return TRUE; @@ -352,7 +344,7 @@ static INT_PTR CALLBACK AvatarDlgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM l } -int AddFileToList(wchar_t *path,wchar_t *lnk,wchar_t *filename, HWND list) +int AddFileToList(wchar_t *path, wchar_t *lnk, wchar_t *filename, HWND list) { // Add to list ListEntry *le = new ListEntry(); @@ -380,15 +372,12 @@ int FillAvatarListFromFiles(HWND list, MCONTACT hContact) if (hFind == INVALID_HANDLE_VALUE) return 0; - do - { - if (finddata.cFileName[0] != '.') - { + do { + if (finddata.cFileName[0] != '.') { mir_snwprintf(path, L"%s\\%s", dir, finddata.cFileName); - max_pos = AddFileToList(path,finddata.cFileName,finddata.cFileName,list); + max_pos = AddFileToList(path, finddata.cFileName, finddata.cFileName, list); } - } - while(FindNextFile(hFind, &finddata)); + } while (FindNextFile(hFind, &finddata)); FindClose(hFind); SendMessage(list, LB_SETCURSEL, max_pos, 0); // Set to first item return 0; @@ -407,17 +396,14 @@ int FillAvatarListFromFolder(HWND list, MCONTACT hContact) if (hFind == INVALID_HANDLE_VALUE) return 0; - do - { - if (finddata.cFileName[0] != '.') - { + do { + if (finddata.cFileName[0] != '.') { wchar_t lnk[MAX_PATH]; mir_snwprintf(lnk, L"%s\\%s", dir, finddata.cFileName); if (ResolveShortcut(lnk, path)) - max_pos = AddFileToList(path,lnk,finddata.cFileName,list); + max_pos = AddFileToList(path, lnk, finddata.cFileName, list); } - } - while(FindNextFile(hFind, &finddata)); + } while (FindNextFile(hFind, &finddata)); FindClose(hFind); SendMessage(list, LB_SETCURSEL, max_pos, 0); // Set to first item return 0; @@ -447,7 +433,7 @@ int FillAvatarListFromDB(HWND list, MCONTACT hContact) ListEntry *le = new ListEntry(); le->hDbEvent = hDbEvent; le->filename = mir_wstrdup(path); - max_pos = SendMessage(list,LB_ADDSTRING, 0, (LPARAM)date); + max_pos = SendMessage(list, LB_ADDSTRING, 0, (LPARAM)date); SendMessage(list, LB_SETITEMDATA, max_pos, (LPARAM)le); } @@ -463,22 +449,20 @@ bool UpdateAvatarPic(HWND hwnd) HWND list = GetDlgItem(hwnd, IDC_AVATARLIST); int cursel = SendMessage(list, LB_GETCURSEL, 0, 0); - if (cursel < 0) - { - SetDlgItemText(hwnd,IDC_AVATARPATH,TranslateT("Avatar history is empty!")); + if (cursel < 0) { + SetDlgItemText(hwnd, IDC_AVATARPATH, TranslateT("Avatar history is empty!")); return false; } - - ListEntry *le = (ListEntry*) SendMessage(list, LB_GETITEMDATA, cursel, 0); - if (!le || !le->filename) - { - SetDlgItemText(hwnd,IDC_AVATARPATH,TranslateT("Avatar path is null.")); + ListEntry *le = (ListEntry*)SendMessage(list, LB_GETITEMDATA, cursel, 0); + + if (!le || !le->filename) { + SetDlgItemText(hwnd, IDC_AVATARPATH, TranslateT("Avatar path is null.")); return 0; } - SetDlgItemText(hwnd,IDC_AVATARPATH,le->filename); + SetDlgItemText(hwnd, IDC_AVATARPATH, le->filename); - HBITMAP avpic = (HBITMAP) CallService(MS_IMG_LOAD, (WPARAM)le->filename, IMGL_WCHAR); + HBITMAP avpic = (HBITMAP)CallService(MS_IMG_LOAD, (WPARAM)le->filename, IMGL_WCHAR); bool found_image = (avpic != NULL); @@ -501,7 +485,7 @@ int CleanupAvatarPic(HWND hwnd) return 0; } -int PreBuildContactMenu(WPARAM wParam, LPARAM) +int PreBuildContactMenu(WPARAM wParam, LPARAM) { char *proto = GetContactProto(wParam); Menu_ShowItem(hMenu, 0 != ProtocolEnabled(proto)); @@ -513,7 +497,7 @@ void InitMenuItem() CreateServiceFunction(MS_AVATARHISTORY_SHOWDIALOG, ShowDialogSvc); CMenuItem mi; - SET_UID(mi,0x2fb5c7eb, 0xa606, 0x4145, 0x9e, 0x86, 0x73, 0x88, 0x73, 0x1d, 0xe7, 0x5c); + SET_UID(mi, 0x2fb5c7eb, 0xa606, 0x4145, 0x9e, 0x86, 0x73, 0x88, 0x73, 0x1d, 0xe7, 0x5c); mi.name.w = LPGENW("View avatar history"); mi.flags = CMIF_UNICODE; mi.position = 1000090010; @@ -541,40 +525,33 @@ int ShowSaveDialog(HWND hwnd, wchar_t* fn, MCONTACT hContact) ofn.hInstance = hInst; ofn.lpstrFilter = filter; - + ofn.nFilterIndex = 1; wcsncpy_s(file, (wcsrchr(fn, '\\') + 1), _TRUNCATE); ofn.lpstrFile = file; wchar_t *displayName = pcli->pfnGetContactDisplayName(hContact, 0); wchar_t title[MAX_PATH]; - if (displayName) - { + if (displayName) { mir_snwprintf(title, TranslateT("Save avatar for %s"), displayName); ofn.lpstrTitle = title; } - else - { - ofn.lpstrTitle = TranslateT("Save avatar"); - } + else ofn.lpstrTitle = TranslateT("Save avatar"); + ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_PATHMUSTEXIST | OFN_DONTADDTORECENT; - ofn.lpstrDefExt = wcsrchr(fn, '.')+1; + ofn.lpstrDefExt = wcsrchr(fn, '.') + 1; - DBVARIANT dbvInitDir = {0}; - if (!db_get_ws(hContact,MODULE_NAME,"SavedAvatarFolder",&dbvInitDir)) - { + DBVARIANT dbvInitDir = { 0 }; + if (!db_get_ws(hContact, MODULE_NAME, "SavedAvatarFolder", &dbvInitDir)) { ofn.lpstrInitialDir = dbvInitDir.ptszVal; db_free(&dbvInitDir); } - else - { - ofn.lpstrInitialDir = L"."; - } - if (GetSaveFileName(&ofn)) - { + else ofn.lpstrInitialDir = L"."; + + if (GetSaveFileName(&ofn)) { CopyFile(fn, file, FALSE); - db_set_ws(hContact,MODULE_NAME,"SavedAvatarFolder",file); + db_set_ws(hContact, MODULE_NAME, "SavedAvatarFolder", file); } return 0; } diff --git a/plugins/AvatarHistory/src/AvatarHistory.cpp b/plugins/AvatarHistory/src/AvatarHistory.cpp index f7cb11eeb5..061060f306 100644 --- a/plugins/AvatarHistory/src/AvatarHistory.cpp +++ b/plugins/AvatarHistory/src/AvatarHistory.cpp @@ -35,7 +35,7 @@ wchar_t basedir[MAX_PATH]; int hLangpack = 0; MWindowList hAvatarWindowsList = NULL; -int OptInit(WPARAM wParam,LPARAM lParam); +int OptInit(WPARAM wParam, LPARAM lParam); wchar_t* GetHistoryFolder(wchar_t *fn); wchar_t* GetProtocolFolder(wchar_t *fn, char *proto); @@ -84,8 +84,8 @@ static INT_PTR GetCachedAvatar(WPARAM wParam, LPARAM lParam) static INT_PTR IsEnabled(WPARAM wParam, LPARAM) { - MCONTACT hContact = (MCONTACT) wParam; - return ContactEnabled(hContact, "LogToDisk", AVH_DEF_LOGTODISK) + MCONTACT hContact = (MCONTACT)wParam; + return ContactEnabled(hContact, "LogToDisk", AVH_DEF_LOGTODISK) || ContactEnabled(hContact, "AvatarPopups", AVH_DEF_AVPOPUPS) || ContactEnabled(hContact, "LogToHistory", AVH_DEF_LOGTOHISTORY); } @@ -115,8 +115,8 @@ static int AvatarChanged(WPARAM hContact, LPARAM lParam) if (mir_strcmp(META_PROTO, proto) == 0) return 0; - DBVARIANT dbvOldHash = {0}; - bool ret = (db_get_ws(hContact,MODULE_NAME,"AvatarHash",&dbvOldHash) == 0); + DBVARIANT dbvOldHash = { 0 }; + bool ret = (db_get_ws(hContact, MODULE_NAME, "AvatarHash", &dbvOldHash) == 0); CONTACTAVATARCHANGEDNOTIFICATION* avatar = (CONTACTAVATARCHANGEDNOTIFICATION*)lParam; if (avatar == NULL) { @@ -187,8 +187,8 @@ static int AvatarChanged(WPARAM hContact, LPARAM lParam) else GetProtocolFolder(history_filename, proto); - mir_snwprintf(history_filename, - L"%s\\%s", history_filename, hash); + mir_snwprintf(history_filename, + L"%s\\%s", history_filename, hash); if (CopyImageFile(avatar->filename, history_filename)) ShowPopup(hContact, TranslateT("Avatar history: Unable to save avatar"), history_filename); @@ -217,7 +217,7 @@ static int AvatarChanged(WPARAM hContact, LPARAM lParam) DBEVENTINFO dbei = {}; dbei.szModule = GetContactProto(hContact); dbei.flags = DBEF_READ | DBEF_UTF; - dbei.timestamp = (DWORD) time(NULL); + dbei.timestamp = (DWORD)time(NULL); dbei.eventType = EVENTTYPE_AVATAR_CHANGE; dbei.cbBlob = (DWORD)mir_strlen(blob) + 1; dbei.pBlob = blob; @@ -230,7 +230,7 @@ static int AvatarChanged(WPARAM hContact, LPARAM lParam) static int PreShutdown(WPARAM, LPARAM) { - WindowList_Broadcast(hAvatarWindowsList,WM_CLOSE,0,0); + WindowList_Broadcast(hAvatarWindowsList, WM_CLOSE, 0, 0); return 0; } @@ -238,7 +238,7 @@ static int ModulesLoaded(WPARAM, LPARAM) { mir_snwprintf(basedir, L"%s\\Avatars History", profilePath); - hFolder = FoldersRegisterCustomPathT( LPGEN("Avatars"), LPGEN("Avatar History"), + hFolder = FoldersRegisterCustomPathT(LPGEN("Avatars"), LPGEN("Avatar History"), PROFILE_PATHT L"\\" CURRENT_PROFILET L"\\Avatars History"); InitPopups(); @@ -249,9 +249,9 @@ static int ModulesLoaded(WPARAM, LPARAM) ///////////////////////////////////////////////////////////////////////////////////////// -static INT_PTR CALLBACK FirstRunDlgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM) +static INT_PTR CALLBACK FirstRunDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM) { - switch(uMsg) { + switch (uMsg) { case WM_INITDIALOG: SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)createDefaultOverlayedIcon(TRUE)); SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)createDefaultOverlayedIcon(FALSE)); @@ -261,25 +261,23 @@ static INT_PTR CALLBACK FirstRunDlgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM break; case WM_COMMAND: - switch(LOWORD(wParam)) { + switch (LOWORD(wParam)) { case IDOK: - { - int ret = 0; - - if (IsDlgButtonChecked(hwnd, IDC_MIR_SAME)) - ret = IDC_MIR_SAME; - else if (IsDlgButtonChecked(hwnd, IDC_MIR_PROTO)) - ret = IDC_MIR_PROTO; - else if (IsDlgButtonChecked(hwnd, IDC_MIR_SHORT)) - ret = IDC_MIR_SHORT; - else if (IsDlgButtonChecked(hwnd, IDC_SHORT)) - ret = IDC_SHORT; - else if (IsDlgButtonChecked(hwnd, IDC_DUP)) - ret = IDC_DUP; - - EndDialog(hwnd, ret); - return TRUE; - } + int ret = 0; + + if (IsDlgButtonChecked(hwnd, IDC_MIR_SAME)) + ret = IDC_MIR_SAME; + else if (IsDlgButtonChecked(hwnd, IDC_MIR_PROTO)) + ret = IDC_MIR_PROTO; + else if (IsDlgButtonChecked(hwnd, IDC_MIR_SHORT)) + ret = IDC_MIR_SHORT; + else if (IsDlgButtonChecked(hwnd, IDC_SHORT)) + ret = IDC_SHORT; + else if (IsDlgButtonChecked(hwnd, IDC_DUP)) + ret = IDC_DUP; + + EndDialog(hwnd, ret); + return TRUE; } break; @@ -299,7 +297,7 @@ extern "C" __declspec(dllexport) int Load(void) CoInitialize(NULL); // Is first run? - if ( db_get_b(NULL, MODULE_NAME, "FirstRun", 1)) { + if (db_get_b(NULL, MODULE_NAME, "FirstRun", 1)) { // Show dialog int ret = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_FIRST_RUN), NULL, FirstRunDlgProc, 0); if (ret == 0) @@ -334,7 +332,7 @@ extern "C" __declspec(dllexport) int Load(void) LoadOptions(); - HookEvent(ME_SYSTEM_MODULESLOADED,ModulesLoaded); + HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded); HookEvent(ME_SYSTEM_PRESHUTDOWN, PreShutdown); HookEvent(ME_OPT_INITIALISE, OptInit); HookEvent(ME_SKIN2_ICONSCHANGED, IcoLibIconsChanged); @@ -345,8 +343,8 @@ extern "C" __declspec(dllexport) int Load(void) Profile_GetPathW(MAX_PATH, profilePath); - SkinAddNewSoundExW("avatar_changed",LPGENW("Avatar history"),LPGENW("Contact changed avatar")); - SkinAddNewSoundExW("avatar_removed",LPGENW("Avatar history"),LPGENW("Contact removed avatar")); + SkinAddNewSoundExW("avatar_changed", LPGENW("Avatar history"), LPGENW("Contact changed avatar")); + SkinAddNewSoundExW("avatar_removed", LPGENW("Avatar history"), LPGENW("Contact removed avatar")); hAvatarWindowsList = WindowList_Create(); diff --git a/plugins/AvatarHistory/src/icolib.cpp b/plugins/AvatarHistory/src/icolib.cpp index 36d039d765..28cfbb9f6c 100644 --- a/plugins/AvatarHistory/src/icolib.cpp +++ b/plugins/AvatarHistory/src/icolib.cpp @@ -38,19 +38,19 @@ int IcoLibIconsChanged(WPARAM, LPARAM) void SetupIcoLib() { iconList[0].hIcolib = Skin_GetIconHandle(SKINICON_OTHER_HISTORY); - Icon_Register(hInst, LPGEN("Avatar history"), iconList+1, _countof(iconList)-1); + Icon_Register(hInst, LPGEN("Avatar history"), iconList + 1, _countof(iconList) - 1); IcoLibUpdateMenus(); } static HICON getOverlayedIcon(HICON icon, HICON overlay, BOOL big) { HIMAGELIST il = ImageList_Create( - GetSystemMetrics(big?SM_CXICON:SM_CXSMICON), - GetSystemMetrics(big?SM_CYICON:SM_CYSMICON), - ILC_COLOR32|ILC_MASK, 2, 2); + GetSystemMetrics(big ? SM_CXICON : SM_CXSMICON), + GetSystemMetrics(big ? SM_CYICON : SM_CYSMICON), + ILC_COLOR32 | ILC_MASK, 2, 2); ImageList_AddIcon(il, icon); ImageList_AddIcon(il, overlay); - HIMAGELIST newImage = ImageList_Merge(il,0,il,1,0,0); + HIMAGELIST newImage = ImageList_Merge(il, 0, il, 1, 0, 0); ImageList_Destroy(il); HICON hIcon = ImageList_GetIcon(newImage, 0, 0); ImageList_Destroy(newImage); diff --git a/plugins/AvatarHistory/src/options.cpp b/plugins/AvatarHistory/src/options.cpp index b1190ed857..3d94a21e3c 100644 --- a/plugins/AvatarHistory/src/options.cpp +++ b/plugins/AvatarHistory/src/options.cpp @@ -24,31 +24,31 @@ Options opts; // Prototypes ///////////////////////////////////////////////////////////////////////////////////// -static OptPageControl optionsControls[] = { +static OptPageControl optionsControls[] = { { NULL, CONTROL_PROTOCOL_LIST, IDC_PROTOCOLS, "%sEnabled", TRUE } }; -static OptPageControl popupsControls[] = { +static OptPageControl popupsControls[] = { { NULL, CONTROL_CHECKBOX, IDC_POPUPS, "AvatarPopups", AVH_DEF_AVPOPUPS }, - { &opts.popup_bkg_color, CONTROL_COLOR, IDC_BGCOLOR, "PopupsBgColor", AVH_DEF_POPUPBG }, - { &opts.popup_text_color, CONTROL_COLOR, IDC_TEXTCOLOR, "PopupsTextColor", AVH_DEF_POPUPFG }, - { &opts.popup_use_win_colors, CONTROL_CHECKBOX, IDC_WINCOLORS, "PopupsWinColors", FALSE }, - { &opts.popup_use_default_colors, CONTROL_CHECKBOX, IDC_DEFAULTCOLORS, "PopupsDefaultColors", AVH_DEF_DEFPOPUPS }, - { &opts.popup_delay_type, CONTROL_RADIO, IDC_DELAYFROMPU, "PopupsDelayType", POPUP_DELAY_DEFAULT, POPUP_DELAY_DEFAULT }, - { NULL, CONTROL_RADIO, IDC_DELAYCUSTOM, "PopupsDelayType", POPUP_DELAY_DEFAULT, POPUP_DELAY_CUSTOM }, - { NULL, CONTROL_RADIO, IDC_DELAYPERMANENT, "PopupsDelayType", POPUP_DELAY_DEFAULT, POPUP_DELAY_PERMANENT }, - { &opts.popup_timeout, CONTROL_SPIN, IDC_DELAY, "PopupsTimeout", 10, IDC_DELAY_SPIN, (WORD) 1, (WORD) 255 }, - { &opts.popup_right_click_action, CONTROL_COMBO, IDC_RIGHT_ACTION, "PopupsRightClick", POPUP_ACTION_CLOSEPOPUP }, - { &opts.popup_left_click_action, CONTROL_COMBO, IDC_LEFT_ACTION, "PopupsLeftClick", POPUP_ACTION_OPENAVATARHISTORY }, - { &opts.popup_show_changed, CONTROL_CHECKBOX, IDC_CHANGED_L, "PopupsShowChanged", TRUE }, - { &opts.popup_changed, CONTROL_TEXT, IDC_CHANGED, "PopupsTextChanged", (ULONG_PTR) DEFAULT_TEMPLATE_CHANGED }, - { &opts.popup_show_removed, CONTROL_CHECKBOX, IDC_REMOVED_L, "PopupsShowRemoved", TRUE }, - { &opts.popup_removed, CONTROL_TEXT, IDC_REMOVED, "PopupsTextRemoved", (ULONG_PTR) DEFAULT_TEMPLATE_REMOVED } + { &opts.popup_bkg_color, CONTROL_COLOR, IDC_BGCOLOR, "PopupsBgColor", AVH_DEF_POPUPBG }, + { &opts.popup_text_color, CONTROL_COLOR, IDC_TEXTCOLOR, "PopupsTextColor", AVH_DEF_POPUPFG }, + { &opts.popup_use_win_colors, CONTROL_CHECKBOX, IDC_WINCOLORS, "PopupsWinColors", FALSE }, + { &opts.popup_use_default_colors, CONTROL_CHECKBOX, IDC_DEFAULTCOLORS, "PopupsDefaultColors", AVH_DEF_DEFPOPUPS }, + { &opts.popup_delay_type, CONTROL_RADIO, IDC_DELAYFROMPU, "PopupsDelayType", POPUP_DELAY_DEFAULT, POPUP_DELAY_DEFAULT }, + { NULL, CONTROL_RADIO, IDC_DELAYCUSTOM, "PopupsDelayType", POPUP_DELAY_DEFAULT, POPUP_DELAY_CUSTOM }, + { NULL, CONTROL_RADIO, IDC_DELAYPERMANENT, "PopupsDelayType", POPUP_DELAY_DEFAULT, POPUP_DELAY_PERMANENT }, + { &opts.popup_timeout, CONTROL_SPIN, IDC_DELAY, "PopupsTimeout", 10, IDC_DELAY_SPIN, (WORD)1, (WORD)255 }, + { &opts.popup_right_click_action, CONTROL_COMBO, IDC_RIGHT_ACTION, "PopupsRightClick", POPUP_ACTION_CLOSEPOPUP }, + { &opts.popup_left_click_action, CONTROL_COMBO, IDC_LEFT_ACTION, "PopupsLeftClick", POPUP_ACTION_OPENAVATARHISTORY }, + { &opts.popup_show_changed, CONTROL_CHECKBOX, IDC_CHANGED_L, "PopupsShowChanged", TRUE }, + { &opts.popup_changed, CONTROL_TEXT, IDC_CHANGED, "PopupsTextChanged", (ULONG_PTR)DEFAULT_TEMPLATE_CHANGED }, + { &opts.popup_show_removed, CONTROL_CHECKBOX, IDC_REMOVED_L, "PopupsShowRemoved", TRUE }, + { &opts.popup_removed, CONTROL_TEXT, IDC_REMOVED, "PopupsTextRemoved", (ULONG_PTR)DEFAULT_TEMPLATE_REMOVED } }; // Options dialog procedure /////////////////////////////////////////////////////////////////////// -static INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +static INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { return SaveOptsDlgProc(optionsControls, _countof(optionsControls), MODULE_NAME, hwndDlg, msg, wParam, lParam); } @@ -71,7 +71,7 @@ static void PopupsEnableDisableCtrls(HWND hwndDlg) EnableWindow(GetDlgItem(hwndDlg, IDC_LEFT_ACTION_L), enabled); EnableWindow(GetDlgItem(hwndDlg, IDC_LEFT_ACTION), enabled); EnableWindow(GetDlgItem(hwndDlg, IDC_PREV), enabled); - + EnableWindow(GetDlgItem(hwndDlg, IDC_BGCOLOR), enabled && BST_UNCHECKED == IsDlgButtonChecked(hwndDlg, IDC_WINCOLORS) && BST_UNCHECKED == IsDlgButtonChecked(hwndDlg, IDC_DEFAULTCOLORS)); EnableWindow(GetDlgItem(hwndDlg, IDC_TEXTCOLOR), enabled && BST_UNCHECKED == IsDlgButtonChecked(hwndDlg, IDC_WINCOLORS) && BST_UNCHECKED == IsDlgButtonChecked(hwndDlg, IDC_DEFAULTCOLORS)); EnableWindow(GetDlgItem(hwndDlg, IDC_DEFAULTCOLORS), enabled && BST_UNCHECKED == IsDlgButtonChecked(hwndDlg, IDC_WINCOLORS)); @@ -85,7 +85,7 @@ static void PopupsEnableDisableCtrls(HWND hwndDlg) EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVED), enabled && IsDlgButtonChecked(hwndDlg, IDC_REMOVED_L)); } -static INT_PTR CALLBACK PopupsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +static INT_PTR CALLBACK PopupsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: @@ -118,7 +118,7 @@ static INT_PTR CALLBACK PopupsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA PopupsEnableDisableCtrls(hwndDlg); break; - case IDC_PREV: + case IDC_PREV: Options op = opts; if (IsDlgButtonChecked(hwndDlg, IDC_DELAYFROMPU)) op.popup_delay_type = POPUP_DELAY_DEFAULT; @@ -127,14 +127,14 @@ static INT_PTR CALLBACK PopupsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA else if (IsDlgButtonChecked(hwndDlg, IDC_DELAYPERMANENT)) op.popup_delay_type = POPUP_DELAY_PERMANENT; - op.popup_timeout = GetDlgItemInt(hwndDlg,IDC_DELAY, NULL, FALSE); - op.popup_bkg_color = SendDlgItemMessage(hwndDlg,IDC_BGCOLOR,CPM_GETCOLOUR,0,0); - op.popup_text_color = SendDlgItemMessage(hwndDlg,IDC_TEXTCOLOR,CPM_GETCOLOUR,0,0); + op.popup_timeout = GetDlgItemInt(hwndDlg, IDC_DELAY, NULL, FALSE); + op.popup_bkg_color = SendDlgItemMessage(hwndDlg, IDC_BGCOLOR, CPM_GETCOLOUR, 0, 0); + op.popup_text_color = SendDlgItemMessage(hwndDlg, IDC_TEXTCOLOR, CPM_GETCOLOUR, 0, 0); op.popup_use_win_colors = IsDlgButtonChecked(hwndDlg, IDC_WINCOLORS) != 0; op.popup_use_default_colors = IsDlgButtonChecked(hwndDlg, IDC_DEFAULTCOLORS) != 0; MCONTACT hContact = db_find_first(); - ShowTestPopup(hContact,TranslateT("Test contact"), TranslateT("Test description"), &op); + ShowTestPopup(hContact, TranslateT("Test contact"), TranslateT("Test description"), &op); break; } } diff --git a/plugins/AvatarHistory/src/popup.cpp b/plugins/AvatarHistory/src/popup.cpp index 165741a06e..9fee0bb3ff 100644 --- a/plugins/AvatarHistory/src/popup.cpp +++ b/plugins/AvatarHistory/src/popup.cpp @@ -50,19 +50,18 @@ void InitPopups() // Deinitializations needed by popups void DeInitPopups() -{ -} +{} // Show an error popup void ShowErrPopup(const wchar_t *description, const wchar_t *title) { ShowPopupEx(NULL, title == NULL ? _A2W(MODULE_NAME) L" Error" : title, description, - NULL, POPUP_TYPE_ERROR, NULL); + NULL, POPUP_TYPE_ERROR, NULL); } -void ShowTestPopup(MCONTACT hContact,const wchar_t *title, const wchar_t *description, const Options *op) +void ShowTestPopup(MCONTACT hContact, const wchar_t *title, const wchar_t *description, const Options *op) { ShowPopupEx(hContact, title, description, NULL, POPUP_TYPE_TEST, op); } @@ -75,9 +74,8 @@ void ShowPopup(MCONTACT hContact, const wchar_t *title, const wchar_t *descripti void ShowDebugPopup(MCONTACT hContact, const wchar_t *title, const wchar_t *description) { - if (db_get_b(NULL,MODULE_NAME,"Debug",0)) - { - ShowPopup(hContact,title,description); + if (db_get_b(NULL, MODULE_NAME, "Debug", 0)) { + ShowPopup(hContact, title, description); } } @@ -90,12 +88,11 @@ PopupDataType; // Show an popup void ShowPopupEx(MCONTACT hContact, const wchar_t *title, const wchar_t *description, - void *plugin_data, int type, const Options *op) + void *plugin_data, int type, const Options *op) { - if (ServiceExists(MS_POPUP_ADDPOPUPT)) - { + if (ServiceExists(MS_POPUP_ADDPOPUPT)) { // Make popup - POPUPDATAT ppd = {0}; + POPUPDATAT ppd = { 0 }; ppd.lchContact = hContact; ppd.lchIcon = createProtoOverlayedIcon(hContact); @@ -108,37 +105,32 @@ void ShowPopupEx(MCONTACT hContact, const wchar_t *title, const wchar_t *descrip mir_wstrncpy(ppd.lptzContactName, title, _countof(ppd.lptzContactName)); else if (hContact != NULL) mir_wstrncpy(ppd.lptzContactName, (wchar_t *)pcli->pfnGetContactDisplayName(hContact, 0), - _countof(ppd.lptzContactName)); + _countof(ppd.lptzContactName)); if (description != NULL) mir_wstrncpy(ppd.lptzText, description, _countof(ppd.lptzText)); - if (type == POPUP_TYPE_NORMAL || type == POPUP_TYPE_TEST) - { - if (op->popup_use_default_colors) - { + if (type == POPUP_TYPE_NORMAL || type == POPUP_TYPE_TEST) { + if (op->popup_use_default_colors) { ppd.colorBack = 0; ppd.colorText = 0; } - else if (op->popup_use_win_colors) - { + else if (op->popup_use_win_colors) { ppd.colorBack = GetSysColor(COLOR_BTNFACE); ppd.colorText = GetSysColor(COLOR_WINDOWTEXT); } - else - { + else { ppd.colorBack = op->popup_bkg_color; ppd.colorText = op->popup_text_color; } } else // if (type == POPUP_TYPE_ERROR) { - ppd.colorBack = RGB(200,0,0); - ppd.colorText = RGB(255,255,255); + ppd.colorBack = RGB(200, 0, 0); + ppd.colorText = RGB(255, 255, 255); } - if (type == POPUP_TYPE_NORMAL) - { + if (type == POPUP_TYPE_NORMAL) { ppd.PluginWindowProc = PopupDlgProc; } else // if (type == POPUP_TYPE_TEST || type == POPUP_TYPE_ERROR) @@ -146,22 +138,20 @@ void ShowPopupEx(MCONTACT hContact, const wchar_t *title, const wchar_t *descrip ppd.PluginWindowProc = DumbPopupDlgProc; } - if (type == POPUP_TYPE_NORMAL || type == POPUP_TYPE_TEST) - { - switch (op->popup_delay_type) - { - case POPUP_DELAY_CUSTOM: - ppd.iSeconds = opts.popup_timeout; - break; - - case POPUP_DELAY_PERMANENT: - ppd.iSeconds = -1; - break; - - case POPUP_DELAY_DEFAULT: - default: - ppd.iSeconds = 0; - break; + if (type == POPUP_TYPE_NORMAL || type == POPUP_TYPE_TEST) { + switch (op->popup_delay_type) { + case POPUP_DELAY_CUSTOM: + ppd.iSeconds = opts.popup_timeout; + break; + + case POPUP_DELAY_PERMANENT: + ppd.iSeconds = -1; + break; + + case POPUP_DELAY_DEFAULT: + default: + ppd.iSeconds = 0; + break; } } else // if (type == POPUP_TYPE_ERROR) @@ -172,8 +162,7 @@ void ShowPopupEx(MCONTACT hContact, const wchar_t *title, const wchar_t *descrip // Now that every field has been filled, we want to see the popup. PUAddPopupT(&ppd); } - else - { + else { MessageBox(NULL, description, title ? title : (wchar_t *)pcli->pfnGetContactDisplayName(hContact, 0), MB_OK); } @@ -185,14 +174,11 @@ void ShowPopupEx(MCONTACT hContact, const wchar_t *title, const wchar_t *descrip // wParam has the number of MOTD in case of WMU_SHOW_MOTD_DETAILS LRESULT CALLBACK PopupWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - if (uMsg == WMU_ACTION) - { - if (lParam == POPUP_ACTION_OPENAVATARHISTORY) - { + if (uMsg == WMU_ACTION) { + if (lParam == POPUP_ACTION_OPENAVATARHISTORY) { CallService("AvatarHistory/ShowDialog", wParam, 0); } - else if (lParam == POPUP_ACTION_OPENHISTORY) - { + else if (lParam == POPUP_ACTION_OPENHISTORY) { CallService(MS_HISTORY_SHOWCONTACTHISTORY, wParam, 0); } } @@ -205,7 +191,7 @@ static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPA { PopupDataType *popup = (PopupDataType*)PUGetPluginData(hWnd); - switch(message) { + switch (message) { case WM_COMMAND: PostMessage(hPopupWindow, WMU_ACTION, (WPARAM)popup->plugin_data, opts.popup_left_click_action); @@ -237,7 +223,7 @@ static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPA // Handle to popup events static LRESULT CALLBACK DumbPopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - switch(message) { + switch (message) { case WM_COMMAND: PUDeletePopup(hWnd); return TRUE; diff --git a/plugins/AvatarHistory/src/utils.cpp b/plugins/AvatarHistory/src/utils.cpp index b742be5326..30f756839b 100644 --- a/plugins/AvatarHistory/src/utils.cpp +++ b/plugins/AvatarHistory/src/utils.cpp @@ -26,12 +26,7 @@ Avatar History Plugin bool ProtocolEnabled(const char *proto) { - if (proto == NULL) - return FALSE; - - char setting[256]; - mir_snprintf(setting, "%sEnabled", proto); - return 0 != db_get_b(NULL, MODULE_NAME, setting, true); + return Proto_IsAccountEnabled(Proto_GetAccount(proto)); } bool ContactEnabled(MCONTACT hContact, char *setting, int def) @@ -61,18 +56,18 @@ BOOL IsUnicodeAscii(const WCHAR * pBuffer, int nSize) void ConvertToFilename(wchar_t *str, size_t size) { - for(size_t i = 0; i < size && str[i] != '\0'; i++) { - switch(str[i]) { - case '/': - case '\\': - case ':': - case '*': - case '?': - case '"': - case '<': - case '>': - case '|': - str[i] = '_'; + for (size_t i = 0; i < size && str[i] != '\0'; i++) { + switch (str[i]) { + case '/': + case '\\': + case ':': + case '*': + case '?': + case '"': + case '<': + case '>': + case '|': + str[i] = '_'; } } } @@ -113,14 +108,14 @@ wchar_t* GetContactFolder(wchar_t *fn, MCONTACT hContact) { char *proto = GetContactProto(hContact); GetProtocolFolder(fn, proto); - + wchar_t uin[MAX_PATH]; ptrW id(Contact_GetInfo(CNF_UNIQUEID, hContact, proto)); wcsncpy_s(uin, (id == NULL) ? TranslateT("Unknown UIN") : id, _TRUNCATE); ConvertToFilename(uin, MAX_PATH); //added so that weather id's like "yw/CI0000" work mir_snwprintf(fn, MAX_PATH, L"%s\\%s", fn, uin); CreateDirectoryTreeW(fn); - + #ifdef DBGPOPUPS wchar_t log[1024]; mir_snwprintf(log, L"Path: %s\nProto: %S\nUIN: %s", fn, proto, uin); @@ -136,9 +131,9 @@ wchar_t* GetOldStyleAvatarName(wchar_t *fn, MCONTACT hContact) SYSTEMTIME curtime; GetLocalTime(&curtime); - mir_snwprintf(fn, MAX_PATH, - L"%s\\%04d-%02d-%02d %02dh%02dm%02ds", fn, - curtime.wYear, curtime.wMonth, curtime.wDay, + mir_snwprintf(fn, MAX_PATH, + L"%s\\%04d-%02d-%02d %02dh%02dm%02ds", fn, + curtime.wYear, curtime.wMonth, curtime.wDay, curtime.wHour, curtime.wMinute, curtime.wSecond); ShowDebugPopup(hContact, L"AVH Debug: GetOldStyleAvatarName", fn); return fn; @@ -154,13 +149,9 @@ void CreateOldStyleShortcut(MCONTACT hContact, wchar_t *history_filename) GetExtension(history_filename)); if (!CreateShortcut(history_filename, shortcut)) - { ShowPopup(hContact, TranslateT("Avatar history: Unable to create shortcut"), shortcut); - } else - { ShowDebugPopup(hContact, L"AVH Debug: Shortcut created successfully", shortcut); - } } BOOL CopyImageFile(wchar_t *old_file, wchar_t *new_file) @@ -170,7 +161,7 @@ BOOL CopyImageFile(wchar_t *old_file, wchar_t *new_file) return !CopyFile(old_file, new_file, TRUE); } -wchar_t * GetCachedAvatar(char *proto, wchar_t *hash) +wchar_t* GetCachedAvatar(char *proto, wchar_t *hash) { wchar_t *ret = NULL; wchar_t file[1024] = L""; @@ -187,21 +178,19 @@ wchar_t * GetCachedAvatar(char *proto, wchar_t *hash) if (hFind == INVALID_HANDLE_VALUE) return NULL; - do - { + do { size_t len = mir_wstrlen(finddata.cFileName); - if (len > 4 - && (!mir_wstrcmpi(&finddata.cFileName[len-4], L".png") - || !mir_wstrcmpi(&finddata.cFileName[len-4], L".bmp") - || !mir_wstrcmpi(&finddata.cFileName[len-4], L".gif") - || !mir_wstrcmpi(&finddata.cFileName[len-4], L".jpg") - || !mir_wstrcmpi(&finddata.cFileName[len-5], L".jpeg"))) - { + if (len > 4 + && (!mir_wstrcmpi(&finddata.cFileName[len - 4], L".png") + || !mir_wstrcmpi(&finddata.cFileName[len - 4], L".bmp") + || !mir_wstrcmpi(&finddata.cFileName[len - 4], L".gif") + || !mir_wstrcmpi(&finddata.cFileName[len - 4], L".jpg") + || !mir_wstrcmpi(&finddata.cFileName[len - 5], L".jpeg"))) { mir_snwprintf(file, L"%s\\%s", file, finddata.cFileName); ret = mir_wstrdup(file); break; } - } while(FindNextFile(hFind, &finddata)); + } while (FindNextFile(hFind, &finddata)); FindClose(hFind); return ret; @@ -210,19 +199,19 @@ wchar_t * GetCachedAvatar(char *proto, wchar_t *hash) BOOL CreateShortcut(wchar_t *file, wchar_t *shortcut) { IShellLink *psl = NULL; - HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **) &psl); + HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl); if (SUCCEEDED(hr)) { - psl->SetPath(file); + psl->SetPath(file); - IPersistFile *ppf = NULL; - hr = psl->QueryInterface(IID_IPersistFile, (void **) &ppf); + IPersistFile *ppf = NULL; + hr = psl->QueryInterface(IID_IPersistFile, (void **)&ppf); if (SUCCEEDED(hr)) { - hr = ppf->Save(shortcut, TRUE); - ppf->Release(); + hr = ppf->Save(shortcut, TRUE); + ppf->Release(); } - psl->Release(); - } + psl->Release(); + } return SUCCEEDED(hr); } @@ -231,25 +220,25 @@ BOOL ResolveShortcut(wchar_t *shortcut, wchar_t *file) { IShellLink* psl = NULL; - HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **) &psl); + HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl); if (SUCCEEDED(hr)) { - IPersistFile* ppf = NULL; - hr = psl->QueryInterface(IID_IPersistFile, (void **) &ppf); + IPersistFile* ppf = NULL; + hr = psl->QueryInterface(IID_IPersistFile, (void **)&ppf); if (SUCCEEDED(hr)) { - hr = ppf->Load(shortcut, STGM_READ); + hr = ppf->Load(shortcut, STGM_READ); if (SUCCEEDED(hr)) { - hr = psl->Resolve(NULL, SLR_UPDATE); + hr = psl->Resolve(NULL, SLR_UPDATE); if (SUCCEEDED(hr)) { WIN32_FIND_DATA wfd; - hr = psl->GetPath(file, MAX_PATH, &wfd, SLGP_RAWPATH); + hr = psl->GetPath(file, MAX_PATH, &wfd, SLGP_RAWPATH); } } - ppf->Release(); + ppf->Release(); } - psl->Release(); + psl->Release(); } return SUCCEEDED(hr); diff --git a/plugins/AvatarHistory/src/version.h b/plugins/AvatarHistory/src/version.h index 402cfc4456..b2d04f8d3d 100644 --- a/plugins/AvatarHistory/src/version.h +++ b/plugins/AvatarHistory/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 1 #define __RELEASE_NUM 0 -#define __BUILD_NUM 1 +#define __BUILD_NUM 2 #include -- cgit v1.2.3