diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2015-08-31 09:33:13 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2015-08-31 09:33:13 +0000 |
commit | c4e939d79b82b195604e48e8d1b794da4c42347f (patch) | |
tree | 7e733724ae420fab0d8bb485734f605b0f878456 /plugins/Toaster/src/services.cpp | |
parent | 9331a9d035bb1b2f9e08ef9141acad1e180fb70b (diff) |
Toaster: crash fixes, popup icons support
git-svn-id: http://svn.miranda-ng.org/main/trunk@15126 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Toaster/src/services.cpp')
-rw-r--r-- | plugins/Toaster/src/services.cpp | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/plugins/Toaster/src/services.cpp b/plugins/Toaster/src/services.cpp index c5eaf84f6a..6cc1b7569a 100644 --- a/plugins/Toaster/src/services.cpp +++ b/plugins/Toaster/src/services.cpp @@ -2,17 +2,16 @@ mir_cs csNotifications;
OBJLIST<ToastNotification> lstNotifications(1);
+wchar_t wszTempDir[MAX_PATH];
__forceinline bool isChatRoom(MCONTACT hContact)
{ return (db_get_b(hContact, GetContactProto(hContact), "ChatRoom", 0) == 1);
}
-wchar_t* SaveBitmap(HBITMAP bmp, const char *szProto)
+wchar_t* SaveBitmap(HBITMAP bmp, const char *szId)
{
- wchar_t wszSavePath[MAX_PATH], wszRelativePath[MAX_PATH];
- GetEnvironmentVariableW(L"TEMP", wszSavePath, MAX_PATH);
- mir_snwprintf(wszRelativePath, L"\\MirandaToaster.%s.png", _A2T(szProto));
- wcscat_s(wszSavePath, wszRelativePath);
+ wchar_t wszSavePath[MAX_PATH];
+ mir_snwprintf(wszSavePath, L"%s\\MirandaToaster.%s.png", wszTempDir, _A2T(szId));
if (!(GetFileAttributes(wszSavePath) < 0xFFFFFFF))
{
@@ -27,14 +26,13 @@ wchar_t* SaveBitmap(HBITMAP bmp, const char *szProto) return mir_wstrdup(wszSavePath);
}
-wchar_t* ProtoIcon(const char *szProto)
+wchar_t* SaveHIcon(HICON hIcon, const char *szId)
{
- HICON hIcon = Skin_LoadProtoIcon(szProto, ID_STATUS_ONLINE, 1);
wchar_t *wszResult = NULL;
ICONINFO icon;
if (GetIconInfo(hIcon, &icon))
{
- wszResult = SaveBitmap(icon.hbmColor, szProto);
+ wszResult = SaveBitmap(icon.hbmColor, szId);
DeleteObject(icon.hbmMask);
DeleteObject(icon.hbmColor);
@@ -42,6 +40,10 @@ wchar_t* ProtoIcon(const char *szProto) return wszResult;
}
+__forceinline wchar_t* ProtoIcon(const char *szProto)
+{ return SaveHIcon(Skin_LoadProtoIcon(szProto, ID_STATUS_ONLINE, 1), szProto);
+}
+
static void __cdecl OnToastNotificationClicked(void* arg)
{
callbackArg *cb = (callbackArg*)arg;
@@ -72,7 +74,7 @@ void __stdcall ShowToastNotification(void* p) ptrT imagePath;
callbackArg *arg = (callbackArg*)mir_calloc(sizeof(callbackArg));
- if (td->hContact)
+ if (td->hContact != NULL && td->hContact != INVALID_CONTACT_ID)
{
arg->hContact = td->hContact;
const char* szProto = GetContactProto(td->hContact);
@@ -85,14 +87,25 @@ void __stdcall ShowToastNotification(void* p) {
imagePath = mir_tstrdup(pai.filename);
}
- else
+ }
+
+ if (imagePath == NULL)
+ {
+ if (szProto)
{
imagePath = ProtoIcon(szProto);
}
+ else if (td->hIcon)
+ {
+ imagePath = SaveHIcon(td->hIcon, CMStringA(FORMAT, "%p", td->hIcon));
+ }
}
- else
+ }
+ else
+ {
+ if (td->hIcon)
{
- imagePath = ProtoIcon(szProto);
+ imagePath = SaveHIcon(td->hIcon, CMStringA(FORMAT, "%p", td->hIcon));
}
}
@@ -116,7 +129,7 @@ static INT_PTR CreatePopup(WPARAM wParam, LPARAM) ptrW text(mir_a2u(ppd->lpzText));
ptrW contactName(mir_a2u(ppd->lpzContactName));
- CallFunctionAsync(&ShowToastNotification, new ToastData(ppd->lchContact, contactName, text));
+ CallFunctionAsync(&ShowToastNotification, new ToastData(ppd->lchContact, contactName, text, ppd->lchIcon));
return 0;
}
@@ -124,7 +137,7 @@ static INT_PTR CreatePopup(WPARAM wParam, LPARAM) static INT_PTR CreatePopupW(WPARAM wParam, LPARAM)
{
POPUPDATAW *ppd = (POPUPDATAW*)wParam;
- CallFunctionAsync(&ShowToastNotification, new ToastData(ppd->lchContact, ppd->lpwzContactName, ppd->lpwzText));
+ CallFunctionAsync(&ShowToastNotification, new ToastData(ppd->lchContact, ppd->lpwzContactName, ppd->lpwzText, ppd->lchIcon));
return 0;
}
@@ -144,7 +157,7 @@ static INT_PTR CreatePopup2(WPARAM wParam, LPARAM) title = mir_a2u(ppd->lpzTitle);
}
- CallFunctionAsync(&ShowToastNotification, new ToastData(ppd->lchContact, title, text));
+ CallFunctionAsync(&ShowToastNotification, new ToastData(ppd->lchContact, title, text, ppd->lchIcon));
return 0;
}
|