Commit 2ccf0082 authored by Alexander Stippich's avatar Alexander Stippich

Rework the mediaplayercontrol

Summary:
Rework the mediaplayercontrol to use the new previous
and next tracks from mediaplaylist. Allows a large
cleanup.

Depends on D22771

Test Plan:
tests pass
play, next and previous buttons are still enabled as before
Random and repeat buttons still work as before

Reviewers: ngraham, mgallien

Reviewed By: mgallien

Tags: #elisa

Differential Revision: https://phabricator.kde.org/D22772
parent 85ca893d
This diff is collapsed.
......@@ -46,20 +46,9 @@ private Q_SLOTS:
void simpleInitialCase();
void addItemInModelCase();
void addItemInModelCaseV2();
void nextAndPreviousButtonAndRandomPlay();
void moveCurrentTrack();
void moveAnotherTrack();
void setCurrentTrackTest();
void setPlayListModelTest();
void testPlayingCase();
void testTracksCase();
};
#endif // MANAGEMEDIAPLAYERCONTROLTEST_H
......@@ -378,11 +378,13 @@ void ElisaApplication::initializePlayer()
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::positionChanged, d->mAudioControl.get(), &ManageAudioPlayer::setPlayerPosition);
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::currentPlayingForRadiosChanged, d->mAudioControl.get(), &ManageAudioPlayer::setCurrentPlayingForRadios);
d->mPlayerControl->setPlayListModel(d->mMediaPlayList.get());
QObject::connect(d->mMediaPlayList.get(), &MediaPlayList::currentTrackChanged, d->mPlayerControl.get(), &ManageMediaPlayerControl::setCurrentTrack);
QObject::connect(d->mMediaPlayList.get(), &MediaPlayList::previousTrackChanged, d->mPlayerControl.get(), &ManageMediaPlayerControl::setPreviousTrack);
QObject::connect(d->mMediaPlayList.get(), &MediaPlayList::nextTrackChanged, d->mPlayerControl.get(), &ManageMediaPlayerControl::setNextTrack);
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::playing, d->mPlayerControl.get(), &ManageMediaPlayerControl::playerPlaying);
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::paused, d->mPlayerControl.get(), &ManageMediaPlayerControl::playerPaused);
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::stopped, d->mPlayerControl.get(), &ManageMediaPlayerControl::playerStopped);
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::paused, d->mPlayerControl.get(), &ManageMediaPlayerControl::playerPausedOrStopped);
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::stopped, d->mPlayerControl.get(), &ManageMediaPlayerControl::playerPausedOrStopped);
d->mManageHeaderBar->setTitleRole(MediaPlayList::TitleRole);
d->mManageHeaderBar->setAlbumRole(MediaPlayList::AlbumRole);
......
......@@ -175,8 +175,6 @@ void ElisaQmlTestPlugin::registerTypes(const char *uri)
qRegisterMetaType<ViewManager::ViewsType>("ViewManager::ViewsType");
qRegisterMetaType<ViewManager::SortOrder>("ViewManager::SortOrder");
qRegisterMetaTypeStreamOperators<ManageMediaPlayerControl::PlayerState>("PlayListControler::PlayerState");
qmlRegisterUncreatableType<ElisaApplication>(uri, 1, 0, "ElisaApplication", QStringLiteral("only one and done in c++"));
qmlRegisterUncreatableMetaObject(ElisaUtils::staticMetaObject, uri, 1, 0, "ElisaUtils", QStringLiteral("Namespace ElisaUtils"));
}
......@@ -17,7 +17,7 @@
#include "managemediaplayercontrol.h"
#include <QDataStream>
#include <QDebug>
ManageMediaPlayerControl::ManageMediaPlayerControl(QObject *parent) : QObject(parent)
{
......@@ -26,75 +26,45 @@ ManageMediaPlayerControl::ManageMediaPlayerControl(QObject *parent) : QObject(pa
bool ManageMediaPlayerControl::playControlEnabled() const
{
if (!mPlayListModel) {
return false;
}
if (!mCurrentTrack.isValid()) {
return false;
}
return mPlayListModel->rowCount() > 0;
return mCurrentTrack.isValid();
}
bool ManageMediaPlayerControl::skipBackwardControlEnabled() const
{
if (!mPlayListModel) {
return false;
}
if (!mCurrentTrack.isValid()) {
return false;
}
return (mRandomOrContinuePlay || (mCurrentTrack.row() > 0)) && mIsInPlayingState;
return (mPreviousTrack.isValid() && mIsInPlayingState);
}
bool ManageMediaPlayerControl::skipForwardControlEnabled() const
{
if (!mPlayListModel) {
return false;
}
if (!mCurrentTrack.isValid()) {
return false;
}
return (mRandomOrContinuePlay || (mCurrentTrack.row() < mPlayListModel->rowCount() - 1)) && mIsInPlayingState;
return (mNextTrack.isValid() && mIsInPlayingState);
}
bool ManageMediaPlayerControl::musicPlaying() const
{
return mPlayerState == ManageMediaPlayerControl::PlayerState::Playing;
return mIsInPlayingState;
}
void ManageMediaPlayerControl::playerPaused()
void ManageMediaPlayerControl::playerPausedOrStopped()
{
//qDebug() << "ManageMediaPlayerControl::playerPaused";
if (!mIsInPlayingState) {
if (mIsInPlayingState) {
auto oldPreviousTrackIsEnabled = skipBackwardControlEnabled();
auto oldNextTrackIsEnabled = skipForwardControlEnabled();
mIsInPlayingState = true;
mIsInPlayingState = false;
Q_EMIT musicPlayingChanged();
if (!mCurrentTrack.isValid()) {
return;
}
auto newNextTrackIsEnabled = skipForwardControlEnabled();
if (oldNextTrackIsEnabled != newNextTrackIsEnabled) {
if (oldNextTrackIsEnabled != skipForwardControlEnabled()) {
Q_EMIT skipForwardControlEnabledChanged();
}
auto newPreviousTrackIsEnabled = skipBackwardControlEnabled();
if (oldPreviousTrackIsEnabled != newPreviousTrackIsEnabled) {
if (oldPreviousTrackIsEnabled != skipBackwardControlEnabled()) {
Q_EMIT skipBackwardControlEnabledChanged();
}
}
mPlayerState = ManageMediaPlayerControl::PlayerState::Paused;
Q_EMIT musicPlayingChanged();
}
void ManageMediaPlayerControl::playerPlaying()
......@@ -104,51 +74,36 @@ void ManageMediaPlayerControl::playerPlaying()
auto oldNextTrackIsEnabled = skipForwardControlEnabled();
mIsInPlayingState = true;
Q_EMIT musicPlayingChanged();
if (!mCurrentTrack.isValid()) {
return;
}
auto newNextTrackIsEnabled = skipForwardControlEnabled();
if (oldNextTrackIsEnabled != newNextTrackIsEnabled) {
if (oldNextTrackIsEnabled != skipForwardControlEnabled()) {
Q_EMIT skipForwardControlEnabledChanged();
}
auto newPreviousTrackIsEnabled = skipBackwardControlEnabled();
if (oldPreviousTrackIsEnabled != newPreviousTrackIsEnabled) {
if (oldPreviousTrackIsEnabled != skipBackwardControlEnabled()) {
Q_EMIT skipBackwardControlEnabledChanged();
}
}
mPlayerState = ManageMediaPlayerControl::PlayerState::Playing;
Q_EMIT musicPlayingChanged();
}
void ManageMediaPlayerControl::playerStopped()
void ManageMediaPlayerControl::setPreviousTrack(const QPersistentModelIndex &previousTrack)
{
//qDebug() << "ManageMediaPlayerControl::playerStopped";
if (mIsInPlayingState) {
auto oldPreviousTrackIsEnabled = skipBackwardControlEnabled();
auto oldNextTrackIsEnabled = skipForwardControlEnabled();
if (mPreviousTrack == previousTrack) {
return;
}
mIsInPlayingState = false;
bool oldValueSkipBackward = skipBackwardControlEnabled();
if (mCurrentTrack.isValid()) {
auto newNextTrackIsEnabled = skipForwardControlEnabled();
if (oldNextTrackIsEnabled != newNextTrackIsEnabled) {
Q_EMIT skipForwardControlEnabledChanged();
}
mPreviousTrack = previousTrack;
Q_EMIT previousTrackChanged();
auto newPreviousTrackIsEnabled = skipBackwardControlEnabled();
if (oldPreviousTrackIsEnabled != newPreviousTrackIsEnabled) {
Q_EMIT skipBackwardControlEnabledChanged();
}
}
if (oldValueSkipBackward != skipBackwardControlEnabled()) {
Q_EMIT skipBackwardControlEnabledChanged();
}
mPlayerState = ManageMediaPlayerControl::PlayerState::Stopped;
Q_EMIT musicPlayingChanged();
}
void ManageMediaPlayerControl::setCurrentTrack(const QPersistentModelIndex &currentTrack)
......@@ -158,8 +113,6 @@ void ManageMediaPlayerControl::setCurrentTrack(const QPersistentModelIndex &curr
}
bool oldPlayControlEnabled = playControlEnabled();
bool oldValueSkipBackward = skipBackwardControlEnabled();
bool oldValueSkipForward = skipForwardControlEnabled();
mCurrentTrack = currentTrack;
Q_EMIT currentTrackChanged();
......@@ -167,198 +120,27 @@ void ManageMediaPlayerControl::setCurrentTrack(const QPersistentModelIndex &curr
if (oldPlayControlEnabled != playControlEnabled()) {
Q_EMIT playControlEnabledChanged();
}
if (!mIsInPlayingState) {
return;
}
if (oldValueSkipBackward != skipBackwardControlEnabled()) {
Q_EMIT skipBackwardControlEnabledChanged();
}
if (oldValueSkipForward != skipForwardControlEnabled()) {
Q_EMIT skipForwardControlEnabledChanged();
}
}
bool ManageMediaPlayerControl::randomOrContinuePlay() const
{
return mRandomOrContinuePlay;
}
void ManageMediaPlayerControl::setRandomOrContinuePlay(bool randomOrContinuePlay)
void ManageMediaPlayerControl::setNextTrack(const QPersistentModelIndex &nextTrack)
{
if (mRandomOrContinuePlay == randomOrContinuePlay) {
if (mNextTrack == nextTrack) {
return;
}
auto oldPreviousTrackIsEnabled = skipBackwardControlEnabled();
auto oldNextTrackIsEnabled = skipForwardControlEnabled();
mRandomOrContinuePlay = randomOrContinuePlay;
Q_EMIT randomOrContinuePlayChanged();
auto newNextTrackIsEnabled = skipForwardControlEnabled();
if (oldNextTrackIsEnabled != newNextTrackIsEnabled) {
Q_EMIT skipForwardControlEnabledChanged();
}
auto newPreviousTrackIsEnabled = skipBackwardControlEnabled();
if (oldPreviousTrackIsEnabled != newPreviousTrackIsEnabled) {
Q_EMIT skipBackwardControlEnabledChanged();
}
}
void ManageMediaPlayerControl::playListTracksWillBeInserted(const QModelIndex &parent, int first, int last)
{
Q_UNUSED(parent);
Q_UNUSED(first);
Q_UNUSED(last);
mSkipBackwardControlWasEnabled = skipBackwardControlEnabled();
mSkipForwardControlWasEnabled = skipForwardControlEnabled();
}
void ManageMediaPlayerControl::playListTracksInserted(const QModelIndex &parent, int first, int last)
{
Q_UNUSED(parent);
Q_UNUSED(first);
Q_UNUSED(last);
if (!mCurrentTrack.isValid()) {
mSkipBackwardControlWasEnabled = false;
mSkipForwardControlWasEnabled = false;
return;
}
auto newNextTrackIsEnabled = skipForwardControlEnabled();
if (mSkipForwardControlWasEnabled != newNextTrackIsEnabled) {
Q_EMIT skipForwardControlEnabledChanged();
}
auto newPreviousTrackIsEnabled = skipBackwardControlEnabled();
if (mSkipBackwardControlWasEnabled != newPreviousTrackIsEnabled) {
Q_EMIT skipBackwardControlEnabledChanged();
}
}
void ManageMediaPlayerControl::playListTracksWillBeRemoved(const QModelIndex &parent, int first, int last)
{
Q_UNUSED(parent);
if (!mCurrentTrack.isValid()) {
mCurrentTrackWillBeRemoved = false;
mSkipBackwardControlWasEnabled = false;
mSkipForwardControlWasEnabled = false;
return;
}
mCurrentTrackWillBeRemoved = (mCurrentTrack.row() >= first && mCurrentTrack.row() <= last);
mSkipBackwardControlWasEnabled = skipBackwardControlEnabled();
mSkipForwardControlWasEnabled = skipForwardControlEnabled();
}
void ManageMediaPlayerControl::playListTracksRemoved(const QModelIndex &parent, int first, int last)
{
Q_UNUSED(parent);
Q_UNUSED(first);
Q_UNUSED(last);
if (mCurrentTrackWillBeRemoved) {
Q_EMIT currentTrackChanged();
Q_EMIT playControlEnabledChanged();
}
if (!mCurrentTrack.isValid()) {
if (mSkipBackwardControlWasEnabled) {
Q_EMIT skipBackwardControlEnabledChanged();
}
if (mSkipForwardControlWasEnabled) {
Q_EMIT skipForwardControlEnabledChanged();
}
return;
}
auto newNextTrackIsEnabled = skipForwardControlEnabled();
if (mSkipForwardControlWasEnabled != newNextTrackIsEnabled) {
Q_EMIT skipForwardControlEnabledChanged();
}
auto newPreviousTrackIsEnabled = skipBackwardControlEnabled();
if (mSkipBackwardControlWasEnabled != newPreviousTrackIsEnabled) {
Q_EMIT skipBackwardControlEnabledChanged();
}
}
void ManageMediaPlayerControl::playListReset()
{
}
bool oldValueSkipForward = skipForwardControlEnabled();
void ManageMediaPlayerControl::tracksAboutToBeMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
{
Q_UNUSED(parent);
Q_UNUSED(start);
Q_UNUSED(end);
Q_UNUSED(destination);
Q_UNUSED(row);
mSkipBackwardControlWasEnabled = skipBackwardControlEnabled();
mSkipForwardControlWasEnabled = skipForwardControlEnabled();
}
mNextTrack = nextTrack;
Q_EMIT nextTrackChanged();
void ManageMediaPlayerControl::tracksMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
{
Q_UNUSED(parent);
Q_UNUSED(start);
Q_UNUSED(end);
Q_UNUSED(destination);
Q_UNUSED(row);
auto newNextTrackIsEnabled = skipForwardControlEnabled();
if (mSkipForwardControlWasEnabled != newNextTrackIsEnabled) {
if (oldValueSkipForward != skipForwardControlEnabled()) {
Q_EMIT skipForwardControlEnabledChanged();
}
auto newPreviousTrackIsEnabled = skipBackwardControlEnabled();
if (mSkipBackwardControlWasEnabled != newPreviousTrackIsEnabled) {
Q_EMIT skipBackwardControlEnabledChanged();
}
}
void ManageMediaPlayerControl::setPlayListModel(QAbstractItemModel *aPlayListModel)
QPersistentModelIndex ManageMediaPlayerControl::previousTrack() const
{
if (mPlayListModel) {
disconnect(mPlayListModel, &QAbstractItemModel::rowsAboutToBeInserted, this, &ManageMediaPlayerControl::playListTracksWillBeInserted);
disconnect(mPlayListModel, &QAbstractItemModel::rowsInserted, this, &ManageMediaPlayerControl::playListTracksInserted);
disconnect(mPlayListModel, &QAbstractItemModel::rowsAboutToBeRemoved, this, &ManageMediaPlayerControl::playListTracksWillBeRemoved);
disconnect(mPlayListModel, &QAbstractItemModel::rowsRemoved, this, &ManageMediaPlayerControl::playListTracksRemoved);
disconnect(mPlayListModel, &QAbstractItemModel::rowsMoved, this, &ManageMediaPlayerControl::tracksMoved);
disconnect(mPlayListModel, &QAbstractItemModel::rowsAboutToBeMoved, this, &ManageMediaPlayerControl::tracksAboutToBeMoved);
disconnect(mPlayListModel, &QAbstractItemModel::modelReset, this, &ManageMediaPlayerControl::playListReset);
}
mPlayListModel = aPlayListModel;
if (mPlayListModel) {
connect(mPlayListModel, &QAbstractItemModel::rowsAboutToBeInserted, this, &ManageMediaPlayerControl::playListTracksWillBeInserted);
connect(mPlayListModel, &QAbstractItemModel::rowsInserted, this, &ManageMediaPlayerControl::playListTracksInserted);
connect(mPlayListModel, &QAbstractItemModel::rowsAboutToBeRemoved, this, &ManageMediaPlayerControl::playListTracksWillBeRemoved);
connect(mPlayListModel, &QAbstractItemModel::rowsRemoved, this, &ManageMediaPlayerControl::playListTracksRemoved);
connect(mPlayListModel, &QAbstractItemModel::rowsMoved, this, &ManageMediaPlayerControl::tracksMoved);
connect(mPlayListModel, &QAbstractItemModel::rowsAboutToBeMoved, this, &ManageMediaPlayerControl::tracksAboutToBeMoved);
connect(mPlayListModel, &QAbstractItemModel::modelReset, this, &ManageMediaPlayerControl::playListReset);
}
Q_EMIT playListModelChanged();
}
QAbstractItemModel *ManageMediaPlayerControl::playListModel() const
{
return mPlayListModel;
return mPreviousTrack;
}
QPersistentModelIndex ManageMediaPlayerControl::currentTrack() const
......@@ -366,19 +148,9 @@ QPersistentModelIndex ManageMediaPlayerControl::currentTrack() const
return mCurrentTrack;
}
QDataStream &operator<<(QDataStream &out, const ManageMediaPlayerControl::PlayerState &state)
QPersistentModelIndex ManageMediaPlayerControl::nextTrack() const
{
out << static_cast<int>(state);
return out;
return mNextTrack;
}
QDataStream &operator>>(QDataStream &in, ManageMediaPlayerControl::PlayerState &state)
{
int value;
in >> value;
state = static_cast<ManageMediaPlayerControl::PlayerState>(value);
return in;
}
#include "moc_managemediaplayercontrol.cpp"
......@@ -46,32 +46,23 @@ class ELISALIB_EXPORT ManageMediaPlayerControl : public QObject
READ musicPlaying
NOTIFY musicPlayingChanged)
Q_PROPERTY(QAbstractItemModel* playListModel
READ playListModel
WRITE setPlayListModel
NOTIFY playListModelChanged)
Q_PROPERTY(QPersistentModelIndex previousTrack
READ previousTrack
WRITE setPreviousTrack
NOTIFY previousTrackChanged)
Q_PROPERTY(QPersistentModelIndex currentTrack
READ currentTrack
WRITE setCurrentTrack
NOTIFY currentTrackChanged)
Q_PROPERTY(bool randomOrContinuePlay
READ randomOrContinuePlay
WRITE setRandomOrContinuePlay
NOTIFY randomOrContinuePlayChanged)
Q_PROPERTY(QPersistentModelIndex nextTrack
READ nextTrack
WRITE setNextTrack
NOTIFY nextTrackChanged)
public:
enum class PlayerState
{
Playing,
Paused,
Stopped,
};
Q_ENUM(PlayerState)
explicit ManageMediaPlayerControl(QObject *parent = nullptr);
bool playControlEnabled() const;
......@@ -82,11 +73,11 @@ public:
bool musicPlaying() const;
QAbstractItemModel* playListModel() const;
QPersistentModelIndex previousTrack() const;
QPersistentModelIndex currentTrack() const;
bool randomOrContinuePlay() const;
QPersistentModelIndex nextTrack() const;
Q_SIGNALS:
......@@ -98,48 +89,32 @@ Q_SIGNALS:
void musicPlayingChanged();
void playListModelChanged();
void previousTrackChanged();
void currentTrackChanged();
void randomOrContinuePlayChanged();
void nextTrackChanged();
public Q_SLOTS:
void setPlayListModel(QAbstractItemModel* aPlayListModel);
void playerPaused();
void playerPausedOrStopped();
void playerPlaying();
void playerStopped();
void setPreviousTrack(const QPersistentModelIndex &previousTrack);
void setCurrentTrack(const QPersistentModelIndex &currentTrack);
void setRandomOrContinuePlay(bool randomOrContinuePlay);
private Q_SLOTS:
void playListTracksWillBeInserted(const QModelIndex &parent, int first, int last);
void playListTracksInserted(const QModelIndex &parent, int first, int last);
void playListTracksWillBeRemoved(const QModelIndex & parent, int first, int last);
void playListTracksRemoved(const QModelIndex & parent, int first, int last);
void playListReset();
void tracksAboutToBeMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row);
void tracksMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row);
void setNextTrack(const QPersistentModelIndex &nextTrack);
private:
QAbstractItemModel *mPlayListModel = nullptr;
QPersistentModelIndex mPreviousTrack;
QPersistentModelIndex mCurrentTrack;
QPersistentModelIndex mNextTrack;
bool mCurrentTrackWillBeRemoved = false;
bool mSkipBackwardControlWasEnabled = false;
......@@ -148,13 +123,6 @@ private:
bool mIsInPlayingState = false;
PlayerState mPlayerState = ManageMediaPlayerControl::PlayerState::Stopped;
bool mRandomOrContinuePlay = false;
};
ELISALIB_EXPORT QDataStream &operator<<(QDataStream &out, const ManageMediaPlayerControl::PlayerState &state);
ELISALIB_EXPORT QDataStream &operator>>(QDataStream &in, ManageMediaPlayerControl::PlayerState &state);
#endif // MANAGEMEDIAPLAYERCONTROL_H
......@@ -325,7 +325,6 @@ ApplicationWindow {
elisa.mediaPlayList.randomPlay = Qt.binding(function() { return headerBar.playerControl.shuffle })
elisa.mediaPlayList.repeatPlay = Qt.binding(function() { return headerBar.playerControl.repeat })
elisa.playerControl.randomOrContinuePlay = Qt.binding(function() { return headerBar.playerControl.shuffle || headerBar.playerControl.repeat})
elisa.audioPlayer.muted = Qt.binding(function() { return headerBar.playerControl.muted })
elisa.audioPlayer.volume = Qt.binding(function() { return headerBar.playerControl.volume })
......
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