2 Copyright 2013-2015 Mats Sjöberg
4 This file is part of the Pumpa programme.
6 Pumpa is free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Pumpa is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Pumpa. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef FILEDOWNLOADER_H
21 #define FILEDOWNLOADER_H
30 //------------------------------------------------------------------------------
32 class FileDownloader
; // forward declaration
34 class FileDownloadManager
: public QObject
{
37 FileDownloadManager(QObject
*);
40 static FileDownloadManager
* getManager(QObject
* = 0);
42 bool hasFile(QString url
);
44 QString
fileName(QString url
);
46 QPixmap
pixmap(QString url
, QString brokenImage
= "");
47 QMovie
* movie(QString url
);
48 bool supportsAnimation(QString url
);
50 FileDownloader
* download(QString url
);
55 void onSslErrors(QNetworkReply
*, QList
<QSslError
>);
56 void onAuthorizedRequestReady(QByteArray response
, int id
);
57 void onFileReady(QString
= "");
60 void executeAuthorizedRequest(KQOAuthRequest
*, FileDownloader
*);
61 QString
urlToPath(QString url
);
63 QNetworkAccessManager
* m_nam
;
64 KQOAuthManager
* m_oam
;
66 QMap
<QString
, FileDownloader
*> m_inProgress
;
67 QMap
<QString
, QString
> m_urlMap
;
72 typedef QPair
<KQOAuthRequest
*, FileDownloader
*> requestData_t
;
73 QMap
<int, requestData_t
> m_requestMap
;
75 static FileDownloadManager
* s_instance
;
77 friend class FileDownloader
;
80 //------------------------------------------------------------------------------
82 class FileDownloader
: public QObject
{
86 FileDownloader(QString url
, FileDownloadManager
* fdm
);
88 QString
url() const { return m_url
; }
91 void networkError(QString
);
98 void requestReady(QByteArray response
, KQOAuthRequest
* oar
);
99 static void resizeImage(QPixmap pix
, QString fn
);
102 KQOAuthRequest
* m_oar
;
105 FileDownloadManager
* m_fdm
;
107 friend class FileDownloadManager
;