implemented event filter

This commit is contained in:
Patrick von Reth 2010-10-30 15:49:26 +02:00
parent 098ee04d03
commit 8651ffba4f
6 changed files with 31 additions and 28 deletions

View File

@ -15,9 +15,6 @@ include_directories(
${QT_QTNETWORK_INCLUDE_DIR} ${QT_QTDBUS_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/3party/gntp-send/headers)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR} )
set(LIBRARY_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH})
if (CMAKE_COMPILER_IS_GNUCXX)
set (KDE4_ENABLE_EXCEPTIONS -fexceptions)

View File

@ -20,7 +20,7 @@
#include <QDebug>
#include <QTcpSocket>
#include <Qt>
#include <QTextEdit>
#include <QTextDocumentFragment>
@ -29,11 +29,8 @@ int Notification::DefaultTimeout=10;
QString Notification::toPlainText ( const QString &string )
{
if ( !Qt::mightBeRichText ( string ) )
return string;
QTextEdit te;
te.setHtml ( string );
return te.toPlainText();
QTextDocumentFragment frag = QTextDocumentFragment::fromHtml(string);
return frag.toPlainText();
}
Notification::Notification ( uint id ) :

View File

@ -1,5 +1,3 @@
SET(LIBRARY_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH}/snoreplugins)
add_subdirectory(freedesktopnotification)
add_subdirectory(freedesktopfrontend)
#add_subdirectory(webposter)

View File

@ -46,10 +46,10 @@ void Growl_Backend::registerApplication(Application *application){
for (int i = 0 ; i < alertCount; ++i){
QString name = aList.at(i)->name();
n[i] = new char[name.length()+1];
strcpy(n[i],name.toLatin1().data());
strcpy(n[i],name.toAscii().constData());
}
_applications.insert(application->name(),new Growl(GROWL_TCP,NULL,application->name().toLatin1().data(),(const char**)n,application->alerts().count()));
_applications.insert(application->name(),new Growl(GROWL_TCP,NULL,application->name().toAscii().constData(),(const char**)n,application->alerts().count()));
for (int i = 0 ; i < alertCount; ++i){
delete [] n[i];
@ -72,12 +72,12 @@ int Growl_Backend::notify(QSharedPointer<Notification> notification){
QString title=Notification::toPlainText(notification->title());
QString text=Notification::toPlainText(notification->text());
qDebug()<<"Notify Growl:"<<notification->application()<<title;
growl->Notify(notification->alert().toLatin1().data(),title.toLatin1().data(),text.toLatin1().data(),"",notification->icon().toLatin1().data());
growl->Notify(notification->alert().toAscii().constData(),title.toAscii().constData(),text.toAscii().constData(),"",notification->icon().toAscii().constData());
return ++id;
}
void Growl_Backend::closeNotification(QSharedPointer<Notification> notification){
Q_UNUSED(notification);
}
#include "growl_backend.moc"

View File

@ -21,29 +21,30 @@
#include <QtCore>
#include <QTextEdit>
#include <iostream>
Q_EXPORT_PLUGIN2(snarl_backend,Snarl_Backend)
QAbstractEventDispatcher::EventFilter Snarl_Backend::originalEventFilter = NULL;
Snarl_Backend::Snarl_Backend(SnoreServer *snore):
Notification_Backend("SnarlBackend",snore)
Notification_Backend("SnarlBackend",snore)
{
Snarl::SnarlInterface *snarlInterface = new Snarl::SnarlInterface();
_applications.insert("SnoreNotify",snarlInterface);
qDebug()<<"Initiating Snarl Backend, Snarl version: "<<snarlInterface->GetVersionExA();
_defautSnarlinetrface = new Snarl::SnarlInterface();
//originalEventFilter = QAbstractEventDispatcher::instance()->setEventFilter(&eventFilter);
}
Snarl_Backend::~Snarl_Backend(){
Snarl_Backend::~Snarl_Backend()
{
foreach(Application *a,this->snore()->aplications().values()){
unregisterApplication(a);
}
delete _defautSnarlinetrface;
QAbstractEventDispatcher::instance()->setEventFilter(originalEventFilter);
}
void Snarl_Backend::registerApplication(Application *application){
@ -106,9 +107,15 @@ void Snarl_Backend::closeNotification(QSharedPointer<Notification> notification)
_defautSnarlinetrface->HideMessage(notification->id());
}
bool Snarl_Backend::eventFilter(QObject *obj, QEvent *event){
qDebug()<<obj->objectName();
return true;
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(){

View File

@ -19,6 +19,9 @@
#include "core/interface.h"
#include "SnarlInterface.h"
#include <QAbstractEventDispatcher>
class Snarl_Backend:public Notification_Backend
{
Q_OBJECT
@ -28,10 +31,11 @@ public:
~Snarl_Backend();
bool isPrimaryNotificationBackend();
protected:
bool eventFilter(QObject *obj, QEvent *event);
private:
static bool eventFilter(void *message);
static QAbstractEventDispatcher::EventFilter originalEventFilter;
QHash<QString,Snarl::SnarlInterface*> _applications;
Snarl::SnarlInterface* _defautSnarlinetrface;