implemented uninitialize, its omehow ugly

This commit is contained in:
Patrick von Reth 2014-01-15 18:24:32 +01:00
parent 0f38add1cf
commit 135d0d470d
19 changed files with 194 additions and 78 deletions

View File

@ -35,12 +35,14 @@ SnorePlugin::SnorePlugin ( const QString &name ) :
SnorePlugin::~SnorePlugin()
{
qDebug()<<m_name<<this<<"deleted";
qDebug() << m_name << this << "deleted";
deinitialize();
}
bool SnorePlugin::init( SnoreCore *snore )
bool SnorePlugin::initialize( SnoreCore *snore )
{
if(m_initialized){
if(m_initialized)
{
qFatal("Something went wrong, plugin %s is already initialized",this->name().toLatin1().constData());
return false;
}
@ -50,7 +52,8 @@ bool SnorePlugin::init( SnoreCore *snore )
return true;
}
bool SnorePlugin::isInitialized(){
bool SnorePlugin::isInitialized()
{
return m_initialized;
}
@ -65,8 +68,10 @@ const QString &SnorePlugin::name() const
}
void SnorePlugin::startTimeout(uint id,int timeout){
if(timeout==-1)//sticky
if(timeout == -1)//sticky
{
return;
}
if(m_timeouts.contains(id)){
QTimer *t = m_timeouts.take(id);
t->stop();
@ -91,9 +96,14 @@ void SnorePlugin::notificationTimedOut(){
}
}
void SnorePlugin::deinit()
bool SnorePlugin::deinitialize()
{
m_initialized = false;
if(m_initialized)
{
m_initialized = false;
return true;
}
return false;
}
}

View File

@ -46,8 +46,8 @@ public:
SnorePlugin ( const QString &name);
virtual ~SnorePlugin();
virtual bool init( SnoreCore *snore );
virtual void deinit();
virtual bool initialize( SnoreCore *snore );
virtual bool deinitialize();
bool isInitialized();
SnoreCore* snore();
const QString &name() const;

View File

@ -45,9 +45,9 @@ SnoreBackend::~SnoreBackend()
}
bool SnoreBackend::init( SnoreCore *snore )
bool SnoreBackend::initialize( SnoreCore *snore )
{
if(!SnorePlugin::init(snore))
if(!SnorePlugin::initialize(snore))
{
return false;
}
@ -95,8 +95,9 @@ void SnoreBackend::slotCloseNotification(Notification notification)
Q_UNUSED(notification)
}
SnoreSecondaryBackend::SnoreSecondaryBackend(const QString &name, bool supportsRhichtext)
:SnoreBackend(name,false,supportsRhichtext)
SnoreSecondaryBackend::SnoreSecondaryBackend(const QString &name, bool supportsRhichtext):
SnorePlugin(name),
m_supportsRichtext(supportsRhichtext)
{
}
@ -106,9 +107,9 @@ SnoreSecondaryBackend::~SnoreSecondaryBackend()
qDebug()<<"Deleting"<<name();
}
bool SnoreSecondaryBackend::init(SnoreCore *snore)
bool SnoreSecondaryBackend::supportsRichtext()
{
return SnoreBackend::init(snore);
return m_supportsRichtext;
}
Snore::Notification SnoreBackend::getActiveNotificationByID(uint id)
@ -142,9 +143,9 @@ void SnoreBackend::addActiveNotification(Notification n)
}
void SnoreBackend::deinit()
bool SnoreBackend::deinitialize()
{
if(m_initialized)
if(SnorePlugin::deinitialize())
{
foreach(const Application &a,snore()->aplications())
{
@ -155,7 +156,7 @@ void SnoreBackend::deinit()
disconnect( this, SIGNAL(notificationClosed(Snore::Notification)), snore()->d(), SLOT(slotNotificationClosed(Snore::Notification)));
disconnect( snore()->d(), SIGNAL(notify(Snore::Notification)), this, SLOT(slotNotify(Snore::Notification)));
SnorePlugin::deinit();
return true;
}
return false;
}

View File

@ -36,8 +36,8 @@ class SNORE_EXPORT SnoreBackend : public SnorePlugin
public:
SnoreBackend(const QString &name, bool canCloseNotification, bool supportsRichtext );
virtual ~SnoreBackend();
virtual bool init(SnoreCore *snore);
virtual void deinit();
virtual bool initialize(SnoreCore *snore);
virtual bool deinitialize();
void requestCloseNotification( Snore::Notification notification,NotificationEnums::CloseReasons::closeReasons reason );
@ -78,14 +78,22 @@ Q_DECLARE_INTERFACE ( Snore::SnoreBackend,
namespace Snore{
class SnoreCore;
class SNORE_EXPORT SnoreSecondaryBackend:public SnoreBackend
class SNORE_EXPORT SnoreSecondaryBackend : public SnorePlugin
{
Q_OBJECT
Q_INTERFACES(Snore::SnorePlugin Snore::SnoreBackend)
Q_INTERFACES(Snore::SnorePlugin Snore::SnorePlugin)
public:
SnoreSecondaryBackend(const QString &name, bool supportsRhichtext);
virtual ~SnoreSecondaryBackend();
virtual bool init(SnoreCore *snore);
bool supportsRichtext();
public slots:
virtual void slotNotify ( Snore::Notification notification ) = 0;
protected:
bool m_supportsRichtext;
};

View File

@ -37,8 +37,4 @@ SnoreFrontend::~SnoreFrontend()
qDebug()<<"Deleting"<<name();
}
bool SnoreFrontend::init( SnoreCore *snore )
{
return SnorePlugin::init(snore);
}
}

View File

@ -39,8 +39,6 @@ class SNORE_EXPORT SnoreFrontend:public SnorePlugin
public:
SnoreFrontend ( const QString &name);
virtual ~SnoreFrontend();
virtual bool init(SnoreCore *snore);
virtual void actionInvoked( Snore::Notification notification )=0;
virtual void notificationClosed( Snore::Notification notification )=0;
};

View File

@ -69,7 +69,7 @@ void SnoreCore::loadPlugins( SnorePlugin::PluginTypes types )
}
case SnorePlugin::SECONDARY_BACKEND:
{
if(!info->load()->init( this )){
if(!info->load()->initialize( this )){
info->unload();
break;
}
@ -79,7 +79,7 @@ void SnoreCore::loadPlugins( SnorePlugin::PluginTypes types )
case SnorePlugin::FRONTEND:
{
qDebug() << info->name() << "is a Notification_Frontend";
if(!info->load()->init( this )){
if(!info->load()->initialize( this )){
info->unload();
break;
}
@ -89,7 +89,7 @@ void SnoreCore::loadPlugins( SnorePlugin::PluginTypes types )
case SnorePlugin::PLUGIN:
{
qDebug() <<info->name()<<"is a SnorePlugin";
if(!info->load()->init(this)){
if(!info->load()->initialize(this)){
info->unload();
break;
}
@ -173,7 +173,7 @@ bool SnoreCore::setPrimaryNotificationBackend ( const QString &backend )
SnoreBackend* b = qobject_cast<SnoreBackend*>(PluginContainer::pluginCache()[backend]->load());
if(!b->isInitialized())
{
if(!b->init(this))
if(!b->initialize(this))
{
qDebug() << "Failed to initialize" << b->name();
return false;
@ -181,7 +181,7 @@ bool SnoreCore::setPrimaryNotificationBackend ( const QString &backend )
}
if(d->m_notificationBackend)
{
d->m_notificationBackend->deinit();
d->m_notificationBackend->deinitialize();
}
d->m_notificationBackend = b;

View File

@ -45,7 +45,7 @@ Growl::~Growl()
delete m_defaultGNTP;
}
bool Growl::init(SnoreCore *snore)
bool Growl::initialize(SnoreCore *snore)
{
const Application &app = snore->d()->defaultApplication();
m_defaultGNTP = new gntp(app.name().toUtf8().constData(), app.icon().localUrl().toUtf8().constData());
@ -63,7 +63,21 @@ bool Growl::init(SnoreCore *snore)
m_defaultGNTP = NULL;
return false;
}
return SnoreBackend::init(snore);
return SnoreBackend::initialize(snore);
}
bool Growl::deinitialize()
{
if(SnoreBackend::deinitialize())
{
if(m_defaultGNTP)
{
delete m_defaultGNTP;
m_defaultGNTP = NULL;
}
return true;
}
return false;
}
void Growl::slotRegisterApplication(const Application &application)
@ -73,11 +87,11 @@ void Growl::slotRegisterApplication(const Application &application)
gntp::gntp_callback callback(&Growl::gntpCallback);
growl->set_gntp_callback(callback);
// qDebug() << Q_FUNC_INFO << application->name().toUtf8().constData();
// qDebug() << Q_FUNC_INFO << application->name().toUtf8().constData();
std::vector<std::string> alerts;
foreach(const Alert &a,application.alerts())
{
// qDebug() << Q_FUNC_INFO << a->name().toUtf8().constData();
// qDebug() << Q_FUNC_INFO << a->name().toUtf8().constData();
alerts.push_back(a.name().toUtf8().constData());
}
@ -110,7 +124,7 @@ void Growl::slotNotify(Notification notification)
growl = m_defaultGNTP;
alert = "Default";
}
// qDebug() << "Notify Growl:" <<notification.application() << alert << Snore::toPlainText(notification.title());
// qDebug() << "Notify Growl:" <<notification.application() << alert << Snore::toPlainText(notification.title());
try
{
growl->notify(alert.toUtf8().constData(),notification.id(),
@ -127,7 +141,7 @@ void Growl::slotNotify(Notification notification)
void Growl::gntpCallback(const int &id,const std::string &reason,const std::string &data)
{
// qDebug() << Q_FUNC_INFO << id << QString(reason.c_str()) << QString(data.c_str());
// qDebug() << Q_FUNC_INFO << id << QString(reason.c_str()) << QString(data.c_str());
Notification n = s_instance->snore()->getActiveNotificationByID(id);
NotificationEnums::CloseReasons::closeReasons r = NotificationEnums::CloseReasons::NONE;
if(reason == "TIMEDOUT")

View File

@ -32,7 +32,8 @@ class Growl:public Snore::SnoreBackend
public:
Growl();
~Growl();
virtual bool init(Snore::SnoreCore *snore);
virtual bool initialize(Snore::SnoreCore *snore);
virtual bool deinitialize();
static void gntpCallback(const int &id,const std::string &reason,const std::string &data);

View File

@ -141,12 +141,12 @@ SnarlBackend::SnarlBackend():
SnarlBackend::~SnarlBackend()
{
if(m_defautSnarlinetrface)
delete m_defautSnarlinetrface;
}
bool SnarlBackend::init(SnoreCore *snore){
bool SnarlBackend::initialize(SnoreCore *snore)
{
SnarlInterface *snarlInterface = new SnarlInterface();
if(!snarlInterface->IsSnarlRunning())
{
@ -156,9 +156,28 @@ bool SnarlBackend::init(SnoreCore *snore){
m_eventLoop = new SnarlBackend::SnarlWidget(this);
m_applications.insert(snore->d()->defaultApplication().name(),snarlInterface);
qDebug()<<"Initiating Snarl Backend, Snarl version: "<<snarlInterface->GetVersion();
m_defautSnarlinetrface = new SnarlInterface();
m_defautSnarlinetrface = snarlInterface;
return SnoreBackend::init(snore);
return SnoreBackend::initialize(snore);
}
bool SnarlBackend::deinitialize()
{
if(SnoreBackend::deinitialize())
{
if(m_defautSnarlinetrface)
{
delete m_defautSnarlinetrface;
m_defautSnarlinetrface = NULL;
delete m_eventLoop;
m_eventLoop = NULL;
m_applications.clear();
}
return true;
}
return false;
}
void SnarlBackend::slotRegisterApplication(const Application &application){

View File

@ -32,7 +32,8 @@ class SnarlBackend:public Snore::SnoreBackend
public:
SnarlBackend();
~SnarlBackend();
virtual bool init(Snore::SnoreCore *snore);
virtual bool initialize(Snore::SnoreCore *snore);
virtual bool deinitialize();
private:
class SnarlWidget;

View File

@ -26,7 +26,7 @@ SnoreToast::~SnoreToast()
}
bool SnoreToast::init(SnoreCore *snore)
bool SnoreToast::initialize(SnoreCore *snore)
{
if(QSysInfo::windowsVersion() != QSysInfo::WV_WINDOWS8)
{
@ -54,12 +54,15 @@ bool SnoreToast::init(SnoreCore *snore)
p->waitForFinished(-1);
qDebug() << p->readAll();
if(p->exitCode() != 0)
{
return false;
}
}
return SnoreBackend::init(snore);
return SnoreBackend::initialize(snore);
}
void SnoreToast::slotNotify(Notification notification)
{
QProcess *p = new QProcess(this);

View File

@ -12,7 +12,7 @@ class SnoreToast : public Snore::SnoreBackend
public:
SnoreToast();
~SnoreToast();
bool init(Snore::SnoreCore *snore);
virtual bool initialize(Snore::SnoreCore *snore);
public slots:
void slotNotify(Snore::Notification notification);

View File

@ -19,28 +19,45 @@ TrayIconNotifer::TrayIconNotifer () :
}
bool TrayIconNotifer::init(SnoreCore *snore){
bool TrayIconNotifer::initialize(SnoreCore *snore){
m_trayIcon = snore->trayIcon();
if(m_trayIcon == NULL)
{
return false;
}
connect(m_trayIcon,SIGNAL(messageClicked()),this,SLOT(actionInvoked()));
return SnoreBackend::init(snore);
return SnoreBackend::initialize(snore);
}
bool TrayIconNotifer::deinitialize()
{
if(SnoreBackend::deinitialize())
{
if(m_trayIcon)
{
disconnect(m_trayIcon,SIGNAL(messageClicked()),this,SLOT(actionInvoked()));
m_trayIcon = NULL;
}
return true;
}
return false;
}
void TrayIconNotifer::slotNotify( Notification notification )
{
m_notificationQue.append(notification);
if(m_lastNotify.elapsed()> Notification::defaultTimeout() * 1000){
if(m_lastNotify.elapsed()> Notification::defaultTimeout() * 1000)
{
displayNotification();
}
}
void TrayIconNotifer::displayNotification(){
void TrayIconNotifer::displayNotification()
{
qDebug()<<"Display"<<m_notificationQue.size();
Notification notification = m_notificationQue.takeFirst();
if(!m_notificationQue.isEmpty()){
if(!m_notificationQue.isEmpty())
{
QTimer::singleShot(notification.timeout()*1000,this,SLOT(slotCloseNotificationByTimeout()));
}
@ -50,19 +67,23 @@ void TrayIconNotifer::displayNotification(){
m_lastNotify.restart();
}
void TrayIconNotifer::slotCloseNotificationByTimeout(){
Notification n = snore()->getActiveNotificationByID(m_displayed);
if(n.isValid()){
void TrayIconNotifer::slotCloseNotificationByTimeout()
{
Notification n = getActiveNotificationByID(m_displayed);
if(n.isValid())
{
closeNotification(n,NotificationEnums::CloseReasons::TIMED_OUT);
}
displayNotification();
}
void TrayIconNotifer::actionInvoked(){
void TrayIconNotifer::actionInvoked()
{
qDebug()<<"Traicon invoked"<<m_displayed;
Notification n = snore()->getActiveNotificationByID(m_displayed);
if(n.isValid()){
Notification n = getActiveNotificationByID(m_displayed);
if(n.isValid())
{
snore()->d()->notificationActionInvoked(n);
closeNotification(n,NotificationEnums::CloseReasons::CLOSED);
}

View File

@ -18,7 +18,8 @@ class TrayIconNotifer:public Snore::SnoreBackend
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
public:
TrayIconNotifer ();
virtual bool init(Snore::SnoreCore *snore);
virtual bool initialize(Snore::SnoreCore *snore);
virtual bool deinitialize();
public slots:
void slotNotify(Snore::Notification notification);

View File

@ -48,15 +48,34 @@ FreedesktopFrontend::~FreedesktopFrontend(){
dbus.unregisterService( "org.freedesktop.Notifications" );
}
bool FreedesktopFrontend::init(SnoreCore *snore){
new NotificationsAdaptor(this);
bool FreedesktopFrontend::initialize(SnoreCore *snore)
{
m_adaptor = new NotificationsAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.registerService( "org.freedesktop.Notifications" );
dbus.registerObject( "/org/freedesktop/Notifications", this );
return SnoreFrontend::init(snore);
if(dbus.registerService( "org.freedesktop.Notifications" ) &&
dbus.registerObject( "/org/freedesktop/Notifications", this ))
{
return SnoreFrontend::initialize(snore);
}
return false;
}
void FreedesktopFrontend::actionInvoked(Notification notification) {
bool FreedesktopFrontend::deinitialize()
{
if(SnoreFrontend::deinitialize())
{
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.unregisterService("org.freedesktop.Notifications" );
dbus.unregisterObject("/org/freedesktop/Notifications" );
m_adaptor->deleteLater();
m_adaptor = NULL;
return true;
}
return false;
}
void FreedesktopFrontend::actionInvoked(Notification notification)
{
if(notification.actionInvoked().isValid())
{
emit ActionInvoked(notification.id(),QString::number(notification.actionInvoked().id()));

View File

@ -23,14 +23,18 @@
#include "core/application.h"
#include <QtDBus>
class FreedesktopFrontend:public Snore::SnoreFrontend{
class NotificationsAdaptor;
class FreedesktopFrontend : public Snore::SnoreFrontend
{
Q_OBJECT
Q_INTERFACES(Snore::SnoreFrontend)
Q_PLUGIN_METADATA(IID "org.Snore.NotificationFrontend/1.0")
public:
FreedesktopFrontend();
~FreedesktopFrontend();
virtual bool init(Snore::SnoreCore *snore);
virtual bool initialize(Snore::SnoreCore *snore);
virtual bool deinitialize();
void actionInvoked(Snore::Notification notification);
void notificationClosed(Snore::Notification notification);
@ -47,6 +51,7 @@ signals:
private:
Snore::Alert m_alert;
Snore::Icon m_icon;
NotificationsAdaptor *m_adaptor;
};

View File

@ -39,17 +39,34 @@ SnarlNetworkFrontend::SnarlNetworkFrontend():
SnarlNetworkFrontend::~SnarlNetworkFrontend(){
}
bool SnarlNetworkFrontend::init(SnoreCore *snore){
parser=new Parser(this);
tcpServer=new QTcpServer(this);
if(!tcpServer->listen(QHostAddress::Any,port)){
bool SnarlNetworkFrontend::initialize(SnoreCore *snore){
parser = new Parser(this);
tcpServer = new QTcpServer(this);
if(!tcpServer->listen(QHostAddress::Any,port))
{
qDebug()<<"The port is already used";
return false;
}else{
}
else
{
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(handleConnection()));
std::cout<<"The Snarl Network Protokoll is developed for Snarl <http://www.fullphat.net/>"<<std::endl;
}
return SnoreFrontend::init(snore);
return SnoreFrontend::initialize(snore);
}
bool SnarlNetworkFrontend::deinitialize()
{
if(SnoreFrontend::deinitialize())
{
parser->deleteLater();
parser = NULL;
tcpServer->deleteLater();
tcpServer = NULL;
return true;
}
return false;
}

View File

@ -49,7 +49,9 @@ public:
public:
SnarlNetworkFrontend();
~SnarlNetworkFrontend();
virtual bool init(Snore::SnoreCore *snore);
virtual bool initialize(Snore::SnoreCore *snore);
virtual bool deinitialize();
void actionInvoked(Snore::Notification notification);
void notificationClosed(Snore::Notification notification);