void JavaScriptEnclosureRequest::initEngine() {
    if (m_evaluated) {
        return;
    }
    
    if (!m_engine) {
        m_engine = new QScriptEngine(this);
    }

    QFile file(fileName());
    
    if (file.open(QFile::ReadOnly)) {
        const QScriptValue result = m_engine->evaluate(file.readAll(), fileName());
        file.close();
        
        if (result.isError()) {
            Logger::log("JavaScriptEnclosureRequest::initEngine(): Error evaluating JavaScript file: "
                        + result.toString());
            return;
        }
        
        Logger::log("JavaScriptEnclosureRequest::initEngine(): JavaScript file evaluated OK", Logger::MediumVerbosity);
        m_evaluated = true;
        m_global = new JavaScriptEnclosureRequestGlobalObject(m_engine);
        
        connect(m_global, SIGNAL(error(QString)), this, SLOT(onRequestError(QString)));
        connect(m_global, SIGNAL(finished(QVariantMap)), this, SLOT(onRequestFinished(QVariantMap)));
        
        m_engine->installTranslatorFunctions();
    }
    else {
        Logger::log("JavaScriptEnclosureRequest::initEngine(): Error reading JavaScript file: "
                    + file.errorString());
    }
}
Exemple #2
0
void O2Requestor::retry() {
    if (status_ != Requesting) {
        qWarning() << "O2Requestor::retry: No pending request";
        return;
    }
    timedReplies_.remove(reply_);
    reply_->disconnect(this);
    reply_->deleteLater();
    QUrl url = url_;
    /*
#if QT_VERSION < 0x050000
    url.addQueryItem(O2_OAUTH2_ACCESS_TOKEN, authenticator_->token());
#else
    QUrlQuery query(url);
    query.addQueryItem(O2_OAUTH2_ACCESS_TOKEN, authenticator_->token());
    url.setQuery(query);
#endif*/
    request_.setRawHeader(O2_HTTP_AUTHORIZATION_HEADER,("OAuth " + authenticator_->token().toLatin1()));
    request_.setUrl(url);
    status_ = ReRequesting;
    switch (operation_) {
    case QNetworkAccessManager::GetOperation:
        reply_ = manager_->get(request_);
        break;
    case QNetworkAccessManager::PostOperation:
        reply_ = manager_->post(request_, data_);
        break;
    default:
        reply_ = manager_->put(request_, data_);
    }
    timedReplies_.add(reply_);
    connect(reply_, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onRequestError(QNetworkReply::NetworkError)), Qt::QueuedConnection);
    connect(reply_, SIGNAL(finished()), this, SLOT(onRequestFinished()), Qt::QueuedConnection);
    connect(reply_, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(onUploadProgress(qint64,qint64)));
}
void ReadabilityArticle::tryLoad()
{
    if (!m_api) {
        m_error = "Cannot access article content (Invalid API Configuration)";
    }
    else if (!m_url.isValid()) {
        m_error = "Cannot access article content (Invalid URL)";
    }
    else {
        m_error.clear();
        if (m_request) {
            disconnect(m_request);
            m_request->disconnect(this);
            m_request->cancel();
            m_request->deleteLater();
        }

        m_request = m_api->getParseRequest(m_url);
        connect(m_request, SIGNAL(responseReady(QJsonObject)),
                this, SLOT(onResponseReceived(QJsonObject)));
        connect(m_request, SIGNAL(requestError(QNetworkReply::NetworkError,QString)),
                this, SLOT(onRequestError(QNetworkReply::NetworkError,QString)));
        m_request->send();
        emit startedLoading();
    }
    emit loadingChanged();
    emit errorChanged(m_error);
}
Exemple #4
0
void O2Requestor::retry()
{
    if (status_ != Requesting) {
        qCWarning(TOMBOYNOTESRESOURCE_LOG) << "O2Requestor::retry: No pending request";
        return;
    }
    timedReplies_.remove(reply_);
    reply_->disconnect(this);
    reply_->deleteLater();
    QUrl url = url_;
#if QT_VERSION < 0x050000
    url.addQueryItem(O2_OAUTH2_ACCESS_TOKEN, authenticator_->token());
#else
    QUrlQuery query(url);
    query.addQueryItem(O2_OAUTH2_ACCESS_TOKEN, authenticator_->token());
    url.setQuery(query);
#endif
    request_.setUrl(url);
    status_ = ReRequesting;
    switch (operation_) {
    case QNetworkAccessManager::GetOperation:
        reply_ = manager_->get(request_);
        break;
    case QNetworkAccessManager::PostOperation:
        reply_ = manager_->post(request_, data_);
        break;
    default:
        reply_ = manager_->put(request_, data_);
    }
    timedReplies_.add(reply_);
    connect(reply_, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onRequestError(QNetworkReply::NetworkError)), Qt::QueuedConnection);
    connect(reply_, &QNetworkReply::finished, this, &O2Requestor::onRequestFinished, Qt::QueuedConnection);
    connect(reply_, &QNetworkReply::uploadProgress, this, &O2Requestor::onUploadProgress);
}
void UpdateChecker::check(bool silent) {
	this->silent = silent;
	//connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(fileIsReady(QNetworkReply*)) );
	QNetworkReply *reply = networkManager->get(QNetworkRequest(QUrl("http://texstudio.sourceforge.net/update/txsUpdate.xml")));
	connect(reply, SIGNAL(finished()), this, SLOT(onRequestCompleted()));
	if (!silent)
		connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onRequestError()));
}
Exemple #6
0
int O2Requestor::get(const QNetworkRequest &req) {
    if (-1 == setup(req, QNetworkAccessManager::GetOperation)) {
        return -1;
    }
    reply_ = manager_->get(request_);

    timedReplies_.add(reply_);
    connect(reply_, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onRequestError(QNetworkReply::NetworkError)), Qt::QueuedConnection);
    connect(reply_, SIGNAL(finished()), this, SLOT(onRequestFinished()), Qt::QueuedConnection);
    return id_;
}
Exemple #7
0
int O2Requestor::put(const QNetworkRequest &req, const QByteArray &data) {
    if (-1 == setup(req, QNetworkAccessManager::PutOperation)) {
        return -1;
    }
    data_ = data;
    reply_ = manager_->put(request_, data_);
    timedReplies_.add(reply_);
    connect(reply_, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onRequestError(QNetworkReply::NetworkError)), Qt::QueuedConnection);
    connect(reply_, SIGNAL(finished()), this, SLOT(onRequestFinished()), Qt::QueuedConnection);
    connect(reply_, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(onUploadProgress(qint64,qint64)));
    return id_;
}
Exemple #8
0
void QuoteSource::refresh()
{
	QUrl url = QUrl(API_BASE_URL);
	url.addQueryItem("method", "getQuote");
	url.addQueryItem("format", "xml");
	url.addQueryItem("lang", "en");
	url.addQueryItem("key", QString::number(getRandomKey(0, 99999)));
	qDebug() << url;

	QNetworkRequest request(url);
	QNetworkReply * pReply = m_pNetworkManager->get(request);
	connect(pReply, SIGNAL(finished()), this, SLOT(onRequestFinished()));
	connect(pReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onRequestError(QNetworkReply::NetworkError)));
}
QProcess* ExternalResourcesRequest::process() {
    if (!m_process) {
        m_process = new QProcess(this);
        connect(m_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onRequestError()));
        connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onRequestFinished(int)));
    }
JsonRPCRequest* JsonRPCCommunicator::sendRequest(const QString& pMethod, const QJsonObject& pParams, bool pDaemonHttp)
{

    QUrl lUrl = endpoint_uri;
    QJsonObject lJsonRoot;

    /* Depending of RPC type, will append method name in URI or in JSON data */
    if ( pDaemonHttp ) {
        lJsonRoot = pParams;
        lUrl.setPath("/"+pMethod);
    }
    else {
        lJsonRoot.insert("jsonrpc",QJsonValue::fromVariant(rpc_version));
        lJsonRoot.insert("method",QJsonValue::fromVariant(pMethod));
        if ( !pParams.empty() ) {
            lJsonRoot.insert("params", pParams);
        }
    }

    QJsonDocument lJsonDoc;
    lJsonDoc.setObject(lJsonRoot);

    QNetworkRequest lReq(lUrl);
    lReq.setHeader(QNetworkRequest::ContentTypeHeader,"application/json");

    JsonRPCRequest* lJsonReq = new JsonRPCRequest(pParams, pDaemonHttp);
    QNetworkReply* lReply = network_access_mgr.post(lReq, lJsonDoc.toJson());

    QObject::connect(lReply, SIGNAL(finished()), lJsonReq, SLOT(onRequestFinished()));
    QObject::connect(lReply, SIGNAL(error(QNetworkReply::NetworkError)), lJsonReq, SLOT(onRequestError(QNetworkReply::NetworkError)));


    return lJsonReq;

}