kasts/src/enclosure.h

93 lines
2.8 KiB
C
Raw Normal View History

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
*/
#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>
#include "error.h"
2021-02-21 19:54:10 +01:00
class Entry;
class Enclosure : public QObject
{
Q_OBJECT
Q_PROPERTY(int size READ size WRITE setSize NOTIFY sizeChanged)
2021-06-03 16:23:06 +02:00
Q_PROPERTY(QString formattedSize READ formattedSize NOTIFY sizeChanged)
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)
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)
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-06-03 16:23:06 +02:00
Q_PROPERTY(QString formattedPlayPosition READ formattedPlayPosition NOTIFY playPositionChanged);
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,
PartiallyDownloaded,
2021-02-21 19:54:10 +01:00
Downloaded,
Error,
};
Q_ENUM(Status)
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;
Status status() const;
2021-04-10 22:28:36 +02:00
qint64 playPosition() const;
qint64 duration() const;
int size() const;
2021-06-03 16:23:06 +02:00
QString formattedSize() const;
QString formattedDuration() const;
QString formattedPlayPosition() const;
void setStatus(Status status);
2021-04-10 22:28:36 +02:00
void setPlayPosition(const qint64 &position);
void setDuration(const qint64 &duration);
void setSize(const int &size);
2021-02-21 19:54:10 +01:00
Q_SIGNALS:
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();
void durationChanged();
void sizeChanged();
void downloadError(const Error::Type type, const QString &url, const QString &id, const int errorId, const QString &errorString);
2021-02-21 19:54:10 +01:00
private:
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-02-21 19:54:10 +01:00
int m_size;
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;
Status m_status;
2021-06-03 16:23:06 +02:00
KFormat m_kformat;
};