void LibreFM::requestFinished(int id, bool err) { if(err) { proxy->error(QString("Libre.FM: Request failed: %1.").arg(http.errorString())); if(httpGetId == id) httpGetId = 0; if(httpPostId == id) httpPostId = 0; } else { if(httpGetId == id) { httpGetId = 0; if(needInfo) { QByteArray arr = http.readAll(); proxy->log("Libre.FM response:" + arr); emit xmlInfo(QString::fromUtf8((const char*)arr)); needInfo = false; } else { QString request = http.readAll(); QString status = request.section('\n', 0, 0); if(status == "OK") { session = request.section('\n', 1, 1); nowPlayingUrl = request.section('\n', 2, 2); submissionUrl = request.section('\n', 3, 3); connected = true; proxy->log("Libre.FM: handshake complete"); } else if(status.startsWith("BANNED")) { proxy->error("Libre.FM: I was banned at Libre.FM, I don't want to live any more."); connected = false; } else if(status.startsWith("BADAUTH")) { proxy->error("Libre.FM: Incorrect user name or password."); connected = false; } else if(status.startsWith("BADTIME")) { proxy->error("Libre.FM: Incorrect time. The system clock must be corrected."); connected = false; } else if(status.startsWith("FAILED")) { proxy->error("Libre.FM: " + status); connected = false; } else { connected = false; proxy->warning("Libre.FM: Unknown response: " + status); } } } else if(httpPostId == id) { httpPostId = 0; QString request = http.readAll(); if(request.startsWith("OK")) { // nothing to do } else if(request.startsWith("BADSESSION")) { connected = false; proxy->error("Libre.FM: Bad session identifier. Need for reconnect to the server."); } else if(request.startsWith("FAILED")) { proxy->error("Libre.FM: " + request); } else { proxy->warning("Libre.FM: Unknown response: " + request); } } } doQueue(); }
void ownCloudInfo::qhttpRequestFinished(int id, bool success ) { qDebug() << "HIT!"; QHttp* qhttp = qobject_cast<QHttp*>(sender()); if( success ) { qDebug() << "QHttp based request successful"; } else { qDebug() << "QHttp based request failed: " << qhttp->errorString(); } }
bool CetonStreamHandler::HttpRequest( const QString &method, const QString &script, const QUrl ¶ms, QString &response, uint &status_code) const { QHttp http; http.setHost(_ip_address); QByteArray request_params(params.encodedQuery()); if (method == "GET") { QString path = script + "?" + QString(request_params); QHttpRequestHeader header(method, path); header.setValue("Host", _ip_address); http.request(header); } else { QHttpRequestHeader header(method, script); header.setValue("Host", _ip_address); header.setContentType("application/x-www-form-urlencoded"); http.request(header, request_params); } while (http.hasPendingRequests() || http.currentId()) { usleep(5000); qApp->processEvents(); } if (http.error() != QHttp::NoError) { status_code = 0; response = http.errorString(); return false; } QHttpResponseHeader resp_header = http.lastResponse(); if (!resp_header.isValid()) { status_code = 0; response = "Completed but response object was not valid"; return false; } status_code = resp_header.statusCode(); response = QString(http.readAll()); return true; }
void InfoLastFM::requestFinished(int id, bool err) { if(err) { proxy->error(QString("Last.FM info: Request failed: %1.").arg(http.errorString())); if(httpGetId == id) httpGetId = 0; if(httpPostId == id) httpPostId = 0; } else { if(httpGetId == id) { httpGetId = 0; if(needInfo) { QByteArray arr = http.readAll(); QString text = QString::fromUtf8((const char*)arr); proxy->log("Last.FM info response:" + text); QString artist, album, mbid, imageUrl, info; parseInfo(text, artist, album, mbid, imageUrl, info); if(album.size()) { // album found if(imageUrl.size() && infoType == SInfo::AlbumArt) proxy->setResponse(requestId, SInfo(SInfo::AlbumArt, "", imageUrl)); if(info.size() && infoType == SInfo::AlbumText) proxy->setResponse(requestId, SInfo(SInfo::AlbumText, info, "")); } else if(artist.size()) { // artist found if(imageUrl.size() && infoType == SInfo::ArtistArt) proxy->setResponse(requestId, SInfo(SInfo::ArtistArt, "", imageUrl)); if(info.size() && infoType == SInfo::ArtistText) proxy->setResponse(requestId, SInfo(SInfo::ArtistText, info, "")); } //emit xmlInfo(QString::fromUtf8((const char*)arr)); needInfo = false; } else { } } else if(httpPostId == id) { httpPostId = 0; QString request = http.readAll(); if(request.startsWith("OK")) { // nothing to do } else { proxy->warning("Last.FM info: Unknown response: " + request); } } } doQueue(); }