Fixed: OVQT plugins loading under Unices (in the order: local, OVQT plugins, system)

This commit is contained in:
kervala 2012-09-24 09:52:35 +02:00
parent 7d2815735b
commit f2e15ab93b
2 changed files with 43 additions and 4 deletions

View file

@ -13,7 +13,7 @@ ELSEIF(APPLE)
SET(OVQT_PLUGIN_DIR "plugins") SET(OVQT_PLUGIN_DIR "plugins")
ELSE(WIN32) ELSE(WIN32)
SET(OVQT_PLUGIN_DIR ${NL_SHARE_PREFIX}/object_viewer_qt/plugins) SET(OVQT_PLUGIN_DIR ${NL_SHARE_PREFIX}/object_viewer_qt/plugins)
ADD_DEFINITIONS(-DDATA_DIR="\\"${NL_SHARE_ABSOLUTE_PREFIX}/object_viewer_qt/\\"") ADD_DEFINITIONS(-DDATA_DIR="\\"${NL_SHARE_ABSOLUTE_PREFIX}/object_viewer_qt\\"" -DPLUGINS_DIR="\\"${NL_LIB_ABSOLUTE_PREFIX}/object_viewer_qt\\"")
ENDIF(WIN32) ENDIF(WIN32)
IF(UNIX AND WITH_STATIC) IF(UNIX AND WITH_STATIC)

View file

@ -31,6 +31,10 @@
#include <QtCore/QPluginLoader> #include <QtCore/QPluginLoader>
#include <QtCore/QCoreApplication> #include <QtCore/QCoreApplication>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
namespace ExtensionSystem namespace ExtensionSystem
{ {
const char *const PLUGIN_SPEC_NAME = "name"; const char *const PLUGIN_SPEC_NAME = "name";
@ -143,9 +147,44 @@ bool PluginSpec::setFileName(const QString &fileName)
m_fileName = m_prefix + fileName + m_suffix; m_fileName = m_prefix + fileName + m_suffix;
m_filePath = m_location + "/" + m_fileName; m_filePath = m_location + "/" + m_fileName;
QFile file;
file.setFileName(m_filePath);
bool exists = file.exists();
#ifdef NL_OS_UNIX
#ifdef PLUGINS_DIR
if (!exists)
{
// if plugin can't be found in the same directory as spec file,
// looks for it in PLUGINS_DIR
m_filePath = QString("%1/%2").arg(PLUGINS_DIR).arg(m_fileName);
file.setFileName(m_filePath);
exists = file.exists();
}
#endif
#ifdef NL_LIB_PREFIX
if (!exists)
{
// if plugin can't be found in the same directory as spec file or PLUGINS_DIR,
// looks for it in NL_LIB_PREFIX
m_filePath = QString("%1/%2").arg(NL_LIB_PREFIX).arg(m_fileName);
file.setFileName(m_filePath);
exists = file.exists();
}
#endif
#endif
nlinfo(m_filePath.toStdString().c_str()); nlinfo(m_filePath.toStdString().c_str());
QFile file(m_filePath);
if (!file.exists()) if (!exists)
return reportError(QCoreApplication::translate("PluginSpec", "File does not exist: %1").arg(file.fileName())); return reportError(QCoreApplication::translate("PluginSpec", "File does not exist: %1").arg(file.fileName()));
if (!file.open(QIODevice::ReadOnly)) if (!file.open(QIODevice::ReadOnly))
return reportError(QCoreApplication::translate("PluginSpec", "Could not open file for read: %1").arg(file.fileName())); return reportError(QCoreApplication::translate("PluginSpec", "Could not open file for read: %1").arg(file.fileName()));