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.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 <QUrl>
#include <KFormat>
#include <memory>
#include "entry.h"
@ -36,6 +38,9 @@ class AudioManager : public QObject
Q_PROPERTY(bool canSkipForward READ canSkipForward NOTIFY canSkipForwardChanged)
Q_PROPERTY(bool canSkipBackward READ canSkipBackward NOTIFY canSkipBackwardChanged)
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:
static AudioManager &instance()
@ -84,6 +89,10 @@ public:
[[nodiscard]] bool canGoNext() const;
QString formattedDuration() const;
QString formattedLeftDuration() const;
QString formattedPosition() const;
Q_SIGNALS:
void entryChanged(Entry *entry);
@ -172,4 +181,5 @@ private:
friend class AudioManagerPrivate;
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);
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 <QString>
#include <KFormat>
class Entry;
class Enclosure : public QObject
@ -18,6 +20,7 @@ class Enclosure : public QObject
Q_OBJECT
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 type MEMBER m_type 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(QString path READ path CONSTANT)
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(QString formattedDuration READ formattedDuration NOTIFY durationChanged)
public:
Enclosure(Entry *entry);
@ -46,6 +51,9 @@ public:
qint64 playPosition() const;
qint64 duration() const;
int size() const;
QString formattedSize() const;
QString formattedDuration() const;
QString formattedPlayPosition() const;
void setPlayPosition(const qint64 &position);
void setDuration(const qint64 &duration);
@ -73,4 +81,5 @@ private:
qint64 m_playposition_dbsave;
double m_downloadProgress = 0;
Status m_status;
KFormat m_kformat;
};

View File

@ -11,7 +11,6 @@ import QtMultimedia 5.15
import QtGraphicalEffects 1.15
import org.kde.kirigami 2.14 as Kirigami
import org.kde.kcoreaddons 1.0 as KCoreAddons
import org.kde.kasts 1.0
@ -91,7 +90,7 @@ Kirigami.SwipeListItem {
}
Controls.Label {
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
elide: Text.ElideRight
font: Kirigami.Theme.smallFont
@ -111,7 +110,7 @@ Kirigami.SwipeListItem {
Component {
id: subtitle
Controls.Label {
text: KCoreAddons.Format.formatDuration(entry.enclosure.duration * 1000)
text: entry.enclosure.formattedDuration
Layout.fillWidth: true
elide: Text.ElideRight
font: Kirigami.Theme.smallFont
@ -133,7 +132,7 @@ Kirigami.SwipeListItem {
id: playProgress
RowLayout {
Controls.Label {
text: KCoreAddons.Format.formatDuration(entry.enclosure.playPosition)
text: entry.enclosure.formattedPlayPosition
elide: Text.ElideRight
font: Kirigami.Theme.smallFont
opacity: 0.7
@ -145,7 +144,7 @@ Kirigami.SwipeListItem {
Layout.fillWidth: true
}
Controls.Label {
text: KCoreAddons.Format.formatDuration(entry.enclosure.duration * 1000)
text: entry.enclosure.formattedDuration
elide: Text.ElideRight
font: Kirigami.Theme.smallFont
opacity: 0.7

View File

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

View File

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

View File

@ -9,7 +9,6 @@ import QtQuick.Controls 2.14 as Controls
import QtQuick.Layouts 1.2
import org.kde.kirigami 2.13 as Kirigami
import org.kde.kcoreaddons 1.0 as KCoreAddons
import org.kde.kasts 1.0
@ -62,7 +61,7 @@ Kirigami.ScrollablePage {
Controls.Label {
Layout.fillWidth: true
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 {
Layout.fillWidth: true

View File

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

View File

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