summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/Toaster/src/services.cpp62
-rw-r--r--plugins/Toaster/src/stdafx.h3
-rw-r--r--plugins/Toaster/src/toast_event_handler.h1
-rw-r--r--plugins/Toaster/src/toast_notification.cpp40
-rw-r--r--plugins/Toaster/src/toast_notification.h2
-rw-r--r--plugins/Toaster/src/version.h2
6 files changed, 82 insertions, 28 deletions
diff --git a/plugins/Toaster/src/services.cpp b/plugins/Toaster/src/services.cpp
index 9c3d4b12bd..3369a2ffb8 100644
--- a/plugins/Toaster/src/services.cpp
+++ b/plugins/Toaster/src/services.cpp
@@ -7,6 +7,41 @@ __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 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);
+
+ if (!(GetFileAttributes(wszSavePath) < 0xFFFFFFF))
+ {
+ IMGSRVC_INFO isi = { sizeof(isi) };
+ isi.wszName = mir_wstrdup(wszSavePath);
+ isi.hbm = bmp;
+ isi.dwMask = IMGI_HBITMAP;
+ isi.fif = FREE_IMAGE_FORMAT::FIF_PNG;
+ CallService(MS_IMG_SAVE, (WPARAM)&isi, IMGL_WCHAR);
+ }
+
+ return mir_wstrdup(wszSavePath);
+}
+
+wchar_t* ProtoIcon(const char *szProto)
+{
+ HICON hIcon = Skin_LoadProtoIcon(szProto, ID_STATUS_ONLINE, 1);
+ wchar_t *wszResult = NULL;
+ ICONINFO icon;
+ if (GetIconInfo(hIcon, &icon))
+ {
+ wszResult = SaveBitmap(icon.hbmColor, szProto);
+
+ DeleteObject(icon.hbmMask);
+ DeleteObject(icon.hbmColor);
+ }
+ return wszResult;
+}
+
static void __cdecl OnToastNotificationClicked(void* arg)
{
callbackArg *cb = (callbackArg*)arg;
@@ -15,7 +50,7 @@ static void __cdecl OnToastNotificationClicked(void* arg)
{
if (!isChatRoom(hContact))
{
- CallService(MS_MSG_SENDMESSAGE, (WPARAM)hContact, (LPARAM)"");
+ CallService(MS_MSG_SENDMESSAGE, (WPARAM)hContact);
}
else
{
@@ -48,12 +83,33 @@ static void ShowToastNotification(TCHAR* text, TCHAR* title, MCONTACT hContact)
{
imagePath = mir_tstrdup(pai.filename);
}
+ else
+ {
+ imagePath = ProtoIcon(szProto);
+ }
+ }
+ else
+ {
+ imagePath = ProtoIcon(szProto);
}
}
arg->notification = new ToastNotification(text, title, imagePath);
- arg->notification->Show(new ToastEventHandler(OnToastNotificationClicked, arg));
- lstNotifications.insert(arg->notification);
+
+ HRESULT hr = arg->notification->Initialize();
+ if (SUCCEEDED(hr))
+ {
+ arg->notification->Show(new ToastEventHandler(OnToastNotificationClicked, arg));
+ lstNotifications.insert(arg->notification);
+ }
+ else
+ {
+#ifdef _DEBUG
+ DebugBreak();
+#else
+ Netlib_Logf(NULL, "Toaster: " __FUNCTION__ " failed: HRESULT = %lld", hr);
+#endif
+ }
}
static INT_PTR CreatePopup(WPARAM wParam, LPARAM)
diff --git a/plugins/Toaster/src/stdafx.h b/plugins/Toaster/src/stdafx.h
index f763765039..ac22e2cf5a 100644
--- a/plugins/Toaster/src/stdafx.h
+++ b/plugins/Toaster/src/stdafx.h
@@ -16,6 +16,9 @@
#include <m_popup.h>
#include <m_message.h>
#include <m_chat.h>
+#include <m_skin.h>
+#include <m_imgsrvc.h>
+#include <m_netlib.h>
#include "version.h"
#include "resource.h"
diff --git a/plugins/Toaster/src/toast_event_handler.h b/plugins/Toaster/src/toast_event_handler.h
index 8cf82b3e21..a5a616d81d 100644
--- a/plugins/Toaster/src/toast_event_handler.h
+++ b/plugins/Toaster/src/toast_event_handler.h
@@ -21,7 +21,6 @@ public:
IFACEMETHODIMP Invoke(_In_ ABI::Windows::UI::Notifications::IToastNotification* sender, _In_ IInspectable* args);
IFACEMETHODIMP Invoke(_In_ ABI::Windows::UI::Notifications::IToastNotification* /* sender */, _In_ ABI::Windows::UI::Notifications::IToastDismissedEventArgs* e);
IFACEMETHODIMP Invoke(_In_ ABI::Windows::UI::Notifications::IToastNotification* /* sender */, _In_ ABI::Windows::UI::Notifications::IToastFailedEventArgs* /* e */);
-
private:
ULONG _ref;
void* _arg;
diff --git a/plugins/Toaster/src/toast_notification.cpp b/plugins/Toaster/src/toast_notification.cpp
index 47f98dbf28..8c2eebf32b 100644
--- a/plugins/Toaster/src/toast_notification.cpp
+++ b/plugins/Toaster/src/toast_notification.cpp
@@ -3,13 +3,26 @@
ToastNotification::ToastNotification(_In_ wchar_t* text, _In_ wchar_t* caption, _In_ wchar_t* imagePath)
: _text(text), _caption(caption), _imagePath(imagePath)
{
-
}
ToastNotification::~ToastNotification()
{
}
+HRESULT ToastNotification::Initialize()
+{
+ HRESULT hr = Windows::Foundation::GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager).Get(), &notificationManager);
+ if (SUCCEEDED(hr))
+ {
+ hr = notificationManager->CreateToastNotifierWithId(StringReferenceWrapper(::AppUserModelID).Get(), &notifier);
+ if (SUCCEEDED(hr))
+ {
+ hr = Create(&notification);
+ }
+ }
+ return hr;
+}
+
HRESULT ToastNotification::GetNodeByTag(_In_ HSTRING tagName, _Outptr_ ABI::Windows::Data::Xml::Dom::IXmlNode **node, _In_ ABI::Windows::Data::Xml::Dom::IXmlDocument* xml)
{
Microsoft::WRL::ComPtr<ABI::Windows::Data::Xml::Dom::IXmlNodeList> nodeList;
@@ -152,15 +165,11 @@ HRESULT ToastNotification::Setup(_In_ ABI::Windows::Data::Xml::Dom::IXmlDocument
HRESULT ToastNotification::CreateXml(_Outptr_ ABI::Windows::Data::Xml::Dom::IXmlDocument** xml)
{
- Microsoft::WRL::ComPtr<ABI::Windows::UI::Notifications::IToastNotificationManagerStatics> notificationManager;
- HRESULT hr = Windows::Foundation::GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager).Get(), &notificationManager);
- if (FAILED(hr))
- RaiseException(static_cast<DWORD>(STATUS_INVALID_PARAMETER), EXCEPTION_NONCONTINUABLE, 0, nullptr);
-
ABI::Windows::UI::Notifications::ToastTemplateType templateId = _imagePath == nullptr
? ABI::Windows::UI::Notifications::ToastTemplateType_ToastText02
: ABI::Windows::UI::Notifications::ToastTemplateType_ToastImageAndText02;
- hr = notificationManager->GetTemplateContent(templateId, xml);
+
+ HRESULT hr = notificationManager->GetTemplateContent(templateId, xml);
if (FAILED(hr))
return hr;
@@ -177,9 +186,7 @@ HRESULT ToastNotification::CreateXml(_Outptr_ ABI::Windows::Data::Xml::Dom::IXml
wchar_t* textValues[] =
{
- _caption == nullptr
- ? L"Miranda NG"
- : _caption,
+ _caption == nullptr ? L"Miranda NG" : _caption,
_text
};
@@ -208,19 +215,6 @@ HRESULT ToastNotification::Show()
HRESULT ToastNotification::Show(_In_ ToastEventHandler* handler)
{
- Microsoft::WRL::ComPtr<ABI::Windows::UI::Notifications::IToastNotificationManagerStatics> notificationManager;
- HRESULT hr = Windows::Foundation::GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager).Get(), &notificationManager);
- if (FAILED(hr))
- return hr;
- //RaiseException(static_cast<DWORD>(STATUS_INVALID_PARAMETER), EXCEPTION_NONCONTINUABLE, 0, nullptr);
-
- hr = notificationManager->CreateToastNotifierWithId(StringReferenceWrapper(::AppUserModelID).Get(), &notifier);
- if (FAILED(hr))
- return hr;
- hr = Create(&notification);
- if (FAILED(hr))
- return hr;
-
EventRegistrationToken activatedToken, dismissedToken, failedToken;
Microsoft::WRL::ComPtr<ToastEventHandler> eventHandler(handler);
diff --git a/plugins/Toaster/src/toast_notification.h b/plugins/Toaster/src/toast_notification.h
index 0e4131b945..1f688744bd 100644
--- a/plugins/Toaster/src/toast_notification.h
+++ b/plugins/Toaster/src/toast_notification.h
@@ -8,6 +8,7 @@ private:
wchar_t* _caption;
wchar_t* _imagePath;
+ Microsoft::WRL::ComPtr<ABI::Windows::UI::Notifications::IToastNotificationManagerStatics> notificationManager;
Microsoft::WRL::ComPtr<ABI::Windows::UI::Notifications::IToastNotifier> notifier;
Microsoft::WRL::ComPtr<ABI::Windows::UI::Notifications::IToastNotification> notification;
@@ -25,6 +26,7 @@ public:
COLORREF foreground;
ToastNotification(_In_ wchar_t* text, _In_ wchar_t* caption = nullptr, _In_ wchar_t* imagePath = nullptr);
+ HRESULT Initialize();
~ToastNotification();
HRESULT Show();
diff --git a/plugins/Toaster/src/version.h b/plugins/Toaster/src/version.h
index 7a0f1cdd24..02dc95757d 100644
--- a/plugins/Toaster/src/version.h
+++ b/plugins/Toaster/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 11
#define __RELEASE_NUM 1
-#define __BUILD_NUM 0
+#define __BUILD_NUM 1
#include <stdver.h>