summaryrefslogtreecommitdiff
path: root/plugins/AVS
diff options
context:
space:
mode:
authordartraiden <wowemuh@gmail.com>2023-01-02 21:10:29 +0300
committerdartraiden <wowemuh@gmail.com>2023-01-02 21:10:29 +0300
commit1979fd80424d16b2e489f9b57d01d9c7811d25a2 (patch)
tree960d42c5fe4a51f0fe2850bea91256e226bce221 /plugins/AVS
parentadfbbb217d4f4a05acf198755f219a5223d31c27 (diff)
Update copyrights
Diffstat (limited to 'plugins/AVS')
-rw-r--r--plugins/AVS/src/acc.cpp2
-rw-r--r--plugins/AVS/src/cache.cpp2
-rw-r--r--plugins/AVS/src/contact_ava.cpp526
-rw-r--r--plugins/AVS/src/main.cpp2
-rw-r--r--plugins/AVS/src/options.cpp882
-rw-r--r--plugins/AVS/src/poll.cpp2
-rw-r--r--plugins/AVS/src/poll.h2
-rw-r--r--plugins/AVS/src/services.cpp2
-rw-r--r--plugins/AVS/src/stdafx.cxx2
-rw-r--r--plugins/AVS/src/stdafx.h2
-rw-r--r--plugins/AVS/src/userInfo.cpp970
-rw-r--r--plugins/AVS/src/utils.cpp2
-rw-r--r--plugins/AVS/src/version.h2
13 files changed, 1199 insertions, 1199 deletions
diff --git a/plugins/AVS/src/acc.cpp b/plugins/AVS/src/acc.cpp
index 359a5660c3..e637b83d23 100644
--- a/plugins/AVS/src/acc.cpp
+++ b/plugins/AVS/src/acc.cpp
@@ -2,7 +2,7 @@
Miranda NG: the free IM client for Microsoft* Windows*
-Copyright (C) 2012-22 Miranda NG team (https://miranda-ng.org)
+Copyright (C) 2012-23 Miranda NG team (https://miranda-ng.org)
Copyright (c) 2000-04 Miranda ICQ/IM project,
all portions of this codebase are copyrighted to the people
listed in contributors.txt.
diff --git a/plugins/AVS/src/cache.cpp b/plugins/AVS/src/cache.cpp
index c60c8cd05b..318834644d 100644
--- a/plugins/AVS/src/cache.cpp
+++ b/plugins/AVS/src/cache.cpp
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2012-22 Miranda NG team (https://miranda-ng.org)
+Copyright (C) 2012-23 Miranda NG team (https://miranda-ng.org)
Copyright (C) 2006 Ricardo Pescuma Domenecci, Nightwish
This is free software; you can redistribute it and/or
diff --git a/plugins/AVS/src/contact_ava.cpp b/plugins/AVS/src/contact_ava.cpp
index d2d8c08399..2f67afc693 100644
--- a/plugins/AVS/src/contact_ava.cpp
+++ b/plugins/AVS/src/contact_ava.cpp
@@ -1,263 +1,263 @@
-/*
-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);
- return 0;
- }
-
- 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;
-}
+/*
+Copyright (C) 2012-23 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);
+ return 0;
+ }
+
+ 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 2ad7a85047..bab379ba4d 100644
--- a/plugins/AVS/src/main.cpp
+++ b/plugins/AVS/src/main.cpp
@@ -2,7 +2,7 @@
Miranda NG: the free IM client for Microsoft* Windows*
-Copyright (C) 2012-22 Miranda NG team (https://miranda-ng.org)
+Copyright (C) 2012-23 Miranda NG team (https://miranda-ng.org)
Copyright (c) 2000-04 Miranda ICQ/IM project,
all portions of this codebase are copyrighted to the people
listed in contributors.txt.
diff --git a/plugins/AVS/src/options.cpp b/plugins/AVS/src/options.cpp
index 83348a3f7f..f281c686ed 100644
--- a/plugins/AVS/src/options.cpp
+++ b/plugins/AVS/src/options.cpp
@@ -1,441 +1,441 @@
-/*
-
-Miranda NG: the free IM client for Microsoft* Windows*
-
-Copyright (C) 2012-22 Miranda NG team (https://miranda-ng.org)
-Copyright (c) 2000-04 Miranda ICQ/IM project,
-all portions of this codebase are copyrighted to the people
-listed in contributors.txt.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#include "stdafx.h"
-
-extern OBJLIST<protoPicCacheEntry> g_ProtoPictures;
-extern HANDLE hEventChanged;
-
-static BOOL dialoginit = TRUE;
-
-static void RemoveProtoPic(protoPicCacheEntry *pce)
-{
- if (pce == nullptr)
- return;
-
- db_unset(0, PPICT_MODULE, pce->szProtoname);
-
- // common for all accounts
- if (pce->cacheType == PCE_TYPE_GLOBAL) {
- for (auto &p : g_ProtoPictures) {
- if (p->szProtoname == nullptr)
- continue;
-
- p->clear();
- CreateAvatarInCache(0, p, p->szProtoname);
- NotifyEventHooks(hEventChanged, 0, (LPARAM)p);
- }
- return;
- }
-
- // common for all accounts of this proto
- if (pce->cacheType == PCE_TYPE_PROTO) {
- for (auto &p : g_ProtoPictures) {
- if (p->szProtoname == nullptr)
- continue;
-
- PROTOACCOUNT *pdescr = Proto_GetAccount(p->szProtoname);
- if (pdescr == nullptr && mir_strcmp(p->szProtoname, pce->szProtoname))
- continue;
-
- if (!mir_strcmp(p->szProtoname, pce->szProtoname) || !mir_strcmp(pdescr->szProtoName, pce->pd->szName)) {
- p->clear();
- CreateAvatarInCache(0, p, p->szProtoname);
- NotifyEventHooks(hEventChanged, 0, (LPARAM)p);
- }
- }
- return;
- }
-
- for (auto &p : g_ProtoPictures) {
- if (!mir_strcmp(p->szProtoname, pce->szProtoname)) {
- p->clear();
- NotifyEventHooks(hEventChanged, 0, (LPARAM)p);
- }
- }
-}
-
-static void SetProtoPic(protoPicCacheEntry *pce)
-{
- wchar_t FileName[MAX_PATH], filter[256];
- Bitmap_GetFilter(filter, _countof(filter));
-
- OPENFILENAME ofn = { 0 };
- ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
- ofn.lpstrFilter = filter;
- ofn.hwndOwner = nullptr;
- ofn.lpstrFile = FileName;
- ofn.nMaxFile = MAX_PATH;
- ofn.nMaxFileTitle = MAX_PATH;
- ofn.Flags = OFN_HIDEREADONLY;
- ofn.lpstrInitialDir = L".";
- *FileName = '\0';
- ofn.lpstrDefExt = L"";
- if (!GetOpenFileName(&ofn))
- return;
-
- if (_waccess(FileName, 4) == -1)
- return;
-
- wchar_t szNewPath[MAX_PATH];
- PathToRelativeW(FileName, szNewPath, g_szDataPath);
- db_set_ws(0, PPICT_MODULE, pce->szProtoname, szNewPath);
-
- switch(pce->cacheType) {
- case PCE_TYPE_GLOBAL:
- for (auto &p : g_ProtoPictures) {
- if (mir_strlen(p->szProtoname) == 0)
- continue;
-
- if (p->hbmPic == nullptr || !mir_strcmp(p->szProtoname, AVS_DEFAULT)) {
- CreateAvatarInCache(0, p, pce->szProtoname);
- NotifyEventHooks(hEventChanged, 0, (LPARAM)p);
- }
- }
- break;
-
- case PCE_TYPE_PROTO:
- for (auto &p : g_ProtoPictures) {
- PROTOACCOUNT* pdescr = Proto_GetAccount(p->szProtoname);
- if (pdescr == nullptr && mir_strcmp(p->szProtoname, pce->szProtoname))
- continue;
-
- if (!mir_strcmp(p->szProtoname, pce->szProtoname) || !mir_strcmp(pdescr->szProtoName, pce->pd->szName)) {
- if (mir_strlen(p->szProtoname) != 0) {
- if (p->hbmPic == nullptr) {
- CreateAvatarInCache(0, p, pce->szProtoname);
- NotifyEventHooks(hEventChanged, 0, (LPARAM)p);
- }
- }
- }
- }
- break;
-
- default:
- for (auto &p : g_ProtoPictures) {
- if (mir_strlen(p->szProtoname) == 0)
- break;
-
- if (!mir_strcmp(p->szProtoname, pce->szProtoname) && mir_strlen(p->szProtoname) == mir_strlen(pce->szProtoname)) {
- if (p->hbmPic != nullptr)
- DeleteObject(p->hbmPic);
- memset(p, 0, sizeof(AVATARCACHEENTRY));
- CreateAvatarInCache(0, p, pce->szProtoname);
- NotifyEventHooks(hEventChanged, 0, (LPARAM)p);
- break;
- }
- }
- }
-}
-
-static protoPicCacheEntry *g_selectedProto;
-
-static INT_PTR CALLBACK DlgProcOptionsAvatars(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
-
- CheckDlgButton(hwndDlg, IDC_SHOWWARNINGS, g_plugin.getByte("warnings", 0) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg, IDC_MAKE_GRAYSCALE, g_plugin.getByte("MakeGrayscale", 0) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg, IDC_MAKE_TRANSPARENT_BKG, g_plugin.getByte("MakeTransparentBkg", 0) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg, IDC_MAKE_TRANSP_PROPORTIONAL, g_plugin.getByte("MakeTransparencyProportionalToColorDiff", 0) ? BST_CHECKED : BST_UNCHECKED);
-
- SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_SETRANGE, 0, MAKELONG(8, 2));
- SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_SETPOS, 0, g_plugin.getWord("TranspBkgNumPoints", 5));
-
- SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_SETRANGE, 0, MAKELONG(100, 0));
- SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_SETPOS, 0, g_plugin.getWord("TranspBkgColorDiff", 10));
- {
- BOOL enabled = IsDlgButtonChecked(hwndDlg, IDC_MAKE_TRANSPARENT_BKG);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_L), enabled);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_SPIN), enabled);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS), enabled);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_L), enabled);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN), enabled);
- EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE), enabled);
- EnableWindow(GetDlgItem(hwndDlg, IDC_MAKE_TRANSP_PROPORTIONAL), enabled);
- }
-
- return TRUE;
-
- case WM_COMMAND:
- if ((LOWORD(wParam) == IDC_BKG_NUM_POINTS || LOWORD(wParam) == IDC_BKG_COLOR_DIFFERENCE) && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()))
- return FALSE;
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- break;
-
- case WM_NOTIFY:
- switch (((LPNMHDR)lParam)->idFrom) {
- case IDC_MAKE_TRANSPARENT_BKG:
- {
- BOOL transp_enabled = IsDlgButtonChecked(hwndDlg, IDC_MAKE_TRANSPARENT_BKG);
- 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);
- EnableWindow(GetDlgItem(hwndDlg, IDC_MAKE_TRANSP_PROPORTIONAL), transp_enabled);
- break;
- }
- case 0:
- switch (((LPNMHDR)lParam)->code) {
- case PSN_APPLY:
- g_plugin.setByte("warnings", IsDlgButtonChecked(hwndDlg, IDC_SHOWWARNINGS) ? 1 : 0);
- g_plugin.setByte("MakeGrayscale", IsDlgButtonChecked(hwndDlg, IDC_MAKE_GRAYSCALE) ? 1 : 0);
- g_plugin.setByte("MakeTransparentBkg", IsDlgButtonChecked(hwndDlg, IDC_MAKE_TRANSPARENT_BKG) ? 1 : 0);
- g_plugin.setByte("MakeTransparencyProportionalToColorDiff", IsDlgButtonChecked(hwndDlg, IDC_MAKE_TRANSP_PROPORTIONAL) ? 1 : 0);
- g_plugin.setWord("TranspBkgNumPoints", (uint16_t)SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_GETPOS, 0, 0));
- g_plugin.setWord("TranspBkgColorDiff", (uint16_t)SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_GETPOS, 0, 0));
- }
- }
- break;
- }
- return FALSE;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-static INT_PTR CALLBACK DlgProcOptionsOwn(HWND hwndDlg, UINT msg, WPARAM, LPARAM lParam)
-{
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
-
- CheckDlgButton(hwndDlg, IDC_MAKE_MY_AVATARS_TRANSP, g_plugin.getByte("MakeMyAvatarsTransparent", 0) ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg, IDC_SET_MAKE_SQUARE, g_plugin.getByte("SetAllwaysMakeSquare", 0) ? BST_CHECKED : BST_UNCHECKED);
-
- return TRUE;
-
- case WM_COMMAND:
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- break;
-
- case WM_NOTIFY:
- switch (((LPNMHDR)lParam)->idFrom) {
- case 0:
- switch (((LPNMHDR)lParam)->code) {
- case PSN_APPLY:
- g_plugin.setByte("MakeMyAvatarsTransparent", IsDlgButtonChecked(hwndDlg, IDC_MAKE_MY_AVATARS_TRANSP) ? 1 : 0);
- g_plugin.setByte("SetAllwaysMakeSquare", IsDlgButtonChecked(hwndDlg, IDC_SET_MAKE_SQUARE) ? 1 : 0);
- }
- }
- break;
- }
- return FALSE;
-}
-
-static protoPicCacheEntry* GetProtoFromList(HWND hwndDlg, int iItem)
-{
- LVITEM item;
- item.mask = LVIF_PARAM;
- item.iItem = iItem;
- if (!ListView_GetItem(GetDlgItem(hwndDlg, IDC_PROTOCOLS), &item))
- return nullptr;
-
- return (protoPicCacheEntry*)item.lParam;
-}
-
-static INT_PTR CALLBACK DlgProcOptionsProtos(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- HWND hwndList = GetDlgItem(hwndDlg, IDC_PROTOCOLS);
- HWND hwndChoosePic = GetDlgItem(hwndDlg, IDC_SETPROTOPIC);
- HWND hwndRemovePic = GetDlgItem(hwndDlg, IDC_REMOVEPROTOPIC);
-
- switch (msg) {
- case WM_INITDIALOG:
- dialoginit = TRUE;
- TranslateDialogDefault(hwndDlg);
-
- ListView_SetExtendedListViewStyle(hwndList, LVS_EX_CHECKBOXES);
- {
- LVCOLUMN lvc = { 0 };
- lvc.mask = LVCF_FMT;
- lvc.fmt = LVCFMT_IMAGE | LVCFMT_LEFT;
- ListView_InsertColumn(hwndList, 0, &lvc);
-
- CMStringW tmp;
-
- LVITEM item = { 0 };
- item.mask = LVIF_TEXT | LVIF_PARAM;
- item.iItem = 1000;
- for (auto &p : g_ProtoPictures) {
- switch (p->cacheType) {
- case PCE_TYPE_ACCOUNT:
- item.pszText = p->pa->tszAccountName;
- break;
- case PCE_TYPE_PROTO:
- tmp.Format(TranslateT("Global avatar for %s accounts"), _A2T(p->pd->szName).get());
- item.pszText = tmp.GetBuffer();
- break;
- default:
- item.pszText = TranslateT("Global avatar");
- break;
- }
- item.lParam = (LPARAM)p;
- int newItem = ListView_InsertItem(hwndList, &item);
- if (newItem >= 0)
- ListView_SetCheckState(hwndList, newItem, g_plugin.getByte(p->szProtoname, 1) ? TRUE : FALSE);
- }
- ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE);
- ListView_Arrange(hwndList, LVA_ALIGNLEFT | LVA_ALIGNTOP);
- EnableWindow(hwndChoosePic, FALSE);
- EnableWindow(hwndRemovePic, FALSE);
- }
- dialoginit = FALSE;
- return TRUE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_SETPROTOPIC:
- case IDC_REMOVEPROTOPIC:
- int iItem = ListView_GetSelectionMark(hwndList);
- auto *pce = GetProtoFromList(hwndDlg, iItem);
- if (pce) {
- if (LOWORD(wParam) == IDC_SETPROTOPIC)
- SetProtoPic(pce);
- else
- RemoveProtoPic(pce);
-
- NMHDR nm = { hwndList, IDC_PROTOCOLS, NM_CLICK };
- SendMessage(hwndDlg, WM_NOTIFY, 0, (LPARAM)&nm);
- }
- }
- break;
-
- case WM_DRAWITEM:
- {
- LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam;
- if (dis->CtlType == ODT_BUTTON && dis->CtlID == IDC_PROTOPIC) {
- AVATARDRAWREQUEST avdrq = { 0 };
- avdrq.hTargetDC = dis->hDC;
- avdrq.dwFlags |= AVDRQ_PROTOPICT;
- avdrq.szProto = (g_selectedProto) ? g_selectedProto->szProtoname : nullptr;
- GetClientRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), &avdrq.rcDraw);
- CallService(MS_AV_DRAWAVATAR, 0, (LPARAM)&avdrq);
- }
- }
- return TRUE;
-
- case WM_NOTIFY:
- if (dialoginit)
- break;
-
- switch (((LPNMHDR)lParam)->idFrom) {
- case IDC_PROTOCOLS:
- switch (((LPNMHDR)lParam)->code) {
- case LVN_KEYDOWN:
- {
- NMLVKEYDOWN* ptkd = (NMLVKEYDOWN*)lParam;
- if (ptkd&&ptkd->wVKey == VK_SPACE && ListView_GetSelectedCount(ptkd->hdr.hwndFrom) == 1)
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- }
- break;
-
- case LVN_ITEMCHANGED:
- {
- NMLISTVIEW *nmlv = (NMLISTVIEW *)lParam;
- if (IsWindowVisible(GetDlgItem(hwndDlg, IDC_PROTOCOLS)) && ((nmlv->uNewState ^ nmlv->uOldState) & LVIS_STATEIMAGEMASK))
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- }
- break;
-
- case NM_CLICK:
- EnableWindow(hwndChoosePic, TRUE);
- EnableWindow(hwndRemovePic, TRUE);
-
- int iItem = ListView_GetSelectionMark(hwndList);
- g_selectedProto = GetProtoFromList(hwndDlg, iItem);
- if (g_selectedProto) {
- DBVARIANT dbv;
- if (!db_get_ws(0, PPICT_MODULE, g_selectedProto->szProtoname, &dbv)) {
- if (!PathIsAbsoluteW(VARSW(dbv.pwszVal))) {
- wchar_t szFinalPath[MAX_PATH];
- mir_snwprintf(szFinalPath, L"%%miranda_path%%\\%s", dbv.pwszVal);
- SetDlgItemText(hwndDlg, IDC_PROTOAVATARNAME, szFinalPath);
- }
- else SetDlgItemText(hwndDlg, IDC_PROTOAVATARNAME, dbv.pwszVal);
-
- InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), nullptr, TRUE);
- db_free(&dbv);
- }
- else {
- SetDlgItemText(hwndDlg, IDC_PROTOAVATARNAME, L"");
- InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), nullptr, TRUE);
- }
- }
- }
- break;
-
- case 0:
- if (((LPNMHDR)lParam)->code == PSN_APPLY) {
- for (int i = 0; i < ListView_GetItemCount(hwndList); i++) {
- auto *pce = GetProtoFromList(hwndDlg, i);
-
- BOOL oldVal = g_plugin.getByte(pce->szProtoname, 1);
- BOOL newVal = ListView_GetCheckState(hwndList, i);
-
- if (oldVal && !newVal)
- for (auto &hContact : Contacts(pce->szProtoname))
- DeleteAvatarFromCache(hContact, TRUE);
-
- if (newVal)
- g_plugin.setByte(pce->szProtoname, 1);
- else
- g_plugin.setByte(pce->szProtoname, 0);
- }
- }
- }
- break;
- }
- return FALSE;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// Module entry point
-
-int OptInit(WPARAM wParam, LPARAM)
-{
- OPTIONSDIALOGPAGE odp = {};
- odp.flags = ODPF_BOLDGROUPS;
- odp.szGroup.a = LPGEN("Contacts");
- odp.szTitle.a = LPGEN("Avatars");
-
- odp.szTab.a = LPGEN("Protocols");
- odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS_PICTS);
- odp.pfnDlgProc = DlgProcOptionsProtos;
- g_plugin.addOptions(wParam, &odp);
-
- odp.szTab.a = LPGEN("Contact avatars");
- odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS_AVATARS);
- odp.pfnDlgProc = DlgProcOptionsAvatars;
- g_plugin.addOptions(wParam, &odp);
-
- odp.szTab.a = LPGEN("Own avatars");
- odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS_OWN);
- odp.pfnDlgProc = DlgProcOptionsOwn;
- g_plugin.addOptions(wParam, &odp);
- return 0;
-}
+/*
+
+Miranda NG: the free IM client for Microsoft* Windows*
+
+Copyright (C) 2012-23 Miranda NG team (https://miranda-ng.org)
+Copyright (c) 2000-04 Miranda ICQ/IM project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "stdafx.h"
+
+extern OBJLIST<protoPicCacheEntry> g_ProtoPictures;
+extern HANDLE hEventChanged;
+
+static BOOL dialoginit = TRUE;
+
+static void RemoveProtoPic(protoPicCacheEntry *pce)
+{
+ if (pce == nullptr)
+ return;
+
+ db_unset(0, PPICT_MODULE, pce->szProtoname);
+
+ // common for all accounts
+ if (pce->cacheType == PCE_TYPE_GLOBAL) {
+ for (auto &p : g_ProtoPictures) {
+ if (p->szProtoname == nullptr)
+ continue;
+
+ p->clear();
+ CreateAvatarInCache(0, p, p->szProtoname);
+ NotifyEventHooks(hEventChanged, 0, (LPARAM)p);
+ }
+ return;
+ }
+
+ // common for all accounts of this proto
+ if (pce->cacheType == PCE_TYPE_PROTO) {
+ for (auto &p : g_ProtoPictures) {
+ if (p->szProtoname == nullptr)
+ continue;
+
+ PROTOACCOUNT *pdescr = Proto_GetAccount(p->szProtoname);
+ if (pdescr == nullptr && mir_strcmp(p->szProtoname, pce->szProtoname))
+ continue;
+
+ if (!mir_strcmp(p->szProtoname, pce->szProtoname) || !mir_strcmp(pdescr->szProtoName, pce->pd->szName)) {
+ p->clear();
+ CreateAvatarInCache(0, p, p->szProtoname);
+ NotifyEventHooks(hEventChanged, 0, (LPARAM)p);
+ }
+ }
+ return;
+ }
+
+ for (auto &p : g_ProtoPictures) {
+ if (!mir_strcmp(p->szProtoname, pce->szProtoname)) {
+ p->clear();
+ NotifyEventHooks(hEventChanged, 0, (LPARAM)p);
+ }
+ }
+}
+
+static void SetProtoPic(protoPicCacheEntry *pce)
+{
+ wchar_t FileName[MAX_PATH], filter[256];
+ Bitmap_GetFilter(filter, _countof(filter));
+
+ OPENFILENAME ofn = { 0 };
+ ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
+ ofn.lpstrFilter = filter;
+ ofn.hwndOwner = nullptr;
+ ofn.lpstrFile = FileName;
+ ofn.nMaxFile = MAX_PATH;
+ ofn.nMaxFileTitle = MAX_PATH;
+ ofn.Flags = OFN_HIDEREADONLY;
+ ofn.lpstrInitialDir = L".";
+ *FileName = '\0';
+ ofn.lpstrDefExt = L"";
+ if (!GetOpenFileName(&ofn))
+ return;
+
+ if (_waccess(FileName, 4) == -1)
+ return;
+
+ wchar_t szNewPath[MAX_PATH];
+ PathToRelativeW(FileName, szNewPath, g_szDataPath);
+ db_set_ws(0, PPICT_MODULE, pce->szProtoname, szNewPath);
+
+ switch(pce->cacheType) {
+ case PCE_TYPE_GLOBAL:
+ for (auto &p : g_ProtoPictures) {
+ if (mir_strlen(p->szProtoname) == 0)
+ continue;
+
+ if (p->hbmPic == nullptr || !mir_strcmp(p->szProtoname, AVS_DEFAULT)) {
+ CreateAvatarInCache(0, p, pce->szProtoname);
+ NotifyEventHooks(hEventChanged, 0, (LPARAM)p);
+ }
+ }
+ break;
+
+ case PCE_TYPE_PROTO:
+ for (auto &p : g_ProtoPictures) {
+ PROTOACCOUNT* pdescr = Proto_GetAccount(p->szProtoname);
+ if (pdescr == nullptr && mir_strcmp(p->szProtoname, pce->szProtoname))
+ continue;
+
+ if (!mir_strcmp(p->szProtoname, pce->szProtoname) || !mir_strcmp(pdescr->szProtoName, pce->pd->szName)) {
+ if (mir_strlen(p->szProtoname) != 0) {
+ if (p->hbmPic == nullptr) {
+ CreateAvatarInCache(0, p, pce->szProtoname);
+ NotifyEventHooks(hEventChanged, 0, (LPARAM)p);
+ }
+ }
+ }
+ }
+ break;
+
+ default:
+ for (auto &p : g_ProtoPictures) {
+ if (mir_strlen(p->szProtoname) == 0)
+ break;
+
+ if (!mir_strcmp(p->szProtoname, pce->szProtoname) && mir_strlen(p->szProtoname) == mir_strlen(pce->szProtoname)) {
+ if (p->hbmPic != nullptr)
+ DeleteObject(p->hbmPic);
+ memset(p, 0, sizeof(AVATARCACHEENTRY));
+ CreateAvatarInCache(0, p, pce->szProtoname);
+ NotifyEventHooks(hEventChanged, 0, (LPARAM)p);
+ break;
+ }
+ }
+ }
+}
+
+static protoPicCacheEntry *g_selectedProto;
+
+static INT_PTR CALLBACK DlgProcOptionsAvatars(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
+
+ CheckDlgButton(hwndDlg, IDC_SHOWWARNINGS, g_plugin.getByte("warnings", 0) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_MAKE_GRAYSCALE, g_plugin.getByte("MakeGrayscale", 0) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_MAKE_TRANSPARENT_BKG, g_plugin.getByte("MakeTransparentBkg", 0) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_MAKE_TRANSP_PROPORTIONAL, g_plugin.getByte("MakeTransparencyProportionalToColorDiff", 0) ? BST_CHECKED : BST_UNCHECKED);
+
+ SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_SETRANGE, 0, MAKELONG(8, 2));
+ SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_SETPOS, 0, g_plugin.getWord("TranspBkgNumPoints", 5));
+
+ SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_SETRANGE, 0, MAKELONG(100, 0));
+ SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_SETPOS, 0, g_plugin.getWord("TranspBkgColorDiff", 10));
+ {
+ BOOL enabled = IsDlgButtonChecked(hwndDlg, IDC_MAKE_TRANSPARENT_BKG);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_L), enabled);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS_SPIN), enabled);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_NUM_POINTS), enabled);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_L), enabled);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN), enabled);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BKG_COLOR_DIFFERENCE), enabled);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_MAKE_TRANSP_PROPORTIONAL), enabled);
+ }
+
+ return TRUE;
+
+ case WM_COMMAND:
+ if ((LOWORD(wParam) == IDC_BKG_NUM_POINTS || LOWORD(wParam) == IDC_BKG_COLOR_DIFFERENCE) && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()))
+ return FALSE;
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ break;
+
+ case WM_NOTIFY:
+ switch (((LPNMHDR)lParam)->idFrom) {
+ case IDC_MAKE_TRANSPARENT_BKG:
+ {
+ BOOL transp_enabled = IsDlgButtonChecked(hwndDlg, IDC_MAKE_TRANSPARENT_BKG);
+ 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);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_MAKE_TRANSP_PROPORTIONAL), transp_enabled);
+ break;
+ }
+ case 0:
+ switch (((LPNMHDR)lParam)->code) {
+ case PSN_APPLY:
+ g_plugin.setByte("warnings", IsDlgButtonChecked(hwndDlg, IDC_SHOWWARNINGS) ? 1 : 0);
+ g_plugin.setByte("MakeGrayscale", IsDlgButtonChecked(hwndDlg, IDC_MAKE_GRAYSCALE) ? 1 : 0);
+ g_plugin.setByte("MakeTransparentBkg", IsDlgButtonChecked(hwndDlg, IDC_MAKE_TRANSPARENT_BKG) ? 1 : 0);
+ g_plugin.setByte("MakeTransparencyProportionalToColorDiff", IsDlgButtonChecked(hwndDlg, IDC_MAKE_TRANSP_PROPORTIONAL) ? 1 : 0);
+ g_plugin.setWord("TranspBkgNumPoints", (uint16_t)SendDlgItemMessage(hwndDlg, IDC_BKG_NUM_POINTS_SPIN, UDM_GETPOS, 0, 0));
+ g_plugin.setWord("TranspBkgColorDiff", (uint16_t)SendDlgItemMessage(hwndDlg, IDC_BKG_COLOR_DIFFERENCE_SPIN, UDM_GETPOS, 0, 0));
+ }
+ }
+ break;
+ }
+ return FALSE;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static INT_PTR CALLBACK DlgProcOptionsOwn(HWND hwndDlg, UINT msg, WPARAM, LPARAM lParam)
+{
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
+
+ CheckDlgButton(hwndDlg, IDC_MAKE_MY_AVATARS_TRANSP, g_plugin.getByte("MakeMyAvatarsTransparent", 0) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_SET_MAKE_SQUARE, g_plugin.getByte("SetAllwaysMakeSquare", 0) ? BST_CHECKED : BST_UNCHECKED);
+
+ return TRUE;
+
+ case WM_COMMAND:
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ break;
+
+ case WM_NOTIFY:
+ switch (((LPNMHDR)lParam)->idFrom) {
+ case 0:
+ switch (((LPNMHDR)lParam)->code) {
+ case PSN_APPLY:
+ g_plugin.setByte("MakeMyAvatarsTransparent", IsDlgButtonChecked(hwndDlg, IDC_MAKE_MY_AVATARS_TRANSP) ? 1 : 0);
+ g_plugin.setByte("SetAllwaysMakeSquare", IsDlgButtonChecked(hwndDlg, IDC_SET_MAKE_SQUARE) ? 1 : 0);
+ }
+ }
+ break;
+ }
+ return FALSE;
+}
+
+static protoPicCacheEntry* GetProtoFromList(HWND hwndDlg, int iItem)
+{
+ LVITEM item;
+ item.mask = LVIF_PARAM;
+ item.iItem = iItem;
+ if (!ListView_GetItem(GetDlgItem(hwndDlg, IDC_PROTOCOLS), &item))
+ return nullptr;
+
+ return (protoPicCacheEntry*)item.lParam;
+}
+
+static INT_PTR CALLBACK DlgProcOptionsProtos(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ HWND hwndList = GetDlgItem(hwndDlg, IDC_PROTOCOLS);
+ HWND hwndChoosePic = GetDlgItem(hwndDlg, IDC_SETPROTOPIC);
+ HWND hwndRemovePic = GetDlgItem(hwndDlg, IDC_REMOVEPROTOPIC);
+
+ switch (msg) {
+ case WM_INITDIALOG:
+ dialoginit = TRUE;
+ TranslateDialogDefault(hwndDlg);
+
+ ListView_SetExtendedListViewStyle(hwndList, LVS_EX_CHECKBOXES);
+ {
+ LVCOLUMN lvc = { 0 };
+ lvc.mask = LVCF_FMT;
+ lvc.fmt = LVCFMT_IMAGE | LVCFMT_LEFT;
+ ListView_InsertColumn(hwndList, 0, &lvc);
+
+ CMStringW tmp;
+
+ LVITEM item = { 0 };
+ item.mask = LVIF_TEXT | LVIF_PARAM;
+ item.iItem = 1000;
+ for (auto &p : g_ProtoPictures) {
+ switch (p->cacheType) {
+ case PCE_TYPE_ACCOUNT:
+ item.pszText = p->pa->tszAccountName;
+ break;
+ case PCE_TYPE_PROTO:
+ tmp.Format(TranslateT("Global avatar for %s accounts"), _A2T(p->pd->szName).get());
+ item.pszText = tmp.GetBuffer();
+ break;
+ default:
+ item.pszText = TranslateT("Global avatar");
+ break;
+ }
+ item.lParam = (LPARAM)p;
+ int newItem = ListView_InsertItem(hwndList, &item);
+ if (newItem >= 0)
+ ListView_SetCheckState(hwndList, newItem, g_plugin.getByte(p->szProtoname, 1) ? TRUE : FALSE);
+ }
+ ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE);
+ ListView_Arrange(hwndList, LVA_ALIGNLEFT | LVA_ALIGNTOP);
+ EnableWindow(hwndChoosePic, FALSE);
+ EnableWindow(hwndRemovePic, FALSE);
+ }
+ dialoginit = FALSE;
+ return TRUE;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_SETPROTOPIC:
+ case IDC_REMOVEPROTOPIC:
+ int iItem = ListView_GetSelectionMark(hwndList);
+ auto *pce = GetProtoFromList(hwndDlg, iItem);
+ if (pce) {
+ if (LOWORD(wParam) == IDC_SETPROTOPIC)
+ SetProtoPic(pce);
+ else
+ RemoveProtoPic(pce);
+
+ NMHDR nm = { hwndList, IDC_PROTOCOLS, NM_CLICK };
+ SendMessage(hwndDlg, WM_NOTIFY, 0, (LPARAM)&nm);
+ }
+ }
+ break;
+
+ case WM_DRAWITEM:
+ {
+ LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam;
+ if (dis->CtlType == ODT_BUTTON && dis->CtlID == IDC_PROTOPIC) {
+ AVATARDRAWREQUEST avdrq = { 0 };
+ avdrq.hTargetDC = dis->hDC;
+ avdrq.dwFlags |= AVDRQ_PROTOPICT;
+ avdrq.szProto = (g_selectedProto) ? g_selectedProto->szProtoname : nullptr;
+ GetClientRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), &avdrq.rcDraw);
+ CallService(MS_AV_DRAWAVATAR, 0, (LPARAM)&avdrq);
+ }
+ }
+ return TRUE;
+
+ case WM_NOTIFY:
+ if (dialoginit)
+ break;
+
+ switch (((LPNMHDR)lParam)->idFrom) {
+ case IDC_PROTOCOLS:
+ switch (((LPNMHDR)lParam)->code) {
+ case LVN_KEYDOWN:
+ {
+ NMLVKEYDOWN* ptkd = (NMLVKEYDOWN*)lParam;
+ if (ptkd&&ptkd->wVKey == VK_SPACE && ListView_GetSelectedCount(ptkd->hdr.hwndFrom) == 1)
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ }
+ break;
+
+ case LVN_ITEMCHANGED:
+ {
+ NMLISTVIEW *nmlv = (NMLISTVIEW *)lParam;
+ if (IsWindowVisible(GetDlgItem(hwndDlg, IDC_PROTOCOLS)) && ((nmlv->uNewState ^ nmlv->uOldState) & LVIS_STATEIMAGEMASK))
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ }
+ break;
+
+ case NM_CLICK:
+ EnableWindow(hwndChoosePic, TRUE);
+ EnableWindow(hwndRemovePic, TRUE);
+
+ int iItem = ListView_GetSelectionMark(hwndList);
+ g_selectedProto = GetProtoFromList(hwndDlg, iItem);
+ if (g_selectedProto) {
+ DBVARIANT dbv;
+ if (!db_get_ws(0, PPICT_MODULE, g_selectedProto->szProtoname, &dbv)) {
+ if (!PathIsAbsoluteW(VARSW(dbv.pwszVal))) {
+ wchar_t szFinalPath[MAX_PATH];
+ mir_snwprintf(szFinalPath, L"%%miranda_path%%\\%s", dbv.pwszVal);
+ SetDlgItemText(hwndDlg, IDC_PROTOAVATARNAME, szFinalPath);
+ }
+ else SetDlgItemText(hwndDlg, IDC_PROTOAVATARNAME, dbv.pwszVal);
+
+ InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), nullptr, TRUE);
+ db_free(&dbv);
+ }
+ else {
+ SetDlgItemText(hwndDlg, IDC_PROTOAVATARNAME, L"");
+ InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), nullptr, TRUE);
+ }
+ }
+ }
+ break;
+
+ case 0:
+ if (((LPNMHDR)lParam)->code == PSN_APPLY) {
+ for (int i = 0; i < ListView_GetItemCount(hwndList); i++) {
+ auto *pce = GetProtoFromList(hwndDlg, i);
+
+ BOOL oldVal = g_plugin.getByte(pce->szProtoname, 1);
+ BOOL newVal = ListView_GetCheckState(hwndList, i);
+
+ if (oldVal && !newVal)
+ for (auto &hContact : Contacts(pce->szProtoname))
+ DeleteAvatarFromCache(hContact, TRUE);
+
+ if (newVal)
+ g_plugin.setByte(pce->szProtoname, 1);
+ else
+ g_plugin.setByte(pce->szProtoname, 0);
+ }
+ }
+ }
+ break;
+ }
+ return FALSE;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Module entry point
+
+int OptInit(WPARAM wParam, LPARAM)
+{
+ OPTIONSDIALOGPAGE odp = {};
+ odp.flags = ODPF_BOLDGROUPS;
+ odp.szGroup.a = LPGEN("Contacts");
+ odp.szTitle.a = LPGEN("Avatars");
+
+ odp.szTab.a = LPGEN("Protocols");
+ odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS_PICTS);
+ odp.pfnDlgProc = DlgProcOptionsProtos;
+ g_plugin.addOptions(wParam, &odp);
+
+ odp.szTab.a = LPGEN("Contact avatars");
+ odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS_AVATARS);
+ odp.pfnDlgProc = DlgProcOptionsAvatars;
+ g_plugin.addOptions(wParam, &odp);
+
+ odp.szTab.a = LPGEN("Own avatars");
+ odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS_OWN);
+ odp.pfnDlgProc = DlgProcOptionsOwn;
+ g_plugin.addOptions(wParam, &odp);
+ return 0;
+}
diff --git a/plugins/AVS/src/poll.cpp b/plugins/AVS/src/poll.cpp
index 16b16c65dc..80b1e46ae3 100644
--- a/plugins/AVS/src/poll.cpp
+++ b/plugins/AVS/src/poll.cpp
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2012-22 Miranda NG team (https://miranda-ng.org)
+Copyright (C) 2012-23 Miranda NG team (https://miranda-ng.org)
Copyright (C) 2006 Ricardo Pescuma Domenecci, Nightwish
This is free software; you can redistribute it and/or
diff --git a/plugins/AVS/src/poll.h b/plugins/AVS/src/poll.h
index 3a9c049485..70eaed598d 100644
--- a/plugins/AVS/src/poll.h
+++ b/plugins/AVS/src/poll.h
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2012-22 Miranda NG team (https://miranda-ng.org)
+Copyright (C) 2012-23 Miranda NG team (https://miranda-ng.org)
Copyright (C) 2006 Ricardo Pescuma Domenecci, Nightwish
This is free software; you can redistribute it and/or
diff --git a/plugins/AVS/src/services.cpp b/plugins/AVS/src/services.cpp
index 544e521b4e..0c11763074 100644
--- a/plugins/AVS/src/services.cpp
+++ b/plugins/AVS/src/services.cpp
@@ -2,7 +2,7 @@
Miranda NG: the free IM client for Microsoft* Windows*
-Copyright (C) 2012-22 Miranda NG team (https://miranda-ng.org)
+Copyright (C) 2012-23 Miranda NG team (https://miranda-ng.org)
Copyright (c) 2000-04 Miranda ICQ/IM project,
all portions of this codebase are copyrighted to the people
listed in contributors.txt.
diff --git a/plugins/AVS/src/stdafx.cxx b/plugins/AVS/src/stdafx.cxx
index f64d25234b..ebbde0ade1 100644
--- a/plugins/AVS/src/stdafx.cxx
+++ b/plugins/AVS/src/stdafx.cxx
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2012-22 Miranda NG team (https://miranda-ng.org)
+Copyright (C) 2012-23 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
diff --git a/plugins/AVS/src/stdafx.h b/plugins/AVS/src/stdafx.h
index c43d83e32a..d8eb699e64 100644
--- a/plugins/AVS/src/stdafx.h
+++ b/plugins/AVS/src/stdafx.h
@@ -2,7 +2,7 @@
Miranda NG: the free IM client for Microsoft* Windows*
-Copyright (C) 2012-22 Miranda NG team (https://miranda-ng.org)
+Copyright (C) 2012-23 Miranda NG team (https://miranda-ng.org)
Copyright (c) 2000-04 Miranda ICQ/IM project,
all portions of this codebase are copyrighted to the people
listed in contributors.txt.
diff --git a/plugins/AVS/src/userInfo.cpp b/plugins/AVS/src/userInfo.cpp
index 36eadc75d6..d5e69533d0 100644
--- a/plugins/AVS/src/userInfo.cpp
+++ b/plugins/AVS/src/userInfo.cpp
@@ -1,485 +1,485 @@
-/*
-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"
-
-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
-{
- HANDLE hHook = nullptr;
-
- CCtrlSpin spinPoints, spinDifference;
- CCtrlCheck chkTransparent;
- CCtrlButton btnHide, btnChange, btnDefaults, btnProtect, btnReset, btnDelete;
-
- void ReloadAvatar()
- {
- SaveTransparentData(m_hwnd, m_hContact, IsDlgButtonChecked(m_hwnd, IDC_PROTECTAVATAR));
- ChangeAvatar(m_hContact, true);
- }
-
- INT_PTR OnChangeAvatar(UINT, WPARAM, LPARAM)
- {
- InvalidateRect(GetDlgItem(m_hwnd, IDC_PROTOPIC), nullptr, TRUE);
- return 0;
- }
-
- UI_MESSAGE_MAP(AvatarUserInfoDlg, CUserInfoPageDlg);
- UI_MESSAGE(DM_AVATARCHANGED, OnChangeAvatar);
- UI_MESSAGE_MAP_END();
-
-public:
- AvatarUserInfoDlg() :
- CUserInfoPageDlg(g_plugin, IDD_USER_AVATAR),
- btnHide(this, IDC_HIDEAVATAR),
- btnReset(this, IDC_RESET),
- btnChange(this, IDC_CHANGE),
- btnDelete(this, IDC_DELETE),
- btnProtect(this, IDC_PROTECTAVATAR),
- btnDefaults(this, ID_USE_DEFAULTS),
- chkTransparent(this, IDC_MAKETRANSPBKG),
- spinPoints(this, IDC_BKG_NUM_POINTS_SPIN, 8, 2),
- spinDifference(this, IDC_BKG_NUM_POINTS_SPIN, 100)
- {
- btnHide.OnClick = Callback(this, &AvatarUserInfoDlg::onClick_Hide);
- btnReset.OnClick = Callback(this, &AvatarUserInfoDlg::onClick_Reset);
- btnChange.OnClick = Callback(this, &AvatarUserInfoDlg::onClick_Change);
- btnDelete.OnClick = Callback(this, &AvatarUserInfoDlg::onClick_Delete);
- btnProtect.OnClick = Callback(this, &AvatarUserInfoDlg::onClick_Protect);
- btnDefaults.OnClick = Callback(this, &AvatarUserInfoDlg::onClick_UseDefaults);
-
- chkTransparent.OnChange = Callback(this, &AvatarUserInfoDlg::onChange_Transparent);
- }
-
- bool OnInitDialog() override
- {
- hHook = HookEventMessage(ME_AV_AVATARCHANGED, m_hwnd, DM_AVATARCHANGED);
-
- if (m_hContact != 0)
- btnDelete.Hide();
-
- LoadTransparentData(m_hwnd, GetContactThatHaveTheAvatar(m_hContact));
- return true;
- }
-
- bool OnRefresh() override
- {
- HWND protopic = GetDlgItem(m_hwnd, IDC_PROTOPIC);
- SendMessage(protopic, AVATAR_SETCONTACT, 0, m_hContact);
- SendMessage(protopic, AVATAR_SETAVATARBORDERCOLOR, 0, GetSysColor(COLOR_BTNSHADOW));
- SendMessage(protopic, AVATAR_SETNOAVATARTEXT, 0, (LPARAM)LPGENW("Contact has no avatar"));
- SendMessage(protopic, AVATAR_RESPECTHIDDEN, 0, FALSE);
- SendMessage(protopic, AVATAR_SETRESIZEIFSMALLER, 0, FALSE);
-
- 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;
- }
-
- bool IsEmpty() const override
- {
- auto wszFileName(db_get_wsm(m_hContact, "ContactPhoto", "File"));
- return (wszFileName.IsEmpty() || _waccess(wszFileName, 0) != 0);
- }
-
- void OnDestroy() override
- {
- UnhookEvent(hHook);
- }
-
- void onClick_UseDefaults(CCtrlButton *)
- {
- m_hContact = GetContactThatHaveTheAvatar(m_hContact);
-
- db_unset(m_hContact, "ContactPhoto", "MakeTransparentBkg");
- db_unset(m_hContact, "ContactPhoto", "TranspBkgNumPoints");
- db_unset(m_hContact, "ContactPhoto", "TranspBkgColorDiff");
-
- LoadTransparentData(m_hwnd, m_hContact);
- ReloadAvatar();
- }
-
- void onClick_Change(CCtrlButton *)
- {
- SetAvatar(m_hContact, 0);
- CheckDlgButton(m_hwnd, IDC_PROTECTAVATAR, db_get_b(m_hContact, "ContactPhoto", "Locked", 0) ? BST_CHECKED : BST_UNCHECKED);
- }
-
- void onClick_Hide(CCtrlButton *)
- {
- bool hidden = IsDlgButtonChecked(m_hwnd, IDC_HIDEAVATAR) != 0;
- SetAvatarAttribute(m_hContact, AVS_HIDEONCLIST, hidden);
- if (hidden != Contact::IsHidden(m_hContact))
- Contact::Hide(m_hContact, hidden);
- }
-
- void onClick_Protect(CCtrlButton *)
- {
- BOOL locked = IsDlgButtonChecked(m_hwnd, IDC_PROTECTAVATAR);
- SaveTransparentData(m_hwnd, m_hContact, locked);
- ProtectAvatar(m_hContact, locked ? 1 : 0);
- }
-
- void onChange_Transparent(CCtrlCheck *)
- {
- BOOL enable = IsDlgButtonChecked(m_hwnd, IDC_MAKETRANSPBKG);
- 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();
- }
-
- 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)) {
- DeleteFile(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");
-
- char *szProto = Proto_GetBaseAccountName(m_hContact);
- db_unset(m_hContact, szProto, "AvatarHash");
- DeleteAvatarFromCache(m_hContact, FALSE);
-
- QueueAdd(m_hContact);
- }
-
- void onClick_Delete(CCtrlButton *)
- {
- ProtectAvatar(m_hContact, 0);
- 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 };
- if (!db_get_ws(m_hContact, "ContactPhoto", "File", &dbv)) {
- DeleteFile(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);
- }
-};
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// Protocol avatar dialog
-
-class AvatarProtoInfoDlg : public CUserInfoPageDlg
-{
- char* GetSelectedProtocol()
- {
- // Get selection
- int iItem = protocols.GetSelectionMark();
- if (iItem < 0)
- return nullptr;
-
- // Get protocol name
- LVITEM item = {0};
- item.mask = LVIF_PARAM;
- item.iItem = iItem;
- SendMessage(protocols.GetHwnd(), LVM_GETITEMA, 0, (LPARAM)&item);
- return (char *)item.lParam;
- }
-
- void OffsetWindow(int iCtrlId, int dx)
- {
- HWND hwnd = GetDlgItem(m_hwnd, iCtrlId);
-
- RECT rc;
- GetWindowRect(hwnd, &rc);
- ScreenToClient(m_hwnd, &rc);
- OffsetRect(&rc, dx, 0);
- MoveWindow(hwnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE);
- }
-
- void EnableDisableControls(char *proto)
- {
- if (chkPerProto.IsChecked()) {
- if (proto == nullptr) {
- EnableWindow(GetDlgItem(m_hwnd, IDC_CHANGE), FALSE);
- EnableWindow(GetDlgItem(m_hwnd, IDC_DELETE), FALSE);
- }
- else {
- if (!ProtoServiceExists(proto, PS_SETMYAVATAR)) {
- EnableWindow(GetDlgItem(m_hwnd, IDC_CHANGE), FALSE);
- EnableWindow(GetDlgItem(m_hwnd, IDC_DELETE), FALSE);
- }
- else {
- EnableWindow(GetDlgItem(m_hwnd, IDC_CHANGE), TRUE);
-
- int width, height;
- SendDlgItemMessage(m_hwnd, IDC_PROTOPIC, AVATAR_GETUSEDSPACE, (WPARAM)&width, (LPARAM)&height);
- EnableWindow(GetDlgItem(m_hwnd, IDC_DELETE), (LPARAM)width != 0 || height != 0);
- }
- }
- }
- else {
- EnableWindow(GetDlgItem(m_hwnd, IDC_CHANGE), TRUE);
-
- if (g_plugin.getByte("GlobalUserAvatarNotConsistent", 1))
- EnableWindow(GetDlgItem(m_hwnd, IDC_DELETE), TRUE);
- else {
- int width, height;
- SendDlgItemMessage(m_hwnd, IDC_PROTOPIC, AVATAR_GETUSEDSPACE, (WPARAM)&width, (LPARAM)&height);
- EnableWindow(GetDlgItem(m_hwnd, IDC_DELETE), (LPARAM)width != 0 || height != 0);
- }
- }
- }
-
- CCtrlCheck chkPerProto;
- CCtrlButton btnChange, btnDelete;
- CCtrlListView protocols;
-
-public:
- AvatarProtoInfoDlg() :
- CUserInfoPageDlg(g_plugin, IDD_PROTO_AVATARS),
- protocols(this, IDC_PROTOCOLS),
- btnChange(this, IDC_CHANGE),
- btnDelete(this, IDC_DELETE),
- chkPerProto(this, IDC_PER_PROTO)
- {
- protocols.OnItemChanged = Callback(this, &AvatarProtoInfoDlg::onItemChanged_List);
-
- btnChange.OnClick = Callback(this, &AvatarProtoInfoDlg::onClick_Change);
- btnDelete.OnClick = Callback(this, &AvatarProtoInfoDlg::onClick_Delete);
-
- CreateLink(chkPerProto, g_plugin.bPerProto);
- chkPerProto.OnChange = Callback(this, &AvatarProtoInfoDlg::onChange_PerProto);
- }
-
- bool OnInitDialog() override
- {
- HWND protopic = GetDlgItem(m_hwnd, IDC_PROTOPIC);
- SendMessage(protopic, AVATAR_SETAVATARBORDERCOLOR, 0, (LPARAM)GetSysColor(COLOR_BTNSHADOW));
- SendMessage(protopic, AVATAR_SETNOAVATARTEXT, 0, (LPARAM)LPGENW("No avatar"));
- SendMessage(protopic, AVATAR_SETRESIZEIFSMALLER, 0, (LPARAM)FALSE);
-
- protocols.SetExtendedListViewStyleEx(0, LVS_EX_SUBITEMIMAGES);
-
- HIMAGELIST hIml = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 4, 0);
- protocols.SetImageList(hIml, LVSIL_SMALL);
-
- LVCOLUMN lvc = { 0 };
- lvc.mask = LVCF_FMT;
- lvc.fmt = LVCFMT_IMAGE | LVCFMT_LEFT;
- protocols.InsertColumn(0, &lvc);
-
- LVITEM item = { 0 };
- item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
- item.iItem = 1000;
-
- // List protocols
- int num = 0;
- for (auto &it : Accounts()) {
- if (!ProtoServiceExists(it->szModuleName, PS_GETMYAVATAR))
- continue;
-
- if (!Proto_IsAvatarsEnabled(it->szModuleName))
- continue;
-
- ImageList_AddIcon(hIml, Skin_LoadProtoIcon(it->szModuleName, ID_STATUS_ONLINE));
- item.pszText = it->tszAccountName;
- item.iImage = num;
- item.lParam = (LPARAM)it->szModuleName;
- protocols.InsertItem(&item);
- num++;
- }
-
- protocols.SetCurSel(0);
- protocols.SetColumnWidth(0, LVSCW_AUTOSIZE);
- protocols.Arrange(LVA_ALIGNLEFT | LVA_ALIGNTOP);
- return true;
- }
-
- void onItemChanged_List(CCtrlListView::TEventInfo *ev)
- {
- LPNMLISTVIEW li = ev->nmlv;
- if (li->uNewState & LVIS_SELECTED) {
- SendDlgItemMessage(m_hwnd, IDC_PROTOPIC, AVATAR_SETPROTOCOL, 0, li->lParam);
- EnableDisableControls((char*)li->lParam);
- }
- }
-
- INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override
- {
- if (msg == WM_NOTIFY) {
- LPNMHDR hdr = (LPNMHDR)lParam;
- if (hdr->idFrom == IDC_PROTOPIC && hdr->code == NM_AVATAR_CHANGED)
- EnableDisableControls(GetSelectedProtocol());
- }
- return CDlgBase::DlgProc(msg, wParam, lParam);
- }
-
- void onClick_Change(CCtrlButton *)
- {
- if (!chkPerProto.IsChecked())
- SetMyAvatar(NULL, NULL);
- else {
- char *proto = GetSelectedProtocol();
- if (proto != nullptr)
- SetMyAvatar((WPARAM)proto, NULL);
- }
- }
-
- void onClick_Delete(CCtrlButton *)
- {
- if (!chkPerProto.IsChecked()) {
- if (MessageBox(m_hwnd, TranslateT("Are you sure you want to remove your avatar?"), TranslateT("Global avatar"), MB_YESNO) == IDYES)
- SetMyAvatar(NULL, (LPARAM)L"");
- }
- else {
- if (char *proto = GetSelectedProtocol()) {
- char description[256];
- CallProtoService(proto, PS_GETNAME, _countof(description), (LPARAM)description);
- wchar_t *descr = mir_a2u(description);
- if (MessageBox(m_hwnd, TranslateT("Are you sure you want to remove your avatar?"), descr, MB_YESNO) == IDYES)
- SetMyAvatar((WPARAM)proto, (LPARAM)L"");
- mir_free(descr);
- }
- }
- }
-
- void onChange_PerProto(CCtrlCheck *pCheck)
- {
- int diff = 147; // Pre-calc
-
- if (chkPerProto.IsChecked()) {
- if (!IsWindowVisible(protocols.GetHwnd())) {
- // Show list of protocols
- protocols.Show();
-
- // Move controls
- OffsetWindow(IDC_PROTOPIC, diff);
- OffsetWindow(IDC_CHANGE, diff);
- OffsetWindow(IDC_DELETE, diff);
- }
-
- char *proto = GetSelectedProtocol();
- if (proto == nullptr) {
- protocols.SetItemState(0, LVIS_FOCUSED | LVIS_SELECTED, 0x0F);
- }
- else {
- SendDlgItemMessage(m_hwnd, IDC_PROTOPIC, AVATAR_SETPROTOCOL, 0, (LPARAM)proto);
- EnableDisableControls(proto);
- }
- }
- else {
- if (!m_bInitialized) {
- PostMessage(m_hwnd, WM_COMMAND, IDC_PER_PROTO, 0);
- }
- else if (!pCheck || IsWindowVisible(protocols.GetHwnd())) {
- // Hide list of protocols
- protocols.Hide();
-
- // Move controls
- OffsetWindow(IDC_PROTOPIC, -diff);
- OffsetWindow(IDC_CHANGE, -diff);
- OffsetWindow(IDC_DELETE, -diff);
- }
-
- SendDlgItemMessage(m_hwnd, IDC_PROTOPIC, AVATAR_SETPROTOCOL, 0, NULL);
- }
- }
-};
-
-int OnDetailsInit(WPARAM wParam, LPARAM hContact)
-{
- USERINFOPAGE uip = {};
- uip.szTitle.a = LPGEN("Avatar");
- uip.flags = ODPF_ICON;
- uip.dwInitParam = (LPARAM)g_plugin.getIconHandle(IDI_AVATAR);
-
- if (hContact == NULL) {
- // User dialog
- uip.pDialog = new AvatarProtoInfoDlg();
- g_plugin.addUserInfo(wParam, &uip);
- }
- else {
- char *szProto = Proto_GetBaseAccountName(hContact);
- if (szProto == nullptr || g_plugin.getByte(szProto, 1)) {
- // Contact dialog
- uip.position = -2000000000;
- uip.pDialog = new AvatarUserInfoDlg();
- g_plugin.addUserInfo(wParam, &uip);
- }
- }
- return 0;
-}
+/*
+Copyright (C) 2012-23 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"
+
+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
+{
+ HANDLE hHook = nullptr;
+
+ CCtrlSpin spinPoints, spinDifference;
+ CCtrlCheck chkTransparent;
+ CCtrlButton btnHide, btnChange, btnDefaults, btnProtect, btnReset, btnDelete;
+
+ void ReloadAvatar()
+ {
+ SaveTransparentData(m_hwnd, m_hContact, IsDlgButtonChecked(m_hwnd, IDC_PROTECTAVATAR));
+ ChangeAvatar(m_hContact, true);
+ }
+
+ INT_PTR OnChangeAvatar(UINT, WPARAM, LPARAM)
+ {
+ InvalidateRect(GetDlgItem(m_hwnd, IDC_PROTOPIC), nullptr, TRUE);
+ return 0;
+ }
+
+ UI_MESSAGE_MAP(AvatarUserInfoDlg, CUserInfoPageDlg);
+ UI_MESSAGE(DM_AVATARCHANGED, OnChangeAvatar);
+ UI_MESSAGE_MAP_END();
+
+public:
+ AvatarUserInfoDlg() :
+ CUserInfoPageDlg(g_plugin, IDD_USER_AVATAR),
+ btnHide(this, IDC_HIDEAVATAR),
+ btnReset(this, IDC_RESET),
+ btnChange(this, IDC_CHANGE),
+ btnDelete(this, IDC_DELETE),
+ btnProtect(this, IDC_PROTECTAVATAR),
+ btnDefaults(this, ID_USE_DEFAULTS),
+ chkTransparent(this, IDC_MAKETRANSPBKG),
+ spinPoints(this, IDC_BKG_NUM_POINTS_SPIN, 8, 2),
+ spinDifference(this, IDC_BKG_NUM_POINTS_SPIN, 100)
+ {
+ btnHide.OnClick = Callback(this, &AvatarUserInfoDlg::onClick_Hide);
+ btnReset.OnClick = Callback(this, &AvatarUserInfoDlg::onClick_Reset);
+ btnChange.OnClick = Callback(this, &AvatarUserInfoDlg::onClick_Change);
+ btnDelete.OnClick = Callback(this, &AvatarUserInfoDlg::onClick_Delete);
+ btnProtect.OnClick = Callback(this, &AvatarUserInfoDlg::onClick_Protect);
+ btnDefaults.OnClick = Callback(this, &AvatarUserInfoDlg::onClick_UseDefaults);
+
+ chkTransparent.OnChange = Callback(this, &AvatarUserInfoDlg::onChange_Transparent);
+ }
+
+ bool OnInitDialog() override
+ {
+ hHook = HookEventMessage(ME_AV_AVATARCHANGED, m_hwnd, DM_AVATARCHANGED);
+
+ if (m_hContact != 0)
+ btnDelete.Hide();
+
+ LoadTransparentData(m_hwnd, GetContactThatHaveTheAvatar(m_hContact));
+ return true;
+ }
+
+ bool OnRefresh() override
+ {
+ HWND protopic = GetDlgItem(m_hwnd, IDC_PROTOPIC);
+ SendMessage(protopic, AVATAR_SETCONTACT, 0, m_hContact);
+ SendMessage(protopic, AVATAR_SETAVATARBORDERCOLOR, 0, GetSysColor(COLOR_BTNSHADOW));
+ SendMessage(protopic, AVATAR_SETNOAVATARTEXT, 0, (LPARAM)LPGENW("Contact has no avatar"));
+ SendMessage(protopic, AVATAR_RESPECTHIDDEN, 0, FALSE);
+ SendMessage(protopic, AVATAR_SETRESIZEIFSMALLER, 0, FALSE);
+
+ 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;
+ }
+
+ bool IsEmpty() const override
+ {
+ auto wszFileName(db_get_wsm(m_hContact, "ContactPhoto", "File"));
+ return (wszFileName.IsEmpty() || _waccess(wszFileName, 0) != 0);
+ }
+
+ void OnDestroy() override
+ {
+ UnhookEvent(hHook);
+ }
+
+ void onClick_UseDefaults(CCtrlButton *)
+ {
+ m_hContact = GetContactThatHaveTheAvatar(m_hContact);
+
+ db_unset(m_hContact, "ContactPhoto", "MakeTransparentBkg");
+ db_unset(m_hContact, "ContactPhoto", "TranspBkgNumPoints");
+ db_unset(m_hContact, "ContactPhoto", "TranspBkgColorDiff");
+
+ LoadTransparentData(m_hwnd, m_hContact);
+ ReloadAvatar();
+ }
+
+ void onClick_Change(CCtrlButton *)
+ {
+ SetAvatar(m_hContact, 0);
+ CheckDlgButton(m_hwnd, IDC_PROTECTAVATAR, db_get_b(m_hContact, "ContactPhoto", "Locked", 0) ? BST_CHECKED : BST_UNCHECKED);
+ }
+
+ void onClick_Hide(CCtrlButton *)
+ {
+ bool hidden = IsDlgButtonChecked(m_hwnd, IDC_HIDEAVATAR) != 0;
+ SetAvatarAttribute(m_hContact, AVS_HIDEONCLIST, hidden);
+ if (hidden != Contact::IsHidden(m_hContact))
+ Contact::Hide(m_hContact, hidden);
+ }
+
+ void onClick_Protect(CCtrlButton *)
+ {
+ BOOL locked = IsDlgButtonChecked(m_hwnd, IDC_PROTECTAVATAR);
+ SaveTransparentData(m_hwnd, m_hContact, locked);
+ ProtectAvatar(m_hContact, locked ? 1 : 0);
+ }
+
+ void onChange_Transparent(CCtrlCheck *)
+ {
+ BOOL enable = IsDlgButtonChecked(m_hwnd, IDC_MAKETRANSPBKG);
+ 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();
+ }
+
+ 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)) {
+ DeleteFile(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");
+
+ char *szProto = Proto_GetBaseAccountName(m_hContact);
+ db_unset(m_hContact, szProto, "AvatarHash");
+ DeleteAvatarFromCache(m_hContact, FALSE);
+
+ QueueAdd(m_hContact);
+ }
+
+ void onClick_Delete(CCtrlButton *)
+ {
+ ProtectAvatar(m_hContact, 0);
+ 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 };
+ if (!db_get_ws(m_hContact, "ContactPhoto", "File", &dbv)) {
+ DeleteFile(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);
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Protocol avatar dialog
+
+class AvatarProtoInfoDlg : public CUserInfoPageDlg
+{
+ char* GetSelectedProtocol()
+ {
+ // Get selection
+ int iItem = protocols.GetSelectionMark();
+ if (iItem < 0)
+ return nullptr;
+
+ // Get protocol name
+ LVITEM item = {0};
+ item.mask = LVIF_PARAM;
+ item.iItem = iItem;
+ SendMessage(protocols.GetHwnd(), LVM_GETITEMA, 0, (LPARAM)&item);
+ return (char *)item.lParam;
+ }
+
+ void OffsetWindow(int iCtrlId, int dx)
+ {
+ HWND hwnd = GetDlgItem(m_hwnd, iCtrlId);
+
+ RECT rc;
+ GetWindowRect(hwnd, &rc);
+ ScreenToClient(m_hwnd, &rc);
+ OffsetRect(&rc, dx, 0);
+ MoveWindow(hwnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE);
+ }
+
+ void EnableDisableControls(char *proto)
+ {
+ if (chkPerProto.IsChecked()) {
+ if (proto == nullptr) {
+ EnableWindow(GetDlgItem(m_hwnd, IDC_CHANGE), FALSE);
+ EnableWindow(GetDlgItem(m_hwnd, IDC_DELETE), FALSE);
+ }
+ else {
+ if (!ProtoServiceExists(proto, PS_SETMYAVATAR)) {
+ EnableWindow(GetDlgItem(m_hwnd, IDC_CHANGE), FALSE);
+ EnableWindow(GetDlgItem(m_hwnd, IDC_DELETE), FALSE);
+ }
+ else {
+ EnableWindow(GetDlgItem(m_hwnd, IDC_CHANGE), TRUE);
+
+ int width, height;
+ SendDlgItemMessage(m_hwnd, IDC_PROTOPIC, AVATAR_GETUSEDSPACE, (WPARAM)&width, (LPARAM)&height);
+ EnableWindow(GetDlgItem(m_hwnd, IDC_DELETE), (LPARAM)width != 0 || height != 0);
+ }
+ }
+ }
+ else {
+ EnableWindow(GetDlgItem(m_hwnd, IDC_CHANGE), TRUE);
+
+ if (g_plugin.getByte("GlobalUserAvatarNotConsistent", 1))
+ EnableWindow(GetDlgItem(m_hwnd, IDC_DELETE), TRUE);
+ else {
+ int width, height;
+ SendDlgItemMessage(m_hwnd, IDC_PROTOPIC, AVATAR_GETUSEDSPACE, (WPARAM)&width, (LPARAM)&height);
+ EnableWindow(GetDlgItem(m_hwnd, IDC_DELETE), (LPARAM)width != 0 || height != 0);
+ }
+ }
+ }
+
+ CCtrlCheck chkPerProto;
+ CCtrlButton btnChange, btnDelete;
+ CCtrlListView protocols;
+
+public:
+ AvatarProtoInfoDlg() :
+ CUserInfoPageDlg(g_plugin, IDD_PROTO_AVATARS),
+ protocols(this, IDC_PROTOCOLS),
+ btnChange(this, IDC_CHANGE),
+ btnDelete(this, IDC_DELETE),
+ chkPerProto(this, IDC_PER_PROTO)
+ {
+ protocols.OnItemChanged = Callback(this, &AvatarProtoInfoDlg::onItemChanged_List);
+
+ btnChange.OnClick = Callback(this, &AvatarProtoInfoDlg::onClick_Change);
+ btnDelete.OnClick = Callback(this, &AvatarProtoInfoDlg::onClick_Delete);
+
+ CreateLink(chkPerProto, g_plugin.bPerProto);
+ chkPerProto.OnChange = Callback(this, &AvatarProtoInfoDlg::onChange_PerProto);
+ }
+
+ bool OnInitDialog() override
+ {
+ HWND protopic = GetDlgItem(m_hwnd, IDC_PROTOPIC);
+ SendMessage(protopic, AVATAR_SETAVATARBORDERCOLOR, 0, (LPARAM)GetSysColor(COLOR_BTNSHADOW));
+ SendMessage(protopic, AVATAR_SETNOAVATARTEXT, 0, (LPARAM)LPGENW("No avatar"));
+ SendMessage(protopic, AVATAR_SETRESIZEIFSMALLER, 0, (LPARAM)FALSE);
+
+ protocols.SetExtendedListViewStyleEx(0, LVS_EX_SUBITEMIMAGES);
+
+ HIMAGELIST hIml = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 4, 0);
+ protocols.SetImageList(hIml, LVSIL_SMALL);
+
+ LVCOLUMN lvc = { 0 };
+ lvc.mask = LVCF_FMT;
+ lvc.fmt = LVCFMT_IMAGE | LVCFMT_LEFT;
+ protocols.InsertColumn(0, &lvc);
+
+ LVITEM item = { 0 };
+ item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
+ item.iItem = 1000;
+
+ // List protocols
+ int num = 0;
+ for (auto &it : Accounts()) {
+ if (!ProtoServiceExists(it->szModuleName, PS_GETMYAVATAR))
+ continue;
+
+ if (!Proto_IsAvatarsEnabled(it->szModuleName))
+ continue;
+
+ ImageList_AddIcon(hIml, Skin_LoadProtoIcon(it->szModuleName, ID_STATUS_ONLINE));
+ item.pszText = it->tszAccountName;
+ item.iImage = num;
+ item.lParam = (LPARAM)it->szModuleName;
+ protocols.InsertItem(&item);
+ num++;
+ }
+
+ protocols.SetCurSel(0);
+ protocols.SetColumnWidth(0, LVSCW_AUTOSIZE);
+ protocols.Arrange(LVA_ALIGNLEFT | LVA_ALIGNTOP);
+ return true;
+ }
+
+ void onItemChanged_List(CCtrlListView::TEventInfo *ev)
+ {
+ LPNMLISTVIEW li = ev->nmlv;
+ if (li->uNewState & LVIS_SELECTED) {
+ SendDlgItemMessage(m_hwnd, IDC_PROTOPIC, AVATAR_SETPROTOCOL, 0, li->lParam);
+ EnableDisableControls((char*)li->lParam);
+ }
+ }
+
+ INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override
+ {
+ if (msg == WM_NOTIFY) {
+ LPNMHDR hdr = (LPNMHDR)lParam;
+ if (hdr->idFrom == IDC_PROTOPIC && hdr->code == NM_AVATAR_CHANGED)
+ EnableDisableControls(GetSelectedProtocol());
+ }
+ return CDlgBase::DlgProc(msg, wParam, lParam);
+ }
+
+ void onClick_Change(CCtrlButton *)
+ {
+ if (!chkPerProto.IsChecked())
+ SetMyAvatar(NULL, NULL);
+ else {
+ char *proto = GetSelectedProtocol();
+ if (proto != nullptr)
+ SetMyAvatar((WPARAM)proto, NULL);
+ }
+ }
+
+ void onClick_Delete(CCtrlButton *)
+ {
+ if (!chkPerProto.IsChecked()) {
+ if (MessageBox(m_hwnd, TranslateT("Are you sure you want to remove your avatar?"), TranslateT("Global avatar"), MB_YESNO) == IDYES)
+ SetMyAvatar(NULL, (LPARAM)L"");
+ }
+ else {
+ if (char *proto = GetSelectedProtocol()) {
+ char description[256];
+ CallProtoService(proto, PS_GETNAME, _countof(description), (LPARAM)description);
+ wchar_t *descr = mir_a2u(description);
+ if (MessageBox(m_hwnd, TranslateT("Are you sure you want to remove your avatar?"), descr, MB_YESNO) == IDYES)
+ SetMyAvatar((WPARAM)proto, (LPARAM)L"");
+ mir_free(descr);
+ }
+ }
+ }
+
+ void onChange_PerProto(CCtrlCheck *pCheck)
+ {
+ int diff = 147; // Pre-calc
+
+ if (chkPerProto.IsChecked()) {
+ if (!IsWindowVisible(protocols.GetHwnd())) {
+ // Show list of protocols
+ protocols.Show();
+
+ // Move controls
+ OffsetWindow(IDC_PROTOPIC, diff);
+ OffsetWindow(IDC_CHANGE, diff);
+ OffsetWindow(IDC_DELETE, diff);
+ }
+
+ char *proto = GetSelectedProtocol();
+ if (proto == nullptr) {
+ protocols.SetItemState(0, LVIS_FOCUSED | LVIS_SELECTED, 0x0F);
+ }
+ else {
+ SendDlgItemMessage(m_hwnd, IDC_PROTOPIC, AVATAR_SETPROTOCOL, 0, (LPARAM)proto);
+ EnableDisableControls(proto);
+ }
+ }
+ else {
+ if (!m_bInitialized) {
+ PostMessage(m_hwnd, WM_COMMAND, IDC_PER_PROTO, 0);
+ }
+ else if (!pCheck || IsWindowVisible(protocols.GetHwnd())) {
+ // Hide list of protocols
+ protocols.Hide();
+
+ // Move controls
+ OffsetWindow(IDC_PROTOPIC, -diff);
+ OffsetWindow(IDC_CHANGE, -diff);
+ OffsetWindow(IDC_DELETE, -diff);
+ }
+
+ SendDlgItemMessage(m_hwnd, IDC_PROTOPIC, AVATAR_SETPROTOCOL, 0, NULL);
+ }
+ }
+};
+
+int OnDetailsInit(WPARAM wParam, LPARAM hContact)
+{
+ USERINFOPAGE uip = {};
+ uip.szTitle.a = LPGEN("Avatar");
+ uip.flags = ODPF_ICON;
+ uip.dwInitParam = (LPARAM)g_plugin.getIconHandle(IDI_AVATAR);
+
+ if (hContact == NULL) {
+ // User dialog
+ uip.pDialog = new AvatarProtoInfoDlg();
+ g_plugin.addUserInfo(wParam, &uip);
+ }
+ else {
+ char *szProto = Proto_GetBaseAccountName(hContact);
+ if (szProto == nullptr || g_plugin.getByte(szProto, 1)) {
+ // Contact dialog
+ uip.position = -2000000000;
+ uip.pDialog = new AvatarUserInfoDlg();
+ g_plugin.addUserInfo(wParam, &uip);
+ }
+ }
+ return 0;
+}
diff --git a/plugins/AVS/src/utils.cpp b/plugins/AVS/src/utils.cpp
index f820d870a1..975e3808b3 100644
--- a/plugins/AVS/src/utils.cpp
+++ b/plugins/AVS/src/utils.cpp
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2012-22 Miranda NG team (https://miranda-ng.org)
+Copyright (C) 2012-23 Miranda NG team (https://miranda-ng.org)
Copyright (C) 2006 Ricardo Pescuma Domenecci, Nightwish
This is free software; you can redistribute it and/or
diff --git a/plugins/AVS/src/version.h b/plugins/AVS/src/version.h
index d0bae7638f..b58daf865c 100644
--- a/plugins/AVS/src/version.h
+++ b/plugins/AVS/src/version.h
@@ -10,4 +10,4 @@
#define __DESCRIPTION "Loads and manages contact pictures for other plugins."
#define __AUTHOR "Nightwish, Pescuma"
#define __AUTHORWEB "https://miranda-ng.org/p/AVS"
-#define __COPYRIGHT "© 2000-2012 Miranda-IM project, 2012-22 Miranda NG team"
+#define __COPYRIGHT "© 2000-2012 Miranda-IM project, 2012-23 Miranda NG team"