diff options
| -rw-r--r-- | plugins/Toaster/src/images.h | 9 | ||||
| -rw-r--r-- | plugins/Toaster/src/services.cpp | 47 | ||||
| -rw-r--r-- | plugins/Toaster/src/stdafx.h | 64 | ||||
| -rw-r--r-- | plugins/Toaster/src/structs.h | 59 | ||||
| -rw-r--r-- | plugins/Toaster/src/toast_event_handler.cpp | 4 | ||||
| -rw-r--r-- | plugins/Toaster/src/toast_event_handler.h | 13 | 
6 files changed, 101 insertions, 95 deletions
diff --git a/plugins/Toaster/src/images.h b/plugins/Toaster/src/images.h index cc22359bc9..19d7fddc87 100644 --- a/plugins/Toaster/src/images.h +++ b/plugins/Toaster/src/images.h @@ -50,7 +50,14 @@ public:  			isi.hbm = _hBitmap;
  			isi.dwMask = IMGI_HBITMAP;
  			isi.fif = FREE_IMAGE_FORMAT::FIF_PNG;
 -			CallService(MS_IMG_SAVE, (WPARAM)&isi, IMGL_WCHAR);
 +			try
 +			{
 +				CallService(MS_IMG_SAVE, (WPARAM)&isi, IMGL_WCHAR);
 +			}
 +			catch (...)
 +			{
 +				return nullptr;
 +			}
  		}
  		return mir_wstrdup(wszSavePath);
  	}
 diff --git a/plugins/Toaster/src/services.cpp b/plugins/Toaster/src/services.cpp index 91e2e4aaa3..fca3a833e8 100644 --- a/plugins/Toaster/src/services.cpp +++ b/plugins/Toaster/src/services.cpp @@ -19,8 +19,7 @@ void __stdcall ShowToastNotification(void* p)  		if (ProtoServiceExists(szProto, PS_GETAVATARINFO))
  		{
 -			PROTO_AVATAR_INFORMATION pai = { 0 };
 -			pai.hContact = td->hContact;
 +			PROTO_AVATAR_INFORMATION pai = { td->hContact };
  			if (CallProtoService(szProto, PS_GETAVATARINFO, 0, (LPARAM)&pai) == GAIR_SUCCESS)
  			{
  				imagePath = mir_tstrdup(pai.filename);
 @@ -29,17 +28,20 @@ void __stdcall ShowToastNotification(void* p)  		if (imagePath == NULL)
  		{
 -			if (td->iType == 1 && td->hBitmap && !szProto)
 +			if (szProto)
  			{
 -				imagePath = ToasterImage(td->hBitmap);
 -			}
 -			else if (td->iType == 2 && td->hIcon && !szProto)
 -			{
 -				imagePath = ToasterImage(td->hIcon);
 +				imagePath = ToasterImage(szProto);
  			}
 -			else if (szProto)
 +			else
  			{
 -				imagePath = ToasterImage(szProto);
 +				if (td->iType == 1 && td->hBitmap)
 +				{
 +					imagePath = ToasterImage(td->hBitmap);
 +				}
 +				else if (td->iType == 2 && td->hIcon)
 +				{
 +					imagePath = ToasterImage(td->hIcon);
 +				}
  			}
  		}
  	}
 @@ -57,7 +59,7 @@ void __stdcall ShowToastNotification(void* p)  	if (SUCCEEDED(hr))
  	{
  		ToastHandlerData *thd = new ToastHandlerData();
 -		thd->hContact = td->hContact;
 +		thd->hContact   = td->hContact;
  		thd->vPopupData = td->vPopupData;
  		thd->pPopupProc = td->pPopupProc;
  		thd->tstNotification = notification;
 @@ -148,7 +150,7 @@ static INT_PTR RegisterClass(WPARAM, LPARAM lParam)  	mp_Classes[pc->pszName] = cd;
 -	return (INT_PTR)cd->handle;
 +	return (INT_PTR)cd;
  }
  static INT_PTR CreateClassPopup(WPARAM, LPARAM lParam)
 @@ -180,11 +182,10 @@ static INT_PTR CreateClassPopup(WPARAM, LPARAM lParam)  static INT_PTR UnRegisterClass(WPARAM, LPARAM lParam)
  {
 -	HANDLE h = (HANDLE)lParam;
  	for (auto it = mp_Classes.begin(); it != mp_Classes.end(); it++)
  	{
 -		if (it->second->handle == h)
 +		if (it->second == (void*)lParam)
  		{
  			delete it->second;
  			mp_Classes.erase(it);
 @@ -230,10 +231,24 @@ static INT_PTR PopupQuery(WPARAM wParam, LPARAM)  	}
  }
 -static INT_PTR ShowMessage(WPARAM wParam, LPARAM)
 +static INT_PTR ShowMessage(WPARAM wParam, LPARAM lParam)
  {
 +	HICON hIcon = NULL;
 +	switch (lParam)
 +	{
 +	case SM_WARNING:
 +		hIcon = Skin_LoadIcon(SKINICON_WARNING);
 +		break;
 +	case SM_ERROR:
 +		hIcon = Skin_LoadIcon(SKINICON_ERROR);
 +		break;
 +	case SM_NOTIFY:
 +		hIcon = Skin_LoadIcon(SKINICON_INFORMATION);
 +		break;
 +	}
 +
  	ptrT tszText(mir_utf8decodeT((char*)wParam));
 -	ToastData *td = new ToastData(NULL, NULL, tszText, HICON(0));
 +	ToastData *td = new ToastData(NULL, NULL, tszText, hIcon);
  	CallFunctionAsync(&ShowToastNotification, td);
 diff --git a/plugins/Toaster/src/stdafx.h b/plugins/Toaster/src/stdafx.h index a0b2a3509e..effea40186 100644 --- a/plugins/Toaster/src/stdafx.h +++ b/plugins/Toaster/src/stdafx.h @@ -25,11 +25,6 @@  #include "version.h"
  #include "resource.h"
 -__forceinline bool isChatRoom(MCONTACT hContact)
 -{
 -	return (db_get_b(hContact, GetContactProto(hContact), "ChatRoom", 0) == 1);
 -}
 -
  typedef void(__cdecl *pEventHandler)(void*);
  const wchar_t AppUserModelID[] = _T("MirandaNG");
  DEFINE_PROPERTYKEY(PKEY_AppUserModel_ID, 0x9F4C2855, 0x9F79, 0x4B39, 0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3, 5);
 @@ -38,12 +33,11 @@ DEFINE_PROPERTYKEY(PKEY_AppUserModel_ID, 0x9F4C2855, 0x9F79, 0x4B39, 0xA8, 0xD0,  #define CHECKHR(x) if (FAILED(x)) return x;
 -class ToastNotification;
 -
  #include "string_reference_wrapper.h"
  #include "toast_event_handler.h"
  #include "toast_notification.h"
  #include "add_to_start_menu.h"
 +#include "structs.h"
  #include "images.h"
  extern HINSTANCE g_hInstance;
 @@ -51,62 +45,6 @@ extern mir_cs csNotifications;  extern OBJLIST<ToastNotification> lstNotifications;
  extern wchar_t wszTempDir[MAX_PATH];
 -struct callbackArg
 -{
 -	MCONTACT hContact;
 -	ToastNotification* notification;
 -};
 -
 -struct ToastData
 -{
 -	MCONTACT hContact;
 -	TCHAR *tszTitle;
 -	TCHAR *tszText;
 -	union
 -	{
 -		HICON hIcon;
 -		HBITMAP hBitmap;
 -	};
 -	int iType; // 0 = none, 1 = hBitmap, 2 = hIcon
 -
 -	WNDPROC pPopupProc;
 -	void *vPopupData;
 -
 -	ToastData(MCONTACT _hContact, const TCHAR *_tszTitle, const TCHAR *_tszText, HICON _hIcon = NULL) : 
 -		hContact(_hContact),
 -		tszTitle(mir_tstrdup(_tszTitle)), 
 -		tszText(mir_tstrdup(_tszText)), 
 -		hIcon(_hIcon), 
 -		iType(_hIcon ? 2 : 0) 
 -	{}
 -	ToastData(MCONTACT _hContact, const TCHAR *_tszTitle, const TCHAR *_tszText, HBITMAP bmp = NULL) :
 -		hContact(_hContact),
 -		tszTitle(mir_tstrdup(_tszTitle)),
 -		tszText(mir_tstrdup(_tszText)),
 -		hBitmap(bmp),
 -		iType(bmp ? 1 : 0)
 -	{}
 -	~ToastData()
 -	{
 -		mir_free(tszTitle);
 -		mir_free(tszText);
 -	}
 -};
 -
 -struct ClassData
 -{
 -	int iFlags;
 -	HICON hIcon;
 -	HANDLE handle;
 -
 -	WNDPROC pPopupProc;
 -
 -	ClassData(int f, HICON h = NULL) : iFlags(f), hIcon(h) 
 -	{
 -		Utils_GetRandom(&handle, sizeof(handle));
 -	}
 -};
 -
  void CleanupClasses();
  void InitServices();
  int OnPreShutdown(WPARAM, LPARAM);
 diff --git a/plugins/Toaster/src/structs.h b/plugins/Toaster/src/structs.h new file mode 100644 index 0000000000..e74eb14bf1 --- /dev/null +++ b/plugins/Toaster/src/structs.h @@ -0,0 +1,59 @@ +#pragma once
 +
 +struct ToastData : public MZeroedObject
 +{
 +	MCONTACT hContact;
 +	TCHAR *tszTitle;
 +	TCHAR *tszText;
 +	union
 +	{
 +		HICON hIcon;
 +		HBITMAP hBitmap;
 +	};
 +	int iType; // 0 = none, 1 = hBitmap, 2 = hIcon
 +
 +	WNDPROC pPopupProc;
 +	void *vPopupData;
 +
 +	ToastData(MCONTACT _hContact, const TCHAR *_tszTitle, const TCHAR *_tszText, HICON _hIcon = NULL) : 
 +		hContact(_hContact),
 +		tszTitle(mir_tstrdup(_tszTitle)), 
 +		tszText(mir_tstrdup(_tszText)), 
 +		hIcon(_hIcon), 
 +		iType(_hIcon ? 2 : 0) 
 +	{}
 +	ToastData(MCONTACT _hContact, const TCHAR *_tszTitle, const TCHAR *_tszText, HBITMAP bmp = NULL) :
 +		hContact(_hContact),
 +		tszTitle(mir_tstrdup(_tszTitle)),
 +		tszText(mir_tstrdup(_tszText)),
 +		hBitmap(bmp),
 +		iType(bmp ? 1 : 0)
 +	{}
 +	~ToastData()
 +	{
 +		mir_free(tszTitle);
 +		mir_free(tszText);
 +	}
 +};
 +
 +struct ClassData : public MZeroedObject
 +{
 +	int iFlags;
 +	HICON hIcon;
 +
 +	WNDPROC pPopupProc;
 +
 +	ClassData(int f, HICON h = NULL) : iFlags(f), hIcon(h) 
 +	{
 +	}
 +};
 +
 +struct ToastHandlerData : public MZeroedObject
 +{
 +	MCONTACT hContact;
 +
 +	WNDPROC pPopupProc;
 +	void *vPopupData;
 +
 +	ToastNotification *tstNotification;
 +};
 diff --git a/plugins/Toaster/src/toast_event_handler.cpp b/plugins/Toaster/src/toast_event_handler.cpp index 485e5e5976..6d9da3952f 100644 --- a/plugins/Toaster/src/toast_event_handler.cpp +++ b/plugins/Toaster/src/toast_event_handler.cpp @@ -3,10 +3,6 @@  using namespace ABI::Windows::UI::Notifications;
  using namespace Microsoft::WRL;
 -ToastEventHandler::ToastEventHandler() : _ref(1)
 -{
 -}
 -
  ToastEventHandler::ToastEventHandler(_In_ ToastHandlerData *pData) : _ref(1), _thd(pData)
  {
  	if (_thd->pPopupProc)
 diff --git a/plugins/Toaster/src/toast_event_handler.h b/plugins/Toaster/src/toast_event_handler.h index 097a3d53c4..4405272f54 100644 --- a/plugins/Toaster/src/toast_event_handler.h +++ b/plugins/Toaster/src/toast_event_handler.h @@ -5,22 +5,13 @@ typedef ABI::Windows::Foundation::ITypedEventHandler<ABI::Windows::UI::Notificat  typedef ABI::Windows::Foundation::ITypedEventHandler<ABI::Windows::UI::Notifications::ToastNotification *, ABI::Windows::UI::Notifications::ToastDismissedEventArgs *> DesktopToastDismissedEventHandler;
  typedef ABI::Windows::Foundation::ITypedEventHandler<ABI::Windows::UI::Notifications::ToastNotification *, ABI::Windows::UI::Notifications::ToastFailedEventArgs *> DesktopToastFailedEventHandler;
 -struct ToastHandlerData : public MZeroedObject
 -{
 -	MCONTACT hContact;
 -
 -	WNDPROC pPopupProc;
 -	void *vPopupData;
 -
 -	ToastNotification *tstNotification;
 -};
 +struct ToastHandlerData;
  class ToastEventHandler : public Microsoft::WRL::Implements<DesktopToastActivatedEventHandler, DesktopToastDismissedEventHandler, DesktopToastFailedEventHandler>
  {
  public:
 -	ToastHandlerData *_thd;
 +	std::unique_ptr<ToastHandlerData> _thd;
 -	ToastEventHandler::ToastEventHandler();
  	ToastEventHandler::ToastEventHandler(_In_ ToastHandlerData *pData);
  	~ToastEventHandler();
  | 
