#include <qfactoryloader_p.h>
Inheritance diagram for QFactoryLoader:


Definition at line 46 of file qfactoryloader_p.h.
Public Member Functions | |
| QFactoryLoader (const char *iid, const QStringList &paths=QStringList(), const QString &suffix=QString(), Qt::CaseSensitivity=Qt::CaseSensitive) | |
| ~QFactoryLoader () | |
| QStringList | keys () const |
| QObject * | instance (const QString &key) const |
| QFactoryLoader::QFactoryLoader | ( | const char * | iid, | |
| const QStringList & | paths = QStringList(), |
|||
| const QString & | suffix = QString(), |
|||
| Qt::CaseSensitivity | = Qt::CaseSensitive | |||
| ) |
Definition at line 50 of file qfactoryloader.cpp.
References QString::arg(), QList< T >::at(), QDir::cleanPath(), QList< T >::clear(), QList< T >::count(), d, QDir::Files, QLibraryPrivate::findOrCreate(), QString::fromLatin1(), i, instance(), QList< T >::isEmpty(), j, key, QFactoryInterface::keys(), keys(), library, QCoreApplicationPrivate::mainThread(), QObject::moveToThread(), path, qDebug(), qt_debug_component(), QT_VERSION, QLibraryPrivate::qt_version, QList< T >::removeFirst(), QSettings::setValue(), QVariant::toStringList(), QSettings::UserScope, and QSettings::value().
00053 : QObject(*new QFactoryLoaderPrivate) 00054 { 00055 moveToThread(QCoreApplicationPrivate::mainThread()); 00056 Q_D(QFactoryLoader); 00057 d->iid = iid; 00058 00059 QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); 00060 00061 for (int i = 0; i < paths.count(); ++i) { 00062 QString path = paths.at(i) + suffix; 00063 if (!QDir(path).exists(QLatin1String("."))) 00064 continue; 00065 QStringList plugins = QDir(path).entryList(QDir::Files); 00066 QLibraryPrivate *library = 0; 00067 for (int j = 0; j < plugins.count(); ++j) { 00068 QString fileName = QDir::cleanPath(path + QLatin1Char('/') + plugins.at(j)); 00069 if (qt_debug_component()) { 00070 qDebug() << "QFactoryLoader::QFactoryLoader() looking at" << fileName; 00071 } 00072 library = QLibraryPrivate::findOrCreate(QFileInfo(fileName).canonicalFilePath()); 00073 if (!library->isPlugin()) { 00074 library->release(); 00075 if (qt_debug_component()) { 00076 qDebug() << " not a plugin"; 00077 } 00078 continue; 00079 } 00080 QString regkey = QString::fromLatin1("Qt Factory Cache %1.%2/%3:/%4") 00081 .arg((QT_VERSION & 0xff0000) >> 16) 00082 .arg((QT_VERSION & 0xff00) >> 8) 00083 .arg(QLatin1String(iid)) 00084 .arg(fileName); 00085 QStringList reg, keys; 00086 reg = settings.value(regkey).toStringList(); 00087 if (reg.count() && library->lastModified == reg[0]) { 00088 keys = reg; 00089 keys.removeFirst(); 00090 } else { 00091 if (!library->loadPlugin()) { 00092 if (qt_debug_component()) { 00093 qDebug() << " could not load"; 00094 } 00095 library->release(); 00096 continue; 00097 } 00098 QObject *instance = library->instance(); 00099 if (!instance) 00100 // ignore plugins that have a valid signature but cannot be loaded. 00101 continue; 00102 QFactoryInterface *factory = qobject_cast<QFactoryInterface*>(instance); 00103 if (instance && factory && instance->qt_metacast(iid)) 00104 keys = factory->keys(); 00105 if (keys.isEmpty()) 00106 library->unload(); 00107 reg.clear(); 00108 reg << library->lastModified; 00109 reg += keys; 00110 settings.setValue(regkey, reg); 00111 } 00112 if (qt_debug_component()) { 00113 qDebug() << "keys" << keys; 00114 } 00115 00116 if (keys.isEmpty()) { 00117 library->release(); 00118 continue; 00119 } 00120 d->libraryList += library; 00121 for (int k = 0; k < keys.count(); ++k) { 00122 // first come first serve, unless the first 00123 // library was built with a future Qt version, 00124 // whereas the new one has a Qt version that fits 00125 // better 00126 QString key = keys.at(k); 00127 if (!cs) 00128 key = key.toLower(); 00129 QLibraryPrivate *previous = d->keyMap.value(key); 00130 if (!previous || (previous->qt_version > QT_VERSION && library->qt_version <= QT_VERSION)) { 00131 d->keyMap[key] = library; 00132 d->keyList += keys.at(k); 00133 } 00134 } 00135 } 00136 } 00137 }
Here is the call graph for this function:

| QFactoryLoader::~QFactoryLoader | ( | ) |
| QStringList QFactoryLoader::keys | ( | ) | const |
Definition at line 146 of file qfactoryloader.cpp.
References QList< T >::at(), QList< T >::count(), d, i, and QPluginLoader::staticInstances().
Referenced by Q_GLOBAL_STATIC_WITH_ARGS(), and QFactoryLoader().
00147 { 00148 Q_D(const QFactoryLoader); 00149 QMutexLocker locker(&d->mutex); 00150 QStringList keys = d->keyList; 00151 QObjectList instances = QPluginLoader::staticInstances(); 00152 for (int i = 0; i < instances.count(); ++i) 00153 if (QFactoryInterface *factory = qobject_cast<QFactoryInterface*>(instances.at(i))) 00154 if (instances.at(i)->qt_metacast(d->iid)) 00155 keys += factory->keys(); 00156 return keys; 00157 }
Here is the call graph for this function:

Definition at line 159 of file qfactoryloader.cpp.
References QList< T >::at(), Qt::CaseInsensitive, QList< T >::count(), d, i, key, library, QCoreApplicationPrivate::mainThread(), and QPluginLoader::staticInstances().
Referenced by Q_GLOBAL_STATIC_WITH_ARGS(), and QFactoryLoader().
00160 { 00161 Q_D(const QFactoryLoader); 00162 QMutexLocker locker(&d->mutex); 00163 QObjectList instances = QPluginLoader::staticInstances(); 00164 for (int i = 0; i < instances.count(); ++i) 00165 if (QFactoryInterface *factory = qobject_cast<QFactoryInterface*>(instances.at(i))) 00166 if (instances.at(i)->qt_metacast(d->iid) && factory->keys().contains(key, Qt::CaseInsensitive)) 00167 return instances.at(i); 00168 00169 if (QLibraryPrivate* library = d->keyMap.value(key)) { 00170 if (library->instance || library->loadPlugin()) { 00171 if (QObject *obj = library->instance()) { 00172 if (obj && !obj->parent()) 00173 obj->moveToThread(QCoreApplicationPrivate::mainThread()); 00174 return obj; 00175 } 00176 } 00177 } 00178 return 0; 00179 }
Here is the call graph for this function:

1.5.1