mirror of https://github.com/KDE/kasts.git
Add header to QueuePage with remaining episodes and time
This commit is contained in:
parent
1461c7e86c
commit
d224eb1b24
|
@ -53,15 +53,30 @@ Kirigami.ScrollablePage {
|
|||
ListView {
|
||||
id: queueList
|
||||
visible: count !== 0
|
||||
anchors.fill: parent
|
||||
|
||||
header: ColumnLayout {
|
||||
anchors.right: parent.right
|
||||
anchors.left: parent.left
|
||||
Controls.Label {
|
||||
Layout.fillWidth: true
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: i18np("1 episode", "%1 episodes", queueModel.rowCount()) + " · " + i18n("Time left") + ": " + audio.timeString(queueModel.timeLeft)
|
||||
}
|
||||
Kirigami.Separator {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
|
||||
model: QueueModel {
|
||||
id: queueModel
|
||||
audioManager: audio
|
||||
}
|
||||
|
||||
delegate: Kirigami.DelegateRecycler {
|
||||
width: queueList.width
|
||||
sourceComponent: delegateComponent
|
||||
}
|
||||
anchors.fill: parent
|
||||
|
||||
moveDisplaced: Transition {
|
||||
YAnimator {
|
||||
|
@ -71,4 +86,3 @@ Kirigami.ScrollablePage {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
*/
|
||||
|
||||
#include <QString>
|
||||
#include <QThread>
|
||||
|
||||
#include "audiomanager.h"
|
||||
#include "datamanager.h"
|
||||
#include "entry.h"
|
||||
#include "queuemodel.h"
|
||||
|
@ -13,22 +15,24 @@
|
|||
QueueModel::QueueModel(QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
{
|
||||
connect(&DataManager::instance(), &DataManager::queueEntryMoved, this, [this](const int from, const int to_orig) {
|
||||
connect(&DataManager::instance(), &DataManager::queueEntryMoved, this, [this](int from, int to_orig) {
|
||||
int to = (from < to_orig) ? to_orig + 1 : to_orig;
|
||||
beginMoveRows(QModelIndex(), from, from, QModelIndex(), to);
|
||||
endMoveRows();
|
||||
// qDebug() << "Moved entry" << from << "to" << to;
|
||||
});
|
||||
connect(&DataManager::instance(), &DataManager::queueEntryAdded, this, [this](const int pos, const QString &id) {
|
||||
connect(&DataManager::instance(), &DataManager::queueEntryAdded, this, [this](int pos, const QString &id) {
|
||||
Q_UNUSED(id)
|
||||
beginInsertRows(QModelIndex(), pos, pos);
|
||||
endInsertRows();
|
||||
Q_EMIT timeLeftChanged();
|
||||
// qDebug() << "Added entry at pos" << pos;
|
||||
});
|
||||
connect(&DataManager::instance(), &DataManager::queueEntryRemoved, this, [this](const int pos, const QString &id) {
|
||||
connect(&DataManager::instance(), &DataManager::queueEntryRemoved, this, [this](int pos, const QString &id) {
|
||||
Q_UNUSED(id)
|
||||
beginRemoveRows(QModelIndex(), pos, pos);
|
||||
endRemoveRows();
|
||||
Q_EMIT timeLeftChanged();
|
||||
// qDebug() << "Removed entry at pos" << pos;
|
||||
});
|
||||
}
|
||||
|
@ -54,3 +58,33 @@ int QueueModel::rowCount(const QModelIndex &parent) const
|
|||
// qDebug() << "queueCount is" << DataManager::instance().queueCount();
|
||||
return DataManager::instance().queueCount();
|
||||
}
|
||||
|
||||
int QueueModel::timeLeft() const
|
||||
{
|
||||
int result = 0;
|
||||
QStringList queue = DataManager::instance().queue();
|
||||
for (QString item : queue) {
|
||||
Entry *entry = DataManager::instance().getEntry(item);
|
||||
if (entry->enclosure()) {
|
||||
result += entry->enclosure()->duration() * 1000 - entry->enclosure()->playPosition();
|
||||
}
|
||||
}
|
||||
// qDebug() << "timeLeft is" << result;
|
||||
return result;
|
||||
}
|
||||
|
||||
AudioManager *QueueModel::audioManager()
|
||||
{
|
||||
return m_audio;
|
||||
}
|
||||
|
||||
void QueueModel::setAudioManager(AudioManager *audio)
|
||||
{
|
||||
// AudioManager is qml-owned; we need the pointer to the instance
|
||||
// in order to connect to the positionChanged signal
|
||||
m_audio = audio;
|
||||
connect(m_audio, &AudioManager::positionChanged, this, [this](qint64 position) {
|
||||
Q_UNUSED(position)
|
||||
Q_EMIT timeLeftChanged();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -11,14 +11,34 @@
|
|||
#include <QObject>
|
||||
#include <QVariant>
|
||||
|
||||
#include "audiomanager.h"
|
||||
|
||||
class QueueModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(int timeLeft READ timeLeft NOTIFY timeLeftChanged)
|
||||
Q_PROPERTY(AudioManager *audioManager READ audioManager WRITE setAudioManager)
|
||||
|
||||
public:
|
||||
static QueueModel &instance()
|
||||
{
|
||||
static QueueModel _instance;
|
||||
return _instance;
|
||||
}
|
||||
explicit QueueModel(QObject * = nullptr);
|
||||
//~QueueModel() override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
int rowCount(const QModelIndex &parent) const override;
|
||||
int timeLeft() const;
|
||||
|
||||
AudioManager *audioManager();
|
||||
void setAudioManager(AudioManager *audio);
|
||||
|
||||
Q_SIGNALS:
|
||||
void timeLeftChanged();
|
||||
|
||||
private:
|
||||
AudioManager *m_audio;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue