Chatterino
NetworkPrivate.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include "util/QObjectRef.hpp"
5 
6 #include <QHttpMultiPart>
7 #include <QNetworkRequest>
8 #include <QTimer>
9 #include <functional>
10 #include <memory>
11 
12 class QNetworkReply;
13 
14 namespace chatterino {
15 
16 class NetworkResult;
17 
18 class NetworkRequester : public QObject
19 {
20  Q_OBJECT
21 
22 signals:
23  void requestUrl();
24 };
25 
26 class NetworkWorker : public QObject
27 {
28  Q_OBJECT
29 
30 signals:
31  void doneUrl();
32 };
33 
34 struct NetworkData {
35  NetworkData();
36  ~NetworkData();
37 
38  QNetworkRequest request_;
39  bool hasCaller_{};
41  bool cache_{};
42  bool executeConcurrently_{};
43 
48 
50 
51  QByteArray payload_;
52  // lifetime secured by lifetimeManager_
53  QHttpMultiPart *multiPartPayload_{};
54 
55  // Timer that tracks the timeout
56  // By default, there's no explicit timeout for the request
57  // to enable the timer, the "setTimeout" function needs to be called before
58  // execute is called
59  bool hasTimeout_{};
60  int timeoutMS_{};
61  QTimer *timer_ = nullptr;
62  QObject *lifetimeManager_;
63 
64  QString getHash();
65 
66 private:
67  QString hash_;
68 };
69 
70 void load(const std::shared_ptr<NetworkData> &data);
71 
72 } // namespace chatterino
QByteArray payload_
Definition: NetworkPrivate.hpp:51
QObject * lifetimeManager_
Definition: NetworkPrivate.hpp:62
Definition: NetworkPrivate.hpp:34
Definition: Application.cpp:48
QNetworkRequest request_
Definition: NetworkPrivate.hpp:38
NetworkReplyCreatedCallback onReplyCreated_
Definition: NetworkPrivate.hpp:44
std::function< void(NetworkResult)> NetworkErrorCallback
Definition: NetworkCommon.hpp:16
NetworkSuccessCallback onSuccess_
Definition: NetworkPrivate.hpp:46
NetworkErrorCallback onError_
Definition: NetworkPrivate.hpp:45
NetworkRequestType
Definition: NetworkCommon.hpp:20
QObjectRef< QObject > caller_
Definition: NetworkPrivate.hpp:40
Definition: NetworkPrivate.hpp:26
Definition: NetworkPrivate.hpp:18
std::function< Outcome(NetworkResult)> NetworkSuccessCallback
Definition: NetworkCommon.hpp:15
std::function< void()> NetworkFinallyCallback
Definition: NetworkCommon.hpp:18
void load(const std::shared_ptr< NetworkData > &data)
Definition: NetworkPrivate.cpp:391
NetworkFinallyCallback finally_
Definition: NetworkPrivate.hpp:47
std::function< void(QNetworkReply *)> NetworkReplyCreatedCallback
Definition: NetworkCommon.hpp:17