Commit 9b44b1df authored by Alexander Stippich's avatar Alexander Stippich
Browse files

move header bar and control manager to c++

Summary: next step of moving more classes to c++

Test Plan: headerbar still shows correct data, player controls still work

Reviewers: mgallien

Reviewed By: mgallien

Tags: #elisa

Differential Revision: https://phabricator.kde.org/D12789
parent 4f6142b7
......@@ -29,6 +29,8 @@
#include "mediaplaylist.h"
#include "audiowrapper.h"
#include "manageaudioplayer.h"
#include "managemediaplayercontrol.h"
#include "manageheaderbar.h"
#include "elisa_settings.h"
#include <KConfigCore/KAuthorized>
......@@ -106,6 +108,10 @@ public:
std::unique_ptr<ManageAudioPlayer> mAudioControl;
std::unique_ptr<ManageMediaPlayerControl> mPlayerControl;
std::unique_ptr<ManageHeaderBar> mManageHeaderBar;
};
ElisaApplication::ElisaApplication(QObject *parent) : QObject(parent), d(std::make_unique<ElisaApplicationPrivate>(this))
......@@ -270,6 +276,12 @@ QStringList ElisaApplication::checkFileListAndMakeAbsolute(const QStringList &fi
}
void ElisaApplication::initialize()
{
initializeModels();
initializePlayer();
}
void ElisaApplication::initializeModels()
{
d->mMusicManager = std::make_unique<MusicListenersManager>();
Q_EMIT musicManagerChanged();
......@@ -285,10 +297,6 @@ void ElisaApplication::initialize()
Q_EMIT singleAlbumProxyModelChanged();
d->mMediaPlayList = std::make_unique<MediaPlayList>();
Q_EMIT mediaPlayListChanged();
d->mAudioWrapper = std::make_unique<AudioWrapper>();
Q_EMIT audioPlayerChanged();
d->mAudioControl = std::make_unique<ManageAudioPlayer>();
Q_EMIT audioControlChanged();
d->mMusicManager->setElisaApplication(this);
......@@ -324,16 +332,25 @@ void ElisaApplication::initialize()
ElisaUtils::PlayListEnqueueMode,
ElisaUtils::PlayListEnqueueTriggerPlay)>(&MediaPlayList::enqueue));
}
void ElisaApplication::initializePlayer()
{
d->mAudioWrapper = std::make_unique<AudioWrapper>();
Q_EMIT audioPlayerChanged();
d->mAudioControl = std::make_unique<ManageAudioPlayer>();
Q_EMIT audioControlChanged();
d->mPlayerControl = std::make_unique<ManageMediaPlayerControl>();
Q_EMIT playerControlChanged();
d->mManageHeaderBar = std::make_unique<ManageHeaderBar>();
Q_EMIT manageHeaderBarChanged();
d->mAudioControl->setAlbumNameRole(MediaPlayList::AlbumRole);
d->mAudioControl->setArtistNameRole(MediaPlayList::ArtistRole);
d->mAudioControl->setTitleRole(MediaPlayList::TitleRole);
d->mAudioControl->setUrlRole(MediaPlayList::ResourceRole);
d->mAudioControl->setIsPlayingRole(MediaPlayList::IsPlayingRole);
d->mAudioControl->setPlayListModel(d->mMediaPlayList.get());
d->mAudioControl->setCurrentTrack(d->mMediaPlayList->currentTrack());
d->mAudioWrapper->setSource(d->mAudioControl->playerSource());
QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::playerPlay, d->mAudioWrapper.get(), &AudioWrapper::play);
QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::playerPause, d->mAudioWrapper.get(), &AudioWrapper::pause);
......@@ -355,6 +372,20 @@ void ElisaApplication::initialize()
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::seekableChanged, d->mAudioControl.get(), &ManageAudioPlayer::setPlayerIsSeekable);
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::positionChanged, d->mAudioControl.get(), &ManageAudioPlayer::setPlayerPosition);
d->mPlayerControl->setPlayListModel(d->mMediaPlayList.get());
QObject::connect(d->mMediaPlayList.get(), &MediaPlayList::currentTrackChanged, d->mPlayerControl.get(), &ManageMediaPlayerControl::setCurrentTrack);
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);
d->mManageHeaderBar->setTitleRole(MediaPlayList::TitleRole);
d->mManageHeaderBar->setAlbumRole(MediaPlayList::AlbumRole);
d->mManageHeaderBar->setArtistRole(MediaPlayList::ArtistRole);
d->mManageHeaderBar->setImageRole(MediaPlayList::ImageRole);
d->mManageHeaderBar->setIsValidRole(MediaPlayList::IsValidRole);
d->mManageHeaderBar->setPlayListModel(d->mMediaPlayList.get());
QObject::connect(d->mMediaPlayList.get(), &MediaPlayList::currentTrackChanged, d->mManageHeaderBar.get(), &ManageHeaderBar::setCurrentTrack);
if (!d->mArguments.isEmpty()) {
Q_EMIT enqueue(d->mArguments);
}
......@@ -433,4 +464,14 @@ ManageAudioPlayer *ElisaApplication::audioControl() const
return d->mAudioControl.get();
}
ManageMediaPlayerControl *ElisaApplication::playerControl() const
{
return d->mPlayerControl.get();
}
ManageHeaderBar *ElisaApplication::manageHeaderBar() const
{
return d->mManageHeaderBar.get();
}
#include "moc_elisaapplication.cpp"
......@@ -40,6 +40,8 @@ class SingleAlbumProxyModel;
class MediaPlayList;
class AudioWrapper;
class ManageAudioPlayer;
class ManageMediaPlayerControl;
class ManageHeaderBar;
class ElisaApplicationPrivate;
class ELISALIB_EXPORT ElisaApplication : public QObject
......@@ -88,6 +90,14 @@ class ELISALIB_EXPORT ElisaApplication : public QObject
READ audioControl
NOTIFY audioControlChanged)
Q_PROPERTY(ManageMediaPlayerControl *playerControl
READ playerControl
NOTIFY playerControlChanged)
Q_PROPERTY(ManageHeaderBar *manageHeaderBar
READ manageHeaderBar
NOTIFY manageHeaderBarChanged)
public:
explicit ElisaApplication(QObject *parent = nullptr);
......@@ -117,6 +127,10 @@ public:
ManageAudioPlayer *audioControl() const;
ManageMediaPlayerControl *playerControl() const;
ManageHeaderBar *manageHeaderBar() const;
Q_SIGNALS:
void argumentsChanged();
......@@ -139,6 +153,10 @@ Q_SIGNALS:
void audioControlChanged();
void playerControlChanged();
void manageHeaderBarChanged();
void enqueue(const QStringList &files);
public Q_SLOTS:
......@@ -171,6 +189,10 @@ private Q_SLOTS:
private:
void initializeModels();
void initializePlayer();
void setupActions(const QString &actionName);
QStringList checkFileListAndMakeAbsolute(const QStringList &filesList, const QString &workingDirectory) const;
......
......@@ -392,9 +392,9 @@ RowLayout {
visible: Layout.minimumWidth != 0
artistName: myHeaderBarManager.artist
albumName: myHeaderBarManager.album
albumArtUrl: myHeaderBarManager.image
artistName: elisa.manageHeaderBar.artist
albumName: elisa.manageHeaderBar.album
albumArtUrl: elisa.manageHeaderBar.image
}
}
}
......
......@@ -134,34 +134,21 @@ ApplicationWindow {
playListModel: elisa.mediaPlayList
audioPlayerManager: elisa.audioControl
player: elisa.audioPlayer
headerBarManager: myHeaderBarManager
manageMediaPlayerControl: myPlayControlManager
onRaisePlayer:
{
headerBarManager: elisa.manageHeaderBar
manageMediaPlayerControl: elisa.playerControl
onRaisePlayer: {
mainWindow.show()
mainWindow.raise()
mainWindow.requestActivate()
}
}
}
Connections {
target: elisa.audioPlayer
onVolumeChanged: headerBar.playerControl.volume = elisa.audioPlayer.volume
onMutedChanged: headerBar.playerControl.muted = elisa.audioPlayer.muted
onPlaying: {
myPlayControlManager.playerPlaying()
}
onPaused: {
myPlayControlManager.playerPaused()
}
onStopped: {
myPlayControlManager.playerStopped()
}
}
Connections {
......@@ -172,26 +159,6 @@ ApplicationWindow {
}
}
ManageHeaderBar {
id: myHeaderBarManager
playListModel: elisa.mediaPlayList
currentTrack: elisa.mediaPlayList.currentTrack
artistRole: MediaPlayList.ArtistRole
titleRole: MediaPlayList.TitleRole
albumRole: MediaPlayList.AlbumRole
imageRole: MediaPlayList.ImageRole
isValidRole: MediaPlayList.IsValidRole
}
ManageMediaPlayerControl {
id: myPlayControlManager
playListModel: elisa.mediaPlayList
currentTrack: elisa.mediaPlayList.currentTrack
}
PassiveNotification {
id: messageNotification
}
......@@ -217,11 +184,11 @@ ApplicationWindow {
anchors.fill: parent
tracksCount: myHeaderBarManager.remainingTracks
album: myHeaderBarManager.album
title: myHeaderBarManager.title
artist: myHeaderBarManager.artist
image: myHeaderBarManager.image
tracksCount: elisa.manageHeaderBar.remainingTracks
album: elisa.manageHeaderBar.album
title: elisa.manageHeaderBar.title
artist: elisa.manageHeaderBar.artist
image: elisa.manageHeaderBar.image
ratingVisible: false
......@@ -231,10 +198,10 @@ ApplicationWindow {
playerControl.volume: persistentSettings.playControlItemVolume
playerControl.muted: persistentSettings.playControlItemMuted
playerControl.position: elisa.audioPlayer.position
playerControl.skipBackwardEnabled: myPlayControlManager.skipBackwardControlEnabled
playerControl.skipForwardEnabled: myPlayControlManager.skipForwardControlEnabled
playerControl.playEnabled: myPlayControlManager.playControlEnabled
playerControl.isPlaying: myPlayControlManager.musicPlaying
playerControl.skipBackwardEnabled: elisa.playerControl.skipBackwardControlEnabled
playerControl.skipForwardEnabled: elisa.playerControl.skipForwardControlEnabled
playerControl.playEnabled: elisa.playerControl.playControlEnabled
playerControl.isPlaying: elisa.playerControl.musicPlaying
playerControl.repeat: persistentSettings.playControlItemRepeat
playerControl.shuffle: persistentSettings.playControlItemShuffle
......@@ -299,11 +266,9 @@ ApplicationWindow {
{
elisa.initialize()
elisa.mediaPlayList.randomPlay = Qt.binding(function() { return headerBar.playerControl.shuffle })
elisa.mediaPlayList.repeatPlay = Qt.binding(function() { return headerBar.playerControl.repeat })
myPlayControlManager.randomOrContinuePlay = Qt.binding(function() { return headerBar.playerControl.shuffle || headerBar.playerControl.repeat })
myPlayControlManager.playListModel = Qt.binding(function() { return elisa.mediaPlayList })
myPlayControlManager.currentTrack = Qt.binding(function() { return elisa.mediaPlayList.currentTrack })
elisa.mediaPlayList.randomPlay = Qt.binding(function() { return contentView.playList.randomPlayChecked })
elisa.mediaPlayList.repeatPlay = Qt.binding(function() { return contentView.playList.repeatPlayChecked })
elisa.playerControl.randomOrContinuePlay = Qt.binding(function() { return contentView.playList.randomPlayChecked || contentView.playList.repeatPlayChecked })
if (persistentSettings.playListState) {
elisa.mediaPlayList.persistentState = persistentSettings.playListState
......@@ -316,8 +281,6 @@ ApplicationWindow {
elisa.audioPlayer.muted = Qt.binding(function() { return headerBar.playerControl.muted })
elisa.audioPlayer.volume = Qt.binding(function() { return headerBar.playerControl.volume })
volume: headerBar.playerControl.volume
mprisloader.active = true
}
}
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