added install targets, continued refactoring, added posibility to change notification backend
This commit is contained in:
parent
e0a6355aa4
commit
9cd7ad39bd
|
@ -39,7 +39,7 @@ if (CMAKE_COMPILER_IS_GNUCXX)
|
|||
|
||||
endif(CMAKE_COMPILER_IS_GNUCXX)
|
||||
|
||||
|
||||
|
||||
option(WITH_WEBINTERFACE "Buld with WebInterface" OFF)
|
||||
|
||||
|
||||
add_subdirectory(src)
|
||||
|
|
|
@ -5,9 +5,14 @@ include_directories(
|
|||
|
||||
add_subdirectory(core)
|
||||
|
||||
add_executable ( SnoreNotify main.cpp )
|
||||
target_link_libraries ( SnoreNotify snorecore ${QT_QTGUI_LIBRARY})
|
||||
add_dependencies(SnoreNotify snorecore)
|
||||
add_executable ( snorenotify main.cpp )
|
||||
target_link_libraries ( snorenotify snorecore ${QT_QTGUI_LIBRARY})
|
||||
add_dependencies(snorenotify snorecore)
|
||||
|
||||
install(TARGETS snorenotify RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib)
|
||||
|
||||
|
||||
add_subdirectory(webinterface)
|
||||
add_subdirectory(plugins)
|
||||
|
|
|
@ -16,9 +16,14 @@ set ( SnoreNotify_HDR
|
|||
)
|
||||
|
||||
automoc4_add_library( snorecore SHARED ${SnoreNotify_SRCS})
|
||||
set_target_properties( snorecore PROPERTIES COMPILE_FLAGS "-DSNORECORE_DLL" )
|
||||
set_target_properties( snorecore PROPERTIES OUTPUT_NAME "snore" COMPILE_FLAGS "-DSNORECORE_DLL" )
|
||||
target_link_libraries ( snorecore ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} )
|
||||
|
||||
|
||||
install(TARGETS snorecore RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib)
|
||||
|
||||
install(FILES ${SnoreNotify_HDR} DESTINATION include/snore)
|
||||
|
||||
|
||||
|
|
|
@ -17,19 +17,33 @@
|
|||
#include "application.h"
|
||||
|
||||
|
||||
Application::Application(const QString &name):name(name){}
|
||||
Application::Application(const QString &name):name(name)
|
||||
{}
|
||||
|
||||
Application::Application():name("Error: Uninitialized Application"){}
|
||||
Application::Application():name("Error: Uninitialized Application")
|
||||
{}
|
||||
|
||||
void Application::addAlert(const QString &alert,const QString &title){
|
||||
void Application::addAlert(const QString &alert,const QString &title)
|
||||
{
|
||||
alerts.insert(alert,QSharedPointer<Alert>(new Alert(alert,title)));
|
||||
}
|
||||
|
||||
|
||||
Alert::Alert(const QString &name,const QString &title):name(name),title(title),active(true){}
|
||||
Alert::Alert(const QString &name,const QString &title,bool active):name(name),title(title),active(active){}
|
||||
Alert::Alert(const QString &name,const QString &title):
|
||||
name(name),
|
||||
title(title),
|
||||
active(true)
|
||||
{}
|
||||
|
||||
Alert::Alert():active(false){}
|
||||
Alert::Alert(const QString &name,const QString &title,bool active):
|
||||
name(name),
|
||||
title(title),
|
||||
active(active)
|
||||
{}
|
||||
|
||||
Alert::Alert():
|
||||
active(false)
|
||||
{}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ class SNORE_EXPORT Notification:public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
friend class SnoreServer;
|
||||
friend class Notification_Frontend;
|
||||
public:
|
||||
static int DefaultTimeout;
|
||||
static QString toPlainText(const QString &string);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
QString const SnoreServer::snoreTMP=QDir::temp().path()+"/SnoreNotify/";
|
||||
|
||||
SnoreServer::SnoreServer():primaryNotificationBackend(0)
|
||||
SnoreServer::SnoreServer():_notificationBackend(0)
|
||||
{
|
||||
qDebug()<<"Inititalized";
|
||||
QDir home(snoreTMP);
|
||||
|
@ -41,35 +41,37 @@ SnoreServer::SnoreServer():primaryNotificationBackend(0)
|
|||
}
|
||||
|
||||
void SnoreServer::publicatePlugin(QObject *plugin){
|
||||
qDebug()<<"Loading plugin: "<<plugin->property("name").value<QString>();
|
||||
QString pluginName(plugin->property("name").value<QString>());
|
||||
qDebug()<<"Loading plugin: "<<pluginName;
|
||||
|
||||
|
||||
SnorePlugin *sp=qobject_cast<SnorePlugin*>(plugin);
|
||||
if(sp){
|
||||
plugins.insert(plugin->property("name").value<QString>(),plugin);
|
||||
plugins.insert(pluginName,plugin);
|
||||
qDebug()<<plugin->property("name").value<QString>()<<"is a SnorePlugin";
|
||||
sp->setSnore(this);
|
||||
}
|
||||
Notification_Frontend *nf=qobject_cast<Notification_Frontend*>(plugin);
|
||||
if(nf){
|
||||
qDebug()<<plugin->property("name").value<QString>()<<"is a Notification_Frontend";
|
||||
qDebug()<<pluginName<<"is a Notification_Frontend";
|
||||
nf->setSnore(this);
|
||||
|
||||
}
|
||||
|
||||
Notification_Backend * nb=qobject_cast<Notification_Backend *>(plugin);
|
||||
if(nb){
|
||||
qDebug()<<plugin->property("name").value<QString>()<<"is a Notification_Backend";
|
||||
qDebug()<<pluginName<<"is a Notification_Backend";
|
||||
if(nb->isPrimaryNotificationBackend()){
|
||||
if(primaryNotificationBackend){
|
||||
notyfier.append(primaryNotificationBackend);
|
||||
connect(this,SIGNAL(notify(QSharedPointer<Notification>)),primaryNotificationBackend,SLOT(notify(QSharedPointer<Notification>)));
|
||||
if(_notificationBackend){
|
||||
_notyfier.insert(pluginName,nb);
|
||||
_primaryNotificationBackends.insert(pluginName,nb);
|
||||
connect(this,SIGNAL(notify(QSharedPointer<Notification>)),_notificationBackend,SLOT(notify(QSharedPointer<Notification>)));
|
||||
}
|
||||
primaryNotificationBackend=nb;
|
||||
primaryNotificationBackend->notify(QSharedPointer<Notification>(new Notification(NULL,"Welcome","Snore Notify succesfully registred "+plugin->property("name").value<QString>(),"")));
|
||||
_notificationBackend=nb;
|
||||
_notificationBackend->notify(QSharedPointer<Notification>(new Notification(NULL,"Welcome","Snore Notify succesfully registred "+plugin->property("name").value<QString>(),"")));
|
||||
|
||||
}else{
|
||||
notyfier.append(nb);
|
||||
_notyfier.insert(pluginName,nb);
|
||||
connect(this,SIGNAL(notify(QSharedPointer<Notification>)),nb,SLOT(notify(QSharedPointer<Notification>)));
|
||||
}
|
||||
connect(this,SIGNAL(closeNotify(int)),nb,SLOT(closeNotification(int)));
|
||||
|
@ -80,8 +82,8 @@ void SnoreServer::publicatePlugin(QObject *plugin){
|
|||
int SnoreServer::broadcastNotification(QSharedPointer<Notification> notification){
|
||||
emit notify(notification);
|
||||
qDebug()<<"Broadcasting notification:"<<notification->toString();
|
||||
if(primaryNotificationBackend!=NULL){
|
||||
notification->_id=primaryNotificationBackend->notify(notification);
|
||||
if(_notificationBackend!=NULL){
|
||||
notification->_id=_notificationBackend->notify(notification);
|
||||
std::cout<<"Notification ID: "<<QString::number(notification->_id).toLatin1().data()<<std::endl;
|
||||
return notification->_id;
|
||||
}
|
||||
|
@ -104,24 +106,36 @@ void SnoreServer::notificationActionInvoked(QSharedPointer<Notification> notific
|
|||
}
|
||||
|
||||
void SnoreServer::addApplication(QSharedPointer<Application> application){
|
||||
applications.insert(application->name,application);
|
||||
_applications.insert(application->name,application);
|
||||
emit applicationListChanged();
|
||||
}
|
||||
|
||||
|
||||
bool SnoreServer::applicationListAlertIsActive(const QString &applicationName,const QString &alertName){
|
||||
return applications.contains(applicationName)&&applications.value(applicationName)->alerts.contains(alertName)
|
||||
&&!applications.value(applicationName)->alerts.value(alertName)->active;
|
||||
return _applications.contains(applicationName)&&_applications.value(applicationName)->alerts.contains(alertName)
|
||||
&&!_applications.value(applicationName)->alerts.value(alertName)->active;
|
||||
}
|
||||
|
||||
void SnoreServer::addAlert(const QString &appName,const QString &alertName, const QString &alertTitle){
|
||||
applications.value(appName)->addAlert(alertName,alertTitle);
|
||||
_applications.value(appName)->addAlert(alertName,alertTitle);
|
||||
emit applicationListChanged();
|
||||
}
|
||||
|
||||
void SnoreServer::removeApplication(const QString& appName){
|
||||
applications.take(appName).clear();
|
||||
_applications.take(appName).clear();
|
||||
emit applicationListChanged();
|
||||
}
|
||||
|
||||
const ApplicationsList &SnoreServer::aplicationList() const{
|
||||
return _applications;
|
||||
}
|
||||
|
||||
const QHash<QString,Notification_Backend*> &SnoreServer::primaryNotificationBackends()const{
|
||||
return _primaryNotificationBackends;
|
||||
}
|
||||
|
||||
void SnoreServer::setNotificationBackend(Notification_Backend *backend){
|
||||
_notificationBackend=backend;
|
||||
}
|
||||
|
||||
#include "snoreserver.moc"
|
||||
|
|
|
@ -50,19 +50,20 @@ public:
|
|||
bool applicationListAlertIsActive(const QString &applicationName,const QString &alertName);
|
||||
void addAlert(const QString &appName,const QString &alertName, const QString &alertTitle);
|
||||
void removeApplication(const QString& appName);
|
||||
const ApplicationsList &aplicationList() const;
|
||||
const QHash<QString,Notification_Backend*> &primaryNotificationBackends() const;
|
||||
void setNotificationBackend(Notification_Backend *backend);
|
||||
|
||||
ApplicationsList* getAplicationList(){
|
||||
return &applications;
|
||||
}
|
||||
|
||||
QHash<QString,QObject*> plugins;
|
||||
|
||||
private:
|
||||
ApplicationsList applications;
|
||||
ApplicationsList _applications;
|
||||
|
||||
|
||||
QList<Notification_Backend*> notyfier;
|
||||
Notification_Backend * primaryNotificationBackend;
|
||||
QHash<QString,Notification_Backend*> _notyfier;
|
||||
QHash<QString,Notification_Backend*> _primaryNotificationBackends;
|
||||
Notification_Backend * _notificationBackend;
|
||||
|
||||
|
||||
signals:
|
||||
|
|
|
@ -11,7 +11,7 @@ int main(int argc, char *argv[])
|
|||
QApplication a(argc, argv);
|
||||
SnoreServer s;
|
||||
|
||||
QDir pluginsDir(a.applicationDirPath()+"/plugins");
|
||||
QDir pluginsDir(a.applicationDirPath()+"/snoreplugins");
|
||||
foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
|
||||
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
|
||||
QObject *plugin = loader.instance();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
SET(LIBRARY_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH}/plugins)
|
||||
SET(LIBRARY_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH}/snoreplugins)
|
||||
|
||||
add_subdirectory(freedesktopnotification)
|
||||
add_subdirectory(freedesktopfrontend)
|
||||
|
|
|
@ -6,4 +6,8 @@ if(QT_QTDBUS_FOUND)
|
|||
)
|
||||
automoc4_add_library(dbusbinding MODULE ${DBUSBINDING_SRC} )
|
||||
target_link_libraries(dbusbinding ${QT_QTDBUS_LIBRARY} snorecore )
|
||||
|
||||
install(TARGETS dbusbinding RUNTIME DESTINATION bin/snoreplugins
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib)
|
||||
endif(QT_QTDBUS_FOUND)
|
||||
|
|
|
@ -23,13 +23,17 @@ void DBusPlugin::setSnore(SnoreServer *snore){
|
|||
new DBusBinding(this,snore);
|
||||
}
|
||||
|
||||
DBusBinding::DBusBinding(DBusPlugin* parent,SnoreServer* snore):QDBusAbstractAdaptor(parent),snore(snore){
|
||||
DBusBinding::DBusBinding(DBusPlugin* parent,SnoreServer* snore):
|
||||
QDBusAbstractAdaptor(parent),
|
||||
snore(snore)
|
||||
{
|
||||
registerTypes();
|
||||
QDBusConnection dbus = QDBusConnection::sessionBus();
|
||||
dbus.registerService( "org.SnoreNotify" );
|
||||
dbus.registerObject( "/SnoreNotify", this );
|
||||
connect(snore,SIGNAL(applicationListChanged()),this,SLOT(applicationListChangedSlot()));
|
||||
}
|
||||
|
||||
DBusBinding::~DBusBinding(){
|
||||
QDBusConnection dbus = QDBusConnection::sessionBus();
|
||||
dbus.unregisterService( "/SnoreNotify" );
|
||||
|
@ -43,20 +47,15 @@ void DBusBinding::registerTypes(){
|
|||
qDBusRegisterMetaType<AlertList>();
|
||||
}
|
||||
|
||||
|
||||
ApplicationsList DBusBinding::getApplicationList(){
|
||||
return *snore->getAplicationList();
|
||||
}
|
||||
|
||||
void DBusBinding::setAlertActive(const QString &application,const QString &name,const bool active){
|
||||
QSharedPointer<Application> ap(snore->getAplicationList()->value(application));
|
||||
QSharedPointer<Application> ap(snore->aplicationList().value(application));
|
||||
ap->alerts.value(name)->active=active;
|
||||
emit applicationListChanged(*snore->getAplicationList());
|
||||
emit applicationListChanged(snore->aplicationList());
|
||||
}
|
||||
|
||||
|
||||
void DBusBinding::applicationListChangedSlot(){
|
||||
emit applicationListChanged(*snore->getAplicationList());
|
||||
emit applicationListChanged(snore->aplicationList());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -43,7 +43,6 @@ private:
|
|||
QPointer<SnoreServer> snore;
|
||||
|
||||
public slots:
|
||||
ApplicationsList getApplicationList();
|
||||
void setAlertActive(const QString &application,const QString &alert,const bool active);
|
||||
|
||||
signals:
|
||||
|
|
|
@ -11,6 +11,10 @@ if(QT_QTDBUS_FOUND)
|
|||
automoc4_add_library(freedesktop_frontend MODULE ${FREEDESKTOP_NOTIFICATION_FRONTEND_SRC} )
|
||||
target_link_libraries(freedesktop_frontend snorecore ${QT_QTDBUS_LIBRARY} ${QT_QTGUI_LIBRARY} )
|
||||
|
||||
install(TARGETS freedesktop_frontend RUNTIME DESTINATION bin/snoreplugins
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib)
|
||||
|
||||
endif(QT_QTDBUS_FOUND)
|
||||
|
||||
|
||||
|
|
|
@ -7,6 +7,11 @@ if( GROWL_CPP )
|
|||
)
|
||||
automoc4_add_library(growl_backend MODULE ${GROWL__SRC} )
|
||||
target_link_libraries(growl_backend snorecore ${QT_QTCORE_LIBRARY} ${GROWL_CPP} )
|
||||
|
||||
install(TARGETS growl_backend RUNTIME DESTINATION bin/snoreplugins
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib)
|
||||
|
||||
else( GROWL_CPP )
|
||||
message( STATUS "libgrowl not found..., get it here http://github.com/mattn/gntp-send" )
|
||||
endif( GROWL_CPP )
|
||||
|
|
|
@ -29,11 +29,11 @@ Growl_Backend::~Growl_Backend(){
|
|||
delete growl;
|
||||
}
|
||||
|
||||
int Growl_Backend::notify(QSharedPointer<Notification>notification){
|
||||
QString title=Notification::toPlainText(notification->title);
|
||||
QString text=Notification::toPlainText(notification->text);
|
||||
int Growl_Backend::notify(QSharedPointer<Notification> notification){
|
||||
QString title=Notification::toPlainText(notification->title());
|
||||
QString text=Notification::toPlainText(notification->text());
|
||||
qDebug()<<title<<text;
|
||||
growl->Notify("SnoreNotification",title.toLatin1().data(),text.toLatin1().data(),NULL,notification->getIcon().toLatin1().data());
|
||||
growl->Notify("SnoreNotification",title.toLatin1().data(),text.toLatin1().data(),NULL,notification->icon().toLatin1().data());
|
||||
return ++id;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,5 +3,8 @@ if(WITH_WEBINTERFACE)
|
|||
redirector.cpp
|
||||
)
|
||||
automoc4_add_library(redirector MODULE ${REDIRECTOR_SRC})
|
||||
target_link_libraries(redirector snorecore webinterface)
|
||||
target_link_libraries(redirector snorecore snorewebinterface)
|
||||
install(TARGETS redirector RUNTIME DESTINATION bin/snoreplugins
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib)
|
||||
endif(WITH_WEBINTERFACE)
|
||||
|
|
|
@ -60,7 +60,7 @@ bool Redircetor::parseCommand(QTcpSocket *client, const QString &command){
|
|||
subscriber->connectToHost(addres,port ,QTcpSocket::ReadWrite);
|
||||
if(subscriber->waitForConnected()){
|
||||
SnoreServer* snore(getSnore());
|
||||
foreach(QSharedPointer<Application> a,snore->getAplicationList()->values()){
|
||||
foreach(QSharedPointer<Application> a,snore->aplicationList().values()){
|
||||
QString* app=&a->name;
|
||||
subscriber->write(QString("type=SNP#?version=1.1#?action=register#?app="+*app+"\r\n").toUtf8());
|
||||
foreach(const QSharedPointer<Alert> al,a->alerts.values()){
|
||||
|
|
|
@ -4,5 +4,10 @@ if(WITH_WEBINTERFACE)
|
|||
)
|
||||
|
||||
automoc4_add_library(registredapps MODULE ${REGISTREDAPPS_SRC} )
|
||||
target_link_libraries(registredapps snorecore webinterface)
|
||||
target_link_libraries(registredapps snorecore snorewebinterface)
|
||||
|
||||
install(TARGETS registredapps RUNTIME DESTINATION bin/snoreplugins
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib)
|
||||
|
||||
endif(WITH_WEBINTERFACE)
|
||||
|
|
|
@ -32,7 +32,7 @@ bool RegistredApps::parseCommand(QTcpSocket *client, const QString &command){
|
|||
QString out;
|
||||
out+="Registred Applications\n";
|
||||
SnoreServer *snore=getSnore();
|
||||
foreach(QSharedPointer<Application> a,snore->getAplicationList()->values()){
|
||||
foreach(QSharedPointer<Application> a,snore->aplicationList().values()){
|
||||
out+=a->name+"\n";
|
||||
out+="Registred alerts of "+a->name+"\t alert\t title \t is Active\n";
|
||||
foreach(const QSharedPointer<Alert> al,a->alerts.values())
|
||||
|
|
|
@ -6,4 +6,9 @@ if(WIN32)
|
|||
)
|
||||
automoc4_add_library(snarln_backend MODULE ${SNARL__SRC} )
|
||||
target_link_libraries(snarln_backend snorecore ${QT_QTCORE_LIBRARY} )
|
||||
|
||||
install(TARGETS snarln_backend RUNTIME DESTINATION bin/snoreplugins
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib)
|
||||
|
||||
endif(WIN32)
|
||||
|
|
|
@ -4,3 +4,7 @@ set( SNARL_NETWORK_SRC
|
|||
)
|
||||
automoc4_add_library(snarlnetwork MODULE ${SNARL_NETWORK_SRC} )
|
||||
target_link_libraries(snarlnetwork snorecore ${QT_QTNETWORK_LIBRARY} )
|
||||
|
||||
install(TARGETS snarlnetwork RUNTIME DESTINATION bin/snoreplugins
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib)
|
||||
|
|
|
@ -132,8 +132,8 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){
|
|||
snarl->getSnore()->addAlert(sNotification.notification->application(),alert,title);
|
||||
break;
|
||||
case REGISTER:
|
||||
qDebug()<<snarl->getSnore()->getAplicationList()->keys();
|
||||
if(!snarl->getSnore()->getAplicationList()->contains(sNotification.notification->application())&&!sNotification.notification->application().isEmpty()){
|
||||
qDebug()<<snarl->getSnore()->aplicationList().keys();
|
||||
if(!snarl->getSnore()->aplicationList().contains(sNotification.notification->application())&&!sNotification.notification->application().isEmpty()){
|
||||
snarl->getSnore()->addApplication(QSharedPointer<Application>(new Application(sNotification.notification->application())));
|
||||
}
|
||||
else
|
||||
|
|
|
@ -3,3 +3,7 @@ set( WEBPOSTER_SRC
|
|||
)
|
||||
automoc4_add_library(webposter MODULE ${WEBPOSTER_SRC} )
|
||||
target_link_libraries(webposter snorecore ${QT_QTNETWORK_LIBRARY} )
|
||||
|
||||
install(TARGETS webposter RUNTIME DESTINATION bin/snoreplugins
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib)
|
||||
|
|
|
@ -3,8 +3,12 @@ if(WITH_WEBINTERFACE)
|
|||
set( WEBINTERFACE_SRC
|
||||
webinterface.cpp
|
||||
)
|
||||
automoc4_add_library(webinterface SHARED ${WEBINTERFACE_SRC} )
|
||||
set_target_properties( webinterface PROPERTIES COMPILE_FLAGS "-DWEBINTERFACE_DLL" )
|
||||
target_link_libraries(webinterface snorecore ${QT_QTNETWORK_LIBRARY} )
|
||||
automoc4_add_library(snorewebinterface SHARED ${WEBINTERFACE_SRC} )
|
||||
set_target_properties( snorewebinterface PROPERTIES COMPILE_FLAGS "-DWEBINTERFACE_DLL" )
|
||||
target_link_libraries(snorewebinterface snorecore ${QT_QTNETWORK_LIBRARY} )
|
||||
|
||||
install(TARGETS snorewebinterface RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib)
|
||||
endif(WITH_WEBINTERFACE)
|
||||
|
||||
|
|
Loading…
Reference in New Issue