]> git.sur5r.net Git - minitube/blobdiff - src/downloaditem.h
Upload 3.9.3-2 to unstable
[minitube] / src / downloaditem.h
index 7ccf4db87937c09818fbb37de77dba82603e8ef9..2c074f0c1d7a4076dd26df647ee40e6e114f2b65 100644 (file)
@@ -1,3 +1,23 @@
+/* $BEGIN_LICENSE
+
+This file is part of Minitube.
+Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
+
+Minitube is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Minitube is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
+
+$END_LICENSE */
+
 #ifndef DOWNLOADITEM_H
 #define DOWNLOADITEM_H
 
@@ -20,14 +40,18 @@ class DownloadItem : public QObject {
 
 signals:
     void statusChanged();
+    void bufferProgress(int percent);
     void progress(int percent);
     void finished();
+    void error(QString);
 
 public:
     DownloadItem(Video *video, QUrl url, QString filename, QObject *parent = 0);
+    ~DownloadItem();
     qint64 bytesTotal() const;
     qint64 bytesReceived() const;
     double remainingTime() const;
+    double totalTime() { return m_totalTime; }
     double currentSpeed() const;
     int currentPercent() const { return percent; }
     Video* getVideo() const { return video; }
@@ -35,8 +59,13 @@ public:
     DownloadItemStatus status() const { return m_status; }
     static QString formattedFilesize(qint64 size);
     static QString formattedSpeed(double speed);
-    static QString formattedTime(double time);
+    static QString formattedTime(double time, bool remaining = true);
     QString errorMessage() const;
+    qint64 offset() const { return m_offset; }
+    bool needsDownload(qint64 offset);
+    bool isBuffered(qint64 offset);
+    qint64 blankAtOffset(qint64 offset);
+    void seekTo(qint64 offset, bool sendStatusChanges = true);
 
 public slots:
     void start();
@@ -51,9 +80,12 @@ private slots:
     void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
     void metaDataChanged();
     void requestFinished();
+    void gotStreamUrl(QUrl streamUrl);
+    void speedCheck();
 
 private:
     void init();
+    int initialBufferSize();
 
     qint64 m_bytesReceived;
     QTime m_downloadTime;
@@ -61,9 +93,13 @@ private:
     bool m_finishedDownloading;
     QTime m_lastProgressTime;
     int percent;
+    double m_totalTime;
 
     QUrl m_url;
 
+    qint64 m_offset;
+    bool sendStatusChanges;
+
     QFile m_file;
     QNetworkReply *m_reply;
     Video *video;
@@ -71,6 +107,9 @@ private:
     DownloadItemStatus m_status;
     QString m_errorMessage;
 
+    QTimer *speedCheckTimer;
+
+    QMap<qint64, qint64> buffers;
 };
 
 // This is required in order to use QPointer<DownloadItem> as a QVariant