Ejemplo n.º 1
0
void MapView::tileDownloaded(QNetworkReply *reply)
{
    //recreate original request from reply and delete it from the current requests

    QElapsedTimer timer; timer.start();


    TileRequest finishedRequest(reply);
    currentRequests.removeAll(finishedRequest);

    //check to see if any requests are left in stack
    if (!requestStack.isEmpty())
    {
        //pop the last request in the stack
        TileRequest request = requestStack.takeLast();

        //proceed to download the request
        networkManager->get(request);
        currentRequests.append(request);
    }
    QByteArray *data = new QByteArray(reply->readAll());
    QByteArray *cpData = new QByteArray(*data);

    qDebug("curreq"+QString::number(currentRequests.size())+
           " reqstck"+QString::number(requestStack.size()));

    //check if actual data was returned
    if (data->length()!=0) //todo: check if data is valid
    {

        //AddTileToDBThread* t = new AddTileToDBThread(finishedRequest.z(),finishedRequest.x(),finishedRequest.y(),cpData,finishedRequest.mapSource().url);
        //t->start();

        //the method below also checks presence of tile in db
        addTileToDB(finishedRequest.z(),finishedRequest.x(),finishedRequest.y(),data,finishedRequest.mapSource().url);
        //qDebug(qPrintable("Tile image file size:" + QString::number(data.length()) + " bits"
        //                           "(x:"+QString::number(x)+" y:"+QString::number(y)+" z:"+QString::number(z)+")"));
    }
    else emit noNetwork();

    qDebug("adding tile to db took "+QString::number(timer.elapsed())); timer.restart();

    //check if zoomlevel and map source did not change while downloading
    if( currentZoom == finishedRequest.z() && finishedRequest.mapSource().url == MapSource.url)
        placeTile(data, finishedRequest.x(), finishedRequest.y(), finishedRequest.z());

    qDebug("placing tile took "+QString::number(timer.elapsed()));

    reply->deleteLater(); //do not 'delete reply;'
}
Ejemplo n.º 2
0
void
GTransport::finishedSlot(QNetworkReply *reply)
{
    FUNCTION_CALL_TRACE;

    QVariant statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);

    QVariant redirectionUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);

    iNetworkError = reply->error();

    if (iNetworkError != QNetworkReply::NoError)
    {
        emit error (iNetworkError);
    }

    emit finishedRequest();
}
int HttpCommunicator::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: finishedRequest(); break;
        case 1: finishedSlot((*reinterpret_cast< QNetworkReply*(*)>(_a[1]))); break;
        case 2: downloadProgress((*reinterpret_cast< qint64(*)>(_a[1])),(*reinterpret_cast< qint64(*)>(_a[2]))); break;
        case 3: uploadProgress((*reinterpret_cast< qint64(*)>(_a[1])),(*reinterpret_cast< qint64(*)>(_a[2]))); break;
        case 4: downloadReadyRead(); break;
        case 5: construct2(); break;
        default: ;
        }
        _id -= 6;
    }
    return _id;
}
bool
GContactClient::initTransport()
{
    FUNCTION_CALL_TRACE;

    LOG_DEBUG("Creating HTTP transport");

    mRemoteURI = iProfile.key(Buteo::KEY_REMOTE_DATABASE);
    if (mRemoteURI.isEmpty ())
    {
        // Set to the default value
        mRemoteURI = "https://www.google.com/m8/feeds/contacts/default/full/";
    }

    mTransport = new GTransport ();
    Q_CHECK_PTR (mTransport);

    connect (mTransport, SIGNAL (finishedRequest ()),
             this, SLOT (networkRequestFinished ()));

    connect (mTransport, SIGNAL (error (int)),
             this, SLOT (networkError (int)));

    LOG_DEBUG("Setting remote URI to" << mRemoteURI);
    mTransport->setUrl (mRemoteURI);

    QString proxyHost = iProfile.key(Buteo::KEY_HTTP_PROXY_HOST);
    // Set proxy, if available
    if (!proxyHost.isEmpty()) {

        QString proxyPort = iProfile.key(Buteo::KEY_HTTP_PROXY_PORT);

        mTransport->setProxy (proxyHost, proxyPort);

        LOG_DEBUG("Proxy host:" << proxyHost);
        LOG_DEBUG("Proxy port:" << proxyPort);
    } else {
        LOG_DEBUG("Not using proxy");
    }

    return true;
}
void
GContactClient::fetchRemoteContacts ()
{
    FUNCTION_CALL_TRACE;

    /**
     o Get last sync time
     o Get etag value from local file system (this is a soft etag)
     o Connect finishedRequest to parseResults & network error slots
     o Use mTransport to perform network fetch
    */
    QDateTime syncTime = lastSyncTime ();
    if (!syncTime.isNull ())
        mTransport->setUpdatedMin (syncTime);

    // FIXME: Fetching contacts using etag value as described in Google
    // data API does not seem to work
    // https://developers.google.com/gdata/docs/2.0/reference
    // The etag value has to be handled later

    QString token = authToken ();
    if (token.isNull () || token.isEmpty ())
    {
        LOG_CRITICAL ("Auth token is null");
        return;
    }
    LOG_DEBUG ("++ Auth token" << token);
    mTransport->setAuthToken (token);

    connect (mTransport, SIGNAL (finishedRequest ()),
             this, SLOT (networkRequestFinished ()));

    connect (mTransport, SIGNAL (error (QNetworkReply::NetworkError)),
             this, SLOT (networkError (QNetworkReply::NetworkError)));

    mTransport->request (GTransport::GET);
}