implemented not working snarl callbacks

This commit is contained in:
Patrick von Reth 2010-12-31 15:00:29 +01:00
parent 2d84729ef1
commit 1ff61ae19c
3 changed files with 109 additions and 60 deletions

View File

@ -27,6 +27,7 @@
#include <QSystemTrayIcon>
QString const SnoreServer::snoreTMP = QDir::temp().path() +"/SnoreNotify/";
void SnoreServer::cleanupTMP(){
QDir home ( snoreTMP );
if ( home.exists() )

View File

@ -27,21 +27,26 @@
//disable some msvc warnings
#define _CRT_SECURE_NO_WARNINGS
#define SNORENOTIFIER_MESSAGE_ID 0x4532
using namespace Snarl::V41;
Q_EXPORT_PLUGIN2(snarl_backend,Snarl_Backend)
QAbstractEventDispatcher::EventFilter Snarl_Backend::originalEventFilter = NULL;
Q_EXPORT_PLUGIN2(snarl_backend,Snarl_Backend);
Snarl_Backend::Snarl_Backend(SnoreServer *snore):
Notification_Backend("SnarlBackend",snore)
Notification_Backend("SnarlBackend",snore)
{
activeNotifications = new QHash<int,QSharedPointer<Notification> > ;
winIDWidget = new SnarlWidget(this);
SnarlInterface *snarlInterface = new SnarlInterface();
qDebug()<<"WinID:"<<winIDWidget->winId();
snarlInterface->RegisterApp("SnoreNotify","SnoreNotify",NULL,winIDWidget->winId(),SNORENOTIFIER_MESSAGE_ID);
_applications.insert("SnoreNotify",snarlInterface);
qDebug()<<"Initiating Snarl Backend, Snarl version: "<<snarlInterface->GetVersion();
_defautSnarlinetrface = new SnarlInterface();
//originalEventFilter = QAbstractEventDispatcher::instance()->setEventFilter(&eventFilter);
}
Snarl_Backend::~Snarl_Backend()
@ -50,7 +55,7 @@ Snarl_Backend::~Snarl_Backend()
unregisterApplication(a);
}
delete _defautSnarlinetrface;
QAbstractEventDispatcher::instance()->setEventFilter(originalEventFilter);
delete activeNotifications;
}
void Snarl_Backend::registerApplication(Application *application){
@ -59,7 +64,7 @@ void Snarl_Backend::registerApplication(Application *application){
const char *appName = strdup(application->name().toUtf8().constData());
const char *icon = strdup(application->icon().toUtf8().constData());
snarlInterface->RegisterApp(appName,icon,icon);
snarlInterface->RegisterApp(appName,appName,icon,winIDWidget->winId(),SNORENOTIFIER_MESSAGE_ID);
foreach(Alert *alert,application->alerts()){
snarlInterface->AddClass(appName,alert->name().toUtf8().constData());
@ -91,6 +96,7 @@ int Snarl_Backend::notify(QSharedPointer<Notification>notification){
qDebug()<<"Calling SnarlMessage:"<<notification->id()<<"Title:"<<title<<"Text:"<<text<<"Timeout:"<<QString::number(notification->timeout())<<"Icon:"<<icon;
if(notification->id()==0){
id = snarlInterface->EZNotify(alert,title,text,notification->timeout(), icon);
activeNotifications->insert(id,notification);
}else{
//update message
snarlInterface->EZUpdate(notification->id(),title, text,notification->timeout(),icon);
@ -105,21 +111,51 @@ int Snarl_Backend::notify(QSharedPointer<Notification>notification){
void Snarl_Backend::closeNotification(QSharedPointer<Notification> notification){
_defautSnarlinetrface->Hide(notification->id());
}
bool Snarl_Backend::eventFilter(void *message){
MSG *msg;
msg = (MSG*)message;
if(msg!=NULL){
// uint id = static_cast<LONG32>(reinterpret_cast<DWORD_PTR>(msg->hwnd));
// qDebug()<<QString::number(id);
}
return originalEventFilter==NULL?true:originalEventFilter(message);
activeNotifications->remove(notification->id());
}
bool Snarl_Backend::isPrimaryNotificationBackend(){
return true;
}
SnarlWidget::SnarlWidget(Snarl_Backend * snarl):
_snarl(snarl)
{
}
bool SnarlWidget::winEvent(MSG * msg, long * result){
qDebug()<<"Event loop"<<msg->message<<SNORENOTIFIER_MESSAGE_ID;
if(msg->message == SNORENOTIFIER_MESSAGE_ID){
int action = msg->wParam;
int notificationID = msg->lParam;
QSharedPointer<Notification> notification = _snarl->activeNotifications->value(notificationID);
qDebug()<<"recived a Snarl callback id:"<<notificationID<<"action:"<<action;
switch(action){
case SnarlEnums::NotificationAck:
notification->setActionInvoked(Notification::ACTION_1);
break;
case SnarlEnums::NotificationClicked:
notification->setActionInvoked(Notification::ACTION_2);
break;
case SnarlEnums::NotificationMiddleButton:
notification->setActionInvoked(Notification::ACTION_3);
break;
case SnarlEnums::NotificationClosed:
notification->setActionInvoked(Notification::CLOSED);
break;
case SnarlEnums::NotificationTimedOut:
notification->setActionInvoked(Notification::TIMED_OUT);
break;
default:
qDebug()<<"Unknown snarl action found!!";
return false;
}
_snarl->snore()->notificationActionInvoked(notification);
return true;
}
return false;
}
#include "snarl_backend.moc"

View File

@ -19,8 +19,9 @@
#include "core/interface.h"
#include "SnarlInterface.h"
#include <QWidget>
#include <QAbstractEventDispatcher>
class SnarlWidget;
class Snarl_Backend:public Notification_Backend
{
@ -30,11 +31,10 @@ public:
Snarl_Backend(class SnoreServer *snore=0);
~Snarl_Backend();
bool isPrimaryNotificationBackend();
QHash<int,QSharedPointer<Notification> >* activeNotifications;
private:
static bool eventFilter(void *message);
static QAbstractEventDispatcher::EventFilter originalEventFilter;
SnarlWidget* winIDWidget;
QHash<QString,Snarl::V41::SnarlInterface*> _applications;
Snarl::V41::SnarlInterface* _defautSnarlinetrface;
@ -47,6 +47,18 @@ public slots:
};
class SnarlWidget:public QWidget
{
Q_OBJECT
public:
SnarlWidget(Snarl_Backend* snarl);
bool winEvent( MSG * message, long * result );
private:
Snarl_Backend* _snarl;
};
#endif // SNARL_BACKEND_H