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