diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/AVS/avs.vcxproj | 1 | ||||
-rw-r--r-- | plugins/AVS/avs.vcxproj.filters | 3 | ||||
-rw-r--r-- | plugins/AVS/src/contact_ava.cpp | 262 | ||||
-rw-r--r-- | plugins/AVS/src/main.cpp | 1 | ||||
-rw-r--r-- | plugins/AVS/src/options.cpp | 286 | ||||
-rw-r--r-- | plugins/AVS/src/poll.cpp | 3 | ||||
-rw-r--r-- | plugins/AVS/src/services.cpp | 25 | ||||
-rw-r--r-- | plugins/AVS/src/stdafx.h | 12 | ||||
-rw-r--r-- | plugins/AVS/src/userInfo.cpp | 56 | ||||
-rw-r--r-- | plugins/AVS/src/version.h | 2 |
10 files changed, 330 insertions, 321 deletions
diff --git a/plugins/AVS/avs.vcxproj b/plugins/AVS/avs.vcxproj index d9f23880f3..f8b5b6ff5a 100644 --- a/plugins/AVS/avs.vcxproj +++ b/plugins/AVS/avs.vcxproj @@ -38,6 +38,7 @@ </ClCompile>
<ClCompile Include="src\utils.cpp" />
<ClCompile Include="src\userInfo.cpp" />
+ <ClCompile Include="src\contact_ava.cpp" />
<ClInclude Include="src\acc.h" />
<ClInclude Include="src\image_utils.h" />
<ClInclude Include="src\poll.h" />
diff --git a/plugins/AVS/avs.vcxproj.filters b/plugins/AVS/avs.vcxproj.filters index 421d589193..715fd8e0bf 100644 --- a/plugins/AVS/avs.vcxproj.filters +++ b/plugins/AVS/avs.vcxproj.filters @@ -32,6 +32,9 @@ <ClCompile Include="src\userInfo.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\contact_ava.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\acc.h">
diff --git a/plugins/AVS/src/contact_ava.cpp b/plugins/AVS/src/contact_ava.cpp new file mode 100644 index 0000000000..9a4b935a49 --- /dev/null +++ b/plugins/AVS/src/contact_ava.cpp @@ -0,0 +1,262 @@ +/* +Copyright (C) 2012-22 Miranda NG team (https://miranda-ng.org) + +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 version 2 +of the License. + +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, see <http://www.gnu.org/licenses/>. +*/ + +#include "stdafx.h" + +class CContactAvatarDlg : public CDlgBase +{ + MCONTACT m_hContact; + HANDLE m_hHook = 0; + + UI_MESSAGE_MAP(CContactAvatarDlg, CDlgBase); + UI_MESSAGE(WM_DRAWITEM, OnDrawItem); + UI_MESSAGE(DM_AVATARCHANGED, OnAvatarChanged); + UI_MESSAGE_MAP_END(); + + INT_PTR OnAvatarChanged(UINT, WPARAM, LPARAM) + { + InvalidateRect(GetDlgItem(m_hwnd, IDC_PROTOPIC), nullptr, TRUE); + } + + INT_PTR OnDrawItem(UINT, WPARAM, LPARAM lParam) + { + LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam; + if (dis->CtlType == ODT_BUTTON && dis->CtlID == IDC_PROTOPIC) { + AVATARDRAWREQUEST avdrq = { 0 }; + GetClientRect(GetDlgItem(m_hwnd, IDC_PROTOPIC), &avdrq.rcDraw); + + FillRect(dis->hDC, &avdrq.rcDraw, GetSysColorBrush(COLOR_BTNFACE)); + + avdrq.hContact = m_hContact; + avdrq.hTargetDC = dis->hDC; + avdrq.dwFlags |= AVDRQ_DRAWBORDER; + avdrq.clrBorder = GetSysColor(COLOR_BTNTEXT); + avdrq.radius = 6; + if (!CallService(MS_AV_DRAWAVATAR, 0, (LPARAM)&avdrq)) { + // Get text rectangle + RECT rc = avdrq.rcDraw; + rc.top += 10; + rc.bottom -= 10; + rc.left += 10; + rc.right -= 10; + + // Calc text size + RECT rc_ret = rc; + DrawText(dis->hDC, TranslateT("Contact has no avatar"), -1, &rc_ret, + DT_WORDBREAK | DT_NOPREFIX | DT_CENTER | DT_CALCRECT); + + // Calc needed size + rc.top += ((rc.bottom - rc.top) - (rc_ret.bottom - rc_ret.top)) / 2; + rc.bottom = rc.top + (rc_ret.bottom - rc_ret.top); + DrawText(dis->hDC, TranslateT("Contact has no avatar"), -1, &rc, + DT_WORDBREAK | DT_NOPREFIX | DT_CENTER); + } + + FrameRect(dis->hDC, &avdrq.rcDraw, GetSysColorBrush(COLOR_BTNSHADOW)); + } + return TRUE; + } + + void ReloadAvatar() + { + SaveTransparentData(m_hwnd, m_hContact, chkProtect.IsChecked()); + ChangeAvatar(m_hContact, true); + OnAvatarChanged(0, 0, 0); + } + + void SetAvatarName() + { + uint8_t is_locked = db_get_b(m_hContact, "ContactPhoto", "Locked", 0); + + wchar_t szFinalName[MAX_PATH]; + szFinalName[0] = 0; + + DBVARIANT dbv = {}; + if (is_locked && !db_get_ws(m_hContact, "ContactPhoto", "Backup", &dbv)) { + MyPathToAbsolute(dbv.pwszVal, szFinalName); + db_free(&dbv); + } + else if (!db_get_ws(m_hContact, "ContactPhoto", "RFile", &dbv)) { + MyPathToAbsolute(dbv.pwszVal, szFinalName); + db_free(&dbv); + } + else if (!db_get_ws(m_hContact, "ContactPhoto", "File", &dbv)) { + MyPathToAbsolute(dbv.pwszVal, szFinalName); + db_free(&dbv); + } + szFinalName[MAX_PATH - 1] = 0; + SetDlgItemText(m_hwnd, IDC_AVATARNAME, szFinalName); + } + + CCtrlSpin spin1, spin2; + CCtrlCheck chkProtect, chkMakeTrans, chkHide; + CCtrlButton btnUseDefault, btnChange, btnReset, btnDefault; + +public: + CContactAvatarDlg(MCONTACT hContact) : + CDlgBase(g_plugin, IDD_AVATAROPTIONS), + m_hContact(hContact), + spin1(this, IDC_BKG_NUM_POINTS_SPIN, 8, 2), + spin2(this, IDC_BKG_COLOR_DIFFERENCE_SPIN, 100), + btnReset(this, IDC_RESET), + btnChange(this, IDC_CHANGE), + btnDefault(this, IDC_DELETE), + btnUseDefault(this, ID_USE_DEFAULTS), + chkHide(this, IDC_HIDEAVATAR), + chkProtect(this, IDC_PROTECTAVATAR), + chkMakeTrans(this, IDC_MAKETRANSPBKG) + { + btnReset.OnClick = Callback(this, &CContactAvatarDlg::onClick_Reset); + btnChange.OnClick = Callback(this, &CContactAvatarDlg::onClick_Change); + btnDefault.OnClick = Callback(this, &CContactAvatarDlg::onClick_Default); + btnUseDefault.OnClick = Callback(this, &CContactAvatarDlg::onClick_UseDefault); + + chkProtect.OnChange = Callback(this, &CContactAvatarDlg::onChange_Protect); + chkMakeTrans.OnChange = Callback(this, &CContactAvatarDlg::onChange_MakeTrans); + } + + bool OnInitDialog() override + { + m_hHook = HookEventMessage(ME_AV_AVATARCHANGED, m_hwnd, DM_AVATARCHANGED); + + if (m_hContact) { + wchar_t szTitle[512]; + mir_snwprintf(szTitle, TranslateT("Set avatar options for %s"), Clist_GetContactDisplayName(m_hContact)); + SetWindowText(m_hwnd, szTitle); + } + + SetAvatarName(); + ShowWindow(m_hwnd, SW_SHOWNORMAL); + OnAvatarChanged(0, 0, 0); + chkProtect.SetState(db_get_b(m_hContact, "ContactPhoto", "Locked", 0)); + chkHide.SetState(Contact::IsHidden(m_hContact)); + + LoadTransparentData(m_hwnd, GetContactThatHaveTheAvatar(m_hContact)); + SendMessage(m_hwnd, WM_SETICON, IMAGE_ICON, (LPARAM)g_plugin.getIcon(IDI_AVATAR)); + return true; + } + + bool OnApply() override + { + bool locked = chkProtect.IsChecked(); + bool hidden = chkHide.IsChecked(); + + SetAvatarAttribute(m_hContact, AVS_HIDEONCLIST, hidden); + if (hidden != Contact::IsHidden(m_hContact)) + Contact::Hide(m_hContact, hidden); + + if (!locked && db_get_b(m_hContact, "ContactPhoto", "NeedUpdate", 0)) + QueueAdd(m_hContact); + return true; + } + + void OnDestroy() override + { + UnhookEvent(m_hHook); + } + + void onClick_UseDefault(CCtrlButton *) + { + MCONTACT hContact = GetContactThatHaveTheAvatar(m_hContact); + + db_unset(hContact, "ContactPhoto", "MakeTransparentBkg"); + db_unset(hContact, "ContactPhoto", "TranspBkgNumPoints"); + db_unset(hContact, "ContactPhoto", "TranspBkgColorDiff"); + + LoadTransparentData(m_hwnd, hContact); + ReloadAvatar(); + } + + void onClick_Change(CCtrlButton *) + { + SetAvatar(m_hContact, 0); + SetAvatarName(); + chkProtect.SetState(db_get_b(m_hContact, "ContactPhoto", "Locked")); + } + + void onClick_Reset(CCtrlButton *) + { + ProtectAvatar(m_hContact, 0); + if (MessageBox(nullptr, TranslateT("Delete picture file from disk (may be necessary to force a reload, but will delete local pictures)?"), TranslateT("Reset contact picture"), MB_YESNO) == IDYES) { + DBVARIANT dbv = { 0 }; + if (!db_get_ws(m_hContact, "ContactPhoto", "File", &dbv)) { + DeleteFileW(dbv.pwszVal); + db_free(&dbv); + } + } + db_unset(m_hContact, "ContactPhoto", "Locked"); + db_unset(m_hContact, "ContactPhoto", "Backup"); + db_unset(m_hContact, "ContactPhoto", "RFile"); + db_unset(m_hContact, "ContactPhoto", "File"); + db_unset(m_hContact, "ContactPhoto", "Format"); + + db_unset(m_hContact, Proto_GetBaseAccountName(m_hContact), "AvatarHash"); + DeleteAvatarFromCache(m_hContact, FALSE); + + QueueAdd(m_hContact); + DestroyWindow(m_hwnd); + } + + void onClick_Default(CCtrlButton *) + { + if (MessageBoxW(nullptr, TranslateT("Delete picture file from disk (may be necessary to force a reload, but will delete local pictures)?"), TranslateT("Reset contact picture"), MB_YESNO) == IDYES) { + DBVARIANT dbv = { 0 }; + ProtectAvatar(m_hContact, 0); + if (!db_get_ws(m_hContact, "ContactPhoto", "File", &dbv)) { + DeleteFileW(dbv.pwszVal); + db_free(&dbv); + } + } + db_unset(m_hContact, "ContactPhoto", "Locked"); + db_unset(m_hContact, "ContactPhoto", "Backup"); + db_unset(m_hContact, "ContactPhoto", "RFile"); + db_unset(m_hContact, "ContactPhoto", "File"); + db_unset(m_hContact, "ContactPhoto", "Format"); + DeleteAvatarFromCache(m_hContact, FALSE); + SetAvatarName(); + OnAvatarChanged(0, 0, 0); + } + + void onChange_Protect(CCtrlCheck *) + { + ProtectAvatar(m_hContact, chkProtect.IsChecked()); + } + + void onChange_MakeTrans(CCtrlCheck *) + { + bool enable = chkMakeTrans.IsChecked(); + EnableWindow(GetDlgItem(m_hwnd, IDC_BKG_NUM_POINTS_L), enable); + EnableWindow(GetDlgItem(m_hwnd, IDC_BKG_NUM_POINTS_SPIN), enable); + EnableWindow(GetDlgItem(m_hwnd, IDC_BKG_NUM_POINTS), enable); + EnableWindow(GetDlgItem(m_hwnd, IDC_BKG_COLOR_DIFFERENCE_L), enable); + EnableWindow(GetDlgItem(m_hwnd, IDC_BKG_COLOR_DIFFERENCE_SPIN), enable); + EnableWindow(GetDlgItem(m_hwnd, IDC_BKG_COLOR_DIFFERENCE), enable); + + ReloadAvatar(); + } +}; + +INT_PTR ContactOptions(WPARAM wParam, LPARAM lParam) +{ + if (wParam) { + auto *pDlg = new CContactAvatarDlg(wParam); + if (lParam) + pDlg->SetParent((HWND)lParam); + pDlg->Create(); + } + return 0; +} diff --git a/plugins/AVS/src/main.cpp b/plugins/AVS/src/main.cpp index f99af3102b..4dacf724bb 100644 --- a/plugins/AVS/src/main.cpp +++ b/plugins/AVS/src/main.cpp @@ -24,7 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h"
-HICON g_hIcon = nullptr;
bool g_shutDown = false;
CMPlugin g_plugin;
diff --git a/plugins/AVS/src/options.cpp b/plugins/AVS/src/options.cpp index 8a489b6af2..83348a3f7f 100644 --- a/plugins/AVS/src/options.cpp +++ b/plugins/AVS/src/options.cpp @@ -26,27 +26,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern OBJLIST<protoPicCacheEntry> g_ProtoPictures; extern HANDLE hEventChanged; -extern HICON g_hIcon; static BOOL dialoginit = TRUE; -struct WindowData -{ - WindowData(MCONTACT _1, HWND hwndDlg) : - hContact(_1) - { - hHook = HookEventMessage(ME_AV_AVATARCHANGED, hwndDlg, DM_AVATARCHANGED); - } - - ~WindowData() - { - UnhookEvent(hHook); - } - - MCONTACT hContact; - HANDLE hHook = nullptr; -}; - static void RemoveProtoPic(protoPicCacheEntry *pce) { if (pce == nullptr) @@ -432,273 +414,7 @@ static INT_PTR CALLBACK DlgProcOptionsProtos(HWND hwndDlg, UINT msg, WPARAM wPar } ///////////////////////////////////////////////////////////////////////////////////////// - -void LoadTransparentData(HWND hwndDlg, MCONTACT hContact) -{ - CheckDlgButton(hwndDlg, IDC_MAKETRANSPBKG, db_get_b(hContact, "ContactPhoto", "MakeTransparentBkg", g_plugin.getByte("MakeTransparentBkg", 0)) ? BST_CHECKED : BST_UNCHECKED); - SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_SETPOS, 0, (LPARAM)db_get_w(hContact, "ContactPhoto", "TranspBkgNumPoints", g_plugin.getWord("TranspBkgNumPoints", 5))); - SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_SETPOS, 0, (LPARAM)db_get_w(hContact, "ContactPhoto", "TranspBkgColorDiff", g_plugin.getWord("TranspBkgColorDiff", 10))); - - BOOL transp_enabled = IsDlgButtonChecked(hwndDlg, IDC_MAKETRANSPBKG); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_L), transp_enabled); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_SPIN), transp_enabled); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS), transp_enabled); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_L), transp_enabled); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN), transp_enabled); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE), transp_enabled); -} - -static void SaveTransparentData(HWND hwndDlg, MCONTACT hContact) -{ - BOOL transp = IsDlgButtonChecked(hwndDlg, IDC_MAKETRANSPBKG); - if (g_plugin.getByte("MakeTransparentBkg", 0) == transp) - db_unset(hContact, "ContactPhoto", "MakeTransparentBkg"); - else - db_set_b(hContact, "ContactPhoto", "MakeTransparentBkg", transp); - - uint16_t tmp = (uint16_t)SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_GETPOS, 0, 0); - if (g_plugin.getWord("TranspBkgNumPoints", 5) == tmp) - db_unset(hContact, "ContactPhoto", "TranspBkgNumPoints"); - else - db_set_w(hContact, "ContactPhoto", "TranspBkgNumPoints", tmp); - - tmp = (uint16_t)SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_GETPOS, 0, 0); - if (g_plugin.getWord("TranspBkgColorDiff", 10) == tmp) - db_unset(hContact, "ContactPhoto", "TranspBkgColorDiff"); - else - db_set_w(hContact, "ContactPhoto", "TranspBkgColorDiff", tmp); -} - -void SaveTransparentData(HWND hwndDlg, MCONTACT hContact, BOOL locked) -{ - SaveTransparentData(hwndDlg, hContact); - - MCONTACT tmp = GetContactThatHaveTheAvatar(hContact, locked); - if (tmp != hContact) - SaveTransparentData(hwndDlg, tmp); -} - -INT_PTR CALLBACK DlgProcAvatarOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - WindowData *dat = (WindowData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - MCONTACT hContact = (dat) ? dat->hContact : INVALID_CONTACT_ID; - - switch (msg) { - case WM_INITDIALOG: - dat = new WindowData(hContact = lParam, hwndDlg); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); - - TranslateDialogDefault(hwndDlg); - if (hContact) { - wchar_t szTitle[512]; - mir_snwprintf(szTitle, TranslateT("Set avatar options for %s"), Clist_GetContactDisplayName(hContact)); - SetWindowText(hwndDlg, szTitle); - } - SendMessage(hwndDlg, DM_SETAVATARNAME, 0, 0); - ShowWindow(hwndDlg, SW_SHOWNORMAL); - InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), nullptr, FALSE); - CheckDlgButton(hwndDlg, IDC_PROTECTAVATAR, db_get_b(hContact, "ContactPhoto", "Locked", 0) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_HIDEAVATAR, Contact::IsHidden(hContact) ? BST_CHECKED : BST_UNCHECKED); - - SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_SETBUDDY, (WPARAM)GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS), 0); - SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_SETRANGE, 0, MAKELONG(8, 2)); - - SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_SETBUDDY, (WPARAM)GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE), 0); - SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_SETRANGE, 0, MAKELONG(100, 0)); - - LoadTransparentData(hwndDlg, GetContactThatHaveTheAvatar(hContact)); - SendMessage(hwndDlg, WM_SETICON, IMAGE_ICON, (LPARAM)g_hIcon); - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case ID_USE_DEFAULTS: - hContact = GetContactThatHaveTheAvatar(hContact); - - db_unset(hContact, "ContactPhoto", "MakeTransparentBkg"); - db_unset(hContact, "ContactPhoto", "TranspBkgNumPoints"); - db_unset(hContact, "ContactPhoto", "TranspBkgColorDiff"); - - LoadTransparentData(hwndDlg, hContact); - - SendMessage(hwndDlg, DM_REALODAVATAR, 0, 0); - break; - - case IDOK: - { - bool locked = IsDlgButtonChecked(hwndDlg, IDC_PROTECTAVATAR) != 0; - bool hidden = IsDlgButtonChecked(hwndDlg, IDC_HIDEAVATAR) != 0; - SetAvatarAttribute(hContact, AVS_HIDEONCLIST, hidden); - if (hidden != Contact::IsHidden(hContact)) - Contact::Hide(hContact, hidden); - - if (!locked && db_get_b(hContact, "ContactPhoto", "NeedUpdate", 0)) - QueueAdd(hContact); - } - // Continue to the cancel handle - - case IDCANCEL: - DestroyWindow(hwndDlg); - break; - - case IDC_PROTECTAVATAR: - { - BOOL locked = IsDlgButtonChecked(hwndDlg, IDC_PROTECTAVATAR); - ProtectAvatar(hContact, locked ? 1 : 0); - } - break; - - case IDC_CHANGE: - SetAvatar(hContact, 0); - SendMessage(hwndDlg, DM_SETAVATARNAME, 0, 0); - CheckDlgButton(hwndDlg, IDC_PROTECTAVATAR, db_get_b(hContact, "ContactPhoto", "Locked", 0) ? BST_CHECKED : BST_UNCHECKED); - break; - - case IDC_BKG_NUM_POINTS: - case IDC_BKG_COLOR_DIFFERENCE: - if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) - break; - - case IDC_MAKETRANSPBKG: - { - BOOL enable = IsDlgButtonChecked(hwndDlg, IDC_MAKETRANSPBKG); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_L), enable); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_SPIN), enable); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS), enable); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_L), enable); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN), enable); - EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE), enable); - - SendMessage(hwndDlg, DM_REALODAVATAR, 0, 0); - } - break; - - case IDC_RESET: - ProtectAvatar(hContact, 0); - if (MessageBox(nullptr, TranslateT("Delete picture file from disk (may be necessary to force a reload, but will delete local pictures)?"), TranslateT("Reset contact picture"), MB_YESNO) == IDYES) { - DBVARIANT dbv = { 0 }; - if (!db_get_ws(hContact, "ContactPhoto", "File", &dbv)) { - DeleteFile(dbv.pwszVal); - db_free(&dbv); - } - } - db_unset(hContact, "ContactPhoto", "Locked"); - db_unset(hContact, "ContactPhoto", "Backup"); - db_unset(hContact, "ContactPhoto", "RFile"); - db_unset(hContact, "ContactPhoto", "File"); - db_unset(hContact, "ContactPhoto", "Format"); - { - char *szProto = Proto_GetBaseAccountName(hContact); - db_unset(hContact, szProto, "AvatarHash"); - DeleteAvatarFromCache(hContact, FALSE); - - QueueAdd(hContact); - DestroyWindow(hwndDlg); - } - break; - - case IDC_DELETE: - if (MessageBox(nullptr, TranslateT("Delete picture file from disk (may be necessary to force a reload, but will delete local pictures)?"), TranslateT("Reset contact picture"), MB_YESNO) == IDYES) { - DBVARIANT dbv = { 0 }; - ProtectAvatar(hContact, 0); - if (!db_get_ws(hContact, "ContactPhoto", "File", &dbv)) { - DeleteFile(dbv.pwszVal); - db_free(&dbv); - } - } - db_unset(hContact, "ContactPhoto", "Locked"); - db_unset(hContact, "ContactPhoto", "Backup"); - db_unset(hContact, "ContactPhoto", "RFile"); - db_unset(hContact, "ContactPhoto", "File"); - db_unset(hContact, "ContactPhoto", "Format"); - DeleteAvatarFromCache(hContact, FALSE); - SendMessage(hwndDlg, DM_SETAVATARNAME, 0, 0); - InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), nullptr, TRUE); - break; - } - break; - - case WM_DRAWITEM: - { - LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam; - if (dis->CtlType == ODT_BUTTON && dis->CtlID == IDC_PROTOPIC) { - AVATARDRAWREQUEST avdrq = { 0 }; - GetClientRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), &avdrq.rcDraw); - - FillRect(dis->hDC, &avdrq.rcDraw, GetSysColorBrush(COLOR_BTNFACE)); - - avdrq.hContact = hContact; - avdrq.hTargetDC = dis->hDC; - avdrq.dwFlags |= AVDRQ_DRAWBORDER; - avdrq.clrBorder = GetSysColor(COLOR_BTNTEXT); - avdrq.radius = 6; - if (!CallService(MS_AV_DRAWAVATAR, 0, (LPARAM)&avdrq)) { - // Get text rectangle - RECT rc = avdrq.rcDraw; - rc.top += 10; - rc.bottom -= 10; - rc.left += 10; - rc.right -= 10; - - // Calc text size - RECT rc_ret = rc; - DrawText(dis->hDC, TranslateT("Contact has no avatar"), -1, &rc_ret, - DT_WORDBREAK | DT_NOPREFIX | DT_CENTER | DT_CALCRECT); - - // Calc needed size - rc.top += ((rc.bottom - rc.top) - (rc_ret.bottom - rc_ret.top)) / 2; - rc.bottom = rc.top + (rc_ret.bottom - rc_ret.top); - DrawText(dis->hDC, TranslateT("Contact has no avatar"), -1, &rc, - DT_WORDBREAK | DT_NOPREFIX | DT_CENTER); - } - - FrameRect(dis->hDC, &avdrq.rcDraw, GetSysColorBrush(COLOR_BTNSHADOW)); - } - } - return TRUE; - - case DM_SETAVATARNAME: - { - wchar_t szFinalName[MAX_PATH]; - DBVARIANT dbv = { 0 }; - uint8_t is_locked = db_get_b(hContact, "ContactPhoto", "Locked", 0); - - szFinalName[0] = 0; - - if (is_locked && !db_get_ws(hContact, "ContactPhoto", "Backup", &dbv)) { - MyPathToAbsolute(dbv.pwszVal, szFinalName); - db_free(&dbv); - } - else if (!db_get_ws(hContact, "ContactPhoto", "RFile", &dbv)) { - MyPathToAbsolute(dbv.pwszVal, szFinalName); - db_free(&dbv); - } - else if (!db_get_ws(hContact, "ContactPhoto", "File", &dbv)) { - MyPathToAbsolute(dbv.pwszVal, szFinalName); - db_free(&dbv); - } - szFinalName[MAX_PATH - 1] = 0; - SetDlgItemText(hwndDlg, IDC_AVATARNAME, szFinalName); - } - break; - - case DM_REALODAVATAR: - SaveTransparentData(hwndDlg, hContact, IsDlgButtonChecked(hwndDlg, IDC_PROTECTAVATAR)); - ChangeAvatar(hContact, true); - InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), nullptr, TRUE); - break; - - case DM_AVATARCHANGED: - InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), nullptr, TRUE); - break; - - case WM_NCDESTROY: - delete dat; - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); - break; - } - return FALSE; -} +// Module entry point int OptInit(WPARAM wParam, LPARAM) { diff --git a/plugins/AVS/src/poll.cpp b/plugins/AVS/src/poll.cpp index 276f6a5a34..16b16c65dc 100644 --- a/plugins/AVS/src/poll.cpp +++ b/plugins/AVS/src/poll.cpp @@ -192,8 +192,7 @@ int FetchAvatarFor(MCONTACT hContact, char *szProto) if (szProto != nullptr && PollProtocolCanHaveAvatar(szProto) && PollContactCanHaveAvatar(hContact, szProto)) {
// Can have avatar, but must request it?
- if ((g_AvatarHistoryAvail && CallService(MS_AVATARHISTORY_ENABLED, hContact, 0)) || (PollCheckProtocol(szProto) && PollCheckContact(hContact)))
- {
+ if ((g_AvatarHistoryAvail && CallService(MS_AVATARHISTORY_ENABLED, hContact, 0)) || (PollCheckProtocol(szProto) && PollCheckContact(hContact))) {
// Request it
PROTO_AVATAR_INFORMATION ai = { 0 };
ai.hContact = hContact;
diff --git a/plugins/AVS/src/services.cpp b/plugins/AVS/src/services.cpp index 198135ca3d..d6fa1fdbb8 100644 --- a/plugins/AVS/src/services.cpp +++ b/plugins/AVS/src/services.cpp @@ -117,20 +117,19 @@ UINT_PTR CALLBACK OpenFileSubclass(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP INT_PTR SetAvatar(WPARAM hContact, LPARAM lParam)
{
- wchar_t FileName[MAX_PATH];
- wchar_t *szFinalName;
- uint8_t locking_request;
-
if (hContact == NULL)
return 0;
int is_locked = db_get_b(hContact, "ContactPhoto", "Locked", 0);
- wchar_t *tszPath = (wchar_t*)lParam;
+ wchar_t *tszPath = (wchar_t*)lParam, *szFinalName;
if (tszPath == nullptr) {
wchar_t filter[256];
Bitmap_GetFilter(filter, _countof(filter));
+ wchar_t FileName[MAX_PATH];
+ *FileName = '\0';
+
OPENFILENAME ofn = { 0 };
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = nullptr;
@@ -140,12 +139,11 @@ INT_PTR SetAvatar(WPARAM hContact, LPARAM lParam) ofn.nMaxFileTitle = MAX_PATH;
ofn.Flags = OFN_FILEMUSTEXIST | OFN_ENABLETEMPLATE | OFN_EXPLORER | OFN_ENABLESIZING | OFN_ENABLEHOOK;
ofn.lpstrInitialDir = L".";
- *FileName = '\0';
ofn.lpstrDefExt = L"";
ofn.hInstance = g_plugin.getInst();
ofn.lpTemplateName = MAKEINTRESOURCE(IDD_OPENSUBCLASS);
ofn.lpfnHook = OpenFileSubclass;
- locking_request = is_locked;
+ uint8_t locking_request = is_locked;
ofn.lCustData = (LPARAM)&locking_request;
if (!GetOpenFileName(&ofn))
return 0;
@@ -170,7 +168,7 @@ INT_PTR SetAvatar(WPARAM hContact, LPARAM lParam) // Fix cache
ChangeAvatar(hContact, true);
- return 0;
+ return 1;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -676,17 +674,6 @@ INT_PTR SetMyAvatar(WPARAM wParam, LPARAM lParam) /////////////////////////////////////////////////////////////////////////////////////////
-INT_PTR CALLBACK DlgProcAvatarOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
-
-static INT_PTR ContactOptions(WPARAM wParam, LPARAM lParam)
-{
- if (wParam)
- CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_AVATAROPTIONS), (HWND)lParam, DlgProcAvatarOptions, wParam);
- return 0;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
INT_PTR DrawAvatarPicture(WPARAM, LPARAM lParam)
{
AVATARCACHEENTRY *ace = nullptr;
diff --git a/plugins/AVS/src/stdafx.h b/plugins/AVS/src/stdafx.h index 05091c2ca9..7325135953 100644 --- a/plugins/AVS/src/stdafx.h +++ b/plugins/AVS/src/stdafx.h @@ -124,10 +124,7 @@ struct SetMyAvatarHookData #define AVS_DEFAULT "Global avatar"
-#define DM_SETAVATARNAME (WM_USER + 10)
-#define DM_REALODAVATAR (WM_USER + 11)
#define DM_AVATARCHANGED (WM_USER + 12)
-#define DM_PROTOCOLCHANGED (WM_USER + 13)
#define DM_MYAVATARCHANGED (WM_USER + 21)
void mir_sleep(int time);
@@ -141,11 +138,11 @@ extern HANDLE hGlobalAvatarFolder; extern HANDLE hLoaderEvent, hLoaderThread, hShutdownEvent;
extern HANDLE hEventChanged, hEventContactAvatarChanged, hMyAvatarChanged;
-int GetFileHash(wchar_t* filename);
+int GetFileHash(wchar_t* filename);
uint32_t GetFileSize(wchar_t *szFilename);
-void MakePathRelative(MCONTACT hContact);
-void MakePathRelative(MCONTACT hContact, wchar_t *dest);
-void MyPathToAbsolute(const wchar_t *ptszPath, wchar_t *ptszDest);
+void MakePathRelative(MCONTACT hContact);
+void MakePathRelative(MCONTACT hContact, wchar_t *dest);
+void MyPathToAbsolute(const wchar_t *ptszPath, wchar_t *ptszDest);
void UnloadCache(void);
int CreateAvatarInCache(MCONTACT hContact, AVATARCACHEENTRY *ace, const char *szProto);
@@ -163,6 +160,7 @@ void PushAvatarRequest(CacheNode *cc); int SetAvatarAttribute(MCONTACT hContact, uint32_t attrib, int mode);
void SetIgnoreNotify(char *protocol, BOOL ignore);
+INT_PTR ContactOptions(WPARAM wParam, LPARAM lParam);
INT_PTR DrawAvatarPicture(WPARAM wParam, LPARAM lParam);
INT_PTR GetAvatarBitmap(WPARAM wParam, LPARAM lParam);
INT_PTR GetMyAvatar(WPARAM wParam, LPARAM lParam);
diff --git a/plugins/AVS/src/userInfo.cpp b/plugins/AVS/src/userInfo.cpp index bbf8d0d0f3..919bf96847 100644 --- a/plugins/AVS/src/userInfo.cpp +++ b/plugins/AVS/src/userInfo.cpp @@ -20,6 +20,53 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. BOOL ScreenToClient(HWND hWnd, LPRECT lpRect); ///////////////////////////////////////////////////////////////////////////////////////// + +void LoadTransparentData(HWND hwndDlg, MCONTACT hContact) +{ + CheckDlgButton(hwndDlg, IDC_MAKETRANSPBKG, db_get_b(hContact, "ContactPhoto", "MakeTransparentBkg", g_plugin.getByte("MakeTransparentBkg", 0)) ? BST_CHECKED : BST_UNCHECKED); + SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_SETPOS, 0, (LPARAM)db_get_w(hContact, "ContactPhoto", "TranspBkgNumPoints", g_plugin.getWord("TranspBkgNumPoints", 5))); + SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_SETPOS, 0, (LPARAM)db_get_w(hContact, "ContactPhoto", "TranspBkgColorDiff", g_plugin.getWord("TranspBkgColorDiff", 10))); + + BOOL transp_enabled = IsDlgButtonChecked(hwndDlg, IDC_MAKETRANSPBKG); + EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_L), transp_enabled); + EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_SPIN), transp_enabled); + EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS), transp_enabled); + EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_L), transp_enabled); + EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN), transp_enabled); + EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE), transp_enabled); +} + +static void SaveTransparentData(HWND hwndDlg, MCONTACT hContact) +{ + BOOL transp = IsDlgButtonChecked(hwndDlg, IDC_MAKETRANSPBKG); + if (g_plugin.getByte("MakeTransparentBkg", 0) == transp) + db_unset(hContact, "ContactPhoto", "MakeTransparentBkg"); + else + db_set_b(hContact, "ContactPhoto", "MakeTransparentBkg", transp); + + uint16_t tmp = (uint16_t)SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_GETPOS, 0, 0); + if (g_plugin.getWord("TranspBkgNumPoints", 5) == tmp) + db_unset(hContact, "ContactPhoto", "TranspBkgNumPoints"); + else + db_set_w(hContact, "ContactPhoto", "TranspBkgNumPoints", tmp); + + tmp = (uint16_t)SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_GETPOS, 0, 0); + if (g_plugin.getWord("TranspBkgColorDiff", 10) == tmp) + db_unset(hContact, "ContactPhoto", "TranspBkgColorDiff"); + else + db_set_w(hContact, "ContactPhoto", "TranspBkgColorDiff", tmp); +} + +void SaveTransparentData(HWND hwndDlg, MCONTACT hContact, BOOL locked) +{ + SaveTransparentData(hwndDlg, hContact); + + MCONTACT tmp = GetContactThatHaveTheAvatar(hContact, locked); + if (tmp != hContact) + SaveTransparentData(hwndDlg, tmp); +} + +///////////////////////////////////////////////////////////////////////////////////////// // User info dialog class AvatarUserInfoDlg : public CUserInfoPageDlg @@ -81,12 +128,11 @@ public: { HWND protopic = GetDlgItem(m_hwnd, IDC_PROTOPIC); SendMessage(protopic, AVATAR_SETCONTACT, 0, m_hContact); - SendMessage(protopic, AVATAR_SETAVATARBORDERCOLOR, 0, (LPARAM)GetSysColor(COLOR_BTNSHADOW)); + SendMessage(protopic, AVATAR_SETAVATARBORDERCOLOR, 0, GetSysColor(COLOR_BTNSHADOW)); SendMessage(protopic, AVATAR_SETNOAVATARTEXT, 0, (LPARAM)LPGENW("Contact has no avatar")); - SendMessage(protopic, AVATAR_RESPECTHIDDEN, 0, (LPARAM)FALSE); - SendMessage(protopic, AVATAR_SETRESIZEIFSMALLER, 0, (LPARAM)FALSE); + SendMessage(protopic, AVATAR_RESPECTHIDDEN, 0, FALSE); + SendMessage(protopic, AVATAR_SETRESIZEIFSMALLER, 0, FALSE); - SendMessage(m_hwnd, DM_SETAVATARNAME, 0, 0); CheckDlgButton(m_hwnd, IDC_PROTECTAVATAR, db_get_b(m_hContact, "ContactPhoto", "Locked", 0) ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(m_hwnd, IDC_HIDEAVATAR, Contact::IsHidden(m_hContact) ? BST_CHECKED : BST_UNCHECKED); return false; @@ -118,7 +164,6 @@ public: void onClick_Change(CCtrlButton *) { SetAvatar(m_hContact, 0); - SendMessage(m_hwnd, DM_SETAVATARNAME, 0, 0); CheckDlgButton(m_hwnd, IDC_PROTECTAVATAR, db_get_b(m_hContact, "ContactPhoto", "Locked", 0) ? BST_CHECKED : BST_UNCHECKED); } @@ -188,7 +233,6 @@ public: db_unset(m_hContact, "ContactPhoto", "File"); db_unset(m_hContact, "ContactPhoto", "Format"); DeleteAvatarFromCache(m_hContact, FALSE); - SendMessage(m_hwnd, DM_SETAVATARNAME, 0, 0); } }; diff --git a/plugins/AVS/src/version.h b/plugins/AVS/src/version.h index aef60ef100..311e8f193b 100644 --- a/plugins/AVS/src/version.h +++ b/plugins/AVS/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 98
#define __RELEASE_NUM 1
-#define __BUILD_NUM 4
+#define __BUILD_NUM 5
#include <stdver.h>
|