File indexing completed on 2024-12-22 04:57:54

0001 /*
0002     SPDX-License-Identifier: BSD-2-Clause
0003 */
0004 
0005 #include "o2/o2reply.h"
0006 
0007 O2Reply::O2Reply(QNetworkReply *r, int timeOut, QObject *parent)
0008     : QTimer(parent)
0009     , reply(r)
0010 {
0011     setSingleShot(true);
0012     connect(this, SIGNAL(error(QNetworkReply::NetworkError)), reply, SIGNAL(error(QNetworkReply::NetworkError)), Qt::QueuedConnection);
0013     connect(this, &QTimer::timeout, this, &O2Reply::onTimeOut, Qt::QueuedConnection);
0014     start(timeOut);
0015 }
0016 
0017 void O2Reply::onTimeOut()
0018 {
0019     Q_EMIT error(QNetworkReply::TimeoutError);
0020 }
0021 
0022 O2ReplyList::~O2ReplyList()
0023 {
0024     for (O2Reply *timedReply : std::as_const(replies_)) {
0025         delete timedReply;
0026     }
0027 }
0028 
0029 void O2ReplyList::add(QNetworkReply *reply)
0030 {
0031     if (reply && ignoreSslErrors()) {
0032         reply->ignoreSslErrors();
0033     }
0034     add(new O2Reply(reply));
0035 }
0036 
0037 void O2ReplyList::add(O2Reply *reply)
0038 {
0039     replies_.append(reply);
0040 }
0041 
0042 void O2ReplyList::remove(QNetworkReply *reply)
0043 {
0044     O2Reply *o2Reply = find(reply);
0045     if (o2Reply) {
0046         o2Reply->stop();
0047         (void)replies_.removeOne(o2Reply);
0048     }
0049 }
0050 
0051 O2Reply *O2ReplyList::find(QNetworkReply *reply)
0052 {
0053     for (O2Reply *timedReply : std::as_const(replies_)) {
0054         if (timedReply->reply == reply) {
0055             return timedReply;
0056         }
0057     }
0058     return nullptr;
0059 }
0060 
0061 bool O2ReplyList::ignoreSslErrors()
0062 {
0063     return ignoreSslErrors_;
0064 }
0065 
0066 void O2ReplyList::setIgnoreSslErrors(bool ignoreSslErrors)
0067 {
0068     ignoreSslErrors_ = ignoreSslErrors;
0069 }
0070 
0071 #include "moc_o2reply.cpp"