From ecb83130ba112c39a1b7f2582c812e0984a798b0 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Tue, 10 Dec 2013 11:48:31 +0100 Subject: [PATCH] Make it possible to hide background http downloads from progress bars --- net/http_client.cpp | 8 +++++--- net/http_client.h | 8 +++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/net/http_client.cpp b/net/http_client.cpp index 6acbf5c4b7..f75a86d0a8 100644 --- a/net/http_client.cpp +++ b/net/http_client.cpp @@ -310,7 +310,7 @@ int Client::POST(const char *resource, const std::string &data, Buffer *output) } Download::Download(const std::string &url, const std::string &outfile) - : progress_(0.0f), url_(url), outfile_(outfile), resultCode_(0), completed_(false), failed_(false), cancelled_(false) { + : progress_(0.0f), url_(url), outfile_(outfile), resultCode_(0), completed_(false), failed_(false), cancelled_(false), hidden_(false) { } Download::~Download() { @@ -392,7 +392,7 @@ std::shared_ptr Downloader::StartDownload(const std::string &url, cons return dl; } -void Downloader::StartDownloadWithCallback( +std::shared_ptr Downloader::StartDownloadWithCallback( const std::string &url, const std::string &outfile, std::function callback) { @@ -400,6 +400,7 @@ void Downloader::StartDownloadWithCallback( dl->SetCallback(callback); downloads_.push_back(dl); dl->Start(dl); + return dl; } void Downloader::Update() { @@ -416,7 +417,8 @@ void Downloader::Update() { std::vector Downloader::GetCurrentProgress() { std::vector progress; for (size_t i = 0; i < downloads_.size(); i++) { - progress.push_back(downloads_[i]->Progress()); + if (!downloads_[i]->IsHidden()) + progress.push_back(downloads_[i]->Progress()); } return progress; } diff --git a/net/http_client.h b/net/http_client.h index dd1e070764..0a88082d58 100644 --- a/net/http_client.h +++ b/net/http_client.h @@ -108,6 +108,11 @@ public: } } + // Just metadata. Convenient for download managers, for example, if set, + // Downloader::GetCurrentProgress won't return it in the results. + bool IsHidden() const { return hidden_; } + void SetHidden(bool hidden) { hidden_ = hidden; } + private: void Do(std::shared_ptr self); // Actually does the download. Runs on thread. void SetFailed(int code); @@ -119,6 +124,7 @@ private: bool completed_; bool failed_; volatile bool cancelled_; + bool hidden_; std::function callback_; }; @@ -132,7 +138,7 @@ public: std::shared_ptr StartDownload(const std::string &url, const std::string &outfile); - void StartDownloadWithCallback( + std::shared_ptr StartDownloadWithCallback( const std::string &url, const std::string &outfile, std::function callback);