* @brief Writes the downloaded data to the disk. */
| 337 | * @brief Writes the downloaded data to the disk. |
| 338 | */ |
| 339 | void Downloader::saveFile(qint64 received, qint64 total) |
| 340 | { |
| 341 | Q_UNUSED(received); |
| 342 | Q_UNUSED(total); |
| 343 | |
| 344 | if (!m_reply) |
| 345 | return; |
| 346 | |
| 347 | // Check if we need to redirect |
| 348 | QUrl url = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); |
| 349 | if (!url.isEmpty()) { |
| 350 | startDownload(url); |
| 351 | return; |
| 352 | } |
| 353 | |
| 354 | // Save downloaded data to disk |
| 355 | QFile file(m_downloadDir.filePath(m_fileName + PARTIAL_DOWN)); |
| 356 | if (file.open(QIODevice::WriteOnly | QIODevice::Append)) { |
| 357 | file.write(m_reply->readAll()); |
| 358 | file.close(); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * @brief Calculates the appropriate size units (bytes, KB or MB) for the |