1 /*
2    Copyright 2009 Last.fm Ltd.
3       - Primarily authored by Max Howell, Jono Cole and Doug Mansell
4 
5    This file is part of liblastfm.
6 
7    liblastfm is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11 
12    liblastfm is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with liblastfm.  If not, see <http://www.gnu.org/licenses/>.
19 */
20 #ifndef LASTFM_WS_ACCESS_MANAGER_H
21 #define LASTFM_WS_ACCESS_MANAGER_H
22 
23 #include "global.h"
24 #include <QtNetwork/QNetworkAccessManager>
25 #include <QNetworkRequest>
26 #include <QNetworkProxy>
27 
28 class QNetworkReply;
29 
30 namespace lastfm {
31 
32 /** Sets useragent and proxy. Auto detecting the proxy where possible. */
33 class LASTFM_DLLEXPORT NetworkAccessManager : public QNetworkAccessManager
34 {
35     Q_OBJECT
36 
37 #ifdef Q_OS_WIN
38     class InternetConnectionMonitor* m_monitor;
39 #endif
40 
41 public:
42     NetworkAccessManager( QObject *parent = 0 );
43     ~NetworkAccessManager();
44 
45     void setUserProxy( const QNetworkProxy& proxy );
46 
47     /** PAC allows different proxy configurations depending on the request
48       * URL and even UserAgent! Thus we allow you to pass that in, we
49       * automatically configure the proxy for every request through
50       * WsAccessManager */
51     QNetworkProxy proxy( const QNetworkRequest& = QNetworkRequest() );
52 
53 protected:
54     virtual QNetworkReply* createRequest( Operation, const QNetworkRequest&, QIODevice* outgoingdata = 0 );
55 
56 private slots:
57     void onConnectivityChanged( bool );
58 
59 private:
60     /** this function calls QNetworkAccessManager::setProxy, and thus
61       * configures the proxy correctly for the next request created by
62       * createRequest. This is necessary due */
63     void applyProxy( const QNetworkRequest& );
64 };
65 
66 } //namespace lastfm
67 
68 #endif
69