summaryrefslogtreecommitdiff
path: root/plugins/Toaster/src
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-08-18 18:46:06 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-08-18 18:46:06 +0000
commitc5a9bf1c331dab3e9a31abb1f9e5687fb280bf64 (patch)
tree550a479ca631694e20c5b7bdf539d7ae4f1e100f /plugins/Toaster/src
parentf54a8b0bfb54acef4454ccdb5ea8aff9d0cf3ef6 (diff)
Toaster: added MS_POPUP_QUERY service
git-svn-id: http://svn.miranda-ng.org/main/trunk@14990 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Toaster/src')
-rw-r--r--plugins/Toaster/src/main.cpp80
-rw-r--r--plugins/Toaster/src/services.cpp109
-rw-r--r--plugins/Toaster/src/stdafx.h2
-rw-r--r--plugins/Toaster/src/toast_notification.cpp19
-rw-r--r--plugins/Toaster/src/toast_notification.h2
-rw-r--r--plugins/Toaster/src/version.h2
6 files changed, 129 insertions, 85 deletions
diff --git a/plugins/Toaster/src/main.cpp b/plugins/Toaster/src/main.cpp
index 0f6265e293..c5cf1d04ca 100644
--- a/plugins/Toaster/src/main.cpp
+++ b/plugins/Toaster/src/main.cpp
@@ -29,91 +29,19 @@ DWORD WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID)
extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
{
OSVERSIONINFO osvi = { sizeof(OSVERSIONINFO) };
- //GetVersionEx(&osvi);
- //if (osvi.dwMajorVersion >= 6 && osvi.dwMinorVersion >= 2)
+ if (IsWinVer8Plus())
return &pluginInfo;
- //MessageBox(NULL, _T(MODULE" supports Windows 8 or higher"), _T(MODULE), MB_OK | MB_ICONERROR);
- //return NULL;
+ MessageBox(NULL, _T(MODULE" supports Windows 8 or higher"), _T(MODULE), MB_OK | MB_ICONERROR);
+ return NULL;
}
-static void __cdecl OnToastNotificationClicked(void* arg)
-{
- MCONTACT hContact = (MCONTACT)arg;
- if (hContact)
- CallService(MS_MSG_SENDMESSAGE, (WPARAM)hContact, (LPARAM)"");
-}
-
-static void ShowToastNotification(TCHAR* text, TCHAR* title, MCONTACT hContact)
-{
- ptrT imagePath;
- ToastEventHandler *eventHandler;
- /*if (hContact)
- {
- eventHandler = new ToastEventHandler(OnToastNotificationClicked, (void*)hContact);
-
- TCHAR avatarPath[MAX_PATH] = { 0 };
- const char* szProto = GetContactProto(hContact);
- if (ProtoServiceExists(szProto, PS_GETMYAVATAR))
- if (!CallProtoService(szProto, PS_GETMYAVATAR, (WPARAM)avatarPath, (LPARAM)MAX_PATH))
- imagePath = mir_tstrdup(avatarPath);
- }
- else*/
- eventHandler = new ToastEventHandler(nullptr);
-
- ToastNotification notification(text, title, imagePath);
- notification.Show(eventHandler);
-}
-
-static INT_PTR CreatePopup(WPARAM wParam, LPARAM)
-{
- POPUPDATA *ppd = (POPUPDATA*)wParam;
- ptrW text(mir_a2u(ppd->lpzText));
- ptrW contactName(mir_a2u(ppd->lpzContactName));
-
- ShowToastNotification(text, contactName, ppd->lchContact);
-
- return 0;
-}
-
-static INT_PTR CreatePopupW(WPARAM wParam, LPARAM)
-{
- POPUPDATAW *ppd = (POPUPDATAW*)wParam;
-
- ShowToastNotification(ppd->lpwzText, ppd->lpwzContactName, ppd->lchContact);
-
- return 0;
-}
-
-static INT_PTR CreatePopup2(WPARAM wParam, LPARAM)
-{
- POPUPDATA2 *ppd = (POPUPDATA2*)wParam;
-
- ptrW text, title;
- if (ppd->flags & PU2_UNICODE)
- {
- text = mir_wstrdup(ppd->lpwzText);
- title = mir_wstrdup(ppd->lpwzTitle);
- }
- else
- {
- text = mir_a2u(ppd->lpzText);
- title = mir_a2u(ppd->lpzTitle);
- }
-
- ShowToastNotification(text, title, ppd->lchContact);
-
- return 0;
-}
-
extern "C" int __declspec(dllexport) Load(void)
{
mir_getLP(&pluginInfo);
- CreateServiceFunction(MS_POPUP_ADDPOPUP, CreatePopup);
- CreateServiceFunction(MS_POPUP_ADDPOPUPW, CreatePopupW);
- CreateServiceFunction(MS_POPUP_ADDPOPUP2, CreatePopup2);
+ InitServices();
return 0;
}
diff --git a/plugins/Toaster/src/services.cpp b/plugins/Toaster/src/services.cpp
new file mode 100644
index 0000000000..e92256b656
--- /dev/null
+++ b/plugins/Toaster/src/services.cpp
@@ -0,0 +1,109 @@
+#include "stdafx.h"
+
+static void __cdecl OnToastNotificationClicked(void* arg)
+{
+ MCONTACT hContact = (MCONTACT)arg;
+ if (hContact)
+ CallService(MS_MSG_SENDMESSAGE, (WPARAM)hContact, (LPARAM)"");
+}
+
+static void ShowToastNotification(TCHAR* text, TCHAR* title, MCONTACT hContact)
+{
+ if (!db_get_b(0, "Popup", "ModuleIsEnabled", 1))
+ return;
+
+ ptrT imagePath;
+ ToastEventHandler *eventHandler;
+ if (hContact)
+ {
+ eventHandler = new ToastEventHandler(OnToastNotificationClicked, (void*)hContact);
+
+ TCHAR avatarPath[MAX_PATH] = { 0 };
+ const char* szProto = GetContactProto(hContact);
+ if (ProtoServiceExists(szProto, PS_GETMYAVATAR))
+ if (!CallProtoService(szProto, PS_GETMYAVATAR, (WPARAM)avatarPath, (LPARAM)MAX_PATH))
+ imagePath = mir_tstrdup(avatarPath);
+ }
+ else
+ eventHandler = new ToastEventHandler(nullptr);
+
+ ToastNotification notification(text, title, imagePath);
+ notification.Show(eventHandler);
+}
+
+static INT_PTR CreatePopup(WPARAM wParam, LPARAM)
+{
+ POPUPDATA *ppd = (POPUPDATA*)wParam;
+ ptrW text(mir_a2u(ppd->lpzText));
+ ptrW contactName(mir_a2u(ppd->lpzContactName));
+
+ ShowToastNotification(text, contactName, ppd->lchContact);
+
+ return 0;
+}
+
+static INT_PTR CreatePopupW(WPARAM wParam, LPARAM)
+{
+ POPUPDATAW *ppd = (POPUPDATAW*)wParam;
+
+ ShowToastNotification(ppd->lpwzText, ppd->lpwzContactName, ppd->lchContact);
+
+ return 0;
+}
+
+static INT_PTR CreatePopup2(WPARAM wParam, LPARAM)
+{
+ POPUPDATA2 *ppd = (POPUPDATA2*)wParam;
+
+ ptrW text, title;
+ if (ppd->flags & PU2_UNICODE)
+ {
+ text = mir_wstrdup(ppd->lpwzText);
+ title = mir_wstrdup(ppd->lpwzTitle);
+ }
+ else
+ {
+ text = mir_a2u(ppd->lpzText);
+ title = mir_a2u(ppd->lpzTitle);
+ }
+
+ ShowToastNotification(text, title, ppd->lchContact);
+
+ return 0;
+}
+
+static INT_PTR PopupQuery(WPARAM wParam, LPARAM)
+{
+ 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);
+ return enabled;
+ }
+ break;
+
+ case PUQS_GETSTATUS:
+ return db_get_b(0, "Popup", "ModuleIsEnabled", 1);
+
+ default:
+ return 1;
+ }
+
+ return 0;
+}
+
+void InitServices()
+{
+ CreateServiceFunction(MS_POPUP_ADDPOPUP, CreatePopup);
+ CreateServiceFunction(MS_POPUP_ADDPOPUPW, CreatePopupW);
+ CreateServiceFunction(MS_POPUP_ADDPOPUP2, CreatePopup2);
+ CreateServiceFunction(MS_POPUP_QUERY, PopupQuery);
+}
diff --git a/plugins/Toaster/src/stdafx.h b/plugins/Toaster/src/stdafx.h
index f22ec15681..cdefdc6ccd 100644
--- a/plugins/Toaster/src/stdafx.h
+++ b/plugins/Toaster/src/stdafx.h
@@ -36,4 +36,6 @@ const wchar_t AppUserModelID[] = L"MirandaNG";
extern HINSTANCE g_hInstance;
+void InitServices();
+
#endif //_COMMON_H_
diff --git a/plugins/Toaster/src/toast_notification.cpp b/plugins/Toaster/src/toast_notification.cpp
index 856129f648..3430b404e0 100644
--- a/plugins/Toaster/src/toast_notification.cpp
+++ b/plugins/Toaster/src/toast_notification.cpp
@@ -3,10 +3,7 @@
ToastNotification::ToastNotification(_In_ wchar_t* text, _In_ wchar_t* caption, _In_ wchar_t* imagePath) throw()
: _text(text), _caption(caption), _imagePath(imagePath)
{
- 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);
+
}
ToastNotification::~ToastNotification()
@@ -157,10 +154,15 @@ 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;
- HRESULT hr = _notificationManager->GetTemplateContent(templateId, xml);
+ hr = notificationManager->GetTemplateContent(templateId, xml);
if (FAILED(hr))
return hr;
@@ -208,8 +210,13 @@ 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))
+ RaiseException(static_cast<DWORD>(STATUS_INVALID_PARAMETER), EXCEPTION_NONCONTINUABLE, 0, nullptr);
+
Microsoft::WRL::ComPtr<ABI::Windows::UI::Notifications::IToastNotifier> notifier;
- HRESULT hr = _notificationManager->CreateToastNotifierWithId(StringReferenceWrapper(::AppUserModelID).Get(), &notifier);
+ hr = notificationManager->CreateToastNotifierWithId(StringReferenceWrapper(::AppUserModelID).Get(), &notifier);
if (FAILED(hr))
return hr;
diff --git a/plugins/Toaster/src/toast_notification.h b/plugins/Toaster/src/toast_notification.h
index 4a9c7e16f8..2a3d438c74 100644
--- a/plugins/Toaster/src/toast_notification.h
+++ b/plugins/Toaster/src/toast_notification.h
@@ -8,8 +8,6 @@ private:
wchar_t* _caption;
wchar_t* _imagePath;
- Microsoft::WRL::ComPtr<ABI::Windows::UI::Notifications::IToastNotificationManagerStatics> _notificationManager;
-
HRESULT GetNodeByTag(_In_ HSTRING tagName, _Outptr_ ABI::Windows::Data::Xml::Dom::IXmlNode **node, _In_ ABI::Windows::Data::Xml::Dom::IXmlDocument* xml);
HRESULT AddNode(_In_ HSTRING name, _Outptr_ ABI::Windows::Data::Xml::Dom::IXmlNode **node, _In_ ABI::Windows::Data::Xml::Dom::IXmlNode *rootNode, _In_ ABI::Windows::Data::Xml::Dom::IXmlDocument* xml);
HRESULT SetNodeValueString(_In_ HSTRING inputString, _In_ ABI::Windows::Data::Xml::Dom::IXmlNode* node, _In_ ABI::Windows::Data::Xml::Dom::IXmlDocument* xml);
diff --git a/plugins/Toaster/src/version.h b/plugins/Toaster/src/version.h
index 15a4fa9c6e..5b2f4a42f1 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 0
-#define __BUILD_NUM 0
+#define __BUILD_NUM 1
#include <stdver.h>