~ubuntu-branches/ubuntu/hardy/qgis/hardy

« back to all changes in this revision

Viewing changes to src/core/qgshttptransaction.h

  • Committer: Bazaar Package Importer
  • Author(s): William Grant
  • Date: 2007-05-06 13:42:32 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070506134232-pyli6t388w5asd8x
Tags: 0.8.0-3ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - debian/rules, debian/qgis.install, debian/qgis.dirs debian/qgis.desktop:
    Add and install .desktop.
* debian/qgis.desktop: Remove Applications category; it's not real.
* Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
/* $Id: qgshttptransaction.h 5697 2006-08-15 10:29:46Z morb_au $ */
 
21
 
 
22
#ifndef QGSHTTPTRANSACTION_H
 
23
#define QGSHTTPTRANSACTION_H
 
24
 
 
25
#include <QHttp>
 
26
#include <QString>
 
27
 
 
28
class QTimer;
 
29
 
 
30
/**
 
31
 
 
32
  \brief  HTTP request/response manager that is redirect-aware.
 
33
 
 
34
  This class extends the Qt QHttp concept by being able to recognise
 
35
  and respond to redirection responses (e.g. HTTP code 302)
 
36
  
 
37
  
 
38
  TODO: Make it work
 
39
  
 
40
*/
 
41
 
 
42
class QgsHttpTransaction : public QObject
 
43
{
 
44
  
 
45
  Q_OBJECT
 
46
 
 
47
public:
 
48
  /**
 
49
  * Constructor.
 
50
  */
 
51
  QgsHttpTransaction( QString uri,
 
52
                      QString proxyHost = QString(),
 
53
                      int     proxyPort = 80,
 
54
                      QString proxyUser = QString(),
 
55
                      QString proxyPass = QString() );
 
56
 
 
57
  //! Destructor
 
58
  virtual ~QgsHttpTransaction();
 
59
  
 
60
  void getAsynchronously();
 
61
  
 
62
  //! Gets the response synchronously.  Note that signals will still be emitted
 
63
  //! while in this function.
 
64
 
 
65
  /*!
 
66
      The function returns FALSE if there is an error while getting the response.
 
67
      \param[out] respondedContent is replaced with the new content.
 
68
      \param[in]  redirections     is used to measure how many http redirections we've been through.
 
69
                                   Clients typically don't need to set this.
 
70
   */
 
71
  bool getSynchronously(QByteArray &respondedContent, int redirections = 0);
 
72
 
 
73
  QString responseContentType();
 
74
 
 
75
  /**
 
76
   * If an operation returns 0 (e.g. getSynchronously()), this function
 
77
   * returns the text of the error associated with the failure.
 
78
   * Interactive users of this provider can then, for example,
 
79
   * call a QMessageBox to display the contents.
 
80
   */
 
81
  QString errorString();
 
82
 
 
83
 
 
84
public slots:
 
85
 
 
86
  void dataStarted( int id );
 
87
 
 
88
  void dataHeaderReceived( const QHttpResponseHeader& resp );
 
89
 
 
90
  void dataReceived( const QHttpResponseHeader& resp );
 
91
 
 
92
  void dataProgress( int done, int total );
 
93
 
 
94
  void dataFinished( int id, bool error );
 
95
 
 
96
  void transactionFinished( bool error );
 
97
 
 
98
  void dataStateChanged( int state );
 
99
 
 
100
  void networkTimedOut();
 
101
 
 
102
signals:
 
103
 
 
104
    /** \brief emit a signal to notify of a progress event */
 
105
    void setProgress(int theProgress, int theTotalSteps);
 
106
 
 
107
    /** \brief emit a signal to be caught by qgisapp and display a msg on status bar */
 
108
    void setStatus(QString theStatusQString);
 
109
 
 
110
 
 
111
private:
 
112
  
 
113
  /**
 
114
   * Indicates the associated QHttp object
 
115
   *
 
116
   * \note  We tried to use this as a plain QHttp object
 
117
   *        but strange things were happening with the signals -
 
118
   *        therefore we use the "pointer to" instead.
 
119
   */
 
120
  QHttp* http;
 
121
 
 
122
  /**
 
123
   * Indicates the QHttp ID
 
124
   */
 
125
  int httpid;
 
126
  
 
127
  /**
 
128
   * Indicates if the transaction is in progress
 
129
   */
 
130
  bool httpactive;
 
131
 
 
132
  /*
 
133
   * Indicates the response from the QHttp 
 
134
   */ 
 
135
  QByteArray httpresponse;
 
136
  
 
137
  /*
 
138
   * Indicates the content type of the response from the QHttp 
 
139
   */ 
 
140
  QString    httpresponsecontenttype;
 
141
    
 
142
  /**
 
143
   * The original URL requested for this transaction
 
144
   */
 
145
  QString httpurl;
 
146
  
 
147
  /**
 
148
   * The host being used for this transaction
 
149
   */
 
150
  QString httphost;
 
151
 
 
152
  /**
 
153
   * The port being used for this transaction
 
154
   */
 
155
  int httpport;
 
156
 
 
157
  /**
 
158
   * The username being used for this transaction
 
159
   */
 
160
  QString httpuser;
 
161
 
 
162
  /**
 
163
   * The password being used for this transaction
 
164
   */
 
165
  QString httppass;
 
166
 
 
167
  /**
 
168
   * If not empty, indicates that the QHttp is a redirect
 
169
   * to the contents of this variable
 
170
   */
 
171
  QString httpredirecturl;
 
172
 
 
173
  /**
 
174
   * Number of http redirections this transaction has been
 
175
   * subjected to.
 
176
   *
 
177
   * TODO: Use this as part of a redirection loop detector
 
178
   *
 
179
   */
 
180
  int httpredirections;
 
181
 
 
182
  /**
 
183
   * Indicates the associated QTimer object - used to detect network timeouts
 
184
   */
 
185
  QTimer * mWatchdogTimer;
 
186
 
 
187
  /**
 
188
   * The error message associated with the last HTTP error.
 
189
   */
 
190
  QString mError;
 
191
 
 
192
};
 
193
 
 
194
#endif
 
195
 
 
196
// ENDS