Upload the current report for updating an existing report
| 192 | |
| 193 | // Upload the current report for updating an existing report |
| 194 | bool VulkanDatabase::postReportForUpdate(VulkanDeviceInfo &device, int reportId, QString &updateLog) |
| 195 | { |
| 196 | manager = new QNetworkAccessManager(nullptr); |
| 197 | QHttpMultiPart* multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); |
| 198 | QHttpPart jsonPart; |
| 199 | jsonPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"data\"; filename=\"update_report.json\"")); |
| 200 | QJsonDocument doc(device.toJson("", "")); |
| 201 | jsonPart.setBody(doc.toJson()); |
| 202 | multiPart->append(jsonPart); |
| 203 | QUrl qurl(databaseUrl + "api/v4/updatereport.php?reportid=" + QString::number(reportId)); |
| 204 | QNetworkRequest request(qurl); |
| 205 | QNetworkReply* reply = manager->post(request, multiPart); |
| 206 | multiPart->setParent(reply); |
| 207 | QEventLoop loop; |
| 208 | connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); |
| 209 | loop.exec(QEventLoop::ExcludeUserInputEvents); |
| 210 | bool result = false; |
| 211 | if (reply->error() == QNetworkReply::NoError) |
| 212 | { |
| 213 | QJsonDocument response = QJsonDocument::fromJson(reply->readAll()); |
| 214 | if (response.isObject() && response.object()["log"].isArray()) { |
| 215 | QJsonArray logArray = response.object()["log"].toArray(); |
| 216 | foreach(const QJsonValue logEntry, logArray) { |
| 217 | updateLog += logEntry.toString() + "\n"; |
| 218 | } |
| 219 | } |
| 220 | result = true; |
| 221 | } |
| 222 | else |
| 223 | { |
| 224 | QString err(reply->errorString()); |
| 225 | result = false; |
| 226 | } |
| 227 | delete(manager); |
| 228 | return result; |
| 229 | } |
no test coverage detected