quite alot of refactoring, dont init unneeded plugins

This commit is contained in:
Patrick von Reth 2012-01-26 00:45:22 +01:00
parent 22c8c82b4d
commit 1f66bb6dab
18 changed files with 197 additions and 143 deletions

View File

@ -21,10 +21,11 @@
#include <QHash>
namespace Snore{
class Application;
class Alert;
typedef QHash<QString,class Application*> ApplicationsList ;
typedef QHash<QString,class Alert*> AlertList;
typedef QHash<QString,Application*> ApplicationsList ;
typedef QHash<QString,Alert*> AlertList;
class SNORE_EXPORT Application:public QObject
{

View File

@ -18,26 +18,29 @@
#include "snoreserver.h"
#include <QTimer>
#include <QDebug>
namespace Snore{
SnorePlugin::SnorePlugin ( QString name,SnoreServer *snore ) :
_name ( name ),
_snore ( snore )
SnorePlugin::SnorePlugin ( QString name ) :
_name ( name )
{}
SnorePlugin::~SnorePlugin()
{
delete _snore;
qDebug()<<_name<<this<<"deleted";
_snore->deleteLater();
}
void SnorePlugin::setSnore ( SnoreServer *snore )
void SnorePlugin::init( SnoreServer *snore )
{
this->_snore=snore;
this->_snore = snore;
qDebug()<<"Initialize"<<_name<<this<<snore;
}
SnoreServer* SnorePlugin::snore()
{
return _snore;
return _snore.data();
}
const QString &SnorePlugin::name() const
@ -72,8 +75,8 @@ void SnorePlugin::notificationTimedOut(){
}
}
Notification_Backend::Notification_Backend ( QString name, SnoreServer *snore ) :
SnorePlugin ( name,snore )
Notification_Backend::Notification_Backend ( QString name ) :
SnorePlugin ( name )
{
}
@ -82,8 +85,18 @@ Notification_Backend::~Notification_Backend()
{
}
Notification_Frontend::Notification_Frontend ( QString name, SnoreServer *snore ) :
SnorePlugin ( name,snore )
void Notification_Backend::init( SnoreServer *snore )
{
SnorePlugin::init(snore);
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* ) ) );
if(!isPrimaryNotificationBackend())
connect( snore,SIGNAL( notify(Snore::Notification) ),this,SLOT( notify( Snore::Notification ) ) );
}
Notification_Frontend::Notification_Frontend ( QString name ) :
SnorePlugin ( name )
{
}
@ -91,6 +104,10 @@ Notification_Frontend::Notification_Frontend ( QString name, SnoreServer *snore
Notification_Frontend::~Notification_Frontend()
{
}
void Notification_Frontend::init( SnoreServer *snore )
{
SnorePlugin::init(snore);
connect( snore,SIGNAL ( closeNotify( Snore::Notification ) ),this,SLOT ( notificationClosed( Snore::Notification) ) );
}
}
#include "interface.moc"

View File

@ -19,17 +19,20 @@
#include "snore_exports.h"
#include "notification/notification.h"
#include <QPointer>
namespace Snore{
class Application;
class SnoreServer;
class SNORE_EXPORT SnorePlugin:public QObject
{
Q_OBJECT
public:
SnorePlugin ( QString name,class SnoreServer *snore=0 );
SnorePlugin ( QString name);
virtual ~SnorePlugin();
virtual void setSnore ( class SnoreServer* snore );
virtual class SnoreServer* snore();
virtual void init( SnoreServer* snore );
SnoreServer* snore();
const QString &name() const;
protected:
@ -41,7 +44,7 @@ private slots:
private:
SnorePlugin() {}
QString _name;
class SnoreServer *_snore;
QPointer<SnoreServer> _snore;
QHash<uint,QTimer*> timeouts;
QList<uint> timeout_order;
@ -59,8 +62,9 @@ class SNORE_EXPORT Notification_Backend:public SnorePlugin
Q_OBJECT
Q_INTERFACES(Snore::SnorePlugin)
public:
Notification_Backend ( QString name,class SnoreServer *snore=0 );
Notification_Backend ( QString name );
virtual ~Notification_Backend();
virtual void init(SnoreServer *snore);
virtual bool isPrimaryNotificationBackend() =0;
@ -81,8 +85,9 @@ class SNORE_EXPORT Notification_Frontend:public SnorePlugin
Q_OBJECT
Q_INTERFACES(Snore::SnorePlugin)
public:
Notification_Frontend ( QString name,class SnoreServer *snore=0 );
Notification_Frontend ( QString name);
virtual ~Notification_Frontend();
virtual void init(SnoreServer *snore);
public slots:
virtual void actionInvoked( Snore::Notification notification )=0;

View File

@ -81,7 +81,9 @@ SnoreIcon::SnoreIcon(const SnoreIcon &other):
{ }
SnoreIcon::~SnoreIcon()
{ }
{
d.clear();
}
const QImage &SnoreIcon::image() const{

View File

@ -104,7 +104,9 @@ Notification::Notification ( const Notification &other ):
{
}
Notification::~Notification(){
Notification::~Notification()
{
d.clear();
}
Notification &Notification::operator=(const Notification& other)

View File

@ -39,8 +39,8 @@ QString const SnoreServer::snoreTMP(){
SnoreServer::SnoreServer ( QSystemTrayIcon *trayIcon ) :
_notificationBackend ( NULL ),
_trayIcon ( trayIcon )
m_notificationBackend ( NULL ),
m_trayIcon ( trayIcon )
{
QDir home ( snoreTMP() );
if ( !home.exists() ){
@ -50,13 +50,14 @@ SnoreServer::SnoreServer ( QSystemTrayIcon *trayIcon ) :
if ( trayIcon!=NULL )
{
publicatePlugin ( new TrayIconNotifer ( this,trayIcon ) );
publicatePlugin ( new TrayIconNotifer ( trayIcon ) );
}
}
void SnoreServer::publicatePlugin ( const QString &fileName )
{
QPluginLoader loader ( fileName );
qDebug()<<"Trying to load"<<fileName;
if ( !loader.load())
{
qDebug() <<"Failed loading plugin: "<<loader.errorString();
@ -79,36 +80,32 @@ void SnoreServer::publicatePlugin ( SnorePlugin *plugin )
qDebug() <<"Loading plugin: "<<pluginName;
plugins.insert ( pluginName,plugin );
m_plugins.insert ( pluginName,plugin );
qDebug() <<pluginName<<"is a SnorePlugin";
plugin->setSnore ( this );
Notification_Backend * nb=qobject_cast<Notification_Backend *> ( plugin );
Notification_Backend * nb = qobject_cast<Notification_Backend *> ( plugin );
if ( nb )
{
qDebug() <<pluginName<<"is a Notification_Backend";
if ( nb->isPrimaryNotificationBackend() )
{
_primaryNotificationBackends.append( pluginName);
if ( _notificationBackend == NULL )
m_primaryNotificationBackends.append( pluginName);
if ( m_notificationBackend == NULL )
{
_notificationBackend = nb;
qDebug() <<"Primary NotificationBackend is"<<nb->name();
m_notificationBackend = nb;
}
}
else
{
connect ( this,SIGNAL ( notify(Snore::Notification) ),nb,SLOT( notify( Snore::Notification ) ) );
}
_notyfier.insert ( pluginName,nb );
connect ( this,SIGNAL( closeNotify( Snore::Notification ) ),nb,SLOT ( closeNotification( Snore::Notification) ) );
connect ( this,SIGNAL( applicationInitialized( Snore::Application* ) ),nb,SLOT ( registerApplication( Snore::Application* ) ) );
connect ( this,SIGNAL( applicationRemoved( Snore::Application* ) ),nb,SLOT ( unregisterApplication( Snore::Application* ) ) );
}else{
Notification_Frontend * nf=qobject_cast<Notification_Frontend*> ( plugin );
nb->init( this );
}
m_notyfier.insert ( pluginName,nb );
}else{
Notification_Frontend * nf = qobject_cast<Notification_Frontend*> ( plugin );
if(nf != NULL){
connect ( this,SIGNAL ( closeNotify( Snore::Notification ) ),nf,SLOT ( notificationClosed( Snore::Notification) ) );
qDebug() <<pluginName<<"is a Notification_Frontend";
nf->init( this );
if(nf != NULL)
m_frontends.insert(nf->name(),nf);
}
}
}
@ -117,9 +114,9 @@ uint SnoreServer::broadcastNotification ( Notification notification )
{
qDebug()<<"Broadcasting"<<notification.title()<<notification.timeout();
emit notify ( notification );
if ( _notificationBackend != NULL )
if ( m_notificationBackend != NULL )
{
notification.setId(_notificationBackend->notify( notification ));
notification.setId(m_notificationBackend->notify( notification ));
return notification.id();
}
return -1;
@ -167,19 +164,20 @@ const ApplicationsList &SnoreServer::aplications() const
const QStringList &SnoreServer::primaryNotificationBackends() const
{
return _primaryNotificationBackends;
return m_primaryNotificationBackends;
}
void SnoreServer::setPrimaryNotificationBackend ( const QString &backend )
{
if(!_primaryNotificationBackends.contains(backend))
if(!m_primaryNotificationBackends.contains(backend))
return;
qDebug()<<"Setting Notification Backend to:"<<backend;
_notificationBackend = qobject_cast<Notification_Backend*>(plugins[backend]);
m_notificationBackend = qobject_cast<Notification_Backend*>(m_plugins[backend]);
m_notificationBackend->init(this);
}
const QString &SnoreServer::primaryNotificationBackend(){
return _notificationBackend->name();
return m_notificationBackend->name();
}
}

View File

@ -58,12 +58,13 @@ private:
ApplicationsList _applications;
QHash<QString,Notification_Backend*> _notyfier;
QStringList _primaryNotificationBackends;
Notification_Backend * _notificationBackend;
QHash<QString,SnorePlugin*> plugins;
QHash<QString,Notification_Backend*> m_notyfier;
QHash<QString,Notification_Frontend*> m_frontends;
QStringList m_primaryNotificationBackends;
Notification_Backend * m_notificationBackend;
QHash<QString,SnorePlugin*> m_plugins;
class QSystemTrayIcon *_trayIcon;
class QSystemTrayIcon *m_trayIcon;
signals:

View File

@ -8,8 +8,8 @@
using namespace Snore;
TrayIconNotifer::TrayIconNotifer ( SnoreServer *snore, QSystemTrayIcon *icon ) :
Notification_Backend ( "SystemTray",snore ),
TrayIconNotifer::TrayIconNotifer ( QSystemTrayIcon *icon ) :
Notification_Backend ( "SystemTray" ),
_trayIcon ( icon ),
_id ( 0 ),
_displayed(-1)

View File

@ -11,7 +11,7 @@ class TrayIconNotifer:public Snore::Notification_Backend
Q_OBJECT
Q_INTERFACES(Snore::Notification_Backend)
public:
TrayIconNotifer ( class Snore::SnoreServer *snore=0,class QSystemTrayIcon *icon=0 );
TrayIconNotifer (class QSystemTrayIcon *icon=0 );
bool isPrimaryNotificationBackend();
public slots:

View File

@ -31,18 +31,26 @@ using namespace Snore;
Q_EXPORT_PLUGIN2(freedesktop_frontend,FreedesktopNotification_Frontend)
FreedesktopNotification_Frontend::FreedesktopNotification_Frontend(SnoreServer *snore):
Notification_Frontend("FreedesktopNotification_Frontend",snore)
FreedesktopNotification_Frontend::FreedesktopNotification_Frontend():
Notification_Frontend("FreedesktopNotification_Frontend")
{
new NotificationsAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.registerService( "org.freedesktop.Notifications" );
dbus.registerObject( "/org/freedesktop/Notifications", this );
}
FreedesktopNotification_Frontend::~FreedesktopNotification_Frontend(){
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.unregisterService( "org.freedesktop.Notifications" );
qDebug()<<"FreedesktopNotification_Frontend"<<"bye";
}
void FreedesktopNotification_Frontend::init(SnoreServer *snore){
Notification_Frontend::init(snore);
qDebug()<<"arg"<<snore<<this;
new NotificationsAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.registerService( "org.freedesktop.Notifications" );
dbus.registerObject( "/org/freedesktop/Notifications", this );
}
void FreedesktopNotification_Frontend::actionInvoked(Notification notification) {
@ -70,6 +78,9 @@ uint FreedesktopNotification_Frontend::Notify(const QString &app_name, uint repl
hints["image_data"].value<QDBusArgument>()>>image;
icon = SnoreIcon(image.toQImage());
}
qDebug()<<snore()<<this;
if(!snore()->aplications().contains(app_name)){
#ifdef HAVE_KDE
SnoreIcon appIcon = SnoreIcon(KIconLoader::global()->iconPath(app_icon, KIconLoader::Desktop));

View File

@ -23,8 +23,9 @@ class FreedesktopNotification_Frontend:public Snore::Notification_Frontend{
Q_OBJECT
Q_INTERFACES(Snore::Notification_Frontend)
public:
FreedesktopNotification_Frontend(class Snore::SnoreServer *snore=0);
FreedesktopNotification_Frontend();
~FreedesktopNotification_Frontend();
virtual void init(Snore::SnoreServer *snore);
void actionInvoked(Snore::Notification notification);
void notificationClosed(Snore::Notification notification);

View File

@ -28,18 +28,17 @@ Q_EXPORT_PLUGIN2(growl_backend,Growl_Backend)
Growl_Backend *Growl_Backend::instance = NULL;
Growl_Backend::Growl_Backend(SnoreServer *snore):
Notification_Backend("Growl",snore),
Growl_Backend::Growl_Backend():
Notification_Backend("Growl"),
_id(0)
{
instance = this;
}
Growl_Backend::~Growl_Backend(){
foreach(Application *a,this->snore()->aplications().values()){
unregisterApplication(a);
}
qDebug()<<"Growl_Backend bye bye";
}
void Growl_Backend::registerApplication(Application *application){

View File

@ -25,7 +25,7 @@ class Growl_Backend:public Snore::Notification_Backend
Q_OBJECT
Q_INTERFACES(Snore::Notification_Backend)
public:
Growl_Backend(class Snore::SnoreServer *snore=0);
Growl_Backend();
~Growl_Backend();
bool isPrimaryNotificationBackend(){return true;}
static void gntpCallback(const int &id,const std::string &reason,const std::string &data);

View File

@ -35,16 +35,10 @@ using namespace Snarl::V42;
Q_EXPORT_PLUGIN2(snarl_backend,Snarl_Backend)
Snarl_Backend::Snarl_Backend(SnoreServer *snore):
Notification_Backend("Snarl",snore),
Snarl_Backend::Snarl_Backend():
Notification_Backend("Snarl"),
_away(false)
{
winIDWidget = new SnarlWidget(this);
SnarlInterface *snarlInterface = new SnarlInterface();
_applications.insert("SnoreNotify",snarlInterface);
qDebug()<<"Initiating Snarl Backend, Snarl version: "<<snarlInterface->GetVersion();
_defautSnarlinetrface = new SnarlInterface();
}
@ -56,6 +50,16 @@ Snarl_Backend::~Snarl_Backend()
delete _defautSnarlinetrface;
}
void Snarl_Backend::init(SnoreServer *snore){
Notification_Backend::init(snore);
winIDWidget = new SnarlWidget(this);
SnarlInterface *snarlInterface = new SnarlInterface();
_applications.insert("SnoreNotify",snarlInterface);
qDebug()<<"Initiating Snarl Backend, Snarl version: "<<snarlInterface->GetVersion();
_defautSnarlinetrface = new SnarlInterface();
}
void Snarl_Backend::registerApplication(Application *application){
SnarlInterface *snarlInterface = NULL;
if(_applications.contains(application->name())){

View File

@ -21,6 +21,10 @@
#include <QWidget>
namespace Snore{
class SnoreServer;
}
class SnarlWidget;
class Snarl_Backend:public Snore::Notification_Backend
@ -29,8 +33,9 @@ class Snarl_Backend:public Snore::Notification_Backend
Q_INTERFACES(Snore::Notification_Backend)
friend class SnarlWidget;
public:
Snarl_Backend(class Snore::SnoreServer *snore=0);
Snarl_Backend();
~Snarl_Backend();
virtual void init(Snore::SnoreServer *snore);
bool isPrimaryNotificationBackend();
private:

View File

@ -27,16 +27,10 @@ using namespace Snore;
Q_EXPORT_PLUGIN2(snalnetwork,SnarlNetworkFrontend)
SnarlNetworkFrontend::SnarlNetworkFrontend(SnoreServer *snore):
Notification_Frontend("SnarlNetworkFrontend",snore)
SnarlNetworkFrontend::SnarlNetworkFrontend():
Notification_Frontend("SnarlNetworkFrontend")
{
parser=new Parser(this);
tcpServer=new QTcpServer(this);
if(!tcpServer->listen(QHostAddress::Any,port)){
qDebug()<<"The port is already used";
}
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(handleConnection()));
std::cout<<"The Snarl Network Protokoll is developed for Snarl <http://www.fullphat.net/>"<<std::endl;
}
SnarlNetworkFrontend::~SnarlNetworkFrontend(){
@ -44,6 +38,18 @@ SnarlNetworkFrontend::~SnarlNetworkFrontend(){
delete tcpServer;
}
void SnarlNetworkFrontend::init(SnoreServer *snore){
Notification_Frontend::init(snore);
parser=new Parser(this);
tcpServer=new QTcpServer(this);
if(!tcpServer->listen(QHostAddress::Any,port)){
qDebug()<<"The port is already used";
}else{
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(handleConnection()));
std::cout<<"The Snarl Network Protokoll is developed for Snarl <http://www.fullphat.net/>"<<std::endl;
}
}
void SnarlNetworkFrontend::actionInvoked(Notification notification){
//TODO:fix callback

View File

@ -43,8 +43,9 @@ public:
static const int port=9887;
public:
SnarlNetworkFrontend(Snore::SnoreServer *snore=0);
SnarlNetworkFrontend();
~SnarlNetworkFrontend();
virtual void init(Snore::SnoreServer *snore);
void actionInvoked(Snore::Notification notification);
void notificationClosed(Snore::Notification notification);

View File

@ -5,10 +5,10 @@ import re
rn = re.compile("\r\n$",re.MULTILINE)
n = re.compile("(?<!\r)\n",re.MULTILINE)
oldLicense = re.compile("^" + re.escape( "/****************************************************************************************" ) + ".*2011.*" + re.escape("****************************************************************************************/" ),re.MULTILINE|re.DOTALL)
oldLicense = re.compile("^" + re.escape( "/****************************************************************************************" ) + ".*2010.*" + re.escape("****************************************************************************************/" ),re.MULTILINE|re.DOTALL)
newLicense = """/****************************************************************************************
* Copyright (c) 2011-2012 Patrick von Reth <patrick.vonreth@gmail.com> *
* 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 *
@ -31,6 +31,7 @@ def myWalk(root):
for fileName in files:
fileName = os.path.join(root,fileName)
if os.path.isfile(fileName) and (fileName.endswith(".h") or fileName.endswith(".cpp")):
print(fileName)
f = open(fileName,"rb+")
tmp = f.read()
f.close()