summaryrefslogtreecommitdiff
path: root/Network/LiveCQUpload.hpp
blob: a213c2d82e0e9c3f92e768ca18d77caa67278e9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef LIVE_CQ_UPLOAD_HPP
#define LIVE_CQ_UPLOAD_HPP

#include <QByteArray>
#include <QNetworkRequest>
#include <QObject>
#include <QSet>
#include <QString>
#include <QUrl>
#include <QUrlQuery>

class QNetworkReply;

class LiveCQUpload final
  : public QObject
{
  Q_OBJECT

public:
  class Transport
  {
  public:
    virtual ~Transport () = default;
    virtual QNetworkReply *post (QNetworkRequest const& request, QByteArray const& body) = 0;
  };

  explicit LiveCQUpload (QObject *parent = nullptr);
  LiveCQUpload (Transport *transport, bool take_transport_ownership,
                QObject *parent = nullptr);
  ~LiveCQUpload () override;

  bool setEndpoint (QUrl const& endpoint);
  QUrl endpoint () const { return endpoint_; }

  void setUserAgent (QByteArray const& user_agent) { user_agent_ = user_agent; }

  void postSpot (QUrlQuery const& query);
  void abortOutstandingRequests ();

  Q_SIGNAL void errorOccurred (QString const& reason);
  Q_SIGNAL void spotPosted ();

private:
  void handleReply (QNetworkReply *reply);

  Transport *transport_;
  bool owns_transport_;
  QUrl endpoint_;
  QByteArray user_agent_;
  QSet<QNetworkReply *> outstanding_;
};

#endif