Port away from KDeclarative

This commit is contained in:
Tobias Fella 2021-06-03 16:23:06 +02:00
parent 2145c58333
commit 3f1f3045ec
10 changed files with 70 additions and 15 deletions

View File

@ -504,3 +504,18 @@ void AudioManagerPrivate::prepareAudioStream()
m_player.setPosition(startingPosition); m_player.setPosition(startingPosition);
m_player.pause(); m_player.pause();
} }
QString AudioManager::formattedDuration() const
{
return m_kformat.formatDuration(d->m_player.duration());
}
QString AudioManager::formattedLeftDuration() const
{
return m_kformat.formatDuration(d->m_player.duration() - d->m_player.position());
}
QString AudioManager::formattedPosition() const
{
return m_kformat.formatDuration(d->m_player.position());
}

View File

@ -12,6 +12,8 @@
#include <QString> #include <QString>
#include <QUrl> #include <QUrl>
#include <KFormat>
#include <memory> #include <memory>
#include "entry.h" #include "entry.h"
@ -36,6 +38,9 @@ class AudioManager : public QObject
Q_PROPERTY(bool canSkipForward READ canSkipForward NOTIFY canSkipForwardChanged) Q_PROPERTY(bool canSkipForward READ canSkipForward NOTIFY canSkipForwardChanged)
Q_PROPERTY(bool canSkipBackward READ canSkipBackward NOTIFY canSkipBackwardChanged) Q_PROPERTY(bool canSkipBackward READ canSkipBackward NOTIFY canSkipBackwardChanged)
Q_PROPERTY(bool canGoNext READ canGoNext NOTIFY canGoNextChanged) Q_PROPERTY(bool canGoNext READ canGoNext NOTIFY canGoNextChanged)
Q_PROPERTY(QString formattedLeftDuration READ formattedLeftDuration NOTIFY positionChanged)
Q_PROPERTY(QString formattedDuration READ formattedDuration NOTIFY durationChanged)
Q_PROPERTY(QString formattedPosition READ formattedPosition NOTIFY positionChanged)
public: public:
static AudioManager &instance() static AudioManager &instance()
@ -84,6 +89,10 @@ public:
[[nodiscard]] bool canGoNext() const; [[nodiscard]] bool canGoNext() const;
QString formattedDuration() const;
QString formattedLeftDuration() const;
QString formattedPosition() const;
Q_SIGNALS: Q_SIGNALS:
void entryChanged(Entry *entry); void entryChanged(Entry *entry);
@ -172,4 +181,5 @@ private:
friend class AudioManagerPrivate; friend class AudioManagerPrivate;
std::unique_ptr<AudioManagerPrivate> d; std::unique_ptr<AudioManagerPrivate> d;
KFormat m_kformat;
}; };

View File

@ -249,3 +249,18 @@ void Enclosure::setSize(const int &size)
query.bindValue(QStringLiteral(":size"), m_size); query.bindValue(QStringLiteral(":size"), m_size);
Database::instance().execute(query); Database::instance().execute(query);
} }
QString Enclosure::formattedSize() const
{
return m_kformat.formatByteSize(m_size);
}
QString Enclosure::formattedDuration() const
{
return m_kformat.formatDuration(m_duration * 1000);
}
QString Enclosure::formattedPlayPosition() const
{
return m_kformat.formatDuration(m_playposition);
}

View File

@ -11,6 +11,8 @@
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <KFormat>
class Entry; class Entry;
class Enclosure : public QObject class Enclosure : public QObject
@ -18,6 +20,7 @@ class Enclosure : public QObject
Q_OBJECT Q_OBJECT
Q_PROPERTY(int size READ size WRITE setSize NOTIFY sizeChanged) Q_PROPERTY(int size READ size WRITE setSize NOTIFY sizeChanged)
Q_PROPERTY(QString formattedSize READ formattedSize NOTIFY sizeChanged)
Q_PROPERTY(QString title MEMBER m_title CONSTANT) Q_PROPERTY(QString title MEMBER m_title CONSTANT)
Q_PROPERTY(QString type MEMBER m_type CONSTANT) Q_PROPERTY(QString type MEMBER m_type CONSTANT)
Q_PROPERTY(QString url MEMBER m_url CONSTANT) Q_PROPERTY(QString url MEMBER m_url CONSTANT)
@ -25,7 +28,9 @@ class Enclosure : public QObject
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(qint64 playPosition READ playPosition WRITE setPlayPosition NOTIFY playPositionChanged) Q_PROPERTY(qint64 playPosition READ playPosition WRITE setPlayPosition NOTIFY playPositionChanged)
Q_PROPERTY(QString formattedPlayPosition READ formattedPlayPosition NOTIFY playPositionChanged);
Q_PROPERTY(qint64 duration READ duration WRITE setDuration NOTIFY durationChanged) Q_PROPERTY(qint64 duration READ duration WRITE setDuration NOTIFY durationChanged)
Q_PROPERTY(QString formattedDuration READ formattedDuration NOTIFY durationChanged)
public: public:
Enclosure(Entry *entry); Enclosure(Entry *entry);
@ -46,6 +51,9 @@ public:
qint64 playPosition() const; qint64 playPosition() const;
qint64 duration() const; qint64 duration() const;
int size() const; int size() const;
QString formattedSize() const;
QString formattedDuration() const;
QString formattedPlayPosition() const;
void setPlayPosition(const qint64 &position); void setPlayPosition(const qint64 &position);
void setDuration(const qint64 &duration); void setDuration(const qint64 &duration);
@ -73,4 +81,5 @@ private:
qint64 m_playposition_dbsave; qint64 m_playposition_dbsave;
double m_downloadProgress = 0; double m_downloadProgress = 0;
Status m_status; Status m_status;
KFormat m_kformat;
}; };

View File

@ -11,7 +11,6 @@ import QtMultimedia 5.15
import QtGraphicalEffects 1.15 import QtGraphicalEffects 1.15
import org.kde.kirigami 2.14 as Kirigami import org.kde.kirigami 2.14 as Kirigami
import org.kde.kcoreaddons 1.0 as KCoreAddons
import org.kde.kasts 1.0 import org.kde.kasts 1.0
@ -91,7 +90,7 @@ Kirigami.SwipeListItem {
} }
Controls.Label { Controls.Label {
id: supertitle id: supertitle
text: (!isQueue && entry.queueStatus ? "· " : "") + entry.updated.toLocaleDateString(Qt.locale(), Locale.NarrowFormat) + (entry.enclosure ? ( entry.enclosure.size !== 0 ? " · " + KCoreAddons.Format.formatByteSize(entry.enclosure.size) : "") : "" ) text: (!isQueue && entry.queueStatus ? "· " : "") + entry.updated.toLocaleDateString(Qt.locale(), Locale.NarrowFormat) + (entry.enclosure ? ( entry.enclosure.size !== 0 ? " · " + entry.enclosure.formattedSize : "") : "" )
Layout.fillWidth: true Layout.fillWidth: true
elide: Text.ElideRight elide: Text.ElideRight
font: Kirigami.Theme.smallFont font: Kirigami.Theme.smallFont
@ -111,7 +110,7 @@ Kirigami.SwipeListItem {
Component { Component {
id: subtitle id: subtitle
Controls.Label { Controls.Label {
text: KCoreAddons.Format.formatDuration(entry.enclosure.duration * 1000) text: entry.enclosure.formattedDuration
Layout.fillWidth: true Layout.fillWidth: true
elide: Text.ElideRight elide: Text.ElideRight
font: Kirigami.Theme.smallFont font: Kirigami.Theme.smallFont
@ -133,7 +132,7 @@ Kirigami.SwipeListItem {
id: playProgress id: playProgress
RowLayout { RowLayout {
Controls.Label { Controls.Label {
text: KCoreAddons.Format.formatDuration(entry.enclosure.playPosition) text: entry.enclosure.formattedPlayPosition
elide: Text.ElideRight elide: Text.ElideRight
font: Kirigami.Theme.smallFont font: Kirigami.Theme.smallFont
opacity: 0.7 opacity: 0.7
@ -145,7 +144,7 @@ Kirigami.SwipeListItem {
Layout.fillWidth: true Layout.fillWidth: true
} }
Controls.Label { Controls.Label {
text: KCoreAddons.Format.formatDuration(entry.enclosure.duration * 1000) text: entry.enclosure.formattedDuration
elide: Text.ElideRight elide: Text.ElideRight
font: Kirigami.Theme.smallFont font: Kirigami.Theme.smallFont
opacity: 0.7 opacity: 0.7

View File

@ -11,7 +11,6 @@ import QtMultimedia 5.15
import QtGraphicalEffects 1.15 import QtGraphicalEffects 1.15
import org.kde.kirigami 2.14 as Kirigami import org.kde.kirigami 2.14 as Kirigami
import org.kde.kcoreaddons 1.0 as KCoreAddons
import org.kde.kasts 1.0 import org.kde.kasts 1.0
@ -134,7 +133,7 @@ Rectangle {
RowLayout { RowLayout {
Layout.fillWidth: true Layout.fillWidth: true
Label { Label {
text: KCoreAddons.Format.formatDuration(AudioManager.position) text: AudioManager.formattedPosition
} }
Slider { Slider {
id: durationSlider id: durationSlider
@ -156,8 +155,8 @@ Rectangle {
anchors.right: parent.right anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
text: (SettingsManager.toggleRemainingTime) ? text: (SettingsManager.toggleRemainingTime) ?
"-" + KCoreAddons.Format.formatDuration(AudioManager.duration-AudioManager.position) "-" + AudioManager.formattedLeftDuration
: KCoreAddons.Format.formatDuration(AudioManager.duration) : AudioManager.formattedDuration
} }
MouseArea { MouseArea {

View File

@ -11,7 +11,6 @@ import QtMultimedia 5.15
import QtGraphicalEffects 1.15 import QtGraphicalEffects 1.15
import org.kde.kirigami 2.14 as Kirigami import org.kde.kirigami 2.14 as Kirigami
import org.kde.kcoreaddons 1.0 as KCoreAddons
import org.kde.kasts 1.0 import org.kde.kasts 1.0
@ -152,7 +151,7 @@ Kirigami.Page {
Layout.fillWidth: true Layout.fillWidth: true
Controls.Label { Controls.Label {
padding: Kirigami.Units.largeSpacing padding: Kirigami.Units.largeSpacing
text: KCoreAddons.Format.formatDuration(AudioManager.position) text: AudioManager.formattedPosition
} }
Item { Item {
Layout.fillWidth: true Layout.fillWidth: true
@ -166,8 +165,8 @@ Kirigami.Page {
anchors.right: parent.right anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
text: (SettingsManager.toggleRemainingTime) ? text: (SettingsManager.toggleRemainingTime) ?
"-" + KCoreAddons.Format.formatDuration(AudioManager.duration-AudioManager.position) "-" + AudioManager.formattedLeftDuration
: KCoreAddons.Format.formatDuration(AudioManager.duration) : AudioManager.formattedDuration
} }
MouseArea { MouseArea {

View File

@ -9,7 +9,6 @@ import QtQuick.Controls 2.14 as Controls
import QtQuick.Layouts 1.2 import QtQuick.Layouts 1.2
import org.kde.kirigami 2.13 as Kirigami import org.kde.kirigami 2.13 as Kirigami
import org.kde.kcoreaddons 1.0 as KCoreAddons
import org.kde.kasts 1.0 import org.kde.kasts 1.0
@ -62,7 +61,7 @@ Kirigami.ScrollablePage {
Controls.Label { Controls.Label {
Layout.fillWidth: true Layout.fillWidth: true
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
text: i18np("1 Episode", "%1 Episodes", queueModel.rowCount()) + " · " + i18n("Time Left") + ": " + KCoreAddons.Format.formatDuration(queueModel.timeLeft) text: i18np("1 Episode", "%1 Episodes", queueModel.rowCount()) + " · " + i18n("Time Left") + ": " + queueModel.formattedTimeLeft
} }
Kirigami.Separator { Kirigami.Separator {
Layout.fillWidth: true Layout.fillWidth: true

View File

@ -78,3 +78,9 @@ int QueueModel::timeLeft() const
// qDebug() << "timeLeft is" << result; // qDebug() << "timeLeft is" << result;
return result; return result;
} }
QString QueueModel::formattedTimeLeft() const
{
static KFormat format;
return format.formatDuration(timeLeft());
}

View File

@ -11,6 +11,8 @@
#include <QObject> #include <QObject>
#include <QVariant> #include <QVariant>
#include <KFormat>
#include "audiomanager.h" #include "audiomanager.h"
class QueueModel : public QAbstractListModel class QueueModel : public QAbstractListModel
@ -18,6 +20,7 @@ class QueueModel : public QAbstractListModel
Q_OBJECT Q_OBJECT
Q_PROPERTY(int timeLeft READ timeLeft NOTIFY timeLeftChanged) Q_PROPERTY(int timeLeft READ timeLeft NOTIFY timeLeftChanged)
Q_PROPERTY(QString formattedTimeLeft READ formattedTimeLeft NOTIFY timeLeftChanged)
public: public:
static QueueModel &instance() static QueueModel &instance()
@ -31,6 +34,7 @@ public:
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent) const override; int rowCount(const QModelIndex &parent) const override;
int timeLeft() const; int timeLeft() const;
QString formattedTimeLeft() const;
Q_SIGNALS: Q_SIGNALS:
void timeLeftChanged(); void timeLeftChanged();