void YouTube::addToFavourites(const QString &videoId) { QUrl url("http://gdata.youtube.com/feeds/api/users/default/favorites"); QByteArray xml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" \ "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" \ "<id>" + videoId.toAscii() + "</id>\n" \ "</entry>"); postRequest(url, xml); connect(this, SIGNAL(postSuccessful()), this, SIGNAL(addedToFavourites())); connect(this, SIGNAL(postFailed()), this, SIGNAL(videoInFavourites())); }
void YouTube::rateVideo(const QString &videoId, const QString &likeOrDislike) { QUrl url("http://gdata.youtube.com/feeds/api/videos/" + videoId + "/ratings"); QByteArray xml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" \ "<entry xmlns=\"http://www.w3.org/2005/Atom\"\n" \ "xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">\n" \ "<yt:rating value=\"" + likeOrDislike.toAscii() + "\"/>\n" \ "</entry>"); postRequest(url, xml); connect(this, SIGNAL(postSuccessful()), this, SIGNAL(videoRated())); connect(this, SIGNAL(postFailed()), this, SIGNAL(cannotRate())); }
void YouTube::postFinished() { QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender()); if (!reply) { emit alert(tr("Error - YouTube server unreachable")); return; } int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); QByteArray statusText = reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toByteArray(); // qDebug() << "Status is:" << statusCode << ":" << statusText; if ((statusCode == 200) || (statusCode == 201)) { emit postSuccessful(); } else if ((statusText == "Bad Request") || ((statusText == "Forbidden") && !(currentUser == ""))) { emit postFailed(); } else { emit alert(tr("Error - Server repsonse is: ") + statusText); } disconnect(this, SIGNAL(postSuccessful()), 0, 0); disconnect(this, SIGNAL(postFailed()), 0, 0); reply->deleteLater(); }
void CIMainWindow::on_readyReadBuildingStandardOutput() { while(mProcBuild->canReadLine()) { QString last_line = QString::fromLocal8Bit(mProcBuild->readLine().data()); ui->textBrowser->append(last_line); if (last_line.startsWith("==========")) { QString str_failed = QStringLiteral("失败"); auto str_failed_pos = last_line.indexOf(str_failed); QString failed_num = last_line.mid(str_failed_pos + 3, 1); if (failed_num.toInt() != 0) { postFailed(); } } } }