int QueueBundleUtils::compareBundles(const BundlePtr& a, const BundlePtr& b, int aPropertyName) noexcept { switch (aPropertyName) { case PROP_NAME: { COMPARE_TYPE(a, b); return Util::stricmp(a->getName(), b->getName()); } case PROP_TYPE: { COMPARE_TYPE(a, b); if (!a->isFileBundle() && !b->isFileBundle()) { // Directory bundles RLock l(QueueManager::getInstance()->getCS()); auto dirsA = QueueManager::getInstance()->bundleQueue.getDirectoryCount(a); auto dirsB = QueueManager::getInstance()->bundleQueue.getDirectoryCount(b); if (dirsA != dirsB) { return compare(dirsA, dirsB); } auto filesA = a->getQueueItems().size() + a->getFinishedFiles().size(); auto filesB = b->getQueueItems().size() + b->getFinishedFiles().size(); return compare(filesA, filesB); } return Util::stricmp(Util::getFileExt(a->getTarget()), Util::getFileExt(b->getTarget())); } case PROP_PRIORITY: { COMPARE_FINISHED(a, b); if (a->isFinished() != b->isFinished()) { return a->isFinished() ? 1 : -1; } return compare(static_cast<int>(a->getPriority()), static_cast<int>(b->getPriority())); } case PROP_STATUS: { if (a->getStatus() != b->getStatus()) { return compare(a->getStatus(), b->getStatus()); } return compare( a->getPercentage(a->getDownloadedBytes()), b->getPercentage(b->getDownloadedBytes()) ); } case PROP_SOURCES: { COMPARE_FINISHED(a, b); auto countsA = QueueManager::getInstance()->getSourceCount(a); auto countsB = QueueManager::getInstance()->getSourceCount(b); return QueueItemBase::SourceCount::compare(countsA, countsB); } default: dcassert(0); } return 0; }
std::string QueueBundleUtils::formatDisplayStatus(const BundlePtr& aBundle) noexcept { switch (aBundle->getStatus()) { case Bundle::STATUS_NEW: case Bundle::STATUS_QUEUED: { auto percentage = aBundle->getPercentage(aBundle->getDownloadedBytes()); if (aBundle->isPausedPrio()) return STRING_F(PAUSED_PCT, percentage); if (aBundle->getSpeed() > 0) { // Bundle->isRunning() ? return STRING_F(RUNNING_PCT, percentage); } else { return STRING_F(WAITING_PCT, percentage); } } case Bundle::STATUS_RECHECK: return STRING(RECHECKING); case Bundle::STATUS_DOWNLOADED: return STRING(MOVING); case Bundle::STATUS_MOVED: return STRING(DOWNLOADED); case Bundle::STATUS_DOWNLOAD_FAILED: case Bundle::STATUS_FAILED_MISSING: case Bundle::STATUS_SHARING_FAILED: return aBundle->getLastError(); case Bundle::STATUS_FINISHED: return STRING(FINISHED); case Bundle::STATUS_HASHING: return STRING(HASHING); case Bundle::STATUS_HASH_FAILED: return STRING(HASH_FAILED); case Bundle::STATUS_HASHED: return STRING(HASHING_FINISHED); case Bundle::STATUS_SHARED: return STRING(SHARED); default: return Util::emptyString; } }