started some api changes
This commit is contained in:
parent
7d745469ed
commit
a125761e6f
|
@ -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")
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -23,14 +23,13 @@
|
|||
using namespace Snore;
|
||||
|
||||
Application::Application (const QString &name, const Icon &icon) :
|
||||
m_name ( name ),
|
||||
m_icon(icon),
|
||||
m_initialized ( false )
|
||||
m_name ( name ),
|
||||
m_icon(icon)
|
||||
{
|
||||
}
|
||||
|
||||
Application::Application() :
|
||||
m_name ( "Error: Uninitialized Application" )
|
||||
m_name ( "Error: Uninitialized Application" )
|
||||
{}
|
||||
|
||||
Application::~Application()
|
||||
|
@ -58,25 +57,15 @@ 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 ),
|
||||
m_icon(icon),
|
||||
m_active ( active )
|
||||
m_name ( name ),
|
||||
m_title ( title ),
|
||||
m_icon(icon),
|
||||
m_active ( active )
|
||||
{}
|
||||
|
||||
Alert::Alert() :
|
||||
m_active ( false )
|
||||
m_active ( false )
|
||||
{}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ¬ificationBackends() const;
|
||||
|
|
|
@ -36,8 +36,8 @@
|
|||
using namespace Snore;
|
||||
|
||||
Parser::Parser(SnarlNetworkFrontend *snarl):
|
||||
QObject(snarl),
|
||||
snarl(snarl)
|
||||
QObject(snarl),
|
||||
snarl(snarl)
|
||||
{
|
||||
getSnpType.insert("type",TYPE);
|
||||
getSnpType.insert("app",APP);
|
||||
|
@ -58,12 +58,12 @@ Parser::Parser(SnarlNetworkFrontend *snarl):
|
|||
SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){
|
||||
SnarlNotification sNotification;
|
||||
sNotification.httpClient=false;
|
||||
sNotification.vailid=true;
|
||||
sNotification.vailid=true;
|
||||
sNotification.clientSocket=client;
|
||||
sNotification.isNotification = false;
|
||||
|
||||
|
||||
snpTypes action(ERROR);
|
||||
snpTypes action(ERROR);
|
||||
if(msg.startsWith("GET ")){
|
||||
msg=msg.mid(msg.indexOf("/")+1);
|
||||
msg=msg.mid(0,msg.indexOf(" "));
|
||||
|
@ -123,36 +123,38 @@ 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);
|
||||
}
|
||||
|
||||
if(!appl->alerts().value(sNotification.notification.alert())->isActive())
|
||||
break;
|
||||
sNotification.isNotification = true;
|
||||
return sNotification;
|
||||
break;
|
||||
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())
|
||||
break;
|
||||
sNotification.isNotification = true;
|
||||
return sNotification;
|
||||
break;
|
||||
}
|
||||
case ADD_CLASS:
|
||||
if(sNotification.notification.alert().isEmpty()){
|
||||
qDebug()<<"Error registering alert with empty name";
|
||||
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:
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue