Refactor size property in Enclosure

This will make sure that the size is automatically updated in the GUI if
it's corrected based on the real, downloaded audio file.
This commit is contained in:
Bart De Vries 2021-04-18 22:31:55 +02:00
parent 7a900b5921
commit 423409403e
2 changed files with 23 additions and 8 deletions

View File

@ -138,13 +138,7 @@ void Enclosure::processDownloadedFile() {
QFile file(path());
if(file.size() != m_size) {
qDebug() << "enclosure file size mismatch" << m_entry->title();
m_size = file.size();
QSqlQuery query;
query.prepare(QStringLiteral("UPDATE Enclosures SET size=:size WHERE id=:id AND feed=:feed"));
query.bindValue(QStringLiteral(":id"), m_entry->id());
query.bindValue(QStringLiteral(":feed"), m_entry->feed()->url());
query.bindValue(QStringLiteral(":size"), m_size);
Database::instance().execute(query);
setSize(file.size());
}
Q_EMIT DataManager::instance().downloadCountChanged(m_entry->feed()->url());
@ -185,6 +179,10 @@ qint64 Enclosure::duration() const {
return m_duration;
}
int Enclosure::size() const {
return m_size;
}
void Enclosure::setPlayPosition(const qint64 &position)
{
m_playposition = position;
@ -218,3 +216,17 @@ void Enclosure::setDuration(const qint64 &duration)
query.bindValue(QStringLiteral(":duration"), m_duration);
Database::instance().execute(query);
}
void Enclosure::setSize(const int &size)
{
m_size = size;
Q_EMIT sizeChanged();
// also save to database
QSqlQuery query;
query.prepare(QStringLiteral("UPDATE Enclosures SET size=:size WHERE id=:id AND feed=:feed"));
query.bindValue(QStringLiteral(":id"), m_entry->id());
query.bindValue(QStringLiteral(":feed"), m_entry->feed()->url());
query.bindValue(QStringLiteral(":size"), m_size);
Database::instance().execute(query);
}

View File

@ -19,7 +19,7 @@ class Enclosure : public QObject
Q_OBJECT
Q_PROPERTY(int duration MEMBER m_duration CONSTANT)
Q_PROPERTY(int size MEMBER m_size CONSTANT)
Q_PROPERTY(int size READ size WRITE setSize NOTIFY sizeChanged)
Q_PROPERTY(QString title MEMBER m_title CONSTANT)
Q_PROPERTY(QString type MEMBER m_type CONSTANT)
Q_PROPERTY(QString url MEMBER m_url CONSTANT)
@ -47,9 +47,11 @@ public:
Status status() const;
qint64 playPosition() const;
qint64 duration() const;
int size() const;
void setPlayPosition(const qint64 &position);
void setDuration(const qint64 &duration);
void setSize(const int &size);
Q_SIGNALS:
void statusChanged();
@ -57,6 +59,7 @@ Q_SIGNALS:
void cancelDownload();
void playPositionChanged();
void durationChanged();
void sizeChanged();
private: