mirror of
https://github.com/status-im/snorenotify.git
synced 2025-02-14 17:36:49 +00:00
implemented not working snarl callbacks
This commit is contained in:
parent
2d84729ef1
commit
1ff61ae19c
@ -27,6 +27,7 @@
|
|||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
|
|
||||||
QString const SnoreServer::snoreTMP = QDir::temp().path() +"/SnoreNotify/";
|
QString const SnoreServer::snoreTMP = QDir::temp().path() +"/SnoreNotify/";
|
||||||
|
|
||||||
void SnoreServer::cleanupTMP(){
|
void SnoreServer::cleanupTMP(){
|
||||||
QDir home ( snoreTMP );
|
QDir home ( snoreTMP );
|
||||||
if ( home.exists() )
|
if ( home.exists() )
|
||||||
|
@ -27,99 +27,135 @@
|
|||||||
//disable some msvc warnings
|
//disable some msvc warnings
|
||||||
#define _CRT_SECURE_NO_WARNINGS
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
|
||||||
|
|
||||||
|
#define SNORENOTIFIER_MESSAGE_ID 0x4532
|
||||||
|
|
||||||
using namespace Snarl::V41;
|
using namespace Snarl::V41;
|
||||||
|
|
||||||
Q_EXPORT_PLUGIN2(snarl_backend,Snarl_Backend)
|
Q_EXPORT_PLUGIN2(snarl_backend,Snarl_Backend);
|
||||||
|
|
||||||
QAbstractEventDispatcher::EventFilter Snarl_Backend::originalEventFilter = NULL;
|
|
||||||
|
|
||||||
Snarl_Backend::Snarl_Backend(SnoreServer *snore):
|
Snarl_Backend::Snarl_Backend(SnoreServer *snore):
|
||||||
Notification_Backend("SnarlBackend",snore)
|
Notification_Backend("SnarlBackend",snore)
|
||||||
{
|
{
|
||||||
SnarlInterface *snarlInterface = new SnarlInterface();
|
activeNotifications = new QHash<int,QSharedPointer<Notification> > ;
|
||||||
_applications.insert("SnoreNotify",snarlInterface);
|
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();
|
qDebug()<<"Initiating Snarl Backend, Snarl version: "<<snarlInterface->GetVersion();
|
||||||
_defautSnarlinetrface = new SnarlInterface();
|
_defautSnarlinetrface = new SnarlInterface();
|
||||||
|
|
||||||
|
|
||||||
//originalEventFilter = QAbstractEventDispatcher::instance()->setEventFilter(&eventFilter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Snarl_Backend::~Snarl_Backend()
|
Snarl_Backend::~Snarl_Backend()
|
||||||
{
|
{
|
||||||
foreach(Application *a,this->snore()->aplications().values()){
|
foreach(Application *a,this->snore()->aplications().values()){
|
||||||
unregisterApplication(a);
|
unregisterApplication(a);
|
||||||
}
|
}
|
||||||
delete _defautSnarlinetrface;
|
delete _defautSnarlinetrface;
|
||||||
QAbstractEventDispatcher::instance()->setEventFilter(originalEventFilter);
|
delete activeNotifications;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Snarl_Backend::registerApplication(Application *application){
|
void Snarl_Backend::registerApplication(Application *application){
|
||||||
SnarlInterface *snarlInterface = new SnarlInterface();
|
SnarlInterface *snarlInterface = new SnarlInterface();
|
||||||
_applications.insert(application->name(),snarlInterface);
|
_applications.insert(application->name(),snarlInterface);
|
||||||
|
|
||||||
const char *appName = strdup(application->name().toUtf8().constData());
|
const char *appName = strdup(application->name().toUtf8().constData());
|
||||||
const char *icon = strdup(application->icon().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()){
|
foreach(Alert *alert,application->alerts()){
|
||||||
snarlInterface->AddClass(appName,alert->name().toUtf8().constData());
|
snarlInterface->AddClass(appName,alert->name().toUtf8().constData());
|
||||||
}
|
}
|
||||||
delete [] appName;
|
delete [] appName;
|
||||||
delete [] icon;
|
delete [] icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Snarl_Backend::unregisterApplication(Application *application){
|
void Snarl_Backend::unregisterApplication(Application *application){
|
||||||
SnarlInterface *snarlInterface = _applications.take(application->name());
|
SnarlInterface *snarlInterface = _applications.take(application->name());
|
||||||
if(snarlInterface == NULL)
|
if(snarlInterface == NULL)
|
||||||
return;
|
return;
|
||||||
snarlInterface->UnregisterApp();
|
snarlInterface->UnregisterApp();
|
||||||
delete snarlInterface;
|
delete snarlInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Snarl_Backend::notify(QSharedPointer<Notification>notification){
|
int Snarl_Backend::notify(QSharedPointer<Notification>notification){
|
||||||
SnarlInterface *snarlInterface = _applications.value(notification->application());
|
SnarlInterface *snarlInterface = _applications.value(notification->application());
|
||||||
qDebug()<<notification->application();
|
qDebug()<<notification->application();
|
||||||
if(snarlInterface == NULL)
|
if(snarlInterface == NULL)
|
||||||
snarlInterface = _defautSnarlinetrface;
|
snarlInterface = _defautSnarlinetrface;
|
||||||
|
|
||||||
int id = notification->id();
|
int id = notification->id();
|
||||||
const char *alert = strdup(notification->alert().toUtf8().constData());
|
const char *alert = strdup(notification->alert().toUtf8().constData());
|
||||||
const char *title = strdup(Notification::toPlainText(notification->title()).toUtf8().constData());
|
const char *title = strdup(Notification::toPlainText(notification->title()).toUtf8().constData());
|
||||||
const char *text = strdup(Notification::toPlainText(notification->text()).toUtf8().constData());
|
const char *text = strdup(Notification::toPlainText(notification->text()).toUtf8().constData());
|
||||||
const char *icon = strdup(notification->icon().toUtf8().constData());
|
const char *icon = strdup(notification->icon().toUtf8().constData());
|
||||||
|
|
||||||
qDebug()<<"Calling SnarlMessage:"<<notification->id()<<"Title:"<<title<<"Text:"<<text<<"Timeout:"<<QString::number(notification->timeout())<<"Icon:"<<icon;
|
qDebug()<<"Calling SnarlMessage:"<<notification->id()<<"Title:"<<title<<"Text:"<<text<<"Timeout:"<<QString::number(notification->timeout())<<"Icon:"<<icon;
|
||||||
if(notification->id()==0){
|
if(notification->id()==0){
|
||||||
id = snarlInterface->EZNotify(alert,title,text,notification->timeout(), icon);
|
id = snarlInterface->EZNotify(alert,title,text,notification->timeout(), icon);
|
||||||
}else{
|
activeNotifications->insert(id,notification);
|
||||||
//update message
|
}else{
|
||||||
|
//update message
|
||||||
snarlInterface->EZUpdate(notification->id(),title, text,notification->timeout(),icon);
|
snarlInterface->EZUpdate(notification->id(),title, text,notification->timeout(),icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] alert;
|
delete[] alert;
|
||||||
delete[] title;
|
delete[] title;
|
||||||
delete[] text;
|
delete[] text;
|
||||||
delete[] icon;
|
delete[] icon;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Snarl_Backend::closeNotification(QSharedPointer<Notification> notification){
|
void Snarl_Backend::closeNotification(QSharedPointer<Notification> notification){
|
||||||
_defautSnarlinetrface->Hide(notification->id());
|
_defautSnarlinetrface->Hide(notification->id());
|
||||||
}
|
activeNotifications->remove(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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Snarl_Backend::isPrimaryNotificationBackend(){
|
bool Snarl_Backend::isPrimaryNotificationBackend(){
|
||||||
return true;
|
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"
|
#include "snarl_backend.moc"
|
||||||
|
@ -19,8 +19,9 @@
|
|||||||
#include "core/interface.h"
|
#include "core/interface.h"
|
||||||
#include "SnarlInterface.h"
|
#include "SnarlInterface.h"
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
#include <QAbstractEventDispatcher>
|
class SnarlWidget;
|
||||||
|
|
||||||
class Snarl_Backend:public Notification_Backend
|
class Snarl_Backend:public Notification_Backend
|
||||||
{
|
{
|
||||||
@ -30,11 +31,10 @@ public:
|
|||||||
Snarl_Backend(class SnoreServer *snore=0);
|
Snarl_Backend(class SnoreServer *snore=0);
|
||||||
~Snarl_Backend();
|
~Snarl_Backend();
|
||||||
bool isPrimaryNotificationBackend();
|
bool isPrimaryNotificationBackend();
|
||||||
|
QHash<int,QSharedPointer<Notification> >* activeNotifications;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool eventFilter(void *message);
|
SnarlWidget* winIDWidget;
|
||||||
static QAbstractEventDispatcher::EventFilter originalEventFilter;
|
|
||||||
|
|
||||||
|
|
||||||
QHash<QString,Snarl::V41::SnarlInterface*> _applications;
|
QHash<QString,Snarl::V41::SnarlInterface*> _applications;
|
||||||
Snarl::V41::SnarlInterface* _defautSnarlinetrface;
|
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
|
#endif // SNARL_BACKEND_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user