Show webfinger if displayName is unknown for an author.
[larjonas-pumpa.git] / src / filedownloader.h
bloba8daa4def46b3d63c09831612b7303ca7640d010
1 /*
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
23 #include <QtCore>
24 #include <QtNetwork>
25 #include <QPixmap>
26 #include <QMovie>
28 #include "QtKOAuth"
30 //------------------------------------------------------------------------------
32 class FileDownloader; // forward declaration
34 class FileDownloadManager : public QObject {
35 Q_OBJECT
37 FileDownloadManager(QObject*);
38 public:
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);
52 void dumpStats();
54 private slots:
55 void onSslErrors(QNetworkReply*, QList<QSslError>);
56 void onAuthorizedRequestReady(QByteArray response, int id);
57 void onFileReady(QString = "");
59 private:
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;
68 QString m_cacheDir;
70 int m_nextRequestId;
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 {
83 Q_OBJECT
85 public:
86 FileDownloader(QString url, FileDownloadManager* fdm);
88 QString url() const { return m_url; }
90 signals:
91 void networkError(QString);
92 void fileReady();
94 private slots:
95 void replyFinished();
97 private:
98 void requestReady(QByteArray response, KQOAuthRequest* oar);
99 static void resizeImage(QPixmap pix, QString fn);
101 QString m_url;
102 KQOAuthRequest* m_oar;
103 int m_redirs;
105 FileDownloadManager* m_fdm;
107 friend class FileDownloadManager;
110 #endif