diff --git a/share/FindLibsnore.cmake b/share/FindLibsnore.cmake new file mode 100644 index 0000000..6125765 --- /dev/null +++ b/share/FindLibsnore.cmake @@ -0,0 +1,33 @@ +######################################################################################## +# Copyright (c) 2010 Patrick von Reth # +# # +# This program is free software; you can redistribute it and/or modify it under # +# the terms of the GNU General Public License as published by the Free Software # +# Foundation; either version 2 of the License, or (at your option) any later # +# version. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT ANY # +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A # +# PARTICULAR PURPOSE. See the GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License along with # +# this program. If not, see . # +######################################################################################## + +# - Try to find the libsnore library +# Once done this will define +# +# LIBSNORE_FOUND - system has the LIBSNORE library +# LIBSNORE_LIBRARIES - The libraries needed to use LIBSNORE +# LIBSNORE_PLUGIN_PATH - Path of the plugins + + +find_library(LIBSNORE_LIBRARIES NAMES libsnore snore) +find_path(LIBSNORE_PLUGIN_PATH snoreplugins) +if(LIBSNORE_LIBRARIES AND LIBSNORE_PLUGIN_PATH) + set(LIBSNORE_FOUND TRUE) + set(LIBSNORE_PLUGIN_PATH ${LIBSNORE_PLUGIN_PATH}/snoreplugins) + message(STATUS "Found libsnore ${LIBSNORE_LIBRARIES}") +else(LIBSNORE_LIBRARIES AND LIBSNORE_PLUGIN_PATH) + message(FATAL_ERROR "Could not find libsnore, please install libsnore") +endif(LIBSNORE_LIBRARIES AND LIBSNORE_PLUGIN_PATH) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index b3b3659..e05dbbd 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -5,6 +5,7 @@ set ( SnoreNotify_SRCS interface.cpp utils.cpp trayiconnotifer.cpp + snorenotificationinstance.cpp ) set ( SnoreNotify_HDR @@ -14,6 +15,7 @@ set ( SnoreNotify_HDR interface.h snore_exports.h utils.h + snorenotificationinstance.h ) automoc4_add_library( snorecore SHARED ${SnoreNotify_SRCS}) diff --git a/src/core/snorenotificationinstance.cpp b/src/core/snorenotificationinstance.cpp new file mode 100644 index 0000000..3f29efa --- /dev/null +++ b/src/core/snorenotificationinstance.cpp @@ -0,0 +1,56 @@ +/**************************************************************************************** + * Copyright (c) 2010 Patrick von Reth * + * * + * This program is free software; you can redistribute it and/or modify it under * + * the terms of the GNU General Public License as published by the Free Software * + * Foundation; either version 2 of the License, or (at your option) any later * + * version. * + * * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY * + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * + * PARTICULAR PURPOSE. See the GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License along with * + * this program. If not, see . * + ****************************************************************************************/ + +#include "snorenotificationinstance.h" + +#include + +SnoreNotificationInstance::SnoreNotificationInstance() +{ +} + +SnoreNotificationInstance::SnoreNotificationInstance(const QString &appname, SnoreServer *parent): + _appName(appname), + _app(new Application(appname)), + _snore(parent) +{ + setParent(parent); +} + +SnoreNotificationInstance::~SnoreNotificationInstance(){ + unregisterWithBackends(); +} + + +void SnoreNotificationInstance::addAlert(const QString &name, const QString &title){ + _app->addAlert(new Alert(name,title)); + +} + +void SnoreNotificationInstance::registerWithBackends(){ + _snore->addApplication(_app); + _snore->applicationIsInitialized(_app); + +} + +void SnoreNotificationInstance::unregisterWithBackends(){ + _snore->removeApplication(_appName); +} + +int SnoreNotificationInstance::notify(const QString &alert, const QString &title, const QString &text, const QString &icon, int timeout){ + qDebug()<<"Broadcasting"<broadcastNotification(QSharedPointer(new Notification(NULL,_appName,alert,title,text,icon,timeout))); +} diff --git a/src/core/snorenotificationinstance.h b/src/core/snorenotificationinstance.h new file mode 100644 index 0000000..47dfa9f --- /dev/null +++ b/src/core/snorenotificationinstance.h @@ -0,0 +1,42 @@ +/**************************************************************************************** + * Copyright (c) 2010 Patrick von Reth * + * * + * This program is free software; you can redistribute it and/or modify it under * + * the terms of the GNU General Public License as published by the Free Software * + * Foundation; either version 2 of the License, or (at your option) any later * + * version. * + * * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY * + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * + * PARTICULAR PURPOSE. See the GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License along with * + * this program. If not, see . * + ****************************************************************************************/ + +#ifndef SNORENOTIFICATIONINSTANCE_H +#define SNORENOTIFICATIONINSTANCE_H + +#include "core/snoreserver.h" +#include "core/application.h" + +class SnoreNotificationInstance:public QObject +{ + Q_OBJECT +public: + SnoreNotificationInstance(const QString &appname,SnoreServer *parent); + ~SnoreNotificationInstance(); + void addAlert(const QString &name,const QString &title); + void registerWithBackends(); + void unregisterWithBackends(); + int notify(const QString &alert,const QString &title,const QString &text,const QString &icon=0,int timeout=10); +private: + SnoreNotificationInstance(); + const QString _appName; + Application *_app; + SnoreServer *_snore; + + +}; + +#endif // SNORENOTIFICATIONINSTANCE_H diff --git a/src/core/snoreserver.cpp b/src/core/snoreserver.cpp index da082fe..e36e7f9 100644 --- a/src/core/snoreserver.cpp +++ b/src/core/snoreserver.cpp @@ -17,6 +17,7 @@ #include "snoreserver.h" #include "notification.h" #include "trayiconnotifer.h" +#include "snorenotificationinstance.h" #include @@ -25,7 +26,7 @@ #include #include -QString const SnoreServer::snoreTMP=QDir::temp().path()+"/SnoreNotify/"; +QString const SnoreServer::snoreTMP = QDir::temp().path()+"/SnoreNotify/"; SnoreServer::SnoreServer(QSystemTrayIcon *trayIcon): _notificationBackend(NULL), @@ -45,9 +46,12 @@ SnoreServer::SnoreServer(QSystemTrayIcon *trayIcon): }else QDir::temp().mkpath("SnoreNotify"); + _defaultNotificationInterface = new SnoreNotificationInstance("Snore",this); + if(trayIcon!=NULL){ publicatePlugin(new TrayIconNotifer(this,trayIcon)); } + } void SnoreServer::publicatePlugin(const QString &fileName){ QPluginLoader loader(fileName); @@ -102,7 +106,7 @@ void SnoreServer::publicatePlugin(SnorePlugin *plugin){ connect(this,SIGNAL(applicationInitialized(Application*)),nb,SLOT(registerApplication(Application*))); connect(this,SIGNAL(applicationRemoved(Application*)),nb,SLOT(unregisterApplication(Application*))); nb->setSnore(this); - nb->notify(QSharedPointer(new Notification(NULL,"SnoreNotify","Default Alert","Welcome","Snore Notify succesfully registred "+pluginName,""))); + nb->notify(QSharedPointer(new Notification(NULL,"Snore","Default Alert","Welcome","Snore Notify succesfully registred "+pluginName,""))); } } @@ -110,7 +114,7 @@ void SnoreServer::publicatePlugin(SnorePlugin *plugin){ int SnoreServer::broadcastNotification(QSharedPointer notification){ emit notify(notification); if(_notificationBackend!=NULL){ - notification->_id=_notificationBackend->notify(notification); + notification->_id = _notificationBackend->notify(notification); std::cout<<"Notification ID: "<_id).toLatin1().data()<_id; } @@ -150,6 +154,7 @@ const ApplicationsList &SnoreServer::aplications() const{ return _applications; } + const QHash &SnoreServer::primaryNotificationBackends()const{ return _primaryNotificationBackends; } @@ -160,4 +165,8 @@ void SnoreServer::setNotificationBackend(Notification_Backend *backend){ _notificationBackend=backend; } +SnoreNotificationInstance * SnoreServer::defaultNotificationInterface(){ + return _defaultNotificationInterface; +} + #include "snoreserver.moc" diff --git a/src/core/snoreserver.h b/src/core/snoreserver.h index 6e24cce..ec65db5 100644 --- a/src/core/snoreserver.h +++ b/src/core/snoreserver.h @@ -47,11 +47,13 @@ public: const QHash &primaryNotificationBackends() const; void setNotificationBackend(Notification_Backend *backend); + class SnoreNotificationInstance *defaultNotificationInterface(); QHash plugins; private: ApplicationsList _applications; + class SnoreNotificationInstance *_defaultNotificationInterface; QHash _notyfier; diff --git a/src/plugins/snarl/SnarlInterface.cpp b/src/plugins/snarl/SnarlInterface.cpp index f287b8e..725391a 100644 --- a/src/plugins/snarl/SnarlInterface.cpp +++ b/src/plugins/snarl/SnarlInterface.cpp @@ -1,4 +1,4 @@ -// About: +// About: // Snarl C++ interface implementation // To understand what the different functions do and what they return, please // have a look at the API on http://www.fullphat.net/dev/api.htm. @@ -17,7 +17,7 @@ // // // Authors: -// Written and maintained by Toke Noer Nøttrup +// Written and maintained by Toke Noer Nøttrup // Original C++ version by "Whitman" // // License etc. : @@ -30,6 +30,8 @@ //----------------------------------------------------------------------------- // History +// 2010/08/02 : Removed some dependencies on safe string functions +// : Added uckly casts of HWND to please MinGW64 (since Snarl is 32bit anyway, shouldn't matter.) // 2008/12/31 : Implemented V39 API // : Moved SnarlInterface into new Snarl namespace and moved enums etc. out of class // : Added WCHAR overloads for all functions @@ -52,6 +54,7 @@ // 2007/03/04 : Added - snGetAppPath, snGetIconsPath, snGetVersionEx, // snSetTimeout, uSendEx +#define _CRT_SECURE_NO_WARNINGS #include "SnarlInterface.h" @@ -88,12 +91,12 @@ LONG32 SnarlInterface::ShowMessage(LPCSTR szTitle, LPCSTR szText, LONG32 timeout ZeroMemory((void*)&ss, sizeof(ss)); ss.Cmd = SNARL_SHOW; - StringCbCopyA((LPSTR)&ss.Title, SNARL_STRING_LENGTH, szTitle); - StringCbCopyA((LPSTR)&ss.Text, SNARL_STRING_LENGTH, szText); - StringCbCopyA((LPSTR)&ss.Icon, SNARL_STRING_LENGTH, szIconPath); + strncpy((LPSTR)&ss.Title, szTitle, SNARL_STRING_LENGTH); + strncpy((LPSTR)&ss.Text, szText, SNARL_STRING_LENGTH); + strncpy((LPSTR)&ss.Icon, szIconPath, SNARL_STRING_LENGTH); ss.Timeout = timeout; - ss.LngData2 = reinterpret_cast(hWndReply); + ss.LngData2 = static_cast(reinterpret_cast(hWndReply)); ss.Id = static_cast(uReplyMsg); m_nLastMessageId = Send(ss); @@ -132,14 +135,14 @@ LONG32 SnarlInterface::ShowMessageEx(LPCSTR szClass, LPCSTR szTitle, LPCSTR szTe ssex.Cmd = SNARL_EX_SHOW; ssex.Timeout = timeout; - ssex.LngData2 = reinterpret_cast(hWndReply); + ssex.LngData2 = static_cast(reinterpret_cast(hWndReply)); ssex.Id = static_cast(uReplyMsg); - StringCbCopyA((LPSTR)&ssex.Class, SNARL_STRING_LENGTH, szClass); - StringCbCopyA((LPSTR)&ssex.Title, SNARL_STRING_LENGTH, szTitle); - StringCbCopyA((LPSTR)&ssex.Text, SNARL_STRING_LENGTH, szText); - StringCbCopyA((LPSTR)&ssex.Icon, SNARL_STRING_LENGTH, szIconPath); - StringCbCopyA((LPSTR)&ssex.Extra, SNARL_STRING_LENGTH, szSoundFile); + strncpy((LPSTR)&ssex.Class, szClass, SNARL_STRING_LENGTH); + strncpy((LPSTR)&ssex.Title, szTitle, SNARL_STRING_LENGTH); + strncpy((LPSTR)&ssex.Text, szText, SNARL_STRING_LENGTH); + strncpy((LPSTR)&ssex.Icon, szIconPath, SNARL_STRING_LENGTH); + strncpy((LPSTR)&ssex.Extra, szSoundFile, SNARL_STRING_LENGTH); m_nLastMessageId = Send(ssex); return m_nLastMessageId; @@ -229,10 +232,10 @@ M_RESULT SnarlInterface::UpdateMessage(LONG32 id, LPCSTR szTitle, LPCSTR szText, ss.Cmd = SNARL_UPDATE; ss.Id = id; - StringCbCopyA((LPSTR)&ss.Title, SNARL_STRING_LENGTH, szTitle); - StringCbCopyA((LPSTR)&ss.Text, SNARL_STRING_LENGTH, szText); - StringCbCopyA((LPSTR)&ss.Icon, SNARL_STRING_LENGTH, szIconPath); - + strncpy((LPSTR)&ss.Title, szTitle, SNARL_STRING_LENGTH); + strncpy((LPSTR)&ss.Text, szText, SNARL_STRING_LENGTH); + strncpy((LPSTR)&ss.Icon, szIconPath, SNARL_STRING_LENGTH); + return static_cast(Send(ss)); } @@ -296,10 +299,10 @@ M_RESULT SnarlInterface::RegisterConfig2(HWND hWnd, LPCSTR szAppName, LONG32 rep m_hwndFrom = hWnd; ss.Cmd = SNARL_REGISTER_CONFIG_WINDOW_2; - ss.LngData2 = reinterpret_cast(hWnd); + ss.LngData2 = static_cast(reinterpret_cast(hWnd)); ss.Id = replyMsg; - StringCbCopyA((LPSTR)&ss.Title, SNARL_STRING_LENGTH, szAppName); - StringCbCopyA((LPSTR)&ss.Icon, SNARL_STRING_LENGTH, szIcon); + strncpy((LPSTR)&ss.Title, szAppName, SNARL_STRING_LENGTH); + strncpy((LPSTR)&ss.Icon, szIcon, SNARL_STRING_LENGTH); return static_cast(Send(ss)); } @@ -331,7 +334,7 @@ M_RESULT SnarlInterface::RevokeConfig(HWND hWnd) m_hwndFrom = NULL; ss.Cmd = SNARL_REVOKE_CONFIG_WINDOW; - ss.LngData2 = reinterpret_cast(hWnd); + ss.LngData2 = static_cast(reinterpret_cast(hWnd)); return static_cast(Send(ss)); } @@ -405,8 +408,8 @@ M_RESULT SnarlInterface::RegisterAlert(LPCSTR szAppName, LPCSTR szClass) { SNARLSTRUCT ss; ss.Cmd = SNARL_REGISTER_ALERT; - StringCbCopyA((LPSTR)&ss.Title, SNARL_STRING_LENGTH, szAppName); - StringCbCopyA((LPSTR)&ss.Text, SNARL_STRING_LENGTH, szClass); + strncpy((LPSTR)&ss.Title, szAppName, SNARL_STRING_LENGTH); + strncpy((LPSTR)&ss.Text, szClass, SNARL_STRING_LENGTH); return static_cast(Send(ss)); } @@ -442,7 +445,11 @@ LONG32 SnarlInterface::GetGlobalMsg() HWND SnarlInterface::GetSnarlWindow() { - return FindWindow(NULL, _T("Snarl")); + HWND hWnd = FindWindow(SNARL_WINDOW_CLASS, SNARL_WINDOW_TITLE); + if (hWnd == NULL) + hWnd = FindWindow(NULL, SNARL_WINDOW_TITLE); + + return hWnd; } @@ -457,18 +464,20 @@ LPCTSTR SnarlInterface::GetAppPath() HWND hWnd = GetSnarlWindow(); if (hWnd) { - HWND hWndPath = FindWindowEx(hWnd, 0, _T("static"), NULL); + HWND hWndPath = FindWindowEx(hWnd, NULL, _T("static"), NULL); if (hWndPath) { TCHAR strTmp[MAX_PATH] = {0}; - int nReturn = GetWindowText(hWndPath, strTmp, MAX_PATH); + int nReturn = GetWindowText(hWndPath, strTmp, MAX_PATH-1); if (nReturn > 0) { TCHAR* strReturn = AllocateString(nReturn + 1); - StringCchCopy(strReturn, nReturn + 1, strTmp); + _tcsncpy(strReturn, strTmp, nReturn + 1); + strReturn[nReturn] = 0; return strReturn; } } } + return NULL; } @@ -487,13 +496,14 @@ LPCTSTR SnarlInterface::GetIconsPath() return NULL; size_t nLen = 0; - if (SUCCEEDED(StringCbLength(szPath, MAX_PATH, &nLen))) + // TODO: _tcsnlen MAX_PATH + if (nLen = _tcslen(szPath)) { nLen += 10 + 1; // etc\\icons\\ + NULL szIconPath = AllocateString(nLen); - StringCbCopy(szIconPath, nLen * sizeof(TCHAR), szPath); - StringCbCat(szIconPath, nLen * sizeof(TCHAR), _T("etc\\icons\\")); + _tcsncpy(szIconPath, szPath, nLen); + _tcsncat(szIconPath, _T("etc\\icons\\"), nLen); } FreeString(szPath); @@ -536,14 +546,14 @@ M_RESULT SnarlInterface::RegisterApp(LPCSTR Application, LPCSTR SmallIcon, LPCST { m_hwndFrom = hWnd; - SNARLSTRUCT ss; + SNARLSTRUCT ss; ss.Cmd = SNARL_REGISTER_APP; - StringCbCopyA((LPSTR)&ss.Title, SNARL_STRING_LENGTH, Application); - StringCbCopyA((LPSTR)&ss.Icon, SNARL_STRING_LENGTH, SmallIcon); - StringCbCopyA((LPSTR)&ss.Text, SNARL_STRING_LENGTH, LargeIcon); + strncpy((LPSTR)&ss.Title, Application, SNARL_STRING_LENGTH); + strncpy((LPSTR)&ss.Icon, SmallIcon, SNARL_STRING_LENGTH); + strncpy((LPSTR)&ss.Text, LargeIcon, SNARL_STRING_LENGTH); - ss.LngData2 = reinterpret_cast(hWnd); + ss.LngData2 = static_cast(reinterpret_cast(hWnd)); ss.Id = ReplyMsg; ss.Timeout = GetCurrentProcessId(); @@ -594,17 +604,15 @@ LONG32 SnarlInterface::ShowNotification(LPCSTR Class, LPCSTR Title, LPCSTR Text, SNARLSTRUCTEX ssex; ssex.Cmd = SNARL_SHOW_NOTIFICATION; - StringCbCopyExA((LPSTR)&ssex.Title, SNARL_STRING_LENGTH, Title, NULL, NULL, STRSAFE_IGNORE_NULLS); - StringCbCopyExA((LPSTR)&ssex.Text, SNARL_STRING_LENGTH, Text, NULL, NULL, STRSAFE_IGNORE_NULLS); - StringCbCopyExA((LPSTR)&ssex.Icon, SNARL_STRING_LENGTH, Icon, NULL, NULL, STRSAFE_IGNORE_NULLS); + strncpy((LPSTR)&ssex.Title, Title, SNARL_STRING_LENGTH); + strncpy((LPSTR)&ssex.Text, Text, SNARL_STRING_LENGTH); + strncpy((LPSTR)&ssex.Icon, Icon, SNARL_STRING_LENGTH); + strncpy((LPSTR)&ssex.Extra, Sound, SNARL_STRING_LENGTH); + strncpy((LPSTR)&ssex.Class, Class, SNARL_STRING_LENGTH); ssex.Timeout = Timeout; - ssex.LngData2 = reinterpret_cast(hWndReply); + ssex.LngData2 = static_cast(reinterpret_cast(hWndReply)); ssex.Id = uReplyMsg; - - StringCbCopyExA((LPSTR)&ssex.Extra, SNARL_STRING_LENGTH, Sound, NULL, NULL, STRSAFE_IGNORE_NULLS); - StringCbCopyA((LPSTR)&ssex.Class, SNARL_STRING_LENGTH, Class); - ssex.Reserved1 = GetCurrentProcessId(); m_nLastMessageId = Send(ssex); @@ -643,7 +651,7 @@ M_RESULT SnarlInterface::ChangeAttribute(LONG32 Id, SNARL_ATTRIBUTES Attr, LPCST ss.Id = Id; ss.LngData2 = Attr; - StringCbCopyExA((LPSTR)&ss.Text, SNARL_STRING_LENGTH, Value, NULL, NULL, STRSAFE_IGNORE_NULLS); + strncpy((LPSTR)&ss.Text, Value, SNARL_STRING_LENGTH); return static_cast(Send(ss)); } @@ -682,8 +690,8 @@ M_RESULT SnarlInterface::SetClassDefault(LPCSTR Class, SNARL_ATTRIBUTES Attr, LP ss.LngData2 = Attr; ss.Timeout = GetCurrentProcessId(); - StringCbCopyExA((LPSTR)&ss.Text, SNARL_STRING_LENGTH, Class, NULL, NULL, STRSAFE_IGNORE_NULLS); - StringCbCopyExA((LPSTR)&ss.Icon, SNARL_STRING_LENGTH, Value, NULL, NULL, STRSAFE_IGNORE_NULLS); + strncpy((LPSTR)&ss.Text, Class, SNARL_STRING_LENGTH); + strncpy((LPSTR)&ss.Icon, Value, SNARL_STRING_LENGTH); return static_cast(Send(ss)); } @@ -730,8 +738,8 @@ M_RESULT SnarlInterface::AddClass(LPCSTR Class, LPCSTR Description, SNARL_CLASS_ ss.LngData2 = Flags; ss.Timeout = GetCurrentProcessId(); - StringCbCopyExA((LPSTR)&ss.Text, SNARL_STRING_LENGTH, Class, NULL, NULL, STRSAFE_IGNORE_NULLS); - StringCbCopyExA((LPSTR)&ss.Title, SNARL_STRING_LENGTH, Description, NULL, NULL, STRSAFE_IGNORE_NULLS); + strncpy((LPSTR)&ss.Text, Class, SNARL_STRING_LENGTH); + strncpy((LPSTR)&ss.Title, Description, SNARL_STRING_LENGTH); LONG32 result = Send(ss); @@ -741,7 +749,7 @@ M_RESULT SnarlInterface::AddClass(LPCSTR Class, LPCSTR Description, SNARL_CLASS_ SetClassDefault(Class, SNARL_ATTRIBUTE_ICON, DefaultIcon); if (DefaultTimeout > 0) { char str[64] = {0}; - StringCbPrintfA((LPSTR)&str, sizeof(str), "%d", DefaultTimeout); + _snprintf((LPSTR)&str, sizeof(str), "%d", DefaultTimeout); SetClassDefault(Class, SNARL_ATTRIBUTE_TIMEOUT, str); } @@ -804,9 +812,9 @@ 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; -} \ No newline at end of file + 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; +} diff --git a/src/plugins/snarl/SnarlInterface.h b/src/plugins/snarl/SnarlInterface.h index 1a26ec0..211c6f9 100644 --- a/src/plugins/snarl/SnarlInterface.h +++ b/src/plugins/snarl/SnarlInterface.h @@ -1,18 +1,24 @@ -#ifndef SNARL_INTERFACE +#ifndef SNARL_INTERFACE #define SNARL_INTERFACE #include #include -#include +#include + +#ifndef SMTO_NOTIMEOUTIFNOTHUNG + #define SMTO_NOTIMEOUTIFNOTHUNG 8 +#endif + -//be compatible with x64 -#define LONG32 intptr_t namespace Snarl { static const LPCTSTR SNARL_GLOBAL_MSG = _T("SnarlGlobalEvent"); static const LPCTSTR SNARL_APP_MSG = _T("SnarlAppMessage"); + static const LPCTSTR SNARL_WINDOW_CLASS = _T("w>Snarl"); + static const LPCTSTR SNARL_WINDOW_TITLE = _T("Snarl"); + static const int SNARL_STRING_LENGTH = 1024; static const int SNARL_UNICODE_LENGTH = SNARL_STRING_LENGTH / 2; @@ -34,7 +40,7 @@ namespace Snarl { // -------------------------------------------------------------------- - typedef enum M_RESULT { + enum M_RESULT { M_ABORTED = 0x80000007, M_ACCESS_DENIED = 0x80000009, M_ALREADY_EXISTS = 0x8000000C, @@ -80,7 +86,7 @@ namespace Snarl { static const SNARL_COMMANDS SNARL_GET_REVISION = SNARL_REVOKE_ALERT; - typedef enum SNARL_APP_FLAGS { + enum SNARL_APP_FLAGS { SNARL_APP_HAS_PREFS = 1, SNARL_APP_HAS_ABOUT = 2 }; @@ -100,7 +106,7 @@ namespace Snarl { }; /* Class attributes */ - typedef enum SNARL_ATTRIBUTES { + enum SNARL_ATTRIBUTES { SNARL_ATTRIBUTE_TITLE = 1, SNARL_ATTRIBUTE_TEXT, SNARL_ATTRIBUTE_ICON, @@ -149,12 +155,12 @@ namespace Snarl { SnarlInterface(); ~SnarlInterface(); - static HWND GetSnarlWindow(); + static HWND GetSnarlWindow(); static LONG32 GetGlobalMsg(); - LPTSTR AllocateString(size_t n) { return new TCHAR[n]; } - void FreeString(LPCTSTR str) { delete [] str; str = NULL; } + LPTSTR AllocateString(size_t n) { return new TCHAR[n]; } + void FreeString(LPCTSTR str) { delete [] str; str = NULL; } LONG32 ShowMessage(LPCSTR szTitle, LPCSTR szText, LONG32 timeout = 0, LPCSTR szIconPath = "", HWND hWndReply = NULL, WPARAM uReplyMsg = 0); @@ -210,10 +216,10 @@ namespace Snarl { template LONG32 Send(T ss); LPSTR WideToUTF8(LPCWSTR szWideStr); - LONG32 m_nLastMessageId; HWND m_hwndFrom; // set during snRegisterConfig() or snRegisterConfig2() - + LONG32 m_nLastMessageId; }; -} +} // namespace Snarl + #endif // SNARL_INTERFACE diff --git a/src/plugins/snarl/snarl_backend.cpp b/src/plugins/snarl/snarl_backend.cpp index c01e50a..b45abeb 100644 --- a/src/plugins/snarl/snarl_backend.cpp +++ b/src/plugins/snarl/snarl_backend.cpp @@ -34,15 +34,18 @@ Notification_Backend("SnarlBackend",snore) { Snarl::SnarlInterface *snarlInterface = new Snarl::SnarlInterface(); _applications.insert("SnoreNotify",snarlInterface); - qDebug()<<"Initiating Snarl Backend, Snarl version: "<GetVersionExA(); + qDebug()<<"Initiating Snarl Backend, Snarl version: "<GetVersionExA(); + _defautSnarlinetrface = new Snarl::SnarlInterface(); this->installEventFilter(this); + } Snarl_Backend::~Snarl_Backend(){ foreach(Application *a,this->snore()->aplications().values()){ unregisterApplication(a); } + delete _defautSnarlinetrface; } void Snarl_Backend::registerApplication(Application *application){ @@ -71,7 +74,8 @@ void Snarl_Backend::unregisterApplication(Application *application){ int Snarl_Backend::notify(QSharedPointernotification){ Snarl::SnarlInterface *snarlInterface = _applications.value(notification->application()); if(snarlInterface == NULL) - return -1; + snarlInterface = _defautSnarlinetrface; + wchar_t *title = toWchar(Notification::toPlainText(notification->title())); wchar_t *text = toWchar(Notification::toPlainText(notification->text())); wchar_t *icon = toWchar(notification->icon()); diff --git a/src/plugins/snarl/snarl_backend.h b/src/plugins/snarl/snarl_backend.h index 68de50e..2bdd00c 100644 --- a/src/plugins/snarl/snarl_backend.h +++ b/src/plugins/snarl/snarl_backend.h @@ -24,7 +24,7 @@ class Snarl_Backend:public Notification_Backend Q_OBJECT Q_INTERFACES(Notification_Backend) public: - Snarl_Backend(class SnoreServer *snore=0); + Snarl_Backend(class SnoreServer *snore=0); ~Snarl_Backend(); bool isPrimaryNotificationBackend(){return true;} @@ -35,6 +35,7 @@ private: //returns a wchart_t aray has to deleted after use wchar_t *toWchar(const QString &string); QHash _applications; + Snarl::SnarlInterface* _defautSnarlinetrface; public slots: void registerApplication(Application *application); void unregisterApplication(class Application *application);