mirror of https://github.com/KDE/kasts.git
Add playposition tracking in enclosure
This commit is contained in:
parent
e174269332
commit
ee13a29d10
|
@ -33,7 +33,8 @@ Enclosure::Enclosure(Entry *entry)
|
||||||
m_title = query.value(QStringLiteral("title")).toString();
|
m_title = query.value(QStringLiteral("title")).toString();
|
||||||
m_type = query.value(QStringLiteral("type")).toString();
|
m_type = query.value(QStringLiteral("type")).toString();
|
||||||
m_url = query.value(QStringLiteral("url")).toString();
|
m_url = query.value(QStringLiteral("url")).toString();
|
||||||
m_playposition = query.value(QStringLiteral("playposition")).toInt();
|
m_playposition = query.value(QStringLiteral("playposition")).toLongLong();
|
||||||
|
m_playposition_dbsave = m_playposition;
|
||||||
|
|
||||||
QFile file(path());
|
QFile file(path());
|
||||||
if(file.size() == m_size) {
|
if(file.size() == m_size) {
|
||||||
|
@ -127,3 +128,25 @@ QString Enclosure::path() const
|
||||||
{
|
{
|
||||||
return Fetcher::instance().enclosurePath(m_url);
|
return Fetcher::instance().enclosurePath(m_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qint64 Enclosure::playPosition() const{
|
||||||
|
return m_playposition;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Enclosure::setPlayPosition(const qint64 &position)
|
||||||
|
{
|
||||||
|
m_playposition = position;
|
||||||
|
qDebug() << "save playPosition" << m_entry->title();
|
||||||
|
|
||||||
|
// let's only save the play position to the database every 15 seconds
|
||||||
|
if (abs(m_playposition - m_playposition_dbsave) > 15000) {
|
||||||
|
qDebug() << "save playPosition to database" << m_entry->title();
|
||||||
|
QSqlQuery query;
|
||||||
|
query.prepare(QStringLiteral("UPDATE Enclosures SET playposition=:playposition WHERE id=:id AND feed=:feed"));
|
||||||
|
query.bindValue(QStringLiteral(":id"), m_entry->id());
|
||||||
|
query.bindValue(QStringLiteral(":feed"), m_entry->feed()->url());
|
||||||
|
query.bindValue(QStringLiteral(":playposition"), m_playposition);
|
||||||
|
Database::instance().execute(query);
|
||||||
|
m_playposition_dbsave = m_playposition;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ class Enclosure : public QObject
|
||||||
Q_PROPERTY(Status status MEMBER m_status NOTIFY statusChanged)
|
Q_PROPERTY(Status status MEMBER m_status NOTIFY statusChanged)
|
||||||
Q_PROPERTY(double downloadProgress MEMBER m_downloadProgress NOTIFY downloadProgressChanged)
|
Q_PROPERTY(double downloadProgress MEMBER m_downloadProgress NOTIFY downloadProgressChanged)
|
||||||
Q_PROPERTY(QString path READ path CONSTANT)
|
Q_PROPERTY(QString path READ path CONSTANT)
|
||||||
Q_PROPERTY(QString playposition MEMBER m_playposition CONSTANT)
|
Q_PROPERTY(qint64 playPosition READ playPosition WRITE setPlayPosition NOTIFY playPositionChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Enclosure(Entry *entry);
|
Enclosure(Entry *entry);
|
||||||
|
@ -42,11 +42,15 @@ public:
|
||||||
Q_INVOKABLE void deleteFile();
|
Q_INVOKABLE void deleteFile();
|
||||||
|
|
||||||
QString path() const;
|
QString path() const;
|
||||||
|
qint64 playPosition() const;
|
||||||
|
|
||||||
|
void setPlayPosition(const qint64 &position);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void statusChanged();
|
void statusChanged();
|
||||||
void downloadProgressChanged();
|
void downloadProgressChanged();
|
||||||
void cancelDownload();
|
void cancelDownload();
|
||||||
|
void playPositionChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -58,7 +62,8 @@ private:
|
||||||
QString m_title;
|
QString m_title;
|
||||||
QString m_type;
|
QString m_type;
|
||||||
QString m_url;
|
QString m_url;
|
||||||
int m_playposition;
|
qint64 m_playposition;
|
||||||
|
qint64 m_playposition_dbsave;
|
||||||
double m_downloadProgress = 0;
|
double m_downloadProgress = 0;
|
||||||
Status m_status;
|
Status m_status;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue