Changeset View
Changeset View
Standalone View
Standalone View
host/downloadjob.cpp
Show First 20 Lines • Show All 140 Lines • ▼ Show 20 Line(s) | 135 | if (endTime.isValid()) { | |||
---|---|---|---|---|---|
141 | if (remainingTime > 0) { | 141 | if (remainingTime > 0) { | ||
142 | speed = remainingBytes / remainingTime; | 142 | speed = remainingBytes / remainingTime; | ||
143 | } | 143 | } | ||
144 | } | 144 | } | ||
145 | 145 | | |||
146 | emitSpeed(speed); | 146 | emitSpeed(speed); | ||
147 | } | 147 | } | ||
148 | 148 | | |||
149 | // TODO use the estimatedEndTime to calculate transfer speed | 149 | const QString error = payload.value(QStringLiteral("error")).toString(); | ||
150 | 150 | if (!error.isEmpty()) { | |||
151 | it = payload.constFind(QStringLiteral("state")); | | |||
152 | if (it != end) { | | |||
153 | const QString status = it->toString(); | | |||
154 | if (status == QLatin1String("in_progress")) { | | |||
155 | | ||||
156 | } else if (status == QLatin1String("interrupted")) { | | |||
157 | | ||||
158 | const QString &error = payload.value(QStringLiteral("error")).toString(); | | |||
159 | | ||||
160 | if (error == QLatin1String("USER_CANCELED") | 151 | if (error == QLatin1String("USER_CANCELED") | ||
161 | || error == QLatin1String("USER_SHUTDOWN")) { | 152 | || error == QLatin1String("USER_SHUTDOWN")) { | ||
162 | setError(KIO::ERR_USER_CANCELED); // will keep Notification applet from showing a "finished"/error message | 153 | setError(KIO::ERR_USER_CANCELED); // will keep Notification applet from showing a "finished"/error message | ||
163 | emitResult(); | 154 | emitResult(); | ||
164 | return; | 155 | return; | ||
165 | } | 156 | } | ||
166 | 157 | | |||
167 | // value is a QVariant so we can be lazy and support both KIO errors and custom test | 158 | // value is a QVariant so we can be lazy and support both KIO errors and custom test | ||
168 | // if QVariant is an int: use that as KIO error | 159 | // if QVariant is an int: use that as KIO error | ||
169 | // if QVariant is a QString: set UserError and message | 160 | // if QVariant is a QString: set UserError and message | ||
fvogt: You could change this into
```QString error = payload.value(QStringLiteral("error")).toString… | |||||
170 | static const QHash<QString, QString> errors { | 161 | static const QHash<QString, QString> errors { | ||
171 | // for a list of these error codes *and their meaning* instead of looking at browser | 162 | // for a list of these error codes *and their meaning* instead of looking at browser | ||
172 | // extension docs, check out Chromium's source code: download_interrupt_reason_values.h | 163 | // extension docs, check out Chromium's source code: download_interrupt_reason_values.h | ||
173 | {QStringLiteral("FILE_ACCESS_DENIED"), i18n("Access denied.")}, // KIO::ERR_ACCESS_DENIED | 164 | {QStringLiteral("FILE_ACCESS_DENIED"), i18n("Access denied.")}, // KIO::ERR_ACCESS_DENIED | ||
174 | {QStringLiteral("FILE_NO_SPACE"), i18n("Insufficient free space.")}, // KIO::ERR_DISK_FULL | 165 | {QStringLiteral("FILE_NO_SPACE"), i18n("Insufficient free space.")}, // KIO::ERR_DISK_FULL | ||
175 | {QStringLiteral("FILE_NAME_TOO_LONG"), i18n("The file name you have chosen is too long.")}, | 166 | {QStringLiteral("FILE_NAME_TOO_LONG"), i18n("The file name you have chosen is too long.")}, | ||
176 | {QStringLiteral("FILE_TOO_LARGE"), i18n("The file is too large to be downloaded.")}, | 167 | {QStringLiteral("FILE_TOO_LARGE"), i18n("The file is too large to be downloaded.")}, | ||
177 | // haha | 168 | // haha | ||
Show All 24 Lines | |||||
202 | } | 193 | } | ||
203 | 194 | | |||
204 | // KIO::Error doesn't have a UserDefined one, let's just use magic numbers then | 195 | // KIO::Error doesn't have a UserDefined one, let's just use magic numbers then | ||
205 | // TODO at least set the KIO::Errors that we do have | 196 | // TODO at least set the KIO::Errors that we do have | ||
206 | setError(1000); | 197 | setError(1000); | ||
207 | setErrorText(errorValue); | 198 | setErrorText(errorValue); | ||
208 | 199 | | |||
209 | emitResult(); | 200 | emitResult(); | ||
210 | | ||||
211 | return; | 201 | return; | ||
212 | } else if (status == QLatin1String("complete")) { | 202 | } | ||
203 | | ||||
204 | it = payload.constFind(QStringLiteral("state")); | ||||
205 | if (it != end) { | ||||
206 | const QString state = it->toString(); | ||||
207 | | ||||
208 | // We ignore "interrupted" state and only cancel if we get supplied an "error" | ||||
209 | if (state == QLatin1String("complete")) { | ||||
210 | setError(KJob::NoError); | ||||
213 | emitResult(); | 211 | emitResult(); | ||
fvogt: Same here as for error above. | |||||
214 | return; | 212 | return; | ||
215 | } | 213 | } | ||
216 | } | 214 | } | ||
217 | 215 | | |||
218 | if (descriptionDirty) { | 216 | if (descriptionDirty) { | ||
219 | updateDescription(); | 217 | updateDescription(); | ||
220 | } | 218 | } | ||
221 | } | 219 | } | ||
222 | 220 | | |||
223 | void DownloadJob::updateDescription() | 221 | void DownloadJob::updateDescription() | ||
224 | { | 222 | { | ||
225 | description(this, i18nc("Job heading, like 'Copying'", "Downloading"), | 223 | description(this, i18nc("Job heading, like 'Copying'", "Downloading"), | ||
226 | qMakePair<QString, QString>(i18nc("The URL being downloaded", "Source"), (m_finalUrl.isValid() ? m_finalUrl : m_url).toDisplayString()), | 224 | qMakePair<QString, QString>(i18nc("The URL being downloaded", "Source"), (m_finalUrl.isValid() ? m_finalUrl : m_url).toDisplayString()), | ||
227 | qMakePair<QString, QString>(i18nc("The location being downloaded to", "Destination"), m_destination.toLocalFile()) | 225 | qMakePair<QString, QString>(i18nc("The location being downloaded to", "Destination"), m_destination.toLocalFile()) | ||
228 | ); | 226 | ); | ||
229 | } | 227 | } |
You could change this into