/** * Called when the webview finished loading a new page */ void PhoneGap::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 ); // Get a reference to the current main-frame QWebFrame *webFrame = m_webView->page()->mainFrame(); // 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(); QString objectName = attribName + "_native"; qDebug() << "Adding Plugin " << attribName << " with " << attribValue; // Check for such a plugin PGPlugin *currPlugin = PluginRegistry::getRegistry()->getPlugin( attribValue ); if( currPlugin != NULL ) { currPlugin->setWebFrame( webFrame ); webFrame->addToJavaScriptWindowObject( objectName, currPlugin ); webFrame->evaluateJavaScript( "PhoneGap.Qt.registerObject( '" + attribValue + "', " + objectName + " )" ); webFrame->evaluateJavaScript( "PhoneGap.enablePlugin( '" + attribValue + "' )" ); } else { qDebug() << "Unknown Plugin " << attribName; } } } } } // Device is now ready to rumble webFrame->evaluateJavaScript( "PhoneGap.deviceready();" ); }
/** * 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();" ); }