QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgshttptransaction.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgshttptransaction.h - Tracks a HTTP request with its response,
3  with particular attention to tracking
4  HTTP redirect responses
5  -------------------
6  begin : 17 Mar, 2005
7  copyright : (C) 2005 by Brendan Morley
8  email : morb at ozemail dot com dot au
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  ***************************************************************************/
19 
20 
21 #ifndef QGSHTTPTRANSACTION_H
22 #define QGSHTTPTRANSACTION_H
23 
24 #include <QHttp>
25 #include <QNetworkProxy>
26 #include <QString>
27 
28 class QTimer;
29 
36 class CORE_EXPORT QgsHttpTransaction : public QObject
37 {
38 
39  Q_OBJECT
40 
41  public:
45  QgsHttpTransaction( QString uri,
46  QString proxyHost = QString(),
47  int proxyPort = 80,
48  QString proxyUser = QString(),
49  QString proxyPass = QString(),
50  QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy,
51  QString userName = QString(),
52  QString password = QString() );
53 
55  virtual ~QgsHttpTransaction();
56 
57  void getAsynchronously();
58 
61 
74  bool getSynchronously( QByteArray &respondedContent, int redirections = 0, const QByteArray* postData = 0 );
75 
76  QString responseContentType();
77 
84  QString errorString();
85 
88  static bool applyProxySettings( QHttp& http, const QString& url );
89 
91  void setCredentials( const QString& username, const QString &password );
92 
94  int networkTimeout() const { return mNetworkTimeoutMsec;}
96  void setNetworkTimeout( int msec ) { mNetworkTimeoutMsec = msec;}
97 
98 
99  public slots:
100 
101  void dataStarted( int id );
102 
103  void dataHeaderReceived( const QHttpResponseHeader& resp );
104 
105  void dataReceived( const QHttpResponseHeader& resp );
106 
107  void dataProgress( int done, int total );
108 
109  void dataFinished( int id, bool error );
110 
111  void transactionFinished( bool error );
112 
113  void dataStateChanged( int state );
114 
115  void networkTimedOut();
116 
118  void abort();
119 
120  signals:
121 
123  void setProgress( int done, int total );
124 
126  void dataReadProgress( int theProgress );
128  void totalSteps( int theTotalSteps );
129 
131  void statusChanged( QString theStatusQString );
132 
133 
134  private:
135 
138 
146  QHttp* http;
147 
151  int httpid;
152 
156  bool httpactive;
157 
158  /*
159  * Indicates the response from the QHttp
160  */
161  QByteArray httpresponse;
162 
163  /*
164  * Indicates the content type of the response from the QHttp
165  */
166  QString httpresponsecontenttype;
167 
171  QString httpurl;
172 
176  QString httphost;
177 
182  QString httpredirecturl;
183 
191  int httpredirections;
192 
196  QTimer * mWatchdogTimer;
197 
201  QString mError;
202 
206  QString mUserName;
207 
211  QString mPassword;
212 
214  int mNetworkTimeoutMsec;
215 };
216 
217 #endif
218 
219 // ENDS