QGeoMappingManagerEngineGoogle::QGeoMappingManagerEngineGoogle(const QMap<QString, QVariant> ¶meters, QGeoServiceProvider::Error *error, QString *errorString) : QGeoTiledMappingManagerEngine(parameters), m_parameters(parameters), m_nam(NULL) { QNetworkDiskCache *cache = NULL; Q_UNUSED(error) Q_UNUSED(errorString) setTileSize(QSize(256, 256)); setMinimumZoomLevel(0.0); setMaximumZoomLevel(17.0); QList<QGraphicsGeoMap::MapType> types; types << QGraphicsGeoMap::StreetMap; types << QGraphicsGeoMap::SatelliteMapDay; setSupportedMapTypes(types); QList<QGraphicsGeoMap::ConnectivityMode> modes; modes << QGraphicsGeoMap::OnlineMode; setSupportedConnectivityModes(modes); QList<QString> keys = m_parameters.keys(); if (keys.contains("mapping.networkaccessmanager")) { QNetworkAccessManager *nam; nam = (QNetworkAccessManager *)m_parameters .value("mapping.networkaccessmanager").value<void *>(); if (nam) m_nam = nam; } if (!m_nam) { m_nam = new QNetworkAccessManager(this); cache = new QNetworkDiskCache(this); } if (cache) { QDir dir = QDir::temp(); dir.mkdir("maptiles-google"); dir.cd("maptiles-google"); cache->setCacheDirectory(dir.path()); } if (keys.contains("mapping.proxy")) { QString proxy = m_parameters.value("mapping.proxy").toString(); if (!proxy.isEmpty()) m_nam->setProxy(parseProxy(proxy)); } if (cache && keys.contains("mapping.cache.directory")) { QString cacheDir = m_parameters.value("mapping.cache.directory").toString(); if (!cacheDir.isEmpty()) cache->setCacheDirectory(cacheDir); } if (cache && keys.contains("mapping.cache.size")) { bool ok = false; qint64 cacheSize = m_parameters.value("mapping.cache.size").toString().toLongLong(&ok); if (ok) cache->setMaximumCacheSize(cacheSize); } if (cache) m_nam->setCache(cache); }
bool HttpClient::downloadFile( QString &urlIn, QString &destinationIn ) { // qDebug() << "HttpClient::downloadFile: url=" << urlIn << ", dest=" << destinationIn; if( downloadRunning == true ) { qWarning( "HttpClient(%d): download is running!", __LINE__ ); return false; } _url = urlIn; _destination = destinationIn; QUrl url( urlIn ); QFileInfo fileInfo( destinationIn ); if( urlIn.isEmpty() || ! url.isValid() || fileInfo.fileName().isEmpty() ) { qWarning( "HttpClient(%d): Url or destination file are invalid!", __LINE__ ); return false; } tmpFile = new QFile( destinationIn + "." + QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss") ); if( ! tmpFile->open( QIODevice::WriteOnly ) ) { qWarning( "HttpClient(%d): Unable to open the file %s: %s", __LINE__, tmpFile->fileName ().toLatin1().data(), tmpFile->errorString().toLatin1().data() ); delete tmpFile; tmpFile = static_cast<QFile *> (0); return false; } // Check, if a proxy is defined in the configuration data. If true, we do use it. extern QSettings _settings; QString proxy = _settings.value( "/Internet/Proxy", "" ).toString(); if( proxy.isEmpty() ) { // Check the user's environment, if a proxy is defined there. char* proxyFromEnv = getenv("http_proxy"); if( proxyFromEnv == 0 ) { proxyFromEnv = getenv("HTTP_PROXY"); } if( proxyFromEnv ) { QString qProxy( proxyFromEnv ); // remove an existing http prefix proxy = qProxy.remove("http://"); } } if( ! proxy.isEmpty() ) { QString hostName; quint16 port; if( parseProxy( proxy, hostName, port ) == true ) { QNetworkProxy proxy; proxy.setType( QNetworkProxy::HttpProxy ); proxy.setHostName( hostName ); proxy.setPort( port ); manager->setProxy( proxy ); } } QNetworkRequest request; QString appl = QCoreApplication::applicationName() + "/" + QCoreApplication::applicationVersion() + " (Qt" + QT_VERSION_STR + "/X11)"; request.setUrl( QUrl( _url, QUrl::TolerantMode )); request.setRawHeader( "User-Agent", appl.toLatin1() ); reply = manager->get(request); if( ! reply ) { qWarning( "HttpClient(%d): Reply object is invalid!", __LINE__ ); return false; } reply->setReadBufferSize(0); connect( reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()) ); connect( reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError)) ); connect( reply, SIGNAL(finished()), this, SLOT(slotFinished()) ); connect( reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(slotDownloadProgress( qint64, qint64 )) ); downloadRunning = true; if ( _progressDialog != static_cast<QProgressDialog *> (0) ) { _progressDialog->setWindowTitle( tr( "HTTP" ) ); _progressDialog->setLabelText( tr( "Downloading %1" ).arg( fileInfo.fileName() ) ); _progressDialog->show(); } timer->start(); return true; }