| 89 | } |
| 90 | |
| 91 | void Download::executeTask() |
| 92 | { |
| 93 | setStatus(tr("Downloading %1").arg(m_url.toString())); |
| 94 | |
| 95 | if (getState() == Task::State::AbortedByUser) { |
| 96 | qWarning() << "Attempt to start an aborted Download:" << m_url.toString(); |
| 97 | emitAborted(); |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | QNetworkRequest request(m_url); |
| 102 | m_state = m_sink->init(request); |
| 103 | switch (m_state) { |
| 104 | case State::Succeeded: |
| 105 | emit succeeded(); |
| 106 | qDebug() << "Download cache hit " << m_url.toString(); |
| 107 | return; |
| 108 | case State::Running: |
| 109 | qDebug() << "Downloading " << m_url.toString(); |
| 110 | break; |
| 111 | case State::Inactive: |
| 112 | case State::Failed: |
| 113 | emitFailed(); |
| 114 | return; |
| 115 | case State::AbortedByUser: |
| 116 | emitAborted(); |
| 117 | return; |
| 118 | } |
| 119 | |
| 120 | if (APPLICATION->capabilities() & Application::SupportsFlame |
| 121 | && request.url().host().contains("api.curseforge.com")) { |
| 122 | request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8()); |
| 123 | } |
| 124 | else { |
| 125 | request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8()); |
| 126 | } |
| 127 | |
| 128 | QNetworkReply* rep = m_network->get(request); |
| 129 | |
| 130 | m_reply.reset(rep); |
| 131 | connect(rep, &QNetworkReply::downloadProgress, this, &Download::downloadProgress); |
| 132 | connect(rep, &QNetworkReply::finished, this, &Download::downloadFinished); |
| 133 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 134 | connect(rep, SIGNAL(errorOccurred(QNetworkReply::NetworkError)), SLOT(downloadError(QNetworkReply::NetworkError))); |
| 135 | #else |
| 136 | connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(downloadError(QNetworkReply::NetworkError))); |
| 137 | #endif |
| 138 | connect(rep, &QNetworkReply::sslErrors, this, &Download::sslErrors); |
| 139 | connect(rep, &QNetworkReply::readyRead, this, &Download::downloadReadyRead); |
| 140 | } |
| 141 | |
| 142 | void Download::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) |
| 143 | { |
nothing calls this directly
no test coverage detected