changed plugin loading path, its no longer neccesary to install snore to test it

This commit is contained in:
Patrick von Reth 2014-01-23 13:57:54 +01:00
parent b9f94f5e7d
commit 46ac673070
6 changed files with 54 additions and 26 deletions

View File

@ -10,6 +10,7 @@ include(GNUInstallDirs)
#######################################################################
option(WITH_KDE "Try to build with KDE support if availibe" ON)
option(WITH_FRONTENDS "Build frontends currently only useful if WITH_SNORE_DEAMON=ON" OFF)
option(WITH_FREEDESKTOP_FRONTEND "Build the freedesktop frontend" OFF)
option(WITH_GROWL_BACKEND "Build the Growl backend" ON)
option(WITH_SNORE_DEAMON "Build the Snore deamon, which redirects notifications" OFF)
@ -23,7 +24,9 @@ if(WITH_KDE)
find_package(KDE4)
endif()
if(WITH_SNORE_DEAMON)
set(WITH_FRONTENDS ON)
endif()
if(KDE4_FOUND)
add_definitions(-DHAVE_KDE ${KDE4_DEFINITIONS} -D_UNICODE)
@ -53,9 +56,13 @@ endif(DOXYGEN_FOUND)
set(LIBSNORE_PLUGIN_PATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libsnore)
set(SNORE_PLUGIN_INSTALL_PATH LIBRARY DESTINATION ${LIBSNORE_PLUGIN_PATH})
add_definitions(-DLIBSNORE_PLUGIN_PATH="${LIBSNORE_PLUGIN_PATH}" -DCMAKE_INSTALL_LIBDIR="${CMAKE_INSTALL_LIBDIR}")
add_definitions(-DLIBSNORE_PLUGIN_PATH="${LIBSNORE_PLUGIN_PATH}")
message(STATUS "Installing plugins to ${LIBSNORE_PLUGIN_PATH}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_subdirectory(data)
add_subdirectory(share)
add_subdirectory(src)

View File

@ -28,6 +28,7 @@
#include <QDir>
#include <QDebug>
#include <QMetaEnum>
#include <QApplication>
using namespace Snore;
@ -38,7 +39,7 @@ PluginContainer::PluginContainer(QString fileName, QString pluginName, SnorePlug
m_pluginFile(fileName),
m_pluginName(pluginName),
m_pluginType(type),
m_loader(SnoreCorePrivate::pluginDir().absoluteFilePath(file()))
m_loader(pluginDir().absoluteFilePath(file()))
{
}
@ -101,13 +102,19 @@ const QStringList &PluginContainer::types()
void PluginContainer::updatePluginCache()
{
snoreDebug( SNORE_DEBUG ) << "Updating plugin cache";
s_pluginCache.clear();
cache().remove("");
#if defined(Q_OS_LINUX)
const QString extensions = "so";
#elif defined(Q_OS_WIN)
const QString extensions = "dll";
#elif defined(Q_OS_MAC)
const QString extensions = "dylib";
#endif
foreach(const QString &type,PluginContainer::types())
{
foreach (const QFileInfo &file, SnoreCorePrivate::pluginDir().entryInfoList(QStringList(QString("libsnore_%1_*").arg(type.toLower())), QDir::Files, QDir::Name | QDir::IgnoreCase ))
foreach (const QFileInfo &file, pluginDir().entryInfoList(QStringList(QString("libsnore_%1_*.%2").arg(type.toLower(), extensions)), QDir::Files, QDir::Name | QDir::IgnoreCase ))
{
snoreDebug( SNORE_DEBUG ) << "adding" << file.absoluteFilePath();
QPluginLoader loader(file.absoluteFilePath());
@ -131,7 +138,7 @@ void PluginContainer::updatePluginCache()
}
cache().setValue("version",Version::revision());
cache().setValue("buildtime",Version::buildTime());
cache().setValue("pluginPath",SnoreCorePrivate::pluginDir().absolutePath());
cache().setValue("pluginPath",pluginDir().absolutePath());
QList<PluginContainer*> plugins = pluginCache(SnorePlugin::ALL).values();
cache().beginWriteArray("plugins");
for(int i=0;i< plugins.size();++i)
@ -148,7 +155,6 @@ const QHash<QString, PluginContainer *> PluginContainer::pluginCache(SnorePlugin
{
if(s_pluginCache.isEmpty())
{
QString version = cache().value("version").toString();
QString buildTime = cache().value("buildtime").toString();
int size = cache().beginReadArray("plugins");
@ -187,3 +193,30 @@ const QHash<QString, PluginContainer *> PluginContainer::pluginCache(SnorePlugin
}
return out;
}
const QDir PluginContainer::pluginDir()
{
static QString path;
if(path.isNull())
{
const QString appDir = qApp->applicationDirPath();
QStringList list;
list << QString("%1/../lib/libsnore").arg(appDir)
<< QString("%1/../lib64/libsnore").arg(appDir)
<< QString("%1/libsnore").arg(appDir)
<< QString("%1/").arg(appDir)
<< QLatin1String(LIBSNORE_PLUGIN_PATH);
foreach(const QString &p, list)
{
if(QDir(p).exists())
{
path = p;
break;
}
}
snoreDebug( SNORE_INFO ) << "PluginPath is :" << path;
}
return QDir(path);
}

View File

@ -54,6 +54,7 @@ public:
private:
void static updatePluginCache();
static const QDir pluginDir();
static QHash<SnorePlugin::PluginTypes, QHash<QString,PluginContainer*> > s_pluginCache;
static inline QSettings &cache()
@ -62,7 +63,7 @@ private:
if(_cache == NULL)
{
_cache = new QSettings("SnoreNotify","libsnore");
_cache->beginGroup( SnoreCorePrivate::computeHash(SnoreCorePrivate::pluginDir().absolutePath().toLatin1()));
_cache->beginGroup( SnoreCorePrivate::computeHash(pluginDir().absolutePath().toLatin1()));
}
return *_cache;
}

View File

@ -25,8 +25,6 @@
#include "plugins/snorefrontend.h"
#include "notification/notification_p.h"
#include <QApplication>
using namespace Snore;
@ -41,17 +39,6 @@ QString const SnoreCorePrivate::snoreTMP()
return tmp;
}
const QDir &SnoreCorePrivate::pluginDir()
{
static QDir path(QString("%1/../%2/libsnore").arg(qApp->applicationDirPath(), CMAKE_INSTALL_LIBDIR));
if(!path.exists())
{
path = QDir(LIBSNORE_PLUGIN_PATH);
}
return path;
}
SnoreCorePrivate::SnoreCorePrivate(QSystemTrayIcon *trayIcon):
m_trayIcon(trayIcon),
m_defaultApp("SnoreNotify",Icon(":/root/snore.png"))

View File

@ -37,7 +37,6 @@ class SNORE_EXPORT SnoreCorePrivate : public QObject
public:
static const QString snoreTMP();
static const QDir &pluginDir();
static inline QString computeHash(const QByteArray &data)
{
return QCryptographicHash::hash(data,QCryptographicHash::Md5).toHex();

View File

@ -1,3 +1,4 @@
add_subdirectory(freedesktop)
add_subdirectory(snarlnetwork)
if(WITH_FRONTENDS)
add_subdirectory(freedesktop)
add_subdirectory(snarlnetwork)
endif()