QGIS API Documentation  2.5.0-Master
 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:
46  QgsHttpTransaction( QString uri,
47  QString proxyHost = QString(),
48  int proxyPort = 80,
49  QString proxyUser = QString(),
50  QString proxyPass = QString(),
51  QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy,
52  QString userName = QString(),
53  QString password = QString() );
54 
56  virtual ~QgsHttpTransaction();
57 
58  void getAsynchronously();
59 
62 
75  bool getSynchronously( QByteArray &respondedContent, int redirections = 0, const QByteArray* postData = 0 );
76 
77  QString responseContentType();
78 
85  QString errorString();
86 
89  static bool applyProxySettings( QHttp& http, const QString& url );
90 
96  void setCredentials( const QString& username, const QString &password );
97 
99  int networkTimeout() const { return mNetworkTimeoutMsec;}
101  void setNetworkTimeout( int msec ) { mNetworkTimeoutMsec = msec;}
102 
103 
104  public slots:
105 
106  void dataStarted( int id );
107 
108  void dataHeaderReceived( const QHttpResponseHeader& resp );
109 
110  void dataReceived( const QHttpResponseHeader& resp );
111 
112  void dataProgress( int done, int total );
113 
114  void dataFinished( int id, bool error );
115 
116  void transactionFinished( bool error );
117 
118  void dataStateChanged( int state );
119 
120  void networkTimedOut();
121 
123  void abort();
124 
125  signals:
126 
128  void setProgress( int done, int total );
129 
131  void dataReadProgress( int theProgress );
133  void totalSteps( int theTotalSteps );
134 
136  void statusChanged( QString theStatusQString );
137 
138 
139  private:
140 
143 
151  QHttp* http;
152 
156  int httpid;
157 
162 
163  /*
164  * Indicates the response from the QHttp
165  */
166  QByteArray httpresponse;
167 
168  /*
169  * Indicates the content type of the response from the QHttp
170  */
172 
176  QString httpurl;
177 
181  QString httphost;
182 
188 
197 
201  QTimer * mWatchdogTimer;
202 
206  QString mError;
207 
211  QString mUserName;
212 
216  QString mPassword;
217 
220 };
221 
222 #endif
223 
224 // ENDS
bool httpactive
Indicates if the transaction is in progress.
int httpid
Indicates the QHttp ID.
int networkTimeout() const
Returns the network timeout in msec.
QString mPassword
Password.
QString httphost
The host being used for this transaction.
int mNetworkTimeoutMsec
Network timeout in milliseconds.
QHttp * http
Indicates the associated QHttp object.
void setNetworkTimeout(int msec)
Sets the network timeout in milliseconds.
QString mUserName
User name.
QString httpurl
The original URL requested for this transaction.
QString mError
The error message associated with the last HTTP error.
HTTP request/response manager that is redirect-aware.
int httpredirections
Number of http redirections this transaction has been subjected to.
QString httpredirecturl
If not empty, indicates that the QHttp is a redirect to the contents of this variable.
QTimer * mWatchdogTimer
Indicates the associated QTimer object - used to detect network timeouts.