Make it possible to hide background http downloads from progress bars

This commit is contained in:
Henrik Rydgard 2013-12-10 11:48:31 +01:00
parent 9a66b6e803
commit ecb83130ba
2 changed files with 12 additions and 4 deletions

View File

@ -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<Download> Downloader::StartDownload(const std::string &url, cons
return dl;
}
void Downloader::StartDownloadWithCallback(
std::shared_ptr<Download> Downloader::StartDownloadWithCallback(
const std::string &url,
const std::string &outfile,
std::function<void(Download &)> 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<float> Downloader::GetCurrentProgress() {
std::vector<float> 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;
}

View File

@ -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<Download> 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<void(Download &)> callback_;
};
@ -132,7 +138,7 @@ public:
std::shared_ptr<Download> StartDownload(const std::string &url, const std::string &outfile);
void StartDownloadWithCallback(
std::shared_ptr<Download> StartDownloadWithCallback(
const std::string &url,
const std::string &outfile,
std::function<void(Download &)> callback);