Exemplo n.º 1
0
void MegaShares::checkUrlIsValid() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(this->sender());

    if (!reply) {
        emit urlChecked(false);
        return;
    }

    QString redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
    QRegExp re("http://webprod\\d+\\.megashares.com/[^'\"]+");

    if ((!redirect.isEmpty()) && (re.indexIn(redirect) == -1)) {
        this->checkUrl(QUrl(redirect));
    }
    else {
        QString response(reply->readAll());
        QString fileName = response.section("letter-spacing: -1px\" title=\"", 1, 1).section('"', 0, 0);

        if (fileName.isEmpty()) {
            QString errorString = response.section("class=\"red\">", 1, 1).section('<', 0, 0);

            if (errorString.startsWith("All download slots")) {
                emit urlChecked(true, reply->request().url(), this->serviceName(), m_fileName);
            }
            else {
                emit error(UnknownError);
            }
        }
        else {
            emit urlChecked(true, reply->request().url(), this->serviceName(), fileName);
        }
    }

    reply->deleteLater();
}
Exemplo n.º 2
0
void OAuthPrivate::reply(){
    QNetworkReply * r = qobject_cast<QNetworkReply * >(sender());
    QString data = r->readAll();

    qDebug() << "data: " << data;
    qDebug() << "error: " << r->error();
    qDebug() << "errorstring: " << r->errorString();

    Q_Q(OAuth);

    if(r->error() == QNetworkReply::NoError){
        if(r->request().attribute(QNetworkRequest::User).toInt() == RequestToken){
            emit q->requestTokenReceived(Helper::qsToMap(data), data);
        }else if(r->request().attribute(QNetworkRequest::User).toInt() == AccessToken){
            emit q->accessTokenReceived(Helper::qsToMap(data), data);
        }else{
            emit q->resourceReceived(data);
        }
    }else{
        emit q->errorOccurred(data);
    }

    oauthReply->deleteLater();

}
void SidebarPrivate::linkClickedFinished()
{
    QNetworkReply * reply = static_cast< QNetworkReply * >(sender());

    QString target = reply->property("__target").toString();
    QVariant redirectsVariant = reply->property("__redirects");
    int redirects = redirectsVariant.isNull() ? 20 : redirectsVariant.toInt();

    // Redirect?
    QUrl redirectedUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
    if (redirectedUrl.isValid())
    {
        if (redirectedUrl.isRelative())
        {
            QUrl oldUrl = reply->url();
            redirectedUrl.setScheme(oldUrl.scheme());
            redirectedUrl.setAuthority(oldUrl.authority());
        }
        if (redirects > 0)
        {
            QNetworkRequest request = reply->request();
            request.setUrl(redirectedUrl);
            QNetworkReply * reply = networkAccessManager()->get(request);
            reply->setProperty("__target", target);
            connect(reply, SIGNAL(finished()), this, SLOT(linkClickedFinished()));
        }
        else
        {
            // TOO MANY REDIRECTS
        }
        reply->deleteLater();
        return;
    }

    // Check headers... if PDF then launch a new window, otherwise give it to the OS
    QString contentType(reply->header(QNetworkRequest::ContentTypeHeader).toString());
    if (contentType.contains("application/pdf")) {
        emit urlRequested(reply->request().url(), "tab");
    } else {
        QUrl href(reply->request().url());
        if (href.isValid()) {
            if (href.scheme() == "http" || href.scheme() == "https") {
                if (target == "sidebar") {
                    webView->setUrl(href);
                    slideLayout->push("web");
                    return;
                }
            }

            QDesktopServices::openUrl(href);
        }
        // FIXME error
    }

    reply->deleteLater();
}
    void _replyFinished()
    {
        Q_Q( NetworkAccessManagerProxy );
        QNetworkReply *reply = static_cast<QNetworkReply*>( q->sender() );

        KUrl url = reply->request().url();
        QList<CallBackData*> callbacks = urlMap.values( url );
        urlMap.remove( url );
        QByteArray data = reply->readAll();
        data.detach(); // detach so the bytes are not deleted before methods are invoked
        foreach( const CallBackData *cb, callbacks )
        {
            // There may have been a redirect.
            KUrl redirectUrl = q->getRedirectUrl( reply );

            // Check if there's no redirect.
            if( redirectUrl.isEmpty() )
            {
                QByteArray sig = QMetaObject::normalizedSignature( cb->method );
                sig.remove( 0, 1 ); // remove first char, which is the member code (see qobjectdefs.h)
                                    // and let Qt's meta object system handle the rest.
                if( cb->receiver )
                {
                    bool success( false );
                    const QMetaObject *mo = cb->receiver.data()->metaObject();
                    int methodIndex = mo->indexOfSlot( sig );
                    if( methodIndex != -1 )
                    {
                        Error err = { reply->error(), reply->errorString() };
                        QMetaMethod method = mo->method( methodIndex );
                        success = method.invoke( cb->receiver.data(),
                                                cb->type,
                                                Q_ARG( KUrl, reply->request().url() ),
                                                Q_ARG( QByteArray, data ),
                                                Q_ARG( NetworkAccessManagerProxy::Error, err ) );
                    }

                    if( !success )
                    {
                        debug() << QString( "Failed to invoke method %1 of %2" )
                            .arg( QString(sig) ).arg( mo->className() );
                    }
                }
            }
            else
            {
                debug() << "the server is redirecting the request to: " << redirectUrl;

                // Let's try to fetch the data again, but this time from the new url.
                QNetworkReply *newReply = q->getData( redirectUrl, cb->receiver.data(), cb->method, cb->type );

                emit q->requestRedirected( url, redirectUrl );
                emit q->requestRedirected( reply, newReply );
            }
        }
Exemplo n.º 5
0
void DataBrowser::resourceDownloaded()
{
    QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender());

    if(reply)
    {
        int type = reply->request().attribute(typeAttribute).toInt();
        QUrl url = reply->request().attribute(urlAttribute).toUrl();
        resources.insert(url.toString(), reply->readAll());
        document()->addResource(type, reply->request().url(), QVariant());
        update();
    }
}
Exemplo n.º 6
0
void PublishToMePlugin::checkUrlIsValid() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());

    if (!reply) {
        emit error(tr("Network error"));
        return;
    }

    const QString redirect = getRedirect(reply);

    if (!redirect.isEmpty()) {
        if (FILE_REGEXP.indexIn(redirect) == 0) {
            emit urlChecked(UrlResult(reply->request().url().toString(),
                            redirect.mid(redirect.lastIndexOf("/") + 1)));
        }
        else if (m_redirects < MAX_REDIRECTS) {
            followRedirect(redirect, SLOT(checkUrlIsValid()));
        }
        else {
            emit error(tr("Maximum redirects reached"));
        }

        reply->deleteLater();
        return;
    }

    switch (reply->error()) {
    case QNetworkReply::NoError:
        break;
    case QNetworkReply::OperationCanceledError:
        reply->deleteLater();
        return;
    default:
        emit error(reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString());
        reply->deleteLater();
        return;
    }

    const QString response = QString::fromUtf8(reply->readAll());
    const QString fileName = response.section("icon-download-alt\" style=\"\"></i>", 1, 1)
                                     .section("</div>", 0, 0).trimmed();

    if (fileName.isEmpty()) {
        emit error(tr("File not found"));
    }
    else {
        emit urlChecked(UrlResult(reply->request().url().toString(), fileName));
    }

    reply->deleteLater();
}
Exemplo n.º 7
0
void FilesToShare::checkUrlIsValid() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(this->sender());

    if (!reply) {
        emit urlChecked(false);
        return;
    }

    QString redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
    QRegExp re("http://\\w+-\\d+.files2share.ch:\\d+/[^'\"]+");

    if ((!redirect.isEmpty()) && (re.indexIn(redirect) == -1)) {
        this->checkUrl(QUrl(redirect));
    }
    else {
        QString response(reply->readAll());

        if (response.contains("File Not Found")) {
            emit urlChecked(false);
        }
        else {
            QString fileName = response.section("fname\" value=\"", 1, 1).section('"', 0, 0);

            if (fileName.isEmpty()) {
                emit urlChecked(false);
            }
            else {
                emit urlChecked(true, reply->request().url(), this->serviceName(), fileName);
            }
        }
    }

    reply->deleteLater();
}
Exemplo n.º 8
0
void RequestModel::handleFinished ()
{
	QNetworkReply *reply = qobject_cast<QNetworkReply*> (sender ());
	if (!reply)
	{
		qWarning () << Q_FUNC_INFO
			<< sender ()
			<< "not found";
		return;
	}

	for (int i = 0; i < rowCount (); ++i)
	{
		QStandardItem *ci = item (i);
		if (ci->data ().value<QNetworkReply*> () == reply)
		{
			if (Clear_)
				qDeleteAll (takeRow (i));
			else
			{
				item (i, 1)->setText (QDateTime::currentDateTime ().toString ());
				item (i, 0)->setData (0);
				QNetworkRequest r = reply->request ();
				item (i, 1)->setData (GetHeaders (&r));
				item (i, 2)->setData (GetHeaders (reply));
			}
			break;
		}
	}
}
Exemplo n.º 9
0
void FileBoom::checkUrlIsValid() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(this->sender());

    if (!reply) {
        emit urlChecked(false);
        return;
    }

    QString redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
    QRegExp re("(http://fboom.me|)/file/url.html\\?file=[^'\"]+");

    if ((!redirect.isEmpty()) && (re.indexIn(redirect) == -1)) {
        this->checkUrl(QUrl(redirect));
    }
    else {
        QString response(reply->readAll());
        QString fileName = response.section("icon-download\"></i>", 1, 1).section("</div>", 0, 0).trimmed();

        if (fileName.isEmpty()) {
            emit urlChecked(false);
        }
        else {
            emit urlChecked(true, reply->request().url(), this->serviceName(), fileName);
        }
    }

    reply->deleteLater();
}
Exemplo n.º 10
0
Arquivo: uloz.cpp Projeto: marxoft/qdl
void Uloz::checkUrlIsValid() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(this->sender());

    if (!reply) {
        emit urlChecked(false);
        return;
    }

    QString redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
    QRegExp re("http://\\w+.uloz.to/Ps;Hs;fid=\\d+[^'\"]+");

    if ((!redirect.isEmpty()) && (re.indexIn(redirect) == -1)) {
        this->checkUrl(QUrl(redirect));
    }
    else {
        QString response(reply->readAll());
        QString fileName = response.section("<title>", 1).section(" | Ulo", 0, 0);

        if (fileName.isEmpty()) {
            emit urlChecked(false);
        }
        else {
            emit urlChecked(true, reply->request().url(), this->serviceName(), fileName);
        }
    }

    reply->deleteLater();
}
Exemplo n.º 11
0
void Session::Request::onAccountStashTabsResult() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(QObject::sender());
    QByteArray response;
    if (reply->error()) {
        const QString errorMessage = QString("Network error in %1: %2").arg(__FUNCTION__).arg(reply->errorString());
        Session::LogError(errorMessage);
        QJsonObject error({
            {
                "error", QJsonObject({
                    {"message", errorMessage},
                    {"internal", true}
                })
            }
        });
        response = QJsonDocument(error).toJson();
    }
    else {
        response = reply->readAll();
    }

    QNetworkRequest request = reply->request();
    QVariant data = getAttribute(&request, UserData);
    QString league = getAttribute(&request, League).toString();

    emit accountStashTabs(league, response, data);
    QJsonDocument doc = QJsonDocument::fromJson(response);
    emit accountStashTabsJson(league, doc, data);

    reply->deleteLater();
}
Exemplo n.º 12
0
void Uploadable::checkUrlIsValid() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(this->sender());

    if (!reply) {
        emit urlChecked(false);
        return;
    }

    QString redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
    QRegExp re("http(s|)://adl.uploadable.ch/file/\\w+/[-\\w]+/[-\\w]+");

    if ((!redirect.isEmpty()) && (re.indexIn(redirect) == -1)) {
        this->checkUrl(QUrl(redirect));
    }
    else {
        QString response(reply->readAll());
        QString fileName = response.section("file_name\" title=\"", 1, 1).section('"', 0, 0);

        if (fileName.isEmpty()) {
            emit urlChecked(false);
        }
        else {
            emit urlChecked(true, reply->request().url(), this->serviceName(), fileName);
        }
    }

    reply->deleteLater();
}
Exemplo n.º 13
0
void Session::Request::onLoginPage() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(QObject::sender());
    if (reply->error()) {
        emit loginResult(0x01, "A network error occured: " + reply->errorString());
    }
    else {
        QNetworkRequest request = reply->request();
        // Extract CSF
        const QString hash = getCSRFToken(reply->readAll());
        const QString username = getAttribute(&request, LoginUsername).toString();
        const QString password = getAttribute(&request, LoginPassword).toString();

        QUrlQuery query;
        query.addQueryItem("login_email", username);
        query.addQueryItem("login_password", password);
        query.addQueryItem("hash", hash);
        query.addQueryItem("login", "Login");
        QByteArray data(query.query().toUtf8());

        request = createRequest(LoginUrl());
        setAttribute(&request, LoginUsername, username);
        setAttribute(&request, LoginPassword, password);
        request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

        QNetworkReply *r = _manager->post(request, data);

        connect(r, &QNetworkReply::finished, this, &Session::Request::Request::onLoginPageResult);
    }
    reply->deleteLater();
}
Exemplo n.º 14
0
void DrTuber::checkUrlIsValid() {
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(this->sender());

    if (!reply) {
        emit urlChecked(false);
        return;
    }

    QUrl redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();

    if (!redirect.isEmpty()) {
        this->checkUrl(redirect);
    }
    else {
        QString response(reply->readAll());
        QString fileName = response.section("<title>", 1, 1).section("- Free", 0, 0).simplified();

        if (!fileName.isEmpty()) {
            emit urlChecked(true, reply->request().url(), this->serviceName(), fileName + ".flv");
        }
        else {
            emit urlChecked(false);
        }
    }

    reply->deleteLater();
}
Exemplo n.º 15
0
void OneFichier::checkUrlIsValid() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(this->sender());

    if (!reply) {
        emit urlChecked(false);
        return;
    }

    QString redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
    QRegExp re("http(s|)://\\w-\\d.1fichier.com/[^'\"]+");

    if ((!redirect.isEmpty()) && (re.indexIn(redirect) == -1)) {
        this->checkUrl(QUrl(redirect));
    }
    else {
        QString response(reply->readAll());
        QString fileName = response.section("File Name :</td>", 1, 1)
                                   .section("class=\"normal\">", 1, 1)
                                   .section('<', 0, 0);

        if (fileName.isEmpty()) {
            emit urlChecked(false);
        }
        else {
            emit urlChecked(true, reply->request().url(), this->serviceName(), fileName);
        }
    }

    reply->deleteLater();
}
Exemplo n.º 16
0
void ZAPI::finished()
{
    QNetworkReply* reply = (QNetworkReply*)sender();
    QNetworkRequest request = reply->request();
    int role = request.attribute(ATTR_ROLE).toInt();
    QString strReply = reply->readAll();
    QJsonDocument jsonDoc = QJsonDocument::fromJson(strReply.toUtf8());
    QJsonObject jsonObject = jsonDoc.object();
    //qDebug() << jsonDoc.toJson();
    switch(role) {
    case ROLE_LOGIN:
        access_token = jsonObject["access_token"].toString();
        token_type = jsonObject["token_type"].toString();
        emit loginSignal(jsonObject);
        break;
    case ROLE_REFRESH:
        break;
    case ROLE_URL:
        emit urlSignal(jsonObject);
        break;
    case ROLE_FEEDS:
        emit feedsSignal(jsonObject);
        break;
    }
    reply->deleteLater();
}
QNetworkRequest QNetworkReplyProto::request() const
{
  QNetworkReply *item = qscriptvalue_cast<QNetworkReply*>(thisObject());
  if (item)
    return item->request();
  return QNetworkRequest();
}
Exemplo n.º 18
0
void Multiupload::checkUrlIsValid() {
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(this->sender());

    if (!reply) {
        emit urlChecked(false);
        return;
    }

    QUrl redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();

    if (!redirect.isEmpty()) {
        this->checkUrl(redirect);
    }
    else {
        QString response(reply->readAll());
        
        QRegExp re("http(s|)://www\\d+.multiupload.nl:\\d+/files/[^\"]+");

        if (re.indexIn(response) >= 0) {
            QString fileName = re.cap().section('/', -1);
        
            if (fileName.isEmpty()) {
                emit urlChecked(false);
            }
            else {
                emit urlChecked(true, reply->request().url(), this->serviceName(), fileName);
            }
        }
        else {
            emit urlChecked(false);
        }
    }

    reply->deleteLater();
}
Exemplo n.º 19
0
void RequestModel::handleFinished ()
{
	QNetworkReply *reply = qobject_cast<QNetworkReply*> (sender ());
	if (!reply)
	{
		qWarning () << Q_FUNC_INFO
			<< sender ()
			<< "not found";
		return;
	}

	for (int i = 0; i < rowCount (); ++i)
	{
		QStandardItem *ci = item (i);
		if (ci->data ().value<QNetworkReply*> () == reply)
		{
			if (Clear_)
				qDeleteAll (takeRow (i));
			else
			{
				item (i, 1)->setText (QDateTime::currentDateTime ().toString ());
				item (i, 0)->setData (0);
				QNetworkRequest r = reply->request ();
				item (i, 1)->setData (GetHeaders (&r));

				auto headers = GetHeaders (reply);
				headers ["[HTTP response]"] = QString ("%1 (%2)")
						.arg (reply->attribute (QNetworkRequest::HttpStatusCodeAttribute).toInt ())
						.arg (reply->attribute (QNetworkRequest::HttpReasonPhraseAttribute).toString ());
				item (i, 2)->setData (headers);
			}
			break;
		}
	}
}
Exemplo n.º 20
0
void Pastebin::onDeletePasteFinished()
{
    QNetworkReply *networkReply = qobject_cast<QNetworkReply *>(sender());
    QNetworkRequest networkRequest = networkReply->request();
    QVariant statusCode = networkReply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    const QString pasteKey = networkRequest.attribute(QNetworkRequest::Attribute(QNetworkRequest::User + 1)).toString();
    qDebug() << "Delete paste complete:" << statusCode.toInt();

    if(networkReply->error() == QNetworkReply::NoError) {
        QString response = networkReply->readAll();

        qDebug() << "Response:" << response;

        if(response.startsWith("Bad API request")) {
            qWarning() << "Error with delete paste";
            emit deletePasteError(pasteKey, response);
        }
        else {
            qDebug() << "Delete paste successful";
            emit deletePasteComplete(pasteKey);
        }
    }
    else {
        qWarning() << "Error with delete paste" << networkReply->errorString();
        emit deletePasteError(pasteKey, QString::null);
    }
}
Exemplo n.º 21
0
void FShare::checkUrlIsValid() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(this->sender());

    if (!reply) {
        emit urlChecked(false);
        return;
    }

    QString redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
    QRegExp re("http(s|)://download\\d+.fshare.vn/download/[^'\"]+");

    if ((!redirect.isEmpty()) && (re.indexIn(redirect) == -1)) {
        this->checkUrl(QUrl(redirect));
    }
    else {
        QString response(reply->readAll().simplified());
        QString fileName = response.section(" tin:</b>", 1, 1).section('<', 0, 0).trimmed();

        if (fileName.isEmpty()) {
            emit urlChecked(false);
        }
        else {
            emit urlChecked(true, reply->request().url(), this->serviceName(), fileName);
        }
    }

    reply->deleteLater();
}
Exemplo n.º 22
0
void MixtureCloud::checkUrlIsValid() {
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(this->sender());

    if (!reply) {
        emit urlChecked(false);
        return;
    }

    QString redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
    QRegExp re("http(s|)://\\w+.mixturecloud.com/down.php\\?d=[^\"]+");

    if ((!redirect.isEmpty()) && (re.indexIn(redirect) == -1)) {
        this->checkUrl(QUrl(redirect));
    }
    else {
        QString response(reply->readAll());

        if (re.indexIn(response) >= 0) {
            QString fileName = re.cap().section('/', -1);
            emit urlChecked(true, reply->request().url(), this->serviceName(), fileName);
        }
        else {
            emit urlChecked(false);
        }
    }

    reply->deleteLater();
}
Exemplo n.º 23
0
void Cramit::checkUrlIsValid() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(this->sender());

    if (!reply) {
        emit urlChecked(false);
        return;
    }

    QString redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
    QRegExp re("http://cramit.in/file_download/[^'\"]+");

    if ((!redirect.isEmpty()) && (re.indexIn(redirect) == -1)) {
        this->checkUrl(QUrl(redirect));
    }
    else {
        QString response(reply->readAll());

        if (response.contains("File Not Found")) {
            emit urlChecked(false);
        }
        else {
            QString fileName = response.section(QRegExp("<title>.+Download File "), 1, 1).section('<', 0, 0);

            if (fileName.isEmpty()) {
                emit urlChecked(false);
            }
            else {
                emit urlChecked(true, reply->request().url(), this->serviceName(), fileName);
            }
        }
    }

    reply->deleteLater();
}
Exemplo n.º 24
0
void SearchProvider::requestError(QNetworkReply::NetworkError error)
{
    QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
    LOG_WARNING(QString("Error on request %1 : %2")
                .arg(reply->request().url().toString())
                .arg(error));
    reply->deleteLater();
}
Exemplo n.º 25
0
void RISE::downloaded()
{
    QNetworkReply * reply = ((QNetworkReply*)sender());
    QString fileName = reply->request().attribute(QNetworkRequest::User).toString();
    QFile file(fileName);
    if(file.open(QFile::ReadWrite))
        file.write(reply->readAll());
}
Exemplo n.º 26
0
void SongkickConcerts::FetchInfo(int id, const Song& metadata) {
  Echonest::Artist::SearchParams params;
  params.push_back(qMakePair(Echonest::Artist::Name, QVariant(metadata.artist())));
  params.push_back(qMakePair(Echonest::Artist::IdSpace, QVariant(kSongkickArtistBucket)));
  qLog(Debug) << "Params:" << params;
  QNetworkReply* reply = Echonest::Artist::search(params);
  qLog(Debug) << reply->request().url();
  NewClosure(reply, SIGNAL(finished()), this, SLOT(ArtistSearchFinished(QNetworkReply*, int)), reply, id);
}
Exemplo n.º 27
0
void PictureDownloader::requestError(QNetworkReply::NetworkError error) const
{
    QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
    LOG_WARNING(QString("Error on request %1: [%2] %3")
                .arg(reply->request().url().toString())
                .arg(error)
                .arg(reply->errorString()));
    reply->deleteLater();
}
Exemplo n.º 28
0
bool ActivatePage::getAccessToken()
{
    serverQueryFinished = false;
    serverQueryError = false;
    disconnect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
    label_message->setText("Requesting key...");

    QUrl url( "https://screencloud.net/1.0/oauth/access_token_xauth" );
    // create a request parameters map
    QUrl bodyParams;
    bodyParams.addQueryItem( "data[User][email]", field("register.email").toString());
    bodyParams.addQueryItem( "data[User][password]", field("register.password").toString());
    bodyParams.addQueryItem("oauth_version", "1.0");
    bodyParams.addQueryItem("oauth_signature_method", "PLAINTEXT");
    bodyParams.addQueryItem("oauth_consumer_key", CONSUMER_KEY_SCREENCLOUD);
    bodyParams.addQueryItem("oauth_signature", CONSUMER_SECRET_SCREENCLOUD);
    bodyParams.addQueryItem("oauth_timestamp", QString::number(QDateTime::currentDateTimeUtc().toTime_t()));
    bodyParams.addQueryItem("oauth_nonce", NetworkUtils::generateNonce(15));
    QByteArray body = bodyParams.encodedQuery();

    QNetworkRequest request;
    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
    request.setUrl(url);
    QNetworkReply* reply = manager->post(request, body);
    QEventLoop loop;
    connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
    loop.exec();
    connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
    if ( reply->error() == QNetworkReply::NoError ) {
        //Save to qsettings
        QString replyText = reply->readAll();
        if(replyText.isEmpty())
        {
            label_message->setText("<font color='red'>Failed to get credentials. Empty reply from server.</font>");
            return false;
        }
        INFO(reply->request().url().toString() + " returned: " + replyText);
        QUrl replyParams = QUrl("?" + replyText);
        QSettings settings("screencloud", "ScreenCloud");
        settings.beginGroup("account");
        settings.setValue("token", replyParams.queryItemValue("oauth_token"));
        settings.setValue("token-secret", replyParams.queryItemValue("oauth_token_secret"));
        settings.setValue("email", field("register.email").toString());
        settings.setValue("logged-in", true);
        settings.endGroup();
        return true;
    }else
    {
        label_message->setText("<font color='red'>OAuth error</font>");
        return false;
    }
    return false;
}
Exemplo n.º 29
0
void SearchProvider::naturalSearchParseResponse(QString uid)
{
    QNetworkReply *reply = static_cast<QNetworkReply *>(static_cast<QSignalMapper *>(sender())->mapping(uid));

    QJsonDocument response = QJsonDocument::fromJson(reply->readAll());

    QJsonValue results = response.object()["results"];
    QString text = reply->request().url().query().split('&')[0].split('=')[1];
    LOG_DEBUG(QString("Response for \"%1\": %2 results").arg(text).arg(results.toArray().size()));
    emit searchResultAvailable(uid, results);

    reply->deleteLater();
}
Exemplo n.º 30
0
void OneFichier::onWebPageDownloaded() {
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(this->sender());

    if (!reply) {
        emit error(NetworkError);
        return;
    }

    QRegExp re("http(s|)://\\w-\\d.1fichier.com/[^'\"]+");
    QString redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();

    if (re.indexIn(redirect) == 0) {
        QNetworkRequest request;
        request.setUrl(QUrl(re.cap()));
        emit downloadRequestReady(request);
    }
    else if (!redirect.isEmpty()) {
        this->getDownloadRequest(QUrl(redirect));
    }
    else {
        QString response(reply->readAll());

        if (re.indexIn(response) >= 0) {
            QNetworkRequest request;
            request.setUrl(QUrl(re.cap()));
            emit downloadRequestReady(request);
        }
        else {
            QRegExp re("must wait \\d+ minutes");
        
            if (re.indexIn(response) >= 0) {
                int mins = re.cap().section("must wait ", 1, 1).section(' ', 0, 0).toInt();
                
                if (mins > 0) {
                    this->startWait(mins * 61000);
                    this->connect(this, SIGNAL(waitFinished()), this, SLOT(onWaitFinished()));
                }
                else {
                    emit error(UnknownError);
                }
            }
            else {
                this->getDownloadLink(reply->request().url());
            }
        }
    }

    reply->deleteLater();
}