diff --git a/autotests/managemediaplayercontroltest.cpp b/autotests/managemediaplayercontroltest.cpp index 15511827..4920c37e 100644 --- a/autotests/managemediaplayercontroltest.cpp +++ b/autotests/managemediaplayercontroltest.cpp @@ -1,754 +1,173 @@ /* * Copyright 2016-2017 Matthieu Gallien * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "managemediaplayercontroltest.h" #include "managemediaplayercontrol.h" #include "mediaplaylist.h" #include "databaseinterface.h" #include "musicaudiotrack.h" #include "trackslistener.h" #include #include #include #include #include #include #include #include ManageMediaPlayerControlTest::ManageMediaPlayerControlTest(QObject *parent) : QObject(parent) { } void ManageMediaPlayerControlTest::initTestCase() { qRegisterMetaType>("QHash"); qRegisterMetaType>("QVector"); qRegisterMetaType>("QHash"); } void ManageMediaPlayerControlTest::simpleInitialCase() { ManageMediaPlayerControl myControl; - QCOMPARE(myControl.playControlEnabled(), false); - QCOMPARE(myControl.skipBackwardControlEnabled(), false); - QCOMPARE(myControl.skipForwardControlEnabled(), false); - QCOMPARE(myControl.musicPlaying(), false); - QCOMPARE(myControl.playListModel(), static_cast(nullptr)); - QCOMPARE(myControl.currentTrack().isValid(), false); + QVERIFY(!myControl.playControlEnabled()); + QVERIFY(!myControl.skipBackwardControlEnabled()); + QVERIFY(!myControl.skipForwardControlEnabled()); + QVERIFY(!myControl.musicPlaying()); + QVERIFY(!myControl.currentTrack().isValid()); } -void ManageMediaPlayerControlTest::addItemInModelCase() +void ManageMediaPlayerControlTest::testPlayingCase() { - QStringListModel myPlayList; - ManageMediaPlayerControl myControl; - QCOMPARE(myControl.playControlEnabled(), false); - QCOMPARE(myControl.skipBackwardControlEnabled(), false); - QCOMPARE(myControl.skipForwardControlEnabled(), false); - QCOMPARE(myControl.musicPlaying(), false); - QCOMPARE(myControl.playListModel(), static_cast(nullptr)); - QCOMPARE(myControl.currentTrack().isValid(), false); - - QSignalSpy playControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::playControlEnabledChanged); - QSignalSpy skipBackwardControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::skipBackwardControlEnabledChanged); - QSignalSpy skipForwardControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::skipForwardControlEnabledChanged); QSignalSpy musicPlayingChangedSpy(&myControl, &ManageMediaPlayerControl::musicPlayingChanged); - QSignalSpy playListModelChangedSpy(&myControl, &ManageMediaPlayerControl::playListModelChanged); - QSignalSpy currentTrackChangedSpy(&myControl, &ManageMediaPlayerControl::currentTrackChanged); - myControl.setPlayListModel(&myPlayList); + QVERIFY(!myControl.playControlEnabled()); + QVERIFY(!myControl.skipBackwardControlEnabled()); + QVERIFY(!myControl.skipForwardControlEnabled()); + QVERIFY(!myControl.musicPlaying()); + QVERIFY(!myControl.currentTrack().isValid()); - QCOMPARE(playControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 0); - - QCOMPARE(myControl.playListModel(), &myPlayList); - - myPlayList.setStringList({QStringLiteral("tutu")}); - - QCOMPARE(playControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 0); - - myControl.setCurrentTrack(myPlayList.index(0, 0)); - - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myControl.playControlEnabled(), true); - QCOMPARE(myControl.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myControl.playerPlaying(); - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 1); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myControl.musicPlaying(), true); - - QCOMPARE(myPlayList.insertRows(1, 2, {}), true); - - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 1); - QCOMPARE(musicPlayingChangedSpy.count(), 1); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myControl.skipForwardControlEnabled(), true); - - QCOMPARE(myPlayList.insertRows(0, 2, {}), true); - - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 1); - QCOMPARE(musicPlayingChangedSpy.count(), 1); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myControl.skipBackwardControlEnabled(), true); - - QCOMPARE(myPlayList.removeRows(3, 2, {}), true); - - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 2); - QCOMPARE(musicPlayingChangedSpy.count(), 1); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myControl.skipForwardControlEnabled(), false); - - QCOMPARE(myPlayList.removeRows(0, 2, {}), true); - - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 2); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 2); - QCOMPARE(musicPlayingChangedSpy.count(), 1); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myControl.skipBackwardControlEnabled(), false); - - QCOMPARE(myPlayList.removeRows(0, 1, {}), true); - - QCOMPARE(playControlEnabledChangedSpy.count(), 2); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 2); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 2); QCOMPARE(musicPlayingChangedSpy.count(), 1); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 2); - QCOMPARE(myControl.playControlEnabled(), false); - QCOMPARE(myControl.currentTrack().isValid(), false); + QVERIFY(myControl.musicPlaying()); - myControl.playerStopped(); + myControl.playerPausedOrStopped(); - QCOMPARE(playControlEnabledChangedSpy.count(), 2); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 2); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 2); QCOMPARE(musicPlayingChangedSpy.count(), 2); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 2); - QCOMPARE(myControl.musicPlaying(), false); + QVERIFY(!myControl.musicPlaying()); } -void ManageMediaPlayerControlTest::addItemInModelCaseV2() +void ManageMediaPlayerControlTest::testTracksCase() { QStringListModel myPlayList; + myPlayList.setStringList({QStringLiteral("first"), QStringLiteral("second"), QStringLiteral("third")}); ManageMediaPlayerControl myControl; - QCOMPARE(myControl.playControlEnabled(), false); - QCOMPARE(myControl.skipBackwardControlEnabled(), false); - QCOMPARE(myControl.skipForwardControlEnabled(), false); - QCOMPARE(myControl.musicPlaying(), false); - QCOMPARE(myControl.playListModel(), static_cast(nullptr)); - QCOMPARE(myControl.currentTrack().isValid(), false); - QSignalSpy playControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::playControlEnabledChanged); QSignalSpy skipBackwardControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::skipBackwardControlEnabledChanged); QSignalSpy skipForwardControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::skipForwardControlEnabledChanged); - QSignalSpy musicPlayingChangedSpy(&myControl, &ManageMediaPlayerControl::musicPlayingChanged); - QSignalSpy playListModelChangedSpy(&myControl, &ManageMediaPlayerControl::playListModelChanged); + QSignalSpy previousTrackChangedSpy(&myControl, &ManageMediaPlayerControl::previousTrackChanged); QSignalSpy currentTrackChangedSpy(&myControl, &ManageMediaPlayerControl::currentTrackChanged); + QSignalSpy nextTrackChangedSpy(&myControl, &ManageMediaPlayerControl::nextTrackChanged); - myControl.setPlayListModel(&myPlayList); - - QCOMPARE(playControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 0); - - QCOMPARE(myControl.playListModel(), &myPlayList); - - myPlayList.setStringList({QStringLiteral("tutu")}); - - QCOMPARE(playControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 0); + QVERIFY(!myControl.playControlEnabled()); + QVERIFY(!myControl.skipBackwardControlEnabled()); + QVERIFY(!myControl.skipForwardControlEnabled()); + QVERIFY(!myControl.musicPlaying()); + QVERIFY(!myControl.currentTrack().isValid()); - myControl.setCurrentTrack(myPlayList.index(0, 0)); + myControl.setCurrentTrack(QPersistentModelIndex(myPlayList.index(1, 0))); - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(previousTrackChangedSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myControl.playControlEnabled(), true); - QCOMPARE(myControl.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); - - myControl.playerPlaying(); - - QCOMPARE(playControlEnabledChangedSpy.count(), 1); + QCOMPARE(nextTrackChangedSpy.count(), 0); QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 1); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myControl.musicPlaying(), true); - - QCOMPARE(myPlayList.insertRows(1, 2, {}), true); - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 1); - QCOMPARE(musicPlayingChangedSpy.count(), 1); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myControl.skipForwardControlEnabled(), true); - - QCOMPARE(myPlayList.insertRows(0, 2, {}), true); - - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 1); - QCOMPARE(musicPlayingChangedSpy.count(), 1); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myControl.skipBackwardControlEnabled(), true); - - QCOMPARE(myPlayList.removeRows(2, 1, {}), true); - - QCOMPARE(playControlEnabledChangedSpy.count(), 2); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 2); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 2); - QCOMPARE(musicPlayingChangedSpy.count(), 1); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 2); - - QCOMPARE(myControl.playControlEnabled(), false); - QCOMPARE(myControl.currentTrack().isValid(), false); - QCOMPARE(myControl.skipBackwardControlEnabled(), false); - QCOMPARE(myControl.skipForwardControlEnabled(), false); - - myControl.playerStopped(); - - QCOMPARE(playControlEnabledChangedSpy.count(), 2); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 2); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 2); - QCOMPARE(musicPlayingChangedSpy.count(), 2); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 2); - - QCOMPARE(myControl.musicPlaying(), false); - - QCOMPARE(myPlayList.removeRows(0, 4, {}), true); - - QCOMPARE(playControlEnabledChangedSpy.count(), 2); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 2); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 2); - QCOMPARE(musicPlayingChangedSpy.count(), 2); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 2); -} -void ManageMediaPlayerControlTest::nextAndPreviousButtonAndRandomPlay() -{ - QStringListModel myPlayList; - - ManageMediaPlayerControl myControl; - - QCOMPARE(myControl.playControlEnabled(), false); - QCOMPARE(myControl.skipBackwardControlEnabled(), false); - QCOMPARE(myControl.skipForwardControlEnabled(), false); - QCOMPARE(myControl.musicPlaying(), false); - QCOMPARE(myControl.playListModel(), static_cast(nullptr)); - QCOMPARE(myControl.currentTrack().isValid(), false); - - QSignalSpy playControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::playControlEnabledChanged); - QSignalSpy skipBackwardControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::skipBackwardControlEnabledChanged); - QSignalSpy skipForwardControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::skipForwardControlEnabledChanged); - QSignalSpy musicPlayingChangedSpy(&myControl, &ManageMediaPlayerControl::musicPlayingChanged); - QSignalSpy playListModelChangedSpy(&myControl, &ManageMediaPlayerControl::playListModelChanged); - QSignalSpy currentTrackChangedSpy(&myControl, &ManageMediaPlayerControl::currentTrackChanged); - - myControl.setPlayListModel(&myPlayList); - - QCOMPARE(playControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 0); - - QCOMPARE(myControl.playListModel(), &myPlayList); - - myPlayList.setStringList({QStringLiteral("tutu")}); - - QCOMPARE(playControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 0); - - myControl.setCurrentTrack(myPlayList.index(0, 0)); - - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myControl.playControlEnabled(), true); - QCOMPARE(myControl.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); - - myControl.setRandomOrContinuePlay(true); - - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 1); - - myControl.playerPlaying(); - - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 1); - QCOMPARE(musicPlayingChangedSpy.count(), 1); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myControl.musicPlaying(), true); - QCOMPARE(myControl.skipForwardControlEnabled(), true); - QCOMPARE(myControl.skipBackwardControlEnabled(), true); + QVERIFY(myControl.playControlEnabled()); + QVERIFY(!myControl.skipBackwardControlEnabled()); + QVERIFY(!myControl.skipForwardControlEnabled()); - QCOMPARE(myPlayList.insertRows(1, 2, {}), true); + myControl.setPreviousTrack(QPersistentModelIndex(myPlayList.index(0, 0))); - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 1); - QCOMPARE(musicPlayingChangedSpy.count(), 1); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myPlayList.insertRows(0, 2, {}), true); - - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 1); - QCOMPARE(musicPlayingChangedSpy.count(), 1); - QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(previousTrackChangedSpy.count(), 1); QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myPlayList.removeRows(3, 2, {}), true); - - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 1); - QCOMPARE(musicPlayingChangedSpy.count(), 1); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 1); -} - -void ManageMediaPlayerControlTest::moveCurrentTrack() -{ - MediaPlayList myPlayList; - DatabaseInterface myDatabaseContent; - TracksListener myListener(&myDatabaseContent); - - myDatabaseContent.init(QStringLiteral("testDbDirectContent")); - - connect(&myListener, &TracksListener::trackHasChanged, - &myPlayList, &MediaPlayList::trackChanged, - Qt::QueuedConnection); - connect(&myListener, &TracksListener::tracksListAdded, - &myPlayList, &MediaPlayList::tracksListAdded, - Qt::QueuedConnection); - connect(&myPlayList, &MediaPlayList::newEntryInList, - &myListener, &TracksListener::newEntryInList, - Qt::QueuedConnection); - connect(&myPlayList, &MediaPlayList::newTrackByNameInList, - &myListener, &TracksListener::trackByNameInList, - Qt::QueuedConnection); - connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, - &myListener, &TracksListener::tracksAdded); - - ManageMediaPlayerControl myControl; - - QCOMPARE(myControl.playControlEnabled(), false); - QCOMPARE(myControl.skipBackwardControlEnabled(), false); - QCOMPARE(myControl.skipForwardControlEnabled(), false); - QCOMPARE(myControl.musicPlaying(), false); - QCOMPARE(myControl.playListModel(), static_cast(nullptr)); - QCOMPARE(myControl.currentTrack().isValid(), false); - - QSignalSpy playControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::playControlEnabledChanged); - QSignalSpy skipBackwardControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::skipBackwardControlEnabledChanged); - QSignalSpy skipForwardControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::skipForwardControlEnabledChanged); - QSignalSpy musicPlayingChangedSpy(&myControl, &ManageMediaPlayerControl::musicPlayingChanged); - QSignalSpy playListModelChangedSpy(&myControl, &ManageMediaPlayerControl::playListModelChanged); - QSignalSpy currentTrackChangedSpy(&myControl, &ManageMediaPlayerControl::currentTrackChanged); - - myControl.setPlayListModel(&myPlayList); - - QCOMPARE(playControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 0); - - QCOMPARE(myControl.playListModel(), &myPlayList); - - myDatabaseContent.insertTracksList(mNewTracks, mNewCovers); - - myPlayList.enqueue(ElisaUtils::EntryData{myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album2"), 1, 1), - QStringLiteral("track1")}, - ElisaUtils::Track); - myPlayList.enqueue(ElisaUtils::EntryData{myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album1"), 2, 2), - QStringLiteral("track2")}, - ElisaUtils::Track); - - QCOMPARE(playControlEnabledChangedSpy.count(), 0); + QCOMPARE(nextTrackChangedSpy.count(), 0); QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 0); - - myControl.setCurrentTrack(myPlayList.index(0, 0)); - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myControl.playControlEnabled(), true); - QCOMPARE(myControl.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); + QVERIFY(myControl.playControlEnabled()); + QVERIFY(!myControl.skipBackwardControlEnabled()); + QVERIFY(!myControl.skipForwardControlEnabled()); myControl.playerPlaying(); - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 1); - QCOMPARE(musicPlayingChangedSpy.count(), 1); - QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(previousTrackChangedSpy.count(), 1); QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myControl.musicPlaying(), true); - QCOMPARE(myControl.skipForwardControlEnabled(), true); - - QCOMPARE(myPlayList.moveRows({}, 0, 1, {}, 2), true); - - QCOMPARE(playControlEnabledChangedSpy.count(), 1); + QCOMPARE(nextTrackChangedSpy.count(), 0); QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 2); - QCOMPARE(musicPlayingChangedSpy.count(), 1); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myControl.skipForwardControlEnabled(), false); - QCOMPARE(myControl.skipBackwardControlEnabled(), true); -} - -void ManageMediaPlayerControlTest::moveAnotherTrack() -{ - MediaPlayList myPlayList; - DatabaseInterface myDatabaseContent; - TracksListener myListener(&myDatabaseContent); - - myDatabaseContent.init(QStringLiteral("testDbDirectContent")); - - connect(&myListener, &TracksListener::trackHasChanged, - &myPlayList, &MediaPlayList::trackChanged, - Qt::QueuedConnection); - connect(&myListener, &TracksListener::tracksListAdded, - &myPlayList, &MediaPlayList::tracksListAdded, - Qt::QueuedConnection); - connect(&myPlayList, &MediaPlayList::newEntryInList, - &myListener, &TracksListener::newEntryInList, - Qt::QueuedConnection); - connect(&myPlayList, &MediaPlayList::newTrackByNameInList, - &myListener, &TracksListener::trackByNameInList, - Qt::QueuedConnection); - connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, - &myListener, &TracksListener::tracksAdded); - - ManageMediaPlayerControl myControl; - - QCOMPARE(myControl.playControlEnabled(), false); - QCOMPARE(myControl.skipBackwardControlEnabled(), false); - QCOMPARE(myControl.skipForwardControlEnabled(), false); - QCOMPARE(myControl.musicPlaying(), false); - QCOMPARE(myControl.playListModel(), static_cast(nullptr)); - QCOMPARE(myControl.currentTrack().isValid(), false); - - QSignalSpy playControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::playControlEnabledChanged); - QSignalSpy skipBackwardControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::skipBackwardControlEnabledChanged); - QSignalSpy skipForwardControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::skipForwardControlEnabledChanged); - QSignalSpy musicPlayingChangedSpy(&myControl, &ManageMediaPlayerControl::musicPlayingChanged); - QSignalSpy playListModelChangedSpy(&myControl, &ManageMediaPlayerControl::playListModelChanged); - QSignalSpy currentTrackChangedSpy(&myControl, &ManageMediaPlayerControl::currentTrackChanged); - - myControl.setPlayListModel(&myPlayList); - - QCOMPARE(playControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 0); - - QCOMPARE(myControl.playListModel(), &myPlayList); - - myDatabaseContent.insertTracksList(mNewTracks, mNewCovers); - - myPlayList.enqueue(ElisaUtils::EntryData{myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album2"), 1, 1), - QStringLiteral("track1")}, - ElisaUtils::Track); - myPlayList.enqueue(ElisaUtils::EntryData{myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album1"), 2, 2), - QStringLiteral("track2")}, - ElisaUtils::Track); - - QCOMPARE(playControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 0); - - myControl.setCurrentTrack(myPlayList.index(0, 0)); - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 1); + QVERIFY(myControl.playControlEnabled()); + QVERIFY(myControl.skipBackwardControlEnabled()); + QVERIFY(!myControl.skipForwardControlEnabled()); - QCOMPARE(myControl.playControlEnabled(), true); - QCOMPARE(myControl.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); + myControl.playerPausedOrStopped(); + myControl.setNextTrack(QPersistentModelIndex(myPlayList.index(2, 0))); - myControl.playerPlaying(); - - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 1); - QCOMPARE(musicPlayingChangedSpy.count(), 1); - QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(previousTrackChangedSpy.count(), 1); QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myControl.musicPlaying(), true); - QCOMPARE(myControl.skipForwardControlEnabled(), true); - - QCOMPARE(myPlayList.moveRows({}, 1, 1, {}, 0), true); - + QCOMPARE(nextTrackChangedSpy.count(), 1); + QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 2); QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 2); - QCOMPARE(musicPlayingChangedSpy.count(), 1); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myControl.skipForwardControlEnabled(), false); - QCOMPARE(myControl.skipBackwardControlEnabled(), true); -} - -void ManageMediaPlayerControlTest::setCurrentTrackTest() -{ - MediaPlayList myPlayList; - DatabaseInterface myDatabaseContent; - TracksListener myListener(&myDatabaseContent); - - myDatabaseContent.init(QStringLiteral("testDbDirectContent")); - - connect(&myListener, &TracksListener::trackHasChanged, - &myPlayList, &MediaPlayList::trackChanged, - Qt::QueuedConnection); - connect(&myListener, &TracksListener::tracksListAdded, - &myPlayList, &MediaPlayList::tracksListAdded, - Qt::QueuedConnection); - connect(&myPlayList, &MediaPlayList::newEntryInList, - &myListener, &TracksListener::newEntryInList, - Qt::QueuedConnection); - connect(&myPlayList, &MediaPlayList::newTrackByNameInList, - &myListener, &TracksListener::trackByNameInList, - Qt::QueuedConnection); - connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, - &myListener, &TracksListener::tracksAdded); - - ManageMediaPlayerControl myControl; - - QCOMPARE(myControl.playControlEnabled(), false); - QCOMPARE(myControl.skipBackwardControlEnabled(), false); - QCOMPARE(myControl.skipForwardControlEnabled(), false); - QCOMPARE(myControl.musicPlaying(), false); - QCOMPARE(myControl.playListModel(), static_cast(nullptr)); - QCOMPARE(myControl.currentTrack().isValid(), false); - - QSignalSpy playControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::playControlEnabledChanged); - QSignalSpy skipBackwardControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::skipBackwardControlEnabledChanged); - QSignalSpy skipForwardControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::skipForwardControlEnabledChanged); - QSignalSpy musicPlayingChangedSpy(&myControl, &ManageMediaPlayerControl::musicPlayingChanged); - QSignalSpy playListModelChangedSpy(&myControl, &ManageMediaPlayerControl::playListModelChanged); - QSignalSpy currentTrackChangedSpy(&myControl, &ManageMediaPlayerControl::currentTrackChanged); - - myControl.setPlayListModel(&myPlayList); - - QCOMPARE(playControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 0); - - QCOMPARE(myControl.playListModel(), &myPlayList); + QVERIFY(myControl.playControlEnabled()); + QVERIFY(!myControl.skipBackwardControlEnabled()); + QVERIFY(!myControl.skipForwardControlEnabled()); - myDatabaseContent.insertTracksList(mNewTracks, mNewCovers); - - myPlayList.enqueue(ElisaUtils::EntryData{myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album2"), 1, 1), - QStringLiteral("track1")}, - ElisaUtils::Track); - myPlayList.enqueue(ElisaUtils::EntryData{myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album1"), 2, 2), - QStringLiteral("track2")}, - ElisaUtils::Track); - - QCOMPARE(playControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 0); - - myControl.setCurrentTrack(myPlayList.index(0, 0)); + myControl.playerPlaying(); - QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(previousTrackChangedSpy.count(), 1); QCOMPARE(currentTrackChangedSpy.count(), 1); - - QCOMPARE(myControl.playControlEnabled(), true); - QCOMPARE(myControl.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); - - myControl.setCurrentTrack(myPlayList.index(0, 0)); - + QCOMPARE(nextTrackChangedSpy.count(), 1); + QCOMPARE(nextTrackChangedSpy.count(), 1); + QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 3); QCOMPARE(playControlEnabledChangedSpy.count(), 1); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 1); -} - -void ManageMediaPlayerControlTest::setPlayListModelTest() -{ - QStringListModel myPlayList; - - ManageMediaPlayerControl myControl; - - QCOMPARE(myControl.playControlEnabled(), false); - QCOMPARE(myControl.skipBackwardControlEnabled(), false); - QCOMPARE(myControl.skipForwardControlEnabled(), false); - QCOMPARE(myControl.musicPlaying(), false); - QCOMPARE(myControl.playListModel(), static_cast(nullptr)); - QCOMPARE(myControl.currentTrack().isValid(), false); - - QSignalSpy playControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::playControlEnabledChanged); - QSignalSpy skipBackwardControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::skipBackwardControlEnabledChanged); - QSignalSpy skipForwardControlEnabledChangedSpy(&myControl, &ManageMediaPlayerControl::skipForwardControlEnabledChanged); - QSignalSpy musicPlayingChangedSpy(&myControl, &ManageMediaPlayerControl::musicPlayingChanged); - QSignalSpy playListModelChangedSpy(&myControl, &ManageMediaPlayerControl::playListModelChanged); - QSignalSpy currentTrackChangedSpy(&myControl, &ManageMediaPlayerControl::currentTrackChanged); - - myControl.setPlayListModel(&myPlayList); - - QCOMPARE(playControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 1); - QCOMPARE(currentTrackChangedSpy.count(), 0); - - QCOMPARE(myControl.playListModel(), &myPlayList); - - myControl.setPlayListModel(nullptr); - - QCOMPARE(playControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipBackwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 0); - QCOMPARE(musicPlayingChangedSpy.count(), 0); - QCOMPARE(playListModelChangedSpy.count(), 2); - QCOMPARE(currentTrackChangedSpy.count(), 0); - - QCOMPARE(myControl.playListModel(), static_cast(nullptr)); + QCOMPARE(skipForwardControlEnabledChangedSpy.count(), 1); + QVERIFY(myControl.playControlEnabled()); + QVERIFY(myControl.skipBackwardControlEnabled()); + QVERIFY(myControl.skipForwardControlEnabled()); } - QTEST_GUILESS_MAIN(ManageMediaPlayerControlTest) #include "moc_managemediaplayercontroltest.cpp" diff --git a/autotests/managemediaplayercontroltest.h b/autotests/managemediaplayercontroltest.h index e4513566..ac9b044e 100644 --- a/autotests/managemediaplayercontroltest.h +++ b/autotests/managemediaplayercontroltest.h @@ -1,65 +1,54 @@ /* * Copyright 2016 Matthieu Gallien * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef MANAGEMEDIAPLAYERCONTROLTEST_H #define MANAGEMEDIAPLAYERCONTROLTEST_H #include #include "databasetestdata.h" #include "musicaudiotrack.h" #include #include #include #include class ManageMediaPlayerControlTest : public QObject, public DatabaseTestData { Q_OBJECT public: explicit ManageMediaPlayerControlTest(QObject *parent = nullptr); Q_SIGNALS: private Q_SLOTS: void initTestCase(); void simpleInitialCase(); - void addItemInModelCase(); - - void addItemInModelCaseV2(); - - void nextAndPreviousButtonAndRandomPlay(); - - void moveCurrentTrack(); - - void moveAnotherTrack(); - - void setCurrentTrackTest(); - - void setPlayListModelTest(); + void testPlayingCase(); + void testTracksCase(); }; #endif // MANAGEMEDIAPLAYERCONTROLTEST_H diff --git a/src/elisaapplication.cpp b/src/elisaapplication.cpp index 3c8f0a61..527e9752 100644 --- a/src/elisaapplication.cpp +++ b/src/elisaapplication.cpp @@ -1,485 +1,487 @@ /* * Copyright 2017 Matthieu Gallien * Copyright (C) 2012 Aleix Pol Gonzalez * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "elisaapplication.h" #include "musiclistenersmanager.h" #include "mediaplaylist.h" #include "audiowrapper.h" #include "manageaudioplayer.h" #include "managemediaplayercontrol.h" #include "manageheaderbar.h" #include "elisa_settings.h" #include #if defined KF5ConfigWidgets_FOUND && KF5ConfigWidgets_FOUND #include #endif #if defined KF5XmlGui_FOUND && KF5XmlGui_FOUND #include #include #include #include #include #endif #if defined KF5KCMUtils_FOUND && KF5KCMUtils_FOUND #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include class ElisaApplicationPrivate { public: explicit ElisaApplicationPrivate(QObject *parent) #if defined KF5XmlGui_FOUND && KF5XmlGui_FOUND : mCollection(parent) #endif { Q_UNUSED(parent) auto configurationFileName = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); configurationFileName += QStringLiteral("/elisarc"); Elisa::ElisaConfiguration::instance(configurationFileName); Elisa::ElisaConfiguration::self()->load(); Elisa::ElisaConfiguration::self()->save(); } #if defined KF5XmlGui_FOUND && KF5XmlGui_FOUND KActionCollection mCollection; #endif ElisaUtils::EntryDataList mArguments; std::unique_ptr mMusicManager; std::unique_ptr mMediaPlayList; std::unique_ptr mAudioWrapper; std::unique_ptr mAudioControl; std::unique_ptr mPlayerControl; std::unique_ptr mManageHeaderBar; }; ElisaApplication::ElisaApplication(QObject *parent) : QObject(parent), d(std::make_unique(this)) { } ElisaApplication::~ElisaApplication() = default; void ElisaApplication::setupActions(const QString &actionName) { #if defined KF5XmlGui_FOUND && KF5XmlGui_FOUND if (actionName == QStringLiteral("file_quit")) { auto quitAction = KStandardAction::quit(QCoreApplication::instance(), &QCoreApplication::quit, &d->mCollection); d->mCollection.addAction(actionName, quitAction); } if (actionName == QStringLiteral("help_contents") && KAuthorized::authorizeAction(actionName)) { auto handBookAction = KStandardAction::helpContents(this, &ElisaApplication::appHelpActivated, &d->mCollection); d->mCollection.addAction(handBookAction->objectName(), handBookAction); } if (actionName == QStringLiteral("help_report_bug") && KAuthorized::authorizeAction(actionName) && !KAboutData::applicationData().bugAddress().isEmpty()) { auto reportBugAction = KStandardAction::reportBug(this, &ElisaApplication::reportBug, &d->mCollection); d->mCollection.addAction(reportBugAction->objectName(), reportBugAction); } if (actionName == QStringLiteral("help_about_app") && KAuthorized::authorizeAction(actionName)) { auto aboutAppAction = KStandardAction::aboutApp(this, &ElisaApplication::aboutApplication, this); d->mCollection.addAction(aboutAppAction->objectName(), aboutAppAction); } if (actionName == QStringLiteral("options_configure") && KAuthorized::authorizeAction(actionName)) { auto preferencesAction = KStandardAction::preferences(this, &ElisaApplication::configureElisa, this); d->mCollection.addAction(preferencesAction->objectName(), preferencesAction); } if (actionName == QStringLiteral("options_configure_keybinding") && KAuthorized::authorizeAction(actionName)) { auto keyBindingsAction = KStandardAction::keyBindings(this, &ElisaApplication::configureShortcuts, this); d->mCollection.addAction(keyBindingsAction->objectName(), keyBindingsAction); } if (actionName == QStringLiteral("go_back") && KAuthorized::authorizeAction(actionName)) { auto goBackAction = KStandardAction::back(this, &ElisaApplication::goBack, this); d->mCollection.addAction(goBackAction->objectName(), goBackAction); } if (actionName == QStringLiteral("toggle_playlist") && KAuthorized::authorizeAction(actionName)) { auto togglePlaylistAction = d->mCollection.addAction(actionName, this, &ElisaApplication::togglePlaylist); togglePlaylistAction->setShortcut(QKeySequence(Qt::Key_F9)); togglePlaylistAction->setText(QStringLiteral("Toggle Playlist")); } if (actionName == QStringLiteral("Seek") && KAuthorized::authorizeAction(actionName)) { auto seekAction = d->mCollection.addAction(actionName, this, &ElisaApplication::seek); d->mCollection.setDefaultShortcut(seekAction, QKeySequence(Qt::SHIFT + Qt::Key_Right)); } if (actionName == QStringLiteral("Scrub") && KAuthorized::authorizeAction(actionName)) { auto scrubAction = d->mCollection.addAction(actionName, this, &ElisaApplication::scrub); d->mCollection.setDefaultShortcut(scrubAction, QKeySequence(Qt::SHIFT + Qt::Key_Left)); } if (actionName == QStringLiteral("Play-Pause") && KAuthorized::authorizeAction(actionName)) { auto playPauseAction = d->mCollection.addAction(actionName, this, &ElisaApplication::playPause); d->mCollection.setDefaultShortcut(playPauseAction, QKeySequence(Qt::Key_Space)); } if (actionName == QStringLiteral("edit_find") && KAuthorized::authorizeAction(actionName)) { auto findAction = KStandardAction::find(this, &ElisaApplication::find, this); d->mCollection.addAction(findAction->objectName(), findAction); } d->mCollection.readSettings(); #endif } void ElisaApplication::setArguments(const ElisaUtils::EntryDataList &newArguments) { if (d->mArguments == newArguments) { return; } d->mArguments = checkFileListAndMakeAbsolute(newArguments, QDir::currentPath()); Q_EMIT argumentsChanged(); if (!d->mArguments.isEmpty()) { Q_EMIT enqueue(d->mArguments, ElisaUtils::FileName, ElisaUtils::PlayListEnqueueMode::AppendPlayList, ElisaUtils::PlayListEnqueueTriggerPlay::TriggerPlay); } } void ElisaApplication::activateActionRequested(const QString &actionName, const QVariant ¶meter) { Q_UNUSED(actionName) Q_UNUSED(parameter) } void ElisaApplication::activateRequested(const QStringList &arguments, const QString &workingDirectory) { if (arguments.size() > 1) { auto realArguments = ElisaUtils::EntryDataList{}; bool isFirst = true; for (const auto &oneArgument : arguments) { if (isFirst) { isFirst = false; continue; } realArguments.push_back(ElisaUtils::EntryData{0, oneArgument}); } Q_EMIT enqueue(checkFileListAndMakeAbsolute(realArguments, workingDirectory), ElisaUtils::FileName, ElisaUtils::PlayListEnqueueMode::AppendPlayList, ElisaUtils::PlayListEnqueueTriggerPlay::TriggerPlay); } } void ElisaApplication::openRequested(const QList &uris) { Q_UNUSED(uris) } void ElisaApplication::appHelpActivated() { QDesktopServices::openUrl(QUrl(QStringLiteral("help:/"))); } void ElisaApplication::aboutApplication() { #if defined KF5XmlGui_FOUND && KF5XmlGui_FOUND static QPointer dialog; if (!dialog) { dialog = new KAboutApplicationDialog(KAboutData::applicationData(), nullptr); dialog->setAttribute(Qt::WA_DeleteOnClose); } dialog->show(); #endif } void ElisaApplication::reportBug() { #if defined KF5XmlGui_FOUND && KF5XmlGui_FOUND static QPointer dialog; if (!dialog) { dialog = new KBugReport(KAboutData::applicationData(), nullptr); dialog->setAttribute(Qt::WA_DeleteOnClose); } dialog->show(); #endif } void ElisaApplication::configureShortcuts() { #if defined KF5XmlGui_FOUND && KF5XmlGui_FOUND KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, nullptr); dlg.setModal(true); dlg.addCollection(&d->mCollection); dlg.configure(); #endif } void ElisaApplication::configureElisa() { #if defined KF5KCMUtils_FOUND && KF5KCMUtils_FOUND KCMultiDialog configurationDialog; configurationDialog.addModule(QStringLiteral("kcm_elisa_local_file")); configurationDialog.setModal(true); configurationDialog.exec(); #endif } void ElisaApplication::goBack() {} void ElisaApplication::find() {} void ElisaApplication::togglePlaylist() {} void ElisaApplication::seek() {} void ElisaApplication::scrub() {} void ElisaApplication::playPause() {} ElisaUtils::EntryDataList ElisaApplication::checkFileListAndMakeAbsolute(const ElisaUtils::EntryDataList &filesList, const QString &workingDirectory) const { auto filesToOpen = ElisaUtils::EntryDataList{}; for (const auto &oneFile : filesList) { auto newFile = QFileInfo(std::get<1>(oneFile)); if (newFile.isRelative()) { newFile = QFileInfo(workingDirectory + QStringLiteral("/") + std::get<1>(oneFile)); } if (newFile.exists()) { filesToOpen.push_back(ElisaUtils::EntryData{0, newFile.canonicalFilePath()}); } } return filesToOpen; } void ElisaApplication::initialize() { initializeModels(); initializePlayer(); Q_EMIT initializationDone(); } void ElisaApplication::initializeModels() { d->mMusicManager = std::make_unique(); Q_EMIT musicManagerChanged(); d->mMediaPlayList = std::make_unique(); Q_EMIT mediaPlayListChanged(); d->mMusicManager->setElisaApplication(this); d->mMediaPlayList->setMusicListenersManager(d->mMusicManager.get()); QObject::connect(this, &ElisaApplication::enqueue, d->mMediaPlayList.get(), static_cast(&MediaPlayList::enqueue)); } void ElisaApplication::initializePlayer() { d->mAudioWrapper = std::make_unique(); Q_EMIT audioPlayerChanged(); d->mAudioControl = std::make_unique(); Q_EMIT audioControlChanged(); d->mPlayerControl = std::make_unique(); Q_EMIT playerControlChanged(); d->mManageHeaderBar = std::make_unique(); 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()); QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::playerPlay, d->mAudioWrapper.get(), &AudioWrapper::play); QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::playerPause, d->mAudioWrapper.get(), &AudioWrapper::pause); QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::playerStop, d->mAudioWrapper.get(), &AudioWrapper::stop); QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::seek, d->mAudioWrapper.get(), &AudioWrapper::seek); QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::saveUndoPositionInAudioWrapper, d->mAudioWrapper.get(), &AudioWrapper::saveUndoPosition); QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::restoreUndoPositionInAudioWrapper, d->mAudioWrapper.get(), &AudioWrapper::restoreUndoPosition); QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::skipNextTrack, d->mMediaPlayList.get(), &MediaPlayList::skipNextTrack); QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::sourceInError, d->mMediaPlayList.get(), &MediaPlayList::trackInError); QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::sourceInError, d->mMusicManager.get(), &MusicListenersManager::playBackError); QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::playerSourceChanged, d->mAudioWrapper.get(), &AudioWrapper::setSource); QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::startedPlayingTrack, d->mMusicManager->viewDatabase(), &DatabaseInterface::trackHasStartedPlaying); QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::currentPlayingForRadiosChanged, d->mMediaPlayList.get(), &MediaPlayList::updateRadioData); QObject::connect(d->mMediaPlayList.get(), &MediaPlayList::ensurePlay, d->mAudioControl.get(), &ManageAudioPlayer::ensurePlay); QObject::connect(d->mMediaPlayList.get(), &MediaPlayList::playListFinished, d->mAudioControl.get(), &ManageAudioPlayer::playListFinished); QObject::connect(d->mMediaPlayList.get(), &MediaPlayList::currentTrackChanged, d->mAudioControl.get(), &ManageAudioPlayer::setCurrentTrack); QObject::connect(d->mMediaPlayList.get(), &MediaPlayList::clearPlayListPlayer, d->mAudioControl.get(), &ManageAudioPlayer::saveForUndoClearPlaylist); QObject::connect(d->mMediaPlayList.get(), &MediaPlayList::undoClearPlayListPlayer, d->mAudioControl.get(), &ManageAudioPlayer::restoreForUndoClearPlaylist); QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::playbackStateChanged, d->mAudioControl.get(), &ManageAudioPlayer::setPlayerPlaybackState); QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::statusChanged, d->mAudioControl.get(), &ManageAudioPlayer::setPlayerStatus); QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::errorChanged, d->mAudioControl.get(), &ManageAudioPlayer::setPlayerError); QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::durationChanged, d->mAudioControl.get(), &ManageAudioPlayer::setAudioDuration); QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::seekableChanged, d->mAudioControl.get(), &ManageAudioPlayer::setPlayerIsSeekable); 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); d->mManageHeaderBar->setAlbumArtistRole(MediaPlayList::AlbumArtistRole); d->mManageHeaderBar->setArtistRole(MediaPlayList::ArtistRole); d->mManageHeaderBar->setFileNameRole(MediaPlayList::ResourceRole); d->mManageHeaderBar->setImageRole(MediaPlayList::ImageUrlRole); d->mManageHeaderBar->setDatabaseIdRole(MediaPlayList::DatabaseIdRole); d->mManageHeaderBar->setAlbumIdRole(MediaPlayList::AlbumIdRole); d->mManageHeaderBar->setIsValidRole(MediaPlayList::IsValidRole); QObject::connect(d->mMediaPlayList.get(), &MediaPlayList::currentTrackChanged, d->mManageHeaderBar.get(), &ManageHeaderBar::setCurrentTrack); if (!d->mArguments.isEmpty()) { Q_EMIT enqueue(d->mArguments, ElisaUtils::FileName, ElisaUtils::PlayListEnqueueMode::AppendPlayList, ElisaUtils::PlayListEnqueueTriggerPlay::TriggerPlay); } } QAction * ElisaApplication::action(const QString& name) { #if defined KF5XmlGui_FOUND && KF5XmlGui_FOUND auto resultAction = d->mCollection.action(name); if (!resultAction) { setupActions(name); resultAction = d->mCollection.action(name); } return resultAction; #else Q_UNUSED(name); return new QAction(); #endif } QString ElisaApplication::iconName(const QIcon& icon) { return icon.name(); } void ElisaApplication::installKeyEventFilter(QObject *object) { if(!object) { return; } object->installEventFilter(this); } bool ElisaApplication::eventFilter(QObject *object, QEvent *event) { Q_UNUSED(object); QKeyEvent *keyEvent = static_cast(event); auto playPauseAction = d->mCollection.action(tr("Play-Pause")); if (keyEvent->key() == Qt::Key_Space && playPauseAction->shortcut()[0] == Qt::Key_Space) { return true; } return false; } const ElisaUtils::EntryDataList &ElisaApplication::arguments() const { return d->mArguments; } MusicListenersManager *ElisaApplication::musicManager() const { return d->mMusicManager.get(); } MediaPlayList *ElisaApplication::mediaPlayList() const { return d->mMediaPlayList.get(); } AudioWrapper *ElisaApplication::audioPlayer() const { return d->mAudioWrapper.get(); } 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" diff --git a/src/elisaqmlplugin.cpp b/src/elisaqmlplugin.cpp index 5e566c85..6c90c08c 100644 --- a/src/elisaqmlplugin.cpp +++ b/src/elisaqmlplugin.cpp @@ -1,182 +1,180 @@ /* * Copyright 2018 Matthieu Gallien * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "elisaqmlplugin.h" #if defined UPNPQT_FOUND && UPNPQT_FOUND #include "upnp/upnpcontrolconnectionmanager.h" #include "upnp/upnpcontrolmediaserver.h" #include "upnp/upnpcontrolcontentdirectory.h" #include "upnp/upnpcontentdirectorymodel.h" #include "upnpdevicedescription.h" #include "upnp/didlparser.h" #include "upnp/upnpdiscoverallmusic.h" #include "upnpssdpengine.h" #include "upnpabstractservice.h" #include "upnpcontrolabstractdevice.h" #include "upnpcontrolabstractservice.h" #include "upnpbasictypes.h" #endif #include "elisautils.h" #include "elisaapplication.h" #include "progressindicator.h" #include "mediaplaylist.h" #include "managemediaplayercontrol.h" #include "manageheaderbar.h" #include "manageaudioplayer.h" #include "musicaudiotrack.h" #include "musiclistenersmanager.h" #include "trackslistener.h" #include "viewmanager.h" #include "databaseinterface.h" #include "models/datamodel.h" #include "models/trackmetadatamodel.h" #include "models/trackcontextmetadatamodel.h" #include "models/viewsmodel.h" #include "models/gridviewproxymodel.h" #include "models/alltracksproxymodel.h" #include "models/singlealbumproxymodel.h" #if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND #include "embeddedcoverageimageprovider.h" #endif #if defined KF5KIO_FOUND && KF5KIO_FOUND #include "models/filebrowsermodel.h" #include "models/filebrowserproxymodel.h" #endif #include "audiowrapper.h" #if defined Qt5DBus_FOUND && Qt5DBus_FOUND #include "mpris2/mpris2.h" #include "mpris2/mediaplayer2player.h" #endif #include #include #include #include #include #include void ElisaQmlTestPlugin::initializeEngine(QQmlEngine *engine, const char *uri) { QQmlExtensionPlugin::initializeEngine(engine, uri); #if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND engine->addImageProvider(QStringLiteral("cover"), new EmbeddedCoverageImageProvider); #endif } void ElisaQmlTestPlugin::registerTypes(const char *uri) { #if defined UPNPQT_FOUND && UPNPQT_FOUND qmlRegisterType(uri, 1, 0, "UpnpSsdpEngine"); qmlRegisterType(uri, 1, 0, "UpnpDiscoverAllMusic"); qmlRegisterType(uri, 1, 0, "UpnpAbstractDevice"); qmlRegisterType(uri, 1, 0, "UpnpAbstractService"); qmlRegisterType(uri, 1, 0, "UpnpControlAbstractDevice"); qmlRegisterType(uri, 1, 0, "UpnpControlAbstractService"); qmlRegisterType(uri, 1, 0, "UpnpControlConnectionManager"); qmlRegisterType(uri, 1, 0, "UpnpControlMediaServer"); qmlRegisterType(uri, 1, 0, "UpnpContentDirectoryModel"); qmlRegisterType(uri, 1, 0, "DidlParser"); qmlRegisterType(uri, 1, 0, "UpnpControlContentDirectory"); qmlRegisterType(uri, 1, 0, "UpnpDeviceDescription"); qRegisterMetaType(); qRegisterMetaType >(); qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); #endif qmlRegisterType(uri, 1, 0, "MediaPlayList"); qmlRegisterType(uri, 1, 0, "ManageMediaPlayerControl"); qmlRegisterType(uri, 1, 0, "ManageHeaderBar"); qmlRegisterType(uri, 1, 0, "ManageAudioPlayer"); qmlRegisterType(uri, 1, 0, "ProgressIndicator"); qmlRegisterType(uri, 1, 0, "MusicListenersManager"); qmlRegisterType(uri, 1, 0, "ViewManager"); qmlRegisterType(uri, 1, 0, "DataModel"); qmlRegisterType(uri, 1, 0, "TrackMetadataModel"); qmlRegisterType(uri, 1, 0, "TrackContextMetaDataModel"); qmlRegisterType(uri, 1, 0, "ViewsModel"); qmlRegisterType(uri, 1, 0, "GridViewProxyModel"); qmlRegisterType(uri, 1, 0, "AllTracksProxyModel"); qmlRegisterType(uri, 1, 0, "SingleAlbumProxyModel"); #if defined KF5KIO_FOUND && KF5KIO_FOUND qmlRegisterType(uri, 1, 0, "FileBrowserModel"); qmlRegisterType(uri, 1, 0, "FileBrowserProxyModel"); #endif qmlRegisterType(uri, 1, 0, "AudioWrapper"); qmlRegisterUncreatableType(uri, 1, 0, "DatabaseInterface", QStringLiteral("Only created in c++")); #if defined Qt5DBus_FOUND && Qt5DBus_FOUND qmlRegisterType(uri, 1, 0, "Mpris2"); qRegisterMetaType(); #endif qRegisterMetaType(); qRegisterMetaType>("QHash"); qRegisterMetaType>("QHash"); qRegisterMetaType>("QList"); qRegisterMetaType>("QVector"); qRegisterMetaType>("QVector"); qRegisterMetaType>("QHash"); qRegisterMetaType("DatabaseInterface::ListTrackDataType"); qRegisterMetaType("DatabaseInterface::ListRadioDataType"); qRegisterMetaType("DatabaseInterface::ListAlbumDataType"); qRegisterMetaType("DatabaseInterface::ListArtistDataType"); qRegisterMetaType("DatabaseInterface::ListGenreDataType"); qRegisterMetaType("ModelDataLoader::ListTrackDataType"); qRegisterMetaType("ModelDataLoader::ListRadioDataType"); qRegisterMetaType("ModelDataLoader::ListAlbumDataType"); qRegisterMetaType("ModelDataLoader::ListArtistDataType"); qRegisterMetaType("ModelDataLoader::ListGenreDataType"); qRegisterMetaType("ModelDataLoader::AlbumDataType"); qRegisterMetaType("TracksListener::ListTrackDataType"); qRegisterMetaType>(); qRegisterMetaType(); qRegisterMetaType>("QMap"); qRegisterMetaType("ElisaUtils::PlayListEnqueueMode"); qRegisterMetaType("ElisaUtils::PlayListEnqueueTriggerPlay"); qRegisterMetaType("ElisaUtils::PlayListEntryType"); qRegisterMetaType("ElisaUtils::EntryData"); qRegisterMetaType("ElisaUtils::EntryDataList"); qRegisterMetaType("ElisaUtils::FilterType"); qRegisterMetaType("DatabaseInterface::TrackDataType"); qRegisterMetaType("DatabaseInterface::AlbumDataType"); qRegisterMetaType("DatabaseInterface::ArtistDataType"); qRegisterMetaType("DatabaseInterface::GenreDataType"); qRegisterMetaType("ModelDataLoader::TrackDataType"); qRegisterMetaType("TracksListener::TrackDataType"); qRegisterMetaType("ViewManager::ViewsType"); qRegisterMetaType("ViewManager::SortOrder"); - qRegisterMetaTypeStreamOperators("PlayListControler::PlayerState"); - qmlRegisterUncreatableType(uri, 1, 0, "ElisaApplication", QStringLiteral("only one and done in c++")); qmlRegisterUncreatableMetaObject(ElisaUtils::staticMetaObject, uri, 1, 0, "ElisaUtils", QStringLiteral("Namespace ElisaUtils")); } diff --git a/src/managemediaplayercontrol.cpp b/src/managemediaplayercontrol.cpp index e533df6b..891b5ccf 100644 --- a/src/managemediaplayercontrol.cpp +++ b/src/managemediaplayercontrol.cpp @@ -1,384 +1,156 @@ /* * Copyright 2016 Matthieu Gallien * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "managemediaplayercontrol.h" -#include +#include ManageMediaPlayerControl::ManageMediaPlayerControl(QObject *parent) : QObject(parent) { } 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() { if (!mIsInPlayingState) { auto oldPreviousTrackIsEnabled = skipBackwardControlEnabled(); 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 ¤tTrack) { if (mCurrentTrack == currentTrack) { return; } bool oldPlayControlEnabled = playControlEnabled(); - bool oldValueSkipBackward = skipBackwardControlEnabled(); - bool oldValueSkipForward = skipForwardControlEnabled(); mCurrentTrack = currentTrack; Q_EMIT currentTrackChanged(); 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 { return mCurrentTrack; } -QDataStream &operator<<(QDataStream &out, const ManageMediaPlayerControl::PlayerState &state) +QPersistentModelIndex ManageMediaPlayerControl::nextTrack() const { - out << static_cast(state); - return out; + return mNextTrack; } -QDataStream &operator>>(QDataStream &in, ManageMediaPlayerControl::PlayerState &state) -{ - int value; - in >> value; - state = static_cast(value); - return in; -} - - #include "moc_managemediaplayercontrol.cpp" diff --git a/src/managemediaplayercontrol.h b/src/managemediaplayercontrol.h index 8b05439a..43667ec7 100644 --- a/src/managemediaplayercontrol.h +++ b/src/managemediaplayercontrol.h @@ -1,160 +1,128 @@ /* * Copyright 2016 Matthieu Gallien * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef MANAGEMEDIAPLAYERCONTROL_H #define MANAGEMEDIAPLAYERCONTROL_H #include "elisaLib_export.h" #include #include class QAbstractItemModel; class ELISALIB_EXPORT ManageMediaPlayerControl : public QObject { Q_OBJECT Q_PROPERTY(bool playControlEnabled READ playControlEnabled NOTIFY playControlEnabledChanged) Q_PROPERTY(bool skipBackwardControlEnabled READ skipBackwardControlEnabled NOTIFY skipBackwardControlEnabledChanged) Q_PROPERTY(bool skipForwardControlEnabled READ skipForwardControlEnabled NOTIFY skipForwardControlEnabledChanged) Q_PROPERTY(bool musicPlaying 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; bool skipBackwardControlEnabled() const; bool skipForwardControlEnabled() const; bool musicPlaying() const; - QAbstractItemModel* playListModel() const; + QPersistentModelIndex previousTrack() const; QPersistentModelIndex currentTrack() const; - bool randomOrContinuePlay() const; + QPersistentModelIndex nextTrack() const; Q_SIGNALS: void playControlEnabledChanged(); void skipBackwardControlEnabledChanged(); void skipForwardControlEnabledChanged(); 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 ¤tTrack); - 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; bool mSkipForwardControlWasEnabled = false; 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 diff --git a/src/qml/ElisaMainWindow.qml b/src/qml/ElisaMainWindow.qml index ef362fd2..d302430b 100644 --- a/src/qml/ElisaMainWindow.qml +++ b/src/qml/ElisaMainWindow.qml @@ -1,334 +1,333 @@ /* * Copyright 2016-2018 Matthieu Gallien * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ import QtQuick 2.7 import QtQuick.Controls 2.3 import QtQuick.Layouts 1.1 import QtQuick.Window 2.2 import org.kde.elisa 1.0 import Qt.labs.settings 1.0 ApplicationWindow { id: mainWindow visible: true minimumWidth: contentView.showPlaylist ? 1100 : 700 minimumHeight: 600 LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft LayoutMirroring.childrenInherit: true x: persistentSettings.x y: persistentSettings.y width: persistentSettings.width height: persistentSettings.height title: i18n("Elisa") Accessible.role: Accessible.Application Accessible.name: title property var goBackAction: elisa.action("go_back") property var seekAction: elisa.action("Seek") property var scrubAction: elisa.action("Scrub") property var playPauseAction: elisa.action("Play-Pause") property var findAction: elisa.action("edit_find") Action { shortcut: goBackAction.shortcut onTriggered: contentView.goBack() } Action { shortcut: seekAction.shortcut onTriggered: elisa.audioControl.seek(headerBar.playerControl.position + 10000) } Action { shortcut: scrubAction.shortcut onTriggered: elisa.audioControl.seek(headerBar.playerControl.position - 10000) } Action { shortcut: playPauseAction.shortcut onTriggered: elisa.audioControl.playPause() } Action { shortcut: findAction.shortcut onTriggered: persistentSettings.expandedFilterView = !persistentSettings.expandedFilterView } ApplicationMenu { id: applicationMenu } SystemPalette { id: myPalette colorGroup: SystemPalette.Active } Theme { id: elisaTheme } Settings { id: persistentSettings property int x property int y property int width : 1100 property int height : 600 property var playListState property var audioPlayerState property double playControlItemVolume : 100.0 property bool playControlItemMuted : false property bool expandedFilterView: false property bool showPlaylist: true property bool headerBarIsMaximized: false } Connections { target: headerBar.playerControl onOpenMenu: { if (applicationMenu.visible) { applicationMenu.close() } else { applicationMenu.popup(mainWindow.width - applicationMenu.width, headerBar.height) } } } Connections { target: Qt.application onAboutToQuit: { persistentSettings.x = mainWindow.x; persistentSettings.y = mainWindow.y; persistentSettings.width = mainWindow.width; persistentSettings.height = mainWindow.height; persistentSettings.playListState = elisa.mediaPlayList.persistentState; persistentSettings.audioPlayerState = elisa.audioControl.persistentState persistentSettings.playControlItemVolume = headerBar.playerControl.volume persistentSettings.playControlItemMuted = headerBar.playerControl.muted persistentSettings.showPlaylist = contentView.showPlaylist persistentSettings.headerBarIsMaximized = headerBar.isMaximized } } Loader { id: mprisloader active: false sourceComponent: PlatformIntegration { id: platformInterface playListModel: elisa.mediaPlayList audioPlayerManager: elisa.audioControl player: elisa.audioPlayer 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 } Rectangle { color: myPalette.base anchors.fill: parent ColumnLayout { anchors.fill: parent spacing: 0 HeaderBar { id: headerBar focus: true Layout.minimumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight Layout.maximumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight Layout.fillWidth: true tracksCount: elisa.mediaPlayList.remainingTracks album: elisa.manageHeaderBar.album title: elisa.manageHeaderBar.title artist: elisa.manageHeaderBar.artist albumArtist: elisa.manageHeaderBar.albumArtist image: elisa.manageHeaderBar.image albumID: elisa.manageHeaderBar.albumId ratingVisible: false playerControl.duration: elisa.audioPlayer.duration playerControl.seekable: elisa.audioPlayer.seekable playerControl.volume: persistentSettings.playControlItemVolume playerControl.muted: persistentSettings.playControlItemMuted playerControl.position: elisa.audioPlayer.position playerControl.skipBackwardEnabled: elisa.playerControl.skipBackwardControlEnabled playerControl.skipForwardEnabled: elisa.playerControl.skipForwardControlEnabled playerControl.playEnabled: elisa.playerControl.playControlEnabled playerControl.isPlaying: elisa.playerControl.musicPlaying playerControl.repeat: elisa.mediaPlayList.repeatPlay playerControl.shuffle: elisa.mediaPlayList.randomPlay playerControl.onSeek: elisa.audioPlayer.seek(position) playerControl.onPlay: elisa.audioControl.playPause() playerControl.onPause: elisa.audioControl.playPause() playerControl.onPlayPrevious: elisa.mediaPlayList.skipPreviousTrack() playerControl.onPlayNext: elisa.mediaPlayList.skipNextTrack() playerControl.isMaximized: persistentSettings.headerBarIsMaximized onOpenArtist: { contentView.openArtist(artist) } onOpenNowPlaying: { contentView.openNowPlaying() } onOpenAlbum: { contentView.openAlbum(album, albumArtist, image, albumID) } TrackImportNotification { id: importedTracksCountNotification anchors { right: headerBar.right top: headerBar.top rightMargin: elisaTheme.layoutHorizontalMargin * 1.75 topMargin: elisaTheme.layoutHorizontalMargin * 3 } } Binding { id: indexerBusyBinding target: importedTracksCountNotification property: 'indexingRunning' value: elisa.musicManager.indexerBusy when: elisa.musicManager !== undefined } Binding { target: importedTracksCountNotification property: 'importedTracksCount' value: elisa.musicManager.importedTracksCount when: elisa.musicManager !== undefined } } Rectangle { Layout.fillWidth: true height: 1 color: myPalette.mid } ContentView { id: contentView Layout.fillHeight: true Layout.fillWidth: true showPlaylist: persistentSettings.showPlaylist showExpandedFilterView: persistentSettings.expandedFilterView } } } StateGroup { id: mainWindowState states: [ State { name: "headerBarIsNormal" when: !headerBar.isMaximized changes: [ PropertyChanges { target: mainWindow minimumHeight: 600 explicit: true }, PropertyChanges { target: headerBar Layout.minimumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight Layout.maximumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight } ] }, State { name: "headerBarIsMaximized" when: headerBar.isMaximized changes: [ PropertyChanges { target: mainWindow minimumHeight: 120 + elisaTheme.mediaPlayerControlHeight explicit: true }, PropertyChanges { target: headerBar Layout.minimumHeight: mainWindow.height Layout.maximumHeight: mainWindow.height } ] } ] transitions: Transition { NumberAnimation { properties: "Layout.minimumHeight, Layout.maximumHeight, minimumHeight" easing.type: Easing.InOutQuad duration: 300 } } } Component.onCompleted: { elisa.initialize() if (persistentSettings.playListState) { elisa.mediaPlayList.persistentState = persistentSettings.playListState } if (persistentSettings.audioPlayerState) { elisa.audioControl.persistentState = persistentSettings.audioPlayerState } 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 }) mprisloader.active = true } }