diff --git a/CMakeLists.txt b/CMakeLists.txt index dc7b4010..10b7dfd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,10 +89,6 @@ else(QCA_SUFFIX) set(QCA_PC_NAME qca2.pc) endif(QCA_SUFFIX) -if(DEVELOPER_MODE) - add_definitions(-DDEVELOPER_MODE -DQCA_PLUGIN_PATH="${CMAKE_BINARY_DIR}/lib/${QCA_LIB_NAME}") -endif(DEVELOPER_MODE) - set(QCA_LIB_VERSION_STRING "${QCA_LIB_MAJOR_VERSION}.${QCA_LIB_MINOR_VERSION}.${QCA_LIB_PATCH_VERSION}") configure_file("include/QtCrypto/qca_version.h.in" "${CMAKE_BINARY_DIR}/qca_version.h") @@ -222,6 +218,12 @@ else() set(QCA_PREFIX_INSTALL_DIR "") endif() +if(DEVELOPER_MODE) + add_definitions(-DDEVELOPER_MODE -DQCA_PLUGIN_PATH="${CMAKE_BINARY_DIR}/lib/${QCA_LIB_NAME}") +else() + add_definitions(-DQCA_PLUGIN_PATH="${QCA_PREFIX_INSTALL_DIR}${QCA_PLUGINS_INSTALL_DIR}") +endif(DEVELOPER_MODE) + if (APPLE) find_package(Carbon REQUIRED) set(CMAKE_INSTALL_NAME_DIR ${QCA_LIBRARY_INSTALL_DIR}) diff --git a/include/QtCrypto/qca_core.h b/include/QtCrypto/qca_core.h index ca3756cf..beda5b18 100644 --- a/include/QtCrypto/qca_core.h +++ b/include/QtCrypto/qca_core.h @@ -369,6 +369,19 @@ QCA_EXPORT Provider *findProvider(const QString &name); */ QCA_EXPORT Provider *defaultProvider(); +/** + Retrieve plugin paths. It consists of: + 1. QCA_PLUGIN_PATH environment if set. + 2. \c %QCoreApplication::libraryPaths() . + 3. Directory where plugins were installed. + + QCA_PLUGIN_PATH is paths list like PATH or QT_PLUGIN_PATH. + It uses system path separator. \";\" on Windows and \":\" on Unix. + + This function was introduced in %QCA 2.1. +*/ +QCA_EXPORT QStringList pluginPaths(); + /** Scan for new plugins */ diff --git a/src/qca_core.cpp b/src/qca_core.cpp index 89b3c2e2..46bdc411 100644 --- a/src/qca_core.cpp +++ b/src/qca_core.cpp @@ -34,6 +34,7 @@ #include <QSettings> #include <QVariantMap> #include <QWaitCondition> +#include <QDir> #ifdef Q_OS_UNIX # include <unistd.h> @@ -452,6 +453,37 @@ Provider *defaultProvider() return global->manager->find("default"); } +QStringList pluginPaths() +{ + QStringList paths; +#ifndef DEVELOPER_MODE + const QString qcaPluginPath = qgetenv("QCA_PLUGIN_PATH"); + if (!qcaPluginPath.isEmpty()) + { +#ifdef Q_OS_WIN + QLatin1Char pathSep(';'); +#else + QLatin1Char pathSep(':'); +#endif + foreach (const QString &path, qcaPluginPath.split(pathSep)) + { + QString canonicalPath = QDir(path).canonicalPath(); + if (!canonicalPath.isEmpty()) + paths << canonicalPath; + } + + } + paths += QCoreApplication::libraryPaths(); +#endif + // In developer mode load plugins only from buildtree. + // In regular mode QCA_PLUGIN_PATH is path where plugins was installed + paths << QDir(QCA_PLUGIN_PATH).canonicalPath(); +#ifndef DEVELOPER_MODE + paths.removeDuplicates(); +#endif + return paths; +} + void scanForPlugins() { if(!global_check_load()) diff --git a/src/qca_plugin.cpp b/src/qca_plugin.cpp index 0dca742a..166b5a0e 100644 --- a/src/qca_plugin.cpp +++ b/src/qca_plugin.cpp @@ -366,14 +366,7 @@ void ProviderManager::scan() if(qgetenv("QCA_NO_PLUGINS") == "1") return; - // check plugin files -#ifdef DEVELOPER_MODE - // Load plugins only from buildtree - QStringList dirs; - dirs << QCA_PLUGIN_PATH; -#else - const QStringList dirs = QCoreApplication::libraryPaths(); -#endif + const QStringList dirs = pluginPaths(); if(dirs.isEmpty()) logDebug("No Qt Library Paths"); for(QStringList::ConstIterator it = dirs.begin(); it != dirs.end(); ++it) diff --git a/tools/qcatool/main.cpp b/tools/qcatool/main.cpp index c0f35f26..02585e1f 100644 --- a/tools/qcatool/main.cpp +++ b/tools/qcatool/main.cpp @@ -2881,14 +2881,7 @@ int main(int argc, char **argv) // show plugins if(args[0] == "plugins") { -#ifdef DEVELOPER_MODE - printf("QCA build tree path:\n"); - QStringList paths; - paths << QCA_PLUGIN_PATH; -#else - printf("Qt Library Paths:\n"); - QStringList paths = QCoreApplication::libraryPaths(); -#endif + QStringList paths = QCA::pluginPaths(); if(!paths.isEmpty()) { for(int n = 0; n < paths.count(); ++n)