int Global::documentType(const QUrl& document) { QMimeType mime = QMimeDatabase{}.mimeTypeForUrl(document); QList<QPluginLoader*> plugins = KoJsonTrader::self()->query("Calligra/Part", mime.name()); for (int i = 0; i < plugins.count(); i++) { QPluginLoader* loader = plugins.at(i); if(loader->fileName().contains("words")) { return DocumentType::TextDocument; } else if(loader->fileName().contains("sheets")) { return DocumentType::Spreadsheet; } else if(loader->fileName().contains("stage")) { return DocumentType::Presentation; } } // Since we don't actually have a Calligra plugin that handles these... if(staticTextTypes.contains(mime.name())) { return DocumentType::StaticTextDocument; } return DocumentType::Unknown; }
void AbstractPluginLoader::loadPlugins(const QRegExp& fileRx, QVector<QString>* errors) { Q_D(AbstractPluginLoader); const QDir pluginsFolder(this->loadingFolder()); QStringList entries(pluginsFolder.entryList(QDir::Files)); foreach (const QString& entry, entries) { if (fileRx.indexIn(entry) != -1 && ::isLibrary(entry)) { // Try to load the plugin #ifdef DEBUG_ABSTRACT_PLUGIN_LOADER qDebug() << "try to load" << entry; #endif // DEBUG_ABSTRACT_PLUGIN_LOADER QPluginLoader* pluginLoader = new QPluginLoader(pluginsFolder.absoluteFilePath(entry)); QObject* plugin = pluginLoader->instance(); // Is the plugin compatible ? if (this->isPluginCompatible(plugin)) { d->m_plugins.append(plugin); d->m_pluginLoaders.append(pluginLoader); d->m_pluginFilenames.insert(plugin, entry); } else { #ifdef DEBUG_ABSTRACT_PLUGIN_LOADER qDebug() << " not added"; #endif // DEBUG_ABSTRACT_PLUGIN_LOADER if (errors != NULL) //: %1 holds the path to a plugin (DLL) //: %2 holds an error description errors->append(QObject::tr("Failed to load plugin (maybe wrong interface) %1 : %2") .arg(pluginLoader->fileName()) .arg(pluginLoader->errorString())); pluginLoader->unload(); delete pluginLoader; } // end if (this->isPluginCompatible(plugin)) } // end if (fileRx.indexIn(entry) != -1) } // end foreach () }
void GLWidget::loadPlugins(const QStringList& list) { QStringList::ConstIterator it = list.constBegin(); while(it != list.constEnd()) { QString name = *it; QPluginLoader *loader = new QPluginLoader(name); if (! loader->load()) { qDebug() << "Could not load plugin " << name << "\n"; qDebug() << loader->errorString() << "\n"; } if (loader->isLoaded()) { qDebug() << "Loaded plugin: " << loader->fileName(); // << endl; QObject *plugin = loader->instance(); if (plugin) { plugins.push_back(loader); BasicPlugin *plugin = qobject_cast<BasicPlugin *>(loader->instance()); // initialize plugin if (plugin) { plugin->setWidget(this); plugin->setArgs(mainArgs); plugin->onPluginLoad(); if (plugin->drawScene()) // overrides drawScene? drawPlugin = plugin; } } } else { qDebug() << "Load error: " << name << endl; delete loader; } ++it; } // make sure all plugins know about the latest plugin that overrides drawScene for (unsigned int i=0; i<plugins.size(); ++i) { BasicPlugin *plugin = qobject_cast<BasicPlugin *>(plugins[i]->instance()); if (plugin) plugin->setDrawPlugin(drawPlugin); else { qDebug() << "Error: the plugin must implement the BasicPlugin interface" << endl << " Example: " << endl << " Q_INTERFACES(BasicPlugin)" << endl; } } resetCamera(); }
void tryLoad(QPluginLoader &loader) { if (T *newInst = qobject_cast<T*>(loader.instance())) { if (!inst || inst->pluginPriority() < newInst->pluginPriority()) { inst = newInst; pl.unload(); //release any reference to a previous plugin instance pl.setFileName(loader.fileName()); pl.load(); //Adds a ref to the library } } }
QVariant GameEngine::pluginList() { QStringList list; QPluginLoader* loader; foreach (loader,m_pluginList) { QString s = loader->fileName(); s = s.mid(s.lastIndexOf("/")+1); s = s.left(s.lastIndexOf(".")); s = s.toUpper(); #ifdef Q_WS_MAEMO_5 if (s.contains("LIB")) { s = s.right(s.length() - (s.indexOf("LIB")+3)); } #endif list.append(s); }
QObject *PluginLoader::createForName(const QString &name) { if (!mPluginInfos.contains(name)) { qCWarning(AKONADICORE_LOG) << "plugin name \"" << name << "\" is unknown to the plugin loader." << endl; return 0; } PluginMetaData &info = mPluginInfos[name]; //First try to load it staticly foreach (QObject *plugin, QPluginLoader::staticInstances()) { if (QLatin1String(plugin->metaObject()->className()) == info.className) { info.loaded = true; return plugin; break; } } if (!info.loaded) { QPluginLoader *loader = new QPluginLoader(info.library); if (loader->fileName().isEmpty()) { qCWarning(AKONADICORE_LOG) << loader->errorString(); delete loader; return 0; } mPluginLoaders.insert(name, loader); info.loaded = true; } QPluginLoader *loader = mPluginLoaders.value(name); Q_ASSERT(loader); QObject *object = loader->instance(); if (!object) { qCWarning(AKONADICORE_LOG) << "unable to load plugin" << info.library << "for plugin name" << name << "."; qCWarning(AKONADICORE_LOG) << "Error was:\"" << loader->errorString() << "\"."; return 0; } return object; }
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()); } }