ids are generated by default and not asigned by the backend, somecleanup

This commit is contained in:
Patrick von Reth 2013-07-06 14:12:38 +02:00
parent b4e3488561
commit e28cd4e0d0
26 changed files with 61 additions and 94 deletions

View File

@ -1,7 +1,10 @@
project( SnoreNotify ) project( SnoreNotify )
cmake_minimum_required( VERSION 2.8.8 ) cmake_minimum_required( VERSION 2.8.8 )
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules ${CMAKE_PREFIX_PATH}/share/apps/cmake/modules) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules ${CMAKE_PREFIX_PATH}/share/apps/cmake/modules)
set(CMAKE_AUTOMOC TRUE)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
####################################################################### #######################################################################
option(WITH_FREEDESKTOP_FRONTEND "Build the freedesktop frontend" OFF) option(WITH_FREEDESKTOP_FRONTEND "Build the freedesktop frontend" OFF)
@ -10,7 +13,7 @@ option(WITH_GROWL_BACKEND "Build the Growl backend" ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(KDE4) find_package(KDE4)

View File

@ -100,7 +100,3 @@ bool Alert::isActive() const
} }
} }
#include "application.moc"

View File

@ -6,6 +6,7 @@ set ( SnoreNotify_SRCS ${SnoreNotify_SRCS}
set ( Notification_HDR set ( Notification_HDR
notification.h notification.h
icon.h icon.h
notificationenums.h
) )
install(FILES ${Notification_HDR} DESTINATION include/snore/core/notification) install(FILES ${Notification_HDR} DESTINATION include/snore/core/notification)

View File

@ -179,4 +179,5 @@ const QString &SnoreIcon::url() const
} }
#include "icon.moc" #include "icon.moc"

View File

@ -24,18 +24,21 @@
#include <Qt> #include <Qt>
#include <QTextDocumentFragment> #include <QTextDocumentFragment>
#include <QTextDocument> #include <QTextDocument>
namespace Snore{ namespace Snore{
int Notification::notificationMetaID = qRegisterMetaType<Notification>(); int Notification::notificationMetaID = qRegisterMetaType<Notification>();
int Notification::notificationCount = 0; int Notification::notificationCount = 0;
uint Notification::m_idCount = 1;
class Notification::NotificationData : public QObject class Notification::NotificationData : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
NotificationData ( const QString &application,const QString &alert,const QString &title,const QString &text,const SnoreIcon &icon,int timeout,uint id,NotificationEnums::Prioritys::prioritys priority ): NotificationData ( const QString &application,const QString &alert,const QString &title,const QString &text,const SnoreIcon &icon,int timeout,uint id,NotificationEnums::Prioritys::prioritys priority ):
m_id ( id ), m_id ( id == 0 ?m_idCount++:id),
m_timeout ( timeout ), m_timeout ( timeout ),
m_source ( NULL), m_source ( NULL),
m_application ( application ), m_application ( application ),
@ -46,7 +49,7 @@ public:
m_priority(priority), m_priority(priority),
m_closeReason(NotificationEnums::CloseReasons::NONE) m_closeReason(NotificationEnums::CloseReasons::NONE)
{ {
qDebug()<<"Creating Notification: ActiveNotifications"<<++notificationCount; qDebug()<<"Creating Notification: ActiveNotifications"<<++notificationCount<< "id" << m_id;
m_ref.ref(); m_ref.ref();
} }
@ -136,12 +139,6 @@ const uint &Notification::id() const
return d->m_id; return d->m_id;
} }
void Notification::setId(const uint &id)
{
qDebug()<<"setting notification id:"<<id;
d->m_id = id;
}
const SnoreIcon &Notification::icon() const const SnoreIcon &Notification::icon() const
{ {
return d->m_icon; return d->m_icon;
@ -269,5 +266,4 @@ QDataStream & operator<< ( QDataStream &stream, const Notification::Action &a)
} }
} }
#include "notification.moc"
#include <notification.moc>

View File

@ -19,7 +19,7 @@
#include "../snore_exports.h" #include "../snore_exports.h"
#include "icon.h" #include "icon.h"
#include "NotificationEnums.h" #include "notificationenums.h"
#include <QVariant> #include <QVariant>
namespace Snore{ namespace Snore{
@ -78,10 +78,10 @@ public:
//protected://TODO::make only accesable from a backend //protected://TODO::make only accesable from a backend
void setActionInvoked ( Action *action ); void setActionInvoked ( Action *action );
void setActionInvoked ( const int &actionID); void setActionInvoked ( const int &actionID);
void setId(const uint &id);
private: private:
static uint m_idCount;
class NotificationData; class NotificationData;
NotificationData* d; NotificationData* d;
static int notificationCount; static int notificationCount;

View File

@ -90,4 +90,3 @@ const QStringList &PluginContainer::types(){
} }
} }
#include "plugincontainer.moc"

View File

@ -89,4 +89,3 @@ void SnorePlugin::notificationTimedOut(){
} }
} }
#include "plugins.moc"

View File

@ -99,4 +99,3 @@ void SnoreBackend::addActiveNotification(Notification n)
} }
#include "snorebackend.moc"

View File

@ -19,13 +19,13 @@
#include "../snore_exports.h" #include "../snore_exports.h"
#include "plugins.h" #include "plugins.h"
#include "../notification/notification.h" #include "../notification/notification.h"
#include "../snore.h"
#include <QPointer> #include <QPointer>
#include <QFlag> #include <QFlag>
#include <QtCore> #include <QtCore>
namespace Snore{ namespace Snore{
class SnoreCore;
class SNORE_EXPORT SnoreBackend : public SnorePlugin class SNORE_EXPORT SnoreBackend : public SnorePlugin
{ {
@ -39,7 +39,6 @@ public:
bool requestCloseNotification( Snore::Notification notification,NotificationEnums::CloseReasons::closeReasons reason ); bool requestCloseNotification( Snore::Notification notification,NotificationEnums::CloseReasons::closeReasons reason );
Snore::Notification getActiveNotificationByID(uint id); Snore::Notification getActiveNotificationByID(uint id);
void addActiveNotification(Notification n);
signals: signals:
void closeNotification( Snore::Notification ); void closeNotification( Snore::Notification );
@ -48,7 +47,7 @@ signals:
public slots: public slots:
virtual void slotRegisterApplication ( Snore::Application *application ) = 0; virtual void slotRegisterApplication ( Snore::Application *application ) = 0;
virtual void slotUnregisterApplication ( Snore::Application *application ) = 0; virtual void slotUnregisterApplication ( Snore::Application *application ) = 0;
virtual uint slotNotify ( Snore::Notification notification ) = 0; virtual void slotNotify ( Snore::Notification notification ) = 0;
virtual bool slotCloseNotification ( Snore::Notification notification ) =0; virtual bool slotCloseNotification ( Snore::Notification notification ) =0;
protected: protected:
@ -58,6 +57,8 @@ protected:
private: private:
QHash<uint,Notification> m_activeNotifications; QHash<uint,Notification> m_activeNotifications;
void addActiveNotification(Notification n);
friend void SnoreCore::broadcastNotification(Notification notification);
}; };

View File

@ -43,4 +43,3 @@ bool SnoreFrontend::init( SnoreCore *snore )
return true; return true;
} }
} }
#include "snorefrontend.moc"

View File

@ -218,7 +218,7 @@ void SnoreCore::loadPlugins ( PluginContainer::PluginTypes types )
} }
} }
uint SnoreCore::broadcastNotification ( Notification notification ) void SnoreCore::broadcastNotification ( Notification notification )
{ {
qDebug()<<"Broadcasting"<<notification.title()<<notification.timeout(); qDebug()<<"Broadcasting"<<notification.title()<<notification.timeout();
emit notify ( notification ); emit notify ( notification );
@ -228,11 +228,9 @@ uint SnoreCore::broadcastNotification ( Notification notification )
qDebug()<<"Notification backend "<<m_notificationBackend<<" isnt initialized will snore will exit now"; qDebug()<<"Notification backend "<<m_notificationBackend<<" isnt initialized will snore will exit now";
qApp->quit(); qApp->quit();
} }
notification.setId( m_notificationBackend->slotNotify( notification )); m_notificationBackend->slotNotify( notification );
m_notificationBackend->addActiveNotification(notification); m_notificationBackend->addActiveNotification(notification);
return notification.id();
} }
return -1;
} }
@ -335,5 +333,3 @@ void SnoreCore::requestCloseNotification(Notification n, NotificationEnums::Clos
} }
} }
#include "snore.moc"

View File

@ -45,7 +45,7 @@ public:
void loadPlugins ( PluginContainer::PluginTypes types ); void loadPlugins ( PluginContainer::PluginTypes types );
uint broadcastNotification ( Notification notification ); void broadcastNotification( Notification notification );
void notificationActionInvoked ( Notification notification ); void notificationActionInvoked ( Notification notification );
void addApplication ( Application *application ); void addApplication ( Application *application );

View File

@ -69,13 +69,13 @@ void Growl::slotUnregisterApplication(Application *application){
delete growl; delete growl;
} }
uint Growl::slotNotify(Notification notification){ void Growl::slotNotify(Notification notification){
gntp *growl = m_applications.value(notification.application()); gntp *growl = m_applications.value(notification.application());
if(growl == NULL) if(growl == NULL)
return -1; return;
//qDebug()<<"Notify Growl:"<<notification.application()<<Notification.toPlainText(notification.title()); //qDebug()<<"Notify Growl:"<<notification.application()<<Notification.toPlainText(notification.title());
try{ try{
growl->notify(notification.alert().toUtf8().constData(),m_id, growl->notify(notification.alert().toUtf8().constData(),notification.id(),
Notification::toPlainText(notification.title()).toUtf8().constData(), Notification::toPlainText(notification.title()).toUtf8().constData(),
Notification::toPlainText(notification.text()).toUtf8().constData(), Notification::toPlainText(notification.text()).toUtf8().constData(),
notification.icon().localUrl().isEmpty()?NULL:notification.icon().localUrl().toUtf8().constData(),NULL,"1"); notification.icon().localUrl().isEmpty()?NULL:notification.icon().localUrl().toUtf8().constData(),NULL,"1");
@ -83,7 +83,6 @@ uint Growl::slotNotify(Notification notification){
}catch(const std::exception& e){ }catch(const std::exception& e){
qDebug()<<"Growl:"<<e.what(); qDebug()<<"Growl:"<<e.what();
} }
return m_id++;
} }
bool Growl::slotCloseNotification(Notification notification){ bool Growl::slotCloseNotification(Notification notification){
@ -106,7 +105,3 @@ void Growl::gntpCallback(const int &id,const std::string &reason,const std::stri
} }
s_instance->closeNotification(n,r); s_instance->closeNotification(n,r);
} }
#include "growl.moc"

View File

@ -38,7 +38,7 @@ private:
public slots: public slots:
void slotRegisterApplication(Snore::Application *application); void slotRegisterApplication(Snore::Application *application);
void slotUnregisterApplication(Snore::Application *application); void slotUnregisterApplication(Snore::Application *application);
uint slotNotify(Snore::Notification notification); void slotNotify(Snore::Notification notification);
bool slotCloseNotification(Snore::Notification notification); bool slotCloseNotification(Snore::Notification notification);
}; };

View File

@ -164,17 +164,16 @@ void SnarlBackend::slotUnregisterApplication(Application *application){
delete snarlInterface; delete snarlInterface;
} }
uint SnarlBackend::slotNotify(Notification notification){ void SnarlBackend::slotNotify(Notification notification){
SnarlInterface *snarlInterface = m_applications.value(notification.application()); SnarlInterface *snarlInterface = m_applications.value(notification.application());
if(snarlInterface == NULL){ if(snarlInterface == NULL){
qDebug()<<notification.application()<<"not in snarl interfaces, defaulting"; qDebug()<<notification.application()<<"not in snarl interfaces, defaulting";
qDebug()<<m_applications.keys(); qDebug()<<m_applications.keys();
snarlInterface = m_defautSnarlinetrface; snarlInterface = m_defautSnarlinetrface;
} }
uint id = notification.id();
if(id == 0){ if(!m_idMap.contains(notification.id())){
id = snarlInterface->Notify(notification.alert().toUtf8().constData(), ULONG32 id = snarlInterface->Notify(notification.alert().toUtf8().constData(),
Notification::toPlainText(notification.title()).toUtf8().constData(), Notification::toPlainText(notification.title()).toUtf8().constData(),
Notification::toPlainText(notification.text()).toUtf8().constData(), Notification::toPlainText(notification.text()).toUtf8().constData(),
notification.timeout(), notification.timeout(),
@ -185,9 +184,11 @@ uint SnarlBackend::slotNotify(Notification notification){
foreach(const Notification::Action *a, notification.actions()){ foreach(const Notification::Action *a, notification.actions()){
snarlInterface->AddAction(id,a->name.toUtf8().constData(),QString("@").append(QString::number(a->id)).toUtf8().constData()); snarlInterface->AddAction(id,a->name.toUtf8().constData(),QString("@").append(QString::number(a->id)).toUtf8().constData());
} }
m_idMap[notification.id()] = id;
}else{ }else{
//update message //update message
snarlInterface->Update(notification.id(), snarlInterface->Update(m_idMap[notification.id()],
notification.alert().toUtf8().constData(), notification.alert().toUtf8().constData(),
Notification::toPlainText(notification.title()).toUtf8().constData(), Notification::toPlainText(notification.title()).toUtf8().constData(),
Notification::toPlainText(notification.text()).toUtf8().constData(), Notification::toPlainText(notification.text()).toUtf8().constData(),
@ -196,13 +197,10 @@ uint SnarlBackend::slotNotify(Notification notification){
!notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0, !notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0,
notification.priority()); notification.priority());
} }
startTimeout(id,notification.timeout()); startTimeout(notification.id(),notification.timeout());
return id;
} }
bool SnarlBackend::slotCloseNotification(Notification notification){ bool SnarlBackend::slotCloseNotification(Notification notification){
m_defautSnarlinetrface->Hide(notification.id()); m_defautSnarlinetrface->Hide(m_idMap.remove(notification.id()));
return true; return true;
} }
#include "snarl.moc"

View File

@ -39,9 +39,12 @@ private:
public slots: public slots:
void slotRegisterApplication(Snore::Application *application); void slotRegisterApplication(Snore::Application *application);
void slotUnregisterApplication(Snore::Application *application); void slotUnregisterApplication(Snore::Application *application);
uint slotNotify(Snore::Notification notification); void slotNotify(Snore::Notification notification);
bool slotCloseNotification(Snore::Notification notification); bool slotCloseNotification(Snore::Notification notification);
private:
QHash<uint,LONG32> m_idMap;
}; };

View File

@ -59,7 +59,7 @@ void SnoreToast::slotUnregisterApplication(Application *application)
Q_UNUSED(application) Q_UNUSED(application)
} }
uint SnoreToast::slotNotify(Notification notification) void SnoreToast::slotNotify(Notification notification)
{ {
QProcess *p = new QProcess(this); QProcess *p = new QProcess(this);
@ -81,10 +81,8 @@ uint SnoreToast::slotNotify(Notification notification)
qDebug() << "SnoreToast" << arguements; qDebug() << "SnoreToast" << arguements;
p->start("SnoreToast", arguements); p->start("SnoreToast", arguements);
uint id = p->pid()->dwProcessId; p->setProperty("SNORE_NOTIFICATION_ID",notification.id());
p->setProperty("SNORE_NOTIFICATION_ID",id); qDebug() << notification.id();
return id;
} }
bool SnoreToast::slotCloseNotification(Notification notification) bool SnoreToast::slotCloseNotification(Notification notification)
@ -96,7 +94,8 @@ bool SnoreToast::slotCloseNotification(Notification notification)
void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus) void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus)
{ {
QProcess *p = qobject_cast<QProcess*>(sender()); QProcess *p = qobject_cast<QProcess*>(sender());
Notification n = snore()->getActiveNotificationByID(p->property("SNORE_NOTIFICATION_ID").toUInt()); qDebug() << p->property("SNORE_NOTIFICATION_ID").toUInt();
Notification n = getActiveNotificationByID(p->property("SNORE_NOTIFICATION_ID").toUInt());
NotificationEnums::CloseReasons::closeReason reason = NotificationEnums::CloseReasons::CLOSED; NotificationEnums::CloseReasons::closeReason reason = NotificationEnums::CloseReasons::CLOSED;
@ -127,5 +126,3 @@ void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus)
closeNotification(n,reason); closeNotification(n,reason);
} }
#include "snoretoast.moc"

View File

@ -17,7 +17,7 @@ public:
public slots: public slots:
void slotRegisterApplication(Snore::Application *application); void slotRegisterApplication(Snore::Application *application);
void slotUnregisterApplication(Snore::Application *application); void slotUnregisterApplication(Snore::Application *application);
uint slotNotify(Snore::Notification notification); void slotNotify(Snore::Notification notification);
bool slotCloseNotification(Snore::Notification notification); bool slotCloseNotification(Snore::Notification notification);
private slots: private slots:

View File

@ -13,7 +13,6 @@ Q_EXPORT_PLUGIN2(trayicon,TrayIconNotifer)
TrayIconNotifer::TrayIconNotifer () : TrayIconNotifer::TrayIconNotifer () :
SnoreBackend ( "SystemTray" ), SnoreBackend ( "SystemTray" ),
m_trayIcon(NULL), m_trayIcon(NULL),
m_id ( 0 ),
m_displayed(-1) m_displayed(-1)
{ {
@ -36,13 +35,12 @@ void TrayIconNotifer::slotUnregisterApplication ( Application *application )
Q_UNUSED ( application ) Q_UNUSED ( application )
} }
uint TrayIconNotifer::slotNotify ( Notification notification ) void TrayIconNotifer::slotNotify( Notification notification )
{ {
m_notificationQue.append(notification); m_notificationQue.append(notification);
if(m_lastNotify.elapsed()> Notification::DefaultTimeout * 1000){ if(m_lastNotify.elapsed()> Notification::DefaultTimeout * 1000){
displayNotification(); displayNotification();
} }
return m_id++;
} }
bool TrayIconNotifer::slotCloseNotification( Notification notification ) bool TrayIconNotifer::slotCloseNotification( Notification notification )
@ -87,5 +85,3 @@ void TrayIconNotifer::actionInvoked(){
} }
#include "trayiconnotifer.moc"

View File

@ -22,14 +22,13 @@ public:
public slots: public slots:
void slotRegisterApplication ( Snore::Application *application ); void slotRegisterApplication ( Snore::Application *application );
void slotUnregisterApplication ( Snore::Application *application ); void slotUnregisterApplication ( Snore::Application *application );
uint slotNotify ( Snore::Notification notification ); void slotNotify ( Snore::Notification notification );
bool slotCloseNotification ( Snore::Notification notification ); bool slotCloseNotification ( Snore::Notification notification );
private: private:
QSystemTrayIcon *m_trayIcon; QSystemTrayIcon *m_trayIcon;
QList<Snore::Notification > m_notificationQue; QList<Snore::Notification > m_notificationQue;
QTime m_lastNotify; QTime m_lastNotify;
uint m_id;
uint m_displayed; uint m_displayed;
private slots: private slots:

View File

@ -129,5 +129,3 @@ QString FreedesktopFrontend::GetServerInformation(QString& vendor, QString& vers
specVersion = "0"; specVersion = "0";
return "Snore"; return "Snore";
} }
#include "freedesktopnotificationfrontend.moc"

View File

@ -194,5 +194,3 @@ QByteArray Parser::download(const QUrl &address){
loop.exec(); loop.exec();
return reply->readAll(); return reply->readAll();
} }
#include "parser.moc"

View File

@ -116,5 +116,3 @@ void SnarlNetworkFrontend::callback(const SnarlNotification &sn,QString msg){
} }
} }
#include "snarlnetwork.moc"

View File

@ -67,5 +67,3 @@ void SnoreNotify::exit(){
m_trayIcon->hide(); m_trayIcon->hide();
} }
#include "snorenotify.moc"

View File

@ -70,6 +70,3 @@ void TrayIcon::setPrimaryBackend(){
} }
#include "trayicon.moc"