コード例 #1
0
ファイル: oauth.cpp プロジェクト: mgsxx/QEverCloudGenerator
void qevercloud::EvernoteOAuthWebView::permanentFinished(QObject *rf)
{
    ReplyFetcher* replyFetcher = qobject_cast<ReplyFetcher*>(rf);
    if(replyFetcher->isError()) {
        setError(replyFetcher->errorText());
    } else {
        isSucceeded_ = true;

        QByteArray reply = replyFetcher->receivedData();
        QMap<QString, QString> params;
        QList<QByteArray> vals = reply.split('&');
        for(int i = 0; i < vals.length(); i++) {
            QString decoded = QUrl::fromPercentEncoding(vals[i]);
            int pos = decoded.indexOf('=');
            params[decoded.left(pos).trimmed()] = decoded.mid(pos + 1);
        }
        oauthResult_.noteStoreUrl = params[QStringLiteral("edam_noteStoreUrl")];
        oauthResult_.expires = Timestamp(params[QStringLiteral("edam_expires")].toLongLong());
        oauthResult_.shardId = params[QStringLiteral("edam_shard")];
        oauthResult_.userId = params[QStringLiteral("edam_userId")].toInt();
        oauthResult_.webApiUrlPrefix = params[QStringLiteral("edam_webApiUrlPrefix")];
        oauthResult_.authenticationToken = params[QStringLiteral("oauth_token")];

        emit authenticationFinished(true);
        emit authenticationSuceeded();
    }
    replyFetcher->deleteLater();
}
コード例 #2
0
ファイル: oauth.cpp プロジェクト: mgsxx/QEverCloudGenerator
void qevercloud::EvernoteOAuthWebView::temporaryFinished(QObject *rf)
{
    ReplyFetcher* replyFetcher = qobject_cast<ReplyFetcher*>(rf);
    if(replyFetcher->isError()) {
        setError(replyFetcher->errorText());
    } else {
        QString reply = QString(replyFetcher->receivedData());
        int index = reply.indexOf(QStringLiteral("&oauth_token_secret"));
        QString token = reply.left(index);

        // step 2: directing a user to the login page
        connect(this, SIGNAL(urlChanged(QUrl)), this, SLOT(onUrlChanged(QUrl)));
        QUrl loginUrl(QStringLiteral("https://%1//OAuth.action?%2").arg(host_).arg(token));
        this->setUrl(loginUrl);
    }
    replyFetcher->deleteLater();
}
コード例 #3
0
void qevercloud::AsyncResult::onReplyFetched(QObject *rp)
{
    ReplyFetcher* reply = qobject_cast<ReplyFetcher*>(rp);
    QSharedPointer<EverCloudExceptionData> error;
    QVariant result;
    try {
        if(reply->isError()) {
            error = QSharedPointer<EverCloudExceptionData>(new EverCloudExceptionData(reply->errorText()));
        } else if(reply->httpStatusCode() != 200) {
            error = QSharedPointer<EverCloudExceptionData>(new EverCloudExceptionData(QStringLiteral("HTTP Status Code = %1").arg(reply->httpStatusCode())));
        } else {
            result = readFunction_(reply->receivedData());
        }
    } catch(const EverCloudException& e) {
        error = e.exceptionData();
    } catch(const std::exception& e) {
        error = QSharedPointer<EverCloudExceptionData>(new EverCloudExceptionData(QStringLiteral("Exception of type \"%1\" with the message: %2").arg(typeid(e).name()).arg(e.what())));
    } catch(...) {
        error = QSharedPointer<EverCloudExceptionData>(new EverCloudExceptionData(QStringLiteral("Unknown exception")));
    }
    emit finished(result, error);
    reply->deleteLater();
    if(autoDelete_) this->deleteLater();
}