2021-02-21 19:54:10 +01:00
|
|
|
/**
|
|
|
|
* SPDX-FileCopyrightText: 2020 Tobias Fella <fella@posteo.de>
|
2021-04-11 20:30:58 +02:00
|
|
|
* SPDX-FileCopyrightText: 2021 Bart De Vries <bart@mogwai.be>
|
2021-02-21 19:54:10 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
|
|
*/
|
|
|
|
|
2021-04-22 17:05:33 +02:00
|
|
|
#pragma once
|
2021-02-21 19:54:10 +01:00
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
|
2021-06-03 16:23:06 +02:00
|
|
|
#include <KFormat>
|
|
|
|
|
2021-05-14 16:46:54 +02:00
|
|
|
#include "error.h"
|
|
|
|
|
2021-02-21 19:54:10 +01:00
|
|
|
class Entry;
|
|
|
|
|
|
|
|
class Enclosure : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2021-06-24 17:12:07 +02:00
|
|
|
Q_PROPERTY(qint64 size READ size WRITE setSize NOTIFY sizeChanged)
|
2021-06-03 16:23:06 +02:00
|
|
|
Q_PROPERTY(QString formattedSize READ formattedSize NOTIFY sizeChanged)
|
2021-06-24 17:12:07 +02:00
|
|
|
Q_PROPERTY(qint64 sizeOnDisk READ sizeOnDisk NOTIFY sizeOnDiskChanged)
|
2021-02-21 19:54:10 +01:00
|
|
|
Q_PROPERTY(QString title MEMBER m_title CONSTANT)
|
|
|
|
Q_PROPERTY(QString type MEMBER m_type CONSTANT)
|
|
|
|
Q_PROPERTY(QString url MEMBER m_url CONSTANT)
|
2021-06-23 21:11:04 +02:00
|
|
|
Q_PROPERTY(Status status READ status WRITE setStatus NOTIFY statusChanged)
|
2021-02-21 19:54:10 +01:00
|
|
|
Q_PROPERTY(double downloadProgress MEMBER m_downloadProgress NOTIFY downloadProgressChanged)
|
2021-06-24 17:12:07 +02:00
|
|
|
Q_PROPERTY(QString formattedDownloadSize READ formattedDownloadSize NOTIFY downloadProgressChanged)
|
2021-02-21 19:54:10 +01:00
|
|
|
Q_PROPERTY(QString path READ path CONSTANT)
|
2021-04-10 22:28:36 +02:00
|
|
|
Q_PROPERTY(qint64 playPosition READ playPosition WRITE setPlayPosition NOTIFY playPositionChanged)
|
2021-07-14 19:35:41 +02:00
|
|
|
Q_PROPERTY(QString formattedLeftDuration READ formattedLeftDuration NOTIFY playPositionChanged)
|
2021-10-03 20:49:17 +02:00
|
|
|
Q_PROPERTY(QString formattedPlayPosition READ formattedPlayPosition NOTIFY playPositionChanged)
|
2021-04-18 22:21:59 +02:00
|
|
|
Q_PROPERTY(qint64 duration READ duration WRITE setDuration NOTIFY durationChanged)
|
2021-06-03 16:23:06 +02:00
|
|
|
Q_PROPERTY(QString formattedDuration READ formattedDuration NOTIFY durationChanged)
|
2021-02-21 19:54:10 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
Enclosure(Entry *entry);
|
|
|
|
|
|
|
|
enum Status {
|
|
|
|
Downloadable,
|
|
|
|
Downloading,
|
2021-06-23 21:11:04 +02:00
|
|
|
PartiallyDownloaded,
|
2021-02-21 19:54:10 +01:00
|
|
|
Downloaded,
|
|
|
|
Error,
|
|
|
|
};
|
|
|
|
Q_ENUM(Status)
|
|
|
|
|
2021-06-23 21:11:04 +02:00
|
|
|
static int statusToDb(Status status); // needed to translate Enclosure::Status values to int for sqlite
|
|
|
|
static Status dbToStatus(int value); // needed to translate from int to Enclosure::Status values for sqlite
|
|
|
|
|
2021-02-21 19:54:10 +01:00
|
|
|
Q_INVOKABLE void download();
|
|
|
|
Q_INVOKABLE void deleteFile();
|
|
|
|
|
|
|
|
QString path() const;
|
2021-04-13 20:51:00 +02:00
|
|
|
Status status() const;
|
2021-04-10 22:28:36 +02:00
|
|
|
qint64 playPosition() const;
|
2021-04-18 22:21:59 +02:00
|
|
|
qint64 duration() const;
|
2021-06-24 17:12:07 +02:00
|
|
|
qint64 size() const;
|
|
|
|
qint64 sizeOnDisk() const;
|
2021-06-03 16:23:06 +02:00
|
|
|
QString formattedSize() const;
|
|
|
|
QString formattedDuration() const;
|
2021-07-14 19:35:41 +02:00
|
|
|
QString formattedLeftDuration() const;
|
2021-06-03 16:23:06 +02:00
|
|
|
QString formattedPlayPosition() const;
|
2021-06-24 17:12:07 +02:00
|
|
|
QString formattedDownloadSize() const;
|
2021-04-18 22:21:59 +02:00
|
|
|
|
2021-06-23 21:11:04 +02:00
|
|
|
void setStatus(Status status);
|
2021-04-10 22:28:36 +02:00
|
|
|
void setPlayPosition(const qint64 &position);
|
2021-04-18 22:21:59 +02:00
|
|
|
void setDuration(const qint64 &duration);
|
2021-06-24 17:12:07 +02:00
|
|
|
void setSize(const qint64 &size);
|
|
|
|
void checkSizeOnDisk();
|
2021-02-21 19:54:10 +01:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
2021-05-02 09:05:26 +02:00
|
|
|
void statusChanged(Entry *entry, Status status);
|
2021-02-21 19:54:10 +01:00
|
|
|
void downloadProgressChanged();
|
|
|
|
void cancelDownload();
|
2021-04-10 22:28:36 +02:00
|
|
|
void playPositionChanged();
|
2021-04-18 22:21:59 +02:00
|
|
|
void durationChanged();
|
2021-04-18 22:31:55 +02:00
|
|
|
void sizeChanged();
|
2021-06-24 17:12:07 +02:00
|
|
|
void sizeOnDiskChanged();
|
2021-07-14 22:27:52 +02:00
|
|
|
void downloadError(const Error::Type type, const QString &url, const QString &id, const int errorId, const QString &errorString, const QString &title);
|
2021-02-21 19:54:10 +01:00
|
|
|
|
|
|
|
private:
|
2021-04-09 22:32:13 +02:00
|
|
|
void processDownloadedFile();
|
|
|
|
|
2021-02-21 19:54:10 +01:00
|
|
|
Entry *m_entry;
|
2021-04-13 22:48:09 +02:00
|
|
|
qint64 m_duration;
|
2021-06-24 17:12:07 +02:00
|
|
|
qint64 m_size = 0;
|
2021-10-26 23:14:44 +02:00
|
|
|
qint64 m_sizeOnDisk = 0;
|
2021-02-21 19:54:10 +01:00
|
|
|
QString m_title;
|
|
|
|
QString m_type;
|
|
|
|
QString m_url;
|
2021-04-10 22:28:36 +02:00
|
|
|
qint64 m_playposition;
|
|
|
|
qint64 m_playposition_dbsave;
|
2021-02-21 19:54:10 +01:00
|
|
|
double m_downloadProgress = 0;
|
2021-06-24 17:12:07 +02:00
|
|
|
qint64 m_downloadSize = 0;
|
2021-02-21 19:54:10 +01:00
|
|
|
Status m_status;
|
2021-06-03 16:23:06 +02:00
|
|
|
KFormat m_kformat;
|
2021-06-23 21:11:04 +02:00
|
|
|
};
|