From 4dc918470c838072354fe22415669bd161fcdd13 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Mon, 4 Jan 2016 12:31:07 +0000 Subject: Toaster: more fixes, code cleanup git-svn-id: http://svn.miranda-ng.org/main/trunk@16017 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Toaster/src/services.cpp | 52 +++++++++++------------------- plugins/Toaster/src/toast_notification.cpp | 8 +++++ plugins/Toaster/src/toast_notification.h | 8 ++--- 3 files changed, 28 insertions(+), 40 deletions(-) (limited to 'plugins/Toaster') diff --git a/plugins/Toaster/src/services.cpp b/plugins/Toaster/src/services.cpp index f217367509..7f25162755 100644 --- a/plugins/Toaster/src/services.cpp +++ b/plugins/Toaster/src/services.cpp @@ -16,7 +16,6 @@ void __stdcall ShowToastNotification(void* p) if (td->hContact != NULL && td->hContact != INVALID_CONTACT_ID) { const char* szProto = GetContactProto(td->hContact); - if (ProtoServiceExists(szProto, PS_GETAVATARINFO)) { PROTO_AVATAR_INFORMATION pai = { td->hContact }; @@ -28,20 +27,11 @@ void __stdcall ShowToastNotification(void* p) if (imagePath == NULL) { - if (szProto) - { - imagePath = ToasterImage(szProto); - } + if (szProto) imagePath = ToasterImage(szProto); else { - if (td->iType == 1 && td->hBitmap) - { - imagePath = ToasterImage(td->hBitmap); - } - else if (td->iType == 2 && td->hIcon) - { - imagePath = ToasterImage(td->hIcon); - } + if (td->iType == 1 && td->hBitmap) imagePath = ToasterImage(td->hBitmap); + else if (td->iType == 2 && td->hIcon) imagePath = ToasterImage(td->hIcon); } } } @@ -53,7 +43,7 @@ void __stdcall ShowToastNotification(void* p) } } - new ToastNotification(td->tszText, td->tszTitle, imagePath, td->hContact, td->pPopupProc, td->vPopupData); + new (std::nothrow) ToastNotification(td->tszText, td->tszTitle, imagePath, td->hContact, td->pPopupProc, td->vPopupData); } static INT_PTR GetPopupData(WPARAM wParam, LPARAM) @@ -89,7 +79,7 @@ static INT_PTR CreatePopupW(WPARAM wParam, LPARAM) td->vPopupData = ppd->PluginData; td->pPopupProc = ppd->PluginWindowProc; - CallFunctionAsync(&ShowToastNotification, td); + CallFunctionAsync(ShowToastNotification, td); return 0; } @@ -119,12 +109,11 @@ static INT_PTR CreatePopup2(WPARAM wParam, LPARAM) td->vPopupData = ppd->PluginData; td->pPopupProc = ppd->PluginWindowProc; - CallFunctionAsync(&ShowToastNotification, td); - + CallFunctionAsync(ShowToastNotification, td); return 0; } -static INT_PTR RegisterClass(WPARAM, LPARAM lParam) +static INT_PTR RegisterPopupClass(WPARAM, LPARAM lParam) { POPUPCLASS *pc = (POPUPCLASS*)lParam; @@ -157,13 +146,13 @@ static INT_PTR CreateClassPopup(WPARAM, LPARAM lParam) td->vPopupData = ppc->PluginData; td->pPopupProc = it->second->pPopupProc; - CallFunctionAsync(&ShowToastNotification, td); + CallFunctionAsync(ShowToastNotification, td); } return 0; } -static INT_PTR UnRegisterClass(WPARAM, LPARAM lParam) +static INT_PTR UnRegisterPopupClass(WPARAM, LPARAM lParam) { for (auto it = mp_Classes.begin(); it != mp_Classes.end(); it++) { @@ -186,26 +175,23 @@ void CleanupClasses() static INT_PTR PopupQuery(WPARAM wParam, LPARAM) { - switch (wParam) { + switch (wParam) + { case PUQS_ENABLEPOPUPS: { bool enabled = db_get_b(0, "Popup", "ModuleIsEnabled", 1) != 0; if (!enabled) db_set_b(0, "Popup", "ModuleIsEnabled", 1); return !enabled; } - break; case PUQS_DISABLEPOPUPS: { bool enabled = db_get_b(0, "Popup", "ModuleIsEnabled", 1) != 0; if (enabled) db_set_b(0, "Popup", "ModuleIsEnabled", 0); - CallFunctionAsync(&HideAllToasts, NULL); + CallFunctionAsync(HideAllToasts, NULL); return enabled; } - break; - case PUQS_GETSTATUS: return db_get_b(0, "Popup", "ModuleIsEnabled", 1); - default: return 1; } @@ -228,7 +214,7 @@ static INT_PTR ShowMessageW(WPARAM wParam, LPARAM lParam) } ToastData *td = new ToastData(NULL, NULL, (wchar_t*)wParam, hIcon); - CallFunctionAsync(&ShowToastNotification, td); + CallFunctionAsync(ShowToastNotification, td); return 0; } @@ -242,16 +228,14 @@ static INT_PTR ShowMessage(WPARAM wParam, LPARAM lParam) static INT_PTR HideToast(WPARAM, LPARAM lParam) { ToastNotification* pNotification = reinterpret_cast(lParam); - mir_cslock lck(csNotifications); if (lstNotifications.getIndex(pNotification) != -1) - lstNotifications.remove(pNotification); + pNotification->Destroy(); return 0; } void __stdcall HideAllToasts(void*) { - mir_cslock lck(csNotifications); - while(lstNotifications.getCount()) - lstNotifications.remove(0); + while (lstNotifications.getCount()) + lstNotifications[0].Destroy(); } void InitServices() @@ -266,8 +250,8 @@ void InitServices() CreateServiceFunction(MS_POPUP_QUERY, PopupQuery); CreateServiceFunction(MS_POPUP_ADDPOPUPCLASS, CreateClassPopup); - CreateServiceFunction(MS_POPUP_REGISTERCLASS, RegisterClass); - CreateServiceFunction(MS_POPUP_UNREGISTERCLASS, UnRegisterClass); + CreateServiceFunction(MS_POPUP_REGISTERCLASS, RegisterPopupClass); + CreateServiceFunction(MS_POPUP_UNREGISTERCLASS, UnRegisterPopupClass); CreateServiceFunction(MS_POPUP_GETPLUGINDATA, GetPopupData); CreateServiceFunction(MS_POPUP_GETCONTACT, GetPopupContact); diff --git a/plugins/Toaster/src/toast_notification.cpp b/plugins/Toaster/src/toast_notification.cpp index 70a2872396..0708be6ec4 100644 --- a/plugins/Toaster/src/toast_notification.cpp +++ b/plugins/Toaster/src/toast_notification.cpp @@ -23,6 +23,7 @@ ToastNotification::ToastNotification( notification->add_Dismissed(Callback(this, &ToastNotification::OnDismiss).Get(), &_ertDismissed); notification->add_Failed(Callback(this, &ToastNotification::OnFail).Get(), &_ertFailed); notifier->Show(notification.Get()); + CallPopupProc(UM_INITPOPUP); } ToastNotification::~ToastNotification() @@ -101,4 +102,11 @@ HRESULT ToastNotification::OnFail(_In_ ABI::Windows::UI::Notifications::IToastNo { Destroy(); return S_OK; +} + +void ToastNotification::Destroy() +{ + CallPopupProc(UM_FREEPLUGINDATA); + mir_cslock lck(csNotifications); + lstNotifications.remove(this); } \ No newline at end of file diff --git a/plugins/Toaster/src/toast_notification.h b/plugins/Toaster/src/toast_notification.h index 2320cbce99..812c361810 100644 --- a/plugins/Toaster/src/toast_notification.h +++ b/plugins/Toaster/src/toast_notification.h @@ -13,7 +13,6 @@ private: WNDPROC _pfnPopupProc; void *_pvPopupData; - wchar_t* _text; wchar_t* _caption; wchar_t* _imagePath; @@ -33,11 +32,7 @@ public: ToastNotification(_In_ wchar_t* text, _In_ wchar_t* caption = nullptr, _In_ wchar_t* imagePath = nullptr, MCONTACT hContact = 0, WNDPROC pWndProc = nullptr, void *pData = nullptr); ~ToastNotification(); - inline void Destroy() - { mir_cslock lck(csNotifications); lstNotifications.remove(this); - } - - HRESULT OnActivate(_In_ ABI::Windows::UI::Notifications::IToastNotification*, IInspectable*); + HRESULT OnActivate(_In_ ABI::Windows::UI::Notifications::IToastNotification*, _In_ IInspectable*); HRESULT OnDismiss(_In_ ABI::Windows::UI::Notifications::IToastNotification*, _In_ ABI::Windows::UI::Notifications::IToastDismissedEventArgs*); HRESULT OnFail(_In_ ABI::Windows::UI::Notifications::IToastNotification*, _In_ ABI::Windows::UI::Notifications::IToastFailedEventArgs*); @@ -52,4 +47,5 @@ public: { return (_pfnPopupProc ? _pfnPopupProc((HWND)this, uMsg, 0, 0) : 0); } + void Destroy(); }; -- cgit v1.2.3