summaryrefslogtreecommitdiffstats
path: root/src/corelib/plugin/qfactoryloader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/plugin/qfactoryloader.cpp')
-rw-r--r--src/corelib/plugin/qfactoryloader.cpp179
1 files changed, 91 insertions, 88 deletions
diff --git a/src/corelib/plugin/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp
index dcf1b1a81d..6cd02e3a3f 100644
--- a/src/corelib/plugin/qfactoryloader.cpp
+++ b/src/corelib/plugin/qfactoryloader.cpp
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -33,7 +39,7 @@
#include "qfactoryloader_p.h"
-#ifndef QT_NO_LIBRARY
+#ifndef QT_NO_QOBJECT
#include "qfactoryinterface.h"
#include "qmap.h"
#include <qdir.h>
@@ -50,37 +56,29 @@
QT_BEGIN_NAMESPACE
-Q_GLOBAL_STATIC(QList<QFactoryLoader *>, qt_factory_loaders)
-
-Q_GLOBAL_STATIC_WITH_ARGS(QMutex, qt_factoryloader_mutex, (QMutex::Recursive))
-
-namespace {
-
-// avoid duplicate QStringLiteral data:
-inline QString iidKeyLiteral() { return QStringLiteral("IID"); }
-#ifdef QT_SHARED
-inline QString versionKeyLiteral() { return QStringLiteral("version"); }
-#endif
-inline QString metaDataKeyLiteral() { return QStringLiteral("MetaData"); }
-inline QString keysKeyLiteral() { return QStringLiteral("Keys"); }
-
-}
-
class QFactoryLoaderPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QFactoryLoader)
public:
QFactoryLoaderPrivate(){}
+ QByteArray iid;
+#ifndef QT_NO_LIBRARY
~QFactoryLoaderPrivate();
mutable QMutex mutex;
- QByteArray iid;
QList<QLibraryPrivate*> libraryList;
QMap<QString,QLibraryPrivate*> keyMap;
QString suffix;
Qt::CaseSensitivity cs;
QStringList loadedPaths;
+#endif
};
+#ifndef QT_NO_LIBRARY
+
+Q_GLOBAL_STATIC(QList<QFactoryLoader *>, qt_factory_loaders)
+
+Q_GLOBAL_STATIC_WITH_ARGS(QMutex, qt_factoryloader_mutex, (QMutex::Recursive))
+
QFactoryLoaderPrivate::~QFactoryLoaderPrivate()
{
for (int i = 0; i < libraryList.count(); ++i) {
@@ -90,25 +88,6 @@ QFactoryLoaderPrivate::~QFactoryLoaderPrivate()
}
}
-QFactoryLoader::QFactoryLoader(const char *iid,
- const QString &suffix,
- Qt::CaseSensitivity cs)
- : QObject(*new QFactoryLoaderPrivate)
-{
- moveToThread(QCoreApplicationPrivate::mainThread());
- Q_D(QFactoryLoader);
- d->iid = iid;
- d->cs = cs;
- d->suffix = suffix;
-
-
- QMutexLocker locker(qt_factoryloader_mutex());
- update();
- qt_factory_loaders()->append(this);
-}
-
-
-
void QFactoryLoader::update()
{
#ifdef QT_SHARED
@@ -172,12 +151,12 @@ void QFactoryLoader::update()
QStringList keys;
bool metaDataOk = false;
- QString iid = library->metaData.value(iidKeyLiteral()).toString();
+ QString iid = library->metaData.value(QLatin1String("IID")).toString();
if (iid == QLatin1String(d->iid.constData(), d->iid.size())) {
- QJsonObject object = library->metaData.value(metaDataKeyLiteral()).toObject();
+ QJsonObject object = library->metaData.value(QLatin1String("MetaData")).toObject();
metaDataOk = true;
- QJsonArray k = object.value(keysKeyLiteral()).toArray();
+ QJsonArray k = object.value(QLatin1String("Keys")).toArray();
for (int i = 0; i < k.size(); ++i)
keys += d->cs ? k.at(i).toString() : k.at(i).toString().toLower();
}
@@ -200,9 +179,9 @@ void QFactoryLoader::update()
QLibraryPrivate *previous = d->keyMap.value(key);
int prev_qt_version = 0;
if (previous) {
- prev_qt_version = (int)previous->metaData.value(versionKeyLiteral()).toDouble();
+ prev_qt_version = (int)previous->metaData.value(QLatin1String("version")).toDouble();
}
- int qt_version = (int)library->metaData.value(versionKeyLiteral()).toDouble();
+ int qt_version = (int)library->metaData.value(QLatin1String("version")).toDouble();
if (!previous || (prev_qt_version > QT_VERSION && qt_version <= QT_VERSION)) {
d->keyMap[key] = library;
++keyUsageCount;
@@ -229,17 +208,61 @@ QFactoryLoader::~QFactoryLoader()
qt_factory_loaders()->removeAll(this);
}
+#if defined(Q_OS_UNIX) && !defined (Q_OS_MAC)
+QLibraryPrivate *QFactoryLoader::library(const QString &key) const
+{
+ Q_D(const QFactoryLoader);
+ return d->keyMap.value(d->cs ? key : key.toLower());
+}
+#endif
+
+void QFactoryLoader::refreshAll()
+{
+ QMutexLocker locker(qt_factoryloader_mutex());
+ QList<QFactoryLoader *> *loaders = qt_factory_loaders();
+ for (QList<QFactoryLoader *>::const_iterator it = loaders->constBegin();
+ it != loaders->constEnd(); ++it) {
+ (*it)->update();
+ }
+}
+
+#endif // QT_NO_LIBRARY
+
+QFactoryLoader::QFactoryLoader(const char *iid,
+ const QString &suffix,
+ Qt::CaseSensitivity cs)
+ : QObject(*new QFactoryLoaderPrivate)
+{
+ moveToThread(QCoreApplicationPrivate::mainThread());
+ Q_D(QFactoryLoader);
+ d->iid = iid;
+#ifndef QT_NO_LIBRARY
+ d->cs = cs;
+ d->suffix = suffix;
+
+ QMutexLocker locker(qt_factoryloader_mutex());
+ update();
+ qt_factory_loaders()->append(this);
+#else
+ Q_UNUSED(suffix);
+ Q_UNUSED(cs);
+#endif
+}
+
QList<QJsonObject> QFactoryLoader::metaData() const
{
Q_D(const QFactoryLoader);
- QMutexLocker locker(&d->mutex);
QList<QJsonObject> metaData;
+#ifndef QT_NO_LIBRARY
+ QMutexLocker locker(&d->mutex);
for (int i = 0; i < d->libraryList.size(); ++i)
metaData.append(d->libraryList.at(i)->metaData);
+#endif
- foreach (const QStaticPlugin &plugin, QPluginLoader::staticPlugins()) {
+ const auto staticPlugins = QPluginLoader::staticPlugins();
+ for (const QStaticPlugin &plugin : staticPlugins) {
const QJsonObject object = plugin.metaData();
- if (object.value(iidKeyLiteral()) != QLatin1String(d->iid.constData(), d->iid.size()))
+ if (object.value(QLatin1String("IID")) != QLatin1String(d->iid.constData(), d->iid.size()))
continue;
metaData.append(object);
}
@@ -252,6 +275,7 @@ QObject *QFactoryLoader::instance(int index) const
if (index < 0)
return 0;
+#ifndef QT_NO_LIBRARY
if (index < d->libraryList.size()) {
QLibraryPrivate *library = d->libraryList.at(index);
if (library->instance || library->loadPlugin()) {
@@ -266,12 +290,13 @@ QObject *QFactoryLoader::instance(int index) const
}
return 0;
}
-
index -= d->libraryList.size();
+#endif
+
QVector<QStaticPlugin> staticPlugins = QPluginLoader::staticPlugins();
for (int i = 0; i < staticPlugins.count(); ++i) {
const QJsonObject object = staticPlugins.at(i).metaData();
- if (object.value(iidKeyLiteral()) != QLatin1String(d->iid.constData(), d->iid.size()))
+ if (object.value(QLatin1String("IID")) != QLatin1String(d->iid.constData(), d->iid.size()))
continue;
if (index == 0)
@@ -282,33 +307,13 @@ QObject *QFactoryLoader::instance(int index) const
return 0;
}
-#if defined(Q_OS_UNIX) && !defined (Q_OS_MAC)
-QLibraryPrivate *QFactoryLoader::library(const QString &key) const
-{
- Q_D(const QFactoryLoader);
- return d->keyMap.value(d->cs ? key : key.toLower());
-}
-#endif
-
-void QFactoryLoader::refreshAll()
-{
- QMutexLocker locker(qt_factoryloader_mutex());
- QList<QFactoryLoader *> *loaders = qt_factory_loaders();
- for (QList<QFactoryLoader *>::const_iterator it = loaders->constBegin();
- it != loaders->constEnd(); ++it) {
- (*it)->update();
- }
-}
-
QMultiMap<int, QString> QFactoryLoader::keyMap() const
{
QMultiMap<int, QString> result;
- const QString metaDataKey = metaDataKeyLiteral();
- const QString keysKey = keysKeyLiteral();
const QList<QJsonObject> metaDataList = metaData();
for (int i = 0; i < metaDataList.size(); ++i) {
- const QJsonObject metaData = metaDataList.at(i).value(metaDataKey).toObject();
- const QJsonArray keys = metaData.value(keysKey).toArray();
+ const QJsonObject metaData = metaDataList.at(i).value(QLatin1String("MetaData")).toObject();
+ const QJsonArray keys = metaData.value(QLatin1String("Keys")).toArray();
const int keyCount = keys.size();
for (int k = 0; k < keyCount; ++k)
result.insert(i, keys.at(k).toString());
@@ -318,12 +323,10 @@ QMultiMap<int, QString> QFactoryLoader::keyMap() const
int QFactoryLoader::indexOf(const QString &needle) const
{
- const QString metaDataKey = metaDataKeyLiteral();
- const QString keysKey = keysKeyLiteral();
const QList<QJsonObject> metaDataList = metaData();
for (int i = 0; i < metaDataList.size(); ++i) {
- const QJsonObject metaData = metaDataList.at(i).value(metaDataKey).toObject();
- const QJsonArray keys = metaData.value(keysKey).toArray();
+ const QJsonObject metaData = metaDataList.at(i).value(QLatin1String("MetaData")).toObject();
+ const QJsonArray keys = metaData.value(QLatin1String("Keys")).toArray();
const int keyCount = keys.size();
for (int k = 0; k < keyCount; ++k) {
if (!keys.at(k).toString().compare(needle, Qt::CaseInsensitive))
@@ -335,4 +338,4 @@ int QFactoryLoader::indexOf(const QString &needle) const
QT_END_NAMESPACE
-#endif // QT_NO_LIBRARY
+#endif // QT_NO_QOBJECT