3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
6 Minitube is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Minitube is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Minitube. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef DOWNLOADITEM_H
22 #define DOWNLOADITEM_H
25 #include <QNetworkReply>
29 enum DownloadItemStatus {
37 class DownloadItem : public QObject {
43 void bufferProgress(int percent);
44 void progress(int percent);
49 DownloadItem(Video *video, QUrl url, QString filename, QObject *parent = 0);
51 qint64 bytesTotal() const;
52 qint64 bytesReceived() const;
53 double remainingTime() const;
54 double totalTime() { return m_totalTime; }
55 double currentSpeed() const;
56 int currentPercent() const { return percent; }
57 Video* getVideo() const { return video; }
58 QString currentFilename() const { return m_file.fileName(); }
59 DownloadItemStatus status() const { return m_status; }
60 static QString formattedFilesize(qint64 size);
61 static QString formattedSpeed(double speed);
62 static QString formattedTime(double time, bool remaining = true);
63 QString errorMessage() const;
64 qint64 offset() const { return m_offset; }
65 bool needsDownload(qint64 offset);
66 bool isBuffered(qint64 offset);
67 qint64 blankAtOffset(qint64 offset);
68 void seekTo(qint64 offset, bool sendStatusChanges = true);
78 void downloadReadyRead();
79 void error(QNetworkReply::NetworkError code);
80 void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
81 void metaDataChanged();
82 void requestFinished();
83 void gotStreamUrl(QUrl streamUrl);
88 int initialBufferSize();
90 qint64 m_bytesReceived;
93 bool m_finishedDownloading;
94 QTime m_lastProgressTime;
101 bool sendStatusChanges;
104 QNetworkReply *m_reply;
107 DownloadItemStatus m_status;
108 QString m_errorMessage;
110 QTimer *speedCheckTimer;
112 QMap<qint64, qint64> buffers;
115 // This is required in order to use QPointer<DownloadItem> as a QVariant
116 // as used by the Model/View playlist
117 typedef QPointer<DownloadItem> DownloadItemPointer;
118 Q_DECLARE_METATYPE(DownloadItemPointer)
120 #endif // DOWNLOADITEM_H