Human-friendly links
[GPXSee.git] / src / downloader.h
blobb92646b45eb3ac8f40573d61b19f143119f8f6b6
1 #ifndef DOWNLOADER_H
2 #define DOWNLOADER_H
4 #include <QNetworkAccessManager>
5 #include <QUrl>
6 #include <QList>
7 #include <QMap>
8 #include <QSet>
11 class QNetworkReply;
13 class Download
15 public:
16 Download(const QUrl &url, const QString &file)
17 {_url = url; _file = file;}
18 const QUrl& url() const {return _url;}
19 const QString& file() const {return _file;}
21 private:
22 QUrl _url;
23 QString _file;
27 class Downloader : public QObject
29 Q_OBJECT
31 public:
32 Downloader(QObject *parent = 0);
34 bool get(const QList<Download> &list);
36 signals:
37 void finished();
39 private slots:
40 void downloadFinished(QNetworkReply *reply);
42 private:
43 class Redirect
45 public:
46 Redirect() : _level(0) {}
47 Redirect(const QUrl &origin, int level) :
48 _origin(origin), _level(level) {}
50 const QUrl &origin() const {return _origin;}
51 int level() const {return _level;}
53 bool isNull() const {return (_level == 0);}
55 private:
56 QUrl _origin;
57 int _level;
60 bool doDownload(const Download &dl, const Redirect &redirect = Redirect());
61 bool saveToDisk(const QString &filename, QIODevice *data);
63 QNetworkAccessManager _manager;
64 QMap<QUrl, QNetworkReply *> _currentDownloads;
65 QSet<QUrl> _errorDownloads;
68 #endif // DOWNLOADER_H