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_MINOR 4)
set(SNORE_VERSION_SUFFIX "beta2")
set(SNORE_VERSION_MINOR 5)
set(SNORE_VERSION_SUFFIX "pre")

View File

@ -24,8 +24,7 @@ using namespace Snore;
Application::Application (const QString &name, const Icon &icon) :
m_name ( name ),
m_icon(icon),
m_initialized ( false )
m_icon(icon)
{
}
@ -58,16 +57,6 @@ const AlertList &Application::alerts() const
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) :
m_name ( name ),
m_title ( title ),

View File

@ -41,15 +41,12 @@ public:
const QString &name() const;
const Icon &icon() const;
const AlertList &alerts() const;
bool isInitialized();
void setInitialized ( bool b );
private:
QString m_name;
Icon m_icon;
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 )
{
m_applications.insert ( application->name(),application );
registerApplication(application);
}
void SnoreCore::applicationIsInitialized ( Application *application )
{
application->setInitialized ( true );
emit applicationInitialized ( application );
registerApplication(application);
}
void SnoreCore::removeApplication ( const QString& appName )
{
qDebug()<<"Remove Application"<<appName;
emit applicationRemoved ( m_applications.value ( appName ) );
m_applications.take ( appName )->deleteLater();
deregisterApplication( m_applications.value ( appName ) );
}
void SnoreCore::deregisterApplication(Application *application)
{
emit applicationRemoved (application );
m_applications.take ( application->name() );
application->deleteLater();
}
const ApplicationsList &SnoreCore::aplications() const

View File

@ -48,11 +48,15 @@ public:
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 QStringList &notificationBackends() const;

View File

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

View File

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