diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-08-31 20:36:18 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-08-31 20:36:18 +0000 |
commit | 0ed4c703d7de168e5f59c84cb7d447a42e27877e (patch) | |
tree | 20360ca25e42d4fd29e26ddbeeda5a46cb7a684e /plugins/Toaster/src/toast_notification.cpp | |
parent | 9f87be3ed2ddf7db63e7b5d554df84122e2b21bb (diff) |
Toaster: code cleanup
git-svn-id: http://svn.miranda-ng.org/main/trunk@15131 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Toaster/src/toast_notification.cpp')
-rw-r--r-- | plugins/Toaster/src/toast_notification.cpp | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/plugins/Toaster/src/toast_notification.cpp b/plugins/Toaster/src/toast_notification.cpp index af89e779d1..941bacbefc 100644 --- a/plugins/Toaster/src/toast_notification.cpp +++ b/plugins/Toaster/src/toast_notification.cpp @@ -1,5 +1,7 @@ #include "stdafx.h"
+using namespace Microsoft::WRL;
+
ToastNotification::ToastNotification(_In_ wchar_t* text, _In_ wchar_t* caption, _In_ wchar_t* imagePath)
: _text(text), _caption(caption), _imagePath(imagePath)
{
@@ -11,24 +13,15 @@ ToastNotification::~ToastNotification() HRESULT ToastNotification::Initialize()
{
- HRESULT hr = Windows::Foundation::GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager).Get(), ¬ificationManager);
- if (SUCCEEDED(hr))
- {
- hr = notificationManager->CreateToastNotifierWithId(StringReferenceWrapper(::AppUserModelID).Get(), ¬ifier);
- if (SUCCEEDED(hr))
- {
- hr = Create(¬ification);
- }
- }
- return hr;
+ CHECKHR(Windows::Foundation::GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager).Get(), ¬ificationManager));
+ CHECKHR(notificationManager->CreateToastNotifierWithId(StringReferenceWrapper(::AppUserModelID).Get(), ¬ifier))
+ return Create(¬ification);
}
HRESULT ToastNotification::CreateXml(_Outptr_ ABI::Windows::Data::Xml::Dom::IXmlDocument** xml)
{
- Microsoft::WRL::ComPtr<ABI::Windows::Data::Xml::Dom::IXmlDocumentIO> xmlDocument;
- HRESULT hr = Windows::Foundation::ActivateInstance(StringReferenceWrapper(RuntimeClass_Windows_Data_Xml_Dom_XmlDocument).Get(), &xmlDocument);
- if (FAILED(hr))
- return hr;
+ ComPtr<ABI::Windows::Data::Xml::Dom::IXmlDocumentIO> xmlDocument;
+ CHECKHR(Windows::Foundation::ActivateInstance(StringReferenceWrapper(RuntimeClass_Windows_Data_Xml_Dom_XmlDocument).Get(), &xmlDocument));
HXML xmlToast = xmlCreateNode(L"toast", NULL, 0);
HXML xmlAudioNode = xmlAddChild(xmlToast, L"audio", NULL);
@@ -57,25 +50,20 @@ HRESULT ToastNotification::CreateXml(_Outptr_ ABI::Windows::Data::Xml::Dom::IXml TCHAR *xtmp = xmlToString(xmlToast, NULL);
size_t xlen = mir_tstrlen(xtmp);
- hr = xmlDocument->LoadXml(StringReferenceWrapper(xtmp, xlen).Get());
- if (FAILED(hr))
- return hr;
+ CHECKHR(xmlDocument->LoadXml(StringReferenceWrapper(xtmp, xlen).Get()));
return xmlDocument.CopyTo(xml);
}
HRESULT ToastNotification::Create(_Outptr_ ABI::Windows::UI::Notifications::IToastNotification** _notification)
{
- Microsoft::WRL::ComPtr<ABI::Windows::Data::Xml::Dom::IXmlDocument> xml;
- HRESULT hr = CreateXml(&xml);
- if (FAILED(hr))
- return hr;
-
- Microsoft::WRL::ComPtr<ABI::Windows::UI::Notifications::IToastNotificationFactory> factory;
- hr = Windows::Foundation::GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotification).Get(), &factory);
- if (FAILED(hr))
- return hr;
- return hr = factory->CreateToastNotification(xml.Get(), _notification);
+ ComPtr<ABI::Windows::Data::Xml::Dom::IXmlDocument> xml;
+ CHECKHR(CreateXml(&xml));
+
+ ComPtr<ABI::Windows::UI::Notifications::IToastNotificationFactory> factory;
+ CHECKHR(Windows::Foundation::GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotification).Get(), &factory));
+
+ return factory->CreateToastNotification(xml.Get(), _notification);
}
HRESULT ToastNotification::Show()
@@ -86,7 +74,7 @@ HRESULT ToastNotification::Show() HRESULT ToastNotification::Show(_In_ ToastEventHandler* handler)
{
EventRegistrationToken activatedToken, dismissedToken, failedToken;
- Microsoft::WRL::ComPtr<ToastEventHandler> eventHandler(handler);
+ ComPtr<ToastEventHandler> eventHandler(handler);
notification->add_Activated(eventHandler.Get(), &activatedToken);
notification->add_Dismissed(eventHandler.Get(), &dismissedToken);
|