当前位置: 首页>>代码示例>>C++>>正文


C++ Transfer::cancel方法代码示例

本文整理汇总了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") {
//.........这里部分代码省略.........
开发者ID:marxoft,项目名称:cutenews,代码行数:101,代码来源:transferserver.cpp


注:本文中的Transfer::cancel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。