/*! Creates and returns a screensaver on the given token. \param token Identifies the screensaver to be created. \return The created state. */ Screensaver* ScreensaverFactoryPrivate::createScreensaver(const ScreensaverToken &token) { QStringList pluginPaths; // check plugin dirs from root of different drives QFileInfoList drives = QDir::drives(); for(int i=0; i < drives.count(); i++) { QFileInfo drive = drives.at(i); QString driveLetter = drive.absolutePath(); QString path = driveLetter + mPluginDirectory; if (QDir(path).exists()) { pluginPaths << path; } } // check plugin dir relative to current dir if (QDir(mPluginDirectory).exists() && !pluginPaths.contains(QDir(mPluginDirectory).absolutePath())) { pluginPaths << mPluginDirectory; } IScreensaverProvider *provider(0); QPluginLoader *loader = new QPluginLoader(); QObject *plugin(0); for(int i=0; i < pluginPaths.count(); i++) { QString path = pluginPaths.at(i); QString fileName = QDir(path).absoluteFilePath(token.mLibrary); loader->setFileName(fileName); plugin = loader->instance(); provider = qobject_cast<IScreensaverProvider*>(plugin); if (provider) { break; } } Screensaver *screensaver(0); if (provider) { screensaver = provider->createScreensaver(token); if (!screensaver) { qWarning() << "Screensaver creation failed."; qWarning() << token.mLibrary << "cannot provide" << token.mUri; loader->unload(); delete loader; } else { // unload plugin once screensaver gets deleted ScreensaverPluginUnloader *unloader = new ScreensaverPluginUnloader(loader); unloader->connect(screensaver, SIGNAL(destroyed()), SLOT(deleteLater())); } } else { qDebug() << "Screensaver creation failed."; qWarning() << token.mLibrary << "- provider not found"; loader->unload(); delete loader; } return screensaver; }
AExtensionFactoryPrivate::AExtensionFactoryPrivate() : QObject( qApp ) { QString extensionsDirName; AExtensionInterface *iface = 0; QObject *plugin = 0; QPluginLoader pluginLoader; #ifdef Q_OS_WIN32 extensionsDirName = qApp->applicationDirPath()+"/extensions"; #else extensionsDirName = "/usr/lib/ananas4/extensions"; #endif hash.clear(); extensionKeys.clear(); QDir extensionsDirectory( extensionsDirName ); QStringList extensionFiles = extensionsDirectory.entryList( QDir::Files ); QString fileName = extensionFiles.first(); for (int i=0; i<extensionFiles.count(); i++){ fileName = extensionFiles[i]; pluginLoader.setFileName( extensionsDirectory.absoluteFilePath( fileName ) ); plugin = pluginLoader.instance(); if (plugin) { iface = qobject_cast<AExtensionInterface *>(plugin); if( iface ) { extensionKeys.append( iface->key()); hash[ iface->key()] = iface; } } } }
static QList<VirtualKeyboardFactory *> getVKBFactories() { QList<VirtualKeyboardFactory *> list; QString path("/usr/lib/luna"); qDebug() << "\033[1;33;45m" << Q_FUNC_INFO << "Searching for VKB plugins in" << path << "\033[0m"; QDir plugindir = QDir(path); QStringList files = plugindir.entryList(QDir::Files); qDebug() << "\033[1;33;45m" << Q_FUNC_INFO << "Found" << files.count() << "files" << "\033[0m"; QPluginLoader loader; QStringList::const_iterator it = files.constBegin(); while (it != files.constEnd()) { qDebug() << "\033[1;33;40m" << Q_FUNC_INFO << "Checking" << (*it) << "\033[0m"; loader.setFileName(plugindir.absoluteFilePath(*it)); VirtualKeyboardFactory *factory = qobject_cast<VirtualKeyboardFactory *>(loader.instance()); if (factory) { qDebug() << "\033[1;32;40m" << Q_FUNC_INFO << "Loaded plugin" << (*it) << "successfully" << "\033[0m"; list.append(factory); } else { qWarning() << "\033[1;31;40m" << Q_FUNC_INFO << "Failed to load" << (*it) << "\n" << loader.errorString() << "\033[0m"; } ++it; } return list; }
void tst_QPluginLoader::loadHints() { QPluginLoader loader; QCOMPARE(loader.loadHints(), (QLibrary::LoadHints)0); //Do not crash loader.setLoadHints(QLibrary::ResolveAllSymbolsHint); loader.setFileName( sys_qualifiedLibraryName("theplugin")); //a plugin QCOMPARE(loader.loadHints(), QLibrary::ResolveAllSymbolsHint); }
// looking for dynamic plugins foreach(const QFileInfo & fileName, files) { emit log((int)LogDebug, MODULENAME, QString("Loading plugin: %1").arg(fileName.fileName()), ""); QPluginLoader loader; loader.setLoadHints(QLibrary::ResolveAllSymbolsHint|QLibrary::ExportExternalSymbolsHint); loader.setFileName( fileName.absoluteFilePath()); if (!loader.load()) { qCritical() << loader.errorString(); continue; } QObject *plugin = loader.instance(); if (plugin && qobject_cast<PropertyInterface*>(plugin)) m_plugins.push_back(qobject_cast<PropertyInterface*>(plugin)); else emit log((int)LogWarning, MODULENAME, QString("It\'s not a PropertyEditor plugin: %1").arg(fileName.fileName()), ""); }
foreach (const QString &dir, dirsToCheck) { QVector<KPluginMetaData> metadataList = KPluginLoader::findPlugins(dir, [=](const KPluginMetaData &data) { return data.serviceTypes().contains("artikulate/libsound/backend"); }); foreach (const auto &metadata, metadataList) { loader.setFileName(metadata.fileName()); qCDebug(LIBSOUND_LOG) << "Load Plugin: " << metadata.name(); if (!loader.load()) { qCCritical(LIBSOUND_LOG) << "Error while loading plugin: " << metadata.name(); } KPluginFactory *factory = KPluginLoader(loader.fileName()).factory(); if (!factory) { qCCritical(LIBSOUND_LOG) << "Could not load plugin:" << metadata.name(); continue; } BackendInterface *plugin = factory->create<BackendInterface>(parent, QList< QVariant >()); if (plugin->outputBackend()) { m_backendList.append(plugin->outputBackend()); } }
void tst_QPluginLoader::reloadPlugin() { QPluginLoader loader; loader.setFileName( sys_qualifiedLibraryName("theplugin")); //a plugin loader.load(); // not recommended, instance() should do the job. PluginInterface *instance = qobject_cast<PluginInterface*>(loader.instance()); QVERIFY(instance); QCOMPARE(instance->pluginName(), QLatin1String("Plugin ok")); QSignalSpy spy(loader.instance(), SIGNAL(destroyed())); QVERIFY(spy.isValid()); QVERIFY(loader.unload()); // refcount reached 0, did really unload QCOMPARE(spy.count(), 1); // reload plugin QVERIFY(loader.load()); QVERIFY(loader.isLoaded()); PluginInterface *instance2 = qobject_cast<PluginInterface*>(loader.instance()); QVERIFY(instance2); QCOMPARE(instance2->pluginName(), QLatin1String("Plugin ok")); QVERIFY(loader.unload()); }
void QGeoSatelliteInfoSourcePrivate::loadDynamicPlugins(QHash<QString, QGeoPositionInfoSourceFactory *> &plugins) { QStringList paths; paths << mobilityPlugins(QLatin1String("position")); QPluginLoader qpl; QString blockName; QSettings settings(QSettings::SystemScope, QLatin1String("Nokia"), QLatin1String("QtLocationPosAndSat")); QVariant value = settings.value("position.plugin.operator.whitelist"); if (value.isValid()) { QStringList parts = value.toString().split(","); if (parts.size() == 4) { QFile file(parts.at(1)); file.open(QIODevice::ReadOnly); QCryptographicHash hash(QCryptographicHash::Sha1); while (!file.atEnd()) { QByteArray data = file.read(4096); hash.addData(data); } file.close(); QByteArray hexHash = hash.result().toHex(); bool loadIt = true; if (QString::number(file.size()) != parts.at(3)) { qCritical("Position info plugin: bad plugin size for %s", qPrintable(parts.at(1))); qWarning("Will fall back to platform default"); loadIt = false; } if (hexHash != parts.at(2).toLatin1()) { qCritical("Position info plugin: bad plugin hash for %s", qPrintable(parts.at(1))); qWarning("Will fall back to platform default"); loadIt = false; } if (loadIt) { qpl.setFileName(parts.at(1)); QGeoPositionInfoSourceFactory *f = qobject_cast<QGeoPositionInfoSourceFactory*>(qpl.instance()); if (f) { QString name = f->sourceName(); if (name == parts.at(0)) { plugins.insert(name, f); } else { qCritical("Position info plugin: bad plugin name for %s", qPrintable(parts.at(1))); qWarning("Will fall back to platform default"); } } } // still set blockName to ensure the plugin doesn't load blockName = parts.at(1); } else { qWarning("Position plugin whitelist: invalid format -- should be key,filename,hash,size"); } } for (int i = 0; i < paths.count(); ++i) { if (paths.at(i) != blockName) { qpl.setFileName(paths.at(i)); QGeoPositionInfoSourceFactory *f = qobject_cast<QGeoPositionInfoSourceFactory*>(qpl.instance()); if (f) { QString name = f->sourceName(); #if !defined QT_NO_DEBUG const bool showDebug = qgetenv("QT_DEBUG_PLUGINS").toInt() > 0; if (showDebug) qDebug("Dynamic: found a service provider plugin with name %s", qPrintable(name)); #endif plugins.insertMulti(name, f); } } } }
/** * @brief Avr_Core_Builder::loadCore Loads the core described by the configuration file at the path mmcu * @param mmcu The path for the configuration file * @return */ Avr_Core* Avr_Core_Builder::loadCore(QString mmcu){ //Loader to open plugins QPluginLoader loader; core = new Avr_Core(); //Setup the Basics core->setMemory(new Avr_Memory); core->setRegisters(new Avr_Registers); //Load Configuration File string line;string id;string setting; QString path = PLUGIN_PATH + mmcu; ifstream configFile; configFile.open(path.toStdString().c_str()); if (configFile.is_open()){ //Process config file, there might be a problem //with the loop termination here while (!configFile.eof()){ configFile >> line; if (line == "END"){ break; } if (line[0]==';'){ //Line is a comment skip continue; } int i = line.find(':'); id = line.substr(0,i); setting = line.substr(i + 1, line.size() - i - 1); if (id == "RAMSIZE"){ qDebug() << "Load Ram\n"; core->mem->initRam(sizeToInt(setting) + 0xff); core->reg->setRam(core->mem->getRam()); core->reg->setRamEnd(core->mem->getRamEnd()); }else if (id == "FLASHSIZE"){ qDebug() << "Load Flash\n"; core->setFlash(new Avr_Flash(sizeToInt(setting))); }else if (id == "EPROMSIZE"){ qDebug() << "Load Eprom\n"; core->mem->initEprom(sizeToInt(setting)); }else if (id == "SPL"){ qDebug() << "Set SPL\n"; core->reg->setStackPL(getRegPtr(setting)); }else if (id == "SPH"){ qDebug() << "Set SPH\n"; core->reg->setStackPH(getRegPtr(setting)); }else if (id == "SREG"){ core->reg->setSREGP(getRegPtr(setting)); }else if (id == "PLUGINLIB"){ qDebug() << "Load Plugin " << QString(setting.c_str()) << "\n"; loader.setFileName(PLUGIN_PATH + QString(setting.c_str())); loader.load(); QObject *plugin = loader.instance(); Avr_Hardware_Interface *h = qobject_cast<Avr_Hardware_Interface*>(plugin); //Attach all registers h->attachRegister(core->reg); //Load Registers for the plugin //this loads specific registers for specific roles for (int j = 0; j < h->getRegisterCount();j++){ configFile >> line; if (line[0]==';'){ j -= 1; continue; } i = line.find(':'); id = line.substr(0,i); setting = line.substr(i + 1, line.size() - i - 1); qDebug() << "Setting " << QString(setting.c_str()) << "\n"; h->bindRegister(QString(id.c_str()),getRegPtr(setting)); //h->bindRegister(QString(id.c_str()),getRegLoc(setting)); } //Load Interrupts core->hardware.push_back(h); }else if (id == "INTERFACE"){ loader.setFileName(QString(setting.c_str())); loader.load(); QList <QObject*> objects = loader.staticInstances(); if (loader.isLoaded()){ std::cout << "Loaded\n"; }else{ std::cout << "Object Count " << objects.size() <<"\n"; } QObject *plugin = loader.instance(); //Set the Interface; this->interface = qobject_cast<Avr_Hardware_Interface*>(plugin); } }
/*! * This function will do the basic loading/unloading tests on the applet. */ void Ft_AppletLoader::DoAppletTest (const char *soname, bool hasBrief) { QPluginLoader loader; loader.setFileName (QString (APPLET_PATH) + QString (soname)); loader.setLoadHints (QLibrary::ResolveAllSymbolsHint); /* * Getting the DcpAppletIf applet interface object. Checking if the applet * loaded, the type of the applet interface is right. */ QVERIFY2 (loader.load (), qPrintable (loader.errorString ())); DcpAppletIf *applet = qobject_cast<DcpAppletIf *>(loader.instance ()); QVERIFY (applet != 0); /* * Do initialization... in the same way how controlpanel doing: */ applet->init (); #ifndef TEST_NEW_TITLE_METHODS QVERIFY (! applet->title ().isEmpty ()); #endif /* * Checking if the applet brief is constructed. */ DcpBrief *brief = applet->constructBrief (); if (hasBrief) { QVERIFY2(brief, "Error when creating brief widget"); #ifdef TEST_NEW_TITLE_METHODS /* * Checking if the applet has a non-empty title string. */ QVERIFY (! brief->titleText ().isEmpty ()); #endif } else QVERIFY2(!brief, "This applet should not have a Brief"); /* * Checking if the the main view (the applet widget) is constructed. FIXME: * We should call the getMainWidgetId here, but I'm not sure how it is done * after the refactoring. */ DcpWidget *widget = applet->constructWidget (0); QVERIFY2 (widget, "Error when creating applet's main widget"); #ifdef TEST_NEW_TITLE_METHODS /* * Check if the applet widget has a non-empty title string. */ QVERIFY (! widget->title ().isEmpty ()); #endif QTest::qWait (1000); // loader.unload (); // delete widget; // delete brief; }
void TransferEnginePrivate::enabledPluginsCheck() { Q_Q(TransferEngine); if (m_fileWatcherTimer->isActive()) { m_fileWatcherTimer->stop(); } if (m_infoObjects.count() > 0) { qWarning() << Q_FUNC_INFO << "Already quering account info" << m_infoObjects.count(); return; } // First clear old data m_enabledPlugins.clear(); qDeleteAll(m_infoObjects); m_infoObjects.clear(); QPluginLoader loader; loader.setLoadHints(QLibrary::ResolveAllSymbolsHint | QLibrary::ExportExternalSymbolsHint); // Handle the case if all the plugins have been removed. QStringList plugins = pluginList(); if (plugins.isEmpty()) { emit q->transferMethodListChanged(); return; } // We have plugins Q_FOREACH(QString plugin, plugins) { loader.setFileName(plugin); TransferPluginInterface *interface = qobject_cast<TransferPluginInterface*>(loader.instance()); if (interface && interface->enabled()) { TransferPluginInfo *info = interface->infoObject(); if (!info) { qWarning() << Q_FUNC_INFO << "NULL Info object!"; continue; } if (info->ready()) { if (info->info().count() > 0) { m_enabledPlugins << info->info(); } else { // Plugin has nothing to provide, just ignore it delete info; } } else { // These object will be cleaned in pluginInfoReady() slot. m_infoObjects << info; connect(info, SIGNAL(infoReady()), this, SLOT(pluginInfoReady())); connect(info, SIGNAL(infoError(QString)), this, SLOT(pluginInfoError(QString))); info->query(); } } if (!interface) { qWarning() << Q_FUNC_INFO << loader.errorString(); } }