void PAAlternativeLauncher::manifestReadyRead()
{
	QNetworkReply *reply = dynamic_cast<QNetworkReply *>(sender());
	if(reply)
	{
		if(reply->error() == QNetworkReply::NoError)
		{
			qint64 bytes_available = reply->bytesAvailable();
			QByteArray input = reply->read(bytes_available);
			Q_ASSERT(input.size() == bytes_available);
			mZstream.next_in = (Bytef *)input.constData();
			mZstream.avail_in = bytes_available;

			uInt old_avail_out = mZstream.avail_out;
			int res = inflate(&mZstream, Z_SYNC_FLUSH);
			if(res != Z_OK && res != Z_STREAM_END)
			{
				reply->abort();
				info.warning("ZLib", mZstream.msg, false);
				return;
			}

			mManifestJson.write((const char *)mBuffer, old_avail_out - mZstream.avail_out);
			mZstream.avail_out = mBufferSize;
			mZstream.next_out = mBuffer;
			Q_ASSERT(mZstream.avail_in == 0);
		}
		else
		{
			reply->abort();
			info.critical(tr("Manifest"), tr("Error while getting manifest (1).\n%1").arg(reply->errorString()));
		}
	}
}
QByteArray QNetworkReplyProto::read(qint64 maxSize)
{
  QNetworkReply *item = qscriptvalue_cast<QNetworkReply*>(thisObject());
  if (item)
    return item->read(maxSize);
  return QByteArray();
}
qint64 QNetworkReplyProto::read(char * data, qint64 maxSize)
{
  QNetworkReply *item = qscriptvalue_cast<QNetworkReply*>(thisObject());
  if (item)
    return item->read(data, maxSize);
  return 0;
}
/*
 * TwitterRequest::onTimelineReply()
 *
 * Callback handler for QNetworkReply finished() signal
 */
void TwitterRequest::onTimelineReply()
{
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
    QString response;
    bool success = false;
    if (reply)
    {
        if (reply->error() == QNetworkReply::NoError)
        {
            int available = reply->bytesAvailable();
            if (available > 0)
            {
                int bufSize = sizeof(char) * available + sizeof(char);
                QByteArray buffer(bufSize, 0);
                int read = reply->read(buffer.data(), available);
                response = QString::fromUtf8(buffer);
                success = true;
            }
        }
        else
        {
            response =  QString("Error: ") + reply->errorString() + QString(" status:") + reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString();
            qDebug() << response;
        }
        reply->deleteLater();
    }
    if (response.trimmed().isEmpty())
    {
        response = "Twitter request failed. Check internet connection";
        qDebug() << response;
    }
    emit complete(response, success);
}
    void onQNetworkReplyReadyRead() {
        DEBUG("onQNetworkReplyReadyRead()");
        bool firstRead = invocationStatus != Invocation::RESPONSE_RECEIVED;
        invocationStatus = Invocation::RESPONSE_RECEIVED;

        QVariant statusCode = qreply->attribute( QNetworkRequest::HttpStatusCodeAttribute );
        if (statusCode.isValid())
        {
            httpStatus = HTTPInvocationDefinition::resolveHttpStatus(statusCode.toInt());
        } else {
            // TODO: what to do, when no code?
            invocationStatus = Invocation::ERROR;
            result << InvocationErrors::INVOCATION_FAILED
                   << Result::reasonFromDesc("Http status code not valid");
            return;
        }

        if (httpStatus != HTTPInvocationDefinition::OK_200) {
            invocationStatus = Invocation::ERROR;
            result << InvocationErrors::INVOCATION_FAILED
                   << Result::reasonFromDesc("Http error response code (not 200)")
                   << Result::Meta("http_code", statusCode.toString());

            // nothing to save to file
            DEBUG("Error no data to save to file");
            return;
        }

        // is target open?
        if (!outputFile.isOpen()) {
            if (!outputFile.open(QIODevice::WriteOnly)) {
                q->abort();
                result << InvocationErrors::INVOCATION_INVALID
                       << Result::reasonFromDesc("Open output file failed")
                       << Result::Meta("file_path", outputFilePath);

                invocationStatus = Invocation::INVALID_INVOCATION;
                emit q->finishedError(q);
                return;
            }
        }

        if (firstRead)
            emit q->downloadStarted(q);

        QVariant contentLength = qreply->header(QNetworkRequest::ContentLengthHeader);
        qint64 bytesTotal = contentLength.isValid() ? contentLength.toInt() : -1;

        int readBytes = 0;
        while ( (readBytes = qreply->read(readBuffer, READ_BUFFER_SIZE) ) > 0) {
            totalReadBytes += readBytes;
            outputFile.write(readBuffer, readBytes);
            onQNetworkReplyDownloadProgress(totalReadBytes, bytesTotal);
        }

    }
void CommandDownloadFile::readyRead()
{
    Q_D(CommandDownloadFile);

    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
    Q_ASSERT(reply);
    if (!reply)
        return;

    qint64 sz = reply->bytesAvailable();
    QByteArray ba = reply->read(sz);

    QIODevice* out = d->out;
    out->write(ba);
}
Example #7
0
// creates a total download progress for multiple QNetworkReplies
void SettingsDialog::downloadProgress(qint64 received, qint64 total)
{
    // Don't show progress for non-docset pages
    if (total == -1 || received < 10240)
        return;

    QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
    if (!reply || !reply->isOpen())
        return;

    if (reply->property(DownloadTypeProperty).toInt() == DownloadDocset)  {
        const QString docsetName = reply->property(DocsetNameProperty).toString();

        QTemporaryFile *tmpFile = m_tmpFiles[docsetName];
        if (!tmpFile) {
            tmpFile = new QTemporaryFile(this);
            tmpFile->open();
            m_tmpFiles.insert(docsetName, tmpFile);
        }

        tmpFile->write(reply->read(received));
    }

    // Try to get the item associated to the request
    QListWidgetItem *item
            = ui->availableDocsetList->item(reply->property(ListItemIndexProperty).toInt());
    if (item)
        item->setData(ProgressItemDelegate::ValueRole, percent(received, total));

    qint64 previousReceived = 0;
    const QVariant previousReceivedVariant = reply->property(DownloadPreviousReceived);
    if (!previousReceivedVariant.isValid())
        m_combinedTotal += total;
    else
        previousReceived = previousReceivedVariant.toLongLong();

    m_combinedReceived += received - previousReceived;
    reply->setProperty(DownloadPreviousReceived, received);

    displayProgress();
}
QByteArray MarketSession::executeRawHttpsQuery(const QByteArray &request)
{
    QByteArray data;
    QUrl url("https://android.clients.google.com/market/api/ApiRequest");
    QNetworkAccessManager manager;
    QNetworkRequest req;
    req.setUrl(url);
    req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
    req.setRawHeader("Cookie",QString("ANDROIDSECURE=%1").arg(authSubToken).toUtf8());
    req.setRawHeader("User-Agent", "Android-Market/2 (sapphire PLAT-RC33); gzip");
    req.setRawHeader("Accept-Charset","ISO-8859-1,utf-8;q=0.7,*;q=0.7");

    QString requestData=QString("version=%1&request=%2")
            .arg(PROTOCOL_VERSION).arg(QString(request.toBase64()));
    QNetworkReply* http = manager.post(req,requestData.toUtf8());
    QEventLoop eventLoop;
    connect(http,SIGNAL(finished()),&eventLoop, SLOT(quit()));
    eventLoop.exec();
    data=gzipDecompress(http->read(http->header(QNetworkRequest::ContentLengthHeader).toUInt()));
    delete http;
    return data;
}
void Check_for_updates::replyFinished()
{
  long long int n;

  char buf[128];

  int this_version,
      latest_version;

  QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());

  if(reply->error() != QNetworkReply::NoError)
  {
    reply->deleteLater();

    return;
  }

  if(reply->bytesAvailable() < 31)
  {
    reply->deleteLater();

    return;
  }

  n = reply->read(buf, 100);

  if(n < 31)
  {
    reply->deleteLater();

    return;
  }

  reply->deleteLater();

  buf[30] = 0;

  if(strncmp(buf, "EDFbrowser latest version: ", 27))
  {
    return;
  }

  if(is_integer_number(buf + 27))
  {
    return;
  }

  latest_version = atoi(buf + 27);

  if((latest_version < 1) || (latest_version > 1000000))
  {
    return;
  }

  sprintf(buf, PROGRAM_VERSION);

  buf[1] = buf[0];

  this_version = atoi(buf + 1);

  if(this_version >= latest_version)
  {
    return;
  }

  QMessageBox messagewindow(QMessageBox::Information,
                            "New version available",
                            "A newer version of EDFbrowser is available.\n"
                            "Do you want to download the new version now?",
                            QMessageBox::Yes | QMessageBox::No);

  if(messagewindow.exec() != QMessageBox::Yes)
  {
    return;
  }

  QDesktopServices::openUrl(QUrl("http://www.teuniz.net/edfbrowser/"));
}
Example #10
0
void Twitter::onDataReceived()
{
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
    QString response;
    bool success = false;
    if (reply)
    {
        if (reply->error() == QNetworkReply::NoError)
        {
            int available = reply->bytesAvailable();
            if (available > 0)
            {
                int bufSize = sizeof(char) * available + sizeof(char);
                QByteArray buffer(bufSize, 0);
                reply->read(buffer.data(), available);
                response = QString(buffer);
                success = true;
            }
        }
        else
        {
            response =  QString("Error: ") + reply->errorString() + QString(" status:") + reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString();
            emit tweetParseComplete(false, "We can't connect to the internet");
        }
        reply->deleteLater();
    }
    if (success )
    {
    	if (response != "[]") {
    		bb::data::JsonDataAccess jda;
    		QVariant jsonva = jda.loadFromBuffer(response);
    		QVariantMap map = jsonva.toMap();
    		QVariantList results = map.value("results").toList();
    		//okay let's get the news items

    		int numTweets = 0;
    		foreach (QVariant v, results) {
    			QVariantMap map = v.toMap();

    			Tweet *tweet = new Tweet();
    			tweet->parse(v);

    			QVariant q = QVariant::fromValue(tweet);

        		_tweetList.append(q); //to go from a QVariant back to a Tweet* item: Tweet *Tweet = q.value<Tweet*>();

    			QVariantList path;
				path.append(_tweetList.indexOf(q));

				emit  itemAdded (path);
				numTweets++;
    		}

        	if (numTweets > 0) {
        		emit tweetParseComplete(true, "Parsed successfully");
        	} else {
        		if (_tweetList.count() == 0) {
        			emit tweetParseComplete(false, "No Tweets yet");
        		}
        	}
    	}