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

0001 /*
0002     SPDX-License-Identifier: BSD-2-Clause
0003 */
0004 
0005 #pragma once
0006 
0007 #include <QList>
0008 #include <QNetworkReply>
0009 #include <QTimer>
0010 
0011 /// A network request/reply pair that can time out.
0012 class O2Reply : public QTimer
0013 {
0014     Q_OBJECT
0015 
0016 public:
0017     O2Reply(QNetworkReply *reply, int timeOut = 60 * 1000, QObject *parent = nullptr);
0018 
0019 Q_SIGNALS:
0020     void error(QNetworkReply::NetworkError);
0021 
0022 public Q_SLOTS:
0023     /// When time out occurs, the QNetworkReply's error() signal is triggered.
0024     void onTimeOut();
0025 
0026 public:
0027     QNetworkReply *reply = nullptr;
0028 };
0029 
0030 /// List of O2Replies.
0031 class O2ReplyList
0032 {
0033 public:
0034     O2ReplyList()
0035     {
0036         ignoreSslErrors_ = false;
0037     }
0038 
0039     /// Destructor.
0040     /// Deletes all O2Reply instances in the list.
0041     virtual ~O2ReplyList();
0042 
0043     /// Create a new O2Reply from a QNetworkReply, and add it to this list.
0044     void add(QNetworkReply *reply);
0045 
0046     /// Add an O2Reply to the list, while taking ownership of it.
0047     void add(O2Reply *reply);
0048 
0049     /// Remove item from the list that corresponds to a QNetworkReply.
0050     void remove(QNetworkReply *reply);
0051 
0052     /// Find an O2Reply in the list, corresponding to a QNetworkReply.
0053     /// @return Matching O2Reply or NULL.
0054     O2Reply *find(QNetworkReply *reply);
0055 
0056     bool ignoreSslErrors();
0057     void setIgnoreSslErrors(bool ignoreSslErrors);
0058 
0059 protected:
0060     QList<O2Reply *> replies_;
0061     bool ignoreSslErrors_;
0062 };