QGIS API Documentation  2.6.0-Brighton
 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 
94  void setCredentials( const QString& username, const QString &password );
95 
97  int networkTimeout() const { return mNetworkTimeoutMsec;}
99  void setNetworkTimeout( int msec ) { mNetworkTimeoutMsec = msec;}
100 
101 
102  public slots:
103 
104  void dataStarted( int id );
105 
106  void dataHeaderReceived( const QHttpResponseHeader& resp );
107 
108  void dataReceived( const QHttpResponseHeader& resp );
109 
110  void dataProgress( int done, int total );
111 
112  void dataFinished( int id, bool error );
113 
114  void transactionFinished( bool error );
115 
116  void dataStateChanged( int state );
117 
118  void networkTimedOut();
119 
121  void abort();
122 
123  signals:
124 
126  void setProgress( int done, int total );
127 
129  void dataReadProgress( int theProgress );
131  void totalSteps( int theTotalSteps );
132 
134  void statusChanged( QString theStatusQString );
135 
136 
137  private:
138 
141 
149  QHttp* http;
150 
154  int httpid;
155 
159  bool httpactive;
160 
161  /*
162  * Indicates the response from the QHttp
163  */
164  QByteArray httpresponse;
165 
166  /*
167  * Indicates the content type of the response from the QHttp
168  */
169  QString httpresponsecontenttype;
170 
174  QString httpurl;
175 
179  QString httphost;
180 
185  QString httpredirecturl;
186 
194  int httpredirections;
195 
199  QTimer * mWatchdogTimer;
200 
204  QString mError;
205 
209  QString mUserName;
210 
214  QString mPassword;
215 
217  int mNetworkTimeoutMsec;
218 };
219 
220 #endif
221 
222 // ENDS