From ee22c7cde330254cd97adb9ce818b80d3b6bbbd8 Mon Sep 17 00:00:00 2001 From: Tobias Markmann <tm@ayena.de> Date: Tue, 12 Jul 2016 11:39:50 +0200 Subject: Remove Snarl notification support This removes Snarl from 3rdParty, our adapter to it in SwifTools and the integration in Swift UI. Test-Information: Builds and installer still work on Windows 8. Standard system tray balloon notifications still work. Change-Id: Id580642932eac260c79eaf2343a94ec9d5606f11 diff --git a/3rdParty/Snarl/SConscript b/3rdParty/Snarl/SConscript deleted file mode 100644 index a93282c..0000000 --- a/3rdParty/Snarl/SConscript +++ /dev/null @@ -1,18 +0,0 @@ -Import("env") - -################################################################################ -# Flags -################################################################################ - -if env.get("HAVE_SNARL", False) : - if env["SCONS_STAGE"] == "flags" : - env["SNARL_FLAGS"] = { - "CPPPATH": [Dir(".")], - "LIBPATH": [Dir(".")], - "LIBS": ["Snarl"], - } - - elif env["SCONS_STAGE"] == "build" : - myenv = env.Clone() - myenv.Replace(CCFLAGS = [flag for flag in env["CCFLAGS"] if flag not in ["-W", "-Wall"]]) - myenv.StaticLibrary("Snarl", ["SnarlInterface.cpp"], CPPPATH = ["."]) diff --git a/3rdParty/Snarl/SnarlInterface.cpp b/3rdParty/Snarl/SnarlInterface.cpp deleted file mode 100644 index 0ae0b37..0000000 --- a/3rdParty/Snarl/SnarlInterface.cpp +++ /dev/null @@ -1,517 +0,0 @@ -/// <summary> -/// Snarl C++ interface implementation -/// -/// Written and maintained by Toke Noer Nøttrup (toke@noer.it) -/// -/// Please note the following changes compared to the VB6 (official API) dokumentation: -/// - Function names doesn't have the prefix "sn". Naming of constants and variables are -/// generally changed to follow Microsoft C# standard. This naming convention is kept for -/// the C++ version, to keep them alike. -/// - Grouped variables like SNARL_LAUNCHED, SNARL_QUIT is enums in SnarlEnums namespace. -/// - Message events like SNARL_NOTIFICATION_CLICKED, is found in SnarlEnums::MessageEvent. -/// - Please note that string functions return NULL when they fail and not an empty string. -/// - Some functions in the VB API takes an appToken as first parameter. This token is a -/// member variable in C++ version, so it is omitted from the functions. -/// (Always call RegisterApp as first function!) -/// - Functions manipulating messages (Update, Hide etc.) still takes a message token as -/// parameter, but you can get the last message token calling GetLastMsgToken(); -/// Example: snarl.Hide(snarl.GetLastMsgToken()); -/// -/// The functions in SnarlInterface both have ANSI(UTF8) and UNICODE versions. -/// If the LPCWSTR (unicode) version of the functions are called, the strings -/// are converted to UTF8 by SnarlInterface before sent to Snarl. So using the -/// ANSI/UTF8/LPCSTR versions of the functions are faster! -/// -/// Funtions special to C++ V41 API compared to VB version: -/// GetLastMsgToken() -/// GetAppPath() -/// GetIconsPath() -/// </summary> -///---------------------------------------------------------------------------- -/// <example> -/// SnarlInterface snarl; -/// snarl.RegisterApp(_T("CppTest"), _T("C++ test app"), NULL); -/// snarl.AddClass(_T("Class1"), _T("Class 1")); -/// snarl.EZNotify(_T("Class1"), _T("C++ example 1"), _T("Some text"), 10); -/// snarl.UnregisterApp(); -/// -/// Please see the SimpleTest.cpp and SnarlV41Test.cpp for more example code. -/// </example> -///---------------------------------------------------------------------------- -/// <VersionHistory> -/// 2010-08-13 : First release of V41 Snarl API implementation -/// </VersionHistory> - -#define _CRT_SECURE_NO_WARNINGS - -#include "SnarlInterface.h" - - -namespace Snarl { -namespace V41 { - -//----------------------------------------------------------------------------- -// Constructor/Destructor -//----------------------------------------------------------------------------- -SnarlInterface::SnarlInterface() - : appToken(0), lastMsgToken(0), localError(SnarlEnums::Success) -{ -} - -SnarlInterface::~SnarlInterface() -{ -} - -// ---------------------------------------------------------------------------- - -LONG32 SnarlInterface::RegisterApp(LPCSTR signature, LPCSTR title, LPCSTR icon, HWND hWndReply /* = NULL */, LONG32 msgReply /* = 0 */, SnarlEnums::AppFlags flags /* = SnarlEnums::AppDefault */) -{ - SnarlMessage msg; - msg.Command = SnarlEnums::RegisterApp; - msg.Token = 0; - PackData(msg.PacketData, - "id::%s#?title::%s#?icon::%s#?hwnd::%d#?umsg::%d#?flags::%d", - signature, title, icon, hWndReply, msgReply, flags); - - appToken = Send(msg); - lastMsgToken = 0; - - return appToken; -} - -LONG32 SnarlInterface::RegisterApp(LPCWSTR signature, LPCWSTR title, LPCWSTR icon, HWND hWndReply /* = NULL */, LONG32 msgReply /* = 0 */, SnarlEnums::AppFlags flags /* = SnarlEnums::AppDefault */) -{ - LPCSTR szParam1 = WideToUTF8(signature); - LPCSTR szParam2 = WideToUTF8(title); - LPCSTR szParam3 = WideToUTF8(icon); - - LONG32 result = RegisterApp(szParam1, szParam2, szParam3, hWndReply, msgReply, flags); - - delete [] szParam1; - delete [] szParam2; - delete [] szParam3; - - return result; -} - -LONG32 SnarlInterface::UnregisterApp() -{ - SnarlMessage msg; - msg.Command = SnarlEnums::UnregisterApp; - msg.Token = appToken; - PackData(msg.PacketData, NULL); - - appToken = 0; - lastMsgToken = 0; - - return Send(msg); -} - -LONG32 SnarlInterface::UpdateApp(LPCSTR title /* = NULL */, LPCSTR icon /* = NULL */) -{ - if (title == NULL && icon == NULL) - return 0; - - SnarlMessage msg; - msg.Command = SnarlEnums::UpdateApp; - msg.Token = appToken; - - // TODO: Uckly code ahead - if (title != NULL && title[0] != 0 && icon != NULL && icon[0] != 0) - PackData(msg.PacketData, "title::%s#?icon::%s", title, icon); - else if (title != NULL && title[0] != 0) - PackData(msg.PacketData, "title::%s", title); - else if (icon != NULL && icon[0] != 0) - PackData(msg.PacketData, "icon::%s", icon); - - return Send(msg); -} - -LONG32 SnarlInterface::UpdateApp(LPCWSTR title /* = NULL */, LPCWSTR icon /* = NULL */) -{ - LPCSTR szParam1 = WideToUTF8(title); - LPCSTR szParam2 = WideToUTF8(icon); - - LONG32 result = UpdateApp(szParam1, szParam2); - - delete [] szParam1; - delete [] szParam2; - - return result; -} - -LONG32 SnarlInterface::AddClass(LPCSTR className, LPCSTR description, bool enabled /* = true */) -{ - SnarlMessage msg; - msg.Command = SnarlEnums::AddClass; - msg.Token = appToken; - PackData(msg.PacketData, "id::%s#?name::%s#?enabled::%d", className, description, (enabled ? 1 : 0)); - - return Send(msg); -} - -LONG32 SnarlInterface::AddClass(LPCWSTR className, LPCWSTR description, bool enabled /* = true */) -{ - LPCSTR szParam1 = WideToUTF8(className); - LPCSTR szParam2 = WideToUTF8(description); - - LONG32 result = AddClass(szParam1, szParam2, enabled); - - delete [] szParam1; - delete [] szParam2; - - return result; -} - -LONG32 SnarlInterface::RemoveClass(LPCSTR className, bool forgetSettings /* = false */) -{ - SnarlMessage msg; - msg.Command = SnarlEnums::RemoveClass; - msg.Token = appToken; - PackData(msg.PacketData, "id::%s#?forget::%d", className, (forgetSettings ? 1 : 0)); - - return Send(msg); -} - -LONG32 SnarlInterface::RemoveClass(LPCWSTR className, bool forgetSettings /* = false */) -{ - LPCSTR szParam1 = WideToUTF8(className); - - LONG32 result = RemoveClass(szParam1, forgetSettings); - - delete [] szParam1; - - return result; -} - -LONG32 SnarlInterface::RemoveAllClasses(bool forgetSettings /* = false */) -{ - SnarlMessage msg; - msg.Command = SnarlEnums::RemoveClass; - msg.Token = appToken; - PackData(msg.PacketData, "all::1#?forget::%d", (forgetSettings ? 1 : 0)); - - return Send(msg); -} - -LONG32 SnarlInterface::EZNotify(LPCSTR className, LPCSTR title, LPCSTR text, LONG32 timeout /* = -1 */, LPCSTR icon /* = NULL */, LONG32 priority /* = 0 */, LPCSTR acknowledge /* = NULL */, LPCSTR value /* = NULL */) -{ - SnarlMessage msg; - msg.Command = SnarlEnums::Notify; - msg.Token = appToken; - PackData(msg.PacketData, - "id::%s#?title::%s#?text::%s#?timeout::%d#?icon::%s#?priority::%d#?ack::%s#?value::%s", - className, title, text, timeout, (icon ? icon : ""), priority, (acknowledge ? acknowledge : ""), (value ? value : "")); - - lastMsgToken = Send(msg); - return lastMsgToken; -} - -LONG32 SnarlInterface::EZNotify(LPCWSTR className, LPCWSTR title, LPCWSTR text, LONG32 timeout /* = -1 */, LPCWSTR icon /* = NULL */, LONG32 priority /* = 0 */, LPCWSTR acknowledge /* = NULL */, LPCWSTR value /* = NULL */) -{ - LPCSTR szParam1 = WideToUTF8(className); - LPCSTR szParam2 = WideToUTF8(title); - LPCSTR szParam3 = WideToUTF8(text); - LPCSTR szParam4 = WideToUTF8(icon); - LPCSTR szParam5 = WideToUTF8(acknowledge); - LPCSTR szParam6 = WideToUTF8(value); - - LONG32 result = EZNotify(szParam1, szParam2, szParam3, timeout, szParam4, priority, szParam5, szParam6); - - delete [] szParam1; delete [] szParam2; delete [] szParam3; - delete [] szParam4; delete [] szParam5; delete [] szParam6; - - return result; -} - -LONG32 SnarlInterface::Notify(LPCSTR className, LPCSTR packetData) -{ - SnarlMessage msg; - msg.Command = SnarlEnums::Notify; - msg.Token = appToken; - PackData(msg.PacketData, "id::%s#?%s", className, packetData); - - lastMsgToken = Send(msg); - return lastMsgToken; -} - -LONG32 SnarlInterface::Notify(LPCWSTR className, LPCWSTR packetData) -{ - LPCSTR szParam1 = WideToUTF8(className); - LPCSTR szParam2 = WideToUTF8(packetData); - - LONG32 result = Notify(szParam1, szParam2); - - delete [] szParam1; delete [] szParam2; - - return result; -} - -LONG32 SnarlInterface::EZUpdate(LONG32 msgToken, LPCSTR title /* = NULL */, LPCSTR text /* = NULL */, LONG32 timeout /* = -1 */, LPCSTR icon /* = NULL */) -{ - SnarlMessage msg; - msg.Command = SnarlEnums::UpdateNotification; - msg.Token = msgToken; - - // Create packed data - errno_t err = 0; - ZeroMemory(msg.PacketData, sizeof(msg.PacketData)); - char* pData = reinterpret_cast<char*>(msg.PacketData); - - if (title != NULL) { - err |= strncat_s(pData, SnarlPacketDataSize, (pData[0] != NULL) ? "#?title::" : "title::", _TRUNCATE); //StringCbCat(tmp, SnarlPacketDataSize, "title::%s"); - err |= strncat_s(pData, SnarlPacketDataSize, title, _TRUNCATE); - } - if (text != NULL) { - err |= strncat_s(pData, SnarlPacketDataSize, (pData[0] != NULL) ? "#?text::" : "text::", _TRUNCATE); - err |= strncat_s(pData, SnarlPacketDataSize, text, _TRUNCATE); - } - if (icon != NULL) { - err |= strncat_s(pData, SnarlPacketDataSize, (pData[0] != NULL) ? "#?icon::" : "icon::", _TRUNCATE); - err |= strncat_s(pData, SnarlPacketDataSize, icon, _TRUNCATE); - } - if (timeout != -1) { - char tmp[32]; - _itoa_s(timeout, tmp, 10); - - err |= strncat_s(pData, SnarlPacketDataSize, (pData[0] != NULL) ? "#?timeout::" : "timeout::", _TRUNCATE); - err |= strncat_s(pData, SnarlPacketDataSize, tmp, _TRUNCATE); - } - - // Check for strcat errors and exit on error - if (err != 0) { - localError = SnarlEnums::ErrorFailed; - return 0; - } - - return Send(msg); -} - -LONG32 SnarlInterface::EZUpdate(LONG32 msgToken, LPCWSTR title /* = NULL */, LPCWSTR text /* = NULL */, LONG32 timeout /* = -1 */, LPCWSTR icon /* = NULL */) -{ - LPCSTR szParam1 = WideToUTF8(title); - LPCSTR szParam2 = WideToUTF8(text); - LPCSTR szParam3 = WideToUTF8(icon); - - LONG32 result = EZUpdate(msgToken, szParam1, szParam2, timeout, szParam3); - - delete [] szParam1; delete [] szParam2; delete [] szParam3; - - return result; -} - -LONG32 SnarlInterface::Update(LONG32 msgToken, LPCSTR packetData) -{ - SnarlMessage msg; - msg.Command = SnarlEnums::UpdateNotification; - msg.Token = msgToken; - PackData(msg.PacketData, packetData); - - return Send(msg); -} - -LONG32 SnarlInterface::Update(LONG32 msgToken, LPCWSTR packetData) -{ - LPCSTR szParam1 = WideToUTF8(packetData); - - LONG32 result = Update(msgToken, szParam1); - - delete [] szParam1; - - return result; -} - -LONG32 SnarlInterface::Hide(LONG32 msgToken) -{ - SnarlMessage msg; - msg.Command = SnarlEnums::HideNotification; - msg.Token = msgToken; - PackData(msg.PacketData, NULL); - - return Send(msg); -} - -LONG32 SnarlInterface::IsVisible(LONG32 msgToken) -{ - SnarlMessage msg; - msg.Command = SnarlEnums::IsNotificationVisible; - msg.Token = msgToken; - PackData(msg.PacketData, NULL); - - return Send(msg); -} - -SnarlEnums::SnarlStatus SnarlInterface::GetLastError() -{ - return localError; -} - -// static -BOOL SnarlInterface::IsSnarlRunning() -{ - return IsWindow(GetSnarlWindow()); -} - -LONG32 SnarlInterface::GetVersion() -{ - localError = SnarlEnums::Success; - - HWND hWnd = GetSnarlWindow(); - if (!IsWindow(hWnd)) - { - localError = SnarlEnums::ErrorNotRunning; - return 0; - } - - HANDLE hProp = GetProp(hWnd, _T("_version")); - return reinterpret_cast<int>(hProp); -} - -// static -UINT SnarlInterface::Broadcast() -{ - return RegisterWindowMessage(SnarlGlobalMsg); -} - -// static -UINT SnarlInterface::AppMsg() -{ - return RegisterWindowMessage(SnarlAppMsg); -} - -// static -HWND SnarlInterface::GetSnarlWindow() -{ - return FindWindow(SnarlWindowClass, SnarlWindowTitle);; -} - -LPCTSTR SnarlInterface::GetAppPath() -{ - HWND hWnd = GetSnarlWindow(); - if (hWnd) - { - HWND hWndPath = FindWindowEx(hWnd, NULL, _T("static"), NULL); - if (hWndPath) - { - TCHAR strTmp[MAX_PATH] = {0}; - int nReturn = GetWindowText(hWndPath, strTmp, MAX_PATH-1); - if (nReturn > 0) { - TCHAR* strReturn = AllocateString(nReturn + 1); - _tcsncpy(strReturn, strTmp, nReturn + 1); - strReturn[nReturn] = 0; - return strReturn; - } - } - } - - return NULL; -} - -LPCTSTR SnarlInterface::GetIconsPath() -{ - TCHAR* szIconPath = NULL; - LPCTSTR szPath = GetAppPath(); - if (!szPath) - return NULL; - - size_t nLen = 0; - // TODO: _tcsnlen MAX_PATH - if (nLen = _tcsnlen(szPath, MAX_PATH)) - { - nLen += 10 + 1; // etc\\icons\\ + NULL - szIconPath = AllocateString(nLen); - - _tcsncpy(szIconPath, szPath, nLen); - _tcsncat(szIconPath, _T("etc\\icons\\"), nLen); - } - - FreeString(szPath); - - return szIconPath; -} - -LONG32 SnarlInterface::GetLastMsgToken() const -{ - return lastMsgToken; -} - - -//----------------------------------------------------------------------------- -// Private functions -//----------------------------------------------------------------------------- - -LONG32 SnarlInterface::Send(SnarlMessage msg) -{ - DWORD_PTR nReturn = 0; // Failure - - HWND hWnd = GetSnarlWindow(); - if (!IsWindow(hWnd)) - { - localError = SnarlEnums::ErrorNotRunning; - return 0; - } - - COPYDATASTRUCT cds; - cds.dwData = 0x534E4C02; // "SNL",2; - cds.cbData = sizeof(SnarlMessage); - cds.lpData = &msg; - - if (SendMessageTimeout(hWnd, WM_COPYDATA, (WPARAM)GetCurrentProcessId(), (LPARAM)&cds, SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG, 500, &nReturn) == 0) - { - // return zero on failure - if (GetLastError() == ERROR_TIMEOUT) - localError = SnarlEnums::ErrorTimedOut; - else - localError = SnarlEnums::ErrorFailed; - - return 0; - } - - // return result and cache LastError - HANDLE hProp = GetProp(hWnd, _T("last_error")); - localError = static_cast<SnarlEnums::SnarlStatus>(reinterpret_cast<int>(hProp)); - - return nReturn; -} - -//----------------------------------------------------------------------------- - -// Remember to delete [] returned string -inline -LPSTR SnarlInterface::WideToUTF8(LPCWSTR szWideStr) -{ - if (szWideStr == NULL) - return NULL; - - int nSize = WideCharToMultiByte(CP_UTF8, 0, szWideStr, -1, NULL, 0, NULL, NULL); - LPSTR szUTF8 = new char[nSize]; - WideCharToMultiByte(CP_UTF8, 0, szWideStr, -1, szUTF8, nSize, NULL, NULL); - - return szUTF8; -} - -void SnarlInterface::PackData(BYTE* data, LPCSTR format, ...) -{ - // Always zero array - Used to clear the array in member functions - ZeroMemory(data, SnarlPacketDataSize); - - // Return if format string is empty - if (format == NULL || format[0] == 0) - return; - - int cchStrTextLen = 0; - va_list args; - va_start(args, format); - - // Get size of buffer - cchStrTextLen = _vscprintf(format, args) + 1; // + NULL - if (cchStrTextLen <= 1) - return; - - // Create formated string - _TRUNCATE will ensure zero terminated - _vsnprintf_s((char*)data, SnarlPacketDataSize, _TRUNCATE, format, args); - - va_end(args); -} - -}} // namespace Snarl::V41 diff --git a/3rdParty/Snarl/SnarlInterface.h b/3rdParty/Snarl/SnarlInterface.h deleted file mode 100644 index 9440451..0000000 --- a/3rdParty/Snarl/SnarlInterface.h +++ /dev/null @@ -1,276 +0,0 @@ -#ifndef SNARL_INTERFACE_V41 -#define SNARL_INTERFACE_V41 - -#include <tchar.h> -#include <windows.h> -#include <cstdio> - -#ifndef SMTO_NOTIMEOUTIFNOTHUNG - #define SMTO_NOTIMEOUTIFNOTHUNG 8 -#endif - - -namespace Snarl { - namespace V41 { - - static const LPCTSTR SnarlWindowClass = _T("w>Snarl"); - static const LPCTSTR SnarlWindowTitle = _T("Snarl"); - - static const LPCTSTR SnarlGlobalMsg = _T("SnarlGlobalEvent"); - static const LPCTSTR SnarlAppMsg = _T("SnarlAppMessage"); - - static const int SnarlPacketDataSize = 4096; - - // Enums put in own namespace, because ANSI C++ doesn't decorate enums with tagname :( - namespace SnarlEnums { - - /// <summary> - /// Global event identifiers. - /// Identifiers marked with a '*' are sent by Snarl in two ways: - /// 1. As a broadcast message (uMsg = 'SNARL_GLOBAL_MSG') - /// 2. To the window registered in snRegisterConfig() or snRegisterConfig2() - /// (uMsg = reply message specified at the time of registering) - /// In both cases these values appear in wParam. - /// - /// Identifiers not marked are not broadcast; they are simply sent to the application's registered window. - /// </summary> - enum GlobalEvent - { - SnarlLaunched = 1, // Snarl has just started running* - SnarlQuit = 2, // Snarl is about to stop running* - SnarlAskAppletVer = 3, // (R1.5) Reserved for future use - SnarlShowAppUi = 4 // (R1.6) Application should show its UI - }; - - /// <summary> - /// Message event identifiers. - /// These are sent by Snarl to the window specified in RegisterApp() when the - /// Snarl Notification raised times out or the user clicks on it. - /// </summary> - enum MessageEvent - { - NotificationClicked = 32, // Notification was right-clicked by user - NotificationCancelled = 32, // Added in V37 (R1.6) -- same value, just improved the meaning of it - NotificationTimedOut = 33, // - NotificationAck = 34, // Notification was left-clicked by user - NotificationMenu = 35, // Menu item selected (V39) - NotificationMiddleButton = 36, // Notification middle-clicked by user (V39) - NotificationClosed = 37 // User clicked the close gadget (V39) - }; - - /// <summary> - /// Error values returned by calls to GetLastError(). - /// </summary> - enum SnarlStatus - { - Success = 0, - - ErrorFailed = 101, // miscellaneous failure - ErrorUnknownCommand, // specified command not recognised - ErrorTimedOut, // Snarl took too long to respond - - ErrorArgMissing = 109, // required argument missing - ErrorSystem, // internal system error - - ErrorNotRunning = 201, // Snarl handling window not found - ErrorNotRegistered, // - ErrorAlreadyRegistered, // not used yet; RegisterApp() returns existing token - ErrorClassAlreadyExists, // not used yet; AddClass() returns existing token - ErrorClassBlocked, - ErrorClassNotFound, - ErrorNotificationNotFound - }; - - /// <summary> - /// Application flags - features this app supports. - /// </summary> - enum AppFlags - { - AppDefault = 0, - AppHasPrefs = 1, - AppHasAbout = 2, - AppIsWindowless = 0x8000 - }; - - enum SnarlCommand - { - RegisterApp = 1, - UnregisterApp, - UpdateApp, - SetCallback, - AddClass, - RemoveClass, - Notify, - UpdateNotification, - HideNotification, - IsNotificationVisible, - LastError // deprecated but retained for backwards compatability - }; - } - - struct SnarlMessage - { - SnarlEnums::SnarlCommand Command; - LONG32 Token; - BYTE PacketData[SnarlPacketDataSize]; - }; - - static const DWORD WM_SNARLTEST = WM_USER + 237; - - - // ------------------------------------------------------------------------ - /// SnarlInterface class definition - // ------------------------------------------------------------------------ - class SnarlInterface { - public: - SnarlInterface(); - ~SnarlInterface(); - - LPTSTR AllocateString(size_t n) { return new TCHAR[n]; } - void FreeString(LPTSTR str) { delete [] str; str = NULL; } - void FreeString(LPCTSTR str) { delete [] str; } - - /// <summary>Register application with Snarl.</summary> - /// <returns>The application token or 0 on failure.</returns> - /// <remarks>The application token is saved in SnarlInterface member variable, so just use return value to check for error.</remarks> - LONG32 RegisterApp(LPCSTR signature, LPCSTR title, LPCSTR icon, HWND hWndReply = NULL, LONG32 msgReply = 0, SnarlEnums::AppFlags flags = SnarlEnums::AppDefault); - LONG32 RegisterApp(LPCWSTR signature, LPCWSTR title, LPCWSTR icon, HWND hWndReply = NULL, LONG32 msgReply = 0, SnarlEnums::AppFlags flags = SnarlEnums::AppDefault); - - /// <summary>Unregister application with Snarl when application is closing.</summary> - /// <returns>0 on failure.</returns> - LONG32 UnregisterApp(); - - /// <summary>Update information provided when calling RegisterApp.</summary> - /// <returns>0 on failure.</returns> - LONG32 UpdateApp(LPCSTR title = NULL, LPCSTR icon = NULL); - LONG32 UpdateApp(LPCWSTR title = NULL, LPCWSTR icon = NULL); - - /// <summary>Add a notification class to Snarl.</summary> - /// <returns>0 on failure.</returns> - LONG32 AddClass(LPCSTR className, LPCSTR description, bool enabled = true); - LONG32 AddClass(LPCWSTR className, LPCWSTR description, bool enabled = true); - - /// <summary>Remove a notification class added with AddClass().</summary> - /// <returns>0 on failure.</returns> - LONG32 RemoveClass(LPCSTR className, bool forgetSettings = false); - LONG32 RemoveClass(LPCWSTR className, bool forgetSettings = false); - - /// <summary>Remove all notification classes in one call.</summary> - /// <returns>0 on failure.</returns> - LONG32 RemoveAllClasses(bool forgetSettings = false); - - /// <summary>Show a Snarl notification.</summary> - /// <returns>Returns the notification token or 0 on failure.</returns> - /// <remarks>You can use <see cref="GetLastMsgToken()" /> to get the last token.</remarks> - LONG32 EZNotify(LPCSTR className, LPCSTR title, LPCSTR text, LONG32 timeout = -1, LPCSTR icon = NULL, LONG32 priority = 0, LPCSTR acknowledge = NULL, LPCSTR value = NULL); - LONG32 EZNotify(LPCWSTR className, LPCWSTR title, LPCWSTR text, LONG32 timeout = -1, LPCWSTR icon = NULL, LONG32 priority = 0, LPCWSTR acknowledge = NULL, LPCWSTR value = NULL); - - /// <summary> - /// Show a Snarl notification. - /// This function requires that you write your own packet data. - /// </summary> - /// <returns>Returns the notification token or 0 on failure.</returns> - /// <remarks>You can use <see cref="GetLastMsgToken()" /> to get the last token.</remarks> - LONG32 Notify(LPCSTR className, LPCSTR packetData); - LONG32 Notify(LPCWSTR className, LPCWSTR packetData); - - /// <summary>Update the text or other parameters of a visible Snarl notification.</summary> - /// <returns>0 on failure.</returns> - LONG32 EZUpdate(LONG32 msgToken, LPCSTR title = NULL, LPCSTR text = NULL, LONG32 timeout = -1, LPCSTR icon = NULL); - LONG32 EZUpdate(LONG32 msgToken, LPCWSTR title = NULL, LPCWSTR text = NULL, LONG32 timeout = -1, LPCWSTR icon = NULL); - - /// <summary> - /// Update the text or other parameters of a visible Snarl notification. - /// This function requires that you write your own packet data. - /// </summary> - /// <returns>0 on failure.</returns> - LONG32 Update(LONG32 msgToken, LPCSTR packetData); - LONG32 Update(LONG32 msgToken, LPCWSTR packetData); - - /// <summary>Hide a Snarl notification.</summary> - /// <returns>0 on failure.</returns> - LONG32 Hide(LONG32 msgToken); - - /// <summary>Test if a Snarl notification is visible.</summary> - /// <returns>Returns -1 if message is visible. 0 if not visible or if an error occured.</returns> - LONG32 IsVisible(LONG32 msgToken); - - /// <summary>Get the last error from Snarl. Call after other functions return 0 to know why it failed.</summary> - /// <returns>Returns one of the SnarlEnums::SnarlStatus values.</returns> - SnarlEnums::SnarlStatus GetLastError(); - - /// <summary>Get Snarl version, if it is running.</summary> - /// <returns>Returns a number indicating Snarl version.</returns> - LONG32 GetVersion(); - - /// <summary> - /// Get the path to where Snarl is installed. - /// ** Remember to call <see cref="FreeString(LPCTSTR)" /> on the returned string !!! - /// </summary> - /// <returns>Returns the path to where Snarl is installed.</returns> - /// <remarks>This is a V39 API method.</remarks> - LPCTSTR GetAppPath(); - - /// <summary> - /// Get the path to where the default Snarl icons are located. - /// <para>** Remember to call <see cref="FreeString(LPCTSTR)" /> on the returned string !!!</para> - /// </summary> - /// <returns>Returns the path to where the default Snarl icons are located.</returns> - /// <remarks>This is a V39 API method.</remarks> - LPCTSTR GetIconsPath(); - - /// <summary>GetLastMsgToken() returns token of the last message sent to Snarl.</summary> - /// <returns>Returns message token of last message.</returns> - /// <remarks>This function is not in the official API!</remarks> - LONG32 GetLastMsgToken() const; - - /// <summary>Check whether Snarl is running</summary> - /// <returns>Returns true if Snarl system was found running.</returns> - static BOOL IsSnarlRunning(); - - /// <summary> - /// Returns the value of Snarl's global registered message. - /// Notes: - /// Snarl registers SNARL_GLOBAL_MSG during startup which it then uses to communicate - /// with all running applications through a Windows broadcast message. This function can - /// only fail if for some reason the Windows RegisterWindowMessage() function fails - /// - given this, this function *cannnot* be used to test for the presence of Snarl. - /// </summary> - /// <returns>A 16-bit value (translated to 32-bit) which is the registered Windows message for Snarl.</returns> - static UINT Broadcast(); - - /// <summary>Returns the global Snarl Application message (V39)</summary> - /// <returns>Returns Snarl application registered message.</returns> - static UINT AppMsg(); - - /// <summary>Returns a handle to the Snarl Dispatcher window (V37)</summary> - /// <returns>Returns handle to Snarl Dispatcher window, or zero if it's not found.</returns> - /// <remarks>This is now the preferred way to test if Snarl is actually running.</remarks> - static HWND GetSnarlWindow(); - - private: - /// <summary>Send message to Snarl.</summary> - /// <returns>Return zero on failure.</returns> - LONG32 Send(SnarlMessage msg); - - /// <summary>Convert a unicode string to UTF8</summary> - /// <returns>Returns pointer to the new string - Remember to delete [] returned string !</returns> - /// <remarks>Remember to delete [] returned string !!!</remarks> - LPSTR WideToUTF8(LPCWSTR szWideStr); - - /// <summary>Pack data into the PackedData member field.</summary> - /// <param name="data">Should always be a pointer to the PackedData field</param> - /// <param name="format">The format string. Can be NULL or "" to just zero PackedData!</param> - /// <param name="...">Variable number of objects to convert</param> - void PackData(BYTE* data, LPCSTR format, ...); - - LONG32 appToken; - LONG32 lastMsgToken; - SnarlEnums::SnarlStatus localError; - - }; // class - - } // namespace V41 -} // namespace Snarl - -#endif // SNARL_INTERFACE_V41 diff --git a/BuildTools/SCons/SConstruct b/BuildTools/SCons/SConstruct index 70cd9d8..6dd1115 100644 --- a/BuildTools/SCons/SConstruct +++ b/BuildTools/SCons/SConstruct @@ -317,10 +317,6 @@ if env["PLATFORM"] == "darwin" : env["GROWL_FRAMEWORK"] = "/Library/Frameworks/Growl.framework" conf.Finish() -# Snarl -if env["PLATFORM"] == "win32" : - env["HAVE_SNARL"] = True - # LibXML conf = Configure(conf_env, custom_tests = {"CheckVersion": CheckVersion}) if env.get("try_libxml", True) and conf.CheckCHeader("libxml/parser.h") and conf.CheckLib("xml2") : diff --git a/SwifTools/Notifier/SConscript b/SwifTools/Notifier/SConscript index a8e8590..e87312c 100644 --- a/SwifTools/Notifier/SConscript +++ b/SwifTools/Notifier/SConscript @@ -17,11 +17,5 @@ elif myenv["PLATFORM"] == "darwin" : "NotificationCenterNotifierDelegate.mm", ] -if swiftools_env.get("HAVE_SNARL", False) : - myenv.MergeFlags(myenv["SNARL_FLAGS"]) - sources += [ - "SnarlNotifier.cpp", - ] - objects = myenv.StaticObject(sources) swiftools_env.Append(SWIFTOOLS_OBJECTS = objects) diff --git a/SwifTools/Notifier/SnarlNotifier.cpp b/SwifTools/Notifier/SnarlNotifier.cpp deleted file mode 100644 index e3977a7..0000000 --- a/SwifTools/Notifier/SnarlNotifier.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2010 Isode Limited. - * All rights reserved. - * See the COPYING file for more information. - */ - -#include <SwifTools/Notifier/SnarlNotifier.h> - -#include <cassert> -#include <iostream> -#include <boost/bind.hpp> - -#include <Swiften/Base/foreach.h> -#include <SwifTools/Notifier/Win32NotifierWindow.h> - -#define SWIFT_SNARLNOTIFIER_MESSAGE_ID 0x4567 // Sounds sick to pick a number, but this is windows - -namespace Swift { - -SnarlNotifier::SnarlNotifier(const std::string& name, Win32NotifierWindow* window, const boost::filesystem::path& icon) : window(window), available(false) { - window->onMessageReceived.connect(boost::bind(&SnarlNotifier::handleMessageReceived, this, _1)); - available = snarl.RegisterApp(name.c_str(), name.c_str(), icon.string().c_str(), window->getID(), SWIFT_SNARLNOTIFIER_MESSAGE_ID); - foreach(Notifier::Type type, getAllTypes()) { - snarl.AddClass(typeToString(type).c_str(), typeToString(type).c_str()); - } -} - -SnarlNotifier::~SnarlNotifier() { - snarl.UnregisterApp(); - window->onMessageReceived.disconnect(boost::bind(&SnarlNotifier::handleMessageReceived, this, _1)); - if (!notifications.empty()) { - std::cerr << "Warning: " << notifications.size() << " Snarl notifications pending" << std::endl; - } -} - -bool SnarlNotifier::isAvailable() const { - return available; -} - - -void SnarlNotifier::showMessage(Type type, const std::string& subject, const std::string& description, const boost::filesystem::path& picture, boost::function<void()> callback) { - int timeout = (type == IncomingMessage || type == SystemMessage) ? DEFAULT_MESSAGE_NOTIFICATION_TIMEOUT_SECONDS : DEFAULT_STATUS_NOTIFICATION_TIMEOUT_SECONDS; - int notificationID = snarl.EZNotify( - typeToString(type).c_str(), - subject.c_str(), - description.c_str(), - timeout, - picture.string().c_str()); - if (notificationID > 0) { - notifications.insert(std::make_pair(notificationID, callback)); - } -} - -void SnarlNotifier::handleMessageReceived(MSG* message) { - if (message->message == SWIFT_SNARLNOTIFIER_MESSAGE_ID) { - int action = message->wParam; - if (action == Snarl::V41::SnarlEnums::NotificationTimedOut || action == Snarl::V41::SnarlEnums::NotificationAck || action == Snarl::V41::SnarlEnums::NotificationClosed) { - int notificationID = message->lParam; - NotificationsMap::iterator i = notifications.find(notificationID); - if (i != notifications.end()) { - if (action == Snarl::V41::SnarlEnums::NotificationAck && !i->second.empty()) { - i->second(); - } - notifications.erase(i); - } - else { - std::cerr << "Warning: Orphaned Snarl notification received"; - } - } - } -} - -} diff --git a/SwifTools/Notifier/SnarlNotifier.h b/SwifTools/Notifier/SnarlNotifier.h deleted file mode 100644 index 5006185..0000000 --- a/SwifTools/Notifier/SnarlNotifier.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2010-2016 Isode Limited. - * All rights reserved. - * See the COPYING file for more information. - */ - -#pragma once - -#include <map> - -#include <SnarlInterface.h> - -#include <SwifTools/Notifier/Notifier.h> - -namespace Swift { - class Win32NotifierWindow; - - class SnarlNotifier : public Notifier { - public: - SnarlNotifier(const std::string& name, Win32NotifierWindow* window, const boost::filesystem::path& icon); - ~SnarlNotifier(); - - virtual void showMessage(Type type, const std::string& subject, const std::string& description, const boost::filesystem::path& picture, boost::function<void()> callback); - virtual bool isAvailable() const; - - virtual void purgeCallbacks() { - notifications.clear(); - } - - private: - void handleMessageReceived(MSG* message); - - private: - Snarl::V41::SnarlInterface snarl; - Win32NotifierWindow* window; - bool available; - typedef std::map<int, boost::function<void()> > NotificationsMap; - NotificationsMap notifications; - }; -} diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript index 4b3d716..7e2aafe 100644 --- a/Swift/QtUI/SConscript +++ b/Swift/QtUI/SConscript @@ -43,9 +43,6 @@ if myenv.get("HAVE_GROWL", False) : myenv.Append(CPPDEFINES = ["HAVE_GROWL"]) if myenv["swift_mobile"] : myenv.Append(CPPDEFINES = ["SWIFT_MOBILE"]) -if myenv.get("HAVE_SNARL", False) : - myenv.UseFlags(myenv["SNARL_FLAGS"]) - myenv.Append(CPPDEFINES = ["HAVE_SNARL"]) if myenv.get("HAVE_HUNSPELL", True): myenv.Append(CPPDEFINES = ["HAVE_HUNSPELL"]) myenv.UseFlags(myenv["HUNSPELL_FLAGS"]) diff --git a/Swift/QtUI/WindowsNotifier.cpp b/Swift/QtUI/WindowsNotifier.cpp index c954fab..d6e8ba9 100644 --- a/Swift/QtUI/WindowsNotifier.cpp +++ b/Swift/QtUI/WindowsNotifier.cpp @@ -20,20 +20,14 @@ namespace Swift { WindowsNotifier::WindowsNotifier(const std::string& name, const boost::filesystem::path& icon, QSystemTrayIcon* tray) : tray(tray) { notifierWindow = new QtWin32NotifierWindow(); - snarlNotifier = new SnarlNotifier(name, notifierWindow, icon); connect(tray, SIGNAL(messageClicked()), SLOT(handleMessageClicked())); } WindowsNotifier::~WindowsNotifier() { - delete snarlNotifier; delete notifierWindow; } void WindowsNotifier::showMessage(Type type, const std::string& subject, const std::string& description, const boost::filesystem::path& picture, boost::function<void()> callback) { - if (snarlNotifier->isAvailable()) { - snarlNotifier->showMessage(type, subject, description, picture, callback); - return; - } std::vector<Notifier::Type> defaultTypes = getDefaultTypes(); if (std::find(defaultTypes.begin(), defaultTypes.end(), type) == defaultTypes.end()) { return; diff --git a/Swift/QtUI/WindowsNotifier.h b/Swift/QtUI/WindowsNotifier.h index fae0795..945ef6b 100644 --- a/Swift/QtUI/WindowsNotifier.h +++ b/Swift/QtUI/WindowsNotifier.h @@ -11,11 +11,12 @@ #include <QObject> #include <SwifTools/Notifier/Notifier.h> -#include <SwifTools/Notifier/SnarlNotifier.h> class QSystemTrayIcon; namespace Swift { + class Win32NotifierWindow; + class WindowsNotifier : public QObject, public Notifier { Q_OBJECT @@ -32,7 +33,6 @@ namespace Swift { private: QSystemTrayIcon* tray; Win32NotifierWindow* notifierWindow; - SnarlNotifier* snarlNotifier; boost::function<void()> lastCallback; }; } -- cgit v0.10.2-6-g49f6