|
Lines 11-21
Link Here
|
| 11 |
#define ZMART_MEDIA_CALLBACKS_H |
11 |
#define ZMART_MEDIA_CALLBACKS_H |
| 12 |
|
12 |
|
| 13 |
#include <stdlib.h> |
13 |
#include <stdlib.h> |
| 14 |
#include <iostream> |
14 |
#include <ctime> |
| 15 |
|
15 |
|
| 16 |
#include <boost/format.hpp> |
16 |
#include <boost/format.hpp> |
| 17 |
|
17 |
|
| 18 |
#include "zypp/base/Logger.h" |
|
|
| 19 |
#include "zypp/ZYppCallbacks.h" |
18 |
#include "zypp/ZYppCallbacks.h" |
| 20 |
#include "zypp/Pathname.h" |
19 |
#include "zypp/Pathname.h" |
| 21 |
#include "zypp/KeyRing.h" |
20 |
#include "zypp/KeyRing.h" |
|
Lines 69-75
Link Here
|
| 69 |
}; |
68 |
}; |
| 70 |
|
69 |
|
| 71 |
// progress for downloading a file |
70 |
// progress for downloading a file |
| 72 |
struct DownloadProgressReportReceiver : public zypp::callback::ReceiveReport<zypp::media::DownloadProgressReport> |
71 |
struct DownloadProgressReportReceiver |
|
|
72 |
: public zypp::callback::ReceiveReport<zypp::media::DownloadProgressReport> |
| 73 |
{ |
73 |
{ |
| 74 |
DownloadProgressReportReceiver() |
74 |
DownloadProgressReportReceiver() |
| 75 |
: _gopts(Zypper::instance()->globalOpts()), _be_quiet(false) |
75 |
: _gopts(Zypper::instance()->globalOpts()), _be_quiet(false) |
|
Lines 77-82
Link Here
|
| 77 |
|
77 |
|
| 78 |
virtual void start( const zypp::Url & uri, zypp::Pathname localfile ) |
78 |
virtual void start( const zypp::Url & uri, zypp::Pathname localfile ) |
| 79 |
{ |
79 |
{ |
|
|
80 |
_last_reported = time(NULL); |
| 81 |
_last_drate_avg = -1; |
| 82 |
|
| 80 |
Out & out = Zypper::instance()->out(); |
83 |
Out & out = Zypper::instance()->out(); |
| 81 |
|
84 |
|
| 82 |
if (out.verbosity() < Out::HIGH && |
85 |
if (out.verbosity() < Out::HIGH && |
|
Lines 98-109
Link Here
|
| 98 |
} |
101 |
} |
| 99 |
|
102 |
|
| 100 |
//! \todo return false on SIGINT |
103 |
//! \todo return false on SIGINT |
| 101 |
virtual bool progress(int value, const zypp::Url & uri) |
104 |
virtual bool progress(int value, const zypp::Url & uri, double drate_avg, double drate_now) |
| 102 |
{ |
105 |
{ |
| 103 |
if (_be_quiet) |
106 |
if (_be_quiet) |
| 104 |
return true; |
107 |
return true; |
| 105 |
|
108 |
|
| 106 |
Zypper::instance()->out().dwnldProgress(uri, value); //! \todo add transfer rate |
109 |
// std::cout << "avg: " << drate_avg << " current: " << drate_now << std::endl; |
|
|
110 |
|
| 111 |
// don't report more often than 1 second |
| 112 |
time_t now = time(NULL); |
| 113 |
if (now > _last_reported) |
| 114 |
_last_reported = now; |
| 115 |
else |
| 116 |
return true; |
| 117 |
|
| 118 |
Zypper::instance()->out().dwnldProgress(uri, value, (long) drate_now); |
| 119 |
_last_drate_avg = drate_avg; |
| 107 |
return true; |
120 |
return true; |
| 108 |
} |
121 |
} |
| 109 |
|
122 |
|
|
Lines 112-118
Link Here
|
| 112 |
problem( const zypp::Url & uri, DownloadProgressReport::Error error, const std::string & description ) |
125 |
problem( const zypp::Url & uri, DownloadProgressReport::Error error, const std::string & description ) |
| 113 |
{ |
126 |
{ |
| 114 |
if (_be_quiet) |
127 |
if (_be_quiet) |
| 115 |
Zypper::instance()->out().dwnldProgressEnd(uri, true); |
128 |
Zypper::instance()->out().dwnldProgressEnd(uri, _last_drate_avg, true); |
| 116 |
Zypper::instance()->out().error(zcb_error2str(error, description)); |
129 |
Zypper::instance()->out().error(zcb_error2str(error, description)); |
| 117 |
|
130 |
|
| 118 |
return (Action) read_action_ari(PROMPT_ARI_MEDIA_PROBLEM, DownloadProgressReport::ABORT); |
131 |
return (Action) read_action_ari(PROMPT_ARI_MEDIA_PROBLEM, DownloadProgressReport::ABORT); |
|
Lines 124-135
Link Here
|
| 124 |
if (_be_quiet) |
137 |
if (_be_quiet) |
| 125 |
return; |
138 |
return; |
| 126 |
|
139 |
|
| 127 |
Zypper::instance()->out().dwnldProgressEnd(uri); |
140 |
Zypper::instance()->out().dwnldProgressEnd(uri, _last_drate_avg); |
| 128 |
} |
141 |
} |
| 129 |
|
142 |
|
| 130 |
private: |
143 |
private: |
| 131 |
const GlobalOptions & _gopts; |
144 |
const GlobalOptions & _gopts; |
| 132 |
bool _be_quiet; |
145 |
bool _be_quiet; |
|
|
146 |
time_t _last_reported; |
| 147 |
double _last_drate_avg; |
| 133 |
}; |
148 |
}; |
| 134 |
|
149 |
|
| 135 |
|
150 |
|