本文整理汇总了C++中Transfer::cancel方法的典型用法代码示例。如果您正苦于以下问题:C++ Transfer::cancel方法的具体用法?C++ Transfer::cancel怎么用?C++ Transfer::cancel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transfer
的用法示例。
在下文中一共展示了Transfer::cancel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleRequest
bool TransferServer::handleRequest(QHttpRequest *request, QHttpResponse *response) {
const QStringList parts = request->path().split("/", QString::SkipEmptyParts);
if ((parts.isEmpty()) || (parts.size() > 2) || (parts.first() != "transfers")) {
return false;
}
if (parts.size() == 1) {
if (request->method() == QHttpRequest::HTTP_GET) {
const int offset = qMax(0, Utils::urlQueryItemValue(request->url(), "offset").toInt());
int limit = Utils::urlQueryItemValue(request->url(), "limit").toInt();
if ((limit <= 0) || (limit > Transfers::instance()->count())) {
limit = Transfers::instance()->count();
}
QVariantList list;
for (int i = offset; i < limit; i++) {
if (const Transfer *transfer = Transfers::instance()->get(i)) {
list << transferToMap(transfer);
}
else {
break;
}
}
writeResponse(response, QHttpResponse::STATUS_OK, QtJson::Json::serialize(list));
return true;
}
if (request->method() == QHttpRequest::HTTP_POST) {
const QVariantMap properties = QtJson::Json::parse(request->body()).toMap();
const QString url = properties.value("url").toString();
const QString subscriptionId = properties.value("subscriptionId").toString();
if ((url.isEmpty()) || (subscriptionId.isEmpty())) {
writeResponse(response, QHttpResponse::STATUS_BAD_REQUEST);
}
else {
Transfers::instance()->addEnclosureDownload(url, subscriptionId);
writeResponse(response, QHttpResponse::STATUS_CREATED);
}
return true;
}
writeResponse(response, QHttpResponse::STATUS_METHOD_NOT_ALLOWED);
return true;
}
if (parts.at(1) == "start") {
if (request->method() == QHttpRequest::HTTP_GET) {
const QString id = Utils::urlQueryItemValue(request->url(), "id");
if (!id.isEmpty()) {
if (Transfers::instance()->start(id)) {
writeResponse(response, QHttpResponse::STATUS_OK);
}
else {
writeResponse(response, QHttpResponse::STATUS_BAD_REQUEST);
}
}
else {
Transfers::instance()->start();
writeResponse(response, QHttpResponse::STATUS_OK);
}
return true;
}
writeResponse(response, QHttpResponse::STATUS_METHOD_NOT_ALLOWED);
return true;
}
if (parts.at(1) == "pause") {
if (request->method() == QHttpRequest::HTTP_GET) {
const QString id = Utils::urlQueryItemValue(request->url(), "id");
if (!id.isEmpty()) {
if (Transfers::instance()->pause(id)) {
writeResponse(response, QHttpResponse::STATUS_OK);
}
else {
writeResponse(response, QHttpResponse::STATUS_BAD_REQUEST);
}
}
else {
Transfers::instance()->pause();
writeResponse(response, QHttpResponse::STATUS_OK);
}
return true;
}
writeResponse(response, QHttpResponse::STATUS_METHOD_NOT_ALLOWED);
return true;
}
if (parts.at(1) == "cancel") {
//.........这里部分代码省略.........