File indexing completed on 2024-10-06 09:35:54
0001 /* This file is part of the KDE libraries 0002 Copyright (C) 1999 Torben Weis <weis@kde.org> 0003 Copyright (C) 2000 Michael Matz <matz@kde.org> 0004 Copyright (C) 2007 Bernhard Loos <nhuh.put@web.de.org> 0005 0006 This library is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU Library General Public 0008 License version 2 as published by the Free Software Foundation. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 #include "klibrary.h" 0021 0022 #include <QDir> 0023 #include <QPointer> 0024 #include <QDebug> 0025 0026 #include <kpluginfactory.h> 0027 #include <kpluginloader.h> 0028 0029 // not static for the benefit of KLibLoader 0030 QString findLibrary(const QString &name) 0031 { 0032 QString libname = KPluginLoader::findPlugin(name); 0033 #ifdef Q_OS_WIN 0034 // we don't have 'lib' prefix on windows -> remove it and try again 0035 if (libname.isEmpty()) { 0036 libname = name; 0037 QString file, path; 0038 0039 int pos = libname.lastIndexOf(QLatin1Char('/')); 0040 if (pos >= 0) { 0041 file = libname.mid(pos + 1); 0042 path = libname.left(pos); 0043 libname = path + QLatin1Char('/') + file.mid(3); 0044 } else { 0045 file = libname; 0046 libname = file.mid(3); 0047 } 0048 if (!file.startsWith(QLatin1String("lib"))) { 0049 return file; 0050 } 0051 0052 libname = KPluginLoader::findPlugin(libname); 0053 if (libname.isEmpty()) { 0054 libname = name; 0055 } 0056 } 0057 #endif 0058 return libname; 0059 } 0060 0061 KLibrary::KLibrary(QObject *parent) 0062 : QLibrary(parent), d_ptr(nullptr) 0063 { 0064 } 0065 0066 KLibrary::KLibrary(const QString &name, QObject *parent) 0067 : QLibrary(findLibrary(name), parent), d_ptr(nullptr) 0068 { 0069 } 0070 0071 KLibrary::KLibrary(const QString &name, int verNum, QObject *parent) 0072 : QLibrary(findLibrary(name), verNum, parent), d_ptr(nullptr) 0073 { 0074 } 0075 0076 KLibrary::~KLibrary() 0077 { 0078 } 0079 0080 void KLibrary::setFileName(const QString &name) 0081 { 0082 QLibrary::setFileName(findLibrary(name)); 0083 } 0084 0085 #include "moc_klibrary.cpp"