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 )
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_AUTOMOC TRUE)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
#######################################################################
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)

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
notification.h
icon.h
notificationenums.h
)
install(FILES ${Notification_HDR} DESTINATION include/snore/core/notification)

View File

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

View File

@ -24,18 +24,21 @@
#include <Qt>
#include <QTextDocumentFragment>
#include <QTextDocument>
namespace Snore{
int Notification::notificationMetaID = qRegisterMetaType<Notification>();
int Notification::notificationCount = 0;
uint Notification::m_idCount = 1;
class Notification::NotificationData : public QObject
{
Q_OBJECT
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 ):
m_id ( id ),
m_id ( id == 0 ?m_idCount++:id),
m_timeout ( timeout ),
m_source ( NULL),
m_application ( application ),
@ -46,7 +49,7 @@ public:
m_priority(priority),
m_closeReason(NotificationEnums::CloseReasons::NONE)
{
qDebug()<<"Creating Notification: ActiveNotifications"<<++notificationCount;
qDebug()<<"Creating Notification: ActiveNotifications"<<++notificationCount<< "id" << m_id;
m_ref.ref();
}
@ -89,7 +92,7 @@ Notification::Notification () :
{
}
Notification::Notification ( const QString &application, const QString &alert, const QString &title, const QString &text, const SnoreIcon &icon, int timeout, uint id, NotificationEnums::Prioritys::prioritys priority )
Notification::Notification ( const QString &application, const QString &alert, const QString &title, const QString &text, const SnoreIcon &icon, int timeout, uint id,NotificationEnums::Prioritys::prioritys priority )
{
d = new NotificationData(application,alert,title,text,icon,timeout,id,priority);
}
@ -136,12 +139,6 @@ const uint &Notification::id() const
return d->m_id;
}
void Notification::setId(const uint &id)
{
qDebug()<<"setting notification id:"<<id;
d->m_id = id;
}
const SnoreIcon &Notification::icon() const
{
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 "icon.h"
#include "NotificationEnums.h"
#include "notificationenums.h"
#include <QVariant>
namespace Snore{
@ -40,7 +40,7 @@ public:
public:
Notification ();
Notification (const QString &application,const QString &alert,const QString &title,const QString &text,const SnoreIcon &icon,int timeout=10,uint id=0, NotificationEnums::Prioritys::prioritys priority = NotificationEnums::Prioritys::NORMAL );
Notification (const QString &application,const QString &alert,const QString &title,const QString &text,const SnoreIcon &icon,int timeout=10,uint id = 0, NotificationEnums::Prioritys::prioritys priority = NotificationEnums::Prioritys::NORMAL );
Notification ( const Notification &other );
~Notification();
Notification &operator=(const Notification& other);
@ -78,10 +78,10 @@ public:
//protected://TODO::make only accesable from a backend
void setActionInvoked ( Action *action );
void setActionInvoked ( const int &actionID);
void setId(const uint &id);
private:
static uint m_idCount;
class NotificationData;
NotificationData* d;
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 "plugins.h"
#include "../notification/notification.h"
#include "../snore.h"
#include <QPointer>
#include <QFlag>
#include <QtCore>
namespace Snore{
class SnoreCore;
class SNORE_EXPORT SnoreBackend : public SnorePlugin
{
@ -39,7 +39,6 @@ public:
bool requestCloseNotification( Snore::Notification notification,NotificationEnums::CloseReasons::closeReasons reason );
Snore::Notification getActiveNotificationByID(uint id);
void addActiveNotification(Notification n);
signals:
void closeNotification( Snore::Notification );
@ -48,7 +47,7 @@ signals:
public slots:
virtual void slotRegisterApplication ( 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;
protected:
@ -58,6 +57,8 @@ protected:
private:
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;
}
}
#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();
emit notify ( notification );
@ -228,11 +228,9 @@ uint SnoreCore::broadcastNotification ( Notification notification )
qDebug()<<"Notification backend "<<m_notificationBackend<<" isnt initialized will snore will exit now";
qApp->quit();
}
notification.setId( m_notificationBackend->slotNotify( notification ));
m_notificationBackend->slotNotify( 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 );
uint broadcastNotification ( Notification notification );
void broadcastNotification( Notification notification );
void notificationActionInvoked ( Notification notification );
void addApplication ( Application *application );

View File

@ -69,13 +69,13 @@ void Growl::slotUnregisterApplication(Application *application){
delete growl;
}
uint Growl::slotNotify(Notification notification){
void Growl::slotNotify(Notification notification){
gntp *growl = m_applications.value(notification.application());
if(growl == NULL)
return -1;
return;
//qDebug()<<"Notify Growl:"<<notification.application()<<Notification.toPlainText(notification.title());
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.text()).toUtf8().constData(),
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){
qDebug()<<"Growl:"<<e.what();
}
return m_id++;
}
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);
}
#include "growl.moc"

View File

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

View File

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

View File

@ -39,9 +39,12 @@ private:
public slots:
void slotRegisterApplication(Snore::Application *application);
void slotUnregisterApplication(Snore::Application *application);
uint slotNotify(Snore::Notification notification);
void slotNotify(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)
}
uint SnoreToast::slotNotify(Notification notification)
void SnoreToast::slotNotify(Notification notification)
{
QProcess *p = new QProcess(this);
@ -81,10 +81,8 @@ uint SnoreToast::slotNotify(Notification notification)
qDebug() << "SnoreToast" << arguements;
p->start("SnoreToast", arguements);
uint id = p->pid()->dwProcessId;
p->setProperty("SNORE_NOTIFICATION_ID",id);
return id;
p->setProperty("SNORE_NOTIFICATION_ID",notification.id());
qDebug() << notification.id();
}
bool SnoreToast::slotCloseNotification(Notification notification)
@ -96,7 +94,8 @@ bool SnoreToast::slotCloseNotification(Notification notification)
void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus)
{
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;
@ -127,5 +126,3 @@ void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus)
closeNotification(n,reason);
}
#include "snoretoast.moc"

View File

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

View File

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

View File

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

View File

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

View File

@ -194,5 +194,3 @@ QByteArray Parser::download(const QUrl &address){
loop.exec();
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();
}
#include "snorenotify.moc"

View File

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