Exemplo n.º 1
0
/**
 * It is called each time a new chunk of data is received.
 * @param conn The Connection that ran the operation.
 * @param result The number of bytes read on success,
 * or a \link #CONNERR_GENERIC CONNERR \endlink code \< 0 on failure.
 */
void MediaWiki::connRecvFinished(MAUtil::Connection * conn, int result)
{
    if(result >= 0) {
		// Notify the UI that a new chunk was received
		mHomeScreen->engineChunkReceived();

		// Parse each chunk.
		// mBuffer now contains the result,we can now parse it.
		processSearchResults();
		// Read next chunk of data.
        mHttp.recv(mBuffer, CONNECTION_BUFFER_SIZE);

        return;
    }
    else if(result == CONNERR_CLOSED) {
        // The result is parsed, now display it( if there is any).
		if ( mWiki->titleResults.size() > 0 ){
			mHomeScreen->engineFinished();
		}
		else{
			// No results available,display some message.
			mHomeScreen->engineError(ERROR_NO_RESULTS);
		}
    } else {
		// Notify the UI of the error.
        mHomeScreen->engineError(ERROR_INVALID_DATA+integerToString(result, 10));
    }
    mHttp.close();
    mIsConnected = false;

}
Exemplo n.º 2
0
void Fetcher::downloadFinished(QNetworkReply* reply)
{
//    qDebug() << "Reply Received" << reply->url();
    if (reply->error() == QNetworkReply::NoError)
    {
        QUrl redirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
        if (redirectUrl == reply->url())
        {
            showErrorMessage("Redirected to the original url. Aborting to avoid infinite loop.", this, QMessageBox::Critical);
            return;
        }

        if(!redirectUrl.isEmpty())
        {
            qDebug() << "Redirect to" << redirectUrl;
            downloadUrl(redirectUrl);
            return;
        }
        processSearchResults(reply);
    }
    else
    {
        qDebug() << "Error:" << reply->errorString();
        showErrorMessage("Error:" + reply->errorString(), this, QMessageBox::Critical);
    }
    reply->deleteLater();
}
Exemplo n.º 3
0
void QUHttpCollector::processNetworkOperationDone(bool error) {
	int count = localFiles().size();
	closeLocalFiles();

	if(error) {
		setState(Idle);
		communicator()->send(http()->errorString());
		communicator()->send(QUCommunicatorInterface::Failed);
		return;
	}

	if(state() == SearchRequest) {
		ignoredUrls = 0;
		processSearchResults();
	} else if(state() == ImageRequest)
		processImageResults(count);
}
Exemplo n.º 4
0
/**
 * It is called when the read is done.
 * @param conn The Connection that ran the operation.
 * @param result \> 0 on success,
 * or a \link #CONNERR_GENERIC CONNERR \endlink code \< 0 on failure.
 */
void MediaWiki::connReadFinished(MAUtil::Connection* conn, int result)
{
    if(result >= 0){
        // mBuffer now contains the result,we can now parse it.
		processSearchResults();
		if ( mWiki->titleResults.size() > 0 )
		{
			// The result is parsed, now display it.
			mHomeScreen->engineFinished();
		}
		else{
			// The results vector is empty.
			mHomeScreen->engineError(ERROR_NO_RESULTS);
		}
	}
	else{
		// Notify UI on the error.
		mHomeScreen->engineError(ERROR_INVALID_DATA+integerToString(result,10));
	}

	mHttp.close();

	mIsConnected = false;
}