Exemplo n.º 1
0
void UrlFactory::TryCorrectGoogleVersions()
{
    static bool versionRetrieved = false;

    if (versionRetrieved)
    {
        return;
    }
    QMutexLocker locker(&mutex);
    if(CorrectGoogleVersions && !IsCorrectGoogleVersions())
    {
        QNetworkReply *reply;
        QNetworkRequest qheader;
        QNetworkAccessManager network;
        QEventLoop q;
        QTimer tT;
        tT.setSingleShot(true);
        connect(&network, SIGNAL(finished(QNetworkReply*)),
                &q, SLOT(quit()));
        connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
        network.setProxy(Proxy);
#ifdef DEBUG_URLFACTORY
        qDebug()<<"Correct GoogleVersion";
#endif //DEBUG_URLFACTORY
        setIsCorrectGoogleVersions(true);
        QString url = "http://maps.google.com";

        qheader.setUrl(QUrl(url));
        qheader.setRawHeader("User-Agent",UserAgent);
        reply=network.get(qheader);
        tT.start(Timeout);
        q.exec();
        if(!tT.isActive())
            return;
        tT.stop();
        if( (reply->error()!=QNetworkReply::NoError))
        {
#ifdef DEBUG_URLFACTORY
            qDebug()<<"Try corrected version withou abort or error:"<<reply->errorString();
#endif //DEBUG_URLFACTORY
            return;
        }
        QString html=QString(reply->readAll());
        QRegExp reg("\"*http://mt0.google.com/vt/lyrs=m@(\\d*)",Qt::CaseInsensitive);
        if(reg.indexIn(html)!=-1)
        {
            QStringList gc=reg.capturedTexts();
            VersionGoogleMap = QString("m@%1").arg(gc[1]);
            VersionGoogleMapChina = VersionGoogleMap;

#ifdef DEBUG_URLFACTORY
            qDebug()<<"TryCorrectGoogleVersions, VersionGoogleMap: "<<VersionGoogleMap;
#endif //DEBUG_URLFACTORY
        }

        reg=QRegExp("\"*http://mt0.google.com/vt/lyrs=h@(\\d*)",Qt::CaseInsensitive);
        if(reg.indexIn(html)!=-1)
        {
            QStringList gc=reg.capturedTexts();
            VersionGoogleLabels = QString("h@%1").arg(gc[1]);
            VersionGoogleLabelsChina = VersionGoogleLabels;
#ifdef DEBUG_URLFACTORY
            qDebug()<<"TryCorrectGoogleVersions, VersionGoogleLabels: "<<VersionGoogleLabels;
#endif //DEBUG_URLFACTORY
        }
        reg=QRegExp("\"*http://khm\\D?\\d.google.com/kh/v=(\\d*)",Qt::CaseInsensitive);
        if(reg.indexIn(html)!=-1)
        {
            QStringList gc=reg.capturedTexts();
            VersionGoogleSatellite = gc[1];
            VersionGoogleSatelliteKorea = VersionGoogleSatellite;
            VersionGoogleSatelliteChina = "s@" + VersionGoogleSatellite;
            qDebug()<<"TryCorrectGoogleVersions, VersionGoogleSatellite: "<<VersionGoogleSatellite;

        }
        reg=QRegExp("\"*http://mt0.google.com/vt/lyrs=t@(\\d*),r@(\\d*)",Qt::CaseInsensitive);
        if(reg.indexIn(html)!=-1)
        {
            QStringList gc=reg.capturedTexts();
            VersionGoogleTerrain = QString("t@%1,r@%2").arg(gc[1]).arg(gc[2]);
            VersionGoogleTerrainChina = VersionGoogleTerrain;
#ifdef DEBUG_URLFACTORY
            qDebug()<<"TryCorrectGoogleVersions, VersionGoogleTerrain: "<<VersionGoogleTerrain;
#endif //DEBUG_URLFACTORY
        }
        reply->deleteLater();

    }
Exemplo n.º 2
0
void UrlFactory::TryCorrectGoogleVersions()
{
    static bool versionRetrieved = false;

    if (versionRetrieved) {
        return;
    }
    QMutexLocker locker(&mutex);


    if (CorrectGoogleVersions && !IsCorrectGoogleVersions()) {
        QNetworkReply *reply;
        QNetworkRequest qheader;
        // This SSL Hack is half assed... technically bad *security* joojoo.
        // Required due to a QT5 bug on linux and Mac
        //
        QSslConfiguration conf = qheader.sslConfiguration();
        conf.setPeerVerifyMode(QSslSocket::VerifyNone);
        qheader.setSslConfiguration(conf);
        QNetworkAccessManager network;
        QEventLoop q;
        QTimer tT;
        tT.setSingleShot(true);
        connect(&network, SIGNAL(finished(QNetworkReply *)),
                &q, SLOT(quit()));
        connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
        network.setProxy(Proxy);
#ifdef DEBUG_URLFACTORY
        qDebug() << "Correct GoogleVersion";
#endif // DEBUG_URLFACTORY
       // setIsCorrectGoogleVersions(true);
       // QString url = "https://www.google.com/maps/@0,-0,7z?dg=dbrw&newdg=1";
       // We need to switch to the Above url... the /lochp method will be depreciated soon
       // https://productforums.google.com/forum/#!category-topic/maps/navigation/k6EFrp7J7Jk
        QString url = "http://www.google.com/lochp";

        qheader.setUrl(QUrl(url));
        qheader.setRawHeader("User-Agent", UserAgent);
        reply = network.get(qheader);
        tT.start(Timeout);
        q.exec();
        if (!tT.isActive()) {
            return;
        }
        tT.stop();
        if ((reply->error() != QNetworkReply::NoError)) {
#ifdef DEBUG_URLFACTORY
            qDebug() << "Try corrected version withou abort or error:" << reply->errorString();
#endif // DEBUG_URLFACTORY
            return;
        }

        QString html = QString(reply->readAll());
#ifdef DEBUG_URLFACTORY
        qDebug() << html;
#endif // DEBUG_URLFACTORY

        QRegExp reg("\"*http://mts0.google.com/vt/lyrs=m@(\\d*)", Qt::CaseInsensitive);
        if (reg.indexIn(html) != -1) {
            QStringList gc = reg.capturedTexts();
            VersionGoogleMap = QString("m@%1").arg(gc[1]);
            VersionGoogleMapChina = VersionGoogleMap;
            VersionGoogleMapKorea = VersionGoogleMap;
#ifdef DEBUG_URLFACTORY
            qDebug() << "TryCorrectGoogleVersions, VersionGoogleMap: " << VersionGoogleMap;
#endif // DEBUG_URLFACTORY
        }

        reg = QRegExp("\"*http://mts0.google.com/vt/lyrs=h@(\\d*)", Qt::CaseInsensitive);
        if (reg.indexIn(html) != -1) {
            QStringList gc = reg.capturedTexts();
            VersionGoogleLabels = QString("h@%1").arg(gc[1]);
            VersionGoogleLabelsChina = VersionGoogleLabels;
            VersionGoogleLabelsKorea = VersionGoogleLabels;
#ifdef DEBUG_URLFACTORY
            qDebug() << "TryCorrectGoogleVersions, VersionGoogleLabels: " << VersionGoogleLabels;
#endif // DEBUG_URLFACTORY
        }

        reg = QRegExp("\"*http://khms0.google.com/kh/v=(\\d*)", Qt::CaseInsensitive);
        if (reg.indexIn(html) != -1) {
            QStringList gc = reg.capturedTexts();
            VersionGoogleSatellite = gc[1];
            VersionGoogleSatelliteKorea = VersionGoogleSatellite;
            VersionGoogleSatelliteChina = "s@" + VersionGoogleSatellite;

#ifdef DEBUG_URLFACTORY
            qDebug() << "TryCorrectGoogleVersions, VersionGoogleSatellite: " << VersionGoogleSatellite;
#endif // DEBUG_URLFACTORY
        }

        reg = QRegExp("\"*http://mts0.google.com/vt/lyrs=t@(\\d*),r@(\\d*)", Qt::CaseInsensitive);
        if (reg.indexIn(html) != -1) {
            QStringList gc = reg.capturedTexts();
            VersionGoogleTerrain = QString("t@%1,r@%2").arg(gc[1]).arg(gc[2]);
            VersionGoogleTerrainChina = VersionGoogleTerrain;
            VersionGoogleTerrainChina = VersionGoogleTerrain;
#ifdef DEBUG_URLFACTORY
            qDebug() << "TryCorrectGoogleVersions, VersionGoogleTerrain: " << VersionGoogleTerrain;
#endif // DEBUG_URLFACTORY
        }
        reply->deleteLater();
        versionRetrieved = true;
    }