summaryrefslogtreecommitdiffstats
path: root/noatun/library/noatun/downloader.h
blob: 7d711c264640302f7954e5daca4b5ecf13909ecd (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#ifndef _DOWNLOADER_H
#define _DOWNLOADER_H

#include <kurl.h>
#include <tqobject.h>
#include <tqptrlist.h>

class TQFile;
class TQTimer;
class Downloader;


namespace KIO
{
	class TransferJob;
	class Job;
}

/**
 * Item to download, usually queued up in Downloader
 **/
class DownloadItem
{
	friend class Downloader;
public:
	DownloadItem();
	virtual ~DownloadItem();

	bool isDownloaded() const;

	/**
	 * @return the local filename this item will be saved to
	 **/
	TQString localFilename() const;

	virtual void setLocalFilename(const TQString &filename);

	/**
	 * Called if this item has been fully downloaded
	 **/
	virtual void downloadFinished();
	/**
	 * Called at regular intervals while downloading this item
	 **/
	virtual void downloaded(int percent);
	/**
	 * Called when downloading this item timed out
	 **/
	virtual void downloadTimeout();
	/**
	 * @return true if the download was scheduled, false if the file is local
	 **/
	bool enqueue(const KURL &url);
	/**
	 * Remove this item from Downloader queue
	 **/
	void dequeue();

private:
	TQString mLocalFilename;
};

/**
 * download playlistitems, in a queue based fasion
 **/
class Downloader : public TQObject
{
Q_OBJECT
  TQ_OBJECT
	struct QueueItem
	{
		DownloadItem *notifier;
		KURL file;
		TQString local;
	};

public:
	Downloader(TQObject *tqparent=0);
	virtual ~Downloader();

public slots:
	TQString enqueue(DownloadItem *notifier, const KURL &file);
	void dequeue(DownloadItem *notifier);

	/**
	 * @internal
	 **/
	void start();

signals:
	/**
	 * Emitted when a new DownloadItem was added to the queue
	 * @p notifier is the added item
	 **/
	void enqueued(DownloadItem *notifier, const KURL &file);
	/**
	 * Emitted when a DownloadItem was removed from the queue
	 * @p notifier is the removed item
	 **/
	void dequeued(DownloadItem *notifier);

private slots:
	void getNext();

	void data( KIO::Job *, const TQByteArray &data);
	void percent( KIO::Job *, unsigned long percent);
	void jobDone( KIO::Job *);
	void giveUpWithThisDownloadServerIsRunningNT();

private:
	TQPtrList<Downloader::QueueItem> mQueue;
	TQPtrList<Downloader::QueueItem> *mUnstartedQueue;
	TQFile *localfile;
	Downloader::QueueItem *current;
	KIO::TransferJob *mJob;
	TQTimer *mTimeout;
	bool mStarted;
};

#endif