properly unload plugins

This commit is contained in:
Patrick von Reth 2014-02-20 20:38:58 +01:00
parent d9efefe2c1
commit 6b30cb6562
4 changed files with 24 additions and 3 deletions

View File

@ -52,7 +52,7 @@ PluginContainer::~PluginContainer()
SnorePlugin *PluginContainer::load() SnorePlugin *PluginContainer::load()
{ {
if ( !m_loader.load()) if(!m_loader.isLoaded() && !m_loader.load())
{ {
snoreDebug( SNORE_WARNING ) << "Failed loading plugin: " << m_loader.errorString(); snoreDebug( SNORE_WARNING ) << "Failed loading plugin: " << m_loader.errorString();
return NULL; return NULL;
@ -80,6 +80,11 @@ SnorePlugin::PluginTypes PluginContainer::type()
return m_pluginType; return m_pluginType;
} }
bool PluginContainer::isLoaded() const
{
return m_loader.isLoaded();
}
SnorePlugin::PluginTypes PluginContainer::typeFromString(const QString &t) SnorePlugin::PluginTypes PluginContainer::typeFromString(const QString &t)
{ {
return (SnorePlugin::PluginTypes)SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType")).keyToValue(t.toUpper().toLatin1()); return (SnorePlugin::PluginTypes)SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType")).keyToValue(t.toUpper().toLatin1());

View File

@ -48,6 +48,8 @@ public:
const QString &name(); const QString &name();
SnorePlugin::PluginTypes type(); SnorePlugin::PluginTypes type();
bool isLoaded() const;
static SnorePlugin::PluginTypes typeFromString(const QString &t); static SnorePlugin::PluginTypes typeFromString(const QString &t);
static QString typeToString(const SnorePlugin::PluginTypes t); static QString typeToString(const SnorePlugin::PluginTypes t);

View File

@ -23,8 +23,11 @@
#include "plugins/plugins.h" #include "plugins/plugins.h"
#include "plugins/snorebackend.h" #include "plugins/snorebackend.h"
#include "plugins/snorefrontend.h" #include "plugins/snorefrontend.h"
#include "plugins/plugincontainer.h"
#include "notification/notification_p.h" #include "notification/notification_p.h"
#include <QApplication>
using namespace Snore; using namespace Snore;
SnoreCorePrivate::SnoreCorePrivate(QSystemTrayIcon *trayIcon): SnoreCorePrivate::SnoreCorePrivate(QSystemTrayIcon *trayIcon):
@ -32,6 +35,7 @@ SnoreCorePrivate::SnoreCorePrivate(QSystemTrayIcon *trayIcon):
m_defaultApp("SnoreNotify",Icon(":/root/snore.png")) m_defaultApp("SnoreNotify",Icon(":/root/snore.png"))
{ {
m_defaultApp.addAlert(Alert("Default",Icon(":/root/snore.png"))); m_defaultApp.addAlert(Alert("Default",Icon(":/root/snore.png")));
connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(slotAboutToQuit()));
} }
SnoreCorePrivate::~SnoreCorePrivate() SnoreCorePrivate::~SnoreCorePrivate()
@ -85,3 +89,14 @@ void SnoreCorePrivate::slotNotificationClosed(Notification n)
} }
} }
void SnoreCorePrivate::slotAboutToQuit()
{
foreach (PluginContainer *p, PluginContainer::pluginCache(SnorePlugin::ALL))
{
if(p->isLoaded())
{
p->load()->deinitialize();
}
}
}

View File

@ -53,8 +53,6 @@ public:
bool setBackendIfAvailible(const QString & backend); bool setBackendIfAvailible(const QString & backend);
/** /**
* *
* @return whether the backend can update a notification * @return whether the backend can update a notification
@ -68,6 +66,7 @@ signals:
private slots: private slots:
void slotNotificationClosed(Snore::Notification); void slotNotificationClosed(Snore::Notification);
void slotAboutToQuit();
private: private:
SnoreCore *q_ptr; SnoreCore *q_ptr;