json QueueUtils::serializeBundleProperty(const BundlePtr& aBundle, int aPropertyName) noexcept { switch (aPropertyName) { case QueueApi::PROP_SOURCES: { int total = 0, online = 0; std::string str; getBundleSourceInfo(aBundle, online, total, str); return { { "online", online }, { "total", total }, { "str", str }, }; } case QueueApi::PROP_STATUS: { return{ { "id", aBundle->getStatus() }, { "failed", aBundle->isFailed() }, { "str", formatBundleStatus(aBundle) }, }; } case QueueApi::PROP_TYPE: { if (aBundle->isFileBundle()) { return Serializer::serializeFileType(aBundle->getTarget()); } else { size_t files = 0; size_t folders = 0; { RLock l(QueueManager::getInstance()->getCS()); files = aBundle->getQueueItems().size() + aBundle->getFinishedFiles().size(); folders = aBundle->getDirectories().size(); } return Serializer::serializeFolderType(files, folders); } } case QueueApi::PROP_PRIORITY: { return serializePriority(*aBundle.get()); } } dcassert(0); return json(); }
json QueueBundleUtils::serializeBundleProperty(const BundlePtr& aBundle, int aPropertyName) noexcept { switch (aPropertyName) { case PROP_SOURCES: { auto c = QueueManager::getInstance()->getSourceCount(aBundle); return Serializer::serializeSourceCount(c); } case PROP_STATUS: { return{ { "id", formatStatusId(aBundle) }, { "failed", aBundle->isFailed() }, { "finished", aBundle->getStatus() >= Bundle::STATUS_MOVED }, { "str", formatDisplayStatus(aBundle) }, }; } case PROP_TYPE: { if (aBundle->isFileBundle()) { return Serializer::serializeFileType(aBundle->getTarget()); } else { size_t files = 0, folders = 0; QueueManager::getInstance()->getBundleContent(aBundle, files, folders); return Serializer::serializeFolderType(static_cast<int>(files), static_cast<int>(folders)); } } case PROP_PRIORITY: { return Serializer::serializePriority(*aBundle.get()); } } dcassert(0); return nullptr; }