Commit d8d6d037 authored by Matthieu Gallien's avatar Matthieu Gallien 🎵

fix now playing view no longer updating to follow playing track

Summary:
properly initialize the metadata model in now playing view

BUG: 412334

Test Plan: Now playing view works OK and no warnings are printed in console

Reviewers: #elisa, ngraham, astippich, jguidon

Reviewed By: #elisa, ngraham

Differential Revision: https://phabricator.kde.org/D24274
parent 5e0c7685
......@@ -393,6 +393,7 @@ void ElisaApplication::initializePlayer()
d->mManageHeaderBar->setFileNameRole(MediaPlayList::ResourceRole);
d->mManageHeaderBar->setImageRole(MediaPlayList::ImageUrlRole);
d->mManageHeaderBar->setDatabaseIdRole(MediaPlayList::DatabaseIdRole);
d->mManageHeaderBar->setTrackTypeRole(MediaPlayList::ElementTypeRole);
d->mManageHeaderBar->setAlbumIdRole(MediaPlayList::AlbumIdRole);
d->mManageHeaderBar->setIsValidRole(MediaPlayList::IsValidRole);
QObject::connect(d->mMediaPlayList.get(), &MediaPlayList::currentTrackChanged, d->mManageHeaderBar.get(), &ManageHeaderBar::setCurrentTrack);
......
......@@ -92,6 +92,12 @@ void ManageHeaderBar::setDatabaseIdRole(int databaseIdRole)
Q_EMIT databaseIdRoleChanged();
}
void ManageHeaderBar::setTrackTypeRole(int trackTypeRole)
{
mTrackTypeIdRole = trackTypeRole;
Q_EMIT trackTypeRoleChanged();
}
int ManageHeaderBar::imageRole() const
{
return mImageRole;
......@@ -102,6 +108,11 @@ int ManageHeaderBar::databaseIdRole() const
return mDatabaseIdRole;
}
int ManageHeaderBar::trackTypeRole() const
{
return mTrackTypeIdRole;
}
void ManageHeaderBar::setAlbumIdRole(int albumIdRole)
{
mAlbumIdRole = albumIdRole;
......@@ -185,6 +196,15 @@ qulonglong ManageHeaderBar::databaseId() const
return mCurrentTrack.data(mDatabaseIdRole).toULongLong();
}
ElisaUtils::PlayListEntryType ManageHeaderBar::trackType() const
{
if (!mCurrentTrack.isValid()) {
return ElisaUtils::Unknown;
}
return mCurrentTrack.data(mTrackTypeIdRole).value<ElisaUtils::PlayListEntryType>();
}
qulonglong ManageHeaderBar::albumId() const
{
if (!mCurrentTrack.isValid()) {
......@@ -288,6 +308,16 @@ void ManageHeaderBar::notifyDatabaseIdProperty()
}
}
void ManageHeaderBar::notifyTrackTypeProperty()
{
auto newTrackTypeValue = mCurrentTrack.data(mTrackTypeIdRole).value<ElisaUtils::PlayListEntryType>();
if (mOldTrackType != newTrackTypeValue) {
Q_EMIT trackTypeRoleChanged();
mOldTrackType = newTrackTypeValue;
}
}
void ManageHeaderBar::notifyAlbumIdProperty()
{
bool conversionOk;
......@@ -331,6 +361,7 @@ void ManageHeaderBar::setCurrentTrack(const QPersistentModelIndex &currentTrack)
notifyFileNameProperty();
notifyImageProperty();
notifyDatabaseIdProperty();
notifyTrackTypeProperty();
notifyAlbumIdProperty();
notifyIsValidProperty();
}
......
......@@ -20,6 +20,8 @@
#include "elisaLib_export.h"
#include "elisautils.h"
#include <QObject>
#include <QList>
#include <QPersistentModelIndex>
......@@ -71,6 +73,11 @@ class ELISALIB_EXPORT ManageHeaderBar : public QObject
WRITE setDatabaseIdRole
NOTIFY databaseIdRoleChanged)
Q_PROPERTY(int trackTypeRole
READ trackTypeRole
WRITE setTrackTypeRole
NOTIFY trackTypeRoleChanged)
Q_PROPERTY(int albumIdRole
READ albumIdRole
WRITE setAlbumIdRole
......@@ -109,6 +116,10 @@ class ELISALIB_EXPORT ManageHeaderBar : public QObject
READ databaseId
NOTIFY databaseIdChanged)
Q_PROPERTY(ElisaUtils::PlayListEntryType trackType
READ trackType
NOTIFY trackTypeChanged)
Q_PROPERTY(qulonglong albumId
READ albumId
NOTIFY albumIdChanged)
......@@ -137,6 +148,8 @@ public:
int databaseIdRole() const;
int trackTypeRole() const;
int albumIdRole() const;
int isValidRole() const;
......@@ -155,6 +168,8 @@ public:
qulonglong databaseId() const;
ElisaUtils::PlayListEntryType trackType() const;
qulonglong albumId() const;
bool isValid() const;
......@@ -177,6 +192,8 @@ Q_SIGNALS:
void databaseIdRoleChanged();
void trackTypeRoleChanged();
void albumIdRoleChanged();
void isValidRoleChanged();
......@@ -197,6 +214,8 @@ Q_SIGNALS:
void albumIdChanged();
void trackTypeChanged();
void isValidChanged();
public Q_SLOTS:
......@@ -217,6 +236,8 @@ public Q_SLOTS:
void setDatabaseIdRole(int databaseIdRole);
void setTrackTypeRole(int trackTypeRole);
void setAlbumIdRole(int albumIdRole);
void setIsValidRole(int isValidRole);
......@@ -237,6 +258,8 @@ private:
void notifyDatabaseIdProperty();
void notifyTrackTypeProperty();
void notifyAlbumIdProperty();
void notifyIsValidProperty();
......@@ -257,6 +280,8 @@ private:
int mDatabaseIdRole = Qt::DisplayRole;
int mTrackTypeIdRole = Qt::DisplayRole;
int mAlbumIdRole = Qt::DisplayRole;
int mIsValidRole = Qt::DisplayRole;
......@@ -275,6 +300,8 @@ private:
qulonglong mOldDatabaseId = 0;
ElisaUtils::PlayListEntryType mOldTrackType = ElisaUtils::Unknown;
qulonglong mOldAlbumId = 0;
bool mOldIsValid = false;
......
......@@ -339,6 +339,7 @@ RowLayout {
StackView.onActivated: viewManager.viewIsLoaded(viewType)
databaseId: elisa.manageHeaderBar.databaseId
trackType: elisa.manageHeaderBar.trackType
title: elisa.manageHeaderBar.title
artistName: elisa.manageHeaderBar.artist
albumName: elisa.manageHeaderBar.album
......
......@@ -29,6 +29,7 @@ FocusScope {
property var viewType
property int databaseId: 0
property var trackType
property alias title: titleLabel.text
property string albumName: ''
property string artistName: ''
......@@ -258,20 +259,20 @@ FocusScope {
}
onDatabaseIdChanged: {
metaDataModel.initializeByTrackId(databaseId)
metaDataModel.initializeById(trackType, databaseId)
}
Connections {
target: elisa
onMusicManagerChanged: {
metaDataModel.initializeByTrackId(databaseId)
metaDataModel.initializeById(trackType, databaseId)
}
}
Component.onCompleted: {
if (elisa.musicManager) {
metaDataModel.initializeByTrackId(databaseId)
metaDataModel.initializeById(trackType, databaseId)
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment