fixed plugins unloaded when cache is updated

This commit is contained in:
Patrick von Reth 2014-01-11 18:41:28 +01:00
parent a43234f115
commit 072736d832
5 changed files with 25 additions and 25 deletions

View File

@ -45,37 +45,29 @@ QSettings &PluginContainer::cacheFile(){
PluginContainer::PluginContainer(QString fileName, QString pluginName, PluginContainer::PluginType type):
m_pluginFile(fileName),
m_pluginName(pluginName),
m_pluginType(type)
m_pluginType(type),
m_loader(SnoreCorePrivate::pluginDir().absoluteFilePath(file()))
{
}
PluginContainer::~PluginContainer()
{
if(m_instance)
{
m_instance->deleteLater();
}
m_loader.unload();
}
SnorePlugin *PluginContainer::load()
{
if(m_instance != NULL)
return m_instance;
QPluginLoader loader ( SnoreCorePrivate::pluginDir().absoluteFilePath(file()));
qDebug() << "Trying to load" << file();
if ( !loader.load())
if ( !m_loader.load())
{
qDebug() << "Failed loading plugin: " << loader.errorString();
qDebug() << "Failed loading plugin: " << m_loader.errorString();
return NULL;
}
m_instance = qobject_cast<SnorePlugin*> ( loader.instance());
return m_instance;
return qobject_cast<SnorePlugin*> ( m_loader.instance());
}
void PluginContainer::unload()
{
m_instance->deleteLater();
m_loader.unload();
}
const QString & PluginContainer::file()
@ -151,13 +143,13 @@ void PluginContainer::updatePluginCache(){
}
PluginContainer *info = new PluginContainer( SnoreCorePrivate::pluginDir().relativeFilePath(filepath),sp->name(),PluginContainer::typeFromString(type));
s_pluginCache.insert(info->name(),info);
sp->deleteLater();
qDebug() << "added" << info->name() << "to cache";
}
}
qDebug()<<s_pluginCache.keys();
cache.setValue("version",Version::revision());
cache.setValue("buildtime",Version::buildTime());
cache.setValue("pluginPath",SnoreCorePrivate::pluginDir().path());
QList<PluginContainer*> plugins = s_pluginCache.values();
cache.beginWriteArray("plugins");
@ -176,8 +168,12 @@ QHash<QString, PluginContainer *> PluginContainer::pluginCache(){
QSettings &cache = cacheFile();
QString version = cache.value("version").toString();
QString path = cache.value("pluginPath").toString();
QString buildTime = cache.value("buildtime").toString();
int size = cache.beginReadArray("plugins");
if(size == 0 || version != Version::revision() || path != SnoreCorePrivate::pluginDir().path()){
if(size == 0 ||
version != Version::revision() ||
buildTime != Version::buildTime() ||
path != SnoreCorePrivate::pluginDir().path()){
cache.endArray();
updatePluginCache();
}else{

View File

@ -24,6 +24,8 @@
#include <QPointer>
#include <QSettings>
#include <QFlag>
#include <QPluginLoader>
namespace Snore{
class SnoreCore;
@ -63,10 +65,10 @@ private:
static QHash<QString,PluginContainer*> s_pluginCache;
QPointer<SnorePlugin> m_instance;
QString m_pluginFile;
QString m_pluginName;
PluginContainer::PluginType m_pluginType;
QPluginLoader m_loader;
};
}

View File

@ -63,7 +63,7 @@ void SnoreCore::loadPlugins( PluginContainer::PluginTypes types )
{
case PluginContainer::BACKEND:
{
qDebug() <<info->name()<<"is a Notification_Backend";
qDebug() << info->name() << "is a Notification_Backend";
d->m_notificationBackends.append( info->name());
break;
}
@ -78,7 +78,7 @@ void SnoreCore::loadPlugins( PluginContainer::PluginTypes types )
}
case PluginContainer::FRONTEND:
{
qDebug() <<info->name()<<"is a Notification_Frontend";
qDebug() << info->name() << "is a Notification_Frontend";
if(!info->load()->init( this )){
info->unload();
break;
@ -170,14 +170,17 @@ const QStringList &SnoreCore::secondaryNotificationBackends() const
bool SnoreCore::setPrimaryNotificationBackend ( const QString &backend )
{
Q_D(SnoreCore);
if(!PluginContainer::pluginCache().contains(backend)){
if(!PluginContainer::pluginCache().contains(backend))
{
qDebug()<<"Unknown Backend:"<<backend;
return setPrimaryNotificationBackend();
}
qDebug() << "Setting Notification Backend to:" << backend;
SnoreBackend* b = qobject_cast<SnoreBackend*>(PluginContainer::pluginCache()[backend]->load());
if(!b->isInitialized()){
if(!b->init(this)){
if(!b->isInitialized())
{
if(!b->init(this))
{
qDebug() << "Failed to initialize" << b->name();
return false;
}

View File

@ -40,7 +40,6 @@ const QDir &SnoreCorePrivate::pluginDir(){
{
path = QDir(LIBSNORE_PLUGIN_PATH);
}
qDebug() << "PluginDir" << path.absolutePath();
return path;
}

View File

@ -15,7 +15,7 @@ int main ( int argc, char *argv[] )
#ifdef HAVE_KDE
KAboutData about("SnoreNotify",0,ki18n("SnoreNotify"),Snore::Version::version().toLatin1(),
ki18n("A notification deamon."),KAboutData::License_LGPL_V3, ki18n("Copyright (c) 2010-2013-2014 Patrick von Reth <vonreth@kde.org>"));
ki18n("A notification deamon."),KAboutData::License_LGPL_V3, ki18n("Copyright (c) 2010-2014 Patrick von Reth <vonreth@kde.org>"));
KCmdLineArgs::init(argc, argv, &about);
KUniqueApplication app;
#else