File indexing completed on 2024-05-12 16:21:29
0001 /** 0002 * SPDX-FileCopyrightText: 2020 Tobias Fella <tobias.fella@kde.org> 0003 * SPDX-FileCopyrightText: 2021 Bart De Vries <bart@mogwai.be> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #pragma once 0009 0010 #include <QDebug> 0011 #include <QObject> 0012 #include <QString> 0013 0014 #include <KFormat> 0015 0016 #include "error.h" 0017 0018 class Entry; 0019 0020 class Enclosure : public QObject 0021 { 0022 Q_OBJECT 0023 0024 Q_PROPERTY(qint64 size READ size WRITE setSize NOTIFY sizeChanged) 0025 Q_PROPERTY(QString formattedSize READ formattedSize NOTIFY sizeChanged) 0026 Q_PROPERTY(qint64 sizeOnDisk READ sizeOnDisk NOTIFY sizeOnDiskChanged) 0027 Q_PROPERTY(QString title MEMBER m_title NOTIFY titleChanged) 0028 Q_PROPERTY(QString type MEMBER m_type NOTIFY typeChanged) 0029 Q_PROPERTY(QString url READ url NOTIFY urlChanged) 0030 Q_PROPERTY(Status status READ status WRITE setStatus NOTIFY statusChanged) 0031 Q_PROPERTY(double downloadProgress MEMBER m_downloadProgress NOTIFY downloadProgressChanged) 0032 Q_PROPERTY(QString formattedDownloadSize READ formattedDownloadSize NOTIFY downloadProgressChanged) 0033 Q_PROPERTY(QString path READ path NOTIFY pathChanged) 0034 Q_PROPERTY(QString cachedEmbeddedImage READ cachedEmbeddedImage CONSTANT) 0035 Q_PROPERTY(qint64 playPosition READ playPosition WRITE setPlayPosition NOTIFY playPositionChanged) 0036 Q_PROPERTY(QString formattedLeftDuration READ formattedLeftDuration NOTIFY leftDurationChanged) 0037 Q_PROPERTY(QString formattedPlayPosition READ formattedPlayPosition NOTIFY playPositionChanged) 0038 Q_PROPERTY(qint64 duration READ duration WRITE setDuration NOTIFY durationChanged) 0039 Q_PROPERTY(QString formattedDuration READ formattedDuration NOTIFY durationChanged) 0040 0041 public: 0042 Enclosure(Entry *entry); 0043 0044 enum Status { 0045 Downloadable, 0046 Downloading, 0047 PartiallyDownloaded, 0048 Downloaded, 0049 Error, 0050 }; 0051 Q_ENUM(Status) 0052 0053 static int statusToDb(Status status); // needed to translate Enclosure::Status values to int for sqlite 0054 static Status dbToStatus(int value); // needed to translate from int to Enclosure::Status values for sqlite 0055 0056 Q_INVOKABLE void download(); 0057 Q_INVOKABLE void deleteFile(); 0058 0059 QString path() const; 0060 QString url() const; 0061 Status status() const; 0062 QString cachedEmbeddedImage() const; 0063 qint64 playPosition() const; 0064 qint64 duration() const; 0065 qint64 size() const; 0066 qint64 sizeOnDisk() const; 0067 QString formattedSize() const; 0068 QString formattedDuration() const; 0069 QString formattedLeftDuration() const; 0070 QString formattedPlayPosition() const; 0071 QString formattedDownloadSize() const; 0072 0073 void setStatus(Status status); 0074 void setPlayPosition(const qint64 &position); 0075 void setDuration(const qint64 &duration); 0076 void setSize(const qint64 &size); 0077 void checkSizeOnDisk(); 0078 0079 Q_SIGNALS: 0080 void titleChanged(const QString &title); 0081 void typeChanged(const QString &type); 0082 void urlChanged(const QString &url); 0083 void pathChanged(const QString &path); 0084 void statusChanged(Entry *entry, Status status); 0085 void downloadProgressChanged(); 0086 void cancelDownload(); 0087 void playPositionChanged(); 0088 void leftDurationChanged(); 0089 void durationChanged(); 0090 void sizeChanged(); 0091 void sizeOnDiskChanged(); 0092 void downloadError(const Error::Type type, const QString &url, const QString &id, const int errorId, const QString &errorString, const QString &title); 0093 0094 private: 0095 void updateFromDb(); 0096 void processDownloadedFile(); 0097 0098 Entry *m_entry; 0099 qint64 m_duration; 0100 qint64 m_size = 0; 0101 qint64 m_sizeOnDisk = 0; 0102 QString m_title; 0103 QString m_type; 0104 QString m_url; 0105 qint64 m_playposition; 0106 qint64 m_playposition_dbsave; 0107 double m_downloadProgress = 0; 0108 qint64 m_downloadSize = 0; 0109 Status m_status; 0110 KFormat m_kformat; 0111 };