Commit 59ad7f49 authored by Jonathan Marten's avatar Jonathan Marten
Browse files

Search all possible locations for plugins

QLibraryInfo::location(QLibraryInfo::PluginsPath) only returns the
plugin path for the Qt installation.  However, the encoder plugins
may have been installed elsewhere and located using the QT_PLUGIN_PATH
environment variable, in addition to as the Qt installation location.
Any plugins located elsewhere will not be found, resulting in an
assert in encoderFromExtension() when the AudioCDProtocol is constructed.

Look for plugins in all possible locations returned by
QCoreApplication::libraryPaths() instead.
parent 83b2e594
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <QLibrary> #include <QLibrary>
#include <QLibraryInfo> #include <QLibraryInfo>
#include <QRegularExpression> #include <QRegularExpression>
#include <QCoreApplication>
Q_LOGGING_CATEGORY(AUDIOCD_KIO_LOG, "kf5.kio.audiocd") Q_LOGGING_CATEGORY(AUDIOCD_KIO_LOG, "kf5.kio.audiocd")
...@@ -31,13 +32,13 @@ Q_LOGGING_CATEGORY(AUDIOCD_KIO_LOG, "kf5.kio.audiocd") ...@@ -31,13 +32,13 @@ Q_LOGGING_CATEGORY(AUDIOCD_KIO_LOG, "kf5.kio.audiocd")
* @param libFileName file to try to load. * @param libFileName file to try to load.
* @returns pointer to the symbol or NULL * @returns pointer to the symbol or NULL
*/ */
QFunctionPointer loadPlugin(const QString &libFileName) static QFunctionPointer loadPlugin(const QString &libFileName)
{ {
qCDebug(AUDIOCD_KIO_LOG) << "Trying to load library. File: \"" << libFileName.toLatin1() << "\"."; qCDebug(AUDIOCD_KIO_LOG) << "Trying to load" << libFileName;
QFunctionPointer cplugin = QLibrary(QLibraryInfo::location(QLibraryInfo::PluginsPath) + '/' + libFileName).resolve( "create_audiocd_encoders" ); QFunctionPointer cplugin = QLibrary(libFileName).resolve("create_audiocd_encoders");
if (!cplugin) if (!cplugin)
return NULL; return NULL;
qCDebug(AUDIOCD_KIO_LOG) << "We have a plugin. File: \"" << libFileName << "\"."; qCDebug(AUDIOCD_KIO_LOG) << "Loaded plugin";
return cplugin; return cplugin;
} }
...@@ -49,30 +50,34 @@ QFunctionPointer loadPlugin(const QString &libFileName) ...@@ -49,30 +50,34 @@ QFunctionPointer loadPlugin(const QString &libFileName)
void AudioCDEncoder::findAllPlugins(KIO::SlaveBase *slave, QList<AudioCDEncoder *>&encoders) void AudioCDEncoder::findAllPlugins(KIO::SlaveBase *slave, QList<AudioCDEncoder *>&encoders)
{ {
QString foundEncoders; QString foundEncoders;
QDir dir=QLibraryInfo::location(QLibraryInfo::PluginsPath);
if (!dir.exists()) { for (const QString &path : QCoreApplication::libraryPaths()) {
qCDebug(AUDIOCD_KIO_LOG) << "Directory given by QLibraryInfo: " << dir.path() << " doesn't exists!"; QDir dir(path);
} if (!dir.exists()) {
dir.setFilter(QDir::Files | QDir::Hidden); //qCDebug(AUDIOCD_KIO_LOG) << "Library path" << path << "does not exist";
const QFileInfoList files = dir.entryInfoList(); continue;
for (int i = 0; i < files.count(); ++i) { }
QFileInfo fi(files.at(i));
if (0 < fi.fileName().count(QRegularExpression( QLatin1String( "^libaudiocd_encoder_.*.so$" )))) { dir.setFilter(QDir::Files);
QString fileName = (fi.fileName().mid(0, fi.fileName().indexOf(QLatin1Char( '.' )))); const QFileInfoList files = dir.entryInfoList();
if (foundEncoders.contains(fileName)) { for (const QFileInfo &fi : qAsConst(files)) {
qCDebug(AUDIOCD_KIO_LOG) << "Warning, encoder has been found twice!"; if (fi.fileName().contains(QRegularExpression(QLatin1String("^libaudiocd_encoder_.*.so$")))) {
continue; QString fileName = fi.baseName();
}
foundEncoders.append(fileName); if (foundEncoders.contains(fileName)) {
QFunctionPointer function = loadPlugin(fileName); qCWarning(AUDIOCD_KIO_LOG) << "Encoder" << fileName << "found in multiple locations";
if (function) { continue;
void (*functionPointer) (KIO::SlaveBase *, QList<AudioCDEncoder*>&) = }
(void (*)(KIO::SlaveBase *slave, QList<AudioCDEncoder *>&encoders)) function; foundEncoders.append(fileName);
functionPointer(slave, encoders);
QFunctionPointer function = loadPlugin(fi.absoluteFilePath());
if (function) {
void (*functionPointer) (KIO::SlaveBase *, QList<AudioCDEncoder*>&) =
(void (*)(KIO::SlaveBase *slave, QList<AudioCDEncoder *>&encoders)) function;
functionPointer(slave, encoders);
}
} }
} }
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment