122 } |
115 } |
123 } |
116 } |
124 |
117 |
125 // Helper functions to get download attribute of a particular type. |
118 // Helper functions to get download attribute of a particular type. |
126 |
119 |
127 static int intAttribute(Download * download, DownloadAttribute which) |
120 static int intAttribute(WRT::Download * download, WRT::DownloadAttribute which) |
128 { |
121 { |
129 return download->getAttribute(which).toInt(); |
122 return download->attribute(which).toInt(); |
130 } |
123 } |
131 |
124 |
132 static uint uintAttribute(Download * download, DownloadAttribute which) |
125 static uint uintAttribute(WRT::Download * download, WRT::DownloadAttribute which) |
133 { |
126 { |
134 return download->getAttribute(which).toUInt(); |
127 return download->attribute(which).toUInt(); |
135 } |
128 } |
136 |
129 |
137 static QString stringAttribute(Download * download, DownloadAttribute which) |
130 static QString stringAttribute(WRT::Download * download, WRT::DownloadAttribute which) |
138 { |
131 { |
139 return download->getAttribute(which).toString(); |
132 return download->attribute(which).toString(); |
140 } |
133 } |
141 |
134 |
142 // Helper functions for reporting download attributes. |
135 // Helper functions for reporting download attributes. |
143 |
136 |
144 template<typename T> |
137 template<typename T> |
145 void debugDownloadAttribute( |
138 void debugDownloadAttribute( |
146 Download * download, |
139 WRT::Download * download, |
147 char const * name, |
140 char const * name, |
148 const T & value) |
141 const T & value) |
149 { |
142 { |
150 qDebug() << "DL" << download->id() << name << value; |
143 qDebug() << "DL" << download->id() << name << value; |
151 } |
144 } |
152 |
145 |
153 static void debugDownloadInt( |
146 static void debugDownloadInt( |
154 Download * download, |
147 WRT::Download * download, |
155 DownloadAttribute which, |
148 WRT::DownloadAttribute which, |
156 const char * name) |
149 const char * name) |
157 { |
150 { |
158 int value = intAttribute(download, which); |
151 int value = intAttribute(download, which); |
159 |
152 |
160 debugDownloadAttribute(download, name, value); |
153 debugDownloadAttribute(download, name, value); |
161 } |
154 } |
162 |
155 |
163 static void debugDownloadUInt( |
156 static void debugDownloadUInt( |
164 Download * download, |
157 WRT::Download * download, |
165 DownloadAttribute which, |
158 WRT::DownloadAttribute which, |
166 const char * name) |
159 const char * name) |
167 { |
160 { |
168 uint value = uintAttribute(download, which); |
161 uint value = uintAttribute(download, which); |
169 |
162 |
170 debugDownloadAttribute(download, name, value); |
163 debugDownloadAttribute(download, name, value); |
171 } |
164 } |
172 |
165 |
173 static void debugDownloadStr( |
166 static void debugDownloadStr( |
174 Download * download, |
167 WRT::Download * download, |
175 DownloadAttribute which, |
168 WRT::DownloadAttribute which, |
176 const char * name) |
169 const char * name) |
177 { |
170 { |
178 QString value = stringAttribute(download, which); |
171 QString value = stringAttribute(download, which); |
179 |
172 |
180 debugDownloadAttribute(download, name, value); |
173 debugDownloadAttribute(download, name, value); |
181 } |
174 } |
182 |
175 |
183 static void debugDownloadState(Download * download) |
176 static void debugDownloadState(WRT::Download * download) |
184 { |
177 { |
185 int num = intAttribute(download, DlDownloadState); |
178 int num = intAttribute(download, WRT::State); |
186 |
179 |
187 const char * state = downloadState(num); |
180 const char * state = downloadState(num); |
188 |
181 |
189 debugDownloadAttribute(download, "DownloadState", state); |
182 debugDownloadAttribute(download, "DownloadState", state); |
190 |
183 |
191 } |
184 } |
192 |
185 |
193 static void debugDownloadError(Download * download) |
186 static void debugDownloadError(WRT::Download * download) |
194 { |
187 { |
195 int num = intAttribute(download, DlLastError); |
188 int num = intAttribute(download, WRT::LastError); |
196 |
189 |
197 const char * error = downloadError(static_cast<QNetworkReply::NetworkError>(num)); |
190 const char * error = downloadError(static_cast<QNetworkReply::NetworkError>(num)); |
198 |
191 |
199 debugDownloadAttribute(download, "DownloadError", error); |
192 debugDownloadAttribute(download, "DownloadError", error); |
200 } |
193 } |
201 |
194 |
202 // Helper function for implementing DownloadProxyData::debug(). |
195 // Helper function for implementing DownloadProxyData::debug(). |
203 |
196 |
204 static void debugDownload(Download * download) |
197 static void debugDownload(WRT::Download * download) |
205 { |
198 { |
206 debugDownloadState(download); |
199 debugDownloadState(download); |
207 |
200 |
208 debugDownloadError(download); |
201 debugDownloadError(download); |
209 |
202 |
210 debugDownloadStr(download, |
203 debugDownloadStr(download, |
211 DlLastErrorString, |
204 WRT::LastErrorString, |
212 "LastErrorString"); |
205 "LastErrorString"); |
213 |
206 |
214 debugDownloadStr(download, |
207 debugDownloadStr(download, |
215 DlSourceUrl, |
208 WRT::SourceUrl, |
216 "SourceUrl"); |
209 "SourceUrl"); |
217 |
210 |
218 debugDownloadStr(download, |
211 debugDownloadStr(download, |
219 DlContentType, |
212 WRT::ContentType, |
220 "ContentType"); |
213 "ContentType"); |
221 |
214 |
222 debugDownloadStr(download, |
215 debugDownloadStr(download, |
223 DlDestPath, |
216 WRT::DestinationPath, |
224 "DestPath"); |
217 "DestinationPath"); |
225 |
218 |
226 debugDownloadStr(download, |
219 debugDownloadStr(download, |
227 DlFileName, |
220 WRT::FileName, |
228 "FileName"); |
221 "FileName"); |
229 |
222 |
230 debugDownloadInt(download, |
223 debugDownloadInt(download, |
231 DlDownloadedSize, |
224 WRT::DownloadedSize, |
232 "DownloadedSize"); |
225 "DownloadedSize"); |
233 |
226 |
234 debugDownloadInt(download, |
227 debugDownloadInt(download, |
235 DlTotalSize, |
228 WRT::TotalSize, |
236 "TotalSize"); |
229 "TotalSize"); |
237 |
230 |
238 debugDownloadInt(download, |
231 debugDownloadInt(download, |
239 DlLastPausedSize, |
232 WRT::LastPausedSize, |
240 "LastPausedSize"); |
233 "LastPausedSize"); |
241 |
234 |
242 debugDownloadInt(download, |
235 debugDownloadInt(download, |
243 DlPercentage, |
236 WRT::Percentage, |
244 "Percentage"); |
237 "Percentage"); |
245 |
238 |
246 debugDownloadStr(download, |
239 debugDownloadStr(download, |
247 DlStartTime, |
240 WRT::StartTime, |
248 "StartTime"); |
241 "StartTime"); |
249 |
242 |
250 debugDownloadStr(download, |
243 debugDownloadStr(download, |
251 DlEndTime, |
244 WRT::EndTime, |
252 "EndTime"); |
245 "EndTime"); |
253 |
246 |
254 debugDownloadUInt(download, |
247 debugDownloadUInt(download, |
255 DlElapsedTime, |
248 WRT::ElapsedTime, |
256 "ElapsedTime"); |
249 "ElapsedTime"); |
257 |
250 |
258 debugDownloadStr(download, |
251 debugDownloadStr(download, |
259 DlRemainingTime, |
252 WRT::RemainingTime, |
260 "RemainingTime"); |
253 "RemainingTime"); |
261 |
254 |
262 debugDownloadStr(download, |
255 debugDownloadStr(download, |
263 DlSpeed, |
256 WRT::Speed, |
264 "Speed"); |
257 "Speed"); |
265 |
258 |
266 debugDownloadInt(download, |
259 debugDownloadInt(download, |
267 DlProgressInterval, |
260 WRT::ProgressInterval, |
268 "ProgressInterval"); |
261 "ProgressInterval"); |
269 } |
262 } |
270 |
263 #endif |
271 #endif // USE_DOWNLOAD_MANAGER |
|
272 |
264 |
273 void DownloadProxyData::debug() |
265 void DownloadProxyData::debug() |
274 { |
266 { |
275 #ifdef USE_DOWNLOAD_MANAGER |
267 #ifdef USE_DOWNLOAD_MANAGER |
276 if (m_download == 0) { |
268 if (m_download == 0) { |
277 return; |
269 return; |
278 } |
270 } |
279 |
271 |
280 int id = m_download->id(); |
272 int id = m_download->id(); |
281 |
273 |
282 DownloadManager * manager = m_download->downloadManager(); |
274 WRT::DownloadManager * manager = m_download->downloadManager(); |
283 |
275 |
284 Download * download = manager->findDownload(id); |
276 WRT::Download * download = manager->findDownload(id); |
285 |
277 |
286 if (download != 0) { |
278 if (download != 0) { |
287 debugDownload(download); |
279 debugDownload(download); |
288 } |
280 } |
289 #endif // USE_DOWNLOAD_MANAGER |
281 #endif |
290 } |
282 } |
291 |
283 |
292 void DownloadProxyData::remove() |
284 void DownloadProxyData::remove() |
293 { |
285 { |
294 #ifdef USE_DOWNLOAD_MANAGER |
286 #ifdef USE_DOWNLOAD_MANAGER |
295 if (m_download == 0) { |
287 if (m_download == 0) { |
296 return; |
288 return; |
297 } |
289 } |
298 |
290 |
299 DownloadManager * manager = m_download->downloadManager(); |
291 WRT::DownloadManager * manager = m_download->downloadManager(); |
300 |
292 |
301 manager->removeOne(m_download); |
293 manager->removeOne(m_download); |
302 |
294 |
303 // Download is no longer valid. |
295 // Download is no longer valid. |
304 |
296 |
305 m_download = 0; |
297 m_download = 0; |
306 #endif // USE_DOWNLOAD_MANAGER |
298 #endif |
307 } |
299 } |
308 |
300 |
309 QString DownloadProxyData::fileName() |
301 QString DownloadProxyData::fileName() |
310 { |
302 { |
311 #ifdef USE_DOWNLOAD_MANAGER |
303 #ifdef USE_DOWNLOAD_MANAGER |
312 if (m_download == 0) { |
304 if (m_download == 0) { |
313 return QString(); |
305 return QString(); |
314 } |
306 } |
315 |
307 |
316 return stringAttribute(m_download, DlFileName); |
308 return stringAttribute(m_download, WRT::FileName); |
317 #else // USE_DOWNLOAD_MANAGER |
309 #else |
318 return QString(); |
310 return QString(); |
319 #endif // USE_DOWNLOAD_MANAGER |
311 #endif |
320 } |
312 } |