From 792cc4bbe38037b5ecac6c46f1fd8dc2ae119a6b Mon Sep 17 00:00:00 2001 From: martii Date: Sat, 16 Nov 2013 13:08:18 +0100 Subject: [PATCH] system/ytcache: add progress data Conflicts: src/gui/moviebrowser.cpp Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/050138c107dd90f504592a6a9a97a45edc844fd5 Author: martii Date: 2013-11-16 (Sat, 16 Nov 2013) ------------------ This commit was generated by Migit --- src/gui/moviebrowser.cpp | 13 +++++++++++-- src/system/ytcache.cpp | 24 ++++++++++++++++++++++-- src/system/ytcache.h | 5 ++++- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/gui/moviebrowser.cpp b/src/gui/moviebrowser.cpp index 82edf4d8d..9ba263e4d 100644 --- a/src/gui/moviebrowser.cpp +++ b/src/gui/moviebrowser.cpp @@ -3815,7 +3815,9 @@ void CMovieBrowser::refreshYTMenu() yt_menue->removeItem(item_id); } MI_MOVIE_INFO::miSource source = (show_mode == MB_SHOW_YT) ? MI_MOVIE_INFO::YT : MI_MOVIE_INFO::NK; - yt_pending = cYTCache::getInstance()->getPending(source); + double dltotal, dlnow; + time_t dlstart; + yt_pending = cYTCache::getInstance()->getPending(source, &dltotal, &dlnow, &dlstart); yt_completed = cYTCache::getInstance()->getCompleted(source); yt_failed = cYTCache::getInstance()->getFailed(source); @@ -3830,10 +3832,17 @@ void CMovieBrowser::refreshYTMenu() yt_menue->addItem(new CMenuSeparator(CMenuSeparator::LINE | CMenuSeparator::STRING, LOCALE_MOVIEBROWSER_YT_PENDING)); yt_menue->addItem(new CMenuForwarder(LOCALE_MOVIEBROWSER_YT_CANCEL, true, NULL, ytcache_selector, "cancel_all")); yt_menue->addItem(GenericMenuSeparator); + std::string progress; + if (dlstart && dltotal && dlnow) { + time_t done = time(NULL) - dlstart; + time_t left = ((dltotal - dlnow) * done)/dlnow; + progress = "(" + to_string(done) + "s/" + to_string(left) + "s)"; + } int i = 0; yt_pending_offset = yt_menue->getItemsCount(); for (std::vector::iterator it = yt_pending.begin(); it != yt_pending.end(); ++it, ++i) { - yt_menue->addItem(new CMenuForwarder((*it).file.Name.c_str(), true, NULL, ytcache_selector)); + yt_menue->addItem(new CMenuForwarder((*it).file.Name, true, progress.c_str(), ytcache_selector)); + progress = ""; } yt_pending_end = yt_menue->getItemsCount(); } diff --git a/src/system/ytcache.cpp b/src/system/ytcache.cpp index 774ec7026..86fc2b101 100644 --- a/src/system/ytcache.cpp +++ b/src/system/ytcache.cpp @@ -103,9 +103,11 @@ bool cYTCache::useCachedCopy(MI_MOVIE_INFO *mi) return false; } -int cYTCache::curlProgress(void *clientp, double /*dltotal*/, double /*dlnow*/, double /*ultotal*/, double /*ulnow*/) +int cYTCache::curlProgress(void *clientp, double dltotal, double dlnow, double /*ultotal*/, double /*ulnow*/) { cYTCache *caller = (cYTCache *) clientp; + caller->dltotal = dltotal; + caller->dlnow = dlnow; if (caller->cancelled) return 1; return 0; @@ -153,6 +155,9 @@ bool cYTCache::download(MI_MOVIE_INFO *mi) } } + dltotal = 0; + dlnow = 0; + dlstart = time(NULL); fprintf (stderr, "downloading %s to %s\n", mi->file.Url.c_str(), file.c_str()); CURLcode res = curl_easy_perform(curl); @@ -328,13 +333,28 @@ std::vector cYTCache::getCompleted(MI_MOVIE_INFO::miSource source return res; } -std::vector cYTCache::getPending(MI_MOVIE_INFO::miSource source) +std::vector cYTCache::getPending(MI_MOVIE_INFO::miSource source, double *p_dltotal, double *p_dlnow, time_t *p_start) { OpenThreads::ScopedLock m_lock(mutex); std::vector res; for (std::vector::iterator it = pending.begin(); it != pending.end(); ++it) if ((*it).source == source) res.push_back(*it); + if (res.size() > 0 && pending.front().source == source) { + if (p_dltotal) + *p_dltotal = dltotal; + if (p_dlnow) + *p_dlnow = dlnow; + if (p_start) + *p_start = dlstart; + } else { + if (p_dltotal) + *p_dltotal = 0; + if (p_dlnow) + *p_dlnow = 0; + if (p_start) + *p_start = 0; + } return res; } diff --git a/src/system/ytcache.h b/src/system/ytcache.h index 91dcd03e7..1e3fcba3a 100644 --- a/src/system/ytcache.h +++ b/src/system/ytcache.h @@ -47,6 +47,9 @@ class cYTCache static int curlProgress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow); bool compareMovieInfo(MI_MOVIE_INFO *a, MI_MOVIE_INFO *b); public: + double dltotal; + double dlnow; + time_t dlstart; static cYTCache *getInstance(); cYTCache(); ~cYTCache(); @@ -57,7 +60,7 @@ class cYTCache void cancelAll(MI_MOVIE_INFO::miSource = MI_MOVIE_INFO::YT); std::vector getCompleted(MI_MOVIE_INFO::miSource = MI_MOVIE_INFO::YT); std::vector getFailed(MI_MOVIE_INFO::miSource = MI_MOVIE_INFO::YT); - std::vector getPending(MI_MOVIE_INFO::miSource = MI_MOVIE_INFO::YT); + std::vector getPending(MI_MOVIE_INFO::miSource = MI_MOVIE_INFO::YT, double *p_dltotal = NULL, double *p_dlnow = NULL, time_t *p_start = NULL); void clearCompleted(MI_MOVIE_INFO *mi); void clearFailed(MI_MOVIE_INFO *mi); void clearCompleted(MI_MOVIE_INFO::miSource source = MI_MOVIE_INFO::YT);