summaryrefslogtreecommitdiffstats
path: root/scribus/downloadmanager/scdlthread.h
blob: 7d5b4eb4f3c20ff5050c9d97b0973d9c2955df69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef SCDLTHREAD_H
#define SCDLTHREAD_H

#include <QThread>
#include <QUrl>
#include <QStringList>
#include <QPair>
#include <QString>
#include <QQueue>
#include <QFile>
#include <QNetworkAccessManager>

class ScDLThread : public QThread
{
	Q_OBJECT
	public:
		ScDLThread(QObject * parent = 0);
		~ScDLThread();
		void run();

		void addURL(const QUrl &url, bool overwrite, const QString& location="");
		void addURLs(const QStringList &urlList, bool overwrite, const QString& location="");
		void startDownloads();
		QString saveFileName(const QUrl &url, const QString &location, bool overwrite);

	signals:
		void finished();
		void runSignal();
		void received(const QString &);

	private slots:
		void startNextDownload();
		void downloadFinished();
		void downloadReadyRead();
		void runSlot();

	private:
		bool urlOK(QUrl url);
		QStringList m_urlList;
		QFile output;
		QQueue<QPair<QUrl, QString> > downloadQueue;
		int downloadedCount;
		int totalCount;
		QNetworkReply *currentDownload;
		QNetworkAccessManager manager;
};
#endif