QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsnetworkaccessmanager.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsnetworkaccessmanager.h - description
3  -------------------
4  begin : 2010-05-08
5  copyright : (C) 2010 by Juergen E. Fischer
6  email : jef at norbit dot de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSNETWORKACCESSMANAGER_H
19 #define QGSNETWORKACCESSMANAGER_H
20 
21 #include <QList>
22 #include <QStringList>
23 #include <QNetworkAccessManager>
24 #include <QNetworkProxy>
25 #include <QNetworkRequest>
26 
27 #include "qgssingleton.h"
28 
29 /*
30  * \class QgsNetworkAccessManager
31  * \brief network access manager for QGIS
32  * \ingroup core
33  * \since 1.5
34  *
35  * This class implements the QGIS network access manager. It's a singleton
36  * that can be used across QGIS.
37  *
38  * Plugins can insert proxy factories and thereby redirect requests to
39  * individual proxies.
40  *
41  * If no proxy factories are there or none returns a proxy for an URL a
42  * fallback proxy can be set. There's also a exclude list that defines URLs
43  * that the fallback proxy should not be used for, then no proxy will be used.
44  *
45  */
46 class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager, public QgsSingleton<QgsNetworkAccessManager>
47 {
48  Q_OBJECT
49 
50  public:
51  QgsNetworkAccessManager( QObject *parent = 0 );
52 
55 
57  void insertProxyFactory( QNetworkProxyFactory *factory );
58 
60  void removeProxyFactory( QNetworkProxyFactory *factory );
61 
63  const QList<QNetworkProxyFactory *> proxyFactories() const;
64 
66  const QNetworkProxy &fallbackProxy() const;
67 
69  const QStringList &excludeList() const;
70 
72  void setFallbackProxyAndExcludes( const QNetworkProxy &proxy, const QStringList &excludes );
73 
75  static QString cacheLoadControlName( QNetworkRequest::CacheLoadControl theControl );
76 
78  static QNetworkRequest::CacheLoadControl cacheLoadControlFromName( const QString &theName );
79 
81  void setupDefaultProxyAndCache();
82 
83  bool useSystemProxy() { return mUseSystemProxy; }
84 
85  signals:
86  void requestAboutToBeCreated( QNetworkAccessManager::Operation, const QNetworkRequest &, QIODevice * );
87  void requestCreated( QNetworkReply * );
88  void requestTimedOut( QNetworkReply * );
89 
90  private slots:
91  void abortRequest();
92 
93  protected:
94  virtual QNetworkReply *createRequest( QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *outgoingData = 0 ) override;
95 
96  private:
97  QList<QNetworkProxyFactory*> mProxyFactories;
98  QNetworkProxy mFallbackProxy;
99  QStringList mExcludedURLs;
100  bool mUseSystemProxy;
101 };
102 
103 #endif // QGSNETWORKACCESSMANAGER_H
104