updated SnoreInterface to a version thats working with mingw-w64, added a simple interface to generate intern notifications, made it possible again to notify with snarl if the application is unregistered
This commit is contained in:
parent
67cae7dca5
commit
79b4e434f8
|
@ -0,0 +1,33 @@
|
|||
########################################################################################
|
||||
# Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> #
|
||||
# #
|
||||
# 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 <http://www.gnu.org/licenses/>. #
|
||||
########################################################################################
|
||||
|
||||
# - 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)
|
|
@ -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})
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/****************************************************************************************
|
||||
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> *
|
||||
* *
|
||||
* 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 <http://www.gnu.org/licenses/>. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include "snorenotificationinstance.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
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"<<title;
|
||||
return _snore->broadcastNotification(QSharedPointer<Notification>(new Notification(NULL,_appName,alert,title,text,icon,timeout)));
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/****************************************************************************************
|
||||
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> *
|
||||
* *
|
||||
* 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 <http://www.gnu.org/licenses/>. *
|
||||
****************************************************************************************/
|
||||
|
||||
#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
|
|
@ -17,6 +17,7 @@
|
|||
#include "snoreserver.h"
|
||||
#include "notification.h"
|
||||
#include "trayiconnotifer.h"
|
||||
#include "snorenotificationinstance.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
@ -25,7 +26,7 @@
|
|||
#include <QDir>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
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<Notification>(new Notification(NULL,"SnoreNotify","Default Alert","Welcome","Snore Notify succesfully registred "+pluginName,"")));
|
||||
nb->notify(QSharedPointer<Notification>(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> notification){
|
||||
emit notify(notification);
|
||||
if(_notificationBackend!=NULL){
|
||||
notification->_id=_notificationBackend->notify(notification);
|
||||
notification->_id = _notificationBackend->notify(notification);
|
||||
std::cout<<"Notification ID: "<<QString::number(notification->_id).toLatin1().data()<<std::endl;
|
||||
return notification->_id;
|
||||
}
|
||||
|
@ -150,6 +154,7 @@ const ApplicationsList &SnoreServer::aplications() const{
|
|||
return _applications;
|
||||
}
|
||||
|
||||
|
||||
const QHash<QString,Notification_Backend*> &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"
|
||||
|
|
|
@ -47,11 +47,13 @@ public:
|
|||
const QHash<QString,Notification_Backend*> &primaryNotificationBackends() const;
|
||||
void setNotificationBackend(Notification_Backend *backend);
|
||||
|
||||
class SnoreNotificationInstance *defaultNotificationInterface();
|
||||
|
||||
QHash<QString,SnorePlugin*> plugins;
|
||||
|
||||
private:
|
||||
ApplicationsList _applications;
|
||||
class SnoreNotificationInstance *_defaultNotificationInterface;
|
||||
|
||||
|
||||
QHash<QString,Notification_Backend*> _notyfier;
|
||||
|
|
|
@ -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<LONG32>(hWndReply);
|
||||
ss.LngData2 = static_cast<LONG32>(reinterpret_cast<DWORD_PTR>(hWndReply));
|
||||
ss.Id = static_cast<LONG32>(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<LONG32>(hWndReply);
|
||||
ssex.LngData2 = static_cast<LONG32>(reinterpret_cast<DWORD_PTR>(hWndReply));
|
||||
ssex.Id = static_cast<LONG32>(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<M_RESULT>(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<LONG32>(hWnd);
|
||||
ss.LngData2 = static_cast<LONG32>(reinterpret_cast<DWORD_PTR>(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<M_RESULT>(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<LONG32>(hWnd);
|
||||
ss.LngData2 = static_cast<LONG32>(reinterpret_cast<DWORD_PTR>(hWnd));
|
||||
|
||||
return static_cast<M_RESULT>(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<M_RESULT>(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<LONG32>(hWnd);
|
||||
ss.LngData2 = static_cast<LONG32>(reinterpret_cast<DWORD_PTR>(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<LONG32>(hWndReply);
|
||||
ssex.LngData2 = static_cast<LONG32>(reinterpret_cast<DWORD_PTR>(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<M_RESULT>(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<M_RESULT>(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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -1,18 +1,24 @@
|
|||
#ifndef SNARL_INTERFACE
|
||||
#ifndef SNARL_INTERFACE
|
||||
#define SNARL_INTERFACE
|
||||
|
||||
#include <tchar.h>
|
||||
#include <windows.h>
|
||||
#include <strsafe.h>
|
||||
#include <cstdio>
|
||||
|
||||
#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 <class T> 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
|
||||
|
|
|
@ -34,15 +34,18 @@ Notification_Backend("SnarlBackend",snore)
|
|||
{
|
||||
Snarl::SnarlInterface *snarlInterface = new Snarl::SnarlInterface();
|
||||
_applications.insert("SnoreNotify",snarlInterface);
|
||||
qDebug()<<"Initiating Snarl Backend, Snarl version: "<<snarlInterface->GetVersionExA();
|
||||
qDebug()<<"Initiating Snarl Backend, Snarl version: "<<snarlInterface->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(QSharedPointer<Notification>notification){
|
||||
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());
|
||||
|
|
|
@ -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<QString,Snarl::SnarlInterface*> _applications;
|
||||
Snarl::SnarlInterface* _defautSnarlinetrface;
|
||||
public slots:
|
||||
void registerApplication(Application *application);
|
||||
void unregisterApplication(class Application *application);
|
||||
|
|
Loading…
Reference in New Issue