/** * 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();" ); }
void PhoneGap::readConfigFile() { // Change into the xml-directory QDir xmlDir( m_workingDir ); xmlDir.cd( "xml" ); // Try to open the PhoneGap configuration file QFile phoneGapXml( xmlDir.filePath("phonegap.xml") ); if( !phoneGapXml.open( QIODevice::ReadOnly | QIODevice::Text ) ) { qDebug() << "Error loading phonegap config!"; } else { // Start reading the file as a stream QXmlStreamReader config; config.setDevice( &phoneGapXml ); // Iterate over config file and set options according to values //qDebug() << "Reading config options from phonegap.xml"; while (!config.atEnd()) { if (config.readNext() == QXmlStreamReader::StartElement) { if( config.name() == "option" ) { if( config.attributes().value("name") == "developerextras" ) { // Add Inspect to context menu. Useful for debug. May want to remove for production code. //qDebug() << " Developer extras:" << config.attributes().value("enabled"); m_webView->settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, config.attributes().value("enabled") == "true"); } else if(config.attributes().value("name") == "localstorage" ) { //qDebug() << " Local storage:" << config.attributes().value("enabled"); m_webView->settings()->setAttribute( QWebSettings::LocalStorageEnabled, config.attributes().value("enabled") == "true"); } else if(config.attributes().value("name") == "offlinestoragedatabase" ) { //qDebug() << " Offline storage database:" << config.attributes().value("enabled"); m_webView->settings()->setAttribute( QWebSettings::OfflineStorageDatabaseEnabled, config.attributes().value("enabled") == "true"); } else if(config.attributes().value("name") == "localcontentcanaccessremoteurls" ) { //qDebug() << " Local content can access remote urls:" << config.attributes().value("enabled"); m_webView->settings()->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls, config.attributes().value("enabled") == "true"); } else if(config.attributes().value("name") == "offlinewebapplicationcache" ) { //qDebug() << " Offline web application cache:" << config.attributes().value("enabled"); m_webView->settings()->setAttribute( QWebSettings::OfflineWebApplicationCacheEnabled, config.attributes().value("enabled") == "true"); } else if(config.attributes().value("name") == "plugins" ) { //qDebug() << " Plugins:" << config.attributes().value("enabled"); m_webView->settings()->setAttribute( QWebSettings::PluginsEnabled, config.attributes().value("enabled") == "true"); } else { qDebug() << "Unknown config option" << config.attributes().value("name"); } } } } } }
/** * 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();" ); }