Beispiel #1
0
void GagImageDownloader::start()
{
    // if there is still downloads ongoing when start() is called
    // there will be big problem since m_gagList will be replaced
    Q_ASSERT(m_replyHash.isEmpty());
    foreach (const GagObject &gag, m_gagList) {
        if (gag.imageUrl().isEmpty() && gag.gifImageUrl().isEmpty())
            continue;

        if (m_downloadGIF && !gag.isGIF()) {
            qWarning("GagImageDownloader::start(): Not GIF, skip");
            continue;
        }
        const QUrl downloadImageUrl = m_downloadGIF ? gag.gifImageUrl() : gag.imageUrl();

        QNetworkReply *reply = m_networkManager->createGetRequest(downloadImageUrl, NetworkManager::Image);
        // make sure the QNetworkReply will be destroy when this object is destroyed
        reply->setParent(this);
        m_replyHash.insert(reply, gag);
        connect(reply, SIGNAL(finished()), SLOT(onFinished()));
    }

    m_imagesTotal = m_replyHash.count();
    if (m_imagesTotal > 1) {
        emit downloadProgress(0, m_imagesTotal);
    } else if (m_imagesTotal == 1) {
        connect(m_replyHash.keys().first(), SIGNAL(downloadProgress(qint64, qint64)),
                this, SIGNAL(downloadProgress(qint64,qint64)));
    } else {
        emit finished();
    }
}
QGeoCodeReply *QGeoCodingManagerEngineQGC::reverseGeocode(const QGeoCoordinate &coordinate, const QGeoShape &bounds)
{
    Q_UNUSED(bounds)

    QNetworkRequest request;
    request.setRawHeader("User-Agent", m_userAgent);

    QUrl url(QStringLiteral("http://maps.googleapis.com/maps/api/geocode/json"));
    QUrlQuery query;
    query.addQueryItem(QStringLiteral("sensor"), QStringLiteral("false"));
    query.addQueryItem(QStringLiteral("language"), locale().name().left(2));
    query.addQueryItem(QStringLiteral("latlng"), QStringLiteral("%1,%2")
                       .arg(coordinate.latitude())
                       .arg(coordinate.longitude()));

    url.setQuery(query);
    request.setUrl(url);
    //qDebug() << url;

    QNetworkReply *reply = m_networkManager->get(request);
    reply->setParent(0);

    QGeoCodeReplyQGC *geocodeReply = new QGeoCodeReplyQGC(reply);

    connect(geocodeReply, SIGNAL(finished()), this, SLOT(replyFinished()));
    connect(geocodeReply, SIGNAL(error(QGeoCodeReply::Error,QString)),
            this, SLOT(replyError(QGeoCodeReply::Error,QString)));

    return geocodeReply;
}
QGeoCodeReply *QGeoCodingManagerEngineQGC::geocode(const QString &address, int limit, int offset, const QGeoShape &bounds)
{
    Q_UNUSED(limit);
    Q_UNUSED(offset);

    QNetworkRequest request;
    request.setRawHeader("User-Agent", m_userAgent);

    QUrl url(QStringLiteral("http://maps.googleapis.com/maps/api/geocode/json"));
    QUrlQuery query;
    query.addQueryItem(QStringLiteral("sensor"), QStringLiteral("false"));
    query.addQueryItem(QStringLiteral("language"), locale().name().left(2));
    query.addQueryItem(QStringLiteral("address"), address);
    if (bounds.type() == QGeoShape::RectangleType) {
        query.addQueryItem(QStringLiteral("bounds"), boundingBoxToLtrb(bounds));
    }

    url.setQuery(query);
    request.setUrl(url);
    //qDebug() << url;

    QNetworkReply *reply = m_networkManager->get(request);
    reply->setParent(0);

    QGeoCodeReplyQGC *geocodeReply = new QGeoCodeReplyQGC(reply);

    connect(geocodeReply, SIGNAL(finished()), this, SLOT(replyFinished()));
    connect(geocodeReply, SIGNAL(error(QGeoCodeReply::Error,QString)),
            this, SLOT(replyError(QGeoCodeReply::Error,QString)));

    return geocodeReply;
}
void CommandDownloadFile::reexecuteQuery()
{
    Q_D(CommandDownloadFile);
    QNetworkRequest request( d->downloadUrl );
    setRequestAccessToken(request, session()->accessToken());
    QNetworkReply* reply = session()->networkManager()->get(request);
    reply->setReadBufferSize(d->bufferSize);
    connect(reply, SIGNAL(finished()), SLOT(requestFinished()));
    connect(reply, SIGNAL(readyRead()), SLOT(readyRead()));
    connect(reply, SIGNAL(downloadProgress(qint64,qint64)), SIGNAL(progress(qint64,qint64)));
    reply->setParent(this);
}
Beispiel #5
0
QNetworkReply* QNetworkReplyWrapper::release()
{
    if (!m_reply)
        return 0;

    resetConnections();
    QNetworkReply* reply = m_reply;
    m_reply = 0;
    m_sniffer = nullptr;

    reply->setParent(0);
    return reply;
}
void SearchEnginesManager::addEngine(const QUrl &url)
{
    ENSURE_LOADED;

    if (!url.isValid()) {
        return;
    }

    qApp->setOverrideCursor(Qt::WaitCursor);

    QNetworkReply* reply = mApp->networkManager()->get(QNetworkRequest(url));
    reply->setParent(this);
    connect(reply, SIGNAL(finished()), this, SLOT(replyFinished()));
}
void ChatService::startLoginRequest()
{
    _buddylist_poll_timer->stop();
    
    qDebug() << _network->cookieJar()->cookiesForUrl(QUrl(FACEBOOK_URL)).count() << " cookies";
    QList<QNetworkCookie> cookies;
    
    QMap<QString, QString> params;
    QUrl url(FACEBOOK_LOGIN_URL);

    QNetworkCookie cookie;
    cookie.setDomain(".facebook.com");
    cookie.setPath("/");

    // facebook uses this cookie to test for cookie support
    // if we dont set it it thinks we don't support cookies.
    cookie.setName("test_cookie");
    cookie.setValue("1");
    cookies << cookie;

    cookie.setName("isfbe");
    cookie.setValue("false");
    cookies << cookie;

    _network->cookieJar()->setCookiesFromUrl(cookies, QUrl(FACEBOOK_URL));

    qDebug() << _network->cookieJar()->cookiesForUrl(QUrl(FACEBOOK_URL)).count() << " cookies";

    // it seems those are not really needed, until I figure what
    // are they for
    //params.insert("md5pass", "0");
    //params.insert("noerror", "1");

    params.insert("email", _login);
    params.insert("pass", _password);
    params.insert("persistent", "1");
    params.insert("login", "Login");
    params.insert("charset_test", "€,´,€,´,水,Д,Є");

    QString data = encodePostParams(params);
    qDebug() << data;

    QNetworkReply *reply = _network->post(QNetworkRequest(url), data.toAscii());
    reply->setParent(this);
    
    QObject::connect(reply, SIGNAL(finished()), this, SLOT(slotLoginRequestFinished()));
    QObject::connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotLoginRequestError(QNetworkReply::NetworkError)));
}
void CommandFileList::reexecuteQuery()
{
    Q_D(CommandFileList);

    QUrl url("https://www.googleapis.com/drive/v2/files");
    if (!d->query.isEmpty())
        url.addQueryItem("q", d->query);
    if (!d->fields.isEmpty())
        url.addQueryItem("fields", d->fields);
    //url.addQueryItem("maxResults","100");

    QNetworkRequest request(url);
    setRequestAccessToken(request, session()->accessToken());

    QNetworkReply* reply = session()->networkManager()->get(request);
    connect(reply, SIGNAL(finished()), this, SLOT(queryFinished()));
    reply->setParent(this);
}
void CommandSetFileProperties::reexecuteQuery()
{
    Q_D(CommandSetFileProperties);


    QString urlStr("https://www.googleapis.com/drive/v2/files");

    if (!d->fileInfo.id().isEmpty())
        urlStr += QString("/%1/properties").arg(d->fileInfo.id());
    QUrl url(urlStr);
    QNetworkRequest request(url);
    setRequestAccessToken(request, session()->accessToken());

    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json; charset=UTF-8");

    Q_FOREACH (const QString& key,d->fields.keys()) {
        currentKey=key;
        QVariantMap fileInfoMap;
        fileInfoMap.insert(KEY_STRING,key);
        fileInfoMap.insert(VALUE_STRING,d->fields[key]);
        fileInfoMap.insert(VISIBILITY_STRING,"PUBLIC");
        QByteArray body = QJson::Serializer().serialize(fileInfoMap);

        QNetworkReply* reply = session()->networkManager()->post(request, body);


        connect(reply, SIGNAL(finished()), this, SLOT(queryFinished()));


        connect(reply,SIGNAL(error(QNetworkReply::NetworkError)),SLOT(queryFailed(QNetworkReply::NetworkError)));

        reply->setParent(this);
    }




}