| 200 | } |
| 201 | |
| 202 | void NetworkReplyModel::objectCreated(QObject *obj) |
| 203 | { |
| 204 | if (auto nam = qobject_cast<QNetworkAccessManager *>(obj)) { |
| 205 | beginInsertRows({}, m_nodes.size(), m_nodes.size()); |
| 206 | NAMNode node; |
| 207 | node.nam = nam; |
| 208 | node.displayName = Util::displayString(nam); |
| 209 | m_nodes.push_back(node); |
| 210 | endInsertRows(); |
| 211 | |
| 212 | connect( |
| 213 | nam, &QNetworkAccessManager::finished, this, [this, nam](QNetworkReply *reply) { replyFinished(reply, nam); }, Qt::DirectConnection); |
| 214 | #ifndef QT_NO_SSL |
| 215 | connect( |
| 216 | nam, &QNetworkAccessManager::encrypted, this, [this, nam](QNetworkReply *reply) { replyEncrypted(reply, nam); }, Qt::DirectConnection); |
| 217 | connect(nam, &QNetworkAccessManager::sslErrors, this, [this, nam](QNetworkReply *reply, const QList<QSslError> &errors) { replySslErrors(reply, errors, nam); }); |
| 218 | #endif |
| 219 | } |
| 220 | |
| 221 | if (auto reply = qobject_cast<QNetworkReply *>(obj)) { |
| 222 | auto nam = reply->manager(); |
| 223 | auto namIt = std::find_if(m_nodes.begin(), m_nodes.end(), [nam](const NAMNode &node) { |
| 224 | return node.nam == nam; |
| 225 | }); |
| 226 | |
| 227 | if (namIt == m_nodes.end()) { |
| 228 | // TODO |
| 229 | return; |
| 230 | } |
| 231 | |
| 232 | ReplyNode replyNode; |
| 233 | replyNode.reply = reply; |
| 234 | replyNode.displayName = Util::displayString(reply); |
| 235 | replyNode.op = reply->operation(); |
| 236 | replyNode.url = reply->url(); |
| 237 | if (reply->isFinished()) { |
| 238 | replyNode.state |= NetworkReply::Finished; |
| 239 | replyNode.duration = 0; |
| 240 | } else { |
| 241 | replyNode.duration = m_time.elapsed(); |
| 242 | } |
| 243 | replyNode.contentType = contentType(reply->header(QNetworkRequest::ContentTypeHeader)); |
| 244 | updateReplyNode(nam, replyNode); |
| 245 | |
| 246 | if (m_captureResponse) { |
| 247 | connect( |
| 248 | reply, &QNetworkReply::downloadProgress, this, [this, reply, nam](qint64 received, qint64 total) { replyProgressSync(reply, received, total, nam); }, Qt::DirectConnection); |
| 249 | if (!prioritizeLatestConnection(reply, QMetaObject::normalizedSignature("downloadProgress(qint64,qint64)"), this)) { |
| 250 | qWarning() << "Failed to prioritize our slot, capturing network response might not work"; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | // capture nam, as we cannot deref reply anymore when this triggers |
| 255 | connect(reply, &QNetworkReply::downloadProgress, this, [this, reply, nam](qint64 received, qint64 total) { replyProgress(reply, received, total, nam); }); |
| 256 | connect(reply, &QNetworkReply::uploadProgress, this, [this, reply, nam](qint64 received, qint64 total) { replyProgress(reply, received, total, nam); }); |
| 257 | connect(reply, &QNetworkReply::destroyed, this, [this, reply, nam]() { replyDeleted(reply, nam); }); |
| 258 | } |
| 259 | } |
nothing calls this directly
no test coverage detected