started refactoring

This commit is contained in:
Patrick von Reth 2012-01-30 12:15:28 +01:00
parent a0241edf2d
commit 556bd5398f
27 changed files with 638 additions and 426 deletions

View File

@ -11,18 +11,17 @@ get_git_head_revision(GIT_REFSPEC SNORE_REVISION)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/version.cpp" @ONLY)
add_subdirectory(notification)
add_subdirectory(plugins)
set ( SnoreNotify_SRCS ${SnoreNotify_SRCS}
snoreserver.cpp
application.cpp
interface.cpp
${CMAKE_CURRENT_BINARY_DIR}/version.cpp
${CMAKE_CURRENT_BINARY_DIR}/version.cpp
)
set ( SnoreNotify_HDR ${SnoreNotify_HDR}
snoreserver.h
application.h
interface.h
snore_exports.h
version.h
)

View File

@ -1,206 +0,0 @@
/****************************************************************************************
* Copyright (c) 2010-2012 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "interface.h"
#include "snoreserver.h"
#include <QTimer>
#include <QPluginLoader>
#include <QDir>
#include <QDebug>
namespace Snore{
SnorePluginInfo::SnorePluginInfo(QString fileName, QString pluginName, SnorePluginInfo::PluginType type)
:m_pluginFile(fileName),
m_pluginName(pluginName),
m_pluginType(type),
m_instance(NULL)
{
}
SnorePlugin *SnorePluginInfo::load(){
if(m_instance != NULL)
return m_instance;
QPluginLoader loader ( SnoreServer::pluginDir().absoluteFilePath(file()));
qDebug()<<"Trying to load"<<file();
if ( !loader.load())
{
qDebug() <<"Failed loading plugin: "<<loader.errorString();
return NULL;
}
m_instance = qobject_cast<SnorePlugin*> ( loader.instance());
return m_instance;
}
const QString & SnorePluginInfo::file()
{
return m_pluginFile;
}
const QString & SnorePluginInfo::name()
{
return m_pluginName;
}
const SnorePluginInfo::PluginType SnorePluginInfo::type()
{
return m_pluginType;
}
SnorePluginInfo::PluginType SnorePluginInfo::typeFromString(const QString &t){
if(t == QLatin1String("backend"))
return BACKEND;
if(t == QLatin1String("secondary_backend"))
return SECONDARY_BACKEND;
if(t == QLatin1String("frontend"))
return FRONTEND;
return PLUGIN;
}
const QStringList &SnorePluginInfo::types(){
static QStringList *list =NULL;
if(list == NULL){
list = new QStringList();
*list<<"backend"<<"secondary_backend"<<"frontend"<<"plugin";
}
return *list;
}
SnorePlugin::SnorePlugin ( QString name ) :
m_name ( name ),
m_initialized(false)
{}
SnorePlugin::~SnorePlugin()
{
qDebug()<<m_name<<this<<"deleted";
}
bool SnorePlugin::init( SnoreServer *snore )
{
qDebug()<<"Initialize"<<m_name<<this<<snore;
this->m_snore = snore;
m_initialized = true;
return true;
}
bool SnorePlugin::isInitialized(){
return m_initialized;
}
SnoreServer* SnorePlugin::snore()
{
return m_snore.data();
}
const QString &SnorePlugin::name() const
{
return m_name;
}
void SnorePlugin::startTimeout(uint id,int timeout){
if(timeout==-1)//sticky
return;
if(m_timeouts.contains(id)){
QTimer *t = m_timeouts.take(id);
t->stop();
t->deleteLater();
m_timeout_order.removeOne(id);
}
QTimer *timer= new QTimer(this);
timer->setInterval(timeout*1000);
timer->setSingleShot(true);
m_timeouts.insert(id,timer);
m_timeout_order.append(id);
connect(timer,SIGNAL(timeout()),this,SLOT(notificationTimedOut()));
timer->start();
}
void SnorePlugin::notificationTimedOut(){
uint id = m_timeout_order.takeFirst();
m_timeouts.take(id)->deleteLater();
if(activeNotifications.contains(id)){
Notification n = activeNotifications.take(id);
snore()->closeNotification(n,NotificationEnums::CloseReasons::TIMED_OUT);
}
}
Notification_Backend::Notification_Backend ( QString name ) :
SnorePlugin ( name )
{
}
Notification_Backend::~Notification_Backend()
{
qDebug()<<"Deleting"<<name();
}
bool Notification_Backend::init( SnoreServer *snore )
{
if(!SnorePlugin::init(snore))
return false;
connect( snore,SIGNAL( closeNotify( Snore::Notification ) ),this,SLOT( closeNotification( Snore::Notification) ) );
connect( snore,SIGNAL( applicationInitialized( Snore::Application* ) ),this,SLOT( registerApplication( Snore::Application* ) ) );
connect( snore,SIGNAL( applicationRemoved( Snore::Application* ) ),this,SLOT( unregisterApplication( Snore::Application* ) ) );
foreach(Application *a,snore->aplications()){
this->registerApplication(a);
}
return true;
}
Secondary_Notification_Backend::Secondary_Notification_Backend(const QString &name)
:Notification_Backend(name)
{
}
Secondary_Notification_Backend::~Secondary_Notification_Backend()
{
qDebug()<<"Deleting"<<name();
}
bool Secondary_Notification_Backend::init(SnoreServer *snore)
{
connect( snore,SIGNAL( notify(Snore::Notification) ),this,SLOT( notify( Snore::Notification ) ) );
return Notification_Backend::init(snore);
}
Notification_Frontend::Notification_Frontend ( const QString &name ) :
SnorePlugin ( name )
{
}
Notification_Frontend::~Notification_Frontend()
{
qDebug()<<"Deleting"<<name();
}
bool Notification_Frontend::init( SnoreServer *snore )
{
if(!SnorePlugin::init(snore))
return false;
connect( snore,SIGNAL ( closeNotify( Snore::Notification ) ),this,SLOT ( notificationClosed( Snore::Notification) ) );
return true;
}
}
#include "interface.moc"

View File

@ -1,157 +0,0 @@
/****************************************************************************************
* Copyright (c) 2010-2012 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#ifndef INTERFACE_H
#define INTERFACE_H
#include "snore_exports.h"
#include "notification/notification.h"
#include <QPointer>
#include <QFlag>
namespace Snore{
class Application;
class SnoreServer;
class SnorePlugin;
class SNORE_EXPORT SnorePluginInfo{
public:
enum PluginType{
ALL = 0x0,//dor loading plugins
BACKEND = 0x1,
SECONDARY_BACKEND = 0x2,
FRONTEND = 0x4,
PLUGIN = 0x8
};
Q_DECLARE_FLAGS(PluginTypes, PluginType)
SnorePluginInfo(QString fileName,QString pluginName,PluginType type);
SnorePlugin *load();
const QString &file();
const QString &name();
const SnorePluginInfo::PluginType type();
static Snore::SnorePluginInfo::PluginType typeFromString(const QString &t);
static const QStringList &types();
private:
QPointer<SnorePlugin> m_instance;
QString m_pluginFile;
QString m_pluginName;
Snore::SnorePluginInfo::PluginType m_pluginType;
};
class SNORE_EXPORT SnorePlugin:public QObject
{
Q_OBJECT
public:
SnorePlugin ( QString name);
virtual ~SnorePlugin();
virtual bool init( SnoreServer* snore );
bool isInitialized();
SnoreServer* snore();
const QString &name() const;
protected:
QHash<uint,Notification> activeNotifications;
void startTimeout(uint id,int timeout);
private slots:
void notificationTimedOut();
private:
SnorePlugin() {}
QString m_name;
bool m_initialized;
QPointer<SnoreServer> m_snore;
QHash<uint,QTimer*> m_timeouts;
QList<uint> m_timeout_order;
};
}
Q_DECLARE_OPERATORS_FOR_FLAGS(Snore::SnorePluginInfo::PluginTypes)
Q_DECLARE_INTERFACE ( Snore::SnorePlugin,
"org.Snore.SnorePlugin/1.0" )
namespace Snore{
class SNORE_EXPORT Notification_Backend:public SnorePlugin
{
Q_OBJECT
Q_INTERFACES(Snore::SnorePlugin)
public:
Notification_Backend ( QString name );
virtual ~Notification_Backend();
virtual bool init(SnoreServer *snore);
public slots:
virtual void registerApplication ( Snore::Application *application ) =0;
virtual void unregisterApplication ( Snore::Application *application ) =0;
virtual uint notify ( Snore::Notification notification ) =0;
virtual void closeNotification ( Snore::Notification notification ) =0;
};
}
Q_DECLARE_INTERFACE ( Snore::Notification_Backend,
"org.Snore.NotificationBackend/1.0" )
namespace Snore{
class SNORE_EXPORT Secondary_Notification_Backend:public Notification_Backend
{
Q_OBJECT
Q_INTERFACES(Snore::SnorePlugin Snore::Notification_Backend)
public:
Secondary_Notification_Backend(const QString &name);
virtual ~Secondary_Notification_Backend();
virtual bool init(SnoreServer *snore);
};
}
Q_DECLARE_INTERFACE ( Snore::Secondary_Notification_Backend,
"org.Snore.SecondaryNotificationBackend/1.0" )
namespace Snore{
class SNORE_EXPORT Notification_Frontend:public SnorePlugin
{
Q_OBJECT
Q_INTERFACES(Snore::SnorePlugin)
public:
Notification_Frontend ( const QString &name);
virtual ~Notification_Frontend();
virtual bool init(SnoreServer *snore);
public slots:
virtual void actionInvoked( Snore::Notification notification )=0;
virtual void notificationClosed( Snore::Notification notification )=0;
};
}
Q_DECLARE_INTERFACE ( Snore::Notification_Frontend,
"org.Snore.NotificationFrontend/1.0" )
#endif//INTERFACE_H

View File

@ -17,6 +17,7 @@
#include "notification.h"
#include "snoreserver.h"
#include "notification/icon.h"
#include "plugins/plugincontainer.h"
#include <QDebug>
#include <QTcpSocket>
@ -67,7 +68,7 @@ public:
uint m_id;
int m_timeout;
Notification::Action *m_actionInvoked;
Notification_Frontend *m_source;
SnoreFrontend *m_source;
QString m_application;
QString m_alert;
QString m_title;
@ -156,11 +157,11 @@ void Notification::setActionInvoked ( const int &id)
d->m_actionInvoked = d->m_actions[id];
}
void Notification::setSource(Notification_Frontend *source) const{
void Notification::setSource(SnoreFrontend *source) const{
d->m_source = source;
}
Notification_Frontend *Notification::source() const
SnoreFrontend *Notification::source() const
{
return d->m_source;
}

View File

@ -79,8 +79,8 @@ public:
void setActionInvoked ( Action *action );
void setActionInvoked ( const int &actionID);
const Action* actionInvoked() const;
void setSource(class Notification_Frontend *source)const;
class Notification_Frontend *source() const;
void setSource(class SnoreFrontend *source)const;
class SnoreFrontend *source() const;
const QString &application() const;
const QString &title() const;
const QString &text() const;

View File

@ -0,0 +1,19 @@
set ( SnoreNotify_SRCS ${SnoreNotify_SRCS}
plugins/plugincontainer.cpp
plugins/plugins.cpp
plugins/snorefrontend.cpp
plugins/snorebackend.cpp
PARENT_SCOPE)
set ( Plugins_HDR
plugincontainer.h
plugins.h
snorefrontend.h
snorebackend.h
)
install(FILES ${Plugins_HDR} DESTINATION include/snore/core/plugins)

View File

@ -0,0 +1,90 @@
/****************************************************************************************
* Copyright (c) 2010-2012 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "../snoreserver.h"
#include "plugins.h"
#include "snorebackend.h"
#include "snorefrontend.h"
#include <QTimer>
#include <QPluginLoader>
#include <QDir>
#include <QDebug>
namespace Snore{
PluginContainer::PluginContainer(QString fileName, QString pluginName, PluginContainer::PluginType type)
:m_pluginFile(fileName),
m_pluginName(pluginName),
m_pluginType(type),
m_instance(NULL)
{
}
SnorePlugin *PluginContainer::load(){
if(m_instance != NULL)
return m_instance;
QPluginLoader loader ( SnoreServer::pluginDir().absoluteFilePath(file()));
qDebug()<<"Trying to load"<<file();
if ( !loader.load())
{
qDebug() <<"Failed loading plugin: "<<loader.errorString();
return NULL;
}
m_instance = qobject_cast<SnorePlugin*> ( loader.instance());
return m_instance;
}
const QString & PluginContainer::file()
{
return m_pluginFile;
}
const QString & PluginContainer::name()
{
return m_pluginName;
}
const PluginContainer::PluginType PluginContainer::type()
{
return m_pluginType;
}
PluginContainer::PluginType PluginContainer::typeFromString(const QString &t){
if(t == QLatin1String("backend"))
return BACKEND;
if(t == QLatin1String("secondary_backend"))
return SECONDARY_BACKEND;
if(t == QLatin1String("frontend"))
return FRONTEND;
return PLUGIN;
}
const QStringList &PluginContainer::types(){
static QStringList *list = NULL;
if(list == NULL){
list = new QStringList();
*list<<"backend"<<"secondary_backend"<<"frontend"<<"plugin";
}
return *list;
}
}
#include "plugincontainer.moc"

View File

@ -0,0 +1,61 @@
/****************************************************************************************
* Copyright (c) 2010-2012 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#ifndef PLUGINCONTAINER_H
#define PLUGINCONTAINER_H
#include "../snore_exports.h"
#include <QPointer>
#include <QFlag>
namespace Snore{
class SnoreServer;
class SnorePlugin;
class SnoreFrontend;
class SnoreBackend;
class SnoreSecondaryBackend;
class SNORE_EXPORT PluginContainer{
public:
enum PluginType{
ALL = 0x0,//for loading plugins
BACKEND = 0x1,
SECONDARY_BACKEND = 0x2,
FRONTEND = 0x4,
PLUGIN = 0x8
};
Q_DECLARE_FLAGS(PluginTypes, PluginType)
PluginContainer(QString fileName,QString pluginName,PluginType type);
SnorePlugin *load();
const QString &file();
const QString &name();
const PluginContainer::PluginType type();
static Snore::PluginContainer::PluginType typeFromString(const QString &t);
static const QStringList &types();
private:
QPointer<SnorePlugin> m_instance;
QString m_pluginFile;
QString m_pluginName;
Snore::PluginContainer::PluginType m_pluginType;
};
}
Q_DECLARE_OPERATORS_FOR_FLAGS(Snore::PluginContainer::PluginTypes)
#endif//PLUGINCONTAINER_H

View File

@ -0,0 +1,88 @@
/****************************************************************************************
* Copyright (c) 2010-2012 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "../snoreserver.h"
#include "snorebackend.h"
#include "snorefrontend.h"
#include <QTimer>
#include <QPluginLoader>
#include <QDir>
#include <QDebug>
namespace Snore{
SnorePlugin::SnorePlugin ( QString name ) :
m_name ( name ),
m_initialized(false)
{}
SnorePlugin::~SnorePlugin()
{
qDebug()<<m_name<<this<<"deleted";
}
bool SnorePlugin::init( SnoreServer *snore )
{
qDebug()<<"Initialize"<<m_name<<this<<snore;
this->m_snore = snore;
m_initialized = true;
return true;
}
bool SnorePlugin::isInitialized(){
return m_initialized;
}
SnoreServer* SnorePlugin::snore()
{
return m_snore.data();
}
const QString &SnorePlugin::name() const
{
return m_name;
}
void SnorePlugin::startTimeout(uint id,int timeout){
if(timeout==-1)//sticky
return;
if(m_timeouts.contains(id)){
QTimer *t = m_timeouts.take(id);
t->stop();
t->deleteLater();
m_timeout_order.removeOne(id);
}
QTimer *timer= new QTimer(this);
timer->setInterval(timeout*1000);
timer->setSingleShot(true);
m_timeouts.insert(id,timer);
m_timeout_order.append(id);
connect(timer,SIGNAL(timeout()),this,SLOT(notificationTimedOut()));
timer->start();
}
void SnorePlugin::notificationTimedOut(){
uint id = m_timeout_order.takeFirst();
m_timeouts.take(id)->deleteLater();
if(activeNotifications.contains(id)){
Notification n = activeNotifications.take(id);
snore()->closeNotification(n,NotificationEnums::CloseReasons::TIMED_OUT);
}
}
}
#include "plugins.moc"

View File

@ -0,0 +1,66 @@
/****************************************************************************************
* Copyright (c) 2010-2012 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#ifndef SNORE_PLUGINS_H
#define SNORE_PLUGINS_H
#include "../snore_exports.h"
#include "../notification/notification.h"
#include "plugincontainer.h"
#include <QPointer>
#include <QFlag>
namespace Snore{
class Application;
class SnoreServer;
class SNORE_EXPORT SnorePlugin:public QObject
{
Q_OBJECT
public:
SnorePlugin ( QString name);
virtual ~SnorePlugin();
virtual bool init( SnoreServer* snore );
bool isInitialized();
SnoreServer* snore();
const QString &name() const;
protected:
QHash<uint,Notification> activeNotifications;
void startTimeout(uint id,int timeout);
private slots:
void notificationTimedOut();
private:
SnorePlugin() {}
QString m_name;
bool m_initialized;
QPointer<SnoreServer> m_snore;
QHash<uint,QTimer*> m_timeouts;
QList<uint> m_timeout_order;
};
}
Q_DECLARE_INTERFACE ( Snore::SnorePlugin,
"org.Snore.SnorePlugin/1.0" )
#endif//SNORE_PLUGINS_H

View File

@ -0,0 +1,72 @@
/****************************************************************************************
* Copyright (c) 2010-2012 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "snorebackend.h"
#include "../snoreserver.h"
#include <QTimer>
#include <QPluginLoader>
#include <QDir>
#include <QDebug>
namespace Snore{
SnoreBackend::SnoreBackend ( QString name ) :
SnorePlugin ( name )
{
}
SnoreBackend::~SnoreBackend()
{
qDebug()<<"Deleting"<<name();
}
bool SnoreBackend::init( SnoreServer *snore )
{
if(!SnorePlugin::init(snore))
return false;
connect( snore,SIGNAL( closeNotify( Snore::Notification ) ),this,SLOT( closeNotification( Snore::Notification) ) );
connect( snore,SIGNAL( applicationInitialized( Snore::Application* ) ),this,SLOT( registerApplication( Snore::Application* ) ) );
connect( snore,SIGNAL( applicationRemoved( Snore::Application* ) ),this,SLOT( unregisterApplication( Snore::Application* ) ) );
foreach(Application *a,snore->aplications()){
this->registerApplication(a);
}
return true;
}
SnoreSecondaryBackend::SnoreSecondaryBackend(const QString &name)
:SnoreBackend(name)
{
}
SnoreSecondaryBackend::~SnoreSecondaryBackend()
{
qDebug()<<"Deleting"<<name();
}
bool SnoreSecondaryBackend::init(SnoreServer *snore)
{
connect( snore,SIGNAL( notify(Snore::Notification) ),this,SLOT( notify( Snore::Notification ) ) );
return SnoreBackend::init(snore);
}
}
#include "snorebackend.moc"

View File

@ -0,0 +1,74 @@
/****************************************************************************************
* Copyright (c) 2010-2012 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#ifndef SNORE_BACKEND_H
#define SNORE_BACKEND_H
#include "../snore_exports.h"
#include "../notification/notification.h"
#include "plugins.h"
#include <QPointer>
#include <QFlag>
#include <QtCore>
namespace Snore{
class SnoreServer;
class SNORE_EXPORT SnoreBackend:public SnorePlugin
{
Q_OBJECT
Q_INTERFACES(Snore::SnorePlugin)
public:
SnoreBackend ( QString name );
virtual ~SnoreBackend();
virtual bool init(SnoreServer *snore);
public slots:
virtual void registerApplication ( Snore::Application *application ) =0;
virtual void unregisterApplication ( Snore::Application *application ) =0;
virtual uint notify ( Snore::Notification notification ) =0;
virtual void closeNotification ( Snore::Notification notification ) =0;
};
}
Q_DECLARE_INTERFACE ( Snore::SnoreBackend,
"org.Snore.NotificationBackend/1.0" )
namespace Snore{
class SnoreServer;
class SNORE_EXPORT SnoreSecondaryBackend:public SnoreBackend
{
Q_OBJECT
Q_INTERFACES(Snore::SnorePlugin Snore::SnoreBackend)
public:
SnoreSecondaryBackend(const QString &name);
virtual ~SnoreSecondaryBackend();
virtual bool init(SnoreServer *snore);
};
}
Q_DECLARE_INTERFACE ( Snore::SnoreSecondaryBackend,
"org.Snore.SecondaryNotificationBackend/1.0" )
#endif//SNORE_BACKEND_H

View File

@ -0,0 +1,46 @@
/****************************************************************************************
* Copyright (c) 2010-2012 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "snorefrontend.h"
#include "../snoreserver.h"
#include <QTimer>
#include <QPluginLoader>
#include <QDir>
#include <QDebug>
namespace Snore{
SnoreFrontend::SnoreFrontend ( const QString &name ) :
SnorePlugin ( name )
{
}
SnoreFrontend::~SnoreFrontend()
{
qDebug()<<"Deleting"<<name();
}
bool SnoreFrontend::init( SnoreServer *snore )
{
if(!SnorePlugin::init(snore))
return false;
connect( snore,SIGNAL ( closeNotify( Snore::Notification ) ),this,SLOT ( notificationClosed( Snore::Notification) ) );
return true;
}
}
#include "snorefrontend.moc"

View File

@ -0,0 +1,51 @@
/****************************************************************************************
* Copyright (c) 2010-2012 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#ifndef SNORE_FRONTEND_H
#define SNORE_FRONTEND_H
#include "../snore_exports.h"
#include "../notification/notification.h"
#include "plugins.h"
#include <QPointer>
#include <QFlag>
namespace Snore{
class Application;
class SnoreServer;
class SnorePlugin;
class SNORE_EXPORT SnoreFrontend:public SnorePlugin
{
Q_OBJECT
Q_INTERFACES(Snore::SnorePlugin)
public:
SnoreFrontend ( const QString &name);
virtual ~SnoreFrontend();
virtual bool init(SnoreServer *snore);
public slots:
virtual void actionInvoked( Snore::Notification notification )=0;
virtual void notificationClosed( Snore::Notification notification )=0;
};
}
Q_DECLARE_INTERFACE ( Snore::SnoreFrontend,
"org.Snore.NotificationFrontend/1.0" )
#endif//SNORE_FRONTEND_H

View File

@ -16,6 +16,11 @@
#include "snoreserver.h"
#include "notification/notification.h"
#include "plugins/plugincontainer.h"
#include "plugins/plugins.h"
#include "plugins/snorebackend.h"
#include "plugins/snorefrontend.h"
#include "version.h"
#include <iostream>
@ -29,7 +34,7 @@
namespace Snore{
QHash<QString,SnorePluginInfo*> SnoreServer::s_pluginCache = QHash<QString,SnorePluginInfo*>() ;
QHash<QString,PluginContainer*> SnoreServer::s_pluginCache = QHash<QString,PluginContainer*>() ;
QString SnoreServer::s_pluginPath = QString(qApp->applicationDirPath()+"/snoreplugins");
@ -55,18 +60,19 @@ SnoreServer::SnoreServer ( QSystemTrayIcon *trayIcon ) :
}
QHash<QString, SnorePluginInfo *> SnoreServer::pluginCache(){
QHash<QString, PluginContainer *> SnoreServer::pluginCache(){
if(!s_pluginCache.isEmpty())
return s_pluginCache;
QSettings cache(SnoreServer::pluginDir().absoluteFilePath("plugin.cache"),QSettings::IniFormat);
QString version = cache.value("version").toString();
int size = cache.beginReadArray("plugins");
if(size == 0){
if(size == 0 || version != Version::revision()){
updatePluginCache();
}else{
for(int i=0;i<size;++i) {
cache.setArrayIndex(i);
SnorePluginInfo::PluginType type = (SnorePluginInfo::PluginType)cache.value("type").toInt();
SnorePluginInfo *info = new SnorePluginInfo(cache.value("fileName").toString(),cache.value("name").toString(),type);
PluginContainer::PluginType type = (PluginContainer::PluginType)cache.value("type").toInt();
PluginContainer *info = new PluginContainer(cache.value("fileName").toString(),cache.value("name").toString(),type);
s_pluginCache.insert(info->name(),info);
}
cache.endArray();
@ -83,7 +89,7 @@ void SnoreServer::updatePluginCache(const QString &pluginPath){
s_pluginCache.clear();
foreach(const QString &type,SnorePluginInfo::types()){
foreach(const QString &type,PluginContainer::types()){
QDir plPath(SnoreServer::pluginDir().absoluteFilePath(type));
qDebug()<<"Searching for plugins in"<<plPath.path();
foreach (QString fileName, plPath.entryList(QDir::Files)) {
@ -101,7 +107,7 @@ void SnoreServer::updatePluginCache(const QString &pluginPath){
plugin->deleteLater();
continue;
}
SnorePluginInfo *info = new SnorePluginInfo( SnoreServer::pluginDir().relativeFilePath(filepath),sp->name(),SnorePluginInfo::typeFromString(type));
PluginContainer *info = new PluginContainer( SnoreServer::pluginDir().relativeFilePath(filepath),sp->name(),PluginContainer::typeFromString(type));
s_pluginCache.insert(info->name(),info);
sp->deleteLater();
qDebug()<<"added "<<info->name()<<"to cache";
@ -109,7 +115,8 @@ void SnoreServer::updatePluginCache(const QString &pluginPath){
}
qDebug()<<s_pluginCache.keys();
QList<SnorePluginInfo*> plugins = s_pluginCache.values();
cache.setValue("version",Version::revision());
QList<PluginContainer*> plugins = s_pluginCache.values();
cache.beginWriteArray("plugins");
for(int i=0;i< plugins.size();++i) {
cache.setArrayIndex(i);
@ -125,26 +132,29 @@ const QDir &SnoreServer::pluginDir()
//TODO:fix logic
static QDir *plDir = NULL;
if(plDir == NULL){
qDebug()<<"PluginDir"<<s_pluginPath;
plDir = new QDir(s_pluginPath);
if(!plDir->exists())
plDir = new QDir(LIBSNORE_PLUGIN_PATH);
}
qDebug()<<"SnorePluginDir:"<<plDir->path();
return *plDir;
}
void SnoreServer::publicatePlugin ( SnorePluginInfo::PluginTypes types )
void SnoreServer::publicatePlugin ( PluginContainer::PluginTypes types )
{
foreach ( SnorePluginInfo *info, SnoreServer::pluginCache().values())
qDebug()<<"PluginInfo"<<SnoreServer::pluginCache().keys();
foreach ( PluginContainer *info, SnoreServer::pluginCache().values())
{
if(types == SnorePluginInfo::ALL or types.testFlag(info->type())){
if(types == PluginContainer::ALL or types.testFlag(info->type())){
switch(info->type()){
case SnorePluginInfo::BACKEND:{
case PluginContainer::BACKEND:{
qDebug() <<info->name()<<"is a Notification_Backend";
m_notificationBackends.append( info->name());
break;
}
case SnorePluginInfo::SECONDARY_BACKEND:{
Secondary_Notification_Backend *nb = qobject_cast<Secondary_Notification_Backend *> ( info->load() );
case PluginContainer::SECONDARY_BACKEND:{
SnoreSecondaryBackend *nb = qobject_cast<SnoreSecondaryBackend *> ( info->load() );
if(!nb->init( this )){
nb->deleteLater();
break;
@ -152,8 +162,8 @@ void SnoreServer::publicatePlugin ( SnorePluginInfo::PluginTypes types )
m_secondaryNotificationBackends.append(info->name());
break;
}
case SnorePluginInfo::FRONTEND:{
Notification_Frontend * nf = qobject_cast<Notification_Frontend*> (info->load());
case PluginContainer::FRONTEND:{
SnoreFrontend * nf = qobject_cast<SnoreFrontend*> (info->load());
qDebug() <<info->name()<<"is a Notification_Frontend";
if(!nf->init( this )){
nf->deleteLater();
@ -162,7 +172,7 @@ void SnoreServer::publicatePlugin ( SnorePluginInfo::PluginTypes types )
m_Frontends.append(info->name());
break;
}
case SnorePluginInfo::PLUGIN:{
case PluginContainer::PLUGIN:{
qDebug() <<info->name()<<"is a SnorePlugin";
if(!info->load()->init(this)){
info->load()->deleteLater();
@ -207,7 +217,7 @@ void SnoreServer::closeNotification ( Notification notification,const Notificati
void SnoreServer::notificationActionInvoked ( Notification notification )
{
emit actionInvoked(notification);
Notification_Frontend *nf= notification.source();
SnoreFrontend *nf= notification.source();
if ( nf != NULL )
{
nf->actionInvoked ( notification );
@ -255,10 +265,12 @@ const QStringList &SnoreServer::secondaryNotificationBackends() const
void SnoreServer::setPrimaryNotificationBackend ( const QString &backend )
{
if(!m_notificationBackends.contains(backend))
if(!pluginCache().contains(backend)){
qDebug()<<"Unknown Backend:"<<backend;
return;
}
qDebug()<<"Setting Notification Backend to:"<<backend;
m_notificationBackend = qobject_cast<Notification_Backend*>(pluginCache()[backend]->load());
m_notificationBackend = qobject_cast<SnoreBackend*>(pluginCache()[backend]->load());
if(!m_notificationBackend->isInitialized())
m_notificationBackend->init(this);
}

View File

@ -18,7 +18,8 @@
#define SNORESERVER_H
#include "snore_exports.h"
#include "interface.h"
#include "plugins/plugincontainer.h"
#include "notification/notification.h"
#include <QStringList>
@ -37,7 +38,7 @@ public:
public:
SnoreServer (QSystemTrayIcon *trayIcon=0 );
void publicatePlugin ( SnorePluginInfo::PluginTypes types );
void publicatePlugin ( PluginContainer::PluginTypes types );
uint broadcastNotification ( Notification notification );
@ -60,9 +61,9 @@ public:
private:
static QHash<QString,SnorePluginInfo*> pluginCache();
static QHash<QString,PluginContainer*> pluginCache();
static QHash<QString,SnorePluginInfo*> s_pluginCache;
static QHash<QString,PluginContainer*> s_pluginCache;
ApplicationsList m_applications;
@ -71,7 +72,7 @@ private:
QStringList m_secondaryNotificationBackends;
QStringList m_plugins;
Notification_Backend * m_notificationBackend;
SnoreBackend * m_notificationBackend;
QSystemTrayIcon *m_trayIcon;
static QString s_pluginPath;

View File

@ -32,7 +32,7 @@ using namespace Snore;
Q_EXPORT_PLUGIN2(freedesktop_frontend,FreedesktopNotification_Frontend)
FreedesktopNotification_Frontend::FreedesktopNotification_Frontend():
Notification_Frontend("FreedesktopNotification_Frontend")
SnoreFrontend("FreedesktopNotification_Frontend")
{
}
@ -47,7 +47,7 @@ bool FreedesktopNotification_Frontend::init(SnoreServer *snore){
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.registerService( "org.freedesktop.Notifications" );
dbus.registerObject( "/org/freedesktop/Notifications", this );
return Notification_Frontend::init(snore);
return SnoreFrontend::init(snore);
}
void FreedesktopNotification_Frontend::actionInvoked(Notification notification) {

View File

@ -16,12 +16,12 @@
#ifndef FREEDESKTOPNOTIFICATION_FRONTEND_H
#define FREEDESKTOPNOTIFICATION_FRONTEND_H
#include "core/interface.h"
#include "core/plugins/snorefrontend.h"
#include <QtDBus>
class FreedesktopNotification_Frontend:public Snore::Notification_Frontend{
class FreedesktopNotification_Frontend:public Snore::SnoreFrontend{
Q_OBJECT
Q_INTERFACES(Snore::Notification_Frontend)
Q_INTERFACES(Snore::SnoreFrontend)
public:
FreedesktopNotification_Frontend();
~FreedesktopNotification_Frontend();

View File

@ -29,7 +29,7 @@ Q_EXPORT_PLUGIN2(growl_backend,Growl_Backend)
Growl_Backend *Growl_Backend::instance = NULL;
Growl_Backend::Growl_Backend():
Notification_Backend("Growl"),
SnoreBackend("Growl"),
_id(0)
{
instance = this;

View File

@ -16,18 +16,17 @@
#ifndef GROWL_BACKEND_H
#define GROWL_BACKEND_H
#include "core/interface.h"
#include "core/plugins/snorebackend.h"
#include <string>
class Growl_Backend:public Snore::Notification_Backend
class Growl_Backend:public Snore::SnoreBackend
{
Q_OBJECT
Q_INTERFACES(Snore::Notification_Backend)
Q_INTERFACES(Snore::SnoreBackend)
public:
Growl_Backend();
~Growl_Backend();
bool isPrimaryNotificationBackend(){return true;}
static void gntpCallback(const int &id,const std::string &reason,const std::string &data);
private:
//a static instance for the static callback methode

View File

@ -36,7 +36,7 @@ using namespace Snarl::V42;
Q_EXPORT_PLUGIN2(snarl_backend,Snarl_Backend)
Snarl_Backend::Snarl_Backend():
Notification_Backend("Snarl"),
SnoreBackend("Snarl"),
_away(false)
{
@ -60,7 +60,7 @@ bool Snarl_Backend::init(SnoreServer *snore){
qDebug()<<"Initiating Snarl Backend, Snarl version: "<<snarlInterface->GetVersion();
m_defautSnarlinetrface = new SnarlInterface();
return Notification_Backend::init(snore);
return SnoreBackend::init(snore);
}
void Snarl_Backend::registerApplication(Application *application){
@ -142,9 +142,6 @@ void Snarl_Backend::closeNotification(Notification notification){
activeNotifications.remove(notification.id());
}
bool Snarl_Backend::isPrimaryNotificationBackend(){
return true;
}
SnarlWidget::SnarlWidget(Snarl_Backend * snarl):
_snarl(snarl)

View File

@ -16,7 +16,7 @@
#ifndef SNARL_BACKEND_H
#define SNARL_BACKEND_H
#include "core/interface.h"
#include "core/plugins/snorebackend.h"
#include "SnarlInterface.h"
#include <QWidget>
@ -27,16 +27,15 @@ namespace Snore{
class SnarlWidget;
class Snarl_Backend:public Snore::Notification_Backend
class Snarl_Backend:public Snore::SnoreBackend
{
Q_OBJECT
Q_INTERFACES(Snore::Notification_Backend)
Q_INTERFACES(Snore::SnoreBackend)
friend class SnarlWidget;
public:
Snarl_Backend();
~Snarl_Backend();
virtual bool init(Snore::SnoreServer *snore);
bool isPrimaryNotificationBackend();
private:
SnarlWidget* winIDWidget;

View File

@ -28,7 +28,7 @@ Q_EXPORT_PLUGIN2(snalnetwork,SnarlNetworkFrontend)
SnarlNetworkFrontend::SnarlNetworkFrontend():
Notification_Frontend("SnarlNetworkFrontend")
SnoreFrontend("SnarlNetworkFrontend")
{
}
@ -46,7 +46,7 @@ bool SnarlNetworkFrontend::init(SnoreServer *snore){
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(handleConnection()));
std::cout<<"The Snarl Network Protokoll is developed for Snarl <http://www.fullphat.net/>"<<std::endl;
}
return Notification_Frontend::init(snore);
return SnoreFrontend::init(snore);
}

View File

@ -16,7 +16,7 @@
#ifndef SNARLNETWORK_H
#define SNARLNETWORK_H
#include "core/interface.h"
#include "core/plugins/snorefrontend.h"
#include "parser.h"
#include <QPointer>
@ -35,9 +35,9 @@ struct SnarlNotification{
QPointer<class QTcpSocket> clientSocket;
};
class SnarlNetworkFrontend:public Snore::Notification_Frontend{
class SnarlNetworkFrontend:public Snore::SnoreFrontend{
Q_OBJECT
Q_INTERFACES(Snore::Notification_Frontend)
Q_INTERFACES(Snore::SnoreFrontend)
friend class Parser;
public:
static const int port=9887;

View File

@ -11,7 +11,7 @@ using namespace Snore;
Q_EXPORT_PLUGIN2(trayicon_backend,TrayIconNotifer)
TrayIconNotifer::TrayIconNotifer () :
Notification_Backend ( "SystemTray" ),
SnoreBackend ( "SystemTray" ),
m_id ( 0 ),
m_displayed(-1)
{
@ -23,7 +23,7 @@ bool TrayIconNotifer::init(SnoreServer *snore){
m_trayIcon = snore->trayIcon();
if(m_trayIcon == NULL)
return false;
return Notification_Backend::init(snore);
return SnoreBackend::init(snore);
}
void TrayIconNotifer::registerApplication ( Application *application )

View File

@ -1,7 +1,7 @@
#ifndef TRAYICONNOTIFER_H
#define TRAYICONNOTIFER_H
#include "core/interface.h"
#include "core/plugins/snorebackend.h"
#include <QTime>
@ -11,10 +11,10 @@ namespace Snore{
class QSystemTrayIcon;
class TrayIconNotifer:public Snore::Notification_Backend
class TrayIconNotifer:public Snore::SnoreBackend
{
Q_OBJECT
Q_INTERFACES(Snore::Notification_Backend)
Q_INTERFACES(Snore::SnoreBackend)
public:
TrayIconNotifer ();
virtual bool init(Snore::SnoreServer *snore);

View File

@ -36,7 +36,7 @@ SnoreNotify::SnoreNotify():
{
m_trayIcon = new TrayIcon();
m_snore = new Snore::SnoreServer(m_trayIcon->trayIcon());
m_snore->publicatePlugin(SnorePluginInfo::ALL);
m_snore->publicatePlugin(PluginContainer::ALL);
load();
m_trayIcon->initConextMenu(m_snore);