std::string QueueUtils::formatBundleStatus(const BundlePtr& aBundle) noexcept { auto getPercentage = [&] { return aBundle->getSize() > 0 ? (double)aBundle->getDownloadedBytes() *100.0 / (double)aBundle->getSize() : 0; }; switch (aBundle->getStatus()) { case Bundle::STATUS_NEW: case Bundle::STATUS_QUEUED: { if (aBundle->isPausedPrio()) return STRING_F(PAUSED_PCT, getPercentage()); if (aBundle->getSpeed() > 0) { // Bundle->isRunning() ? return STRING_F(RUNNING_PCT, getPercentage()); } else { return STRING_F(WAITING_PCT, getPercentage()); } } 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; } }
double QueueUtils::getNumericInfo(const BundlePtr& b, int aPropertyName) noexcept { dcassert(b->getSize() != 0); switch (aPropertyName) { case QueueApi::PROP_SIZE: return (double)b->getSize(); case QueueApi::PROP_BYTES_DOWNLOADED: return (double)b->getDownloadedBytes(); case QueueApi::PROP_PRIORITY: return b->getPriority(); case QueueApi::PROP_TIME_ADDED: return (double)b->getTimeAdded(); case QueueApi::PROP_TIME_FINISHED: return (double)b->getTimeFinished(); case QueueApi::PROP_SPEED: return (double)b->getSpeed(); case QueueApi::PROP_SECONDS_LEFT: return (double)b->getSecondsLeft(); default: dcassert(0); return 0; } }