]> git.sur5r.net Git - minitube/blob - src/downloaditem.h
Fixed small leak
[minitube] / src / downloaditem.h
1 #ifndef DOWNLOADITEM_H
2 #define DOWNLOADITEM_H
3
4 #include <QtCore>
5 #include <QNetworkReply>
6
7 class Video;
8
9 enum DownloadItemStatus {
10     Idle = 0,
11     Starting,
12     Downloading,
13     Finished,
14     Failed
15 };
16
17 class DownloadItem : public QObject {
18
19     Q_OBJECT
20
21 signals:
22     void statusChanged();
23     void progress(int percent);
24     void finished();
25
26 public:
27     DownloadItem(Video *video, QUrl url, QString filename, QObject *parent = 0);
28     ~DownloadItem();
29     qint64 bytesTotal() const;
30     qint64 bytesReceived() const;
31     double remainingTime() const;
32     double currentSpeed() const;
33     int currentPercent() const { return percent; }
34     Video* getVideo() const { return video; }
35     QString currentFilename() const { return m_file.fileName(); }
36     DownloadItemStatus status() const { return m_status; }
37     static QString formattedFilesize(qint64 size);
38     static QString formattedSpeed(double speed);
39     static QString formattedTime(double time);
40     QString errorMessage() const;
41
42 public slots:
43     void start();
44     void stop();
45     void tryAgain();
46     void open();
47     void openFolder();
48
49 private slots:
50     void downloadReadyRead();
51     void error(QNetworkReply::NetworkError code);
52     void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
53     void metaDataChanged();
54     void requestFinished();
55
56 private:
57     void init();
58
59     qint64 m_bytesReceived;
60     QTime m_downloadTime;
61     bool m_startedSaving;
62     bool m_finishedDownloading;
63     QTime m_lastProgressTime;
64     int percent;
65
66     QUrl m_url;
67
68     QFile m_file;
69     QNetworkReply *m_reply;
70     Video *video;
71
72     DownloadItemStatus m_status;
73     QString m_errorMessage;
74
75 };
76
77 // This is required in order to use QPointer<DownloadItem> as a QVariant
78 // as used by the Model/View playlist
79 typedef QPointer<DownloadItem> DownloadItemPointer;
80 Q_DECLARE_METATYPE(DownloadItemPointer)
81
82 #endif // DOWNLOADITEM_H