From 072736d83224f2a89f1a4662242ee9b20d8f16cc Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Sat, 11 Jan 2014 18:41:28 +0100 Subject: [PATCH] fixed plugins unloaded when cache is updated --- src/core/plugins/plugincontainer.cpp | 30 ++++++++++++---------------- src/core/plugins/plugincontainer.h | 4 +++- src/core/snore.cpp | 13 +++++++----- src/core/snore_p.cpp | 1 - src/main.cpp | 2 +- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/core/plugins/plugincontainer.cpp b/src/core/plugins/plugincontainer.cpp index 7ca9f27..62484e5 100644 --- a/src/core/plugins/plugincontainer.cpp +++ b/src/core/plugins/plugincontainer.cpp @@ -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 ( loader.instance()); - return m_instance; + return qobject_cast ( 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()< plugins = s_pluginCache.values(); cache.beginWriteArray("plugins"); @@ -176,8 +168,12 @@ QHash 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{ diff --git a/src/core/plugins/plugincontainer.h b/src/core/plugins/plugincontainer.h index fdf73e4..7a300d7 100644 --- a/src/core/plugins/plugincontainer.h +++ b/src/core/plugins/plugincontainer.h @@ -24,6 +24,8 @@ #include #include #include +#include + namespace Snore{ class SnoreCore; @@ -63,10 +65,10 @@ private: static QHash s_pluginCache; - QPointer m_instance; QString m_pluginFile; QString m_pluginName; PluginContainer::PluginType m_pluginType; + QPluginLoader m_loader; }; } diff --git a/src/core/snore.cpp b/src/core/snore.cpp index ff2d09a..85b79ef 100644 --- a/src/core/snore.cpp +++ b/src/core/snore.cpp @@ -63,7 +63,7 @@ void SnoreCore::loadPlugins( PluginContainer::PluginTypes types ) { case PluginContainer::BACKEND: { - qDebug() <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() <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:"<(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; } diff --git a/src/core/snore_p.cpp b/src/core/snore_p.cpp index 7985f2b..ada590f 100644 --- a/src/core/snore_p.cpp +++ b/src/core/snore_p.cpp @@ -40,7 +40,6 @@ const QDir &SnoreCorePrivate::pluginDir(){ { path = QDir(LIBSNORE_PLUGIN_PATH); } - qDebug() << "PluginDir" << path.absolutePath(); return path; } diff --git a/src/main.cpp b/src/main.cpp index 5b2b9d3..f0953ec 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 ")); + ki18n("A notification deamon."),KAboutData::License_LGPL_V3, ki18n("Copyright (c) 2010-2014 Patrick von Reth ")); KCmdLineArgs::init(argc, argv, &about); KUniqueApplication app; #else