00001 #ifndef _DOWNLOADER_H
00002 #define _DOWNLOADER_H
00003
00004 #include <kurl.h>
00005 #include <qobject.h>
00006 #include <qptrlist.h>
00007
00008 class QFile;
00009 class QTimer;
00010 class Downloader;
00011
00012
00013 namespace KIO
00014 {
00015 class TransferJob;
00016 class Job;
00017 }
00018
00019 class DownloadItem
00020 {
00021 friend class Downloader;
00022 public:
00023 DownloadItem();
00024 virtual ~DownloadItem();
00025
00026 bool isDownloaded() const;
00027
00028 QString localFilename() const;
00029
00030 virtual void setLocalFilename(const QString &filename);
00031
00032 virtual void downloadFinished();
00033 virtual void downloaded(int percent);
00034 virtual void downloadTimeout();
00039 bool enqueue(const KURL &url);
00040 void dequeue();
00041
00042 private:
00043 QString mLocalFilename;
00044 };
00045
00049 class Downloader : public QObject
00050 {
00051 Q_OBJECT
00052 struct QueueItem
00053 {
00054 DownloadItem *notifier;
00055 KURL file;
00056 QString local;
00057 };
00058
00059 public:
00060 Downloader(QObject *parent=0);
00061 virtual ~Downloader();
00062
00063
00064 public slots:
00065 QString enqueue(DownloadItem *notifier, const KURL &file);
00066 void dequeue(DownloadItem *notifier);
00067
00071 void start();
00072
00073 signals:
00074 void enqueued(DownloadItem *notifier, const KURL &file);
00075 void dequeued(DownloadItem *notifier);
00076
00077 private slots:
00078 void getNext();
00079
00080 void data( KIO::Job *, const QByteArray &data);
00081 void percent( KIO::Job *, unsigned long percent);
00082 void jobDone( KIO::Job *);
00083 void giveUpWithThisDownloadServerIsRunningNT();
00084
00085 private:
00086 QPtrList<Downloader::QueueItem> mQueue;
00087 QPtrList<Downloader::QueueItem> *mUnstartedQueue;
00088 QFile *localfile;
00089 Downloader::QueueItem *current;
00090 KIO::TransferJob *mJob;
00091 QTimer *mTimeout;
00092 bool mStarted;
00093 };
00094
00095 #endif
00096