1
/** \file download_progress.h */ // -*-c++-*-
3
// Copyright (C) 2010-2011 Daniel Burrows
5
// This program is free software; you can redistribute it and/or
6
// modify it under the terms of the GNU General Public License as
7
// published by the Free Software Foundation; either version 2 of the
8
// License, or (at your option) any later version.
10
// This program is distributed in the hope that it will be useful, but
11
// WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
// General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program; see the file COPYING. If not, write to
17
// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
// Boston, MA 02111-1307, USA.
20
#ifndef APTITUDE_GENERIC_VIEWS_DOWNLOAD_PROGRESS_H
21
#define APTITUDE_GENERIC_VIEWS_DOWNLOAD_PROGRESS_H
24
#include <boost/optional.hpp>
25
#include <boost/variant.hpp>
27
#include <sigc++/slot.h>
36
/** \brief Interface for objects that can display the progress of
39
* Operates at a higher level and more cleanly than AcqProgress.
40
* See src/generic/controllers/acquire_download_progress.h for a
41
* bridge between the two worlds.
43
class download_progress
46
virtual ~download_progress();
48
/** \brief Represents the download progress of a single file. */
51
unsigned long current_size;
52
unsigned long total_size;
55
std::string description;
56
boost::optional<unsigned long> id;
60
file_progress(unsigned long _current_size,
61
unsigned long _total_size,
63
const std::string &_description,
64
const boost::optional<unsigned long> &_id,
65
const std::string &_mode)
66
: current_size(_current_size),
67
total_size(_total_size),
70
description(_description),
76
/** \brief Get the number of bytes that have been downloaded. */
77
unsigned long get_current_size() const { return current_size; }
79
/** \brief Get the total size of the file. */
80
unsigned long get_total_size() const { return total_size; }
82
/** \return \b true if the file has been successfully fetched
83
* according to the download backend.
85
bool get_complete() const { return complete; }
87
/** \brief Get a brief description of this file. */
88
const std::string &get_description() const { return description; }
90
/** \brief Get an integer that identifies this item.
92
* May be unset if the item doesn't have an ID yet.
94
const boost::optional<unsigned long> &get_id() const { return id; }
96
/** \brief Retrieve the current mode string for the file.
98
* If there is no mode, this will be an empty string.
100
const std::string &get_mode() const { return mode; }
102
bool operator==(const file_progress &other) const;
103
bool operator!=(const file_progress &other) const
105
return ! (*this == other);
109
/** \brief Represents the current progress of a download. */
113
typedef boost::variant<file_progress, std::string> worker_status;
116
const double download_rate;
117
const std::vector<worker_status> active_downloads;
118
const double fraction_complete;
119
const unsigned long time_remaining;
122
status(const double _download_rate,
123
const std::vector<worker_status> &_active_downloads,
124
const double _fraction_complete,
125
const unsigned long _time_remaining)
126
: download_rate(_download_rate),
127
active_downloads(_active_downloads),
128
fraction_complete(_fraction_complete),
129
time_remaining(_time_remaining)
133
/** \brief Get the current download speed in bytes per second. */
134
double get_download_rate() const { return download_rate; }
136
/** \brief Get the currently active download processes. */
137
const std::vector<worker_status> &get_active_downloads() const
139
return active_downloads;
142
/** \brief Get the proportional completion of the download (scale
145
double get_fraction_complete() const { return fraction_complete; }
147
/** \brief Get the estimated number of seconds until the download
150
unsigned long get_time_remaining() const { return time_remaining; }
152
bool operator==(const status &other) const;
153
bool operator!=(const status &other) const
155
return ! (*this == other);
159
/** \brief Update the download progress indicator.
161
* \param current_status The current status of the download.
163
* \return \b true to continue the download; \b false to abort it.
165
virtual bool update_progress(const status ¤t_status) = 0;
167
/** \brief Invoked when a file is starting to be downloaded.
169
* \param description A brief description of the file.
170
* \param id An integer identifying this file, or
171
* unset if it hasn't been assigned yet.
172
* \param file_size The size of the file; invalid if the
173
* file size isn't known.
175
virtual void file_started(const std::string &description,
176
const boost::optional<unsigned long> &id,
177
const boost::optional<unsigned long long> &file_size) = 0;
179
/** \brief Invoked when a file isn't even started because it was
180
* already downloaded.
182
* \param description A brief description of the file.
183
* \param id An integer identifying this file, or
184
* unset if it hasn't been assigned yet.
185
* \param file_size The size of the file; invalid if the
186
* file size isn't known.
189
virtual void file_already_downloaded(const std::string &description,
190
const boost::optional<unsigned long> &id,
191
const boost::optional<unsigned long long> &file_size) = 0;
193
/** \brief Invoked when a file fails to download.
195
* \param ignored True if the file was successfully fetched
198
* I"m not sure what this means, but it
199
* matters to existing download UIs.
200
* \param error A textual description of the error.
201
* \param description A brief description of the file.
202
* \param id An integer identifying this file, or
203
* unset if it hasn't been assigned yet.
205
virtual void error(bool ignored,
206
const std::string &error,
207
const std::string &description,
208
const boost::optional<unsigned long> &id) = 0;
210
/** \brief Invoked when something is done being downloaded.
212
* \param description A brief description of the file.
213
* \param id An integer identifying this file, or
214
* unset if it hasn't been assigned yet.
216
virtual void file_finished(const std::string &description,
217
const boost::optional<unsigned long> &id) = 0;
219
/** \brief Invoked when each stage of the download is complete.
221
* The whole download process might not be done; for instance,
222
* we might need to change to a new CD. complete() is invoked
223
* after the entire download finishes.
225
* \param fetched_bytes The number of bytes that were downloaded.
227
* \param elapsed_time How long (in seconds) the download lasted.
229
* \param latest_download_rate The final estimated download rate.
231
* \todo Should the parameters be incorporated into a status
232
* snapshot so that can be used instead?
234
virtual void done(double fetched_bytes,
235
unsigned long elapsed_time,
236
double latest_download_rate) = 0;
238
/** \brief Invoked when the install media should be replaced.
240
* \param media The label of the media to insert.
241
* \param drive The name of the drive in which the media
243
* \param k A continuation that must be invoked when
244
* the user has said whether it's OK to
245
* continue (possibly after media_change has
246
* returned). Pass \b true to continue the
247
* installation, or \b false to abort it.
249
virtual void media_change(const std::string &media,
250
const std::string &drive,
251
const sigc::slot1<void, bool> &k) = 0;
253
/** \brief Invoked when the whole download finishes.
255
* \param fetched_bytes The number of bytes that were downloaded.
257
* \param elapsed_time How long (in seconds) the download lasted.
259
* \param latest_download_rate The final estimated download rate.
261
virtual void complete(double fetched_bytes,
262
unsigned long elapsed_time,
263
double latest_download_rate) = 0;
266
std::ostream &operator<<(std::ostream &out,
267
const download_progress::file_progress &progress);
269
std::ostream &operator<<(std::ostream &out,
270
const download_progress::status &status);
274
#endif // APTITUDE_GENERIC_VIEWS_DOWNLOAD_PROGRESS_H