~ubuntu-branches/ubuntu/vivid/aptitude/vivid

« back to all changes in this revision

Viewing changes to src/generic/views/download_progress.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2011-06-22 12:32:56 UTC
  • mfrom: (1.8.6 sid)
  • Revision ID: james.westby@ubuntu.com-20110622123256-8aox9w9ch3x72dci
Tags: 0.6.4-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/05aptitude: never autoremove kernels
  - drop aptitude-doc to Suggests
  - 03_branding.dpatch: ubuntu branding
  - 04_changelog.dpatch: take changelogs from changelogs.ubuntu.com
  - 09_ubuntu_fortify_source.dpatch: Suppress a number of warnings (turned
    into errors by -Werror) triggered by Ubuntu's default of
    -D_FORTIFY_SOURCE=2.
  - 11_ubuntu_uses_sudo.dpatch: fix status line of 'Become root' menu entry
    to not refer to su.
  - 12_point_manpage_to_doc_package.dpatch: point Finnish manpage to the
    correct place for further info
  - 14_html2text_preferred.dpatch: switch back to html2text in favor of
    elinks, since html2text is in main and elinks isn't.
* dropped 01_intltool_update.dpatch
* updated 15_ftbfs_new_apt

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** \file download_progress.h */    // -*-c++-*-
 
2
 
 
3
// Copyright (C) 2010-2011 Daniel Burrows
 
4
//
 
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.
 
9
//
 
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.
 
14
//
 
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.
 
19
 
 
20
#ifndef APTITUDE_GENERIC_VIEWS_DOWNLOAD_PROGRESS_H
 
21
#define APTITUDE_GENERIC_VIEWS_DOWNLOAD_PROGRESS_H
 
22
 
 
23
// System includes:
 
24
#include <boost/optional.hpp>
 
25
#include <boost/variant.hpp>
 
26
 
 
27
#include <sigc++/slot.h>
 
28
 
 
29
#include <string>
 
30
#include <vector>
 
31
 
 
32
namespace aptitude
 
33
{
 
34
  namespace views
 
35
  {
 
36
    /** \brief Interface for objects that can display the progress of
 
37
     *  a download.
 
38
     *
 
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.
 
42
     */
 
43
    class download_progress
 
44
    {
 
45
    public:
 
46
      virtual ~download_progress();
 
47
 
 
48
      /** \brief Represents the download progress of a single file. */
 
49
      class file_progress
 
50
      {
 
51
        unsigned long current_size;
 
52
        unsigned long total_size;
 
53
 
 
54
        bool complete;
 
55
        std::string description;
 
56
        boost::optional<unsigned long> id;
 
57
        std::string mode;
 
58
 
 
59
      public:
 
60
        file_progress(unsigned long _current_size,
 
61
                      unsigned long _total_size,
 
62
                      bool _complete,
 
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),
 
68
 
 
69
            complete(_complete),
 
70
            description(_description),
 
71
            id(_id),
 
72
            mode(_mode)
 
73
        {
 
74
        }
 
75
 
 
76
        /** \brief Get the number of bytes that have been downloaded. */
 
77
        unsigned long get_current_size() const { return current_size; }
 
78
 
 
79
        /** \brief Get the total size of the file. */
 
80
        unsigned long get_total_size() const { return total_size; }
 
81
 
 
82
        /** \return \b true if the file has been successfully fetched
 
83
         *  according to the download backend.
 
84
         */
 
85
        bool get_complete() const { return complete; }
 
86
 
 
87
        /** \brief Get a brief description of this file. */
 
88
        const std::string &get_description() const { return description; }
 
89
 
 
90
        /** \brief Get an integer that identifies this item.
 
91
         *
 
92
         *  May be unset if the item doesn't have an ID yet.
 
93
         */
 
94
        const boost::optional<unsigned long> &get_id() const { return id; }
 
95
 
 
96
        /** \brief Retrieve the current mode string for the file.
 
97
         *
 
98
         *  If there is no mode, this will be an empty string.
 
99
         */
 
100
        const std::string &get_mode() const { return mode; }
 
101
 
 
102
        bool operator==(const file_progress &other) const;
 
103
        bool operator!=(const file_progress &other) const
 
104
        {
 
105
          return ! (*this == other);
 
106
        }
 
107
      };
 
108
 
 
109
      /** \brief Represents the current progress of a download. */
 
110
      class status
 
111
      {
 
112
      public:
 
113
        typedef boost::variant<file_progress, std::string> worker_status;
 
114
 
 
115
      private:
 
116
        const double download_rate;
 
117
        const std::vector<worker_status> active_downloads;
 
118
        const double fraction_complete;
 
119
        const unsigned long time_remaining;
 
120
 
 
121
      public:
 
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)
 
130
        {
 
131
        }
 
132
 
 
133
        /** \brief Get the current download speed in bytes per second. */
 
134
        double get_download_rate() const { return download_rate; }
 
135
 
 
136
        /** \brief Get the currently active download processes. */
 
137
        const std::vector<worker_status> &get_active_downloads() const
 
138
        {
 
139
          return active_downloads;
 
140
        }
 
141
 
 
142
        /** \brief Get the proportional completion of the download (scale
 
143
         *  of 0 to 1).
 
144
         */
 
145
        double get_fraction_complete() const { return fraction_complete; }
 
146
 
 
147
        /** \brief Get the estimated number of seconds until the download
 
148
         *  completes.
 
149
         */
 
150
        unsigned long get_time_remaining() const { return time_remaining; }
 
151
 
 
152
        bool operator==(const status &other) const;
 
153
        bool operator!=(const status &other) const
 
154
        {
 
155
          return ! (*this == other);
 
156
        }
 
157
      };
 
158
 
 
159
      /** \brief Update the download progress indicator.
 
160
       *
 
161
       *  \param current_status    The current status of the download.
 
162
       *
 
163
       *  \return \b true to continue the download; \b false to abort it.
 
164
       */
 
165
      virtual bool update_progress(const status &current_status) = 0;
 
166
 
 
167
      /** \brief Invoked when a file is starting to be downloaded.
 
168
       *
 
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.
 
174
       */
 
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;
 
178
 
 
179
      /** \brief Invoked when a file isn't even started because it was
 
180
       *  already downloaded.
 
181
       *
 
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.
 
187
       */
 
188
 
 
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;
 
192
 
 
193
      /** \brief Invoked when a file fails to download.
 
194
       *
 
195
       *  \param ignored        True if the file was successfully fetched
 
196
       *                        anyway.
 
197
       *
 
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.
 
204
       */
 
205
      virtual void error(bool ignored,
 
206
                         const std::string &error,
 
207
                         const std::string &description,
 
208
                         const boost::optional<unsigned long> &id) = 0;
 
209
 
 
210
      /** \brief Invoked when something is done being downloaded.
 
211
       *
 
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.
 
215
       */
 
216
      virtual void file_finished(const std::string &description,
 
217
                                 const boost::optional<unsigned long> &id) = 0;
 
218
 
 
219
      /** \brief Invoked when each stage of the download is complete.
 
220
       *
 
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.
 
224
       *
 
225
       *  \param fetched_bytes  The number of bytes that were downloaded.
 
226
       *
 
227
       *  \param elapsed_time   How long (in seconds) the download lasted.
 
228
       *
 
229
       *  \param latest_download_rate  The final estimated download rate.
 
230
       *
 
231
       * \todo Should the parameters be incorporated into a status
 
232
       * snapshot so that can be used instead?
 
233
       */
 
234
      virtual void done(double fetched_bytes,
 
235
                        unsigned long elapsed_time,
 
236
                        double latest_download_rate) = 0;
 
237
 
 
238
      /** \brief Invoked when the install media should be replaced.
 
239
       *
 
240
       *  \param media          The label of the media to insert.
 
241
       *  \param drive          The name of the drive in which the media
 
242
       *                        should be placed.
 
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.
 
248
       */
 
249
      virtual void media_change(const std::string &media,
 
250
                                const std::string &drive,
 
251
                                const sigc::slot1<void, bool> &k) = 0;
 
252
 
 
253
      /** \brief Invoked when the whole download finishes.
 
254
       *
 
255
       *  \param fetched_bytes  The number of bytes that were downloaded.
 
256
       *
 
257
       *  \param elapsed_time   How long (in seconds) the download lasted.
 
258
       *
 
259
       *  \param latest_download_rate  The final estimated download rate.
 
260
       */
 
261
      virtual void complete(double fetched_bytes,
 
262
                            unsigned long elapsed_time,
 
263
                            double latest_download_rate) = 0;
 
264
    };
 
265
 
 
266
    std::ostream &operator<<(std::ostream &out,
 
267
                             const download_progress::file_progress &progress);
 
268
 
 
269
    std::ostream &operator<<(std::ostream &out,
 
270
                             const download_progress::status &status);
 
271
  }
 
272
}
 
273
 
 
274
#endif // APTITUDE_GENERIC_VIEWS_DOWNLOAD_PROGRESS_H