Sayonara Player
AsyncWebAccess.h
1 /* AsyncWebAccess.h */
2 
3 /* Copyright (C) 2011-2020 Michael Lugmair (Lucio Carreras)
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef ASYNCWEBACCESS_H_
22 #define ASYNCWEBACCESS_H_
23 
24 #include "AbstractWebAccess.h"
25 #include "Utils/Pimpl.h"
26 
27 #include <QObject>
28 
29 class QImage;
30 class QNetworkReply;
36  public QObject,
37  public AbstractWebAccess
38 {
39  Q_OBJECT
40 
41 public:
42 
46  enum class Behavior : uint8_t
47  {
48  AsBrowser=0,
49  AsSayonara,
50  Random,
51  None
52  };
53 
54 
55  enum class Status : uint8_t
56  {
57  GotData,
58  AudioStream,
59  NoHttp,
60  NoData,
61  Timeout,
62  Error
63  };
64 
65 signals:
66  void sigFinished();
67 
68 public:
69 
75  AsyncWebAccess(QObject* parent=nullptr, const QByteArray& header=QByteArray(),
76  AsyncWebAccess::Behavior behavior=AsyncWebAccess::Behavior::AsBrowser);
77 
78  virtual ~AsyncWebAccess() override;
79 
84  QByteArray data() const;
85 
90  bool hasData() const;
91 
96  QImage image() const;
97 
98 
104  QString url() const;
105 
111  void setBehavior(AsyncWebAccess::Behavior behavior);
112 
113 
119  void run(const QString& url, int timeout=4000);
120 
127  void runPost(const QString& url, const QByteArray& postData, int timeout=4000);
128 
133  void setRawHeader(const QMap<QByteArray, QByteArray>& header);
134 
139  AsyncWebAccess::Status status() const;
140 
145  bool hasError() const;
146 
147 public slots:
148  void stop() override;
149 
150 
151 private slots:
152 
153  void dataAvailable();
154 
159  void finished();
160 
161  void redirected(const QUrl& url);
162 
167  void timeout();
168 
169 private:
170  PIMPL(AsyncWebAccess)
171  void redirectRequest(QString redirecUurl);
172 };
173 
174 #endif
bool hasError() const
Indicates if error.
QImage image() const
get fetched data formatted as image
QByteArray data() const
get fetched data
bool hasData() const
indicates, if data is avaialbe
void setRawHeader(const QMap< QByteArray, QByteArray > &header)
modify header.
AsyncWebAccess(QObject *parent=nullptr, const QByteArray &header=QByteArray(), AsyncWebAccess::Behavior behavior=AsyncWebAccess::Behavior::AsBrowser)
AsyncWebAccess constructor.
Behavior
The Behavior enum. Responsible for the user-agent variable in the HTTP header.
Definition: AsyncWebAccess.h:46
Asynchgronous web access class.
Definition: AsyncWebAccess.h:35
QString url() const
get last called url. This url may differ from the originally called url when request has been redire...
void run(const QString &url, int timeout=4000)
starts a GET request
AsyncWebAccess::Status status() const
Request Status.
void runPost(const QString &url, const QByteArray &postData, int timeout=4000)
starts a POST request
void setBehavior(AsyncWebAccess::Behavior behavior)
Set the behaviour how sayonara should be recognized by the server. This variable will set the user-ag...
Definition: AbstractWebAccess.h:26