started some api changes

This commit is contained in:
Patrick von Reth 2014-01-10 18:31:28 +01:00
parent 7d745469ed
commit a125761e6f
7 changed files with 60 additions and 54 deletions

View File

@ -13,8 +13,8 @@ option(WITH_SNORE_DEAMON "Build the Snore deamon, which redirects notifications"
####################################################################### #######################################################################
set(SNORE_VERSION_MAJOR 0) set(SNORE_VERSION_MAJOR 0)
set(SNORE_VERSION_MINOR 4) set(SNORE_VERSION_MINOR 5)
set(SNORE_VERSION_SUFFIX "beta2") set(SNORE_VERSION_SUFFIX "pre")

View File

@ -24,8 +24,7 @@ using namespace Snore;
Application::Application (const QString &name, const Icon &icon) : Application::Application (const QString &name, const Icon &icon) :
m_name ( name ), m_name ( name ),
m_icon(icon), m_icon(icon)
m_initialized ( false )
{ {
} }
@ -58,16 +57,6 @@ const AlertList &Application::alerts() const
return m_alerts; return m_alerts;
} }
bool Application::isInitialized()
{
return m_initialized;
}
void Application::setInitialized ( bool b )
{
m_initialized = b;
}
Alert::Alert (const QString &name, const QString &title, const Icon &icon, bool active) : Alert::Alert (const QString &name, const QString &title, const Icon &icon, bool active) :
m_name ( name ), m_name ( name ),
m_title ( title ), m_title ( title ),

View File

@ -41,15 +41,12 @@ public:
const QString &name() const; const QString &name() const;
const Icon &icon() const; const Icon &icon() const;
const AlertList &alerts() const; const AlertList &alerts() const;
bool isInitialized();
void setInitialized ( bool b );
private: private:
QString m_name; QString m_name;
Icon m_icon; Icon m_icon;
AlertList m_alerts; AlertList m_alerts;
bool m_initialized;
}; };

View File

@ -151,22 +151,35 @@ void SnoreCore::notificationActionInvoked ( Notification notification )
} }
} }
void SnoreCore::registerApplication(Application *application)
{
if(!m_applications.contains(application->name()))
{
m_applications.insert ( application->name(),application );
emit applicationInitialized ( application );
}
}
void SnoreCore::addApplication ( Application *application ) void SnoreCore::addApplication ( Application *application )
{ {
m_applications.insert ( application->name(),application ); registerApplication(application);
} }
void SnoreCore::applicationIsInitialized ( Application *application ) void SnoreCore::applicationIsInitialized ( Application *application )
{ {
application->setInitialized ( true ); registerApplication(application);
emit applicationInitialized ( application );
} }
void SnoreCore::removeApplication ( const QString& appName ) void SnoreCore::removeApplication ( const QString& appName )
{ {
qDebug()<<"Remove Application"<<appName; deregisterApplication( m_applications.value ( appName ) );
emit applicationRemoved ( m_applications.value ( appName ) ); }
m_applications.take ( appName )->deleteLater();
void SnoreCore::deregisterApplication(Application *application)
{
emit applicationRemoved (application );
m_applications.take ( application->name() );
application->deleteLater();
} }
const ApplicationsList &SnoreCore::aplications() const const ApplicationsList &SnoreCore::aplications() const

View File

@ -48,11 +48,15 @@ public:
void broadcastNotification( Notification notification ); void broadcastNotification( Notification notification );
void notificationActionInvoked ( Notification notification ); void notificationActionInvoked( Notification notification );//TODO: move to private header
void registerApplication( Application *application );
void deregisterApplication( Application *application );
void Q_DECL_DEPRECATED addApplication ( Application *application );
void Q_DECL_DEPRECATED applicationIsInitialized ( Application* application );
void Q_DECL_DEPRECATED removeApplication ( const QString& appName );
void addApplication ( Application *application );
void applicationIsInitialized ( Application* application );
void removeApplication ( const QString& appName );
const ApplicationsList &aplications() const; const ApplicationsList &aplications() const;
const QStringList &notificationBackends() const; const QStringList &notificationBackends() const;

View File

@ -123,10 +123,10 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){
switch(action){ switch(action){
case NOTIFICATION:{ case NOTIFICATION:{
qDebug()<<sNotification.notification.application(); qDebug() << sNotification.notification.application();
Application * appl=snarl->snore()->aplications().value(sNotification.notification.application()); Application * appl = snarl->snore()->aplications().value(sNotification.notification.application());
if(!appl->isInitialized()){ if(!snarl->snore()->aplications().contains(appl->name())){
snarl->snore()->applicationIsInitialized(appl); snarl->snore()->registerApplication(appl);
} }
if(!appl->alerts().value(sNotification.notification.alert())->isActive()) if(!appl->alerts().value(sNotification.notification.alert())->isActive())
@ -141,18 +141,20 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){
break; break;
} }
if(title.isEmpty()) if(title.isEmpty())
{
title = alert; title = alert;
snarl->snore()->aplications().value(sNotification.notification.application())->addAlert(new Alert(alert,title)); }
snarl->m_applications.value(sNotification.notification.application())->addAlert(new Alert(alert,title));
break; break;
case REGISTER: case REGISTER:
if(!snarl->snore()->aplications().contains(sNotification.notification.application())&&!sNotification.notification.application().isEmpty()){ if(!sNotification.notification.application().isEmpty() && !snarl->m_applications.contains(sNotification.notification.application())){
snarl->snore()->addApplication(new Application(sNotification.notification.application())); snarl->m_applications.insert(sNotification.notification.application(), new Application(sNotification.notification.application()));
} }
else else
qDebug()<<sNotification.notification.application()<<"already registred"; qDebug()<<sNotification.notification.application()<<"already registred";
break; break;
case UNREGISTER: case UNREGISTER:
snarl->snore()->removeApplication(sNotification.notification.application()); snarl->snore()->deregisterApplication( snarl->snore()->aplications().value(sNotification.notification.application()) );
break; break;
case ERROR: case ERROR:
default: default:

View File

@ -61,6 +61,7 @@ private:
class QTcpServer *tcpServer; class QTcpServer *tcpServer;
Parser *parser; Parser *parser;
QHash<uint,SnarlNotification> notifications; QHash<uint,SnarlNotification> notifications;
QHash<QString,Snore::Application*> m_applications;
void callback(const SnarlNotification &sn,QString msg); void callback(const SnarlNotification &sn,QString msg);