void Cordova::initPlugins() { QList<QDir> searchPath = {get_app_dir()}; _plugins.clear(); for (QDir pluginsDir: searchPath) { for (const QString &fileName: pluginsDir.entryList(QDir::Files)) { QString path = pluginsDir.absoluteFilePath(fileName); qDebug() << "Testing" << path; if (!QLibrary::isLibrary(path)) continue; CordovaGetPluginInstances loader = (CordovaGetPluginInstances) QLibrary::resolve(path, "cordovaGetPluginInstances"); if (!loader) { qCritical() << "Missing cordovaGetPluginInstances symbol in" << path; continue; } auto plugins = (*loader)(this); for (QSharedPointer<CPlugin> plugin: plugins) { qDebug() << "Enable plugin" << plugin->fullName(); emit pluginWantsToBeAdded(plugin->fullName(), plugin.data(), plugin->shortName()); } _plugins += plugins; } } }
/** * Called when the webview finished loading a new page */ void Cordova::loadFinished( bool ok ) { Q_UNUSED(ok) // Change into the xml-directory QDir xmlDir( m_workingDir ); xmlDir.cd( "xml" ); // Try to open the plugins configuration QFile pluginsXml( xmlDir.filePath("plugins.xml") ); if( !pluginsXml.open( QIODevice::ReadOnly | QIODevice::Text ) ) { qDebug() << "Error loading plugins config!"; return; } // Start reading the file as a stream QXmlStreamReader plugins; plugins.setDevice( &pluginsXml ); // Iterate over plugins-configuration and load all according plugins while(!plugins.atEnd()) { if( plugins.readNext() == QXmlStreamReader::StartElement ) { // Check if we have a plugin element if( plugins.name() == "plugin" ) { QXmlStreamAttributes attribs = plugins.attributes(); // Check for name & value attributes if( attribs.hasAttribute("name") && attribs.hasAttribute("value") ) { // Construct object & attribute names QString attribName = attribs.value( "name" ).toString(); QString attribValue = attribs.value( "value" ).toString(); qDebug() << "Adding Plugin " << attribName << " with " << attribValue; // Check for such a plugin CPlugin *currPlugin = PluginRegistry::getRegistry()->getPlugin( attribValue ); if(currPlugin) { currPlugin->init(); emit pluginWantsToBeAdded(attribValue, currPlugin, attribName); execJS( "Cordova.enablePlugin( '" + attribValue + "' )" ); } else { qDebug() << "Unknown Plugin " << attribName; } } } } } // Device is now ready to rumble execJS( "Cordova.deviceready();" ); }