diff --git a/autotests/albummodeltest.cpp b/autotests/albummodeltest.cpp index b2e904e9..e247d364 100644 --- a/autotests/albummodeltest.cpp +++ b/autotests/albummodeltest.cpp @@ -1,486 +1,484 @@ /* * Copyright 2015-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "musicalbum.h" #include "musicaudiotrack.h" #include "databaseinterface.h" #include "models/albummodel.h" #include "qabstractitemmodeltester.h" #include #include #include #include #include #include #include #include #include #include #include #include class AlbumModelTests: public QObject { Q_OBJECT private: QList mNewTracks = { {true, QStringLiteral("$1"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 1, 1, QTime::fromMSecsSinceStartOfDay(1), {QUrl::fromLocalFile(QStringLiteral("/$1"))}, QDateTime::fromMSecsSinceEpoch(1), QUrl::fromLocalFile(QStringLiteral("album1")), 1, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$2"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 2, 2, QTime::fromMSecsSinceStartOfDay(2), {QUrl::fromLocalFile(QStringLiteral("/$2"))}, QDateTime::fromMSecsSinceEpoch(2), QUrl::fromLocalFile(QStringLiteral("album1")), 2, false, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$3"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 3, 3, QTime::fromMSecsSinceStartOfDay(3), {QUrl::fromLocalFile(QStringLiteral("/$3"))}, QDateTime::fromMSecsSinceEpoch(3), QUrl::fromLocalFile(QStringLiteral("album1")), 3, false, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4Bis"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$5"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 1, 1, QTime::fromMSecsSinceStartOfDay(5), {QUrl::fromLocalFile(QStringLiteral("/$5"))}, QDateTime::fromMSecsSinceEpoch(5), QUrl::fromLocalFile(QStringLiteral("album2")), 4, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$6"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 2, 1, QTime::fromMSecsSinceStartOfDay(6), {QUrl::fromLocalFile(QStringLiteral("/$6"))}, QDateTime::fromMSecsSinceEpoch(6), QUrl::fromLocalFile(QStringLiteral("album2")), 1, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$7"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 3, 1, QTime::fromMSecsSinceStartOfDay(7), {QUrl::fromLocalFile(QStringLiteral("/$7"))}, QDateTime::fromMSecsSinceEpoch(7), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$8"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 4, 1, QTime::fromMSecsSinceStartOfDay(8), {QUrl::fromLocalFile(QStringLiteral("/$8"))}, QDateTime::fromMSecsSinceEpoch(8), QUrl::fromLocalFile(QStringLiteral("album2")), 2, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$9"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 5, 1, QTime::fromMSecsSinceStartOfDay(9), {QUrl::fromLocalFile(QStringLiteral("/$9"))}, QDateTime::fromMSecsSinceEpoch(9), QUrl::fromLocalFile(QStringLiteral("album2")), 3, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$10"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist1 and artist2"), QStringLiteral("album2"), QStringLiteral("artist1"), 6, 1, QTime::fromMSecsSinceStartOfDay(10), {QUrl::fromLocalFile(QStringLiteral("/$10"))}, QDateTime::fromMSecsSinceEpoch(10), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$11"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(11), {QUrl::fromLocalFile(QStringLiteral("/$11"))}, QDateTime::fromMSecsSinceEpoch(11), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$12"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(12), {QUrl::fromLocalFile(QStringLiteral("/$12"))}, QDateTime::fromMSecsSinceEpoch(12), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$13"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(13), {QUrl::fromLocalFile(QStringLiteral("/$13"))}, QDateTime::fromMSecsSinceEpoch(13), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$14"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(14), {QUrl::fromLocalFile(QStringLiteral("/$14"))}, QDateTime::fromMSecsSinceEpoch(14), QUrl::fromLocalFile(QStringLiteral("album4")), 4, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$15"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(15), {QUrl::fromLocalFile(QStringLiteral("/$15"))}, QDateTime::fromMSecsSinceEpoch(15), QUrl::fromLocalFile(QStringLiteral("album4")), 5, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$16"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(16), {QUrl::fromLocalFile(QStringLiteral("/$16"))}, QDateTime::fromMSecsSinceEpoch(16), QUrl::fromLocalFile(QStringLiteral("album4")), 1, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$17"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 4, 1, QTime::fromMSecsSinceStartOfDay(17), {QUrl::fromLocalFile(QStringLiteral("/$17"))}, QDateTime::fromMSecsSinceEpoch(17), QUrl::fromLocalFile(QStringLiteral("album4")), 2, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$18"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 5, 1, QTime::fromMSecsSinceStartOfDay(18), {QUrl::fromLocalFile(QStringLiteral("/$18"))}, QDateTime::fromMSecsSinceEpoch(18), QUrl::fromLocalFile(QStringLiteral("album4")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$19"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 1, 1, QTime::fromMSecsSinceStartOfDay(19), {QUrl::fromLocalFile(QStringLiteral("/$19"))}, QDateTime::fromMSecsSinceEpoch(19), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 2, 1, QTime::fromMSecsSinceStartOfDay(20), {QUrl::fromLocalFile(QStringLiteral("/$20"))}, QDateTime::fromMSecsSinceEpoch(20), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$21"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 3, 1, QTime::fromMSecsSinceStartOfDay(21), {QUrl::fromLocalFile(QStringLiteral("/$21"))}, QDateTime::fromMSecsSinceEpoch(21), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$22"), QStringLiteral("0"), QStringLiteral("track9"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist7"), 9, 1, QTime::fromMSecsSinceStartOfDay(22), {QUrl::fromLocalFile(QStringLiteral("/$22"))}, QDateTime::fromMSecsSinceEpoch(22), QUrl::fromLocalFile(QStringLiteral("album3")), 9, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, }; QHash mNewCovers = { {QStringLiteral("file:///$1"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$2"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$3"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4Bis"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$5"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$6"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$7"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$8"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$9"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$0"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$11"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$12"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$13"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$14"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$15"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$16"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$17"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$18"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$19"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$20"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$21"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$22"), QUrl::fromLocalFile(QStringLiteral("album3"))}, }; private Q_SLOTS: void initTestCase() { qRegisterMetaType>("QHash"); qRegisterMetaType>("QHash"); qRegisterMetaType>("QList"); qRegisterMetaType>("QVector"); qRegisterMetaType>("QHash"); qRegisterMetaType("MusicArtist"); } void removeOneTrack() { DatabaseInterface musicDb; AlbumModel albumsModel; QAbstractItemModelTester testModel(&albumsModel); connect(&musicDb, &DatabaseInterface::albumModified, &albumsModel, &AlbumModel::albumModified); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&albumsModel, &AlbumModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&albumsModel, &AlbumModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&albumsModel, &AlbumModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&albumsModel, &AlbumModel::rowsRemoved); QSignalSpy dataChangedSpy(&albumsModel, &AlbumModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); albumsModel.setAlbumData(musicDb.albumFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists"))); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); auto trackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); auto firstTrack = musicDb.trackFromDatabaseId(trackId); musicDb.removeTracksList({firstTrack.resourceURI()}); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 1); QCOMPARE(endRemoveRowsSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); } void removeOneAlbum() { DatabaseInterface musicDb; AlbumModel albumsModel; QAbstractItemModelTester testModel(&albumsModel); connect(&musicDb, &DatabaseInterface::albumModified, &albumsModel, &AlbumModel::albumModified); connect(&musicDb, &DatabaseInterface::albumRemoved, &albumsModel, &AlbumModel::albumRemoved); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&albumsModel, &AlbumModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&albumsModel, &AlbumModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&albumsModel, &AlbumModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&albumsModel, &AlbumModel::rowsRemoved); QSignalSpy dataChangedSpy(&albumsModel, &AlbumModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); albumsModel.setAlbumData(musicDb.albumFromTitleAndArtist(QStringLiteral("album3"), QStringLiteral("artist2"))); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); auto firstTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album3"), 1, 1); auto firstTrack = musicDb.trackFromDatabaseId(firstTrackId); auto secondTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album3"), 2, 1); auto secondTrack = musicDb.trackFromDatabaseId(secondTrackId); auto thirdTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album3"), 3, 1); auto thirdTrack = musicDb.trackFromDatabaseId(thirdTrackId); musicDb.removeTracksList({firstTrack.resourceURI(), secondTrack.resourceURI(), thirdTrack.resourceURI()}); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 3); QCOMPARE(endRemoveRowsSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 0); } void addOneTrack() { DatabaseInterface musicDb; AlbumModel albumsModel; QAbstractItemModelTester testModel(&albumsModel); connect(&musicDb, &DatabaseInterface::albumModified, &albumsModel, &AlbumModel::albumModified); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&albumsModel, &AlbumModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&albumsModel, &AlbumModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&albumsModel, &AlbumModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&albumsModel, &AlbumModel::rowsRemoved); QSignalSpy dataChangedSpy(&albumsModel, &AlbumModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); auto newFiles = QList(); const auto &constNewTracks = mNewTracks; for (const auto &oneTrack : constNewTracks) { newFiles.push_back(oneTrack.resourceURI()); } musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); albumsModel.setAlbumData(musicDb.albumFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists"))); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), QUrl::fromLocalFile(QStringLiteral("album1")), 5, true, {}, QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); auto newFiles2 = QList(); for (const auto &oneTrack : newTracks) { newFiles2.push_back(oneTrack.resourceURI()); } musicDb.insertTracksList(newTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 2); QCOMPARE(endInsertRowsSpy.count(), 2); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(beginInsertRowsSpy.at(1).at(1).toInt(), 4); QCOMPARE(beginInsertRowsSpy.at(1).at(2).toInt(), 4); QCOMPARE(albumsModel.data(albumsModel.index(4, 0), AlbumModel::TitleRole).toString(), QStringLiteral("track6")); auto secondNewTrack = MusicAudioTrack{true, QStringLiteral("$24"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist2"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 5, 1, QTime::fromMSecsSinceStartOfDay(24), {QUrl::fromLocalFile(QStringLiteral("/$24"))}, QDateTime::fromMSecsSinceEpoch(24), QUrl::fromLocalFile(QStringLiteral("album1")), 5, true, {}, QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto secondNewTracks = QList(); secondNewTracks.push_back(secondNewTrack); auto newFiles3 = QList(); for (const auto &oneTrack : secondNewTracks) { newFiles3.push_back(oneTrack.resourceURI()); } musicDb.insertTracksList(secondNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 3); QCOMPARE(endInsertRowsSpy.count(), 3); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(beginInsertRowsSpy.at(2).at(1).toInt(), 4); QCOMPARE(beginInsertRowsSpy.at(2).at(2).toInt(), 4); QCOMPARE(albumsModel.data(albumsModel.index(4, 0), AlbumModel::TitleRole).toString(), QStringLiteral("track5")); } void modifyOneTrack() { DatabaseInterface musicDb; AlbumModel albumsModel; QAbstractItemModelTester testModel(&albumsModel); connect(&musicDb, &DatabaseInterface::albumModified, &albumsModel, &AlbumModel::albumModified); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&albumsModel, &AlbumModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&albumsModel, &AlbumModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&albumsModel, &AlbumModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&albumsModel, &AlbumModel::rowsRemoved); QSignalSpy dataChangedSpy(&albumsModel, &AlbumModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); auto newFiles = QList(); const auto &constNewTracks = mNewTracks; for (const auto &oneTrack : constNewTracks) { newFiles.push_back(oneTrack.resourceURI()); } musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); albumsModel.setAlbumData(musicDb.albumFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists"))); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); auto modifiedTrack = MusicAudioTrack{ true, QStringLiteral("$3"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 5, 3, QTime::fromMSecsSinceStartOfDay(3), {QUrl::fromLocalFile(QStringLiteral("/$3"))}, QDateTime::fromMSecsSinceEpoch(23), QUrl::fromLocalFile(QStringLiteral("album1")), 5, true, {}, QStringLiteral("composer1"), QStringLiteral("lyricist1")}; musicDb.modifyTracksList({modifiedTrack}, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.at(0).at(0).toModelIndex(), albumsModel.index(2, 0)); QCOMPARE(dataChangedSpy.at(0).at(1).toModelIndex(), albumsModel.index(2, 0)); QCOMPARE(albumsModel.data(albumsModel.index(2, 0), AlbumModel::TrackNumberRole).toInt(), 5); } }; QTEST_GUILESS_MAIN(AlbumModelTests) #include "albummodeltest.moc" diff --git a/autotests/allalbumsmodeltest.cpp b/autotests/allalbumsmodeltest.cpp index f74de55c..243d5fa9 100644 --- a/autotests/allalbumsmodeltest.cpp +++ b/autotests/allalbumsmodeltest.cpp @@ -1,485 +1,483 @@ /* * Copyright 2015-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "musicalbum.h" #include "musicaudiotrack.h" #include "databaseinterface.h" #include "models/allalbumsmodel.h" #include "qabstractitemmodeltester.h" #include #include #include #include #include #include #include #include #include #include #include #include class AllAlbumsModelTests: public QObject { Q_OBJECT private: QList mNewTracks = { {true, QStringLiteral("$1"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 1, 1, QTime::fromMSecsSinceStartOfDay(1), {QUrl::fromLocalFile(QStringLiteral("/$1"))}, QDateTime::fromMSecsSinceEpoch(1), QUrl::fromLocalFile(QStringLiteral("album1")), 1, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$2"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 2, 2, QTime::fromMSecsSinceStartOfDay(2), {QUrl::fromLocalFile(QStringLiteral("/$2"))}, QDateTime::fromMSecsSinceEpoch(2), QUrl::fromLocalFile(QStringLiteral("album1")), 2, false, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$3"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 3, 3, QTime::fromMSecsSinceStartOfDay(3), {QUrl::fromLocalFile(QStringLiteral("/$3"))}, QDateTime::fromMSecsSinceEpoch(3), QUrl::fromLocalFile(QStringLiteral("album1")), 3, false, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4Bis"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$5"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 1, 1, QTime::fromMSecsSinceStartOfDay(5), {QUrl::fromLocalFile(QStringLiteral("/$5"))}, QDateTime::fromMSecsSinceEpoch(5), QUrl::fromLocalFile(QStringLiteral("album2")), 4, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$6"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 2, 1, QTime::fromMSecsSinceStartOfDay(6), {QUrl::fromLocalFile(QStringLiteral("/$6"))}, QDateTime::fromMSecsSinceEpoch(6), QUrl::fromLocalFile(QStringLiteral("album2")), 1, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$7"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 3, 1, QTime::fromMSecsSinceStartOfDay(7), {QUrl::fromLocalFile(QStringLiteral("/$7"))}, QDateTime::fromMSecsSinceEpoch(7), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$8"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 4, 1, QTime::fromMSecsSinceStartOfDay(8), {QUrl::fromLocalFile(QStringLiteral("/$8"))}, QDateTime::fromMSecsSinceEpoch(8), QUrl::fromLocalFile(QStringLiteral("album2")), 2, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$9"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 5, 1, QTime::fromMSecsSinceStartOfDay(9), {QUrl::fromLocalFile(QStringLiteral("/$9"))}, QDateTime::fromMSecsSinceEpoch(9), QUrl::fromLocalFile(QStringLiteral("album2")), 3, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$10"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist1 and artist2"), QStringLiteral("album2"), QStringLiteral("artist1"), 6, 1, QTime::fromMSecsSinceStartOfDay(10), {QUrl::fromLocalFile(QStringLiteral("/$10"))}, QDateTime::fromMSecsSinceEpoch(10), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$11"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(11), {QUrl::fromLocalFile(QStringLiteral("/$11"))}, QDateTime::fromMSecsSinceEpoch(11), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$12"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(12), {QUrl::fromLocalFile(QStringLiteral("/$12"))}, QDateTime::fromMSecsSinceEpoch(12), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$13"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(13), {QUrl::fromLocalFile(QStringLiteral("/$13"))}, QDateTime::fromMSecsSinceEpoch(13), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$14"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(14), {QUrl::fromLocalFile(QStringLiteral("/$14"))}, QDateTime::fromMSecsSinceEpoch(14), QUrl::fromLocalFile(QStringLiteral("album4")), 4, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$15"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(15), {QUrl::fromLocalFile(QStringLiteral("/$15"))}, QDateTime::fromMSecsSinceEpoch(15), QUrl::fromLocalFile(QStringLiteral("album4")), 5, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$16"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(16), {QUrl::fromLocalFile(QStringLiteral("/$16"))}, QDateTime::fromMSecsSinceEpoch(16), QUrl::fromLocalFile(QStringLiteral("album4")), 1, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$17"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 4, 1, QTime::fromMSecsSinceStartOfDay(17), {QUrl::fromLocalFile(QStringLiteral("/$17"))}, QDateTime::fromMSecsSinceEpoch(17), QUrl::fromLocalFile(QStringLiteral("album4")), 2, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$18"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 5, 1, QTime::fromMSecsSinceStartOfDay(18), {QUrl::fromLocalFile(QStringLiteral("/$18"))}, QDateTime::fromMSecsSinceEpoch(18), QUrl::fromLocalFile(QStringLiteral("album4")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$19"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 1, 1, QTime::fromMSecsSinceStartOfDay(19), {QUrl::fromLocalFile(QStringLiteral("/$19"))}, QDateTime::fromMSecsSinceEpoch(19), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 2, 1, QTime::fromMSecsSinceStartOfDay(20), {QUrl::fromLocalFile(QStringLiteral("/$20"))}, QDateTime::fromMSecsSinceEpoch(20), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$21"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 3, 1, QTime::fromMSecsSinceStartOfDay(21), {QUrl::fromLocalFile(QStringLiteral("/$21"))}, QDateTime::fromMSecsSinceEpoch(21), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$22"), QStringLiteral("0"), QStringLiteral("track9"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist7"), 9, 1, QTime::fromMSecsSinceStartOfDay(22), {QUrl::fromLocalFile(QStringLiteral("/$22"))}, QDateTime::fromMSecsSinceEpoch(22), QUrl::fromLocalFile(QStringLiteral("album3")), 9, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, }; QHash mNewCovers = { {QStringLiteral("file:///$1"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$2"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$3"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4Bis"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$5"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$6"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$7"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$8"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$9"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$0"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$11"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$12"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$13"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$14"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$15"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$16"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$17"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$18"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$19"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$20"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$21"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$22"), QUrl::fromLocalFile(QStringLiteral("album3"))}, }; private Q_SLOTS: void initTestCase() { qRegisterMetaType>("QHash"); qRegisterMetaType>("QHash"); qRegisterMetaType>>("QHash>"); qRegisterMetaType>("QVector"); qRegisterMetaType>("QHash"); qRegisterMetaType("MusicArtist"); } void removeOneTrack() { DatabaseInterface musicDb; AllAlbumsModel albumsModel; QAbstractItemModelTester testModel(&albumsModel, Qt::BlockingQueuedConnection); connect(&musicDb, &DatabaseInterface::albumsAdded, &albumsModel, &AllAlbumsModel::albumsAdded); connect(&musicDb, &DatabaseInterface::albumModified, &albumsModel, &AllAlbumsModel::albumModified); connect(&musicDb, &DatabaseInterface::albumRemoved, &albumsModel, &AllAlbumsModel::albumRemoved); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&albumsModel, &AllAlbumsModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&albumsModel, &AllAlbumsModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&albumsModel, &AllAlbumsModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&albumsModel, &AllAlbumsModel::rowsRemoved); QSignalSpy dataChangedSpy(&albumsModel, &AllAlbumsModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); while(beginInsertRowsSpy.count() < 5) { QCOMPARE(beginInsertRowsSpy.wait(500), true); } while(endInsertRowsSpy.count() < 5) { QCOMPARE(endInsertRowsSpy.wait(500), true); } QCOMPARE(albumsModel.rowCount(), 5); QCOMPARE(beginInsertRowsSpy.count(), 5); QCOMPARE(endInsertRowsSpy.count(), 5); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); auto trackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); auto firstTrack = musicDb.trackFromDatabaseId(trackId); QCOMPARE(firstTrack.isValid(), true); musicDb.removeTracksList({firstTrack.resourceURI()}); QCOMPARE(dataChangedSpy.wait(500), true); QCOMPARE(albumsModel.rowCount(), 5); QCOMPARE(beginInsertRowsSpy.count(), 5); QCOMPARE(endInsertRowsSpy.count(), 5); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 1); } void removeOneAlbum() { DatabaseInterface musicDb; AllAlbumsModel albumsModel; QAbstractItemModelTester testModel(&albumsModel, Qt::BlockingQueuedConnection); connect(&musicDb, &DatabaseInterface::albumsAdded, &albumsModel, &AllAlbumsModel::albumsAdded); connect(&musicDb, &DatabaseInterface::albumModified, &albumsModel, &AllAlbumsModel::albumModified); connect(&musicDb, &DatabaseInterface::albumRemoved, &albumsModel, &AllAlbumsModel::albumRemoved); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&albumsModel, &AllAlbumsModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&albumsModel, &AllAlbumsModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&albumsModel, &AllAlbumsModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&albumsModel, &AllAlbumsModel::rowsRemoved); QSignalSpy dataChangedSpy(&albumsModel, &AllAlbumsModel::dataChanged); QCOMPARE(albumsModel.rowCount(), 0); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); while(beginInsertRowsSpy.count() < 5) { QCOMPARE(beginInsertRowsSpy.wait(500), true); } while(endInsertRowsSpy.count() < 5) { QCOMPARE(endInsertRowsSpy.wait(500), true); } QCOMPARE(albumsModel.rowCount(), 5); QCOMPARE(beginInsertRowsSpy.count(), 5); QCOMPARE(endInsertRowsSpy.count(), 5); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); auto firstTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album3"), 1, 1); auto firstTrack = musicDb.trackFromDatabaseId(firstTrackId); auto secondTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album3"), 2, 1); auto secondTrack = musicDb.trackFromDatabaseId(secondTrackId); auto thirdTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album3"), 3, 1); auto thirdTrack = musicDb.trackFromDatabaseId(thirdTrackId); musicDb.removeTracksList({firstTrack.resourceURI(), secondTrack.resourceURI(), thirdTrack.resourceURI()}); while (beginRemoveRowsSpy.count() < 1) { QCOMPARE(beginRemoveRowsSpy.wait(500), true); } while (endRemoveRowsSpy.count() < 1) { QCOMPARE(endRemoveRowsSpy.wait(500), true); } QCOMPARE(albumsModel.rowCount(), 4); QCOMPARE(beginInsertRowsSpy.count(), 5); QCOMPARE(endInsertRowsSpy.count(), 5); QCOMPARE(beginRemoveRowsSpy.count(), 1); QCOMPARE(endRemoveRowsSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); } void addOneTrack() { DatabaseInterface musicDb; AllAlbumsModel albumsModel; QAbstractItemModelTester testModel(&albumsModel, Qt::BlockingQueuedConnection); connect(&musicDb, &DatabaseInterface::albumsAdded, &albumsModel, &AllAlbumsModel::albumsAdded); connect(&musicDb, &DatabaseInterface::albumModified, &albumsModel, &AllAlbumsModel::albumModified); connect(&musicDb, &DatabaseInterface::albumRemoved, &albumsModel, &AllAlbumsModel::albumRemoved); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&albumsModel, &AllAlbumsModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&albumsModel, &AllAlbumsModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&albumsModel, &AllAlbumsModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&albumsModel, &AllAlbumsModel::rowsRemoved); QSignalSpy dataChangedSpy(&albumsModel, &AllAlbumsModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); while(beginInsertRowsSpy.count() < 5) { QCOMPARE(beginInsertRowsSpy.wait(500), true); } while(endInsertRowsSpy.count() < 5) { QCOMPARE(endInsertRowsSpy.wait(500), true); } QCOMPARE(beginInsertRowsSpy.count(), 5); QCOMPARE(endInsertRowsSpy.count(), 5); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track23"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 23, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("file://image$23"))}, 5, true, {}, QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); musicDb.insertTracksList(newTracks, mNewCovers, QStringLiteral("autoTest")); while(dataChangedSpy.count() < 1) { QCOMPARE(dataChangedSpy.wait(500), true); } QCOMPARE(beginInsertRowsSpy.count(), 5); QCOMPARE(endInsertRowsSpy.count(), 5); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 1); } void addOneAlbum() { DatabaseInterface musicDb; AllAlbumsModel albumsModel; QAbstractItemModelTester testModel(&albumsModel, Qt::BlockingQueuedConnection); connect(&musicDb, &DatabaseInterface::albumsAdded, &albumsModel, &AllAlbumsModel::albumsAdded); connect(&musicDb, &DatabaseInterface::albumModified, &albumsModel, &AllAlbumsModel::albumModified); connect(&musicDb, &DatabaseInterface::albumRemoved, &albumsModel, &AllAlbumsModel::albumRemoved); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&albumsModel, &AllAlbumsModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&albumsModel, &AllAlbumsModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&albumsModel, &AllAlbumsModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&albumsModel, &AllAlbumsModel::rowsRemoved); QSignalSpy dataChangedSpy(&albumsModel, &AllAlbumsModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); auto newFiles = QList(); const auto &constNewTracks = mNewTracks; for (const auto &oneTrack : constNewTracks) { newFiles.push_back(oneTrack.resourceURI()); } musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); while(beginInsertRowsSpy.count() < 5) { QCOMPARE(beginInsertRowsSpy.wait(500), true); } while(endInsertRowsSpy.count() < 5) { QCOMPARE(endInsertRowsSpy.wait(500), true); } QCOMPARE(beginInsertRowsSpy.count(), 5); QCOMPARE(endInsertRowsSpy.count(), 5); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); auto newTrack = MusicAudioTrack{true, QStringLiteral("$19"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album5"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(19), {QUrl::fromLocalFile(QStringLiteral("/$19"))}, QDateTime::fromMSecsSinceEpoch(19), {QUrl::fromLocalFile(QStringLiteral("file://image$19"))}, 5, true, {}, QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); auto newCover = QUrl::fromLocalFile(QStringLiteral("album5")); auto newCovers = QHash(); newCovers[QStringLiteral("album5")] = newCover; auto newFiles2 = QList(); for (const auto &oneTrack : newTracks) { newFiles2.push_back(oneTrack.resourceURI()); } musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); while(beginInsertRowsSpy.count() < 6) { QCOMPARE(beginInsertRowsSpy.wait(500), true); } while(endInsertRowsSpy.count() < 6) { QCOMPARE(endInsertRowsSpy.wait(500), true); } QCOMPARE(beginInsertRowsSpy.count(), 6); QCOMPARE(endInsertRowsSpy.count(), 6); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); } }; QTEST_GUILESS_MAIN(AllAlbumsModelTests) #include "allalbumsmodeltest.moc" diff --git a/autotests/allartistsmodeltest.cpp b/autotests/allartistsmodeltest.cpp index 7dcf2933..b4cb2e90 100644 --- a/autotests/allartistsmodeltest.cpp +++ b/autotests/allartistsmodeltest.cpp @@ -1,331 +1,329 @@ /* * Copyright 2015-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "musicalbum.h" #include "musicaudiotrack.h" #include "databaseinterface.h" #include "models/allartistsmodel.h" #include "qabstractitemmodeltester.h" #include #include #include #include #include #include #include #include #include #include #include #include class AllArtistsModelTests: public QObject { Q_OBJECT private: QList mNewTracks = { {true, QStringLiteral("$1"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 1, 1, QTime::fromMSecsSinceStartOfDay(1), {QUrl::fromLocalFile(QStringLiteral("/$1"))}, QDateTime::fromMSecsSinceEpoch(1), QUrl::fromLocalFile(QStringLiteral("album1")), 1, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$2"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 2, 2, QTime::fromMSecsSinceStartOfDay(2), {QUrl::fromLocalFile(QStringLiteral("/$2"))}, QDateTime::fromMSecsSinceEpoch(2), QUrl::fromLocalFile(QStringLiteral("album1")), 2, false, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$3"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 3, 3, QTime::fromMSecsSinceStartOfDay(3), {QUrl::fromLocalFile(QStringLiteral("/$3"))}, QDateTime::fromMSecsSinceEpoch(3), QUrl::fromLocalFile(QStringLiteral("album1")), 3, false, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4Bis"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$5"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 1, 1, QTime::fromMSecsSinceStartOfDay(5), {QUrl::fromLocalFile(QStringLiteral("/$5"))}, QDateTime::fromMSecsSinceEpoch(5), QUrl::fromLocalFile(QStringLiteral("album2")), 4, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$6"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 2, 1, QTime::fromMSecsSinceStartOfDay(6), {QUrl::fromLocalFile(QStringLiteral("/$6"))}, QDateTime::fromMSecsSinceEpoch(6), QUrl::fromLocalFile(QStringLiteral("album2")), 1, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$7"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 3, 1, QTime::fromMSecsSinceStartOfDay(7), {QUrl::fromLocalFile(QStringLiteral("/$7"))}, QDateTime::fromMSecsSinceEpoch(7), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$8"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 4, 1, QTime::fromMSecsSinceStartOfDay(8), {QUrl::fromLocalFile(QStringLiteral("/$8"))}, QDateTime::fromMSecsSinceEpoch(8), QUrl::fromLocalFile(QStringLiteral("album2")), 2, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$9"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 5, 1, QTime::fromMSecsSinceStartOfDay(9), {QUrl::fromLocalFile(QStringLiteral("/$9"))}, QDateTime::fromMSecsSinceEpoch(9), QUrl::fromLocalFile(QStringLiteral("album2")), 3, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$10"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist1 and artist2"), QStringLiteral("album2"), QStringLiteral("artist1"), 6, 1, QTime::fromMSecsSinceStartOfDay(10), {QUrl::fromLocalFile(QStringLiteral("/$10"))}, QDateTime::fromMSecsSinceEpoch(10), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$11"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(11), {QUrl::fromLocalFile(QStringLiteral("/$11"))}, QDateTime::fromMSecsSinceEpoch(11), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$12"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(12), {QUrl::fromLocalFile(QStringLiteral("/$12"))}, QDateTime::fromMSecsSinceEpoch(12), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$13"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(13), {QUrl::fromLocalFile(QStringLiteral("/$13"))}, QDateTime::fromMSecsSinceEpoch(13), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$14"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(14), {QUrl::fromLocalFile(QStringLiteral("/$14"))}, QDateTime::fromMSecsSinceEpoch(14), QUrl::fromLocalFile(QStringLiteral("album4")), 4, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$15"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(15), {QUrl::fromLocalFile(QStringLiteral("/$15"))}, QDateTime::fromMSecsSinceEpoch(15), QUrl::fromLocalFile(QStringLiteral("album4")), 5, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$16"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(16), {QUrl::fromLocalFile(QStringLiteral("/$16"))}, QDateTime::fromMSecsSinceEpoch(16), QUrl::fromLocalFile(QStringLiteral("album4")), 1, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$17"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 4, 1, QTime::fromMSecsSinceStartOfDay(17), {QUrl::fromLocalFile(QStringLiteral("/$17"))}, QDateTime::fromMSecsSinceEpoch(17), QUrl::fromLocalFile(QStringLiteral("album4")), 2, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$18"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 5, 1, QTime::fromMSecsSinceStartOfDay(18), {QUrl::fromLocalFile(QStringLiteral("/$18"))}, QDateTime::fromMSecsSinceEpoch(18), QUrl::fromLocalFile(QStringLiteral("album4")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$19"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 1, 1, QTime::fromMSecsSinceStartOfDay(19), {QUrl::fromLocalFile(QStringLiteral("/$19"))}, QDateTime::fromMSecsSinceEpoch(19), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 2, 1, QTime::fromMSecsSinceStartOfDay(20), {QUrl::fromLocalFile(QStringLiteral("/$20"))}, QDateTime::fromMSecsSinceEpoch(20), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$21"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 3, 1, QTime::fromMSecsSinceStartOfDay(21), {QUrl::fromLocalFile(QStringLiteral("/$21"))}, QDateTime::fromMSecsSinceEpoch(21), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$22"), QStringLiteral("0"), QStringLiteral("track9"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist7"), 9, 1, QTime::fromMSecsSinceStartOfDay(22), {QUrl::fromLocalFile(QStringLiteral("/$22"))}, QDateTime::fromMSecsSinceEpoch(22), QUrl::fromLocalFile(QStringLiteral("album3")), 9, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, }; QHash mNewCovers = { {QStringLiteral("file:///$1"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$2"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$3"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4Bis"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$5"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$6"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$7"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$8"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$9"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$0"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$11"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$12"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$13"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$14"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$15"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$16"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$17"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$18"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$19"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$20"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$21"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$22"), QUrl::fromLocalFile(QStringLiteral("album3"))}, }; private Q_SLOTS: void initTestCase() { qRegisterMetaType>("QHash"); qRegisterMetaType>("QHash"); qRegisterMetaType>>("QHash>"); qRegisterMetaType>("QVector"); qRegisterMetaType>("QHash"); qRegisterMetaType("MusicArtist"); } void removeOneArtist() { DatabaseInterface musicDb; AllArtistsModel artistsModel; QAbstractItemModelTester testModel(&artistsModel); connect(&musicDb, &DatabaseInterface::artistsAdded, &artistsModel, &AllArtistsModel::artistsAdded); connect(&musicDb, &DatabaseInterface::artistModified, &artistsModel, &AllArtistsModel::artistModified); connect(&musicDb, &DatabaseInterface::artistRemoved, &artistsModel, &AllArtistsModel::artistRemoved); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&artistsModel, &AllArtistsModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&artistsModel, &AllArtistsModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&artistsModel, &AllArtistsModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&artistsModel, &AllArtistsModel::rowsRemoved); QSignalSpy dataChangedSpy(&artistsModel, &AllArtistsModel::dataChanged); QCOMPARE(artistsModel.rowCount(), 0); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); auto newFiles = QList(); const auto &constNewTracks = mNewTracks; for (const auto &oneTrack : constNewTracks) { newFiles.push_back(oneTrack.resourceURI()); } musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(artistsModel.rowCount(), 7); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); auto trackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist1 and artist2"), QStringLiteral("album2"), 6, 1); auto firstTrack = musicDb.trackFromDatabaseId(trackId); musicDb.removeTracksList({firstTrack.resourceURI()}); QCOMPARE(artistsModel.rowCount(), 6); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 1); QCOMPARE(endRemoveRowsSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); } void addOneArtist() { DatabaseInterface musicDb; AllArtistsModel artistsModel; QAbstractItemModelTester testModel(&artistsModel); connect(&musicDb, &DatabaseInterface::artistsAdded, &artistsModel, &AllArtistsModel::artistsAdded); connect(&musicDb, &DatabaseInterface::artistModified, &artistsModel, &AllArtistsModel::artistModified); connect(&musicDb, &DatabaseInterface::artistRemoved, &artistsModel, &AllArtistsModel::artistRemoved); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&artistsModel, &AllArtistsModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&artistsModel, &AllArtistsModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&artistsModel, &AllArtistsModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&artistsModel, &AllArtistsModel::rowsRemoved); QSignalSpy dataChangedSpy(&artistsModel, &AllArtistsModel::dataChanged); QCOMPARE(artistsModel.rowCount(), 0); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); auto newFiles = QList(); const auto &constNewTracks = mNewTracks; for (const auto &oneTrack : constNewTracks) { newFiles.push_back(oneTrack.resourceURI()); } musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(artistsModel.rowCount(), 7); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track23"), QStringLiteral("artist6"), QStringLiteral("album4"), QStringLiteral("Various Artists"), 23, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("file://image$23"))}, 5, true, {}, QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); auto newFiles2 = QList(); for (const auto &oneTrack : newTracks) { newFiles2.push_back(oneTrack.resourceURI()); } musicDb.insertTracksList(newTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(artistsModel.rowCount(), 8); QCOMPARE(beginInsertRowsSpy.count(), 2); QCOMPARE(endInsertRowsSpy.count(), 2); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); } }; QTEST_GUILESS_MAIN(AllArtistsModelTests) #include "allartistsmodeltest.moc" diff --git a/autotests/alltracksmodeltest.cpp b/autotests/alltracksmodeltest.cpp index 07ad4df8..d9af1cf6 100644 --- a/autotests/alltracksmodeltest.cpp +++ b/autotests/alltracksmodeltest.cpp @@ -1,643 +1,641 @@ /* * Copyright 2015-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "musicalbum.h" #include "musicaudiotrack.h" #include "databaseinterface.h" #include "models/alltracksmodel.h" #include "qabstractitemmodeltester.h" #include #include #include #include #include #include #include #include #include #include #include #include class AllTracksModelTests: public QObject { Q_OBJECT private: QList mNewTracks = { {true, QStringLiteral("$1"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 1, 1, QTime::fromMSecsSinceStartOfDay(1), {QUrl::fromLocalFile(QStringLiteral("/$1"))}, QDateTime::fromMSecsSinceEpoch(1), QUrl::fromLocalFile(QStringLiteral("album1")), 1, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$2"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 2, 2, QTime::fromMSecsSinceStartOfDay(2), {QUrl::fromLocalFile(QStringLiteral("/$2"))}, QDateTime::fromMSecsSinceEpoch(2), QUrl::fromLocalFile(QStringLiteral("album1")), 2, false, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$3"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 3, 3, QTime::fromMSecsSinceStartOfDay(3), {QUrl::fromLocalFile(QStringLiteral("/$3"))}, QDateTime::fromMSecsSinceEpoch(3), QUrl::fromLocalFile(QStringLiteral("album1")), 3, false, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4Bis"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$5"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 1, 1, QTime::fromMSecsSinceStartOfDay(5), {QUrl::fromLocalFile(QStringLiteral("/$5"))}, QDateTime::fromMSecsSinceEpoch(5), QUrl::fromLocalFile(QStringLiteral("album2")), 4, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$6"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 2, 1, QTime::fromMSecsSinceStartOfDay(6), {QUrl::fromLocalFile(QStringLiteral("/$6"))}, QDateTime::fromMSecsSinceEpoch(6), QUrl::fromLocalFile(QStringLiteral("album2")), 1, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$7"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 3, 1, QTime::fromMSecsSinceStartOfDay(7), {QUrl::fromLocalFile(QStringLiteral("/$7"))}, QDateTime::fromMSecsSinceEpoch(7), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$8"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 4, 1, QTime::fromMSecsSinceStartOfDay(8), {QUrl::fromLocalFile(QStringLiteral("/$8"))}, QDateTime::fromMSecsSinceEpoch(8), QUrl::fromLocalFile(QStringLiteral("album2")), 2, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$9"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 5, 1, QTime::fromMSecsSinceStartOfDay(9), {QUrl::fromLocalFile(QStringLiteral("/$9"))}, QDateTime::fromMSecsSinceEpoch(9), QUrl::fromLocalFile(QStringLiteral("album2")), 3, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$10"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist1 and artist2"), QStringLiteral("album2"), QStringLiteral("artist1"), 6, 1, QTime::fromMSecsSinceStartOfDay(10), {QUrl::fromLocalFile(QStringLiteral("/$10"))}, QDateTime::fromMSecsSinceEpoch(10), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$11"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(11), {QUrl::fromLocalFile(QStringLiteral("/$11"))}, QDateTime::fromMSecsSinceEpoch(11), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$12"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(12), {QUrl::fromLocalFile(QStringLiteral("/$12"))}, QDateTime::fromMSecsSinceEpoch(12), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$13"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(13), {QUrl::fromLocalFile(QStringLiteral("/$13"))}, QDateTime::fromMSecsSinceEpoch(13), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$14"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(14), {QUrl::fromLocalFile(QStringLiteral("/$14"))}, QDateTime::fromMSecsSinceEpoch(14), QUrl::fromLocalFile(QStringLiteral("album4")), 4, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$15"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(15), {QUrl::fromLocalFile(QStringLiteral("/$15"))}, QDateTime::fromMSecsSinceEpoch(15), QUrl::fromLocalFile(QStringLiteral("album4")), 5, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$16"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(16), {QUrl::fromLocalFile(QStringLiteral("/$16"))}, QDateTime::fromMSecsSinceEpoch(16), QUrl::fromLocalFile(QStringLiteral("album4")), 1, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$17"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 4, 1, QTime::fromMSecsSinceStartOfDay(17), {QUrl::fromLocalFile(QStringLiteral("/$17"))}, QDateTime::fromMSecsSinceEpoch(17), QUrl::fromLocalFile(QStringLiteral("album4")), 2, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$18"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 5, 1, QTime::fromMSecsSinceStartOfDay(18), {QUrl::fromLocalFile(QStringLiteral("/$18"))}, QDateTime::fromMSecsSinceEpoch(18), QUrl::fromLocalFile(QStringLiteral("album4")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$19"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 1, 1, QTime::fromMSecsSinceStartOfDay(19), {QUrl::fromLocalFile(QStringLiteral("/$19"))}, QDateTime::fromMSecsSinceEpoch(19), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 2, 1, QTime::fromMSecsSinceStartOfDay(20), {QUrl::fromLocalFile(QStringLiteral("/$20"))}, QDateTime::fromMSecsSinceEpoch(20), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$21"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 3, 1, QTime::fromMSecsSinceStartOfDay(21), {QUrl::fromLocalFile(QStringLiteral("/$21"))}, QDateTime::fromMSecsSinceEpoch(21), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$22"), QStringLiteral("0"), QStringLiteral("track9"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist7"), 9, 1, QTime::fromMSecsSinceStartOfDay(22), {QUrl::fromLocalFile(QStringLiteral("/$22"))}, QDateTime::fromMSecsSinceEpoch(22), QUrl::fromLocalFile(QStringLiteral("album3")), 9, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, }; QHash mNewCovers = { {QStringLiteral("file:///$1"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$2"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$3"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4Bis"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$5"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$6"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$7"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$8"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$9"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$0"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$11"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$12"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$13"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$14"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$15"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$16"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$17"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$18"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$19"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$20"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$21"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$22"), QUrl::fromLocalFile(QStringLiteral("album3"))}, }; private Q_SLOTS: void initTestCase() { qRegisterMetaType>("QHash"); qRegisterMetaType>("QHash"); qRegisterMetaType>>("QHash>"); qRegisterMetaType>("QVector"); qRegisterMetaType>("QHash"); qRegisterMetaType("MusicArtist"); } void removeOneTrack() { DatabaseInterface musicDb; AllTracksModel tracksModel; QAbstractItemModelTester testModel(&tracksModel); connect(&musicDb, &DatabaseInterface::tracksAdded, &tracksModel, &AllTracksModel::tracksAdded); connect(&musicDb, &DatabaseInterface::trackModified, &tracksModel, &AllTracksModel::trackModified); connect(&musicDb, &DatabaseInterface::trackRemoved, &tracksModel, &AllTracksModel::trackRemoved); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&tracksModel, &AllTracksModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&tracksModel, &AllTracksModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&tracksModel, &AllTracksModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&tracksModel, &AllTracksModel::rowsRemoved); QSignalSpy dataChangedSpy(&tracksModel, &AllTracksModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(tracksModel.rowCount(), 22); auto trackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); auto firstTrack = musicDb.trackFromDatabaseId(trackId); musicDb.removeTracksList({firstTrack.resourceURI()}); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 1); QCOMPARE(endRemoveRowsSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(tracksModel.rowCount(), 21); } void removeOneAlbum() { DatabaseInterface musicDb; AllTracksModel tracksModel; QAbstractItemModelTester testModel(&tracksModel); connect(&musicDb, &DatabaseInterface::tracksAdded, &tracksModel, &AllTracksModel::tracksAdded); connect(&musicDb, &DatabaseInterface::trackModified, &tracksModel, &AllTracksModel::trackModified); connect(&musicDb, &DatabaseInterface::trackRemoved, &tracksModel, &AllTracksModel::trackRemoved); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&tracksModel, &AllTracksModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&tracksModel, &AllTracksModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&tracksModel, &AllTracksModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&tracksModel, &AllTracksModel::rowsRemoved); QSignalSpy dataChangedSpy(&tracksModel, &AllTracksModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(tracksModel.rowCount(), 22); auto firstTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album3"), 1, 1); auto firstTrack = musicDb.trackFromDatabaseId(firstTrackId); auto secondTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album3"), 2, 1); auto secondTrack = musicDb.trackFromDatabaseId(secondTrackId); auto thirdTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album3"), 3, 1); auto thirdTrack = musicDb.trackFromDatabaseId(thirdTrackId); musicDb.removeTracksList({firstTrack.resourceURI(), secondTrack.resourceURI(), thirdTrack.resourceURI()}); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 3); QCOMPARE(endRemoveRowsSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(tracksModel.rowCount(), 19); } void addOneTrack() { DatabaseInterface musicDb; AllTracksModel tracksModel; QAbstractItemModelTester testModel(&tracksModel); connect(&musicDb, &DatabaseInterface::tracksAdded, &tracksModel, &AllTracksModel::tracksAdded); connect(&musicDb, &DatabaseInterface::trackModified, &tracksModel, &AllTracksModel::trackModified); connect(&musicDb, &DatabaseInterface::trackRemoved, &tracksModel, &AllTracksModel::trackRemoved); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&tracksModel, &AllTracksModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&tracksModel, &AllTracksModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&tracksModel, &AllTracksModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&tracksModel, &AllTracksModel::rowsRemoved); QSignalSpy dataChangedSpy(&tracksModel, &AllTracksModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(tracksModel.rowCount(), 22); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track23"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 23, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("file://image$23"))}, 5, true, {}, QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); musicDb.insertTracksList(newTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 2); QCOMPARE(endInsertRowsSpy.count(), 2); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(tracksModel.rowCount(), 23); } void addOneAlbum() { DatabaseInterface musicDb; AllTracksModel tracksModel; QAbstractItemModelTester testModel(&tracksModel); connect(&musicDb, &DatabaseInterface::tracksAdded, &tracksModel, &AllTracksModel::tracksAdded); connect(&musicDb, &DatabaseInterface::trackModified, &tracksModel, &AllTracksModel::trackModified); connect(&musicDb, &DatabaseInterface::trackRemoved, &tracksModel, &AllTracksModel::trackRemoved); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&tracksModel, &AllTracksModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&tracksModel, &AllTracksModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&tracksModel, &AllTracksModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&tracksModel, &AllTracksModel::rowsRemoved); QSignalSpy dataChangedSpy(&tracksModel, &AllTracksModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); auto newFiles = QList(); const auto &constNewTracks = mNewTracks; for (const auto &oneTrack : constNewTracks) { newFiles.push_back(oneTrack.resourceURI()); } musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(tracksModel.rowCount(), 22); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track23"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 23, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("file://image$23"))}, 5, true, {}, QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); auto newCover = QUrl::fromLocalFile(QStringLiteral("album5")); auto newCovers = QHash(); newCovers[QStringLiteral("album5")] = newCover; auto newFiles2 = QList(); for (const auto &oneTrack : newTracks) { newFiles2.push_back(oneTrack.resourceURI()); } musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 2); QCOMPARE(endInsertRowsSpy.count(), 2); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(tracksModel.rowCount(), 23); } void addDuplicateTracks() { AllTracksModel tracksModel; QAbstractItemModelTester testModel(&tracksModel); auto newTracks = QList(); newTracks.push_back({true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track23"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 23, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("file://image$23"))}, 5, true, {}, QStringLiteral("composer1"), QStringLiteral("lyricist1")}); newTracks.push_back({true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track23"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 23, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("file://image$23"))}, 5, true, {}, QStringLiteral("composer1"), QStringLiteral("lyricist1")}); QSignalSpy beginInsertRowsSpy(&tracksModel, &AllTracksModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&tracksModel, &AllTracksModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&tracksModel, &AllTracksModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&tracksModel, &AllTracksModel::rowsRemoved); QSignalSpy dataChangedSpy(&tracksModel, &AllTracksModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); tracksModel.tracksAdded(newTracks); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(tracksModel.rowCount(), 1); } void modifyOneTrack() { DatabaseInterface musicDb; AllTracksModel tracksModel; QAbstractItemModelTester testModel(&tracksModel); connect(&musicDb, &DatabaseInterface::tracksAdded, &tracksModel, &AllTracksModel::tracksAdded); connect(&musicDb, &DatabaseInterface::trackModified, &tracksModel, &AllTracksModel::trackModified); connect(&musicDb, &DatabaseInterface::trackRemoved, &tracksModel, &AllTracksModel::trackRemoved); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&tracksModel, &AllTracksModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&tracksModel, &AllTracksModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&tracksModel, &AllTracksModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&tracksModel, &AllTracksModel::rowsRemoved); QSignalSpy dataChangedSpy(&tracksModel, &AllTracksModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(tracksModel.rowCount(), 22); auto newTrack = MusicAudioTrack{true, QStringLiteral("$1"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 1, 1, QTime::fromMSecsSinceStartOfDay(1), {QUrl::fromLocalFile(QStringLiteral("/$1"))}, QDateTime::fromMSecsSinceEpoch(1), {QUrl::fromLocalFile(QStringLiteral("file://image$1"))}, 5, true, {}, QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); musicDb.insertTracksList(newTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(tracksModel.rowCount(), 22); auto dataChangedSignal = dataChangedSpy.constFirst(); QCOMPARE(dataChangedSignal.size(), 3); auto changedIndex = dataChangedSignal.constFirst().toModelIndex(); QCOMPARE(tracksModel.data(changedIndex, ElisaUtils::RatingRole).isValid(), true); QCOMPARE(tracksModel.data(changedIndex, ElisaUtils::RatingRole).toInt(), 5); } void addEmptyTracksList() { AllTracksModel tracksModel; QAbstractItemModelTester testModel(&tracksModel); auto newTracks = QList(); QSignalSpy beginInsertRowsSpy(&tracksModel, &AllTracksModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&tracksModel, &AllTracksModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&tracksModel, &AllTracksModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&tracksModel, &AllTracksModel::rowsRemoved); QSignalSpy dataChangedSpy(&tracksModel, &AllTracksModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); tracksModel.tracksAdded(newTracks); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(tracksModel.rowCount(), 0); } void addTracksListTwice() { DatabaseInterface musicDb; AllTracksModel tracksModel; QAbstractItemModelTester testModel(&tracksModel); connect(&musicDb, &DatabaseInterface::tracksAdded, &tracksModel, &AllTracksModel::tracksAdded); connect(&musicDb, &DatabaseInterface::trackModified, &tracksModel, &AllTracksModel::trackModified); connect(&musicDb, &DatabaseInterface::trackRemoved, &tracksModel, &AllTracksModel::trackRemoved); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&tracksModel, &AllTracksModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&tracksModel, &AllTracksModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&tracksModel, &AllTracksModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&tracksModel, &AllTracksModel::rowsRemoved); QSignalSpy dataChangedSpy(&tracksModel, &AllTracksModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(tracksModel.rowCount(), 22); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track23"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 23, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("file://image$23"))}, 5, true, {}, QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); musicDb.insertTracksList(newTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 2); QCOMPARE(endInsertRowsSpy.count(), 2); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(tracksModel.rowCount(), 23); } }; QTEST_GUILESS_MAIN(AllTracksModelTests) #include "alltracksmodeltest.moc" diff --git a/autotests/alltracksproxymodeltest.cpp b/autotests/alltracksproxymodeltest.cpp index 8b891d2b..e4991deb 100644 --- a/autotests/alltracksproxymodeltest.cpp +++ b/autotests/alltracksproxymodeltest.cpp @@ -1,666 +1,664 @@ /* * Copyright 2015-2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "musicalbum.h" #include "musicaudiotrack.h" #include "databaseinterface.h" #include "models/alltracksmodel.h" #include "models/alltracksproxymodel.h" #include "qabstractitemmodeltester.h" #include #include #include #include #include #include #include #include #include #include #include #include class AllTracksProxyModelTests: public QObject { Q_OBJECT private: QList mNewTracks = { {true, QStringLiteral("$1"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 1, 1, QTime::fromMSecsSinceStartOfDay(1), {QUrl::fromLocalFile(QStringLiteral("/$1"))}, QDateTime::fromMSecsSinceEpoch(1), QUrl::fromLocalFile(QStringLiteral("album1")), 1, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$2"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 2, 2, QTime::fromMSecsSinceStartOfDay(2), {QUrl::fromLocalFile(QStringLiteral("/$2"))}, QDateTime::fromMSecsSinceEpoch(2), QUrl::fromLocalFile(QStringLiteral("album1")), 2, false, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$3"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 3, 3, QTime::fromMSecsSinceStartOfDay(3), {QUrl::fromLocalFile(QStringLiteral("/$3"))}, QDateTime::fromMSecsSinceEpoch(3), QUrl::fromLocalFile(QStringLiteral("album1")), 3, false, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4Bis"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$5"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 1, 1, QTime::fromMSecsSinceStartOfDay(5), {QUrl::fromLocalFile(QStringLiteral("/$5"))}, QDateTime::fromMSecsSinceEpoch(5), QUrl::fromLocalFile(QStringLiteral("album2")), 4, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$6"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 2, 1, QTime::fromMSecsSinceStartOfDay(6), {QUrl::fromLocalFile(QStringLiteral("/$6"))}, QDateTime::fromMSecsSinceEpoch(6), QUrl::fromLocalFile(QStringLiteral("album2")), 1, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$7"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 3, 1, QTime::fromMSecsSinceStartOfDay(7), {QUrl::fromLocalFile(QStringLiteral("/$7"))}, QDateTime::fromMSecsSinceEpoch(7), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$8"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 4, 1, QTime::fromMSecsSinceStartOfDay(8), {QUrl::fromLocalFile(QStringLiteral("/$8"))}, QDateTime::fromMSecsSinceEpoch(8), QUrl::fromLocalFile(QStringLiteral("album2")), 2, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$9"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 5, 1, QTime::fromMSecsSinceStartOfDay(9), {QUrl::fromLocalFile(QStringLiteral("/$9"))}, QDateTime::fromMSecsSinceEpoch(9), QUrl::fromLocalFile(QStringLiteral("album2")), 3, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$10"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist1 and artist2"), QStringLiteral("album2"), QStringLiteral("artist1"), 6, 1, QTime::fromMSecsSinceStartOfDay(10), {QUrl::fromLocalFile(QStringLiteral("/$10"))}, QDateTime::fromMSecsSinceEpoch(10), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$11"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(11), {QUrl::fromLocalFile(QStringLiteral("/$11"))}, QDateTime::fromMSecsSinceEpoch(11), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$12"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(12), {QUrl::fromLocalFile(QStringLiteral("/$12"))}, QDateTime::fromMSecsSinceEpoch(12), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$13"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(13), {QUrl::fromLocalFile(QStringLiteral("/$13"))}, QDateTime::fromMSecsSinceEpoch(13), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$14"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(14), {QUrl::fromLocalFile(QStringLiteral("/$14"))}, QDateTime::fromMSecsSinceEpoch(14), QUrl::fromLocalFile(QStringLiteral("album4")), 4, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$15"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(15), {QUrl::fromLocalFile(QStringLiteral("/$15"))}, QDateTime::fromMSecsSinceEpoch(15), QUrl::fromLocalFile(QStringLiteral("album4")), 5, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$16"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(16), {QUrl::fromLocalFile(QStringLiteral("/$16"))}, QDateTime::fromMSecsSinceEpoch(16), QUrl::fromLocalFile(QStringLiteral("album4")), 1, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$17"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 4, 1, QTime::fromMSecsSinceStartOfDay(17), {QUrl::fromLocalFile(QStringLiteral("/$17"))}, QDateTime::fromMSecsSinceEpoch(17), QUrl::fromLocalFile(QStringLiteral("album4")), 2, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$18"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 5, 1, QTime::fromMSecsSinceStartOfDay(18), {QUrl::fromLocalFile(QStringLiteral("/$18"))}, QDateTime::fromMSecsSinceEpoch(18), QUrl::fromLocalFile(QStringLiteral("album4")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$19"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 1, 1, QTime::fromMSecsSinceStartOfDay(19), {QUrl::fromLocalFile(QStringLiteral("/$19"))}, QDateTime::fromMSecsSinceEpoch(19), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 2, 1, QTime::fromMSecsSinceStartOfDay(20), {QUrl::fromLocalFile(QStringLiteral("/$20"))}, QDateTime::fromMSecsSinceEpoch(20), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$21"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 3, 1, QTime::fromMSecsSinceStartOfDay(21), {QUrl::fromLocalFile(QStringLiteral("/$21"))}, QDateTime::fromMSecsSinceEpoch(21), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$22"), QStringLiteral("0"), QStringLiteral("track9"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist7"), 9, 1, QTime::fromMSecsSinceStartOfDay(22), {QUrl::fromLocalFile(QStringLiteral("/$22"))}, QDateTime::fromMSecsSinceEpoch(22), QUrl::fromLocalFile(QStringLiteral("album3")), 9, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, }; QHash mNewCovers = { {QStringLiteral("file:///$1"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$2"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$3"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4Bis"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$5"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$6"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$7"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$8"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$9"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$0"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$11"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$12"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$13"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$14"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$15"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$16"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$17"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$18"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$19"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$20"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$21"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$22"), QUrl::fromLocalFile(QStringLiteral("album3"))}, }; private Q_SLOTS: void initTestCase() { qRegisterMetaType>("QHash"); qRegisterMetaType>("QHash"); qRegisterMetaType>>("QHash>"); qRegisterMetaType>("QVector"); qRegisterMetaType>("QHash"); qRegisterMetaType("MusicArtist"); } void removeOneTrack() { DatabaseInterface musicDb; AllTracksModel tracksModel; QAbstractItemModelTester testModel(&tracksModel); AllTracksProxyModel proxyTracksModel; QAbstractItemModelTester proxyTestModel(&proxyTracksModel); proxyTracksModel.setSourceModel(&tracksModel); connect(&musicDb, &DatabaseInterface::tracksAdded, &tracksModel, &AllTracksModel::tracksAdded); connect(&musicDb, &DatabaseInterface::trackModified, &tracksModel, &AllTracksModel::trackModified); connect(&musicDb, &DatabaseInterface::trackRemoved, &tracksModel, &AllTracksModel::trackRemoved); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&proxyTracksModel, &AllTracksModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&proxyTracksModel, &AllTracksModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&proxyTracksModel, &AllTracksModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&proxyTracksModel, &AllTracksModel::rowsRemoved); QSignalSpy dataChangedSpy(&proxyTracksModel, &AllTracksModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(proxyTracksModel.rowCount(), 22); auto trackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); auto firstTrack = musicDb.trackFromDatabaseId(trackId); musicDb.removeTracksList({firstTrack.resourceURI()}); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 1); QCOMPARE(endRemoveRowsSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(proxyTracksModel.rowCount(), 21); } void removeOneAlbum() { DatabaseInterface musicDb; AllTracksModel tracksModel; QAbstractItemModelTester testModel(&tracksModel); AllTracksProxyModel proxyTracksModel; QAbstractItemModelTester proxyTestModel(&proxyTracksModel); proxyTracksModel.setSourceModel(&tracksModel); connect(&musicDb, &DatabaseInterface::tracksAdded, &tracksModel, &AllTracksModel::tracksAdded); connect(&musicDb, &DatabaseInterface::trackModified, &tracksModel, &AllTracksModel::trackModified); connect(&musicDb, &DatabaseInterface::trackRemoved, &tracksModel, &AllTracksModel::trackRemoved); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&proxyTracksModel, &AllTracksModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&proxyTracksModel, &AllTracksModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&proxyTracksModel, &AllTracksModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&proxyTracksModel, &AllTracksModel::rowsRemoved); QSignalSpy dataChangedSpy(&proxyTracksModel, &AllTracksModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(proxyTracksModel.rowCount(), 22); auto firstTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album3"), 1, 1); auto firstTrack = musicDb.trackFromDatabaseId(firstTrackId); auto secondTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album3"), 2, 1); auto secondTrack = musicDb.trackFromDatabaseId(secondTrackId); auto thirdTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album3"), 3, 1); auto thirdTrack = musicDb.trackFromDatabaseId(thirdTrackId); musicDb.removeTracksList({firstTrack.resourceURI(), secondTrack.resourceURI(), thirdTrack.resourceURI()}); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 3); QCOMPARE(endRemoveRowsSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(proxyTracksModel.rowCount(), 19); } void addOneTrack() { DatabaseInterface musicDb; AllTracksModel tracksModel; QAbstractItemModelTester testModel(&tracksModel); AllTracksProxyModel proxyTracksModel; QAbstractItemModelTester proxyTestModel(&proxyTracksModel); proxyTracksModel.setSourceModel(&tracksModel); connect(&musicDb, &DatabaseInterface::tracksAdded, &tracksModel, &AllTracksModel::tracksAdded); connect(&musicDb, &DatabaseInterface::trackModified, &tracksModel, &AllTracksModel::trackModified); connect(&musicDb, &DatabaseInterface::trackRemoved, &tracksModel, &AllTracksModel::trackRemoved); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&proxyTracksModel, &AllTracksModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&proxyTracksModel, &AllTracksModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&proxyTracksModel, &AllTracksModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&proxyTracksModel, &AllTracksModel::rowsRemoved); QSignalSpy dataChangedSpy(&proxyTracksModel, &AllTracksModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(proxyTracksModel.rowCount(), 22); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track23"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 23, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("file://image$23"))}, 5, true, {}, QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); musicDb.insertTracksList(newTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 2); QCOMPARE(endInsertRowsSpy.count(), 2); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(proxyTracksModel.rowCount(), 23); } void addOneAlbum() { DatabaseInterface musicDb; AllTracksModel tracksModel; QAbstractItemModelTester testModel(&tracksModel); AllTracksProxyModel proxyTracksModel; QAbstractItemModelTester proxyTestModel(&proxyTracksModel); proxyTracksModel.setSourceModel(&tracksModel); connect(&musicDb, &DatabaseInterface::tracksAdded, &tracksModel, &AllTracksModel::tracksAdded); connect(&musicDb, &DatabaseInterface::trackModified, &tracksModel, &AllTracksModel::trackModified); connect(&musicDb, &DatabaseInterface::trackRemoved, &tracksModel, &AllTracksModel::trackRemoved); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&proxyTracksModel, &AllTracksModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&proxyTracksModel, &AllTracksModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&proxyTracksModel, &AllTracksModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&proxyTracksModel, &AllTracksModel::rowsRemoved); QSignalSpy dataChangedSpy(&proxyTracksModel, &AllTracksModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); auto newFiles = QList(); const auto &constNewTracks = mNewTracks; for (const auto &oneTrack : constNewTracks) { newFiles.push_back(oneTrack.resourceURI()); } musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(proxyTracksModel.rowCount(), 22); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track23"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 23, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("file://image$23"))}, 5, true, {}, QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); auto newCover = QUrl::fromLocalFile(QStringLiteral("album5")); auto newCovers = QHash(); newCovers[QStringLiteral("album5")] = newCover; auto newFiles2 = QList(); for (const auto &oneTrack : newTracks) { newFiles2.push_back(oneTrack.resourceURI()); } musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 2); QCOMPARE(endInsertRowsSpy.count(), 2); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(proxyTracksModel.rowCount(), 23); } void addDuplicateTracks() { AllTracksModel tracksModel; QAbstractItemModelTester testModel(&tracksModel); AllTracksProxyModel proxyTracksModel; QAbstractItemModelTester proxyTestModel(&proxyTracksModel); proxyTracksModel.setSourceModel(&tracksModel); auto newTracks = QList(); newTracks.push_back({true, QStringLiteral("$19"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 6, 1, QTime::fromMSecsSinceStartOfDay(19), {QUrl::fromLocalFile(QStringLiteral("/$19"))}, QDateTime::fromMSecsSinceEpoch(19), {QUrl::fromLocalFile(QStringLiteral("file://image$19"))}, 5, true, {}, QStringLiteral("composer1"), QStringLiteral("lyricist1")}); newTracks.push_back({true, QStringLiteral("$19"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 6, 1, QTime::fromMSecsSinceStartOfDay(19), {QUrl::fromLocalFile(QStringLiteral("/$19"))}, QDateTime::fromMSecsSinceEpoch(19), {QUrl::fromLocalFile(QStringLiteral("file://image$19"))}, 5, true, {}, QStringLiteral("composer1"), QStringLiteral("lyricist1")}); QSignalSpy beginInsertRowsSpy(&proxyTracksModel, &AllTracksModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&proxyTracksModel, &AllTracksModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&proxyTracksModel, &AllTracksModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&proxyTracksModel, &AllTracksModel::rowsRemoved); QSignalSpy dataChangedSpy(&proxyTracksModel, &AllTracksModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); tracksModel.tracksAdded(newTracks); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(proxyTracksModel.rowCount(), 1); } void modifyOneTrack() { DatabaseInterface musicDb; AllTracksModel tracksModel; QAbstractItemModelTester testModel(&tracksModel); AllTracksProxyModel proxyTracksModel; QAbstractItemModelTester proxyTestModel(&proxyTracksModel); proxyTracksModel.setSourceModel(&tracksModel); connect(&musicDb, &DatabaseInterface::tracksAdded, &tracksModel, &AllTracksModel::tracksAdded); connect(&musicDb, &DatabaseInterface::trackModified, &tracksModel, &AllTracksModel::trackModified); connect(&musicDb, &DatabaseInterface::trackRemoved, &tracksModel, &AllTracksModel::trackRemoved); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&proxyTracksModel, &AllTracksModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&proxyTracksModel, &AllTracksModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&proxyTracksModel, &AllTracksModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&proxyTracksModel, &AllTracksModel::rowsRemoved); QSignalSpy dataChangedSpy(&proxyTracksModel, &AllTracksModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(proxyTracksModel.rowCount(), 22); auto newTrack = MusicAudioTrack{true, QStringLiteral("$1"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 1, 1, QTime::fromMSecsSinceStartOfDay(1), {QUrl::fromLocalFile(QStringLiteral("/$1"))}, QDateTime::fromMSecsSinceEpoch(1), {QUrl::fromLocalFile(QStringLiteral("file://image$1"))}, 5, true, {}, QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); musicDb.insertTracksList(newTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(proxyTracksModel.rowCount(), 22); auto dataChangedSignal = dataChangedSpy.constFirst(); QCOMPARE(dataChangedSignal.size(), 3); auto changedIndex = dataChangedSignal.constFirst().toModelIndex(); QCOMPARE(proxyTracksModel.data(changedIndex, ElisaUtils::RatingRole).isValid(), true); QCOMPARE(proxyTracksModel.data(changedIndex, ElisaUtils::RatingRole).toInt(), 5); } void addEmptyTracksList() { AllTracksModel tracksModel; QAbstractItemModelTester testModel(&tracksModel); AllTracksProxyModel proxyTracksModel; QAbstractItemModelTester proxyTestModel(&proxyTracksModel); proxyTracksModel.setSourceModel(&tracksModel); auto newTracks = QList(); QSignalSpy beginInsertRowsSpy(&proxyTracksModel, &AllTracksModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&proxyTracksModel, &AllTracksModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&proxyTracksModel, &AllTracksModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&proxyTracksModel, &AllTracksModel::rowsRemoved); QSignalSpy dataChangedSpy(&proxyTracksModel, &AllTracksModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); tracksModel.tracksAdded(newTracks); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(proxyTracksModel.rowCount(), 0); } void addTracksListTwice() { DatabaseInterface musicDb; AllTracksModel tracksModel; QAbstractItemModelTester testModel(&tracksModel); AllTracksProxyModel proxyTracksModel; QAbstractItemModelTester proxyTestModel(&proxyTracksModel); proxyTracksModel.setSourceModel(&tracksModel); connect(&musicDb, &DatabaseInterface::tracksAdded, &tracksModel, &AllTracksModel::tracksAdded); connect(&musicDb, &DatabaseInterface::trackModified, &tracksModel, &AllTracksModel::trackModified); connect(&musicDb, &DatabaseInterface::trackRemoved, &tracksModel, &AllTracksModel::trackRemoved); musicDb.init(QStringLiteral("testDb")); QSignalSpy beginInsertRowsSpy(&proxyTracksModel, &AllTracksModel::rowsAboutToBeInserted); QSignalSpy endInsertRowsSpy(&proxyTracksModel, &AllTracksModel::rowsInserted); QSignalSpy beginRemoveRowsSpy(&proxyTracksModel, &AllTracksModel::rowsAboutToBeRemoved); QSignalSpy endRemoveRowsSpy(&proxyTracksModel, &AllTracksModel::rowsRemoved); QSignalSpy dataChangedSpy(&proxyTracksModel, &AllTracksModel::dataChanged); QCOMPARE(beginInsertRowsSpy.count(), 0); QCOMPARE(endInsertRowsSpy.count(), 0); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 1); QCOMPARE(endInsertRowsSpy.count(), 1); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(proxyTracksModel.rowCount(), 22); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track23"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 23, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("file://image$23"))}, 5, true, {}, QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); musicDb.insertTracksList(newTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(beginInsertRowsSpy.count(), 2); QCOMPARE(endInsertRowsSpy.count(), 2); QCOMPARE(beginRemoveRowsSpy.count(), 0); QCOMPARE(endRemoveRowsSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(proxyTracksModel.rowCount(), 23); } }; QTEST_GUILESS_MAIN(AllTracksProxyModelTests) #include "alltracksproxymodeltest.moc" diff --git a/autotests/databaseinterfacetest.cpp b/autotests/databaseinterfacetest.cpp index bf4884b9..9013fdd8 100644 --- a/autotests/databaseinterfacetest.cpp +++ b/autotests/databaseinterfacetest.cpp @@ -1,4412 +1,4410 @@ /* * Copyright 2015-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "databaseinterface.h" #include "musicalbum.h" #include "musicaudiotrack.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include class DatabaseInterfaceTests: public QObject { Q_OBJECT private: QList mNewTracks = { {true, QStringLiteral("$1"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 1, 1, QTime::fromMSecsSinceStartOfDay(1), {QUrl::fromLocalFile(QStringLiteral("/$1"))}, QDateTime::fromMSecsSinceEpoch(1), QUrl::fromLocalFile(QStringLiteral("album1")), 1, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$2"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 2, 2, QTime::fromMSecsSinceStartOfDay(2), {QUrl::fromLocalFile(QStringLiteral("/$2"))}, QDateTime::fromMSecsSinceEpoch(2), QUrl::fromLocalFile(QStringLiteral("album1")), 2, false, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$3"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 3, 3, QTime::fromMSecsSinceStartOfDay(3), {QUrl::fromLocalFile(QStringLiteral("/$3"))}, QDateTime::fromMSecsSinceEpoch(3), QUrl::fromLocalFile(QStringLiteral("album1")), 3, false, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4Bis"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$5"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 1, 1, QTime::fromMSecsSinceStartOfDay(5), {QUrl::fromLocalFile(QStringLiteral("/$5"))}, QDateTime::fromMSecsSinceEpoch(5), QUrl::fromLocalFile(QStringLiteral("album2")), 4, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$6"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 2, 1, QTime::fromMSecsSinceStartOfDay(6), {QUrl::fromLocalFile(QStringLiteral("/$6"))}, QDateTime::fromMSecsSinceEpoch(6), QUrl::fromLocalFile(QStringLiteral("album2")), 1, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$7"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 3, 1, QTime::fromMSecsSinceStartOfDay(7), {QUrl::fromLocalFile(QStringLiteral("/$7"))}, QDateTime::fromMSecsSinceEpoch(7), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$8"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 4, 1, QTime::fromMSecsSinceStartOfDay(8), {QUrl::fromLocalFile(QStringLiteral("/$8"))}, QDateTime::fromMSecsSinceEpoch(8), QUrl::fromLocalFile(QStringLiteral("album2")), 2, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$9"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 5, 1, QTime::fromMSecsSinceStartOfDay(9), {QUrl::fromLocalFile(QStringLiteral("/$9"))}, QDateTime::fromMSecsSinceEpoch(9), QUrl::fromLocalFile(QStringLiteral("album2")), 3, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$10"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist1 and artist2"), QStringLiteral("album2"), QStringLiteral("artist1"), 6, 1, QTime::fromMSecsSinceStartOfDay(10), {QUrl::fromLocalFile(QStringLiteral("/$10"))}, QDateTime::fromMSecsSinceEpoch(10), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$11"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(11), {QUrl::fromLocalFile(QStringLiteral("/$11"))}, QDateTime::fromMSecsSinceEpoch(11), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$12"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(12), {QUrl::fromLocalFile(QStringLiteral("/$12"))}, QDateTime::fromMSecsSinceEpoch(12), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$13"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(13), {QUrl::fromLocalFile(QStringLiteral("/$13"))}, QDateTime::fromMSecsSinceEpoch(13), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$14"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(14), {QUrl::fromLocalFile(QStringLiteral("/$14"))}, QDateTime::fromMSecsSinceEpoch(14), QUrl::fromLocalFile(QStringLiteral("album4")), 4, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$15"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(15), {QUrl::fromLocalFile(QStringLiteral("/$15"))}, QDateTime::fromMSecsSinceEpoch(15), QUrl::fromLocalFile(QStringLiteral("album4")), 5, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$16"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(16), {QUrl::fromLocalFile(QStringLiteral("/$16"))}, QDateTime::fromMSecsSinceEpoch(16), QUrl::fromLocalFile(QStringLiteral("album4")), 1, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$17"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 4, 1, QTime::fromMSecsSinceStartOfDay(17), {QUrl::fromLocalFile(QStringLiteral("/$17"))}, QDateTime::fromMSecsSinceEpoch(17), QUrl::fromLocalFile(QStringLiteral("album4")), 2, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$18"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 5, 1, QTime::fromMSecsSinceStartOfDay(18), {QUrl::fromLocalFile(QStringLiteral("/$18"))}, QDateTime::fromMSecsSinceEpoch(18), QUrl::fromLocalFile(QStringLiteral("album4")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$19"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 1, 1, QTime::fromMSecsSinceStartOfDay(19), {QUrl::fromLocalFile(QStringLiteral("/$19"))}, QDateTime::fromMSecsSinceEpoch(19), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 2, 1, QTime::fromMSecsSinceStartOfDay(20), {QUrl::fromLocalFile(QStringLiteral("/$20"))}, QDateTime::fromMSecsSinceEpoch(20), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$21"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 3, 1, QTime::fromMSecsSinceStartOfDay(21), {QUrl::fromLocalFile(QStringLiteral("/$21"))}, QDateTime::fromMSecsSinceEpoch(21), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$22"), QStringLiteral("0"), QStringLiteral("track9"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist7"), 9, 1, QTime::fromMSecsSinceStartOfDay(22), {QUrl::fromLocalFile(QStringLiteral("/$22"))}, QDateTime::fromMSecsSinceEpoch(22), QUrl::fromLocalFile(QStringLiteral("album3")), 9, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, }; QHash mNewCovers = { {QStringLiteral("file:///$1"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$2"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$3"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4Bis"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$5"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$6"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$7"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$8"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$9"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$0"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$11"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$12"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$13"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$14"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$15"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$16"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$17"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$18"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$19"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$20"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$21"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$22"), QUrl::fromLocalFile(QStringLiteral("album3"))}, }; private Q_SLOTS: void initTestCase() { qRegisterMetaType>("QHash"); qRegisterMetaType>("QHash"); qRegisterMetaType>("QList"); qRegisterMetaType>("QVector"); qRegisterMetaType>("QHash"); qRegisterMetaType("MusicArtist"); } void avoidCrashInTrackIdFromTitleAlbumArtist() { DatabaseInterface musicDb; musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album3"), 1, 1); } void avoidCrashInAllArtists() { DatabaseInterface musicDb; musicDb.allArtists(); } void avoidCrashInAllAlbums() { DatabaseInterface musicDb; musicDb.allAlbums(); } void addOneTrackWithoutAlbumArtist() { DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb")); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), {}, 6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///$23")] = QUrl::fromLocalFile(QStringLiteral("album3")); musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 1); QCOMPARE(musicDb.allArtists().count(), 1); QCOMPARE(musicDb.allTracks().count(), 1); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto track = musicDb.trackFromDatabaseId(musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), 6, 1)); QCOMPARE(track.isValid(), true); QCOMPARE(track.title(), QStringLiteral("track6")); QCOMPARE(track.artist(), QStringLiteral("artist2")); QCOMPARE(track.albumName(), QStringLiteral("album3")); QCOMPARE(track.albumArtist(), QStringLiteral("artist2")); QCOMPARE(track.isValidAlbumArtist(), false); QCOMPARE(track.albumCover(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(track.trackNumber(), 6); QCOMPARE(track.discNumber(), 1); QCOMPARE(track.duration(), QTime::fromMSecsSinceStartOfDay(23)); QCOMPARE(track.resourceURI(), QUrl::fromLocalFile(QStringLiteral("/$23"))); QCOMPARE(track.rating(), 5); QCOMPARE(track.genre(), QStringLiteral("genre1")); QCOMPARE(track.composer(), QStringLiteral("composer1")); QCOMPARE(track.lyricist(), QStringLiteral("lyricist1")); QCOMPARE(track.albumId(), qulonglong(1)); auto album = musicDb.albumFromTitleAndArtist(QStringLiteral("album3"), QStringLiteral("artist2")); QCOMPARE(album.isValid(), true); QCOMPARE(album.tracksCount(), 1); QCOMPARE(album.title(), QStringLiteral("album3")); QCOMPARE(album.artist(), QStringLiteral("artist2")); QCOMPARE(album.isValidArtist(), false); QCOMPARE(album.albumArtURI(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(album.isSingleDiscAlbum(), true); } void addTwoTracksWithoutAlbumArtist() { QTemporaryFile databaseFile; databaseFile.open(); qDebug() << "addTwoTracksWithoutAlbumArtist" << databaseFile.fileName(); DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb"), databaseFile.fileName()); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto newTracks = QList(); newTracks = {{true, QStringLiteral("$19"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), {}, 6, 1, QTime::fromMSecsSinceStartOfDay(19), {QUrl::fromLocalFile(QStringLiteral("/$19"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track7"), QStringLiteral("artist3"), QStringLiteral("album3"), {}, 7, 1, QTime::fromMSecsSinceStartOfDay(20), {QUrl::fromLocalFile(QStringLiteral("/$20"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}}; auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///$23")] = QUrl::fromLocalFile(QStringLiteral("album3")); newCovers[QStringLiteral("file:///$20")] = QUrl::fromLocalFile(QStringLiteral("album3")); musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 1); QCOMPARE(musicDb.allArtists().count(), 2); QCOMPARE(musicDb.allTracks().count(), 2); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto firstTrack = musicDb.trackFromDatabaseId(musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), 6, 1)); QCOMPARE(firstTrack.isValid(), true); QCOMPARE(firstTrack.title(), QStringLiteral("track6")); QCOMPARE(firstTrack.artist(), QStringLiteral("artist2")); QCOMPARE(firstTrack.albumName(), QStringLiteral("album3")); QCOMPARE(firstTrack.albumArtist(), QStringLiteral("artist2")); QCOMPARE(firstTrack.isValidAlbumArtist(), false); QCOMPARE(firstTrack.albumCover(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(firstTrack.trackNumber(), 6); QCOMPARE(firstTrack.discNumber(), 1); QCOMPARE(firstTrack.duration(), QTime::fromMSecsSinceStartOfDay(19)); QCOMPARE(firstTrack.resourceURI(), QUrl::fromLocalFile(QStringLiteral("/$19"))); QCOMPARE(firstTrack.rating(), 5); QCOMPARE(firstTrack.genre(), QStringLiteral("genre1")); QCOMPARE(firstTrack.composer(), QStringLiteral("composer1")); QCOMPARE(firstTrack.lyricist(), QStringLiteral("lyricist1")); QCOMPARE(firstTrack.albumId(), qulonglong(2)); auto secondTrack = musicDb.trackFromDatabaseId(musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track7"), QStringLiteral("artist3"), QStringLiteral("album3"), 7, 1)); QCOMPARE(secondTrack.isValid(), true); QCOMPARE(secondTrack.title(), QStringLiteral("track7")); QCOMPARE(secondTrack.artist(), QStringLiteral("artist3")); QCOMPARE(secondTrack.albumName(), QStringLiteral("album3")); QCOMPARE(secondTrack.albumArtist(), QStringLiteral("artist3")); QCOMPARE(secondTrack.isValidAlbumArtist(), false); QCOMPARE(secondTrack.albumCover(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(secondTrack.trackNumber(), 7); QCOMPARE(secondTrack.discNumber(), 1); QCOMPARE(secondTrack.duration(), QTime::fromMSecsSinceStartOfDay(20)); QCOMPARE(secondTrack.resourceURI(), QUrl::fromLocalFile(QStringLiteral("/$20"))); QCOMPARE(secondTrack.rating(), 5); QCOMPARE(secondTrack.genre(), QStringLiteral("genre1")); QCOMPARE(secondTrack.composer(), QStringLiteral("composer1")); QCOMPARE(secondTrack.lyricist(), QStringLiteral("lyricist1")); QCOMPARE(secondTrack.albumId(), qulonglong(2)); auto album = musicDb.albumFromTitleAndArtist(QStringLiteral("album3"), QStringLiteral("artist2")); QCOMPARE(album.isValid(), true); QCOMPARE(album.tracksCount(), 2); QCOMPARE(album.title(), QStringLiteral("album3")); QCOMPARE(album.artist(), QStringLiteral("Various Artists")); QCOMPARE(album.isValidArtist(), false); QCOMPARE(album.albumArtURI(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(album.isSingleDiscAlbum(), true); } void addThreeTracksWithoutAlbumArtistButSameArtist() { DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb")); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto newTracks = QList(); newTracks = {{true, QStringLiteral("$19"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), {}, 6, 1, QTime::fromMSecsSinceStartOfDay(19), {QUrl::fromLocalFile(QStringLiteral("/$19"))}, QDateTime::fromMSecsSinceEpoch(19), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track7"), QStringLiteral("artist2"), QStringLiteral("album3"), {}, 7, 1, QTime::fromMSecsSinceStartOfDay(20), {QUrl::fromLocalFile(QStringLiteral("/$20"))}, QDateTime::fromMSecsSinceEpoch(20), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 4, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$21"), QStringLiteral("0"), QStringLiteral("track8"), QStringLiteral("artist2"), QStringLiteral("album3"), {}, 8, 1, QTime::fromMSecsSinceStartOfDay(21), {QUrl::fromLocalFile(QStringLiteral("/$21"))}, QDateTime::fromMSecsSinceEpoch(21), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 3, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}}; auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///$19")] = QUrl::fromLocalFile(QStringLiteral("album3")); newCovers[QStringLiteral("file:///$20")] = QUrl::fromLocalFile(QStringLiteral("album3")); newCovers[QStringLiteral("file:///$21")] = QUrl::fromLocalFile(QStringLiteral("album3")); musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 1); QCOMPARE(musicDb.allArtists().count(), 1); QCOMPARE(musicDb.allTracks().count(), 3); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto firstTrack = musicDb.trackFromDatabaseId(musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), 6, 1)); QCOMPARE(firstTrack.isValid(), true); QCOMPARE(firstTrack.title(), QStringLiteral("track6")); QCOMPARE(firstTrack.artist(), QStringLiteral("artist2")); QCOMPARE(firstTrack.albumName(), QStringLiteral("album3")); QCOMPARE(firstTrack.albumArtist(), QStringLiteral("artist2")); QCOMPARE(firstTrack.isValidAlbumArtist(), false); QCOMPARE(firstTrack.albumCover(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(firstTrack.trackNumber(), 6); QCOMPARE(firstTrack.discNumber(), 1); QCOMPARE(firstTrack.duration(), QTime::fromMSecsSinceStartOfDay(19)); QCOMPARE(firstTrack.resourceURI(), QUrl::fromLocalFile(QStringLiteral("/$19"))); QCOMPARE(firstTrack.rating(), 5); QCOMPARE(firstTrack.genre(), QStringLiteral("genre1")); QCOMPARE(firstTrack.composer(), QStringLiteral("composer1")); QCOMPARE(firstTrack.lyricist(), QStringLiteral("lyricist1")); QCOMPARE(firstTrack.isSingleDiscAlbum(), true); QCOMPARE(firstTrack.albumId(), qulonglong(1)); auto secondTrack = musicDb.trackFromDatabaseId(musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track7"), QStringLiteral("artist2"), QStringLiteral("album3"), 7, 1)); QCOMPARE(secondTrack.isValid(), true); QCOMPARE(secondTrack.title(), QStringLiteral("track7")); QCOMPARE(secondTrack.artist(), QStringLiteral("artist2")); QCOMPARE(secondTrack.albumName(), QStringLiteral("album3")); QCOMPARE(secondTrack.albumArtist(), QStringLiteral("artist2")); QCOMPARE(secondTrack.isValidAlbumArtist(), false); QCOMPARE(secondTrack.albumCover(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(secondTrack.trackNumber(), 7); QCOMPARE(secondTrack.discNumber(), 1); QCOMPARE(secondTrack.duration(), QTime::fromMSecsSinceStartOfDay(20)); QCOMPARE(secondTrack.resourceURI(), QUrl::fromLocalFile(QStringLiteral("/$20"))); QCOMPARE(secondTrack.rating(), 4); QCOMPARE(secondTrack.genre(), QStringLiteral("genre1")); QCOMPARE(secondTrack.composer(), QStringLiteral("composer1")); QCOMPARE(secondTrack.lyricist(), QStringLiteral("lyricist1")); QCOMPARE(secondTrack.isSingleDiscAlbum(), true); QCOMPARE(secondTrack.albumId(), qulonglong(1)); auto thirdTrack = musicDb.trackFromDatabaseId(musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track8"), QStringLiteral("artist2"), QStringLiteral("album3"), 8, 1)); QCOMPARE(thirdTrack.isValid(), true); QCOMPARE(thirdTrack.title(), QStringLiteral("track8")); QCOMPARE(thirdTrack.artist(), QStringLiteral("artist2")); QCOMPARE(thirdTrack.albumName(), QStringLiteral("album3")); QCOMPARE(thirdTrack.albumArtist(), QStringLiteral("artist2")); QCOMPARE(thirdTrack.isValidAlbumArtist(), false); QCOMPARE(thirdTrack.albumCover(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(thirdTrack.trackNumber(), 8); QCOMPARE(thirdTrack.discNumber(), 1); QCOMPARE(thirdTrack.duration(), QTime::fromMSecsSinceStartOfDay(21)); QCOMPARE(thirdTrack.resourceURI(), QUrl::fromLocalFile(QStringLiteral("/$21"))); QCOMPARE(thirdTrack.rating(), 3); QCOMPARE(thirdTrack.genre(), QStringLiteral("genre1")); QCOMPARE(thirdTrack.composer(), QStringLiteral("composer1")); QCOMPARE(thirdTrack.lyricist(), QStringLiteral("lyricist1")); QCOMPARE(thirdTrack.isSingleDiscAlbum(), true); QCOMPARE(thirdTrack.albumId(), qulonglong(1)); auto album = musicDb.albumFromTitleAndArtist(QStringLiteral("album3"), QStringLiteral("artist2")); QCOMPARE(album.isValid(), true); QCOMPARE(album.tracksCount(), 3); QCOMPARE(album.title(), QStringLiteral("album3")); QCOMPARE(album.artist(), QStringLiteral("artist2")); QCOMPARE(album.isValidArtist(), false); QCOMPARE(album.albumArtURI(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(album.isSingleDiscAlbum(), true); } void addTwoTracksWithPartialAlbumArtist() { QTemporaryFile databaseFile; databaseFile.open(); qDebug() << "addTwoTracksWithPartialAlbumArtist" << databaseFile.fileName(); DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb"), databaseFile.fileName()); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto newTracks = QList(); newTracks = {{true, QStringLiteral("$19"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), {}, 6, 1, QTime::fromMSecsSinceStartOfDay(19), {QUrl::fromLocalFile(QStringLiteral("/$19"))}, QDateTime::fromMSecsSinceEpoch(19), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track7"), QStringLiteral("artist3"), QStringLiteral("album3"), {QStringLiteral("artist4")}, 7, 1, QTime::fromMSecsSinceStartOfDay(20), {QUrl::fromLocalFile(QStringLiteral("/$20"))}, QDateTime::fromMSecsSinceEpoch(20), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}}; auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///$19")] = QUrl::fromLocalFile(QStringLiteral("album3")); newCovers[QStringLiteral("file:///$20")] = QUrl::fromLocalFile(QStringLiteral("album3")); musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 1); QCOMPARE(musicDb.allArtists().count(), 3); QCOMPARE(musicDb.allTracks().count(), 2); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 1); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto firstTrack = musicDb.trackFromDatabaseId(musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), 6, 1)); QCOMPARE(firstTrack.isValid(), true); QCOMPARE(firstTrack.title(), QStringLiteral("track6")); QCOMPARE(firstTrack.artist(), QStringLiteral("artist2")); QCOMPARE(firstTrack.albumName(), QStringLiteral("album3")); QCOMPARE(firstTrack.albumArtist(), QStringLiteral("artist4")); QCOMPARE(firstTrack.isValidAlbumArtist(), true); QCOMPARE(firstTrack.albumCover(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(firstTrack.trackNumber(), 6); QCOMPARE(firstTrack.discNumber(), 1); QCOMPARE(firstTrack.duration(), QTime::fromMSecsSinceStartOfDay(19)); QCOMPARE(firstTrack.resourceURI(), QUrl::fromLocalFile(QStringLiteral("/$19"))); QCOMPARE(firstTrack.rating(), 5); QCOMPARE(firstTrack.genre(), QStringLiteral("genre1")); QCOMPARE(firstTrack.composer(), QStringLiteral("composer1")); QCOMPARE(firstTrack.lyricist(), QStringLiteral("lyricist1")); QCOMPARE(firstTrack.isSingleDiscAlbum(), true); QCOMPARE(firstTrack.albumId(), qulonglong(2)); auto secondTrack = musicDb.trackFromDatabaseId(musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track7"), QStringLiteral("artist3"), QStringLiteral("album3"), 7, 1)); QCOMPARE(secondTrack.isValid(), true); QCOMPARE(secondTrack.title(), QStringLiteral("track7")); QCOMPARE(secondTrack.artist(), QStringLiteral("artist3")); QCOMPARE(secondTrack.albumName(), QStringLiteral("album3")); QCOMPARE(secondTrack.albumArtist(), QStringLiteral("artist4")); QCOMPARE(secondTrack.isValidAlbumArtist(), true); QCOMPARE(secondTrack.albumCover(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(secondTrack.trackNumber(), 7); QCOMPARE(secondTrack.discNumber(), 1); QCOMPARE(secondTrack.duration(), QTime::fromMSecsSinceStartOfDay(20)); QCOMPARE(secondTrack.resourceURI(), QUrl::fromLocalFile(QStringLiteral("/$20"))); QCOMPARE(secondTrack.rating(), 5); QCOMPARE(secondTrack.genre(), QStringLiteral("genre1")); QCOMPARE(secondTrack.composer(), QStringLiteral("composer1")); QCOMPARE(secondTrack.lyricist(), QStringLiteral("lyricist1")); QCOMPARE(secondTrack.isSingleDiscAlbum(), true); QCOMPARE(secondTrack.albumId(), qulonglong(2)); auto album = musicDb.albumFromTitleAndArtist(QStringLiteral("album3"), QStringLiteral("artist4")); QCOMPARE(album.isValid(), true); QCOMPARE(album.tracksCount(), 2); QCOMPARE(album.title(), QStringLiteral("album3")); QCOMPARE(album.artist(), QStringLiteral("artist4")); QCOMPARE(album.isValidArtist(), true); QCOMPARE(album.albumArtURI(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(album.isSingleDiscAlbum(), true); } void addMultipleTimeSameTracks() { QTemporaryFile databaseFile; databaseFile.open(); qDebug() << "addMultipleTimeSameTracks" << databaseFile.fileName(); DatabaseInterface musicDb; QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); musicDb.init(QStringLiteral("testDb"), databaseFile.fileName()); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); auto firstAlbum = musicDb.albumFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists")); QCOMPARE(firstAlbum.isValid(), true); QCOMPARE(firstAlbum.title(), QStringLiteral("album1")); auto firstAlbumInvalid = musicDb.albumFromTitleAndArtist(QStringLiteral("album1Invalid"), QStringLiteral("Invalid Artist")); QCOMPARE(firstAlbumInvalid.isValid(), false); } void addTwiceSameTracksWithDatabaseFile() { QTemporaryFile myTempDatabase; myTempDatabase.open(); { DatabaseInterface musicDb; QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); musicDb.init(QStringLiteral("testDb1"), myTempDatabase.fileName()); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); auto firstAlbum = musicDb.albumFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists")); QCOMPARE(firstAlbum.isValid(), true); QCOMPARE(firstAlbum.title(), QStringLiteral("album1")); auto firstAlbumInvalid = musicDb.albumFromTitleAndArtist(QStringLiteral("album1Invalid"), QStringLiteral("Invalid Artist")); QCOMPARE(firstAlbumInvalid.isValid(), false); } { DatabaseInterface musicDb; QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); musicDb.init(QStringLiteral("testDb2"), myTempDatabase.fileName()); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); auto firstAlbum = musicDb.albumFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists")); QCOMPARE(firstAlbum.isValid(), true); QCOMPARE(firstAlbum.title(), QStringLiteral("album1")); auto firstAlbumInvalid = musicDb.albumFromTitleAndArtist(QStringLiteral("album1Invalid"), QStringLiteral("Invalid Artist")); QCOMPARE(firstAlbumInvalid.isValid(), false); } } void restoreModifiedTracksWidthDatabaseFile() { QTemporaryFile myTempDatabase; myTempDatabase.open(); { DatabaseInterface musicDb; QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto allNewTracks = mNewTracks; allNewTracks.push_back({true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}); musicDb.init(QStringLiteral("testDb1"), myTempDatabase.fileName()); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); qDebug() << "restoreModifiedTracksWidthDatabaseFile" << myTempDatabase.fileName(); auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///$23")] = QUrl::fromLocalFile(QStringLiteral("album3")); musicDb.insertTracksList(allNewTracks, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 23); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto firstAlbum = musicDb.albumFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists")); QCOMPARE(firstAlbum.isValid(), true); QCOMPARE(firstAlbum.title(), QStringLiteral("album1")); auto firstAlbumInvalid = musicDb.albumFromTitleAndArtist(QStringLiteral("album1Invalid"), QStringLiteral("Invalid Artist")); QCOMPARE(firstAlbumInvalid.isValid(), false); auto fourthAlbum = musicDb.albumFromTitleAndArtist(QStringLiteral("album3"), QStringLiteral("artist2")); QCOMPARE(fourthAlbum.isValid(), true); QCOMPARE(fourthAlbum.title(), QStringLiteral("album3")); QCOMPARE(fourthAlbum.tracksCount(), 4); auto oneTrack = fourthAlbum.trackFromIndex(3); QCOMPARE(oneTrack.isValid(), true); QCOMPARE(oneTrack.rating(), 5); } { DatabaseInterface musicDb; QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto allNewTracks = mNewTracks; allNewTracks.push_back({true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 3, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}); musicDb.init(QStringLiteral("testDb2"), myTempDatabase.fileName()); qDebug() << "restoreModifiedTracksWidthDatabaseFile" << myTempDatabase.fileName(); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 23); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///$23")] = QUrl::fromLocalFile(QStringLiteral("album3")); musicDb.insertTracksList(allNewTracks, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 23); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 2); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); QCOMPARE(musicDb.allAlbums().count(), 5); auto firstAlbum = musicDb.albumFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists")); QCOMPARE(firstAlbum.isValid(), true); QCOMPARE(firstAlbum.title(), QStringLiteral("album1")); auto firstAlbumInvalid = musicDb.albumFromTitleAndArtist(QStringLiteral("album1Invalid"), QStringLiteral("Invalid Artist")); QCOMPARE(firstAlbumInvalid.isValid(), false); auto fourthAlbum = musicDb.albumFromTitleAndArtist(QStringLiteral("album3"), QStringLiteral("artist2")); QCOMPARE(fourthAlbum.isValid(), true); QCOMPARE(fourthAlbum.title(), QStringLiteral("album3")); QCOMPARE(fourthAlbum.tracksCount(), 4); auto oneTrack = fourthAlbum.trackFromIndex(3); QCOMPARE(oneTrack.isValid(), true); QCOMPARE(oneTrack.title(), QStringLiteral("track6")); QCOMPARE(oneTrack.rating(), 3); } } void simpleAccessor() { DatabaseInterface musicDb; QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); musicDb.init(QStringLiteral("testDb")); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); auto allAlbums = musicDb.allAlbums(); auto firstAlbumTitle = allAlbums[0].title(); auto firstAlbumArtist = allAlbums[0].artist(); auto firstAlbumImage = allAlbums[0].albumArtURI(); auto firstAlbumTracksCount = allAlbums[0].tracksCount(); auto firstAlbumIsSingleDiscAlbum = allAlbums[0].isSingleDiscAlbum(); QCOMPARE(firstAlbumTitle, QStringLiteral("album1")); QCOMPARE(firstAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(firstAlbumImage.isValid(), true); QCOMPARE(firstAlbumImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(firstAlbumTracksCount, 4); QCOMPARE(firstAlbumIsSingleDiscAlbum, false); auto invalidTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 2, 1); QCOMPARE(invalidTrackId, decltype(invalidTrackId)(0)); auto trackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); auto firstTrack = musicDb.trackFromDatabaseId(trackId); auto firstTrackTitle = firstTrack.title(); auto firstTrackArtist = firstTrack.artist(); auto firstTrackAlbumArtist = firstTrack.albumArtist(); auto firstTrackAlbum = firstTrack.albumName(); auto firstTrackImage = firstTrack.albumCover(); auto firstTrackDuration = firstTrack.duration(); auto firstTrackMilliSecondsDuration = firstTrack.duration().msecsSinceStartOfDay(); auto firstTrackTrackNumber = firstTrack.trackNumber(); auto firstTrackDiscNumber = firstTrack.discNumber(); auto firstTrackResource = firstTrack.resourceURI(); auto firstTrackRating = firstTrack.rating(); auto firstIsSingleDiscAlbum = firstTrack.isSingleDiscAlbum(); QCOMPARE(firstTrack.isValid(), true); QCOMPARE(firstTrackTitle, QStringLiteral("track1")); QCOMPARE(firstTrackArtist, QStringLiteral("artist1")); QCOMPARE(firstTrackAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(firstTrackAlbum, QStringLiteral("album1")); QCOMPARE(firstTrackImage.isValid(), true); QCOMPARE(firstTrackImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(firstTrackDuration, QTime::fromMSecsSinceStartOfDay(1)); QCOMPARE(firstTrackMilliSecondsDuration, 1); QCOMPARE(firstTrackTrackNumber, 1); QCOMPARE(firstTrackDiscNumber, 1); QCOMPARE(firstTrackResource.isValid(), true); QCOMPARE(firstTrackResource, QUrl::fromLocalFile(QStringLiteral("/$1"))); QCOMPARE(firstTrackRating, 1); QCOMPARE(firstIsSingleDiscAlbum, false); auto secondAlbumTitle = allAlbums[1].title(); auto secondAlbumArtist = allAlbums[1].artist(); auto secondAlbumImage = allAlbums[1].albumArtURI(); auto secondAlbumTracksCount = allAlbums[1].tracksCount(); auto secondAlbumIsSingleDiscAlbum = allAlbums[1].isSingleDiscAlbum(); QCOMPARE(secondAlbumTitle, QStringLiteral("album2")); QCOMPARE(secondAlbumArtist, QStringLiteral("artist1")); QCOMPARE(secondAlbumImage.isValid(), true); QCOMPARE(secondAlbumImage, QUrl::fromLocalFile(QStringLiteral("album2"))); QCOMPARE(secondAlbumTracksCount, 6); QCOMPARE(secondAlbumIsSingleDiscAlbum, true); } void simpleAccessorAndVariousArtistAlbum() { DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDbVariousArtistAlbum")); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); auto allAlbums = musicDb.allAlbums(); auto firstAlbumTitle = allAlbums[0].title(); auto firstAlbumArtist = allAlbums[0].artist(); auto firstAlbumImage = allAlbums[0].albumArtURI(); auto firstAlbumTracksCount = allAlbums[0].tracksCount(); auto firstAlbumIsSingleDiscAlbum = allAlbums[0].isSingleDiscAlbum(); QCOMPARE(firstAlbumTitle, QStringLiteral("album1")); QCOMPARE(firstAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(firstAlbumImage.isValid(), true); QCOMPARE(firstAlbumImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(firstAlbumTracksCount, 4); QCOMPARE(firstAlbumIsSingleDiscAlbum, false); auto invalidTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 2, 1); QCOMPARE(invalidTrackId, decltype(invalidTrackId)(0)); auto firstTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); auto firstTrack = musicDb.trackFromDatabaseId(firstTrackId); auto firstTrackTitle = firstTrack.title(); auto firstTrackArtist = firstTrack.artist(); auto firstTrackAlbumArtist = firstTrack.albumArtist(); auto firstTrackAlbum = firstTrack.albumName(); auto firstTrackImage = firstTrack.albumCover(); auto firstTrackDuration = firstTrack.duration(); auto firstTrackMilliSecondsDuration = firstTrack.duration().msecsSinceStartOfDay(); auto firstTrackTrackNumber = firstTrack.trackNumber(); auto firstTrackDiscNumber = firstTrack.discNumber(); auto firstTrackResource = firstTrack.resourceURI(); auto firstTrackRating = firstTrack.rating(); auto firstIsSingleDiscAlbum = firstTrack.isSingleDiscAlbum(); QCOMPARE(firstTrack.isValid(), true); QCOMPARE(firstTrackTitle, QStringLiteral("track1")); QCOMPARE(firstTrackArtist, QStringLiteral("artist1")); QCOMPARE(firstTrackAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(firstTrackAlbum, QStringLiteral("album1")); QCOMPARE(firstTrackImage.isValid(), true); QCOMPARE(firstTrackImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(firstTrackDuration, QTime::fromMSecsSinceStartOfDay(1)); QCOMPARE(firstTrackMilliSecondsDuration, 1); QCOMPARE(firstTrackTrackNumber, 1); QCOMPARE(firstTrackDiscNumber, 1); QCOMPARE(firstTrackResource.isValid(), true); QCOMPARE(firstTrackResource, QUrl::fromLocalFile(QStringLiteral("/$1"))); QCOMPARE(firstTrackRating, 1); QCOMPARE(firstIsSingleDiscAlbum, false); auto secondTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album1"), 2, 2); auto secondTrack = musicDb.trackFromDatabaseId(secondTrackId); auto secondTrackTitle = secondTrack.title(); auto secondTrackArtist = secondTrack.artist(); auto secondTrackAlbumArtist = secondTrack.albumArtist(); auto secondTrackAlbum = secondTrack.albumName(); auto seconfTrackImage = secondTrack.albumCover(); auto secondTrackDuration = secondTrack.duration(); auto secondTrackMilliSecondsDuration = secondTrack.duration().msecsSinceStartOfDay(); auto secondTrackTrackNumber = secondTrack.trackNumber(); auto secondTrackDiscNumber = secondTrack.discNumber(); auto secondTrackResource = secondTrack.resourceURI(); auto secondTrackRating = secondTrack.rating(); auto secondIsSingleDiscAlbum = secondTrack.isSingleDiscAlbum(); QCOMPARE(secondTrack.isValid(), true); QCOMPARE(secondTrackTitle, QStringLiteral("track2")); QCOMPARE(secondTrackArtist, QStringLiteral("artist2")); QCOMPARE(secondTrackAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(secondTrackAlbum, QStringLiteral("album1")); QCOMPARE(seconfTrackImage.isValid(), true); QCOMPARE(seconfTrackImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(secondTrackDuration, QTime::fromMSecsSinceStartOfDay(2)); QCOMPARE(secondTrackMilliSecondsDuration, 2); QCOMPARE(secondTrackTrackNumber, 2); QCOMPARE(secondTrackDiscNumber, 2); QCOMPARE(secondTrackResource.isValid(), true); QCOMPARE(secondTrackResource, QUrl::fromLocalFile(QStringLiteral("/$2"))); QCOMPARE(secondTrackRating, 2); QCOMPARE(secondIsSingleDiscAlbum, false); auto thirdTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3); auto thirdTrack = musicDb.trackFromDatabaseId(thirdTrackId); auto thirdTrackTitle = thirdTrack.title(); auto thirdTrackArtist = thirdTrack.artist(); auto thirdTrackAlbumArtist = thirdTrack.albumArtist(); auto thirdTrackAlbum = thirdTrack.albumName(); auto thirdTrackImage = thirdTrack.albumCover(); auto thirdTrackDuration = thirdTrack.duration(); auto thirdTrackMilliSecondsDuration = thirdTrack.duration().msecsSinceStartOfDay(); auto thirdTrackTrackNumber = thirdTrack.trackNumber(); auto thirdTrackDiscNumber = thirdTrack.discNumber(); auto thirdTrackResource = thirdTrack.resourceURI(); auto thirdTrackRating = thirdTrack.rating(); auto thirdIsSingleDiscAlbum = thirdTrack.isSingleDiscAlbum(); QCOMPARE(thirdTrack.isValid(), true); QCOMPARE(thirdTrackTitle, QStringLiteral("track3")); QCOMPARE(thirdTrackArtist, QStringLiteral("artist3")); QCOMPARE(thirdTrackAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(thirdTrackAlbum, QStringLiteral("album1")); QCOMPARE(thirdTrackImage.isValid(), true); QCOMPARE(thirdTrackImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(thirdTrackDuration, QTime::fromMSecsSinceStartOfDay(3)); QCOMPARE(thirdTrackMilliSecondsDuration, 3); QCOMPARE(thirdTrackTrackNumber, 3); QCOMPARE(thirdTrackDiscNumber, 3); QCOMPARE(thirdTrackResource.isValid(), true); QCOMPARE(thirdTrackResource, QUrl::fromLocalFile(QStringLiteral("/$3"))); QCOMPARE(thirdTrackRating, 3); QCOMPARE(thirdIsSingleDiscAlbum, false); auto fourthTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), 4, 4); auto fourthTrack = musicDb.trackFromDatabaseId(fourthTrackId); auto fourthTrackTitle = fourthTrack.title(); auto fourthTrackArtist = fourthTrack.artist(); auto fourthTrackAlbumArtist = fourthTrack.albumArtist(); auto fourthTrackAlbum = fourthTrack.albumName(); auto fourthTrackImage = fourthTrack.albumCover(); auto fourthTrackDuration = fourthTrack.duration(); auto fourthTrackMilliSecondsDuration = fourthTrack.duration().msecsSinceStartOfDay(); auto fourthTrackTrackNumber = fourthTrack.trackNumber(); auto fourthTrackDiscNumber = fourthTrack.discNumber(); auto fourthTrackResource = fourthTrack.resourceURI(); auto fourthTrackRating = thirdTrack.rating(); auto fourthIsSingleDiscAlbum = fourthTrack.isSingleDiscAlbum(); QCOMPARE(fourthTrack.isValid(), true); QCOMPARE(fourthTrackTitle, QStringLiteral("track4")); QCOMPARE(fourthTrackArtist, QStringLiteral("artist4")); QCOMPARE(fourthTrackAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(fourthTrackAlbum, QStringLiteral("album1")); QCOMPARE(fourthTrackImage.isValid(), true); QCOMPARE(fourthTrackImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(fourthTrackDuration, QTime::fromMSecsSinceStartOfDay(4)); QCOMPARE(fourthTrackMilliSecondsDuration, 4); QCOMPARE(fourthTrackTrackNumber, 4); QCOMPARE(fourthTrackDiscNumber, 4); QCOMPARE(fourthTrackResource.isValid(), true); QCOMPARE(fourthTrackResource, QUrl::fromLocalFile(QStringLiteral("/$4"))); QCOMPARE(fourthTrackRating, 3); QCOMPARE(fourthIsSingleDiscAlbum, false); auto secondAlbumTitle = allAlbums[1].title(); auto secondAlbumArtist = allAlbums[1].artist(); auto secondAlbumImage = allAlbums[1].albumArtURI(); auto secondAlbumTracksCount = allAlbums[1].tracksCount(); auto secondAlbumIsSingleDiscAlbum = allAlbums[1].isSingleDiscAlbum(); QCOMPARE(secondAlbumTitle, QStringLiteral("album2")); QCOMPARE(secondAlbumArtist, QStringLiteral("artist1")); QCOMPARE(secondAlbumImage.isValid(), true); QCOMPARE(secondAlbumImage, QUrl::fromLocalFile(QStringLiteral("album2"))); QCOMPARE(secondAlbumTracksCount, 6); QCOMPARE(secondAlbumIsSingleDiscAlbum, true); } void fetchAllTracksFromSource() { DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDbVariousArtistAlbum")); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist9"), QStringLiteral("album3"), QStringLiteral("artist2"), 6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); auto newFiles2 = QList(); for (const auto &oneTrack : newTracks) { newFiles2.push_back(oneTrack.resourceURI()); } auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///$23")] = QUrl::fromLocalFile(QStringLiteral("image$19")); musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest2")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 8); QCOMPARE(musicDb.allTracks().count(), 23); QCOMPARE(musicDbArtistAddedSpy.count(), 2); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 2); auto allTracks = musicDb.allTracksFromSource(QStringLiteral("autoTest")); auto allTracks2 = musicDb.allTracksFromSource(QStringLiteral("autoTest2")); QCOMPARE(allTracks.count(), 22); QCOMPARE(allTracks2.count(), 1); } void simpleAccessorAndVariousArtistAlbumWithFile() { QTemporaryFile myDatabaseFile; myDatabaseFile.open(); { DatabaseInterface musicDb; QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); musicDb.init(QStringLiteral("testDbVariousArtistAlbum1"), myDatabaseFile.fileName()); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); auto allAlbums = musicDb.allAlbums(); auto firstAlbumTitle = allAlbums[0].title(); auto firstAlbumArtist = allAlbums[0].artist(); auto firstAlbumImage = allAlbums[0].albumArtURI(); auto firstAlbumTracksCount = allAlbums[0].tracksCount(); auto firstAlbumIsSingleDiscAlbum = allAlbums[0].isSingleDiscAlbum(); QCOMPARE(firstAlbumTitle, QStringLiteral("album1")); QCOMPARE(firstAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(firstAlbumImage.isValid(), true); QCOMPARE(firstAlbumImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(firstAlbumTracksCount, 4); QCOMPARE(firstAlbumIsSingleDiscAlbum, false); auto invalidTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 2, 1); QCOMPARE(invalidTrackId, decltype(invalidTrackId)(0)); auto firstTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); auto firstTrack = musicDb.trackFromDatabaseId(firstTrackId); auto firstTrackTitle = firstTrack.title(); auto firstTrackArtist = firstTrack.artist(); auto firstTrackAlbumArtist = firstTrack.albumArtist(); auto firstTrackAlbum = firstTrack.albumName(); auto firstTrackImage = firstTrack.albumCover(); auto firstTrackDuration = firstTrack.duration(); auto firstTrackMilliSecondsDuration = firstTrack.duration().msecsSinceStartOfDay(); auto firstTrackTrackNumber = firstTrack.trackNumber(); auto firstTrackDiscNumber = firstTrack.discNumber(); auto firstTrackResource = firstTrack.resourceURI(); auto firstTrackRating = firstTrack.rating(); auto firstIsSingleDiscAlbum = firstTrack.isSingleDiscAlbum(); QCOMPARE(firstTrack.isValid(), true); QCOMPARE(firstTrackTitle, QStringLiteral("track1")); QCOMPARE(firstTrackArtist, QStringLiteral("artist1")); QCOMPARE(firstTrackAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(firstTrackAlbum, QStringLiteral("album1")); QCOMPARE(firstTrackImage.isValid(), true); QCOMPARE(firstTrackImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(firstTrackDuration, QTime::fromMSecsSinceStartOfDay(1)); QCOMPARE(firstTrackMilliSecondsDuration, 1); QCOMPARE(firstTrackTrackNumber, 1); QCOMPARE(firstTrackDiscNumber, 1); QCOMPARE(firstTrackResource.isValid(), true); QCOMPARE(firstTrackResource, QUrl::fromLocalFile(QStringLiteral("/$1"))); QCOMPARE(firstTrackRating, 1); QCOMPARE(firstIsSingleDiscAlbum, false); auto secondTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album1"), 2, 2); auto secondTrack = musicDb.trackFromDatabaseId(secondTrackId); auto secondTrackTitle = secondTrack.title(); auto secondTrackArtist = secondTrack.artist(); auto secondTrackAlbumArtist = secondTrack.albumArtist(); auto secondTrackAlbum = secondTrack.albumName(); auto seconfTrackImage = secondTrack.albumCover(); auto secondTrackDuration = secondTrack.duration(); auto secondTrackMilliSecondsDuration = secondTrack.duration().msecsSinceStartOfDay(); auto secondTrackTrackNumber = secondTrack.trackNumber(); auto secondTrackDiscNumber = secondTrack.discNumber(); auto secondTrackResource = secondTrack.resourceURI(); auto secondTrackRating = secondTrack.rating(); auto secondIsSingleDiscAlbum = secondTrack.isSingleDiscAlbum(); QCOMPARE(secondTrack.isValid(), true); QCOMPARE(secondTrackTitle, QStringLiteral("track2")); QCOMPARE(secondTrackArtist, QStringLiteral("artist2")); QCOMPARE(secondTrackAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(secondTrackAlbum, QStringLiteral("album1")); QCOMPARE(seconfTrackImage.isValid(), true); QCOMPARE(seconfTrackImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(secondTrackDuration, QTime::fromMSecsSinceStartOfDay(2)); QCOMPARE(secondTrackMilliSecondsDuration, 2); QCOMPARE(secondTrackTrackNumber, 2); QCOMPARE(secondTrackDiscNumber, 2); QCOMPARE(secondTrackResource.isValid(), true); QCOMPARE(secondTrackResource, QUrl::fromLocalFile(QStringLiteral("/$2"))); QCOMPARE(secondTrackRating, 2); QCOMPARE(secondIsSingleDiscAlbum, false); auto thirdTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3); auto thirdTrack = musicDb.trackFromDatabaseId(thirdTrackId); auto thirdTrackTitle = thirdTrack.title(); auto thirdTrackArtist = thirdTrack.artist(); auto thirdTrackAlbumArtist = thirdTrack.albumArtist(); auto thirdTrackAlbum = thirdTrack.albumName(); auto thirdTrackImage = thirdTrack.albumCover(); auto thirdTrackDuration = thirdTrack.duration(); auto thirdTrackMilliSecondsDuration = thirdTrack.duration().msecsSinceStartOfDay(); auto thirdTrackTrackNumber = thirdTrack.trackNumber(); auto thirdTrackDiscNumber = thirdTrack.discNumber(); auto thirdTrackResource = thirdTrack.resourceURI(); auto thirdTrackRating = thirdTrack.rating(); auto thirdIsSingleDiscAlbum = thirdTrack.isSingleDiscAlbum(); QCOMPARE(thirdTrack.isValid(), true); QCOMPARE(thirdTrackTitle, QStringLiteral("track3")); QCOMPARE(thirdTrackArtist, QStringLiteral("artist3")); QCOMPARE(thirdTrackAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(thirdTrackAlbum, QStringLiteral("album1")); QCOMPARE(thirdTrackImage.isValid(), true); QCOMPARE(thirdTrackImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(thirdTrackDuration, QTime::fromMSecsSinceStartOfDay(3)); QCOMPARE(thirdTrackMilliSecondsDuration, 3); QCOMPARE(thirdTrackTrackNumber, 3); QCOMPARE(thirdTrackDiscNumber, 3); QCOMPARE(thirdTrackResource.isValid(), true); QCOMPARE(thirdTrackResource, QUrl::fromLocalFile(QStringLiteral("/$3"))); QCOMPARE(thirdTrackRating, 3); QCOMPARE(thirdIsSingleDiscAlbum, false); auto fourthTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), 4, 4); auto fourthTrack = musicDb.trackFromDatabaseId(fourthTrackId); auto fourthTrackTitle = fourthTrack.title(); auto fourthTrackArtist = fourthTrack.artist(); auto fourthTrackAlbumArtist = fourthTrack.albumArtist(); auto fourthTrackAlbum = fourthTrack.albumName(); auto fourthTrackImage = fourthTrack.albumCover(); auto fourthTrackDuration = fourthTrack.duration(); auto fourthTrackMilliSecondsDuration = fourthTrack.duration().msecsSinceStartOfDay(); auto fourthTrackTrackNumber = fourthTrack.trackNumber(); auto fourthTrackDiscNumber = fourthTrack.discNumber(); auto fourthTrackResource = fourthTrack.resourceURI(); auto fourthTrackRating = thirdTrack.rating(); auto fourthIsSingleDiscAlbum = fourthTrack.isSingleDiscAlbum(); QCOMPARE(fourthTrack.isValid(), true); QCOMPARE(fourthTrackTitle, QStringLiteral("track4")); QCOMPARE(fourthTrackArtist, QStringLiteral("artist4")); QCOMPARE(fourthTrackAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(fourthTrackAlbum, QStringLiteral("album1")); QCOMPARE(fourthTrackImage.isValid(), true); QCOMPARE(fourthTrackImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(fourthTrackDuration, QTime::fromMSecsSinceStartOfDay(4)); QCOMPARE(fourthTrackMilliSecondsDuration, 4); QCOMPARE(fourthTrackTrackNumber, 4); QCOMPARE(fourthTrackDiscNumber, 4); QCOMPARE(fourthTrackResource.isValid(), true); QCOMPARE(fourthTrackResource, QUrl::fromLocalFile(QStringLiteral("/$4"))); QCOMPARE(fourthTrackRating, 3); QCOMPARE(fourthIsSingleDiscAlbum, false); auto secondAlbumTitle = allAlbums[1].title(); auto secondAlbumArtist = allAlbums[1].artist(); auto secondAlbumImage = allAlbums[1].albumArtURI(); auto secondAlbumTracksCount = allAlbums[1].tracksCount(); auto secondAlbumIsSingleDiscAlbum = allAlbums[1].isSingleDiscAlbum(); QCOMPARE(secondAlbumTitle, QStringLiteral("album2")); QCOMPARE(secondAlbumArtist, QStringLiteral("artist1")); QCOMPARE(secondAlbumImage.isValid(), true); QCOMPARE(secondAlbumImage, QUrl::fromLocalFile(QStringLiteral("album2"))); QCOMPARE(secondAlbumTracksCount, 6); QCOMPARE(secondAlbumIsSingleDiscAlbum, true); } { DatabaseInterface musicDb; QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); musicDb.init(QStringLiteral("testDbVariousArtistAlbum2"), myDatabaseFile.fileName()); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); auto allAlbums = musicDb.allAlbums(); auto firstAlbumTitle = allAlbums[0].title(); auto firstAlbumArtist = allAlbums[0].artist(); auto firstAlbumImage = allAlbums[0].albumArtURI(); auto firstAlbumTracksCount = allAlbums[0].tracksCount(); auto firstAlbumIsSingleDiscAlbum = allAlbums[0].isSingleDiscAlbum(); QCOMPARE(firstAlbumTitle, QStringLiteral("album1")); QCOMPARE(firstAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(firstAlbumImage.isValid(), true); QCOMPARE(firstAlbumImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(firstAlbumTracksCount, 4); QCOMPARE(firstAlbumIsSingleDiscAlbum, false); auto invalidTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 2, 1); QCOMPARE(invalidTrackId, decltype(invalidTrackId)(0)); auto firstTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); auto firstTrack = musicDb.trackFromDatabaseId(firstTrackId); auto firstTrackTitle = firstTrack.title(); auto firstTrackArtist = firstTrack.artist(); auto firstTrackAlbumArtist = firstTrack.albumArtist(); auto firstTrackAlbum = firstTrack.albumName(); auto firstTrackImage = firstTrack.albumCover(); auto firstTrackDuration = firstTrack.duration(); auto firstTrackMilliSecondsDuration = firstTrack.duration().msecsSinceStartOfDay(); auto firstTrackTrackNumber = firstTrack.trackNumber(); auto firstTrackDiscNumber = firstTrack.discNumber(); auto firstTrackResource = firstTrack.resourceURI(); auto firstTrackRating = firstTrack.rating(); auto firstIsSingleDiscAlbum = firstTrack.isSingleDiscAlbum(); QCOMPARE(firstTrack.isValid(), true); QCOMPARE(firstTrackTitle, QStringLiteral("track1")); QCOMPARE(firstTrackArtist, QStringLiteral("artist1")); QCOMPARE(firstTrackAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(firstTrackAlbum, QStringLiteral("album1")); QCOMPARE(firstTrackImage.isValid(), true); QCOMPARE(firstTrackImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(firstTrackDuration, QTime::fromMSecsSinceStartOfDay(1)); QCOMPARE(firstTrackMilliSecondsDuration, 1); QCOMPARE(firstTrackTrackNumber, 1); QCOMPARE(firstTrackDiscNumber, 1); QCOMPARE(firstTrackResource.isValid(), true); QCOMPARE(firstTrackResource, QUrl::fromLocalFile(QStringLiteral("/$1"))); QCOMPARE(firstTrackRating, 1); QCOMPARE(firstIsSingleDiscAlbum, false); auto secondTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album1"), 2, 2); auto secondTrack = musicDb.trackFromDatabaseId(secondTrackId); auto secondTrackTitle = secondTrack.title(); auto secondTrackArtist = secondTrack.artist(); auto secondTrackAlbumArtist = secondTrack.albumArtist(); auto secondTrackAlbum = secondTrack.albumName(); auto seconfTrackImage = secondTrack.albumCover(); auto secondTrackDuration = secondTrack.duration(); auto secondTrackMilliSecondsDuration = secondTrack.duration().msecsSinceStartOfDay(); auto secondTrackTrackNumber = secondTrack.trackNumber(); auto secondTrackDiscNumber = secondTrack.discNumber(); auto secondTrackResource = secondTrack.resourceURI(); auto secondTrackRating = secondTrack.rating(); auto secondIsSingleDiscAlbum = secondTrack.isSingleDiscAlbum(); QCOMPARE(secondTrack.isValid(), true); QCOMPARE(secondTrackTitle, QStringLiteral("track2")); QCOMPARE(secondTrackArtist, QStringLiteral("artist2")); QCOMPARE(secondTrackAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(secondTrackAlbum, QStringLiteral("album1")); QCOMPARE(seconfTrackImage.isValid(), true); QCOMPARE(seconfTrackImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(secondTrackDuration, QTime::fromMSecsSinceStartOfDay(2)); QCOMPARE(secondTrackMilliSecondsDuration, 2); QCOMPARE(secondTrackTrackNumber, 2); QCOMPARE(secondTrackDiscNumber, 2); QCOMPARE(secondTrackResource.isValid(), true); QCOMPARE(secondTrackResource, QUrl::fromLocalFile(QStringLiteral("/$2"))); QCOMPARE(secondTrackRating, 2); QCOMPARE(secondIsSingleDiscAlbum, false); auto thirdTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3); auto thirdTrack = musicDb.trackFromDatabaseId(thirdTrackId); auto thirdTrackTitle = thirdTrack.title(); auto thirdTrackArtist = thirdTrack.artist(); auto thirdTrackAlbumArtist = thirdTrack.albumArtist(); auto thirdTrackAlbum = thirdTrack.albumName(); auto thirdTrackImage = thirdTrack.albumCover(); auto thirdTrackDuration = thirdTrack.duration(); auto thirdTrackMilliSecondsDuration = thirdTrack.duration().msecsSinceStartOfDay(); auto thirdTrackTrackNumber = thirdTrack.trackNumber(); auto thirdTrackDiscNumber = thirdTrack.discNumber(); auto thirdTrackResource = thirdTrack.resourceURI(); auto thirdTrackRating = thirdTrack.rating(); auto thirdIsSingleDiscAlbum = thirdTrack.isSingleDiscAlbum(); QCOMPARE(thirdTrack.isValid(), true); QCOMPARE(thirdTrackTitle, QStringLiteral("track3")); QCOMPARE(thirdTrackArtist, QStringLiteral("artist3")); QCOMPARE(thirdTrackAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(thirdTrackAlbum, QStringLiteral("album1")); QCOMPARE(thirdTrackImage.isValid(), true); QCOMPARE(thirdTrackImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(thirdTrackDuration, QTime::fromMSecsSinceStartOfDay(3)); QCOMPARE(thirdTrackMilliSecondsDuration, 3); QCOMPARE(thirdTrackTrackNumber, 3); QCOMPARE(thirdTrackDiscNumber, 3); QCOMPARE(thirdTrackResource.isValid(), true); QCOMPARE(thirdTrackResource, QUrl::fromLocalFile(QStringLiteral("/$3"))); QCOMPARE(thirdTrackRating, 3); QCOMPARE(thirdIsSingleDiscAlbum, false); auto fourthTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), 4, 4); auto fourthTrack = musicDb.trackFromDatabaseId(fourthTrackId); auto fourthTrackTitle = fourthTrack.title(); auto fourthTrackArtist = fourthTrack.artist(); auto fourthTrackAlbumArtist = fourthTrack.albumArtist(); auto fourthTrackAlbum = fourthTrack.albumName(); auto fourthTrackImage = fourthTrack.albumCover(); auto fourthTrackDuration = fourthTrack.duration(); auto fourthTrackMilliSecondsDuration = fourthTrack.duration().msecsSinceStartOfDay(); auto fourthTrackTrackNumber = fourthTrack.trackNumber(); auto fourthTrackDiscNumber = fourthTrack.discNumber(); auto fourthTrackResource = fourthTrack.resourceURI(); auto fourthTrackRating = thirdTrack.rating(); auto fourthIsSingleDiscAlbum = fourthTrack.isSingleDiscAlbum(); QCOMPARE(fourthTrack.isValid(), true); QCOMPARE(fourthTrackTitle, QStringLiteral("track4")); QCOMPARE(fourthTrackArtist, QStringLiteral("artist4")); QCOMPARE(fourthTrackAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(fourthTrackAlbum, QStringLiteral("album1")); QCOMPARE(fourthTrackImage.isValid(), true); QCOMPARE(fourthTrackImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(fourthTrackDuration, QTime::fromMSecsSinceStartOfDay(4)); QCOMPARE(fourthTrackMilliSecondsDuration, 4); QCOMPARE(fourthTrackTrackNumber, 4); QCOMPARE(fourthTrackDiscNumber, 4); QCOMPARE(fourthTrackResource.isValid(), true); QCOMPARE(fourthTrackResource, QUrl::fromLocalFile(QStringLiteral("/$4"))); QCOMPARE(fourthTrackRating, 3); QCOMPARE(fourthIsSingleDiscAlbum, false); auto secondAlbumTitle = allAlbums[1].title(); auto secondAlbumArtist = allAlbums[1].artist(); auto secondAlbumImage = allAlbums[1].albumArtURI(); auto secondAlbumTracksCount = allAlbums[1].tracksCount(); auto secondAlbumIsSingleDiscAlbum = allAlbums[1].isSingleDiscAlbum(); QCOMPARE(secondAlbumTitle, QStringLiteral("album2")); QCOMPARE(secondAlbumArtist, QStringLiteral("artist1")); QCOMPARE(secondAlbumImage.isValid(), true); QCOMPARE(secondAlbumImage, QUrl::fromLocalFile(QStringLiteral("album2"))); QCOMPARE(secondAlbumTracksCount, 6); QCOMPARE(secondAlbumIsSingleDiscAlbum, true); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist8"), QStringLiteral("album3"), QStringLiteral("artist2"), 6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); auto newFiles2 = QList(); for (const auto &oneTrack : newTracks) { newFiles2.push_back(oneTrack.resourceURI()); } auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///$23")] = QUrl::fromLocalFile(QStringLiteral("image$19")); musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 8); QCOMPARE(musicDb.allTracks().count(), 23); QCOMPARE(musicDbArtistAddedSpy.count(), 2); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 2); } } void testTracksFromAuthor() { DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDbVariousArtistAlbum")); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); auto allTracks = musicDb.tracksFromAuthor(QStringLiteral("artist1")); QCOMPARE(allTracks.size(), 6); QCOMPARE(allTracks[0].albumArtist(), QStringLiteral("Various Artists")); QCOMPARE(allTracks[1].albumArtist(), QStringLiteral("artist1")); QCOMPARE(allTracks[2].albumArtist(), QStringLiteral("artist1")); QCOMPARE(allTracks[3].albumArtist(), QStringLiteral("artist1")); QCOMPARE(allTracks[4].albumArtist(), QStringLiteral("artist1")); QCOMPARE(allTracks[5].albumArtist(), QStringLiteral("artist1")); } void removeOneTrack() { QTemporaryFile databaseFile; databaseFile.open(); qDebug() << "removeOneTrack" << databaseFile.fileName(); DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb"), databaseFile.fileName()); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto allAlbums = musicDb.allAlbums(); auto firstAlbumTitle = allAlbums[0].title(); auto firstAlbumArtist = allAlbums[0].artist(); auto firstAlbumImage = allAlbums[0].albumArtURI(); auto firstAlbumTracksCount = allAlbums[0].tracksCount(); auto firstAlbumIsSingleDiscAlbum = allAlbums[0].isSingleDiscAlbum(); QCOMPARE(firstAlbumTitle, QStringLiteral("album1")); QCOMPARE(firstAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(firstAlbumImage.isValid(), true); QCOMPARE(firstAlbumImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(firstAlbumTracksCount, 4); QCOMPARE(firstAlbumIsSingleDiscAlbum, false); auto trackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); QVERIFY2(trackId != 0, "trackId should be different from 0"); auto firstTrack = musicDb.trackFromDatabaseId(trackId); QCOMPARE(firstTrack.isValid(), true); musicDb.removeTracksList({firstTrack.resourceURI()}); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 21); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 1); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 1); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto allAlbumsV2 = musicDb.allAlbums(); const auto &firstAlbum = allAlbumsV2[0]; QCOMPARE(musicDb.allAlbums().isEmpty(), false); QCOMPARE(firstAlbum.isValid(), true); auto firstAlbumTitleV2 = firstAlbum.title(); auto firstAlbumArtistV2 = firstAlbum.artist(); auto firstAlbumImageV2 = firstAlbum.albumArtURI(); auto firstAlbumTracksCountV2 = firstAlbum.tracksCount(); auto firstAlbumIsSingleDiscAlbumV2 = firstAlbum.isSingleDiscAlbum(); QCOMPARE(firstAlbumTitleV2, QStringLiteral("album1")); QCOMPARE(firstAlbumArtistV2, QStringLiteral("Various Artists")); QCOMPARE(firstAlbumImageV2.isValid(), true); QCOMPARE(firstAlbumImageV2, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(firstAlbumTracksCountV2, 3); QCOMPARE(firstAlbumIsSingleDiscAlbumV2, false); auto removedTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); QCOMPARE(removedTrackId, qulonglong(0)); } void removeOneTrackAndModifyIt() { QTemporaryFile databaseFile; databaseFile.open(); qDebug() << "removeOneTrackAndModifyIt" << databaseFile.fileName(); DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb"), databaseFile.fileName()); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto allAlbums = musicDb.allAlbums(); auto firstAlbumTitle = allAlbums[0].title(); auto firstAlbumArtist = allAlbums[0].artist(); auto firstAlbumImage = allAlbums[0].albumArtURI(); auto firstAlbumTracksCount = allAlbums[0].tracksCount(); auto firstAlbumIsSingleDiscAlbum = allAlbums[0].isSingleDiscAlbum(); QCOMPARE(firstAlbumTitle, QStringLiteral("album1")); QCOMPARE(firstAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(firstAlbumImage.isValid(), true); QCOMPARE(firstAlbumImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(firstAlbumTracksCount, 4); QCOMPARE(firstAlbumIsSingleDiscAlbum, false); auto trackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); QCOMPARE(trackId != 0, true); auto firstTrack = musicDb.trackFromDatabaseId(trackId); QCOMPARE(firstTrack.isValid(), true); musicDb.removeTracksList({firstTrack.resourceURI()}); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 21); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 1); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 1); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto allAlbumsV2 = musicDb.allAlbums(); const auto &firstAlbum = allAlbumsV2[0]; QCOMPARE(musicDb.allAlbums().isEmpty(), false); QCOMPARE(firstAlbum.isValid(), true); auto firstAlbumTitleV2 = firstAlbum.title(); auto firstAlbumArtistV2 = firstAlbum.artist(); auto firstAlbumImageV2 = firstAlbum.albumArtURI(); auto firstAlbumTracksCountV2 = firstAlbum.tracksCount(); auto firstAlbumIsSingleDiscAlbumV2 = firstAlbum.isSingleDiscAlbum(); QCOMPARE(firstAlbumTitleV2, QStringLiteral("album1")); QCOMPARE(firstAlbumArtistV2, QStringLiteral("Various Artists")); QCOMPARE(firstAlbumImageV2.isValid(), true); QCOMPARE(firstAlbumImageV2, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(firstAlbumTracksCountV2, 3); QCOMPARE(firstAlbumIsSingleDiscAlbumV2, false); auto removedTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); QCOMPARE(removedTrackId, qulonglong(0)); firstTrack.setDatabaseId(0); musicDb.modifyTracksList({firstTrack}, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 2); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 1); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 2); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto allAlbums3 = musicDb.allAlbums(); auto firstAlbumTitle3 = allAlbums3[0].title(); auto firstAlbumArtist3 = allAlbums3[0].artist(); auto firstAlbumImage3 = allAlbums3[0].albumArtURI(); auto firstAlbumTracksCount3 = allAlbums3[0].tracksCount(); auto firstAlbumIsSingleDiscAlbum3 = allAlbums3[0].isSingleDiscAlbum(); QCOMPARE(firstAlbumTitle3, QStringLiteral("album1")); QCOMPARE(firstAlbumArtist3, QStringLiteral("Various Artists")); QCOMPARE(firstAlbumImage3.isValid(), true); QCOMPARE(firstAlbumImage3, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(firstAlbumTracksCount3, 4); QCOMPARE(firstAlbumIsSingleDiscAlbum3, false); auto trackId3 = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); QCOMPARE(trackId3 != 0, true); } void removeOneAlbum() { QTemporaryFile databaseFile; databaseFile.open(); qDebug() << "removeOneAlbum" << databaseFile.fileName(); DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb"), databaseFile.fileName()); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto allAlbums = musicDb.allAlbums(); auto firstAlbumTitle = allAlbums[0].title(); auto firstAlbumArtist = allAlbums[0].artist(); auto firstAlbumImage = allAlbums[0].albumArtURI(); auto firstAlbumTracksCount = allAlbums[0].tracksCount(); auto firstAlbumIsSingleDiscAlbum = allAlbums[0].isSingleDiscAlbum(); QCOMPARE(firstAlbumTitle, QStringLiteral("album1")); QCOMPARE(firstAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(firstAlbumImage.isValid(), true); QCOMPARE(firstAlbumImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(firstAlbumTracksCount, 4); QCOMPARE(firstAlbumIsSingleDiscAlbum, false); auto firstTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1); auto firstTrack = musicDb.trackFromDatabaseId(firstTrackId); auto secondTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), 2, 1); auto secondTrack = musicDb.trackFromDatabaseId(secondTrackId); auto thirdTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), 3, 1); auto thirdTrack = musicDb.trackFromDatabaseId(thirdTrackId); auto fourthTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track4"), QStringLiteral("artist1"), QStringLiteral("album2"), 4, 1); auto fourthTrack = musicDb.trackFromDatabaseId(fourthTrackId); auto fithTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track5"), QStringLiteral("artist1"), QStringLiteral("album2"), 5, 1); auto fithTrack = musicDb.trackFromDatabaseId(fithTrackId); auto sixthTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist1 and artist2"), QStringLiteral("album2"), 6, 1); auto sixthTrack = musicDb.trackFromDatabaseId(sixthTrackId); musicDb.removeTracksList({firstTrack.resourceURI(), secondTrack.resourceURI(), thirdTrack.resourceURI(), fourthTrack.resourceURI(), fithTrack.resourceURI(), sixthTrack.resourceURI()}); QCOMPARE(musicDb.allAlbums().count(), 4); QCOMPARE(musicDb.allArtists().count(), 6); QCOMPARE(musicDb.allTracks().count(), 16); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 1); QCOMPARE(musicDbAlbumRemovedSpy.count(), 1); QCOMPARE(musicDbTrackRemovedSpy.count(), 6); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto removedAlbum = musicDb.albumFromTitleAndArtist(QStringLiteral("album2"), QStringLiteral("Invalid Artist")); QCOMPARE(removedAlbum.isValid(), false); } void removeOneArtist() { DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb")); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto allAlbums = musicDb.allAlbums(); auto firstAlbumTitle = allAlbums[0].title(); auto firstAlbumArtist = allAlbums[0].artist(); auto firstAlbumImage = allAlbums[0].albumArtURI(); auto firstAlbumTracksCount = allAlbums[0].tracksCount(); auto firstAlbumIsSingleDiscAlbum = allAlbums[0].isSingleDiscAlbum(); QCOMPARE(firstAlbumTitle, QStringLiteral("album1")); QCOMPARE(firstAlbumArtist, QStringLiteral("Various Artists")); QCOMPARE(firstAlbumImage.isValid(), true); QCOMPARE(firstAlbumImage, QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(firstAlbumTracksCount, 4); QCOMPARE(firstAlbumIsSingleDiscAlbum, false); auto trackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3); auto track = musicDb.trackFromDatabaseId(trackId); musicDb.removeTracksList({track.resourceURI()}); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 6); QCOMPARE(musicDb.allTracks().count(), 21); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 1); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 1); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 1); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); } void addOneTrack() { DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb")); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), QUrl::fromLocalFile(QStringLiteral("album3")), 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///$23")] = QUrl::fromLocalFile(QStringLiteral("album3")); musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 23); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 2); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 1); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); } void addTwoTracksSameAlbumSameTitle() { QTemporaryFile databaseFile; databaseFile.open(); qDebug() << "addTwoTracksSameAlbumSameTitle" << databaseFile.fileName(); DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb"), databaseFile.fileName()); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///$23")] = QUrl::fromLocalFile(QStringLiteral("album3")); musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 1); QCOMPARE(musicDb.allArtists().count(), 1); QCOMPARE(musicDb.allTracks().count(), 1); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto firstTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), 6, 1); auto firstTrack = musicDb.trackFromDatabaseId(firstTrackId); auto firstTrackTitle = firstTrack.title(); auto firstTrackArtist = firstTrack.artist(); auto firstTrackAlbumArtist = firstTrack.albumArtist(); auto firstTrackAlbum = firstTrack.albumName(); auto firstTrackImage = firstTrack.albumCover(); auto firstTrackDuration = firstTrack.duration(); auto firstTrackMilliSecondsDuration = firstTrack.duration().msecsSinceStartOfDay(); auto firstTrackTrackNumber = firstTrack.trackNumber(); auto firstTrackDiscNumber = firstTrack.discNumber(); auto firstTrackResource = firstTrack.resourceURI(); auto firstTrackRating = firstTrack.rating(); auto firstIsSingleDiscAlbum = firstTrack.isSingleDiscAlbum(); QCOMPARE(firstTrack.isValid(), true); QCOMPARE(firstTrackTitle, QStringLiteral("track6")); QCOMPARE(firstTrackArtist, QStringLiteral("artist2")); QCOMPARE(firstTrackAlbumArtist, QStringLiteral("artist2")); QCOMPARE(firstTrackAlbum, QStringLiteral("album3")); QCOMPARE(firstTrackImage.isValid(), true); QCOMPARE(firstTrackImage, QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(firstTrackDuration, QTime::fromMSecsSinceStartOfDay(23)); QCOMPARE(firstTrackMilliSecondsDuration, 23); QCOMPARE(firstTrackTrackNumber, 6); QCOMPARE(firstTrackDiscNumber, 1); QCOMPARE(firstTrackResource.isValid(), true); QCOMPARE(firstTrackResource, QUrl::fromLocalFile(QStringLiteral("/$23"))); QCOMPARE(firstTrackRating, 5); QCOMPARE(firstIsSingleDiscAlbum, true); auto allAlbums = musicDb.allAlbums(); auto firstAlbumTitle = allAlbums[0].title(); auto firstAlbumArtist = allAlbums[0].artist(); auto firstAlbumImage = allAlbums[0].albumArtURI(); auto firstAlbumTracksCount = allAlbums[0].tracksCount(); auto firstAlbumIsSingleDiscAlbum = allAlbums[0].isSingleDiscAlbum(); QCOMPARE(firstAlbumTitle, QStringLiteral("album3")); QCOMPARE(firstAlbumArtist, QStringLiteral("artist2")); QCOMPARE(firstAlbumImage.isValid(), true); QCOMPARE(firstAlbumImage, QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(firstAlbumTracksCount, 1); QCOMPARE(firstAlbumIsSingleDiscAlbum, true); auto newTrack2 = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist9"), QStringLiteral("album3"), QStringLiteral("artist2"), 6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), QUrl::fromLocalFile(QStringLiteral("album3")), 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks2 = QList(); newTracks2.push_back(newTrack2); auto newCovers2 = mNewCovers; newCovers2[QStringLiteral("file:///$23")] = QUrl::fromLocalFile(QStringLiteral("image$19")); musicDb.insertTracksList(newTracks2, newCovers2, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(50); QCOMPARE(musicDb.allAlbums().count(), 1); QCOMPARE(musicDb.allArtists().count(), 2); QCOMPARE(musicDb.allTracks().count(), 1); QCOMPARE(musicDbArtistAddedSpy.count(), 2); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 1); QCOMPARE(musicDbTrackModifiedSpy.count(), 1); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto secondTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist9"), QStringLiteral("album3"), 6, 1); auto secondTrack = musicDb.trackFromDatabaseId(secondTrackId); auto secondTrackTitle = secondTrack.title(); auto secondTrackArtist = secondTrack.artist(); auto secondTrackAlbumArtist = secondTrack.albumArtist(); auto secondTrackAlbum = secondTrack.albumName(); auto secondTrackImage = secondTrack.albumCover(); auto secondTrackDuration = secondTrack.duration(); auto secondTrackMilliSecondsDuration = secondTrack.duration().msecsSinceStartOfDay(); auto secondTrackTrackNumber = secondTrack.trackNumber(); auto secondTrackDiscNumber = secondTrack.discNumber(); auto secondTrackResource = secondTrack.resourceURI(); auto secondTrackRating = secondTrack.rating(); auto secondIsSingleDiscAlbum = secondTrack.isSingleDiscAlbum(); QCOMPARE(secondTrack.isValid(), true); QCOMPARE(secondTrackTitle, QStringLiteral("track6")); QCOMPARE(secondTrackArtist, QStringLiteral("artist9")); QCOMPARE(secondTrackAlbumArtist, QStringLiteral("artist2")); QCOMPARE(secondTrackAlbum, QStringLiteral("album3")); QCOMPARE(secondTrackImage.isValid(), true); QCOMPARE(secondTrackImage, QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(secondTrackDuration, QTime::fromMSecsSinceStartOfDay(23)); QCOMPARE(secondTrackMilliSecondsDuration, 23); QCOMPARE(secondTrackTrackNumber, 6); QCOMPARE(secondTrackDiscNumber, 1); QCOMPARE(secondTrackResource.isValid(), true); QCOMPARE(secondTrackResource, QUrl::fromLocalFile(QStringLiteral("/$23"))); QCOMPARE(secondTrackRating, 5); QCOMPARE(secondIsSingleDiscAlbum, true); auto allAlbums2 = musicDb.allAlbums(); auto firstAlbumTitle2 = allAlbums2[0].title(); auto firstAlbumArtist2 = allAlbums2[0].artist(); auto firstAlbumImage2 = allAlbums2[0].albumArtURI(); auto firstAlbumTracksCount2 = allAlbums2[0].tracksCount(); auto firstAlbumIsSingleDiscAlbum2 = allAlbums2[0].isSingleDiscAlbum(); QCOMPARE(firstAlbumTitle2, QStringLiteral("album3")); QCOMPARE(firstAlbumArtist2, QStringLiteral("artist2")); QCOMPARE(firstAlbumImage2.isValid(), true); QCOMPARE(firstAlbumImage2, QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(firstAlbumTracksCount2, 1); QCOMPARE(firstAlbumIsSingleDiscAlbum2, true); } void addTwoTracksSameFileWithAlbumSameName() { QTemporaryFile databaseFile; databaseFile.open(); qDebug() << "addTwoTracksSameFileWithAlbumSameName" << databaseFile.fileName(); DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb"), databaseFile.fileName()); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///$23")] = QUrl::fromLocalFile(QStringLiteral("album3")); musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 1); QCOMPARE(musicDb.allArtists().count(), 1); QCOMPARE(musicDb.allTracks().count(), 1); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto firstTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), 6, 1); auto firstTrack = musicDb.trackFromDatabaseId(firstTrackId); auto firstTrackTitle = firstTrack.title(); auto firstTrackArtist = firstTrack.artist(); auto firstTrackAlbumArtist = firstTrack.albumArtist(); auto firstTrackAlbum = firstTrack.albumName(); auto firstTrackImage = firstTrack.albumCover(); auto firstTrackDuration = firstTrack.duration(); auto firstTrackMilliSecondsDuration = firstTrack.duration().msecsSinceStartOfDay(); auto firstTrackTrackNumber = firstTrack.trackNumber(); auto firstTrackDiscNumber = firstTrack.discNumber(); auto firstTrackResource = firstTrack.resourceURI(); auto firstTrackRating = firstTrack.rating(); auto firstIsSingleDiscAlbum = firstTrack.isSingleDiscAlbum(); QCOMPARE(firstTrack.isValid(), true); QCOMPARE(firstTrackTitle, QStringLiteral("track6")); QCOMPARE(firstTrackArtist, QStringLiteral("artist2")); QCOMPARE(firstTrackAlbumArtist, QStringLiteral("artist2")); QCOMPARE(firstTrackAlbum, QStringLiteral("album3")); QCOMPARE(firstTrackImage.isValid(), true); QCOMPARE(firstTrackImage, QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(firstTrackDuration, QTime::fromMSecsSinceStartOfDay(23)); QCOMPARE(firstTrackMilliSecondsDuration, 23); QCOMPARE(firstTrackTrackNumber, 6); QCOMPARE(firstTrackDiscNumber, 1); QCOMPARE(firstTrackResource.isValid(), true); QCOMPARE(firstTrackResource, QUrl::fromLocalFile(QStringLiteral("/$23"))); QCOMPARE(firstTrackRating, 5); QCOMPARE(firstIsSingleDiscAlbum, true); auto allAlbums = musicDb.allAlbums(); QCOMPARE(allAlbums.size(), 1); auto firstAlbumTitle = allAlbums[0].title(); auto firstAlbumArtist = allAlbums[0].artist(); auto firstAlbumImage = allAlbums[0].albumArtURI(); auto firstAlbumTracksCount = allAlbums[0].tracksCount(); auto firstAlbumIsSingleDiscAlbum = allAlbums[0].isSingleDiscAlbum(); QCOMPARE(firstAlbumTitle, QStringLiteral("album3")); QCOMPARE(firstAlbumArtist, QStringLiteral("artist2")); QCOMPARE(firstAlbumImage.isValid(), true); QCOMPARE(firstAlbumImage, QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(firstAlbumTracksCount, 1); QCOMPARE(firstAlbumIsSingleDiscAlbum, true); auto newTrack2 = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist9"), QStringLiteral("album3"), QStringLiteral("artist9"), 6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), QUrl::fromLocalFile(QStringLiteral("album3")), 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks2 = QList(); newTracks2.push_back(newTrack2); auto newCovers2 = mNewCovers; newCovers2[QStringLiteral("file:///$23")] = QUrl::fromLocalFile(QStringLiteral("album3")); musicDb.insertTracksList(newTracks2, newCovers2, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(50); QCOMPARE(musicDb.allAlbums().count(), 2); QCOMPARE(musicDb.allArtists().count(), 2); QCOMPARE(musicDb.allTracks().count(), 1); QCOMPARE(musicDbArtistAddedSpy.count(), 2); QCOMPARE(musicDbAlbumAddedSpy.count(), 2); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 1); QCOMPARE(musicDbTrackModifiedSpy.count(), 1); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto secondTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist9"), QStringLiteral("album3"), 6, 1); auto secondTrack = musicDb.trackFromDatabaseId(secondTrackId); auto secondTrackTitle = secondTrack.title(); auto secondTrackArtist = secondTrack.artist(); auto secondTrackAlbumArtist = secondTrack.albumArtist(); auto secondTrackAlbum = secondTrack.albumName(); auto secondTrackImage = secondTrack.albumCover(); auto secondTrackDuration = secondTrack.duration(); auto secondTrackMilliSecondsDuration = secondTrack.duration().msecsSinceStartOfDay(); auto secondTrackTrackNumber = secondTrack.trackNumber(); auto secondTrackDiscNumber = secondTrack.discNumber(); auto secondTrackResource = secondTrack.resourceURI(); auto secondTrackRating = secondTrack.rating(); auto secondIsSingleDiscAlbum = secondTrack.isSingleDiscAlbum(); QCOMPARE(secondTrack.isValid(), true); QCOMPARE(secondTrackTitle, QStringLiteral("track6")); QCOMPARE(secondTrackArtist, QStringLiteral("artist9")); QCOMPARE(secondTrackAlbumArtist, QStringLiteral("artist9")); QCOMPARE(secondTrackAlbum, QStringLiteral("album3")); QCOMPARE(secondTrackImage.isValid(), true); QCOMPARE(secondTrackImage, QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(secondTrackDuration, QTime::fromMSecsSinceStartOfDay(23)); QCOMPARE(secondTrackMilliSecondsDuration, 23); QCOMPARE(secondTrackTrackNumber, 6); QCOMPARE(secondTrackDiscNumber, 1); QCOMPARE(secondTrackResource.isValid(), true); QCOMPARE(secondTrackResource, QUrl::fromLocalFile(QStringLiteral("/$23"))); QCOMPARE(secondTrackRating, 5); QCOMPARE(secondIsSingleDiscAlbum, true); auto allAlbums2 = musicDb.allAlbums(); auto firstAlbumTitle2 = allAlbums2[0].title(); auto firstAlbumArtist2 = allAlbums2[0].artist(); auto firstAlbumImage2 = allAlbums2[0].albumArtURI(); auto firstAlbumTracksCount2 = allAlbums2[0].tracksCount(); auto firstAlbumIsSingleDiscAlbum2 = allAlbums2[0].isSingleDiscAlbum(); QCOMPARE(firstAlbumTitle2, QStringLiteral("album3")); QCOMPARE(firstAlbumArtist2, QStringLiteral("artist2")); QCOMPARE(firstAlbumImage2.isValid(), true); QCOMPARE(firstAlbumImage2, QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(firstAlbumTracksCount2, 0); QCOMPARE(firstAlbumIsSingleDiscAlbum2, true); auto secondAlbumTitle = allAlbums2[1].title(); auto secondAlbumArtist = allAlbums2[1].artist(); auto secondAlbumImage = allAlbums2[1].albumArtURI(); auto secondAlbumTracksCount = allAlbums2[1].tracksCount(); auto secondAlbumIsSingleDiscAlbum = allAlbums2[1].isSingleDiscAlbum(); QCOMPARE(secondAlbumTitle, QStringLiteral("album3")); QCOMPARE(secondAlbumArtist, QStringLiteral("artist9")); QCOMPARE(secondAlbumImage.isValid(), true); QCOMPARE(secondAlbumImage, QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(secondAlbumTracksCount, 1); QCOMPARE(secondAlbumIsSingleDiscAlbum, true); auto modifiedAlbumIds = QList{musicDbAlbumModifiedSpy.at(0).at(1).toULongLong(),}; std::sort(modifiedAlbumIds.begin(), modifiedAlbumIds.end()); QCOMPARE(modifiedAlbumIds.at(0), qulonglong(2)); } void addTwoTracksWithAlbumSameName() { QTemporaryFile databaseFile; databaseFile.open(); qDebug() << "addTwoTracksWithAlbumSameName" << databaseFile.fileName(); DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb"), databaseFile.fileName()); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///$23")] = QUrl::fromLocalFile(QStringLiteral("album3")); musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 1); QCOMPARE(musicDb.allArtists().count(), 1); QCOMPARE(musicDb.allTracks().count(), 1); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto firstTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), 6, 1); auto firstTrack = musicDb.trackFromDatabaseId(firstTrackId); auto firstTrackTitle = firstTrack.title(); auto firstTrackArtist = firstTrack.artist(); auto firstTrackAlbumArtist = firstTrack.albumArtist(); auto firstTrackAlbum = firstTrack.albumName(); auto firstTrackImage = firstTrack.albumCover(); auto firstTrackDuration = firstTrack.duration(); auto firstTrackMilliSecondsDuration = firstTrack.duration().msecsSinceStartOfDay(); auto firstTrackTrackNumber = firstTrack.trackNumber(); auto firstTrackDiscNumber = firstTrack.discNumber(); auto firstTrackResource = firstTrack.resourceURI(); auto firstTrackRating = firstTrack.rating(); auto firstIsSingleDiscAlbum = firstTrack.isSingleDiscAlbum(); QCOMPARE(firstTrack.isValid(), true); QCOMPARE(firstTrackTitle, QStringLiteral("track6")); QCOMPARE(firstTrackArtist, QStringLiteral("artist2")); QCOMPARE(firstTrackAlbumArtist, QStringLiteral("artist2")); QCOMPARE(firstTrackAlbum, QStringLiteral("album3")); QCOMPARE(firstTrackImage.isValid(), true); QCOMPARE(firstTrackImage, QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(firstTrackDuration, QTime::fromMSecsSinceStartOfDay(23)); QCOMPARE(firstTrackMilliSecondsDuration, 23); QCOMPARE(firstTrackTrackNumber, 6); QCOMPARE(firstTrackDiscNumber, 1); QCOMPARE(firstTrackResource.isValid(), true); QCOMPARE(firstTrackResource, QUrl::fromLocalFile(QStringLiteral("/$23"))); QCOMPARE(firstTrackRating, 5); QCOMPARE(firstIsSingleDiscAlbum, true); auto allAlbums = musicDb.allAlbums(); QCOMPARE(allAlbums.size(), 1); auto firstAlbumTitle = allAlbums[0].title(); auto firstAlbumArtist = allAlbums[0].artist(); auto firstAlbumImage = allAlbums[0].albumArtURI(); auto firstAlbumTracksCount = allAlbums[0].tracksCount(); auto firstAlbumIsSingleDiscAlbum = allAlbums[0].isSingleDiscAlbum(); QCOMPARE(firstAlbumTitle, QStringLiteral("album3")); QCOMPARE(firstAlbumArtist, QStringLiteral("artist2")); QCOMPARE(firstAlbumImage.isValid(), true); QCOMPARE(firstAlbumImage, QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(firstAlbumTracksCount, 1); QCOMPARE(firstAlbumIsSingleDiscAlbum, true); auto newTrack2 = MusicAudioTrack{true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist9"), QStringLiteral("album3"), QStringLiteral("artist9"), 6, 1, QTime::fromMSecsSinceStartOfDay(20), {QUrl::fromLocalFile(QStringLiteral("/$20"))}, QDateTime::fromMSecsSinceEpoch(20), {QUrl::fromLocalFile(QStringLiteral("file://image$20"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks2 = QList(); newTracks2.push_back(newTrack2); auto newCovers2 = mNewCovers; newCovers2[QStringLiteral("file:///$20")] = QUrl::fromLocalFile(QStringLiteral("album3")); musicDb.insertTracksList(newTracks2, newCovers2, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(50); QCOMPARE(musicDb.allAlbums().count(), 2); QCOMPARE(musicDb.allArtists().count(), 2); QCOMPARE(musicDb.allTracks().count(), 2); QCOMPARE(musicDbArtistAddedSpy.count(), 2); QCOMPARE(musicDbAlbumAddedSpy.count(), 2); QCOMPARE(musicDbTrackAddedSpy.count(), 2); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto secondTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist9"), QStringLiteral("album3"), 6, 1); auto secondTrack = musicDb.trackFromDatabaseId(secondTrackId); auto secondTrackTitle = secondTrack.title(); auto secondTrackArtist = secondTrack.artist(); auto secondTrackAlbumArtist = secondTrack.albumArtist(); auto secondTrackAlbum = secondTrack.albumName(); auto secondTrackImage = secondTrack.albumCover(); auto secondTrackDuration = secondTrack.duration(); auto secondTrackMilliSecondsDuration = secondTrack.duration().msecsSinceStartOfDay(); auto secondTrackTrackNumber = secondTrack.trackNumber(); auto secondTrackDiscNumber = secondTrack.discNumber(); auto secondTrackResource = secondTrack.resourceURI(); auto secondTrackRating = secondTrack.rating(); auto secondIsSingleDiscAlbum = secondTrack.isSingleDiscAlbum(); QCOMPARE(secondTrack.isValid(), true); QCOMPARE(secondTrackTitle, QStringLiteral("track6")); QCOMPARE(secondTrackArtist, QStringLiteral("artist9")); QCOMPARE(secondTrackAlbumArtist, QStringLiteral("artist9")); QCOMPARE(secondTrackAlbum, QStringLiteral("album3")); QCOMPARE(secondTrackImage.isValid(), true); QCOMPARE(secondTrackImage, QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(secondTrackDuration, QTime::fromMSecsSinceStartOfDay(20)); QCOMPARE(secondTrackMilliSecondsDuration, 20); QCOMPARE(secondTrackTrackNumber, 6); QCOMPARE(secondTrackDiscNumber, 1); QCOMPARE(secondTrackResource.isValid(), true); QCOMPARE(secondTrackResource, QUrl::fromLocalFile(QStringLiteral("/$20"))); QCOMPARE(secondTrackRating, 5); QCOMPARE(secondIsSingleDiscAlbum, true); auto allAlbums2 = musicDb.allAlbums(); auto firstAlbumTitle2 = allAlbums2[0].title(); auto firstAlbumArtist2 = allAlbums2[0].artist(); auto firstAlbumImage2 = allAlbums2[0].albumArtURI(); auto firstAlbumTracksCount2 = allAlbums2[0].tracksCount(); auto firstAlbumIsSingleDiscAlbum2 = allAlbums2[0].isSingleDiscAlbum(); QCOMPARE(firstAlbumTitle2, QStringLiteral("album3")); QCOMPARE(firstAlbumArtist2, QStringLiteral("artist2")); QCOMPARE(firstAlbumImage2.isValid(), true); QCOMPARE(firstAlbumImage2, QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(firstAlbumTracksCount2, 1); QCOMPARE(firstAlbumIsSingleDiscAlbum2, true); auto secondAlbumTitle = allAlbums2[1].title(); auto secondAlbumArtist = allAlbums2[1].artist(); auto secondAlbumImage = allAlbums2[1].albumArtURI(); auto secondAlbumTracksCount = allAlbums2[1].tracksCount(); auto secondAlbumIsSingleDiscAlbum = allAlbums2[1].isSingleDiscAlbum(); QCOMPARE(secondAlbumTitle, QStringLiteral("album3")); QCOMPARE(secondAlbumArtist, QStringLiteral("artist9")); QCOMPARE(secondAlbumImage.isValid(), true); QCOMPARE(secondAlbumImage, QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(secondAlbumTracksCount, 1); QCOMPARE(secondAlbumIsSingleDiscAlbum, true); } void addTwoTracksInAlbumWithoutCover() { DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb")); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album7"), QStringLiteral("artist2"), 6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), QUrl::fromLocalFile(QStringLiteral("album3")), 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///$23")] = QUrl(); musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 6); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 23); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 2); QCOMPARE(musicDbTrackAddedSpy.count(), 2); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto trackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album7"), 6, 1); const auto &firstTrack = musicDb.trackFromDatabaseId(trackId); QCOMPARE(firstTrack.isValid(), true); QCOMPARE(firstTrack.albumCover(), QUrl()); auto newTrack2 = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track7"), QStringLiteral("artist2"), QStringLiteral("album7"), QStringLiteral("artist2"), 7, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("album7"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks2 = QList(); newTracks2.push_back(newTrack2); auto newCovers2 = mNewCovers; newCovers2[QStringLiteral("file:///$23")] = QUrl::fromLocalFile(QStringLiteral("album7")); musicDb.insertTracksList(newTracks2, newCovers2, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 6); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 23); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 2); QCOMPARE(musicDbTrackAddedSpy.count(), 2); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 1); QCOMPARE(musicDbTrackModifiedSpy.count(), 3); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto secondTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track7"), QStringLiteral("artist2"), QStringLiteral("album7"), 7, 1); const auto &secondTrack = musicDb.trackFromDatabaseId(secondTrackId); QCOMPARE(secondTrack.isValid(), true); QCOMPARE(secondTrack.albumCover(), QUrl::fromLocalFile(QStringLiteral("album7"))); } void modifyOneTrack() { QTemporaryFile databaseFile; databaseFile.open(); qDebug() << "modifyOneTrack" << databaseFile.fileName(); DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb"), databaseFile.fileName()); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto modifiedTrack = MusicAudioTrack{true, QStringLiteral("$3"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 5, 3, QTime::fromMSecsSinceStartOfDay(3), {QUrl::fromLocalFile(QStringLiteral("/$3"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("file://image$3"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}; musicDb.modifyTracksList({modifiedTrack}, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 1); QCOMPARE(musicDbTrackModifiedSpy.count(), 3); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto trackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 5, 3); QCOMPARE(trackId != 0, true); auto track = musicDb.trackFromDatabaseId(trackId); QCOMPARE(track.isValid(), true); QCOMPARE(track.trackNumber(), 5); } void addOneAlbum() { DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb")); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album7"), QStringLiteral("artist2"), 6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("album7"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); auto newCover = QUrl::fromLocalFile(QStringLiteral("file://image$19")); auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///$23")] = newCover; musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 6); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 23); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 2); QCOMPARE(musicDbTrackAddedSpy.count(), 2); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); const auto &newAlbum = musicDb.albumFromTitleAndArtist(QStringLiteral("album7"), QStringLiteral("artist2")); QCOMPARE(newAlbum.albumArtURI(), QUrl::fromLocalFile(QStringLiteral("file://image$19"))); } void addOneArtist() { DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb")); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist6"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), QUrl::fromLocalFile(QStringLiteral("album1")), 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); auto newFiles2 = QList(); for (const auto &oneTrack : newTracks) { newFiles2.push_back(oneTrack.resourceURI()); } auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///$23")] = QUrl::fromLocalFile(QStringLiteral("album1")); musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 8); QCOMPARE(musicDb.allTracks().count(), 23); QCOMPARE(musicDbArtistAddedSpy.count(), 2); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 2); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 1); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); } void reloadDatabaseWithAllTracks() { QTemporaryFile databaseFile; databaseFile.open(); qDebug() << "reloadDatabaseWithAllTracks" << databaseFile.fileName(); { DatabaseInterface musicDb; QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); musicDb.init(QStringLiteral("testDb"), databaseFile.fileName()); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); } DatabaseInterface musicDb2; QSignalSpy musicDbArtistAddedSpy2(&musicDb2, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy2(&musicDb2, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy2(&musicDb2, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy2(&musicDb2, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy2(&musicDb2, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy2(&musicDb2, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy2(&musicDb2, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy2(&musicDb2, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy2(&musicDb2, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy2(&musicDb2, &DatabaseInterface::databaseError); QCOMPARE(musicDb2.allAlbums().count(), 0); QCOMPARE(musicDb2.allArtists().count(), 0); QCOMPARE(musicDb2.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy2.count(), 0); QCOMPARE(musicDbAlbumAddedSpy2.count(), 0); QCOMPARE(musicDbTrackAddedSpy2.count(), 0); QCOMPARE(musicDbArtistRemovedSpy2.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy2.count(), 0); QCOMPARE(musicDbTrackRemovedSpy2.count(), 0); QCOMPARE(musicDbArtistModifiedSpy2.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy2.count(), 0); QCOMPARE(musicDbTrackModifiedSpy2.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy2.count(), 0); musicDb2.init(QStringLiteral("testDb2"), databaseFile.fileName()); musicDbTrackAddedSpy2.wait(300); QCOMPARE(musicDb2.allAlbums().count(), 5); QCOMPARE(musicDb2.allArtists().count(), 7); QCOMPARE(musicDb2.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy2.count(), 1); QCOMPARE(musicDbAlbumAddedSpy2.count(), 1); QCOMPARE(musicDbTrackAddedSpy2.count(), 1); QCOMPARE(musicDbArtistRemovedSpy2.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy2.count(), 0); QCOMPARE(musicDbTrackRemovedSpy2.count(), 0); QCOMPARE(musicDbArtistModifiedSpy2.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy2.count(), 0); QCOMPARE(musicDbTrackModifiedSpy2.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy2.count(), 0); musicDb2.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(musicDb2.allAlbums().count(), 5); QCOMPARE(musicDb2.allArtists().count(), 7); QCOMPARE(musicDb2.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy2.count(), 1); QCOMPARE(musicDbAlbumAddedSpy2.count(), 1); QCOMPARE(musicDbTrackAddedSpy2.count(), 1); QCOMPARE(musicDbArtistRemovedSpy2.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy2.count(), 0); QCOMPARE(musicDbTrackRemovedSpy2.count(), 0); QCOMPARE(musicDbArtistModifiedSpy2.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy2.count(), 1); QCOMPARE(musicDbTrackModifiedSpy2.count(), 1); QCOMPARE(musicDbDatabaseErrorSpy2.count(), 0); } void testRemovalOfTracksFromInvalidSource() { DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb")); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); musicDb.removeAllTracksFromSource(QStringLiteral("autoTestNotValid")); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); } void testRemovalOfTracksFromValidSource() { QTemporaryFile databaseFile; databaseFile.open(); qDebug() << "testRemovalOfTracksFromValidSource" << databaseFile.fileName(); DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb"), databaseFile.fileName()); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); musicDb.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 5); QCOMPARE(musicDb.allArtists().count(), 7); QCOMPARE(musicDb.allTracks().count(), 22); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 2); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); QList secondNewTracks = { {true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist6"), QStringLiteral("album7"), QStringLiteral("artist6"), 1, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("file://image$6"))}, 1, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$24"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist6"), QStringLiteral("album7"), QStringLiteral("artist6"), 2, 1, QTime::fromMSecsSinceStartOfDay(24), {QUrl::fromLocalFile(QStringLiteral("/$24"))}, QDateTime::fromMSecsSinceEpoch(24), {QUrl::fromLocalFile(QStringLiteral("file://image$6"))}, 2, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$25"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist6"), QStringLiteral("album7"), QStringLiteral("artist6"), 3, 1, QTime::fromMSecsSinceStartOfDay(25), {QUrl::fromLocalFile(QStringLiteral("/$25"))}, QDateTime::fromMSecsSinceEpoch(25), {QUrl::fromLocalFile(QStringLiteral("file://image$6"))}, 3, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$26"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist6"), QStringLiteral("album7"), QStringLiteral("artist6"), 4, 1, QTime::fromMSecsSinceStartOfDay(26), {QUrl::fromLocalFile(QStringLiteral("/$26"))}, QDateTime::fromMSecsSinceEpoch(26), {QUrl::fromLocalFile(QStringLiteral("file://image$6"))}, 4, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$27"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist6"), QStringLiteral("album7"), QStringLiteral("artist6"), 5, 1, QTime::fromMSecsSinceStartOfDay(27), {QUrl::fromLocalFile(QStringLiteral("/$27"))}, QDateTime::fromMSecsSinceEpoch(27), {QUrl::fromLocalFile(QStringLiteral("file://image$6"))}, 5, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$28"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist6"), QStringLiteral("album7"), QStringLiteral("artist6"), 6, 1, QTime::fromMSecsSinceStartOfDay(28), {QUrl::fromLocalFile(QStringLiteral("/$28"))}, QDateTime::fromMSecsSinceEpoch(28), {QUrl::fromLocalFile(QStringLiteral("file://image$6"))}, 6, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$29"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 2, 2, QTime::fromMSecsSinceStartOfDay(29), {QUrl::fromLocalFile(QStringLiteral("/$29"))}, QDateTime::fromMSecsSinceEpoch(29), {QUrl::fromLocalFile(QStringLiteral("file://image$2"))}, 2, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, }; musicDb.insertTracksList(secondNewTracks, mNewCovers, QStringLiteral("autoTestSource2")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 6); QCOMPARE(musicDb.allArtists().count(), 8); QCOMPARE(musicDb.allTracks().count(), 28); QCOMPARE(musicDbArtistAddedSpy.count(), 2); QCOMPARE(musicDbAlbumAddedSpy.count(), 2); QCOMPARE(musicDbTrackAddedSpy.count(), 2); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 1); QCOMPARE(musicDbTrackModifiedSpy.count(), 3); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); musicDb.removeAllTracksFromSource(QStringLiteral("autoTest")); QCOMPARE(musicDb.allAlbums().count(), 2); QCOMPARE(musicDb.allArtists().count(), 3); QCOMPARE(musicDb.allTracks().count(), 7); QCOMPARE(musicDbArtistAddedSpy.count(), 2); QCOMPARE(musicDbAlbumAddedSpy.count(), 2); QCOMPARE(musicDbTrackAddedSpy.count(), 2); QCOMPARE(musicDbArtistRemovedSpy.count(), 5); QCOMPARE(musicDbAlbumRemovedSpy.count(), 4); QCOMPARE(musicDbTrackRemovedSpy.count(), 21); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 2); QCOMPARE(musicDbTrackModifiedSpy.count(), 3); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); } void testAddAlbumsSameName() { QTemporaryFile databaseFile; databaseFile.open(); qDebug() << "testAddAlbumsSameName" << databaseFile.fileName(); DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb"), databaseFile.fileName()); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); QList newTracks = { {true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist6"), QStringLiteral("album1"), QStringLiteral("artist6"), 1, 1, QTime::fromMSecsSinceStartOfDay(1), {QUrl::fromLocalFile(QStringLiteral("/$20"))}, QDateTime::fromMSecsSinceEpoch(20), {QUrl::fromLocalFile(QStringLiteral("file://image$6"))}, 1, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$21"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist6"), QStringLiteral("album1"), QStringLiteral("artist6"), 2, 1, QTime::fromMSecsSinceStartOfDay(2), {QUrl::fromLocalFile(QStringLiteral("/$21"))}, QDateTime::fromMSecsSinceEpoch(21), {QUrl::fromLocalFile(QStringLiteral("file://image$6"))}, 2, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$22"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist6"), QStringLiteral("album1"), QStringLiteral("artist6"), 3, 1, QTime::fromMSecsSinceStartOfDay(3), {QUrl::fromLocalFile(QStringLiteral("/$22"))}, QDateTime::fromMSecsSinceEpoch(22), {QUrl::fromLocalFile(QStringLiteral("file://image$6"))}, 3, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist6"), QStringLiteral("album1"), QStringLiteral("artist6"), 4, 1, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("file://image$6"))}, 4, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$24"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist6"), QStringLiteral("album1"), QStringLiteral("artist6"), 5, 1, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$24"))}, QDateTime::fromMSecsSinceEpoch(24), {QUrl::fromLocalFile(QStringLiteral("file://image$6"))}, 5, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$25"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist6"), QStringLiteral("album1"), QStringLiteral("artist6"), 6, 1, QTime::fromMSecsSinceStartOfDay(5), {QUrl::fromLocalFile(QStringLiteral("/$25"))}, QDateTime::fromMSecsSinceEpoch(25), {QUrl::fromLocalFile(QStringLiteral("file://image$6"))}, 6, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$2"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 2, 2, QTime::fromMSecsSinceStartOfDay(2), {QUrl::fromLocalFile(QStringLiteral("/$26"))}, QDateTime::fromMSecsSinceEpoch(26), {QUrl::fromLocalFile(QStringLiteral("file://image$2"))}, 2, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, }; musicDb.insertTracksList(newTracks, mNewCovers, QStringLiteral("autoTestSource2")); musicDbTrackAddedSpy.wait(100); QCOMPARE(musicDb.allAlbums().count(), 2); QCOMPARE(musicDb.allArtists().count(), 3); QCOMPARE(musicDb.allTracks().count(), 7); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto firstAlbum = musicDb.albumFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Invalid Artist")); } void addTwoIdenticalTracksWithPartialAlbumArtist() { QTemporaryFile databaseFile; databaseFile.open(); qDebug() << "addTwoTracksWithoutAlbumArtist" << databaseFile.fileName(); DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb"), databaseFile.fileName()); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto newTracks = QList(); newTracks = {{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), {}, 6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")},}; auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///$23")] = QUrl::fromLocalFile(QStringLiteral("album3")); musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 1); QCOMPARE(musicDb.allArtists().count(), 1); QCOMPARE(musicDb.allTracks().count(), 1); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto firstTrack = musicDb.trackFromDatabaseId(musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), 6, 1)); QCOMPARE(firstTrack.isValid(), true); QCOMPARE(firstTrack.title(), QStringLiteral("track6")); QCOMPARE(firstTrack.artist(), QStringLiteral("artist2")); QCOMPARE(firstTrack.albumName(), QStringLiteral("album3")); QCOMPARE(firstTrack.albumArtist(), QStringLiteral("artist2")); QCOMPARE(firstTrack.isValidAlbumArtist(), false); QCOMPARE(firstTrack.albumCover(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(firstTrack.trackNumber(), 6); QCOMPARE(firstTrack.discNumber(), 1); QCOMPARE(firstTrack.duration(), QTime::fromMSecsSinceStartOfDay(23)); QCOMPARE(firstTrack.resourceURI(), QUrl::fromLocalFile(QStringLiteral("/$23"))); QCOMPARE(firstTrack.rating(), 5); QCOMPARE(firstTrack.genre(), QStringLiteral("genre1")); QCOMPARE(firstTrack.composer(), QStringLiteral("composer1")); QCOMPARE(firstTrack.lyricist(), QStringLiteral("lyricist1")); QCOMPARE(firstTrack.albumId(), qulonglong(2)); auto newTracks2 = QList(); newTracks2 = {{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")},}; auto newCovers2 = mNewCovers; newCovers2[QStringLiteral("file:///$23")] = QUrl::fromLocalFile(QStringLiteral("album3")); musicDb.insertTracksList(newTracks2, newCovers2, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 1); QCOMPARE(musicDb.allArtists().count(), 1); QCOMPARE(musicDb.allTracks().count(), 1); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); } void addTwoTracksWithPartialAlbumArtist2() { QTemporaryFile databaseFile; databaseFile.open(); qDebug() << "addTwoTracksWithPartialAlbumArtist" << databaseFile.fileName(); DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb"), databaseFile.fileName()); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto newTracks = QList(); newTracks = {{true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track7"), QStringLiteral("artist3"), QStringLiteral("album3"), {QStringLiteral("artist4")}, 7, 1, QTime::fromMSecsSinceStartOfDay(20), {QUrl::fromLocalFile(QStringLiteral("/$20"))}, QDateTime::fromMSecsSinceEpoch(20), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}}; auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///$23")] = QUrl::fromLocalFile(QStringLiteral("album3")); newCovers[QStringLiteral("file:///$20")] = QUrl::fromLocalFile(QStringLiteral("album3")); musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 1); QCOMPARE(musicDb.allArtists().count(), 2); QCOMPARE(musicDb.allTracks().count(), 1); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto newTracks2 = QList(); newTracks2 = {{true, QStringLiteral("$19"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist4"), QStringLiteral("album3"), {}, 6, 1, QTime::fromMSecsSinceStartOfDay(19), {QUrl::fromLocalFile(QStringLiteral("/$19"))}, QDateTime::fromMSecsSinceEpoch(19), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}}; musicDb.insertTracksList(newTracks2, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 1); QCOMPARE(musicDb.allArtists().count(), 2); QCOMPARE(musicDb.allTracks().count(), 2); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 2); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 1); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto firstTrack = musicDb.trackFromDatabaseId(musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist4"), QStringLiteral("album3"), 6, 1)); QCOMPARE(firstTrack.isValid(), true); QCOMPARE(firstTrack.title(), QStringLiteral("track6")); QCOMPARE(firstTrack.artist(), QStringLiteral("artist4")); QCOMPARE(firstTrack.albumName(), QStringLiteral("album3")); QCOMPARE(firstTrack.albumArtist(), QStringLiteral("artist4")); QCOMPARE(firstTrack.isValidAlbumArtist(), true); QCOMPARE(firstTrack.albumCover(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(firstTrack.trackNumber(), 6); QCOMPARE(firstTrack.discNumber(), 1); QCOMPARE(firstTrack.duration(), QTime::fromMSecsSinceStartOfDay(19)); QCOMPARE(firstTrack.resourceURI(), QUrl::fromLocalFile(QStringLiteral("/$19"))); QCOMPARE(firstTrack.rating(), 5); QCOMPARE(firstTrack.genre(), QStringLiteral("genre1")); QCOMPARE(firstTrack.composer(), QStringLiteral("composer1")); QCOMPARE(firstTrack.lyricist(), QStringLiteral("lyricist1")); QCOMPARE(firstTrack.albumId(), qulonglong(2)); auto secondTrack = musicDb.trackFromDatabaseId(musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track7"), QStringLiteral("artist3"), QStringLiteral("album3"), 7, 1)); QCOMPARE(secondTrack.isValid(), true); QCOMPARE(secondTrack.title(), QStringLiteral("track7")); QCOMPARE(secondTrack.artist(), QStringLiteral("artist3")); QCOMPARE(secondTrack.albumName(), QStringLiteral("album3")); QCOMPARE(secondTrack.albumArtist(), QStringLiteral("artist4")); QCOMPARE(secondTrack.isValidAlbumArtist(), true); QCOMPARE(secondTrack.albumCover(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(secondTrack.trackNumber(), 7); QCOMPARE(secondTrack.discNumber(), 1); QCOMPARE(secondTrack.duration(), QTime::fromMSecsSinceStartOfDay(20)); QCOMPARE(secondTrack.resourceURI(), QUrl::fromLocalFile(QStringLiteral("/$20"))); QCOMPARE(secondTrack.rating(), 5); QCOMPARE(secondTrack.genre(), QStringLiteral("genre1")); QCOMPARE(secondTrack.composer(), QStringLiteral("composer1")); QCOMPARE(secondTrack.lyricist(), QStringLiteral("lyricist1")); QCOMPARE(secondTrack.albumId(), qulonglong(2)); auto album = musicDb.albumFromTitleAndArtist(QStringLiteral("album3"), QStringLiteral("artist4")); QCOMPARE(album.isValid(), true); QCOMPARE(album.tracksCount(), 2); QCOMPARE(album.title(), QStringLiteral("album3")); QCOMPARE(album.artist(), QStringLiteral("artist4")); QCOMPARE(album.isValidArtist(), true); QCOMPARE(album.albumArtURI(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(album.isSingleDiscAlbum(), true); } void addTowAlbumsWithDifferentPathsAndSameName() { QTemporaryFile databaseFile; databaseFile.open(); qDebug() << "addTowAlbumsWithDifferentPathsAndSameName" << databaseFile.fileName(); DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb"), databaseFile.fileName()); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto newTracks = QList(); newTracks = {{true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track7"), QStringLiteral("artist1"), QStringLiteral("album7"), {}, 7, 1, QTime::fromMSecsSinceStartOfDay(20), {QUrl::fromLocalFile(QStringLiteral("/album7/$20"))}, QDateTime::fromMSecsSinceEpoch(20), {QUrl::fromLocalFile(QStringLiteral("album7"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$21"), QStringLiteral("0"), QStringLiteral("track8"), QStringLiteral("artist2"), QStringLiteral("album7"), {}, 8, 1, QTime::fromMSecsSinceStartOfDay(21), {QUrl::fromLocalFile(QStringLiteral("/album7/$21"))}, QDateTime::fromMSecsSinceEpoch(21), {QUrl::fromLocalFile(QStringLiteral("album7"))}, 5, true, QStringLiteral("genre2"), QStringLiteral("composer2"), QStringLiteral("lyricist2")}, {true, QStringLiteral("$22"), QStringLiteral("0"), QStringLiteral("track9"), QStringLiteral("artist3"), QStringLiteral("album7"), {}, 9, 1, QTime::fromMSecsSinceStartOfDay(22), {QUrl::fromLocalFile(QStringLiteral("/album8/$22"))}, QDateTime::fromMSecsSinceEpoch(22), {QUrl::fromLocalFile(QStringLiteral("album7"))}, 5, true, QStringLiteral("genre3"), QStringLiteral("composer3"), QStringLiteral("lyricist3")}, {true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track10"), QStringLiteral("artist4"), QStringLiteral("album7"), {}, 10, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/album8/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("album7"))}, 5, true, QStringLiteral("genre4"), QStringLiteral("composer4"), QStringLiteral("lyricist4")},}; auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///album7/$20")] = QUrl::fromLocalFile(QStringLiteral("album7")); newCovers[QStringLiteral("file:///album7/$21")] = QUrl::fromLocalFile(QStringLiteral("album7")); newCovers[QStringLiteral("file:///album8/$22")] = QUrl::fromLocalFile(QStringLiteral("album8")); newCovers[QStringLiteral("file:///album8/$23")] = QUrl::fromLocalFile(QStringLiteral("album8")); musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 2); QCOMPARE(musicDb.allArtists().count(), 4); QCOMPARE(musicDb.allTracks().count(), 4); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); QCOMPARE(musicDb.allAlbums().size(), 2); QCOMPARE(musicDb.allArtists().size(), 4); QCOMPARE(musicDb.allTracks().size(), 4); auto allAlbums = musicDb.allAlbums(); auto firstAlbum = allAlbums[0]; QCOMPARE(firstAlbum.tracksCount(), 2); auto secondAlbum = allAlbums[1]; QCOMPARE(secondAlbum.tracksCount(), 2); } void addTowAlbumsWithDifferentPathsAndSameTracks() { QTemporaryFile databaseFile; databaseFile.open(); qDebug() << "addTowAlbumsWithDifferentPathsAndSameName" << databaseFile.fileName(); DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb"), databaseFile.fileName()); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto newTracks = QList(); newTracks = {{true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track7"), QStringLiteral("artist1"), QStringLiteral("album7"), {}, 7, 1, QTime::fromMSecsSinceStartOfDay(20), {QUrl::fromLocalFile(QStringLiteral("/album7/$20"))}, QDateTime::fromMSecsSinceEpoch(20), {QUrl::fromLocalFile(QStringLiteral("album7"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$21"), QStringLiteral("0"), QStringLiteral("track8"), QStringLiteral("artist2"), QStringLiteral("album7"), {}, 8, 1, QTime::fromMSecsSinceStartOfDay(21), {QUrl::fromLocalFile(QStringLiteral("/album7/$21"))}, QDateTime::fromMSecsSinceEpoch(21), {QUrl::fromLocalFile(QStringLiteral("album7"))}, 5, true, QStringLiteral("genre2"), QStringLiteral("composer2"), QStringLiteral("lyricist2")}, {true, QStringLiteral("$22"), QStringLiteral("0"), QStringLiteral("track9"), QStringLiteral("artist3"), QStringLiteral("album7"), {}, 9, 1, QTime::fromMSecsSinceStartOfDay(22), {QUrl::fromLocalFile(QStringLiteral("/album7/$22"))}, QDateTime::fromMSecsSinceEpoch(22), {QUrl::fromLocalFile(QStringLiteral("album7"))}, 5, true, QStringLiteral("genre3"), QStringLiteral("composer3"), QStringLiteral("lyricist3")}, {true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track7"), QStringLiteral("artist1"), QStringLiteral("album7"), {}, 7, 1, QTime::fromMSecsSinceStartOfDay(20), {QUrl::fromLocalFile(QStringLiteral("/album8/$20"))}, QDateTime::fromMSecsSinceEpoch(20), {QUrl::fromLocalFile(QStringLiteral("album7"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$21"), QStringLiteral("0"), QStringLiteral("track8"), QStringLiteral("artist2"), QStringLiteral("album7"), {}, 8, 1, QTime::fromMSecsSinceStartOfDay(21), {QUrl::fromLocalFile(QStringLiteral("/album8/$21"))}, QDateTime::fromMSecsSinceEpoch(21), {QUrl::fromLocalFile(QStringLiteral("album7"))}, 5, true, QStringLiteral("genre2"), QStringLiteral("composer2"), QStringLiteral("lyricist2")}, {true, QStringLiteral("$22"), QStringLiteral("0"), QStringLiteral("track9"), QStringLiteral("artist3"), QStringLiteral("album7"), {}, 9, 1, QTime::fromMSecsSinceStartOfDay(22), {QUrl::fromLocalFile(QStringLiteral("/album8/$22"))}, QDateTime::fromMSecsSinceEpoch(22), {QUrl::fromLocalFile(QStringLiteral("album7"))}, 5, true, QStringLiteral("genre3"), QStringLiteral("composer3"), QStringLiteral("lyricist3")},}; auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///album7/$20")] = QUrl::fromLocalFile(QStringLiteral("album7")); newCovers[QStringLiteral("file:///album7/$21")] = QUrl::fromLocalFile(QStringLiteral("album7")); newCovers[QStringLiteral("file:///album7/$22")] = QUrl::fromLocalFile(QStringLiteral("album7")); newCovers[QStringLiteral("file:///album8/$20")] = QUrl::fromLocalFile(QStringLiteral("album8")); newCovers[QStringLiteral("file:///album8/$21")] = QUrl::fromLocalFile(QStringLiteral("album8")); newCovers[QStringLiteral("file:///album8/$22")] = QUrl::fromLocalFile(QStringLiteral("album8")); musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 2); QCOMPARE(musicDb.allArtists().count(), 3); QCOMPARE(musicDb.allTracks().count(), 6); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto allAlbums = musicDb.allAlbums(); auto firstAlbum = allAlbums[0]; QCOMPARE(firstAlbum.tracksCount(), 3); auto secondAlbum = allAlbums[1]; QCOMPARE(secondAlbum.tracksCount(), 3); } void addTwoTracksFromSameAlbumButDifferentDiscs() { QTemporaryFile databaseFile; databaseFile.open(); qDebug() << "addTwoTracksFromSameAlbumButDifferentDiscs" << databaseFile.fileName(); DatabaseInterface musicDb; musicDb.init(QStringLiteral("testDb"), databaseFile.fileName()); QSignalSpy musicDbArtistAddedSpy(&musicDb, &DatabaseInterface::artistsAdded); QSignalSpy musicDbAlbumAddedSpy(&musicDb, &DatabaseInterface::albumsAdded); QSignalSpy musicDbTrackAddedSpy(&musicDb, &DatabaseInterface::tracksAdded); QSignalSpy musicDbArtistRemovedSpy(&musicDb, &DatabaseInterface::artistRemoved); QSignalSpy musicDbAlbumRemovedSpy(&musicDb, &DatabaseInterface::albumRemoved); QSignalSpy musicDbTrackRemovedSpy(&musicDb, &DatabaseInterface::trackRemoved); QSignalSpy musicDbArtistModifiedSpy(&musicDb, &DatabaseInterface::artistModified); QSignalSpy musicDbAlbumModifiedSpy(&musicDb, &DatabaseInterface::albumModified); QSignalSpy musicDbTrackModifiedSpy(&musicDb, &DatabaseInterface::trackModified); QSignalSpy musicDbDatabaseErrorSpy(&musicDb, &DatabaseInterface::databaseError); QCOMPARE(musicDb.allAlbums().count(), 0); QCOMPARE(musicDb.allArtists().count(), 0); QCOMPARE(musicDb.allTracks().count(), 0); QCOMPARE(musicDbArtistAddedSpy.count(), 0); QCOMPARE(musicDbAlbumAddedSpy.count(), 0); QCOMPARE(musicDbTrackAddedSpy.count(), 0); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto newTrack = MusicAudioTrack{true, QStringLiteral("$23"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 6, 1, QTime::fromMSecsSinceStartOfDay(23), {QUrl::fromLocalFile(QStringLiteral("/$23"))}, QDateTime::fromMSecsSinceEpoch(23), {QUrl::fromLocalFile(QStringLiteral("album3"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks = QList(); newTracks.push_back(newTrack); auto newCovers = mNewCovers; newCovers[QStringLiteral("file:///$23")] = QUrl::fromLocalFile(QStringLiteral("album3")); musicDb.insertTracksList(newTracks, newCovers, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(300); QCOMPARE(musicDb.allAlbums().count(), 1); QCOMPARE(musicDb.allArtists().count(), 1); QCOMPARE(musicDb.allTracks().count(), 1); QCOMPARE(musicDbArtistAddedSpy.count(), 1); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 1); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 0); QCOMPARE(musicDbTrackModifiedSpy.count(), 0); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto firstTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist2"), QStringLiteral("album3"), 6, 1); auto firstTrack = musicDb.trackFromDatabaseId(firstTrackId); auto firstTrackTitle = firstTrack.title(); auto firstTrackArtist = firstTrack.artist(); auto firstTrackAlbumArtist = firstTrack.albumArtist(); auto firstTrackAlbum = firstTrack.albumName(); auto firstTrackImage = firstTrack.albumCover(); auto firstTrackDuration = firstTrack.duration(); auto firstTrackMilliSecondsDuration = firstTrack.duration().msecsSinceStartOfDay(); auto firstTrackTrackNumber = firstTrack.trackNumber(); auto firstTrackDiscNumber = firstTrack.discNumber(); auto firstTrackResource = firstTrack.resourceURI(); auto firstTrackRating = firstTrack.rating(); auto firstIsSingleDiscAlbum = firstTrack.isSingleDiscAlbum(); QCOMPARE(firstTrack.isValid(), true); QCOMPARE(firstTrackTitle, QStringLiteral("track6")); QCOMPARE(firstTrackArtist, QStringLiteral("artist2")); QCOMPARE(firstTrackAlbumArtist, QStringLiteral("artist2")); QCOMPARE(firstTrackAlbum, QStringLiteral("album3")); QCOMPARE(firstTrackImage.isValid(), true); QCOMPARE(firstTrackImage, QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(firstTrackDuration, QTime::fromMSecsSinceStartOfDay(23)); QCOMPARE(firstTrackMilliSecondsDuration, 23); QCOMPARE(firstTrackTrackNumber, 6); QCOMPARE(firstTrackDiscNumber, 1); QCOMPARE(firstTrackResource.isValid(), true); QCOMPARE(firstTrackResource, QUrl::fromLocalFile(QStringLiteral("/$23"))); QCOMPARE(firstTrackRating, 5); QCOMPARE(firstIsSingleDiscAlbum, true); auto allAlbums = musicDb.allAlbums(); QCOMPARE(allAlbums.size(), 1); auto firstAlbumTitle = allAlbums[0].title(); auto firstAlbumArtist = allAlbums[0].artist(); auto firstAlbumImage = allAlbums[0].albumArtURI(); auto firstAlbumTracksCount = allAlbums[0].tracksCount(); auto firstAlbumIsSingleDiscAlbum = allAlbums[0].isSingleDiscAlbum(); QCOMPARE(firstAlbumTitle, QStringLiteral("album3")); QCOMPARE(firstAlbumArtist, QStringLiteral("artist2")); QCOMPARE(firstAlbumImage.isValid(), true); QCOMPARE(firstAlbumImage, QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(firstAlbumTracksCount, 1); QCOMPARE(firstAlbumIsSingleDiscAlbum, true); auto newTrack2 = MusicAudioTrack{true, QStringLiteral("$25"), QStringLiteral("0"), QStringLiteral("track8"), QStringLiteral("artist9"), QStringLiteral("album3"), QStringLiteral("artist2"), 8, 2, QTime::fromMSecsSinceStartOfDay(25), {QUrl::fromLocalFile(QStringLiteral("/$25"))}, QDateTime::fromMSecsSinceEpoch(25), {QUrl::fromLocalFile(QStringLiteral("file://image$25"))}, 5, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}; auto newTracks2 = QList(); newTracks2.push_back(newTrack2); auto newCovers2 = mNewCovers; newCovers2[QStringLiteral("file:///$25")] = QUrl::fromLocalFile(QStringLiteral("album3")); musicDb.insertTracksList(newTracks2, newCovers2, QStringLiteral("autoTest")); musicDbTrackAddedSpy.wait(50); QCOMPARE(musicDb.allAlbums().count(), 1); QCOMPARE(musicDb.allArtists().count(), 2); QCOMPARE(musicDb.allTracks().count(), 2); QCOMPARE(musicDbArtistAddedSpy.count(), 2); QCOMPARE(musicDbAlbumAddedSpy.count(), 1); QCOMPARE(musicDbTrackAddedSpy.count(), 2); QCOMPARE(musicDbArtistRemovedSpy.count(), 0); QCOMPARE(musicDbAlbumRemovedSpy.count(), 0); QCOMPARE(musicDbTrackRemovedSpy.count(), 0); QCOMPARE(musicDbArtistModifiedSpy.count(), 0); QCOMPARE(musicDbAlbumModifiedSpy.count(), 1); QCOMPARE(musicDbTrackModifiedSpy.count(), 1); QCOMPARE(musicDbDatabaseErrorSpy.count(), 0); auto secondTrackId = musicDb.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track8"), QStringLiteral("artist9"), QStringLiteral("album3"), 8, 2); auto secondTrack = musicDb.trackFromDatabaseId(secondTrackId); auto secondTrackTitle = secondTrack.title(); auto secondTrackArtist = secondTrack.artist(); auto secondTrackAlbumArtist = secondTrack.albumArtist(); auto secondTrackAlbum = secondTrack.albumName(); auto secondTrackImage = secondTrack.albumCover(); auto secondTrackDuration = secondTrack.duration(); auto secondTrackMilliSecondsDuration = secondTrack.duration().msecsSinceStartOfDay(); auto secondTrackTrackNumber = secondTrack.trackNumber(); auto secondTrackDiscNumber = secondTrack.discNumber(); auto secondTrackResource = secondTrack.resourceURI(); auto secondTrackRating = secondTrack.rating(); auto secondIsSingleDiscAlbum = secondTrack.isSingleDiscAlbum(); QCOMPARE(secondTrack.isValid(), true); QCOMPARE(secondTrackTitle, QStringLiteral("track8")); QCOMPARE(secondTrackArtist, QStringLiteral("artist9")); QCOMPARE(secondTrackAlbumArtist, QStringLiteral("artist2")); QCOMPARE(secondTrackAlbum, QStringLiteral("album3")); QCOMPARE(secondTrackImage.isValid(), true); QCOMPARE(secondTrackImage, QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(secondTrackDuration, QTime::fromMSecsSinceStartOfDay(25)); QCOMPARE(secondTrackMilliSecondsDuration, 25); QCOMPARE(secondTrackTrackNumber, 8); QCOMPARE(secondTrackDiscNumber, 2); QCOMPARE(secondTrackResource.isValid(), true); QCOMPARE(secondTrackResource, QUrl::fromLocalFile(QStringLiteral("/$25"))); QCOMPARE(secondTrackRating, 5); QCOMPARE(secondIsSingleDiscAlbum, false); const auto &modifiedTrackSignal = musicDbTrackModifiedSpy.at(0); QCOMPARE(modifiedTrackSignal.count(), 1); const auto &modifiedTrack = modifiedTrackSignal.at(0).value(); auto modifiedTrackTitle = modifiedTrack.title(); auto modifiedTrackArtist = modifiedTrack.artist(); auto modifiedTrackAlbumArtist = modifiedTrack.albumArtist(); auto modifiedTrackAlbum = modifiedTrack.albumName(); auto modifiedTrackImage = modifiedTrack.albumCover(); auto modifiedTrackDuration = modifiedTrack.duration(); auto modifiedTrackMilliSecondsDuration = modifiedTrack.duration().msecsSinceStartOfDay(); auto modifiedTrackTrackNumber = modifiedTrack.trackNumber(); auto modifiedTrackDiscNumber = modifiedTrack.discNumber(); auto modifiedTrackResource = modifiedTrack.resourceURI(); auto modifiedTrackRating = modifiedTrack.rating(); auto modifiedTrackIsSingleDiscAlbum = modifiedTrack.isSingleDiscAlbum(); QCOMPARE(modifiedTrack.isValid(), true); QCOMPARE(modifiedTrackTitle, QStringLiteral("track6")); QCOMPARE(modifiedTrackArtist, QStringLiteral("artist2")); QCOMPARE(modifiedTrackAlbumArtist, QStringLiteral("artist2")); QCOMPARE(modifiedTrackAlbum, QStringLiteral("album3")); QCOMPARE(modifiedTrackImage.isValid(), true); QCOMPARE(modifiedTrackImage, QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(modifiedTrackDuration, QTime::fromMSecsSinceStartOfDay(23)); QCOMPARE(modifiedTrackMilliSecondsDuration, 23); QCOMPARE(modifiedTrackTrackNumber, 6); QCOMPARE(modifiedTrackDiscNumber, 1); QCOMPARE(modifiedTrackResource.isValid(), true); QCOMPARE(modifiedTrackResource, QUrl::fromLocalFile(QStringLiteral("/$23"))); QCOMPARE(modifiedTrackRating, 5); QCOMPARE(modifiedTrackIsSingleDiscAlbum, false); auto allAlbums2 = musicDb.allAlbums(); auto firstAlbumTitle2 = allAlbums2[0].title(); auto firstAlbumArtist2 = allAlbums2[0].artist(); auto firstAlbumImage2 = allAlbums2[0].albumArtURI(); auto firstAlbumTracksCount2 = allAlbums2[0].tracksCount(); auto firstAlbumIsSingleDiscAlbum2 = allAlbums2[0].isSingleDiscAlbum(); QCOMPARE(firstAlbumTitle2, QStringLiteral("album3")); QCOMPARE(firstAlbumArtist2, QStringLiteral("artist2")); QCOMPARE(firstAlbumImage2.isValid(), true); QCOMPARE(firstAlbumImage2, QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(firstAlbumTracksCount2, 2); QCOMPARE(firstAlbumIsSingleDiscAlbum2, false); } }; QTEST_GUILESS_MAIN(DatabaseInterfaceTests) #include "databaseinterfacetest.moc" diff --git a/autotests/elisaapplicationtest.cpp b/autotests/elisaapplicationtest.cpp index 82735130..f2f6698f 100644 --- a/autotests/elisaapplicationtest.cpp +++ b/autotests/elisaapplicationtest.cpp @@ -1,101 +1,99 @@ /* * Copyright 2015-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "elisaapplication.h" #include "config-upnp-qt.h" #include #include #include #include #include #include #include class ElisaApplicationTests: public QObject { Q_OBJECT public: ElisaApplicationTests(QObject *parent = nullptr) : QObject(parent) { } private: private Q_SLOTS: void initTestCase() { qRegisterMetaType>("QHash"); qRegisterMetaType>("QHash"); qRegisterMetaType>("QVector"); qRegisterMetaType>("QHash"); qRegisterMetaType>("QList"); } void setArgumentsTest() { ElisaApplication myApp; QSignalSpy argumentsChangedSpy(&myApp, &ElisaApplication::argumentsChanged); QSignalSpy enqueueSpy(&myApp, &ElisaApplication::enqueue); auto myTestFile = QFileInfo(QStringLiteral(LOCAL_FILE_TESTS_SAMPLE_FILES_PATH) + QStringLiteral("/music/test.ogg")); auto myDirectory = QDir::current(); auto relativePath = myDirectory.relativeFilePath(myTestFile.canonicalFilePath()); myApp.setArguments({relativePath}); QCOMPARE(argumentsChangedSpy.count(), 1); QCOMPARE(enqueueSpy.count(), 1); QCOMPARE(myApp.arguments().count(), 1); QCOMPARE(myApp.arguments().at(0), myTestFile.canonicalFilePath()); } void activateRequestedTest() { ElisaApplication myApp; QSignalSpy argumentsChangedSpy(&myApp, &ElisaApplication::argumentsChanged); QSignalSpy enqueueSpy(&myApp, &ElisaApplication::enqueue); auto myTestFile = QFileInfo(QStringLiteral(LOCAL_FILE_TESTS_SAMPLE_FILES_PATH) + QStringLiteral("/music/test.ogg")); auto myDirectory = QDir::current(); auto relativePath = myDirectory.relativeFilePath(myTestFile.canonicalFilePath()); myApp.activateRequested({QString(), relativePath}, QDir::currentPath()); QCOMPARE(argumentsChangedSpy.count(), 0); QCOMPARE(enqueueSpy.count(), 1); QCOMPARE(enqueueSpy.at(0).count(), 1); QCOMPARE(enqueueSpy.at(0).at(0).toString(), myTestFile.canonicalFilePath()); } }; QTEST_MAIN(ElisaApplicationTests) #include "elisaapplicationtest.moc" diff --git a/autotests/elisaqmltestplugin.h b/autotests/elisaqmltestplugin.h index 6e6c3c72..73d8c6f4 100644 --- a/autotests/elisaqmltestplugin.h +++ b/autotests/elisaqmltestplugin.h @@ -1,37 +1,35 @@ /* * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef ELISAQMLTESTPLUGIN_H #define ELISAQMLTESTPLUGIN_H #include class QQmlEngine; class ElisaQmlTestPlugin : public QQmlExtensionPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") public: void initializeEngine(QQmlEngine *engine, const char *uri) Q_DECL_OVERRIDE; void registerTypes(const char *uri) Q_DECL_OVERRIDE; }; #endif // ELISAQMLTESTPLUGIN_H diff --git a/autotests/elisaqmltests.cpp b/autotests/elisaqmltests.cpp index f00c808c..af15efb9 100644 --- a/autotests/elisaqmltests.cpp +++ b/autotests/elisaqmltests.cpp @@ -1,22 +1,20 @@ /* * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include QUICK_TEST_MAIN(ElisaQmlTests) diff --git a/autotests/localfilelistingtest.cpp b/autotests/localfilelistingtest.cpp index eab3a712..0dc74035 100644 --- a/autotests/localfilelistingtest.cpp +++ b/autotests/localfilelistingtest.cpp @@ -1,739 +1,737 @@ /* * Copyright 2015-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "file/localfilelisting.h" #include "musicaudiotrack.h" #include "config-upnp-qt.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include class LocalFileListingTests: public QObject { Q_OBJECT public: LocalFileListingTests(QObject *parent = nullptr) : QObject(parent) { } private: QList mNewTracks = { {true, QStringLiteral("$1"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 1, 1, QTime::fromMSecsSinceStartOfDay(1), {QUrl::fromLocalFile(QStringLiteral("/$1"))}, QDateTime::fromMSecsSinceEpoch(1), QUrl::fromLocalFile(QStringLiteral("album1")), 1, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$2"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 2, 2, QTime::fromMSecsSinceStartOfDay(2), {QUrl::fromLocalFile(QStringLiteral("/$2"))}, QDateTime::fromMSecsSinceEpoch(2), QUrl::fromLocalFile(QStringLiteral("album1")), 2, false, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$3"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 3, 3, QTime::fromMSecsSinceStartOfDay(3), {QUrl::fromLocalFile(QStringLiteral("/$3"))}, QDateTime::fromMSecsSinceEpoch(3), QUrl::fromLocalFile(QStringLiteral("album1")), 3, false, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4Bis"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$5"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 1, 1, QTime::fromMSecsSinceStartOfDay(5), {QUrl::fromLocalFile(QStringLiteral("/$5"))}, QDateTime::fromMSecsSinceEpoch(5), QUrl::fromLocalFile(QStringLiteral("album2")), 4, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$6"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 2, 1, QTime::fromMSecsSinceStartOfDay(6), {QUrl::fromLocalFile(QStringLiteral("/$6"))}, QDateTime::fromMSecsSinceEpoch(6), QUrl::fromLocalFile(QStringLiteral("album2")), 1, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$7"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 3, 1, QTime::fromMSecsSinceStartOfDay(7), {QUrl::fromLocalFile(QStringLiteral("/$7"))}, QDateTime::fromMSecsSinceEpoch(7), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$8"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 4, 1, QTime::fromMSecsSinceStartOfDay(8), {QUrl::fromLocalFile(QStringLiteral("/$8"))}, QDateTime::fromMSecsSinceEpoch(8), QUrl::fromLocalFile(QStringLiteral("album2")), 2, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$9"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 5, 1, QTime::fromMSecsSinceStartOfDay(9), {QUrl::fromLocalFile(QStringLiteral("/$9"))}, QDateTime::fromMSecsSinceEpoch(9), QUrl::fromLocalFile(QStringLiteral("album2")), 3, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$10"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist1 and artist2"), QStringLiteral("album2"), QStringLiteral("artist1"), 6, 1, QTime::fromMSecsSinceStartOfDay(10), {QUrl::fromLocalFile(QStringLiteral("/$10"))}, QDateTime::fromMSecsSinceEpoch(10), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$11"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(11), {QUrl::fromLocalFile(QStringLiteral("/$11"))}, QDateTime::fromMSecsSinceEpoch(11), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$12"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(12), {QUrl::fromLocalFile(QStringLiteral("/$12"))}, QDateTime::fromMSecsSinceEpoch(12), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$13"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(13), {QUrl::fromLocalFile(QStringLiteral("/$13"))}, QDateTime::fromMSecsSinceEpoch(13), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$14"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(14), {QUrl::fromLocalFile(QStringLiteral("/$14"))}, QDateTime::fromMSecsSinceEpoch(14), QUrl::fromLocalFile(QStringLiteral("album4")), 4, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$15"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(15), {QUrl::fromLocalFile(QStringLiteral("/$15"))}, QDateTime::fromMSecsSinceEpoch(15), QUrl::fromLocalFile(QStringLiteral("album4")), 5, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$16"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(16), {QUrl::fromLocalFile(QStringLiteral("/$16"))}, QDateTime::fromMSecsSinceEpoch(16), QUrl::fromLocalFile(QStringLiteral("album4")), 1, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$17"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 4, 1, QTime::fromMSecsSinceStartOfDay(17), {QUrl::fromLocalFile(QStringLiteral("/$17"))}, QDateTime::fromMSecsSinceEpoch(17), QUrl::fromLocalFile(QStringLiteral("album4")), 2, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$18"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 5, 1, QTime::fromMSecsSinceStartOfDay(18), {QUrl::fromLocalFile(QStringLiteral("/$18"))}, QDateTime::fromMSecsSinceEpoch(18), QUrl::fromLocalFile(QStringLiteral("album4")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$19"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 1, 1, QTime::fromMSecsSinceStartOfDay(19), {QUrl::fromLocalFile(QStringLiteral("/$19"))}, QDateTime::fromMSecsSinceEpoch(19), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 2, 1, QTime::fromMSecsSinceStartOfDay(20), {QUrl::fromLocalFile(QStringLiteral("/$20"))}, QDateTime::fromMSecsSinceEpoch(20), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$21"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 3, 1, QTime::fromMSecsSinceStartOfDay(21), {QUrl::fromLocalFile(QStringLiteral("/$21"))}, QDateTime::fromMSecsSinceEpoch(21), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$22"), QStringLiteral("0"), QStringLiteral("track9"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist7"), 9, 1, QTime::fromMSecsSinceStartOfDay(22), {QUrl::fromLocalFile(QStringLiteral("/$22"))}, QDateTime::fromMSecsSinceEpoch(22), QUrl::fromLocalFile(QStringLiteral("album3")), 9, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, }; QHash mNewCovers = { {QStringLiteral("file:///$1"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$2"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$3"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4Bis"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$5"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$6"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$7"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$8"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$9"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$0"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$11"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$12"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$13"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$14"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$15"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$16"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$17"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$18"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$19"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$20"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$21"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$22"), QUrl::fromLocalFile(QStringLiteral("album3"))}, }; private Q_SLOTS: void initTestCase() { qRegisterMetaType>("QHash"); qRegisterMetaType>("QHash"); qRegisterMetaType>("QList"); qRegisterMetaType>("QVector"); qRegisterMetaType>("QHash"); qRegisterMetaType>("QList"); qRegisterMetaType("NotificationItem"); } void initialTestWithNoTrack() { LocalFileListing myListing; QSignalSpy tracksListSpy(&myListing, &LocalFileListing::tracksList); QSignalSpy removedTracksListSpy(&myListing, &LocalFileListing::removedTracksList); QSignalSpy rootPathChangedSpy(&myListing, &LocalFileListing::rootPathChanged); QSignalSpy errorWatchingFilesSpy(&myListing, &LocalFileListing::errorWatchingFiles); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 0); QCOMPARE(errorWatchingFilesSpy.count(), 0); myListing.init(); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 0); QCOMPARE(errorWatchingFilesSpy.count(), 0); myListing.setRootPath(QStringLiteral("/directoryNotExist")); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 1); QCOMPARE(errorWatchingFilesSpy.count(), 0); QCOMPARE(myListing.rootPath(), QStringLiteral("/directoryNotExist")); myListing.refreshContent(); if (errorWatchingFilesSpy.count()) { QEXPECT_FAIL("", "watching files for change is not working", Abort); } QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 1); QCOMPARE(errorWatchingFilesSpy.count(), 0); } void initialTestWithTracks() { LocalFileListing myListing; QString musicPath = QStringLiteral(LOCAL_FILE_TESTS_SAMPLE_FILES_PATH) + QStringLiteral("/music"); QSignalSpy tracksListSpy(&myListing, &LocalFileListing::tracksList); QSignalSpy removedTracksListSpy(&myListing, &LocalFileListing::removedTracksList); QSignalSpy rootPathChangedSpy(&myListing, &LocalFileListing::rootPathChanged); QSignalSpy errorWatchingFilesSpy(&myListing, &LocalFileListing::errorWatchingFiles); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 0); QCOMPARE(errorWatchingFilesSpy.count(), 0); myListing.init(); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 0); QCOMPARE(errorWatchingFilesSpy.count(), 0); myListing.setRootPath(musicPath); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 1); QCOMPARE(errorWatchingFilesSpy.count(), 0); QCOMPARE(myListing.rootPath(), musicPath); myListing.refreshContent(); QCOMPARE(tracksListSpy.count(), 2); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 1); if (errorWatchingFilesSpy.count()) { QEXPECT_FAIL("", "watching files for change is not working", Abort); } QCOMPARE(errorWatchingFilesSpy.count(), 0); auto firstNewTracksSignal = tracksListSpy.at(0); auto firstNewTracks = firstNewTracksSignal.at(0).value>(); auto secondNewTracksSignal = tracksListSpy.at(1); auto secondNewTracks = secondNewTracksSignal.at(0).value>(); auto newCovers = secondNewTracksSignal.at(1).value>(); QCOMPARE(firstNewTracks.count() + secondNewTracks.count(), 3); QCOMPARE(newCovers.count(), 3); } void addAndRemoveTracks() { LocalFileListing myListing; QString musicOriginPath = QStringLiteral(LOCAL_FILE_TESTS_SAMPLE_FILES_PATH) + QStringLiteral("/music"); QString musicPath = QStringLiteral(LOCAL_FILE_TESTS_WORKING_PATH) + QStringLiteral("/music2/data/innerData"); QString musicParentPath = QStringLiteral(LOCAL_FILE_TESTS_WORKING_PATH) + QStringLiteral("/music2"); QDir musicParentDirectory(musicParentPath); QDir rootDirectory(QStringLiteral(LOCAL_FILE_TESTS_WORKING_PATH)); musicParentDirectory.removeRecursively(); rootDirectory.mkpath(QStringLiteral("music2/data/innerData")); QSignalSpy tracksListSpy(&myListing, &LocalFileListing::tracksList); QSignalSpy removedTracksListSpy(&myListing, &LocalFileListing::removedTracksList); QSignalSpy rootPathChangedSpy(&myListing, &LocalFileListing::rootPathChanged); QSignalSpy errorWatchingFilesSpy(&myListing, &LocalFileListing::errorWatchingFiles); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 0); QCOMPARE(errorWatchingFilesSpy.count(), 0); myListing.init(); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 0); QCOMPARE(errorWatchingFilesSpy.count(), 0); myListing.setRootPath(musicParentPath); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 1); QCOMPARE(errorWatchingFilesSpy.count(), 0); QCOMPARE(myListing.rootPath(), musicParentPath); myListing.refreshContent(); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 1); if (errorWatchingFilesSpy.count()) { QEXPECT_FAIL("", "watching files for change is not working", Abort); } QCOMPARE(errorWatchingFilesSpy.count(), 0); QFile myTrack(musicOriginPath + QStringLiteral("/test.ogg")); myTrack.copy(musicPath + QStringLiteral("/test.ogg")); QFile myCover(musicOriginPath + QStringLiteral("/cover.jpg")); myCover.copy(musicPath + QStringLiteral("/cover.jpg")); QCOMPARE(tracksListSpy.wait(), true); QCOMPARE(tracksListSpy.count(), 1); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 1); if (errorWatchingFilesSpy.count()) { QEXPECT_FAIL("", "watching files for change is not working", Abort); } QCOMPARE(errorWatchingFilesSpy.count(), 0); auto newTracksSignal = tracksListSpy.at(0); auto newTracks = newTracksSignal.at(0).value>(); auto newCovers = newTracksSignal.at(1).value>(); QCOMPARE(newTracks.count(), 1); QCOMPARE(newCovers.count(), 1); QString commandLine(QStringLiteral("rm -rf ") + musicPath); system(commandLine.toLatin1().data()); QCOMPARE(removedTracksListSpy.wait(), true); QCOMPARE(tracksListSpy.count(), 1); QCOMPARE(removedTracksListSpy.count(), 1); QCOMPARE(rootPathChangedSpy.count(), 1); QCOMPARE(errorWatchingFilesSpy.count(), 0); auto removeSignal = removedTracksListSpy.at(0); auto removedTracks = removeSignal.at(0).value>(); QCOMPARE(removedTracks.isEmpty(), false); QCOMPARE(rootDirectory.mkpath(QStringLiteral("music2/data/innerData")), true); QCOMPARE(myTrack.copy(musicPath + QStringLiteral("/test.ogg")), true); QCOMPARE(myCover.copy(musicPath + QStringLiteral("/cover.jpg")), true); if (tracksListSpy.count() == 1) { QCOMPARE(tracksListSpy.wait(), true); } QCOMPARE(tracksListSpy.count(), 2); QCOMPARE(removedTracksListSpy.count(), 1); QCOMPARE(rootPathChangedSpy.count(), 1); QCOMPARE(errorWatchingFilesSpy.count(), 0); auto newTracksSignalLast = tracksListSpy.at(1); auto newTracksLast = newTracksSignalLast.at(0).value>(); auto newCoversLast = newTracksSignalLast.at(1).value>(); QCOMPARE(newTracksLast.count(), 1); QCOMPARE(newCoversLast.count(), 1); } void addTracksAndRemoveDirectory() { LocalFileListing myListing; QString musicOriginPath = QStringLiteral(LOCAL_FILE_TESTS_SAMPLE_FILES_PATH) + QStringLiteral("/music"); QString musicPath = QStringLiteral(LOCAL_FILE_TESTS_WORKING_PATH) + QStringLiteral("/music2/data/innerData"); QString innerMusicPath = QStringLiteral(LOCAL_FILE_TESTS_WORKING_PATH) + QStringLiteral("/music2/data"); QString musicParentPath = QStringLiteral(LOCAL_FILE_TESTS_WORKING_PATH) + QStringLiteral("/music2"); QDir musicParentDirectory(musicParentPath); QDir rootDirectory(QStringLiteral(LOCAL_FILE_TESTS_WORKING_PATH)); musicParentDirectory.removeRecursively(); rootDirectory.mkpath(QStringLiteral("music2/data/innerData")); QSignalSpy tracksListSpy(&myListing, &LocalFileListing::tracksList); QSignalSpy removedTracksListSpy(&myListing, &LocalFileListing::removedTracksList); QSignalSpy rootPathChangedSpy(&myListing, &LocalFileListing::rootPathChanged); QSignalSpy errorWatchingFilesSpy(&myListing, &LocalFileListing::errorWatchingFiles); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 0); QCOMPARE(errorWatchingFilesSpy.count(), 0); myListing.init(); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 0); QCOMPARE(errorWatchingFilesSpy.count(), 0); myListing.setRootPath(musicParentPath); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 1); QCOMPARE(errorWatchingFilesSpy.count(), 0); QCOMPARE(myListing.rootPath(), musicParentPath); myListing.refreshContent(); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 1); if (errorWatchingFilesSpy.count()) { QEXPECT_FAIL("", "watching files for change is not working", Abort); } QCOMPARE(errorWatchingFilesSpy.count(), 0); QFile myTrack(musicOriginPath + QStringLiteral("/test.ogg")); myTrack.copy(musicPath + QStringLiteral("/test.ogg")); QFile myCover(musicOriginPath + QStringLiteral("/cover.jpg")); myCover.copy(musicPath + QStringLiteral("/cover.jpg")); QCOMPARE(tracksListSpy.wait(), true); QCOMPARE(tracksListSpy.count(), 1); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 1); if (errorWatchingFilesSpy.count()) { QEXPECT_FAIL("", "watching files for change is not working", Abort); } QCOMPARE(errorWatchingFilesSpy.count(), 0); auto newTracksSignal = tracksListSpy.at(0); auto newTracks = newTracksSignal.at(0).value>(); auto newCovers = newTracksSignal.at(1).value>(); QCOMPARE(newTracks.count(), 1); QCOMPARE(newCovers.count(), 1); QString commandLine(QStringLiteral("rm -rf ") + innerMusicPath); system(commandLine.toLatin1().data()); QCOMPARE(removedTracksListSpy.wait(), true); QCOMPARE(tracksListSpy.count(), 1); QCOMPARE(removedTracksListSpy.count(), 1); QCOMPARE(rootPathChangedSpy.count(), 1); QCOMPARE(errorWatchingFilesSpy.count(), 0); auto removeSignal = removedTracksListSpy.at(0); auto removedTracks = removeSignal.at(0).value>(); QCOMPARE(removedTracks.isEmpty(), false); QCOMPARE(rootDirectory.mkpath(QStringLiteral("music2/data/innerData")), true); QCOMPARE(myTrack.copy(musicPath + QStringLiteral("/test.ogg")), true); QCOMPARE(myCover.copy(musicPath + QStringLiteral("/cover.jpg")), true); if (tracksListSpy.count() == 1) { QCOMPARE(tracksListSpy.wait(), true); } QCOMPARE(tracksListSpy.count(), 2); QCOMPARE(removedTracksListSpy.count(), 1); QCOMPARE(rootPathChangedSpy.count(), 1); QCOMPARE(errorWatchingFilesSpy.count(), 0); auto newTracksSignalLast = tracksListSpy.at(1); auto newTracksLast = newTracksSignalLast.at(0).value>(); auto newCoversLast = newTracksSignalLast.at(1).value>(); QCOMPARE(newTracksLast.count(), 1); QCOMPARE(newCoversLast.count(), 1); } void addAndMoveTracks() { LocalFileListing myListing; QString musicOriginPath = QStringLiteral(LOCAL_FILE_TESTS_SAMPLE_FILES_PATH) + QStringLiteral("/music"); QString musicPath = QStringLiteral(LOCAL_FILE_TESTS_WORKING_PATH) + QStringLiteral("/music2/data/innerData"); QDir musicDirectory(musicPath); QString musicParentPath = QStringLiteral(LOCAL_FILE_TESTS_WORKING_PATH) + QStringLiteral("/music2"); QDir musicParentDirectory(musicParentPath); QString musicFriendPath = QStringLiteral(LOCAL_FILE_TESTS_WORKING_PATH) + QStringLiteral("/music3"); QDir musicFriendDirectory(musicFriendPath); QCOMPARE(musicFriendDirectory.removeRecursively(), true); QCOMPARE(musicParentDirectory.removeRecursively(), true); musicFriendDirectory.mkpath(musicFriendPath); musicDirectory.mkpath(musicPath); QSignalSpy tracksListSpy(&myListing, &LocalFileListing::tracksList); QSignalSpy removedTracksListSpy(&myListing, &LocalFileListing::removedTracksList); QSignalSpy modifiedTracksListSpy(&myListing, &LocalFileListing::modifyTracksList); QSignalSpy rootPathChangedSpy(&myListing, &LocalFileListing::rootPathChanged); QSignalSpy errorWatchingFilesSpy(&myListing, &LocalFileListing::errorWatchingFiles); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(modifiedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 0); QCOMPARE(errorWatchingFilesSpy.count(), 0); myListing.init(); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(modifiedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 0); QCOMPARE(errorWatchingFilesSpy.count(), 0); myListing.setRootPath(musicParentPath); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(modifiedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 1); QCOMPARE(errorWatchingFilesSpy.count(), 0); QCOMPARE(myListing.rootPath(), musicParentPath); myListing.refreshContent(); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(modifiedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 1); if (errorWatchingFilesSpy.count()) { QEXPECT_FAIL("", "watching files for change is not working", Abort); } QCOMPARE(errorWatchingFilesSpy.count(), 0); QFile myTrack(musicOriginPath + QStringLiteral("/test.ogg")); myTrack.copy(musicPath + QStringLiteral("/test.ogg")); QFile myCover(musicOriginPath + QStringLiteral("/cover.jpg")); myCover.copy(musicPath + QStringLiteral("/cover.jpg")); QCOMPARE(tracksListSpy.wait(), true); QCOMPARE(tracksListSpy.count(), 1); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(modifiedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 1); if (errorWatchingFilesSpy.count()) { QEXPECT_FAIL("", "watching files for change is not working", Abort); } QCOMPARE(errorWatchingFilesSpy.count(), 0); auto newTracksSignal = tracksListSpy.at(0); auto newTracks = newTracksSignal.at(0).value>(); auto newCovers = newTracksSignal.at(1).value>(); QCOMPARE(newTracks.count(), 1); QCOMPARE(newCovers.count(), 1); QString commandLine(QStringLiteral("mv ") + musicPath + QStringLiteral(" ") + musicFriendPath); system(commandLine.toLatin1().data()); QCOMPARE(removedTracksListSpy.wait(), true); QCOMPARE(tracksListSpy.count(), 1); QCOMPARE(removedTracksListSpy.count(), 1); QCOMPARE(modifiedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 1); QCOMPARE(errorWatchingFilesSpy.count(), 0); auto removeSignal = removedTracksListSpy.at(0); auto removedTracks = removeSignal.at(0).value>(); QCOMPARE(removedTracks.isEmpty(), false); QCOMPARE(musicFriendDirectory.mkpath(musicFriendPath), true); QCOMPARE(musicDirectory.mkpath(musicPath), true); QCOMPARE(myTrack.copy(musicPath + QStringLiteral("/test.ogg")), true); QCOMPARE(myCover.copy(musicPath + QStringLiteral("/cover.jpg")), true); if (tracksListSpy.count() == 1) { QCOMPARE(tracksListSpy.wait(), true); } QCOMPARE(tracksListSpy.count(), 2); QCOMPARE(removedTracksListSpy.count(), 1); QCOMPARE(modifiedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 1); QCOMPARE(errorWatchingFilesSpy.count(), 0); auto newTracksSignalLast = tracksListSpy.at(1); auto newTracksLast = newTracksSignalLast.at(0).value>(); auto newCoversLast = newTracksSignalLast.at(1).value>(); QCOMPARE(newTracksLast.count(), 1); QCOMPARE(newCoversLast.count(), 1); } void restoreRemovedTracks() { LocalFileListing myListing; QSignalSpy tracksListSpy(&myListing, &LocalFileListing::tracksList); QSignalSpy removedTracksListSpy(&myListing, &LocalFileListing::removedTracksList); QSignalSpy modifiedTracksListSpy(&myListing, &LocalFileListing::modifyTracksList); QSignalSpy rootPathChangedSpy(&myListing, &LocalFileListing::rootPathChanged); QSignalSpy indexingStartedSpy(&myListing, &LocalFileListing::indexingStarted); QSignalSpy indexingFinishedSpy(&myListing, &LocalFileListing::indexingFinished); QSignalSpy newNotificationSpy(&myListing, &LocalFileListing::newNotification); QSignalSpy closeNotificationSpy(&myListing, &LocalFileListing::closeNotification); QSignalSpy askRestoredTracksSpy(&myListing, &LocalFileListing::askRestoredTracks); QSignalSpy errorWatchingFilesSpy(&myListing, &LocalFileListing::errorWatchingFiles); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(modifiedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 0); QCOMPARE(indexingStartedSpy.count(), 0); QCOMPARE(indexingFinishedSpy.count(), 0); QCOMPARE(newNotificationSpy.count(), 0); QCOMPARE(closeNotificationSpy.count(), 0); QCOMPARE(askRestoredTracksSpy.count(), 0); QCOMPARE(errorWatchingFilesSpy.count(), 0); myListing.setRootPath(QStringLiteral("/does/not/exists")); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(modifiedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 1); QCOMPARE(indexingStartedSpy.count(), 0); QCOMPARE(indexingFinishedSpy.count(), 0); QCOMPARE(newNotificationSpy.count(), 0); QCOMPARE(closeNotificationSpy.count(), 0); QCOMPARE(askRestoredTracksSpy.count(), 0); QCOMPARE(errorWatchingFilesSpy.count(), 0); myListing.init(); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 0); QCOMPARE(modifiedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 1); QCOMPARE(indexingStartedSpy.count(), 0); QCOMPARE(indexingFinishedSpy.count(), 0); QCOMPARE(newNotificationSpy.count(), 0); QCOMPARE(closeNotificationSpy.count(), 0); QCOMPARE(askRestoredTracksSpy.count(), 1); QCOMPARE(errorWatchingFilesSpy.count(), 0); myListing.restoredTracks(QStringLiteral("/does/not/exists"), {{QUrl::fromLocalFile(QStringLiteral("/removed/files1")), QDateTime::fromMSecsSinceEpoch(1)}, {QUrl::fromLocalFile(QStringLiteral("/removed/files2")), QDateTime::fromMSecsSinceEpoch(2)}}); QCOMPARE(tracksListSpy.count(), 0); QCOMPARE(removedTracksListSpy.count(), 1); QCOMPARE(modifiedTracksListSpy.count(), 0); QCOMPARE(rootPathChangedSpy.count(), 1); QCOMPARE(indexingStartedSpy.count(), 1); QCOMPARE(indexingFinishedSpy.count(), 1); QCOMPARE(newNotificationSpy.count(), 0); QCOMPARE(closeNotificationSpy.count(), 0); QCOMPARE(askRestoredTracksSpy.count(), 1); QCOMPARE(errorWatchingFilesSpy.count(), 0); auto removedTracksSignal = removedTracksListSpy.at(0); QCOMPARE(removedTracksSignal.count(), 1); auto removedTracks = removedTracksSignal.at(0).value>(); QCOMPARE(removedTracks.count(), 2); std::sort(removedTracks.begin(), removedTracks.end()); QCOMPARE(removedTracks[0], QUrl::fromLocalFile(QStringLiteral("/removed/files1"))); QCOMPARE(removedTracks[1], QUrl::fromLocalFile(QStringLiteral("/removed/files2"))); } }; QTEST_GUILESS_MAIN(LocalFileListingTests) #include "localfilelistingtest.moc" diff --git a/autotests/manageaudioplayertest.cpp b/autotests/manageaudioplayertest.cpp index 47168cf0..2a057b16 100644 --- a/autotests/manageaudioplayertest.cpp +++ b/autotests/manageaudioplayertest.cpp @@ -1,8940 +1,8938 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "manageaudioplayertest.h" #include "manageaudioplayer.h" #include #include #include #include ManageAudioPlayerTest::ManageAudioPlayerTest(QObject *parent) : QObject(parent) { } void ManageAudioPlayerTest::initTestCase() { } void ManageAudioPlayerTest::simpleInitialCase() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerError(QMediaPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); myPlayer.setPlayerStatus(QMediaPlayer::NoMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::NoMedia); QCOMPARE(skipNextTrackSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); } void ManageAudioPlayerTest::noPlayCase() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerError(QMediaPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); QCOMPARE(playerPlaySpy.wait(100), false); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); } void ManageAudioPlayerTest::skipNextTrack() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerError(QMediaPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); myPlayer.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); QCOMPARE(playerStopSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); QCOMPARE(skipNextTrackSpy.wait(100), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); } void ManageAudioPlayerTest::skipNextTrackWithRandomPlay() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerError(QMediaPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); QCOMPARE(playerStopSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); QCOMPARE(skipNextTrackSpy.wait(100), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); } void ManageAudioPlayerTest::skipPreviousTrack() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///2.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerError(QMediaPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); QCOMPARE(playerStopSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); QCOMPARE(skipNextTrackSpy.wait(100), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); } void ManageAudioPlayerTest::playTrackAndskipNextTrack() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerError(QMediaPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); myPlayer.setPlayerStatus(QMediaPlayer::NoMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::NoMedia); QCOMPARE(skipNextTrackSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///2.mp3"))); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); myPlayer.setCurrentTrack(myPlayList.index(2, 0)); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(2, 0))); QCOMPARE(playerStopSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///3.mp3"))); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); QCOMPARE(skipNextTrackSpy.wait(100), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 9); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 3); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 5); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 3); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); } void ManageAudioPlayerTest::playTrackAndskipPreviousTrack() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///2.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerError(QMediaPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); myPlayer.setPlayerStatus(QMediaPlayer::NoMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::NoMedia); QCOMPARE(skipNextTrackSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(2, 0)); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(2, 0))); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///3.mp3"))); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); myPlayer.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); QCOMPARE(playerStopSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///2.mp3"))); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); QCOMPARE(skipNextTrackSpy.wait(100), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 9); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 3); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 5); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 3); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); } void ManageAudioPlayerTest::skipNextTrackAndPlayTrack() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerError(QMediaPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); myPlayer.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); QCOMPARE(playerStopSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///2.mp3"))); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); QCOMPARE(skipNextTrackSpy.wait(100), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); myPlayer.setPlayerStatus(QMediaPlayer::NoMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::NoMedia); QCOMPARE(skipNextTrackSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(2, 0)); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(2, 0))); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///3.mp3"))); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 9); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 3); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); } void ManageAudioPlayerTest::skipPreviousTrackAndPlayTrack() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///2.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerError(QMediaPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); QCOMPARE(playerStopSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); QCOMPARE(skipNextTrackSpy.wait(100), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); myPlayer.setPlayerStatus(QMediaPlayer::NoMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::NoMedia); QCOMPARE(skipNextTrackSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///2.mp3"))); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 9); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 3); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); } void ManageAudioPlayerTest::playLastCase() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setCurrentTrack(myPlayList.index(2, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(2, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///3.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerError(QMediaPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); myPlayer.setPlayerStatus(QMediaPlayer::NoMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::NoMedia); QCOMPARE(skipNextTrackSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.playListFinished(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); QCOMPARE(playerPlaySpy.wait(100), false); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); } void ManageAudioPlayerTest::playSingleAndClearPlayListTrack() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerError(QMediaPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); myPlayer.setCurrentTrack({}); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex{}); QCOMPARE(playerStopSpy.wait(300), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); QCOMPARE(playerPlaySpy.wait(300), false); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); } void ManageAudioPlayerTest::playSingleTrack() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerError(QMediaPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); myPlayer.setPlayerStatus(QMediaPlayer::NoMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::NoMedia); QCOMPARE(skipNextTrackSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.playListFinished(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); QCOMPARE(playerPlaySpy.wait(100), false); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); } void ManageAudioPlayerTest::playRestoredTrack() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerError(QMediaPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); } void ManageAudioPlayerTest::testRestoreSettingsAutomaticPlay() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy titleRoleChangedSpy(&myPlayer, &ManageAudioPlayer::titleRoleChanged); QSignalSpy artistNameRoleChangedSpy(&myPlayer, &ManageAudioPlayer::artistNameRoleChanged); QSignalSpy albumNameRoleChangedSpy(&myPlayer, &ManageAudioPlayer::albumNameRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(0, 0)->setData(QStringLiteral("title"), ManageAudioPlayerTest::TitleRole); myPlayList.item(0, 0)->setData(QStringLiteral("artist"), ManageAudioPlayerTest::ArtistRole); myPlayList.item(0, 0)->setData(QStringLiteral("album"), ManageAudioPlayerTest::AlbumRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setTitleRole(ManageAudioPlayerTest::TitleRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.titleRole(), static_cast(ManageAudioPlayerTest::ManageAudioPlayerTest::TitleRole)); myPlayer.setArtistNameRole(ManageAudioPlayerTest::ArtistRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.artistNameRole(), static_cast(ManageAudioPlayerTest::ManageAudioPlayerTest::ArtistRole)); myPlayer.setAlbumNameRole(ManageAudioPlayerTest::AlbumRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.albumNameRole(), static_cast(ManageAudioPlayerTest::ManageAudioPlayerTest::AlbumRole)); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QVariantMap settings; settings[QStringLiteral("isPlaying")] = true; settings[QStringLiteral("audioPlayerCurrentTitle")] = QStringLiteral("title"); settings[QStringLiteral("audioPlayerCurrentArtistName")] = QStringLiteral("artist"); settings[QStringLiteral("audioPlayerCurrentAlbumName")] = QStringLiteral("album"); myPlayer.setPersistentState(settings); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); QCOMPARE(playerPlaySpy.wait(500), false); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerError(QMediaPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); QCOMPARE(skipNextTrackSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerStatus(QMediaPlayer::InvalidMedia); QCOMPARE(skipNextTrackSpy.wait(150), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 2); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::InvalidMedia); } void ManageAudioPlayerTest::testRestoreSettingsNoAutomaticPlay() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy titleRoleChangedSpy(&myPlayer, &ManageAudioPlayer::titleRoleChanged); QSignalSpy artistNameRoleChangedSpy(&myPlayer, &ManageAudioPlayer::artistNameRoleChanged); QSignalSpy albumNameRoleChangedSpy(&myPlayer, &ManageAudioPlayer::albumNameRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(0, 0)->setData(QStringLiteral("title"), ManageAudioPlayerTest::TitleRole); myPlayList.item(0, 0)->setData(QStringLiteral("artist"), ManageAudioPlayerTest::ArtistRole); myPlayList.item(0, 0)->setData(QStringLiteral("album"), ManageAudioPlayerTest::AlbumRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QVariantMap settings; settings[QStringLiteral("isPlaying")] = false; settings[QStringLiteral("audioPlayerCurrentTitle")] = QStringLiteral("title"); settings[QStringLiteral("audioPlayerCurrentArtistName")] = QStringLiteral("artist"); settings[QStringLiteral("audioPlayerCurrentAlbumName")] = QStringLiteral("album"); myPlayer.setPersistentState(settings); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setTitleRole(ManageAudioPlayerTest::TitleRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.titleRole(), static_cast(ManageAudioPlayerTest::ManageAudioPlayerTest::TitleRole)); myPlayer.setArtistNameRole(ManageAudioPlayerTest::ArtistRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.artistNameRole(), static_cast(ManageAudioPlayerTest::ManageAudioPlayerTest::ArtistRole)); myPlayer.setAlbumNameRole(ManageAudioPlayerTest::AlbumRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.albumNameRole(), static_cast(ManageAudioPlayerTest::ManageAudioPlayerTest::AlbumRole)); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerError(QMediaPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); QCOMPARE(playerPlaySpy.wait(1000), false); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); } void ManageAudioPlayerTest::testRestoreSettingsAutomaticPlayAndPosition() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy titleRoleChangedSpy(&myPlayer, &ManageAudioPlayer::titleRoleChanged); QSignalSpy artistNameRoleChangedSpy(&myPlayer, &ManageAudioPlayer::artistNameRoleChanged); QSignalSpy albumNameRoleChangedSpy(&myPlayer, &ManageAudioPlayer::albumNameRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(0, 0)->setData(QStringLiteral("title"), ManageAudioPlayerTest::TitleRole); myPlayList.item(0, 0)->setData(QStringLiteral("artist"), ManageAudioPlayerTest::ArtistRole); myPlayList.item(0, 0)->setData(QStringLiteral("album"), ManageAudioPlayerTest::AlbumRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QVariantMap settings; settings[QStringLiteral("isPlaying")] = true; settings[QStringLiteral("audioPlayerCurrentTitle")] = QStringLiteral("title"); settings[QStringLiteral("audioPlayerCurrentArtistName")] = QStringLiteral("artist"); settings[QStringLiteral("audioPlayerCurrentAlbumName")] = QStringLiteral("album"); settings[QStringLiteral("playerPosition")] = 10000; myPlayer.setPersistentState(settings); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setTitleRole(ManageAudioPlayerTest::TitleRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.titleRole(), static_cast(ManageAudioPlayerTest::ManageAudioPlayerTest::TitleRole)); myPlayer.setArtistNameRole(ManageAudioPlayerTest::ArtistRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.artistNameRole(), static_cast(ManageAudioPlayerTest::ManageAudioPlayerTest::ArtistRole)); myPlayer.setAlbumNameRole(ManageAudioPlayerTest::AlbumRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(seekSpy.at(0).at(0).toInt(), 10000); QCOMPARE(myPlayer.albumNameRole(), static_cast(ManageAudioPlayerTest::ManageAudioPlayerTest::AlbumRole)); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerError(QMediaPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); myPlayer.setPlayerStatus(QMediaPlayer::NoMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::NoMedia); QCOMPARE(skipNextTrackSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); } void ManageAudioPlayerTest::playTrackPauseAndSkipNextTrack() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerError(QMediaPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(playerPauseSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PausedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PausedState)); myPlayer.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); QCOMPARE(playerStopSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///2.mp3"))); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); QCOMPARE(skipNextTrackSpy.wait(100), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); } void ManageAudioPlayerTest::testRestoreSettingsNoPlayWrongTrack() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy titleRoleChangedSpy(&myPlayer, &ManageAudioPlayer::titleRoleChanged); QSignalSpy artistNameRoleChangedSpy(&myPlayer, &ManageAudioPlayer::artistNameRoleChanged); QSignalSpy albumNameRoleChangedSpy(&myPlayer, &ManageAudioPlayer::albumNameRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(0, 0)->setData(QStringLiteral("title"), ManageAudioPlayerTest::TitleRole); myPlayList.item(0, 0)->setData(QStringLiteral("artist"), ManageAudioPlayerTest::ArtistRole); myPlayList.item(0, 0)->setData(QStringLiteral("album"), ManageAudioPlayerTest::AlbumRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QStringLiteral("title2"), ManageAudioPlayerTest::TitleRole); myPlayList.item(1, 0)->setData(QStringLiteral("artist2"), ManageAudioPlayerTest::ArtistRole); myPlayList.item(1, 0)->setData(QStringLiteral("album2"), ManageAudioPlayerTest::AlbumRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setTitleRole(ManageAudioPlayerTest::TitleRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.titleRole(), static_cast(ManageAudioPlayerTest::ManageAudioPlayerTest::TitleRole)); myPlayer.setArtistNameRole(ManageAudioPlayerTest::ArtistRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.artistNameRole(), static_cast(ManageAudioPlayerTest::ManageAudioPlayerTest::ArtistRole)); myPlayer.setAlbumNameRole(ManageAudioPlayerTest::AlbumRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.albumNameRole(), static_cast(ManageAudioPlayerTest::ManageAudioPlayerTest::AlbumRole)); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QVariantMap settings; settings[QStringLiteral("isPlaying")] = true; settings[QStringLiteral("audioPlayerCurrentTitle")] = QStringLiteral("title"); settings[QStringLiteral("audioPlayerCurrentArtistName")] = QStringLiteral("artist"); settings[QStringLiteral("audioPlayerCurrentAlbumName")] = QStringLiteral("album"); myPlayer.setPersistentState(settings); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///2.mp3"))); QCOMPARE(playerPlaySpy.wait(500), false); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerError(QMediaPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); QCOMPARE(playerPlaySpy.wait(500), false); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); } void ManageAudioPlayerTest::testRestorePlayListAndSettingsAutomaticPlay() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy titleRoleChangedSpy(&myPlayer, &ManageAudioPlayer::titleRoleChanged); QSignalSpy artistNameRoleChangedSpy(&myPlayer, &ManageAudioPlayer::artistNameRoleChanged); QSignalSpy albumNameRoleChangedSpy(&myPlayer, &ManageAudioPlayer::albumNameRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QStringLiteral("title"), ManageAudioPlayerTest::TitleRole); myPlayList.item(0, 0)->setData(QStringLiteral("artist"), ManageAudioPlayerTest::ArtistRole); myPlayList.item(0, 0)->setData(QStringLiteral("album"), ManageAudioPlayerTest::AlbumRole); myPlayList.item(1, 0)->setData(QStringLiteral("title2"), ManageAudioPlayerTest::TitleRole); myPlayList.item(1, 0)->setData(QStringLiteral("artist2"), ManageAudioPlayerTest::ArtistRole); myPlayList.item(1, 0)->setData(QStringLiteral("album2"), ManageAudioPlayerTest::AlbumRole); myPlayList.item(2, 0)->setData(QStringLiteral("title3"), ManageAudioPlayerTest::TitleRole); myPlayList.item(2, 0)->setData(QStringLiteral("artist3"), ManageAudioPlayerTest::ArtistRole); myPlayList.item(2, 0)->setData(QStringLiteral("album3"), ManageAudioPlayerTest::AlbumRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setTitleRole(ManageAudioPlayerTest::TitleRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 0); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.titleRole(), static_cast(ManageAudioPlayerTest::ManageAudioPlayerTest::TitleRole)); myPlayer.setArtistNameRole(ManageAudioPlayerTest::ArtistRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.artistNameRole(), static_cast(ManageAudioPlayerTest::ManageAudioPlayerTest::ArtistRole)); myPlayer.setAlbumNameRole(ManageAudioPlayerTest::AlbumRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.albumNameRole(), static_cast(ManageAudioPlayerTest::ManageAudioPlayerTest::AlbumRole)); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QVariantMap settings; settings[QStringLiteral("isPlaying")] = true; settings[QStringLiteral("audioPlayerCurrentTitle")] = QStringLiteral("title"); settings[QStringLiteral("audioPlayerCurrentArtistName")] = QStringLiteral("artist"); settings[QStringLiteral("audioPlayerCurrentAlbumName")] = QStringLiteral("album"); myPlayer.setPersistentState(settings); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(playerPlaySpy.wait(500), false); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setPlayerStatus(QMediaPlayer::LoadingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadingMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerError(QMediaPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerStatus(QMediaPlayer::LoadedMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::LoadedMedia); myPlayer.setPlayerStatus(QMediaPlayer::BufferingMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::BufferingMedia); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(QMediaPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::EndOfMedia); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); QCOMPARE(skipNextTrackSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerStatus(QMediaPlayer::InvalidMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(artistNameRoleChangedSpy.count(), 1); QCOMPARE(albumNameRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), QMediaPlayer::InvalidMedia); QCOMPARE(skipNextTrackSpy.wait(300), true); } QTEST_GUILESS_MAIN(ManageAudioPlayerTest) #include "moc_manageaudioplayertest.cpp" diff --git a/autotests/manageaudioplayertest.h b/autotests/manageaudioplayertest.h index bfcd17b8..28b0b4cc 100644 --- a/autotests/manageaudioplayertest.h +++ b/autotests/manageaudioplayertest.h @@ -1,98 +1,96 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef MANAGEAUDIOPLAYERTEST_H #define MANAGEAUDIOPLAYERTEST_H #include class ManageAudioPlayerTest : public QObject { Q_OBJECT public: enum ColumnsRoles { IsValidRole = Qt::UserRole + 1, TitleRole = IsValidRole + 1, DurationRole = TitleRole + 1, MilliSecondsDurationRole = DurationRole + 1, CreatorRole = MilliSecondsDurationRole + 1, ArtistRole = CreatorRole + 1, AlbumRole = ArtistRole + 1, TrackNumberRole = AlbumRole + 1, RatingRole = TrackNumberRole + 1, ImageRole = RatingRole + 1, ResourceRole = ImageRole + 1, CountRole = ResourceRole + 1, IsPlayingRole = CountRole + 1, }; Q_ENUM(ColumnsRoles) explicit ManageAudioPlayerTest(QObject *parent = nullptr); Q_SIGNALS: private Q_SLOTS: void initTestCase(); void simpleInitialCase(); void noPlayCase(); void skipNextTrack(); void skipNextTrackWithRandomPlay(); void skipPreviousTrack(); void playTrackAndskipNextTrack(); void playTrackAndskipPreviousTrack(); void skipNextTrackAndPlayTrack(); void skipPreviousTrackAndPlayTrack(); void playLastCase(); void playSingleTrack(); void playRestoredTrack(); void testRestoreSettingsAutomaticPlay(); void testRestoreSettingsNoAutomaticPlay(); void testRestoreSettingsAutomaticPlayAndPosition(); void playTrackPauseAndSkipNextTrack(); void testRestoreSettingsNoPlayWrongTrack(); void testRestorePlayListAndSettingsAutomaticPlay(); void playSingleAndClearPlayListTrack(); }; #endif // MANAGEAUDIOPLAYERTEST_H diff --git a/autotests/manageheaderbartest.cpp b/autotests/manageheaderbartest.cpp index 85daf13b..1dc5e0aa 100644 --- a/autotests/manageheaderbartest.cpp +++ b/autotests/manageheaderbartest.cpp @@ -1,2764 +1,2762 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "manageheaderbartest.h" #include "manageheaderbar.h" #include "mediaplaylist.h" #include "databaseinterface.h" #include "trackslistener.h" #include #include #include #include #include #include #include #include #include #include ManageHeaderBarTest::ManageHeaderBarTest(QObject *parent) : QObject(parent) { } void ManageHeaderBarTest::initTestCase() { qRegisterMetaType>("QHash"); qRegisterMetaType>("QVector"); qRegisterMetaType>("QHash"); } void ManageHeaderBarTest::simpleInitialCase() { ManageHeaderBar myControl; QCOMPARE(myControl.currentTrack().isValid(), false); QCOMPARE(myControl.playListModel(), static_cast(nullptr)); QCOMPARE(myControl.artistRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.titleRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.imageRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumIdRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.isValidRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.artist().toString().isEmpty(), true); QCOMPARE(myControl.title().toString().isEmpty(), true); QCOMPARE(myControl.album().toString().isEmpty(), true); QCOMPARE(myControl.image().toString().isEmpty(), true); QCOMPARE(myControl.isValid(), false); QCOMPARE(myControl.remainingTracks(), 0); } void ManageHeaderBarTest::setCurrentTrackCase() { QStringListModel myPlayList; ManageHeaderBar myControl; QSignalSpy currentTrackChangedSpy(&myControl, &ManageHeaderBar::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myControl, &ManageHeaderBar::playListModelChanged); QSignalSpy artistRoleChangedSpy(&myControl, &ManageHeaderBar::artistRoleChanged); QSignalSpy titleRoleChangedSpy(&myControl, &ManageHeaderBar::titleRoleChanged); QSignalSpy albumRoleChangedSpy(&myControl, &ManageHeaderBar::albumRoleChanged); QSignalSpy imageRoleChangedSpy(&myControl, &ManageHeaderBar::imageRoleChanged); QSignalSpy albumIdRoleChangedSpy(&myControl, &ManageHeaderBar::albumIdRoleChanged); QSignalSpy isValidRoleChangedSpy(&myControl, &ManageHeaderBar::isValidRoleChanged); QSignalSpy artistChangedSpy(&myControl, &ManageHeaderBar::artistChanged); QSignalSpy titleChangedSpy(&myControl, &ManageHeaderBar::titleChanged); QSignalSpy albumChangedSpy(&myControl, &ManageHeaderBar::albumChanged); QSignalSpy imageChangedSpy(&myControl, &ManageHeaderBar::imageChanged); QSignalSpy albumIdChangedSpy(&myControl, &ManageHeaderBar::albumIdChanged); QSignalSpy isValidChangedSpy(&myControl, &ManageHeaderBar::isValidChanged); QSignalSpy remainingTracksChangedSpy(&myControl, &ManageHeaderBar::remainingTracksChanged); QCOMPARE(myControl.currentTrack().isValid(), false); QCOMPARE(myControl.playListModel(), static_cast(nullptr)); QCOMPARE(myControl.artistRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.titleRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.imageRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumIdRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.isValidRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.artist().toString().isEmpty(), true); QCOMPARE(myControl.title().toString().isEmpty(), true); QCOMPARE(myControl.album().toString().isEmpty(), true); QCOMPARE(myControl.image().toString().isEmpty(), true); QCOMPARE(myControl.isValid(), false); QCOMPARE(myControl.remainingTracks(), 0); myControl.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.playListModel(), &myPlayList); QCOMPARE(myPlayList.insertRows(0, 3), true); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); myControl.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 1); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); } void ManageHeaderBarTest::setCurrentTrackCaseFromNewAlbum() { QStringListModel myPlayList; ManageHeaderBar myControl; QSignalSpy currentTrackChangedSpy(&myControl, &ManageHeaderBar::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myControl, &ManageHeaderBar::playListModelChanged); QSignalSpy artistRoleChangedSpy(&myControl, &ManageHeaderBar::artistRoleChanged); QSignalSpy titleRoleChangedSpy(&myControl, &ManageHeaderBar::titleRoleChanged); QSignalSpy albumRoleChangedSpy(&myControl, &ManageHeaderBar::albumRoleChanged); QSignalSpy imageRoleChangedSpy(&myControl, &ManageHeaderBar::imageRoleChanged); QSignalSpy albumIdRoleChangedSpy(&myControl, &ManageHeaderBar::albumIdRoleChanged); QSignalSpy isValidRoleChangedSpy(&myControl, &ManageHeaderBar::isValidRoleChanged); QSignalSpy artistChangedSpy(&myControl, &ManageHeaderBar::artistChanged); QSignalSpy titleChangedSpy(&myControl, &ManageHeaderBar::titleChanged); QSignalSpy albumChangedSpy(&myControl, &ManageHeaderBar::albumChanged); QSignalSpy imageChangedSpy(&myControl, &ManageHeaderBar::imageChanged); QSignalSpy albumIdChangedSpy(&myControl, &ManageHeaderBar::albumIdChanged); QSignalSpy isValidChangedSpy(&myControl, &ManageHeaderBar::isValidChanged); QSignalSpy remainingTracksChangedSpy(&myControl, &ManageHeaderBar::remainingTracksChanged); QCOMPARE(myControl.currentTrack().isValid(), false); QCOMPARE(myControl.playListModel(), static_cast(nullptr)); QCOMPARE(myControl.artistRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.titleRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.imageRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumIdRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.isValidRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.artist().toString().isEmpty(), true); QCOMPARE(myControl.title().toString().isEmpty(), true); QCOMPARE(myControl.album().toString().isEmpty(), true); QCOMPARE(myControl.image().toString().isEmpty(), true); QCOMPARE(myControl.isValid(), false); QCOMPARE(myControl.remainingTracks(), 0); myControl.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.playListModel(), &myPlayList); QCOMPARE(myPlayList.insertRows(0, 1), true); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); myControl.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 1); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); } void ManageHeaderBarTest::completeCase() { QStandardItemModel myPlayList; ManageHeaderBar myControl; QSignalSpy currentTrackChangedSpy(&myControl, &ManageHeaderBar::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myControl, &ManageHeaderBar::playListModelChanged); QSignalSpy artistRoleChangedSpy(&myControl, &ManageHeaderBar::artistRoleChanged); QSignalSpy titleRoleChangedSpy(&myControl, &ManageHeaderBar::titleRoleChanged); QSignalSpy albumRoleChangedSpy(&myControl, &ManageHeaderBar::albumRoleChanged); QSignalSpy imageRoleChangedSpy(&myControl, &ManageHeaderBar::imageRoleChanged); QSignalSpy albumIdRoleChangedSpy(&myControl, &ManageHeaderBar::albumIdRoleChanged); QSignalSpy isValidRoleChangedSpy(&myControl, &ManageHeaderBar::isValidRoleChanged); QSignalSpy artistChangedSpy(&myControl, &ManageHeaderBar::artistChanged); QSignalSpy titleChangedSpy(&myControl, &ManageHeaderBar::titleChanged); QSignalSpy albumChangedSpy(&myControl, &ManageHeaderBar::albumChanged); QSignalSpy imageChangedSpy(&myControl, &ManageHeaderBar::imageChanged); QSignalSpy albumIdChangedSpy(&myControl, &ManageHeaderBar::albumIdChanged); QSignalSpy isValidChangedSpy(&myControl, &ManageHeaderBar::isValidChanged); QSignalSpy remainingTracksChangedSpy(&myControl, &ManageHeaderBar::remainingTracksChanged); QCOMPARE(myControl.currentTrack().isValid(), false); QCOMPARE(myControl.playListModel(), static_cast(nullptr)); QCOMPARE(myControl.artistRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.titleRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.imageRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumIdRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.isValidRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.artist().toString().isEmpty(), true); QCOMPARE(myControl.title().toString().isEmpty(), true); QCOMPARE(myControl.album().toString().isEmpty(), true); QCOMPARE(myControl.image().toString().isEmpty(), true); QCOMPARE(myControl.isValid(), false); QCOMPARE(myControl.remainingTracks(), 0); myControl.setArtistRole(ManageHeaderBarTest::ArtistRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.artistRole(), static_cast(ManageHeaderBarTest::ArtistRole)); myControl.setTitleRole(ManageHeaderBarTest::TitleRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.titleRole(), static_cast(ManageHeaderBarTest::TitleRole)); myControl.setAlbumRole(ManageHeaderBarTest::AlbumRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.albumRole(), static_cast(ManageHeaderBarTest::AlbumRole)); myControl.setImageRole(ManageHeaderBarTest::ImageRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.imageRole(), static_cast(ManageHeaderBarTest::ImageRole)); myControl.setAlbumIdRole(ManageHeaderBarTest::AlbumIdRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.albumIdRole(), static_cast(ManageHeaderBarTest::AlbumIdRole)); myControl.setIsValidRole(ManageHeaderBarTest::IsValidRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.isValidRole(), static_cast(ManageHeaderBarTest::IsValidRole)); myControl.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.playListModel(), &myPlayList); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); myControl.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); QCOMPARE(myControl.remainingTracks(), 1); auto firstItem = myPlayList.item(0, 0); firstItem->setData(QUrl::fromUserInput(QStringLiteral("file://0.mp3")), ManageHeaderBarTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 1); auto currentItem = myPlayList.item(1, 0); currentItem->setData(QStringLiteral("artist1"), ManageHeaderBarTest::ArtistRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.artist(), QVariant(QStringLiteral("artist1"))); currentItem->setData(QStringLiteral("song1"), ManageHeaderBarTest::TitleRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.title(), QVariant(QStringLiteral("song1"))); currentItem->setData(QStringLiteral("album1"), ManageHeaderBarTest::AlbumRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.album(), QVariant(QStringLiteral("album1"))); currentItem->setData(QUrl::fromUserInput(QStringLiteral("file://image.png")), ManageHeaderBarTest::ImageRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 1); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.image(), QUrl::fromUserInput(QStringLiteral("file://image.png"))); currentItem->setData(qulonglong(12), ManageHeaderBarTest::AlbumIdRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 1); QCOMPARE(albumIdChangedSpy.count(), 1); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.albumId(), 12); currentItem->setData(true, ManageHeaderBarTest::IsValidRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 1); QCOMPARE(albumIdChangedSpy.count(), 1); QCOMPARE(isValidChangedSpy.count(), 1); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.isValid(), true); QCOMPARE(myPlayList.removeRow(2), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 1); QCOMPARE(albumIdChangedSpy.count(), 1); QCOMPARE(isValidChangedSpy.count(), 1); QCOMPARE(remainingTracksChangedSpy.count(), 2); QCOMPARE(myControl.remainingTracks(), 0); myControl.setCurrentTrack({}); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 2); QCOMPARE(titleChangedSpy.count(), 2); QCOMPARE(albumChangedSpy.count(), 2); QCOMPARE(imageChangedSpy.count(), 2); QCOMPARE(albumIdChangedSpy.count(), 2); QCOMPARE(isValidChangedSpy.count(), 2); QCOMPARE(remainingTracksChangedSpy.count(), 2); QCOMPARE(myControl.currentTrack(), QPersistentModelIndex()); QCOMPARE(myControl.artist().toString().isEmpty(), true); QCOMPARE(myControl.title().toString().isEmpty(), true); QCOMPARE(myControl.album().toString().isEmpty(), true); QCOMPARE(myControl.image().toString().isEmpty(), true); QCOMPARE(myControl.albumId(), 0); QCOMPARE(myControl.isValid(), false); QCOMPARE(myControl.remainingTracks(), 0); myControl.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 3); QCOMPARE(titleChangedSpy.count(), 3); QCOMPARE(albumChangedSpy.count(), 3); QCOMPARE(imageChangedSpy.count(), 3); QCOMPARE(albumIdChangedSpy.count(), 3); QCOMPARE(isValidChangedSpy.count(), 3); QCOMPARE(remainingTracksChangedSpy.count(), 2); QCOMPARE(myControl.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); QCOMPARE(myControl.artist().toString(), QStringLiteral("artist1")); QCOMPARE(myControl.title().toString(), QStringLiteral("song1")); QCOMPARE(myControl.album().toString(), QStringLiteral("album1")); QCOMPARE(myControl.image().toString(), QStringLiteral("file://image.png")); QCOMPARE(myControl.isValid(), true); QCOMPARE(myControl.remainingTracks(), 0); myPlayList.appendRow(new QStandardItem); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 3); QCOMPARE(titleChangedSpy.count(), 3); QCOMPARE(albumChangedSpy.count(), 3); QCOMPARE(imageChangedSpy.count(), 3); QCOMPARE(albumIdChangedSpy.count(), 3); QCOMPARE(isValidChangedSpy.count(), 3); QCOMPARE(remainingTracksChangedSpy.count(), 3); QCOMPARE(myControl.remainingTracks(), 1); auto lastItem = myPlayList.item(2, 0); lastItem->setData(QUrl::fromUserInput(QStringLiteral("file://2.mp3")), ManageHeaderBarTest::ResourceRole); lastItem->setData(QStringLiteral("artist1"), ManageHeaderBarTest::ArtistRole); lastItem->setData(QStringLiteral("song2"), ManageHeaderBarTest::TitleRole); lastItem->setData(QStringLiteral("album1"), ManageHeaderBarTest::AlbumRole); lastItem->setData(QUrl::fromUserInput(QStringLiteral("file://image.png")), ManageHeaderBarTest::ImageRole); lastItem->setData(qulonglong(12), ManageHeaderBarTest::AlbumIdRole); lastItem->setData(true, ManageHeaderBarTest::IsValidRole); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 3); QCOMPARE(titleChangedSpy.count(), 3); QCOMPARE(albumChangedSpy.count(), 3); QCOMPARE(imageChangedSpy.count(), 3); QCOMPARE(albumIdChangedSpy.count(), 3); QCOMPARE(isValidChangedSpy.count(), 3); QCOMPARE(remainingTracksChangedSpy.count(), 3); myControl.setCurrentTrack(myPlayList.index(2, 0)); QCOMPARE(currentTrackChangedSpy.count(), 4); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 3); QCOMPARE(titleChangedSpy.count(), 4); QCOMPARE(albumChangedSpy.count(), 3); QCOMPARE(imageChangedSpy.count(), 3); QCOMPARE(albumIdChangedSpy.count(), 3); QCOMPARE(isValidChangedSpy.count(), 3); QCOMPARE(remainingTracksChangedSpy.count(), 4); QCOMPARE(myControl.currentTrack(), QPersistentModelIndex(myPlayList.index(2, 0))); QCOMPARE(myControl.title().toString(), QStringLiteral("song2")); QCOMPARE(myControl.albumId(), 12); QCOMPARE(myControl.remainingTracks(), 0); } void ManageHeaderBarTest::setCurrentTrackAndInvalidCase() { QStandardItemModel myPlayList; ManageHeaderBar myControl; QSignalSpy currentTrackChangedSpy(&myControl, &ManageHeaderBar::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myControl, &ManageHeaderBar::playListModelChanged); QSignalSpy artistRoleChangedSpy(&myControl, &ManageHeaderBar::artistRoleChanged); QSignalSpy titleRoleChangedSpy(&myControl, &ManageHeaderBar::titleRoleChanged); QSignalSpy albumRoleChangedSpy(&myControl, &ManageHeaderBar::albumRoleChanged); QSignalSpy imageRoleChangedSpy(&myControl, &ManageHeaderBar::imageRoleChanged); QSignalSpy albumIdRoleChangedSpy(&myControl, &ManageHeaderBar::albumIdRoleChanged); QSignalSpy isValidRoleChangedSpy(&myControl, &ManageHeaderBar::isValidRoleChanged); QSignalSpy artistChangedSpy(&myControl, &ManageHeaderBar::artistChanged); QSignalSpy titleChangedSpy(&myControl, &ManageHeaderBar::titleChanged); QSignalSpy albumChangedSpy(&myControl, &ManageHeaderBar::albumChanged); QSignalSpy imageChangedSpy(&myControl, &ManageHeaderBar::imageChanged); QSignalSpy albumIdChangedSpy(&myControl, &ManageHeaderBar::albumIdChanged); QSignalSpy isValidChangedSpy(&myControl, &ManageHeaderBar::isValidChanged); QSignalSpy remainingTracksChangedSpy(&myControl, &ManageHeaderBar::remainingTracksChanged); QCOMPARE(myControl.currentTrack().isValid(), false); QCOMPARE(myControl.playListModel(), static_cast(nullptr)); QCOMPARE(myControl.artistRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.titleRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.imageRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumIdRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.isValidRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.artist().toString().isEmpty(), true); QCOMPARE(myControl.title().toString().isEmpty(), true); QCOMPARE(myControl.album().toString().isEmpty(), true); QCOMPARE(myControl.image().toString().isEmpty(), true); QCOMPARE(myControl.isValid(), false); QCOMPARE(myControl.remainingTracks(), 0); myControl.setArtistRole(ManageHeaderBarTest::ArtistRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.artistRole(), static_cast(ManageHeaderBarTest::ArtistRole)); myControl.setTitleRole(ManageHeaderBarTest::TitleRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.titleRole(), static_cast(ManageHeaderBarTest::TitleRole)); myControl.setAlbumRole(ManageHeaderBarTest::AlbumRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.albumRole(), static_cast(ManageHeaderBarTest::AlbumRole)); myControl.setImageRole(ManageHeaderBarTest::ImageRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.imageRole(), static_cast(ManageHeaderBarTest::ImageRole)); myControl.setAlbumIdRole(ManageHeaderBarTest::AlbumIdRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.albumIdRole(), static_cast(ManageHeaderBarTest::AlbumIdRole)); myControl.setIsValidRole(ManageHeaderBarTest::IsValidRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.isValidRole(), static_cast(ManageHeaderBarTest::IsValidRole)); myControl.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.playListModel(), &myPlayList); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); myControl.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); QCOMPARE(myControl.remainingTracks(), 1); auto firstItem = myPlayList.item(0, 0); firstItem->setData(QUrl::fromUserInput(QStringLiteral("file://0.mp3")), ManageHeaderBarTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 1); auto currentItem = myPlayList.item(1, 0); currentItem->setData(QStringLiteral("artist1"), ManageHeaderBarTest::ArtistRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.artist(), QVariant(QStringLiteral("artist1"))); currentItem->setData(QStringLiteral("song1"), ManageHeaderBarTest::TitleRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.title(), QVariant(QStringLiteral("song1"))); currentItem->setData(QStringLiteral("album1"), ManageHeaderBarTest::AlbumRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.album(), QVariant(QStringLiteral("album1"))); currentItem->setData(QUrl::fromUserInput(QStringLiteral("file://image.png")), ManageHeaderBarTest::ImageRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 1); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.image(), QUrl::fromUserInput(QStringLiteral("file://image.png"))); currentItem->setData(qulonglong(12), ManageHeaderBarTest::AlbumIdRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 1); QCOMPARE(albumIdChangedSpy.count(), 1); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.albumId(), qulonglong(12)); currentItem->setData(true, ManageHeaderBarTest::IsValidRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 1); QCOMPARE(albumIdChangedSpy.count(), 1); QCOMPARE(isValidChangedSpy.count(), 1); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.isValid(), true); QCOMPARE(myPlayList.removeRow(2), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 1); QCOMPARE(albumIdChangedSpy.count(), 1); QCOMPARE(isValidChangedSpy.count(), 1); QCOMPARE(remainingTracksChangedSpy.count(), 2); QCOMPARE(myControl.remainingTracks(), 0); QCOMPARE(myPlayList.removeRows(0, 2), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 2); QCOMPARE(titleChangedSpy.count(), 2); QCOMPARE(albumChangedSpy.count(), 2); QCOMPARE(imageChangedSpy.count(), 2); QCOMPARE(albumIdChangedSpy.count(), 2); QCOMPARE(isValidChangedSpy.count(), 2); QCOMPARE(remainingTracksChangedSpy.count(), 2); QCOMPARE(myControl.artist().toString().isEmpty(), true); QCOMPARE(myControl.title().toString().isEmpty(), true); QCOMPARE(myControl.album().toString().isEmpty(), true); QCOMPARE(myControl.image().toString().isEmpty(), true); QCOMPARE(myControl.isValid(), false); QCOMPARE(myControl.remainingTracks(), 0); } void ManageHeaderBarTest::setCurrentTrackAndRemoveItCase() { QStandardItemModel myPlayList; ManageHeaderBar myControl; QSignalSpy currentTrackChangedSpy(&myControl, &ManageHeaderBar::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myControl, &ManageHeaderBar::playListModelChanged); QSignalSpy artistRoleChangedSpy(&myControl, &ManageHeaderBar::artistRoleChanged); QSignalSpy titleRoleChangedSpy(&myControl, &ManageHeaderBar::titleRoleChanged); QSignalSpy albumRoleChangedSpy(&myControl, &ManageHeaderBar::albumRoleChanged); QSignalSpy imageRoleChangedSpy(&myControl, &ManageHeaderBar::imageRoleChanged); QSignalSpy albumIdRoleChangedSpy(&myControl, &ManageHeaderBar::albumIdRoleChanged); QSignalSpy isValidRoleChangedSpy(&myControl, &ManageHeaderBar::isValidRoleChanged); QSignalSpy artistChangedSpy(&myControl, &ManageHeaderBar::artistChanged); QSignalSpy titleChangedSpy(&myControl, &ManageHeaderBar::titleChanged); QSignalSpy albumChangedSpy(&myControl, &ManageHeaderBar::albumChanged); QSignalSpy imageChangedSpy(&myControl, &ManageHeaderBar::imageChanged); QSignalSpy albumIdChangedSpy(&myControl, &ManageHeaderBar::albumIdChanged); QSignalSpy isValidChangedSpy(&myControl, &ManageHeaderBar::isValidChanged); QSignalSpy remainingTracksChangedSpy(&myControl, &ManageHeaderBar::remainingTracksChanged); QCOMPARE(myControl.currentTrack().isValid(), false); QCOMPARE(myControl.playListModel(), static_cast(nullptr)); QCOMPARE(myControl.artistRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.titleRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.imageRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumIdRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.isValidRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.artist().toString().isEmpty(), true); QCOMPARE(myControl.title().toString().isEmpty(), true); QCOMPARE(myControl.album().toString().isEmpty(), true); QCOMPARE(myControl.image().toString().isEmpty(), true); QCOMPARE(myControl.isValid(), false); QCOMPARE(myControl.remainingTracks(), 0); myControl.setArtistRole(ManageHeaderBarTest::ArtistRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.artistRole(), static_cast(ManageHeaderBarTest::ArtistRole)); myControl.setTitleRole(ManageHeaderBarTest::TitleRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.titleRole(), static_cast(ManageHeaderBarTest::TitleRole)); myControl.setAlbumRole(ManageHeaderBarTest::AlbumRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.albumRole(), static_cast(ManageHeaderBarTest::AlbumRole)); myControl.setImageRole(ManageHeaderBarTest::ImageRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.imageRole(), static_cast(ManageHeaderBarTest::ImageRole)); myControl.setAlbumIdRole(ManageHeaderBarTest::AlbumIdRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.albumIdRole(), static_cast(ManageHeaderBarTest::AlbumIdRole)); myControl.setIsValidRole(ManageHeaderBarTest::IsValidRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.isValidRole(), static_cast(ManageHeaderBarTest::IsValidRole)); myControl.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.playListModel(), &myPlayList); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); auto firstItem = myPlayList.item(0, 0); firstItem->setData(QUrl::fromUserInput(QStringLiteral("file://0.mp3")), ManageHeaderBarTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); firstItem->setData(QStringLiteral("artist1"), ManageHeaderBarTest::ArtistRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); firstItem->setData(QStringLiteral("song1"), ManageHeaderBarTest::TitleRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); firstItem->setData(QStringLiteral("album1"), ManageHeaderBarTest::AlbumRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); firstItem->setData(QUrl::fromUserInput(QStringLiteral("file://image.png")), ManageHeaderBarTest::ImageRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); firstItem->setData(true, ManageHeaderBarTest::IsValidRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); myControl.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 1); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 1); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); QCOMPARE(myControl.remainingTracks(), 1); QCOMPARE(myControl.isValid(), true); QCOMPARE(myControl.image(), QUrl::fromUserInput(QStringLiteral("file://image.png"))); QCOMPARE(myControl.album(), QVariant(QStringLiteral("album1"))); QCOMPARE(myControl.artist(), QVariant(QStringLiteral("artist1"))); QCOMPARE(myControl.title(), QVariant(QStringLiteral("song1"))); QCOMPARE(myPlayList.removeRow(0), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 2); QCOMPARE(titleChangedSpy.count(), 2); QCOMPARE(albumChangedSpy.count(), 2); QCOMPARE(imageChangedSpy.count(), 2); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 2); QCOMPARE(remainingTracksChangedSpy.count(), 2); QCOMPARE(myControl.artist().toString().isEmpty(), true); QCOMPARE(myControl.title().toString().isEmpty(), true); QCOMPARE(myControl.album().toString().isEmpty(), true); QCOMPARE(myControl.image().toString().isEmpty(), true); QCOMPARE(myControl.isValid(), false); QCOMPARE(myControl.remainingTracks(), 0); } void ManageHeaderBarTest::insertBeforeCurrentTrack() { QStandardItemModel myPlayList; ManageHeaderBar myControl; QSignalSpy currentTrackChangedSpy(&myControl, &ManageHeaderBar::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myControl, &ManageHeaderBar::playListModelChanged); QSignalSpy artistRoleChangedSpy(&myControl, &ManageHeaderBar::artistRoleChanged); QSignalSpy titleRoleChangedSpy(&myControl, &ManageHeaderBar::titleRoleChanged); QSignalSpy albumRoleChangedSpy(&myControl, &ManageHeaderBar::albumRoleChanged); QSignalSpy imageRoleChangedSpy(&myControl, &ManageHeaderBar::imageRoleChanged); QSignalSpy albumIdRoleChangedSpy(&myControl, &ManageHeaderBar::albumIdRoleChanged); QSignalSpy isValidRoleChangedSpy(&myControl, &ManageHeaderBar::isValidRoleChanged); QSignalSpy artistChangedSpy(&myControl, &ManageHeaderBar::artistChanged); QSignalSpy titleChangedSpy(&myControl, &ManageHeaderBar::titleChanged); QSignalSpy albumChangedSpy(&myControl, &ManageHeaderBar::albumChanged); QSignalSpy imageChangedSpy(&myControl, &ManageHeaderBar::imageChanged); QSignalSpy albumIdChangedSpy(&myControl, &ManageHeaderBar::albumIdChanged); QSignalSpy isValidChangedSpy(&myControl, &ManageHeaderBar::isValidChanged); QSignalSpy remainingTracksChangedSpy(&myControl, &ManageHeaderBar::remainingTracksChanged); QCOMPARE(myControl.currentTrack().isValid(), false); QCOMPARE(myControl.playListModel(), static_cast(nullptr)); QCOMPARE(myControl.artistRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.titleRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.imageRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumIdRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.isValidRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.artist().toString().isEmpty(), true); QCOMPARE(myControl.title().toString().isEmpty(), true); QCOMPARE(myControl.album().toString().isEmpty(), true); QCOMPARE(myControl.image().toString().isEmpty(), true); QCOMPARE(myControl.isValid(), false); QCOMPARE(myControl.remainingTracks(), 0); myControl.setArtistRole(ManageHeaderBarTest::ArtistRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.artistRole(), static_cast(ManageHeaderBarTest::ArtistRole)); myControl.setTitleRole(ManageHeaderBarTest::TitleRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.titleRole(), static_cast(ManageHeaderBarTest::TitleRole)); myControl.setAlbumRole(ManageHeaderBarTest::AlbumRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.albumRole(), static_cast(ManageHeaderBarTest::AlbumRole)); myControl.setImageRole(ManageHeaderBarTest::ImageRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.imageRole(), static_cast(ManageHeaderBarTest::ImageRole)); myControl.setAlbumIdRole(ManageHeaderBarTest::AlbumIdRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.albumIdRole(), static_cast(ManageHeaderBarTest::AlbumIdRole)); myControl.setIsValidRole(ManageHeaderBarTest::IsValidRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.isValidRole(), static_cast(ManageHeaderBarTest::IsValidRole)); myControl.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.playListModel(), &myPlayList); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); auto firstItem = myPlayList.item(0, 0); firstItem->setData(QUrl::fromUserInput(QStringLiteral("file://0.mp3")), ManageHeaderBarTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); firstItem->setData(QStringLiteral("artist1"), ManageHeaderBarTest::ArtistRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); firstItem->setData(QStringLiteral("song1"), ManageHeaderBarTest::TitleRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); firstItem->setData(QStringLiteral("album1"), ManageHeaderBarTest::AlbumRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); firstItem->setData(QUrl::fromUserInput(QStringLiteral("file://image.png")), ManageHeaderBarTest::ImageRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); firstItem->setData(true, ManageHeaderBarTest::IsValidRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); myControl.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 1); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 1); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); QCOMPARE(myControl.remainingTracks(), 1); QCOMPARE(myControl.isValid(), true); QCOMPARE(myControl.image(), QUrl::fromUserInput(QStringLiteral("file://image.png"))); QCOMPARE(myControl.album(), QVariant(QStringLiteral("album1"))); QCOMPARE(myControl.artist(), QVariant(QStringLiteral("artist1"))); QCOMPARE(myControl.title(), QVariant(QStringLiteral("song1"))); myPlayList.insertRow(0, new QStandardItem); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 1); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 1); QCOMPARE(remainingTracksChangedSpy.count(), 1); } void ManageHeaderBarTest::moveCurrentTrack() { MediaPlayList myPlayList; DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); ManageHeaderBar myControl; QSignalSpy currentTrackChangedSpy(&myControl, &ManageHeaderBar::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myControl, &ManageHeaderBar::playListModelChanged); QSignalSpy artistRoleChangedSpy(&myControl, &ManageHeaderBar::artistRoleChanged); QSignalSpy titleRoleChangedSpy(&myControl, &ManageHeaderBar::titleRoleChanged); QSignalSpy albumRoleChangedSpy(&myControl, &ManageHeaderBar::albumRoleChanged); QSignalSpy imageRoleChangedSpy(&myControl, &ManageHeaderBar::imageRoleChanged); QSignalSpy albumIdRoleChangedSpy(&myControl, &ManageHeaderBar::albumIdRoleChanged); QSignalSpy isValidRoleChangedSpy(&myControl, &ManageHeaderBar::isValidRoleChanged); QSignalSpy artistChangedSpy(&myControl, &ManageHeaderBar::artistChanged); QSignalSpy titleChangedSpy(&myControl, &ManageHeaderBar::titleChanged); QSignalSpy albumChangedSpy(&myControl, &ManageHeaderBar::albumChanged); QSignalSpy imageChangedSpy(&myControl, &ManageHeaderBar::imageChanged); QSignalSpy albumIdChangedSpy(&myControl, &ManageHeaderBar::albumIdChanged); QSignalSpy isValidChangedSpy(&myControl, &ManageHeaderBar::isValidChanged); QSignalSpy remainingTracksChangedSpy(&myControl, &ManageHeaderBar::remainingTracksChanged); QCOMPARE(myControl.currentTrack().isValid(), false); QCOMPARE(myControl.playListModel(), static_cast(nullptr)); QCOMPARE(myControl.artistRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.titleRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.imageRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumIdRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.isValidRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.artist().toString().isEmpty(), true); QCOMPARE(myControl.title().toString().isEmpty(), true); QCOMPARE(myControl.album().toString().isEmpty(), true); QCOMPARE(myControl.image().toString().isEmpty(), true); QCOMPARE(myControl.isValid(), false); QCOMPARE(myControl.remainingTracks(), 0); myControl.setArtistRole(MediaPlayList::ArtistRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.artistRole(), static_cast(MediaPlayList::ArtistRole)); myControl.setTitleRole(MediaPlayList::TitleRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.titleRole(), static_cast(MediaPlayList::TitleRole)); myControl.setAlbumRole(MediaPlayList::AlbumRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.albumRole(), static_cast(MediaPlayList::AlbumRole)); myControl.setImageRole(MediaPlayList::ImageRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.imageRole(), static_cast(MediaPlayList::ImageRole)); myControl.setAlbumIdRole(MediaPlayList::AlbumIdRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.albumIdRole(), static_cast(MediaPlayList::AlbumIdRole)); myControl.setIsValidRole(MediaPlayList::IsValidRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.isValidRole(), static_cast(MediaPlayList::IsValidRole)); myControl.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.playListModel(), &myPlayList); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); myPlayList.enqueue({QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album1"), 2, 2}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); myControl.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 1); QCOMPARE(albumIdChangedSpy.count(), 1); QCOMPARE(isValidChangedSpy.count(), 1); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); QCOMPARE(myControl.remainingTracks(), 1); QCOMPARE(myControl.isValid(), true); QCOMPARE(myControl.image(), QUrl::fromUserInput(QStringLiteral("file:album2"))); QCOMPARE(myControl.album(), QVariant(QStringLiteral("album2"))); QCOMPARE(myControl.artist(), QVariant(QStringLiteral("artist1"))); QCOMPARE(myControl.title(), QVariant(QStringLiteral("track1"))); QCOMPARE(myControl.albumId(), qulonglong(2)); QCOMPARE(myPlayList.moveRow(myControl.currentTrack().parent(), 0, myControl.currentTrack().parent(), 2), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 1); QCOMPARE(albumIdChangedSpy.count(), 1); QCOMPARE(isValidChangedSpy.count(), 1); QCOMPARE(remainingTracksChangedSpy.count(), 2); QCOMPARE(myControl.remainingTracks(), 0); } void ManageHeaderBarTest::moveAnotherTrack() { MediaPlayList myPlayList; DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); ManageHeaderBar myControl; QSignalSpy currentTrackChangedSpy(&myControl, &ManageHeaderBar::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myControl, &ManageHeaderBar::playListModelChanged); QSignalSpy artistRoleChangedSpy(&myControl, &ManageHeaderBar::artistRoleChanged); QSignalSpy titleRoleChangedSpy(&myControl, &ManageHeaderBar::titleRoleChanged); QSignalSpy albumRoleChangedSpy(&myControl, &ManageHeaderBar::albumRoleChanged); QSignalSpy imageRoleChangedSpy(&myControl, &ManageHeaderBar::imageRoleChanged); QSignalSpy albumIdRoleChangedSpy(&myControl, &ManageHeaderBar::albumIdRoleChanged); QSignalSpy isValidRoleChangedSpy(&myControl, &ManageHeaderBar::isValidRoleChanged); QSignalSpy artistChangedSpy(&myControl, &ManageHeaderBar::artistChanged); QSignalSpy titleChangedSpy(&myControl, &ManageHeaderBar::titleChanged); QSignalSpy albumChangedSpy(&myControl, &ManageHeaderBar::albumChanged); QSignalSpy imageChangedSpy(&myControl, &ManageHeaderBar::imageChanged); QSignalSpy albumIdChangedSpy(&myControl, &ManageHeaderBar::albumIdChanged); QSignalSpy isValidChangedSpy(&myControl, &ManageHeaderBar::isValidChanged); QSignalSpy remainingTracksChangedSpy(&myControl, &ManageHeaderBar::remainingTracksChanged); QCOMPARE(myControl.currentTrack().isValid(), false); QCOMPARE(myControl.playListModel(), static_cast(nullptr)); QCOMPARE(myControl.artistRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.titleRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.imageRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumIdRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.isValidRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.artist().toString().isEmpty(), true); QCOMPARE(myControl.title().toString().isEmpty(), true); QCOMPARE(myControl.album().toString().isEmpty(), true); QCOMPARE(myControl.image().toString().isEmpty(), true); QCOMPARE(myControl.isValid(), false); QCOMPARE(myControl.remainingTracks(), 0); myControl.setArtistRole(MediaPlayList::ArtistRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.artistRole(), static_cast(MediaPlayList::ArtistRole)); myControl.setTitleRole(MediaPlayList::TitleRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.titleRole(), static_cast(MediaPlayList::TitleRole)); myControl.setAlbumRole(MediaPlayList::AlbumRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.albumRole(), static_cast(MediaPlayList::AlbumRole)); myControl.setImageRole(MediaPlayList::ImageRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.imageRole(), static_cast(MediaPlayList::ImageRole)); myControl.setAlbumIdRole(MediaPlayList::AlbumIdRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.albumIdRole(), static_cast(MediaPlayList::AlbumIdRole)); myControl.setIsValidRole(MediaPlayList::IsValidRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.isValidRole(), static_cast(MediaPlayList::IsValidRole)); myControl.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.playListModel(), &myPlayList); auto newFiles = QList(); const auto &constNewTracks = mNewTracks; for (const auto &oneTrack : constNewTracks) { newFiles.push_back(oneTrack.resourceURI()); } myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); myPlayList.enqueue({QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album1"), 2, 2}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); myControl.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 1); QCOMPARE(albumIdChangedSpy.count(), 1); QCOMPARE(isValidChangedSpy.count(), 1); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); QCOMPARE(myControl.remainingTracks(), 1); QCOMPARE(myControl.isValid(), true); QCOMPARE(myControl.image(), QUrl::fromUserInput(QStringLiteral("file:album2"))); QCOMPARE(myControl.album(), QVariant(QStringLiteral("album2"))); QCOMPARE(myControl.artist(), QVariant(QStringLiteral("artist1"))); QCOMPARE(myControl.title(), QVariant(QStringLiteral("track1"))); QCOMPARE(myControl.albumId(), qulonglong(2)); QCOMPARE(myPlayList.moveRow(myControl.currentTrack().parent(), 1, myControl.currentTrack().parent(), 0), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 1); QCOMPARE(albumIdChangedSpy.count(), 1); QCOMPARE(isValidChangedSpy.count(), 1); QCOMPARE(remainingTracksChangedSpy.count(), 2); QCOMPARE(myControl.remainingTracks(), 0); } void ManageHeaderBarTest::setCurrentTrackTest() { MediaPlayList myPlayList; DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); ManageHeaderBar myControl; QSignalSpy currentTrackChangedSpy(&myControl, &ManageHeaderBar::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myControl, &ManageHeaderBar::playListModelChanged); QSignalSpy artistRoleChangedSpy(&myControl, &ManageHeaderBar::artistRoleChanged); QSignalSpy titleRoleChangedSpy(&myControl, &ManageHeaderBar::titleRoleChanged); QSignalSpy albumRoleChangedSpy(&myControl, &ManageHeaderBar::albumRoleChanged); QSignalSpy imageRoleChangedSpy(&myControl, &ManageHeaderBar::imageRoleChanged); QSignalSpy albumIdRoleChangedSpy(&myControl, &ManageHeaderBar::albumIdRoleChanged); QSignalSpy isValidRoleChangedSpy(&myControl, &ManageHeaderBar::isValidRoleChanged); QSignalSpy artistChangedSpy(&myControl, &ManageHeaderBar::artistChanged); QSignalSpy titleChangedSpy(&myControl, &ManageHeaderBar::titleChanged); QSignalSpy albumChangedSpy(&myControl, &ManageHeaderBar::albumChanged); QSignalSpy imageChangedSpy(&myControl, &ManageHeaderBar::imageChanged); QSignalSpy albumIdChangedSpy(&myControl, &ManageHeaderBar::albumIdChanged); QSignalSpy isValidChangedSpy(&myControl, &ManageHeaderBar::isValidChanged); QSignalSpy remainingTracksChangedSpy(&myControl, &ManageHeaderBar::remainingTracksChanged); QCOMPARE(myControl.currentTrack().isValid(), false); QCOMPARE(myControl.playListModel(), static_cast(nullptr)); QCOMPARE(myControl.artistRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.titleRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.imageRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumIdRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.isValidRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.artist().toString().isEmpty(), true); QCOMPARE(myControl.title().toString().isEmpty(), true); QCOMPARE(myControl.album().toString().isEmpty(), true); QCOMPARE(myControl.image().toString().isEmpty(), true); QCOMPARE(myControl.isValid(), false); QCOMPARE(myControl.remainingTracks(), 0); myControl.setArtistRole(MediaPlayList::ArtistRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.artistRole(), static_cast(MediaPlayList::ArtistRole)); myControl.setTitleRole(MediaPlayList::TitleRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.titleRole(), static_cast(MediaPlayList::TitleRole)); myControl.setAlbumRole(MediaPlayList::AlbumRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.albumRole(), static_cast(MediaPlayList::AlbumRole)); myControl.setImageRole(MediaPlayList::ImageRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.imageRole(), static_cast(MediaPlayList::ImageRole)); myControl.setAlbumIdRole(MediaPlayList::AlbumIdRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.albumIdRole(), static_cast(MediaPlayList::AlbumIdRole)); myControl.setIsValidRole(MediaPlayList::IsValidRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.isValidRole(), static_cast(MediaPlayList::IsValidRole)); myControl.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.playListModel(), &myPlayList); auto newFiles = QList(); const auto &constNewTracks = mNewTracks; for (const auto &oneTrack : constNewTracks) { newFiles.push_back(oneTrack.resourceURI()); } myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); myPlayList.enqueue({QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album1"), 2, 2}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); myControl.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 1); QCOMPARE(albumIdChangedSpy.count(), 1); QCOMPARE(isValidChangedSpy.count(), 1); QCOMPARE(remainingTracksChangedSpy.count(), 1); QCOMPARE(myControl.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); QCOMPARE(myControl.remainingTracks(), 1); QCOMPARE(myControl.isValid(), true); QCOMPARE(myControl.image(), QUrl::fromUserInput(QStringLiteral("file:album2"))); QCOMPARE(myControl.album(), QVariant(QStringLiteral("album2"))); QCOMPARE(myControl.artist(), QVariant(QStringLiteral("artist1"))); QCOMPARE(myControl.title(), QVariant(QStringLiteral("track1"))); QCOMPARE(myControl.albumId(), qulonglong(2)); myControl.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 1); QCOMPARE(titleRoleChangedSpy.count(), 1); QCOMPARE(albumRoleChangedSpy.count(), 1); QCOMPARE(imageRoleChangedSpy.count(), 1); QCOMPARE(albumIdRoleChangedSpy.count(), 1); QCOMPARE(isValidRoleChangedSpy.count(), 1); QCOMPARE(artistChangedSpy.count(), 1); QCOMPARE(titleChangedSpy.count(), 1); QCOMPARE(albumChangedSpy.count(), 1); QCOMPARE(imageChangedSpy.count(), 1); QCOMPARE(albumIdChangedSpy.count(), 1); QCOMPARE(isValidChangedSpy.count(), 1); QCOMPARE(remainingTracksChangedSpy.count(), 1); } void ManageHeaderBarTest::setPlayListModelTest() { MediaPlayList myPlayList; DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); ManageHeaderBar myControl; QSignalSpy currentTrackChangedSpy(&myControl, &ManageHeaderBar::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myControl, &ManageHeaderBar::playListModelChanged); QSignalSpy artistRoleChangedSpy(&myControl, &ManageHeaderBar::artistRoleChanged); QSignalSpy titleRoleChangedSpy(&myControl, &ManageHeaderBar::titleRoleChanged); QSignalSpy albumRoleChangedSpy(&myControl, &ManageHeaderBar::albumRoleChanged); QSignalSpy imageRoleChangedSpy(&myControl, &ManageHeaderBar::imageRoleChanged); QSignalSpy albumIdRoleChangedSpy(&myControl, &ManageHeaderBar::albumIdRoleChanged); QSignalSpy isValidRoleChangedSpy(&myControl, &ManageHeaderBar::isValidRoleChanged); QSignalSpy artistChangedSpy(&myControl, &ManageHeaderBar::artistChanged); QSignalSpy titleChangedSpy(&myControl, &ManageHeaderBar::titleChanged); QSignalSpy albumChangedSpy(&myControl, &ManageHeaderBar::albumChanged); QSignalSpy imageChangedSpy(&myControl, &ManageHeaderBar::imageChanged); QSignalSpy albumIdChangedSpy(&myControl, &ManageHeaderBar::albumIdChanged); QSignalSpy isValidChangedSpy(&myControl, &ManageHeaderBar::isValidChanged); QSignalSpy remainingTracksChangedSpy(&myControl, &ManageHeaderBar::remainingTracksChanged); QCOMPARE(myControl.currentTrack().isValid(), false); QCOMPARE(myControl.playListModel(), static_cast(nullptr)); QCOMPARE(myControl.artistRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.titleRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.imageRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.albumIdRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.isValidRole(), static_cast(Qt::DisplayRole)); QCOMPARE(myControl.artist().toString().isEmpty(), true); QCOMPARE(myControl.title().toString().isEmpty(), true); QCOMPARE(myControl.album().toString().isEmpty(), true); QCOMPARE(myControl.image().toString().isEmpty(), true); QCOMPARE(myControl.isValid(), false); QCOMPARE(myControl.remainingTracks(), 0); myControl.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(artistRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.playListModel(), &myPlayList); myControl.setPlayListModel(nullptr); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 2); QCOMPARE(artistRoleChangedSpy.count(), 0); QCOMPARE(titleRoleChangedSpy.count(), 0); QCOMPARE(albumRoleChangedSpy.count(), 0); QCOMPARE(imageRoleChangedSpy.count(), 0); QCOMPARE(albumIdRoleChangedSpy.count(), 0); QCOMPARE(isValidRoleChangedSpy.count(), 0); QCOMPARE(artistChangedSpy.count(), 0); QCOMPARE(titleChangedSpy.count(), 0); QCOMPARE(albumChangedSpy.count(), 0); QCOMPARE(imageChangedSpy.count(), 0); QCOMPARE(albumIdChangedSpy.count(), 0); QCOMPARE(isValidChangedSpy.count(), 0); QCOMPARE(remainingTracksChangedSpy.count(), 0); QCOMPARE(myControl.playListModel(), static_cast(nullptr)); } QTEST_GUILESS_MAIN(ManageHeaderBarTest) #include "moc_manageheaderbartest.cpp" diff --git a/autotests/manageheaderbartest.h b/autotests/manageheaderbartest.h index cc0bb018..2103360b 100644 --- a/autotests/manageheaderbartest.h +++ b/autotests/manageheaderbartest.h @@ -1,236 +1,234 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef MANAGEHEADERBARTEST_H #define MANAGEHEADERBARTEST_H #include #include "musicaudiotrack.h" #include #include #include #include class ManageHeaderBarTest : public QObject { Q_OBJECT public: enum ColumnsRoles { IsValidRole = Qt::UserRole + 1, TitleRole = IsValidRole + 1, DurationRole = TitleRole + 1, MilliSecondsDurationRole = DurationRole + 1, CreatorRole = MilliSecondsDurationRole + 1, ArtistRole = CreatorRole + 1, AlbumRole = ArtistRole + 1, TrackNumberRole = AlbumRole + 1, RatingRole = TrackNumberRole + 1, ImageRole = RatingRole + 1, AlbumIdRole = ImageRole + 1, ResourceRole = AlbumIdRole + 1, CountRole = ResourceRole + 1, IsPlayingRole = CountRole + 1, }; Q_ENUM(ColumnsRoles) explicit ManageHeaderBarTest(QObject *parent = nullptr); Q_SIGNALS: private Q_SLOTS: void initTestCase(); void simpleInitialCase(); void setCurrentTrackCase(); void setCurrentTrackCaseFromNewAlbum(); void completeCase(); void setCurrentTrackAndInvalidCase(); void setCurrentTrackAndRemoveItCase(); void insertBeforeCurrentTrack(); void moveCurrentTrack(); void moveAnotherTrack(); void setCurrentTrackTest(); void setPlayListModelTest(); private: QList mNewTracks = { {true, QStringLiteral("$1"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 1, 1, QTime::fromMSecsSinceStartOfDay(1), {QUrl::fromLocalFile(QStringLiteral("/$1"))}, QDateTime::fromMSecsSinceEpoch(1), QUrl::fromLocalFile(QStringLiteral("album1")), 1, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$2"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 2, 2, QTime::fromMSecsSinceStartOfDay(2), {QUrl::fromLocalFile(QStringLiteral("/$2"))}, QDateTime::fromMSecsSinceEpoch(2), QUrl::fromLocalFile(QStringLiteral("album1")), 2, false, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$3"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 3, 3, QTime::fromMSecsSinceStartOfDay(3), {QUrl::fromLocalFile(QStringLiteral("/$3"))}, QDateTime::fromMSecsSinceEpoch(3), QUrl::fromLocalFile(QStringLiteral("album1")), 3, false, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4Bis"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$5"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 1, 1, QTime::fromMSecsSinceStartOfDay(5), {QUrl::fromLocalFile(QStringLiteral("/$5"))}, QDateTime::fromMSecsSinceEpoch(5), QUrl::fromLocalFile(QStringLiteral("album2")), 4, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$6"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 2, 1, QTime::fromMSecsSinceStartOfDay(6), {QUrl::fromLocalFile(QStringLiteral("/$6"))}, QDateTime::fromMSecsSinceEpoch(6), QUrl::fromLocalFile(QStringLiteral("album2")), 1, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$7"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 3, 1, QTime::fromMSecsSinceStartOfDay(7), {QUrl::fromLocalFile(QStringLiteral("/$7"))}, QDateTime::fromMSecsSinceEpoch(7), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$8"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 4, 1, QTime::fromMSecsSinceStartOfDay(8), {QUrl::fromLocalFile(QStringLiteral("/$8"))}, QDateTime::fromMSecsSinceEpoch(8), QUrl::fromLocalFile(QStringLiteral("album2")), 2, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$9"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 5, 1, QTime::fromMSecsSinceStartOfDay(9), {QUrl::fromLocalFile(QStringLiteral("/$9"))}, QDateTime::fromMSecsSinceEpoch(9), QUrl::fromLocalFile(QStringLiteral("album2")), 3, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$10"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist1 and artist2"), QStringLiteral("album2"), QStringLiteral("artist1"), 6, 1, QTime::fromMSecsSinceStartOfDay(10), {QUrl::fromLocalFile(QStringLiteral("/$10"))}, QDateTime::fromMSecsSinceEpoch(10), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$11"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(11), {QUrl::fromLocalFile(QStringLiteral("/$11"))}, QDateTime::fromMSecsSinceEpoch(11), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$12"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(12), {QUrl::fromLocalFile(QStringLiteral("/$12"))}, QDateTime::fromMSecsSinceEpoch(12), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$13"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(13), {QUrl::fromLocalFile(QStringLiteral("/$13"))}, QDateTime::fromMSecsSinceEpoch(13), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$14"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(14), {QUrl::fromLocalFile(QStringLiteral("/$14"))}, QDateTime::fromMSecsSinceEpoch(14), QUrl::fromLocalFile(QStringLiteral("album4")), 4, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$15"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(15), {QUrl::fromLocalFile(QStringLiteral("/$15"))}, QDateTime::fromMSecsSinceEpoch(15), QUrl::fromLocalFile(QStringLiteral("album4")), 5, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$16"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(16), {QUrl::fromLocalFile(QStringLiteral("/$16"))}, QDateTime::fromMSecsSinceEpoch(16), QUrl::fromLocalFile(QStringLiteral("album4")), 1, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$17"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 4, 1, QTime::fromMSecsSinceStartOfDay(17), {QUrl::fromLocalFile(QStringLiteral("/$17"))}, QDateTime::fromMSecsSinceEpoch(17), QUrl::fromLocalFile(QStringLiteral("album4")), 2, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$18"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 5, 1, QTime::fromMSecsSinceStartOfDay(18), {QUrl::fromLocalFile(QStringLiteral("/$18"))}, QDateTime::fromMSecsSinceEpoch(18), QUrl::fromLocalFile(QStringLiteral("album4")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$19"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 1, 1, QTime::fromMSecsSinceStartOfDay(19), {QUrl::fromLocalFile(QStringLiteral("/$19"))}, QDateTime::fromMSecsSinceEpoch(19), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 2, 1, QTime::fromMSecsSinceStartOfDay(20), {QUrl::fromLocalFile(QStringLiteral("/$20"))}, QDateTime::fromMSecsSinceEpoch(20), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$21"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 3, 1, QTime::fromMSecsSinceStartOfDay(21), {QUrl::fromLocalFile(QStringLiteral("/$21"))}, QDateTime::fromMSecsSinceEpoch(21), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$22"), QStringLiteral("0"), QStringLiteral("track9"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist7"), 9, 1, QTime::fromMSecsSinceStartOfDay(22), {QUrl::fromLocalFile(QStringLiteral("/$22"))}, QDateTime::fromMSecsSinceEpoch(22), QUrl::fromLocalFile(QStringLiteral("album3")), 9, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, }; QHash mNewCovers = { {QStringLiteral("file:///$1"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$2"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$3"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4Bis"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$5"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$6"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$7"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$8"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$9"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$0"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$11"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$12"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$13"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$14"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$15"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$16"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$17"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$18"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$19"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$20"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$21"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$22"), QUrl::fromLocalFile(QStringLiteral("album3"))}, }; }; #endif // MANAGEHEADERBARTEST_H diff --git a/autotests/managemediaplayercontroltest.cpp b/autotests/managemediaplayercontroltest.cpp index fb290374..de483b19 100644 --- a/autotests/managemediaplayercontroltest.cpp +++ b/autotests/managemediaplayercontroltest.cpp @@ -1,762 +1,760 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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); } void ManageMediaPlayerControlTest::addItemInModelCase() { 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.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); 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); } void ManageMediaPlayerControlTest::addItemInModelCaseV2() { 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.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(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); QCOMPARE(myPlayList.insertRows(1, 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(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(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::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, 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, QStringLiteral("autoTest")); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album2"), 1, 1}); myPlayList.enqueue({QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album1"), 2, 2}); 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(), 1); QCOMPARE(musicPlayingChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.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(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::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, 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, QStringLiteral("autoTest")); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album2"), 1, 1}); myPlayList.enqueue({QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album1"), 2, 2}); 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(), 1); QCOMPARE(musicPlayingChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(myControl.musicPlaying(), true); QCOMPARE(myControl.skipForwardControlEnabled(), true); QCOMPARE(myPlayList.moveRows({}, 1, 1, {}, 0), 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(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::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, 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, QStringLiteral("autoTest")); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album2"), 1, 1}); myPlayList.enqueue({QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album1"), 2, 2}); 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.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); } 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)); } QTEST_GUILESS_MAIN(ManageMediaPlayerControlTest) #include "moc_managemediaplayercontroltest.cpp" diff --git a/autotests/managemediaplayercontroltest.h b/autotests/managemediaplayercontroltest.h index bc3cc65d..f2b108cc 100644 --- a/autotests/managemediaplayercontroltest.h +++ b/autotests/managemediaplayercontroltest.h @@ -1,211 +1,209 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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 "musicaudiotrack.h" #include #include #include #include class ManageMediaPlayerControlTest : public QObject { 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(); private: QList mNewTracks = { {true, QStringLiteral("$1"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 1, 1, QTime::fromMSecsSinceStartOfDay(1), {QUrl::fromLocalFile(QStringLiteral("/$1"))}, QDateTime::fromMSecsSinceEpoch(1), QUrl::fromLocalFile(QStringLiteral("album1")), 1, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$2"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 2, 2, QTime::fromMSecsSinceStartOfDay(2), {QUrl::fromLocalFile(QStringLiteral("/$2"))}, QDateTime::fromMSecsSinceEpoch(2), QUrl::fromLocalFile(QStringLiteral("album1")), 2, false, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$3"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 3, 3, QTime::fromMSecsSinceStartOfDay(3), {QUrl::fromLocalFile(QStringLiteral("/$3"))}, QDateTime::fromMSecsSinceEpoch(3), QUrl::fromLocalFile(QStringLiteral("album1")), 3, false, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4Bis"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$5"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 1, 1, QTime::fromMSecsSinceStartOfDay(5), {QUrl::fromLocalFile(QStringLiteral("/$5"))}, QDateTime::fromMSecsSinceEpoch(5), QUrl::fromLocalFile(QStringLiteral("album2")), 4, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$6"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 2, 1, QTime::fromMSecsSinceStartOfDay(6), {QUrl::fromLocalFile(QStringLiteral("/$6"))}, QDateTime::fromMSecsSinceEpoch(6), QUrl::fromLocalFile(QStringLiteral("album2")), 1, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$7"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 3, 1, QTime::fromMSecsSinceStartOfDay(7), {QUrl::fromLocalFile(QStringLiteral("/$7"))}, QDateTime::fromMSecsSinceEpoch(7), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$8"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 4, 1, QTime::fromMSecsSinceStartOfDay(8), {QUrl::fromLocalFile(QStringLiteral("/$8"))}, QDateTime::fromMSecsSinceEpoch(8), QUrl::fromLocalFile(QStringLiteral("album2")), 2, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$9"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 5, 1, QTime::fromMSecsSinceStartOfDay(9), {QUrl::fromLocalFile(QStringLiteral("/$9"))}, QDateTime::fromMSecsSinceEpoch(9), QUrl::fromLocalFile(QStringLiteral("album2")), 3, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$10"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist1 and artist2"), QStringLiteral("album2"), QStringLiteral("artist1"), 6, 1, QTime::fromMSecsSinceStartOfDay(10), {QUrl::fromLocalFile(QStringLiteral("/$10"))}, QDateTime::fromMSecsSinceEpoch(10), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$11"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(11), {QUrl::fromLocalFile(QStringLiteral("/$11"))}, QDateTime::fromMSecsSinceEpoch(11), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$12"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(12), {QUrl::fromLocalFile(QStringLiteral("/$12"))}, QDateTime::fromMSecsSinceEpoch(12), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$13"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(13), {QUrl::fromLocalFile(QStringLiteral("/$13"))}, QDateTime::fromMSecsSinceEpoch(13), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$14"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(14), {QUrl::fromLocalFile(QStringLiteral("/$14"))}, QDateTime::fromMSecsSinceEpoch(14), QUrl::fromLocalFile(QStringLiteral("album4")), 4, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$15"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(15), {QUrl::fromLocalFile(QStringLiteral("/$15"))}, QDateTime::fromMSecsSinceEpoch(15), QUrl::fromLocalFile(QStringLiteral("album4")), 5, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$16"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(16), {QUrl::fromLocalFile(QStringLiteral("/$16"))}, QDateTime::fromMSecsSinceEpoch(16), QUrl::fromLocalFile(QStringLiteral("album4")), 1, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$17"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 4, 1, QTime::fromMSecsSinceStartOfDay(17), {QUrl::fromLocalFile(QStringLiteral("/$17"))}, QDateTime::fromMSecsSinceEpoch(17), QUrl::fromLocalFile(QStringLiteral("album4")), 2, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$18"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 5, 1, QTime::fromMSecsSinceStartOfDay(18), {QUrl::fromLocalFile(QStringLiteral("/$18"))}, QDateTime::fromMSecsSinceEpoch(18), QUrl::fromLocalFile(QStringLiteral("album4")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$19"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 1, 1, QTime::fromMSecsSinceStartOfDay(19), {QUrl::fromLocalFile(QStringLiteral("/$19"))}, QDateTime::fromMSecsSinceEpoch(19), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 2, 1, QTime::fromMSecsSinceStartOfDay(20), {QUrl::fromLocalFile(QStringLiteral("/$20"))}, QDateTime::fromMSecsSinceEpoch(20), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$21"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 3, 1, QTime::fromMSecsSinceStartOfDay(21), {QUrl::fromLocalFile(QStringLiteral("/$21"))}, QDateTime::fromMSecsSinceEpoch(21), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$22"), QStringLiteral("0"), QStringLiteral("track9"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist7"), 9, 1, QTime::fromMSecsSinceStartOfDay(22), {QUrl::fromLocalFile(QStringLiteral("/$22"))}, QDateTime::fromMSecsSinceEpoch(22), QUrl::fromLocalFile(QStringLiteral("album3")), 9, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, }; QHash mNewCovers = { {QStringLiteral("file:///$1"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$2"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$3"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4Bis"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$5"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$6"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$7"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$8"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$9"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$0"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$11"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$12"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$13"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$14"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$15"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$16"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$17"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$18"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$19"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$20"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$21"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$22"), QUrl::fromLocalFile(QStringLiteral("album3"))}, }; }; #endif // MANAGEMEDIAPLAYERCONTROLTEST_H diff --git a/autotests/mediaplaylisttest.cpp b/autotests/mediaplaylisttest.cpp index 17b6c653..ab66e95e 100644 --- a/autotests/mediaplaylisttest.cpp +++ b/autotests/mediaplaylisttest.cpp @@ -1,7581 +1,7579 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "mediaplaylisttest.h" #include "mediaplaylisttestconfig.h" #include "mediaplaylist.h" #include "databaseinterface.h" #include "musicalbum.h" #include "musicaudiotrack.h" #include "trackslistener.h" #include "qabstractitemmodeltester.h" #include #include #include #include #include #include MediaPlayListTest::MediaPlayListTest(QObject *parent) : QObject(parent) { } void MediaPlayListTest::initTestCase() { qRegisterMetaType>("QHash"); qRegisterMetaType>>("QHash>"); qRegisterMetaType>("QVector"); qRegisterMetaType>("QHash"); } void MediaPlayListTest::simpleInitialCase() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); auto newTrackID = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist1 and artist2"), QStringLiteral("album2"), 6, 1); myPlayList.enqueue(newTrackID); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); } void MediaPlayListTest::enqueueAlbumCase() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myPlayList.enqueue(myDatabaseContent.albumFromTitleAndArtist(QStringLiteral("album2"), QStringLiteral("artist1"))); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 6); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 6); QCOMPARE(trackHasBeenAddedSpy.count(), 6); QCOMPARE(persistentStateChangedSpy.count(), 6); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 6); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.rowCount(), 6); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 5); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::AlbumIdRole).toULongLong(), 2); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track2")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::TrackNumberRole).toInt(), 2); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 6); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::AlbumIdRole).toULongLong(), 2); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track3")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::TrackNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 7); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::AlbumIdRole).toULongLong(), 2); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track4")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::TrackNumberRole).toInt(), 4); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 8); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::AlbumIdRole).toULongLong(), 2); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track5")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::TrackNumberRole).toInt(), 5); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 9); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::AlbumIdRole).toULongLong(), 2); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track6")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1 and artist2")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::TrackNumberRole).toInt(), 6); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 10); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::AlbumIdRole).toULongLong(), 2); } void MediaPlayListTest::clearPlayListCase() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.count(), 0); myPlayList.enqueue(myDatabaseContent.albumFromTitleAndArtist(QStringLiteral("album2"), QStringLiteral("artist1"))); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 6); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 6); QCOMPARE(trackHasBeenAddedSpy.count(), 6); QCOMPARE(persistentStateChangedSpy.count(), 6); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 6); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(myPlayList.rowCount(), 6); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 5); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track2")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::TrackNumberRole).toInt(), 2); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 6); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track3")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::TrackNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 7); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track4")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::TrackNumberRole).toInt(), 4); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 8); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track5")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::TrackNumberRole).toInt(), 5); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 9); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track6")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1 and artist2")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::TrackNumberRole).toInt(), 6); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 10); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.clearPlayList(); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 1); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 6); QCOMPARE(rowsRemovedSpy.count(), 1); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 6); QCOMPARE(trackHasBeenAddedSpy.count(), 6); QCOMPARE(persistentStateChangedSpy.count(), 6); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 6); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(myPlayList.rowCount(), 0); QCOMPARE(myPlayList.currentTrack().isValid(), false); } void MediaPlayListTest::enqueueArtistCase() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myPlayList.enqueue(QStringLiteral("artist1")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 1); QCOMPARE(myPlayList.rowCount(), 1); QCOMPARE(rowsAboutToBeInsertedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 1); QCOMPARE(myPlayList.rowCount(), 6); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::AlbumIdRole).toULongLong(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 5); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::AlbumIdRole).toULongLong(), 2); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track2")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::TrackNumberRole).toInt(), 2); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 6); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::AlbumIdRole).toULongLong(), 2); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track3")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::TrackNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 7); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::AlbumIdRole).toULongLong(), 2); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track4")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::TrackNumberRole).toInt(), 4); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 8); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::AlbumIdRole).toULongLong(), 2); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track5")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::TrackNumberRole).toInt(), 5); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 9); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::AlbumIdRole).toULongLong(), 2); } void MediaPlayListTest::removeFirstTrackOfAlbum() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myPlayList.enqueue(myDatabaseContent.albumFromTitleAndArtist(QStringLiteral("album2"), QStringLiteral("artist1"))); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 6); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 6); QCOMPARE(trackHasBeenAddedSpy.count(), 6); QCOMPARE(persistentStateChangedSpy.count(), 6); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 6); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); myPlayList.removeRow(0); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 1); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 6); QCOMPARE(rowsRemovedSpy.count(), 1); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 6); QCOMPARE(trackHasBeenAddedSpy.count(), 6); QCOMPARE(persistentStateChangedSpy.count(), 7); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 6); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); } void MediaPlayListTest::testHasHeader() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); auto firstTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1); myPlayList.enqueue(firstTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); auto secondTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); myPlayList.enqueue(secondTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); auto thirdTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), 2, 1); myPlayList.enqueue(thirdTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 3); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); auto fourthTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), 3, 1); myPlayList.enqueue(fourthTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 3); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 4); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); myPlayList.removeRows(2, 1); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 1); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 1); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 5); QCOMPARE(dataChangedSpy.count(), 5); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); } void MediaPlayListTest::testHasHeaderWithRestore() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContentHeaderWithRestore")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 1); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(newArtistInListSpy.wait(50), false); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1}); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 2); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(newArtistInListSpy.wait(50), false); myPlayList.enqueue({QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), 2, 1}); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 3); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 3); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(newArtistInListSpy.wait(50), false); myPlayList.enqueue({QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), 3, 1}); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 4); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 4); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 4); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 4); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 8); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 4); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 5); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track2")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::TrackNumberRole).toInt(), 2); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 6); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track3")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::TrackNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 7); } void MediaPlayListTest::testHasHeaderWithRemove() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); auto firstTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1); myPlayList.enqueue(firstTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); auto secondTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), 2, 1); myPlayList.enqueue(secondTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); auto thirdTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); myPlayList.enqueue(thirdTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 3); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); auto fourthTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), 3, 1); myPlayList.enqueue(fourthTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 3); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 4); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); myPlayList.removeRows(2, 1); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 1); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 1); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 5); QCOMPARE(dataChangedSpy.count(), 5); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); myPlayList.removeRows(0, 1); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 2); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 2); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 6); QCOMPARE(dataChangedSpy.count(), 6); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); } void MediaPlayListTest::testHasHeaderMoveFirst() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); auto firstTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1); myPlayList.enqueue(firstTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); auto secondTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), 2, 1); myPlayList.enqueue(secondTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); auto thirdTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), 3, 1); myPlayList.enqueue(thirdTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 3); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); auto fourthTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track4"), QStringLiteral("artist1"), QStringLiteral("album2"), 4, 1); myPlayList.enqueue(fourthTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 3); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 4); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.moveRows({}, 0, 1, {}, 4), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 1); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 1); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 5); QCOMPARE(dataChangedSpy.count(), 6); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); const auto &firstDataChanged = dataChangedSpy[4]; QCOMPARE(firstDataChanged.count(), 3); QCOMPARE(firstDataChanged.at(0).toModelIndex(), myPlayList.index(3, 0)); QCOMPARE(firstDataChanged.at(1).toModelIndex(), myPlayList.index(3, 0)); QCOMPARE(firstDataChanged.at(2).value>(), {MediaPlayList::HasAlbumHeader}); const auto &secondDataChanged = dataChangedSpy[5]; QCOMPARE(secondDataChanged.count(), 3); QCOMPARE(secondDataChanged.at(0).toModelIndex(), myPlayList.index(0, 0)); QCOMPARE(secondDataChanged.at(1).toModelIndex(), myPlayList.index(0, 0)); QCOMPARE(secondDataChanged.at(2).value>(), {MediaPlayList::HasAlbumHeader}); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); } void MediaPlayListTest::testHasHeaderMoveAnother() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); auto firstTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1); myPlayList.enqueue(firstTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); auto secondTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), 2, 1); myPlayList.enqueue(secondTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); auto thirdTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), 3, 1); myPlayList.enqueue(thirdTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 3); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); auto fourthTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track4"), QStringLiteral("artist1"), QStringLiteral("album2"), 4, 1); myPlayList.enqueue(fourthTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 3); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 4); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.moveRows({}, 3, 1, {}, 0), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 1); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 1); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 5); QCOMPARE(dataChangedSpy.count(), 6); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); const auto &firstDataChanged = dataChangedSpy[4]; QCOMPARE(firstDataChanged.count(), 3); QCOMPARE(firstDataChanged.at(0).toModelIndex(), myPlayList.index(0, 0)); QCOMPARE(firstDataChanged.at(1).toModelIndex(), myPlayList.index(0, 0)); QCOMPARE(firstDataChanged.at(2).value>(), {MediaPlayList::HasAlbumHeader}); const auto &secondDataChanged = dataChangedSpy[5]; QCOMPARE(secondDataChanged.count(), 3); QCOMPARE(secondDataChanged.at(0).toModelIndex(), myPlayList.index(1, 0)); QCOMPARE(secondDataChanged.at(1).toModelIndex(), myPlayList.index(1, 0)); QCOMPARE(secondDataChanged.at(2).value>(), {MediaPlayList::HasAlbumHeader}); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); } void MediaPlayListTest::testHasHeaderMoveFirstLikeQml() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); auto firstTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1); myPlayList.enqueue(firstTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); auto secondTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), 2, 1); myPlayList.enqueue(secondTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); auto thirdTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), 3, 1); myPlayList.enqueue(thirdTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 3); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); auto fourthTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track4"), QStringLiteral("artist1"), QStringLiteral("album2"), 4, 1); myPlayList.enqueue(fourthTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 3); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 4); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); myPlayList.move(0, 3, 1); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 1); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 1); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 5); QCOMPARE(dataChangedSpy.count(), 6); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); const auto &firstDataChanged = dataChangedSpy[4]; QCOMPARE(firstDataChanged.count(), 3); QCOMPARE(firstDataChanged.at(0).toModelIndex(), myPlayList.index(3, 0)); QCOMPARE(firstDataChanged.at(1).toModelIndex(), myPlayList.index(3, 0)); QCOMPARE(firstDataChanged.at(2).value>(), {MediaPlayList::HasAlbumHeader}); const auto &secondDataChanged = dataChangedSpy[5]; QCOMPARE(secondDataChanged.count(), 3); QCOMPARE(secondDataChanged.at(0).toModelIndex(), myPlayList.index(0, 0)); QCOMPARE(secondDataChanged.at(1).toModelIndex(), myPlayList.index(0, 0)); QCOMPARE(secondDataChanged.at(2).value>(), {MediaPlayList::HasAlbumHeader}); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); } void MediaPlayListTest::testHasHeaderMoveAnotherLikeQml() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); auto firstTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1); myPlayList.enqueue(firstTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); auto secondTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), 2, 1); myPlayList.enqueue(secondTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); auto thirdTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), 3, 1); myPlayList.enqueue(thirdTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 3); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); auto fourthTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track4"), QStringLiteral("artist1"), QStringLiteral("album2"), 4, 1); myPlayList.enqueue(fourthTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 3); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 4); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); myPlayList.move(3, 0, 1); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 1); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 1); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 5); QCOMPARE(dataChangedSpy.count(), 6); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); const auto &firstDataChanged = dataChangedSpy[4]; QCOMPARE(firstDataChanged.count(), 3); QCOMPARE(firstDataChanged.at(0).toModelIndex(), myPlayList.index(0, 0)); QCOMPARE(firstDataChanged.at(1).toModelIndex(), myPlayList.index(0, 0)); QCOMPARE(firstDataChanged.at(2).value>(), {MediaPlayList::HasAlbumHeader}); const auto &secondDataChanged = dataChangedSpy[5]; QCOMPARE(secondDataChanged.count(), 3); QCOMPARE(secondDataChanged.at(0).toModelIndex(), myPlayList.index(1, 0)); QCOMPARE(secondDataChanged.at(1).toModelIndex(), myPlayList.index(1, 0)); QCOMPARE(secondDataChanged.at(2).value>(), {MediaPlayList::HasAlbumHeader}); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); } void MediaPlayListTest::testHasHeaderYetAnotherMoveLikeQml() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); auto firstTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1); myPlayList.enqueue(firstTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); auto secondTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), 2, 1); myPlayList.enqueue(secondTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); auto thirdTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); myPlayList.enqueue(thirdTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 3); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); auto fourthTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track4"), QStringLiteral("artist1"), QStringLiteral("album2"), 4, 1); myPlayList.enqueue(fourthTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 3); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 4); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); myPlayList.move(0, 2, 1); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 1); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 1); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 5); QCOMPARE(dataChangedSpy.count(), 6); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); const auto &firstDataChanged = dataChangedSpy[4]; QCOMPARE(firstDataChanged.count(), 3); QCOMPARE(firstDataChanged.at(0).toModelIndex(), myPlayList.index(0, 0)); QCOMPARE(firstDataChanged.at(1).toModelIndex(), myPlayList.index(0, 0)); QCOMPARE(firstDataChanged.at(2).value>(), {MediaPlayList::HasAlbumHeader}); const auto &secondDataChanged = dataChangedSpy[5]; QCOMPARE(secondDataChanged.count(), 3); QCOMPARE(secondDataChanged.at(0).toModelIndex(), myPlayList.index(3, 0)); QCOMPARE(secondDataChanged.at(1).toModelIndex(), myPlayList.index(3, 0)); QCOMPARE(secondDataChanged.at(2).value>(), {MediaPlayList::HasAlbumHeader}); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); myPlayList.move(2, 0, 1); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 2); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 2); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 6); QCOMPARE(dataChangedSpy.count(), 8); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); const auto &newFirstDataChanged = dataChangedSpy[6]; QCOMPARE(newFirstDataChanged.count(), 3); QCOMPARE(newFirstDataChanged.at(0).toModelIndex(), myPlayList.index(3, 0)); QCOMPARE(newFirstDataChanged.at(1).toModelIndex(), myPlayList.index(3, 0)); QCOMPARE(newFirstDataChanged.at(2).value>(), {MediaPlayList::HasAlbumHeader}); const auto &newSecondDataChanged = dataChangedSpy[7]; QCOMPARE(newSecondDataChanged.count(), 3); QCOMPARE(newSecondDataChanged.at(0).toModelIndex(), myPlayList.index(1, 0)); QCOMPARE(newSecondDataChanged.at(1).toModelIndex(), myPlayList.index(1, 0)); QCOMPARE(newSecondDataChanged.at(2).value>(), {MediaPlayList::HasAlbumHeader}); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); } void MediaPlayListTest::enqueueReplaceAndPlay() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); auto firstTrackID = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist1 and artist2"), QStringLiteral("album2"), 6, 1); myPlayList.enqueue(firstTrackID); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track6")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1 and artist2")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TrackNumberRole).toInt(), 6); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 10); auto secondTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); myPlayList.enqueue(secondTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::DiscNumberRole).toInt(), 1); myPlayList.replaceAndPlay(myDatabaseContent.albumFromTitleAndArtist(QStringLiteral("album1"), QStringLiteral("Various Artists"))); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 1); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 6); QCOMPARE(rowsRemovedSpy.count(), 1); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 6); QCOMPARE(trackHasBeenAddedSpy.count(), 6); QCOMPARE(persistentStateChangedSpy.count(), 6); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 6); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track2")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist2")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::TrackNumberRole).toInt(), 2); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::DiscNumberRole).toInt(), 2); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 2); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track3")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist3")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::TrackNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::DiscNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track4")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist4")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::TrackNumberRole).toInt(), 4); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::DiscNumberRole).toInt(), 4); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 4); } void MediaPlayListTest::crashOnEnqueue() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); CrashEnqueuePlayList myCrash(&myPlayList); connect(&myPlayList, &MediaPlayList::rowsInserted, &myCrash, &CrashEnqueuePlayList::crashMediaPlayList); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); auto newTrackID = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track6"), QStringLiteral("artist1 and artist2"), QStringLiteral("album2"), 6, 1); myPlayList.enqueue(newTrackID); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); } void MediaPlayListTest::restoreMultipleIdenticalTracks() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContentHeaderWithRestore")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myPlayList.enqueue({QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3}); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 1); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); myPlayList.enqueue({QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3}); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 2); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); myPlayList.enqueue({QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3}); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 3); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 3); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); myPlayList.enqueue({QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3}); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 4); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 4); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 4); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 4); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 8); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 4); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track3")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist3")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TrackNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::DiscNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track3")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist3")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::TrackNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::DiscNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track3")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist3")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::TrackNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::DiscNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track3")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist3")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::TrackNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::DiscNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 3); } void MediaPlayListTest::testHasHeaderAlbumWithSameTitle() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); auto firstTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album3"), 1, 1); myPlayList.enqueue(firstTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); auto secondTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); myPlayList.enqueue(secondTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); auto thirdTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album3"), 2, 1); myPlayList.enqueue(thirdTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 3); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); auto fourthTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album3"), 3, 1); myPlayList.enqueue(fourthTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 3); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 4); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 4); QCOMPARE(trackHasBeenAddedSpy.count(), 4); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 4); QCOMPARE(newTrackByIdInListSpy.count(), 4); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); auto fithTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track9"), QStringLiteral("artist2"), QStringLiteral("album3"), 9, 1); myPlayList.enqueue(fithTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 5); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 5); QCOMPARE(trackHasBeenAddedSpy.count(), 5); QCOMPARE(persistentStateChangedSpy.count(), 5); QCOMPARE(dataChangedSpy.count(), 4); QCOMPARE(newTrackByIdInListSpy.count(), 5); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 5); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 5); QCOMPARE(trackHasBeenAddedSpy.count(), 5); QCOMPARE(persistentStateChangedSpy.count(), 5); QCOMPARE(dataChangedSpy.count(), 5); QCOMPARE(newTrackByIdInListSpy.count(), 5); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); auto sixthTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist7"), QStringLiteral("album3"), 1, 1); myPlayList.enqueue(sixthTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 6); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 6); QCOMPARE(trackHasBeenAddedSpy.count(), 6); QCOMPARE(persistentStateChangedSpy.count(), 6); QCOMPARE(dataChangedSpy.count(), 5); QCOMPARE(newTrackByIdInListSpy.count(), 6); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 6); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 6); QCOMPARE(trackHasBeenAddedSpy.count(), 6); QCOMPARE(persistentStateChangedSpy.count(), 6); QCOMPARE(dataChangedSpy.count(), 6); QCOMPARE(newTrackByIdInListSpy.count(), 6); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), false); } void MediaPlayListTest::testSavePersistentState() { MediaPlayList myPlayListSave; QAbstractItemModelTester testModelSave(&myPlayListSave); DatabaseInterface myDatabaseContent; TracksListener myListenerSave(&myDatabaseContent); MediaPlayList myPlayListRead; QAbstractItemModelTester testModelRead(&myPlayListRead); TracksListener myListenerRead(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpySave(&myPlayListSave, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpySave(&myPlayListSave, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpySave(&myPlayListSave, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpySave(&myPlayListSave, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpySave(&myPlayListSave, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpySave(&myPlayListSave, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpySave(&myPlayListSave, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpySave(&myPlayListSave, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpySave(&myPlayListSave, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpySave(&myPlayListSave, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpySave(&myPlayListSave, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpySave(&myPlayListSave, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpySave(&myPlayListSave, &MediaPlayList::newArtistInList); QSignalSpy rowsAboutToBeMovedSpyRead(&myPlayListRead, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpyRead(&myPlayListRead, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpyRead(&myPlayListRead, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpyRead(&myPlayListRead, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpyRead(&myPlayListRead, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpyRead(&myPlayListRead, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpyRead(&myPlayListRead, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpyRead(&myPlayListRead, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpyRead(&myPlayListRead, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpyRead(&myPlayListRead, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpyRead(&myPlayListRead, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpyRead(&myPlayListRead, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpyRead(&myPlayListRead, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpySave.count(), 0); QCOMPARE(rowsAboutToBeMovedSpySave.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpySave.count(), 0); QCOMPARE(rowsRemovedSpySave.count(), 0); QCOMPARE(rowsMovedSpySave.count(), 0); QCOMPARE(rowsInsertedSpySave.count(), 0); QCOMPARE(trackHasBeenAddedSpySave.count(), 0); QCOMPARE(persistentStateChangedSpySave.count(), 0); QCOMPARE(dataChangedSpySave.count(), 0); QCOMPARE(newTrackByIdInListSpySave.count(), 0); QCOMPARE(newTrackByNameInListSpySave.count(), 0); QCOMPARE(newArtistInListSpySave.count(), 0); QCOMPARE(rowsAboutToBeRemovedSpyRead.count(), 0); QCOMPARE(rowsAboutToBeMovedSpyRead.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpyRead.count(), 0); QCOMPARE(rowsRemovedSpyRead.count(), 0); QCOMPARE(rowsMovedSpyRead.count(), 0); QCOMPARE(rowsInsertedSpyRead.count(), 0); QCOMPARE(trackHasBeenAddedSpyRead.count(), 0); QCOMPARE(persistentStateChangedSpyRead.count(), 0); QCOMPARE(dataChangedSpyRead.count(), 0); QCOMPARE(newTrackByIdInListSpyRead.count(), 0); QCOMPARE(newTrackByNameInListSpyRead.count(), 0); QCOMPARE(newArtistInListSpyRead.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListenerSave, &TracksListener::trackHasChanged, &myPlayListSave, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListenerSave, &TracksListener::albumAdded, &myPlayListSave, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayListSave, &MediaPlayList::newTrackByIdInList, &myListenerSave, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayListSave, &MediaPlayList::newTrackByNameInList, &myListenerSave, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayListSave, &MediaPlayList::newTrackByFileNameInList, &myListenerSave, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayListSave, &MediaPlayList::newArtistInList, &myListenerSave, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListenerSave, &TracksListener::tracksAdded); connect(&myListenerRead, &TracksListener::trackHasChanged, &myPlayListRead, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListenerRead, &TracksListener::albumAdded, &myPlayListRead, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayListRead, &MediaPlayList::newTrackByIdInList, &myListenerRead, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayListRead, &MediaPlayList::newTrackByNameInList, &myListenerRead, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayListRead, &MediaPlayList::newTrackByFileNameInList, &myListenerRead, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayListRead, &MediaPlayList::newArtistInList, &myListenerRead, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListenerRead, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpySave.count(), 0); QCOMPARE(rowsAboutToBeMovedSpySave.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpySave.count(), 0); QCOMPARE(rowsRemovedSpySave.count(), 0); QCOMPARE(rowsMovedSpySave.count(), 0); QCOMPARE(rowsInsertedSpySave.count(), 0); QCOMPARE(trackHasBeenAddedSpySave.count(), 0); QCOMPARE(persistentStateChangedSpySave.count(), 0); QCOMPARE(dataChangedSpySave.count(), 0); QCOMPARE(newTrackByIdInListSpySave.count(), 0); QCOMPARE(newTrackByNameInListSpySave.count(), 0); QCOMPARE(newArtistInListSpySave.count(), 0); QCOMPARE(rowsAboutToBeRemovedSpyRead.count(), 0); QCOMPARE(rowsAboutToBeMovedSpyRead.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpyRead.count(), 0); QCOMPARE(rowsRemovedSpyRead.count(), 0); QCOMPARE(rowsMovedSpyRead.count(), 0); QCOMPARE(rowsInsertedSpyRead.count(), 0); QCOMPARE(trackHasBeenAddedSpyRead.count(), 0); QCOMPARE(persistentStateChangedSpyRead.count(), 0); QCOMPARE(dataChangedSpyRead.count(), 0); QCOMPARE(newTrackByIdInListSpyRead.count(), 0); QCOMPARE(newTrackByNameInListSpyRead.count(), 0); QCOMPARE(newArtistInListSpyRead.count(), 0); auto firstTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album3"), 1, 1); myPlayListSave.enqueue(firstTrackId); QCOMPARE(rowsAboutToBeRemovedSpySave.count(), 0); QCOMPARE(rowsAboutToBeMovedSpySave.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpySave.count(), 1); QCOMPARE(rowsRemovedSpySave.count(), 0); QCOMPARE(rowsMovedSpySave.count(), 0); QCOMPARE(rowsInsertedSpySave.count(), 1); QCOMPARE(trackHasBeenAddedSpySave.count(), 1); QCOMPARE(persistentStateChangedSpySave.count(), 1); QCOMPARE(dataChangedSpySave.count(), 0); QCOMPARE(newTrackByIdInListSpySave.count(), 1); QCOMPARE(newTrackByNameInListSpySave.count(), 0); QCOMPARE(newArtistInListSpySave.count(), 0); QCOMPARE(rowsAboutToBeRemovedSpyRead.count(), 0); QCOMPARE(rowsAboutToBeMovedSpyRead.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpyRead.count(), 0); QCOMPARE(rowsRemovedSpyRead.count(), 0); QCOMPARE(rowsMovedSpyRead.count(), 0); QCOMPARE(rowsInsertedSpyRead.count(), 0); QCOMPARE(trackHasBeenAddedSpyRead.count(), 0); QCOMPARE(persistentStateChangedSpyRead.count(), 0); QCOMPARE(dataChangedSpyRead.count(), 0); QCOMPARE(newTrackByIdInListSpyRead.count(), 0); QCOMPARE(newTrackByNameInListSpyRead.count(), 0); QCOMPARE(newArtistInListSpyRead.count(), 0); QCOMPARE(dataChangedSpySave.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpySave.count(), 0); QCOMPARE(rowsAboutToBeMovedSpySave.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpySave.count(), 1); QCOMPARE(rowsRemovedSpySave.count(), 0); QCOMPARE(rowsMovedSpySave.count(), 0); QCOMPARE(rowsInsertedSpySave.count(), 1); QCOMPARE(trackHasBeenAddedSpySave.count(), 1); QCOMPARE(persistentStateChangedSpySave.count(), 1); QCOMPARE(dataChangedSpySave.count(), 1); QCOMPARE(newTrackByIdInListSpySave.count(), 1); QCOMPARE(newTrackByNameInListSpySave.count(), 0); QCOMPARE(newArtistInListSpySave.count(), 0); QCOMPARE(rowsAboutToBeRemovedSpyRead.count(), 0); QCOMPARE(rowsAboutToBeMovedSpyRead.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpyRead.count(), 0); QCOMPARE(rowsRemovedSpyRead.count(), 0); QCOMPARE(rowsMovedSpyRead.count(), 0); QCOMPARE(rowsInsertedSpyRead.count(), 0); QCOMPARE(trackHasBeenAddedSpyRead.count(), 0); QCOMPARE(persistentStateChangedSpyRead.count(), 0); QCOMPARE(dataChangedSpyRead.count(), 0); QCOMPARE(newTrackByIdInListSpyRead.count(), 0); QCOMPARE(newTrackByNameInListSpyRead.count(), 0); QCOMPARE(newArtistInListSpyRead.count(), 0); QCOMPARE(myPlayListSave.data(myPlayListSave.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); auto secondTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); myPlayListSave.enqueue(secondTrackId); QCOMPARE(rowsAboutToBeRemovedSpySave.count(), 0); QCOMPARE(rowsAboutToBeMovedSpySave.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpySave.count(), 2); QCOMPARE(rowsRemovedSpySave.count(), 0); QCOMPARE(rowsMovedSpySave.count(), 0); QCOMPARE(rowsInsertedSpySave.count(), 2); QCOMPARE(trackHasBeenAddedSpySave.count(), 2); QCOMPARE(persistentStateChangedSpySave.count(), 2); QCOMPARE(dataChangedSpySave.count(), 1); QCOMPARE(newTrackByIdInListSpySave.count(), 2); QCOMPARE(newTrackByNameInListSpySave.count(), 0); QCOMPARE(newArtistInListSpySave.count(), 0); QCOMPARE(rowsAboutToBeRemovedSpyRead.count(), 0); QCOMPARE(rowsAboutToBeMovedSpyRead.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpyRead.count(), 0); QCOMPARE(rowsRemovedSpyRead.count(), 0); QCOMPARE(rowsMovedSpyRead.count(), 0); QCOMPARE(rowsInsertedSpyRead.count(), 0); QCOMPARE(trackHasBeenAddedSpyRead.count(), 0); QCOMPARE(persistentStateChangedSpyRead.count(), 0); QCOMPARE(dataChangedSpyRead.count(), 0); QCOMPARE(newTrackByIdInListSpyRead.count(), 0); QCOMPARE(newTrackByNameInListSpyRead.count(), 0); QCOMPARE(newArtistInListSpyRead.count(), 0); QCOMPARE(dataChangedSpySave.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpySave.count(), 0); QCOMPARE(rowsAboutToBeMovedSpySave.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpySave.count(), 2); QCOMPARE(rowsRemovedSpySave.count(), 0); QCOMPARE(rowsMovedSpySave.count(), 0); QCOMPARE(rowsInsertedSpySave.count(), 2); QCOMPARE(trackHasBeenAddedSpySave.count(), 2); QCOMPARE(persistentStateChangedSpySave.count(), 2); QCOMPARE(dataChangedSpySave.count(), 2); QCOMPARE(newTrackByIdInListSpySave.count(), 2); QCOMPARE(newTrackByNameInListSpySave.count(), 0); QCOMPARE(newArtistInListSpySave.count(), 0); QCOMPARE(rowsAboutToBeRemovedSpyRead.count(), 0); QCOMPARE(rowsAboutToBeMovedSpyRead.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpyRead.count(), 0); QCOMPARE(rowsRemovedSpyRead.count(), 0); QCOMPARE(rowsMovedSpyRead.count(), 0); QCOMPARE(rowsInsertedSpyRead.count(), 0); QCOMPARE(trackHasBeenAddedSpyRead.count(), 0); QCOMPARE(persistentStateChangedSpyRead.count(), 0); QCOMPARE(dataChangedSpyRead.count(), 0); QCOMPARE(newTrackByIdInListSpyRead.count(), 0); QCOMPARE(newTrackByNameInListSpyRead.count(), 0); QCOMPARE(newArtistInListSpyRead.count(), 0); QCOMPARE(myPlayListSave.data(myPlayListSave.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayListSave.data(myPlayListSave.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); auto thirdTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album3"), 2, 1); myPlayListSave.enqueue(thirdTrackId); QCOMPARE(rowsAboutToBeRemovedSpySave.count(), 0); QCOMPARE(rowsAboutToBeMovedSpySave.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpySave.count(), 3); QCOMPARE(rowsRemovedSpySave.count(), 0); QCOMPARE(rowsMovedSpySave.count(), 0); QCOMPARE(rowsInsertedSpySave.count(), 3); QCOMPARE(trackHasBeenAddedSpySave.count(), 3); QCOMPARE(persistentStateChangedSpySave.count(), 3); QCOMPARE(dataChangedSpySave.count(), 2); QCOMPARE(newTrackByIdInListSpySave.count(), 3); QCOMPARE(newTrackByNameInListSpySave.count(), 0); QCOMPARE(newArtistInListSpySave.count(), 0); QCOMPARE(rowsAboutToBeRemovedSpyRead.count(), 0); QCOMPARE(rowsAboutToBeMovedSpyRead.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpyRead.count(), 0); QCOMPARE(rowsRemovedSpyRead.count(), 0); QCOMPARE(rowsMovedSpyRead.count(), 0); QCOMPARE(rowsInsertedSpyRead.count(), 0); QCOMPARE(trackHasBeenAddedSpyRead.count(), 0); QCOMPARE(persistentStateChangedSpyRead.count(), 0); QCOMPARE(dataChangedSpyRead.count(), 0); QCOMPARE(newTrackByIdInListSpyRead.count(), 0); QCOMPARE(newTrackByNameInListSpyRead.count(), 0); QCOMPARE(newArtistInListSpyRead.count(), 0); QCOMPARE(dataChangedSpySave.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpySave.count(), 0); QCOMPARE(rowsAboutToBeMovedSpySave.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpySave.count(), 3); QCOMPARE(rowsRemovedSpySave.count(), 0); QCOMPARE(rowsMovedSpySave.count(), 0); QCOMPARE(rowsInsertedSpySave.count(), 3); QCOMPARE(trackHasBeenAddedSpySave.count(), 3); QCOMPARE(persistentStateChangedSpySave.count(), 3); QCOMPARE(dataChangedSpySave.count(), 3); QCOMPARE(newTrackByIdInListSpySave.count(), 3); QCOMPARE(newTrackByNameInListSpySave.count(), 0); QCOMPARE(newArtistInListSpySave.count(), 0); QCOMPARE(rowsAboutToBeRemovedSpyRead.count(), 0); QCOMPARE(rowsAboutToBeMovedSpyRead.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpyRead.count(), 0); QCOMPARE(rowsRemovedSpyRead.count(), 0); QCOMPARE(rowsMovedSpyRead.count(), 0); QCOMPARE(rowsInsertedSpyRead.count(), 0); QCOMPARE(trackHasBeenAddedSpyRead.count(), 0); QCOMPARE(persistentStateChangedSpyRead.count(), 0); QCOMPARE(dataChangedSpyRead.count(), 0); QCOMPARE(newTrackByIdInListSpyRead.count(), 0); QCOMPARE(newTrackByNameInListSpyRead.count(), 0); QCOMPARE(newArtistInListSpyRead.count(), 0); QCOMPARE(myPlayListSave.data(myPlayListSave.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayListSave.data(myPlayListSave.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayListSave.data(myPlayListSave.index(0, 0), MediaPlayList::ColumnsRoles::DurationRole).toBool(), true); QCOMPARE(myPlayListSave.data(myPlayListSave.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist2")); QCOMPARE(myPlayListSave.data(myPlayListSave.index(0, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist2")); QCOMPARE(myPlayListSave.data(myPlayListSave.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album3")); QCOMPARE(myPlayListSave.data(myPlayListSave.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayListSave.data(myPlayListSave.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayListSave.data(myPlayListSave.index(0, 0), MediaPlayList::ColumnsRoles::ImageRole).toUrl(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(myPlayListSave.data(myPlayListSave.index(0, 0), MediaPlayList::ColumnsRoles::ResourceRole).toUrl(), QUrl::fromUserInput(QStringLiteral("/$11"))); QCOMPARE(myPlayListSave.data(myPlayListSave.index(0, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); QCOMPARE(myPlayListSave.data(myPlayListSave.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayListSave.data(myPlayListSave.index(0, 0), MediaPlayList::ColumnsRoles::IsSingleDiscAlbumHeader).toBool(), true); QCOMPARE(myPlayListSave.data(myPlayListSave.index(1, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayListSave.data(myPlayListSave.index(1, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayListSave.data(myPlayListSave.index(1, 0), MediaPlayList::ColumnsRoles::DurationRole).toBool(), true); QCOMPARE(myPlayListSave.data(myPlayListSave.index(1, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayListSave.data(myPlayListSave.index(1, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("Various Artists")); QCOMPARE(myPlayListSave.data(myPlayListSave.index(1, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayListSave.data(myPlayListSave.index(1, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayListSave.data(myPlayListSave.index(1, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayListSave.data(myPlayListSave.index(1, 0), MediaPlayList::ColumnsRoles::ImageRole).toUrl(), QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(myPlayListSave.data(myPlayListSave.index(1, 0), MediaPlayList::ColumnsRoles::ResourceRole).toUrl(), QUrl::fromUserInput(QStringLiteral("/$1"))); QCOMPARE(myPlayListSave.data(myPlayListSave.index(1, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); QCOMPARE(myPlayListSave.data(myPlayListSave.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayListSave.data(myPlayListSave.index(1, 0), MediaPlayList::ColumnsRoles::IsSingleDiscAlbumHeader).toBool(), false); QCOMPARE(myPlayListSave.data(myPlayListSave.index(2, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayListSave.data(myPlayListSave.index(2, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track2")); QCOMPARE(myPlayListSave.data(myPlayListSave.index(2, 0), MediaPlayList::ColumnsRoles::DurationRole).toBool(), true); QCOMPARE(myPlayListSave.data(myPlayListSave.index(2, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist2")); QCOMPARE(myPlayListSave.data(myPlayListSave.index(2, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist2")); QCOMPARE(myPlayListSave.data(myPlayListSave.index(2, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album3")); QCOMPARE(myPlayListSave.data(myPlayListSave.index(2, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 2); QCOMPARE(myPlayListSave.data(myPlayListSave.index(2, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayListSave.data(myPlayListSave.index(2, 0), MediaPlayList::ColumnsRoles::ImageRole).toUrl(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(myPlayListSave.data(myPlayListSave.index(2, 0), MediaPlayList::ColumnsRoles::ResourceRole).toUrl(), QUrl::fromUserInput(QStringLiteral("/$12"))); QCOMPARE(myPlayListSave.data(myPlayListSave.index(2, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); QCOMPARE(myPlayListSave.data(myPlayListSave.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayListSave.data(myPlayListSave.index(2, 0), MediaPlayList::ColumnsRoles::IsSingleDiscAlbumHeader).toBool(), true); myPlayListRead.setPersistentState(myPlayListSave.persistentState()); QCOMPARE(dataChangedSpyRead.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpySave.count(), 0); QCOMPARE(rowsAboutToBeMovedSpySave.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpySave.count(), 3); QCOMPARE(rowsRemovedSpySave.count(), 0); QCOMPARE(rowsMovedSpySave.count(), 0); QCOMPARE(rowsInsertedSpySave.count(), 3); QCOMPARE(trackHasBeenAddedSpySave.count(), 3); QCOMPARE(persistentStateChangedSpySave.count(), 3); QCOMPARE(dataChangedSpySave.count(), 3); QCOMPARE(newTrackByIdInListSpySave.count(), 3); QCOMPARE(newTrackByNameInListSpySave.count(), 0); QCOMPARE(newArtistInListSpySave.count(), 0); QCOMPARE(rowsAboutToBeRemovedSpyRead.count(), 0); QCOMPARE(rowsAboutToBeMovedSpyRead.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpyRead.count(), 3); QCOMPARE(rowsRemovedSpyRead.count(), 0); QCOMPARE(rowsMovedSpyRead.count(), 0); QCOMPARE(rowsInsertedSpyRead.count(), 3); QCOMPARE(trackHasBeenAddedSpyRead.count(), 3); QCOMPARE(persistentStateChangedSpyRead.count(), 4); QCOMPARE(dataChangedSpyRead.count(), 6); QCOMPARE(newTrackByIdInListSpyRead.count(), 0); QCOMPARE(newTrackByNameInListSpyRead.count(), 3); QCOMPARE(newArtistInListSpyRead.count(), 0); QCOMPARE(myPlayListRead.tracksCount(), 3); QCOMPARE(myPlayListRead.data(myPlayListRead.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayListRead.data(myPlayListRead.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayListRead.data(myPlayListRead.index(0, 0), MediaPlayList::ColumnsRoles::DurationRole).toBool(), true); QCOMPARE(myPlayListRead.data(myPlayListRead.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist2")); QCOMPARE(myPlayListRead.data(myPlayListRead.index(0, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist2")); QCOMPARE(myPlayListRead.data(myPlayListRead.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album3")); QCOMPARE(myPlayListRead.data(myPlayListRead.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayListRead.data(myPlayListRead.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayListRead.data(myPlayListRead.index(0, 0), MediaPlayList::ColumnsRoles::ImageRole).toUrl(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(myPlayListRead.data(myPlayListRead.index(0, 0), MediaPlayList::ColumnsRoles::ResourceRole).toUrl(), QUrl::fromUserInput(QStringLiteral("/$11"))); QCOMPARE(myPlayListRead.data(myPlayListRead.index(0, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); QCOMPARE(myPlayListRead.data(myPlayListRead.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayListRead.data(myPlayListRead.index(0, 0), MediaPlayList::ColumnsRoles::IsSingleDiscAlbumHeader).toBool(), true); QCOMPARE(myPlayListRead.data(myPlayListRead.index(1, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayListRead.data(myPlayListRead.index(1, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayListRead.data(myPlayListRead.index(1, 0), MediaPlayList::ColumnsRoles::DurationRole).toBool(), true); QCOMPARE(myPlayListRead.data(myPlayListRead.index(1, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayListRead.data(myPlayListRead.index(1, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("Various Artists")); QCOMPARE(myPlayListRead.data(myPlayListRead.index(1, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayListRead.data(myPlayListRead.index(1, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayListRead.data(myPlayListRead.index(1, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayListRead.data(myPlayListRead.index(1, 0), MediaPlayList::ColumnsRoles::ImageRole).toUrl(), QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(myPlayListRead.data(myPlayListRead.index(1, 0), MediaPlayList::ColumnsRoles::ResourceRole).toUrl(), QUrl::fromUserInput(QStringLiteral("/$1"))); QCOMPARE(myPlayListRead.data(myPlayListRead.index(1, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); QCOMPARE(myPlayListRead.data(myPlayListRead.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayListRead.data(myPlayListRead.index(1, 0), MediaPlayList::ColumnsRoles::IsSingleDiscAlbumHeader).toBool(), false); QCOMPARE(myPlayListRead.data(myPlayListRead.index(2, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayListRead.data(myPlayListRead.index(2, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track2")); QCOMPARE(myPlayListRead.data(myPlayListRead.index(2, 0), MediaPlayList::ColumnsRoles::DurationRole).toBool(), true); QCOMPARE(myPlayListRead.data(myPlayListRead.index(2, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist2")); QCOMPARE(myPlayListRead.data(myPlayListRead.index(2, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist2")); QCOMPARE(myPlayListRead.data(myPlayListRead.index(2, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album3")); QCOMPARE(myPlayListRead.data(myPlayListRead.index(2, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 2); QCOMPARE(myPlayListRead.data(myPlayListRead.index(2, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayListRead.data(myPlayListRead.index(2, 0), MediaPlayList::ColumnsRoles::ImageRole).toUrl(), QUrl::fromLocalFile(QStringLiteral("album3"))); QCOMPARE(myPlayListRead.data(myPlayListRead.index(2, 0), MediaPlayList::ColumnsRoles::ResourceRole).toUrl(), QUrl::fromUserInput(QStringLiteral("/$12"))); QCOMPARE(myPlayListRead.data(myPlayListRead.index(2, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); QCOMPARE(myPlayListRead.data(myPlayListRead.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayListRead.data(myPlayListRead.index(2, 0), MediaPlayList::ColumnsRoles::IsSingleDiscAlbumHeader).toBool(), true); } void MediaPlayListTest::testReplaceAndPlayArtist() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myPlayList.replaceAndPlay(QStringLiteral("artist3")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 1); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 1); QCOMPARE(myPlayList.tracksCount(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track3")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DurationRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist3")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("Various Artists")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ImageRole).toUrl(), QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ResourceRole).toUrl(), QUrl::fromUserInput(QStringLiteral("/$3"))); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsSingleDiscAlbumHeader).toBool(), false); myPlayList.replaceAndPlay(QStringLiteral("artist4")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 1); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 1); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 2); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 1); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 1); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 4); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 2); QCOMPARE(myPlayList.tracksCount(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track4")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DurationRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist4")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("Various Artists")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 4); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 4); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ImageRole).toUrl(), QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ResourceRole).toUrl(), QUrl::fromUserInput(QStringLiteral("/$4"))); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsSingleDiscAlbumHeader).toBool(), false); } void MediaPlayListTest::testReplaceAndPlayTrackId() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); auto firstTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3); QCOMPARE(firstTrackId != 0, true); myPlayList.replaceAndPlay(firstTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.tracksCount(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track3")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DurationRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist3")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("Various Artists")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ImageRole).toUrl(), QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ResourceRole).toUrl(), QUrl::fromUserInput(QStringLiteral("/$3"))); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsSingleDiscAlbumHeader).toBool(), false); auto secondTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), 4, 4); QCOMPARE(secondTrackId != 0, true); myPlayList.replaceAndPlay(secondTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 1); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 1); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 1); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 1); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.tracksCount(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track4")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DurationRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist4")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("Various Artists")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 4); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 4); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ImageRole).toUrl(), QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ResourceRole).toUrl(), QUrl::fromUserInput(QStringLiteral("/$4"))); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsSingleDiscAlbumHeader).toBool(), false); } void MediaPlayListTest::testReplaceAndPlayTrackData() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); auto firstTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3); QCOMPARE(firstTrackId != 0, true); auto firstTrack = myDatabaseContent.trackFromDatabaseId(firstTrackId); QCOMPARE(firstTrack.isValid(), true); myPlayList.replaceAndPlay(firstTrack); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.tracksCount(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track3")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DurationRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist3")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("Various Artists")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ImageRole).toUrl(), QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ResourceRole).toUrl(), QUrl::fromUserInput(QStringLiteral("file:///$3"))); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsSingleDiscAlbumHeader).toBool(), false); auto secondTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), 4, 4); QCOMPARE(secondTrackId != 0, true); auto secondTrack = myDatabaseContent.trackFromDatabaseId(secondTrackId); QCOMPARE(secondTrack.isValid(), true); myPlayList.replaceAndPlay(secondTrack); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 1); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 1); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.tracksCount(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track4")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DurationRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist4")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("Various Artists")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 4); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 4); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ImageRole).toUrl(), QUrl::fromLocalFile(QStringLiteral("album1"))); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ResourceRole).toUrl(), QUrl::fromUserInput(QStringLiteral("/$4"))); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsSingleDiscAlbumHeader).toBool(), false); } void MediaPlayListTest::testSetData() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); auto firstTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album3"), 1, 1); myPlayList.enqueue(firstTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 1); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 1); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); auto secondTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); myPlayList.enqueue(secondTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 2); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); auto thirdTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album3"), 2, 1); myPlayList.enqueue(thirdTrackId); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 3); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.setData(myPlayList.index(2, 0), true, MediaPlayList::ColumnsRoles::IsPlayingRole), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 4); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::HasAlbumHeader).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.setData(myPlayList.index(2, 0), true, MediaPlayList::ColumnsRoles::TitleRole), false); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 4); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.setData(myPlayList.index(4, 0), true, MediaPlayList::ColumnsRoles::TitleRole), false); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 4); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.setData({}, true, MediaPlayList::ColumnsRoles::TitleRole), false); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 3); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 3); QCOMPARE(trackHasBeenAddedSpy.count(), 3); QCOMPARE(persistentStateChangedSpy.count(), 3); QCOMPARE(dataChangedSpy.count(), 4); QCOMPARE(newTrackByIdInListSpy.count(), 3); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); } void MediaPlayListTest::testRemoveSelection() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myPlayList.replaceAndPlay(QStringLiteral("artist1")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 1); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 1); QCOMPARE(myPlayList.tracksCount(), 6); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("Various Artists")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track2")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 2); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track3")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track4")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 4); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track5")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 5); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); myPlayList.removeSelection({2, 4, 5}); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 3); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 3); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 5); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 1); QCOMPARE(myPlayList.tracksCount(), 3); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("Various Artists")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track3")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); } void MediaPlayListTest::testTrackBeenRemoved() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myPlayList.replaceAndPlay(QStringLiteral("artist1")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 1); QCOMPARE(dataChangedSpy.wait(), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 1); QCOMPARE(myPlayList.tracksCount(), 6); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("Various Artists")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track2")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 2); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track3")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track4")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 4); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track5")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 5); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); auto removedTrackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), 2, 1); QCOMPARE(removedTrackId != 0, true); auto removedTrack = myDatabaseContent.trackFromDatabaseId(removedTrackId); QCOMPARE(removedTrack.isValid(), true); myPlayList.trackRemoved(removedTrack.databaseId()); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 1); QCOMPARE(myPlayList.tracksCount(), 6); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("Various Artists")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track2")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), -1); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 0); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track3")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track4")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 4); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track5")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::AlbumArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 5); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); } CrashEnqueuePlayList::CrashEnqueuePlayList(MediaPlayList *list, QObject *parent) : QObject(parent), mList(list) { } void CrashEnqueuePlayList::crashMediaPlayList() { mList->data(mList->index(0, 0), MediaPlayList::ResourceRole); } void MediaPlayListTest::testBringUpCase() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSpy(&myPlayList, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSpy(&myPlayList, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSpy(&myPlayList, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); } void MediaPlayListTest::testBringUpCaseFromNewAlbum() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSpy(&myPlayList, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSpy(&myPlayList, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSpy(&myPlayList, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); auto newTrackID = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 2); myPlayList.enqueue(newTrackID); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); } void MediaPlayListTest::testBringUpAndDownCase() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSpy(&myPlayList, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSpy(&myPlayList, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSpy(&myPlayList, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.removeRow(0); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 1); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex()); } void MediaPlayListTest::testBringUpAndRemoveCase() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSpy(&myPlayList, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSpy(&myPlayList, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSpy(&myPlayList, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.removeRow(0); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 1); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex()); } void MediaPlayListTest::testBringUpAndRemoveMultipleCase() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSpy(&myPlayList, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSpy(&myPlayList, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSpy(&myPlayList, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.enqueue({QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album1"), 2, 2}); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.removeRow(0); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); } void MediaPlayListTest::testBringUpAndRemoveMultipleNotBeginCase() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSpy(&myPlayList, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSpy(&myPlayList, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSpy(&myPlayList, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.enqueue({QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album1"), 2, 2}); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.enqueue({QStringLiteral("track4"), QStringLiteral("artist1"), QStringLiteral("album2"), 4, 1}); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); myPlayList.removeRow(1); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); } void MediaPlayListTest::testBringUpAndPlayCase() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSpy(&myPlayList, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSpy(&myPlayList, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSpy(&myPlayList, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); myPlayList.enqueue({QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album1"), 3, 3}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); } void MediaPlayListTest::testBringUpAndSkipNextCase() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSpy(&myPlayList, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSpy(&myPlayList, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSpy(&myPlayList, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); myPlayList.enqueue({QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album1"), 3, 3}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); } void MediaPlayListTest::testBringUpAndSkipPreviousCase() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSpy(&myPlayList, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSpy(&myPlayList, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSpy(&myPlayList, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); myPlayList.enqueue({QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album1"), 3, 3}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); myPlayList.skipPreviousTrack(); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); } void MediaPlayListTest::testBringUpAndSkipPreviousAndContinueCase() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSpy(&myPlayList, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSpy(&myPlayList, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSpy(&myPlayList, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.setRepeatPlay(true); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); myPlayList.enqueue({QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3}); myPlayList.enqueue({QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), 2, 1}); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1}); myPlayList.enqueue({QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), 3, 1}); myPlayList.enqueue({QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album1"), 2, 2}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(2, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 4); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(3, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 5); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(4, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 6); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(5, 0))); myPlayList.skipPreviousTrack(); QCOMPARE(currentTrackChangedSpy.count(), 7); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(4, 0))); myPlayList.skipPreviousTrack(); QCOMPARE(currentTrackChangedSpy.count(), 8); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(3, 0))); myPlayList.skipPreviousTrack(); QCOMPARE(currentTrackChangedSpy.count(), 9); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(2, 0))); myPlayList.skipPreviousTrack(); QCOMPARE(currentTrackChangedSpy.count(), 10); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); myPlayList.skipPreviousTrack(); QCOMPARE(currentTrackChangedSpy.count(), 11); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.skipPreviousTrack(); QCOMPARE(currentTrackChangedSpy.count(), 12); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(5, 0))); } void MediaPlayListTest::finishPlayList() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSpy(&myPlayList, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSpy(&myPlayList, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSpy(&myPlayList, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); myPlayList.enqueue({QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album1"), 3, 3}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 1); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); } void MediaPlayListTest::randomPlayList() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSpy(&myPlayList, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSpy(&myPlayList, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSpy(&myPlayList, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.seedRandomGenerator(0); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); myPlayList.enqueue({QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3}); myPlayList.enqueue({QStringLiteral("track5"), QStringLiteral("artist1"), QStringLiteral("album2"), 5, 1}); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.setRandomPlay(true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 1); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.randomPlay(), true); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(randomPlayChangedSpy.count(), 1); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(randomPlayChangedSpy.count(), 1); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 4); QCOMPARE(randomPlayChangedSpy.count(), 1); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 5); QCOMPARE(randomPlayChangedSpy.count(), 1); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); } void MediaPlayListTest::randomAndContinuePlayList() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSpy(&myPlayList, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSpy(&myPlayList, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSpy(&myPlayList, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.seedRandomGenerator(0); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); myPlayList.enqueue({QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3}); myPlayList.enqueue({QStringLiteral("track5"), QStringLiteral("artist1"), QStringLiteral("album2"), 5, 1}); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.setRandomPlay(true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 1); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.randomPlay(), true); myPlayList.setRepeatPlay(true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 1); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.repeatPlay(), true); myPlayList.switchTo(3); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(randomPlayChangedSpy.count(), 1); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(3, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(randomPlayChangedSpy.count(), 1); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 4); QCOMPARE(randomPlayChangedSpy.count(), 1); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 5); QCOMPARE(randomPlayChangedSpy.count(), 1); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); } void MediaPlayListTest::continuePlayList() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSpy(&myPlayList, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSpy(&myPlayList, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSpy(&myPlayList, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.seedRandomGenerator(0); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); myPlayList.enqueue({QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3}); myPlayList.enqueue({QStringLiteral("track5"), QStringLiteral("artist1"), QStringLiteral("album2"), 5, 1}); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.setRepeatPlay(true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.repeatPlay(), true); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(2, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 4); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(3, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 5); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); } void MediaPlayListTest::testRestoreSettings() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSpy(&myPlayList, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSpy(&myPlayList, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSpy(&myPlayList, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); QVariantMap settings; settings[QStringLiteral("currentTrack")] = 2; settings[QStringLiteral("randomPlay")] = true; settings[QStringLiteral("repeatPlay")] = true; myPlayList.setPersistentState(settings); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 1); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.seedRandomGenerator(0); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 1); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); myPlayList.enqueue({QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3}); myPlayList.enqueue({QStringLiteral("track5"), QStringLiteral("artist1"), QStringLiteral("album2"), 5, 1}); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1}); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 1); QCOMPARE(repeatPlayChangedSpy.count(), 1); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(2, 0))); } void MediaPlayListTest::testSaveAndRestoreSettings() { MediaPlayList myPlayListSave; QAbstractItemModelTester testModelSave(&myPlayListSave); DatabaseInterface myDatabaseContent; TracksListener myListenerSave(&myDatabaseContent); MediaPlayList myPlayListRestore; QAbstractItemModelTester testModelRestore(&myPlayListRestore); TracksListener myListenerRestore(&myDatabaseContent); QSignalSpy currentTrackChangedSaveSpy(&myPlayListSave, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSaveSpy(&myPlayListSave, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSaveSpy(&myPlayListSave, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSaveSpy(&myPlayListSave, &MediaPlayList::playListFinished); QSignalSpy currentTrackChangedRestoreSpy(&myPlayListRestore, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedRestoreSpy(&myPlayListRestore, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedRestoreSpy(&myPlayListRestore, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedRestoreSpy(&myPlayListRestore, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListenerSave, &TracksListener::trackHasChanged, &myPlayListSave, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListenerSave, &TracksListener::albumAdded, &myPlayListSave, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayListSave, &MediaPlayList::newTrackByIdInList, &myListenerSave, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayListSave, &MediaPlayList::newTrackByNameInList, &myListenerSave, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayListSave, &MediaPlayList::newTrackByFileNameInList, &myListenerSave, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayListSave, &MediaPlayList::newArtistInList, &myListenerSave, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListenerSave, &TracksListener::tracksAdded); connect(&myListenerRestore, &TracksListener::trackHasChanged, &myPlayListRestore, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListenerRestore, &TracksListener::albumAdded, &myPlayListRestore, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayListRestore, &MediaPlayList::newTrackByIdInList, &myListenerRestore, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayListRestore, &MediaPlayList::newTrackByNameInList, &myListenerRestore, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayListRestore, &MediaPlayList::newTrackByFileNameInList, &myListenerRestore, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayListRestore, &MediaPlayList::newArtistInList, &myListenerRestore, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListenerRestore, &TracksListener::tracksAdded); QCOMPARE(currentTrackChangedSaveSpy.count(), 0); QCOMPARE(randomPlayChangedSaveSpy.count(), 0); QCOMPARE(repeatPlayChangedSaveSpy.count(), 0); QCOMPARE(playListFinishedSaveSpy.count(), 0); QCOMPARE(currentTrackChangedRestoreSpy.count(), 0); QCOMPARE(randomPlayChangedRestoreSpy.count(), 0); QCOMPARE(repeatPlayChangedRestoreSpy.count(), 0); QCOMPARE(playListFinishedRestoreSpy.count(), 0); myPlayListSave.seedRandomGenerator(0); QCOMPARE(currentTrackChangedSaveSpy.count(), 0); QCOMPARE(randomPlayChangedSaveSpy.count(), 0); QCOMPARE(repeatPlayChangedSaveSpy.count(), 0); QCOMPARE(playListFinishedSaveSpy.count(), 0); QCOMPARE(currentTrackChangedRestoreSpy.count(), 0); QCOMPARE(randomPlayChangedRestoreSpy.count(), 0); QCOMPARE(repeatPlayChangedRestoreSpy.count(), 0); QCOMPARE(playListFinishedRestoreSpy.count(), 0); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSaveSpy.count(), 0); QCOMPARE(randomPlayChangedSaveSpy.count(), 0); QCOMPARE(repeatPlayChangedSaveSpy.count(), 0); QCOMPARE(playListFinishedSaveSpy.count(), 0); QCOMPARE(currentTrackChangedRestoreSpy.count(), 0); QCOMPARE(randomPlayChangedRestoreSpy.count(), 0); QCOMPARE(repeatPlayChangedRestoreSpy.count(), 0); QCOMPARE(playListFinishedRestoreSpy.count(), 0); myPlayListSave.setRepeatPlay(true); QCOMPARE(currentTrackChangedSaveSpy.count(), 0); QCOMPARE(randomPlayChangedSaveSpy.count(), 0); QCOMPARE(repeatPlayChangedSaveSpy.count(), 1); QCOMPARE(playListFinishedSaveSpy.count(), 0); QCOMPARE(currentTrackChangedRestoreSpy.count(), 0); QCOMPARE(randomPlayChangedRestoreSpy.count(), 0); QCOMPARE(repeatPlayChangedRestoreSpy.count(), 0); QCOMPARE(playListFinishedRestoreSpy.count(), 0); myPlayListSave.setRandomPlay(true); QCOMPARE(currentTrackChangedSaveSpy.count(), 0); QCOMPARE(randomPlayChangedSaveSpy.count(), 1); QCOMPARE(repeatPlayChangedSaveSpy.count(), 1); QCOMPARE(playListFinishedSaveSpy.count(), 0); QCOMPARE(currentTrackChangedRestoreSpy.count(), 0); QCOMPARE(randomPlayChangedRestoreSpy.count(), 0); QCOMPARE(repeatPlayChangedRestoreSpy.count(), 0); QCOMPARE(playListFinishedRestoreSpy.count(), 0); myPlayListSave.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); myPlayListSave.enqueue({QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3}); myPlayListSave.enqueue({QStringLiteral("track5"), QStringLiteral("artist1"), QStringLiteral("album2"), 5, 1}); myPlayListSave.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1}); QCOMPARE(currentTrackChangedSaveSpy.count(), 0); QCOMPARE(randomPlayChangedSaveSpy.count(), 1); QCOMPARE(repeatPlayChangedSaveSpy.count(), 1); QCOMPARE(playListFinishedSaveSpy.count(), 0); QCOMPARE(currentTrackChangedRestoreSpy.count(), 0); QCOMPARE(randomPlayChangedRestoreSpy.count(), 0); QCOMPARE(repeatPlayChangedRestoreSpy.count(), 0); QCOMPARE(playListFinishedRestoreSpy.count(), 0); QCOMPARE(currentTrackChangedSaveSpy.wait(), true); QCOMPARE(currentTrackChangedSaveSpy.count(), 1); QCOMPARE(randomPlayChangedSaveSpy.count(), 1); QCOMPARE(repeatPlayChangedSaveSpy.count(), 1); QCOMPARE(playListFinishedSaveSpy.count(), 0); QCOMPARE(currentTrackChangedRestoreSpy.count(), 0); QCOMPARE(randomPlayChangedRestoreSpy.count(), 0); QCOMPARE(repeatPlayChangedRestoreSpy.count(), 0); QCOMPARE(playListFinishedRestoreSpy.count(), 0); QCOMPARE(myPlayListSave.currentTrack(), QPersistentModelIndex(myPlayListSave.index(0, 0))); myPlayListSave.skipNextTrack(); QCOMPARE(currentTrackChangedSaveSpy.count(), 2); QCOMPARE(randomPlayChangedSaveSpy.count(), 1); QCOMPARE(repeatPlayChangedSaveSpy.count(), 1); QCOMPARE(playListFinishedSaveSpy.count(), 0); QCOMPARE(currentTrackChangedRestoreSpy.count(), 0); QCOMPARE(randomPlayChangedRestoreSpy.count(), 0); QCOMPARE(repeatPlayChangedRestoreSpy.count(), 0); QCOMPARE(playListFinishedRestoreSpy.count(), 0); myPlayListSave.skipNextTrack(); QCOMPARE(currentTrackChangedSaveSpy.count(), 3); QCOMPARE(randomPlayChangedSaveSpy.count(), 1); QCOMPARE(repeatPlayChangedSaveSpy.count(), 1); QCOMPARE(playListFinishedSaveSpy.count(), 0); QCOMPARE(currentTrackChangedRestoreSpy.count(), 0); QCOMPARE(randomPlayChangedRestoreSpy.count(), 0); QCOMPARE(repeatPlayChangedRestoreSpy.count(), 0); QCOMPARE(playListFinishedRestoreSpy.count(), 0); myPlayListRestore.setPersistentState(myPlayListSave.persistentState()); QCOMPARE(currentTrackChangedSaveSpy.count(), 3); QCOMPARE(randomPlayChangedSaveSpy.count(), 1); QCOMPARE(repeatPlayChangedSaveSpy.count(), 1); QCOMPARE(playListFinishedSaveSpy.count(), 0); QCOMPARE(currentTrackChangedRestoreSpy.count(), 1); QCOMPARE(randomPlayChangedRestoreSpy.count(), 1); QCOMPARE(repeatPlayChangedRestoreSpy.count(), 1); QCOMPARE(playListFinishedRestoreSpy.count(), 0); qDebug() << myPlayListRestore.currentTrack(); QCOMPARE(myPlayListRestore.repeatPlay(), true); QCOMPARE(myPlayListRestore.randomPlay(), true); const auto indexSavePlaylist = myPlayListRestore.currentTrack(); QCOMPARE(myPlayListRestore.currentTrack(), QPersistentModelIndex(myPlayListRestore.index(indexSavePlaylist.row(), 0))); } void MediaPlayListTest::removeBeforeCurrentTrack() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSpy(&myPlayList, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSpy(&myPlayList, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSpy(&myPlayList, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); myPlayList.enqueue({QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3}); myPlayList.enqueue({QStringLiteral("track5"), QStringLiteral("artist1"), QStringLiteral("album2"), 5, 1}); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(2, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 4); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(3, 0))); myPlayList.removeRow(1); QCOMPARE(currentTrackChangedSpy.count(), 4); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); } void MediaPlayListTest::switchToTrackTest() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSpy(&myPlayList, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSpy(&myPlayList, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSpy(&myPlayList, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); myPlayList.enqueue({QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3}); myPlayList.enqueue({QStringLiteral("track4"), QStringLiteral("artist1"), QStringLiteral("album1"), 4, 4}); myPlayList.enqueue({QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album1"), 2, 2}); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.switchTo(4); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(4, 0))); } void MediaPlayListTest::singleTrack() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSpy(&myPlayList, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSpy(&myPlayList, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSpy(&myPlayList, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 1); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); } void MediaPlayListTest::testBringUpAndRemoveLastCase() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy currentTrackChangedSpy(&myPlayList, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSpy(&myPlayList, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSpy(&myPlayList, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSpy(&myPlayList, &MediaPlayList::playListFinished); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); myPlayList.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); myPlayList.enqueue({QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), 2, 1}); myPlayList.enqueue({QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), 3, 1}); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(currentTrackChangedSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); myPlayList.skipNextTrack(); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 0); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(2, 0))); myPlayList.removeRow(2); QCOMPARE(currentTrackChangedSpy.count(), 4); QCOMPARE(randomPlayChangedSpy.count(), 0); QCOMPARE(repeatPlayChangedSpy.count(), 0); QCOMPARE(playListFinishedSpy.count(), 1); QCOMPARE(myPlayList.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); } void MediaPlayListTest::testSaveLoadPlayList() { MediaPlayList myPlayListSave; QAbstractItemModelTester testModelSave(&myPlayListSave); DatabaseInterface myDatabaseContent; TracksListener myListenerSave(&myDatabaseContent); MediaPlayList myPlayListRestore; QAbstractItemModelTester testModelRestore(&myPlayListRestore); TracksListener myListenerRestore(&myDatabaseContent); QSignalSpy currentTrackChangedSaveSpy(&myPlayListSave, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedSaveSpy(&myPlayListSave, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedSaveSpy(&myPlayListSave, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedSaveSpy(&myPlayListSave, &MediaPlayList::playListFinished); QSignalSpy playListLoadedSaveSpy(&myPlayListSave, &MediaPlayList::playListLoaded); QSignalSpy playListLoadFailedSaveSpy(&myPlayListSave, &MediaPlayList::playListLoadFailed); QSignalSpy currentTrackChangedRestoreSpy(&myPlayListRestore, &MediaPlayList::currentTrackChanged); QSignalSpy randomPlayChangedRestoreSpy(&myPlayListRestore, &MediaPlayList::randomPlayChanged); QSignalSpy repeatPlayChangedRestoreSpy(&myPlayListRestore, &MediaPlayList::repeatPlayChanged); QSignalSpy playListFinishedRestoreSpy(&myPlayListRestore, &MediaPlayList::playListFinished); QSignalSpy playListLoadedRestoreSpy(&myPlayListRestore, &MediaPlayList::playListLoaded); QSignalSpy playListLoadFailedRestoreSpy(&myPlayListRestore, &MediaPlayList::playListLoadFailed); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListenerSave, &TracksListener::trackHasChanged, &myPlayListSave, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListenerSave, &TracksListener::albumAdded, &myPlayListSave, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayListSave, &MediaPlayList::newTrackByIdInList, &myListenerSave, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayListSave, &MediaPlayList::newTrackByNameInList, &myListenerSave, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayListSave, &MediaPlayList::newTrackByFileNameInList, &myListenerSave, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayListSave, &MediaPlayList::newArtistInList, &myListenerSave, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListenerSave, &TracksListener::tracksAdded); connect(&myListenerRestore, &TracksListener::trackHasChanged, &myPlayListRestore, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListenerRestore, &TracksListener::albumAdded, &myPlayListRestore, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayListRestore, &MediaPlayList::newTrackByIdInList, &myListenerRestore, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayListRestore, &MediaPlayList::newTrackByNameInList, &myListenerRestore, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayListRestore, &MediaPlayList::newTrackByFileNameInList, &myListenerRestore, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayListRestore, &MediaPlayList::newArtistInList, &myListenerRestore, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListenerRestore, &TracksListener::tracksAdded); QCOMPARE(currentTrackChangedSaveSpy.count(), 0); QCOMPARE(randomPlayChangedSaveSpy.count(), 0); QCOMPARE(repeatPlayChangedSaveSpy.count(), 0); QCOMPARE(playListFinishedSaveSpy.count(), 0); QCOMPARE(playListLoadedSaveSpy.count(), 0); QCOMPARE(playListLoadFailedSaveSpy.count(), 0); QCOMPARE(currentTrackChangedRestoreSpy.count(), 0); QCOMPARE(randomPlayChangedRestoreSpy.count(), 0); QCOMPARE(repeatPlayChangedRestoreSpy.count(), 0); QCOMPARE(playListFinishedRestoreSpy.count(), 0); QCOMPARE(playListLoadedRestoreSpy.count(), 0); QCOMPARE(playListLoadFailedRestoreSpy.count(), 0); myPlayListSave.seedRandomGenerator(0); QCOMPARE(currentTrackChangedSaveSpy.count(), 0); QCOMPARE(randomPlayChangedSaveSpy.count(), 0); QCOMPARE(repeatPlayChangedSaveSpy.count(), 0); QCOMPARE(playListFinishedSaveSpy.count(), 0); QCOMPARE(playListLoadedSaveSpy.count(), 0); QCOMPARE(playListLoadFailedSaveSpy.count(), 0); QCOMPARE(currentTrackChangedRestoreSpy.count(), 0); QCOMPARE(randomPlayChangedRestoreSpy.count(), 0); QCOMPARE(repeatPlayChangedRestoreSpy.count(), 0); QCOMPARE(playListFinishedRestoreSpy.count(), 0); QCOMPARE(playListLoadedRestoreSpy.count(), 0); QCOMPARE(playListLoadFailedRestoreSpy.count(), 0); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(currentTrackChangedSaveSpy.count(), 0); QCOMPARE(randomPlayChangedSaveSpy.count(), 0); QCOMPARE(repeatPlayChangedSaveSpy.count(), 0); QCOMPARE(playListFinishedSaveSpy.count(), 0); QCOMPARE(playListLoadedSaveSpy.count(), 0); QCOMPARE(playListLoadFailedSaveSpy.count(), 0); QCOMPARE(currentTrackChangedRestoreSpy.count(), 0); QCOMPARE(randomPlayChangedRestoreSpy.count(), 0); QCOMPARE(repeatPlayChangedRestoreSpy.count(), 0); QCOMPARE(playListFinishedRestoreSpy.count(), 0); QCOMPARE(playListLoadedRestoreSpy.count(), 0); QCOMPARE(playListLoadFailedRestoreSpy.count(), 0); myPlayListSave.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1}); myPlayListSave.enqueue({QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), 3, 3}); myPlayListSave.enqueue({QStringLiteral("track5"), QStringLiteral("artist1"), QStringLiteral("album2"), 5, 1}); myPlayListSave.enqueue({QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1}); QCOMPARE(currentTrackChangedSaveSpy.count(), 0); QCOMPARE(randomPlayChangedSaveSpy.count(), 0); QCOMPARE(repeatPlayChangedSaveSpy.count(), 0); QCOMPARE(playListFinishedSaveSpy.count(), 0); QCOMPARE(playListLoadedSaveSpy.count(), 0); QCOMPARE(playListLoadFailedSaveSpy.count(), 0); QCOMPARE(currentTrackChangedRestoreSpy.count(), 0); QCOMPARE(randomPlayChangedRestoreSpy.count(), 0); QCOMPARE(repeatPlayChangedRestoreSpy.count(), 0); QCOMPARE(playListFinishedRestoreSpy.count(), 0); QCOMPARE(playListLoadedRestoreSpy.count(), 0); QCOMPARE(playListLoadFailedRestoreSpy.count(), 0); QCOMPARE(currentTrackChangedSaveSpy.wait(), true); QCOMPARE(currentTrackChangedSaveSpy.count(), 1); QCOMPARE(randomPlayChangedSaveSpy.count(), 0); QCOMPARE(repeatPlayChangedSaveSpy.count(), 0); QCOMPARE(playListFinishedSaveSpy.count(), 0); QCOMPARE(playListLoadedSaveSpy.count(), 0); QCOMPARE(playListLoadFailedSaveSpy.count(), 0); QCOMPARE(currentTrackChangedRestoreSpy.count(), 0); QCOMPARE(randomPlayChangedRestoreSpy.count(), 0); QCOMPARE(repeatPlayChangedRestoreSpy.count(), 0); QCOMPARE(playListFinishedRestoreSpy.count(), 0); QCOMPARE(playListLoadedRestoreSpy.count(), 0); QCOMPARE(playListLoadFailedRestoreSpy.count(), 0); QCOMPARE(myPlayListSave.currentTrack(), QPersistentModelIndex(myPlayListSave.index(0, 0))); QTemporaryFile playlistFile(QStringLiteral("./myPlaylistXXXXXX.m3u")); playlistFile.open(); QCOMPARE(myPlayListSave.savePlaylist(QUrl::fromLocalFile(playlistFile.fileName())), true); QCOMPARE(currentTrackChangedSaveSpy.count(), 1); QCOMPARE(randomPlayChangedSaveSpy.count(), 0); QCOMPARE(repeatPlayChangedSaveSpy.count(), 0); QCOMPARE(playListFinishedSaveSpy.count(), 0); QCOMPARE(playListLoadedSaveSpy.count(), 0); QCOMPARE(playListLoadFailedSaveSpy.count(), 0); QCOMPARE(currentTrackChangedRestoreSpy.count(), 0); QCOMPARE(randomPlayChangedRestoreSpy.count(), 0); QCOMPARE(repeatPlayChangedRestoreSpy.count(), 0); QCOMPARE(playListFinishedRestoreSpy.count(), 0); QCOMPARE(playListLoadedRestoreSpy.count(), 0); QCOMPARE(playListLoadFailedRestoreSpy.count(), 0); myPlayListRestore.loadPlaylist(QUrl::fromLocalFile(playlistFile.fileName())); QCOMPARE(currentTrackChangedSaveSpy.count(), 1); QCOMPARE(randomPlayChangedSaveSpy.count(), 0); QCOMPARE(repeatPlayChangedSaveSpy.count(), 0); QCOMPARE(playListFinishedSaveSpy.count(), 0); QCOMPARE(playListLoadedSaveSpy.count(), 0); QCOMPARE(playListLoadFailedSaveSpy.count(), 0); QCOMPARE(currentTrackChangedRestoreSpy.count(), 0); QCOMPARE(randomPlayChangedRestoreSpy.count(), 0); QCOMPARE(repeatPlayChangedRestoreSpy.count(), 0); QCOMPARE(playListFinishedRestoreSpy.count(), 0); QCOMPARE(playListLoadedRestoreSpy.count(), 1); QCOMPARE(playListLoadFailedRestoreSpy.count(), 0); QCOMPARE(currentTrackChangedRestoreSpy.wait(300), true); QCOMPARE(currentTrackChangedSaveSpy.count(), 1); QCOMPARE(randomPlayChangedSaveSpy.count(), 0); QCOMPARE(repeatPlayChangedSaveSpy.count(), 0); QCOMPARE(playListFinishedSaveSpy.count(), 0); QCOMPARE(playListLoadedSaveSpy.count(), 0); QCOMPARE(playListLoadFailedSaveSpy.count(), 0); QCOMPARE(currentTrackChangedRestoreSpy.count(), 1); QCOMPARE(randomPlayChangedRestoreSpy.count(), 0); QCOMPARE(repeatPlayChangedRestoreSpy.count(), 0); QCOMPARE(playListFinishedRestoreSpy.count(), 0); QCOMPARE(playListLoadedRestoreSpy.count(), 1); QCOMPARE(playListLoadFailedRestoreSpy.count(), 0); QCOMPARE(myPlayListRestore.currentTrack(), QPersistentModelIndex(myPlayListRestore.index(0, 0))); } void MediaPlayListTest::testEnqueueFiles() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myPlayList.enqueue({QStringLiteral("/$1"), QStringLiteral("/$2")}); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 2); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.rowCount(), 2); QCOMPARE(dataChangedSpy.wait(300), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 4); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 2); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("track2")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("artist2")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::TrackNumberRole).toInt(), 2); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::DiscNumberRole).toInt(), 2); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 2); } void MediaPlayListTest::testEnqueueSampleFiles() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myPlayList.enqueue({QStringLiteral(MEDIAPLAYLIST_TESTS_SAMPLE_FILES_PATH) + QStringLiteral("/test.ogg"), QStringLiteral(MEDIAPLAYLIST_TESTS_SAMPLE_FILES_PATH) + QStringLiteral("/test2.ogg")}); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 2); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 2); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.rowCount(), 2); QCOMPARE(dataChangedSpy.wait(300), true); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 2); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 2); QCOMPARE(trackHasBeenAddedSpy.count(), 2); QCOMPARE(persistentStateChangedSpy.count(), 2); QCOMPARE(dataChangedSpy.count(), 4); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 2); QCOMPARE(newArtistInListSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("Title")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("Test")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("Artist")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 1000); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::TitleRole).toString(), QStringLiteral("Title2")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::AlbumRole).toString(), QStringLiteral("Test2")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ArtistRole).toString(), QStringLiteral("Artist2")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::MilliSecondsDurationRole).toInt(), 1000); } void MediaPlayListTest::testEmptyEnqueue() { MediaPlayList myPlayList; QAbstractItemModelTester testModel(&myPlayList); DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy rowsAboutToBeMovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeMoved); QSignalSpy rowsAboutToBeRemovedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeRemoved); QSignalSpy rowsAboutToBeInsertedSpy(&myPlayList, &MediaPlayList::rowsAboutToBeInserted); QSignalSpy rowsMovedSpy(&myPlayList, &MediaPlayList::rowsMoved); QSignalSpy rowsRemovedSpy(&myPlayList, &MediaPlayList::rowsRemoved); QSignalSpy rowsInsertedSpy(&myPlayList, &MediaPlayList::rowsInserted); QSignalSpy trackHasBeenAddedSpy(&myPlayList, &MediaPlayList::trackHasBeenAdded); QSignalSpy persistentStateChangedSpy(&myPlayList, &MediaPlayList::persistentStateChanged); QSignalSpy dataChangedSpy(&myPlayList, &MediaPlayList::dataChanged); QSignalSpy newTrackByIdInListSpy(&myPlayList, &MediaPlayList::newTrackByIdInList); QSignalSpy newTrackByNameInListSpy(&myPlayList, &MediaPlayList::newTrackByNameInList); QSignalSpy newTrackByFileNameInListSpy(&myPlayList, &MediaPlayList::newTrackByFileNameInList); QSignalSpy newArtistInListSpy(&myPlayList, &MediaPlayList::newArtistInList); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged, Qt::QueuedConnection); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newTrackByFileNameInList, &myListener, &TracksListener::trackByFileNameInList, Qt::QueuedConnection); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList, Qt::QueuedConnection); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myPlayList.enqueue(QList{}); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myPlayList.enqueue(QStringList{}); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myPlayList.enqueue(QList{}, ElisaUtils::AppendPlayList, ElisaUtils::DoNotTriggerPlay); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myPlayList.enqueue(QList{}, ElisaUtils::AppendPlayList, ElisaUtils::DoNotTriggerPlay); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); myPlayList.enqueueArtists({}, ElisaUtils::AppendPlayList, ElisaUtils::DoNotTriggerPlay); QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0); QCOMPARE(rowsAboutToBeMovedSpy.count(), 0); QCOMPARE(rowsAboutToBeInsertedSpy.count(), 0); QCOMPARE(rowsRemovedSpy.count(), 0); QCOMPARE(rowsMovedSpy.count(), 0); QCOMPARE(rowsInsertedSpy.count(), 0); QCOMPARE(trackHasBeenAddedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(newTrackByIdInListSpy.count(), 0); QCOMPARE(newTrackByNameInListSpy.count(), 0); QCOMPARE(newTrackByFileNameInListSpy.count(), 0); QCOMPARE(newArtistInListSpy.count(), 0); } QTEST_GUILESS_MAIN(MediaPlayListTest) #include "moc_mediaplaylisttest.cpp" diff --git a/autotests/mediaplaylisttest.h b/autotests/mediaplaylisttest.h index 6eb6b70b..d1c7fce6 100644 --- a/autotests/mediaplaylisttest.h +++ b/autotests/mediaplaylisttest.h @@ -1,309 +1,307 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef MEDIAPLAYLISTTEST_H #define MEDIAPLAYLISTTEST_H #include "musicaudiotrack.h" #include #include #include #include #include class MediaPlayListTest : public QObject { Q_OBJECT public: explicit MediaPlayListTest(QObject *parent = nullptr); Q_SIGNALS: private Q_SLOTS: void initTestCase(); void simpleInitialCase(); void enqueueAlbumCase(); void enqueueArtistCase(); void removeFirstTrackOfAlbum(); void testHasHeader(); void testHasHeaderWithRestore(); void testHasHeaderWithRemove(); void testHasHeaderMoveFirst(); void testHasHeaderMoveAnother(); void testHasHeaderMoveFirstLikeQml(); void testHasHeaderMoveAnotherLikeQml(); void testHasHeaderYetAnotherMoveLikeQml(); void enqueueReplaceAndPlay(); void crashOnEnqueue(); void restoreMultipleIdenticalTracks(); void testHasHeaderAlbumWithSameTitle(); void testSavePersistentState(); void testReplaceAndPlayArtist(); void testReplaceAndPlayTrackId(); void testReplaceAndPlayTrackData(); void testSetData(); void testRemoveSelection(); void testTrackBeenRemoved(); void testBringUpCase(); void testBringUpCaseFromNewAlbum(); void testBringUpAndDownCase(); void testBringUpAndRemoveCase(); void testBringUpAndRemoveMultipleCase(); void testBringUpAndRemoveMultipleNotBeginCase(); void testBringUpAndPlayCase(); void testBringUpAndSkipNextCase(); void testBringUpAndSkipPreviousCase(); void testBringUpAndSkipPreviousAndContinueCase(); void finishPlayList(); void randomPlayList(); void randomAndContinuePlayList(); void continuePlayList(); void testRestoreSettings(); void removeBeforeCurrentTrack(); void switchToTrackTest(); void singleTrack(); void testBringUpAndRemoveLastCase(); void testSaveAndRestoreSettings(); void testSaveLoadPlayList(); void testEnqueueFiles(); void testEnqueueSampleFiles(); void testEmptyEnqueue(); void clearPlayListCase(); private: QList mNewTracks = { {true, QStringLiteral("$1"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 1, 1, QTime::fromMSecsSinceStartOfDay(1), {QUrl::fromLocalFile(QStringLiteral("/$1"))}, QDateTime::fromMSecsSinceEpoch(1), QUrl::fromLocalFile(QStringLiteral("album1")), 1, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$2"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 2, 2, QTime::fromMSecsSinceStartOfDay(2), {QUrl::fromLocalFile(QStringLiteral("/$2"))}, QDateTime::fromMSecsSinceEpoch(2), QUrl::fromLocalFile(QStringLiteral("album1")), 2, false, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$3"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 3, 3, QTime::fromMSecsSinceStartOfDay(3), {QUrl::fromLocalFile(QStringLiteral("/$3"))}, QDateTime::fromMSecsSinceEpoch(3), QUrl::fromLocalFile(QStringLiteral("album1")), 3, false, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4Bis"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$5"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 1, 1, QTime::fromMSecsSinceStartOfDay(5), {QUrl::fromLocalFile(QStringLiteral("/$5"))}, QDateTime::fromMSecsSinceEpoch(5), QUrl::fromLocalFile(QStringLiteral("album2")), 4, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$6"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 2, 1, QTime::fromMSecsSinceStartOfDay(6), {QUrl::fromLocalFile(QStringLiteral("/$6"))}, QDateTime::fromMSecsSinceEpoch(6), QUrl::fromLocalFile(QStringLiteral("album2")), 1, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$7"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 3, 1, QTime::fromMSecsSinceStartOfDay(7), {QUrl::fromLocalFile(QStringLiteral("/$7"))}, QDateTime::fromMSecsSinceEpoch(7), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$8"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 4, 1, QTime::fromMSecsSinceStartOfDay(8), {QUrl::fromLocalFile(QStringLiteral("/$8"))}, QDateTime::fromMSecsSinceEpoch(8), QUrl::fromLocalFile(QStringLiteral("album2")), 2, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$9"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 5, 1, QTime::fromMSecsSinceStartOfDay(9), {QUrl::fromLocalFile(QStringLiteral("/$9"))}, QDateTime::fromMSecsSinceEpoch(9), QUrl::fromLocalFile(QStringLiteral("album2")), 3, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$10"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist1 and artist2"), QStringLiteral("album2"), QStringLiteral("artist1"), 6, 1, QTime::fromMSecsSinceStartOfDay(10), {QUrl::fromLocalFile(QStringLiteral("/$10"))}, QDateTime::fromMSecsSinceEpoch(10), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$11"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(11), {QUrl::fromLocalFile(QStringLiteral("/$11"))}, QDateTime::fromMSecsSinceEpoch(11), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$12"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(12), {QUrl::fromLocalFile(QStringLiteral("/$12"))}, QDateTime::fromMSecsSinceEpoch(12), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$13"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(13), {QUrl::fromLocalFile(QStringLiteral("/$13"))}, QDateTime::fromMSecsSinceEpoch(13), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$14"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(14), {QUrl::fromLocalFile(QStringLiteral("/$14"))}, QDateTime::fromMSecsSinceEpoch(14), QUrl::fromLocalFile(QStringLiteral("album4")), 4, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$15"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(15), {QUrl::fromLocalFile(QStringLiteral("/$15"))}, QDateTime::fromMSecsSinceEpoch(15), QUrl::fromLocalFile(QStringLiteral("album4")), 5, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$16"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(16), {QUrl::fromLocalFile(QStringLiteral("/$16"))}, QDateTime::fromMSecsSinceEpoch(16), QUrl::fromLocalFile(QStringLiteral("album4")), 1, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$17"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 4, 1, QTime::fromMSecsSinceStartOfDay(17), {QUrl::fromLocalFile(QStringLiteral("/$17"))}, QDateTime::fromMSecsSinceEpoch(17), QUrl::fromLocalFile(QStringLiteral("album4")), 2, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$18"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 5, 1, QTime::fromMSecsSinceStartOfDay(18), {QUrl::fromLocalFile(QStringLiteral("/$18"))}, QDateTime::fromMSecsSinceEpoch(18), QUrl::fromLocalFile(QStringLiteral("album4")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$19"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 1, 1, QTime::fromMSecsSinceStartOfDay(19), {QUrl::fromLocalFile(QStringLiteral("/$19"))}, QDateTime::fromMSecsSinceEpoch(19), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 2, 1, QTime::fromMSecsSinceStartOfDay(20), {QUrl::fromLocalFile(QStringLiteral("/$20"))}, QDateTime::fromMSecsSinceEpoch(20), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$21"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 3, 1, QTime::fromMSecsSinceStartOfDay(21), {QUrl::fromLocalFile(QStringLiteral("/$21"))}, QDateTime::fromMSecsSinceEpoch(21), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$22"), QStringLiteral("0"), QStringLiteral("track9"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist7"), 9, 1, QTime::fromMSecsSinceStartOfDay(22), {QUrl::fromLocalFile(QStringLiteral("/$22"))}, QDateTime::fromMSecsSinceEpoch(22), QUrl::fromLocalFile(QStringLiteral("album3")), 9, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, }; QHash mNewCovers = { {QStringLiteral("file:///$1"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$2"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$3"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4Bis"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$5"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$6"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$7"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$8"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$9"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$0"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$11"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$12"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$13"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$14"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$15"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$16"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$17"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$18"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$19"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$20"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$21"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$22"), QUrl::fromLocalFile(QStringLiteral("album3"))}, }; }; class MediaPlayList; class CrashEnqueuePlayList : public QObject { Q_OBJECT public: explicit CrashEnqueuePlayList(MediaPlayList *list, QObject *parent = nullptr); public Q_SLOTS: void crashMediaPlayList(); private: MediaPlayList *mList = nullptr; }; #endif // MEDIAPLAYLISTTEST_H diff --git a/autotests/qmltests/tst_GridBrowserDelegate.qml b/autotests/qmltests/tst_GridBrowserDelegate.qml index f1cff172..c44bc252 100644 --- a/autotests/qmltests/tst_GridBrowserDelegate.qml +++ b/autotests/qmltests/tst_GridBrowserDelegate.qml @@ -1,338 +1,336 @@ /* * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ import QtQuick 2.3 import QtTest 1.0 import "../../src/qml" FocusScope { GridBrowserDelegate { id: delegateItem height: 160 width: 100 shadowForImage: true mainText: "hello" secondaryText: "hello secondary" function i18nc() { } Item { id: myPalette property color text property color shadow } Item { id: elisaTheme } } Item { id: otherItem focus: true width: 50 height: 50 anchors.top: delegateItem.bottom } TestCase { name: "TestGridBrowserDelegate" SignalSpy { id: enqueueSpy target: delegateItem signalName: "enqueue" } SignalSpy { id: replaceAndPlaySpy target: delegateItem signalName: "replaceAndPlay" } SignalSpy { id: openSpy target: delegateItem signalName: "open" } SignalSpy { id: selectedSpy target: delegateItem signalName: "selected" } when: windowShown function init() { otherItem.focus = true enqueueSpy.clear(); replaceAndPlaySpy.clear(); openSpy.clear(); selectedSpy.clear(); } function test_focus() { compare(enqueueSpy.count, 0); compare(replaceAndPlaySpy.count, 0); compare(openSpy.count, 0); compare(selectedSpy.count, 0); compare(delegateItem.focus, false, "delegateItem.focus"); delegateItem.forceActiveFocus(); compare(enqueueSpy.count, 0); compare(replaceAndPlaySpy.count, 0); compare(openSpy.count, 0); compare(selectedSpy.count, 0); compare(delegateItem.focus, true, "delegateItem.focus"); var enqueueButtonItem = findChild(delegateItem, "enqueueButton"); var openButtonItem = findChild(delegateItem, "openButton"); var replaceAndPlayButtonItem = findChild(delegateItem, "replaceAndPlayButton"); verify(enqueueButtonItem !== null, "valid enqueueButton") verify(openButtonItem !== null, "valid openButton") verify(replaceAndPlayButtonItem !== null, "valid replaceAndPlayButton") compare(enqueueButtonItem.focus, false, "enqueueButton.focus"); compare(openButtonItem.focus, false, "enqueueButton.focus"); compare(replaceAndPlayButtonItem.focus, false, "enqueueButton.focus"); keyClick(Qt.Key_Tab) compare(enqueueSpy.count, 0) compare(replaceAndPlaySpy.count, 0) compare(openSpy.count, 0) compare(selectedSpy.count, 0) compare(delegateItem.focus, true, "delegateItem.focus"); compare(enqueueButtonItem.focus, true, "enqueueButton.focus"); compare(openButtonItem.focus, false, "enqueueButton.focus"); compare(replaceAndPlayButtonItem.focus, false, "enqueueButton.focus"); keyClick(Qt.Key_Tab) compare(enqueueSpy.count, 0) compare(replaceAndPlaySpy.count, 0) compare(openSpy.count, 0) compare(selectedSpy.count, 0) compare(delegateItem.focus, true, "delegateItem.focus"); compare(enqueueButtonItem.focus, false, "enqueueButton.focus"); compare(openButtonItem.focus, true, "enqueueButton.focus"); compare(replaceAndPlayButtonItem.focus, false, "enqueueButton.focus"); keyClick(Qt.Key_Tab) compare(enqueueSpy.count, 0) compare(replaceAndPlaySpy.count, 0) compare(openSpy.count, 0) compare(selectedSpy.count, 0) compare(delegateItem.focus, true, "delegateItem.focus"); compare(enqueueButtonItem.focus, false, "enqueueButton.focus"); compare(openButtonItem.focus, false, "enqueueButton.focus"); compare(replaceAndPlayButtonItem.focus, true, "enqueueButton.focus"); enqueueButtonItem.focus = false; openButtonItem.focus = false; replaceAndPlayButtonItem.focus = false; otherItem.focus = true; compare(enqueueSpy.count, 0) compare(replaceAndPlaySpy.count, 0) compare(openSpy.count, 0) compare(selectedSpy.count, 0) compare(delegateItem.focus, false, "delegateItem.focus"); } function test_mouse_clicks() { compare(delegateItem.focus, false, "delegateItem.focus"); compare(enqueueSpy.count, 0); compare(replaceAndPlaySpy.count, 0); compare(openSpy.count, 0); compare(selectedSpy.count, 0); mouseMove(delegateItem, 0, 0); compare(delegateItem.focus, false, "delegateItem.focus"); compare(enqueueSpy.count, 0); compare(replaceAndPlaySpy.count, 0); compare(openSpy.count, 0); compare(selectedSpy.count, 0); var enqueueButtonItem = findChild(delegateItem, "enqueueButton"); var openButtonItem = findChild(delegateItem, "openButton"); var replaceAndPlayButtonItem = findChild(delegateItem, "replaceAndPlayButton"); verify(enqueueButtonItem !== null, "valid enqueueButton") verify(openButtonItem !== null, "valid openButton") verify(replaceAndPlayButtonItem !== null, "valid replaceAndPlayButton") compare(enqueueButtonItem.focus, false, "enqueueButton.focus"); compare(openButtonItem.focus, false, "enqueueButton.focus"); compare(replaceAndPlayButtonItem.focus, false, "enqueueButton.focus"); mouseClick(delegateItem, 0, 0); compare(delegateItem.focus, false, "delegateItem.focus"); compare(enqueueButtonItem.focus, false, "enqueueButton.focus"); compare(openButtonItem.focus, false, "enqueueButton.focus"); compare(replaceAndPlayButtonItem.focus, false, "enqueueButton.focus"); compare(enqueueSpy.count, 0); compare(replaceAndPlaySpy.count, 0); compare(openSpy.count, 0); compare(selectedSpy.count, 1); mouseDoubleClickSequence(delegateItem, 0, 0); openSpy.wait(150); compare(delegateItem.focus, false, "delegateItem.focus"); compare(enqueueButtonItem.focus, false, "enqueueButton.focus"); compare(openButtonItem.focus, false, "enqueueButton.focus"); compare(replaceAndPlayButtonItem.focus, false, "enqueueButton.focus"); compare(enqueueSpy.count, 0); compare(replaceAndPlaySpy.count, 0); compare(openSpy.count, 1); compare(selectedSpy.count, 2); mouseMove(enqueueButtonItem); mouseClick(enqueueButtonItem); compare(delegateItem.focus, false, "delegateItem.focus"); compare(enqueueButtonItem.focus, false, "enqueueButton.focus"); compare(openButtonItem.focus, false, "enqueueButton.focus"); compare(replaceAndPlayButtonItem.focus, false, "enqueueButton.focus"); compare(enqueueSpy.count, 1); compare(replaceAndPlaySpy.count, 0); compare(openSpy.count, 1); compare(selectedSpy.count, 2); mouseMove(openButtonItem); mouseClick(openButtonItem); compare(delegateItem.focus, false, "delegateItem.focus"); compare(enqueueButtonItem.focus, false, "enqueueButton.focus"); compare(openButtonItem.focus, false, "enqueueButton.focus"); compare(replaceAndPlayButtonItem.focus, false, "enqueueButton.focus"); compare(enqueueSpy.count, 1); compare(replaceAndPlaySpy.count, 0); compare(openSpy.count, 2); compare(selectedSpy.count, 2); mouseMove(replaceAndPlayButtonItem); mouseClick(replaceAndPlayButtonItem); compare(delegateItem.focus, false, "delegateItem.focus"); compare(enqueueButtonItem.focus, false, "enqueueButton.focus"); compare(openButtonItem.focus, false, "enqueueButton.focus"); compare(replaceAndPlayButtonItem.focus, false, "enqueueButton.focus"); compare(enqueueSpy.count, 1); compare(replaceAndPlaySpy.count, 1); compare(openSpy.count, 2); compare(selectedSpy.count, 2); mouseMove(otherItem, 0, 0); compare(delegateItem.focus, false, "delegateItem.focus"); compare(enqueueButtonItem.focus, false, "enqueueButton.focus"); compare(openButtonItem.focus, false, "enqueueButton.focus"); compare(replaceAndPlayButtonItem.focus, false, "enqueueButton.focus"); compare(enqueueSpy.count, 1); compare(replaceAndPlaySpy.count, 1); compare(openSpy.count, 2); compare(selectedSpy.count, 2); enqueueButtonItem.focus = false; openButtonItem.focus = false; replaceAndPlayButtonItem.focus = false; otherItem.focus = true; } function test_keyboard() { compare(enqueueSpy.count, 0); compare(replaceAndPlaySpy.count, 0); compare(openSpy.count, 0); compare(selectedSpy.count, 0); compare(delegateItem.focus, false, "delegateItem.focus"); delegateItem.forceActiveFocus(); compare(enqueueSpy.count, 0); compare(replaceAndPlaySpy.count, 0); compare(openSpy.count, 0); compare(selectedSpy.count, 0); compare(delegateItem.focus, true, "delegateItem.focus"); var enqueueButtonItem = findChild(delegateItem, "enqueueButton"); var openButtonItem = findChild(delegateItem, "openButton"); var replaceAndPlayButtonItem = findChild(delegateItem, "replaceAndPlayButton"); verify(enqueueButtonItem !== null, "valid enqueueButton") verify(openButtonItem !== null, "valid openButton") verify(replaceAndPlayButtonItem !== null, "valid replaceAndPlayButton") compare(enqueueButtonItem.focus, false, "enqueueButton.focus"); compare(openButtonItem.focus, false, "enqueueButton.focus"); compare(replaceAndPlayButtonItem.focus, false, "enqueueButton.focus"); keyClick(Qt.Key_Tab); compare(enqueueSpy.count, 0); compare(replaceAndPlaySpy.count, 0); compare(openSpy.count, 0); compare(selectedSpy.count, 0); compare(delegateItem.focus, true, "delegateItem.focus"); compare(enqueueButtonItem.focus, true, "enqueueButton.focus"); compare(openButtonItem.focus, false, "enqueueButton.focus"); compare(replaceAndPlayButtonItem.focus, false, "enqueueButton.focus"); keyClick(Qt.Key_Tab); compare(enqueueSpy.count, 0); compare(replaceAndPlaySpy.count, 0); compare(openSpy.count, 0); compare(selectedSpy.count, 0); compare(delegateItem.focus, true, "delegateItem.focus"); compare(enqueueButtonItem.focus, false, "enqueueButton.focus"); compare(openButtonItem.focus, true, "enqueueButton.focus"); compare(replaceAndPlayButtonItem.focus, false, "enqueueButton.focus"); keyClick(Qt.Key_Tab); compare(enqueueSpy.count, 0); compare(replaceAndPlaySpy.count, 0); compare(openSpy.count, 0); compare(selectedSpy.count, 0); compare(delegateItem.focus, true, "delegateItem.focus"); compare(enqueueButtonItem.focus, false, "enqueueButton.focus"); compare(openButtonItem.focus, false, "enqueueButton.focus"); compare(replaceAndPlayButtonItem.focus, true, "enqueueButton.focus"); keyClick(Qt.Key_Enter); compare(enqueueSpy.count, 0); compare(replaceAndPlaySpy.count, 0); compare(openSpy.count, 1); compare(selectedSpy.count, 0); compare(delegateItem.focus, true, "delegateItem.focus"); compare(enqueueButtonItem.focus, false, "enqueueButton.focus"); compare(openButtonItem.focus, false, "enqueueButton.focus"); compare(replaceAndPlayButtonItem.focus, true, "enqueueButton.focus"); keyClick(Qt.Key_Return); compare(enqueueSpy.count, 0); compare(replaceAndPlaySpy.count, 0); compare(openSpy.count, 2); compare(selectedSpy.count, 0); compare(delegateItem.focus, true, "delegateItem.focus"); compare(enqueueButtonItem.focus, false, "enqueueButton.focus"); compare(openButtonItem.focus, false, "enqueueButton.focus"); compare(replaceAndPlayButtonItem.focus, true, "enqueueButton.focus"); enqueueButtonItem.focus = false; openButtonItem.focus = false; replaceAndPlayButtonItem.focus = false; otherItem.focus = true; } } } diff --git a/autotests/qmltests/tst_NavigationActionBar.qml b/autotests/qmltests/tst_NavigationActionBar.qml index ff1bb535..8e88f19d 100644 --- a/autotests/qmltests/tst_NavigationActionBar.qml +++ b/autotests/qmltests/tst_NavigationActionBar.qml @@ -1,324 +1,322 @@ /* * Copyright 2018 Alexander Stippich . */ import QtQuick 2.3 import QtTest 1.0 import "../../src/qml" FocusScope { property bool expandedFilterView: false function i18nc(string1,string2) { return string2 } Item { id: elisaTheme property int layoutHorizontalMargin: 8 property int layoutVerticalMargin: 6 property int defaultFontPointSize: 12 property int filterClearButtonMargin: layoutVerticalMargin property int ratingStarSize: 15 } SystemPalette { id: myPalette colorGroup: SystemPalette.Active } Binding { target: navigationActionBar1 property: "expandedFilterView" value: expandedFilterView } NavigationActionBar { id: navigationActionBar1 mainTitle: 'testTitle1' secondaryTitle: 'secondaryTitle1' enableGoBack: true allowArtistNavigation: true showRating: true height: 100 } NavigationActionBar { id: navigationActionBar2 mainTitle: 'testTitle2' secondaryTitle: 'secondaryTitle2' enableGoBack: false allowArtistNavigation: false showRating: false expandedFilterView: true height: 100 y: 200 } TestCase { name: "TestNavigationActionBar" SignalSpy { id: enqueueSpy1 target: navigationActionBar1 signalName: "enqueue" } SignalSpy { id: enqueueSpy2 target: navigationActionBar2 signalName: "enqueue" } SignalSpy { id: replaceAndPlaySpy1 target: navigationActionBar1 signalName: "replaceAndPlay" } SignalSpy { id: replaceAndPlaySpy2 target: navigationActionBar2 signalName: "replaceAndPlay" } SignalSpy { id: goBackSpy1 target: navigationActionBar1 signalName: "goBack" } SignalSpy { id: goBackSpy2 target: navigationActionBar2 signalName: "goBack" } SignalSpy { id: filterViewChangedSpy1 target: navigationActionBar1 signalName: "filterViewChanged" } SignalSpy { id: filterViewChangedSpy2 target: navigationActionBar2 signalName: "filterViewChanged" } SignalSpy { id: showArtistSpy1 target: navigationActionBar1 signalName: "showArtist" } SignalSpy { id: showArtistSpy2 target: navigationActionBar2 signalName: "showArtist" } when: windowShown function init() { enqueueSpy1.clear(); enqueueSpy2.clear(); replaceAndPlaySpy1.clear(); replaceAndPlaySpy2.clear(); goBackSpy1.clear(); goBackSpy2.clear(); filterViewChangedSpy1.clear(); filterViewChangedSpy2.clear(); showArtistSpy1.clear(); showArtistSpy2.clear(); expandedFilterView = false; } function test_goBack() { compare(enqueueSpy1.count, 0); compare(enqueueSpy2.count, 0); compare(replaceAndPlaySpy1.count, 0); compare(replaceAndPlaySpy2.count, 0); compare(goBackSpy1.count, 0); compare(goBackSpy2.count, 0); compare(filterViewChangedSpy1.count, 0); compare(filterViewChangedSpy2.count, 0); compare(showArtistSpy1.count, 0); compare(showArtistSpy2.count, 0); var goPreviousButtonItem1 = findChild(navigationActionBar1, "goPreviousButton"); verify(goPreviousButtonItem1 !== null, "valid goPreviousButton") mouseClick(goPreviousButtonItem1); compare(goBackSpy1.count, 1); var goPreviousButtonItem2 = findChild(navigationActionBar2, "goPreviousButton"); verify(goPreviousButtonItem2 !== null, "valid goPreviousButton") mouseClick(goPreviousButtonItem2); compare(goBackSpy2.count, 0); } function test_enqueue() { compare(enqueueSpy1.count, 0); compare(enqueueSpy2.count, 0); compare(replaceAndPlaySpy1.count, 0); compare(replaceAndPlaySpy2.count, 0); compare(goBackSpy1.count, 0); compare(goBackSpy2.count, 0); compare(filterViewChangedSpy1.count, 0); compare(filterViewChangedSpy2.count, 0); compare(showArtistSpy1.count, 0); compare(showArtistSpy2.count, 0); var enqueueButtonItem = findChild(navigationActionBar1, "enqueueButton"); verify(enqueueButtonItem !== null, "valid enqueueButton") mouseClick(enqueueButtonItem); compare(enqueueSpy1.count, 1); } function test_filterState() { compare(enqueueSpy1.count, 0); compare(enqueueSpy2.count, 0); compare(replaceAndPlaySpy1.count, 0); compare(replaceAndPlaySpy2.count, 0); compare(goBackSpy1.count, 0); compare(goBackSpy2.count, 0); compare(filterViewChangedSpy1.count, 0); compare(filterViewChangedSpy2.count, 0); compare(showArtistSpy1.count, 0); compare(showArtistSpy2.count, 0); var showFilterButtonItem1 = findChild(navigationActionBar1, "showFilterButton"); verify(showFilterButtonItem1 !== null, "valid showFilterButton") mouseClick(showFilterButtonItem1); compare(filterViewChangedSpy1.count, 1); var signalArgument1 = filterViewChangedSpy1.signalArguments[0]; expandedFilterView = signalArgument1[0]; compare(expandedFilterView,true); compare(navigationActionBar1.state,'expanded') var showFilterButtonItem2 = findChild(navigationActionBar2, "showFilterButton"); verify(showFilterButtonItem2 !== null, "valid showFilterButton") mouseClick(showFilterButtonItem2); compare(filterViewChangedSpy2.count, 1); var signalArgument2 = filterViewChangedSpy2.signalArguments[0]; compare(signalArgument2[0],false) expandedFilterView = signalArgument2[0]; compare(expandedFilterView,false) compare(navigationActionBar1.expandedFilterView, false) compare(navigationActionBar1.state,'collapsed') } function test_replaceAndPlay() { compare(enqueueSpy1.count, 0); compare(enqueueSpy2.count, 0); compare(replaceAndPlaySpy1.count, 0); compare(replaceAndPlaySpy2.count, 0); compare(goBackSpy1.count, 0); compare(goBackSpy2.count, 0); compare(filterViewChangedSpy1.count, 0); compare(filterViewChangedSpy2.count, 0); compare(showArtistSpy1.count, 0); compare(showArtistSpy2.count, 0); var replaceAndPlayButtonItem = findChild(navigationActionBar1, "replaceAndPlayButton"); verify(replaceAndPlayButtonItem !== null, "valid replaceAndPlayButton") mouseClick(replaceAndPlayButtonItem); compare(replaceAndPlaySpy1.count, 1); } function test_showArtist() { compare(enqueueSpy1.count, 0); compare(enqueueSpy2.count, 0); compare(replaceAndPlaySpy1.count, 0); compare(replaceAndPlaySpy2.count, 0); compare(goBackSpy1.count, 0); compare(goBackSpy2.count, 0); compare(filterViewChangedSpy1.count, 0); compare(filterViewChangedSpy2.count, 0); compare(showArtistSpy1.count, 0); compare(showArtistSpy2.count, 0); var showArtistButtonItem1 = findChild(navigationActionBar1, "showArtistButton"); verify(showArtistButtonItem1 !== null, "valid showArtistButton") mouseClick(showArtistButtonItem1); compare(showArtistSpy1.count, 1); var showArtistButtonItem2 = findChild(navigationActionBar2, "showArtistButton"); verify(showArtistButtonItem2 !== null, "valid showArtistButton") mouseClick(showArtistButtonItem2); compare(showArtistSpy2.count, 0); } function test_filterRating() { expandedFilterView = true; wait(200); var ratingFilterItem1 = findChild(navigationActionBar1, "ratingFilter"); verify(ratingFilterItem1 !== null, "valid ratingFilter") mouseClick(ratingFilterItem1,1); compare(navigationActionBar1.filterRating, 2); mouseClick(ratingFilterItem1,1); compare(navigationActionBar1.filterRating, 0); mouseClick(ratingFilterItem1,1 + elisaTheme.ratingStarSize); compare(navigationActionBar1.filterRating, 4); mouseClick(ratingFilterItem1,1 + elisaTheme.ratingStarSize); compare(navigationActionBar1.filterRating, 0); mouseClick(ratingFilterItem1,1 + 2 * elisaTheme.ratingStarSize); compare(navigationActionBar1.filterRating, 6); mouseClick(ratingFilterItem1,1 + 2 * elisaTheme.ratingStarSize); compare(navigationActionBar1.filterRating, 0); mouseClick(ratingFilterItem1,1 + 3 * elisaTheme.ratingStarSize); compare(navigationActionBar1.filterRating, 8); mouseClick(ratingFilterItem1,1 + 3 * elisaTheme.ratingStarSize); compare(navigationActionBar1.filterRating, 0); mouseClick(ratingFilterItem1,1 + 4 * elisaTheme.ratingStarSize); compare(navigationActionBar1.filterRating, 10); mouseClick(ratingFilterItem1,1 + 4 * elisaTheme.ratingStarSize); compare(navigationActionBar1.filterRating, 0); var ratingFilterItem2 = findChild(navigationActionBar2, "ratingFilter"); verify(ratingFilterItem2 !== null, "valid ratingFilter") mouseClick(ratingFilterItem2,1); compare(navigationActionBar2.filterRating, 0); mouseClick(ratingFilterItem2,1 + elisaTheme.ratingStarSize); compare(navigationActionBar2.filterRating, 0); mouseClick(ratingFilterItem2,1 + 2 * elisaTheme.ratingStarSize); compare(navigationActionBar2.filterRating, 0); mouseClick(ratingFilterItem2,1 + 3 * elisaTheme.ratingStarSize); compare(navigationActionBar2.filterRating, 0); mouseClick(ratingFilterItem2,1 + 4 * elisaTheme.ratingStarSize); compare(navigationActionBar2.filterRating, 0); } function test_filterText() { var textsFilterItem1 = findChild(navigationActionBar1, "filterTextInput"); verify(textsFilterItem1 !== null, "valid filterTextInput") compare(textsFilterItem1.focus, false); mouseClick(textsFilterItem1); compare(textsFilterItem1.focus, true); keyClick(Qt.Key_T); keyClick(Qt.Key_E); keyClick(Qt.Key_S); keyClick(Qt.Key_T); compare(navigationActionBar1.filterText, 'test'); mouseClick(textsFilterItem1,textsFilterItem1.width - textsFilterItem1.height); compare(navigationActionBar1.filterText, ""); } } } diff --git a/autotests/qmltests/tst_PlayListEntry.qml b/autotests/qmltests/tst_PlayListEntry.qml index caeff7bc..44fc640f 100644 --- a/autotests/qmltests/tst_PlayListEntry.qml +++ b/autotests/qmltests/tst_PlayListEntry.qml @@ -1,126 +1,124 @@ /* * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ import QtQuick 2.3 import QtTest 1.0 import "../../src/qml" import org.kde.elisa 1.0 Item { height: 50 width: 300 PlayListEntry { id: playListEntry height: 50 width: 300 isAlternateColor: false hasAlbumHeader: false isSingleDiscAlbum: false titleDisplay: "hello" isValid: true isPlaying: MediaPlayList.IsPaused isSelected: true containsMouse: false function i18nc() { return "" } SystemPalette { id: myPalette } Item { id: elisaTheme property int layoutHorizontalMargin: 8 property int smallDelegateToolButtonSize: 20 property int ratingStarSize: 15 } } TestCase { name: "TestPlayListEntry" SignalSpy { id: startPlaybackSpy target: playListEntry signalName: "startPlayback" } SignalSpy { id: pausePlaybackSpy target: playListEntry signalName: "pausePlayback" } SignalSpy { id: removeFromPlaylistSpy target: playListEntry signalName: "removeFromPlaylist" } SignalSpy { id: switchToTrackSpy target: playListEntry signalName: "switchToTrack" } when: windowShown function init() { startPlaybackSpy.clear(); pausePlaybackSpy.clear(); removeFromPlaylistSpy.clear(); switchToTrackSpy.clear(); } function test_playnow_click() { compare(startPlaybackSpy.count, 0); compare(pausePlaybackSpy.count, 0); compare(removeFromPlaylistSpy.count, 0); compare(switchToTrackSpy.count, 0); playListEntry.forceActiveFocus(); compare(startPlaybackSpy.count, 0); compare(pausePlaybackSpy.count, 0); compare(removeFromPlaylistSpy.count, 0); compare(switchToTrackSpy.count, 0); var playPauseButtonItem = findChild(playListEntry, "playPauseButton"); verify(playPauseButtonItem !== null, "valid playPauseButton") mouseMove(playPauseButtonItem, playPauseButtonItem.width / 2, playPauseButtonItem.height / 2); wait(300); mouseClick(playPauseButtonItem); compare(startPlaybackSpy.count, 1); compare(pausePlaybackSpy.count, 0); compare(removeFromPlaylistSpy.count, 0); compare(switchToTrackSpy.count, 0); } } } diff --git a/autotests/trackslistenertest.cpp b/autotests/trackslistenertest.cpp index 88fab516..7d3b1850 100644 --- a/autotests/trackslistenertest.cpp +++ b/autotests/trackslistenertest.cpp @@ -1,625 +1,623 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "trackslistener.h" #include "mediaplaylist.h" #include "databaseinterface.h" #include "config-upnp-qt.h" #include #include #include #include #include #include #include #include #include #include #include #include class TracksListenerTests: public QObject { Q_OBJECT public: TracksListenerTests(QObject *parent = nullptr) : QObject(parent) { } private: QList mNewTracks = { {true, QStringLiteral("$1"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 1, 1, QTime::fromMSecsSinceStartOfDay(1), {QUrl::fromLocalFile(QStringLiteral("/$1"))}, QDateTime::fromMSecsSinceEpoch(1), QUrl::fromLocalFile(QStringLiteral("album1")), 1, false, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$2"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 2, 2, QTime::fromMSecsSinceStartOfDay(2), {QUrl::fromLocalFile(QStringLiteral("/$2"))}, QDateTime::fromMSecsSinceEpoch(2), QUrl::fromLocalFile(QStringLiteral("album1")), 2, false, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$3"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist3"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 3, 3, QTime::fromMSecsSinceStartOfDay(3), {QUrl::fromLocalFile(QStringLiteral("/$3"))}, QDateTime::fromMSecsSinceEpoch(3), QUrl::fromLocalFile(QStringLiteral("album1")), 3, false, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$4"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist4"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 4, 4, QTime::fromMSecsSinceStartOfDay(4), {QUrl::fromLocalFile(QStringLiteral("/$4Bis"))}, QDateTime::fromMSecsSinceEpoch(4), QUrl::fromLocalFile(QStringLiteral("album1")), 4, false, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$5"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 1, 1, QTime::fromMSecsSinceStartOfDay(5), {QUrl::fromLocalFile(QStringLiteral("/$5"))}, QDateTime::fromMSecsSinceEpoch(5), QUrl::fromLocalFile(QStringLiteral("album2")), 4, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$6"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 2, 1, QTime::fromMSecsSinceStartOfDay(6), {QUrl::fromLocalFile(QStringLiteral("/$6"))}, QDateTime::fromMSecsSinceEpoch(6), QUrl::fromLocalFile(QStringLiteral("album2")), 1, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$7"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 3, 1, QTime::fromMSecsSinceStartOfDay(7), {QUrl::fromLocalFile(QStringLiteral("/$7"))}, QDateTime::fromMSecsSinceEpoch(7), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$8"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 4, 1, QTime::fromMSecsSinceStartOfDay(8), {QUrl::fromLocalFile(QStringLiteral("/$8"))}, QDateTime::fromMSecsSinceEpoch(8), QUrl::fromLocalFile(QStringLiteral("album2")), 2, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$9"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist1"), QStringLiteral("album2"), QStringLiteral("artist1"), 5, 1, QTime::fromMSecsSinceStartOfDay(9), {QUrl::fromLocalFile(QStringLiteral("/$9"))}, QDateTime::fromMSecsSinceEpoch(9), QUrl::fromLocalFile(QStringLiteral("album2")), 3, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$10"), QStringLiteral("0"), QStringLiteral("track6"), QStringLiteral("artist1 and artist2"), QStringLiteral("album2"), QStringLiteral("artist1"), 6, 1, QTime::fromMSecsSinceStartOfDay(10), {QUrl::fromLocalFile(QStringLiteral("/$10"))}, QDateTime::fromMSecsSinceEpoch(10), QUrl::fromLocalFile(QStringLiteral("album2")), 5, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$11"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(11), {QUrl::fromLocalFile(QStringLiteral("/$11"))}, QDateTime::fromMSecsSinceEpoch(11), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$12"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(12), {QUrl::fromLocalFile(QStringLiteral("/$12"))}, QDateTime::fromMSecsSinceEpoch(12), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$13"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(13), {QUrl::fromLocalFile(QStringLiteral("/$13"))}, QDateTime::fromMSecsSinceEpoch(13), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$14"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 1, 1, QTime::fromMSecsSinceStartOfDay(14), {QUrl::fromLocalFile(QStringLiteral("/$14"))}, QDateTime::fromMSecsSinceEpoch(14), QUrl::fromLocalFile(QStringLiteral("album4")), 4, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$15"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 2, 1, QTime::fromMSecsSinceStartOfDay(15), {QUrl::fromLocalFile(QStringLiteral("/$15"))}, QDateTime::fromMSecsSinceEpoch(15), QUrl::fromLocalFile(QStringLiteral("album4")), 5, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$16"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 3, 1, QTime::fromMSecsSinceStartOfDay(16), {QUrl::fromLocalFile(QStringLiteral("/$16"))}, QDateTime::fromMSecsSinceEpoch(16), QUrl::fromLocalFile(QStringLiteral("album4")), 1, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$17"), QStringLiteral("0"), QStringLiteral("track4"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 4, 1, QTime::fromMSecsSinceStartOfDay(17), {QUrl::fromLocalFile(QStringLiteral("/$17"))}, QDateTime::fromMSecsSinceEpoch(17), QUrl::fromLocalFile(QStringLiteral("album4")), 2, true, QStringLiteral("genre4"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$18"), QStringLiteral("0"), QStringLiteral("track5"), QStringLiteral("artist2"), QStringLiteral("album4"), QStringLiteral("artist2"), 5, 1, QTime::fromMSecsSinceStartOfDay(18), {QUrl::fromLocalFile(QStringLiteral("/$18"))}, QDateTime::fromMSecsSinceEpoch(18), QUrl::fromLocalFile(QStringLiteral("album4")), 3, true, QStringLiteral("genre3"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$19"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 1, 1, QTime::fromMSecsSinceStartOfDay(19), {QUrl::fromLocalFile(QStringLiteral("/$19"))}, QDateTime::fromMSecsSinceEpoch(19), QUrl::fromLocalFile(QStringLiteral("album3")), 1, true, QStringLiteral("genre2"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$20"), QStringLiteral("0"), QStringLiteral("track2"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 2, 1, QTime::fromMSecsSinceStartOfDay(20), {QUrl::fromLocalFile(QStringLiteral("/$20"))}, QDateTime::fromMSecsSinceEpoch(20), QUrl::fromLocalFile(QStringLiteral("album3")), 2, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$21"), QStringLiteral("0"), QStringLiteral("track3"), QStringLiteral("artist7"), QStringLiteral("album3"), QStringLiteral("artist7"), 3, 1, QTime::fromMSecsSinceStartOfDay(21), {QUrl::fromLocalFile(QStringLiteral("/$21"))}, QDateTime::fromMSecsSinceEpoch(21), QUrl::fromLocalFile(QStringLiteral("album3")), 3, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, {true, QStringLiteral("$22"), QStringLiteral("0"), QStringLiteral("track9"), QStringLiteral("artist2"), QStringLiteral("album3"), QStringLiteral("artist7"), 9, 1, QTime::fromMSecsSinceStartOfDay(22), {QUrl::fromLocalFile(QStringLiteral("/$22"))}, QDateTime::fromMSecsSinceEpoch(22), QUrl::fromLocalFile(QStringLiteral("album3")), 9, true, QStringLiteral("genre1"), QStringLiteral("composer1"), QStringLiteral("lyricist1")}, }; QHash mNewCovers = { {QStringLiteral("file:///$1"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$2"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$3"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$4Bis"), QUrl::fromLocalFile(QStringLiteral("album1"))}, {QStringLiteral("file:///$5"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$6"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$7"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$8"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$9"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$0"), QUrl::fromLocalFile(QStringLiteral("album2"))}, {QStringLiteral("file:///$11"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$12"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$13"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$14"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$15"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$16"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$17"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$18"), QUrl::fromLocalFile(QStringLiteral("album4"))}, {QStringLiteral("file:///$19"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$20"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$21"), QUrl::fromLocalFile(QStringLiteral("album3"))}, {QStringLiteral("file:///$22"), QUrl::fromLocalFile(QStringLiteral("album3"))}, }; private Q_SLOTS: void initTestCase() { qRegisterMetaType>("QHash"); qRegisterMetaType>("QHash"); qRegisterMetaType>("QList"); qRegisterMetaType>("QVector"); qRegisterMetaType>("QHash"); qRegisterMetaType>("QList"); } void testTrackRemoval() { MediaPlayList myPlayList; DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy trackHasChangedSpy(&myListener, &TracksListener::trackHasChanged); QSignalSpy trackHasBeenRemovedSpy(&myListener, &TracksListener::trackHasBeenRemoved); QSignalSpy albumAddedSpy(&myListener, &TracksListener::albumAdded); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myDatabaseContent, &DatabaseInterface::trackRemoved, &myListener, &TracksListener::trackRemoved); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); connect(&myDatabaseContent, &DatabaseInterface::trackModified, &myListener, &TracksListener::trackModified); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged); connect(&myListener, &TracksListener::trackHasBeenRemoved, &myPlayList, &MediaPlayList::trackRemoved); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList); QCOMPARE(trackHasChangedSpy.count(), 0); QCOMPARE(trackHasBeenRemovedSpy.count(), 0); QCOMPARE(albumAddedSpy.count(), 0); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(trackHasChangedSpy.count(), 0); QCOMPARE(trackHasBeenRemovedSpy.count(), 0); QCOMPARE(albumAddedSpy.count(), 0); myPlayList.replaceAndPlay(QStringLiteral("artist1")); QCOMPARE(trackHasChangedSpy.count(), 0); QCOMPARE(trackHasBeenRemovedSpy.count(), 0); QCOMPARE(albumAddedSpy.count(), 1); QCOMPARE(myPlayList.tracksCount(), 6); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track2")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 2); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track3")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track4")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 4); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track5")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 5); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); myDatabaseContent.removeTracksList({QUrl::fromLocalFile(QStringLiteral("/$1"))}); QCOMPARE(trackHasChangedSpy.count(), 0); QCOMPARE(trackHasBeenRemovedSpy.count(), 1); QCOMPARE(albumAddedSpy.count(), 1); QCOMPARE(myPlayList.tracksCount(), 6); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), -1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 0); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track2")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 2); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track3")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 3); QCOMPARE(myPlayList.data(myPlayList.index(3, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track4")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 4); QCOMPARE(myPlayList.data(myPlayList.index(4, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track5")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album2")); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 5); QCOMPARE(myPlayList.data(myPlayList.index(5, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); } void testInsertTrackIdAndRemoval() { MediaPlayList myPlayList; DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy trackHasChangedSpy(&myListener, &TracksListener::trackHasChanged); QSignalSpy trackHasBeenRemovedSpy(&myListener, &TracksListener::trackHasBeenRemoved); QSignalSpy albumAddedSpy(&myListener, &TracksListener::albumAdded); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myDatabaseContent, &DatabaseInterface::trackRemoved, &myListener, &TracksListener::trackRemoved); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); connect(&myDatabaseContent, &DatabaseInterface::trackModified, &myListener, &TracksListener::trackModified); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged); connect(&myListener, &TracksListener::trackHasBeenRemoved, &myPlayList, &MediaPlayList::trackRemoved); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList); QCOMPARE(trackHasChangedSpy.count(), 0); QCOMPARE(trackHasBeenRemovedSpy.count(), 0); QCOMPARE(albumAddedSpy.count(), 0); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(trackHasChangedSpy.count(), 0); QCOMPARE(trackHasBeenRemovedSpy.count(), 0); QCOMPARE(albumAddedSpy.count(), 0); auto trackId = myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1); QCOMPARE(trackId != 0, true); myPlayList.replaceAndPlay(trackId); QCOMPARE(trackHasChangedSpy.count(), 1); QCOMPARE(trackHasBeenRemovedSpy.count(), 0); QCOMPARE(albumAddedSpy.count(), 0); QCOMPARE(myPlayList.tracksCount(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); myDatabaseContent.removeTracksList({QUrl::fromLocalFile(QStringLiteral("/$1"))}); QCOMPARE(trackHasChangedSpy.count(), 1); QCOMPARE(trackHasBeenRemovedSpy.count(), 1); QCOMPARE(albumAddedSpy.count(), 0); QCOMPARE(myPlayList.tracksCount(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), -1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 0); } void testInsertTrackByNameAndRemoval() { MediaPlayList myPlayList; DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy trackHasChangedSpy(&myListener, &TracksListener::trackHasChanged); QSignalSpy trackHasBeenRemovedSpy(&myListener, &TracksListener::trackHasBeenRemoved); QSignalSpy albumAddedSpy(&myListener, &TracksListener::albumAdded); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myDatabaseContent, &DatabaseInterface::trackRemoved, &myListener, &TracksListener::trackRemoved); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); connect(&myDatabaseContent, &DatabaseInterface::trackModified, &myListener, &TracksListener::trackModified); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged); connect(&myListener, &TracksListener::trackHasBeenRemoved, &myPlayList, &MediaPlayList::trackRemoved); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList); QCOMPARE(trackHasChangedSpy.count(), 0); QCOMPARE(trackHasBeenRemovedSpy.count(), 0); QCOMPARE(albumAddedSpy.count(), 0); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(trackHasChangedSpy.count(), 0); QCOMPARE(trackHasBeenRemovedSpy.count(), 0); QCOMPARE(albumAddedSpy.count(), 0); myPlayList.enqueue(MediaPlayListEntry(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1)); QCOMPARE(trackHasChangedSpy.count(), 1); QCOMPARE(trackHasBeenRemovedSpy.count(), 0); QCOMPARE(albumAddedSpy.count(), 0); QCOMPARE(myPlayList.tracksCount(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); myDatabaseContent.removeTracksList({QUrl::fromLocalFile(QStringLiteral("/$1"))}); QCOMPARE(trackHasChangedSpy.count(), 1); QCOMPARE(trackHasBeenRemovedSpy.count(), 1); QCOMPARE(albumAddedSpy.count(), 0); QCOMPARE(myPlayList.tracksCount(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), -1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 0); } void testInsertTrackByNameBeforeDatabaseAndRemoval() { MediaPlayList myPlayList; DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy trackHasChangedSpy(&myListener, &TracksListener::trackHasChanged); QSignalSpy trackHasBeenRemovedSpy(&myListener, &TracksListener::trackHasBeenRemoved); QSignalSpy albumAddedSpy(&myListener, &TracksListener::albumAdded); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myDatabaseContent, &DatabaseInterface::trackRemoved, &myListener, &TracksListener::trackRemoved); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); connect(&myDatabaseContent, &DatabaseInterface::trackModified, &myListener, &TracksListener::trackModified); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged); connect(&myListener, &TracksListener::trackHasBeenRemoved, &myPlayList, &MediaPlayList::trackRemoved); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList); QCOMPARE(trackHasChangedSpy.count(), 0); QCOMPARE(trackHasBeenRemovedSpy.count(), 0); QCOMPARE(albumAddedSpy.count(), 0); myPlayList.enqueue(MediaPlayListEntry(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1)); QCOMPARE(trackHasChangedSpy.count(), 0); QCOMPARE(trackHasBeenRemovedSpy.count(), 0); QCOMPARE(albumAddedSpy.count(), 0); QCOMPARE(myPlayList.tracksCount(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), -1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 0); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(trackHasChangedSpy.count(), 1); QCOMPARE(trackHasBeenRemovedSpy.count(), 0); QCOMPARE(albumAddedSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); myDatabaseContent.removeTracksList({QUrl::fromLocalFile(QStringLiteral("/$1"))}); QCOMPARE(trackHasChangedSpy.count(), 1); QCOMPARE(trackHasBeenRemovedSpy.count(), 1); QCOMPARE(albumAddedSpy.count(), 0); QCOMPARE(myPlayList.tracksCount(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), -1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 0); } void testInsertTrackByNameModifyAndRemoval() { MediaPlayList myPlayList; DatabaseInterface myDatabaseContent; TracksListener myListener(&myDatabaseContent); QSignalSpy trackHasChangedSpy(&myListener, &TracksListener::trackHasChanged); QSignalSpy trackHasBeenRemovedSpy(&myListener, &TracksListener::trackHasBeenRemoved); QSignalSpy albumAddedSpy(&myListener, &TracksListener::albumAdded); myDatabaseContent.init(QStringLiteral("testDbDirectContent")); connect(&myDatabaseContent, &DatabaseInterface::trackRemoved, &myListener, &TracksListener::trackRemoved); connect(&myDatabaseContent, &DatabaseInterface::tracksAdded, &myListener, &TracksListener::tracksAdded); connect(&myDatabaseContent, &DatabaseInterface::trackModified, &myListener, &TracksListener::trackModified); connect(&myListener, &TracksListener::trackHasChanged, &myPlayList, &MediaPlayList::trackChanged); connect(&myListener, &TracksListener::trackHasBeenRemoved, &myPlayList, &MediaPlayList::trackRemoved); connect(&myListener, &TracksListener::albumAdded, &myPlayList, &MediaPlayList::albumAdded); connect(&myPlayList, &MediaPlayList::newTrackByIdInList, &myListener, &TracksListener::trackByIdInList); connect(&myPlayList, &MediaPlayList::newTrackByNameInList, &myListener, &TracksListener::trackByNameInList); connect(&myPlayList, &MediaPlayList::newArtistInList, &myListener, &TracksListener::newArtistInList); QCOMPARE(trackHasChangedSpy.count(), 0); QCOMPARE(trackHasBeenRemovedSpy.count(), 0); QCOMPARE(albumAddedSpy.count(), 0); myDatabaseContent.insertTracksList(mNewTracks, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(trackHasChangedSpy.count(), 0); QCOMPARE(trackHasBeenRemovedSpy.count(), 0); QCOMPARE(albumAddedSpy.count(), 0); myPlayList.enqueue(MediaPlayListEntry(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), 1, 1)); QCOMPARE(trackHasChangedSpy.count(), 1); QCOMPARE(trackHasBeenRemovedSpy.count(), 0); QCOMPARE(albumAddedSpy.count(), 0); QCOMPARE(myPlayList.tracksCount(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 1); myDatabaseContent.insertTracksList({ {true, QStringLiteral("$1"), QStringLiteral("0"), QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 2, 3, QTime::fromMSecsSinceStartOfDay(1000), {QUrl::fromLocalFile(QStringLiteral("/$1"))}, QDateTime::fromMSecsSinceEpoch(1), {QUrl::fromLocalFile(QStringLiteral("file://image$1"))}, 1, false, {}, {}, QStringLiteral("lyricist1")} }, mNewCovers, QStringLiteral("autoTest")); QCOMPARE(trackHasChangedSpy.count(), 2); QCOMPARE(trackHasBeenRemovedSpy.count(), 0); QCOMPARE(albumAddedSpy.count(), 0); QCOMPARE(myPlayList.tracksCount(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), 2); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 3); myDatabaseContent.removeTracksList({QUrl::fromLocalFile(QStringLiteral("/$1"))}); QCOMPARE(trackHasChangedSpy.count(), 2); QCOMPARE(trackHasBeenRemovedSpy.count(), 1); QCOMPARE(albumAddedSpy.count(), 0); QCOMPARE(myPlayList.tracksCount(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::IsValidRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TitleRole).toString(), QStringLiteral("track1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::ArtistRole).toString(), QStringLiteral("artist1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::AlbumRole).toString(), QStringLiteral("album1")); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::TrackNumberRole).toInt(), -1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), MediaPlayList::ColumnsRoles::DiscNumberRole).toInt(), 0); } }; QTEST_GUILESS_MAIN(TracksListenerTests) #include "trackslistenertest.moc" diff --git a/src/abstractfile/abstractfilelistener.cpp b/src/abstractfile/abstractfilelistener.cpp index e2d83d5f..571c1efd 100644 --- a/src/abstractfile/abstractfilelistener.cpp +++ b/src/abstractfile/abstractfilelistener.cpp @@ -1,108 +1,106 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "abstractfilelistener.h" #include "abstractfilelisting.h" #include "databaseinterface.h" #include "notificationitem.h" #include class AbstractFileListenerPrivate { public: QThread mFileQueryThread; AbstractFileListing *mFileListing = nullptr; }; AbstractFileListener::AbstractFileListener(QObject *parent) : QObject(parent), d(std::make_unique()) { } AbstractFileListener::~AbstractFileListener() { d->mFileQueryThread.quit(); d->mFileQueryThread.wait(); } DatabaseInterface *AbstractFileListener::databaseInterface() const { return nullptr; } void AbstractFileListener::setDatabaseInterface(DatabaseInterface *model) { if (model) { connect(this, &AbstractFileListener::newTrackFile, d->mFileListing, &AbstractFileListing::newTrackFile); connect(d->mFileListing, &AbstractFileListing::tracksList, model, &DatabaseInterface::insertTracksList); connect(d->mFileListing, &AbstractFileListing::removedTracksList, model, &DatabaseInterface::removeTracksList); connect(d->mFileListing, &AbstractFileListing::modifyTracksList, model, &DatabaseInterface::modifyTracksList); connect(d->mFileListing, &AbstractFileListing::askRestoredTracks, model, &DatabaseInterface::askRestoredTracks); connect(model, &DatabaseInterface::restoredTracks, d->mFileListing, &AbstractFileListing::restoredTracks); QMetaObject::invokeMethod(d->mFileListing, "init", Qt::QueuedConnection); } Q_EMIT databaseInterfaceChanged(); } void AbstractFileListener::applicationAboutToQuit() { d->mFileListing->applicationAboutToQuit(); d->mFileQueryThread.exit(); d->mFileQueryThread.wait(); } void AbstractFileListener::quitListener() { applicationAboutToQuit(); Q_EMIT clearDatabase(d->mFileListing->sourceName()); } void AbstractFileListener::setFileListing(AbstractFileListing *fileIndexer) { d->mFileListing = fileIndexer; d->mFileQueryThread.start(); d->mFileListing->moveToThread(&d->mFileQueryThread); connect(fileIndexer, &AbstractFileListing::indexingStarted, this, &AbstractFileListener::indexingStarted); connect(fileIndexer, &AbstractFileListing::indexingFinished, this, &AbstractFileListener::indexingFinished); connect(fileIndexer, &AbstractFileListing::newNotification, this, &AbstractFileListener::newNotification); connect(fileIndexer, &AbstractFileListing::closeNotification, this, &AbstractFileListener::closeNotification); } AbstractFileListing *AbstractFileListener::fileListing() const { return d->mFileListing; } #include "moc_abstractfilelistener.cpp" diff --git a/src/abstractfile/abstractfilelistener.h b/src/abstractfile/abstractfilelistener.h index cf8aa5f9..0475f128 100644 --- a/src/abstractfile/abstractfilelistener.h +++ b/src/abstractfile/abstractfilelistener.h @@ -1,92 +1,90 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef ABSTRACTFILELISTENER_H #define ABSTRACTFILELISTENER_H #include "notificationitem.h" #include #include #include #include class AbstractFileListenerPrivate; class DatabaseInterface; class MusicAudioTrack; class AbstractFileListing; class AbstractFileListener : public QObject { Q_OBJECT Q_PROPERTY(DatabaseInterface* databaseInterface READ databaseInterface WRITE setDatabaseInterface NOTIFY databaseInterfaceChanged) public: explicit AbstractFileListener(QObject *parent = nullptr); ~AbstractFileListener() override; DatabaseInterface* databaseInterface() const; AbstractFileListing* fileListing() const; Q_SIGNALS: void databaseInterfaceChanged(); void newTrackFile(const MusicAudioTrack &newTrack); void indexingStarted(); void indexingFinished(); void configurationChanged(); void clearDatabase(const QString &listenerName); void newNotification(NotificationItem notification); void closeNotification(QString notificationId); public Q_SLOTS: void setDatabaseInterface(DatabaseInterface* databaseInterface); void applicationAboutToQuit(); void quitListener(); protected: void setFileListing(AbstractFileListing *fileIndexer); NotificationItem& currentNotification(); private: std::unique_ptr d; }; #endif // ABSTRACTFILELISTENER_H diff --git a/src/abstractfile/abstractfilelisting.cpp b/src/abstractfile/abstractfilelisting.cpp index a8cb2dbb..817ecded 100644 --- a/src/abstractfile/abstractfilelisting.cpp +++ b/src/abstractfile/abstractfilelisting.cpp @@ -1,447 +1,445 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "abstractfilelisting.h" #include "musicaudiotrack.h" #include "notificationitem.h" #include "filescanner.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include class AbstractFileListingPrivate { public: explicit AbstractFileListingPrivate(QString sourceName) : mSourceName(std::move(sourceName)) { } QFileSystemWatcher mFileSystemWatcher; QHash mAllAlbumCover; QHash>> mDiscoveredFiles; QString mSourceName; FileScanner mFileScanner; QMimeDatabase mMimeDb; QHash mAllFiles; QAtomicInt mStopRequest = 0; int mImportedTracksCount = 0; int mNotificationUpdateInterval = 1; int mNewFilesEmitInterval = 1; bool mHandleNewFiles = true; }; AbstractFileListing::AbstractFileListing(const QString &sourceName, QObject *parent) : QObject(parent), d(std::make_unique(sourceName)) { connect(&d->mFileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &AbstractFileListing::directoryChanged); connect(&d->mFileSystemWatcher, &QFileSystemWatcher::fileChanged, this, &AbstractFileListing::fileChanged); } AbstractFileListing::~AbstractFileListing() = default; void AbstractFileListing::init() { Q_EMIT askRestoredTracks(sourceName()); } void AbstractFileListing::newTrackFile(const MusicAudioTrack &partialTrack) { const auto &newTrack = scanOneFile(partialTrack.resourceURI()); if (newTrack.isValid() && newTrack != partialTrack) { Q_EMIT modifyTracksList({newTrack}, d->mAllAlbumCover, d->mSourceName); } } void AbstractFileListing::restoredTracks(const QString &musicSource, QHash allFiles) { if (musicSource == sourceName()) { executeInit(std::move(allFiles)); refreshContent(); } } void AbstractFileListing::applicationAboutToQuit() { d->mStopRequest = 1; } void AbstractFileListing::scanDirectory(QList &newFiles, const QUrl &path) { if (d->mStopRequest == 1) { return; } QDir rootDirectory(path.toLocalFile()); rootDirectory.refresh(); if (rootDirectory.exists()) { watchPath(path.toLocalFile()); } auto ¤tDirectoryListingFiles = d->mDiscoveredFiles[path]; auto currentFilesList = QSet(); rootDirectory.refresh(); const auto entryList = rootDirectory.entryInfoList(QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs); for (const auto &oneEntry : entryList) { auto newFilePath = QUrl::fromLocalFile(oneEntry.canonicalFilePath()); if (oneEntry.isDir() || oneEntry.isFile()) { currentFilesList.insert(newFilePath); } } auto removedTracks = QVector>(); for (const auto &removedFilePath : currentDirectoryListingFiles) { auto itFilePath = std::find(currentFilesList.begin(), currentFilesList.end(), removedFilePath.first); if (itFilePath != currentFilesList.end()) { continue; } removedTracks.push_back(removedFilePath); } auto allRemovedTracks = QList(); for (const auto &oneRemovedTrack : removedTracks) { if (oneRemovedTrack.second) { allRemovedTracks.push_back(oneRemovedTrack.first); } else { removeFile(oneRemovedTrack.first, allRemovedTracks); } } for (const auto &oneRemovedTrack : removedTracks) { currentDirectoryListingFiles.remove(oneRemovedTrack); currentDirectoryListingFiles.remove(oneRemovedTrack); } if (!allRemovedTracks.isEmpty()) { Q_EMIT removedTracksList(allRemovedTracks); } if (!d->mHandleNewFiles) { return; } for (const auto &newFilePath : currentFilesList) { QFileInfo oneEntry(newFilePath.toLocalFile()); auto itFilePath = std::find(currentDirectoryListingFiles.begin(), currentDirectoryListingFiles.end(), QPair{newFilePath, oneEntry.isFile()}); if (itFilePath != currentDirectoryListingFiles.end()) { continue; } if (oneEntry.isDir()) { addFileInDirectory(newFilePath, path); scanDirectory(newFiles, newFilePath); if (d->mStopRequest == 1) { break; } continue; } if (!oneEntry.isFile()) { continue; } auto newTrack = scanOneFile(newFilePath); if (newTrack.isValid() && d->mStopRequest == 0) { addCover(newTrack); addFileInDirectory(newTrack.resourceURI(), path); newFiles.push_back(newTrack); ++d->mImportedTracksCount; if (d->mImportedTracksCount % d->mNotificationUpdateInterval == 0) { d->mNotificationUpdateInterval = std::min(50, 1 + d->mNotificationUpdateInterval * 2); } if (newFiles.size() > d->mNewFilesEmitInterval && d->mStopRequest == 0) { d->mNewFilesEmitInterval = std::min(50, 1 + d->mNewFilesEmitInterval * d->mNewFilesEmitInterval); emitNewFiles(newFiles); newFiles.clear(); } } if (d->mStopRequest == 1) { break; } } } const QString &AbstractFileListing::sourceName() const { return d->mSourceName; } void AbstractFileListing::directoryChanged(const QString &path) { const auto directoryEntry = d->mDiscoveredFiles.find(QUrl::fromLocalFile(path)); if (directoryEntry == d->mDiscoveredFiles.end()) { return; } Q_EMIT indexingStarted(); scanDirectoryTree(path); Q_EMIT indexingFinished(); } void AbstractFileListing::fileChanged(const QString &modifiedFileName) { auto modifiedFile = QUrl::fromLocalFile(modifiedFileName); auto modifiedTrack = scanOneFile(modifiedFile); if (modifiedTrack.isValid()) { Q_EMIT modifyTracksList({modifiedTrack}, d->mAllAlbumCover, d->mSourceName); } } void AbstractFileListing::executeInit(QHash allFiles) { d->mAllFiles = std::move(allFiles); } void AbstractFileListing::triggerRefreshOfContent() { d->mImportedTracksCount = 0; } void AbstractFileListing::refreshContent() { triggerRefreshOfContent(); } MusicAudioTrack AbstractFileListing::scanOneFile(const QUrl &scanFile) { MusicAudioTrack newTrack; auto localFileName = scanFile.toLocalFile(); const auto &fileMimeType = d->mMimeDb.mimeTypeForFile(localFileName); if (!fileMimeType.name().startsWith(QStringLiteral("audio/"))) { return newTrack; } QFileInfo scanFileInfo(localFileName); if (scanFileInfo.exists()) { auto itExistingFile = d->mAllFiles.find(scanFile); if (itExistingFile != d->mAllFiles.end()) { if (*itExistingFile >= scanFileInfo.fileTime(QFile::FileModificationTime)) { d->mAllFiles.erase(itExistingFile); return newTrack; } } } newTrack = d->mFileScanner.scanOneFile(scanFile, d->mMimeDb); if (newTrack.isValid()) { newTrack.setFileModificationTime(scanFileInfo.fileTime(QFile::FileModificationTime)); if (scanFileInfo.exists()) { watchPath(scanFile.toLocalFile()); } } return newTrack; } void AbstractFileListing::watchPath(const QString &pathName) { if (!d->mFileSystemWatcher.addPath(pathName)) { Q_EMIT errorWatchingFiles(); qDebug() << "AbstractFileListing::watchPath" << "fail for" << pathName; } } void AbstractFileListing::addFileInDirectory(const QUrl &newFile, const QUrl &directoryName) { const auto directoryEntry = d->mDiscoveredFiles.find(directoryName); if (directoryEntry == d->mDiscoveredFiles.end()) { watchPath(directoryName.toLocalFile()); QDir currentDirectory(directoryName.toLocalFile()); if (currentDirectory.cdUp()) { const auto parentDirectoryName = currentDirectory.absolutePath(); const auto parentDirectory = QUrl::fromLocalFile(parentDirectoryName); const auto parentDirectoryEntry = d->mDiscoveredFiles.find(parentDirectory); if (parentDirectoryEntry == d->mDiscoveredFiles.end()) { watchPath(parentDirectoryName); } auto &parentCurrentDirectoryListingFiles = d->mDiscoveredFiles[parentDirectory]; parentCurrentDirectoryListingFiles.insert({directoryName, false}); } } auto ¤tDirectoryListingFiles = d->mDiscoveredFiles[directoryName]; QFileInfo isAFile(newFile.toLocalFile()); currentDirectoryListingFiles.insert({newFile, isAFile.isFile()}); } void AbstractFileListing::scanDirectoryTree(const QString &path) { auto newFiles = QList(); scanDirectory(newFiles, QUrl::fromLocalFile(path)); if (!newFiles.isEmpty() && d->mStopRequest == 0) { emitNewFiles(newFiles); } } void AbstractFileListing::setHandleNewFiles(bool handleThem) { d->mHandleNewFiles = handleThem; } void AbstractFileListing::emitNewFiles(const QList &tracks) { Q_EMIT tracksList(tracks, d->mAllAlbumCover, d->mSourceName); } void AbstractFileListing::addCover(const MusicAudioTrack &newTrack) { auto itCover = d->mAllAlbumCover.find(newTrack.albumName()); if (itCover != d->mAllAlbumCover.end()) { return; } QFileInfo trackFilePath(newTrack.resourceURI().toLocalFile()); QDir trackFileDir = trackFilePath.absoluteDir(); QString dirNamePattern = QStringLiteral("*") + trackFileDir.dirName() + QStringLiteral("*"); QStringList filters; filters << QStringLiteral("*[Cc]over*.jpg") << QStringLiteral("*[Cc]over*.png") << QStringLiteral("*[Ff]older*.jpg") << QStringLiteral("*[Ff]older*.png") << QStringLiteral("*[Ff]ront*.jpg") << QStringLiteral("*[Ff]ront*.png") << dirNamePattern + QStringLiteral(".jpg") << dirNamePattern + QStringLiteral(".png") << dirNamePattern.toLower() + QStringLiteral(".jpg") << dirNamePattern.toLower() + QStringLiteral(".png"); dirNamePattern.remove(QLatin1Char(' ')); filters << dirNamePattern + QStringLiteral(".jpg") << dirNamePattern + QStringLiteral(".png") << dirNamePattern.toLower() + QStringLiteral(".jpg") << dirNamePattern.toLower() + QStringLiteral(".png"); trackFileDir.setNameFilters(filters); QFileInfoList coverFiles = trackFileDir.entryInfoList(); if (coverFiles.isEmpty()) { return; } else { d->mAllAlbumCover[newTrack.resourceURI().toString()] = QUrl::fromLocalFile(coverFiles.at(0).absoluteFilePath()); } } void AbstractFileListing::removeDirectory(const QUrl &removedDirectory, QList &allRemovedFiles) { const auto itRemovedDirectory = d->mDiscoveredFiles.find(removedDirectory); if (itRemovedDirectory == d->mDiscoveredFiles.end()) { return; } const auto ¤tRemovedDirectory = *itRemovedDirectory; for (const auto &itFile : currentRemovedDirectory) { if (itFile.first.isValid() && !itFile.first.isEmpty()) { removeFile(itFile.first, allRemovedFiles); if (itFile.second) { allRemovedFiles.push_back(itFile.first); } } } d->mDiscoveredFiles.erase(itRemovedDirectory); } void AbstractFileListing::removeFile(const QUrl &oneRemovedTrack, QList &allRemovedFiles) { auto itRemovedDirectory = d->mDiscoveredFiles.find(oneRemovedTrack); if (itRemovedDirectory != d->mDiscoveredFiles.end()) { removeDirectory(oneRemovedTrack, allRemovedFiles); } } void AbstractFileListing::setSourceName(const QString &name) { d->mSourceName = name; } QHash &AbstractFileListing::allFiles() { return d->mAllFiles; } void AbstractFileListing::checkFilesToRemove() { QList allRemovedFiles; for (auto itFile = d->mAllFiles.begin(); itFile != d->mAllFiles.end(); ++itFile) { allRemovedFiles.push_back(itFile.key()); } if (!allRemovedFiles.isEmpty()) { Q_EMIT removedTracksList(allRemovedFiles); } } FileScanner &AbstractFileListing::fileScanner() { return d->mFileScanner; } #include "moc_abstractfilelisting.cpp" diff --git a/src/abstractfile/abstractfilelisting.h b/src/abstractfile/abstractfilelisting.h index 9d7b6235..92c21200 100644 --- a/src/abstractfile/abstractfilelisting.h +++ b/src/abstractfile/abstractfilelisting.h @@ -1,134 +1,132 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef ABSTRACTFILELISTING_H #define ABSTRACTFILELISTING_H #include "elisaLib_export.h" #include "notificationitem.h" #include #include #include #include #include #include #include class AbstractFileListingPrivate; class MusicAudioTrack; class NotificationItem; class FileScanner; class ELISALIB_EXPORT AbstractFileListing : public QObject { Q_OBJECT public: explicit AbstractFileListing(const QString &sourceName, QObject *parent = nullptr); ~AbstractFileListing() override; virtual void applicationAboutToQuit(); const QString &sourceName() const; Q_SIGNALS: void tracksList(const QList &tracks, const QHash &covers, const QString &musicSource); void removedTracksList(const QList &removedTracks); void modifyTracksList(const QList &modifiedTracks, const QHash &covers, const QString &musicSource); void indexingStarted(); void indexingFinished(); void newNotification(NotificationItem notification); void closeNotification(QString notificationId); void askRestoredTracks(const QString &musicSource); void errorWatchingFiles(); public Q_SLOTS: void refreshContent(); void init(); void newTrackFile(const MusicAudioTrack &partialTrack); void restoredTracks(const QString &musicSource, QHash allFiles); protected Q_SLOTS: void directoryChanged(const QString &path); void fileChanged(const QString &modifiedFileName); protected: virtual void executeInit(QHash allFiles); virtual void triggerRefreshOfContent(); void scanDirectory(QList &newFiles, const QUrl &path); virtual MusicAudioTrack scanOneFile(const QUrl &scanFile); void watchPath(const QString &pathName); void addFileInDirectory(const QUrl &newFile, const QUrl &directoryName); void scanDirectoryTree(const QString &path); void setHandleNewFiles(bool handleThem); void emitNewFiles(const QList &tracks); void addCover(const MusicAudioTrack &newTrack); void removeDirectory(const QUrl &removedDirectory, QList &allRemovedFiles); void removeFile(const QUrl &oneRemovedTrack, QList &allRemovedFiles); void setSourceName(const QString &name); QHash& allFiles(); void checkFilesToRemove(); FileScanner& fileScanner(); private: std::unique_ptr d; }; #endif // ABSTRACTFILELISTING_H diff --git a/src/android/AndroidTheme.qml b/src/android/AndroidTheme.qml index d5f6bf08..689a98e5 100644 --- a/src/android/AndroidTheme.qml +++ b/src/android/AndroidTheme.qml @@ -1,35 +1,33 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ import QtQuick 2.0 Item { property string albumCover: 'media-optical-audio.svg' property string artistImage: 'view-media-artist.svg' property string clearIcon: 'edit-clear.svg' property string skipBackwardIcon: 'media-skip-backward.svg' property string pauseIcon: 'media-playback-pause.svg' property string playIcon: 'media-playback-start.svg' property string skipForwardIcon: 'media-skip-forward.svg' property string playerVolumeMutedIcon: 'player-volume-muted.svg' property string playerVolumeIcon: 'player-volume.svg' property string ratingIcon: 'rating.svg' property string ratingUnratedIcon: 'rating-unrated.svg' property string errorIcon: 'error.svg' } diff --git a/src/android/ElisaMainWindow.qml b/src/android/ElisaMainWindow.qml index 3441e946..4d99fd07 100644 --- a/src/android/ElisaMainWindow.qml +++ b/src/android/ElisaMainWindow.qml @@ -1,564 +1,562 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ import QtQuick 2.6 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.3 import QtQuick.Window 2.2 import QtQml.Models 2.1 import org.kde.elisa 1.0 ApplicationWindow { id: mainWindow visible: true title: 'Elisa' SystemPalette { id: myPalette colorGroup: SystemPalette.Active } Theme { id: elisaTheme } property string globalBrowseFlag: 'BrowseDirectChildren' property string globalFilter: '*' property string globalSortCriteria: '' PlatformIntegration { id: platformInterface playListModel: playListModelItem playListControler: playListControlerItem audioPlayerManager: manageAudioPlayer headerBarManager: myHeaderBarManager manageMediaPlayerControl: myPlayControlManager onRaisePlayer: { mainWindow.raise() mainWindow.requestActivate() } } MusicListenersManager { id: allListeners } AudioWrapper { id: audioPlayer audioRole: Audio.MusicRole muted: playControlItem.muted volume: playControlItem.volume * 100 onVolumeChanged: playControlItem.volume = volume / 100.0 onMutedChanged: playControlItem.muted = muted source: manageAudioPlayer.playerSource onPlaying: { myPlayControlManager.playerPlaying() } onPaused: { myPlayControlManager.playerPaused() } onStopped: { myPlayControlManager.playerStopped() } } MediaPlayList { id: playListModelItem persistentState: persistentSettings.playListState musicListenersManager: allListeners } PlayListControler { id: playListControlerItem playListModel: playListModelItem isValidRole: MediaPlayList.IsValidRole onPlayListFinished: manageAudioPlayer.playListFinished() persistentState: persistentSettings.playListControlerState Component.onCompleted: { var d = new Date(); var n = d.getMilliseconds(); seedRandomGenerator(n); } } ManageHeaderBar { id: myHeaderBarManager playListModel: playListModelItem currentTrack: playListControlerItem.currentTrack artistRole: MediaPlayList.ArtistRole titleRole: MediaPlayList.TitleRole albumRole: MediaPlayList.AlbumRole imageRole: MediaPlayList.ImageRole albumIdRole: MediaPlayList.AlbumIdRole isValidRole: MediaPlayList.IsValidRole } ManageAudioPlayer { id: manageAudioPlayer currentTrack: playListControlerItem.currentTrack playListModel: playListModelItem urlRole: MediaPlayList.ResourceRole isPlayingRole: MediaPlayList.IsPlayingRole playerStatus: audioPlayer.status playerPlaybackState: audioPlayer.playbackState playerError: audioPlayer.error audioDuration: audioPlayer.duration playerIsSeekable: audioPlayer.seekable playerPosition: audioPlayer.position persistentState: persistentSettings.audioPlayerState onPlayerPlay: audioPlayer.play() onPlayerPause: audioPlayer.pause() onPlayerStop: audioPlayer.stop() onSkipNextTrack: playListControlerItem.skipNextTrack() onSeek: audioPlayer.seek(position) } ManageMediaPlayerControl { id: myPlayControlManager playListModel: playListModelItem currentTrack: playListControlerItem.currentTrack } AllAlbumsModel { id: allAlbumsModel } Connections { target: allListeners onAlbumAdded: allAlbumsModel.albumAdded(newAlbum) } Connections { target: allListeners onAlbumRemoved: allAlbumsModel.albumRemoved(removedAlbum) } Connections { target: allListeners onAlbumModified: allAlbumsModel.albumModified(modifiedAlbum) } AllArtistsModel { id: allArtistsModel } Connections { target: allListeners onArtistAdded: allArtistsModel.artistAdded(newArtist) } Connections { target: allListeners onArtistRemoved: allArtistsModel.artistRemoved(removedArtist) } Connections { target: allListeners onArtistModified: allArtistsModel.artistModified(modifiedArtist) } Rectangle { color: myPalette.base anchors.fill: parent ColumnLayout { anchors.fill: parent spacing: 0 HeaderBar { id: headerBar Layout.preferredHeight: Screen.pixelDensity * 40. Layout.minimumHeight: Screen.pixelDensity * 40. Layout.maximumHeight: Screen.pixelDensity * 40. Layout.fillWidth: true tracksCount: myHeaderBarManager.remainingTracks album: myHeaderBarManager.album title: myHeaderBarManager.title artist: myHeaderBarManager.artist image: myHeaderBarManager.image ratingVisible: false Rectangle { anchors.fill: menuButton z: 1 radius: width / 2 color: myPalette.window } } MediaPlayerControl { id: playControlItem duration: audioPlayer.duration seekable: audioPlayer.seekable volume: persistentSettings.playControlItemVolume muted: persistentSettings.playControlItemMuted position: audioPlayer.position skipBackwardEnabled: myPlayControlManager.skipBackwardControlEnabled skipForwardEnabled: myPlayControlManager.skipForwardControlEnabled playEnabled: myPlayControlManager.playControlEnabled isPlaying: myPlayControlManager.musicPlaying Layout.preferredHeight: Screen.pixelDensity * 12. Layout.minimumHeight: Layout.preferredHeight Layout.maximumHeight: Layout.preferredHeight Layout.fillWidth: true onSeek: audioPlayer.seek(position) onPlay: manageAudioPlayer.playPause() onPause: manageAudioPlayer.playPause() onPlayPrevious: playListControlerItem.skipPreviousTrack() onPlayNext: playListControlerItem.skipNextTrack() } RowLayout { Layout.fillHeight: true Layout.fillWidth: true spacing: 0 Rectangle { color: myPalette.window Layout.fillHeight: true Layout.preferredWidth: Screen.pixelDensity * 50. Layout.minimumWidth: Screen.pixelDensity * 50. Layout.maximumWidth: Screen.pixelDensity * 50. } Item { Layout.fillHeight: true Layout.fillWidth: true RowLayout { anchors.fill: parent spacing: 0 id: contentZone Item { id: mainContentView Layout.leftMargin: Screen.pixelDensity * 0.5 Layout.rightMargin: Screen.pixelDensity * 0.5 Layout.fillHeight: true Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 //z: 1 visible: Layout.minimumWidth != 0 MediaBrowser { id: localAlbums anchors.fill: parent firstPage: MediaAllAlbumView { playListModel: playListModelItem playerControl: manageAudioPlayer stackView: localAlbums.stackView musicListener: allListeners contentDirectoryModel: allAlbumsModel } visible: opacity > 0 } MediaBrowser { id: localArtists anchors.fill: parent firstPage: MediaAllArtistView { playListModel: playListModelItem artistsModel: allArtistsModel playerControl: manageAudioPlayer stackView: localArtists.stackView musicListener: allListeners contentDirectoryModel: allAlbumsModel } visible: opacity > 0 } } Rectangle { id: firstViewSeparatorItem border.width: 1 border.color: myPalette.mid color: myPalette.mid visible: true Layout.bottomMargin: Screen.pixelDensity * 0.5 Layout.topMargin: Screen.pixelDensity * 0.5 Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter Layout.preferredHeight: parent.height - Screen.pixelDensity * 5. Layout.minimumHeight: parent.height - Screen.pixelDensity * 5. Layout.maximumHeight: parent.height - Screen.pixelDensity * 5. Layout.preferredWidth: 1 Layout.minimumWidth: 1 Layout.maximumWidth: 1 } MediaPlayListView { id: playList playListModel: playListModelItem playListControler: playListControlerItem randomPlayChecked: playListControlerItem.randomPlayControl repeatPlayChecked: playListControlerItem.repeatPlayControl Layout.fillHeight: true Layout.minimumWidth: contentZone.width Layout.maximumWidth: contentZone.width Layout.preferredWidth: contentZone.width Component.onCompleted: { playListControlerItem.randomPlay = Qt.binding(function() { return playList.randomPlayChecked }) playListControlerItem.repeatPlay = Qt.binding(function() { return playList.repeatPlayChecked }) myPlayControlManager.randomOrContinuePlay = Qt.binding(function() { return playList.randomPlayChecked || playList.repeatPlayChecked }) } } Rectangle { id: viewSeparatorItem border.width: 1 border.color: myPalette.mid color: myPalette.mid visible: Layout.minimumWidth != 0 Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter Layout.preferredHeight: parent.height - Screen.pixelDensity * 5. Layout.preferredWidth: 1 Layout.minimumWidth: 1 Layout.maximumWidth: 1 } ContextView { id: albumContext Layout.fillHeight: true Layout.minimumWidth: contentZone.width Layout.maximumWidth: contentZone.width Layout.preferredWidth: contentZone.width visible: Layout.minimumWidth != 0 artistName: myHeaderBarManager.artist albumName: myHeaderBarManager.album albumArtUrl: myHeaderBarManager.image } } states: [ State { name: 'allAlbums' when: viewModeView.currentRow === 1 PropertyChanges { target: mainContentView Layout.minimumWidth: contentZone.width * 0.66 Layout.maximumWidth: contentZone.width * 0.66 Layout.preferredWidth: contentZone.width * 0.66 } PropertyChanges { target: firstViewSeparatorItem Layout.minimumWidth: 1 Layout.maximumWidth: 1 Layout.preferredWidth: 1 } PropertyChanges { target: playList Layout.minimumWidth: contentZone.width * 0.33 Layout.maximumWidth: contentZone.width * 0.33 Layout.preferredWidth: contentZone.width * 0.33 } PropertyChanges { target: viewSeparatorItem Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 } PropertyChanges { target: albumContext Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 } PropertyChanges { target: localAlbums opacity: 1 } PropertyChanges { target: localArtists opacity: 0 } }, State { name: 'allArtists' when: viewModeView.currentRow === 2 PropertyChanges { target: mainContentView Layout.minimumWidth: contentZone.width * 0.66 Layout.maximumWidth: contentZone.width * 0.66 Layout.preferredWidth: contentZone.width * 0.66 } PropertyChanges { target: firstViewSeparatorItem Layout.minimumWidth: 1 Layout.maximumWidth: 1 Layout.preferredWidth: 1 } PropertyChanges { target: playList Layout.minimumWidth: contentZone.width * 0.33 Layout.maximumWidth: contentZone.width * 0.33 Layout.preferredWidth: contentZone.width * 0.33 } PropertyChanges { target: viewSeparatorItem Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 } PropertyChanges { target: albumContext Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 } PropertyChanges { target: localAlbums opacity: 0 } PropertyChanges { target: localArtists opacity: 1 } }, State { name: 'full' when: viewModeView.currentRow == 0 PropertyChanges { target: mainContentView Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 } PropertyChanges { target: firstViewSeparatorItem Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 } PropertyChanges { target: playList Layout.minimumWidth: contentZone.width / 2 Layout.maximumWidth: contentZone.width / 2 Layout.preferredWidth: contentZone.width / 2 } PropertyChanges { target: viewSeparatorItem Layout.minimumWidth: 1 Layout.maximumWidth: 1 Layout.preferredWidth: 1 } PropertyChanges { target: albumContext Layout.minimumWidth: contentZone.width / 2 Layout.maximumWidth: contentZone.width / 2 Layout.preferredWidth: contentZone.width / 2 } PropertyChanges { target: localAlbums opacity: 0 } PropertyChanges { target: localArtists opacity: 0 } } ] transitions: Transition { NumberAnimation { properties: "Layout.minimumWidth, Layout.maximumWidth, Layout.preferredWidth, opacity" easing.type: Easing.InOutQuad duration: 300 } } } } } } } diff --git a/src/android/PlatformIntegration.qml b/src/android/PlatformIntegration.qml index 89c19158..36863c6d 100644 --- a/src/android/PlatformIntegration.qml +++ b/src/android/PlatformIntegration.qml @@ -1,34 +1,32 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ import QtQuick 2.0 import org.kde.elisa 1.0 Item { id: rootItem property var playListModel property var playListControler property var audioPlayerManager property var player property var headerBarManager property var manageMediaPlayerControl signal raisePlayer() } diff --git a/src/audiowrapper.cpp b/src/audiowrapper.cpp index 5fcba4ea..ff8579b9 100644 --- a/src/audiowrapper.cpp +++ b/src/audiowrapper.cpp @@ -1,184 +1,182 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "audiowrapper.h" #include #include #include "config-upnp-qt.h" class AudioWrapperPrivate { public: QMediaPlayer mPlayer; }; AudioWrapper::AudioWrapper(QObject *parent) : QObject(parent), d(std::make_unique()) { connect(&d->mPlayer, &QMediaPlayer::mutedChanged, this, &AudioWrapper::playerMutedChanged); connect(&d->mPlayer, &QMediaPlayer::volumeChanged, this, &AudioWrapper::playerVolumeChanged); connect(&d->mPlayer, &QMediaPlayer::mediaChanged, this, &AudioWrapper::sourceChanged); connect(&d->mPlayer, &QMediaPlayer::mediaStatusChanged, this, &AudioWrapper::statusChanged); connect(&d->mPlayer, &QMediaPlayer::stateChanged, this, &AudioWrapper::playbackStateChanged); connect(&d->mPlayer, &QMediaPlayer::stateChanged, this, &AudioWrapper::playerStateChanged); connect(&d->mPlayer, QOverload::of(&QMediaPlayer::error), this, &AudioWrapper::errorChanged); connect(&d->mPlayer, &QMediaPlayer::durationChanged, this, &AudioWrapper::durationChanged); connect(&d->mPlayer, &QMediaPlayer::positionChanged, this, &AudioWrapper::positionChanged); connect(&d->mPlayer, &QMediaPlayer::seekableChanged, this, &AudioWrapper::seekableChanged); } AudioWrapper::~AudioWrapper() = default; bool AudioWrapper::muted() const { return d->mPlayer.isMuted(); } qreal AudioWrapper::volume() const { auto realVolume = static_cast(d->mPlayer.volume() / 100.0); auto userVolume = static_cast(QAudio::convertVolume(realVolume, QAudio::LinearVolumeScale, QAudio::LogarithmicVolumeScale)); return userVolume * 100.0; } QUrl AudioWrapper::source() const { return d->mPlayer.media().canonicalUrl(); } QMediaPlayer::Error AudioWrapper::error() const { if (d->mPlayer.error() != QMediaPlayer::NoError) { qDebug() << "AudioWrapper::error" << d->mPlayer.errorString(); } return d->mPlayer.error(); } qint64 AudioWrapper::duration() const { return d->mPlayer.duration(); } qint64 AudioWrapper::position() const { return d->mPlayer.position(); } bool AudioWrapper::seekable() const { return d->mPlayer.isSeekable(); } QAudio::Role AudioWrapper::audioRole() const { return d->mPlayer.audioRole(); } QMediaPlayer::State AudioWrapper::playbackState() const { return d->mPlayer.state(); } QMediaPlayer::MediaStatus AudioWrapper::status() const { return d->mPlayer.mediaStatus(); } void AudioWrapper::setMuted(bool muted) { d->mPlayer.setMuted(muted); } void AudioWrapper::setVolume(qreal volume) { auto realVolume = static_cast(QAudio::convertVolume(volume / 100.0, QAudio::LogarithmicVolumeScale, QAudio::LinearVolumeScale)); d->mPlayer.setVolume(qRound(realVolume * 100)); } void AudioWrapper::setSource(const QUrl &source) { d->mPlayer.setMedia({source}); } void AudioWrapper::setPosition(qint64 position) { d->mPlayer.setPosition(position); } void AudioWrapper::play() { d->mPlayer.play(); } void AudioWrapper::pause() { d->mPlayer.pause(); } void AudioWrapper::stop() { d->mPlayer.stop(); } void AudioWrapper::seek(int position) { d->mPlayer.setPosition(position); } void AudioWrapper::setAudioRole(QAudio::Role audioRole) { d->mPlayer.setAudioRole(audioRole); } void AudioWrapper::playerStateChanged() { switch(d->mPlayer.state()) { case QMediaPlayer::State::StoppedState: Q_EMIT stopped(); break; case QMediaPlayer::State::PlayingState: Q_EMIT playing(); break; case QMediaPlayer::State::PausedState: Q_EMIT paused(); break; } } void AudioWrapper::playerVolumeChanged() { QTimer::singleShot(0, [this]() {Q_EMIT volumeChanged();}); } void AudioWrapper::playerMutedChanged() { QTimer::singleShot(0, [this]() {Q_EMIT mutedChanged();}); } #include "moc_audiowrapper.cpp" diff --git a/src/audiowrapper.h b/src/audiowrapper.h index e1ef6758..58dabd73 100644 --- a/src/audiowrapper.h +++ b/src/audiowrapper.h @@ -1,171 +1,169 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef AUDIOWRAPPER_H #define AUDIOWRAPPER_H #include "elisaLib_export.h" #include #include #include #include #include class AudioWrapperPrivate; class ELISALIB_EXPORT AudioWrapper : public QObject { Q_OBJECT Q_PROPERTY(bool muted READ muted WRITE setMuted NOTIFY mutedChanged) Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY volumeChanged) Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) Q_PROPERTY(QMediaPlayer::MediaStatus status READ status NOTIFY statusChanged) Q_PROPERTY(QMediaPlayer::State playbackState READ playbackState NOTIFY playbackStateChanged) Q_PROPERTY(QMediaPlayer::Error error READ error NOTIFY errorChanged) Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged) Q_PROPERTY(qint64 position READ position WRITE setPosition NOTIFY positionChanged) Q_PROPERTY(bool seekable READ seekable NOTIFY seekableChanged) Q_PROPERTY(QAudio::Role audioRole READ audioRole WRITE setAudioRole NOTIFY audioRoleChanged) public: explicit AudioWrapper(QObject *parent = nullptr); ~AudioWrapper() override; bool muted() const; qreal volume() const; QUrl source() const; QMediaPlayer::MediaStatus status() const; QMediaPlayer::State playbackState() const; QMediaPlayer::Error error() const; qint64 duration() const; qint64 position() const; bool seekable() const; QAudio::Role audioRole() const; Q_SIGNALS: void mutedChanged(); void volumeChanged(); void sourceChanged(); void statusChanged(QMediaPlayer::MediaStatus status); void playbackStateChanged(QMediaPlayer::State state); void errorChanged(QMediaPlayer::Error error); void durationChanged(qint64 duration); void positionChanged(qint64 position); void seekableChanged(bool seekable); void playing(); void paused(); void stopped(); void audioRoleChanged(); public Q_SLOTS: void setMuted(bool muted); void setVolume(qreal volume); void setSource(const QUrl &source); void setPosition(qint64 position); void play(); void pause(); void stop(); void seek(int position); void setAudioRole(QAudio::Role audioRole); private Q_SLOTS: void playerStateChanged(); void playerVolumeChanged(); void playerMutedChanged(); private: std::unique_ptr d; }; #endif // AUDIOWRAPPER_H diff --git a/src/baloo/baloolistener.cpp b/src/baloo/baloolistener.cpp index ff96d1ee..184f2c24 100644 --- a/src/baloo/baloolistener.cpp +++ b/src/baloo/baloolistener.cpp @@ -1,44 +1,42 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "baloolistener.h" #include "localbaloofilelisting.h" #include "databaseinterface.h" #include class BalooListenerPrivate { public: LocalBalooFileListing mBalooFileIndexer; }; BalooListener::BalooListener(QObject *parent) : AbstractFileListener(parent), d(new BalooListenerPrivate) { setFileListing(&d->mBalooFileIndexer); } BalooListener::~BalooListener() = default; #include "moc_baloolistener.cpp" diff --git a/src/baloo/baloolistener.h b/src/baloo/baloolistener.h index b33882cd..d6c6a013 100644 --- a/src/baloo/baloolistener.h +++ b/src/baloo/baloolistener.h @@ -1,54 +1,52 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef BALOOLISTENER_H #define BALOOLISTENER_H #include "../abstractfile/abstractfilelistener.h" #include #include #include #include class BalooListenerPrivate; class DatabaseInterface; class MusicAudioTrack; class BalooListener : public AbstractFileListener { Q_OBJECT public: explicit BalooListener(QObject *parent = nullptr); ~BalooListener() override; Q_SIGNALS: public Q_SLOTS: private: std::unique_ptr d; }; #endif // BALOOLISTENER_H diff --git a/src/baloo/localbaloofilelisting.cpp b/src/baloo/localbaloofilelisting.cpp index ee2868d1..aee4eb7d 100644 --- a/src/baloo/localbaloofilelisting.cpp +++ b/src/baloo/localbaloofilelisting.cpp @@ -1,404 +1,402 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "localbaloofilelisting.h" #include "musicaudiotrack.h" #include "notificationitem.h" #include "elisa_settings.h" #include "elisautils.h" #include "baloo/scheduler.h" #include "baloo/fileindexer.h" #include "baloowatcherapplicationadaptor.h" #include "filescanner.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class LocalBalooFileListingPrivate { public: Baloo::Query mQuery; QHash> mAllAlbums; QDBusServiceWatcher mServiceWatcher; QScopedPointer mBalooIndexer; QScopedPointer mBalooScheduler; QAtomicInt mStopRequest = 0; BalooWatcherApplicationAdaptor *mDbusAdaptor = nullptr; bool mIsRegistered = false; bool mIsRegistering = false; }; LocalBalooFileListing::LocalBalooFileListing(QObject *parent) : AbstractFileListing(QStringLiteral("baloo"), parent), d(std::make_unique()) { d->mQuery.addType(QStringLiteral("Audio")); setHandleNewFiles(false); auto sessionBus = QDBusConnection::sessionBus(); d->mDbusAdaptor = new BalooWatcherApplicationAdaptor(this); sessionBus.registerObject(QStringLiteral("/org/kde/BalooWatcherApplication"), d->mDbusAdaptor, QDBusConnection::ExportAllContents); connect(&d->mServiceWatcher, &QDBusServiceWatcher::serviceRegistered, this, &LocalBalooFileListing::serviceRegistered); connect(&d->mServiceWatcher, &QDBusServiceWatcher::serviceOwnerChanged, this, &LocalBalooFileListing::serviceOwnerChanged); connect(&d->mServiceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, &LocalBalooFileListing::serviceUnregistered); d->mServiceWatcher.setConnection(sessionBus); d->mServiceWatcher.addWatchedService(QStringLiteral("org.kde.baloo")); if (sessionBus.interface()->isServiceRegistered(QStringLiteral("org.kde.baloo"))) { registerToBaloo(); } } LocalBalooFileListing::~LocalBalooFileListing() { Q_EMIT closeNotification(QStringLiteral("balooInvalidConfiguration")); } void LocalBalooFileListing::applicationAboutToQuit() { AbstractFileListing::applicationAboutToQuit(); d->mStopRequest = 1; } void LocalBalooFileListing::newBalooFile(const QString &fileName) { auto newFile = QUrl::fromLocalFile(fileName); auto newTrack = scanOneFile(newFile); if (newTrack.isValid()) { QFileInfo newFileInfo(fileName); addFileInDirectory(newFile, QUrl::fromLocalFile(newFileInfo.absoluteDir().absolutePath())); emitNewFiles({newTrack}); } } void LocalBalooFileListing::registeredToBaloo(QDBusPendingCallWatcher *watcher) { qDebug() << "LocalBalooFileListing::registeredToBaloo"; if (!watcher) { return; } QDBusPendingReply<> reply = *watcher; if (reply.isError()) { qDebug() << "LocalBalooFileListing::executeInit" << reply.error().name() << reply.error().message(); d->mIsRegistered = false; } else { d->mIsRegistered = true; } d->mIsRegistering = false; watcher->deleteLater(); } void LocalBalooFileListing::registerToBaloo() { if (d->mIsRegistering) { qDebug() << "LocalBalooFileListing::registerToBaloo" << "already registering"; return; } qDebug() << "LocalBalooFileListing::registerToBaloo"; d->mIsRegistering = true; auto sessionBus = QDBusConnection::sessionBus(); d->mBalooIndexer.reset(new org::kde::baloo::fileindexer(QStringLiteral("org.kde.baloo"), QStringLiteral("/fileindexer"), sessionBus, this)); if (!d->mBalooIndexer->isValid()) { qDebug() << "LocalBalooFileListing::registerToBaloo" << "invalid org.kde.baloo/fileindexer interface"; return; } connect(d->mBalooIndexer.data(), &org::kde::baloo::fileindexer::finishedIndexingFile, this, &LocalBalooFileListing::newBalooFile); d->mBalooScheduler.reset(new org::kde::baloo::scheduler(QStringLiteral("org.kde.baloo"), QStringLiteral("/scheduler"), sessionBus, this)); if (!d->mBalooScheduler->isValid()) { qDebug() << "LocalBalooFileListing::registerToBaloo" << "invalid org.kde.baloo/scheduler interface"; return; } qDebug() << "LocalBalooFileListing::registerToBaloo" << "call registerMonitor"; auto answer = d->mBalooIndexer->registerMonitor(); if (answer.isError()) { qDebug() << "LocalBalooFileListing::executeInit" << answer.error().name() << answer.error().message(); } auto pendingCallWatcher = new QDBusPendingCallWatcher(answer); connect(pendingCallWatcher, &QDBusPendingCallWatcher::finished, this, &LocalBalooFileListing::registeredToBaloo); if (pendingCallWatcher->isFinished()) { registeredToBaloo(pendingCallWatcher); } QDBusMessage registerBalooWatcher = QDBusMessage::createMethodCall(QStringLiteral("org.kde.baloo"), QStringLiteral("/"), QStringLiteral("org.kde.baloo.main"), QStringLiteral("registerBalooWatcher")); registerBalooWatcher.setArguments({QStringLiteral("org.mpris.MediaPlayer2.elisa/org/kde/BalooWatcherApplication")}); auto pendingCall = sessionBus.asyncCall(registerBalooWatcher); qDebug() << "LocalBalooFileListing::registerToBaloo" << "call registerBalooWatcher"; auto pendingCallWatcher2 = new QDBusPendingCallWatcher(pendingCall); connect(pendingCallWatcher2, &QDBusPendingCallWatcher::finished, this, &LocalBalooFileListing::registeredToBaloo); if (pendingCallWatcher2->isFinished()) { registeredToBaloo(pendingCallWatcher2); } } void LocalBalooFileListing::renamedFiles(const QString &from, const QString &to, const QStringList &listFiles) { qDebug() << "LocalBalooFileListing::renamedFiles" << from << to << listFiles; } void LocalBalooFileListing::serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner) { Q_UNUSED(oldOwner); Q_UNUSED(newOwner); qDebug() << "LocalBalooFileListing::serviceOwnerChanged" << serviceName << oldOwner << newOwner; if (serviceName == QStringLiteral("org.kde.baloo") && !newOwner.isEmpty()) { d->mIsRegistered = false; registerToBaloo(); } } void LocalBalooFileListing::serviceRegistered(const QString &serviceName) { qDebug() << "LocalBalooFileListing::serviceRegistered" << serviceName; if (serviceName == QStringLiteral("org.kde.baloo")) { registerToBaloo(); } } void LocalBalooFileListing::serviceUnregistered(const QString &serviceName) { qDebug() << "LocalBalooFileListing::serviceUnregistered" << serviceName; if (serviceName == QStringLiteral("org.kde.baloo")) { d->mIsRegistered = false; } } void LocalBalooFileListing::executeInit(QHash allFiles) { AbstractFileListing::executeInit(std::move(allFiles)); } void LocalBalooFileListing::triggerRefreshOfContent() { if (!checkBalooConfiguration()) { return; } Q_EMIT indexingStarted(); AbstractFileListing::triggerRefreshOfContent(); auto resultIterator = d->mQuery.exec(); auto newFiles = QList(); while(resultIterator.next() && d->mStopRequest == 0) { const auto &newFileUrl = QUrl::fromLocalFile(resultIterator.filePath()); auto scanFileInfo = QFileInfo(resultIterator.filePath()); const auto currentDirectory = QUrl::fromLocalFile(scanFileInfo.absoluteDir().absolutePath()); addFileInDirectory(newFileUrl, currentDirectory); const auto &newTrack = scanOneFile(newFileUrl); if (newTrack.isValid()) { newFiles.push_back(newTrack); if (newFiles.size() > 500 && d->mStopRequest == 0) { emitNewFiles(newFiles); newFiles.clear(); } } } if (!newFiles.isEmpty() && d->mStopRequest == 0) { emitNewFiles(newFiles); } checkFilesToRemove(); Q_EMIT indexingFinished(); } MusicAudioTrack LocalBalooFileListing::scanOneFile(const QUrl &scanFile) { auto newTrack = MusicAudioTrack(); auto localFileName = scanFile.toLocalFile(); auto scanFileInfo = QFileInfo(localFileName); if (scanFileInfo.exists()) { watchPath(localFileName); } else { return newTrack; } auto itExistingFile = allFiles().find(scanFile); if (itExistingFile != allFiles().end()) { if (*itExistingFile >= scanFileInfo.fileTime(QFile::FileModificationTime)) { allFiles().erase(itExistingFile); return newTrack; } } Baloo::File match(localFileName); match.load(); newTrack.setFileModificationTime(scanFileInfo.fileTime(QFile::FileModificationTime)); newTrack.setResourceURI(scanFile); fileScanner().scanProperties(match, newTrack); if (!newTrack.isValid()) { newTrack = AbstractFileListing::scanOneFile(scanFile); } if (newTrack.isValid()) { AbstractFileListing::addCover(newTrack); } return newTrack; } bool LocalBalooFileListing::checkBalooConfiguration() { bool problemDetected = false; Baloo::IndexerConfig balooConfiguration; problemDetected = problemDetected || !balooConfiguration.fileIndexingEnabled(); problemDetected = problemDetected || balooConfiguration.onlyBasicIndexing(); if (problemDetected) { NotificationItem balooInvalidConfiguration; balooInvalidConfiguration.setNotificationId(QStringLiteral("balooInvalidConfiguration")); balooInvalidConfiguration.setTargetObject(this); balooInvalidConfiguration.setMessage(i18nc("Notification about unusable Baloo Configuration", "Baloo configuration does not allow to discover your music")); balooInvalidConfiguration.setMainButtonText(i18nc("Text of button to modify Baloo Configuration", "Modify it")); balooInvalidConfiguration.setMainButtonIconName(QStringLiteral("configure")); balooInvalidConfiguration.setMainButtonMethodName(QStringLiteral("fixBalooConfiguration")); balooInvalidConfiguration.setSecondaryButtonText(i18nc("Text of button to disable Baloo indexer", "Disable Baloo support")); balooInvalidConfiguration.setSecondaryButtonIconName(QStringLiteral("configure")); balooInvalidConfiguration.setSecondaryButtonMethodName(QStringLiteral("disableBalooIndexer")); Q_EMIT newNotification(balooInvalidConfiguration); } else { Q_EMIT closeNotification(QStringLiteral("balooInvalidConfiguration")); } return !problemDetected; } void LocalBalooFileListing::fixBalooConfiguration() { qDebug() << "LocalBalooFileListing::fixBalooConfiguration"; Baloo::IndexerConfig balooConfiguration; if (!balooConfiguration.fileIndexingEnabled()) { balooConfiguration.setFileIndexingEnabled(true); } if (balooConfiguration.onlyBasicIndexing()) { balooConfiguration.setOnlyBasicIndexing(false); } balooConfiguration.refresh(); if (checkBalooConfiguration()) { triggerRefreshOfContent(); } } void LocalBalooFileListing::disableBalooIndexer() { Elisa::ElisaConfiguration::self()->setBalooIndexer(false); Elisa::ElisaConfiguration::self()->save(); } #include "moc_localbaloofilelisting.cpp" diff --git a/src/baloo/localbaloofilelisting.h b/src/baloo/localbaloofilelisting.h index fd9ea578..f8372c07 100644 --- a/src/baloo/localbaloofilelisting.h +++ b/src/baloo/localbaloofilelisting.h @@ -1,88 +1,86 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef LOCALBALOOFILELISTING_H #define LOCALBALOOFILELISTING_H #include "../abstractfile/abstractfilelisting.h" #include #include #include #include #include #include class LocalBalooFileListingPrivate; class MusicAudioTrack; class QDBusPendingCallWatcher; class LocalBalooFileListing : public AbstractFileListing { Q_OBJECT public: explicit LocalBalooFileListing(QObject *parent = nullptr); ~LocalBalooFileListing() override; void applicationAboutToQuit() override; Q_SIGNALS: public Q_SLOTS: void renamedFiles(const QString &from, const QString &to, const QStringList &listFiles); void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner); void serviceRegistered(const QString &serviceName); void serviceUnregistered(const QString &serviceName); void fixBalooConfiguration(); void disableBalooIndexer(); private Q_SLOTS: void newBalooFile(const QString &fileName); void registeredToBaloo(QDBusPendingCallWatcher *watcher); private: void registerToBaloo(); void executeInit(QHash allFiles) override; void triggerRefreshOfContent() override; MusicAudioTrack scanOneFile(const QUrl &scanFile) override; bool checkBalooConfiguration(); std::unique_ptr d; }; #endif // LOCALBALOOFILELISTING_H diff --git a/src/databaseinterface.cpp b/src/databaseinterface.cpp index 5cdf775a..e3dce781 100644 --- a/src/databaseinterface.cpp +++ b/src/databaseinterface.cpp @@ -1,4977 +1,4975 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "databaseinterface.h" #include #include #include #include #include #include #include #include #include #include #include class DatabaseInterfacePrivate { public: DatabaseInterfacePrivate(const QSqlDatabase &tracksDatabase) : mTracksDatabase(tracksDatabase), mSelectAlbumQuery(mTracksDatabase), mSelectTrackQuery(mTracksDatabase), mSelectAlbumIdFromTitleQuery(mTracksDatabase), mInsertAlbumQuery(mTracksDatabase), mSelectTrackIdFromTitleAlbumIdArtistQuery(mTracksDatabase), mInsertTrackQuery(mTracksDatabase), mSelectAlbumTrackCountQuery(mTracksDatabase), mUpdateAlbumQuery(mTracksDatabase), mSelectTracksFromArtist(mTracksDatabase), mSelectTrackFromIdQuery(mTracksDatabase), mSelectCountAlbumsForArtistQuery(mTracksDatabase), mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery(mTracksDatabase), mSelectAllAlbumsQuery(mTracksDatabase), mSelectAllAlbumsFromArtistQuery(mTracksDatabase), mSelectAllArtistsQuery(mTracksDatabase), mInsertArtistsQuery(mTracksDatabase), mSelectArtistByNameQuery(mTracksDatabase), mSelectArtistQuery(mTracksDatabase), mSelectTrackFromFilePathQuery(mTracksDatabase), mRemoveTrackQuery(mTracksDatabase), mRemoveAlbumQuery(mTracksDatabase), mRemoveArtistQuery(mTracksDatabase), mSelectAllTracksQuery(mTracksDatabase), mInsertTrackMapping(mTracksDatabase), mSelectAllTracksFromSourceQuery(mTracksDatabase), mInsertMusicSource(mTracksDatabase), mSelectMusicSource(mTracksDatabase), mUpdateIsSingleDiscAlbumFromIdQuery(mTracksDatabase), mUpdateTrackMapping(mTracksDatabase), mSelectTracksMapping(mTracksDatabase), mSelectTracksMappingPriority(mTracksDatabase), mUpdateAlbumArtUriFromAlbumIdQuery(mTracksDatabase), mSelectTracksMappingPriorityByTrackId(mTracksDatabase), mSelectAllTrackFilesFromSourceQuery(mTracksDatabase), mSelectAlbumIdsFromArtist(mTracksDatabase), mRemoveTracksMappingFromSource(mTracksDatabase), mRemoveTracksMapping(mTracksDatabase), mSelectTracksWithoutMappingQuery(mTracksDatabase), mSelectAlbumIdFromTitleAndArtistQuery(mTracksDatabase), mSelectAlbumIdFromTitleWithoutArtistQuery(mTracksDatabase), mInsertAlbumArtistQuery(mTracksDatabase), mInsertTrackArtistQuery(mTracksDatabase), mRemoveTrackArtistQuery(mTracksDatabase), mRemoveAlbumArtistQuery(mTracksDatabase), mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery(mTracksDatabase), mSelectAlbumArtUriFromAlbumIdQuery(mTracksDatabase), mInsertComposerQuery(mTracksDatabase), mSelectComposerByNameQuery(mTracksDatabase), mSelectComposerQuery(mTracksDatabase), mInsertLyricistQuery(mTracksDatabase), mSelectLyricistByNameQuery(mTracksDatabase), mSelectLyricistQuery(mTracksDatabase), mInsertGenreQuery(mTracksDatabase), mSelectGenreByNameQuery(mTracksDatabase), mSelectGenreQuery(mTracksDatabase), mSelectAllTracksShortQuery(mTracksDatabase), mSelectAllAlbumsShortQuery(mTracksDatabase), mSelectAllComposersQuery(mTracksDatabase), mSelectAllLyricistsQuery(mTracksDatabase), mSelectCountAlbumsForComposerQuery(mTracksDatabase), mSelectCountAlbumsForLyricistQuery(mTracksDatabase), mSelectAllGenresQuery(mTracksDatabase), mSelectGenreForArtistQuery(mTracksDatabase), mSelectGenreForAlbumQuery(mTracksDatabase), mUpdateTrackQuery(mTracksDatabase) { } QSqlDatabase mTracksDatabase; QSqlQuery mSelectAlbumQuery; QSqlQuery mSelectTrackQuery; QSqlQuery mSelectAlbumIdFromTitleQuery; QSqlQuery mInsertAlbumQuery; QSqlQuery mSelectTrackIdFromTitleAlbumIdArtistQuery; QSqlQuery mInsertTrackQuery; QSqlQuery mSelectAlbumTrackCountQuery; QSqlQuery mUpdateAlbumQuery; QSqlQuery mSelectTracksFromArtist; QSqlQuery mSelectTrackFromIdQuery; QSqlQuery mSelectCountAlbumsForArtistQuery; QSqlQuery mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery; QSqlQuery mSelectAllAlbumsQuery; QSqlQuery mSelectAllAlbumsFromArtistQuery; QSqlQuery mSelectAllArtistsQuery; QSqlQuery mInsertArtistsQuery; QSqlQuery mSelectArtistByNameQuery; QSqlQuery mSelectArtistQuery; QSqlQuery mSelectTrackFromFilePathQuery; QSqlQuery mRemoveTrackQuery; QSqlQuery mRemoveAlbumQuery; QSqlQuery mRemoveArtistQuery; QSqlQuery mSelectAllTracksQuery; QSqlQuery mInsertTrackMapping; QSqlQuery mSelectAllTracksFromSourceQuery; QSqlQuery mInsertMusicSource; QSqlQuery mSelectMusicSource; QSqlQuery mUpdateIsSingleDiscAlbumFromIdQuery; QSqlQuery mUpdateTrackMapping; QSqlQuery mSelectTracksMapping; QSqlQuery mSelectTracksMappingPriority; QSqlQuery mUpdateAlbumArtUriFromAlbumIdQuery; QSqlQuery mSelectTracksMappingPriorityByTrackId; QSqlQuery mSelectAllTrackFilesFromSourceQuery; QSqlQuery mSelectAlbumIdsFromArtist; QSqlQuery mRemoveTracksMappingFromSource; QSqlQuery mRemoveTracksMapping; QSqlQuery mSelectTracksWithoutMappingQuery; QSqlQuery mSelectAlbumIdFromTitleAndArtistQuery; QSqlQuery mSelectAlbumIdFromTitleWithoutArtistQuery; QSqlQuery mInsertAlbumArtistQuery; QSqlQuery mInsertTrackArtistQuery; QSqlQuery mRemoveTrackArtistQuery; QSqlQuery mRemoveAlbumArtistQuery; QSqlQuery mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery; QSqlQuery mSelectAlbumArtUriFromAlbumIdQuery; QSqlQuery mInsertComposerQuery; QSqlQuery mSelectComposerByNameQuery; QSqlQuery mSelectComposerQuery; QSqlQuery mInsertLyricistQuery; QSqlQuery mSelectLyricistByNameQuery; QSqlQuery mSelectLyricistQuery; QSqlQuery mInsertGenreQuery; QSqlQuery mSelectGenreByNameQuery; QSqlQuery mSelectGenreQuery; QSqlQuery mSelectAllTracksShortQuery; QSqlQuery mSelectAllAlbumsShortQuery; QSqlQuery mSelectAllComposersQuery; QSqlQuery mSelectAllLyricistsQuery; QSqlQuery mSelectCountAlbumsForComposerQuery; QSqlQuery mSelectCountAlbumsForLyricistQuery; QSqlQuery mSelectAllGenresQuery; QSqlQuery mSelectGenreForArtistQuery; QSqlQuery mSelectGenreForAlbumQuery; QSqlQuery mUpdateTrackQuery; qulonglong mAlbumId = 1; qulonglong mArtistId = 1; qulonglong mComposerId = 1; qulonglong mLyricistId = 1; qulonglong mGenreId = 1; qulonglong mTrackId = 1; qulonglong mDiscoverId = 1; QAtomicInt mStopRequest = 0; bool mInitFinished = false; }; DatabaseInterface::DatabaseInterface(QObject *parent) : QObject(parent), d(nullptr) { } DatabaseInterface::~DatabaseInterface() { if (d) { d->mTracksDatabase.close(); } } void DatabaseInterface::init(const QString &dbName, const QString &databaseFileName) { QSqlDatabase tracksDatabase = QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"), dbName); if (!databaseFileName.isEmpty()) { tracksDatabase.setDatabaseName(QStringLiteral("file:") + databaseFileName); } else { tracksDatabase.setDatabaseName(QStringLiteral("file:memdb1?mode=memory")); } tracksDatabase.setConnectOptions(QStringLiteral("foreign_keys = ON;locking_mode = EXCLUSIVE;QSQLITE_OPEN_URI;QSQLITE_BUSY_TIMEOUT=500000")); auto result = tracksDatabase.open(); if (result) { qDebug() << "database open"; } else { qDebug() << "database not open"; } qDebug() << "DatabaseInterface::init" << (tracksDatabase.driver()->hasFeature(QSqlDriver::Transactions) ? "yes" : "no"); tracksDatabase.exec(QStringLiteral("PRAGMA foreign_keys = ON;")); d = std::make_unique(tracksDatabase); initDatabase(); initRequest(); if (!databaseFileName.isEmpty()) { reloadExistingDatabase(); } } MusicAlbum DatabaseInterface::albumFromTitleAndArtist(const QString &title, const QString &artist) { auto result = MusicAlbum(); auto transactionResult = startTransaction(); if (!transactionResult) { return result; } result = internalAlbumFromTitleAndArtist(title, artist); transactionResult = finishTransaction(); if (!transactionResult) { return result; } return result; } QList> DatabaseInterface::allData(DataUtils::DataType aType) { auto result = QList>{}; auto transactionResult = startTransaction(); if (!transactionResult) { return result; } switch (aType) { case DataUtils::DataType::AllArtists: result = internalAllArtistsPartialData(); break; case DataUtils::DataType::AllAlbums: result = internalAllAlbumsPartialData(); break; case DataUtils::DataType::AllTracks: result = internalAllTracksPartialData(); break; case DataUtils::DataType::AllGenres: result = internalAllGenresPartialData(); break; case DataUtils::DataType::AllComposers: result = internalAllComposersPartialData(); break; case DataUtils::DataType::AllLyricists: result = internalAllLyricistsPartialData(); break; case DataUtils::DataType::UnknownType: break; }; transactionResult = finishTransaction(); if (!transactionResult) { return result; } return result; } QList DatabaseInterface::allTracks() { auto result = QList(); if (!d) { return result; } auto transactionResult = startTransaction(); if (!transactionResult) { return result; } auto queryResult = d->mSelectAllTracksQuery.exec(); if (!queryResult || !d->mSelectAllTracksQuery.isSelect() || !d->mSelectAllTracksQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::allAlbums" << d->mSelectAllTracksQuery.lastQuery(); qDebug() << "DatabaseInterface::allAlbums" << d->mSelectAllTracksQuery.boundValues(); qDebug() << "DatabaseInterface::allAlbums" << d->mSelectAllTracksQuery.lastError(); return result; } while(d->mSelectAllTracksQuery.next()) { const auto ¤tRecord = d->mSelectAllTracksQuery.record(); result.push_back(buildTrackFromDatabaseRecord(currentRecord)); } d->mSelectAllTracksQuery.finish(); transactionResult = finishTransaction(); if (!transactionResult) { return result; } return result; } QList DatabaseInterface::allTracksFromSource(const QString &musicSource) { auto result = QList(); if (!d) { return result; } auto transactionResult = startTransaction(); if (!transactionResult) { return result; } d->mSelectAllTracksFromSourceQuery.bindValue(QStringLiteral(":source"), musicSource); auto queryResult = d->mSelectAllTracksFromSourceQuery.exec(); if (!queryResult || !d->mSelectAllTracksFromSourceQuery.isSelect() || !d->mSelectAllTracksFromSourceQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::allAlbums" << d->mSelectAllTracksFromSourceQuery.lastQuery(); qDebug() << "DatabaseInterface::allAlbums" << d->mSelectAllTracksFromSourceQuery.boundValues(); qDebug() << "DatabaseInterface::allAlbums" << d->mSelectAllTracksFromSourceQuery.lastError(); d->mSelectAllTracksFromSourceQuery.finish(); transactionResult = finishTransaction(); if (!transactionResult) { return result; } return result; } while(d->mSelectAllTracksFromSourceQuery.next()) { const auto ¤tRecord = d->mSelectAllTracksFromSourceQuery.record(); result.push_back(buildTrackFromDatabaseRecord(currentRecord)); } d->mSelectAllTracksFromSourceQuery.finish(); transactionResult = finishTransaction(); if (!transactionResult) { return result; } return result; } QList DatabaseInterface::allAlbums() { auto result = QList(); if (!d) { return result; } auto transactionResult = startTransaction(); if (!transactionResult) { return result; } auto queryResult = d->mSelectAllAlbumsQuery.exec(); if (!queryResult || !d->mSelectAllAlbumsQuery.isSelect() || !d->mSelectAllAlbumsQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::allAlbums" << d->mSelectAllAlbumsQuery.lastQuery(); qDebug() << "DatabaseInterface::allAlbums" << d->mSelectAllAlbumsQuery.boundValues(); qDebug() << "DatabaseInterface::allAlbums" << d->mSelectAllAlbumsQuery.lastError(); return result; } while(d->mSelectAllAlbumsQuery.next()) { auto newAlbum = MusicAlbum(); const auto ¤tRecord = d->mSelectAllAlbumsQuery.record(); newAlbum.setDatabaseId(currentRecord.value(0).toULongLong()); newAlbum.setTitle(currentRecord.value(1).toString()); newAlbum.setId(currentRecord.value(2).toString()); newAlbum.setArtist(currentRecord.value(3).toString()); newAlbum.setAlbumPath(currentRecord.value(4).toUrl()); newAlbum.setAlbumArtURI(currentRecord.value(5).toUrl()); newAlbum.setTracksCount(currentRecord.value(6).toInt()); newAlbum.setIsSingleDiscAlbum(currentRecord.value(7).toBool()); newAlbum.setTracks(fetchTracks(newAlbum.databaseId())); newAlbum.setValid(true); d->mSelectGenreForAlbumQuery.bindValue(QStringLiteral(":albumId"), newAlbum.databaseId()); queryResult = d->mSelectGenreForAlbumQuery.exec(); if (!queryResult || !d->mSelectGenreForAlbumQuery.isSelect() || !d->mSelectGenreForAlbumQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::internalAlbumFromId" << d->mSelectGenreForAlbumQuery.lastQuery(); qDebug() << "DatabaseInterface::internalAlbumFromId" << d->mSelectGenreForAlbumQuery.boundValues(); qDebug() << "DatabaseInterface::internalAlbumFromId" << d->mSelectGenreForAlbumQuery.lastError(); d->mSelectGenreForAlbumQuery.finish(); return result; } QStringList allGenres; while(d->mSelectGenreForAlbumQuery.next()) { allGenres.push_back(d->mSelectGenreForAlbumQuery.record().value(0).toString()); } newAlbum.setGenres(allGenres); d->mSelectGenreForAlbumQuery.finish(); result.push_back(newAlbum); } d->mSelectAllAlbumsQuery.finish(); transactionResult = finishTransaction(); if (!transactionResult) { return result; } return result; } QList DatabaseInterface::allArtists() { auto result = QList{}; if (!d) { return result; } result = internalAllPeople(d->mSelectAllArtistsQuery, d->mSelectCountAlbumsForArtistQuery); return result; } QList DatabaseInterface::allGenres() { auto result = QList(); if (!d) { return result; } auto transactionResult = startTransaction(); if (!transactionResult) { return result; } auto queryResult = d->mSelectAllGenresQuery.exec(); if (!queryResult || !d->mSelectAllGenresQuery.isSelect() || !d->mSelectAllGenresQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::allAlbums" << d->mSelectAllGenresQuery.lastQuery(); qDebug() << "DatabaseInterface::allAlbums" << d->mSelectAllGenresQuery.boundValues(); qDebug() << "DatabaseInterface::allAlbums" << d->mSelectAllGenresQuery.lastError(); return result; } while(d->mSelectAllGenresQuery.next()) { auto newGenre = MusicAudioGenre(); const auto ¤tRecord = d->mSelectAllGenresQuery.record(); newGenre.setDatabaseId(currentRecord.value(0).toULongLong()); newGenre.setName(currentRecord.value(1).toString()); result.push_back(newGenre); } d->mSelectAllGenresQuery.finish(); transactionResult = finishTransaction(); if (!transactionResult) { return result; } return result; } QList DatabaseInterface::allComposers() { return internalAllPeople(d->mSelectAllComposersQuery, d->mSelectCountAlbumsForComposerQuery); } QList DatabaseInterface::allLyricists() { return internalAllPeople(d->mSelectAllLyricistsQuery, d->mSelectCountAlbumsForLyricistQuery); } QList DatabaseInterface::tracksFromAuthor(const QString &artistName) { auto allTracks = QList(); auto transactionResult = startTransaction(); if (!transactionResult) { return allTracks; } allTracks = internalTracksFromAuthor(artistName); transactionResult = finishTransaction(); if (!transactionResult) { return allTracks; } return allTracks; } MusicArtist DatabaseInterface::internalArtistFromId(qulonglong artistId) { auto result = MusicArtist(); if (!d || !d->mTracksDatabase.isValid() || !d->mInitFinished) { return result; } d->mSelectArtistQuery.bindValue(QStringLiteral(":artistId"), artistId); auto queryResult = d->mSelectArtistQuery.exec(); if (!queryResult || !d->mSelectArtistQuery.isSelect() || !d->mSelectArtistQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::internalArtistFromId" << d->mSelectArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::internalArtistFromId" << d->mSelectArtistQuery.boundValues(); qDebug() << "DatabaseInterface::internalArtistFromId" << d->mSelectArtistQuery.lastError(); d->mSelectArtistQuery.finish(); return result; } if (!d->mSelectArtistQuery.next()) { d->mSelectArtistQuery.finish(); return result; } const auto ¤tRecord = d->mSelectArtistQuery.record(); result.setDatabaseId(currentRecord.value(0).toULongLong()); result.setName(currentRecord.value(1).toString()); result.setValid(true); d->mSelectArtistQuery.finish(); d->mSelectCountAlbumsForArtistQuery.bindValue(QStringLiteral(":artistName"), result.name()); queryResult = d->mSelectCountAlbumsForArtistQuery.exec(); if (!queryResult || !d->mSelectCountAlbumsForArtistQuery.isSelect() || !d->mSelectCountAlbumsForArtistQuery.isActive() || !d->mSelectCountAlbumsForArtistQuery.next()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::internalArtistFromId" << d->mSelectCountAlbumsForArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::internalArtistFromId" << d->mSelectCountAlbumsForArtistQuery.boundValues(); qDebug() << "DatabaseInterface::internalArtistFromId" << d->mSelectCountAlbumsForArtistQuery.lastError(); d->mSelectCountAlbumsForArtistQuery.finish(); return result; } result.setAlbumsCount(d->mSelectCountAlbumsForArtistQuery.record().value(0).toInt()); d->mSelectCountAlbumsForArtistQuery.finish(); return result; } MusicAudioTrack DatabaseInterface::trackFromDatabaseId(qulonglong id) { auto result = MusicAudioTrack(); if (!d) { return result; } auto transactionResult = startTransaction(); if (!transactionResult) { return result; } result = internalTrackFromDatabaseId(id); transactionResult = finishTransaction(); if (!transactionResult) { return result; } return result; } qulonglong DatabaseInterface::trackIdFromTitleAlbumTrackDiscNumber(const QString &title, const QString &artist, const QString &album, int trackNumber, int discNumber) { auto result = qulonglong(0); if (!d) { return result; } auto transactionResult = startTransaction(); if (!transactionResult) { return result; } result = internalTrackIdFromTitleAlbumTracDiscNumber(title, artist, album, trackNumber, discNumber); transactionResult = finishTransaction(); if (!transactionResult) { return result; } return result; } qulonglong DatabaseInterface::trackIdFromFileName(const QUrl &fileName) { auto result = qulonglong(0); if (!d) { return result; } auto transactionResult = startTransaction(); if (!transactionResult) { return result; } result = internalTrackIdFromFileName(fileName); transactionResult = finishTransaction(); if (!transactionResult) { return result; } return result; } void DatabaseInterface::applicationAboutToQuit() { d->mStopRequest = 1; } void DatabaseInterface::removeAllTracksFromSource(const QString &sourceName) { auto transactionResult = startTransaction(); if (!transactionResult) { return; } QList newArtistsIds; auto sourceId = internalSourceIdFromName(sourceName); auto allFileNames = internalAllFileNameFromSource(sourceId); internalRemoveTracksList(allFileNames, sourceId, newArtistsIds); if (!newArtistsIds.isEmpty()) { QList newArtists; for (auto artistId : qAsConst(newArtistsIds)) { newArtists.push_back(internalArtistFromId(artistId)); } Q_EMIT artistsAdded(newArtists); } transactionResult = finishTransaction(); if (!transactionResult) { return; } } void DatabaseInterface::getAlbumFromAlbumId(qulonglong id) { auto result = MusicAlbum(); auto transactionResult = startTransaction(); if (!transactionResult) { Q_EMIT sentAlbumData(result); } result = internalAlbumFromId(id); transactionResult = finishTransaction(); if (!transactionResult) { Q_EMIT sentAlbumData(result); } Q_EMIT sentAlbumData(result); } void DatabaseInterface::askRestoredTracks(const QString &musicSource) { auto transactionResult = startTransaction(); if (!transactionResult) { return; } auto result = internalAllFileNameFromSource(internalSourceIdFromName(musicSource)); Q_EMIT restoredTracks(musicSource, result); transactionResult = finishTransaction(); if (!transactionResult) { return; } } void DatabaseInterface::insertTracksList(const QList &tracks, const QHash &covers, const QString &musicSource) { if (d->mStopRequest == 1) { return; } auto transactionResult = startTransaction(); if (!transactionResult) { return; } QSet modifiedAlbumIds; QSet modifiedTrackIds; QList insertedTracks; QList insertedAlbums; QList insertedArtists; for(const auto &oneTrack : tracks) { d->mSelectTracksMapping.bindValue(QStringLiteral(":fileName"), oneTrack.resourceURI()); auto result = d->mSelectTracksMapping.exec(); if (!result || !d->mSelectTracksMapping.isSelect() || !d->mSelectTracksMapping.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertTracksList" << d->mSelectTracksMapping.lastQuery(); qDebug() << "DatabaseInterface::insertTracksList" << d->mSelectTracksMapping.boundValues(); qDebug() << "DatabaseInterface::insertTracksList" << d->mSelectTracksMapping.lastError(); d->mSelectTracksMapping.finish(); rollBackTransaction(); return; } bool isNewTrack = !d->mSelectTracksMapping.next(); if (isNewTrack) { insertTrackOrigin(oneTrack.resourceURI(), oneTrack.fileModificationTime(), insertMusicSource(musicSource)); } else { updateTrackOrigin(d->mSelectTracksMapping.record().value(0).toULongLong(), oneTrack.resourceURI(), oneTrack.fileModificationTime()); } d->mSelectTracksMapping.finish(); const auto insertedTrackId = internalInsertTrack(oneTrack, covers, 0, modifiedAlbumIds, (isNewTrack ? TrackFileInsertType::NewTrackFileInsert : TrackFileInsertType::ModifiedTrackFileInsert), insertedAlbums, insertedArtists, modifiedTrackIds); if (isNewTrack && insertedTrackId != 0) { insertedTracks.push_back(insertedTrackId); } if (d->mStopRequest == 1) { transactionResult = finishTransaction(); if (!transactionResult) { return; } return; } } if (!insertedArtists.isEmpty()) { QList newArtists; for (auto artistId : qAsConst(insertedArtists)) { newArtists.push_back(internalArtistFromId(artistId)); } Q_EMIT artistsAdded(newArtists); } QList newAlbums; for (auto albumId : qAsConst(insertedAlbums)) { modifiedAlbumIds.remove(albumId); newAlbums.push_back(internalAlbumFromId(albumId)); } if (!newAlbums.isEmpty()) { Q_EMIT albumsAdded(newAlbums); } const auto &constModifiedAlbumIds = modifiedAlbumIds; for (auto albumId : constModifiedAlbumIds) { Q_EMIT albumModified(internalAlbumFromId(albumId), albumId); } for (auto trackId : qAsConst(modifiedTrackIds)) { Q_EMIT trackModified(internalTrackFromDatabaseId(trackId)); } QList newTracks; for (auto trackId : qAsConst(insertedTracks)) { newTracks.push_back(internalTrackFromDatabaseId(trackId)); } if (!newTracks.isEmpty()) { Q_EMIT tracksAdded(newTracks); } transactionResult = finishTransaction(); if (!transactionResult) { return; } } void DatabaseInterface::removeTracksList(const QList &removedTracks) { auto transactionResult = startTransaction(); if (!transactionResult) { return; } QList newArtistsIds; internalRemoveTracksList(removedTracks, newArtistsIds); if (!newArtistsIds.isEmpty()) { QList newArtists; for (auto artistId : qAsConst(newArtistsIds)) { newArtists.push_back(internalArtistFromId(artistId)); } Q_EMIT artistsAdded(newArtists); } transactionResult = finishTransaction(); if (!transactionResult) { return; } } void DatabaseInterface::modifyTracksList(const QList &modifiedTracks, const QHash &covers, const QString &musicSource) { auto transactionResult = startTransaction(); if (!transactionResult) { return; } QSet modifiedAlbumIds; QSet modifiedTrackIds; QList newAlbumIds; QList newArtistsIds; QList insertedTracks; for (const auto &oneModifiedTrack : modifiedTracks) { if (oneModifiedTrack.albumArtist().isEmpty()) { continue; } bool modifyExistingTrack = internalTrackFromDatabaseId(oneModifiedTrack.databaseId()).isValid() || (internalTrackIdFromFileName(oneModifiedTrack.resourceURI()) != 0); auto originTrackId = oneModifiedTrack.databaseId(); if (!originTrackId) { originTrackId = internalTrackIdFromFileName(oneModifiedTrack.resourceURI()); } if (!modifyExistingTrack) { insertTrackOrigin(oneModifiedTrack.resourceURI(), oneModifiedTrack.fileModificationTime(), insertMusicSource(musicSource)); } else { updateTrackOrigin(originTrackId, oneModifiedTrack.resourceURI(), oneModifiedTrack.fileModificationTime()); } const auto insertedTrackId = internalInsertTrack(oneModifiedTrack, covers, (modifyExistingTrack ? originTrackId : 0), modifiedAlbumIds, (modifyExistingTrack ? TrackFileInsertType::ModifiedTrackFileInsert : TrackFileInsertType::NewTrackFileInsert), newAlbumIds, newArtistsIds, modifiedTrackIds); if (!modifyExistingTrack && insertedTrackId != 0) { insertedTracks.push_back(insertedTrackId); } } QList newAlbums; for (auto albumId : qAsConst(newAlbumIds)) { modifiedAlbumIds.remove(albumId); newAlbums.push_back(internalAlbumFromId(albumId)); } if (!newAlbums.isEmpty()) { Q_EMIT albumsAdded(newAlbums); } for (auto albumId : qAsConst(modifiedAlbumIds)) { Q_EMIT albumModified(internalAlbumFromId(albumId), albumId); } for (auto trackId : qAsConst(modifiedTrackIds)) { Q_EMIT trackModified(internalTrackFromDatabaseId(trackId)); } QList newTracks; for (auto trackId : qAsConst(insertedTracks)) { newTracks.push_back(internalTrackFromDatabaseId(trackId)); } if (!newTracks.isEmpty()) { Q_EMIT tracksAdded(newTracks); } transactionResult = finishTransaction(); if (!transactionResult) { return; } } bool DatabaseInterface::startTransaction() const { auto result = false; auto transactionResult = d->mTracksDatabase.transaction(); if (!transactionResult) { qDebug() << "transaction failed" << d->mTracksDatabase.lastError() << d->mTracksDatabase.lastError().driverText(); return result; } result = true; return result; } bool DatabaseInterface::finishTransaction() const { auto result = false; auto transactionResult = d->mTracksDatabase.commit(); if (!transactionResult) { qDebug() << "commit failed" << d->mTracksDatabase.lastError() << d->mTracksDatabase.lastError().nativeErrorCode(); return result; } result = true; return result; } bool DatabaseInterface::rollBackTransaction() const { auto result = false; auto transactionResult = d->mTracksDatabase.rollback(); if (!transactionResult) { qDebug() << "commit failed" << d->mTracksDatabase.lastError() << d->mTracksDatabase.lastError().nativeErrorCode(); return result; } result = true; return result; } void DatabaseInterface::initDatabase() { auto transactionResult = startTransaction(); if (!transactionResult) { return; } auto listTables = d->mTracksDatabase.tables(); if (!listTables.contains(QStringLiteral("DatabaseVersionV5"))) { auto oldTables = QStringList{QStringLiteral("DatabaseVersionV2"), QStringLiteral("DatabaseVersionV3"), QStringLiteral("DatabaseVersionV4"), QStringLiteral("AlbumsArtists"), QStringLiteral("TracksArtists"), QStringLiteral("TracksMapping"), QStringLiteral("Tracks"), QStringLiteral("Composer"), QStringLiteral("Genre"), QStringLiteral("Lyricist"), QStringLiteral("Albums"), QStringLiteral("DiscoverSource"), QStringLiteral("Artists"),}; for (const auto &oneTable : oldTables) { if (listTables.indexOf(oneTable) == -1) { continue; } QSqlQuery createSchemaQuery(d->mTracksDatabase); auto result = createSchemaQuery.exec(QStringLiteral("DROP TABLE ") + oneTable); if (!result) { qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastQuery(); qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastError(); Q_EMIT databaseError(); } } listTables = d->mTracksDatabase.tables(); } if (!listTables.contains(QStringLiteral("DatabaseVersionV5"))) { QSqlQuery createSchemaQuery(d->mTracksDatabase); const auto &result = createSchemaQuery.exec(QStringLiteral("CREATE TABLE `DatabaseVersionV5` (`Version` INTEGER PRIMARY KEY NOT NULL)")); if (!result) { qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastQuery(); qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastError(); Q_EMIT databaseError(); } } if (!listTables.contains(QStringLiteral("DiscoverSource"))) { QSqlQuery createSchemaQuery(d->mTracksDatabase); const auto &result = createSchemaQuery.exec(QStringLiteral("CREATE TABLE `DiscoverSource` (`ID` INTEGER PRIMARY KEY NOT NULL, " "`Name` VARCHAR(55) NOT NULL, " "UNIQUE (`Name`))")); if (!result) { qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastQuery(); qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastError(); Q_EMIT databaseError(); } } if (!listTables.contains(QStringLiteral("Artists"))) { QSqlQuery createSchemaQuery(d->mTracksDatabase); const auto &result = createSchemaQuery.exec(QStringLiteral("CREATE TABLE `Artists` (`ID` INTEGER PRIMARY KEY NOT NULL, " "`Name` VARCHAR(55) NOT NULL, " "UNIQUE (`Name`))")); if (!result) { qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastQuery(); qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastError(); Q_EMIT databaseError(); } } if (!listTables.contains(QStringLiteral("Composer"))) { QSqlQuery createSchemaQuery(d->mTracksDatabase); const auto &result = createSchemaQuery.exec(QStringLiteral("CREATE TABLE `Composer` (`ID` INTEGER PRIMARY KEY NOT NULL, " "`Name` VARCHAR(55) NOT NULL, " "UNIQUE (`Name`))")); if (!result) { qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastQuery(); qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastError(); Q_EMIT databaseError(); } } if (!listTables.contains(QStringLiteral("Genre"))) { QSqlQuery createSchemaQuery(d->mTracksDatabase); const auto &result = createSchemaQuery.exec(QStringLiteral("CREATE TABLE `Genre` (`ID` INTEGER PRIMARY KEY NOT NULL, " "`Name` VARCHAR(85) NOT NULL, " "UNIQUE (`Name`))")); if (!result) { qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastQuery(); qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastError(); Q_EMIT databaseError(); } } if (!listTables.contains(QStringLiteral("Lyricist"))) { QSqlQuery createSchemaQuery(d->mTracksDatabase); const auto &result = createSchemaQuery.exec(QStringLiteral("CREATE TABLE `Lyricist` (`ID` INTEGER PRIMARY KEY NOT NULL, " "`Name` VARCHAR(55) NOT NULL, " "UNIQUE (`Name`))")); if (!result) { qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastQuery(); qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastError(); Q_EMIT databaseError(); } } if (!listTables.contains(QStringLiteral("Albums"))) { QSqlQuery createSchemaQuery(d->mTracksDatabase); const auto &result = createSchemaQuery.exec(QStringLiteral("CREATE TABLE `Albums` (" "`ID` INTEGER PRIMARY KEY NOT NULL, " "`Title` VARCHAR(55) NOT NULL, " "`AlbumPath` VARCHAR(255) NOT NULL, " "`CoverFileName` VARCHAR(255) NOT NULL, " "`TracksCount` INTEGER NOT NULL, " "`IsSingleDiscAlbum` BOOLEAN NOT NULL, " "`AlbumInternalID` VARCHAR(55))")); if (!result) { qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastQuery(); qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastError(); } } if (!listTables.contains(QStringLiteral("AlbumsArtists"))) { QSqlQuery createSchemaQuery(d->mTracksDatabase); const auto &result = createSchemaQuery.exec(QStringLiteral("CREATE TABLE `AlbumsArtists` (" "`AlbumID` INTEGER NOT NULL, " "`ArtistID` INTEGER NOT NULL, " "CONSTRAINT pk_albumsartists PRIMARY KEY (`AlbumID`, `ArtistID`), " "CONSTRAINT fk_albums FOREIGN KEY (`AlbumID`) REFERENCES `Albums`(`ID`) " "ON DELETE CASCADE, " "CONSTRAINT fk_artists FOREIGN KEY (`ArtistID`) REFERENCES `Artists`(`ID`) " "ON DELETE CASCADE)")); if (!result) { qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastQuery(); qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastError(); Q_EMIT databaseError(); } } if (!listTables.contains(QStringLiteral("Tracks"))) { QSqlQuery createSchemaQuery(d->mTracksDatabase); const auto &result = createSchemaQuery.exec(QStringLiteral("CREATE TABLE `Tracks` (" "`ID` INTEGER PRIMARY KEY NOT NULL, " "`Title` VARCHAR(85) NOT NULL, " "`AlbumID` INTEGER NOT NULL, " "`TrackNumber` INTEGER NOT NULL, " "`DiscNumber` INTEGER DEFAULT -1, " "`Duration` INTEGER NOT NULL, " "`Rating` INTEGER NOT NULL DEFAULT 0, " "`GenreID` INTEGER DEFAULT -1, " "`ComposerID` INTEGER, " "`LyricistID` INTEGER, " "`Comment` VARCHAR(85) DEFAULT '', " "`Year` INTEGER DEFAULT 0, " "`Channels` INTEGER DEFAULT -1, " "`BitRate` INTEGER DEFAULT -1, " "`SampleRate` INTEGER DEFAULT -1, " "UNIQUE (`Title`, `AlbumID`, `TrackNumber`, `DiscNumber`), " "CONSTRAINT fk_tracks_composer FOREIGN KEY (`ComposerID`) REFERENCES `Composer`(`ID`), " "CONSTRAINT fk_tracks_lyricist FOREIGN KEY (`LyricistID`) REFERENCES `Lyricist`(`ID`), " "CONSTRAINT fk_tracks_genre FOREIGN KEY (`GenreID`) REFERENCES `Genre`(`ID`), " "CONSTRAINT fk_tracks_album FOREIGN KEY (`AlbumID`) REFERENCES `Albums`(`ID`))")); if (!result) { qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastQuery(); qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastError(); Q_EMIT databaseError(); } } if (!listTables.contains(QStringLiteral("TracksArtists"))) { QSqlQuery createSchemaQuery(d->mTracksDatabase); const auto &result = createSchemaQuery.exec(QStringLiteral("CREATE TABLE `TracksArtists` (" "`TrackID` INTEGER NOT NULL, " "`ArtistID` INTEGER NOT NULL, " "CONSTRAINT pk_tracksartists PRIMARY KEY (`TrackID`, `ArtistID`), " "CONSTRAINT fk_tracks FOREIGN KEY (`TrackID`) REFERENCES `Tracks`(`ID`) " "ON DELETE CASCADE, " "CONSTRAINT fk_artists FOREIGN KEY (`ArtistID`) REFERENCES `Artists`(`ID`) " "ON DELETE CASCADE)")); if (!result) { qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastQuery(); qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastError(); Q_EMIT databaseError(); } } if (!listTables.contains(QStringLiteral("TracksMapping"))) { QSqlQuery createSchemaQuery(d->mTracksDatabase); const auto &result = createSchemaQuery.exec(QStringLiteral("CREATE TABLE `TracksMapping` (" "`TrackID` INTEGER NULL, " "`DiscoverID` INTEGER NOT NULL, " "`FileName` VARCHAR(255) NOT NULL, " "`Priority` INTEGER NOT NULL, " "`FileModifiedTime` DATETIME NOT NULL, " "PRIMARY KEY (`FileName`), " "CONSTRAINT TracksUnique UNIQUE (`TrackID`, `Priority`), " "CONSTRAINT fk_tracksmapping_trackID FOREIGN KEY (`TrackID`) REFERENCES `Tracks`(`ID`) ON DELETE CASCADE, " "CONSTRAINT fk_tracksmapping_discoverID FOREIGN KEY (`DiscoverID`) REFERENCES `DiscoverSource`(`ID`))")); if (!result) { qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastQuery(); qDebug() << "DatabaseInterface::initDatabase" << createSchemaQuery.lastError(); } } { QSqlQuery createTrackIndex(d->mTracksDatabase); const auto &result = createTrackIndex.exec(QStringLiteral("CREATE INDEX " "IF NOT EXISTS " "`TracksAlbumIndex` ON `Tracks` " "(`AlbumID`)")); if (!result) { qDebug() << "DatabaseInterface::initDatabase" << createTrackIndex.lastQuery(); qDebug() << "DatabaseInterface::initDatabase" << createTrackIndex.lastError(); Q_EMIT databaseError(); } } { QSqlQuery createTrackIndex(d->mTracksDatabase); const auto &result = createTrackIndex.exec(QStringLiteral("CREATE INDEX " "IF NOT EXISTS " "`AlbumsArtistsArtistIndex` ON `AlbumsArtists` " "(`ArtistID`)")); if (!result) { qDebug() << "DatabaseInterface::initDatabase" << createTrackIndex.lastQuery(); qDebug() << "DatabaseInterface::initDatabase" << createTrackIndex.lastError(); Q_EMIT databaseError(); } } { QSqlQuery createTrackIndex(d->mTracksDatabase); const auto &result = createTrackIndex.exec(QStringLiteral("CREATE INDEX " "IF NOT EXISTS " "`AlbumsArtistsAlbumIndex` ON `AlbumsArtists` " "(`AlbumID`)")); if (!result) { qDebug() << "DatabaseInterface::initDatabase" << createTrackIndex.lastQuery(); qDebug() << "DatabaseInterface::initDatabase" << createTrackIndex.lastError(); Q_EMIT databaseError(); } } { QSqlQuery createTrackIndex(d->mTracksDatabase); const auto &result = createTrackIndex.exec(QStringLiteral("CREATE INDEX " "IF NOT EXISTS " "`TracksArtistsArtistIndex` ON `TracksArtists` " "(`ArtistID`)")); if (!result) { qDebug() << "DatabaseInterface::initDatabase" << createTrackIndex.lastQuery(); qDebug() << "DatabaseInterface::initDatabase" << createTrackIndex.lastError(); Q_EMIT databaseError(); } } { QSqlQuery createTrackIndex(d->mTracksDatabase); const auto &result = createTrackIndex.exec(QStringLiteral("CREATE INDEX " "IF NOT EXISTS " "`TracksArtistsTrackIndex` ON `TracksArtists` " "(`TrackID`)")); if (!result) { qDebug() << "DatabaseInterface::initDatabase" << createTrackIndex.lastQuery(); qDebug() << "DatabaseInterface::initDatabase" << createTrackIndex.lastError(); Q_EMIT databaseError(); } } { QSqlQuery createTrackIndex(d->mTracksDatabase); const auto &result = createTrackIndex.exec(QStringLiteral("CREATE INDEX " "IF NOT EXISTS " "`TracksFileNameIndex` ON `TracksMapping` " "(`FileName`)")); if (!result) { qDebug() << "DatabaseInterface::initDatabase" << createTrackIndex.lastQuery(); qDebug() << "DatabaseInterface::initDatabase" << createTrackIndex.lastError(); Q_EMIT databaseError(); } } transactionResult = finishTransaction(); if (!transactionResult) { return; } } void DatabaseInterface::initRequest() { auto transactionResult = startTransaction(); if (!transactionResult) { return; } { auto selectAlbumQueryText = QStringLiteral("SELECT " "album.`ID`, " "album.`Title`, " "album.`AlbumInternalID`, " "artist.`Name`, " "album.`AlbumPath`, " "album.`CoverFileName`, " "album.`TracksCount`, " "album.`IsSingleDiscAlbum` " "FROM `Albums` album " "LEFT JOIN `AlbumsArtists` albumArtist " "ON " "albumArtist.`AlbumID` = album.`ID` " "LEFT JOIN `Artists` artist " "ON " "albumArtist.`ArtistID` = artist.`ID` " "WHERE " "album.`ID` = :albumId"); auto result = d->mSelectAlbumQuery.prepare(selectAlbumQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectAlbumQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectAlbumQuery.lastError(); Q_EMIT databaseError(); } } { auto selectAllAlbumsText = QStringLiteral("SELECT " "album.`ID`, " "album.`Title`, " "album.`AlbumInternalID`, " "artist.`Name`, " "album.`AlbumPath`, " "album.`CoverFileName`, " "album.`TracksCount`, " "album.`IsSingleDiscAlbum` " "FROM `Albums` album " "LEFT JOIN `AlbumsArtists` albumArtist " "ON " "albumArtist.`AlbumID` = album.`ID` " "LEFT JOIN `Artists` artist " "ON " "albumArtist.`ArtistID` = artist.`ID` " "ORDER BY album.`Title` COLLATE NOCASE"); auto result = d->mSelectAllAlbumsQuery.prepare(selectAllAlbumsText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllAlbumsQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllAlbumsQuery.lastError(); Q_EMIT databaseError(); } } { auto selectAllGenresText = QStringLiteral("SELECT " "genre.`ID`, " "genre.`Name` " "FROM `Genre` genre " "ORDER BY genre.`Name` COLLATE NOCASE"); auto result = d->mSelectAllGenresQuery.prepare(selectAllGenresText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllAlbumsQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllAlbumsQuery.lastError(); Q_EMIT databaseError(); } } { auto selectAllAlbumsText = QStringLiteral("SELECT " "album.`ID`, " "album.`Title`, " "artist.`Name` " "FROM `Albums` album " "LEFT JOIN `AlbumsArtists` albumArtist " "ON " "albumArtist.`AlbumID` = album.`ID` " "LEFT JOIN `Artists` artist " "ON " "albumArtist.`ArtistID` = artist.`ID` " "ORDER BY album.`Title` COLLATE NOCASE"); auto result = d->mSelectAllAlbumsShortQuery.prepare(selectAllAlbumsText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllAlbumsShortQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllAlbumsShortQuery.lastError(); Q_EMIT databaseError(); } } { auto selectAllArtistsWithFilterText = QStringLiteral("SELECT `ID`, " "`Name` " "FROM `Artists` " "ORDER BY `Name` COLLATE NOCASE"); auto result = d->mSelectAllArtistsQuery.prepare(selectAllArtistsWithFilterText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllArtistsQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllArtistsQuery.lastError(); Q_EMIT databaseError(); } } { auto selectAllComposersWithFilterText = QStringLiteral("SELECT `ID`, " "`Name` " "FROM `Artists` " "ORDER BY `Name` COLLATE NOCASE"); auto result = d->mSelectAllComposersQuery.prepare(selectAllComposersWithFilterText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllComposersQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllComposersQuery.lastError(); Q_EMIT databaseError(); } } { auto selectAllLyricistsWithFilterText = QStringLiteral("SELECT `ID`, " "`Name` " "FROM `Lyricist` " "ORDER BY `Name` COLLATE NOCASE"); auto result = d->mSelectAllLyricistsQuery.prepare(selectAllLyricistsWithFilterText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllLyricistsQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllLyricistsQuery.lastError(); Q_EMIT databaseError(); } } { auto selectAllTracksText = QStringLiteral("SELECT " "tracks.`ID`, " "tracks.`Title`, " "tracks.`AlbumID`, " "artist.`Name`, " "artistAlbum.`Name`, " "tracksMapping.`FileName`, " "tracksMapping.`FileModifiedTime`, " "tracks.`TrackNumber`, " "tracks.`DiscNumber`, " "tracks.`Duration`, " "album.`Title`, " "tracks.`Rating`, " "album.`CoverFileName`, " "album.`IsSingleDiscAlbum`, " "trackGenre.`Name`, " "trackComposer.`Name`, " "trackLyricist.`Name`, " "tracks.`Comment`, " "tracks.`Year`, " "tracks.`Channels`, " "tracks.`BitRate`, " "tracks.`SampleRate` " "FROM " "`Tracks` tracks, `Artists` artist, `TracksArtists` trackArtist, " "`Albums` album, `TracksMapping` tracksMapping " "LEFT JOIN `AlbumsArtists` artistAlbumMapping ON artistAlbumMapping.`AlbumID` = album.`ID` " "LEFT JOIN `Artists` artistAlbum ON artistAlbum.`ID` = artistAlbumMapping.`ArtistID` " "LEFT JOIN `Genre` trackGenre ON trackGenre.`ID` = tracks.`GenreID` " "LEFT JOIN `Composer` trackComposer ON trackComposer.`ID` = tracks.`ComposerID` " "LEFT JOIN `Lyricist` trackLyricist ON trackLyricist.`ID` = tracks.`LyricistID` " "WHERE " "tracks.`ID` = trackArtist.`TrackID` AND " "artist.`ID` = trackArtist.`ArtistID` AND " "tracks.`AlbumID` = album.`ID` AND " "tracksMapping.`TrackID` = tracks.`ID` AND " "tracksMapping.`Priority` = (SELECT MIN(`Priority`) FROM `TracksMapping` WHERE `TrackID` = tracks.`ID`)"); auto result = d->mSelectAllTracksQuery.prepare(selectAllTracksText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllTracksQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllTracksQuery.lastError(); Q_EMIT databaseError(); } } { auto selectAllTracksShortText = QStringLiteral("SELECT " "tracks.`ID`, " "tracks.`Title`, " "artistAlbum.`Name` " "FROM " "`Tracks` tracks, " "`Albums` album " "LEFT JOIN `AlbumsArtists` artistAlbumMapping ON artistAlbumMapping.`AlbumID` = album.`ID` " "LEFT JOIN `Artists` artistAlbum ON artistAlbum.`ID` = artistAlbumMapping.`ArtistID` " "WHERE " "tracks.`AlbumID` = album.`ID`"); auto result = d->mSelectAllTracksShortQuery.prepare(selectAllTracksShortText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllTracksShortQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllTracksShortQuery.lastError(); Q_EMIT databaseError(); } } { auto selectAllTracksFromSourceQueryText = QStringLiteral("SELECT " "tracks.`ID`, " "tracks.`Title`, " "tracks.`AlbumID`, " "artist.`Name`, " "artistAlbum.`Name`, " "tracksMapping.`FileName`, " "tracksMapping.`FileModifiedTime`, " "tracks.`TrackNumber`, " "tracks.`DiscNumber`, " "tracks.`Duration`, " "album.`Title`, " "tracks.`Rating`, " "album.`CoverFileName`, " "album.`IsSingleDiscAlbum`, " "trackGenre.`Name`, " "trackComposer.`Name`, " "trackLyricist.`Name`, " "tracks.`Comment`, " "tracks.`Year`, " "tracks.`Channels`, " "tracks.`BitRate`, " "tracks.`SampleRate` " "FROM " "`Tracks` tracks, `Artists` artist, `TracksArtists` trackArtist, " "`Albums` album, `TracksMapping` tracksMapping, `DiscoverSource` source " "LEFT JOIN `AlbumsArtists` artistAlbumMapping ON artistAlbumMapping.`AlbumID` = album.`ID` " "LEFT JOIN `Artists` artistAlbum ON artistAlbum.`ID` = artistAlbumMapping.`ArtistID` " "LEFT JOIN `Composer` trackComposer ON trackComposer.`ID` = tracks.`ComposerID` " "LEFT JOIN `Lyricist` trackLyricist ON trackLyricist.`ID` = tracks.`LyricistID` " "LEFT JOIN `Genre` trackGenre ON trackGenre.`ID` = tracks.`GenreID` " "WHERE " "tracks.`ID` = trackArtist.`TrackID` AND " "artist.`ID` = trackArtist.`ArtistID` AND " "tracks.`AlbumID` = album.`ID` AND " "source.`Name` = :source AND " "source.`ID` = tracksMapping.`DiscoverID` AND " "tracksMapping.`TrackID` = tracks.`ID` AND " "tracksMapping.`Priority` = (SELECT MIN(`Priority`) FROM `TracksMapping` WHERE `TrackID` = tracks.`ID`)"); auto result = d->mSelectAllTracksFromSourceQuery.prepare(selectAllTracksFromSourceQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllTracksFromSourceQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllTracksFromSourceQuery.lastError(); Q_EMIT databaseError(); } } { auto selectArtistByNameText = QStringLiteral("SELECT `ID`, " "`Name` " "FROM `Artists` " "WHERE " "`Name` = :name"); auto result = d->mSelectArtistByNameQuery.prepare(selectArtistByNameText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectArtistByNameQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectArtistByNameQuery.lastError(); Q_EMIT databaseError(); } } { auto selectComposerByNameText = QStringLiteral("SELECT `ID`, " "`Name` " "FROM `Composer` " "WHERE " "`Name` = :name"); auto result = d->mSelectComposerByNameQuery.prepare(selectComposerByNameText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectComposerByNameQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectComposerByNameQuery.lastError(); } } { auto selectLyricistByNameText = QStringLiteral("SELECT `ID`, " "`Name` " "FROM `Lyricist` " "WHERE " "`Name` = :name"); auto result = d->mSelectLyricistByNameQuery.prepare(selectLyricistByNameText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectLyricistByNameQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectLyricistByNameQuery.lastError(); } } { auto selectGenreByNameText = QStringLiteral("SELECT `ID`, " "`Name` " "FROM `Genre` " "WHERE " "`Name` = :name"); auto result = d->mSelectGenreByNameQuery.prepare(selectGenreByNameText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectGenreByNameQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectGenreByNameQuery.lastError(); Q_EMIT databaseError(); } } { auto insertArtistsText = QStringLiteral("INSERT INTO `Artists` (`ID`, `Name`) " "VALUES (:artistId, :name)"); auto result = d->mInsertArtistsQuery.prepare(insertArtistsText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mInsertArtistsQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mInsertArtistsQuery.lastError(); Q_EMIT databaseError(); } } { auto insertGenreText = QStringLiteral("INSERT INTO `Genre` (`ID`, `Name`) " "VALUES (:genreId, :name)"); auto result = d->mInsertGenreQuery.prepare(insertGenreText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mInsertGenreQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mInsertGenreQuery.lastError(); Q_EMIT databaseError(); } } { auto insertComposerText = QStringLiteral("INSERT INTO `Composer` (`ID`, `Name`) " "VALUES (:composerId, :name)"); auto result = d->mInsertComposerQuery.prepare(insertComposerText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mInsertComposerQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mInsertComposerQuery.lastError(); } } { auto insertLyricistText = QStringLiteral("INSERT INTO `Lyricist` (`ID`, `Name`) " "VALUES (:lyricistId, :name)"); auto result = d->mInsertLyricistQuery.prepare(insertLyricistText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mInsertLyricistQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mInsertLyricistQuery.lastError(); } } { auto selectTrackQueryText = QStringLiteral("SELECT " "tracks.`ID`, " "tracks.`Title`, " "tracks.`AlbumID`, " "artist.`Name`, " "artistAlbum.`Name`, " "tracksMapping.`FileName`, " "tracksMapping.`FileModifiedTime`, " "tracks.`TrackNumber`, " "tracks.`DiscNumber`, " "tracks.`Duration`, " "album.`Title`, " "tracks.`Rating`, " "album.`CoverFileName`, " "album.`IsSingleDiscAlbum`, " "trackGenre.`Name`, " "trackComposer.`Name`, " "trackLyricist.`Name`, " "tracks.`Comment`, " "tracks.`Year`, " "tracks.`Channels`, " "tracks.`BitRate`, " "tracks.`SampleRate` " "FROM " "`Tracks` tracks, `Artists` artist, `TracksArtists` trackArtist, " "`Albums` album, `TracksMapping` tracksMapping " "LEFT JOIN `AlbumsArtists` artistAlbumMapping ON artistAlbumMapping.`AlbumID` = album.`ID` " "LEFT JOIN `Artists` artistAlbum ON artistAlbum.`ID` = artistAlbumMapping.`ArtistID` " "LEFT JOIN `Composer` trackComposer ON trackComposer.`ID` = tracks.`ComposerID` " "LEFT JOIN `Lyricist` trackLyricist ON trackLyricist.`ID` = tracks.`LyricistID` " "LEFT JOIN `Genre` trackGenre ON trackGenre.`ID` = tracks.`GenreID` " "WHERE " "tracks.`ID` = trackArtist.`TrackID` AND " "artist.`ID` = trackArtist.`ArtistID` AND " "tracksMapping.`TrackID` = tracks.`ID` AND " "tracks.`AlbumID` = album.`ID` AND " "album.`ID` = :albumId AND " "tracksMapping.`Priority` = (SELECT MIN(`Priority`) FROM `TracksMapping` WHERE `TrackID` = tracks.`ID`) " "ORDER BY tracks.`DiscNumber` ASC, " "tracks.`TrackNumber` ASC"); auto result = d->mSelectTrackQuery.prepare(selectTrackQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectTrackQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectTrackQuery.lastError(); Q_EMIT databaseError(); } } { auto selectTrackFromIdQueryText = QStringLiteral("SELECT " "tracks.`Id`, " "tracks.`Title`, " "tracks.`AlbumID`, " "artist.`Name`, " "artistAlbum.`Name`, " "tracksMapping.`FileName`, " "tracksMapping.`FileModifiedTime`, " "tracks.`TrackNumber`, " "tracks.`DiscNumber`, " "tracks.`Duration`, " "album.`Title`, " "tracks.`Rating`, " "album.`CoverFileName`, " "album.`IsSingleDiscAlbum`, " "trackGenre.`Name`, " "trackComposer.`Name`, " "trackLyricist.`Name`, " "tracks.`Comment`, " "tracks.`Year`, " "tracks.`Channels`, " "tracks.`BitRate`, " "tracks.`SampleRate` " "FROM " "`Tracks` tracks, `Artists` artist, `TracksArtists` trackArtist, " "`Albums` album, `TracksMapping` tracksMapping " "LEFT JOIN `AlbumsArtists` artistAlbumMapping ON artistAlbumMapping.`AlbumID` = album.`ID` " "LEFT JOIN `Artists` artistAlbum ON artistAlbum.`ID` = artistAlbumMapping.`ArtistID` " "LEFT JOIN `Composer` trackComposer ON trackComposer.`ID` = tracks.`ComposerID` " "LEFT JOIN `Lyricist` trackLyricist ON trackLyricist.`ID` = tracks.`LyricistID` " "LEFT JOIN `Genre` trackGenre ON trackGenre.`ID` = tracks.`GenreID` " "WHERE " "tracks.`ID` = trackArtist.`TrackID` AND " "artist.`ID` = trackArtist.`ArtistID` AND " "tracks.`ID` = :trackId AND " "tracks.`AlbumID` = album.`ID` AND " "tracksMapping.`TrackID` = tracks.`ID` AND " "tracksMapping.`Priority` = (SELECT MIN(`Priority`) FROM `TracksMapping` WHERE `TrackID` = tracks.`ID`)"); auto result = d->mSelectTrackFromIdQuery.prepare(selectTrackFromIdQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectTrackFromIdQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectTrackFromIdQuery.lastError(); Q_EMIT databaseError(); } } { auto selectCountAlbumsQueryText = QStringLiteral("SELECT count(*) " "FROM `Albums` album, `Artists` artist, `AlbumsArtists` albumArtist " "WHERE artist.`Name` = :artistName AND " "album.`ID` = albumArtist.`AlbumID` AND " "artist.`ID` = albumArtist.`ArtistID`"); const auto result = d->mSelectCountAlbumsForArtistQuery.prepare(selectCountAlbumsQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectCountAlbumsForArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectCountAlbumsForArtistQuery.lastError(); Q_EMIT databaseError(); } } { auto selectGenreForArtistQueryText = QStringLiteral("SELECT DISTINCT trackGenre.`Name` " "FROM " "`Albums` album, " "`Artists` artist, " "`AlbumsArtists` albumArtist, " "`Tracks` track " "LEFT JOIN `Genre` trackGenre ON trackGenre.`ID` = track.`GenreID` " "WHERE artist.`Name` = :artistName AND " "album.`ID` = albumArtist.`AlbumID` AND " "artist.`ID` = albumArtist.`ArtistID` AND " "album.`ID` = track.`AlbumID`"); const auto result = d->mSelectGenreForArtistQuery.prepare(selectGenreForArtistQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectGenreForArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectGenreForArtistQuery.lastError(); Q_EMIT databaseError(); } } { auto selectGenreForAlbumQueryText = QStringLiteral("SELECT DISTINCT trackGenre.`Name` " "FROM " "`Tracks` track " "LEFT JOIN `Genre` trackGenre ON trackGenre.`ID` = track.`GenreID` " "WHERE " "track.`AlbumID` = :albumId"); const auto result = d->mSelectGenreForAlbumQuery.prepare(selectGenreForAlbumQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectGenreForAlbumQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectGenreForAlbumQuery.lastError(); Q_EMIT databaseError(); } } { auto selectCountAlbumsQueryText = QStringLiteral("SELECT distinct count(album.`ID`) " "FROM `Albums` album, " "`Tracks` track, " "`Composer` albumComposer " "WHERE albumComposer.`Name` = :artistName AND " "track.`ComposerID` = albumComposer.`ID` AND " "track.`AlbumID` = album.`ID`"); const auto result = d->mSelectCountAlbumsForComposerQuery.prepare(selectCountAlbumsQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectCountAlbumsForComposerQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectCountAlbumsForComposerQuery.lastError(); Q_EMIT databaseError(); } } { auto selectCountAlbumsQueryText = QStringLiteral("SELECT distinct count(album.`ID`) " "FROM `Albums` album, " "`Tracks` track, " "`Lyricist` albumLyricist " "WHERE albumLyricist.`Name` = :artistName AND " "track.`LyricistID` = albumLyricist.`ID` AND " "track.`AlbumID` = album.`ID`"); const auto result = d->mSelectCountAlbumsForLyricistQuery.prepare(selectCountAlbumsQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectCountAlbumsForLyricistQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectCountAlbumsForLyricistQuery.lastError(); Q_EMIT databaseError(); } } { auto selectAlbumIdFromTitleQueryText = QStringLiteral("SELECT " "album.`ID` " "FROM " "`Albums` album, `Artists` artist, `AlbumsArtists` albumArtist " "WHERE " "artist.`Name` = :artistName AND " "album.`ID` = albumArtist.`AlbumID` AND " "artist.`ID` = albumArtist.`ArtistID` AND " "album.`Title` = :title"); auto result = d->mSelectAlbumIdFromTitleQuery.prepare(selectAlbumIdFromTitleQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectAlbumIdFromTitleQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectAlbumIdFromTitleQuery.lastError(); Q_EMIT databaseError(); } } { auto selectAlbumIdFromTitleAndArtistQueryText = QStringLiteral("SELECT " "album.`ID` " "FROM " "`Albums` album, " "`AlbumsArtists` albumArtist " "WHERE " "album.`ID` = albumArtist.`AlbumID` AND " "album.`Title` = :title AND " "album.`AlbumPath` = :albumPath AND " "albumArtist.`ArtistID` = :artistId"); auto result = d->mSelectAlbumIdFromTitleAndArtistQuery.prepare(selectAlbumIdFromTitleAndArtistQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectAlbumIdFromTitleAndArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectAlbumIdFromTitleAndArtistQuery.lastError(); Q_EMIT databaseError(); } } { auto selectAlbumIdFromTitleWithoutArtistQueryText = QStringLiteral("SELECT " "album.`ID` " "FROM " "`Albums` album " "WHERE " "album.`AlbumPath` = :albumPath AND " "album.`Title` = :title AND " "NOT EXISTS (" "SELECT " "albumArtist.`AlbumID` " "FROM " "`AlbumsArtists` albumArtist " "WHERE " "albumArtist.`AlbumID` = album.`ID`" ")"); auto result = d->mSelectAlbumIdFromTitleWithoutArtistQuery.prepare(selectAlbumIdFromTitleWithoutArtistQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectAlbumIdFromTitleWithoutArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectAlbumIdFromTitleWithoutArtistQuery.lastError(); Q_EMIT databaseError(); } } { auto insertAlbumQueryText = QStringLiteral("INSERT INTO `Albums` " "(`ID`, " "`Title`, " "`AlbumPath`, " "`CoverFileName`, " "`TracksCount`, " "`IsSingleDiscAlbum`) " "VALUES " "(:albumId, " ":title, " ":albumPath, " ":coverFileName, " ":tracksCount, " ":isSingleDiscAlbum)"); auto result = d->mInsertAlbumQuery.prepare(insertAlbumQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mInsertAlbumQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mInsertAlbumQuery.lastError(); Q_EMIT databaseError(); } } { auto insertAlbumArtistQueryText = QStringLiteral("INSERT INTO `AlbumsArtists` (`AlbumID`, `ArtistID`) " "VALUES (:albumId, :artistId)"); auto result = d->mInsertAlbumArtistQuery.prepare(insertAlbumArtistQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mInsertAlbumArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mInsertAlbumArtistQuery.lastError(); Q_EMIT databaseError(); } } { auto insertTrackArtistQueryText = QStringLiteral("INSERT INTO `TracksArtists` (`TrackID`, `ArtistID`) " "VALUES (:trackId, :artistId)"); auto result = d->mInsertTrackArtistQuery.prepare(insertTrackArtistQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mInsertTrackArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mInsertTrackArtistQuery.lastError(); Q_EMIT databaseError(); } } { auto insertTrackMappingQueryText = QStringLiteral("INSERT INTO " "`TracksMapping` " "(`FileName`, " "`DiscoverID`, " "`Priority`, " "`FileModifiedTime`) " "VALUES (:fileName, :discoverId, :priority, :mtime)"); auto result = d->mInsertTrackMapping.prepare(insertTrackMappingQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mInsertTrackMapping.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mInsertTrackMapping.lastError(); Q_EMIT databaseError(); } } { auto initialUpdateTracksValidityQueryText = QStringLiteral("UPDATE `TracksMapping` " "SET " "`TrackID` = :trackId, " "`Priority` = :priority, " "`FileModifiedTime` = :mtime " "WHERE `FileName` = :fileName"); auto result = d->mUpdateTrackMapping.prepare(initialUpdateTracksValidityQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mUpdateTrackMapping.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mUpdateTrackMapping.lastError(); Q_EMIT databaseError(); } } { auto removeTracksMappingFromSourceQueryText = QStringLiteral("DELETE FROM `TracksMapping` " "WHERE `FileName` = :fileName AND `DiscoverID` = :sourceId"); auto result = d->mRemoveTracksMappingFromSource.prepare(removeTracksMappingFromSourceQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mRemoveTracksMappingFromSource.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mRemoveTracksMappingFromSource.lastError(); Q_EMIT databaseError(); } } { auto removeTracksMappingQueryText = QStringLiteral("DELETE FROM `TracksMapping` " "WHERE `FileName` = :fileName"); auto result = d->mRemoveTracksMapping.prepare(removeTracksMappingQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mRemoveTracksMapping.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mRemoveTracksMapping.lastError(); Q_EMIT databaseError(); } } { auto selectTracksWithoutMappingQueryText = QStringLiteral("SELECT " "tracks.`Id`, " "tracks.`Title`, " "tracks.`AlbumID`, " "artist.`Name`, " "artistAlbum.`Name`, " "\"\" as FileName, " "NULL as FileModifiedTime, " "tracks.`TrackNumber`, " "tracks.`DiscNumber`, " "tracks.`Duration`, " "album.`Title`, " "tracks.`Rating`, " "album.`CoverFileName`, " "album.`IsSingleDiscAlbum`, " "trackGenre.`Name`, " "trackComposer.`Name`, " "trackLyricist.`Name`, " "tracks.`Comment`, " "tracks.`Year`, " "tracks.`Channels`, " "tracks.`BitRate`, " "tracks.`SampleRate` " "FROM " "`Tracks` tracks, " "`Artists` artist, " "`TracksArtists` trackArtist, " "`Albums` album " "LEFT JOIN `AlbumsArtists` artistAlbumMapping ON artistAlbumMapping.`AlbumID` = album.`ID` " "LEFT JOIN `Artists` artistAlbum ON artistAlbum.`ID` = artistAlbumMapping.`ArtistID` " "LEFT JOIN `Composer` trackComposer ON trackComposer.`ID` = tracks.`ComposerID` " "LEFT JOIN `Lyricist` trackLyricist ON trackLyricist.`ID` = tracks.`LyricistID` " "LEFT JOIN `Genre` trackGenre ON trackGenre.`ID` = tracks.`GenreID` " "WHERE " "tracks.`ID` = trackArtist.`TrackID` AND " "artist.`ID` = trackArtist.`ArtistID` AND " "tracks.`AlbumID` = album.`ID` AND " "tracks.`ID` NOT IN (SELECT tracksMapping2.`TrackID` FROM `TracksMapping` tracksMapping2)"); auto result = d->mSelectTracksWithoutMappingQuery.prepare(selectTracksWithoutMappingQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectTracksWithoutMappingQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectTracksWithoutMappingQuery.lastError(); Q_EMIT databaseError(); } } { auto selectTracksMappingQueryText = QStringLiteral("SELECT " "`TrackID`, " "`FileName`, " "`DiscoverID`, " "`Priority`, " "`FileModifiedTime` " "FROM " "`TracksMapping` " "WHERE " "`FileName` = :fileName"); auto result = d->mSelectTracksMapping.prepare(selectTracksMappingQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectTracksMapping.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectTracksMapping.lastError(); Q_EMIT databaseError(); } } { auto selectTracksMappingPriorityQueryText = QStringLiteral("SELECT " "`Priority` " "FROM " "`TracksMapping` " "WHERE " "`TrackID` = :trackId AND " "`FileName` = :fileName"); auto result = d->mSelectTracksMappingPriority.prepare(selectTracksMappingPriorityQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectTracksMappingPriority.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectTracksMappingPriority.lastError(); Q_EMIT databaseError(); } } { auto selectTracksMappingPriorityQueryByTrackIdText = QStringLiteral("SELECT " "MAX(`Priority`) " "FROM " "`TracksMapping` " "WHERE " "`TrackID` = :trackId"); auto result = d->mSelectTracksMappingPriorityByTrackId.prepare(selectTracksMappingPriorityQueryByTrackIdText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectTracksMappingPriorityByTrackId.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectTracksMappingPriorityByTrackId.lastError(); Q_EMIT databaseError(); } } { auto selectAllTrackFilesFromSourceQueryText = QStringLiteral("SELECT " "tracksMapping.`FileName`, " "tracksMapping.`FileModifiedTime` " "FROM " "`TracksMapping` tracksMapping " "WHERE " "tracksMapping.`DiscoverID` = :discoverId"); auto result = d->mSelectAllTrackFilesFromSourceQuery.prepare(selectAllTrackFilesFromSourceQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllTrackFilesFromSourceQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectAllTrackFilesFromSourceQuery.lastError(); Q_EMIT databaseError(); } } { auto insertMusicSourceQueryText = QStringLiteral("INSERT OR IGNORE INTO `DiscoverSource` (`ID`, `Name`) " "VALUES (:discoverId, :name)"); auto result = d->mInsertMusicSource.prepare(insertMusicSourceQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mInsertMusicSource.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mInsertMusicSource.lastError(); Q_EMIT databaseError(); } } { auto selectMusicSourceQueryText = QStringLiteral("SELECT `ID` FROM `DiscoverSource` WHERE `Name` = :name"); auto result = d->mSelectMusicSource.prepare(selectMusicSourceQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectMusicSource.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectMusicSource.lastError(); Q_EMIT databaseError(); } } { auto selectTrackQueryText = QStringLiteral("SELECT " "tracks.`ID`, tracksMapping.`FileName` " "FROM " "`Tracks` tracks, `Artists` artist, `TracksArtists` trackArtist, " "`TracksMapping` tracksMapping " "WHERE " "tracks.`Title` = :title AND " "tracks.`AlbumID` = :album AND " "artist.`Name` = :artist AND " "tracks.`ID` = trackArtist.`TrackID` AND " "artist.`ID` = trackArtist.`ArtistID` AND " "tracksMapping.`TrackID` = tracks.`ID` AND " "tracksMapping.`Priority` = (SELECT MIN(`Priority`) FROM `TracksMapping` WHERE `TrackID` = tracks.`ID`)"); auto result = d->mSelectTrackIdFromTitleAlbumIdArtistQuery.prepare(selectTrackQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectTrackIdFromTitleAlbumIdArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectTrackIdFromTitleAlbumIdArtistQuery.lastError(); Q_EMIT databaseError(); } } { auto insertTrackQueryText = QStringLiteral("INSERT INTO `Tracks` (`ID`, `Title`, `AlbumID`, `GenreID`, `ComposerID`, `LyricistID`, `Comment`, `TrackNumber`, `DiscNumber`, `Channels`, `BitRate`, `SampleRate`, `Year`, `Duration`, `Rating` ) " "VALUES (:trackId, :title, :album, :genreId, :composerId, :lyricistId, :comment, :trackNumber, :discNumber, :channels, :bitRate, :sampleRate, :year, :trackDuration, :trackRating)"); auto result = d->mInsertTrackQuery.prepare(insertTrackQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mInsertTrackQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mInsertTrackQuery.lastError(); Q_EMIT databaseError(); } } { auto updateTrackQueryText = QStringLiteral("UPDATE `Tracks` " "SET " "`Title` = :title, " "`AlbumID` = :album, " "`GenreID` = :genreId, " "`ComposerID` = :composerId, " "`LyricistID` = :lyricistId, " "`Comment` = :comment, " "`TrackNumber` = :trackNumber, " "`DiscNumber` = :discNumber, " "`Channels` = :channels, " "`BitRate` = :bitRate, " "`SampleRate` = :sampleRate, " "`Year` = :year, " " `Duration` = :trackDuration, " "`Rating` = :trackRating " "WHERE " "`ID` = :trackId"); auto result = d->mUpdateTrackQuery.prepare(updateTrackQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mUpdateTrackQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mUpdateTrackQuery.lastError(); Q_EMIT databaseError(); } } { auto selectTrackQueryText = QStringLiteral("SELECT " "tracks.ID " "FROM " "`Tracks` tracks, " "`Albums` albums, " "`TracksArtists` trackArtist, " "`Artists` artist " "WHERE " "tracks.`Title` = :title AND " "tracks.`AlbumID` = albums.`ID` AND " "albums.`Title` = :album AND " "tracks.`TrackNumber` = :trackNumber AND " "tracks.`DiscNumber` = :discNumber AND " "trackArtist.`TrackID` = tracks.`ID` AND " "trackArtist.`ArtistID` = artist.`ID` AND " "artist.`Name` = :artist"); auto result = d->mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery.prepare(selectTrackQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery.lastError(); Q_EMIT databaseError(); } } { auto selectTrackQueryText = QStringLiteral("SELECT " "tracks.ID " "FROM " "`Tracks` tracks, " "`Albums` albums " "WHERE " "tracks.`Title` = :title AND " "tracks.`AlbumID` = albums.`ID` AND " "albums.`Title` = :album AND " "albums.`AlbumPath` = :albumPath AND " "tracks.`TrackNumber` = :trackNumber AND " "tracks.`DiscNumber` = :discNumber AND " "( " "( NOT EXISTS (SELECT albumArtistMapping.`AlbumID` " "FROM " "`AlbumsArtists` albumArtistMapping " "WHERE " "albumArtistMapping.`AlbumID` = albums.`ID`) " ") OR " "( EXISTS (SELECT albumArtistMapping.`AlbumID` " "FROM " "`AlbumsArtists` albumArtistMapping, " "`Artists` albumArtist " "WHERE " "albumArtist.`Name` = :albumArtist AND " "albumArtist.`ID` = albumArtistMapping.`ArtistID` AND " "albumArtistMapping.`AlbumID` = albums.`ID`) " ") " ")"); auto result = d->mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery.prepare(selectTrackQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery.lastError(); Q_EMIT databaseError(); } } { auto selectAlbumArtUriFromAlbumIdQueryText = QStringLiteral("SELECT `CoverFileName`" "FROM " "`Albums` " "WHERE " "`ID` = :albumId"); auto result = d->mSelectAlbumArtUriFromAlbumIdQuery.prepare(selectAlbumArtUriFromAlbumIdQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectAlbumArtUriFromAlbumIdQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectAlbumArtUriFromAlbumIdQuery.lastError(); Q_EMIT databaseError(); } } { auto selectAlbumTrackCountQueryText = QStringLiteral("SELECT `TracksCount` " "FROM `Albums`" "WHERE " "`ID` = :albumId"); auto result = d->mSelectAlbumTrackCountQuery.prepare(selectAlbumTrackCountQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectAlbumTrackCountQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectAlbumTrackCountQuery.lastError(); Q_EMIT databaseError(); } } { auto updateAlbumQueryText = QStringLiteral("UPDATE `Albums` " "SET `TracksCount` = (SELECT COUNT(*) FROM `Tracks` WHERE `AlbumID` = `Albums`.`ID`) " "WHERE " "`ID` = :albumId"); auto result = d->mUpdateAlbumQuery.prepare(updateAlbumQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mUpdateAlbumQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mUpdateAlbumQuery.lastError(); Q_EMIT databaseError(); } } { auto updateIsSingleDiscAlbumFromIdQueryText = QStringLiteral("UPDATE `Albums` " "SET `IsSingleDiscAlbum` = (SELECT COUNT(DISTINCT DiscNumber) = 1 FROM `Tracks` WHERE `AlbumID` = :albumId) " "WHERE " "`ID` = :albumId AND " "`IsSingleDiscAlbum` != (SELECT COUNT(DISTINCT DiscNumber) = 1 FROM `Tracks` WHERE `AlbumID` = :albumId)"); auto result = d->mUpdateIsSingleDiscAlbumFromIdQuery.prepare(updateIsSingleDiscAlbumFromIdQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mUpdateIsSingleDiscAlbumFromIdQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mUpdateIsSingleDiscAlbumFromIdQuery.lastError(); Q_EMIT databaseError(); } } { auto updateAlbumArtUriFromAlbumIdQueryText = QStringLiteral("UPDATE `Albums` " "SET `CoverFileName` = :coverFileName " "WHERE " "`ID` = :albumId"); auto result = d->mUpdateAlbumArtUriFromAlbumIdQuery.prepare(updateAlbumArtUriFromAlbumIdQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mUpdateAlbumArtUriFromAlbumIdQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mUpdateAlbumArtUriFromAlbumIdQuery.lastError(); Q_EMIT databaseError(); } } { auto selectTracksFromArtistQueryText = QStringLiteral("SELECT " "tracks.`ID`, " "tracks.`Title`, " "tracks.`AlbumID`, " "artist.`Name`, " "artistAlbum.`Name`, " "tracksMapping.`FileName`, " "tracksMapping.`FileModifiedTime`, " "tracks.`TrackNumber`, " "tracks.`DiscNumber`, " "tracks.`Duration`, " "album.`Title`, " "tracks.`Rating`, " "album.`CoverFileName`, " "album.`IsSingleDiscAlbum`, " "trackGenre.`Name`, " "trackComposer.`Name`, " "trackLyricist.`Name`, " "tracks.`Comment`, " "tracks.`Year`, " "tracks.`Channels`, " "tracks.`BitRate`, " "tracks.`SampleRate` " "FROM `Tracks` tracks, `Albums` album, `Artists` artist, `TracksArtists` trackArtist, " "`TracksMapping` tracksMapping " "LEFT JOIN `AlbumsArtists` artistAlbumMapping ON artistAlbumMapping.`AlbumID` = album.`ID` " "LEFT JOIN `Artists` artistAlbum ON artistAlbum.`ID` = artistAlbumMapping.`ArtistID` " "LEFT JOIN `Composer` trackComposer ON trackComposer.`ID` = tracks.`ComposerID` " "LEFT JOIN `Lyricist` trackLyricist ON trackLyricist.`ID` = tracks.`LyricistID` " "LEFT JOIN `Genre` trackGenre ON trackGenre.`ID` = tracks.`GenreID` " "WHERE " "artist.`Name` = :artistName AND " "tracks.`AlbumID` = album.`ID` AND " "artist.`ID` = trackArtist.`ArtistID` AND " "tracks.`ID` = trackArtist.`TrackID` AND " "tracksMapping.`TrackID` = tracks.`ID` AND " "tracksMapping.`Priority` = (SELECT MIN(`Priority`) FROM `TracksMapping` WHERE `TrackID` = tracks.`ID`) " "ORDER BY tracks.`Title` ASC, " "album.`Title` ASC"); auto result = d->mSelectTracksFromArtist.prepare(selectTracksFromArtistQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectTracksFromArtist.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectTracksFromArtist.lastError(); Q_EMIT databaseError(); } } { auto selectAlbumIdsFromArtistQueryText = QStringLiteral("SELECT " "album.`ID` " "FROM " "`Albums` album, " "`Artists` artist," "`AlbumsArtists` albumArtist " "WHERE " "album.`ID` = albumArtist.`AlbumID` AND " "artist.`ID` = albumArtist.`ArtistID` AND " "artist.`Name` = :artistName"); auto result = d->mSelectAlbumIdsFromArtist.prepare(selectAlbumIdsFromArtistQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectAlbumIdsFromArtist.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectAlbumIdsFromArtist.lastError(); Q_EMIT databaseError(); } } { auto selectArtistQueryText = QStringLiteral("SELECT `ID`, " "`Name` " "FROM `Artists` " "WHERE " "`ID` = :artistId"); auto result = d->mSelectArtistQuery.prepare(selectArtistQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectArtistQuery.lastError(); Q_EMIT databaseError(); } } { auto selectGenreQueryText = QStringLiteral("SELECT `ID`, " "`Name` " "FROM `Genre` " "WHERE " "`ID` = :genreId"); auto result = d->mSelectGenreQuery.prepare(selectGenreQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectGenreQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectGenreQuery.lastError(); Q_EMIT databaseError(); } } { auto selectComposerQueryText = QStringLiteral("SELECT `ID`, " "`Name` " "FROM `Composer` " "WHERE " "`ID` = :composerId"); auto result = d->mSelectComposerQuery.prepare(selectComposerQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectComposerQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectComposerQuery.lastError(); } } { auto selectLyricistQueryText = QStringLiteral("SELECT `ID`, " "`Name` " "FROM `Lyricist` " "WHERE " "`ID` = :lyricistId"); auto result = d->mSelectLyricistQuery.prepare(selectLyricistQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectLyricistQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectLyricistQuery.lastError(); } } { auto selectTrackFromFilePathQueryText = QStringLiteral("SELECT " "tracks.`ID`, " "tracks.`Title`, " "tracks.`AlbumID`, " "artist.`Name`, " "artistAlbum.`Name`, " "tracksMapping.`FileName`, " "tracksMapping.`FileModifiedTime`, " "tracks.`TrackNumber`, " "tracks.`DiscNumber`, " "tracks.`Duration`, " "album.`Title`, " "tracks.`Rating`, " "album.`CoverFileName`, " "album.`IsSingleDiscAlbum`, " "trackGenre.`Name`, " "trackComposer.`Name`, " "trackLyricist.`Name`, " "tracks.`Comment`, " "tracks.`Year`, " "tracks.`Channels`, " "tracks.`BitRate`, " "tracks.`SampleRate` " "FROM `Tracks` tracks, `Artists` artist, `Albums` album, `TracksArtists` trackArtist, " "`TracksMapping` tracksMapping " "LEFT JOIN `AlbumsArtists` artistAlbumMapping ON artistAlbumMapping.`AlbumID` = album.`ID` " "LEFT JOIN `Artists` artistAlbum ON artistAlbum.`ID` = artistAlbumMapping.`ArtistID` " "LEFT JOIN `Composer` trackComposer ON trackComposer.`ID` = tracks.`ComposerID` " "LEFT JOIN `Lyricist` trackLyricist ON trackLyricist.`ID` = tracks.`LyricistID` " "LEFT JOIN `Genre` trackGenre ON trackGenre.`ID` = tracks.`GenreID` " "WHERE " "tracks.`AlbumID` = album.`ID` AND " "artist.`ID` = trackArtist.`ArtistID` AND " "tracks.`ID` = trackArtist.`TrackID` AND " "tracksMapping.`TrackID` = tracks.`ID` AND " "tracksMapping.`FileName` = :filePath AND " "tracksMapping.`Priority` = (SELECT MIN(`Priority`) FROM `TracksMapping` WHERE `TrackID` = tracks.`ID`)"); auto result = d->mSelectTrackFromFilePathQuery.prepare(selectTrackFromFilePathQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mSelectTrackFromFilePathQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mSelectTrackFromFilePathQuery.lastError(); Q_EMIT databaseError(); } } { auto removeTrackQueryText = QStringLiteral("DELETE FROM `Tracks` " "WHERE " "`ID` = :trackId"); auto result = d->mRemoveTrackQuery.prepare(removeTrackQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mRemoveTrackQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mRemoveTrackQuery.lastError(); Q_EMIT databaseError(); } } { auto removeTrackArtistQueryText = QStringLiteral("DELETE FROM `TracksArtists` " "WHERE " "`TrackID` = :trackId"); auto result = d->mRemoveTrackArtistQuery.prepare(removeTrackArtistQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mRemoveTrackArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mRemoveTrackArtistQuery.lastError(); Q_EMIT databaseError(); } } { auto removeAlbumQueryText = QStringLiteral("DELETE FROM `Albums` " "WHERE " "`ID` = :albumId"); auto result = d->mRemoveAlbumQuery.prepare(removeAlbumQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mRemoveAlbumQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mRemoveAlbumQuery.lastError(); Q_EMIT databaseError(); } } { auto removeAlbumArtistQueryText = QStringLiteral("DELETE FROM `AlbumsArtists` " "WHERE " "`AlbumID` = :albumId"); auto result = d->mRemoveAlbumArtistQuery.prepare(removeAlbumArtistQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mRemoveAlbumArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mRemoveAlbumArtistQuery.lastError(); Q_EMIT databaseError(); } } { auto removeAlbumQueryText = QStringLiteral("DELETE FROM `Artists` " "WHERE " "`ID` = :artistId"); auto result = d->mRemoveArtistQuery.prepare(removeAlbumQueryText); if (!result) { qDebug() << "DatabaseInterface::initRequest" << d->mRemoveArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::initRequest" << d->mRemoveArtistQuery.lastError(); Q_EMIT databaseError(); } } finishTransaction(); d->mInitFinished = true; Q_EMIT requestsInitDone(); } qulonglong DatabaseInterface::insertAlbum(const QString &title, const QString &albumArtist, const QString &trackArtist, const QString &trackPath, const QUrl &albumArtURI, int tracksCount, AlbumDiscsCount isSingleDiscAlbum, QList &newAlbumIds, QList &newArtistsIds) { auto result = qulonglong(0); if (title.isEmpty()) { return result; } if (!albumArtist.isEmpty() || !trackArtist.isEmpty()) { d->mSelectAlbumIdFromTitleAndArtistQuery.bindValue(QStringLiteral(":title"), title); d->mSelectAlbumIdFromTitleAndArtistQuery.bindValue(QStringLiteral(":albumPath"), trackPath); if (!albumArtist.isEmpty()) { d->mSelectAlbumIdFromTitleAndArtistQuery.bindValue(QStringLiteral(":artistId"), insertArtist(albumArtist, newArtistsIds)); } else { d->mSelectAlbumIdFromTitleAndArtistQuery.bindValue(QStringLiteral(":artistId"), insertArtist(trackArtist, newArtistsIds)); } auto queryResult = d->mSelectAlbumIdFromTitleAndArtistQuery.exec(); if (!queryResult || !d->mSelectAlbumIdFromTitleAndArtistQuery.isSelect() || !d->mSelectAlbumIdFromTitleAndArtistQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertAlbum" << d->mSelectAlbumIdFromTitleAndArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::insertAlbum" << d->mSelectAlbumIdFromTitleAndArtistQuery.boundValues(); qDebug() << "DatabaseInterface::insertAlbum" << d->mSelectAlbumIdFromTitleAndArtistQuery.lastError(); d->mSelectAlbumIdFromTitleAndArtistQuery.finish(); return result; } if (d->mSelectAlbumIdFromTitleAndArtistQuery.next()) { result = d->mSelectAlbumIdFromTitleAndArtistQuery.record().value(0).toULongLong(); d->mSelectAlbumIdFromTitleAndArtistQuery.finish(); return result; } d->mSelectAlbumIdFromTitleAndArtistQuery.finish(); } if (result == 0) { d->mSelectAlbumIdFromTitleWithoutArtistQuery.bindValue(QStringLiteral(":title"), title); d->mSelectAlbumIdFromTitleWithoutArtistQuery.bindValue(QStringLiteral(":albumPath"), trackPath); auto queryResult = d->mSelectAlbumIdFromTitleWithoutArtistQuery.exec(); if (!queryResult || !d->mSelectAlbumIdFromTitleWithoutArtistQuery.isSelect() || !d->mSelectAlbumIdFromTitleWithoutArtistQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertAlbum" << d->mSelectAlbumIdFromTitleWithoutArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::insertAlbum" << d->mSelectAlbumIdFromTitleWithoutArtistQuery.boundValues(); qDebug() << "DatabaseInterface::insertAlbum" << d->mSelectAlbumIdFromTitleWithoutArtistQuery.lastError(); d->mSelectAlbumIdFromTitleWithoutArtistQuery.finish(); return result; } if (d->mSelectAlbumIdFromTitleWithoutArtistQuery.next()) { result = d->mSelectAlbumIdFromTitleWithoutArtistQuery.record().value(0).toULongLong(); d->mSelectAlbumIdFromTitleWithoutArtistQuery.finish(); return result; } d->mSelectAlbumIdFromTitleWithoutArtistQuery.finish(); } d->mInsertAlbumQuery.bindValue(QStringLiteral(":albumId"), d->mAlbumId); d->mInsertAlbumQuery.bindValue(QStringLiteral(":title"), title); d->mInsertAlbumQuery.bindValue(QStringLiteral(":albumPath"), trackPath); d->mInsertAlbumQuery.bindValue(QStringLiteral(":coverFileName"), albumArtURI); d->mInsertAlbumQuery.bindValue(QStringLiteral(":tracksCount"), tracksCount); d->mInsertAlbumQuery.bindValue(QStringLiteral(":isSingleDiscAlbum"), isSingleDiscAlbum == SingleDiscAlbum); auto queryResult = d->mInsertAlbumQuery.exec(); if (!queryResult || !d->mInsertAlbumQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertAlbum" << d->mInsertAlbumQuery.lastQuery(); qDebug() << "DatabaseInterface::insertAlbum" << d->mInsertAlbumQuery.boundValues(); qDebug() << "DatabaseInterface::insertAlbum" << d->mInsertAlbumQuery.lastError(); d->mInsertAlbumQuery.finish(); return result; } result = d->mAlbumId; d->mInsertAlbumQuery.finish(); if (!albumArtist.isEmpty()) { d->mInsertAlbumArtistQuery.bindValue(QStringLiteral(":albumId"), d->mAlbumId); d->mInsertAlbumArtistQuery.bindValue(QStringLiteral(":artistId"), insertArtist(albumArtist, newArtistsIds)); queryResult = d->mInsertAlbumArtistQuery.exec(); if (!queryResult || !d->mInsertAlbumArtistQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertAlbum" << d->mInsertAlbumArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::insertAlbum" << d->mInsertAlbumArtistQuery.boundValues(); qDebug() << "DatabaseInterface::insertAlbum" << d->mInsertAlbumArtistQuery.lastError(); d->mInsertAlbumArtistQuery.finish(); return result; } d->mInsertAlbumArtistQuery.finish(); } ++d->mAlbumId; newAlbumIds.push_back(result); return result; } bool DatabaseInterface::updateAlbumFromId(qulonglong albumId, const QUrl &albumArtUri, const MusicAudioTrack ¤tTrack, QList &newArtistsIds) { auto modifiedAlbum = false; auto previousAlbum = internalAlbumFromId(albumId); d->mUpdateIsSingleDiscAlbumFromIdQuery.bindValue(QStringLiteral(":albumId"), albumId); auto result = d->mUpdateIsSingleDiscAlbumFromIdQuery.exec(); if (!result || !d->mUpdateIsSingleDiscAlbumFromIdQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::updateIsSingleDiscAlbumFromId" << d->mUpdateIsSingleDiscAlbumFromIdQuery.lastQuery(); qDebug() << "DatabaseInterface::updateIsSingleDiscAlbumFromId" << d->mUpdateIsSingleDiscAlbumFromIdQuery.boundValues(); qDebug() << "DatabaseInterface::updateIsSingleDiscAlbumFromId" << d->mUpdateIsSingleDiscAlbumFromIdQuery.lastError(); d->mUpdateIsSingleDiscAlbumFromIdQuery.finish(); return modifiedAlbum; } modifiedAlbum = (d->mUpdateIsSingleDiscAlbumFromIdQuery.numRowsAffected() != 0); d->mUpdateIsSingleDiscAlbumFromIdQuery.finish(); if (!albumArtUri.isValid()) { return modifiedAlbum; } auto storedAlbumArtUri = internalAlbumArtUriFromAlbumId(albumId); if (!storedAlbumArtUri.isValid() || storedAlbumArtUri != albumArtUri) { d->mUpdateAlbumArtUriFromAlbumIdQuery.bindValue(QStringLiteral(":albumId"), albumId); d->mUpdateAlbumArtUriFromAlbumIdQuery.bindValue(QStringLiteral(":coverFileName"), albumArtUri); result = d->mUpdateAlbumArtUriFromAlbumIdQuery.exec(); if (!result || !d->mUpdateAlbumArtUriFromAlbumIdQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::updateIsSingleDiscAlbumFromId" << d->mUpdateAlbumArtUriFromAlbumIdQuery.lastQuery(); qDebug() << "DatabaseInterface::updateIsSingleDiscAlbumFromId" << d->mUpdateAlbumArtUriFromAlbumIdQuery.boundValues(); qDebug() << "DatabaseInterface::updateIsSingleDiscAlbumFromId" << d->mUpdateAlbumArtUriFromAlbumIdQuery.lastError(); d->mUpdateAlbumArtUriFromAlbumIdQuery.finish(); return modifiedAlbum; } d->mUpdateAlbumArtUriFromAlbumIdQuery.finish(); modifiedAlbum = true; } if (!isValidArtist(albumId) && currentTrack.isValidAlbumArtist()) { d->mRemoveAlbumArtistQuery.bindValue(QStringLiteral(":albumId"), albumId); result = d->mRemoveAlbumArtistQuery.exec(); if (!result || !d->mRemoveAlbumArtistQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::updateIsSingleDiscAlbumFromId" << d->mRemoveAlbumArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::updateIsSingleDiscAlbumFromId" << d->mRemoveAlbumArtistQuery.boundValues(); qDebug() << "DatabaseInterface::updateIsSingleDiscAlbumFromId" << d->mRemoveAlbumArtistQuery.lastError(); d->mRemoveAlbumArtistQuery.finish(); return modifiedAlbum; } d->mRemoveAlbumArtistQuery.finish(); d->mInsertAlbumArtistQuery.bindValue(QStringLiteral(":albumId"), albumId); d->mInsertAlbumArtistQuery.bindValue(QStringLiteral(":artistId"), insertArtist(currentTrack.albumArtist(), newArtistsIds)); result = d->mInsertAlbumArtistQuery.exec(); if (!result || !d->mInsertAlbumArtistQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::updateIsSingleDiscAlbumFromId" << d->mInsertAlbumArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::updateIsSingleDiscAlbumFromId" << d->mInsertAlbumArtistQuery.boundValues(); qDebug() << "DatabaseInterface::updateIsSingleDiscAlbumFromId" << d->mInsertAlbumArtistQuery.lastError(); d->mInsertAlbumArtistQuery.finish(); return modifiedAlbum; } d->mInsertAlbumArtistQuery.finish(); modifiedAlbum = true; } return modifiedAlbum; } qulonglong DatabaseInterface::insertArtist(const QString &name, QList &newArtistsIds) { auto result = qulonglong(0); if (name.isEmpty()) { return result; } d->mSelectArtistByNameQuery.bindValue(QStringLiteral(":name"), name); auto queryResult = d->mSelectArtistByNameQuery.exec(); if (!queryResult || !d->mSelectArtistByNameQuery.isSelect() || !d->mSelectArtistByNameQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertArtist" << d->mSelectArtistByNameQuery.lastQuery(); qDebug() << "DatabaseInterface::insertArtist" << d->mSelectArtistByNameQuery.boundValues(); qDebug() << "DatabaseInterface::insertArtist" << d->mSelectArtistByNameQuery.lastError(); d->mSelectArtistByNameQuery.finish(); return result; } if (d->mSelectArtistByNameQuery.next()) { result = d->mSelectArtistByNameQuery.record().value(0).toULongLong(); d->mSelectArtistByNameQuery.finish(); return result; } d->mSelectArtistByNameQuery.finish(); d->mInsertArtistsQuery.bindValue(QStringLiteral(":artistId"), d->mArtistId); d->mInsertArtistsQuery.bindValue(QStringLiteral(":name"), name); queryResult = d->mInsertArtistsQuery.exec(); if (!queryResult || !d->mInsertArtistsQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertArtist" << d->mInsertArtistsQuery.lastQuery(); qDebug() << "DatabaseInterface::insertArtist" << d->mInsertArtistsQuery.boundValues(); qDebug() << "DatabaseInterface::insertArtist" << d->mInsertArtistsQuery.lastError(); d->mInsertArtistsQuery.finish(); return result; } result = d->mArtistId; ++d->mArtistId; newArtistsIds.push_back(result); d->mInsertArtistsQuery.finish(); return result; } qulonglong DatabaseInterface::insertComposer(const QString &name) { auto result = qulonglong(0); if (name.isEmpty()) { return result; } d->mSelectComposerByNameQuery.bindValue(QStringLiteral(":name"), name); auto queryResult = d->mSelectComposerByNameQuery.exec(); if (!queryResult || !d->mSelectComposerByNameQuery.isSelect() || !d->mSelectComposerByNameQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertComposer" << d->mSelectComposerByNameQuery.lastQuery(); qDebug() << "DatabaseInterface::insertComposer" << d->mSelectComposerByNameQuery.boundValues(); qDebug() << "DatabaseInterface::insertComposer" << d->mSelectComposerByNameQuery.lastError(); d->mSelectComposerByNameQuery.finish(); return result; } if (d->mSelectComposerByNameQuery.next()) { result = d->mSelectComposerByNameQuery.record().value(0).toULongLong(); d->mSelectComposerByNameQuery.finish(); return result; } d->mSelectComposerByNameQuery.finish(); d->mInsertComposerQuery.bindValue(QStringLiteral(":composerId"), d->mComposerId); d->mInsertComposerQuery.bindValue(QStringLiteral(":name"), name); queryResult = d->mInsertComposerQuery.exec(); if (!queryResult || !d->mInsertComposerQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertComposer" << d->mInsertComposerQuery.lastQuery(); qDebug() << "DatabaseInterface::insertComposer" << d->mInsertComposerQuery.boundValues(); qDebug() << "DatabaseInterface::insertComposer" << d->mInsertComposerQuery.lastError(); d->mInsertComposerQuery.finish(); return result; } result = d->mComposerId; ++d->mComposerId; d->mInsertComposerQuery.finish(); Q_EMIT composersAdded({internalComposerFromId(d->mComposerId - 1)}); return result; } qulonglong DatabaseInterface::insertGenre(const QString &name) { auto result = qulonglong(0); if (name.isEmpty()) { return result; } d->mSelectGenreByNameQuery.bindValue(QStringLiteral(":name"), name); auto queryResult = d->mSelectGenreByNameQuery.exec(); if (!queryResult || !d->mSelectGenreByNameQuery.isSelect() || !d->mSelectGenreByNameQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertGenre" << d->mSelectGenreByNameQuery.lastQuery(); qDebug() << "DatabaseInterface::insertGenre" << d->mSelectGenreByNameQuery.boundValues(); qDebug() << "DatabaseInterface::insertGenre" << d->mSelectGenreByNameQuery.lastError(); d->mSelectGenreByNameQuery.finish(); return result; } if (d->mSelectGenreByNameQuery.next()) { result = d->mSelectGenreByNameQuery.record().value(0).toULongLong(); d->mSelectGenreByNameQuery.finish(); return result; } d->mSelectGenreByNameQuery.finish(); d->mInsertGenreQuery.bindValue(QStringLiteral(":genreId"), d->mGenreId); d->mInsertGenreQuery.bindValue(QStringLiteral(":name"), name); queryResult = d->mInsertGenreQuery.exec(); if (!queryResult || !d->mInsertGenreQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertGenre" << d->mInsertGenreQuery.lastQuery(); qDebug() << "DatabaseInterface::insertGenre" << d->mInsertGenreQuery.boundValues(); qDebug() << "DatabaseInterface::insertGenre" << d->mInsertGenreQuery.lastError(); d->mInsertGenreQuery.finish(); return result; } result = d->mGenreId; ++d->mGenreId; d->mInsertGenreQuery.finish(); Q_EMIT genresAdded({internalGenreFromId(d->mGenreId - 1)}); return result; } MusicAudioGenre DatabaseInterface::internalGenreFromId(qulonglong genreId) { auto result = MusicAudioGenre{}; if (!d || !d->mTracksDatabase.isValid() || !d->mInitFinished) { return result; } d->mSelectGenreQuery.bindValue(QStringLiteral(":genreId"), genreId); auto queryResult = d->mSelectGenreQuery.exec(); if (!queryResult || !d->mSelectGenreQuery.isSelect() || !d->mSelectGenreQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::internalGenreFromId" << d->mSelectGenreQuery.lastQuery(); qDebug() << "DatabaseInterface::internalGenreFromId" << d->mSelectGenreQuery.boundValues(); qDebug() << "DatabaseInterface::internalGenreFromId" << d->mSelectGenreQuery.lastError(); d->mSelectGenreQuery.finish(); return result; } if (!d->mSelectGenreQuery.next()) { d->mSelectGenreQuery.finish(); return result; } const auto ¤tRecord = d->mSelectGenreQuery.record(); result.setDatabaseId(currentRecord.value(0).toULongLong()); result.setName(currentRecord.value(1).toString()); d->mSelectGenreQuery.finish(); return result; } void DatabaseInterface::insertTrackOrigin(const QUrl &fileNameURI, const QDateTime &fileModifiedTime, qulonglong discoverId) { d->mInsertTrackMapping.bindValue(QStringLiteral(":discoverId"), discoverId); d->mInsertTrackMapping.bindValue(QStringLiteral(":fileName"), fileNameURI); d->mInsertTrackMapping.bindValue(QStringLiteral(":priority"), 1); d->mInsertTrackMapping.bindValue(QStringLiteral(":mtime"), fileModifiedTime); auto queryResult = d->mInsertTrackMapping.exec(); if (!queryResult || !d->mInsertTrackMapping.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertArtist" << d->mInsertTrackMapping.lastQuery(); qDebug() << "DatabaseInterface::insertArtist" << d->mInsertTrackMapping.boundValues(); qDebug() << "DatabaseInterface::insertArtist" << d->mInsertTrackMapping.lastError(); d->mInsertTrackMapping.finish(); return; } d->mInsertTrackMapping.finish(); } void DatabaseInterface::updateTrackOrigin(qulonglong trackId, const QUrl &fileName, const QDateTime &fileModifiedTime) { d->mUpdateTrackMapping.bindValue(QStringLiteral(":trackId"), trackId); d->mUpdateTrackMapping.bindValue(QStringLiteral(":fileName"), fileName); d->mUpdateTrackMapping.bindValue(QStringLiteral(":priority"), computeTrackPriority(trackId, fileName)); d->mUpdateTrackMapping.bindValue(QStringLiteral(":mtime"), fileModifiedTime); auto queryResult = d->mUpdateTrackMapping.exec(); if (!queryResult || !d->mUpdateTrackMapping.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::updateTrackOrigin" << d->mUpdateTrackMapping.lastQuery(); qDebug() << "DatabaseInterface::updateTrackOrigin" << d->mUpdateTrackMapping.boundValues(); qDebug() << "DatabaseInterface::updateTrackOrigin" << d->mUpdateTrackMapping.lastError(); d->mUpdateTrackMapping.finish(); return; } d->mInsertTrackMapping.finish(); } int DatabaseInterface::computeTrackPriority(qulonglong trackId, const QUrl &fileName) { auto result = int(1); if (!d) { return result; } d->mSelectTracksMappingPriority.bindValue(QStringLiteral(":trackId"), trackId); d->mSelectTracksMappingPriority.bindValue(QStringLiteral(":fileName"), fileName); auto queryResult = d->mSelectTracksMappingPriority.exec(); if (!queryResult || !d->mSelectTracksMappingPriority.isSelect() || !d->mSelectTracksMappingPriority.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::internalTrackIdFromFileName" << d->mSelectTracksMappingPriority.lastQuery(); qDebug() << "DatabaseInterface::internalTrackIdFromFileName" << d->mSelectTracksMappingPriority.boundValues(); qDebug() << "DatabaseInterface::internalTrackIdFromFileName" << d->mSelectTracksMappingPriority.lastError(); d->mSelectTracksMappingPriority.finish(); return result; } if (d->mSelectTracksMappingPriority.next()) { result = d->mSelectTracksMappingPriority.record().value(0).toInt(); d->mSelectTracksMappingPriority.finish(); return result; } d->mSelectTracksMappingPriority.finish(); d->mSelectTracksMappingPriorityByTrackId.bindValue(QStringLiteral(":trackId"), trackId); queryResult = d->mSelectTracksMappingPriorityByTrackId.exec(); if (!queryResult || !d->mSelectTracksMappingPriorityByTrackId.isSelect() || !d->mSelectTracksMappingPriorityByTrackId.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::internalTrackIdFromFileName" << d->mSelectTracksMappingPriorityByTrackId.lastQuery(); qDebug() << "DatabaseInterface::internalTrackIdFromFileName" << d->mSelectTracksMappingPriorityByTrackId.boundValues(); qDebug() << "DatabaseInterface::internalTrackIdFromFileName" << d->mSelectTracksMappingPriorityByTrackId.lastError(); d->mSelectTracksMappingPriorityByTrackId.finish(); return result; } if (d->mSelectTracksMappingPriorityByTrackId.next()) { result = d->mSelectTracksMappingPriorityByTrackId.record().value(0).toInt() + 1; } d->mSelectTracksMappingPriorityByTrackId.finish(); return result; } qulonglong DatabaseInterface::internalInsertTrack(const MusicAudioTrack &oneTrack, const QHash &covers, qulonglong originTrackId, QSet &modifiedAlbumIds, TrackFileInsertType insertType, QList &newAlbumIds, QList &newArtistsIds, QSet &modifiedTrackIds) { qulonglong resultId = 0; auto oldTrack = oneTrack; if (oneTrack.albumArtist().isEmpty()) { return resultId; } QUrl::FormattingOptions currentOptions = QUrl::PreferLocalFile | QUrl::RemoveAuthority | QUrl::RemoveFilename | QUrl::RemoveFragment | QUrl::RemovePassword | QUrl::RemovePort | QUrl::RemoveQuery | QUrl::RemoveScheme | QUrl::RemoveUserInfo; const auto &trackPath = oneTrack.resourceURI().toString(currentOptions); auto albumId = insertAlbum(oneTrack.albumName(), (oneTrack.isValidAlbumArtist() ? oneTrack.albumArtist() : QString()), oneTrack.artist(), trackPath, covers[oneTrack.resourceURI().toString()], 0, SingleDiscAlbum, newAlbumIds, newArtistsIds); if (albumId == 0) { return resultId; } auto otherTrackId = getDuplicateTrackIdFromTitleAlbumTrackDiscNumber(oneTrack.title(), oneTrack.albumName(), oneTrack.albumArtist(), trackPath, oneTrack.trackNumber(), oneTrack.discNumber()); bool isModifiedTrack = (otherTrackId != 0) || (insertType == TrackFileInsertType::ModifiedTrackFileInsert); bool isSameTrack = false; qulonglong oldAlbumId = 0; if (isModifiedTrack) { if (otherTrackId == 0) { otherTrackId = internalTrackIdFromFileName(oneTrack.resourceURI()); } originTrackId = otherTrackId; oldTrack = internalTrackFromDatabaseId(originTrackId); isSameTrack = (oldTrack.title() == oneTrack.title()); isSameTrack = isSameTrack && (oldTrack.albumName() == oneTrack.albumName()); isSameTrack = isSameTrack && (oldTrack.artist() == oneTrack.artist()); isSameTrack = isSameTrack && (oldTrack.trackNumber() == oneTrack.trackNumber()); isSameTrack = isSameTrack && (oldTrack.discNumber() == oneTrack.discNumber()); isSameTrack = isSameTrack && (oldTrack.duration() == oneTrack.duration()); isSameTrack = isSameTrack && (oldTrack.rating() == oneTrack.rating()); isSameTrack = isSameTrack && (oldTrack.resourceURI() == oneTrack.resourceURI()); isSameTrack = isSameTrack && (oldTrack.genre() == oneTrack.genre()); isSameTrack = isSameTrack && (oldTrack.composer() == oneTrack.composer()); isSameTrack = isSameTrack && (oldTrack.lyricist() == oneTrack.lyricist()); isSameTrack = isSameTrack && (oldTrack.comment() == oneTrack.comment()); isSameTrack = isSameTrack && (oldTrack.year() == oneTrack.year()); isSameTrack = isSameTrack && (oldTrack.channels() == oneTrack.channels()); isSameTrack = isSameTrack && (oldTrack.bitRate() == oneTrack.bitRate()); isSameTrack = isSameTrack && (oldTrack.sampleRate() == oneTrack.sampleRate()); oldAlbumId = internalAlbumIdFromTitleAndArtist(oldTrack.albumName(), oldTrack.albumArtist()); if (!isSameTrack) { auto newTrack = oneTrack; newTrack.setDatabaseId(oldTrack.databaseId()); updateTrackInDatabase(newTrack, albumId, newArtistsIds); updateTrackOrigin(newTrack.databaseId(), oneTrack.resourceURI(), oneTrack.fileModificationTime()); updateAlbumFromId(albumId, oneTrack.albumCover(), oneTrack, newArtistsIds); Q_EMIT trackModified(internalTrackFromDatabaseId(originTrackId)); modifiedAlbumIds.insert(albumId); if (oldAlbumId != 0) { modifiedAlbumIds.insert(oldAlbumId); } isSameTrack = true; } } else { originTrackId = d->mTrackId; } resultId = originTrackId; if (!isSameTrack) { d->mInsertTrackQuery.bindValue(QStringLiteral(":trackId"), originTrackId); d->mInsertTrackQuery.bindValue(QStringLiteral(":title"), oneTrack.title()); d->mInsertTrackQuery.bindValue(QStringLiteral(":album"), albumId); d->mInsertTrackQuery.bindValue(QStringLiteral(":trackNumber"), oneTrack.trackNumber()); d->mInsertTrackQuery.bindValue(QStringLiteral(":discNumber"), oneTrack.discNumber()); d->mInsertTrackQuery.bindValue(QStringLiteral(":trackDuration"), QVariant::fromValue(oneTrack.duration().msecsSinceStartOfDay())); d->mInsertTrackQuery.bindValue(QStringLiteral(":trackRating"), oneTrack.rating()); auto genreId = insertGenre(oneTrack.genre()); if (genreId != 0) { d->mInsertTrackQuery.bindValue(QStringLiteral(":genreId"), genreId); } else { d->mInsertTrackQuery.bindValue(QStringLiteral(":genreId"), {}); } auto composerId = insertComposer(oneTrack.composer()); if (composerId != 0) { d->mInsertTrackQuery.bindValue(QStringLiteral(":composerId"), composerId); } else { d->mInsertTrackQuery.bindValue(QStringLiteral(":composerId"), {}); } auto lyricistId = insertLyricist(oneTrack.lyricist()); if (lyricistId != 0) { d->mInsertTrackQuery.bindValue(QStringLiteral(":lyricistId"), lyricistId); } else { d->mInsertTrackQuery.bindValue(QStringLiteral(":lyricistId"), {}); } d->mInsertTrackQuery.bindValue(QStringLiteral(":comment"), oneTrack.comment()); d->mInsertTrackQuery.bindValue(QStringLiteral(":year"), oneTrack.year()); d->mInsertTrackQuery.bindValue(QStringLiteral(":channels"), oneTrack.channels()); d->mInsertTrackQuery.bindValue(QStringLiteral(":bitRate"), oneTrack.bitRate()); d->mInsertTrackQuery.bindValue(QStringLiteral(":sampleRate"), oneTrack.sampleRate()); auto result = d->mInsertTrackQuery.exec(); if (result && d->mInsertTrackQuery.isActive()) { d->mInsertTrackQuery.finish(); if (!isModifiedTrack || (!isSameTrack && oneTrack.artist() != oldTrack.artist())) { d->mInsertTrackArtistQuery.bindValue(QStringLiteral(":trackId"), originTrackId); d->mInsertTrackArtistQuery.bindValue(QStringLiteral(":artistId"), insertArtist(oneTrack.artist(), newArtistsIds)); result = d->mInsertTrackArtistQuery.exec(); if (!result || !d->mInsertTrackArtistQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::internalInsertTrack" << d->mInsertTrackArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::internalInsertTrack" << d->mInsertTrackArtistQuery.boundValues(); qDebug() << "DatabaseInterface::internalInsertTrack" << d->mInsertTrackArtistQuery.lastError(); d->mInsertTrackArtistQuery.finish(); return resultId; } d->mInsertTrackArtistQuery.finish(); } if (!isModifiedTrack) { ++d->mTrackId; } updateTrackOrigin(originTrackId, oneTrack.resourceURI(), oneTrack.fileModificationTime()); if (isModifiedTrack) { Q_EMIT trackModified(internalTrackFromDatabaseId(originTrackId)); modifiedAlbumIds.insert(albumId); if (oldAlbumId != 0) { modifiedAlbumIds.insert(oldAlbumId); } } if (updateAlbumFromId(albumId, covers[oneTrack.resourceURI().toString()], oneTrack, newArtistsIds)) { auto modifiedTracks = fetchTrackIds(albumId); for (auto oneModifiedTrack : modifiedTracks) { if (oneModifiedTrack != resultId) { modifiedTrackIds.insert(oneModifiedTrack); } } modifiedAlbumIds.insert(albumId); } if (updateTracksCount(albumId)) { modifiedAlbumIds.insert(albumId); } } else { d->mInsertTrackQuery.finish(); Q_EMIT databaseError(); qDebug() << "DatabaseInterface::internalInsertTrack" << oneTrack << oneTrack.resourceURI(); qDebug() << "DatabaseInterface::internalInsertTrack" << d->mInsertTrackQuery.lastQuery(); qDebug() << "DatabaseInterface::internalInsertTrack" << d->mInsertTrackQuery.boundValues(); qDebug() << "DatabaseInterface::internalInsertTrack" << d->mInsertTrackQuery.lastError(); } } return resultId; } MusicAudioTrack DatabaseInterface::buildTrackFromDatabaseRecord(const QSqlRecord &trackRecord) const { auto result = MusicAudioTrack(); result.setDatabaseId(trackRecord.value(0).toULongLong()); result.setTitle(trackRecord.value(1).toString()); result.setParentId(trackRecord.value(2).toString()); result.setArtist(trackRecord.value(3).toString()); if (trackRecord.value(4).isValid()) { result.setAlbumArtist(trackRecord.value(4).toString()); } result.setResourceURI(trackRecord.value(5).toUrl()); result.setFileModificationTime(trackRecord.value(6).toDateTime()); result.setTrackNumber(trackRecord.value(7).toInt()); result.setDiscNumber(trackRecord.value(8).toInt()); result.setDuration(QTime::fromMSecsSinceStartOfDay(trackRecord.value(9).toInt())); result.setAlbumName(trackRecord.value(10).toString()); result.setRating(trackRecord.value(11).toInt()); result.setAlbumCover(trackRecord.value(12).toUrl()); result.setIsSingleDiscAlbum(trackRecord.value(13).toBool()); result.setGenre(trackRecord.value(14).toString()); result.setComposer(trackRecord.value(15).toString()); result.setLyricist(trackRecord.value(16).toString()); result.setComment(trackRecord.value(17).toString()); result.setYear(trackRecord.value(18).toInt()); result.setChannels(trackRecord.value(19).toInt()); result.setBitRate(trackRecord.value(20).toInt()); result.setSampleRate(trackRecord.value(21).toInt()); result.setAlbumId(trackRecord.value(2).toULongLong()); result.setValid(true); return result; } void DatabaseInterface::internalRemoveTracksList(const QList &removedTracks, QList &newArtistsIds) { for (const auto &removedTrackFileName : removedTracks) { d->mRemoveTracksMapping.bindValue(QStringLiteral(":fileName"), removedTrackFileName.toString()); auto result = d->mRemoveTracksMapping.exec(); if (!result || !d->mRemoveTracksMapping.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::internalRemoveTracksList" << d->mRemoveTracksMapping.lastQuery(); qDebug() << "DatabaseInterface::internalRemoveTracksList" << d->mRemoveTracksMapping.boundValues(); qDebug() << "DatabaseInterface::internalRemoveTracksList" << d->mRemoveTracksMapping.lastError(); continue; } d->mRemoveTracksMapping.finish(); } internalRemoveTracksWithoutMapping(newArtistsIds); } void DatabaseInterface::internalRemoveTracksList(const QHash &removedTracks, qulonglong sourceId, QList &newArtistsIds) { for (auto itRemovedTrack = removedTracks.begin(); itRemovedTrack != removedTracks.end(); ++itRemovedTrack) { d->mRemoveTracksMappingFromSource.bindValue(QStringLiteral(":fileName"), itRemovedTrack.key().toString()); d->mRemoveTracksMappingFromSource.bindValue(QStringLiteral(":sourceId"), sourceId); auto result = d->mRemoveTracksMappingFromSource.exec(); if (!result || !d->mRemoveTracksMappingFromSource.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::removeTracksList" << d->mRemoveTracksMappingFromSource.lastQuery(); qDebug() << "DatabaseInterface::removeTracksList" << d->mRemoveTracksMappingFromSource.boundValues(); qDebug() << "DatabaseInterface::removeTracksList" << d->mRemoveTracksMappingFromSource.lastError(); continue; } d->mRemoveTracksMappingFromSource.finish(); } internalRemoveTracksWithoutMapping(newArtistsIds); } void DatabaseInterface::internalRemoveTracksWithoutMapping(QList &newArtistsIds) { auto queryResult = d->mSelectTracksWithoutMappingQuery.exec(); if (!queryResult || !d->mSelectTracksWithoutMappingQuery.isSelect() || !d->mSelectTracksWithoutMappingQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertArtist" << d->mSelectTracksWithoutMappingQuery.lastQuery(); qDebug() << "DatabaseInterface::insertArtist" << d->mSelectTracksWithoutMappingQuery.boundValues(); qDebug() << "DatabaseInterface::insertArtist" << d->mSelectTracksWithoutMappingQuery.lastError(); d->mSelectTracksWithoutMappingQuery.finish(); return; } QList willRemoveTrack; while (d->mSelectTracksWithoutMappingQuery.next()) { const auto ¤tRecord = d->mSelectTracksWithoutMappingQuery.record(); willRemoveTrack.push_back(buildTrackFromDatabaseRecord(currentRecord)); } d->mSelectTracksWithoutMappingQuery.finish(); QSet modifiedAlbums; for (const auto &oneRemovedTrack : willRemoveTrack) { removeTrackInDatabase(oneRemovedTrack.databaseId()); Q_EMIT trackRemoved(oneRemovedTrack.databaseId()); const auto &modifiedAlbumId = internalAlbumIdFromTitleAndArtist(oneRemovedTrack.albumName(), oneRemovedTrack.albumArtist()); const auto &allTracksFromArtist = internalTracksFromAuthor(oneRemovedTrack.artist()); const auto &allAlbumsFromArtist = internalAlbumIdsFromAuthor(oneRemovedTrack.artist()); const auto &removedArtistId = internalArtistIdFromName(oneRemovedTrack.artist()); const auto &removedArtist = internalArtistFromId(removedArtistId); if (updateTracksCount(modifiedAlbumId)) { modifiedAlbums.insert(modifiedAlbumId); } updateAlbumFromId(modifiedAlbumId, oneRemovedTrack.albumCover(), oneRemovedTrack, newArtistsIds); if (allTracksFromArtist.isEmpty() && allAlbumsFromArtist.isEmpty()) { removeArtistInDatabase(removedArtistId); Q_EMIT artistRemoved(removedArtist); } } for (auto modifiedAlbumId : modifiedAlbums) { auto modifiedAlbum = internalAlbumFromId(modifiedAlbumId); if (modifiedAlbum.isValid() && !modifiedAlbum.isEmpty()) { Q_EMIT albumModified(modifiedAlbum, modifiedAlbumId); } else { removeAlbumInDatabase(modifiedAlbum.databaseId()); Q_EMIT albumRemoved(modifiedAlbum, modifiedAlbumId); const auto &allTracksFromArtist = internalTracksFromAuthor(modifiedAlbum.artist()); const auto &allAlbumsFromArtist = internalAlbumIdsFromAuthor(modifiedAlbum.artist()); const auto &removedArtistId = internalArtistIdFromName(modifiedAlbum.artist()); const auto &removedArtist = internalArtistFromId(removedArtistId); if (allTracksFromArtist.isEmpty() && allAlbumsFromArtist.isEmpty()) { removeArtistInDatabase(removedArtistId); Q_EMIT artistRemoved(removedArtist); } } } } QUrl DatabaseInterface::internalAlbumArtUriFromAlbumId(qulonglong albumId) { auto result = QUrl(); d->mSelectAlbumArtUriFromAlbumIdQuery.bindValue(QStringLiteral(":albumId"), albumId); auto queryResult = d->mSelectAlbumArtUriFromAlbumIdQuery.exec(); if (!queryResult || !d->mSelectAlbumArtUriFromAlbumIdQuery.isSelect() || !d->mSelectAlbumArtUriFromAlbumIdQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertArtist" << d->mSelectAlbumArtUriFromAlbumIdQuery.lastQuery(); qDebug() << "DatabaseInterface::insertArtist" << d->mSelectAlbumArtUriFromAlbumIdQuery.boundValues(); qDebug() << "DatabaseInterface::insertArtist" << d->mSelectAlbumArtUriFromAlbumIdQuery.lastError(); d->mSelectAlbumArtUriFromAlbumIdQuery.finish(); return result; } if (!d->mSelectAlbumArtUriFromAlbumIdQuery.next()) { d->mSelectAlbumArtUriFromAlbumIdQuery.finish(); return result; } result = d->mSelectAlbumArtUriFromAlbumIdQuery.record().value(0).toUrl(); d->mSelectAlbumArtUriFromAlbumIdQuery.finish(); return result; } bool DatabaseInterface::isValidArtist(qulonglong albumId) { auto result = false; d->mSelectAlbumQuery.bindValue(QStringLiteral(":albumId"), albumId); auto queryResult = d->mSelectAlbumQuery.exec(); if (!queryResult || !d->mSelectAlbumQuery.isSelect() || !d->mSelectAlbumQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::internalAlbumFromId" << d->mSelectAlbumQuery.lastQuery(); qDebug() << "DatabaseInterface::internalAlbumFromId" << d->mSelectAlbumQuery.boundValues(); qDebug() << "DatabaseInterface::internalAlbumFromId" << d->mSelectAlbumQuery.lastError(); d->mSelectAlbumQuery.finish(); return result; } if (!d->mSelectAlbumQuery.next()) { d->mSelectAlbumQuery.finish(); return result; } const auto ¤tRecord = d->mSelectAlbumQuery.record(); result = !currentRecord.value(3).toString().isEmpty(); return result; } qulonglong DatabaseInterface::internalSourceIdFromName(const QString &sourceName) { qulonglong sourceId = 0; d->mSelectMusicSource.bindValue(QStringLiteral(":name"), sourceName); auto queryResult = d->mSelectMusicSource.exec(); if (!queryResult || !d->mSelectMusicSource.isSelect() || !d->mSelectMusicSource.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertMusicSource" << d->mSelectMusicSource.lastQuery(); qDebug() << "DatabaseInterface::insertMusicSource" << d->mSelectMusicSource.boundValues(); qDebug() << "DatabaseInterface::insertMusicSource" << d->mSelectMusicSource.lastError(); d->mSelectMusicSource.finish(); return sourceId; } if (!d->mSelectMusicSource.next()) { return sourceId; } sourceId = d->mSelectMusicSource.record().value(0).toULongLong(); return sourceId; } QHash DatabaseInterface::internalAllFileNameFromSource(qulonglong sourceId) { QHash allFileNames; d->mSelectMusicSource.finish(); d->mSelectAllTrackFilesFromSourceQuery.bindValue(QStringLiteral(":discoverId"), sourceId); auto queryResult = d->mSelectAllTrackFilesFromSourceQuery.exec(); if (!queryResult || !d->mSelectAllTrackFilesFromSourceQuery.isSelect() || !d->mSelectAllTrackFilesFromSourceQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertMusicSource" << d->mSelectAllTrackFilesFromSourceQuery.lastQuery(); qDebug() << "DatabaseInterface::insertMusicSource" << d->mSelectAllTrackFilesFromSourceQuery.boundValues(); qDebug() << "DatabaseInterface::insertMusicSource" << d->mSelectAllTrackFilesFromSourceQuery.lastError(); d->mSelectAllTrackFilesFromSourceQuery.finish(); return allFileNames; } while(d->mSelectAllTrackFilesFromSourceQuery.next()) { auto fileName = d->mSelectAllTrackFilesFromSourceQuery.record().value(0).toUrl(); auto fileModificationTime = d->mSelectAllTrackFilesFromSourceQuery.record().value(1).toDateTime(); allFileNames[fileName] = fileModificationTime; } d->mSelectAllTrackFilesFromSourceQuery.finish(); return allFileNames; } QList > DatabaseInterface::internalAllGenericPartialData(QSqlQuery &query, int nbFields) { auto result = QList>{}; auto queryResult = query.exec(); if (!queryResult || !query.isSelect() || !query.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::allArtists" << query.lastQuery(); qDebug() << "DatabaseInterface::allArtists" << query.boundValues(); qDebug() << "DatabaseInterface::allArtists" << query.lastError(); query.finish(); auto transactionResult = finishTransaction(); if (!transactionResult) { return result; } return result; } while(query.next()) { auto newData = QMap{}; const auto ¤tRecord = query.record(); newData[DatabaseId] = currentRecord.value(0); newData[DisplayRole] = currentRecord.value(1); if (nbFields == 2) { newData[SecondaryRole] = currentRecord.value(2); } result.push_back(newData); } query.finish(); return result; } MusicArtist DatabaseInterface::internalComposerFromId(qulonglong composerId) { auto result = MusicArtist(); if (!d || !d->mTracksDatabase.isValid() || !d->mInitFinished) { return result; } d->mSelectComposerQuery.bindValue(QStringLiteral(":composerId"), composerId); auto queryResult = d->mSelectComposerQuery.exec(); if (!queryResult || !d->mSelectComposerQuery.isSelect() || !d->mSelectComposerQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::internalComposerFromId" << d->mSelectComposerQuery.lastQuery(); qDebug() << "DatabaseInterface::internalComposerFromId" << d->mSelectComposerQuery.boundValues(); qDebug() << "DatabaseInterface::internalComposerFromId" << d->mSelectComposerQuery.lastError(); d->mSelectComposerQuery.finish(); return result; } if (!d->mSelectComposerQuery.next()) { d->mSelectComposerQuery.finish(); return result; } const auto ¤tRecord = d->mSelectComposerQuery.record(); result.setDatabaseId(currentRecord.value(0).toULongLong()); result.setName(currentRecord.value(1).toString()); result.setValid(true); d->mSelectComposerQuery.finish(); return result; } qulonglong DatabaseInterface::insertLyricist(const QString &name) { auto result = qulonglong(0); if (name.isEmpty()) { return result; } d->mSelectLyricistByNameQuery.bindValue(QStringLiteral(":name"), name); auto queryResult = d->mSelectLyricistByNameQuery.exec(); if (!queryResult || !d->mSelectLyricistByNameQuery.isSelect() || !d->mSelectLyricistByNameQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertLyricist" << d->mSelectLyricistByNameQuery.lastQuery(); qDebug() << "DatabaseInterface::insertLyricist" << d->mSelectLyricistByNameQuery.boundValues(); qDebug() << "DatabaseInterface::insertLyricist" << d->mSelectLyricistByNameQuery.lastError(); d->mSelectLyricistByNameQuery.finish(); return result; } if (d->mSelectLyricistByNameQuery.next()) { result = d->mSelectLyricistByNameQuery.record().value(0).toULongLong(); d->mSelectLyricistByNameQuery.finish(); return result; } d->mSelectLyricistByNameQuery.finish(); d->mInsertLyricistQuery.bindValue(QStringLiteral(":lyricistId"), d->mLyricistId); d->mInsertLyricistQuery.bindValue(QStringLiteral(":name"), name); queryResult = d->mInsertLyricistQuery.exec(); if (!queryResult || !d->mInsertLyricistQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertLyricist" << d->mInsertLyricistQuery.lastQuery(); qDebug() << "DatabaseInterface::insertLyricist" << d->mInsertLyricistQuery.boundValues(); qDebug() << "DatabaseInterface::insertLyricist" << d->mInsertLyricistQuery.lastError(); d->mInsertLyricistQuery.finish(); return result; } result = d->mLyricistId; ++d->mLyricistId; d->mInsertLyricistQuery.finish(); Q_EMIT lyricistsAdded({internalLyricistFromId(d->mLyricistId - 1)}); return result; } MusicArtist DatabaseInterface::internalLyricistFromId(qulonglong lyricistId) { auto result = MusicArtist(); if (!d || !d->mTracksDatabase.isValid() || !d->mInitFinished) { return result; } d->mSelectLyricistQuery.bindValue(QStringLiteral(":lyricistId"), lyricistId); auto queryResult = d->mSelectLyricistQuery.exec(); if (!queryResult || !d->mSelectLyricistQuery.isSelect() || !d->mSelectLyricistQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::internalLyricistFromId" << d->mSelectLyricistQuery.lastQuery(); qDebug() << "DatabaseInterface::internalLyricistFromId" << d->mSelectLyricistQuery.boundValues(); qDebug() << "DatabaseInterface::internalLyricistFromId" << d->mSelectLyricistQuery.lastError(); d->mSelectLyricistQuery.finish(); return result; } if (!d->mSelectLyricistQuery.next()) { d->mSelectLyricistQuery.finish(); return result; } const auto ¤tRecord = d->mSelectLyricistQuery.record(); result.setDatabaseId(currentRecord.value(0).toULongLong()); result.setName(currentRecord.value(1).toString()); result.setValid(true); d->mSelectLyricistQuery.finish(); return result; } qulonglong DatabaseInterface::internalArtistIdFromName(const QString &name) { auto result = qulonglong(0); if (name.isEmpty()) { return result; } d->mSelectArtistByNameQuery.bindValue(QStringLiteral(":name"), name); auto queryResult = d->mSelectArtistByNameQuery.exec(); if (!queryResult || !d->mSelectArtistByNameQuery.isSelect() || !d->mSelectArtistByNameQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertArtist" << d->mSelectArtistByNameQuery.lastQuery(); qDebug() << "DatabaseInterface::insertArtist" << d->mSelectArtistByNameQuery.boundValues(); qDebug() << "DatabaseInterface::insertArtist" << d->mSelectArtistByNameQuery.lastError(); d->mSelectArtistByNameQuery.finish(); return result; } if (!d->mSelectArtistByNameQuery.next()) { d->mSelectArtistByNameQuery.finish(); return result; } result = d->mSelectArtistByNameQuery.record().value(0).toULongLong(); d->mSelectArtistByNameQuery.finish(); return result; } void DatabaseInterface::removeTrackInDatabase(qulonglong trackId) { d->mRemoveTrackArtistQuery.bindValue(QStringLiteral(":trackId"), trackId); auto result = d->mRemoveTrackArtistQuery.exec(); if (!result || !d->mRemoveTrackArtistQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::removeTrackInDatabase" << d->mRemoveTrackArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::removeTrackInDatabase" << d->mRemoveTrackArtistQuery.boundValues(); qDebug() << "DatabaseInterface::removeTrackInDatabase" << d->mRemoveTrackArtistQuery.lastError(); } d->mRemoveTrackArtistQuery.finish(); d->mRemoveTrackQuery.bindValue(QStringLiteral(":trackId"), trackId); result = d->mRemoveTrackQuery.exec(); if (!result || !d->mRemoveTrackQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::removeTrackInDatabase" << d->mRemoveTrackQuery.lastQuery(); qDebug() << "DatabaseInterface::removeTrackInDatabase" << d->mRemoveTrackQuery.boundValues(); qDebug() << "DatabaseInterface::removeTrackInDatabase" << d->mRemoveTrackQuery.lastError(); } d->mRemoveTrackQuery.finish(); } void DatabaseInterface::updateTrackInDatabase(const MusicAudioTrack &oneTrack, qulonglong albumId, QList &newArtistsIds) { d->mUpdateTrackQuery.bindValue(QStringLiteral(":trackId"), oneTrack.databaseId()); d->mUpdateTrackQuery.bindValue(QStringLiteral(":title"), oneTrack.title()); d->mUpdateTrackQuery.bindValue(QStringLiteral(":album"), albumId); d->mUpdateTrackQuery.bindValue(QStringLiteral(":trackNumber"), oneTrack.trackNumber()); d->mUpdateTrackQuery.bindValue(QStringLiteral(":discNumber"), oneTrack.discNumber()); d->mUpdateTrackQuery.bindValue(QStringLiteral(":trackDuration"), QVariant::fromValue(oneTrack.duration().msecsSinceStartOfDay())); d->mUpdateTrackQuery.bindValue(QStringLiteral(":trackRating"), oneTrack.rating()); auto genreId = insertGenre(oneTrack.genre()); if (genreId != 0) { d->mUpdateTrackQuery.bindValue(QStringLiteral(":genreId"), genreId); } else { d->mUpdateTrackQuery.bindValue(QStringLiteral(":genreId"), {}); } auto composerId = insertComposer(oneTrack.composer()); if (composerId != 0) { d->mUpdateTrackQuery.bindValue(QStringLiteral(":composerId"), composerId); } else { d->mUpdateTrackQuery.bindValue(QStringLiteral(":composerId"), {}); } auto lyricistId = insertLyricist(oneTrack.lyricist()); if (lyricistId != 0) { d->mUpdateTrackQuery.bindValue(QStringLiteral(":lyricistId"), lyricistId); } else { d->mUpdateTrackQuery.bindValue(QStringLiteral(":lyricistId"), {}); } d->mUpdateTrackQuery.bindValue(QStringLiteral(":comment"), oneTrack.comment()); d->mUpdateTrackQuery.bindValue(QStringLiteral(":year"), oneTrack.year()); d->mUpdateTrackQuery.bindValue(QStringLiteral(":channels"), oneTrack.channels()); d->mUpdateTrackQuery.bindValue(QStringLiteral(":bitRate"), oneTrack.bitRate()); d->mUpdateTrackQuery.bindValue(QStringLiteral(":sampleRate"), oneTrack.sampleRate()); auto result = d->mUpdateTrackQuery.exec(); if (result && d->mUpdateTrackQuery.isActive()) { d->mUpdateTrackQuery.finish(); d->mRemoveTrackArtistQuery.bindValue(QStringLiteral(":trackId"), oneTrack.databaseId()); auto result = d->mRemoveTrackArtistQuery.exec(); if (!result || !d->mRemoveTrackArtistQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::updateTrackInDatabase" << d->mRemoveTrackArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::updateTrackInDatabase" << d->mRemoveTrackArtistQuery.boundValues(); qDebug() << "DatabaseInterface::updateTrackInDatabase" << d->mRemoveTrackArtistQuery.lastError(); } d->mRemoveTrackArtistQuery.finish(); d->mInsertTrackArtistQuery.bindValue(QStringLiteral(":trackId"), oneTrack.databaseId()); d->mInsertTrackArtistQuery.bindValue(QStringLiteral(":artistId"), insertArtist(oneTrack.artist(), newArtistsIds)); result = d->mInsertTrackArtistQuery.exec(); if (!result || !d->mInsertTrackArtistQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::updateTrackInDatabase" << d->mInsertTrackArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::updateTrackInDatabase" << d->mInsertTrackArtistQuery.boundValues(); qDebug() << "DatabaseInterface::updateTrackInDatabase" << d->mInsertTrackArtistQuery.lastError(); d->mInsertTrackArtistQuery.finish(); return; } d->mInsertTrackArtistQuery.finish(); } else { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::updateTrackInDatabase" << d->mUpdateTrackQuery.lastQuery(); qDebug() << "DatabaseInterface::updateTrackInDatabase" << d->mUpdateTrackQuery.boundValues(); qDebug() << "DatabaseInterface::updateTrackInDatabase" << d->mUpdateTrackQuery.lastError(); d->mUpdateTrackQuery.finish(); return; } } void DatabaseInterface::removeAlbumInDatabase(qulonglong albumId) { d->mRemoveAlbumArtistQuery.bindValue(QStringLiteral(":albumId"), albumId); auto result = d->mRemoveAlbumArtistQuery.exec(); if (!result || !d->mRemoveAlbumArtistQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::removeAlbumInDatabase" << d->mRemoveAlbumArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::removeAlbumInDatabase" << d->mRemoveAlbumArtistQuery.boundValues(); qDebug() << "DatabaseInterface::removeAlbumInDatabase" << d->mRemoveAlbumArtistQuery.lastError(); } d->mRemoveAlbumArtistQuery.finish(); d->mRemoveAlbumQuery.bindValue(QStringLiteral(":albumId"), albumId); result = d->mRemoveAlbumQuery.exec(); if (!result || !d->mRemoveAlbumQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::removeAlbumInDatabase" << d->mRemoveAlbumQuery.lastQuery(); qDebug() << "DatabaseInterface::removeAlbumInDatabase" << d->mRemoveAlbumQuery.boundValues(); qDebug() << "DatabaseInterface::removeAlbumInDatabase" << d->mRemoveAlbumQuery.lastError(); } d->mRemoveAlbumQuery.finish(); } void DatabaseInterface::removeArtistInDatabase(qulonglong artistId) { d->mRemoveArtistQuery.bindValue(QStringLiteral(":artistId"), artistId); auto result = d->mRemoveArtistQuery.exec(); if (!result || !d->mRemoveArtistQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::removeArtistInDatabase" << d->mRemoveArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::removeArtistInDatabase" << d->mRemoveArtistQuery.boundValues(); qDebug() << "DatabaseInterface::removeArtistInDatabase" << d->mRemoveArtistQuery.lastError(); } d->mRemoveArtistQuery.finish(); } void DatabaseInterface::reloadExistingDatabase() { auto transactionResult = startTransaction(); if (!transactionResult) { return; } //d->mInitialUpdateTracksValidity.exec(); qDebug() << "DatabaseInterface::reloadExistingDatabase"; transactionResult = finishTransaction(); if (!transactionResult) { return; } const auto restoredArtists = allArtists(); for (const auto &oneArtist : restoredArtists) { d->mArtistId = std::max(d->mArtistId, oneArtist.databaseId()); } ++d->mArtistId; if (!restoredArtists.isEmpty()) { Q_EMIT artistsAdded(restoredArtists); } const auto restoredComposers = allComposers(); for (const auto &oneComposer : restoredComposers) { d->mComposerId = std::max(d->mComposerId, oneComposer.databaseId()); } ++d->mComposerId; if (!restoredComposers.isEmpty()) { Q_EMIT composersAdded(restoredComposers); } const auto restoredLyricists = allLyricists(); for (const auto &oneLyricist : restoredLyricists) { d->mLyricistId = std::max(d->mLyricistId, oneLyricist.databaseId()); } ++d->mLyricistId; if (!restoredLyricists.isEmpty()) { Q_EMIT lyricistsAdded(restoredLyricists); } const auto restoredAlbums = allAlbums(); for (const auto &oneAlbum : restoredAlbums) { d->mAlbumId = std::max(d->mAlbumId, oneAlbum.databaseId()); } ++d->mAlbumId; if (!restoredAlbums.isEmpty()) { Q_EMIT albumsAdded(restoredAlbums); } const auto restoredTracks = allTracks(); for (const auto &oneTrack : restoredTracks) { d->mTrackId = std::max(d->mTrackId, oneTrack.databaseId()); } ++d->mTrackId; if (!restoredTracks.isEmpty()) { Q_EMIT tracksAdded(restoredTracks); } const auto restoredGenres = allGenres(); for (const auto &oneGenre : restoredGenres) { d->mGenreId = std::max(d->mGenreId, oneGenre.databaseId()); } ++d->mGenreId; if (!restoredGenres.isEmpty()) { Q_EMIT genresAdded(restoredGenres); } } qulonglong DatabaseInterface::insertMusicSource(const QString &name) { qulonglong result = 0; d->mSelectMusicSource.bindValue(QStringLiteral(":name"), name); auto queryResult = d->mSelectMusicSource.exec(); if (!queryResult || !d->mSelectMusicSource.isSelect() || !d->mSelectMusicSource.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertMusicSource" << d->mSelectMusicSource.lastQuery(); qDebug() << "DatabaseInterface::insertMusicSource" << d->mSelectMusicSource.boundValues(); qDebug() << "DatabaseInterface::insertMusicSource" << d->mSelectMusicSource.lastError(); d->mSelectMusicSource.finish(); return result; } if (d->mSelectMusicSource.next()) { result = d->mSelectMusicSource.record().value(0).toULongLong(); d->mSelectMusicSource.finish(); return result; } d->mSelectMusicSource.finish(); d->mInsertMusicSource.bindValue(QStringLiteral(":discoverId"), d->mDiscoverId); d->mInsertMusicSource.bindValue(QStringLiteral(":name"), name); queryResult = d->mInsertMusicSource.exec(); if (!queryResult || !d->mInsertMusicSource.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::insertMusicSource" << d->mInsertMusicSource.lastQuery(); qDebug() << "DatabaseInterface::insertMusicSource" << d->mInsertMusicSource.boundValues(); qDebug() << "DatabaseInterface::insertMusicSource" << d->mInsertMusicSource.lastError(); d->mInsertMusicSource.finish(); return d->mDiscoverId; } d->mInsertMusicSource.finish(); ++d->mDiscoverId; return d->mDiscoverId - 1; } QList DatabaseInterface::fetchTracks(qulonglong albumId) { auto allTracks = QList(); d->mSelectTrackQuery.bindValue(QStringLiteral(":albumId"), albumId); auto result = d->mSelectTrackQuery.exec(); if (!result || !d->mSelectTrackQuery.isSelect() || !d->mSelectTrackQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::fetchTracks" << d->mSelectTrackQuery.lastQuery(); qDebug() << "DatabaseInterface::fetchTracks" << d->mSelectTrackQuery.boundValues(); qDebug() << "DatabaseInterface::fetchTracks" << d->mSelectTrackQuery.lastError(); } while (d->mSelectTrackQuery.next()) { const auto ¤tRecord = d->mSelectTrackQuery.record(); allTracks.push_back(buildTrackFromDatabaseRecord(currentRecord)); } d->mSelectTrackQuery.finish(); return allTracks; } QList DatabaseInterface::fetchTrackIds(qulonglong albumId) { auto allTracks = QList(); d->mSelectTrackQuery.bindValue(QStringLiteral(":albumId"), albumId); auto result = d->mSelectTrackQuery.exec(); if (!result || !d->mSelectTrackQuery.isSelect() || !d->mSelectTrackQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::fetchTracks" << d->mSelectTrackQuery.lastQuery(); qDebug() << "DatabaseInterface::fetchTracks" << d->mSelectTrackQuery.boundValues(); qDebug() << "DatabaseInterface::fetchTracks" << d->mSelectTrackQuery.lastError(); } while (d->mSelectTrackQuery.next()) { const auto ¤tRecord = d->mSelectTrackQuery.record(); allTracks.push_back(currentRecord.value(0).toULongLong()); } d->mSelectTrackQuery.finish(); updateTracksCount(albumId); return allTracks; } bool DatabaseInterface::updateTracksCount(qulonglong albumId) { bool isModified = false; d->mSelectAlbumTrackCountQuery.bindValue(QStringLiteral(":albumId"), albumId); auto result = d->mSelectAlbumTrackCountQuery.exec(); if (!result || !d->mSelectAlbumTrackCountQuery.isSelect() || !d->mSelectAlbumTrackCountQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::updateTracksCount" << d->mSelectAlbumTrackCountQuery.lastQuery(); qDebug() << "DatabaseInterface::updateTracksCount" << d->mSelectAlbumTrackCountQuery.boundValues(); qDebug() << "DatabaseInterface::updateTracksCount" << d->mSelectAlbumTrackCountQuery.lastError(); d->mSelectAlbumTrackCountQuery.finish(); return isModified; } if (!d->mSelectAlbumTrackCountQuery.next()) { d->mSelectAlbumTrackCountQuery.finish(); return isModified; } auto oldTracksCount = d->mSelectAlbumTrackCountQuery.record().value(0).toInt(); d->mUpdateAlbumQuery.bindValue(QStringLiteral(":albumId"), albumId); result = d->mUpdateAlbumQuery.exec(); if (!result || !d->mUpdateAlbumQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::updateTracksCount" << d->mUpdateAlbumQuery.lastQuery(); qDebug() << "DatabaseInterface::updateTracksCount" << d->mUpdateAlbumQuery.boundValues(); qDebug() << "DatabaseInterface::updateTracksCount" << d->mUpdateAlbumQuery.lastError(); d->mUpdateAlbumQuery.finish(); return isModified; } d->mUpdateAlbumQuery.finish(); d->mSelectAlbumTrackCountQuery.bindValue(QStringLiteral(":albumId"), albumId); result = d->mSelectAlbumTrackCountQuery.exec(); if (!result || !d->mSelectAlbumTrackCountQuery.isSelect() || !d->mSelectAlbumTrackCountQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::updateTracksCount" << d->mSelectAlbumTrackCountQuery.lastQuery(); qDebug() << "DatabaseInterface::updateTracksCount" << d->mSelectAlbumTrackCountQuery.boundValues(); qDebug() << "DatabaseInterface::updateTracksCount" << d->mSelectAlbumTrackCountQuery.lastError(); d->mSelectAlbumTrackCountQuery.finish(); return isModified; } if (!d->mSelectAlbumTrackCountQuery.next()) { d->mSelectAlbumTrackCountQuery.finish(); return isModified; } auto newTracksCount = d->mSelectAlbumTrackCountQuery.record().value(0).toInt(); isModified = (newTracksCount != oldTracksCount); return isModified; } MusicAlbum DatabaseInterface::internalAlbumFromId(qulonglong albumId) { auto retrievedAlbum = MusicAlbum(); d->mSelectAlbumQuery.bindValue(QStringLiteral(":albumId"), albumId); auto result = d->mSelectAlbumQuery.exec(); if (!result || !d->mSelectAlbumQuery.isSelect() || !d->mSelectAlbumQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::internalAlbumFromId" << d->mSelectAlbumQuery.lastQuery(); qDebug() << "DatabaseInterface::internalAlbumFromId" << d->mSelectAlbumQuery.boundValues(); qDebug() << "DatabaseInterface::internalAlbumFromId" << d->mSelectAlbumQuery.lastError(); d->mSelectAlbumQuery.finish(); return retrievedAlbum; } if (!d->mSelectAlbumQuery.next()) { d->mSelectAlbumQuery.finish(); return retrievedAlbum; } const auto ¤tRecord = d->mSelectAlbumQuery.record(); retrievedAlbum.setDatabaseId(currentRecord.value(0).toULongLong()); retrievedAlbum.setTitle(currentRecord.value(1).toString()); retrievedAlbum.setId(currentRecord.value(2).toString()); retrievedAlbum.setArtist(currentRecord.value(3).toString()); retrievedAlbum.setAlbumPath(currentRecord.value(4).toUrl()); retrievedAlbum.setAlbumArtURI(currentRecord.value(5).toUrl()); retrievedAlbum.setTracksCount(currentRecord.value(6).toInt()); retrievedAlbum.setIsSingleDiscAlbum(currentRecord.value(7).toBool()); retrievedAlbum.setTracks(fetchTracks(albumId)); retrievedAlbum.setValid(true); d->mSelectAlbumQuery.finish(); d->mSelectGenreForAlbumQuery.bindValue(QStringLiteral(":albumId"), albumId); result = d->mSelectGenreForAlbumQuery.exec(); if (!result || !d->mSelectGenreForAlbumQuery.isSelect() || !d->mSelectGenreForAlbumQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::internalAlbumFromId" << d->mSelectGenreForAlbumQuery.lastQuery(); qDebug() << "DatabaseInterface::internalAlbumFromId" << d->mSelectGenreForAlbumQuery.boundValues(); qDebug() << "DatabaseInterface::internalAlbumFromId" << d->mSelectGenreForAlbumQuery.lastError(); d->mSelectGenreForAlbumQuery.finish(); return retrievedAlbum; } QStringList allGenres; while(d->mSelectGenreForAlbumQuery.next()) { allGenres.push_back(d->mSelectGenreForAlbumQuery.record().value(0).toString()); } retrievedAlbum.setGenres(allGenres); d->mSelectGenreForAlbumQuery.finish(); return retrievedAlbum; } MusicAlbum DatabaseInterface::internalAlbumFromTitleAndArtist(const QString &title, const QString &artist) { auto result = MusicAlbum(); auto albumId = internalAlbumIdFromTitleAndArtist(title, artist); if (albumId == 0) { return result; } result = internalAlbumFromId(albumId); return result; } qulonglong DatabaseInterface::internalAlbumIdFromTitleAndArtist(const QString &title, const QString &artist) { auto result = qulonglong(0); d->mSelectAlbumIdFromTitleQuery.bindValue(QStringLiteral(":title"), title); d->mSelectAlbumIdFromTitleQuery.bindValue(QStringLiteral(":artistName"), artist); auto queryResult = d->mSelectAlbumIdFromTitleQuery.exec(); if (!queryResult || !d->mSelectAlbumIdFromTitleQuery.isSelect() || !d->mSelectAlbumIdFromTitleQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::internalAlbumIdFromTitleAndArtist" << d->mSelectAlbumIdFromTitleQuery.lastQuery(); qDebug() << "DatabaseInterface::internalAlbumIdFromTitleAndArtist" << d->mSelectAlbumIdFromTitleQuery.boundValues(); qDebug() << "DatabaseInterface::internalAlbumIdFromTitleAndArtist" << d->mSelectAlbumIdFromTitleQuery.lastError(); d->mSelectAlbumIdFromTitleQuery.finish(); return result; } if (d->mSelectAlbumIdFromTitleQuery.next()) { result = d->mSelectAlbumIdFromTitleQuery.record().value(0).toULongLong(); } d->mSelectAlbumIdFromTitleQuery.finish(); if (result == 0) { d->mSelectAlbumIdFromTitleWithoutArtistQuery.bindValue(QStringLiteral(":title"), title); auto queryResult = d->mSelectAlbumIdFromTitleWithoutArtistQuery.exec(); if (!queryResult || !d->mSelectAlbumIdFromTitleWithoutArtistQuery.isSelect() || !d->mSelectAlbumIdFromTitleWithoutArtistQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::internalAlbumIdFromTitleAndArtist" << d->mSelectAlbumIdFromTitleWithoutArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::internalAlbumIdFromTitleAndArtist" << d->mSelectAlbumIdFromTitleWithoutArtistQuery.boundValues(); qDebug() << "DatabaseInterface::internalAlbumIdFromTitleAndArtist" << d->mSelectAlbumIdFromTitleWithoutArtistQuery.lastError(); d->mSelectAlbumIdFromTitleWithoutArtistQuery.finish(); return result; } if (d->mSelectAlbumIdFromTitleWithoutArtistQuery.next()) { result = d->mSelectAlbumIdFromTitleWithoutArtistQuery.record().value(0).toULongLong(); } d->mSelectAlbumIdFromTitleWithoutArtistQuery.finish(); } return result; } MusicAudioTrack DatabaseInterface::internalTrackFromDatabaseId(qulonglong id) { auto result = MusicAudioTrack(); if (!d || !d->mTracksDatabase.isValid() || !d->mInitFinished) { return result; } d->mSelectTrackFromIdQuery.bindValue(QStringLiteral(":trackId"), id); auto queryResult = d->mSelectTrackFromIdQuery.exec(); if (!queryResult || !d->mSelectTrackFromIdQuery.isSelect() || !d->mSelectTrackFromIdQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::internalTrackFromDatabaseId" << d->mSelectAlbumQuery.lastQuery(); qDebug() << "DatabaseInterface::internalTrackFromDatabaseId" << d->mSelectAlbumQuery.boundValues(); qDebug() << "DatabaseInterface::internalTrackFromDatabaseId" << d->mSelectAlbumQuery.lastError(); d->mSelectTrackFromIdQuery.finish(); return result; } if (!d->mSelectTrackFromIdQuery.next()) { d->mSelectTrackFromIdQuery.finish(); return result; } const auto ¤tRecord = d->mSelectTrackFromIdQuery.record(); result = buildTrackFromDatabaseRecord(currentRecord); d->mSelectTrackFromIdQuery.finish(); return result; } qulonglong DatabaseInterface::internalTrackIdFromTitleAlbumTracDiscNumber(const QString &title, const QString &artist, const QString &album, int trackNumber, int discNumber) { auto result = qulonglong(0); if (!d) { return result; } d->mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery.bindValue(QStringLiteral(":title"), title); d->mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery.bindValue(QStringLiteral(":artist"), artist); d->mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery.bindValue(QStringLiteral(":album"), album); d->mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery.bindValue(QStringLiteral(":trackNumber"), trackNumber); d->mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery.bindValue(QStringLiteral(":discNumber"), discNumber); auto queryResult = d->mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery.exec(); if (!queryResult || !d->mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery.isSelect() || !d->mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::trackIdFromTitleAlbumArtist" << d->mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery.lastQuery(); qDebug() << "DatabaseInterface::trackIdFromTitleAlbumArtist" << d->mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery.boundValues(); qDebug() << "DatabaseInterface::trackIdFromTitleAlbumArtist" << d->mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery.lastError(); d->mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery.finish(); return result; } if (d->mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery.next()) { result = d->mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery.record().value(0).toULongLong(); } d->mSelectTrackIdFromTitleArtistAlbumTrackDiscNumberQuery.finish(); return result; } qulonglong DatabaseInterface::getDuplicateTrackIdFromTitleAlbumTrackDiscNumber(const QString &title, const QString &album, const QString &albumArtist, const QString &trackPath, int trackNumber, int discNumber) { auto result = qulonglong(0); if (!d) { return result; } d->mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery.bindValue(QStringLiteral(":title"), title); d->mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery.bindValue(QStringLiteral(":album"), album); d->mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery.bindValue(QStringLiteral(":albumPath"), trackPath); d->mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery.bindValue(QStringLiteral(":albumArtist"), albumArtist); d->mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery.bindValue(QStringLiteral(":trackNumber"), trackNumber); d->mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery.bindValue(QStringLiteral(":discNumber"), discNumber); auto queryResult = d->mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery.exec(); if (!queryResult || !d->mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery.isSelect() || !d->mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::trackIdFromTitleAlbumArtist" << d->mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery.lastQuery(); qDebug() << "DatabaseInterface::trackIdFromTitleAlbumArtist" << d->mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery.boundValues(); qDebug() << "DatabaseInterface::trackIdFromTitleAlbumArtist" << d->mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery.lastError(); d->mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery.finish(); return result; } if (d->mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery.next()) { result = d->mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery.record().value(0).toULongLong(); } d->mSelectTrackIdFromTitleAlbumTrackDiscNumberQuery.finish(); return result; } qulonglong DatabaseInterface::internalTrackIdFromFileName(const QUrl &fileName) { auto result = qulonglong(0); if (!d) { return result; } d->mSelectTracksMapping.bindValue(QStringLiteral(":fileName"), fileName); auto queryResult = d->mSelectTracksMapping.exec(); if (!queryResult || !d->mSelectTracksMapping.isSelect() || !d->mSelectTracksMapping.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::internalTrackIdFromFileName" << d->mSelectTracksMapping.lastQuery(); qDebug() << "DatabaseInterface::internalTrackIdFromFileName" << d->mSelectTracksMapping.boundValues(); qDebug() << "DatabaseInterface::internalTrackIdFromFileName" << d->mSelectTracksMapping.lastError(); d->mSelectTracksMapping.finish(); return result; } if (d->mSelectTracksMapping.next()) { const auto ¤tRecordValue = d->mSelectTracksMapping.record().value(0); if (currentRecordValue.isValid()) { result = currentRecordValue.toULongLong(); } } d->mSelectTracksMapping.finish(); return result; } QList DatabaseInterface::internalTracksFromAuthor(const QString &artistName) { auto allTracks = QList(); d->mSelectTracksFromArtist.bindValue(QStringLiteral(":artistName"), artistName); auto result = d->mSelectTracksFromArtist.exec(); if (!result || !d->mSelectTracksFromArtist.isSelect() || !d->mSelectTracksFromArtist.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::tracksFromAuthor" << d->mSelectTracksFromArtist.lastQuery(); qDebug() << "DatabaseInterface::tracksFromAuthor" << d->mSelectTracksFromArtist.boundValues(); qDebug() << "DatabaseInterface::tracksFromAuthor" << d->mSelectTracksFromArtist.lastError(); return allTracks; } while (d->mSelectTracksFromArtist.next()) { const auto ¤tRecord = d->mSelectTracksFromArtist.record(); allTracks.push_back(buildTrackFromDatabaseRecord(currentRecord)); } d->mSelectTracksFromArtist.finish(); return allTracks; } QList DatabaseInterface::internalAlbumIdsFromAuthor(const QString &artistName) { auto allAlbumIds = QList(); d->mSelectAlbumIdsFromArtist.bindValue(QStringLiteral(":artistName"), artistName); auto result = d->mSelectAlbumIdsFromArtist.exec(); if (!result || !d->mSelectAlbumIdsFromArtist.isSelect() || !d->mSelectAlbumIdsFromArtist.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::tracksFromAuthor" << d->mSelectAlbumIdsFromArtist.lastQuery(); qDebug() << "DatabaseInterface::tracksFromAuthor" << d->mSelectAlbumIdsFromArtist.boundValues(); qDebug() << "DatabaseInterface::tracksFromAuthor" << d->mSelectAlbumIdsFromArtist.lastError(); return allAlbumIds; } while (d->mSelectAlbumIdsFromArtist.next()) { const auto ¤tRecord = d->mSelectAlbumIdsFromArtist.record(); allAlbumIds.push_back(currentRecord.value(0).toULongLong()); } d->mSelectAlbumIdsFromArtist.finish(); return allAlbumIds; } QList> DatabaseInterface::internalAllArtistsPartialData() { return internalAllGenericPartialData(d->mSelectAllArtistsQuery, 1); } QList > DatabaseInterface::internalAllAlbumsPartialData() { return internalAllGenericPartialData(d->mSelectAllAlbumsShortQuery, 2); } QList > DatabaseInterface::internalAllTracksPartialData() { return internalAllGenericPartialData(d->mSelectAllTracksShortQuery, 2); } QList > DatabaseInterface::internalAllGenresPartialData() { return internalAllGenericPartialData(d->mSelectAllGenresQuery, 1); } QList > DatabaseInterface::internalAllComposersPartialData() { return internalAllGenericPartialData(d->mSelectAllComposersQuery, 1); } QList > DatabaseInterface::internalAllLyricistsPartialData() { return internalAllGenericPartialData(d->mSelectAllLyricistsQuery, 1); } QList DatabaseInterface::internalAllPeople(QSqlQuery allPeopleQuery, QSqlQuery selectCountAlbumsForPeopleQuery) { auto result = QList(); if (!d) { return result; } auto transactionResult = startTransaction(); if (!transactionResult) { return result; } auto queryResult = allPeopleQuery.exec(); if (!queryResult || !allPeopleQuery.isSelect() || !allPeopleQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::allArtists" << allPeopleQuery.lastQuery(); qDebug() << "DatabaseInterface::allArtists" << allPeopleQuery.boundValues(); qDebug() << "DatabaseInterface::allArtists" << allPeopleQuery.lastError(); allPeopleQuery.finish(); transactionResult = finishTransaction(); if (!transactionResult) { return result; } return result; } while(allPeopleQuery.next()) { auto newArtist = MusicArtist(); const auto ¤tRecord = allPeopleQuery.record(); newArtist.setDatabaseId(currentRecord.value(0).toULongLong()); newArtist.setName(currentRecord.value(1).toString()); newArtist.setValid(true); selectCountAlbumsForPeopleQuery.bindValue(QStringLiteral(":artistName"), newArtist.name()); auto queryResult = selectCountAlbumsForPeopleQuery.exec(); if (!queryResult || !selectCountAlbumsForPeopleQuery.isSelect() || !selectCountAlbumsForPeopleQuery.isActive() || !selectCountAlbumsForPeopleQuery.next()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::allArtists" << selectCountAlbumsForPeopleQuery.lastQuery(); qDebug() << "DatabaseInterface::allArtists" << selectCountAlbumsForPeopleQuery.boundValues(); qDebug() << "DatabaseInterface::allArtists" << selectCountAlbumsForPeopleQuery.lastError(); selectCountAlbumsForPeopleQuery.finish(); transactionResult = finishTransaction(); if (!transactionResult) { return result; } return result; } newArtist.setAlbumsCount(selectCountAlbumsForPeopleQuery.record().value(0).toInt()); selectCountAlbumsForPeopleQuery.finish(); d->mSelectGenreForArtistQuery.bindValue(QStringLiteral(":artistName"), newArtist.name()); queryResult = d->mSelectGenreForArtistQuery.exec(); if (!queryResult || !d->mSelectGenreForArtistQuery.isSelect() || !d->mSelectGenreForArtistQuery.isActive()) { Q_EMIT databaseError(); qDebug() << "DatabaseInterface::allArtists" << d->mSelectGenreForArtistQuery.lastQuery(); qDebug() << "DatabaseInterface::allArtists" << d->mSelectGenreForArtistQuery.boundValues(); qDebug() << "DatabaseInterface::allArtists" << d->mSelectGenreForArtistQuery.lastError(); d->mSelectGenreForArtistQuery.finish(); transactionResult = finishTransaction(); if (!transactionResult) { return result; } return result; } QStringList allGenres; while(d->mSelectGenreForArtistQuery.next()) { allGenres.push_back(d->mSelectGenreForArtistQuery.record().value(0).toString()); } newArtist.setGenres(allGenres); d->mSelectGenreForArtistQuery.finish(); result.push_back(newArtist); } allPeopleQuery.finish(); transactionResult = finishTransaction(); if (!transactionResult) { return result; } return result; } #include "moc_databaseinterface.cpp" diff --git a/src/databaseinterface.h b/src/databaseinterface.h index 570b8a5b..9c6f5375 100644 --- a/src/databaseinterface.h +++ b/src/databaseinterface.h @@ -1,292 +1,290 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef DATABASEINTERFACE_H #define DATABASEINTERFACE_H #include "elisaLib_export.h" #include "datatype.h" #include "elisautils.h" #include "musicalbum.h" #include "musicaudiotrack.h" #include "musicartist.h" #include "musicaudiogenre.h" #include #include #include #include #include #include #include #include #include class DatabaseInterfacePrivate; class QMutex; class QSqlRecord; class QSqlQuery; class ELISALIB_EXPORT DatabaseInterface : public QObject { Q_OBJECT public: enum class AlbumData { Title, Artist, Image, TracksCount, Id, }; enum PropertyType { DatabaseId, DisplayRole, SecondaryRole, }; Q_ENUMS(PropertyType) enum AlbumDiscsCount { SingleDiscAlbum, MultipleDiscsAlbum, }; Q_ENUMS(AlbumDiscsCounts) explicit DatabaseInterface(QObject *parent = nullptr); ~DatabaseInterface() override; Q_INVOKABLE void init(const QString &dbName, const QString &databaseFileName = {}); MusicAlbum albumFromTitleAndArtist(const QString &title, const QString &artist); QList> allData(DataUtils::DataType aType); QList allTracks(); QList allTracksFromSource(const QString &musicSource); QList allAlbums(); QList allArtists(); QList allGenres(); QList allComposers(); QList allLyricists(); QList tracksFromAuthor(const QString &artistName); MusicAudioTrack trackFromDatabaseId(qulonglong id); qulonglong trackIdFromTitleAlbumTrackDiscNumber(const QString &title, const QString &artist, const QString &album, int trackNumber, int discNumber); qulonglong trackIdFromFileName(const QUrl &fileName); void applicationAboutToQuit(); Q_SIGNALS: void artistsAdded(const QList &newArtist); void composersAdded(const QList &newComposer); void lyricistsAdded(const QList &newLyricist); void albumsAdded(const QList &newAlbum); void tracksAdded(const QList &allTracks); void genresAdded(const QList &allGenres); void artistRemoved(const MusicArtist &removedArtist); void albumRemoved(const MusicAlbum &removedAlbum, qulonglong removedAlbumId); void trackRemoved(qulonglong id); void artistModified(const MusicArtist &modifiedArtist); void albumModified(const MusicAlbum &modifiedAlbum, qulonglong modifiedAlbumId); void trackModified(const MusicAudioTrack &modifiedTrack); void sentAlbumData(const MusicAlbum albumData); void requestsInitDone(); void databaseError(); void restoredTracks(const QString &musicSource, QHash allFiles); public Q_SLOTS: void insertTracksList(const QList &tracks, const QHash &covers, const QString &musicSource); void removeTracksList(const QList &removedTracks); void modifyTracksList(const QList &modifiedTracks, const QHash &covers, const QString &musicSource); void removeAllTracksFromSource(const QString &sourceName); void getAlbumFromAlbumId(qulonglong id); void askRestoredTracks(const QString &musicSource); private: enum class TrackFileInsertType { NewTrackFileInsert, ModifiedTrackFileInsert, }; bool startTransaction() const; bool finishTransaction() const; bool rollBackTransaction() const; QList fetchTracks(qulonglong albumId); QList fetchTrackIds(qulonglong albumId); bool updateTracksCount(qulonglong albumId); MusicArtist internalArtistFromId(qulonglong artistId); MusicAlbum internalAlbumFromId(qulonglong albumId); MusicAlbum internalAlbumFromTitleAndArtist(const QString &title, const QString &artist); qulonglong internalAlbumIdFromTitleAndArtist(const QString &title, const QString &artist); MusicAudioTrack internalTrackFromDatabaseId(qulonglong id); qulonglong internalTrackIdFromTitleAlbumTracDiscNumber(const QString &title, const QString &artist, const QString &album, int trackNumber, int discNumber); qulonglong getDuplicateTrackIdFromTitleAlbumTrackDiscNumber(const QString &title, const QString &album, const QString &albumArtist, const QString &trackPath, int trackNumber, int discNumber); qulonglong internalTrackIdFromFileName(const QUrl &fileName); QList internalTracksFromAuthor(const QString &artistName); QList internalAlbumIdsFromAuthor(const QString &artistName); void initDatabase(); void initRequest(); qulonglong insertAlbum(const QString &title, const QString &albumArtist, const QString &trackArtist, const QString &trackPath, const QUrl &albumArtURI, int tracksCount, AlbumDiscsCount isSingleDiscAlbum, QList &newAlbumIds, QList &newArtistsIds); bool updateAlbumFromId(qulonglong albumId, const QUrl &albumArtUri, const MusicAudioTrack ¤tTrack, QList &newArtistsIds); qulonglong insertArtist(const QString &name, QList &newArtistsIds); qulonglong internalArtistIdFromName(const QString &name); qulonglong insertGenre(const QString &name); MusicAudioGenre internalGenreFromId(qulonglong genreId); void removeTrackInDatabase(qulonglong trackId); void updateTrackInDatabase(const MusicAudioTrack &oneTrack, qulonglong albumId, QList &newArtistsIds); void removeAlbumInDatabase(qulonglong albumId); void removeArtistInDatabase(qulonglong artistId); void reloadExistingDatabase(); qulonglong insertMusicSource(const QString &name); void insertTrackOrigin(const QUrl &fileNameURI, const QDateTime &fileModifiedTime, qulonglong discoverId); void updateTrackOrigin(qulonglong trackId, const QUrl &fileName, const QDateTime &fileModifiedTime); int computeTrackPriority(qulonglong trackId, const QUrl &fileName); qulonglong internalInsertTrack(const MusicAudioTrack &oneModifiedTrack, const QHash &covers, qulonglong originTrackId, QSet &modifiedAlbumIds, TrackFileInsertType insertType, QList &newAlbumIds, QList &newArtistsIds, QSet &modifiedTrackIds); MusicAudioTrack buildTrackFromDatabaseRecord(const QSqlRecord &trackRecord) const; void internalRemoveTracksList(const QList &removedTracks, QList &newArtistsIds); void internalRemoveTracksList(const QHash &removedTracks, qulonglong sourceId, QList &newArtistsIds); void internalRemoveTracksWithoutMapping(QList &newArtistsIds); QUrl internalAlbumArtUriFromAlbumId(qulonglong albumId); bool isValidArtist(qulonglong albumId); qulonglong insertComposer(const QString &name); MusicArtist internalComposerFromId(qulonglong composerId); qulonglong insertLyricist(const QString &name); MusicArtist internalLyricistFromId(qulonglong lyricistId); qulonglong internalSourceIdFromName(const QString &sourceName); QHash internalAllFileNameFromSource(qulonglong sourceId); QList> internalAllGenericPartialData(QSqlQuery &query, int nbFields); QList> internalAllArtistsPartialData(); QList> internalAllAlbumsPartialData(); QList> internalAllTracksPartialData(); QList> internalAllGenresPartialData(); QList> internalAllComposersPartialData(); QList> internalAllLyricistsPartialData(); QList internalAllPeople(QSqlQuery allPeopleQuery, QSqlQuery selectCountAlbumsForPeopleQuery); std::unique_ptr d; }; #endif // DATABASEINTERFACE_H diff --git a/src/datatype.cpp b/src/datatype.cpp index f0c01c14..a4e844fa 100644 --- a/src/datatype.cpp +++ b/src/datatype.cpp @@ -1,23 +1,21 @@ /* * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "datatype.h" #include "moc_datatype.cpp" diff --git a/src/datatype.h b/src/datatype.h index 4584b326..de3567d7 100644 --- a/src/datatype.h +++ b/src/datatype.h @@ -1,45 +1,43 @@ /* * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef DATATYPE_H #define DATATYPE_H #include "elisaLib_export.h" #include namespace DataUtils { Q_NAMESPACE enum class DataType { AllArtists, AllAlbums, AllTracks, AllGenres, AllComposers, AllLyricists, UnknownType, }; Q_ENUM_NS(DataType) } #endif // DATATYPE_H diff --git a/src/elisaapplication.cpp b/src/elisaapplication.cpp index efbde5ff..37deec92 100644 --- a/src/elisaapplication.cpp +++ b/src/elisaapplication.cpp @@ -1,548 +1,546 @@ /* * Copyright 2017 Matthieu Gallien * Copyright (C) 2012 Aleix Pol Gonzalez * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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 "models/allalbumsproxymodel.h" #include "models/alltracksproxymodel.h" #include "models/allartistsproxymodel.h" #include "models/singleartistproxymodel.h" #include "models/singlealbumproxymodel.h" #if defined KF5KIO_FOUND && KF5KIO_FOUND #include "models/filebrowserproxymodel.h" #endif #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 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 QStringList mArguments; std::unique_ptr mMusicManager; std::unique_ptr mAllAlbumsProxyModel; std::unique_ptr mAllArtistsProxyModel; std::unique_ptr mAllTracksProxyModel; std::unique_ptr mAllGenresProxyModel; std::unique_ptr mAllComposersProxyModel; std::unique_ptr mAllLyricistsProxyModel; std::unique_ptr mSingleArtistProxyModel; std::unique_ptr mSingleAlbumProxyModel; #if defined KF5KIO_FOUND && KF5KIO_FOUND std::unique_ptr mFileBrowserProxyModel; #endif 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("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 QStringList &newArguments) { if (d->mArguments == newArguments) { return; } d->mArguments = checkFileListAndMakeAbsolute(newArguments, QDir::currentPath()); Q_EMIT argumentsChanged(); if (!d->mArguments.isEmpty()) { Q_EMIT enqueue(d->mArguments); } } void ElisaApplication::activateActionRequested(const QString &actionName, const QVariant ¶meter) { Q_UNUSED(actionName) Q_UNUSED(parameter) } void ElisaApplication::activateRequested(const QStringList &arguments, const QString &workingDirectory) { auto realArguments = arguments; if (realArguments.size() > 1) { realArguments.removeFirst(); Q_EMIT enqueue(checkFileListAndMakeAbsolute(realArguments, workingDirectory)); } } 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() {} QStringList ElisaApplication::checkFileListAndMakeAbsolute(const QStringList &filesList, const QString &workingDirectory) const { QStringList filesToOpen; for (const auto &oneFile : filesList) { auto newFile = QFileInfo(oneFile); if (newFile.isRelative()) { newFile = QFileInfo(workingDirectory + QStringLiteral("/") + oneFile); } if (newFile.exists()) { filesToOpen.push_back(newFile.canonicalFilePath()); } } return filesToOpen; } void ElisaApplication::initialize() { initializeModels(); initializePlayer(); Q_EMIT initializationDone(); } void ElisaApplication::initializeModels() { d->mMusicManager = std::make_unique(); Q_EMIT musicManagerChanged(); d->mAllAlbumsProxyModel = std::make_unique(); Q_EMIT allAlbumsProxyModelChanged(); d->mAllArtistsProxyModel = std::make_unique(); Q_EMIT allArtistsProxyModelChanged(); d->mAllGenresProxyModel = std::make_unique(); Q_EMIT allGenresProxyModelChanged(); d->mAllComposersProxyModel = std::make_unique(); Q_EMIT allComposersProxyModelChanged(); d->mAllLyricistsProxyModel = std::make_unique(); Q_EMIT allLyricistsProxyModelChanged(); d->mAllTracksProxyModel = std::make_unique(); Q_EMIT allTracksProxyModelChanged(); d->mSingleArtistProxyModel = std::make_unique(); Q_EMIT singleArtistProxyModelChanged(); d->mSingleAlbumProxyModel = std::make_unique(); Q_EMIT singleAlbumProxyModelChanged(); #if defined KF5KIO_FOUND && KF5KIO_FOUND d->mFileBrowserProxyModel = std::make_unique(); Q_EMIT fileBrowserProxyModelChanged(); #endif 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(), &MediaPlayList::enqueueAndPlay); d->mAllAlbumsProxyModel->setSourceModel(d->mMusicManager->allAlbumsModel()); d->mAllArtistsProxyModel->setSourceModel(d->mMusicManager->allArtistsModel()); d->mAllGenresProxyModel->setSourceModel(d->mMusicManager->allGenresModel()); d->mAllComposersProxyModel->setSourceModel(d->mMusicManager->allComposersModel()); d->mAllLyricistsProxyModel->setSourceModel(d->mMusicManager->allLyricistsModel()); d->mAllTracksProxyModel->setSourceModel(d->mMusicManager->allTracksModel()); d->mSingleArtistProxyModel->setSourceModel(d->mMusicManager->allAlbumsModel()); d->mSingleAlbumProxyModel->setSourceModel(d->mMusicManager->albumModel()); QObject::connect(d->mAllAlbumsProxyModel.get(), &AllAlbumsProxyModel::albumToEnqueue, d->mMediaPlayList.get(), static_cast &, ElisaUtils::PlayListEnqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay)>(&MediaPlayList::enqueue)); QObject::connect(d->mAllArtistsProxyModel.get(), &AllArtistsProxyModel::artistToEnqueue, d->mMediaPlayList.get(), &MediaPlayList::enqueueArtists); QObject::connect(d->mAllTracksProxyModel.get(), &AllTracksProxyModel::trackToEnqueue, d->mMediaPlayList.get(), static_cast &, ElisaUtils::PlayListEnqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay)>(&MediaPlayList::enqueue)); QObject::connect(d->mSingleArtistProxyModel.get(), &SingleArtistProxyModel::albumToEnqueue, d->mMediaPlayList.get(), static_cast &, ElisaUtils::PlayListEnqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay)>(&MediaPlayList::enqueue)); QObject::connect(d->mSingleAlbumProxyModel.get(), &SingleAlbumProxyModel::trackToEnqueue, d->mMediaPlayList.get(), static_cast &, ElisaUtils::PlayListEnqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay)>(&MediaPlayList::enqueue)); #if defined KF5KIO_FOUND && KF5KIO_FOUND QObject::connect(d->mFileBrowserProxyModel.get(), &FileBrowserProxyModel::filesToEnqueue, d->mMediaPlayList.get(), static_cast &, ElisaUtils::PlayListEnqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay)>(&MediaPlayList::enqueue)); #endif } 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::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->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->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); 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->setAlbumIdRole(MediaPlayList::AlbumIdRole); 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); } } 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(); } const QStringList &ElisaApplication::arguments() const { return d->mArguments; } MusicListenersManager *ElisaApplication::musicManager() const { return d->mMusicManager.get(); } QSortFilterProxyModel *ElisaApplication::allAlbumsProxyModel() const { return d->mAllAlbumsProxyModel.get(); } QSortFilterProxyModel *ElisaApplication::allArtistsProxyModel() const { return d->mAllArtistsProxyModel.get(); } QSortFilterProxyModel *ElisaApplication::allGenresProxyModel() const { return d->mAllGenresProxyModel.get(); } QSortFilterProxyModel *ElisaApplication::allComposersProxyModel() const { return d->mAllComposersProxyModel.get(); } QSortFilterProxyModel *ElisaApplication::allLyricistsProxyModel() const { return d->mAllLyricistsProxyModel.get(); } QSortFilterProxyModel *ElisaApplication::allTracksProxyModel() const { return d->mAllTracksProxyModel.get(); } QSortFilterProxyModel *ElisaApplication::singleArtistProxyModel() const { return d->mSingleArtistProxyModel.get(); } QSortFilterProxyModel *ElisaApplication::singleAlbumProxyModel() const { return d->mSingleAlbumProxyModel.get(); } QSortFilterProxyModel *ElisaApplication::fileBrowserProxyModel() const { #if defined KF5KIO_FOUND && KF5KIO_FOUND return d->mFileBrowserProxyModel.get(); #else return nullptr; #endif } 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/elisaapplication.h b/src/elisaapplication.h index 3802e197..b0c6e62f 100644 --- a/src/elisaapplication.h +++ b/src/elisaapplication.h @@ -1,236 +1,234 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef ELISAAPPLICATION_H #define ELISAAPPLICATION_H #include "elisaLib_export.h" #include "config-upnp-qt.h" #include #include #include class QIcon; class QAction; class MusicListenersManager; class QSortFilterProxyModel; class MediaPlayList; class AudioWrapper; class ManageAudioPlayer; class ManageMediaPlayerControl; class ManageHeaderBar; class ElisaApplicationPrivate; class ELISALIB_EXPORT ElisaApplication : public QObject { Q_OBJECT Q_PROPERTY(QStringList arguments READ arguments WRITE setArguments NOTIFY argumentsChanged) Q_PROPERTY(MusicListenersManager *musicManager READ musicManager NOTIFY musicManagerChanged) Q_PROPERTY(QSortFilterProxyModel* allAlbumsProxyModel READ allAlbumsProxyModel NOTIFY allAlbumsProxyModelChanged) Q_PROPERTY(QSortFilterProxyModel* allArtistsProxyModel READ allArtistsProxyModel NOTIFY allArtistsProxyModelChanged) Q_PROPERTY(QSortFilterProxyModel* allTracksProxyModel READ allTracksProxyModel NOTIFY allTracksProxyModelChanged) Q_PROPERTY(QSortFilterProxyModel* allGenresProxyModel READ allGenresProxyModel NOTIFY allGenresProxyModelChanged) Q_PROPERTY(QSortFilterProxyModel* allComposersProxyModel READ allComposersProxyModel NOTIFY allComposersProxyModelChanged) Q_PROPERTY(QSortFilterProxyModel* allLyricistsProxyModel READ allLyricistsProxyModel NOTIFY allLyricistsProxyModelChanged) Q_PROPERTY(QSortFilterProxyModel* singleArtistProxyModel READ singleArtistProxyModel NOTIFY singleArtistProxyModelChanged) Q_PROPERTY(QSortFilterProxyModel* singleAlbumProxyModel READ singleAlbumProxyModel NOTIFY singleAlbumProxyModelChanged) Q_PROPERTY(QSortFilterProxyModel* fileBrowserProxyModel READ fileBrowserProxyModel NOTIFY fileBrowserProxyModelChanged) Q_PROPERTY(MediaPlayList *mediaPlayList READ mediaPlayList NOTIFY mediaPlayListChanged) Q_PROPERTY(AudioWrapper *audioPlayer READ audioPlayer NOTIFY audioPlayerChanged) Q_PROPERTY(ManageAudioPlayer *audioControl 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); ~ElisaApplication() override; Q_INVOKABLE QAction* action(const QString& name); Q_INVOKABLE QString iconName(const QIcon& icon); const QStringList &arguments() const; MusicListenersManager *musicManager() const; QSortFilterProxyModel *allAlbumsProxyModel() const; QSortFilterProxyModel *allArtistsProxyModel() const; QSortFilterProxyModel *allGenresProxyModel() const; QSortFilterProxyModel *allComposersProxyModel() const; QSortFilterProxyModel *allLyricistsProxyModel() const; QSortFilterProxyModel *allTracksProxyModel() const; QSortFilterProxyModel *singleArtistProxyModel() const; QSortFilterProxyModel *singleAlbumProxyModel() const; QSortFilterProxyModel *fileBrowserProxyModel() const; MediaPlayList *mediaPlayList() const; AudioWrapper *audioPlayer() const; ManageAudioPlayer *audioControl() const; ManageMediaPlayerControl *playerControl() const; ManageHeaderBar *manageHeaderBar() const; Q_SIGNALS: void argumentsChanged(); void musicManagerChanged(); void allAlbumsProxyModelChanged(); void allArtistsProxyModelChanged(); void allGenresProxyModelChanged(); void allComposersProxyModelChanged(); void allLyricistsProxyModelChanged(); void allTracksProxyModelChanged(); void singleArtistProxyModelChanged(); void singleAlbumProxyModelChanged(); void fileBrowserProxyModelChanged(); void mediaPlayListChanged(); void audioPlayerChanged(); void audioControlChanged(); void playerControlChanged(); void manageHeaderBarChanged(); void enqueue(const QStringList &files); void initializationDone(); public Q_SLOTS: void appHelpActivated(); void aboutApplication(); void reportBug(); void configureShortcuts(); void configureElisa(); void setArguments(const QStringList &newArguments); void activateActionRequested(const QString &actionName, const QVariant ¶meter); void activateRequested(const QStringList &arguments, const QString &workingDirectory); void openRequested(const QList< QUrl > &uris); void initialize(); private Q_SLOTS: void goBack(); void find(); void togglePlaylist(); private: void initializeModels(); void initializePlayer(); void setupActions(const QString &actionName); QStringList checkFileListAndMakeAbsolute(const QStringList &filesList, const QString &workingDirectory) const; std::unique_ptr d; }; #endif // ELISAAPPLICATION_H diff --git a/src/elisaimport.cpp b/src/elisaimport.cpp index 8c454d62..b97dfb44 100644 --- a/src/elisaimport.cpp +++ b/src/elisaimport.cpp @@ -1,65 +1,63 @@ /* * Copyright 2015-2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "config-upnp-qt.h" #include "musiclistenersmanager.h" #include "elisaimportapplication.h" #include "elisa_settings.h" #include #include #include #include int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); qRegisterMetaType>("QHash"); qRegisterMetaType>("QList"); qRegisterMetaType>("QVector"); qRegisterMetaType>("QVector"); qRegisterMetaType>("QHash"); qRegisterMetaType("MusicAlbum"); qRegisterMetaType("MusicArtist"); qRegisterMetaType>(); qRegisterMetaType("NotificationItem"); qRegisterMetaType>("QMap"); QCommandLineParser parser; parser.addHelpOption(); parser.addVersionOption(); parser.process(app); auto configurationFileName = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); configurationFileName += QStringLiteral("/elisarc"); Elisa::ElisaConfiguration::instance(configurationFileName); Elisa::ElisaConfiguration::self()->load(); Elisa::ElisaConfiguration::self()->save(); MusicListenersManager myMusicManager; ElisaImportApplication myApplication; QObject::connect(&myMusicManager, &MusicListenersManager::indexingRunningChanged, &myApplication, &ElisaImportApplication::indexingChanged); return app.exec(); } diff --git a/src/elisaimportapplication.cpp b/src/elisaimportapplication.cpp index b6b9d56a..570fdc4f 100644 --- a/src/elisaimportapplication.cpp +++ b/src/elisaimportapplication.cpp @@ -1,40 +1,38 @@ /* * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "elisaimportapplication.h" #include ElisaImportApplication::ElisaImportApplication(QObject *parent) : QObject(parent) { } void ElisaImportApplication::indexingChanged() { static bool firstCall = true; if (firstCall) { firstCall = false; } else { QCoreApplication::quit(); } } #include "moc_elisaimportapplication.cpp" diff --git a/src/elisaimportapplication.h b/src/elisaimportapplication.h index c4d432ef..7062ab3e 100644 --- a/src/elisaimportapplication.h +++ b/src/elisaimportapplication.h @@ -1,39 +1,37 @@ /* * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef ELISAIMPORTAPPLICATION_H #define ELISAIMPORTAPPLICATION_H #include class ElisaImportApplication : public QObject { Q_OBJECT public: explicit ElisaImportApplication(QObject *parent = nullptr); Q_SIGNALS: public Q_SLOTS: void indexingChanged(); }; #endif // ELISAIMPORTAPPLICATION_H diff --git a/src/elisaqmlplugin.cpp b/src/elisaqmlplugin.cpp index 336740ff..6a9d9681 100644 --- a/src/elisaqmlplugin.cpp +++ b/src/elisaqmlplugin.cpp @@ -1,163 +1,161 @@ /* * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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 "elisaapplication.h" #include "progressindicator.h" #include "mediaplaylist.h" #include "managemediaplayercontrol.h" #include "manageheaderbar.h" #include "manageaudioplayer.h" #include "musicaudiotrack.h" #include "musicaudiogenre.h" #include "musiclistenersmanager.h" #include "models/allalbumsmodel.h" #include "models/albummodel.h" #include "models/allartistsmodel.h" #include "models/alltracksmodel.h" #include "models/allalbumsproxymodel.h" #include "models/alltracksproxymodel.h" #include "models/allartistsproxymodel.h" #include "models/singleartistproxymodel.h" #include "models/singlealbumproxymodel.h" #include "models/genericdatamodel.h" #if defined KF5KIO_FOUND && KF5KIO_FOUND #include "models/filebrowserproxymodel.h" #endif #include "audiowrapper.h" #include "notificationitem.h" #include "topnotificationmanager.h" #include "trackdatahelper.h" #include "elisautils.h" #include "datatype.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); } 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 qRegisterMetaType("DataUtils::DataType"); 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, "AllAlbumsProxyModel"); qmlRegisterType(uri, 1, 0, "AllArtistsProxyModel"); qmlRegisterType(uri, 1, 0, "AllTracksProxyModel"); qmlRegisterType(uri, 1, 0, "SingleAlbumProxyModel"); qmlRegisterType(uri, 1, 0, "SingleArtistProxyModel"); qmlRegisterType(uri, 1, 0, "GenericDataModel"); #if defined KF5KIO_FOUND && KF5KIO_FOUND qmlRegisterType(uri, 1, 0, "FileBrowserProxyModel"); #endif qmlRegisterType(uri, 1, 0, "AudioWrapper"); qmlRegisterType(uri, 1, 0, "TopNotificationManager"); qmlRegisterType(uri, 1, 0, "TrackDataHelper"); qmlRegisterUncreatableMetaObject(DataUtils::staticMetaObject, uri, 1, 0, "DataUtils", QStringLiteral("Only enums")); #if defined Qt5DBus_FOUND && Qt5DBus_FOUND qmlRegisterType(uri, 1, 0, "Mpris2"); qRegisterMetaType(); #endif qRegisterMetaType(); qRegisterMetaType>("QHash"); qRegisterMetaType>("QHash"); qRegisterMetaType>("QList"); qRegisterMetaType>("QVector"); qRegisterMetaType>("QList"); qRegisterMetaType>("QList"); qRegisterMetaType>("QList"); qRegisterMetaType>("QVector"); qRegisterMetaType>("QHash"); qRegisterMetaType("MusicAlbum"); qRegisterMetaType("MusicArtist"); qRegisterMetaType>(); qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType("NotificationItem"); qRegisterMetaType>("QMap"); qRegisterMetaType("ElisaUtils::PlayListEnqueueMode"); qRegisterMetaType("ElisaUtils::PlayListEnqueueTriggerPlay"); qRegisterMetaTypeStreamOperators("PlayListControler::PlayerState"); qmlRegisterUncreatableType(uri, 1, 0, "ElisaApplication", QStringLiteral("only one and done in c++")); } diff --git a/src/elisaqmlplugin.h b/src/elisaqmlplugin.h index d7c3724f..a1e901df 100644 --- a/src/elisaqmlplugin.h +++ b/src/elisaqmlplugin.h @@ -1,37 +1,35 @@ /* * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef ELISAQMLPLUGIN_H #define ELISAQMLPLUGIN_H #include class QQmlEngine; class ElisaQmlTestPlugin : public QQmlExtensionPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") public: void initializeEngine(QQmlEngine *engine, const char *uri) override; void registerTypes(const char *uri) override; }; #endif // ELISAQMLPLUGIN_H diff --git a/src/elisautils.cpp b/src/elisautils.cpp index f7f5675b..aba78899 100644 --- a/src/elisautils.cpp +++ b/src/elisautils.cpp @@ -1,22 +1,20 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "elisautils.h" #include "moc_elisautils.cpp" diff --git a/src/elisautils.h b/src/elisautils.h index bd73a1ec..2f3c8171 100644 --- a/src/elisautils.h +++ b/src/elisautils.h @@ -1,82 +1,80 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef ELISAUTILS_H #define ELISAUTILS_H #include "elisaLib_export.h" #include namespace ElisaUtils { Q_NAMESPACE enum PlayListEnqueueMode { AppendPlayList, ReplacePlayList, }; Q_ENUM_NS(PlayListEnqueueMode) enum PlayListEnqueueTriggerPlay { DoNotTriggerPlay, TriggerPlay, }; Q_ENUM_NS(PlayListEnqueueTriggerPlay) enum ColumnsRoles { TitleRole = Qt::UserRole + 1, SecondaryTextRole, ImageUrlRole, ShadowForImageRole, ChildModelRole, DurationRole, MilliSecondsDurationRole, ArtistRole, AllArtistsRole, HighestTrackRating, AlbumRole, AlbumArtistRole, TrackNumberRole, DiscNumberRole, RatingRole, GenreRole, LyricistRole, ComposerRole, CommentRole, YearRole, ChannelsRole, BitRateRole, SampleRateRole, ImageRole, ResourceRole, IdRole, DatabaseIdRole, IsSingleDiscAlbumRole, ContainerDataRole, IsPartialDataRole, }; Q_ENUM_NS(ColumnsRoles) } #endif // ELISAUTILS_H diff --git a/src/file/filelistener.cpp b/src/file/filelistener.cpp index ff7c665d..9a5e822c 100644 --- a/src/file/filelistener.cpp +++ b/src/file/filelistener.cpp @@ -1,61 +1,59 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "filelistener.h" #include "localfilelisting.h" #include "databaseinterface.h" #include class FileListenerPrivate { public: LocalFileListing mLocalFileIndexer; }; FileListener::FileListener(QObject *parent) : AbstractFileListener(parent), d(std::make_unique()) { setFileListing(&d->mLocalFileIndexer); connect(&d->mLocalFileIndexer, &LocalFileListing::rootPathChanged, this, &FileListener::rootPathChanged); } FileListener::~FileListener() = default; const LocalFileListing& FileListener::localFileIndexer() const { return d->mLocalFileIndexer; } QString FileListener::rootPath() const { return d->mLocalFileIndexer.rootPath(); } void FileListener::setRootPath(const QString &rootPath) { d->mLocalFileIndexer.setRootPath(rootPath); } #include "moc_filelistener.cpp" diff --git a/src/file/filelistener.h b/src/file/filelistener.h index d80776e5..7077ccc6 100644 --- a/src/file/filelistener.h +++ b/src/file/filelistener.h @@ -1,64 +1,62 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef FILELISTENER_H #define FILELISTENER_H #include "../abstractfile/abstractfilelistener.h" #include #include #include class FileListenerPrivate; class LocalFileListing; class FileListener : public AbstractFileListener { Q_OBJECT Q_PROPERTY(QString rootPath READ rootPath WRITE setRootPath NOTIFY rootPathChanged) public: explicit FileListener(QObject *parent = nullptr); ~FileListener() override; const LocalFileListing& localFileIndexer() const; QString rootPath() const; Q_SIGNALS: void rootPathChanged(); public Q_SLOTS: void setRootPath(const QString &rootPath); private: std::unique_ptr d; }; #endif // FILELISTENER_H diff --git a/src/file/localfilelisting.cpp b/src/file/localfilelisting.cpp index caf0c4e6..dd25454f 100644 --- a/src/file/localfilelisting.cpp +++ b/src/file/localfilelisting.cpp @@ -1,87 +1,85 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "localfilelisting.h" #include "musicaudiotrack.h" #include #include #include #include #include #include #include #include #include class LocalFileListingPrivate { public: QString mRootPath; }; LocalFileListing::LocalFileListing(QObject *parent) : AbstractFileListing(QStringLiteral("local"), parent), d(std::make_unique()) { } LocalFileListing::~LocalFileListing() = default; QString LocalFileListing::rootPath() const { return d->mRootPath; } void LocalFileListing::setRootPath(const QString &rootPath) { if (d->mRootPath == rootPath) { return; } d->mRootPath = rootPath; Q_EMIT rootPathChanged(); setSourceName(rootPath); } void LocalFileListing::executeInit(QHash allFiles) { AbstractFileListing::executeInit(std::move(allFiles)); } void LocalFileListing::triggerRefreshOfContent() { Q_EMIT indexingStarted(); AbstractFileListing::triggerRefreshOfContent(); scanDirectoryTree(d->mRootPath); checkFilesToRemove(); Q_EMIT indexingFinished(); } #include "moc_localfilelisting.cpp" diff --git a/src/file/localfilelisting.h b/src/file/localfilelisting.h index 5d7a3e0b..4e0c0f1d 100644 --- a/src/file/localfilelisting.h +++ b/src/file/localfilelisting.h @@ -1,71 +1,69 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef LOCALFILELISTING_H #define LOCALFILELISTING_H #include "elisaLib_export.h" #include "../abstractfile/abstractfilelisting.h" #include #include class LocalFileListingPrivate; class ELISALIB_EXPORT LocalFileListing : public AbstractFileListing { Q_OBJECT Q_PROPERTY(QString rootPath READ rootPath WRITE setRootPath NOTIFY rootPathChanged) public: explicit LocalFileListing(QObject *parent = nullptr); ~LocalFileListing() override; QString rootPath() const; Q_SIGNALS: void rootPathChanged(); public Q_SLOTS: void setRootPath(const QString &rootPath); private: void executeInit(QHash allFiles) override; void triggerRefreshOfContent() override; std::unique_ptr d; }; #endif // LOCALFILELISTING_H diff --git a/src/filescanner.cpp b/src/filescanner.cpp index acae4fe2..83c01746 100644 --- a/src/filescanner.cpp +++ b/src/filescanner.cpp @@ -1,217 +1,215 @@ /* * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "filescanner.h" #include "config-upnp-qt.h" #if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND #include #include #include #include #include #if defined KF5Baloo_FOUND && KF5Baloo_FOUND #include #endif #endif #include class FileScannerPrivate { public: #if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND KFileMetaData::ExtractorCollection mAllExtractors; KFileMetaData::PropertyMap mAllProperties; #endif }; FileScanner::FileScanner() : d(std::make_unique()) { } FileScanner::~FileScanner() = default; MusicAudioTrack FileScanner::scanOneFile(const QUrl &scanFile, const QMimeDatabase &mimeDatabase) { #if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND MusicAudioTrack newTrack; auto localFileName = scanFile.toLocalFile(); QFileInfo scanFileInfo(localFileName); newTrack.setFileModificationTime(scanFileInfo.fileTime(QFile::FileModificationTime)); newTrack.setResourceURI(scanFile); const auto &fileMimeType = mimeDatabase.mimeTypeForFile(localFileName); if (!fileMimeType.name().startsWith(QStringLiteral("audio/"))) { return newTrack; } QString mimetype = fileMimeType.name(); QList exList = d->mAllExtractors.fetchExtractors(mimetype); if (exList.isEmpty()) { return newTrack; } KFileMetaData::Extractor* ex = exList.first(); KFileMetaData::SimpleExtractionResult result(localFileName, mimetype, KFileMetaData::ExtractionResult::ExtractMetaData); ex->extract(&result); d->mAllProperties = result.properties(); scanProperties(localFileName, newTrack); return newTrack; #else Q_UNUSED(scanFile) Q_UNUSED(mimeDatabase) return {}; #endif } void FileScanner::scanProperties(const Baloo::File &match, MusicAudioTrack &trackData) { #if defined KF5Baloo_FOUND && KF5Baloo_FOUND d->mAllProperties = match.properties(); scanProperties(match.path(), trackData); #else Q_UNUSED(match) Q_UNUSED(trackData) #endif } void FileScanner::scanProperties(const QString &localFileName, MusicAudioTrack &trackData) { #if defined KF5FileMetaData_FOUND && KF5FileMetaData_FOUND auto titleProperty = d->mAllProperties.find(KFileMetaData::Property::Title); auto durationProperty = d->mAllProperties.find(KFileMetaData::Property::Duration); auto artistProperty = d->mAllProperties.find(KFileMetaData::Property::Artist); auto albumProperty = d->mAllProperties.find(KFileMetaData::Property::Album); auto albumArtistProperty = d->mAllProperties.find(KFileMetaData::Property::AlbumArtist); auto trackNumberProperty = d->mAllProperties.find(KFileMetaData::Property::TrackNumber); auto discNumberProperty = d->mAllProperties.find(KFileMetaData::Property::DiscNumber); auto genreProperty = d->mAllProperties.find(KFileMetaData::Property::Genre); auto yearProperty = d->mAllProperties.find(KFileMetaData::Property::ReleaseYear); auto composerProperty = d->mAllProperties.find(KFileMetaData::Property::Composer); auto lyricistProperty = d->mAllProperties.find(KFileMetaData::Property::Lyricist); auto channelsProperty = d->mAllProperties.find(KFileMetaData::Property::Channels); auto bitRateProperty = d->mAllProperties.find(KFileMetaData::Property::BitRate); auto sampleRateProperty = d->mAllProperties.find(KFileMetaData::Property::SampleRate); auto commentProperty = d->mAllProperties.find(KFileMetaData::Property::Comment); #if defined Q_OS_LINUX && !defined Q_OS_ANDROID auto fileData = KFileMetaData::UserMetaData(localFileName); #endif if (albumProperty != d->mAllProperties.end()) { trackData.setAlbumName(albumProperty->toString()); } if (artistProperty != d->mAllProperties.end()) { trackData.setArtist(artistProperty->toStringList().join(QStringLiteral(", "))); } if (durationProperty != d->mAllProperties.end()) { trackData.setDuration(QTime::fromMSecsSinceStartOfDay(int(1000 * durationProperty->toDouble()))); } if (titleProperty != d->mAllProperties.end()) { trackData.setTitle(titleProperty->toString()); } if (trackNumberProperty != d->mAllProperties.end()) { trackData.setTrackNumber(trackNumberProperty->toInt()); } if (discNumberProperty != d->mAllProperties.end()) { trackData.setDiscNumber(discNumberProperty->toInt()); } else { trackData.setDiscNumber(1); } if (albumArtistProperty != d->mAllProperties.end()) { trackData.setAlbumArtist(albumArtistProperty->toStringList().join(QStringLiteral(", "))); } if (yearProperty != d->mAllProperties.end()) { trackData.setYear(yearProperty->toInt()); } if (channelsProperty != d->mAllProperties.end()) { trackData.setChannels(channelsProperty->toInt()); } if (bitRateProperty != d->mAllProperties.end()) { trackData.setBitRate(bitRateProperty->toInt()); } if (sampleRateProperty != d->mAllProperties.end()) { trackData.setSampleRate(sampleRateProperty->toInt()); } if (genreProperty != d->mAllProperties.end()) { trackData.setGenre(genreProperty->toStringList().join(QStringLiteral(", "))); } if (composerProperty != d->mAllProperties.end()) { trackData.setComposer(composerProperty->toStringList().join(QStringLiteral(", "))); } if (lyricistProperty != d->mAllProperties.end()) { trackData.setLyricist(lyricistProperty->toStringList().join(QStringLiteral(", "))); } if (commentProperty != d->mAllProperties.end()) { trackData.setComment(commentProperty->toString()); } if (trackData.artist().isEmpty()) { trackData.setArtist(trackData.albumArtist()); } #if defined Q_OS_LINUX && !defined Q_OS_ANDROID trackData.setRating(fileData.rating()); #else trackData.setRating(0); #endif if (!trackData.duration().isValid()) { return; } trackData.setValid(true); #else Q_UNUSED(localFileName) Q_UNUSED(trackData) #endif } diff --git a/src/filescanner.h b/src/filescanner.h index ca182c57..39191224 100644 --- a/src/filescanner.h +++ b/src/filescanner.h @@ -1,65 +1,63 @@ /* * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef FILESCANNER_H #define FILESCANNER_H #include "musicaudiotrack.h" #include #include #include #include namespace KFileMetaData { class ExtractorCollection; } namespace Baloo { class File; } class FileScannerPrivate; class FileScanner { public: FileScanner(); virtual ~FileScanner(); MusicAudioTrack scanOneFile(const QUrl &scanFile, const QMimeDatabase &mimeDatabase); void scanProperties(const Baloo::File &match, MusicAudioTrack &trackData); void scanProperties(const QString &localFileName, MusicAudioTrack &trackData); private: std::unique_ptr d; }; #endif // FILESCANNER_H diff --git a/src/localFileConfiguration/localfileconfiguration.cpp b/src/localFileConfiguration/localfileconfiguration.cpp index d61233f9..1692263f 100644 --- a/src/localFileConfiguration/localfileconfiguration.cpp +++ b/src/localFileConfiguration/localfileconfiguration.cpp @@ -1,122 +1,120 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "localfileconfiguration.h" #include "elisa_settings.h" #include #include #include #include K_PLUGIN_FACTORY_WITH_JSON(KCMElisaLocalFileFactory, "kcm_elisa_local_file.json", registerPlugin();) KCMElisaLocalFile::KCMElisaLocalFile(QObject* parent, const QVariantList &args) : ConfigModule(parent, args) { KAboutData *about = new KAboutData(QStringLiteral("kcm_elisa_local_file"), i18n("Elisa Local Files Indexer Configuration"), QStringLiteral("0.1"), {}, KAboutLicense::LGPL_V3, i18n("Copyright 2017 Matthieu Gallien ")); about->addAuthor(i18n("Matthieu Gallien"),i18n("Author"), QStringLiteral("mgallien@mgallien.fr")); setAboutData(about); auto configurationFileName = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); configurationFileName += QStringLiteral("/elisarc"); Elisa::ElisaConfiguration::instance(configurationFileName); connect(Elisa::ElisaConfiguration::self(), &Elisa::ElisaConfiguration::configChanged, this, &KCMElisaLocalFile::configChanged); connect(&mConfigFileWatcher, &QFileSystemWatcher::fileChanged, this, &KCMElisaLocalFile::configChanged); setRootPath(Elisa::ElisaConfiguration::rootPath()); Elisa::ElisaConfiguration::setRootPath(mRootPath); Elisa::ElisaConfiguration::self()->save(); mConfigFileWatcher.addPath(Elisa::ElisaConfiguration::self()->config()->name()); } KCMElisaLocalFile::~KCMElisaLocalFile() = default; QStringList KCMElisaLocalFile::rootPath() const { return mRootPath; } void KCMElisaLocalFile::defaults() { setRootPath(QStandardPaths::standardLocations(QStandardPaths::MusicLocation)); } void KCMElisaLocalFile::load() { setRootPath(Elisa::ElisaConfiguration::rootPath()); } void KCMElisaLocalFile::save() { Elisa::ElisaConfiguration::setRootPath(mRootPath); Elisa::ElisaConfiguration::self()->save(); } void KCMElisaLocalFile::setRootPath(QStringList rootPath) { if (mRootPath == rootPath && !mRootPath.isEmpty()) { return; } mRootPath.clear(); for (const auto &onePath : rootPath) { if (onePath.startsWith(QStringLiteral("file:///"))) { mRootPath.push_back(onePath.mid(7)); } else if (onePath.startsWith(QStringLiteral("file:/"))) { mRootPath.push_back(onePath.mid(5)); } else { mRootPath.push_back(onePath); } } if (mRootPath.isEmpty()) { auto systemMusicPaths = QStandardPaths::standardLocations(QStandardPaths::MusicLocation); for (const auto &musicPath : qAsConst(systemMusicPaths)) { mRootPath.push_back(musicPath); } } Q_EMIT rootPathChanged(mRootPath); setNeedsSave(true); Q_EMIT needsSaveChanged(); } void KCMElisaLocalFile::configChanged() { setRootPath(Elisa::ElisaConfiguration::rootPath()); } #include "localfileconfiguration.moc" diff --git a/src/localFileConfiguration/localfileconfiguration.h b/src/localFileConfiguration/localfileconfiguration.h index e9e9952f..078a9395 100644 --- a/src/localFileConfiguration/localfileconfiguration.h +++ b/src/localFileConfiguration/localfileconfiguration.h @@ -1,71 +1,69 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #if !defined LOCALFILECONFIGURATION_H_ #define LOCALFILECONFIGURATION_H_ #include #include #include class KCMElisaLocalFile : public KQuickAddons::ConfigModule { Q_OBJECT Q_PROPERTY(QStringList rootPath READ rootPath WRITE setRootPath NOTIFY rootPathChanged) public: explicit KCMElisaLocalFile(QObject *parent, const QVariantList &args); ~KCMElisaLocalFile() override; QStringList rootPath() const; Q_SIGNALS: void rootPathChanged(QStringList rootPath); public Q_SLOTS: void defaults() override final; void load() override final; void save() override final; void setRootPath(QStringList rootPath); private Q_SLOTS: void configChanged(); private: QStringList mRootPath; QFileSystemWatcher mConfigFileWatcher; }; #endif diff --git a/src/localFileConfiguration/package/contents/ui/main.qml b/src/localFileConfiguration/package/contents/ui/main.qml index 665d2914..7fc8fc31 100644 --- a/src/localFileConfiguration/package/contents/ui/main.qml +++ b/src/localFileConfiguration/package/contents/ui/main.qml @@ -1,157 +1,155 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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 1.4 import QtQuick.Layouts 1.3 import QtQuick.Dialogs 1.2 import QtQml.Models 2.3 import org.kde.kcm 1.0 Item { //implicitWidth and implicitHeight will be used as initial size //when loaded in kcmshell5 implicitWidth: 400 implicitHeight: 200 LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft LayoutMirroring.childrenInherit: true ConfigModule.buttons: ConfigModule.Help|ConfigModule.Apply SystemPalette { id: myPalette colorGroup: SystemPalette.Active } Component { id: highlightBar Rectangle { width: 200; height: 50 color: myPalette.highlight } } Component { id: pathDelegate Item { id: delegateItem height: 3 * 30 width: pathList.width Rectangle { anchors.fill: parent anchors.margins: 0.1 * 30 color: myPalette.base MouseArea { anchors.fill: parent hoverEnabled: true onEntered: pathList.currentIndex = delegateItem.DelegateModel.itemsIndex Label { text: modelData anchors.centerIn: parent } ToolButton { iconName: 'list-remove' anchors.top: parent.top anchors.right: parent.right onClicked: { var oldPaths = kcm.rootPath oldPaths.splice(delegateItem.DelegateModel.itemsIndex, 1) kcm.rootPath = oldPaths } } } } } } RowLayout { spacing: 0 anchors.fill: parent ScrollView { flickableItem.boundsBehavior: Flickable.StopAtBounds Layout.fillWidth: true Layout.fillHeight: true ListView { id:pathList anchors.fill: parent model: DelegateModel { model: kcm.rootPath delegate: pathDelegate } highlight: highlightBar } } ColumnLayout { Layout.fillHeight: true Layout.leftMargin: !LayoutMirroring.enabled ? (0.3 * 30) : 0 Layout.rightMargin: LayoutMirroring.enabled ? (0.3 * 30) : 0 Button { text: i18n("Add new path") onClicked: fileDialog.open() Layout.alignment: Qt.AlignTop | Qt.AlignLeft FileDialog { id: fileDialog title: i18n("Choose a Folder") folder: shortcuts.home selectFolder: true visible: false onAccepted: { var oldPaths = kcm.rootPath oldPaths.push(fileDialog.fileUrls) kcm.rootPath = oldPaths } } } Item { Layout.fillHeight: true } } } } diff --git a/src/main.cpp b/src/main.cpp index eec69091..aacd94d7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,159 +1,157 @@ /* * Copyright 2015-2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "config-upnp-qt.h" #include "elisaapplication.h" #include "elisa_settings.h" //#define QT_QML_DEBUG #if defined KF5Declarative_FOUND && KF5Declarative_FOUND #include #endif #include #include #include #if defined KF5Crash_FOUND && KF5Crash_FOUND #include #endif #if defined KF5DBusAddons_FOUND && KF5DBusAddons_FOUND #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if defined Qt5AndroidExtras_FOUND && Qt5AndroidExtras_FOUND #include #include #endif #if defined Q_OS_ANDROID int __attribute__((visibility("default"))) main(int argc, char *argv[]) #else int main(int argc, char *argv[]) #endif { QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); qputenv("QT_GSTREAMER_USE_PLAYBIN_VOLUME", "true"); QApplication app(argc, argv); #if defined KF5Crash_FOUND && KF5Crash_FOUND KCrash::initialize(); #endif QApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("elisa"))); KLocalizedString::setApplicationDomain("elisa"); KAboutData aboutData( QStringLiteral("elisa"), i18n("Elisa"), QStringLiteral("0.3.0"), i18n("A Simple Music Player written with KDE Frameworks"), KAboutLicense::LGPL_V3, i18n("(c) 2015-2018, Elisa contributors")); aboutData.addAuthor(QStringLiteral("Matthieu Gallien"),i18n("Creator"), QStringLiteral("mgallien@mgallien.fr")); aboutData.addAuthor(QStringLiteral("Alexander Stippich"), i18n("Author"), QStringLiteral("a.stippich@gmx.net")); aboutData.addCredit(QStringLiteral("Andrew Lake"), i18n("Concept and design work"), QStringLiteral("jamboarder@gmail.com")); aboutData.addCredit(QStringLiteral("Luigi Toscano"), i18n("Localization support"), QStringLiteral("luigi.toscano@tiscali.it")); aboutData.addCredit(QStringLiteral("Safa Alfulaij"), i18n("Right to left support in interface"), QStringLiteral("safa1996alfulaij@gmail.com")); aboutData.addCredit(QStringLiteral("Diego Gangl"), i18n("Various improvements to the interface"), QStringLiteral("diego@sinestesia.co")); KAboutData::setApplicationData(aboutData); KLocalizedString::setApplicationDomain("elisa"); QCommandLineParser parser; parser.addHelpOption(); parser.addVersionOption(); aboutData.setupCommandLine(&parser); parser.process(app); aboutData.processCommandLine(&parser); #if defined Qt5AndroidExtras_FOUND && Qt5AndroidExtras_FOUND qDebug() << QCoreApplication::arguments(); QAndroidJniObject::callStaticMethod("com/kde/elisa/ElisaService", "startMyService", "(Landroid/content/Context;)V", QtAndroid::androidContext().object()); #endif QQuickStyle::setStyle(QStringLiteral("org.kde.desktop")); QQuickStyle::setFallbackStyle(QStringLiteral("Fusion")); QQmlApplicationEngine engine; engine.addImportPath(QStringLiteral("qrc:/imports")); QQmlFileSelector selector(&engine); #if defined KF5Declarative_FOUND && KF5Declarative_FOUND KDeclarative::KDeclarative decl; decl.setDeclarativeEngine(&engine); decl.setupEngine(&engine); decl.setupContext(); #endif engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); engine.rootContext()->setContextProperty(QStringLiteral("logicalDpi"), QGuiApplication::primaryScreen()->logicalDotsPerInch()); #if defined KF5DBusAddons_FOUND && KF5DBusAddons_FOUND KDBusService elisaService(KDBusService::Unique); #endif std::unique_ptr myApp = std::make_unique(); #if defined KF5DBusAddons_FOUND && KF5DBusAddons_FOUND QObject::connect(&elisaService, &KDBusService::activateActionRequested, myApp.get(), &ElisaApplication::activateActionRequested); QObject::connect(&elisaService, &KDBusService::activateRequested, myApp.get(), &ElisaApplication::activateRequested); QObject::connect(&elisaService, &KDBusService::openRequested, myApp.get(), &ElisaApplication::openRequested); #endif myApp->setArguments(parser.positionalArguments()); engine.rootContext()->setContextProperty(QStringLiteral("elisa"), myApp.release()); engine.load(QUrl(QStringLiteral("qrc:/qml/ElisaMainWindow.qml"))); return app.exec(); } diff --git a/src/manageaudioplayer.cpp b/src/manageaudioplayer.cpp index 4aed1f7b..e265fcd9 100644 --- a/src/manageaudioplayer.cpp +++ b/src/manageaudioplayer.cpp @@ -1,581 +1,579 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "manageaudioplayer.h" #include "mediaplaylist.h" #include ManageAudioPlayer::ManageAudioPlayer(QObject *parent) : QObject(parent) { } QPersistentModelIndex ManageAudioPlayer::currentTrack() const { return mCurrentTrack; } QAbstractItemModel *ManageAudioPlayer::playListModel() const { return mPlayListModel; } int ManageAudioPlayer::urlRole() const { return mUrlRole; } int ManageAudioPlayer::isPlayingRole() const { return mIsPlayingRole; } QUrl ManageAudioPlayer::playerSource() const { if (!mCurrentTrack.isValid()) { return QUrl(); } return mCurrentTrack.data(mUrlRole).toUrl(); } QMediaPlayer::MediaStatus ManageAudioPlayer::playerStatus() const { return mPlayerStatus; } int ManageAudioPlayer::playerPlaybackState() const { return mPlayerPlaybackState; } QMediaPlayer::Error ManageAudioPlayer::playerError() const { return mPlayerError; } int ManageAudioPlayer::audioDuration() const { return mAudioDuration; } bool ManageAudioPlayer::playerIsSeekable() const { return mPlayerIsSeekable; } int ManageAudioPlayer::playerPosition() const { return mPlayerPosition; } int ManageAudioPlayer::playControlPosition() const { return mPlayerPosition; } QVariantMap ManageAudioPlayer::persistentState() const { auto persistentStateValue = QVariantMap(); persistentStateValue[QStringLiteral("isPlaying")] = mPlayingState; persistentStateValue[QStringLiteral("playerPosition")] = mPlayerPosition; if (mCurrentTrack.isValid()) { persistentStateValue[QStringLiteral("audioPlayerCurrentTitle")] = mCurrentTrack.data(mTitleRole); persistentStateValue[QStringLiteral("audioPlayerCurrentArtistName")] = mCurrentTrack.data(mArtistNameRole); persistentStateValue[QStringLiteral("audioPlayerCurrentAlbumName")] = mCurrentTrack.data(mAlbumNameRole); } else { persistentStateValue[QStringLiteral("audioPlayerCurrentTitle")] = {}; persistentStateValue[QStringLiteral("audioPlayerCurrentArtistName")] = {}; persistentStateValue[QStringLiteral("audioPlayerCurrentAlbumName")] = {}; } return persistentStateValue; } int ManageAudioPlayer::playListPosition() const { if (mCurrentTrack.isValid()) { return mCurrentTrack.row(); } return 0; } int ManageAudioPlayer::titleRole() const { return mTitleRole; } int ManageAudioPlayer::artistNameRole() const { return mArtistNameRole; } int ManageAudioPlayer::albumNameRole() const { return mAlbumNameRole; } void ManageAudioPlayer::setCurrentTrack(const QPersistentModelIndex ¤tTrack) { mOldCurrentTrack = mCurrentTrack; mCurrentTrack = currentTrack; if (mCurrentTrack.isValid()) { restorePreviousState(); } mPlayerError = QMediaPlayer::NoError; if (mOldCurrentTrack != mCurrentTrack || mPlayingState) { Q_EMIT currentTrackChanged(); } switch (mPlayerPlaybackState) { case StoppedState: notifyPlayerSourceProperty(); break; case PlayingState: case PausedState: triggerStop(); if (mPlayingState && !mCurrentTrack.isValid()) { mPlayingState = false; } mSkippingCurrentTrack = true; break; } } void ManageAudioPlayer::setPlayListModel(QAbstractItemModel *aPlayListModel) { if (mPlayListModel == aPlayListModel) { return; } if (mPlayListModel) { disconnect(mPlayListModel, &QAbstractItemModel::dataChanged, this, &ManageAudioPlayer::tracksDataChanged); } mPlayListModel = aPlayListModel; if (mPlayListModel) { connect(mPlayListModel, &QAbstractItemModel::dataChanged, this, &ManageAudioPlayer::tracksDataChanged); } Q_EMIT playListModelChanged(); } void ManageAudioPlayer::setUrlRole(int value) { mUrlRole = value; Q_EMIT urlRoleChanged(); notifyPlayerSourceProperty(); restorePreviousState(); } void ManageAudioPlayer::setIsPlayingRole(int value) { if (mIsPlayingRole == value) { return; } mIsPlayingRole = value; Q_EMIT isPlayingRoleChanged(); } void ManageAudioPlayer::setPlayerStatus(QMediaPlayer::MediaStatus playerStatus) { if (mPlayerStatus == playerStatus) { return; } if (playerStatus < static_cast(QMediaPlayer::UnknownMediaStatus) || playerStatus > static_cast(QMediaPlayer::InvalidMedia)) { return; } mPlayerStatus = static_cast(playerStatus); Q_EMIT playerStatusChanged(); switch (mPlayerStatus) { case QMediaPlayer::NoMedia: break; case QMediaPlayer::LoadingMedia: break; case QMediaPlayer::LoadedMedia: if (mPlayingState) { triggerPlay(); } break; case QMediaPlayer::BufferingMedia: break; case QMediaPlayer::StalledMedia: break; case QMediaPlayer::BufferedMedia: break; case QMediaPlayer::EndOfMedia: break; case QMediaPlayer::InvalidMedia: triggerSkipNextTrack(); break; case QMediaPlayer::UnknownMediaStatus: break; } } void ManageAudioPlayer::setPlayerPlaybackState(int playerPlaybackState) { if (mPlayerPlaybackState == playerPlaybackState) { return; } if (playerPlaybackState < static_cast(StoppedState) || playerPlaybackState > static_cast(PausedState)) { return; } mPlayerPlaybackState = static_cast(playerPlaybackState); Q_EMIT playerPlaybackStateChanged(); if (!mSkippingCurrentTrack) { switch(mPlayerPlaybackState) { case StoppedState: if (mPlayerStatus == QMediaPlayer::EndOfMedia || mPlayerStatus == QMediaPlayer::InvalidMedia) { triggerSkipNextTrack(); } if (mPlayListModel && mCurrentTrack.isValid()) { mPlayListModel->setData(mCurrentTrack, MediaPlayList::NotPlaying, mIsPlayingRole); } break; case PlayingState: if (mPlayListModel && mCurrentTrack.isValid()) { mPlayListModel->setData(mCurrentTrack, MediaPlayList::IsPlaying, mIsPlayingRole); } break; case PausedState: if (mPlayListModel && mCurrentTrack.isValid()) { mPlayListModel->setData(mCurrentTrack, MediaPlayList::IsPaused, mIsPlayingRole); } break; } } else { switch(mPlayerPlaybackState) { case StoppedState: notifyPlayerSourceProperty(); mSkippingCurrentTrack = false; if (mPlayListModel && mOldCurrentTrack.isValid()) { mPlayListModel->setData(mOldCurrentTrack, MediaPlayList::NotPlaying, mIsPlayingRole); } break; case PlayingState: if (mPlayListModel && mCurrentTrack.isValid()) { mPlayListModel->setData(mCurrentTrack, MediaPlayList::IsPlaying, mIsPlayingRole); } break; case PausedState: if (mPlayListModel && mCurrentTrack.isValid()) { mPlayListModel->setData(mCurrentTrack, MediaPlayList::IsPaused, mIsPlayingRole); } break; } } } void ManageAudioPlayer::setPlayerError(QMediaPlayer::Error playerError) { if (mPlayerError == playerError) { return; } mPlayerError = playerError; Q_EMIT playerErrorChanged(); if (mPlayerError != QMediaPlayer::NoError) { auto currentSource = playerSource(); Q_EMIT sourceInError(currentSource, mPlayerError); if (currentSource.isLocalFile()) { Q_EMIT displayTrackError(currentSource.toLocalFile()); } else { Q_EMIT displayTrackError(currentSource.toString()); } } } void ManageAudioPlayer::ensurePause() { if (mPlayingState) { mPlayingState = false; triggerPause(); } } void ManageAudioPlayer::ensurePlay() { if (!mPlayingState) { mPlayingState = true; triggerPlay(); } } void ManageAudioPlayer::stop() { mPlayingState = false; triggerStop(); } void ManageAudioPlayer::playPause() { mPlayingState = !mPlayingState; switch (mPlayerStatus) { case QMediaPlayer::LoadedMedia: case QMediaPlayer::BufferingMedia: case QMediaPlayer::BufferedMedia: case QMediaPlayer::LoadingMedia: if (mPlayingState) { triggerPlay(); } else { triggerPause(); } break; case QMediaPlayer::EndOfMedia: if (mPlayerPlaybackState == PlayingState && !mPlayingState) { triggerPause(); } else if (mPlayerPlaybackState == PausedState && mPlayingState) { triggerPlay(); } break; case QMediaPlayer::NoMedia: case QMediaPlayer::StalledMedia: case QMediaPlayer::InvalidMedia: case QMediaPlayer::UnknownMediaStatus: break; } } void ManageAudioPlayer::setAudioDuration(int audioDuration) { if (mAudioDuration == audioDuration) { return; } mAudioDuration = audioDuration; Q_EMIT audioDurationChanged(); } void ManageAudioPlayer::setPlayerIsSeekable(bool playerIsSeekable) { if (mPlayerIsSeekable == playerIsSeekable) { return; } mPlayerIsSeekable = playerIsSeekable; Q_EMIT playerIsSeekableChanged(); } void ManageAudioPlayer::setPlayerPosition(int playerPosition) { if (mPlayerPosition == playerPosition) { return; } mPlayerPosition = playerPosition; Q_EMIT playerPositionChanged(); QTimer::singleShot(0, [this]() {Q_EMIT playControlPositionChanged();}); } void ManageAudioPlayer::setPlayControlPosition(int playerPosition) { Q_EMIT seek(playerPosition); } void ManageAudioPlayer::setPersistentState(const QVariantMap &persistentStateValue) { if (mPersistentState == persistentStateValue) { return; } mPersistentState = persistentStateValue; Q_EMIT persistentStateChanged(); if (mCurrentTrack.isValid()) { restorePreviousState(); } } void ManageAudioPlayer::playerSeek(int position) { Q_EMIT seek(position); } void ManageAudioPlayer::playListFinished() { mPlayingState = false; } void ManageAudioPlayer::tracksDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) { if (!mCurrentTrack.isValid()) { return; } if (mCurrentTrack.row() > bottomRight.row() || mCurrentTrack.row() < topLeft.row()) { return; } if (mCurrentTrack.column() > bottomRight.column() || mCurrentTrack.column() < topLeft.column()) { return; } if (roles.isEmpty()) { notifyPlayerSourceProperty(); restorePreviousState(); } else { for(auto oneRole : roles) { if (oneRole == mUrlRole) { notifyPlayerSourceProperty(); restorePreviousState(); } } } } void ManageAudioPlayer::setTitleRole(int titleRole) { if (mTitleRole == titleRole) { return; } mTitleRole = titleRole; Q_EMIT titleRoleChanged(); if (mCurrentTrack.isValid()) { restorePreviousState(); } } void ManageAudioPlayer::setArtistNameRole(int artistNameRole) { if (mArtistNameRole == artistNameRole) { return; } mArtistNameRole = artistNameRole; Q_EMIT artistNameRoleChanged(); if (mCurrentTrack.isValid()) { restorePreviousState(); } } void ManageAudioPlayer::setAlbumNameRole(int albumNameRole) { if (mAlbumNameRole == albumNameRole) { return; } mAlbumNameRole = albumNameRole; Q_EMIT albumNameRoleChanged(); if (mCurrentTrack.isValid()) { restorePreviousState(); } } void ManageAudioPlayer::notifyPlayerSourceProperty() { auto newUrlValue = mCurrentTrack.data(mUrlRole); if (mSkippingCurrentTrack || mOldPlayerSource != newUrlValue) { Q_EMIT playerSourceChanged(mCurrentTrack.data(mUrlRole).toUrl()); mOldPlayerSource = newUrlValue; } } void ManageAudioPlayer::triggerPlay() { QTimer::singleShot(0, [this]() {Q_EMIT playerPlay();}); } void ManageAudioPlayer::triggerPause() { QTimer::singleShot(0, [this]() {Q_EMIT playerPause();}); } void ManageAudioPlayer::triggerStop() { QTimer::singleShot(0, [this]() {Q_EMIT playerStop();}); } void ManageAudioPlayer::triggerSkipNextTrack() { QTimer::singleShot(0, [this]() {Q_EMIT skipNextTrack();}); } void ManageAudioPlayer::restorePreviousState() { if (mPersistentState.isEmpty()) { return; } auto itTitle = mPersistentState.find(QStringLiteral("audioPlayerCurrentTitle")); auto itArtistName = mPersistentState.find(QStringLiteral("audioPlayerCurrentArtistName")); auto itAlbumName = mPersistentState.find(QStringLiteral("audioPlayerCurrentAlbumName")); if (itTitle == mPersistentState.end() || itArtistName == mPersistentState.end() || itAlbumName == mPersistentState.end()) { return; } if (*itTitle != mCurrentTrack.data(mTitleRole) || *itArtistName != mCurrentTrack.data(mArtistNameRole) || *itAlbumName != mCurrentTrack.data(mAlbumNameRole)) { if (mCurrentTrack.isValid() && mCurrentTrack.data(mTitleRole).isValid() && mCurrentTrack.data(mArtistNameRole).isValid() && mCurrentTrack.data(mAlbumNameRole).isValid()) { mPersistentState.clear(); } return; } if (!mCurrentTrack.data(mUrlRole).toUrl().isValid()) { return; } auto isPlaying = mPersistentState.find(QStringLiteral("isPlaying")); if (isPlaying != mPersistentState.end() && mPlayingState != isPlaying->toBool()) { mPlayingState = isPlaying->toBool(); } auto playerPosition = mPersistentState.find(QStringLiteral("playerPosition")); if (playerPosition != mPersistentState.end()) { mPlayerPosition = playerPosition->toInt(); Q_EMIT seek(mPlayerPosition); } mPersistentState.clear(); } #include "moc_manageaudioplayer.cpp" diff --git a/src/manageaudioplayer.h b/src/manageaudioplayer.h index bd99086a..8d1dd00a 100644 --- a/src/manageaudioplayer.h +++ b/src/manageaudioplayer.h @@ -1,306 +1,304 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef MANAGEAUDIOPLAYER_H #define MANAGEAUDIOPLAYER_H #include "elisaLib_export.h" #include #include #include #include #include class ELISALIB_EXPORT ManageAudioPlayer : public QObject { Q_OBJECT Q_PROPERTY(QPersistentModelIndex currentTrack READ currentTrack WRITE setCurrentTrack NOTIFY currentTrackChanged) Q_PROPERTY(QAbstractItemModel* playListModel READ playListModel WRITE setPlayListModel NOTIFY playListModelChanged) Q_PROPERTY(QUrl playerSource READ playerSource NOTIFY playerSourceChanged) Q_PROPERTY(int titleRole READ titleRole WRITE setTitleRole NOTIFY titleRoleChanged) Q_PROPERTY(int artistNameRole READ artistNameRole WRITE setArtistNameRole NOTIFY artistNameRoleChanged) Q_PROPERTY(int albumNameRole READ albumNameRole WRITE setAlbumNameRole NOTIFY albumNameRoleChanged) Q_PROPERTY(int urlRole READ urlRole WRITE setUrlRole NOTIFY urlRoleChanged) Q_PROPERTY(int isPlayingRole READ isPlayingRole WRITE setIsPlayingRole NOTIFY isPlayingRoleChanged) Q_PROPERTY(QMediaPlayer::MediaStatus playerStatus READ playerStatus WRITE setPlayerStatus NOTIFY playerStatusChanged) Q_PROPERTY(int playerPlaybackState READ playerPlaybackState WRITE setPlayerPlaybackState NOTIFY playerPlaybackStateChanged) Q_PROPERTY(QMediaPlayer::Error playerError READ playerError WRITE setPlayerError NOTIFY playerErrorChanged) Q_PROPERTY(int audioDuration READ audioDuration WRITE setAudioDuration NOTIFY audioDurationChanged) Q_PROPERTY(bool playerIsSeekable READ playerIsSeekable WRITE setPlayerIsSeekable NOTIFY playerIsSeekableChanged) Q_PROPERTY(int playerPosition READ playerPosition WRITE setPlayerPosition NOTIFY playerPositionChanged) Q_PROPERTY(int playControlPosition READ playControlPosition WRITE setPlayControlPosition NOTIFY playControlPositionChanged) Q_PROPERTY(QVariantMap persistentState READ persistentState WRITE setPersistentState NOTIFY persistentStateChanged) public: enum PlayerPlaybackState { PlayingState = 1, PausedState = 2, StoppedState = 0, }; Q_ENUM(PlayerPlaybackState) explicit ManageAudioPlayer(QObject *parent = nullptr); QPersistentModelIndex currentTrack() const; QAbstractItemModel* playListModel() const; int urlRole() const; int isPlayingRole() const; QUrl playerSource() const; QMediaPlayer::MediaStatus playerStatus() const; int playerPlaybackState() const; QMediaPlayer::Error playerError() const; int audioDuration() const; bool playerIsSeekable() const; int playerPosition() const; int playControlPosition() const; QVariantMap persistentState() const; int playListPosition() const; int titleRole() const; int artistNameRole() const; int albumNameRole() const; Q_SIGNALS: void currentTrackChanged(); void playListModelChanged(); void playerSourceChanged(QUrl url); void urlRoleChanged(); void isPlayingRoleChanged(); void playerStatusChanged(); void playerPlaybackStateChanged(); void playerErrorChanged(); void playerPlay(); void playerPause(); void playerStop(); void skipNextTrack(); void audioDurationChanged(); void playerIsSeekableChanged(); void playerPositionChanged(); void playControlPositionChanged(); void persistentStateChanged(); void seek(int position); void titleRoleChanged(); void artistNameRoleChanged(); void albumNameRoleChanged(); void sourceInError(QUrl source, QMediaPlayer::Error playerError); void displayTrackError(const QString &fileName); public Q_SLOTS: void setCurrentTrack(const QPersistentModelIndex ¤tTrack); void setPlayListModel(QAbstractItemModel* aPlayListModel); void setUrlRole(int value); void setIsPlayingRole(int value); void setPlayerStatus(QMediaPlayer::MediaStatus playerStatus); void setPlayerPlaybackState(int playerPlaybackState); void setPlayerError(QMediaPlayer::Error playerError); void ensurePause(); void ensurePlay(); void playPause(); void stop(); void setAudioDuration(int audioDuration); void setPlayerIsSeekable(bool playerIsSeekable); void setPlayerPosition(int playerPosition); void setPlayControlPosition(int playerPosition); void setPersistentState(const QVariantMap &persistentStateValue); void playerSeek(int position); void playListFinished(); void tracksDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles); void setTitleRole(int titleRole); void setArtistNameRole(int artistNameRole); void setAlbumNameRole(int albumNameRole); private: void notifyPlayerSourceProperty(); void triggerPlay(); void triggerPause(); void triggerStop(); void triggerSkipNextTrack(); void restorePreviousState(); QPersistentModelIndex mCurrentTrack; QPersistentModelIndex mOldCurrentTrack; QAbstractItemModel *mPlayListModel = nullptr; int mTitleRole = Qt::DisplayRole; int mArtistNameRole = Qt::DisplayRole; int mAlbumNameRole = Qt::DisplayRole; int mUrlRole = Qt::DisplayRole; int mIsPlayingRole = Qt::DisplayRole; QVariant mOldPlayerSource; QMediaPlayer::MediaStatus mPlayerStatus = QMediaPlayer::NoMedia; PlayerPlaybackState mPlayerPlaybackState = StoppedState; QMediaPlayer::Error mPlayerError = QMediaPlayer::NoError; bool mPlayingState = false; bool mSkippingCurrentTrack = false; int mAudioDuration = 0; bool mPlayerIsSeekable = false; int mPlayerPosition = 0; QVariantMap mPersistentState; }; #endif // MANAGEAUDIOPLAYER_H diff --git a/src/manageheaderbar.cpp b/src/manageheaderbar.cpp index f508ec1c..ae33f493 100644 --- a/src/manageheaderbar.cpp +++ b/src/manageheaderbar.cpp @@ -1,414 +1,412 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "manageheaderbar.h" #include #include #include #include ManageHeaderBar::ManageHeaderBar(QObject *parent) : QObject(parent) { } void ManageHeaderBar::setArtistRole(int value) { mArtistRole = value; Q_EMIT artistRoleChanged(); } int ManageHeaderBar::artistRole() const { return mArtistRole; } void ManageHeaderBar::setTitleRole(int value) { mTitleRole = value; Q_EMIT titleRoleChanged(); } int ManageHeaderBar::titleRole() const { return mTitleRole; } void ManageHeaderBar::setAlbumRole(int value) { mAlbumRole = value; Q_EMIT albumRoleChanged(); } int ManageHeaderBar::albumRole() const { return mAlbumRole; } void ManageHeaderBar::setImageRole(int value) { mImageRole = value; Q_EMIT imageRoleChanged(); } int ManageHeaderBar::imageRole() const { return mImageRole; } void ManageHeaderBar::setAlbumIdRole(int albumIdRole) { mAlbumIdRole = albumIdRole; Q_EMIT albumIdRoleChanged(); } int ManageHeaderBar::albumIdRole() const { return mAlbumIdRole; } QVariant ManageHeaderBar::album() const { if (!mCurrentTrack.isValid()) { return QStringLiteral(""); } return mCurrentTrack.data(mAlbumRole); } QVariant ManageHeaderBar::title() const { if (!mCurrentTrack.isValid()) { return QStringLiteral(""); } return mCurrentTrack.data(mTitleRole); } QVariant ManageHeaderBar::artist() const { if (!mCurrentTrack.isValid()) { return QStringLiteral(""); } return mCurrentTrack.data(mArtistRole); } QUrl ManageHeaderBar::image() const { if (!mCurrentTrack.isValid()) { return {}; } return mCurrentTrack.data(mImageRole).toUrl(); } qulonglong ManageHeaderBar::albumId() const { if (!mCurrentTrack.isValid()) { return 0; } return mCurrentTrack.data(mAlbumIdRole).toULongLong(); } bool ManageHeaderBar::isValid() const { if (!mCurrentTrack.isValid()) { return false; } return mCurrentTrack.data(mIsValidRole).toBool(); } int ManageHeaderBar::remainingTracks() const { if (!mCurrentTrack.isValid()) { return 0; } return mPlayListModel->rowCount(mCurrentTrack.parent()) - mCurrentTrack.row() - 1; } int ManageHeaderBar::isValidRole() const { return mIsValidRole; } QPersistentModelIndex ManageHeaderBar::currentTrack() const { return mCurrentTrack; } void ManageHeaderBar::playListLayoutChanged(const QList &parents, QAbstractItemModel::LayoutChangeHint hint) { Q_UNUSED(parents); Q_UNUSED(hint); qDebug() << "ManageHeaderBar::playListLayoutChanged" << "not implemented"; } void ManageHeaderBar::tracksInserted(const QModelIndex &parent, int first, int last) { Q_UNUSED(parent); Q_UNUSED(first); Q_UNUSED(last); if (!mCurrentTrack.isValid()) { return; } if (mCurrentTrack.row() >= first) { return; } Q_EMIT remainingTracksChanged(); mOldRemainingTracks = remainingTracks(); } void ManageHeaderBar::tracksDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) { if (!mCurrentTrack.isValid()) { return; } if (mCurrentTrack.row() > bottomRight.row() || mCurrentTrack.row() < topLeft.row()) { return; } if (mCurrentTrack.column() > bottomRight.column() || mCurrentTrack.column() < topLeft.column()) { return; } if (roles.isEmpty()) { notifyArtistProperty(); notifyTitleProperty(); notifyAlbumProperty(); notifyImageProperty(); notifyAlbumIdProperty(); notifyIsValidProperty(); } else { for(auto oneRole : roles) { if (oneRole == mArtistRole) { notifyArtistProperty(); } if (oneRole == mTitleRole) { notifyTitleProperty(); } if (oneRole == mAlbumRole) { notifyAlbumProperty(); } if (oneRole == mImageRole) { notifyImageProperty(); } if (oneRole == mAlbumIdRole) { notifyAlbumIdProperty(); } if (oneRole == mIsValidRole) { notifyIsValidProperty(); } } } } void ManageHeaderBar::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); mOldRemainingTracks = remainingTracks(); } void ManageHeaderBar::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 newRemainingTracks = remainingTracks(); if (mOldRemainingTracks != newRemainingTracks) { Q_EMIT remainingTracksChanged(); } } void ManageHeaderBar::tracksRemoved(const QModelIndex &parent, int first, int last) { Q_UNUSED(parent); Q_UNUSED(first); Q_UNUSED(last); if (!mCurrentTrack.isValid()) { notifyArtistProperty(); notifyTitleProperty(); notifyAlbumProperty(); notifyImageProperty(); notifyAlbumIdProperty(); notifyIsValidProperty(); notifyRemainingTracksProperty(); return; } notifyRemainingTracksProperty(); } void ManageHeaderBar::notifyArtistProperty() { auto newArtistValue = mCurrentTrack.data(mArtistRole); if (mOldArtist != newArtistValue) { Q_EMIT artistChanged(); mOldArtist = newArtistValue; } } void ManageHeaderBar::notifyTitleProperty() { auto newTitleValue = mCurrentTrack.data(mTitleRole); if (mOldTitle != newTitleValue) { Q_EMIT titleChanged(); mOldTitle = newTitleValue; } } void ManageHeaderBar::notifyAlbumProperty() { auto newAlbumValue = mCurrentTrack.data(mAlbumRole); if (mOldAlbum != newAlbumValue) { Q_EMIT albumChanged(); mOldAlbum = newAlbumValue; } } void ManageHeaderBar::notifyImageProperty() { auto newImageValue = mCurrentTrack.data(mImageRole); if (mOldImage != newImageValue) { Q_EMIT imageChanged(); mOldImage = newImageValue; } } void ManageHeaderBar::notifyAlbumIdProperty() { bool conversionOk; auto newAlbumIdValue = mCurrentTrack.data(mAlbumIdRole).toULongLong(&conversionOk); if (conversionOk && mOldAlbumId != newAlbumIdValue) { Q_EMIT albumIdChanged(); mOldAlbumId = newAlbumIdValue; } else if (!conversionOk && mOldAlbumId != 0) { Q_EMIT albumIdChanged(); mOldAlbumId = 0; } } void ManageHeaderBar::notifyIsValidProperty() { auto newIsValidValue = mCurrentTrack.data(mIsValidRole).toBool(); if (mOldIsValid != newIsValidValue) { Q_EMIT isValidChanged(); mOldIsValid = newIsValidValue; } } void ManageHeaderBar::notifyRemainingTracksProperty() { auto newRemainingTracksValue = remainingTracks(); if (mOldRemainingTracks != newRemainingTracksValue) { Q_EMIT remainingTracksChanged(); mOldRemainingTracks = newRemainingTracksValue; } } void ManageHeaderBar::setIsValidRole(int isValidRole) { mIsValidRole = isValidRole; emit isValidRoleChanged(); } void ManageHeaderBar::setCurrentTrack(const QPersistentModelIndex ¤tTrack) { if (mCurrentTrack == currentTrack) { return; } auto oldRemainingTracksCount = remainingTracks(); mCurrentTrack = currentTrack; Q_EMIT currentTrackChanged(); if (mCurrentTrack.isValid() && oldRemainingTracksCount != remainingTracks()) { Q_EMIT remainingTracksChanged(); mOldRemainingTracks = remainingTracks(); } notifyArtistProperty(); notifyTitleProperty(); notifyAlbumProperty(); notifyImageProperty(); notifyAlbumIdProperty(); notifyIsValidProperty(); } void ManageHeaderBar::setPlayListModel(QAbstractItemModel *aPlayListModel) { if (mPlayListModel) { disconnect(mPlayListModel, &QAbstractItemModel::rowsInserted, this, &ManageHeaderBar::tracksInserted); disconnect(mPlayListModel, &QAbstractItemModel::rowsAboutToBeMoved, this, &ManageHeaderBar::tracksAboutToBeMoved); disconnect(mPlayListModel, &QAbstractItemModel::rowsMoved, this, &ManageHeaderBar::tracksMoved); disconnect(mPlayListModel, &QAbstractItemModel::rowsRemoved, this, &ManageHeaderBar::tracksRemoved); disconnect(mPlayListModel, &QAbstractItemModel::dataChanged, this, &ManageHeaderBar::tracksDataChanged); disconnect(mPlayListModel, &QAbstractItemModel::layoutChanged, this, &ManageHeaderBar::playListLayoutChanged); } mPlayListModel = aPlayListModel; if (mPlayListModel) { connect(mPlayListModel, &QAbstractItemModel::rowsInserted, this, &ManageHeaderBar::tracksInserted); connect(mPlayListModel, &QAbstractItemModel::rowsAboutToBeMoved, this, &ManageHeaderBar::tracksAboutToBeMoved); connect(mPlayListModel, &QAbstractItemModel::rowsMoved, this, &ManageHeaderBar::tracksMoved); connect(mPlayListModel, &QAbstractItemModel::rowsRemoved, this, &ManageHeaderBar::tracksRemoved); connect(mPlayListModel, &QAbstractItemModel::dataChanged, this, &ManageHeaderBar::tracksDataChanged); connect(mPlayListModel, &QAbstractItemModel::layoutChanged, this, &ManageHeaderBar::playListLayoutChanged); } Q_EMIT playListModelChanged(); } QAbstractItemModel *ManageHeaderBar::playListModel() const { return mPlayListModel; } #include "moc_manageheaderbar.cpp" diff --git a/src/manageheaderbar.h b/src/manageheaderbar.h index c9a50ee2..3ea94d35 100644 --- a/src/manageheaderbar.h +++ b/src/manageheaderbar.h @@ -1,250 +1,248 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef MANAGEHEADERBAR_H #define MANAGEHEADERBAR_H #include "elisaLib_export.h" #include #include #include #include #include #include class ELISALIB_EXPORT ManageHeaderBar : public QObject { Q_OBJECT Q_PROPERTY(QPersistentModelIndex currentTrack READ currentTrack WRITE setCurrentTrack NOTIFY currentTrackChanged) Q_PROPERTY(QAbstractItemModel* playListModel READ playListModel WRITE setPlayListModel NOTIFY playListModelChanged) Q_PROPERTY(int artistRole READ artistRole WRITE setArtistRole NOTIFY artistRoleChanged) Q_PROPERTY(int titleRole READ titleRole WRITE setTitleRole NOTIFY titleRoleChanged) Q_PROPERTY(int albumRole READ albumRole WRITE setAlbumRole NOTIFY albumRoleChanged) Q_PROPERTY(int imageRole READ imageRole WRITE setImageRole NOTIFY imageRoleChanged) Q_PROPERTY(int albumIdRole READ albumIdRole WRITE setAlbumIdRole NOTIFY albumIdRoleChanged) Q_PROPERTY(int isValidRole READ isValidRole WRITE setIsValidRole NOTIFY isValidRoleChanged) Q_PROPERTY(QVariant artist READ artist NOTIFY artistChanged) Q_PROPERTY(QVariant title READ title NOTIFY titleChanged) Q_PROPERTY(QVariant album READ album NOTIFY albumChanged) Q_PROPERTY(QUrl image READ image NOTIFY imageChanged) Q_PROPERTY(qulonglong albumId READ albumId NOTIFY albumIdChanged) Q_PROPERTY(bool isValid READ isValid NOTIFY isValidChanged) Q_PROPERTY(int remainingTracks READ remainingTracks NOTIFY remainingTracksChanged) public: explicit ManageHeaderBar(QObject *parent = nullptr); QPersistentModelIndex currentTrack() const; QAbstractItemModel* playListModel() const; int artistRole() const; int titleRole() const; int albumRole() const; int imageRole() const; int albumIdRole() const; int isValidRole() const; QVariant artist() const; QVariant title() const; QVariant album() const; QUrl image() const; qulonglong albumId() const; bool isValid() const; int remainingTracks() const; Q_SIGNALS: void currentTrackChanged(); void playListModelChanged(); void artistRoleChanged(); void titleRoleChanged(); void albumRoleChanged(); void imageRoleChanged(); void albumIdRoleChanged(); void isValidRoleChanged(); void artistChanged(); void titleChanged(); void albumChanged(); void imageChanged(); void remainingTracksChanged(); void albumIdChanged(); void isValidChanged(); public Q_SLOTS: void setCurrentTrack(const QPersistentModelIndex ¤tTrack); void setPlayListModel(QAbstractItemModel* aPlayListModel); void setArtistRole(int value); void setTitleRole(int value); void setAlbumRole(int value); void setImageRole(int value); void setAlbumIdRole(int albumIdRole); void setIsValidRole(int isValidRole); void playListLayoutChanged(const QList &parents, QAbstractItemModel::LayoutChangeHint hint); void tracksInserted(const QModelIndex &parent, int first, int last); void tracksDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles); 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 tracksRemoved(const QModelIndex &parent, int first, int last); private: void notifyArtistProperty(); void notifyTitleProperty(); void notifyAlbumProperty(); void notifyImageProperty(); void notifyAlbumIdProperty(); void notifyIsValidProperty(); void notifyRemainingTracksProperty(); QPersistentModelIndex mCurrentTrack; QAbstractItemModel *mPlayListModel = nullptr; int mArtistRole = Qt::DisplayRole; int mTitleRole = Qt::DisplayRole; int mAlbumRole = Qt::DisplayRole; int mImageRole = Qt::DisplayRole; int mAlbumIdRole = Qt::DisplayRole; int mIsValidRole = Qt::DisplayRole; QVariant mOldArtist; QVariant mOldTitle; QVariant mOldAlbum; QVariant mOldImage; qulonglong mOldAlbumId = 0; bool mOldIsValid = false; int mOldRemainingTracks = 0; }; #endif // MANAGEHEADERBAR_H diff --git a/src/managemediaplayercontrol.cpp b/src/managemediaplayercontrol.cpp index f5724bac..e533df6b 100644 --- a/src/managemediaplayercontrol.cpp +++ b/src/managemediaplayercontrol.cpp @@ -1,386 +1,384 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "managemediaplayercontrol.h" #include ManageMediaPlayerControl::ManageMediaPlayerControl(QObject *parent) : QObject(parent) { } bool ManageMediaPlayerControl::playControlEnabled() const { if (!mPlayListModel) { return false; } if (!mCurrentTrack.isValid()) { return false; } return mPlayListModel->rowCount() > 0; } bool ManageMediaPlayerControl::skipBackwardControlEnabled() const { if (!mPlayListModel) { return false; } if (!mCurrentTrack.isValid()) { return false; } return (mRandomOrContinuePlay || (mCurrentTrack.row() > 0)) && mIsInPlayingState; } bool ManageMediaPlayerControl::skipForwardControlEnabled() const { if (!mPlayListModel) { return false; } if (!mCurrentTrack.isValid()) { return false; } return (mRandomOrContinuePlay || (mCurrentTrack.row() < mPlayListModel->rowCount() - 1)) && mIsInPlayingState; } bool ManageMediaPlayerControl::musicPlaying() const { return mPlayerState == ManageMediaPlayerControl::PlayerState::Playing; } void ManageMediaPlayerControl::playerPaused() { //qDebug() << "ManageMediaPlayerControl::playerPaused"; if (!mIsInPlayingState) { auto oldPreviousTrackIsEnabled = skipBackwardControlEnabled(); auto oldNextTrackIsEnabled = skipForwardControlEnabled(); mIsInPlayingState = true; if (!mCurrentTrack.isValid()) { return; } auto newNextTrackIsEnabled = skipForwardControlEnabled(); if (oldNextTrackIsEnabled != newNextTrackIsEnabled) { Q_EMIT skipForwardControlEnabledChanged(); } auto newPreviousTrackIsEnabled = skipBackwardControlEnabled(); if (oldPreviousTrackIsEnabled != newPreviousTrackIsEnabled) { Q_EMIT skipBackwardControlEnabledChanged(); } } mPlayerState = ManageMediaPlayerControl::PlayerState::Paused; Q_EMIT musicPlayingChanged(); } void ManageMediaPlayerControl::playerPlaying() { if (!mIsInPlayingState) { auto oldPreviousTrackIsEnabled = skipBackwardControlEnabled(); auto oldNextTrackIsEnabled = skipForwardControlEnabled(); mIsInPlayingState = true; if (!mCurrentTrack.isValid()) { return; } auto newNextTrackIsEnabled = skipForwardControlEnabled(); if (oldNextTrackIsEnabled != newNextTrackIsEnabled) { Q_EMIT skipForwardControlEnabledChanged(); } auto newPreviousTrackIsEnabled = skipBackwardControlEnabled(); if (oldPreviousTrackIsEnabled != newPreviousTrackIsEnabled) { Q_EMIT skipBackwardControlEnabledChanged(); } } mPlayerState = ManageMediaPlayerControl::PlayerState::Playing; Q_EMIT musicPlayingChanged(); } void ManageMediaPlayerControl::playerStopped() { //qDebug() << "ManageMediaPlayerControl::playerStopped"; if (mIsInPlayingState) { auto oldPreviousTrackIsEnabled = skipBackwardControlEnabled(); auto oldNextTrackIsEnabled = skipForwardControlEnabled(); mIsInPlayingState = false; if (mCurrentTrack.isValid()) { auto newNextTrackIsEnabled = skipForwardControlEnabled(); if (oldNextTrackIsEnabled != newNextTrackIsEnabled) { Q_EMIT skipForwardControlEnabledChanged(); } auto newPreviousTrackIsEnabled = skipBackwardControlEnabled(); if (oldPreviousTrackIsEnabled != newPreviousTrackIsEnabled) { 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) { if (mRandomOrContinuePlay == randomOrContinuePlay) { 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() { } 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(); } 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) { Q_EMIT skipForwardControlEnabledChanged(); } auto newPreviousTrackIsEnabled = skipBackwardControlEnabled(); if (mSkipBackwardControlWasEnabled != newPreviousTrackIsEnabled) { Q_EMIT skipBackwardControlEnabledChanged(); } } void ManageMediaPlayerControl::setPlayListModel(QAbstractItemModel *aPlayListModel) { 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; } QPersistentModelIndex ManageMediaPlayerControl::currentTrack() const { return mCurrentTrack; } QDataStream &operator<<(QDataStream &out, const ManageMediaPlayerControl::PlayerState &state) { out << static_cast(state); return out; } 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 8a2aa927..8b05439a 100644 --- a/src/managemediaplayercontrol.h +++ b/src/managemediaplayercontrol.h @@ -1,162 +1,160 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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 currentTrack READ currentTrack WRITE setCurrentTrack NOTIFY currentTrackChanged) Q_PROPERTY(bool randomOrContinuePlay READ randomOrContinuePlay WRITE setRandomOrContinuePlay NOTIFY randomOrContinuePlayChanged) 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 currentTrack() const; bool randomOrContinuePlay() const; Q_SIGNALS: void playControlEnabledChanged(); void skipBackwardControlEnabledChanged(); void skipForwardControlEnabledChanged(); void musicPlayingChanged(); void playListModelChanged(); void currentTrackChanged(); void randomOrContinuePlayChanged(); public Q_SLOTS: void setPlayListModel(QAbstractItemModel* aPlayListModel); void playerPaused(); void playerPlaying(); void playerStopped(); 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); private: QAbstractItemModel *mPlayListModel = nullptr; QPersistentModelIndex mCurrentTrack; 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/mediaplaylist.cpp b/src/mediaplaylist.cpp index c0a7bce6..b1c562d3 100644 --- a/src/mediaplaylist.cpp +++ b/src/mediaplaylist.cpp @@ -1,1398 +1,1396 @@ /* * Copyright 2015-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "mediaplaylist.h" #include "databaseinterface.h" #include "musicaudiotrack.h" #include "musiclistenersmanager.h" #include #include #include #include #include #include #include class MediaPlayListPrivate { public: QList mData; QList mTrackData; MusicListenersManager* mMusicListenersManager = nullptr; QPersistentModelIndex mCurrentTrack; QVariantMap mPersistentState; QMediaPlaylist mLoadPlaylist; int mCurrentPlayListPosition = 0; bool mRandomPlay = false; bool mRepeatPlay = false; }; MediaPlayList::MediaPlayList(QObject *parent) : QAbstractListModel(parent), d(new MediaPlayListPrivate) { connect(&d->mLoadPlaylist, &QMediaPlaylist::loaded, this, &MediaPlayList::loadPlayListLoaded); connect(&d->mLoadPlaylist, &QMediaPlaylist::loadFailed, this, &MediaPlayList::loadPlayListLoadFailed); seedRandomGenerator(QTime::currentTime().msec()); } MediaPlayList::~MediaPlayList() = default; int MediaPlayList::rowCount(const QModelIndex &parent) const { if (parent.isValid()) { return 0; } return d->mData.size(); } QHash MediaPlayList::roleNames() const { auto roles = QAbstractItemModel::roleNames(); roles[static_cast(ColumnsRoles::IsValidRole)] = "isValid"; roles[static_cast(ColumnsRoles::TitleRole)] = "title"; roles[static_cast(ColumnsRoles::DurationRole)] = "duration"; roles[static_cast(ColumnsRoles::ArtistRole)] = "artist"; roles[static_cast(ColumnsRoles::AlbumArtistRole)] = "albumArtist"; roles[static_cast(ColumnsRoles::AlbumRole)] = "album"; roles[static_cast(ColumnsRoles::TrackNumberRole)] = "trackNumber"; roles[static_cast(ColumnsRoles::DiscNumberRole)] = "discNumber"; roles[static_cast(ColumnsRoles::RatingRole)] = "rating"; roles[static_cast(ColumnsRoles::GenreRole)] = "genre"; roles[static_cast(ColumnsRoles::LyricistRole)] = "lyricist"; roles[static_cast(ColumnsRoles::ComposerRole)] = "composer"; roles[static_cast(ColumnsRoles::CommentRole)] = "comment"; roles[static_cast(ColumnsRoles::YearRole)] = "year"; roles[static_cast(ColumnsRoles::ChannelsRole)] = "channels"; roles[static_cast(ColumnsRoles::BitRateRole)] = "bitRate"; roles[static_cast(ColumnsRoles::SampleRateRole)] = "sampleRate"; roles[static_cast(ColumnsRoles::ImageRole)] = "image"; roles[static_cast(ColumnsRoles::CountRole)] = "count"; roles[static_cast(ColumnsRoles::IsPlayingRole)] = "isPlaying"; roles[static_cast(ColumnsRoles::HasAlbumHeader)] = "hasAlbumHeader"; roles[static_cast(ColumnsRoles::IsSingleDiscAlbumHeader)] = "isSingleDiscAlbum"; roles[static_cast(ColumnsRoles::SecondaryTextRole)] = "secondaryText"; roles[static_cast(ColumnsRoles::ImageUrlRole)] = "imageUrl"; roles[static_cast(ColumnsRoles::ShadowForImageRole)] = "shadowForImage"; roles[static_cast(ColumnsRoles::ResourceRole)] = "trackResource"; roles[static_cast(ColumnsRoles::TrackDataRole)] = "trackData"; roles[static_cast(ColumnsRoles::AlbumIdRole)] = "albumId"; return roles; } QVariant MediaPlayList::data(const QModelIndex &index, int role) const { auto result = QVariant(); if (!index.isValid()) { return result; } if (index.row() < 0 || index.row() >= d->mData.size()) { return result; } if (d->mData[index.row()].mIsValid) { switch(role) { case ColumnsRoles::IsValidRole: result = d->mData[index.row()].mIsValid; break; case ColumnsRoles::TitleRole: if (!d->mTrackData[index.row()].title().isEmpty()) { result = d->mTrackData[index.row()].title(); } else { if (d->mData[index.row()].mTrackUrl.isLocalFile()) { result = d->mData[index.row()].mTrackUrl.fileName(); } else { result = d->mData[index.row()].mTrackUrl.toString(); } } break; case ColumnsRoles::DurationRole: { const QTime &trackDuration = d->mTrackData[index.row()].duration(); if (trackDuration.hour() == 0) { result = trackDuration.toString(QStringLiteral("mm:ss")); } else { result = trackDuration.toString(); } break; } case ColumnsRoles::MilliSecondsDurationRole: result = d->mTrackData[index.row()].duration().msecsSinceStartOfDay(); break; case ColumnsRoles::ArtistRole: result = d->mTrackData[index.row()].artist(); break; case ColumnsRoles::AlbumArtistRole: result = d->mTrackData[index.row()].albumArtist(); break; case ColumnsRoles::AlbumRole: result = d->mTrackData[index.row()].albumName(); break; case ColumnsRoles::TrackNumberRole: result = d->mTrackData[index.row()].trackNumber(); break; case ColumnsRoles::DiscNumberRole: result = d->mTrackData[index.row()].discNumber(); break; case ColumnsRoles::IsSingleDiscAlbumHeader: result = d->mTrackData[index.row()].isSingleDiscAlbum(); break; case ColumnsRoles::ResourceRole: if (d->mTrackData[index.row()].resourceURI().isValid()) { result = d->mTrackData[index.row()].resourceURI(); } else { result = d->mData[index.row()].mTrackUrl; } break; case ColumnsRoles::ImageRole: { auto albumArt = d->mTrackData[index.row()].albumCover(); if (albumArt.isValid()) { result = albumArt; } break; } case ColumnsRoles::HasAlbumHeader: result = rowHasHeader(index.row()); break; case ColumnsRoles::RatingRole: result = d->mTrackData[index.row()].rating(); break; case ColumnsRoles::GenreRole: result = d->mTrackData[index.row()].genre(); break; case ColumnsRoles::LyricistRole: result = d->mTrackData[index.row()].lyricist(); break; case ColumnsRoles::ComposerRole: result = d->mTrackData[index.row()].composer(); break; case ColumnsRoles::CommentRole: result = d->mTrackData[index.row()].comment(); break; case ColumnsRoles::YearRole: result = d->mTrackData[index.row()].year(); break; case ColumnsRoles::ChannelsRole: result = d->mTrackData[index.row()].channels(); break; case ColumnsRoles::BitRateRole: result = d->mTrackData[index.row()].bitRate(); break; case ColumnsRoles::SampleRateRole: result = d->mTrackData[index.row()].sampleRate(); break; case ColumnsRoles::CountRole: break; case ColumnsRoles::IsPlayingRole: result = d->mData[index.row()].mIsPlaying; break; case Qt::DisplayRole: { const auto &track = d->mTrackData[index.row()]; auto displayText = QString(); displayText = QStringLiteral("%1 - %2"); if (track.isSingleDiscAlbum()) { displayText = displayText.arg(track.trackNumber()); } else { auto numbersText = QString(); numbersText = QStringLiteral("%1 - %2"); numbersText = numbersText.arg(track.discNumber()); numbersText = numbersText.arg(track.trackNumber()); displayText = displayText.arg(numbersText); } result = displayText.arg(track.title()); break; } case ColumnsRoles::SecondaryTextRole: break; case ColumnsRoles::ImageUrlRole: { const auto &albumArt = d->mTrackData[index.row()].albumCover(); if (albumArt.isValid()) { result = albumArt; } else { result = QUrl(QStringLiteral("image://icon/media-optical-audio")); } break; } case ColumnsRoles::ShadowForImageRole: result = d->mTrackData[index.row()].albumCover().isValid(); break; case ColumnsRoles::TrackDataRole: result = QVariant::fromValue(d->mTrackData[index.row()]); break; case ColumnsRoles::AlbumIdRole: result = d->mTrackData[index.row()].albumId(); break; } } else { switch(role) { case ColumnsRoles::IsValidRole: result = d->mData[index.row()].mIsValid; break; case ColumnsRoles::TitleRole: if (!d->mData[index.row()].mTitle.isEmpty()) { result = d->mData[index.row()].mTitle; } else if (d->mData[index.row()].mTrackUrl.isValid()) { if (d->mData[index.row()].mTrackUrl.isLocalFile()) { auto localFile = QFileInfo(d->mData[index.row()].mTrackUrl.toLocalFile()); result = localFile.fileName(); } else { result = d->mData[index.row()].mTrackUrl.toString(); } } break; case ColumnsRoles::IsPlayingRole: result = d->mData[index.row()].mIsPlaying; break; case ColumnsRoles::ArtistRole: result = d->mData[index.row()].mArtist; break; case ColumnsRoles::AlbumArtistRole: result = d->mData[index.row()].mArtist; break; case ColumnsRoles::AlbumRole: result = d->mData[index.row()].mAlbum; break; case ColumnsRoles::TrackNumberRole: result = -1; break; case ColumnsRoles::HasAlbumHeader: result = rowHasHeader(index.row()); break; case ColumnsRoles::DurationRole: break; case ColumnsRoles::DiscNumberRole: break; case ColumnsRoles::IsSingleDiscAlbumHeader: result = false; break; case ColumnsRoles::MilliSecondsDurationRole: break; case ColumnsRoles::ResourceRole: break; case ColumnsRoles::RatingRole: break; case ColumnsRoles::CountRole: break; case ColumnsRoles::ImageRole: result = QStringLiteral(""); break; case Qt::DisplayRole: result = d->mTrackData[index.row()].title(); break; case ColumnsRoles::SecondaryTextRole: result = QString(); break; case ColumnsRoles::ImageUrlRole: result = QUrl(QStringLiteral("image://icon/error")); break; case ColumnsRoles::ShadowForImageRole: result = false; break; case ColumnsRoles::TrackDataRole: { MusicAudioTrack emptyTrack; result = QVariant::fromValue(emptyTrack); break; } case ColumnsRoles::AlbumIdRole: result = 0; break; } } return result; } bool MediaPlayList::setData(const QModelIndex &index, const QVariant &value, int role) { bool modelModified = false; if (!index.isValid()) { return modelModified; } if (index.row() < 0 || index.row() >= d->mData.size()) { return modelModified; } if (role < ColumnsRoles::IsValidRole || role > ColumnsRoles::HasAlbumHeader) { return modelModified; } auto convertedRole = static_cast(role); switch(convertedRole) { case ColumnsRoles::IsPlayingRole: { modelModified = true; auto newState = static_cast(value.toInt()); d->mData[index.row()].mIsPlaying = newState; Q_EMIT dataChanged(index, index, {role}); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } break; } default: modelModified = false; } return modelModified; } bool MediaPlayList::removeRows(int row, int count, const QModelIndex &parent) { beginRemoveRows(parent, row, row + count - 1); bool hadAlbumHeader = false; if (rowCount() > row + count) { hadAlbumHeader = rowHasHeader(row + count); } for (int i = row, cpt = 0; cpt < count; ++i, ++cpt) { d->mData.removeAt(i); d->mTrackData.removeAt(i); } endRemoveRows(); if (!d->mCurrentTrack.isValid()) { d->mCurrentTrack = index(d->mCurrentPlayListPosition, 0); if (d->mCurrentTrack.isValid()) { notifyCurrentTrackChanged(); } if (!d->mCurrentTrack.isValid()) { Q_EMIT playListFinished(); resetCurrentTrack(); if (!d->mCurrentTrack.isValid()) { notifyCurrentTrackChanged(); } } } if (!d->mCurrentTrack.isValid() && rowCount(parent) <= row) { resetCurrentTrack(); } Q_EMIT tracksCountChanged(); if (hadAlbumHeader != rowHasHeader(row)) { Q_EMIT dataChanged(index(row, 0), index(row, 0), {ColumnsRoles::HasAlbumHeader}); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } } Q_EMIT persistentStateChanged(); return false; } bool MediaPlayList::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) { if (sourceParent != destinationParent) { return false; } if (!beginMoveRows(sourceParent, sourceRow, sourceRow + count - 1, destinationParent, destinationChild)) { return false; } auto firstMovedTrackHasHeader = rowHasHeader(sourceRow); auto nextTrackHasHeader = rowHasHeader(sourceRow + count); auto futureNextTrackHasHeader = rowHasHeader(destinationChild); if (sourceRow < destinationChild) { nextTrackHasHeader = rowHasHeader(sourceRow + count); } for (auto cptItem = 0; cptItem < count; ++cptItem) { if (sourceRow < destinationChild) { d->mData.move(sourceRow, destinationChild - 1); d->mTrackData.move(sourceRow, destinationChild - 1); } else { d->mData.move(sourceRow, destinationChild); d->mTrackData.move(sourceRow, destinationChild); } } endMoveRows(); if (sourceRow < destinationChild) { if (firstMovedTrackHasHeader != rowHasHeader(destinationChild - count)) { Q_EMIT dataChanged(index(destinationChild - count, 0), index(destinationChild - count, 0), {ColumnsRoles::HasAlbumHeader}); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } } } else { if (firstMovedTrackHasHeader != rowHasHeader(destinationChild)) { Q_EMIT dataChanged(index(destinationChild, 0), index(destinationChild, 0), {ColumnsRoles::HasAlbumHeader}); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } } } if (sourceRow < destinationChild) { if (nextTrackHasHeader != rowHasHeader(sourceRow)) { Q_EMIT dataChanged(index(sourceRow, 0), index(sourceRow, 0), {ColumnsRoles::HasAlbumHeader}); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } } } else { if (nextTrackHasHeader != rowHasHeader(sourceRow + count)) { Q_EMIT dataChanged(index(sourceRow + count, 0), index(sourceRow + count, 0), {ColumnsRoles::HasAlbumHeader}); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } } } if (sourceRow < destinationChild) { if (futureNextTrackHasHeader != rowHasHeader(destinationChild + count - 1)) { Q_EMIT dataChanged(index(destinationChild + count - 1, 0), index(destinationChild + count - 1, 0), {ColumnsRoles::HasAlbumHeader}); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } } } else { if (futureNextTrackHasHeader != rowHasHeader(destinationChild + count)) { Q_EMIT dataChanged(index(destinationChild + count, 0), index(destinationChild + count, 0), {ColumnsRoles::HasAlbumHeader}); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } } } Q_EMIT persistentStateChanged(); return true; } void MediaPlayList::move(int from, int to, int n) { if (from < to) { moveRows({}, from, n, {}, to + 1); } else { moveRows({}, from, n, {}, to); } } void MediaPlayList::enqueue(qulonglong newTrackId) { enqueue(MediaPlayListEntry(newTrackId)); } void MediaPlayList::enqueue(const MusicAudioTrack &newTrack) { enqueue(MediaPlayListEntry(newTrack), newTrack); } void MediaPlayList::enqueue(const MediaPlayListEntry &newEntry, const MusicAudioTrack &audioTrack) { beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size()); d->mData.push_back(newEntry); if (audioTrack.isValid()) { d->mTrackData.push_back(audioTrack); } else { d->mTrackData.push_back({}); } endInsertRows(); restorePlayListPosition(); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } Q_EMIT tracksCountChanged(); Q_EMIT persistentStateChanged(); if (!newEntry.mIsValid) { if (newEntry.mTrackUrl.isValid()) { qDebug() << "MediaPlayList::enqueue" << "newTrackByFileNameInList" << newEntry.mTrackUrl; if (newEntry.mTrackUrl.isLocalFile()) { QFileInfo newTrackFile(newEntry.mTrackUrl.toLocalFile()); if (newTrackFile.exists()) { d->mData.last().mIsValid = true; } Q_EMIT newTrackByFileNameInList(newEntry.mTrackUrl); } } else { Q_EMIT newTrackByNameInList(newEntry.mTitle, newEntry.mArtist, newEntry.mAlbum, newEntry.mTrackNumber, newEntry.mDiscNumber); } } else { Q_EMIT newTrackByIdInList(newEntry.mId); } Q_EMIT trackHasBeenAdded(data(index(d->mData.size() - 1, 0), ColumnsRoles::TitleRole).toString(), data(index(d->mData.size() - 1, 0), ColumnsRoles::ImageRole).toUrl()); if (!newEntry.mIsValid) { Q_EMIT dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), {MediaPlayList::HasAlbumHeader}); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } } } void MediaPlayList::enqueue(const MusicAlbum &album) { for (auto oneTrackIndex = 0; oneTrackIndex < album.tracksCount(); ++oneTrackIndex) { enqueue(album.trackFromIndex(oneTrackIndex)); } } void MediaPlayList::enqueue(const MusicArtist &artist) { enqueue(artist.name()); } void MediaPlayList::enqueue(const QString &artistName) { beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size()); d->mData.push_back(MediaPlayListEntry{artistName}); d->mTrackData.push_back({}); endInsertRows(); restorePlayListPosition(); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } Q_EMIT tracksCountChanged(); Q_EMIT newArtistInList(artistName); Q_EMIT persistentStateChanged(); } void MediaPlayList::enqueue(const QUrl &fileName) { qDebug() << "MediaPlayList::enqueue" << fileName; enqueue(MediaPlayListEntry(fileName)); } void MediaPlayList::enqueue(const QStringList &files) { qDebug() << "MediaPlayList::enqueue" << files; for (const auto &oneFileName : files) { enqueue(QUrl::fromLocalFile(oneFileName)); } } void MediaPlayList::enqueueAndPlay(const QStringList &files) { if (files.size() > 0) { int previousTrackNumber = tracksCount(); enqueue(files); switchTo(previousTrackNumber); Q_EMIT ensurePlay(); } } void MediaPlayList::enqueue(const QList &newTrackIds) { if (newTrackIds.isEmpty()) { return; } beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size() + newTrackIds.size() - 1); for (auto newTrackId : newTrackIds) { d->mData.push_back(MediaPlayListEntry{newTrackId}); d->mTrackData.push_back({}); Q_EMIT newTrackByIdInList(newTrackId); } endInsertRows(); restorePlayListPosition(); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } Q_EMIT tracksCountChanged(); Q_EMIT persistentStateChanged(); Q_EMIT dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), {MediaPlayList::HasAlbumHeader}); } void MediaPlayList::enqueue(const QList &albums, ElisaUtils::PlayListEnqueueMode enqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay) { if (albums.isEmpty()) { return; } auto tracksCount = 0; for (const auto &oneAlbum : albums) { for (auto oneTrackIndex = 0; oneTrackIndex < oneAlbum.tracksCount(); ++oneTrackIndex) { ++tracksCount; } } if (enqueueMode == ElisaUtils::ReplacePlayList) { clearPlayList(); } beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size() + tracksCount - 1); for (const auto &oneAlbum : albums) { for (auto oneTrackIndex = 0; oneTrackIndex < oneAlbum.tracksCount(); ++oneTrackIndex) { const auto &oneTrack = oneAlbum.trackFromIndex(oneTrackIndex); d->mData.push_back(MediaPlayListEntry{oneTrack.databaseId()}); d->mTrackData.push_back(oneTrack); } } endInsertRows(); restorePlayListPosition(); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } Q_EMIT tracksCountChanged(); Q_EMIT persistentStateChanged(); Q_EMIT dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), {MediaPlayList::HasAlbumHeader}); if (triggerPlay == ElisaUtils::TriggerPlay) { Q_EMIT ensurePlay(); } } void MediaPlayList::enqueue(const QList &tracks, ElisaUtils::PlayListEnqueueMode enqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay) { if (tracks.isEmpty()) { return; } if (enqueueMode == ElisaUtils::ReplacePlayList) { clearPlayList(); } beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size() + tracks.size() - 1); for (const auto &oneTrack : tracks) { d->mData.push_back(MediaPlayListEntry{oneTrack.databaseId()}); d->mTrackData.push_back(oneTrack); } endInsertRows(); restorePlayListPosition(); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } Q_EMIT tracksCountChanged(); Q_EMIT persistentStateChanged(); Q_EMIT dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), {MediaPlayList::HasAlbumHeader}); if (triggerPlay == ElisaUtils::TriggerPlay) { Q_EMIT ensurePlay(); } } void MediaPlayList::enqueueArtists(const QList &artistNames, ElisaUtils::PlayListEnqueueMode enqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay) { if (artistNames.isEmpty()) { return; } if (enqueueMode == ElisaUtils::ReplacePlayList) { clearPlayList(); } beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size() + artistNames.size() - 1); for (const auto &artistName : artistNames) { d->mData.push_back(MediaPlayListEntry{artistName}); d->mTrackData.push_back({}); Q_EMIT newArtistInList(artistName); } endInsertRows(); restorePlayListPosition(); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } Q_EMIT tracksCountChanged(); Q_EMIT persistentStateChanged(); if (triggerPlay == ElisaUtils::TriggerPlay) { Q_EMIT ensurePlay(); } } void MediaPlayList::enqueue(const QList &trackUrls, ElisaUtils::PlayListEnqueueMode enqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay) { if (trackUrls.isEmpty()) { return; } if (enqueueMode == ElisaUtils::ReplacePlayList) { clearPlayList(); } beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size() + trackUrls.size() - 1); for (const auto &oneTrackUrl : trackUrls) { d->mData.push_back(MediaPlayListEntry{oneTrackUrl}); d->mTrackData.push_back({}); if (oneTrackUrl.isValid()) { qDebug() << "MediaPlayList::enqueue" << "newTrackByFileNameInList" << oneTrackUrl; if (oneTrackUrl.isLocalFile()) { QFileInfo newTrackFile(oneTrackUrl.toLocalFile()); if (newTrackFile.exists()) { d->mData.last().mIsValid = true; } Q_EMIT newTrackByFileNameInList(oneTrackUrl); } } } endInsertRows(); restorePlayListPosition(); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } Q_EMIT tracksCountChanged(); Q_EMIT persistentStateChanged(); Q_EMIT dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), {MediaPlayList::HasAlbumHeader}); if (triggerPlay == ElisaUtils::TriggerPlay) { Q_EMIT ensurePlay(); } } void MediaPlayList::replaceAndPlay(qulonglong newTrackId) { clearPlayList(); enqueue(MediaPlayListEntry(newTrackId)); Q_EMIT ensurePlay(); } void MediaPlayList::replaceAndPlay(const MusicAudioTrack &newTrack) { clearPlayList(); enqueue(newTrack); Q_EMIT ensurePlay(); } void MediaPlayList::replaceAndPlay(const MusicAlbum &album) { clearPlayList(); enqueue(album); Q_EMIT ensurePlay(); } void MediaPlayList::replaceAndPlay(const MusicArtist &artist) { clearPlayList(); enqueue(artist.name()); Q_EMIT ensurePlay(); } void MediaPlayList::replaceAndPlay(const QString &artistName) { clearPlayList(); enqueue(artistName); Q_EMIT ensurePlay(); } void MediaPlayList::replaceAndPlay(const QUrl &fileName) { clearPlayList(); enqueue(fileName); Q_EMIT ensurePlay(); } void MediaPlayList::clearPlayList() { if (d->mData.isEmpty()) { return; } beginRemoveRows({}, 0, d->mData.count() - 1); d->mData.clear(); d->mTrackData.clear(); endRemoveRows(); d->mCurrentPlayListPosition = 0; d->mCurrentTrack = QPersistentModelIndex{}; notifyCurrentTrackChanged(); Q_EMIT tracksCountChanged(); } void MediaPlayList::loadPlaylist(const QUrl &fileName) { d->mLoadPlaylist.clear(); d->mLoadPlaylist.load(fileName, "m3u"); } bool MediaPlayList::savePlaylist(const QUrl &fileName) { QMediaPlaylist savePlaylist; for (int i = 0; i < d->mData.size(); ++i) { const auto &oneTrack = d->mData.at(i); const auto &oneTrackData = d->mTrackData.at(i); if (oneTrack.mIsValid) { savePlaylist.addMedia(oneTrackData.resourceURI()); } } return savePlaylist.save(fileName, "m3u"); } QVariantMap MediaPlayList::persistentState() const { auto currentState = QVariantMap(); auto result = QList(); for (int trackIndex = 0; trackIndex < d->mData.size(); ++trackIndex) { auto oneData = QList(); const auto &oneEntry = d->mData[trackIndex]; if (oneEntry.mIsValid) { const auto &oneTrack = d->mTrackData[trackIndex]; oneData.push_back(oneTrack.title()); oneData.push_back(oneTrack.artist()); oneData.push_back(oneTrack.albumName()); oneData.push_back(QString::number(oneTrack.trackNumber())); oneData.push_back(QString::number(oneTrack.discNumber())); result.push_back(QVariant(oneData)); } } currentState[QStringLiteral("playList")] = result; currentState[QStringLiteral("currentTrack")] = d->mCurrentPlayListPosition; currentState[QStringLiteral("randomPlay")] = d->mRandomPlay; currentState[QStringLiteral("repeatPlay")] = d->mRepeatPlay; return currentState; } MusicListenersManager *MediaPlayList::musicListenersManager() const { return d->mMusicListenersManager; } int MediaPlayList::tracksCount() const { return rowCount(); } QPersistentModelIndex MediaPlayList::currentTrack() const { return d->mCurrentTrack; } int MediaPlayList::currentTrackRow() const { return d->mCurrentTrack.row(); } bool MediaPlayList::randomPlay() const { return d->mRandomPlay; } bool MediaPlayList::repeatPlay() const { return d->mRepeatPlay; } void MediaPlayList::setPersistentState(const QVariantMap &persistentStateValue) { if (d->mPersistentState == persistentStateValue) { return; } qDebug() << "MediaPlayList::setPersistentState" << persistentStateValue; d->mPersistentState = persistentStateValue; auto persistentState = d->mPersistentState[QStringLiteral("playList")].toList(); for (auto &oneData : persistentState) { auto trackData = oneData.toStringList(); if (trackData.size() != 5) { continue; } auto restoredTitle = trackData[0]; auto restoredArtist = trackData[1]; auto restoredAlbum = trackData[2]; auto restoredTrackNumber = trackData[3].toInt(); auto restoredDiscNumber = trackData[4].toInt(); enqueue({restoredTitle, restoredArtist, restoredAlbum, restoredTrackNumber, restoredDiscNumber}); } restorePlayListPosition(); restoreRandomPlay(); restoreRepeatPlay(); Q_EMIT persistentStateChanged(); } void MediaPlayList::removeSelection(QList selection) { std::sort(selection.begin(), selection.end()); std::reverse(selection.begin(), selection.end()); for (auto oneItem : selection) { removeRow(oneItem); } } void MediaPlayList::albumAdded(const QList &tracks) { for (int playListIndex = 0; playListIndex < d->mData.size(); ++playListIndex) { auto &oneEntry = d->mData[playListIndex]; if (!oneEntry.mIsArtist || oneEntry.mIsValid) { continue; } if (oneEntry.mArtist != tracks.first().artist()) { continue; } d->mTrackData[playListIndex] = tracks.first(); oneEntry.mId = tracks.first().databaseId(); oneEntry.mIsValid = true; oneEntry.mIsArtist = false; Q_EMIT dataChanged(index(playListIndex, 0), index(playListIndex, 0), {}); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } if (tracks.size() > 1) { beginInsertRows(QModelIndex(), playListIndex + 1, playListIndex - 1 + tracks.size()); for (int trackIndex = 1; trackIndex < tracks.size(); ++trackIndex) { d->mData.push_back(MediaPlayListEntry{tracks[trackIndex].databaseId()}); d->mTrackData.push_back(tracks[trackIndex]); } endInsertRows(); restorePlayListPosition(); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } Q_EMIT tracksCountChanged(); } Q_EMIT persistentStateChanged(); } } void MediaPlayList::trackChanged(const MusicAudioTrack &track) { for (int i = 0; i < d->mData.size(); ++i) { auto &oneEntry = d->mData[i]; if (!oneEntry.mIsArtist && oneEntry.mIsValid) { if (oneEntry.mTrackUrl.isValid() && track.resourceURI() != oneEntry.mTrackUrl) { continue; } if (!oneEntry.mTrackUrl.isValid() && (oneEntry.mId == 0 || track.databaseId() != oneEntry.mId)) { continue; } if (d->mTrackData[i] != track) { d->mTrackData[i] = track; Q_EMIT dataChanged(index(i, 0), index(i, 0), {}); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } } continue; } else if (!oneEntry.mIsArtist && !oneEntry.mIsValid && !oneEntry.mTrackUrl.isValid()) { if (track.title() != oneEntry.mTitle) { continue; } if (track.albumName() != oneEntry.mAlbum) { continue; } if (track.trackNumber() != oneEntry.mTrackNumber) { continue; } if (track.discNumber() != oneEntry.mDiscNumber) { continue; } d->mTrackData[i] = track; oneEntry.mId = track.databaseId(); oneEntry.mIsValid = true; Q_EMIT dataChanged(index(i, 0), index(i, 0), {}); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } break; } else if (!oneEntry.mIsArtist && !oneEntry.mIsValid && oneEntry.mTrackUrl.isValid()) { qDebug() << "MediaPlayList::trackChanged" << oneEntry << track; qDebug() << "MediaPlayList::trackChanged" << track.resourceURI() << oneEntry.mTrackUrl; if (track.resourceURI() != oneEntry.mTrackUrl) { continue; } d->mTrackData[i] = track; oneEntry.mId = track.databaseId(); oneEntry.mIsValid = true; Q_EMIT dataChanged(index(i, 0), index(i, 0), {}); restorePlayListPosition(); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } break; } } } void MediaPlayList::trackRemoved(qulonglong trackId) { for (int i = 0; i < d->mData.size(); ++i) { auto &oneEntry = d->mData[i]; if (oneEntry.mIsValid) { if (oneEntry.mId == trackId) { oneEntry.mIsValid = false; oneEntry.mTitle = d->mTrackData[i].title(); oneEntry.mArtist = d->mTrackData[i].artist(); oneEntry.mAlbum = d->mTrackData[i].albumName(); oneEntry.mTrackNumber = d->mTrackData[i].trackNumber(); oneEntry.mDiscNumber = d->mTrackData[i].discNumber(); Q_EMIT dataChanged(index(i, 0), index(i, 0), {}); if (!d->mCurrentTrack.isValid()) { resetCurrentTrack(); } } } } } void MediaPlayList::setMusicListenersManager(MusicListenersManager *musicListenersManager) { if (d->mMusicListenersManager == musicListenersManager) { return; } d->mMusicListenersManager = musicListenersManager; if (d->mMusicListenersManager) { d->mMusicListenersManager->subscribeForTracks(this); } Q_EMIT musicListenersManagerChanged(); } void MediaPlayList::setRandomPlay(bool value) { d->mRandomPlay = value; Q_EMIT randomPlayChanged(); } void MediaPlayList::setRepeatPlay(bool value) { d->mRepeatPlay = value; Q_EMIT repeatPlayChanged(); } void MediaPlayList::skipNextTrack() { if (!d->mCurrentTrack.isValid()) { return; } if (!d->mRandomPlay && (d->mCurrentTrack.row() >= (rowCount() - 1))) { if (!d->mRepeatPlay) { Q_EMIT playListFinished(); } if (rowCount() == 1) { d->mCurrentTrack = QPersistentModelIndex{}; notifyCurrentTrackChanged(); } resetCurrentTrack(); return; } if (d->mRandomPlay) { int randomValue = qrand(); randomValue = randomValue % (rowCount()); d->mCurrentTrack = index(randomValue, 0); } else { d->mCurrentTrack = index(d->mCurrentTrack.row() + 1, 0); } notifyCurrentTrackChanged(); } void MediaPlayList::skipPreviousTrack() { if (!d->mCurrentTrack.isValid()) { return; } if (!d->mRandomPlay && !d->mRepeatPlay && d->mCurrentTrack.row() <= 0) { return; } if (d->mRandomPlay) { int randomValue = qrand(); randomValue = randomValue % (rowCount()); d->mCurrentTrack = index(randomValue, 0); } else { if (d->mRepeatPlay) { if (d->mCurrentTrack.row() == 0) { d->mCurrentTrack = index(rowCount() - 1, 0); } else { d->mCurrentTrack = index(d->mCurrentTrack.row() - 1, 0); } } else { d->mCurrentTrack = index(d->mCurrentTrack.row() - 1, d->mCurrentTrack.column(), d->mCurrentTrack.parent()); } } notifyCurrentTrackChanged(); } void MediaPlayList::seedRandomGenerator(uint seed) { qsrand(seed); } void MediaPlayList::switchTo(int row) { if (!d->mCurrentTrack.isValid()) { return; } d->mCurrentTrack = index(row, 0); notifyCurrentTrackChanged(); } void MediaPlayList::trackInError(QUrl sourceInError, QMediaPlayer::Error playerError) { Q_UNUSED(playerError) for (int i = 0; i < d->mData.size(); ++i) { auto &oneTrack = d->mData[i]; if (oneTrack.mIsValid) { const auto &oneTrackData = d->mTrackData.at(i); if (oneTrackData.resourceURI() == sourceInError) { oneTrack.mIsValid = false; Q_EMIT dataChanged(index(i, 0), index(i, 0), {ColumnsRoles::IsValidRole}); } } } } bool MediaPlayList::rowHasHeader(int row) const { if (row >= rowCount()) { return false; } if (row < 0) { return false; } if (row - 1 < 0) { return true; } auto currentAlbumTitle = QString(); auto currentAlbumArtist = QString(); if (d->mData[row].mIsValid) { currentAlbumTitle = d->mTrackData[row].albumName(); currentAlbumArtist = d->mTrackData[row].albumArtist(); } else { currentAlbumTitle = d->mData[row].mAlbum; currentAlbumArtist = d->mData[row].mArtist; } auto previousAlbumTitle = QString(); auto previousAlbumArtist = QString(); if (d->mData[row - 1].mIsValid) { previousAlbumTitle = d->mTrackData[row - 1].albumName(); previousAlbumArtist = d->mTrackData[row - 1].albumArtist(); } else { previousAlbumTitle = d->mData[row - 1].mAlbum; previousAlbumArtist = d->mData[row - 1].mArtist; } if (currentAlbumTitle == previousAlbumTitle && currentAlbumArtist == previousAlbumArtist) { return false; } return true; } void MediaPlayList::loadPlayListLoaded() { clearPlayList(); for (int i = 0; i < d->mLoadPlaylist.mediaCount(); ++i) { enqueue(d->mLoadPlaylist.media(i).canonicalUrl()); } restorePlayListPosition(); restoreRandomPlay(); restoreRepeatPlay(); Q_EMIT persistentStateChanged(); d->mLoadPlaylist.clear(); Q_EMIT playListLoaded(); } void MediaPlayList::loadPlayListLoadFailed() { d->mLoadPlaylist.clear(); Q_EMIT playListLoadFailed(); } void MediaPlayList::resetCurrentTrack() { for(int row = 0; row < rowCount(); ++row) { auto candidateTrack = index(row, 0); if (candidateTrack.isValid() && candidateTrack.data(ColumnsRoles::IsValidRole).toBool()) { d->mCurrentTrack = candidateTrack; notifyCurrentTrackChanged(); break; } } } void MediaPlayList::notifyCurrentTrackChanged() { Q_EMIT currentTrackChanged(d->mCurrentTrack); Q_EMIT currentTrackRowChanged(); bool currentTrackIsValid = d->mCurrentTrack.isValid(); if (currentTrackIsValid) { d->mCurrentPlayListPosition = d->mCurrentTrack.row(); } } void MediaPlayList::restorePlayListPosition() { auto playerCurrentTrack = d->mPersistentState.find(QStringLiteral("currentTrack")); if (playerCurrentTrack != d->mPersistentState.end()) { auto newIndex = index(playerCurrentTrack->toInt(), 0); if (newIndex.isValid() && (newIndex != d->mCurrentTrack)) { d->mCurrentTrack = newIndex; notifyCurrentTrackChanged(); if (d->mCurrentTrack.isValid()) { d->mPersistentState.erase(playerCurrentTrack); } } } } void MediaPlayList::restoreRandomPlay() { auto randomPlayStoredValue = d->mPersistentState.find(QStringLiteral("randomPlay")); if (randomPlayStoredValue != d->mPersistentState.end()) { setRandomPlay(randomPlayStoredValue->toBool()); d->mPersistentState.erase(randomPlayStoredValue); } } void MediaPlayList::restoreRepeatPlay() { auto repeatPlayStoredValue = d->mPersistentState.find(QStringLiteral("repeatPlay")); if (repeatPlayStoredValue != d->mPersistentState.end()) { setRepeatPlay(repeatPlayStoredValue->toBool()); d->mPersistentState.erase(repeatPlayStoredValue); } } QDebug operator<<(QDebug stream, const MediaPlayListEntry &data) { stream << data.mTitle << data.mAlbum << data.mArtist << data.mTrackUrl << data.mTrackNumber << data.mDiscNumber << data.mId << data.mIsValid; return stream; } #include "moc_mediaplaylist.cpp" diff --git a/src/mediaplaylist.h b/src/mediaplaylist.h index 031edb35..34a71d0e 100644 --- a/src/mediaplaylist.h +++ b/src/mediaplaylist.h @@ -1,345 +1,343 @@ /* * Copyright 2015-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef MEDIAPLAYLIST_H #define MEDIAPLAYLIST_H #include "elisaLib_export.h" #include "musicaudiotrack.h" #include "musicalbum.h" #include "musicartist.h" #include "elisautils.h" #include #include #include #include class MediaPlayListPrivate; class DatabaseInterface; class MusicListenersManager; class MediaPlayListEntry; class QDebug; class ELISALIB_EXPORT MediaPlayList : public QAbstractListModel { Q_OBJECT Q_PROPERTY(QVariantMap persistentState READ persistentState WRITE setPersistentState NOTIFY persistentStateChanged) Q_PROPERTY(MusicListenersManager* musicListenersManager READ musicListenersManager WRITE setMusicListenersManager NOTIFY musicListenersManagerChanged) Q_PROPERTY(int tracksCount READ tracksCount NOTIFY tracksCountChanged) Q_PROPERTY(QPersistentModelIndex currentTrack READ currentTrack NOTIFY currentTrackChanged) Q_PROPERTY(int currentTrackRow READ currentTrackRow NOTIFY currentTrackRowChanged) Q_PROPERTY(bool randomPlay READ randomPlay WRITE setRandomPlay NOTIFY randomPlayChanged) Q_PROPERTY(bool repeatPlay READ repeatPlay WRITE setRepeatPlay NOTIFY repeatPlayChanged) public: enum ColumnsRoles { IsValidRole = Qt::UserRole + 1, TitleRole, DurationRole, MilliSecondsDurationRole, TrackDataRole, ArtistRole, AlbumArtistRole, AlbumRole, TrackNumberRole, DiscNumberRole, RatingRole, GenreRole, LyricistRole, ComposerRole, CommentRole, YearRole, ChannelsRole, BitRateRole, SampleRateRole, ImageRole, AlbumIdRole, ResourceRole, CountRole, IsPlayingRole, HasAlbumHeader, IsSingleDiscAlbumHeader, SecondaryTextRole, ImageUrlRole, ShadowForImageRole, }; Q_ENUM(ColumnsRoles) enum PlayState { NotPlaying, IsPlaying, IsPaused, }; Q_ENUM(PlayState) explicit MediaPlayList(QObject *parent = nullptr); ~MediaPlayList() override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; QHash roleNames() const override; Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; Q_INVOKABLE bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override; Q_INVOKABLE void move(int from, int to, int n); Q_INVOKABLE void clearPlayList(); Q_INVOKABLE bool savePlaylist(const QUrl &fileName); QVariantMap persistentState() const; MusicListenersManager* musicListenersManager() const; int tracksCount() const; QPersistentModelIndex currentTrack() const; int currentTrackRow() const; bool randomPlay() const; bool repeatPlay() const; Q_SIGNALS: void newTrackByNameInList(const QString &title, const QString &artist, const QString &album, int trackNumber, int discNumber); void newTrackByFileNameInList(const QUrl &fileName); void newTrackByIdInList(qulonglong newTrackId); void newArtistInList(const QString &artist); void trackHasBeenAdded(const QString &title, const QUrl &image); void persistentStateChanged(); void musicListenersManagerChanged(); void tracksCountChanged(); void currentTrackChanged(QPersistentModelIndex currentTrack); void currentTrackRowChanged(); void randomPlayChanged(); void repeatPlayChanged(); void playListFinished(); void playListLoaded(); void playListLoadFailed(); void ensurePlay(); public Q_SLOTS: void setPersistentState(const QVariantMap &persistentState); void removeSelection(QList selection); void albumAdded(const QList &tracks); void trackChanged(const MusicAudioTrack &track); void trackRemoved(qulonglong trackId); void setMusicListenersManager(MusicListenersManager* musicListenersManager); void setRandomPlay(bool value); void setRepeatPlay(bool value); void skipNextTrack(); void skipPreviousTrack(); void seedRandomGenerator(uint seed); void switchTo(int row); void loadPlaylist(const QUrl &fileName); void enqueue(qulonglong newTrackId); void enqueue(const MusicAudioTrack &newTrack); void enqueue(const MediaPlayListEntry &newEntry, const MusicAudioTrack &audioTrack = {}); void enqueue(const MusicAlbum &album); void enqueue(const MusicArtist &artist); void enqueue(const QString &artistName); void enqueue(const QUrl &fileName); void enqueue(const QStringList &files); void enqueue(const QList &newTrackId); void enqueue(const QList &albums, ElisaUtils::PlayListEnqueueMode enqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay); void enqueue(const QList &tracks, ElisaUtils::PlayListEnqueueMode enqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay); void enqueueArtists(const QList &artistName, ElisaUtils::PlayListEnqueueMode enqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay); void enqueue(const QList &tracks, ElisaUtils::PlayListEnqueueMode enqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay); void enqueueAndPlay(const QStringList &files); void replaceAndPlay(qulonglong newTrackId); void replaceAndPlay(const MusicAudioTrack &newTrack); void replaceAndPlay(const MusicAlbum &album); void replaceAndPlay(const MusicArtist &artist); void replaceAndPlay(const QString &artistName); void replaceAndPlay(const QUrl &fileName); void trackInError(QUrl sourceInError, QMediaPlayer::Error playerError); private Q_SLOTS: void loadPlayListLoaded(); void loadPlayListLoadFailed(); private: bool rowHasHeader(int row) const; void resetCurrentTrack(); void notifyCurrentTrackChanged(); void restorePlayListPosition(); void restoreRandomPlay(); void restoreRepeatPlay(); std::unique_ptr d; }; class MediaPlayListEntry { public: MediaPlayListEntry() { } explicit MediaPlayListEntry(qulonglong id) : mId(id), mIsValid(true) { } MediaPlayListEntry(QString title, QString artist, QString album, int trackNumber, int discNumber) : mTitle(std::move(title)), mAlbum(std::move(album)), mArtist(std::move(artist)), mTrackNumber(trackNumber), mDiscNumber(discNumber) { } explicit MediaPlayListEntry(const MusicAudioTrack &track) : mTitle(track.title()), mAlbum(track.albumName()), mTrackNumber(track.trackNumber()), mDiscNumber(track.discNumber()), mId(track.databaseId()), mIsValid(true) { } explicit MediaPlayListEntry(QString artist) : mArtist(std::move(artist)), mIsArtist(true) { } explicit MediaPlayListEntry(QUrl fileName) : mTrackUrl(std::move(fileName)) { } QString mTitle; QString mAlbum; QString mArtist; QUrl mTrackUrl; int mTrackNumber = -1; int mDiscNumber = -1; qulonglong mId = 0; bool mIsValid = false; bool mIsArtist = false; MediaPlayList::PlayState mIsPlaying = MediaPlayList::NotPlaying; }; QDebug operator<<(QDebug stream, const MediaPlayListEntry &data); #endif // MEDIAPLAYLIST_H diff --git a/src/modeldatacache.cpp b/src/modeldatacache.cpp index f926f9cc..98c6e814 100644 --- a/src/modeldatacache.cpp +++ b/src/modeldatacache.cpp @@ -1,373 +1,371 @@ /* * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "modeldatacache.h" #include "databaseinterface.h" #include #include #include #include #include #include class ModelDataCachePrivate { public: QList> mPartialData; QHash> mFullData; QHash mRows; DatabaseInterface *mDatabase = nullptr; QAtomicInt mDataCount; QAtomicInt mDataChangedLowerBound; QAtomicInt mDataChangedUpperBound; DataUtils::DataType mDataType = DataUtils::DataType::UnknownType; QAtomicInt mHasFullData = false; bool mIsConnected = false; }; ModelDataCache::ModelDataCache(QObject *parent) : QObject(parent), d(std::make_unique()) { d->mFullData.reserve(CACHE_SIZE); } ModelDataCache::ModelDataCache::~ModelDataCache() = default; DataUtils::DataType ModelDataCache::dataType() const { return d->mDataType; } int ModelDataCache::dataCount() const { int result = d->mDataCount; return result; } QVariant ModelDataCache::data(int row, ElisaUtils::ColumnsRoles role) const { auto result = QVariant{}; bool databaseIdIsOk = false; auto databaseId = d->mPartialData[row][DatabaseInterface::DatabaseId].toULongLong(&databaseIdIsOk); if (!databaseIdIsOk || databaseId == 0) { return result; } d->mRows[databaseId] = row; switch (role) { case ElisaUtils::TitleRole: result = d->mPartialData[row][DatabaseInterface::DisplayRole]; break; case ElisaUtils::SecondaryTextRole: result = d->mPartialData[row][DatabaseInterface::SecondaryRole]; break; case ElisaUtils::DatabaseIdRole: result = d->mPartialData[row][DatabaseInterface::DatabaseId]; break; case ElisaUtils::IsPartialDataRole: result = !d->mHasFullData; break; default: if (d->mHasFullData) { result = d->mFullData[databaseId][role]; } else { const auto currentRow = d->mRows[databaseId]; if (d->mDataChangedLowerBound > currentRow) { d->mDataChangedLowerBound = currentRow; } if (d->mDataChangedUpperBound < currentRow) { d->mDataChangedUpperBound = currentRow; } } break; }; return result; } DatabaseInterface *ModelDataCache::database() const { return d->mDatabase; } void ModelDataCache::neededData() { qDebug() << "ModelDataCache::neededData"; if (d->mHasFullData) { return; } switch (d->mDataType) { case DataUtils::DataType::AllAlbums: { auto allData = d->mDatabase->allAlbums(); for (const auto &data : allData) { auto &fullData = d->mFullData[data.databaseId()]; const auto &albumArt = data.albumArtURI(); if (albumArt.isValid()) { fullData[ElisaUtils::ImageUrlRole] = albumArt; fullData[ElisaUtils::ShadowForImageRole] = true; } else { fullData[ElisaUtils::ImageUrlRole] = QUrl(QStringLiteral("image://icon/media-optical-audio")); fullData[ElisaUtils::ShadowForImageRole] = false; } fullData[ElisaUtils::ContainerDataRole] = QVariant::fromValue(data); fullData[ElisaUtils::ArtistRole] = data.artist(); fullData[ElisaUtils::AllArtistsRole] = data.allArtists(); fullData[ElisaUtils::HighestTrackRating] = data.highestTrackRating(); } d->mHasFullData = true; Q_EMIT dataChanged(d->mDataChangedLowerBound, d->mDataChangedUpperBound); break; } case DataUtils::DataType::AllArtists: { auto allData = d->mDatabase->allArtists(); for (const auto &data : allData) { auto &fullData = d->mFullData[data.databaseId()]; fullData[ElisaUtils::ContainerDataRole] = QVariant::fromValue(data); fullData[ElisaUtils::ImageUrlRole] = QUrl(QStringLiteral("image://icon/view-media-artist")); fullData[ElisaUtils::ShadowForImageRole] = false; fullData[ElisaUtils::GenreRole] = data.genres(); } d->mHasFullData = true; Q_EMIT dataChanged(d->mDataChangedLowerBound, d->mDataChangedUpperBound); break; } case DataUtils::DataType::AllComposers: { auto allData = d->mDatabase->allComposers(); for (const auto &data : allData) { auto &fullData = d->mFullData[data.databaseId()]; fullData[ElisaUtils::ContainerDataRole] = QVariant::fromValue(data); fullData[ElisaUtils::ImageUrlRole] = QUrl(QStringLiteral("image://icon/view-media-artist")); fullData[ElisaUtils::ShadowForImageRole] = false; } d->mHasFullData = true; Q_EMIT dataChanged(d->mDataChangedLowerBound, d->mDataChangedUpperBound); break; } case DataUtils::DataType::AllLyricists: { auto allData = d->mDatabase->allLyricists(); for (const auto &data : allData) { auto &fullData = d->mFullData[data.databaseId()]; fullData[ElisaUtils::ContainerDataRole] = QVariant::fromValue(data); fullData[ElisaUtils::ImageUrlRole] = QUrl(QStringLiteral("image://icon/view-media-artist")); fullData[ElisaUtils::ShadowForImageRole] = false; } d->mHasFullData = true; Q_EMIT dataChanged(d->mDataChangedLowerBound, d->mDataChangedUpperBound); break; } case DataUtils::DataType::AllGenres: { auto allData = d->mDatabase->allGenres(); for (const auto &data : allData) { auto &fullData = d->mFullData[data.databaseId()]; fullData[ElisaUtils::ContainerDataRole] = QVariant::fromValue(data); fullData[ElisaUtils::ImageUrlRole] = QUrl(QStringLiteral("image://icon/view-media-genre")); fullData[ElisaUtils::ShadowForImageRole] = false; } d->mHasFullData = true; Q_EMIT dataChanged(d->mDataChangedLowerBound, d->mDataChangedUpperBound); break; } case DataUtils::DataType::AllTracks: { auto allData = d->mDatabase->allTracks(); for (const auto &data : allData) { auto &fullData = d->mFullData[data.databaseId()]; const auto &albumArt = data.albumCover(); if (albumArt.isValid()) { fullData[ElisaUtils::ImageUrlRole] = albumArt; fullData[ElisaUtils::ShadowForImageRole] = true; } else { fullData[ElisaUtils::ImageUrlRole] = QUrl(QStringLiteral("image://icon/media-optical-audio")); fullData[ElisaUtils::ShadowForImageRole] = false; } fullData[ElisaUtils::ContainerDataRole] = QVariant::fromValue(data); fullData[ElisaUtils::ArtistRole] = data.artist(); fullData[ElisaUtils::RatingRole] = data.rating(); } d->mHasFullData = true; Q_EMIT dataChanged(d->mDataChangedLowerBound, d->mDataChangedUpperBound); break; } case DataUtils::DataType::UnknownType: break; } } void ModelDataCache::setDataType(DataUtils::DataType dataType) { if (d->mDataType == dataType) { return; } d->mDataType = dataType; Q_EMIT dataTypeChanged(d->mDataType); if (!d->mDatabase) { return; } connectDatabase(); fetchPartialData(); } void ModelDataCache::setDatabase(DatabaseInterface *database) { if (d->mDatabase == database) { return; } d->mDatabase = database; Q_EMIT databaseChanged(d->mDatabase); if (d->mDataType == DataUtils::DataType::UnknownType) { return; } connectDatabase(); fetchPartialData(); } void ModelDataCache::databaseContentChanged() { fetchPartialData(); } void ModelDataCache::fetchPartialData() { if (!d->mDatabase) { return; } d->mPartialData = d->mDatabase->allData(d->mDataType); d->mDataCount = d->mPartialData.count(); d->mDataChangedLowerBound = d->mDataCount; d->mDataChangedUpperBound = 0; d->mHasFullData = false; QMetaObject::invokeMethod(const_cast(this), "neededData", Qt::QueuedConnection); Q_EMIT dataChanged(-1, -1); } void ModelDataCache::connectDatabase() { if (d->mDataType == DataUtils::DataType::UnknownType) { return; } if (!d->mDatabase) { return; } if (d->mIsConnected) { disconnect(d->mDatabase, nullptr, this, nullptr); d->mIsConnected = false; } switch(d->mDataType) { case DataUtils::DataType::AllAlbums: connect(d->mDatabase, &DatabaseInterface::albumsAdded, this, &ModelDataCache::databaseContentChanged, Qt::QueuedConnection); break; case DataUtils::DataType::AllArtists: connect(d->mDatabase, &DatabaseInterface::artistsAdded, this, &ModelDataCache::databaseContentChanged, Qt::QueuedConnection); break; case DataUtils::DataType::AllTracks: connect(d->mDatabase, &DatabaseInterface::tracksAdded, this, &ModelDataCache::databaseContentChanged, Qt::QueuedConnection); break; case DataUtils::DataType::AllGenres: connect(d->mDatabase, &DatabaseInterface::genresAdded, this, &ModelDataCache::databaseContentChanged, Qt::QueuedConnection); break; case DataUtils::DataType::AllComposers: connect(d->mDatabase, &DatabaseInterface::composersAdded, this, &ModelDataCache::databaseContentChanged, Qt::QueuedConnection); break; case DataUtils::DataType::AllLyricists: connect(d->mDatabase, &DatabaseInterface::lyricistsAdded, this, &ModelDataCache::databaseContentChanged, Qt::QueuedConnection); break; case DataUtils::DataType::UnknownType: break; } d->mIsConnected = true; } #include "moc_modeldatacache.cpp" diff --git a/src/modeldatacache.h b/src/modeldatacache.h index 227f7ae0..8e3030d4 100644 --- a/src/modeldatacache.h +++ b/src/modeldatacache.h @@ -1,98 +1,96 @@ /* * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef MODELDATACACHE_H #define MODELDATACACHE_H #include "elisaLib_export.h" #include "datatype.h" #include "elisautils.h" #include #include class ModelDataCachePrivate; class DatabaseInterface; class MusicAlbum; class ELISALIB_EXPORT ModelDataCache : public QObject { Q_OBJECT Q_PROPERTY(DataUtils::DataType dataType READ dataType WRITE setDataType NOTIFY dataTypeChanged) Q_PROPERTY(DatabaseInterface* database READ database WRITE setDatabase NOTIFY databaseChanged) public: static const int CACHE_SIZE = 3000; enum CallMode { CannotBlock, CanBlock, }; explicit ModelDataCache(QObject *parent = nullptr); ~ModelDataCache(); DataUtils::DataType dataType() const; int dataCount() const; QVariant data(int row, ElisaUtils::ColumnsRoles role) const; DatabaseInterface* database() const; Q_SIGNALS: void dataTypeChanged(DataUtils::DataType dataType); void receiveData(int row); void databaseChanged(DatabaseInterface* database); void dataChanged(int lowerBound, int upperBound); public Q_SLOTS: void neededData(); void setDataType(DataUtils::DataType dataType); void setDatabase(DatabaseInterface* database); private Q_SLOTS: void databaseContentChanged(); private: void fetchPartialData(); void connectDatabase(); std::unique_ptr d; }; #endif // MODELDATACACHE_H diff --git a/src/models/abstractmediaproxymodel.cpp b/src/models/abstractmediaproxymodel.cpp index 46b4a2ab..0b44342f 100644 --- a/src/models/abstractmediaproxymodel.cpp +++ b/src/models/abstractmediaproxymodel.cpp @@ -1,101 +1,99 @@ /* * Copyright 2016-2017 Matthieu Gallien * Copyright 2017 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "abstractmediaproxymodel.h" #include AbstractMediaProxyModel::AbstractMediaProxyModel(QObject *parent) : QSortFilterProxyModel(parent) { setFilterCaseSensitivity(Qt::CaseInsensitive); mThreadPool.setMaxThreadCount(1); } AbstractMediaProxyModel::~AbstractMediaProxyModel() = default; QString AbstractMediaProxyModel::filterText() const { return mFilterText; } int AbstractMediaProxyModel::filterRating() const { return mFilterRating; } void AbstractMediaProxyModel::setFilterText(const QString &filterText) { QWriteLocker writeLocker(&mDataLock); if (mFilterText == filterText) return; mFilterText = filterText; mFilterExpression.setPattern(mFilterText); mFilterExpression.setPatternOptions(QRegularExpression::CaseInsensitiveOption); mFilterExpression.optimize(); invalidate(); Q_EMIT filterTextChanged(mFilterText); } void AbstractMediaProxyModel::setFilterRating(int filterRating) { QWriteLocker writeLocker(&mDataLock); if (mFilterRating == filterRating) { return; } mFilterRating = filterRating; invalidate(); Q_EMIT filterRatingChanged(filterRating); } bool AbstractMediaProxyModel::sortedAscending() const { return sortOrder() ? false : true; } void AbstractMediaProxyModel::sortModel(Qt::SortOrder order) { this->sort(0,order); Q_EMIT sortedAscendingChanged(); } void AbstractMediaProxyModel::setGenreFilterText(const QString &filterText) { if (mGenreFilterText == filterText) { return; } mGenreFilterText = filterText; invalidateFilter(); Q_EMIT genreFilterTextChanged(mGenreFilterText); } #include "moc_abstractmediaproxymodel.cpp" diff --git a/src/models/abstractmediaproxymodel.h b/src/models/abstractmediaproxymodel.h index dfa16a9e..012b7424 100644 --- a/src/models/abstractmediaproxymodel.h +++ b/src/models/abstractmediaproxymodel.h @@ -1,112 +1,110 @@ /* * Copyright 2016-2017 Matthieu Gallien * Copyright 2017 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef ABSTRACTMEDIAPROXYMODEL_H #define ABSTRACTMEDIAPROXYMODEL_H #include "elisaLib_export.h" #include #include #include #include class ELISALIB_EXPORT AbstractMediaProxyModel : public QSortFilterProxyModel { Q_OBJECT Q_PROPERTY(QString filterText READ filterText WRITE setFilterText NOTIFY filterTextChanged) Q_PROPERTY(int filterRating READ filterRating WRITE setFilterRating NOTIFY filterRatingChanged) Q_PROPERTY(bool sortedAscending READ sortedAscending NOTIFY sortedAscendingChanged) Q_PROPERTY(QString genreFilterText READ genreFilterText WRITE setGenreFilterText NOTIFY genreFilterTextChanged) public: explicit AbstractMediaProxyModel(QObject *parent = nullptr); ~AbstractMediaProxyModel() override; QString filterText() const; int filterRating() const; bool sortedAscending() const; QString genreFilterText() const { return mGenreFilterText; } public Q_SLOTS: void setFilterText(const QString &filterText); void setFilterRating(int filterRating); void sortModel(Qt::SortOrder order); void setGenreFilterText(const QString &filterText); Q_SIGNALS: void filterTextChanged(const QString &filterText); void filterRatingChanged(int filterRating); void sortedAscendingChanged(); void genreFilterTextChanged(QString genreFilterText); protected: bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override = 0; QString mFilterText; int mFilterRating = 0; QRegularExpression mFilterExpression; QReadWriteLock mDataLock; QThreadPool mThreadPool; private: QString mGenreFilterText; }; #endif // ABSTRACTMEDIAPROXYMODEL_H diff --git a/src/models/albummodel.cpp b/src/models/albummodel.cpp index abac78e5..fa1cfb75 100644 --- a/src/models/albummodel.cpp +++ b/src/models/albummodel.cpp @@ -1,454 +1,452 @@ /* * Copyright 2015-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "albummodel.h" #include "databaseinterface.h" #include #include #include #include class AlbumModelPrivate { public: AlbumModelPrivate() { } MusicAlbum mCurrentAlbum; }; AlbumModel::AlbumModel(QObject *parent) : QAbstractItemModel(parent), d(std::make_unique()) { } AlbumModel::~AlbumModel() = default; int AlbumModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) { return 0; } return d->mCurrentAlbum.tracksCount(); } QHash AlbumModel::roleNames() const { auto roles = QAbstractItemModel::roleNames(); roles[static_cast(ColumnsRoles::TitleRole)] = "title"; roles[static_cast(ColumnsRoles::DurationRole)] = "duration"; roles[static_cast(ColumnsRoles::ArtistRole)] = "artist"; roles[static_cast(ColumnsRoles::AlbumRole)] = "album"; roles[static_cast(ColumnsRoles::AlbumArtistRole)] = "albumArtist"; roles[static_cast(ColumnsRoles::TrackNumberRole)] = "trackNumber"; roles[static_cast(ColumnsRoles::DiscNumberRole)] = "discNumber"; roles[static_cast(ColumnsRoles::RatingRole)] = "rating"; roles[static_cast(ColumnsRoles::GenreRole)] = "genre"; roles[static_cast(ColumnsRoles::LyricistRole)] = "lyricist"; roles[static_cast(ColumnsRoles::ComposerRole)] = "composer"; roles[static_cast(ColumnsRoles::CommentRole)] = "comment"; roles[static_cast(ColumnsRoles::YearRole)] = "year"; roles[static_cast(ColumnsRoles::ChannelsRole)] = "channels"; roles[static_cast(ColumnsRoles::BitRateRole)] = "bitRate"; roles[static_cast(ColumnsRoles::SampleRateRole)] = "sampleRate"; roles[static_cast(ColumnsRoles::ImageRole)] = "image"; roles[static_cast(ColumnsRoles::DatabaseIdRole)] = "databaseId"; roles[static_cast(ColumnsRoles::DiscFirstTrackRole)] = "isFirstTrackOfDisc"; roles[static_cast(ColumnsRoles::IsSingleDiscAlbumRole)] = "isSingleDiscAlbum"; roles[static_cast(ColumnsRoles::ContainerDataRole)] = "containerData"; roles[static_cast(ColumnsRoles::ResourceRole)] = "trackResource"; roles[static_cast(ColumnsRoles::SecondaryTextRole)] = "secondaryText"; roles[static_cast(ColumnsRoles::ImageUrlRole)] = "imageUrl"; roles[static_cast(ColumnsRoles::ShadowForImageRole)] = "shadowForImage"; return roles; } Qt::ItemFlags AlbumModel::flags(const QModelIndex &index) const { if (!index.isValid()) { return Qt::NoItemFlags; } return Qt::ItemIsSelectable | Qt::ItemIsEnabled; } QVariant AlbumModel::data(const QModelIndex &index, int role) const { auto result = QVariant(); Q_ASSERT(index.isValid()); Q_ASSERT(index.column() == 0); Q_ASSERT(index.row() >= 0 && index.row() < d->mCurrentAlbum.tracksCount()); Q_ASSERT(!index.parent().isValid()); Q_ASSERT(index.model() == this); const auto ¤tTrack = d->mCurrentAlbum.trackFromIndex(index.row()); if (!currentTrack.isValid()) { return result; } result = internalDataTrack(currentTrack, role, index.row()); return result; } QVariant AlbumModel::internalDataTrack(const MusicAudioTrack &track, int role, int rowIndex) const { auto result = QVariant(); switch(role) { case ColumnsRoles::TitleRole: if (track.title().isEmpty()) { track.resourceURI().fileName(); } else { result = track.title(); } break; case ColumnsRoles::MilliSecondsDurationRole: result = track.duration().msecsSinceStartOfDay(); break; case ColumnsRoles::DurationRole: { QTime trackDuration = track.duration(); if (trackDuration.hour() == 0) { result = trackDuration.toString(QStringLiteral("mm:ss")); } else { result = trackDuration.toString(); } break; } case ColumnsRoles::ArtistRole: result = track.artist(); break; case ColumnsRoles::AlbumRole: result = track.albumName(); break; case ColumnsRoles::AlbumArtistRole: result = track.albumArtist(); break; case ColumnsRoles::TrackNumberRole: result = track.trackNumber(); break; case ColumnsRoles::DiscNumberRole: result = track.discNumber(); break; case ColumnsRoles::DiscFirstTrackRole: if (rowIndex == 0) { result = true; } else { auto previousTrack = d->mCurrentAlbum.trackFromIndex(rowIndex - 1); result = (previousTrack.discNumber() != track.discNumber()); } break; case ColumnsRoles::IsSingleDiscAlbumRole: result = track.isSingleDiscAlbum(); break; case ColumnsRoles::RatingRole: result = track.rating(); break; case ColumnsRoles::GenreRole: result = track.genre(); break; case ColumnsRoles::LyricistRole: result = track.lyricist(); break; case ColumnsRoles::ComposerRole: result = track.composer(); break; case ColumnsRoles::YearRole: result = track.year(); break; case ColumnsRoles::ChannelsRole: result = track.channels(); break; case ColumnsRoles::BitRateRole: result = track.bitRate(); break; case ColumnsRoles::ImageRole: { if (d->mCurrentAlbum.albumArtURI().isValid()) { result = d->mCurrentAlbum.albumArtURI(); } break; } case ColumnsRoles::ResourceRole: result = track.resourceURI(); break; case ColumnsRoles::IdRole: result = track.title(); break; case ColumnsRoles::DatabaseIdRole: result = track.databaseId(); break; case ColumnsRoles::ContainerDataRole: result = QVariant::fromValue(track); break; case Qt::DisplayRole: result = track.title(); break; case ColumnsRoles::SecondaryTextRole: { auto secondaryText = QString(); secondaryText = QStringLiteral("%1 - %2%3"); secondaryText = secondaryText.arg(track.trackNumber()); secondaryText = secondaryText.arg(track.title()); if (track.artist() == track.albumArtist()) { secondaryText = secondaryText.arg(QString()); } else { auto artistText = QString(); artistText = QStringLiteral(" - %1"); artistText = artistText.arg(track.artist()); secondaryText = secondaryText.arg(artistText); } result = secondaryText; break; } case ColumnsRoles::ImageUrlRole: { const auto &albumArtUri = d->mCurrentAlbum.albumArtURI(); if (albumArtUri.isValid()) { result = albumArtUri; } else { result = QUrl(QStringLiteral("image://icon/media-optical-audio")); } break; } case ColumnsRoles::ShadowForImageRole: result = d->mCurrentAlbum.albumArtURI().isValid(); break; } return result; } QModelIndex AlbumModel::index(int row, int column, const QModelIndex &parent) const { auto result = QModelIndex(); if (column != 0) { return result; } if (parent.isValid()) { return result; } if (row >= d->mCurrentAlbum.tracksCount()) { return result; } return createIndex(row, column); } QModelIndex AlbumModel::parent(const QModelIndex &child) const { Q_UNUSED(child) return {}; } int AlbumModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent); return 1; } MusicAlbum AlbumModel::albumData() const { return d->mCurrentAlbum; } QString AlbumModel::title() const { return d->mCurrentAlbum.title(); } QString AlbumModel::author() const { return d->mCurrentAlbum.artist(); } int AlbumModel::tracksCount() const { return d->mCurrentAlbum.tracksCount(); } void AlbumModel::setAlbumData(const MusicAlbum &album) { if (d->mCurrentAlbum == album) { return; } if (d->mCurrentAlbum.tracksCount() > 0) { beginRemoveRows({}, 0, d->mCurrentAlbum.tracksCount() - 1); d->mCurrentAlbum = {}; endRemoveRows(); } beginInsertRows({}, 0, album.tracksCount() - 1); d->mCurrentAlbum = album; endInsertRows(); Q_EMIT albumDataChanged(); Q_EMIT tracksCountChanged(); Q_EMIT authorChanged(); Q_EMIT titleChanged(); } void AlbumModel::albumModified(const MusicAlbum &modifiedAlbum) { if (modifiedAlbum.databaseId() != d->mCurrentAlbum.databaseId()) { return; } auto removedTracks = QList(); for (auto i = 0; i < d->mCurrentAlbum.tracksCount(); ++i) { bool trackExist = false; for (auto j = 0; j < modifiedAlbum.tracksCount() && !trackExist; ++j) { trackExist = (d->mCurrentAlbum.trackIdFromIndex(i) == modifiedAlbum.trackIdFromIndex(j)); if (trackExist) { const auto &oldTrack = d->mCurrentAlbum.trackFromIndex(i); const auto &newTrack = modifiedAlbum.trackFromIndex(j); if (oldTrack != newTrack) { trackModified(newTrack); } } } if (!trackExist) { const auto &oldTrack = d->mCurrentAlbum.trackFromIndex(i); removedTracks.push_back(oldTrack); } } for (const auto &removedTrack : removedTracks) { trackRemoved(removedTrack); } for (auto j = 0; j < modifiedAlbum.tracksCount(); ++j) { bool trackExist = false; for (auto i = 0; i < d->mCurrentAlbum.tracksCount() && !trackExist; ++i) { trackExist = (d->mCurrentAlbum.trackIdFromIndex(i) == modifiedAlbum.trackIdFromIndex(j)); } if (!trackExist) { const auto &newTrack = modifiedAlbum.trackFromIndex(j); trackAdded(newTrack); } } } void AlbumModel::albumRemoved(const MusicAlbum &modifiedAlbum) { if (modifiedAlbum.databaseId() != d->mCurrentAlbum.databaseId()) { return; } for (int trackIndex = d->mCurrentAlbum.tracksCount() - 1; trackIndex >= 0 ; --trackIndex) { trackRemoved(d->mCurrentAlbum.trackFromIndex(trackIndex)); } } void AlbumModel::trackAdded(const MusicAudioTrack &newTrack) { if (newTrack.albumName() != d->mCurrentAlbum.title()) { return; } auto trackIndex = d->mCurrentAlbum.trackIndexFromId(newTrack.databaseId()); if (trackIndex != -1) { return; } bool trackInserted = false; for (int trackIndex = 0; trackIndex < d->mCurrentAlbum.tracksCount(); ++trackIndex) { const auto &oneTrack = d->mCurrentAlbum.trackFromIndex(trackIndex); if (oneTrack.discNumber() == newTrack.discNumber() && oneTrack.trackNumber() > newTrack.trackNumber()) { beginInsertRows({}, trackIndex, trackIndex); d->mCurrentAlbum.insertTrack(newTrack, trackIndex); endInsertRows(); trackInserted = true; break; } } if (!trackInserted) { beginInsertRows({}, d->mCurrentAlbum.tracksCount(), d->mCurrentAlbum.tracksCount()); d->mCurrentAlbum.insertTrack(newTrack, d->mCurrentAlbum.tracksCount()); endInsertRows(); } } void AlbumModel::trackModified(const MusicAudioTrack &modifiedTrack) { if (modifiedTrack.albumName() != d->mCurrentAlbum.title()) { return; } auto trackIndex = d->mCurrentAlbum.trackIndexFromId(modifiedTrack.databaseId()); if (trackIndex == -1) { return; } d->mCurrentAlbum.updateTrack(modifiedTrack, trackIndex); Q_EMIT dataChanged(index(trackIndex, 0), index(trackIndex, 0)); } void AlbumModel::trackRemoved(const MusicAudioTrack &removedTrack) { if (removedTrack.albumName() != d->mCurrentAlbum.title()) { return; } auto trackIndex = d->mCurrentAlbum.trackIndexFromId(removedTrack.databaseId()); if (trackIndex == -1) { return; } beginRemoveRows({}, trackIndex, trackIndex); d->mCurrentAlbum.removeTrackFromIndex(trackIndex); endRemoveRows(); } void AlbumModel::loadAlbumData(qulonglong id) { Q_EMIT requestAlbumData(id); } #include "moc_albummodel.cpp" diff --git a/src/models/albummodel.h b/src/models/albummodel.h index 51980190..76786701 100644 --- a/src/models/albummodel.h +++ b/src/models/albummodel.h @@ -1,165 +1,163 @@ /* * Copyright 2015-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef ALBUMMODEL_H #define ALBUMMODEL_H #include "elisaLib_export.h" #include #include #include #include #include "musicalbum.h" #include "musicaudiotrack.h" #include class DatabaseInterface; class AlbumModelPrivate; class QMutex; class ELISALIB_EXPORT AlbumModel : public QAbstractItemModel { Q_OBJECT Q_PROPERTY(MusicAlbum albumData READ albumData WRITE setAlbumData NOTIFY albumDataChanged) Q_PROPERTY(QString title READ title NOTIFY titleChanged) Q_PROPERTY(QString author READ author NOTIFY authorChanged) Q_PROPERTY(int tracksCount READ tracksCount NOTIFY tracksCountChanged) public: enum ItemClass { Container = 0, Album = 1, Artist = 2, AudioTrack = 3, }; enum ColumnsRoles { TitleRole = Qt::UserRole + 1, DurationRole, MilliSecondsDurationRole, ArtistRole, AlbumRole, AlbumArtistRole, TrackNumberRole, DiscNumberRole, RatingRole, GenreRole, LyricistRole, ComposerRole, CommentRole, YearRole, ChannelsRole, BitRateRole, SampleRateRole, ImageRole, ResourceRole, IdRole, DatabaseIdRole, DiscFirstTrackRole, IsSingleDiscAlbumRole, ContainerDataRole, SecondaryTextRole, ImageUrlRole, ShadowForImageRole, }; Q_ENUM(ColumnsRoles) explicit AlbumModel(QObject *parent = nullptr); ~AlbumModel() override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; QHash roleNames() const override; Qt::ItemFlags flags(const QModelIndex &index) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; QModelIndex parent(const QModelIndex &child) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; MusicAlbum albumData() const; QString title() const; QString author() const; int tracksCount() const; Q_INVOKABLE void loadAlbumData(qulonglong id); Q_SIGNALS: void albumDataChanged(); void titleChanged(); void authorChanged(); void tracksCountChanged(); void requestAlbumData(qulonglong id); public Q_SLOTS: void setAlbumData(const MusicAlbum &album); void albumModified(const MusicAlbum &modifiedAlbum); void albumRemoved(const MusicAlbum &modifiedAlbum); private: void trackAdded(const MusicAudioTrack &newTrack); void trackModified(const MusicAudioTrack &modifiedTrack); void trackRemoved(const MusicAudioTrack &removedTrack); QVariant internalDataTrack(const MusicAudioTrack &track, int role, int rowIndex) const; std::unique_ptr d; }; Q_DECLARE_METATYPE(AlbumModel::ItemClass) #endif // ALBUMMODEL_H diff --git a/src/models/allalbumsmodel.cpp b/src/models/allalbumsmodel.cpp index c6b0fff1..a8870934 100644 --- a/src/models/allalbumsmodel.cpp +++ b/src/models/allalbumsmodel.cpp @@ -1,347 +1,345 @@ /* * Copyright 2015-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "allalbumsmodel.h" #include "databaseinterface.h" #include "allartistsmodel.h" #include "albummodel.h" #include "elisautils.h" #include #include #include #include #include #include #include #include #include #include class AllAlbumsModelPrivate { public: AllAlbumsModelPrivate() { mThreadPool.setMaxThreadCount(1); } QVector mAllAlbums; QHash mAlbumsData; AllArtistsModel *mAllArtistsModel = nullptr; QReadWriteLock mDataLock; QThreadPool mThreadPool; }; AllAlbumsModel::AllAlbumsModel(QObject *parent) : QAbstractItemModel(parent), d(std::make_unique()) { } AllAlbumsModel::~AllAlbumsModel() = default; int AllAlbumsModel::albumCount() const { QReadLocker locker(&d->mDataLock); return d->mAllAlbums.size(); } int AllAlbumsModel::rowCount(const QModelIndex &parent) const { auto albumCount = 0; if (parent.isValid()) { return albumCount; } QReadLocker locker(&d->mDataLock); albumCount = d->mAllAlbums.size(); return albumCount; } QHash AllAlbumsModel::roleNames() const { auto roles = QAbstractItemModel::roleNames(); roles[static_cast(ElisaUtils::ColumnsRoles::TitleRole)] = "title"; //roles[static_cast(ElisaUtils::ColumnsRoles::AllTracksTitleRole)] = "tracksTitle"; roles[static_cast(ElisaUtils::ColumnsRoles::ArtistRole)] = "artist"; roles[static_cast(ElisaUtils::ColumnsRoles::AllArtistsRole)] = "allArtists"; roles[static_cast(ElisaUtils::ColumnsRoles::ImageRole)] = "image"; //roles[static_cast(ElisaUtils::ColumnsRoles::CountRole)] = "count"; roles[static_cast(ElisaUtils::ColumnsRoles::IsSingleDiscAlbumRole)] = "isSingleDiscAlbum"; roles[static_cast(ElisaUtils::ColumnsRoles::ContainerDataRole)] = "containerData"; roles[static_cast(ElisaUtils::ColumnsRoles::HighestTrackRating)] = "highestTrackRating"; roles[static_cast(ElisaUtils::ColumnsRoles::DatabaseIdRole)] = "databaseId"; roles[static_cast(ElisaUtils::ColumnsRoles::SecondaryTextRole)] = "secondaryText"; roles[static_cast(ElisaUtils::ColumnsRoles::ImageUrlRole)] = "imageUrl"; roles[static_cast(ElisaUtils::ColumnsRoles::ShadowForImageRole)] = "shadowForImage"; roles[static_cast(ElisaUtils::ColumnsRoles::ChildModelRole)] = "childModel"; //roles[static_cast(ElisaUtils::ColumnsRoles::IsTracksContainerRole)] = "isTracksContainer"; return roles; } Qt::ItemFlags AllAlbumsModel::flags(const QModelIndex &index) const { if (!index.isValid()) { return Qt::NoItemFlags; } return Qt::ItemIsSelectable | Qt::ItemIsEnabled; } QVariant AllAlbumsModel::data(const QModelIndex &index, int role) const { auto result = QVariant(); QReadLocker locker(&d->mDataLock); const auto albumCount = d->mAllAlbums.size(); Q_ASSERT(index.isValid()); Q_ASSERT(index.column() == 0); Q_ASSERT(index.row() >= 0 && index.row() < albumCount); Q_ASSERT(!index.parent().isValid()); Q_ASSERT(index.model() == this); Q_ASSERT(index.internalId() == 0); result = internalDataAlbum(index.row(), role); return result; } QVariant AllAlbumsModel::internalDataAlbum(int albumIndex, int role) const { auto result = QVariant(); switch(role) { case Qt::DisplayRole: case ElisaUtils::ColumnsRoles::TitleRole: result = d->mAlbumsData[d->mAllAlbums[albumIndex]].title(); break; /*case ElisaUtils::ColumnsRoles::AllTracksTitleRole: result = d->mAlbumsData[d->mAllAlbums[albumIndex]].allTracksTitle(); break;*/ case ElisaUtils::ColumnsRoles::ArtistRole: result = d->mAlbumsData[d->mAllAlbums[albumIndex]].artist(); break; case ElisaUtils::ColumnsRoles::AllArtistsRole: result = d->mAlbumsData[d->mAllAlbums[albumIndex]].allArtists().join(QStringLiteral(", ")); break; case ElisaUtils::ColumnsRoles::ImageRole: { auto albumArt = d->mAlbumsData[d->mAllAlbums[albumIndex]].albumArtURI(); if (albumArt.isValid()) { result = albumArt; } break; } /*case ElisaUtils::ColumnsRoles::CountRole: result = d->mAlbumsData[d->mAllAlbums[albumIndex]].tracksCount(); break;*/ case ElisaUtils::ColumnsRoles::IdRole: result = d->mAlbumsData[d->mAllAlbums[albumIndex]].id(); break; case ElisaUtils::ColumnsRoles::IsSingleDiscAlbumRole: result = d->mAlbumsData[d->mAllAlbums[albumIndex]].isSingleDiscAlbum(); break; case ElisaUtils::ColumnsRoles::ContainerDataRole: result = QVariant::fromValue(d->mAlbumsData[d->mAllAlbums[albumIndex]]); break; case ElisaUtils::ColumnsRoles::DatabaseIdRole: result = QVariant::fromValue(d->mAlbumsData[d->mAllAlbums[albumIndex]].databaseId()); break; case ElisaUtils::ColumnsRoles::HighestTrackRating: result = d->mAlbumsData[d->mAllAlbums[albumIndex]].highestTrackRating(); break; case ElisaUtils::ColumnsRoles::SecondaryTextRole: result = d->mAlbumsData[d->mAllAlbums[albumIndex]].artist(); break; case ElisaUtils::ColumnsRoles::ImageUrlRole: { auto albumArt = d->mAlbumsData[d->mAllAlbums[albumIndex]].albumArtURI(); if (albumArt.isValid()) { result = albumArt; } else { result = QUrl(QStringLiteral("image://icon/media-optical-audio")); } break; } case ElisaUtils::ColumnsRoles::ShadowForImageRole: result = d->mAlbumsData[d->mAllAlbums[albumIndex]].albumArtURI().isValid(); break; case ElisaUtils::ColumnsRoles::ChildModelRole: { auto albumData = d->mAlbumsData[d->mAllAlbums[albumIndex]]; result = QVariant::fromValue(albumData); break; } case ElisaUtils::ColumnsRoles::GenreRole: result = d->mAlbumsData[d->mAllAlbums[albumIndex]].genres(); break; /*case ElisaUtils::ColumnsRoles::IsTracksContainerRole: result = true; break;*/ } return result; } QModelIndex AllAlbumsModel::index(int row, int column, const QModelIndex &parent) const { auto result = QModelIndex(); if (column != 0) { return result; } if (parent.isValid()) { return result; } result = createIndex(row, column); return result; } QModelIndex AllAlbumsModel::parent(const QModelIndex &child) const { Q_UNUSED(child) auto result = QModelIndex(); return result; } int AllAlbumsModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent); return 1; } AllArtistsModel *AllAlbumsModel::allArtists() const { return d->mAllArtistsModel; } void AllAlbumsModel::albumsAdded(const QList &newAlbums) { QtConcurrent::run(&d->mThreadPool, [=] () { for (const auto &newAlbum : newAlbums) { if (newAlbum.isValid()) { beginInsertRows({}, d->mAllAlbums.size(), d->mAllAlbums.size()); { QWriteLocker locker(&d->mDataLock); d->mAllAlbums.push_back(newAlbum.databaseId()); d->mAlbumsData[newAlbum.databaseId()] = newAlbum; } endInsertRows(); Q_EMIT albumCountChanged(); } } }); } void AllAlbumsModel::albumRemoved(const MusicAlbum &removedAlbum) { QtConcurrent::run(&d->mThreadPool, [=] () { auto removedAlbumIterator = d->mAllAlbums.end(); { QReadLocker locker(&d->mDataLock); removedAlbumIterator = std::find(d->mAllAlbums.begin(), d->mAllAlbums.end(), removedAlbum.databaseId()); if (removedAlbumIterator == d->mAllAlbums.end()) { return; } int albumIndex = removedAlbumIterator - d->mAllAlbums.begin(); beginRemoveRows({}, albumIndex, albumIndex); } { QWriteLocker writeLocker(&d->mDataLock); d->mAlbumsData.remove(removedAlbum.databaseId()); d->mAllAlbums.erase(removedAlbumIterator); } endRemoveRows(); Q_EMIT albumCountChanged(); }); } void AllAlbumsModel::albumModified(const MusicAlbum &modifiedAlbum) { QtConcurrent::run(&d->mThreadPool, [=] () { auto modifiedAlbumIterator = d->mAllAlbums.end(); { QReadLocker locker(&d->mDataLock); modifiedAlbumIterator = std::find(d->mAllAlbums.begin(), d->mAllAlbums.end(), modifiedAlbum.databaseId()); } int albumIndex = 0; { QWriteLocker writeLocker(&d->mDataLock); if (modifiedAlbumIterator == d->mAllAlbums.end()) { return; } albumIndex = modifiedAlbumIterator - d->mAllAlbums.begin(); d->mAlbumsData[modifiedAlbum.databaseId()] = modifiedAlbum; } Q_EMIT dataChanged(index(albumIndex, 0), index(albumIndex, 0)); }); } void AllAlbumsModel::setAllArtists(AllArtistsModel *model) { if (d->mAllArtistsModel == model) { return; } d->mAllArtistsModel = model; Q_EMIT allArtistsChanged(); } #include "moc_allalbumsmodel.cpp" diff --git a/src/models/allalbumsmodel.h b/src/models/allalbumsmodel.h index f3c1f989..88f603e2 100644 --- a/src/models/allalbumsmodel.h +++ b/src/models/allalbumsmodel.h @@ -1,99 +1,97 @@ /* * Copyright 2015-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef ALLALBUMSMODEL_H #define ALLALBUMSMODEL_H #include "elisaLib_export.h" #include #include #include #include #include "musicalbum.h" #include "musicaudiotrack.h" #include class AllAlbumsModelPrivate; class AllArtistsModel; class ELISALIB_EXPORT AllAlbumsModel : public QAbstractItemModel { Q_OBJECT Q_PROPERTY(int albumCount READ albumCount NOTIFY albumCountChanged) Q_PROPERTY(AllArtistsModel* allArtists READ allArtists WRITE setAllArtists NOTIFY allArtistsChanged) public: explicit AllAlbumsModel(QObject *parent = nullptr); ~AllAlbumsModel() override; Q_INVOKABLE int albumCount() const; int rowCount(const QModelIndex &parent = QModelIndex()) const override; QHash roleNames() const override; Qt::ItemFlags flags(const QModelIndex &index) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; QModelIndex parent(const QModelIndex &child) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; AllArtistsModel *allArtists() const; public Q_SLOTS: void albumsAdded(const QList &newAlbums); void albumRemoved(const MusicAlbum &removedAlbum); void albumModified(const MusicAlbum &modifiedAlbum); void setAllArtists(AllArtistsModel *model); Q_SIGNALS: void albumCountChanged(); void allArtistsChanged(); private: QVariant internalDataAlbum(int albumIndex, int role) const; std::unique_ptr d; }; #endif // ALLALBUMSMODEL_H diff --git a/src/models/allalbumsproxymodel.cpp b/src/models/allalbumsproxymodel.cpp index 9485963e..18924db7 100644 --- a/src/models/allalbumsproxymodel.cpp +++ b/src/models/allalbumsproxymodel.cpp @@ -1,133 +1,131 @@ /* * Copyright 2016-2017 Matthieu Gallien * Copyright 2017 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "allalbumsproxymodel.h" #include "genericdatamodel.h" #include "musicalbum.h" #include #include AllAlbumsProxyModel::AllAlbumsProxyModel(QObject *parent) : AbstractMediaProxyModel(parent) { this->setSortRole(ElisaUtils::ColumnsRoles::TitleRole); this->setSortCaseSensitivity(Qt::CaseInsensitive); this->sortModel(Qt::AscendingOrder); } AllAlbumsProxyModel::~AllAlbumsProxyModel() { } bool AllAlbumsProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { bool result = false; for (int column = 0, columnCount = sourceModel()->columnCount(source_parent); column < columnCount; ++column) { auto currentIndex = sourceModel()->index(source_row, column, source_parent); const auto &genreValue = sourceModel()->data(currentIndex, ElisaUtils::ColumnsRoles::GenreRole); if (!genreFilterText().isNull() && !genreValue.isValid()) { continue; } if (!genreFilterText().isNull() && !genreValue.canConvert()) { continue; } if (!genreFilterText().isNull() && !genreValue.toStringList().contains(genreFilterText())) { continue; } const auto &titleValue = sourceModel()->data(currentIndex, ElisaUtils::ColumnsRoles::TitleRole).toString(); const auto &artistValue = sourceModel()->data(currentIndex, ElisaUtils::ColumnsRoles::ArtistRole).toString(); const auto &allArtistsValue = sourceModel()->data(currentIndex, ElisaUtils::ColumnsRoles::AllArtistsRole).toStringList(); const auto maximumRatingValue = sourceModel()->data(currentIndex, ElisaUtils::ColumnsRoles::HighestTrackRating).toInt(); if (maximumRatingValue < mFilterRating) { result = false; continue; } if (mFilterExpression.match(titleValue).hasMatch()) { result = true; continue; } if (mFilterExpression.match(artistValue).hasMatch()) { result = true; continue; } for (const auto &oneArtist : allArtistsValue) { if (mFilterExpression.match(oneArtist).hasMatch()) { result = true; break; } } if (result) { continue; } if (!result) { break; } } return result; } void AllAlbumsProxyModel::enqueueToPlayList() { QtConcurrent::run(&mThreadPool, [=] () { QReadLocker locker(&mDataLock); auto allAlbums = QList(); allAlbums.reserve(rowCount()); for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) { auto currentIndex = index(rowIndex, 0); allAlbums.push_back(data(currentIndex, ElisaUtils::ColumnsRoles::ContainerDataRole). value()); } Q_EMIT albumToEnqueue(allAlbums, ElisaUtils::AppendPlayList, ElisaUtils::DoNotTriggerPlay); }); } void AllAlbumsProxyModel::replaceAndPlayOfPlayList() { QtConcurrent::run(&mThreadPool, [=] () { QReadLocker locker(&mDataLock); auto allAlbums = QList(); allAlbums.reserve(rowCount()); for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) { auto currentIndex = index(rowIndex, 0); allAlbums.push_back(data(currentIndex, ElisaUtils::ColumnsRoles::ContainerDataRole). value()); } Q_EMIT albumToEnqueue(allAlbums, ElisaUtils::ReplacePlayList, ElisaUtils::TriggerPlay); }); } #include "moc_allalbumsproxymodel.cpp" diff --git a/src/models/allalbumsproxymodel.h b/src/models/allalbumsproxymodel.h index 244bec84..a13b26e3 100644 --- a/src/models/allalbumsproxymodel.h +++ b/src/models/allalbumsproxymodel.h @@ -1,60 +1,58 @@ /* * Copyright 2016-2018 Matthieu Gallien * Copyright 2017 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef ALLALBUMSPROXYMODEL_H #define ALLALBUMSPROXYMODEL_H #include "elisaLib_export.h" #include "abstractmediaproxymodel.h" #include "elisautils.h" class MusicAlbum; class ELISALIB_EXPORT AllAlbumsProxyModel : public AbstractMediaProxyModel { Q_OBJECT public: explicit AllAlbumsProxyModel(QObject *parent = nullptr); ~AllAlbumsProxyModel() override; Q_SIGNALS: void albumToEnqueue(QList newAlbums, ElisaUtils::PlayListEnqueueMode enqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay); public Q_SLOTS: void enqueueToPlayList(); void replaceAndPlayOfPlayList(); protected: bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; }; #endif // ALLALBUMSPROXYMODEL_H diff --git a/src/models/allartistsmodel.cpp b/src/models/allartistsmodel.cpp index 54bd022c..d19aa926 100644 --- a/src/models/allartistsmodel.cpp +++ b/src/models/allartistsmodel.cpp @@ -1,224 +1,222 @@ /* * Copyright 2015-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "allartistsmodel.h" #include "databaseinterface.h" #include "musicartist.h" #include "allalbumsmodel.h" #include #include #include #include class AllArtistsModelPrivate { public: AllArtistsModelPrivate() { } QVector mAllArtists; AllAlbumsModel *mAllAlbumsModel = nullptr; }; AllArtistsModel::AllArtistsModel(QObject *parent) : QAbstractItemModel(parent), d(std::make_unique()) { } AllArtistsModel::~AllArtistsModel() = default; int AllArtistsModel::rowCount(const QModelIndex &parent) const { auto artistCount = 0; if (parent.isValid()) { return artistCount; } artistCount = d->mAllArtists.size(); return artistCount; } QHash AllArtistsModel::roleNames() const { auto roles = QAbstractItemModel::roleNames(); //roles[static_cast(ElisaUtils::ColumnsRoles::NameRole)] = "name"; //roles[static_cast(ElisaUtils::ColumnsRoles::ArtistsCountRole)] = "albumsCount"; roles[static_cast(ElisaUtils::ColumnsRoles::ImageRole)] = "image"; roles[static_cast(ElisaUtils::ColumnsRoles::IdRole)] = "databaseId"; roles[static_cast(ElisaUtils::ColumnsRoles::SecondaryTextRole)] = "secondaryText"; roles[static_cast(ElisaUtils::ColumnsRoles::ImageUrlRole)] = "imageUrl"; roles[static_cast(ElisaUtils::ColumnsRoles::ShadowForImageRole)] = "shadowForImage"; roles[static_cast(ElisaUtils::ColumnsRoles::ContainerDataRole)] = "containerData"; roles[static_cast(ElisaUtils::ColumnsRoles::ChildModelRole)] = "childModel"; roles[static_cast(ElisaUtils::ColumnsRoles::DatabaseIdRole)] = "databaseId"; //roles[static_cast(ElisaUtils::ColumnsRoles::IsTracksContainerRole)] = "isTracksContainer"; return roles; } Qt::ItemFlags AllArtistsModel::flags(const QModelIndex &index) const { if (!index.isValid()) { return Qt::NoItemFlags; } return Qt::ItemIsSelectable | Qt::ItemIsEnabled; } QVariant AllArtistsModel::data(const QModelIndex &index, int role) const { auto result = QVariant(); const auto artistsCount = d->mAllArtists.size(); Q_ASSERT(index.isValid()); Q_ASSERT(index.column() == 0); Q_ASSERT(index.row() >= 0 && index.row() < artistsCount); Q_ASSERT(!index.parent().isValid()); Q_ASSERT(index.model() == this); Q_ASSERT(index.internalId() == 0); switch(role) { case Qt::DisplayRole: result = d->mAllArtists[index.row()].name(); break; /*case ElisaUtils::ColumnsRoles::ArtistsCountRole: result = d->mAllArtists[index.row()].albumsCount(); break;*/ case ElisaUtils::ColumnsRoles::ImageRole: break; case ElisaUtils::ColumnsRoles::IdRole: break; case ElisaUtils::ColumnsRoles::SecondaryTextRole: result = QString(); break; case ElisaUtils::ColumnsRoles::ImageUrlRole: result = QUrl(QStringLiteral("image://icon/view-media-artist")); break; case ElisaUtils::ColumnsRoles::ShadowForImageRole: result = false; break; case ElisaUtils::ColumnsRoles::ContainerDataRole: result = QVariant::fromValue(d->mAllArtists[index.row()]); break; case ElisaUtils::ColumnsRoles::ChildModelRole: result = d->mAllArtists[index.row()].name(); break; case ElisaUtils::ColumnsRoles::GenreRole: result = d->mAllArtists[index.row()].genres(); break; case ElisaUtils::ColumnsRoles::DatabaseIdRole: result = QVariant::fromValue(d->mAllArtists[index.row()].databaseId()); break; /*case ElisaUtils::ColumnsRoles::IsTracksContainerRole: result = false; break;*/ } return result; } QModelIndex AllArtistsModel::index(int row, int column, const QModelIndex &parent) const { auto result = QModelIndex(); if (column != 0) { return result; } if (parent.isValid()) { return result; } result = createIndex(row, column); return result; } QModelIndex AllArtistsModel::parent(const QModelIndex &child) const { Q_UNUSED(child) auto result = QModelIndex(); return result; } int AllArtistsModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent); return 1; } AllAlbumsModel *AllArtistsModel::allAlbums() const { return d->mAllAlbumsModel; } void AllArtistsModel::artistsAdded(const QList &newArtists) { if (!newArtists.isEmpty()) { beginInsertRows({}, d->mAllArtists.size(), d->mAllArtists.size() + newArtists.size() - 1); d->mAllArtists += newArtists.toVector(); endInsertRows(); } } void AllArtistsModel::artistRemoved(const MusicArtist &removedArtist) { auto removedArtistIterator = std::find(d->mAllArtists.begin(), d->mAllArtists.end(), removedArtist); if (removedArtistIterator == d->mAllArtists.end()) { return; } int artistIndex = removedArtistIterator - d->mAllArtists.begin(); beginRemoveRows({}, artistIndex, artistIndex); d->mAllArtists.erase(removedArtistIterator); endRemoveRows(); } void AllArtistsModel::artistModified(const MusicArtist &modifiedArtist) { Q_UNUSED(modifiedArtist); } void AllArtistsModel::setAllAlbums(AllAlbumsModel *model) { if (d->mAllAlbumsModel == model) { return; } d->mAllAlbumsModel = model; Q_EMIT allAlbumsChanged(); } #include "moc_allartistsmodel.cpp" diff --git a/src/models/allartistsmodel.h b/src/models/allartistsmodel.h index 9b734053..c6f90ed9 100644 --- a/src/models/allartistsmodel.h +++ b/src/models/allartistsmodel.h @@ -1,89 +1,87 @@ /* * Copyright 2015-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef ALLARTISTSMODEL_H #define ALLARTISTSMODEL_H #include "elisaLib_export.h" #include #include #include #include #include "musicartist.h" #include class DatabaseInterface; class AllArtistsModelPrivate; class AllAlbumsModel; class ELISALIB_EXPORT AllArtistsModel : public QAbstractItemModel { Q_OBJECT Q_PROPERTY(AllAlbumsModel* allAlbums READ allAlbums WRITE setAllAlbums NOTIFY allAlbumsChanged) public: explicit AllArtistsModel(QObject *parent = nullptr); ~AllArtistsModel() override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; QHash roleNames() const override; Qt::ItemFlags flags(const QModelIndex &index) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; QModelIndex parent(const QModelIndex &child) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; AllAlbumsModel* allAlbums() const; Q_SIGNALS: void allAlbumsChanged(); public Q_SLOTS: void artistsAdded(const QList &newArtists); void artistRemoved(const MusicArtist &removedArtist); void artistModified(const MusicArtist &modifiedArtist); void setAllAlbums(AllAlbumsModel *model); private: std::unique_ptr d; }; #endif // ALLARTISTSMODEL_H diff --git a/src/models/allartistsproxymodel.cpp b/src/models/allartistsproxymodel.cpp index d25a9189..5a9b079d 100644 --- a/src/models/allartistsproxymodel.cpp +++ b/src/models/allartistsproxymodel.cpp @@ -1,112 +1,110 @@ /* * Copyright 2017 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "allartistsproxymodel.h" #include "elisautils.h" #include #include #include AllArtistsProxyModel::AllArtistsProxyModel(QObject *parent) : AbstractMediaProxyModel(parent) { this->setSortRole(Qt::DisplayRole); this->setSortCaseSensitivity(Qt::CaseInsensitive); this->sortModel(Qt::AscendingOrder); } AllArtistsProxyModel::~AllArtistsProxyModel() { } bool AllArtistsProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { bool result = false; for (int column = 0, columnCount = sourceModel()->columnCount(source_parent); column < columnCount; ++column) { auto currentIndex = sourceModel()->index(source_row, column, source_parent); const auto &genreValue = sourceModel()->data(currentIndex, ElisaUtils::ColumnsRoles::GenreRole); if (!genreFilterText().isNull() && !genreValue.isValid()) { continue; } if (!genreFilterText().isNull() && !genreValue.canConvert()) { continue; } if (!genreFilterText().isNull() && !genreValue.toStringList().contains(genreFilterText())) { continue; } const auto &artistValue = sourceModel()->data(currentIndex, Qt::DisplayRole).toString(); if (mFilterExpression.match(artistValue).hasMatch()) { result = true; continue; } if (result) { continue; } if (!result) { break; } } return result; } void AllArtistsProxyModel::enqueueToPlayList() { QtConcurrent::run(&mThreadPool, [=] () { QReadLocker locker(&mDataLock); auto allArtists = QStringList(); allArtists.reserve(rowCount()); for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) { auto currentIndex = index(rowIndex, 0); allArtists.push_back(data(currentIndex, Qt::DisplayRole).toString()); } Q_EMIT artistToEnqueue(allArtists, ElisaUtils::AppendPlayList, ElisaUtils::DoNotTriggerPlay); }); } void AllArtistsProxyModel::replaceAndPlayOfPlayList() { QtConcurrent::run(&mThreadPool, [=] () { QReadLocker locker(&mDataLock); auto allArtists = QStringList(); allArtists.reserve(rowCount()); for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) { auto currentIndex = index(rowIndex, 0); allArtists.push_back(data(currentIndex, Qt::DisplayRole).toString()); } Q_EMIT artistToEnqueue(allArtists, ElisaUtils::ReplacePlayList, ElisaUtils::TriggerPlay); }); } #include "moc_allartistsproxymodel.cpp" diff --git a/src/models/allartistsproxymodel.h b/src/models/allartistsproxymodel.h index c85e417e..92a37d7f 100644 --- a/src/models/allartistsproxymodel.h +++ b/src/models/allartistsproxymodel.h @@ -1,58 +1,56 @@ /* * Copyright 2017 Alexander Stippich * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef ALLARTISTSPROXYMODEL_H #define ALLARTISTSPROXYMODEL_H #include "elisaLib_export.h" #include "abstractmediaproxymodel.h" #include "elisautils.h" class ELISALIB_EXPORT AllArtistsProxyModel : public AbstractMediaProxyModel { Q_OBJECT public: explicit AllArtistsProxyModel(QObject *parent = nullptr); ~AllArtistsProxyModel() override; Q_SIGNALS: void artistToEnqueue(QList artistNames, ElisaUtils::PlayListEnqueueMode enqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay); public Q_SLOTS: void enqueueToPlayList(); void replaceAndPlayOfPlayList(); protected: bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; }; #endif // ALLARTISTSPROXYMODEL_H diff --git a/src/models/allgenresmodel.cpp b/src/models/allgenresmodel.cpp index af3b2f7c..65f011a8 100644 --- a/src/models/allgenresmodel.cpp +++ b/src/models/allgenresmodel.cpp @@ -1,193 +1,191 @@ /* * Copyright 2015-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "allgenresmodel.h" #include "databaseinterface.h" #include "musicaudiogenre.h" #include #include #include #include class AllGenresModelPrivate { public: AllGenresModelPrivate() = default; QVector mAllGenres; }; AllGenresModel::AllGenresModel(QObject *parent) : QAbstractItemModel(parent), d(std::make_unique()) { } AllGenresModel::~AllGenresModel() = default; int AllGenresModel::rowCount(const QModelIndex &parent) const { auto artistCount = 0; if (parent.isValid()) { return artistCount; } artistCount = d->mAllGenres.size(); return artistCount; } QHash AllGenresModel::roleNames() const { auto roles = QAbstractItemModel::roleNames(); //roles[static_cast(ElisaUtils::ColumnsRoles::NameRole)] = "name"; //roles[static_cast(ElisaUtils::ColumnsRoles::ArtistsCountRole)] = "albumsCount"; roles[static_cast(ElisaUtils::ColumnsRoles::ImageRole)] = "image"; roles[static_cast(ElisaUtils::ColumnsRoles::IdRole)] = "databaseId"; roles[static_cast(ElisaUtils::ColumnsRoles::SecondaryTextRole)] = "secondaryText"; roles[static_cast(ElisaUtils::ColumnsRoles::ImageUrlRole)] = "imageUrl"; roles[static_cast(ElisaUtils::ColumnsRoles::ShadowForImageRole)] = "shadowForImage"; roles[static_cast(ElisaUtils::ColumnsRoles::ContainerDataRole)] = "containerData"; roles[static_cast(ElisaUtils::ColumnsRoles::ChildModelRole)] = "childModel"; //roles[static_cast(ElisaUtils::ColumnsRoles::IsTracksContainerRole)] = "isTracksContainer"; return roles; } Qt::ItemFlags AllGenresModel::flags(const QModelIndex &index) const { if (!index.isValid()) { return Qt::NoItemFlags; } return Qt::ItemIsSelectable | Qt::ItemIsEnabled; } QVariant AllGenresModel::data(const QModelIndex &index, int role) const { auto result = QVariant(); const auto artistsCount = d->mAllGenres.size(); Q_ASSERT(index.isValid()); Q_ASSERT(index.column() == 0); Q_ASSERT(index.row() >= 0 && index.row() < artistsCount); Q_ASSERT(!index.parent().isValid()); Q_ASSERT(index.model() == this); Q_ASSERT(index.internalId() == 0); switch(role) { case Qt::DisplayRole: result = d->mAllGenres[index.row()].name(); break; case ElisaUtils::ColumnsRoles::ImageRole: break; case ElisaUtils::ColumnsRoles::IdRole: break; case ElisaUtils::ColumnsRoles::SecondaryTextRole: result = QString(); break; case ElisaUtils::ColumnsRoles::ImageUrlRole: result = QUrl(QStringLiteral("image://icon/view-media-genre")); break; case ElisaUtils::ColumnsRoles::ShadowForImageRole: result = false; break; case ElisaUtils::ColumnsRoles::ContainerDataRole: result = QVariant::fromValue(d->mAllGenres[index.row()]); break; case ElisaUtils::ColumnsRoles::ChildModelRole: result = d->mAllGenres[index.row()].name(); break; /*case ElisaUtils::ColumnsRoles::IsTracksContainerRole: result = false; break;*/ } return result; } QModelIndex AllGenresModel::index(int row, int column, const QModelIndex &parent) const { auto result = QModelIndex(); if (column != 0) { return result; } if (parent.isValid()) { return result; } result = createIndex(row, column); return result; } QModelIndex AllGenresModel::parent(const QModelIndex &child) const { Q_UNUSED(child) auto result = QModelIndex(); return result; } int AllGenresModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent); return 1; } void AllGenresModel::genresAdded(const QList &newGenres) { if (!newGenres.isEmpty()) { beginInsertRows({}, d->mAllGenres.size(), d->mAllGenres.size() + newGenres.size() - 1); d->mAllGenres += newGenres.toVector(); endInsertRows(); } } void AllGenresModel::genreRemoved(const MusicAudioGenre &removedGenre) { auto removedGenreIterator = std::find(d->mAllGenres.begin(), d->mAllGenres.end(), removedGenre); if (removedGenreIterator == d->mAllGenres.end()) { return; } int genreIndex = removedGenreIterator - d->mAllGenres.begin(); beginRemoveRows({}, genreIndex, genreIndex); d->mAllGenres.erase(removedGenreIterator); endRemoveRows(); } void AllGenresModel::genreModified(const MusicAudioGenre &modifiedGenre) { Q_UNUSED(modifiedGenre); } #include "moc_allgenresmodel.cpp" diff --git a/src/models/allgenresmodel.h b/src/models/allgenresmodel.h index b94e6e9b..96d84385 100644 --- a/src/models/allgenresmodel.h +++ b/src/models/allgenresmodel.h @@ -1,78 +1,76 @@ /* * Copyright 2015-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef ALLGENRESMODEL_H #define ALLGENRESMODEL_H #include "elisaLib_export.h" #include #include #include #include #include class DatabaseInterface; class AllGenresModelPrivate; class MusicAudioGenre; class ELISALIB_EXPORT AllGenresModel : public QAbstractItemModel { Q_OBJECT public: explicit AllGenresModel(QObject *parent = nullptr); ~AllGenresModel() override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; QHash roleNames() const override; Qt::ItemFlags flags(const QModelIndex &index) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; QModelIndex parent(const QModelIndex &child) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; Q_SIGNALS: void allAlbumsChanged(); public Q_SLOTS: void genresAdded(const QList &newGenres); void genreRemoved(const MusicAudioGenre &removedGenre); void genreModified(const MusicAudioGenre &modifiedGenre); private: std::unique_ptr d; }; #endif // ALLGENRESMODEL_H diff --git a/src/models/alltracksmodel.cpp b/src/models/alltracksmodel.cpp index 34547838..8c8785c1 100644 --- a/src/models/alltracksmodel.cpp +++ b/src/models/alltracksmodel.cpp @@ -1,338 +1,336 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "alltracksmodel.h" #include "elisautils.h" #include #include class AllTracksModelPrivate { public: QHash mAllTracks; QList mIds; }; AllTracksModel::AllTracksModel(QObject *parent) : QAbstractItemModel(parent), d(std::make_unique()) { } AllTracksModel::~AllTracksModel() = default; int AllTracksModel::rowCount(const QModelIndex &parent) const { auto tracksCount = 0; if (parent.isValid()) { return tracksCount; } tracksCount = d->mAllTracks.size(); return tracksCount; } QHash AllTracksModel::roleNames() const { auto roles = QAbstractItemModel::roleNames(); roles[static_cast(ElisaUtils::ColumnsRoles::TitleRole)] = "title"; roles[static_cast(ElisaUtils::ColumnsRoles::DurationRole)] = "duration"; roles[static_cast(ElisaUtils::ColumnsRoles::ArtistRole)] = "artist"; roles[static_cast(ElisaUtils::ColumnsRoles::AlbumRole)] = "album"; roles[static_cast(ElisaUtils::ColumnsRoles::AlbumArtistRole)] = "albumArtist"; roles[static_cast(ElisaUtils::ColumnsRoles::TrackNumberRole)] = "trackNumber"; roles[static_cast(ElisaUtils::ColumnsRoles::DiscNumberRole)] = "discNumber"; roles[static_cast(ElisaUtils::ColumnsRoles::RatingRole)] = "rating"; roles[static_cast(ElisaUtils::ColumnsRoles::GenreRole)] = "genre"; roles[static_cast(ElisaUtils::ColumnsRoles::LyricistRole)] = "lyricist"; roles[static_cast(ElisaUtils::ColumnsRoles::ComposerRole)] = "composer"; roles[static_cast(ElisaUtils::ColumnsRoles::CommentRole)] = "comment"; roles[static_cast(ElisaUtils::ColumnsRoles::YearRole)] = "year"; roles[static_cast(ElisaUtils::ColumnsRoles::ChannelsRole)] = "channels"; roles[static_cast(ElisaUtils::ColumnsRoles::BitRateRole)] = "bitRate"; roles[static_cast(ElisaUtils::ColumnsRoles::SampleRateRole)] = "sampleRate"; roles[static_cast(ElisaUtils::ColumnsRoles::ImageRole)] = "image"; roles[static_cast(ElisaUtils::ColumnsRoles::DatabaseIdRole)] = "databaseId"; roles[static_cast(ElisaUtils::ColumnsRoles::IsSingleDiscAlbumRole)] = "isSingleDiscAlbum"; roles[static_cast(ElisaUtils::ColumnsRoles::ContainerDataRole)] = "containerData"; roles[static_cast(ElisaUtils::ColumnsRoles::ResourceRole)] = "trackResource"; roles[static_cast(ElisaUtils::ColumnsRoles::SecondaryTextRole)] = "secondaryText"; roles[static_cast(ElisaUtils::ColumnsRoles::ImageUrlRole)] = "imageUrl"; roles[static_cast(ElisaUtils::ColumnsRoles::ShadowForImageRole)] = "shadowForImage"; return roles; } Qt::ItemFlags AllTracksModel::flags(const QModelIndex &index) const { if (!index.isValid()) { return Qt::NoItemFlags; } return Qt::ItemIsSelectable | Qt::ItemIsEnabled; } QVariant AllTracksModel::data(const QModelIndex &index, int role) const { auto result = QVariant(); const auto tracksCount = d->mAllTracks.size(); Q_ASSERT(index.isValid()); Q_ASSERT(index.column() == 0); Q_ASSERT(index.row() >= 0 && index.row() < tracksCount); Q_ASSERT(!index.parent().isValid()); Q_ASSERT(index.model() == this); Q_ASSERT(index.internalId() == 0); const auto &track = d->mAllTracks[d->mIds[index.row()]]; switch(role) { case ElisaUtils::ColumnsRoles::TitleRole: if (d->mAllTracks[d->mIds[index.row()]].title().isEmpty()) { result = d->mAllTracks[d->mIds[index.row()]].resourceURI().fileName(); } else { result = d->mAllTracks[d->mIds[index.row()]].title(); } break; case ElisaUtils::ColumnsRoles::MilliSecondsDurationRole: result = d->mAllTracks[d->mIds[index.row()]].duration().msecsSinceStartOfDay(); break; case ElisaUtils::ColumnsRoles::DurationRole: { QTime trackDuration = d->mAllTracks[d->mIds[index.row()]].duration(); if (trackDuration.hour() == 0) { result = trackDuration.toString(QStringLiteral("mm:ss")); } else { result = trackDuration.toString(); } break; } case ElisaUtils::ColumnsRoles::ArtistRole: result = d->mAllTracks[d->mIds[index.row()]].artist(); break; case ElisaUtils::ColumnsRoles::AlbumRole: result = d->mAllTracks[d->mIds[index.row()]].albumName(); break; case ElisaUtils::ColumnsRoles::AlbumArtistRole: result = d->mAllTracks[d->mIds[index.row()]].albumArtist(); break; case ElisaUtils::ColumnsRoles::TrackNumberRole: result = d->mAllTracks[d->mIds[index.row()]].trackNumber(); break; case ElisaUtils::ColumnsRoles::DiscNumberRole: result = d->mAllTracks[d->mIds[index.row()]].discNumber(); break; case ElisaUtils::ColumnsRoles::IsSingleDiscAlbumRole: result = d->mAllTracks[d->mIds[index.row()]].isSingleDiscAlbum(); break; case ElisaUtils::ColumnsRoles::RatingRole: result = d->mAllTracks[d->mIds[index.row()]].rating(); break; case ElisaUtils::ColumnsRoles::GenreRole: result = d->mAllTracks[d->mIds[index.row()]].genre(); break; case ElisaUtils::ColumnsRoles::LyricistRole: result = d->mAllTracks[d->mIds[index.row()]].lyricist(); break; case ElisaUtils::ColumnsRoles::ComposerRole: result = d->mAllTracks[d->mIds[index.row()]].composer(); break; case ElisaUtils::ColumnsRoles::CommentRole: result = d->mAllTracks[d->mIds[index.row()]].comment(); break; case ElisaUtils::ColumnsRoles::YearRole: result = d->mAllTracks[d->mIds[index.row()]].year(); break; case ElisaUtils::ColumnsRoles::ChannelsRole: result = d->mAllTracks[d->mIds[index.row()]].channels(); break; case ElisaUtils::ColumnsRoles::BitRateRole: result = d->mAllTracks[d->mIds[index.row()]].bitRate(); break; case ElisaUtils::ColumnsRoles::SampleRateRole: result = d->mAllTracks[d->mIds[index.row()]].sampleRate(); break; case ElisaUtils::ColumnsRoles::ImageRole: { const auto &imageUrl = d->mAllTracks[d->mIds[index.row()]].albumCover(); if (imageUrl.isValid()) { result = imageUrl; } break; } case ElisaUtils::ColumnsRoles::ResourceRole: result = d->mAllTracks[d->mIds[index.row()]].resourceURI(); break; case ElisaUtils::ColumnsRoles::IdRole: result = d->mAllTracks[d->mIds[index.row()]].title(); break; case ElisaUtils::ColumnsRoles::DatabaseIdRole: result = d->mAllTracks[d->mIds[index.row()]].databaseId(); break; case ElisaUtils::ColumnsRoles::ContainerDataRole: result = QVariant::fromValue(d->mAllTracks[d->mIds[index.row()]]); break; case Qt::DisplayRole: result = track.title(); break; case ElisaUtils::ColumnsRoles::SecondaryTextRole: { auto secondaryText = QString(); secondaryText = QStringLiteral("%1 - %2%3"); secondaryText = secondaryText.arg(track.trackNumber()); secondaryText = secondaryText.arg(track.title()); if (track.artist() == track.albumArtist()) { secondaryText = secondaryText.arg(QString()); } else { auto artistText = QString(); artistText = QStringLiteral(" - %1"); artistText = artistText.arg(track.artist()); secondaryText = secondaryText.arg(artistText); } result = secondaryText; break; } case ElisaUtils::ColumnsRoles::ImageUrlRole: { const auto &imageUrl = d->mAllTracks[d->mIds[index.row()]].albumCover(); if (imageUrl.isValid()) { result = imageUrl; } else { result = QUrl(QStringLiteral("image://icon/media-optical-audio")); } break; } case ElisaUtils::ColumnsRoles::ShadowForImageRole: result = d->mAllTracks[d->mIds[index.row()]].albumCover().isValid(); break; } return result; } QModelIndex AllTracksModel::index(int row, int column, const QModelIndex &parent) const { auto result = QModelIndex(); if (column != 0) { return result; } if (parent.isValid()) { return result; } if (row > d->mAllTracks.size() - 1) { return result; } result = createIndex(row, column); return result; } QModelIndex AllTracksModel::parent(const QModelIndex &child) const { Q_UNUSED(child) auto result = QModelIndex(); return result; } int AllTracksModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent); return 1; } void AllTracksModel::tracksAdded(const QList &allTracks) { auto newAllTracks = d->mAllTracks; auto newTracksIds = QList(); int countNewTracks = 0; for (const auto &oneTrack : allTracks) { if (!newAllTracks.contains(oneTrack.databaseId())) { newAllTracks[oneTrack.databaseId()] = oneTrack; newTracksIds.push_back(oneTrack.databaseId()); ++countNewTracks; } } if (countNewTracks > 0) { beginInsertRows({}, d->mAllTracks.size(), d->mAllTracks.size() + countNewTracks - 1); d->mAllTracks = newAllTracks; d->mIds.append(newTracksIds); endInsertRows(); } } void AllTracksModel::trackRemoved(qulonglong removedTrackId) { auto itTrack = std::find(d->mIds.begin(), d->mIds.end(), removedTrackId); if (itTrack == d->mIds.end()) { return; } auto position = itTrack - d->mIds.begin(); beginRemoveRows({}, position, position); d->mIds.erase(itTrack); d->mAllTracks.remove(removedTrackId); endRemoveRows(); } void AllTracksModel::trackModified(const MusicAudioTrack &modifiedTrack) { auto trackExists = (d->mAllTracks.contains(modifiedTrack.databaseId())); if (!trackExists) { return; } auto itTrack = std::find(d->mIds.begin(), d->mIds.end(), modifiedTrack.databaseId()); if (itTrack == d->mIds.end()) { return; } auto position = itTrack - d->mIds.begin(); d->mAllTracks[modifiedTrack.databaseId()] = modifiedTrack; Q_EMIT dataChanged(index(position, 0), index(position, 0)); } #include "moc_alltracksmodel.cpp" diff --git a/src/models/alltracksmodel.h b/src/models/alltracksmodel.h index c17ce169..d314e3c9 100644 --- a/src/models/alltracksmodel.h +++ b/src/models/alltracksmodel.h @@ -1,71 +1,69 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef ALLTRACKSMODEL_H #define ALLTRACKSMODEL_H #include "elisaLib_export.h" #include #include "musicaudiotrack.h" #include class AllTracksModelPrivate; class ELISALIB_EXPORT AllTracksModel : public QAbstractItemModel { Q_OBJECT public: explicit AllTracksModel(QObject *parent = nullptr); ~AllTracksModel() override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; QHash roleNames() const override; Qt::ItemFlags flags(const QModelIndex &index) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; QModelIndex parent(const QModelIndex &child) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; public Q_SLOTS: void tracksAdded(const QList &allTracks); void trackRemoved(qulonglong removedTrackId); void trackModified(const MusicAudioTrack &modifiedTrack); private: std::unique_ptr d; }; #endif // ALLTRACKSMODEL_H diff --git a/src/models/alltracksproxymodel.cpp b/src/models/alltracksproxymodel.cpp index ccc13f95..767b456a 100644 --- a/src/models/alltracksproxymodel.cpp +++ b/src/models/alltracksproxymodel.cpp @@ -1,123 +1,121 @@ /* * Copyright 2017 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "alltracksproxymodel.h" #include "genericdatamodel.h" #include #include AllTracksProxyModel::AllTracksProxyModel(QObject *parent) : AbstractMediaProxyModel(parent) { this->setSortRole(Qt::DisplayRole); this->setSortCaseSensitivity(Qt::CaseInsensitive); this->sortModel(Qt::AscendingOrder); } AllTracksProxyModel::~AllTracksProxyModel() { } bool AllTracksProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { bool result = false; for (int column = 0, columnCount = sourceModel()->columnCount(source_parent); column < columnCount; ++column) { auto currentIndex = sourceModel()->index(source_row, column, source_parent); const auto &genreValue = sourceModel()->data(currentIndex, ElisaUtils::ColumnsRoles::GenreRole); if (!genreFilterText().isNull() && !genreValue.isValid()) { continue; } if (!genreFilterText().isNull() && !genreValue.canConvert()) { continue; } if (!genreFilterText().isNull() && !genreValue.toStringList().contains(genreFilterText())) { continue; } const auto &titleValue = sourceModel()->data(currentIndex, Qt::DisplayRole).toString(); const auto &artistValue = sourceModel()->data(currentIndex, ElisaUtils::ColumnsRoles::ArtistRole).toString(); const auto maximumRatingValue = sourceModel()->data(currentIndex, ElisaUtils::ColumnsRoles::RatingRole).toInt(); if (maximumRatingValue < mFilterRating) { result = false; continue; } if (mFilterExpression.match(titleValue).hasMatch()) { result = true; continue; } if (mFilterExpression.match(artistValue).hasMatch()) { result = true; continue; } if (result) { continue; } if (!result) { break; } } return result; } void AllTracksProxyModel::enqueueToPlayList() { QtConcurrent::run(&mThreadPool, [=] () { QReadLocker locker(&mDataLock); auto allTracks = QList(); allTracks.reserve(rowCount()); for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) { auto currentIndex = index(rowIndex, 0); allTracks.push_back(data(currentIndex, ElisaUtils::ColumnsRoles::ContainerDataRole).value()); } Q_EMIT trackToEnqueue(allTracks, ElisaUtils::AppendPlayList, ElisaUtils::DoNotTriggerPlay); }); } void AllTracksProxyModel::replaceAndPlayOfPlayList() { QtConcurrent::run(&mThreadPool, [=] () { QReadLocker locker(&mDataLock); auto allTracks = QList(); allTracks.reserve(rowCount()); for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) { auto currentIndex = index(rowIndex, 0); allTracks.push_back(data(currentIndex, ElisaUtils::ColumnsRoles::ContainerDataRole).value()); } Q_EMIT trackToEnqueue(allTracks, ElisaUtils::ReplacePlayList, ElisaUtils::TriggerPlay); }); } #include "moc_alltracksproxymodel.cpp" diff --git a/src/models/alltracksproxymodel.h b/src/models/alltracksproxymodel.h index 7f1bcf0e..13378c21 100644 --- a/src/models/alltracksproxymodel.h +++ b/src/models/alltracksproxymodel.h @@ -1,58 +1,56 @@ /* * Copyright 2017 Alexander Stippich * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef ALLTRACKSPROXYMODEL_H #define ALLTRACKSPROXYMODEL_H #include "elisaLib_export.h" #include "abstractmediaproxymodel.h" #include "musicaudiotrack.h" #include "elisautils.h" class ELISALIB_EXPORT AllTracksProxyModel : public AbstractMediaProxyModel { Q_OBJECT public: explicit AllTracksProxyModel(QObject *parent = nullptr); ~AllTracksProxyModel() override; Q_SIGNALS: void trackToEnqueue(QList newTracks, ElisaUtils::PlayListEnqueueMode enqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay); public Q_SLOTS: void enqueueToPlayList(); void replaceAndPlayOfPlayList(); protected: bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; }; #endif // ALLTRACKSPROXYMODEL_H diff --git a/src/models/filebrowsermodel.cpp b/src/models/filebrowsermodel.cpp index 7c1c89f7..c9e89b1c 100644 --- a/src/models/filebrowsermodel.cpp +++ b/src/models/filebrowsermodel.cpp @@ -1,121 +1,119 @@ /* * Copyright 2018 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "filebrowsermodel.h" #include #include #include #include #include FileBrowserModel::FileBrowserModel(QObject *parent) : KDirModel(parent) { QMimeDatabase db; QList mimeList = db.allMimeTypes(); QStringList mimeTypes; mimeTypes << QStringLiteral("inode/directory"); foreach (const QMimeType &mime, mimeList) { if (mime.name().startsWith(QStringLiteral("audio/"))) { mimeTypes << mime.name(); } } dirLister()->setMimeFilter(mimeTypes); } FileBrowserModel::~FileBrowserModel() = default; QString FileBrowserModel::url() const { return dirLister()->url().toString(); } void FileBrowserModel::setUrl(const QString &url) { QString path = QUrl(url).path(); path = QUrl::fromLocalFile(path).toString(); if (dirLister()->url().path() == QUrl(path).path()) { dirLister()->updateDirectory(QUrl(path)); return; } beginResetModel(); dirLister()->openUrl(QUrl(path)); endResetModel(); emit urlChanged(); } QHash FileBrowserModel::roleNames() const { auto roles = KDirModel::roleNames(); roles[static_cast(ColumnsRoles::NameRole)] = "name"; roles[static_cast(ColumnsRoles::ContainerDataRole)] = "containerData"; roles[static_cast(ColumnsRoles::ImageUrlRole)] = "imageUrl"; roles[static_cast(ColumnsRoles::DirectoryRole)] = "directory"; return roles; } QVariant FileBrowserModel::data(const QModelIndex &index, int role) const { auto result = QVariant(); if (role < ColumnsRoles::NameRole) { result = KDirModel::data(index,role); } switch(role) { case ColumnsRoles::NameRole: { KFileItem item = itemForIndex(index); result = item.name(); break; } case ColumnsRoles::ContainerDataRole: { KFileItem item = itemForIndex(index); result = item.url(); break; } case ColumnsRoles::ImageUrlRole: { KFileItem item = itemForIndex(index); if (item.isDir()) { result = QUrl(QStringLiteral("image://icon/folder")); } else { result = QUrl(QStringLiteral("image://icon/audio-x-generic")); } break; } case ColumnsRoles::DirectoryRole: KFileItem item = itemForIndex(index); result = item.isDir(); break; } return result; } #include "moc_filebrowsermodel.cpp" diff --git a/src/models/filebrowsermodel.h b/src/models/filebrowsermodel.h index 270cf4e3..0d561dc8 100644 --- a/src/models/filebrowsermodel.h +++ b/src/models/filebrowsermodel.h @@ -1,63 +1,61 @@ /* * Copyright 2018 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef FILEBROWSERMODEL_H #define FILEBROWSERMODEL_H #include "elisaLib_export.h" #include #include class MusicAudioTrack; class ELISALIB_EXPORT FileBrowserModel : public KDirModel { Q_OBJECT public: enum ColumnsRoles { NameRole = Qt::UserRole + 1, ContainerDataRole = Qt::UserRole + 2, ImageUrlRole = Qt::UserRole + 3, DirectoryRole = Qt::UserRole + 4 }; Q_ENUM(ColumnsRoles) explicit FileBrowserModel(QObject *parent = nullptr); ~FileBrowserModel() override; QString url() const; QHash roleNames() const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; void setUrl(const QString &url); Q_SIGNALS: void urlChanged(); }; #endif //FILEBROWSERMODEL_H diff --git a/src/models/filebrowserproxymodel.cpp b/src/models/filebrowserproxymodel.cpp index 503e86d1..f10cbac8 100644 --- a/src/models/filebrowserproxymodel.cpp +++ b/src/models/filebrowserproxymodel.cpp @@ -1,192 +1,190 @@ /* * Copyright 2016-2017 Matthieu Gallien * Copyright 2018 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "filebrowserproxymodel.h" #include "filebrowsermodel.h" #include #include #include #include #include "elisautils.h" FileBrowserProxyModel::FileBrowserProxyModel(QObject *parent) : KDirSortFilterProxyModel(parent) { setFilterCaseSensitivity(Qt::CaseInsensitive); mThreadPool.setMaxThreadCount(1); mFileModel = std::make_unique(); setSourceModel(mFileModel.get()); setSortFoldersFirst(true); sort(Qt::AscendingOrder); connect(mFileModel.get(), &FileBrowserModel::urlChanged,this, &FileBrowserProxyModel::urlChanged); mTopFolder = QDir::homePath(); openFolder(mTopFolder, true); } FileBrowserProxyModel::~FileBrowserProxyModel() = default; QString FileBrowserProxyModel::filterText() const { return mFilterText; } void FileBrowserProxyModel::setFilterText(const QString &filterText) { QWriteLocker writeLocker(&mDataLock); if (mFilterText == filterText) return; mFilterText = filterText; mFilterExpression.setPattern(mFilterText); mFilterExpression.setPatternOptions(QRegularExpression::CaseInsensitiveOption); mFilterExpression.optimize(); invalidate(); Q_EMIT filterTextChanged(mFilterText); } bool FileBrowserProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { bool result = false; for (int column = 0, columnCount = sourceModel()->columnCount(source_parent); column < columnCount; ++column) { auto currentIndex = sourceModel()->index(source_row, column, source_parent); const auto &nameValue = sourceModel()->data(currentIndex, FileBrowserModel::NameRole).toString(); if (mFilterExpression.match(nameValue).hasMatch()) { result = true; continue; } if (result) { continue; } if (!result) { break; } } return result; } void FileBrowserProxyModel::enqueueToPlayList() { qDebug() << "enqueue"; QtConcurrent::run(&mThreadPool, [=] () { QReadLocker locker(&mDataLock); auto allTrackUrls = QList(); for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) { auto currentIndex = index(rowIndex, 0); if (!data(currentIndex, FileBrowserModel::DirectoryRole).toBool()) { allTrackUrls.push_back(data(currentIndex, FileBrowserModel::ContainerDataRole).toUrl()); } } Q_EMIT filesToEnqueue(allTrackUrls, ElisaUtils::AppendPlayList, ElisaUtils::DoNotTriggerPlay); }); } void FileBrowserProxyModel::replaceAndPlayOfPlayList() { qDebug() << "replace"; QtConcurrent::run(&mThreadPool, [=] () { QReadLocker locker(&mDataLock); auto allTrackUrls = QList(); for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) { auto currentIndex = index(rowIndex, 0); if (!data(currentIndex, FileBrowserModel::DirectoryRole).toBool()) { allTrackUrls.push_back(data(currentIndex, FileBrowserModel::ContainerDataRole).toUrl()); } } Q_EMIT filesToEnqueue(allTrackUrls, ElisaUtils::ReplacePlayList, ElisaUtils::TriggerPlay); }); } QString FileBrowserProxyModel::parentFolder() const { //return to the top folder if parent directory does not exist QDir dir(mFileModel->dirLister()->url().toLocalFile()); if (dir.cdUp()) { return dir.path(); } else { return mTopFolder; } } void FileBrowserProxyModel::openParentFolder() { if (canGoBack()) { QString parent = parentFolder(); mFileModel->setUrl(parent); if (parent == mTopFolder) { Q_EMIT canGoBackChanged(); } } } bool FileBrowserProxyModel::canGoBack() const { return mFileModel->dirLister()->url().toLocalFile() != mTopFolder; } void FileBrowserProxyModel::openFolder(const QString &folder, bool isDisplayRoot) { if (folder.isEmpty()) { return; } mFileModel->setUrl(folder); if (!isDisplayRoot) { Q_EMIT canGoBackChanged(); } } MusicAudioTrack FileBrowserProxyModel::loadMetaDataFromUrl(const QUrl &url) { auto newTrack = mFileScanner.scanOneFile(url, mMimeDb); qDebug() << "loaded metadata " << url << newTrack; return newTrack; } QString FileBrowserProxyModel::url() const { return mFileModel->dirLister()->url().toLocalFile(); } bool FileBrowserProxyModel::sortedAscending() const { return sortOrder() ? false : true; } void FileBrowserProxyModel::sortModel(Qt::SortOrder order) { this->sort(0,order); Q_EMIT sortedAscendingChanged(); } #include "moc_filebrowserproxymodel.cpp" diff --git a/src/models/filebrowserproxymodel.h b/src/models/filebrowserproxymodel.h index e0d2684d..5f1232a3 100644 --- a/src/models/filebrowserproxymodel.h +++ b/src/models/filebrowserproxymodel.h @@ -1,130 +1,128 @@ /* * Copyright 2016-2018 Matthieu Gallien * Copyright 2018 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef FILEBROWSERPROXYMODEL_H #define FILEBROWSERPROXYMODEL_H #include "elisaLib_export.h" #include "filebrowsermodel.h" #include "musicaudiotrack.h" #include "filescanner.h" #include "elisautils.h" #include #include #include #include #include class ELISALIB_EXPORT FileBrowserProxyModel : public KDirSortFilterProxyModel { Q_OBJECT Q_PROPERTY(QString filterText READ filterText WRITE setFilterText NOTIFY filterTextChanged) Q_PROPERTY(bool canGoBack READ canGoBack NOTIFY canGoBackChanged) Q_PROPERTY(QString url READ url NOTIFY urlChanged) Q_PROPERTY(bool sortedAscending READ sortedAscending NOTIFY sortedAscendingChanged) public: explicit FileBrowserProxyModel(QObject *parent = nullptr); ~FileBrowserProxyModel() override; QString filterText() const; QString url() const; bool canGoBack() const; Q_INVOKABLE MusicAudioTrack loadMetaDataFromUrl(const QUrl &url); bool sortedAscending() const; public Q_SLOTS: void enqueueToPlayList(); void replaceAndPlayOfPlayList(); void setFilterText(const QString &filterText); void openParentFolder(); void openFolder(const QString &folder, bool isDisplayRoot = false); void sortModel(Qt::SortOrder order); Q_SIGNALS: void filesToEnqueue(QList newFiles, ElisaUtils::PlayListEnqueueMode enqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay); void urlChanged(); void canGoBackChanged(); void filterTextChanged(const QString &filterText); void sortedAscendingChanged(); protected: bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; private: QString parentFolder() const; QString mTopFolder; FileScanner mFileScanner; QMimeDatabase mMimeDb; QString mFilterText; QRegularExpression mFilterExpression; QReadWriteLock mDataLock; QThreadPool mThreadPool; std::unique_ptr mFileModel; }; #endif // FILEBROWSERPROXYMODEL_H diff --git a/src/models/genericdatamodel.cpp b/src/models/genericdatamodel.cpp index bae8dd7e..eebd24ac 100644 --- a/src/models/genericdatamodel.cpp +++ b/src/models/genericdatamodel.cpp @@ -1,211 +1,209 @@ /* * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "genericdatamodel.h" #include "databaseinterface.h" #include "modeldatacache.h" #include #include #include class GenericDataModelPrivate { public: QHash mDataPositionCache; ModelDataCache *mModelCache = nullptr; DataUtils::DataType mDataType = DataUtils::DataType::UnknownType; bool mIsBusy = true; }; GenericDataModel::GenericDataModel(QObject *parent) : QAbstractListModel(parent), d(std::make_unique()) { } GenericDataModel::~GenericDataModel() = default; int GenericDataModel::rowCount(const QModelIndex &parent) const { auto rowCount = 0; if (parent.isValid()) { return rowCount; } rowCount = d->mModelCache->dataCount(); return rowCount; } QHash GenericDataModel::roleNames() const { auto roles = QAbstractItemModel::roleNames(); roles[static_cast(ElisaUtils::ColumnsRoles::SecondaryTextRole)] = "secondaryText"; roles[static_cast(ElisaUtils::ColumnsRoles::ImageUrlRole)] = "imageUrl"; roles[static_cast(ElisaUtils::ColumnsRoles::ShadowForImageRole)] = "shadowForImage"; roles[static_cast(ElisaUtils::ColumnsRoles::ChildModelRole)] = "childModel"; roles[static_cast(ElisaUtils::ColumnsRoles::IsPartialDataRole)] = "isPartial"; roles[static_cast(ElisaUtils::ColumnsRoles::ContainerDataRole)] = "containerData"; roles[static_cast(ElisaUtils::ColumnsRoles::DatabaseIdRole)] = "databaseId"; return roles; } QVariant GenericDataModel::data(const QModelIndex &index, int role) const { auto result = QVariant(); const auto albumCount = d->mModelCache->dataCount(); if (!index.isValid()) { return result; } if (index.column() != 0) { return result; } if (index.row() < 0) { return result; } if (index.parent().isValid()) { return result; } if (index.row() < 0 || index.row() >= albumCount) { return result; } if (role != Qt::DisplayRole && (role < ElisaUtils::SecondaryTextRole || role > ElisaUtils::IsPartialDataRole)) { return result; } switch(role) { case Qt::DisplayRole: result = d->mModelCache->data(index.row(), ElisaUtils::TitleRole); break; default: result = d->mModelCache->data(index.row(), static_cast(role)); break; }; return result; } QModelIndex GenericDataModel::parent(const QModelIndex &child) const { Q_UNUSED(child) return {}; } int GenericDataModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent) return 1; } DataUtils::DataType GenericDataModel::dataType() const { return d->mDataType; } ModelDataCache *GenericDataModel::modelCache() const { return d->mModelCache; } bool GenericDataModel::isBusy() const { return d->mIsBusy; } void GenericDataModel::setDataType(DataUtils::DataType dataType) { if (d->mDataType == dataType) { return; } resetModelType(); d->mDataType = dataType; Q_EMIT dataTypeChanged(d->mDataType); } void GenericDataModel::setModelCache(ModelDataCache *modelCache) { if (d->mModelCache == modelCache) { return; } d->mModelCache = modelCache; Q_EMIT modelCacheChanged(d->mModelCache); connect(this, &GenericDataModel::neededData, d->mModelCache, &ModelDataCache::neededData); connect(d->mModelCache, &ModelDataCache::receiveData, this, &GenericDataModel::receiveData); connect(this, &GenericDataModel::dataTypeChanged, d->mModelCache, &ModelDataCache::setDataType); connect(d->mModelCache, &ModelDataCache::dataChanged, this, &GenericDataModel::modelDataChanged); } void GenericDataModel::modelDataChanged(int lowerBound, int upperBound) { if (lowerBound == -1 && upperBound == -1) { beginResetModel(); endResetModel(); d->mIsBusy = false; Q_EMIT isBusyChanged(d->mIsBusy); } Q_EMIT dataChanged(index(lowerBound), index(upperBound), {}); } void GenericDataModel::resetModelType() { beginResetModel(); d->mDataPositionCache.clear(); d->mIsBusy = true; Q_EMIT isBusyChanged(d->mIsBusy); endResetModel(); } void GenericDataModel::receiveData(int row) { Q_EMIT dataChanged(index(row), index(row), {}); } #include "moc_genericdatamodel.cpp" diff --git a/src/models/genericdatamodel.h b/src/models/genericdatamodel.h index 8826b57f..87cd2028 100644 --- a/src/models/genericdatamodel.h +++ b/src/models/genericdatamodel.h @@ -1,97 +1,95 @@ /* * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef GENERICDATAMODEL_H #define GENERICDATAMODEL_H #include "elisaLib_export.h" #include "datatype.h" #include #include class GenericDataModelPrivate; class ModelDataCache; class ELISALIB_EXPORT GenericDataModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(DataUtils::DataType dataType READ dataType WRITE setDataType NOTIFY dataTypeChanged) Q_PROPERTY(ModelDataCache* modelCache READ modelCache WRITE setModelCache NOTIFY modelCacheChanged) Q_PROPERTY(bool isBusy READ isBusy NOTIFY isBusyChanged) public: explicit GenericDataModel(QObject *parent = nullptr); ~GenericDataModel() override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; QHash roleNames() const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QModelIndex parent(const QModelIndex &child) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; DataUtils::DataType dataType() const; ModelDataCache *modelCache() const; bool isBusy() const; Q_SIGNALS: void neededData(int row) const; void dataTypeChanged(DataUtils::DataType dataType); void modelCacheChanged(ModelDataCache* modelCache); void isBusyChanged(bool isBusy); public Q_SLOTS: void receiveData(int row); void setDataType(DataUtils::DataType dataType); void setModelCache(ModelDataCache* modelCache); void modelDataChanged(int lowerBound, int upperBound); private: void resetModelType(); std::unique_ptr d; }; #endif // GENERICDATAMODEL_H diff --git a/src/models/singlealbumproxymodel.cpp b/src/models/singlealbumproxymodel.cpp index e971e2cb..16ed4e8a 100644 --- a/src/models/singlealbumproxymodel.cpp +++ b/src/models/singlealbumproxymodel.cpp @@ -1,119 +1,117 @@ /* * Copyright 2017 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "singlealbumproxymodel.h" #include "albummodel.h" #include #include SingleAlbumProxyModel::SingleAlbumProxyModel(QObject *parent) : AbstractMediaProxyModel(parent) { } SingleAlbumProxyModel::~SingleAlbumProxyModel() = default; bool SingleAlbumProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { bool result = false; for (int column = 0, columnCount = sourceModel()->columnCount(source_parent); column < columnCount; ++column) { auto currentIndex = sourceModel()->index(source_row, column, source_parent); const auto &genreValue = sourceModel()->data(currentIndex, ElisaUtils::ColumnsRoles::GenreRole); if (!genreFilterText().isNull() && !genreValue.isValid()) { continue; } if (!genreFilterText().isNull() && !genreValue.canConvert()) { continue; } if (!genreFilterText().isNull() && !genreValue.toStringList().contains(genreFilterText())) { continue; } const auto &titleValue = sourceModel()->data(currentIndex, AlbumModel::TitleRole).toString(); const auto maximumRatingValue = sourceModel()->data(currentIndex, AlbumModel::RatingRole).toInt(); if (maximumRatingValue < mFilterRating) { result = false; continue; } if (mFilterExpression.match(titleValue).hasMatch()) { result = true; continue; } if (result) { continue; } if (!result) { break; } } return result; } void SingleAlbumProxyModel::enqueueToPlayList() { QtConcurrent::run(&mThreadPool, [=] () { QReadLocker locker(&mDataLock); auto allTracks = QList(); allTracks.reserve(rowCount()); for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) { auto currentIndex = index(rowIndex, 0); allTracks.push_back(data(currentIndex, AlbumModel::ContainerDataRole).value()); } Q_EMIT trackToEnqueue(allTracks, ElisaUtils::AppendPlayList, ElisaUtils::DoNotTriggerPlay); }); } void SingleAlbumProxyModel::replaceAndPlayOfPlayList() { QtConcurrent::run(&mThreadPool, [=] () { QReadLocker locker(&mDataLock); auto allTracks = QList(); allTracks.reserve(rowCount()); for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) { auto currentIndex = index(rowIndex, 0); allTracks.push_back(data(currentIndex, AlbumModel::ContainerDataRole).value()); } Q_EMIT trackToEnqueue(allTracks, ElisaUtils::ReplacePlayList, ElisaUtils::TriggerPlay); }); } void SingleAlbumProxyModel::loadAlbumData(qulonglong databaseId) { auto albumSourceModel = qobject_cast(this->sourceModel()); if(albumSourceModel) { albumSourceModel->loadAlbumData(databaseId); } } #include "moc_singlealbumproxymodel.cpp" diff --git a/src/models/singlealbumproxymodel.h b/src/models/singlealbumproxymodel.h index 470849ac..eec076a8 100644 --- a/src/models/singlealbumproxymodel.h +++ b/src/models/singlealbumproxymodel.h @@ -1,61 +1,59 @@ /* * Copyright 2017 Alexander Stippich * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef SINGLEALBUMPROXYMODEL_H #define SINGLEALBUMPROXYMODEL_H #include "elisaLib_export.h" #include "abstractmediaproxymodel.h" #include "musicaudiotrack.h" #include "elisautils.h" #include "albummodel.h" class ELISALIB_EXPORT SingleAlbumProxyModel : public AbstractMediaProxyModel { Q_OBJECT public: explicit SingleAlbumProxyModel(QObject *parent = nullptr); ~SingleAlbumProxyModel() override; Q_SIGNALS: void trackToEnqueue(QList newTracks, ElisaUtils::PlayListEnqueueMode enqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay); public Q_SLOTS: void enqueueToPlayList(); void replaceAndPlayOfPlayList(); void loadAlbumData(qulonglong databaseId); protected: bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; }; #endif // SINGLEALBUMPROXYMODEL_H diff --git a/src/models/singleartistproxymodel.cpp b/src/models/singleartistproxymodel.cpp index 88c08e3c..35c6197a 100644 --- a/src/models/singleartistproxymodel.cpp +++ b/src/models/singleartistproxymodel.cpp @@ -1,143 +1,141 @@ /* * Copyright 2016-2017 Matthieu Gallien * Copyright 2017 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "singleartistproxymodel.h" #include "genericdatamodel.h" #include "musicalbum.h" #include #include SingleArtistProxyModel::SingleArtistProxyModel(QObject *parent) : AbstractMediaProxyModel(parent) { this->setSortRole(ElisaUtils::ColumnsRoles::TitleRole); this->setSortCaseSensitivity(Qt::CaseInsensitive); this->sortModel(Qt::AscendingOrder); } SingleArtistProxyModel::~SingleArtistProxyModel() = default; QString SingleArtistProxyModel::artistFilter() const { return mArtistFilter; } void SingleArtistProxyModel::setArtistFilterText(const QString &filterText) { if (mArtistFilter == filterText) return; mArtistFilter = filterText; mArtistExpression.setPattern(QStringLiteral(".*") + mArtistFilter + QStringLiteral(".*")); mArtistExpression.setPatternOptions(QRegularExpression::CaseInsensitiveOption); mArtistExpression.optimize(); invalidate(); Q_EMIT artistFilterTextChanged(mArtistFilter); } bool SingleArtistProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { bool result = false; for (int column = 0, columnCount = sourceModel()->columnCount(source_parent); column < columnCount; ++column) { auto currentIndex = sourceModel()->index(source_row, column, source_parent); const auto &genreValue = sourceModel()->data(currentIndex, ElisaUtils::ColumnsRoles::GenreRole); if (!genreFilterText().isNull() && !genreValue.isValid()) { continue; } if (!genreFilterText().isNull() && !genreValue.canConvert()) { continue; } if (!genreFilterText().isNull() && !genreValue.toStringList().contains(genreFilterText())) { continue; } const auto &titleValue = sourceModel()->data(currentIndex, ElisaUtils::ColumnsRoles::TitleRole).toString(); const auto &artistValue = sourceModel()->data(currentIndex, ElisaUtils::ColumnsRoles::AllArtistsRole).toString(); const auto maximumRatingValue = sourceModel()->data(currentIndex, ElisaUtils::ColumnsRoles::HighestTrackRating).toInt(); if (maximumRatingValue < mFilterRating) { result = false; continue; } if (mArtistExpression.match(artistValue).hasMatch()) { if (mFilterExpression.match(titleValue).hasMatch()) { result = true; continue; } } if (result) { continue; } if (!result) { break; } } return result; } void SingleArtistProxyModel::enqueueToPlayList() { QtConcurrent::run(&mThreadPool, [=] () { QReadLocker locker(&mDataLock); auto allAlbums = QList(); allAlbums.reserve(rowCount()); for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) { auto currentIndex = index(rowIndex, 0); allAlbums.push_back(data(currentIndex, ElisaUtils::ColumnsRoles::ContainerDataRole). value()); } Q_EMIT albumToEnqueue(allAlbums, ElisaUtils::AppendPlayList, ElisaUtils::DoNotTriggerPlay); }); } void SingleArtistProxyModel::replaceAndPlayOfPlayList() { QtConcurrent::run(&mThreadPool, [=] () { QReadLocker locker(&mDataLock); auto allAlbums = QList(); allAlbums.reserve(rowCount()); for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) { auto currentIndex = index(rowIndex, 0); allAlbums.push_back(data(currentIndex, ElisaUtils::ColumnsRoles::ContainerDataRole). value()); } Q_EMIT albumToEnqueue(allAlbums, ElisaUtils::ReplacePlayList, ElisaUtils::TriggerPlay); }); } #include "moc_singleartistproxymodel.cpp" diff --git a/src/models/singleartistproxymodel.h b/src/models/singleartistproxymodel.h index 06287c2d..b610de86 100644 --- a/src/models/singleartistproxymodel.h +++ b/src/models/singleartistproxymodel.h @@ -1,76 +1,74 @@ /* * Copyright 2016-2018 Matthieu Gallien * Copyright 2017 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef SINGLEARTISTPROXYMODEL_H #define SINGLEARTISTPROXYMODEL_H #include "elisaLib_export.h" #include "abstractmediaproxymodel.h" #include "elisautils.h" class MusicAlbum; class ELISALIB_EXPORT SingleArtistProxyModel : public AbstractMediaProxyModel { Q_OBJECT Q_PROPERTY(QString artistFilter READ artistFilter WRITE setArtistFilterText NOTIFY artistFilterTextChanged) public: explicit SingleArtistProxyModel(QObject *parent = nullptr); ~SingleArtistProxyModel() override; QString artistFilter() const; Q_SIGNALS: void albumToEnqueue(QList newAlbums, ElisaUtils::PlayListEnqueueMode enqueueMode, ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay); public Q_SLOTS: void enqueueToPlayList(); void replaceAndPlayOfPlayList(); void setArtistFilterText(const QString &filterText); Q_SIGNALS: void artistFilterTextChanged(const QString &filterText); protected: bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; QString mArtistFilter; QRegularExpression mArtistExpression; }; #endif // SINGLEARTISTPROXYMODEL_H diff --git a/src/musicalbum.cpp b/src/musicalbum.cpp index 7be2ffa6..055e8201 100644 --- a/src/musicalbum.cpp +++ b/src/musicalbum.cpp @@ -1,391 +1,389 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "musicalbum.h" #include #include #include #include #include #include class MusicAlbumPrivate { public: qulonglong mDatabaseId = 0; QString mId; QString mParentId; QString mTitle; QString mArtist; QUrl mAlbumPath; QUrl mAlbumArtURI; QUrl mResourceURI; QList mTracks; int mTracksCount = 0; bool mIsValid = false; bool mIsSingleDiscAlbum = true; QStringList mGenres; }; MusicAlbum::MusicAlbum() : d(std::make_unique()) { } MusicAlbum::MusicAlbum(MusicAlbum &&other) { d.swap(other.d); } MusicAlbum::MusicAlbum(const MusicAlbum &other) : d(std::make_unique(*other.d)) { } MusicAlbum& MusicAlbum::operator=(MusicAlbum &&other) { if (&other != this) { d.reset(); d.swap(other.d); } return *this; } MusicAlbum& MusicAlbum::operator=(const MusicAlbum &other) { if (&other != this) { (*d) = (*other.d); } return *this; } MusicAlbum::~MusicAlbum() = default; void MusicAlbum::setValid(bool value) { d->mIsValid = value; } bool MusicAlbum::isValid() const { return d->mIsValid; } void MusicAlbum::setDatabaseId(qulonglong value) { d->mDatabaseId = value; } qulonglong MusicAlbum::databaseId() const { return d->mDatabaseId; } void MusicAlbum::setId(const QString &value) { d->mId = value; } QString MusicAlbum::id() const { return d->mId; } void MusicAlbum::setParentId(const QString &value) { d->mParentId = value; } QString MusicAlbum::parentId() const { return d->mParentId; } void MusicAlbum::setTracksCount(int count) { d->mTracksCount = count; } int MusicAlbum::tracksCount() const { return d->mTracks.size(); } void MusicAlbum::setTitle(const QString &value) { d->mTitle = value; } QString MusicAlbum::title() const { return d->mTitle; } void MusicAlbum::setArtist(const QString &value) { d->mArtist = value; } QString MusicAlbum::artist() const { QString result; if (!d->mArtist.isEmpty()) { result = d->mArtist; } else { QString possibleAlbumArtist; for (const auto &oneTrack : qAsConst(d->mTracks)) { if (oneTrack.isValidAlbumArtist()) { result = oneTrack.albumArtist(); break; } if (possibleAlbumArtist.isEmpty()) { possibleAlbumArtist = oneTrack.artist(); } else { if (possibleAlbumArtist != oneTrack.artist()) { possibleAlbumArtist.clear(); break; } } } if (result.isEmpty() && d->mTracks.size() > 1) { if (possibleAlbumArtist.isEmpty()) { result = QStringLiteral("Various Artists"); } else { result = possibleAlbumArtist; } } else if (result.isEmpty() && d->mTracks.size() == 1) { result = d->mTracks.constFirst().albumArtist(); } } return result; } void MusicAlbum::setAlbumArtURI(const QUrl &value) { d->mAlbumArtURI = value; } QUrl MusicAlbum::albumArtURI() const { return d->mAlbumArtURI; } void MusicAlbum::setResourceURI(const QUrl &value) { d->mResourceURI = value; } QUrl MusicAlbum::resourceURI() const { return d->mResourceURI; } void MusicAlbum::setIsSingleDiscAlbum(bool value) { d->mIsSingleDiscAlbum = value; } bool MusicAlbum::isSingleDiscAlbum() const { return d->mIsSingleDiscAlbum; } void MusicAlbum::setGenres(const QStringList &aGenres) { d->mGenres = aGenres; } QStringList MusicAlbum::genres() const { return d->mGenres; } void MusicAlbum::setTracks(const QList &allTracks) { d->mTracks = allTracks; } const MusicAudioTrack& MusicAlbum::trackFromIndex(int index) const { return d->mTracks[index]; } qulonglong MusicAlbum::trackIdFromIndex(int index) const { return d->mTracks[index].databaseId(); } int MusicAlbum::trackIndexFromId(qulonglong id) const { int result = -1; for (result = 0; result < d->mTracks.size(); ++result) { if (d->mTracks[result].databaseId() == id) { return result; } } result = -1; return result; } QStringList MusicAlbum::allArtists() const { auto result = QList(); result.reserve(d->mTracks.size() + 1); result.push_back(d->mArtist); const auto &allTracks = d->mTracks; for (const auto &oneTrack : allTracks) { result.push_back(oneTrack.artist()); } std::sort(result.begin(), result.end()); result.erase(std::unique(result.begin(), result.end()), result.end()); return result; } QStringList MusicAlbum::allTracksTitle() const { auto result = QList(); result.reserve(d->mTracks.size()); const auto &allTracks = d->mTracks; for (const auto &oneTrack : allTracks) { result.push_back(oneTrack.title()); } std::sort(result.begin(), result.end()); result.erase(std::unique(result.begin(), result.end()), result.end()); return result; } bool MusicAlbum::isEmpty() const { return d->mTracks.isEmpty(); } void MusicAlbum::removeTrackFromIndex(int index) { if (index < 0 || index >= tracksCount()) { return; } --d->mTracksCount; d->mTracks.removeAt(index); } void MusicAlbum::insertTrack(const MusicAudioTrack &newTrack, int index) { d->mTracks.insert(index, newTrack); ++d->mTracksCount; } void MusicAlbum::updateTrack(const MusicAudioTrack &modifiedTrack, int index) { d->mTracks[index] = modifiedTrack; } ELISALIB_EXPORT QDebug operator<<(QDebug stream, const MusicAlbum &data) { stream << "title:" << data.title() << "databaseId:" << data.databaseId() << "id:" << data.id() << "parentId:" << data.parentId() << "artist:" << data.artist() << "albumPath:" << data.albumPath() << "albumArtURI:" << data.albumArtURI() << "tracks:" << data.tracksCount() << "isSingleDiscAlbum:" << (data.isSingleDiscAlbum() ? "true": "false") << "isValidArtist:" << (data.isValidArtist() ? "true": "false"); return stream; } ELISALIB_EXPORT bool operator==(const MusicAlbum &album1, const MusicAlbum &album2) { return album1.title() == album2.title() && ( (album1.isValidArtist() && album2.isValidArtist() && album1.artist() == album2.artist()) || !album1.isValidArtist() || !album2.isValidArtist()); } int MusicAlbum::highestTrackRating() const { int result = 0; const auto &allTracks = d->mTracks; for (const auto &oneTrack : allTracks) { result = std::max(result, oneTrack.rating()); } return result; } bool MusicAlbum::isValidArtist() const { return !d->mArtist.isEmpty(); } bool MusicAlbum::canUpdateArtist(const MusicAudioTrack ¤tTrack) const { bool result = false; if (currentTrack.isValidAlbumArtist() && currentTrack.albumArtist() != artist()) { result = true; } return result; } void MusicAlbum::setAlbumPath(const QUrl &value) { d->mAlbumPath = value; } QUrl MusicAlbum::albumPath() const { return d->mAlbumPath; } diff --git a/src/musicalbum.h b/src/musicalbum.h index 68047f78..4a46cf15 100644 --- a/src/musicalbum.h +++ b/src/musicalbum.h @@ -1,141 +1,139 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef MUSICALBUM_H #define MUSICALBUM_H #include "elisaLib_export.h" #include "musicaudiotrack.h" #include #include #include #include #include #include class MusicAlbumPrivate; class QDebug; class ELISALIB_EXPORT MusicAlbum { public: MusicAlbum(); MusicAlbum(MusicAlbum &&other); MusicAlbum(const MusicAlbum &other); MusicAlbum& operator=(MusicAlbum &&other); MusicAlbum& operator=(const MusicAlbum &other); ~MusicAlbum(); void setValid(bool value); bool isValid() const; void setDatabaseId(qulonglong value); qulonglong databaseId() const; void setId(const QString &value); QString id() const; void setParentId(const QString &value); QString parentId() const; void setTracksCount(int count); int tracksCount() const; void setTitle(const QString &value); QString title() const; void setArtist(const QString &value); QString artist() const; bool isValidArtist() const; bool canUpdateArtist(const MusicAudioTrack ¤tTrack) const; void setAlbumPath(const QUrl &value); QUrl albumPath() const; void setAlbumArtURI(const QUrl &value); QUrl albumArtURI() const; void setResourceURI(const QUrl &value); QUrl resourceURI() const; void setIsSingleDiscAlbum(bool value); bool isSingleDiscAlbum() const; void setGenres(const QStringList &aGenres); QStringList genres() const; void setTracks(const QList &allTracks); const MusicAudioTrack &trackFromIndex(int index) const; qulonglong trackIdFromIndex(int index) const; int trackIndexFromId(qulonglong id) const; QStringList allArtists() const; QStringList allTracksTitle() const; bool isEmpty() const; void removeTrackFromIndex(int index); void insertTrack(const MusicAudioTrack &newTrack, int index); void updateTrack(const MusicAudioTrack &modifiedTrack, int index); int highestTrackRating() const; private: std::unique_ptr d; }; ELISALIB_EXPORT QDebug operator<<(QDebug stream, const MusicAlbum &data); ELISALIB_EXPORT bool operator==(const MusicAlbum &album1, const MusicAlbum &album2); Q_DECLARE_METATYPE(MusicAlbum) #endif // MUSICALBUM_H diff --git a/src/musicartist.cpp b/src/musicartist.cpp index a280c15b..13f4f9c1 100644 --- a/src/musicartist.cpp +++ b/src/musicartist.cpp @@ -1,138 +1,136 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "musicartist.h" #include #include #include #include class MusicArtistPrivate { public: QString mName; QStringList mGenres; qulonglong mDatabaseId = 0; int mAlbumsCount = 0; bool mIsValid = false; }; MusicArtist::MusicArtist() : d(std::make_unique()) { } MusicArtist::MusicArtist(MusicArtist &&other) { d.swap(other.d); } MusicArtist::MusicArtist(const MusicArtist &other) : d(std::make_unique(*other.d)) { } MusicArtist& MusicArtist::operator=(MusicArtist &&other) { if (&other != this) { d.reset(); d.swap(other.d); } return *this; } MusicArtist &MusicArtist::operator=(const MusicArtist &other) { if (&other != this) { (*d) = (*other.d); } return *this; } MusicArtist::~MusicArtist() = default; void MusicArtist::setValid(bool value) { d->mIsValid = value; } bool MusicArtist::isValid() const { return d->mIsValid; } void MusicArtist::setName(const QString &aName) { d->mName = aName; } QString MusicArtist::name() const { return d->mName; } void MusicArtist::setGenres(const QStringList &aGenres) { d->mGenres = aGenres; } QStringList MusicArtist::genres() const { return d->mGenres; } void MusicArtist::setDatabaseId(qulonglong value) { d->mDatabaseId = value; } qulonglong MusicArtist::databaseId() const { return d->mDatabaseId; } void MusicArtist::setAlbumsCount(int value) { d->mAlbumsCount = value; } int MusicArtist::albumsCount() const { return d->mAlbumsCount; } QDebug& operator<<(QDebug &stream, const MusicArtist &data) { stream << data.name() << data.genres() << data.databaseId() << data.albumsCount() << (data.isValid() ? "is valid" : "is invalid"); return stream; } bool operator==(const MusicArtist &artist1, const MusicArtist &artist2) { return artist1.name() == artist2.name() && artist1.genres() == artist2.genres() && artist1.albumsCount() == artist2.albumsCount(); } diff --git a/src/musicartist.h b/src/musicartist.h index e3b2ce42..aa0a3ffa 100644 --- a/src/musicartist.h +++ b/src/musicartist.h @@ -1,81 +1,79 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef MUSICARTIST_H #define MUSICARTIST_H #include "elisaLib_export.h" #include #include #include class MusicArtistPrivate; class QDebug; class ELISALIB_EXPORT MusicArtist { public: MusicArtist(); MusicArtist(MusicArtist &&other); MusicArtist(const MusicArtist &other); MusicArtist& operator=(MusicArtist &&other); MusicArtist& operator=(const MusicArtist &other); ~MusicArtist(); void setValid(bool value); bool isValid() const; void setName(const QString &aName); QString name() const; void setGenres(const QStringList &aGenres); QStringList genres() const; void setDatabaseId(qulonglong value); qulonglong databaseId() const; void setAlbumsCount(int value); int albumsCount() const; private: std::unique_ptr d; }; QDebug& operator<<(QDebug &stream, const MusicArtist &data); bool operator==(const MusicArtist &artist1, const MusicArtist &artist2); Q_DECLARE_METATYPE(MusicArtist) #endif // MUSICARTIST_H diff --git a/src/musicaudiogenre.cpp b/src/musicaudiogenre.cpp index 7e68769f..bcf97550 100644 --- a/src/musicaudiogenre.cpp +++ b/src/musicaudiogenre.cpp @@ -1,99 +1,97 @@ /* * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "musicaudiogenre.h" #include class MusicAudioGenrePrivate { public: QString mName; qulonglong mDatabaseId = 0; }; MusicAudioGenre::MusicAudioGenre() : d(std::make_unique()) { } MusicAudioGenre::MusicAudioGenre(MusicAudioGenre &&other) { d.swap(other.d); } MusicAudioGenre::MusicAudioGenre(const MusicAudioGenre &other) : d(std::make_unique(*other.d)) { } MusicAudioGenre& MusicAudioGenre::operator=(MusicAudioGenre &&other) { if (&other != this) { d.reset(); d.swap(other.d); } return *this; } MusicAudioGenre &MusicAudioGenre::operator=(const MusicAudioGenre &other) { if (&other != this) { (*d) = (*other.d); } return *this; } MusicAudioGenre::~MusicAudioGenre() = default; void MusicAudioGenre::setName(const QString &aName) { d->mName = aName; } QString MusicAudioGenre::name() const { return d->mName; } void MusicAudioGenre::setDatabaseId(qulonglong value) { d->mDatabaseId = value; } qulonglong MusicAudioGenre::databaseId() const { return d->mDatabaseId; } QDebug& operator<<(QDebug &stream, const MusicAudioGenre &data) { stream << data.name() << data.databaseId(); return stream; } bool operator==(const MusicAudioGenre &genre1, const MusicAudioGenre &genre2) { return genre1.name() == genre2.name(); } diff --git a/src/musicaudiogenre.h b/src/musicaudiogenre.h index 3f41165f..7de239fb 100644 --- a/src/musicaudiogenre.h +++ b/src/musicaudiogenre.h @@ -1,70 +1,68 @@ /* * Copyright 2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef MUSICAUDIOGENRE_H #define MUSICAUDIOGENRE_H #include "elisaLib_export.h" #include #include #include class MusicAudioGenrePrivate; class QDebug; class ELISALIB_EXPORT MusicAudioGenre { public: MusicAudioGenre(); MusicAudioGenre(MusicAudioGenre &&other); MusicAudioGenre(const MusicAudioGenre &other); MusicAudioGenre& operator=(MusicAudioGenre &&other); MusicAudioGenre& operator=(const MusicAudioGenre &other); ~MusicAudioGenre(); void setName(const QString &aName); QString name() const; void setDatabaseId(qulonglong value); qulonglong databaseId() const; private: std::unique_ptr d; }; QDebug& operator<<(QDebug &stream, const MusicAudioGenre &data); bool operator==(const MusicAudioGenre &genre1, const MusicAudioGenre &genre2); Q_DECLARE_METATYPE(MusicAudioGenre) #endif // MUSICAUDIOGENRE_H diff --git a/src/musicaudiotrack.cpp b/src/musicaudiotrack.cpp index 65eb2cdb..296c34d0 100644 --- a/src/musicaudiotrack.cpp +++ b/src/musicaudiotrack.cpp @@ -1,445 +1,443 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "musicaudiotrack.h" #include #include #include class MusicAudioTrackPrivate { public: MusicAudioTrackPrivate() = default; MusicAudioTrackPrivate(bool aValid, QString aId, QString aParentId, QString aTitle, QString aArtist, QString aAlbumName, QString aAlbumArtist, int aTrackNumber, int aDiscNumber, QTime aDuration, QUrl aResourceURI, QDateTime fileModificationTime, QUrl aAlbumCover, int rating, bool aIsSingleDiscAlbum, QString aGenre, QString aComposer, QString aLyricist) : mId(std::move(aId)), mParentId(std::move(aParentId)), mTitle(std::move(aTitle)), mArtist(std::move(aArtist)), mAlbumName(std::move(aAlbumName)), mAlbumArtist(std::move(aAlbumArtist)), mGenre(std::move(aGenre)), mComposer(std::move(aComposer)), mLyricist(std::move(aLyricist)), mResourceURI(std::move(aResourceURI)), mAlbumCover(std::move(aAlbumCover)), mFileModificationTime(std::move(fileModificationTime)), mDuration(aDuration), mTrackNumber(aTrackNumber), mDiscNumber(aDiscNumber), mRating(rating), mIsValid(aValid), mIsSingleDiscAlbum(aIsSingleDiscAlbum) { } QString mId; QString mParentId; QString mTitle; QString mArtist; QString mAlbumName; QString mAlbumArtist; QString mGenre; QString mComposer; QString mLyricist; QString mComment; QUrl mResourceURI; QUrl mAlbumCover; qulonglong mDatabaseId = 0; qulonglong mAlbumId = 0; QDateTime mFileModificationTime; QTime mDuration; int mTrackNumber = -1; int mDiscNumber = -1; int mChannels = -1; int mBitRate = -1; int mSampleRate = -1; int mYear = 0; int mRating = -1; bool mIsValid = false; bool mIsSingleDiscAlbum = true; }; MusicAudioTrack::MusicAudioTrack() : d(std::make_unique()) { } MusicAudioTrack::MusicAudioTrack(bool aValid, QString aId, QString aParentId, QString aTitle, QString aArtist, QString aAlbumName, QString aAlbumArtist, int aTrackNumber, int aDiscNumber, QTime aDuration, QUrl aResourceURI, const QDateTime &fileModificationTime, QUrl aAlbumCover, int rating, bool aIsSingleDiscAlbum, QString aGenre, QString aComposer, QString aLyricist) : d(std::make_unique(aValid, std::move(aId), std::move(aParentId), std::move(aTitle), std::move(aArtist), std::move(aAlbumName), std::move(aAlbumArtist), aTrackNumber, aDiscNumber, aDuration, std::move(aResourceURI), fileModificationTime, std::move(aAlbumCover), rating, aIsSingleDiscAlbum, std::move(aGenre), std::move(aComposer), std::move(aLyricist))) { } MusicAudioTrack::MusicAudioTrack(MusicAudioTrack &&other) noexcept { d.swap(other.d); } MusicAudioTrack::MusicAudioTrack(const MusicAudioTrack &other) : d(std::make_unique(*other.d)) { } MusicAudioTrack::~MusicAudioTrack() = default; MusicAudioTrack& MusicAudioTrack::operator=(MusicAudioTrack &&other) noexcept { if (this != &other) { d.reset(); d.swap(other.d); } return *this; } MusicAudioTrack& MusicAudioTrack::operator=(const MusicAudioTrack &other) { if (this != &other) { (*d) = (*other.d); } return *this; } bool MusicAudioTrack::operator <(const MusicAudioTrack &other) const { return d->mDiscNumber < other.d->mDiscNumber || (d->mDiscNumber == other.d->mDiscNumber && d->mTrackNumber < other.d->mTrackNumber); } bool MusicAudioTrack::operator ==(const MusicAudioTrack &other) const { return d->mTitle == other.d->mTitle && d->mArtist == other.d->mArtist && d->mAlbumName == other.d->mAlbumName && d->mAlbumArtist == other.d->mAlbumArtist && d->mTrackNumber == other.d->mTrackNumber && d->mDiscNumber == other.d->mDiscNumber && d->mDuration == other.d->mDuration && d->mResourceURI == other.d->mResourceURI && d->mFileModificationTime == other.d->mFileModificationTime && d->mAlbumCover == other.d->mAlbumCover && d->mRating == other.d->mRating && d->mGenre == other.d->mGenre && d->mComposer == other.d->mComposer && d->mLyricist == other.d->mLyricist && d->mComment == other.d->mComment && d->mYear == other.d->mYear && d->mChannels == other.d->mChannels && d->mBitRate == other.d->mBitRate && d->mSampleRate == other.d->mSampleRate; } bool MusicAudioTrack::operator !=(const MusicAudioTrack &other) const { return d->mTitle != other.d->mTitle || d->mArtist != other.d->mArtist || d->mAlbumName != other.d->mAlbumName || d->mAlbumArtist != other.d->mAlbumArtist || d->mTrackNumber != other.d->mTrackNumber || d->mDiscNumber != other.d->mDiscNumber || d->mDuration != other.d->mDuration || d->mResourceURI != other.d->mResourceURI || d->mFileModificationTime != other.d->mFileModificationTime || d->mAlbumCover != other.d->mAlbumCover || d->mRating != other.d->mRating || d->mGenre != other.d->mGenre || d->mComposer != other.d->mComposer || d->mLyricist != other.d->mLyricist || d->mComment != other.d->mComment || d->mYear != other.d->mYear || d->mChannels != other.d->mChannels || d->mBitRate != other.d->mBitRate || d->mSampleRate != other.d->mSampleRate; } void MusicAudioTrack::setValid(bool value) { d->mIsValid = value; } bool MusicAudioTrack::isValid() const { return d->mIsValid; } void MusicAudioTrack::setDatabaseId(qulonglong value) { d->mDatabaseId = value; } qulonglong MusicAudioTrack::databaseId() const { return d->mDatabaseId; } void MusicAudioTrack::setAlbumId(qulonglong value) { d->mAlbumId = value; } qulonglong MusicAudioTrack::albumId() const { return d->mAlbumId; } void MusicAudioTrack::setId(const QString &value) const { d->mId = value; } QString MusicAudioTrack::id() const { return d->mId; } void MusicAudioTrack::setParentId(const QString &value) const { d->mParentId = value; } QString MusicAudioTrack::parentId() const { return d->mParentId; } void MusicAudioTrack::setTitle(const QString &value) const { d->mTitle = value; } QString MusicAudioTrack::title() const { return d->mTitle; } void MusicAudioTrack::setArtist(const QString &value) const { d->mArtist = value; } QString MusicAudioTrack::artist() const { return d->mArtist; } void MusicAudioTrack::setAlbumName(const QString &value) const { d->mAlbumName = value; } QString MusicAudioTrack::albumName() const { return d->mAlbumName; } void MusicAudioTrack::setAlbumArtist(const QString &value) const { d->mAlbumArtist = value; } QString MusicAudioTrack::albumArtist() const { return (d->mAlbumArtist.isEmpty() ? d->mArtist : d->mAlbumArtist); } bool MusicAudioTrack::isValidAlbumArtist() const { return !d->mAlbumArtist.isEmpty(); } void MusicAudioTrack::setAlbumCover(const QUrl &value) const { d->mAlbumCover = value; } QUrl MusicAudioTrack::albumCover() const { return d->mAlbumCover; } void MusicAudioTrack::setGenre(const QString &value) const { d->mGenre = value; } QString MusicAudioTrack::genre() const { return d->mGenre; } void MusicAudioTrack::setComposer(const QString &value) const { d->mComposer = value; } QString MusicAudioTrack::composer() const { return d->mComposer; } void MusicAudioTrack::setLyricist(const QString &value) const { d->mLyricist = value; } QString MusicAudioTrack::lyricist() const { return d->mLyricist; } void MusicAudioTrack::setComment(const QString &value) const { d->mComment = value; } QString MusicAudioTrack::comment() const { return d->mComment; } void MusicAudioTrack::setTrackNumber(int value) { d->mTrackNumber = value; } int MusicAudioTrack::trackNumber() const { return d->mTrackNumber; } void MusicAudioTrack::setDiscNumber(int value) { d->mDiscNumber = value; } int MusicAudioTrack::discNumber() const { return d->mDiscNumber; } void MusicAudioTrack::setYear(int value) { d->mYear = value; } int MusicAudioTrack::year() const { return d->mYear; } void MusicAudioTrack::setChannels(int value) { d->mChannels = value; } int MusicAudioTrack::channels() const { return d->mChannels; } void MusicAudioTrack::setBitRate(int value) { d->mBitRate = value; } int MusicAudioTrack::bitRate() const { return d->mBitRate; } void MusicAudioTrack::setSampleRate(int value) { d->mSampleRate = value; } int MusicAudioTrack::sampleRate() const { return d->mSampleRate; } void MusicAudioTrack::setDuration(QTime value) { d->mDuration = value; } QTime MusicAudioTrack::duration() const { return d->mDuration; } void MusicAudioTrack::setFileModificationTime(const QDateTime &value) { d->mFileModificationTime = value; } const QDateTime &MusicAudioTrack::fileModificationTime() const { return d->mFileModificationTime; } void MusicAudioTrack::setResourceURI(const QUrl &value) { d->mResourceURI = value; } const QUrl &MusicAudioTrack::resourceURI() const { return d->mResourceURI; } void MusicAudioTrack::setRating(int value) const { d->mRating = value; } int MusicAudioTrack::rating() const { return d->mRating; } void MusicAudioTrack::setIsSingleDiscAlbum(bool value) { d->mIsSingleDiscAlbum = value; } bool MusicAudioTrack::isSingleDiscAlbum() const { return d->mIsSingleDiscAlbum; } ELISALIB_EXPORT QDebug operator<<(QDebug stream, const MusicAudioTrack &data) { stream << data.title() << data.artist() << data.albumName() << data.albumArtist() << data.duration() << data.resourceURI(); return stream; } diff --git a/src/musicaudiotrack.h b/src/musicaudiotrack.h index ae6ac17e..97993932 100644 --- a/src/musicaudiotrack.h +++ b/src/musicaudiotrack.h @@ -1,175 +1,173 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef MUSICAUDIOTRACK_H #define MUSICAUDIOTRACK_H #include "elisaLib_export.h" #include #include #include #include #include class MusicAudioTrackPrivate; class QDebug; class ELISALIB_EXPORT MusicAudioTrack { public: MusicAudioTrack(); MusicAudioTrack(bool aValid, QString aId, QString aParentId, QString aTitle, QString aArtist, QString aAlbumName, QString aAlbumArtist, int aTrackNumber, int aDiscNumber, QTime aDuration, QUrl aResourceURI, const QDateTime &fileModificationTime, QUrl aAlbumCover, int rating, bool aIsSingleDiscAlbum, QString aGenre, QString aComposer, QString aLyricist); MusicAudioTrack(MusicAudioTrack &&other) noexcept; MusicAudioTrack(const MusicAudioTrack &other); ~MusicAudioTrack(); MusicAudioTrack& operator=(MusicAudioTrack &&other) noexcept; MusicAudioTrack& operator=(const MusicAudioTrack &other); bool operator <(const MusicAudioTrack &other) const; bool operator ==(const MusicAudioTrack &other) const; bool operator !=(const MusicAudioTrack &other) const; void setValid(bool value); bool isValid() const; void setDatabaseId(qulonglong value); qulonglong databaseId() const; void setAlbumId(qulonglong value); qulonglong albumId() const; void setId(const QString &value) const; QString id() const; void setParentId(const QString &value) const; QString parentId() const; void setTitle(const QString &value) const; QString title() const; void setArtist(const QString &value) const; QString artist() const; void setAlbumName(const QString &value) const; QString albumName() const; void setAlbumArtist(const QString &value) const; QString albumArtist() const; void setGenre(const QString &value) const; QString genre() const; void setComposer(const QString &value) const; QString composer() const; void setLyricist(const QString &value) const; QString lyricist() const; void setComment(const QString &value) const; QString comment() const; bool isValidAlbumArtist() const; void setAlbumCover(const QUrl &value) const; QUrl albumCover() const; void setTrackNumber(int value); int trackNumber() const; void setDiscNumber(int value); int discNumber() const; void setYear(int value); int year() const; void setChannels(int value); int channels() const; void setBitRate(int value); int bitRate() const; void setSampleRate(int value); int sampleRate() const; void setDuration(QTime value); QTime duration() const; void setFileModificationTime(const QDateTime &value); const QDateTime &fileModificationTime() const; void setResourceURI(const QUrl &value); const QUrl& resourceURI() const; void setRating(int value) const; int rating() const; void setIsSingleDiscAlbum(bool value); bool isSingleDiscAlbum() const; private: std::unique_ptr d; }; ELISALIB_EXPORT QDebug operator<<(QDebug stream, const MusicAudioTrack &data); Q_DECLARE_METATYPE(MusicAudioTrack) #endif // MUSICAUDIOTRACK_H diff --git a/src/musiclistenersmanager.cpp b/src/musiclistenersmanager.cpp index 576d60af..1c7356e5 100644 --- a/src/musiclistenersmanager.cpp +++ b/src/musiclistenersmanager.cpp @@ -1,484 +1,482 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "musiclistenersmanager.h" #include "config-upnp-qt.h" #if defined UPNPQT_FOUND && UPNPQT_FOUND #include "upnp/upnplistener.h" #endif #if defined KF5Baloo_FOUND && KF5Baloo_FOUND #include "baloo/baloolistener.h" #endif #include "databaseinterface.h" #include "mediaplaylist.h" #include "file/filelistener.h" #include "file/localfilelisting.h" #include "trackslistener.h" #include "notificationitem.h" #include "elisaapplication.h" #include "elisa_settings.h" #include "models/albummodel.h" #include "models/abstractmediaproxymodel.h" #include "models/allalbumsproxymodel.h" #include "models/allartistsproxymodel.h" #include "models/alltracksproxymodel.h" #include "models/singleartistproxymodel.h" #include "models/singlealbumproxymodel.h" #include "models/allalbumsmodel.h" #include "models/allartistsmodel.h" #include "models/alltracksmodel.h" #include "models/allgenresmodel.h" #include #include #include #include #include #include #include #include #include #include #include #include class MusicListenersManagerPrivate { public: QThread mDatabaseThread; QThread mListenerThread; #if defined UPNPQT_FOUND && UPNPQT_FOUND UpnpListener mUpnpListener; #endif #if defined KF5Baloo_FOUND && KF5Baloo_FOUND std::unique_ptr mBalooListener; #endif std::list> mFileListener; DatabaseInterface mDatabaseInterface; QFileSystemWatcher mConfigFileWatcher; ElisaApplication *mElisaApplication = nullptr; AllAlbumsModel mAllAlbumsModel; AllArtistsModel mAllArtistsModel; AllTracksModel mAllTracksModel; AllGenresModel mAllGenresModel; //GenericDataModel mAllComposersModel; //GenericDataModel mAllLyricistsModel; AlbumModel mAlbumModel; int mImportedTracksCount = 0; int mActiveMusicListenersCount = 0; bool mIndexingRunning = false; bool mIndexerBusy = false; }; MusicListenersManager::MusicListenersManager(QObject *parent) : QObject(parent), d(std::make_unique()) { d->mListenerThread.start(); d->mDatabaseThread.start(); d->mDatabaseInterface.moveToThread(&d->mDatabaseThread); connect(&d->mDatabaseInterface, &DatabaseInterface::requestsInitDone, this, &MusicListenersManager::databaseReady); const auto &localDataPaths = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); auto databaseFileName = QString(); if (!localDataPaths.isEmpty()) { QDir myDataDirectory; myDataDirectory.mkpath(localDataPaths.first()); databaseFileName = localDataPaths.first() + QStringLiteral("/elisaDatabase.db"); } QMetaObject::invokeMethod(&d->mDatabaseInterface, "init", Qt::QueuedConnection, Q_ARG(QString, QStringLiteral("listeners")), Q_ARG(QString, databaseFileName)); connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, &MusicListenersManager::applicationAboutToQuit); connect(Elisa::ElisaConfiguration::self(), &Elisa::ElisaConfiguration::configChanged, this, &MusicListenersManager::configChanged); connect(&d->mConfigFileWatcher, &QFileSystemWatcher::fileChanged, this, &MusicListenersManager::configChanged); auto initialRootPath = Elisa::ElisaConfiguration::rootPath(); if (initialRootPath.isEmpty()) { auto systemMusicPaths = QStandardPaths::standardLocations(QStandardPaths::MusicLocation); for (const auto &musicPath : qAsConst(systemMusicPaths)) { initialRootPath.push_back(musicPath); } Elisa::ElisaConfiguration::setRootPath(initialRootPath); Elisa::ElisaConfiguration::self()->save(); } d->mConfigFileWatcher.addPath(Elisa::ElisaConfiguration::self()->config()->name()); d->mAllAlbumsModel.setAllArtists(&d->mAllArtistsModel); d->mAllArtistsModel.setAllAlbums(&d->mAllAlbumsModel); connect(&d->mDatabaseInterface, &DatabaseInterface::albumsAdded, &d->mAllAlbumsModel, &AllAlbumsModel::albumsAdded); connect(&d->mDatabaseInterface, &DatabaseInterface::albumModified, &d->mAllAlbumsModel, &AllAlbumsModel::albumModified); connect(&d->mDatabaseInterface, &DatabaseInterface::albumRemoved, &d->mAllAlbumsModel, &AllAlbumsModel::albumRemoved); connect(&d->mDatabaseInterface, &DatabaseInterface::artistsAdded, &d->mAllArtistsModel, &AllArtistsModel::artistsAdded); connect(&d->mDatabaseInterface, &DatabaseInterface::artistModified, &d->mAllArtistsModel, &AllArtistsModel::artistModified); connect(&d->mDatabaseInterface, &DatabaseInterface::artistRemoved, &d->mAllArtistsModel, &AllArtistsModel::artistRemoved); connect(&d->mDatabaseInterface, &DatabaseInterface::tracksAdded, &d->mAllTracksModel, &AllTracksModel::tracksAdded); connect(&d->mDatabaseInterface, &DatabaseInterface::trackModified, &d->mAllTracksModel, &AllTracksModel::trackModified); connect(&d->mDatabaseInterface, &DatabaseInterface::trackRemoved, &d->mAllTracksModel, &AllTracksModel::trackRemoved); connect(&d->mDatabaseInterface, &DatabaseInterface::genresAdded, &d->mAllGenresModel, &AllGenresModel::genresAdded); /*connect(&d->mDatabaseInterface, &DatabaseInterface::trackModified, &d->mAllGenresModel, &AllTracksModel::trackModified); connect(&d->mDatabaseInterface, &DatabaseInterface::trackRemoved, &d->mAllGenresModel, &AllTracksModel::trackRemoved);*/ connect(&d->mDatabaseInterface, &DatabaseInterface::albumModified, &d->mAlbumModel, &AlbumModel::albumModified); connect(&d->mDatabaseInterface, &DatabaseInterface::albumRemoved, &d->mAlbumModel, &AlbumModel::albumRemoved); connect(&d->mAlbumModel, &AlbumModel::requestAlbumData, &d->mDatabaseInterface, &DatabaseInterface::getAlbumFromAlbumId); connect(&d->mDatabaseInterface, &DatabaseInterface::sentAlbumData, &d->mAlbumModel, &AlbumModel::setAlbumData); connect(&d->mDatabaseInterface, &DatabaseInterface::tracksAdded, this, &MusicListenersManager::increaseImportedTracksCount); } MusicListenersManager::~MusicListenersManager() = default; DatabaseInterface *MusicListenersManager::viewDatabase() const { return &d->mDatabaseInterface; } void MusicListenersManager::subscribeForTracks(MediaPlayList *client) { auto helper = std::make_unique(&d->mDatabaseInterface); helper->moveToThread(&d->mDatabaseThread); connect(&d->mDatabaseThread, &QThread::finished, helper.get(), &QObject::deleteLater); connect(&d->mDatabaseInterface, &DatabaseInterface::trackRemoved, helper.get(), &TracksListener::trackRemoved); connect(&d->mDatabaseInterface, &DatabaseInterface::tracksAdded, helper.get(), &TracksListener::tracksAdded); connect(&d->mDatabaseInterface, &DatabaseInterface::trackModified, helper.get(), &TracksListener::trackModified); connect(this, &MusicListenersManager::removeTracksInError, &d->mDatabaseInterface, &DatabaseInterface::removeTracksList); connect(helper.get(), &TracksListener::trackHasChanged, client, &MediaPlayList::trackChanged); connect(helper.get(), &TracksListener::trackHasBeenRemoved, client, &MediaPlayList::trackRemoved); connect(helper.get(), &TracksListener::albumAdded, client, &MediaPlayList::albumAdded); connect(client, &MediaPlayList::newTrackByIdInList, helper.get(), &TracksListener::trackByIdInList); connect(client, &MediaPlayList::newTrackByNameInList, helper.get(), &TracksListener::trackByNameInList); connect(client, &MediaPlayList::newTrackByFileNameInList, helper.get(), &TracksListener::trackByFileNameInList); connect(client, &MediaPlayList::newArtistInList, helper.get(), &TracksListener::newArtistInList); helper.release(); } int MusicListenersManager::importedTracksCount() const { return d->mImportedTracksCount; } bool MusicListenersManager::isIndexingRunning() const { return d->mIndexingRunning; } ElisaApplication *MusicListenersManager::elisaApplication() const { return d->mElisaApplication; } QAbstractItemModel *MusicListenersManager::allAlbumsModel() const { return &d->mAllAlbumsModel; } QAbstractItemModel *MusicListenersManager::allArtistsModel() const { return &d->mAllArtistsModel; } QAbstractItemModel *MusicListenersManager::allTracksModel() const { return &d->mAllTracksModel; } QAbstractItemModel *MusicListenersManager::allGenresModel() const { return &d->mAllGenresModel; } QAbstractItemModel *MusicListenersManager::allLyricistsModel() const { return nullptr;/*&d->mAllLyricistsModel;*/ } QAbstractItemModel *MusicListenersManager::allComposersModel() const { return nullptr;/*&d->mAllComposersModel;*/ } QAbstractItemModel *MusicListenersManager::albumModel() const { return &d->mAlbumModel; } bool MusicListenersManager::indexerBusy() const { return d->mIndexerBusy; } void MusicListenersManager::databaseReady() { d->mIndexerBusy = true; Q_EMIT indexerBusyChanged(); configChanged(); } void MusicListenersManager::applicationAboutToQuit() { d->mDatabaseInterface.applicationAboutToQuit(); Q_EMIT applicationIsTerminating(); d->mDatabaseThread.exit(); d->mDatabaseThread.wait(); d->mListenerThread.exit(); d->mListenerThread.wait(); } void MusicListenersManager::showConfiguration() { auto configureAction = d->mElisaApplication->action(QStringLiteral("options_configure")); configureAction->trigger(); } void MusicListenersManager::setElisaApplication(ElisaApplication *elisaApplication) { if (d->mElisaApplication == elisaApplication) { return; } d->mElisaApplication = elisaApplication; emit elisaApplicationChanged(); } void MusicListenersManager::playBackError(QUrl sourceInError, QMediaPlayer::Error playerError) { qDebug() << "MusicListenersManager::playBackError" << sourceInError; if (playerError == QMediaPlayer::ResourceError) { Q_EMIT removeTracksInError({sourceInError}); if (sourceInError.isLocalFile()) { Q_EMIT displayTrackError(sourceInError.toLocalFile()); } else { Q_EMIT displayTrackError(sourceInError.toString()); } } } void MusicListenersManager::configChanged() { auto currentConfiguration = Elisa::ElisaConfiguration::self(); d->mConfigFileWatcher.addPath(currentConfiguration->config()->name()); currentConfiguration->load(); #if defined KF5Baloo_FOUND && KF5Baloo_FOUND if (currentConfiguration->balooIndexer() && !d->mBalooListener) { d->mBalooListener = std::make_unique(); d->mBalooListener->moveToThread(&d->mListenerThread); d->mBalooListener->setDatabaseInterface(&d->mDatabaseInterface); connect(this, &MusicListenersManager::applicationIsTerminating, d->mBalooListener.get(), &BalooListener::applicationAboutToQuit, Qt::DirectConnection); connect(d->mBalooListener.get(), &BalooListener::indexingStarted, this, &MusicListenersManager::monitorStartingListeners); connect(d->mBalooListener.get(), &BalooListener::indexingFinished, this, &MusicListenersManager::monitorEndingListeners); connect(d->mBalooListener.get(), &BalooListener::clearDatabase, &d->mDatabaseInterface, &DatabaseInterface::removeAllTracksFromSource); connect(d->mBalooListener.get(), &BalooListener::newNotification, this, &MusicListenersManager::newNotification); connect(d->mBalooListener.get(), &BalooListener::closeNotification, this, &MusicListenersManager::closeNotification); } else if (!currentConfiguration->balooIndexer() && d->mBalooListener) { QMetaObject::invokeMethod(d->mBalooListener.get(), "quitListener", Qt::QueuedConnection); d->mBalooListener.reset(); } #endif #if defined UPNPQT_FOUND && UPNPQT_FOUND d->mUpnpListener.setDatabaseInterface(&d->mDatabaseInterface); d->mUpnpListener.moveToThread(&d->mDatabaseThread); connect(this, &MusicListenersManager::applicationIsTerminating, &d->mUpnpListener, &UpnpListener::applicationAboutToQuit, Qt::DirectConnection); #endif if (currentConfiguration->elisaFilesIndexer()) { const auto &allRootPaths = currentConfiguration->rootPath(); for (auto itFileListener = d->mFileListener.begin(); itFileListener != d->mFileListener.end(); ) { const auto ¤tRootPath = (*itFileListener)->localFileIndexer().rootPath(); auto itPath = std::find(allRootPaths.begin(), allRootPaths.end(), currentRootPath); if (itPath == allRootPaths.end()) { d->mDatabaseInterface.removeAllTracksFromSource((*itFileListener)->fileListing()->sourceName()); itFileListener = d->mFileListener.erase(itFileListener); } else { ++itFileListener; } } for (const auto &oneRootPath : allRootPaths) { auto itPath = std::find_if(d->mFileListener.begin(), d->mFileListener.end(), [&oneRootPath](const auto &value)->bool {return value->localFileIndexer().rootPath() == oneRootPath;}); if (itPath == d->mFileListener.end()) { auto newFileIndexer = std::make_unique(); newFileIndexer->setDatabaseInterface(&d->mDatabaseInterface); newFileIndexer->moveToThread(&d->mListenerThread); connect(this, &MusicListenersManager::applicationIsTerminating, newFileIndexer.get(), &FileListener::applicationAboutToQuit, Qt::DirectConnection); connect(newFileIndexer.get(), &FileListener::indexingStarted, this, &MusicListenersManager::monitorStartingListeners); connect(newFileIndexer.get(), &FileListener::indexingFinished, this, &MusicListenersManager::monitorEndingListeners); connect(newFileIndexer.get(), &FileListener::newNotification, this, &MusicListenersManager::newNotification); connect(newFileIndexer.get(), &FileListener::closeNotification, this, &MusicListenersManager::closeNotification); newFileIndexer->setRootPath(oneRootPath); d->mFileListener.emplace_back(std::move(newFileIndexer)); } } } } void MusicListenersManager::increaseImportedTracksCount(const QList &allTracks) { d->mImportedTracksCount += allTracks.size(); if (d->mImportedTracksCount && d->mIndexerBusy) { d->mIndexerBusy = false; Q_EMIT indexerBusyChanged(); } if (d->mImportedTracksCount >= 4) { Q_EMIT closeNotification(QStringLiteral("notEnoughTracks")); } Q_EMIT importedTracksCountChanged(); } void MusicListenersManager::decreaseImportedTracksCount() { --d->mImportedTracksCount; Q_EMIT importedTracksCountChanged(); } void MusicListenersManager::monitorStartingListeners() { if (d->mActiveMusicListenersCount == 0) { d->mIndexingRunning = true; Q_EMIT indexingRunningChanged(); } ++d->mActiveMusicListenersCount; } void MusicListenersManager::monitorEndingListeners() { --d->mActiveMusicListenersCount; if (d->mActiveMusicListenersCount == 0) { if (d->mImportedTracksCount < 4 && d->mElisaApplication) { NotificationItem notEnoughTracks; notEnoughTracks.setNotificationId(QStringLiteral("notEnoughTracks")); notEnoughTracks.setTargetObject(this); notEnoughTracks.setMessage(i18nc("No track found message", "No track have been found")); auto configureAction = d->mElisaApplication->action(QStringLiteral("options_configure")); notEnoughTracks.setMainButtonText(configureAction->text()); notEnoughTracks.setMainButtonIconName(configureAction->icon().name()); notEnoughTracks.setMainButtonMethodName(QStringLiteral("showConfiguration")); Q_EMIT newNotification(notEnoughTracks); } d->mIndexingRunning = false; Q_EMIT indexingRunningChanged(); //QMetaObject::invokeMethod(&d->mDatabaseInterface, "cleanInvalidTracks", Qt::QueuedConnection); } } #include "moc_musiclistenersmanager.cpp" diff --git a/src/musiclistenersmanager.h b/src/musiclistenersmanager.h index 96d2b242..fd236c8f 100644 --- a/src/musiclistenersmanager.h +++ b/src/musiclistenersmanager.h @@ -1,183 +1,181 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef MUSICLISTENERSMANAGER_H #define MUSICLISTENERSMANAGER_H #include "elisaLib_export.h" #include "notificationitem.h" #include #include #include "musicalbum.h" #include "musicartist.h" #include "musicaudiotrack.h" #include class MusicListenersManagerPrivate; class DatabaseInterface; class MediaPlayList; class NotificationItem; class ElisaApplication; class QAbstractItemModel; class AbstractMediaProxyModel; class ELISALIB_EXPORT MusicListenersManager : public QObject { Q_OBJECT Q_PROPERTY(DatabaseInterface* viewDatabase READ viewDatabase NOTIFY viewDatabaseChanged) Q_PROPERTY(int importedTracksCount READ importedTracksCount NOTIFY importedTracksCountChanged) Q_PROPERTY(bool indexingRunning READ isIndexingRunning NOTIFY indexingRunningChanged) Q_PROPERTY(ElisaApplication* elisaApplication READ elisaApplication WRITE setElisaApplication NOTIFY elisaApplicationChanged) Q_PROPERTY(QAbstractItemModel* allAlbumsModel READ allAlbumsModel CONSTANT) Q_PROPERTY(QAbstractItemModel* allArtistsModel READ allArtistsModel CONSTANT) Q_PROPERTY(QAbstractItemModel* allTracksModel READ allTracksModel CONSTANT) Q_PROPERTY(QAbstractItemModel* allGenresModel READ allGenresModel CONSTANT) Q_PROPERTY(QAbstractItemModel* allLyricistsModel READ allLyricistsModel CONSTANT) Q_PROPERTY(QAbstractItemModel* allComposersModel READ allComposersModel CONSTANT) Q_PROPERTY(QAbstractItemModel* albumModel READ albumModel CONSTANT) Q_PROPERTY(bool indexerBusy READ indexerBusy NOTIFY indexerBusyChanged) public: explicit MusicListenersManager(QObject *parent = nullptr); ~MusicListenersManager() override; DatabaseInterface* viewDatabase() const; void subscribeForTracks(MediaPlayList *client); int importedTracksCount() const; bool isIndexingRunning() const; ElisaApplication* elisaApplication() const; QAbstractItemModel *allAlbumsModel() const; QAbstractItemModel *allArtistsModel() const; QAbstractItemModel *allTracksModel() const; QAbstractItemModel *allGenresModel() const; QAbstractItemModel *allLyricistsModel() const; QAbstractItemModel *allComposersModel() const; QAbstractItemModel *albumModel() const; bool indexerBusy() const; Q_SIGNALS: void viewDatabaseChanged(); void applicationIsTerminating(); void importedTracksCountChanged(); void indexingRunningChanged(); void newNotification(NotificationItem notification); void closeNotification(QString notificationId); void elisaApplicationChanged(); void removeTracksInError(QList tracks); void displayTrackError(const QString &fileName); void indexerBusyChanged(); public Q_SLOTS: void databaseReady(); void applicationAboutToQuit(); void showConfiguration(); void setElisaApplication(ElisaApplication* elisaApplication); void playBackError(QUrl sourceInError, QMediaPlayer::Error playerError); private Q_SLOTS: void configChanged(); void increaseImportedTracksCount(const QList &allTracks); void decreaseImportedTracksCount(); void monitorStartingListeners(); void monitorEndingListeners(); private: std::unique_ptr d; }; #endif // MUSICLISTENERSMANAGER_H diff --git a/src/notificationitem.cpp b/src/notificationitem.cpp index 7c46c30e..0557c34c 100644 --- a/src/notificationitem.cpp +++ b/src/notificationitem.cpp @@ -1,187 +1,185 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "notificationitem.h" #include class NotificationItemPrivate { public: QString mNotificationId; QString mMessage; QString mMainButtonText; QString mMainButtonIconName; QString mSecondaryButtonText; QString mSecondaryButtonIconName; QObject *mTarget = nullptr; QString mMainButtonMethodName; QString mSecondaryButtonMethodName; }; NotificationItem::NotificationItem() : d(std::make_unique()) { } NotificationItem::NotificationItem(const NotificationItem &other) : d(std::make_unique(*other.d)) { } NotificationItem::NotificationItem(NotificationItem &&other) { other.d.swap(d); } NotificationItem& NotificationItem::operator=(const NotificationItem &other) { if (&other != this) { *d = *(other.d); } return *this; } NotificationItem::~NotificationItem() = default; const QString& NotificationItem::notificationId() const { return d->mNotificationId; } const QString& NotificationItem::message() const { return d->mMessage; } const QString& NotificationItem::mainButtonText() const { return d->mMainButtonText; } const QString& NotificationItem::secondaryButtonText() const { return d->mSecondaryButtonText; } const QString& NotificationItem::secondaryButtonIconName() const { return d->mSecondaryButtonIconName; } void NotificationItem::setNotificationId(QString notificationId) { if (d->mNotificationId == notificationId) { return; } d->mNotificationId = std::move(notificationId); } const QString& NotificationItem::mainButtonIconName() const { return d->mMainButtonIconName; } void NotificationItem::setMessage(QString message) { if (d->mMessage == message) { return; } d->mMessage = std::move(message); } void NotificationItem::setMainButtonText(QString mainButtonText) { if (d->mMainButtonText == mainButtonText) { return; } d->mMainButtonText = std::move(mainButtonText); } void NotificationItem::setSecondaryButtonText(QString secondaryButtonText) { if (d->mSecondaryButtonText == secondaryButtonText) { return; } d->mSecondaryButtonText = std::move(secondaryButtonText); } void NotificationItem::setSecondaryButtonIconName(QString secondaryButtonIconName) { if (d->mSecondaryButtonIconName == secondaryButtonIconName) { return; } d->mSecondaryButtonIconName = std::move(secondaryButtonIconName); } void NotificationItem::setTargetObject(QObject *target) { d->mTarget = target; } void NotificationItem::setMainButtonMethodName(QString methodName) { d->mMainButtonMethodName = std::move(methodName); } void NotificationItem::setSecondaryButtonMethodName(QString methodName) { d->mSecondaryButtonMethodName = std::move(methodName); } void NotificationItem::triggerMainButton() const { if (!d->mTarget) { return; } QMetaObject::invokeMethod(d->mTarget, d->mMainButtonMethodName.toLatin1().data(), Qt::QueuedConnection); } void NotificationItem::triggerSecondaryButton() const { if (!d->mTarget) { return; } QMetaObject::invokeMethod(d->mTarget, d->mSecondaryButtonMethodName.toLatin1().data(), Qt::QueuedConnection); } void NotificationItem::setMainButtonIconName(QString mainButtonIconName) { if (d->mMainButtonIconName == mainButtonIconName) { return; } d->mMainButtonIconName = std::move(mainButtonIconName); } diff --git a/src/notificationitem.h b/src/notificationitem.h index b7fcd1c4..12164f87 100644 --- a/src/notificationitem.h +++ b/src/notificationitem.h @@ -1,89 +1,87 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef NOTIFICATIONITEM_H #define NOTIFICATIONITEM_H #include "elisaLib_export.h" #include #include class NotificationItemPrivate; class QObject; class ELISALIB_EXPORT NotificationItem { public: NotificationItem(); NotificationItem(const NotificationItem &other); NotificationItem(NotificationItem &&other); NotificationItem& operator=(const NotificationItem &other); NotificationItem& operator=(NotificationItem &&other); ~NotificationItem(); const QString& notificationId() const; const QString& message() const; const QString& mainButtonText() const; const QString& mainButtonIconName() const; const QString& secondaryButtonText() const; const QString& secondaryButtonIconName() const; void setNotificationId(QString notificationId); void setMessage(QString message); void setMainButtonText(QString mainButtonText); void setMainButtonIconName(QString mainButtonIconName); void setSecondaryButtonText(QString secondaryButtonText); void setSecondaryButtonIconName(QString secondaryButtonIconName); void setTargetObject(QObject *target); void setMainButtonMethodName(QString methodName); void setSecondaryButtonMethodName(QString methodName); void triggerMainButton() const; void triggerSecondaryButton() const; private: std::unique_ptr d; }; #endif // NOTIFICATIONITEM_H diff --git a/src/progressindicator.cpp b/src/progressindicator.cpp index 54293d7a..6024ed13 100644 --- a/src/progressindicator.cpp +++ b/src/progressindicator.cpp @@ -1,60 +1,58 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "progressindicator.h" #include ProgressIndicator::ProgressIndicator(QObject *parent) : QObject(parent) { } ProgressIndicator::~ProgressIndicator() = default; int ProgressIndicator::position() const { return mPosition; } QString ProgressIndicator::progressDuration() const { return mProgressDuration; } void ProgressIndicator::setPosition(int position) { if (mPosition == position) return; mPosition = position; QTime currentProgress = QTime::fromMSecsSinceStartOfDay(mPosition); if (currentProgress.hour() == 0) { mProgressDuration = currentProgress.toString(QStringLiteral("m:ss")); } else { mProgressDuration = currentProgress.toString(QStringLiteral("h:mm:ss")); } Q_EMIT positionChanged(); Q_EMIT progressDurationChanged(); } #include "moc_progressindicator.cpp" diff --git a/src/progressindicator.h b/src/progressindicator.h index f0089b7f..60ea94dd 100644 --- a/src/progressindicator.h +++ b/src/progressindicator.h @@ -1,69 +1,67 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef PROGRESSINDICATOR_H #define PROGRESSINDICATOR_H #include "elisaLib_export.h" #include class ELISALIB_EXPORT ProgressIndicator : public QObject { Q_OBJECT Q_PROPERTY(int position READ position WRITE setPosition NOTIFY positionChanged) Q_PROPERTY(QString progressDuration READ progressDuration NOTIFY progressDurationChanged) public: explicit ProgressIndicator(QObject *parent = nullptr); ~ProgressIndicator() override; int position() const; QString progressDuration() const; Q_SIGNALS: void positionChanged(); void progressDurationChanged(); public Q_SLOTS: void setPosition(int position); private: int mPosition = 0; QString mProgressDuration; }; #endif // PROGRESSINDICATOR_H diff --git a/src/qml/ApplicationMenu.qml b/src/qml/ApplicationMenu.qml index 542dbbed..7a4f39a3 100644 --- a/src/qml/ApplicationMenu.qml +++ b/src/qml/ApplicationMenu.qml @@ -1,105 +1,103 @@ /* * Copyright 2016-2018 Matthieu Gallien * Copyright 2018 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ import QtQuick 2.7 //explore menu from Qt 5.10 once we can require it, but it is item-based import QtQuick.Controls 1.4 import org.kde.elisa 1.0 Menu { id: applicationMenu title: i18nc("open application menu", "Application Menu") property var helpAction: elisa.action("help_contents") property var quitApplication: elisa.action("file_quit") property var reportBugAction: elisa.action("help_report_bug") property var aboutAppAction: elisa.action("help_about_app") property var configureShortcutsAction: elisa.action("options_configure_keybinding") property var configureAction: elisa.action("options_configure") property var togglePlaylistAction: elisa.action("toggle_playlist") MenuItem { text: configureAction.text shortcut: configureAction.shortcut iconName: elisa.iconName(configureAction.icon) onTriggered: configureAction.trigger() visible: configureAction.text !== "" } MenuItem { text: configureShortcutsAction.text shortcut: configureShortcutsAction.shortcut iconName: elisa.iconName(configureShortcutsAction.icon) onTriggered: configureShortcutsAction.trigger() visible: configureShortcutsAction.text !== "" } MenuItem { shortcut: togglePlaylistAction.shortcut text: contentView.showPlaylist ? i18nc("Hide playlist", "Hide Playlist") : i18nc("Show playlist", "Show Playlist") iconName: "view-media-playlist" onTriggered: contentView.showPlaylist = !contentView.showPlaylist enabled: contentView.currentViewIndex != 0 } MenuSeparator { visible: reportBugAction.text !== "" } MenuItem { text: reportBugAction.text shortcut: reportBugAction.shortcut iconName: elisa.iconName(reportBugAction.icon) onTriggered: reportBugAction.trigger() visible: reportBugAction.text !== "" } MenuSeparator { visible: helpAction.text !== "" } MenuItem { text: helpAction.text shortcut: helpAction.shortcut iconName: elisa.iconName(helpAction.icon) onTriggered: helpAction.trigger() visible: helpAction.text !== "" } MenuItem { text: aboutAppAction.text shortcut: aboutAppAction.shortcut iconName: elisa.iconName(aboutAppAction.icon) onTriggered: aboutAppAction.trigger() visible: aboutAppAction.text !== "" } MenuSeparator { visible: quitApplication.text !== "" } MenuItem { text: quitApplication.text shortcut: quitApplication.shortcut iconName: elisa.iconName(quitApplication.icon) onTriggered: quitApplication.trigger() visible: quitApplication.text !== "" } } diff --git a/src/qml/BaseTheme.qml b/src/qml/BaseTheme.qml index 81d647b0..0c8287bd 100644 --- a/src/qml/BaseTheme.qml +++ b/src/qml/BaseTheme.qml @@ -1,122 +1,120 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.2 Item { function dp(pixel) { // 96 - common, "base" DPI value return Math.round(pixel * logicalDpi / 96); } property string defaultAlbumImage: 'image://icon/media-optical-audio' property string defaultArtistImage: 'image://icon/view-media-artist' property string defaultBackgroundImage: 'qrc:///background.png' property string artistIcon: 'image://icon/view-media-artist' property string albumIcon: 'image://icon/view-media-album-cover' property string playlistIcon: 'image://icon/view-media-playlist' property string tracksIcon: 'image://icon/view-media-track' property string genresIcon: 'image://icon/view-media-genre' property string clearIcon: 'image://icon/edit-clear' property string skipBackwardIcon: 'image://icon/media-skip-backward' property string pauseIcon: 'image://icon/media-playback-pause' property string playIcon: 'image://icon/media-playback-start' property string skipForwardIcon: 'image://icon/media-skip-forward' property string pausedIndicatorIcon: 'image://icon/media-playback-paused' property string playingIndicatorIcon: 'image://icon/media-playback-playing' property string playerVolumeMutedIcon: 'image://icon/player-volume-muted' property string playerVolumeIcon: 'image://icon/player-volume' property string ratingIcon: 'image://icon/rating' property string ratingUnratedIcon: 'image://icon/rating-unrated' property string errorIcon: 'image://icon/error' property string repeatIcon: 'image://icon/media-repeat-all' property string shuffleIcon: 'image://icon/media-playlist-shuffle' property string noRepeatIcon: 'image://icon/media-repeat-none' property string noShuffleIcon: 'image://icon/media-playlist-normal' property string folderIcon: 'image://icon/document-open-folder' property string maximizeIcon: 'image://icon/draw-arrow-down' property string minimizeIcon: 'image://icon/draw-arrow-up' property int layoutHorizontalMargin: dp(8) property int layoutVerticalMargin: dp(6) property int delegateHeight: dp(28) FontMetrics { id: playListAuthorTextHeight font.weight: Font.Light } FontMetrics { id: playListAlbumTextHeight font.weight: Font.Bold font.pointSize: elisaTheme.defaultFontPointSize * 1.4 } FontMetrics { id: playListTrackTextHeight font.weight: Font.Bold } property int playListDelegateHeight: (playListTrackTextHeight.height > dp(28)) ? playListTrackTextHeight.height : dp(28) property int playListDelegateWithHeaderHeight: playListDelegateHeight + elisaTheme.layoutVerticalMargin * 5 + playListAuthorTextHeight.height + playListAlbumTextHeight.height property int trackDelegateHeight: dp(45) property int coverImageSize: dp(180) property int smallImageSize: dp(32) property int maximumMetadataWidth: dp(300) property int tooltipRadius: dp(3) property int shadowOffset: dp(2) property int delegateToolButtonSize: dp(34) property int smallDelegateToolButtonSize: dp(20) property int ratingStarSize: dp(15) property int mediaPlayerControlHeight: dp(42) property int mediaPlayerHorizontalMargin: dp(10) property real mediaPlayerControlOpacity: 0.6 property int smallControlButtonSize: dp(22) property int volumeSliderWidth: dp(100) property int dragDropPlaceholderHeight: dp(28) property int navigationBarHeight: dp(100) property int navigationBarFilterHeight: dp(44) property int gridDelegateHeight: dp(100) + layoutVerticalMargin + fontSize.height * 2 property int gridDelegateWidth: dp(100) property int viewSelectorDelegateHeight: dp(24) property int filterClearButtonMargin: layoutVerticalMargin property alias defaultFontPointSize: fontSize.font.pointSize Label { id: fontSize } } diff --git a/src/qml/ContentView.qml b/src/qml/ContentView.qml index 89611bcf..577459a2 100644 --- a/src/qml/ContentView.qml +++ b/src/qml/ContentView.qml @@ -1,851 +1,849 @@ /* * Copyright 2016-2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.2 import QtQuick.Layouts 1.2 import QtQuick.Window 2.2 import org.kde.elisa 1.0 RowLayout { id: contentViewContainer spacing: 0 property bool showPlaylist property alias currentViewIndex: listViews.currentIndex signal toggleSearch() function goBack() { viewManager.goBack() } ViewManager { id: viewManager onSwitchAllAlbumsView: { elisa.allAlbumsProxyModel.genreFilterText = '' listViews.currentIndex = 1 localArtistsLoader.opacity = 0 localTracksLoader.opacity = 0 localAlbumsLoader.opacity = 1 localGenresLoader.opacity = 0 localFilesLoader.opacity = 0 } onSwitchOneAlbumView: { elisa.singleAlbumProxyModel.loadAlbumData(databaseId) currentStackView.push(albumView, { mainTitle: mainTitle, secondaryTitle: secondaryTitle, image: imageUrl, stackView: currentStackView, }) oneAlbumViewIsLoaded() } onSwitchAllArtistsView: { elisa.allArtistsProxyModel.genreFilterText = '' listViews.currentIndex = 2 localArtistsLoader.opacity = 1 localTracksLoader.opacity = 0 localAlbumsLoader.opacity = 0 localGenresLoader.opacity = 0 localFilesLoader.opacity = 0 } onSwitchOneArtistView: { elisa.singleArtistProxyModel.setArtistFilterText(mainTitle) elisa.singleArtistProxyModel.genreFilterText = '' currentStackView.push(innerAlbumView, { mainTitle: mainTitle, secondaryTitle: secondaryTitle, image: imageUrl, stackView: currentStackView, }) oneArtistViewIsLoaded() } onSwitchOneArtistFromGenreView: { elisa.singleArtistProxyModel.setArtistFilterText(mainTitle) elisa.singleArtistProxyModel.genreFilterText = genreName currentStackView.push(innerAlbumView, { mainTitle: mainTitle, secondaryTitle: secondaryTitle, image: imageUrl, stackView: currentStackView, }) oneArtistViewIsLoaded() } onSwitchAllTracksView: { elisa.allTracksProxyModel.genreFilterText = '' listViews.currentIndex = 3 localArtistsLoader.opacity = 0 localTracksLoader.opacity = 1 localAlbumsLoader.opacity = 0 localGenresLoader.opacity = 0 localFilesLoader.opacity = 0 } onSwitchAllGenresView: { listViews.currentIndex = 4 localArtistsLoader.opacity = 0 localTracksLoader.opacity = 0 localAlbumsLoader.opacity = 0 localGenresLoader.opacity = 1 localFilesLoader.opacity = 0 } onSwitchFilesBrowserView: { listViews.currentIndex = 5 localArtistsLoader.opacity = 0 localTracksLoader.opacity = 0 localAlbumsLoader.opacity = 0 localGenresLoader.opacity = 0 localFilesLoader.opacity = 1 } onSwitchAllArtistsFromGenreView: { elisa.allArtistsProxyModel.genreFilterText = genreName currentStackView.push(innerArtistView, { contentModel: elisa.allArtistsProxyModel, mainTitle: genreName, secondaryTitle: '', image: elisaTheme.artistIcon, stackView: currentStackView, }) allArtistsFromGenreViewIsLoaded() } onSwitchOffAllViews: { localArtistsLoader.opacity = 0 localTracksLoader.opacity = 0 localAlbumsLoader.opacity = 0 localGenresLoader.opacity = 0 localFilesLoader.opacity = 0 } } ViewSelector { id: listViews Layout.fillHeight: true Layout.preferredWidth: mainWindow.width * 0.11 Layout.maximumWidth: mainWindow.width * 0.11 onSwitchView: if (index === 1) { viewManager.openAllAlbums() } else if (index === 2) { viewManager.openAllArtists() } else if (index === 3) { viewManager.openAllTracks() } else if (index === 4) { viewManager.openAllGenres() } else if (index === 5) { viewManager.openFilesBrowser() } else { viewManager.closeAllViews() } } Rectangle { id: viewSelectorSeparatorItem border.width: 1 border.color: myPalette.mid color: myPalette.mid visible: true Layout.bottomMargin: elisaTheme.layoutVerticalMargin Layout.topMargin: elisaTheme.layoutVerticalMargin Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter Layout.fillHeight: true Layout.preferredWidth: 1 Layout.minimumWidth: 1 Layout.maximumWidth: 1 } ColumnLayout { Layout.fillHeight: true Layout.fillWidth: true spacing: 0 TopNotification { id: invalidBalooConfiguration Layout.fillWidth: true musicManager: elisa.musicManager focus: true } Item { Layout.fillHeight: true Layout.fillWidth: true RowLayout { anchors.fill: parent spacing: 0 id: contentZone FocusScope { id: mainContentView focus: true Layout.fillHeight: true Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 visible: Layout.minimumWidth != 0 Rectangle { border { color: (mainContentView.activeFocus ? myPalette.highlight : myPalette.base) width: 1 } radius: 3 color: myPalette.base anchors.fill: parent Loader { anchors.fill: parent anchors.leftMargin: parent.width / 3 anchors.rightMargin: parent.width / 3 anchors.topMargin: parent.height / 3 anchors.bottomMargin: parent.height / 3 z: 2 sourceComponent: BusyIndicator { id: busyScanningMusic hoverEnabled: false anchors.fill: parent opacity: 0.8 visible: true running: true z: 2 } active: elisa.musicManager.indexerBusy } Loader { id: localAlbumsLoader active: opacity > 0 visible: opacity > 0 anchors.fill: parent onLoaded: viewManager.allAlbumsViewIsLoaded(item.stackView) sourceComponent: MediaBrowser { id: localAlbums focus: true anchors { fill: parent leftMargin: elisaTheme.layoutHorizontalMargin rightMargin: elisaTheme.layoutHorizontalMargin } firstPage: GridBrowserView { id: allAlbumsView focus: true contentModel: elisa.allAlbumsProxyModel image: elisaTheme.albumIcon mainTitle: i18nc("Title of the view of all albums", "Albums") onOpen: { viewManager.openOneAlbum(localAlbums.stackView, innerMainTitle, innerSecondaryTitle, innerImage, databaseId) } onGoBack: viewManager.goBack() Binding { target: allAlbumsView property: 'expandedFilterView' value: persistentSettings.expandedFilterView } onFilterViewChanged: persistentSettings.expandedFilterView = expandedFilterView } } Behavior on opacity { NumberAnimation { easing.type: Easing.InOutQuad duration: 300 } } } Loader { id: localArtistsLoader active: opacity > 0 visible: opacity > 0 opacity: 0 anchors.fill: parent onLoaded: viewManager.allArtistsViewIsLoaded(item.stackView) sourceComponent: MediaBrowser { id: localArtists focus: true anchors { fill: parent leftMargin: elisaTheme.layoutHorizontalMargin rightMargin: elisaTheme.layoutHorizontalMargin } firstPage: GridBrowserView { id: allArtistsView focus: true showRating: false delegateDisplaySecondaryText: false contentModel: elisa.allArtistsProxyModel image: elisaTheme.artistIcon mainTitle: i18nc("Title of the view of all artists", "Artists") onOpen: { viewManager.openOneArtist(localArtists.stackView, innerMainTitle, innerImage, 0) } onGoBack: viewManager.goBack() Binding { target: allArtistsView property: 'expandedFilterView' value: persistentSettings.expandedFilterView } onFilterViewChanged: persistentSettings.expandedFilterView = expandedFilterView } } Behavior on opacity { NumberAnimation { easing.type: Easing.InOutQuad duration: 300 } } } Loader { id: localTracksLoader active: opacity > 0 visible: opacity > 0 opacity: 0 anchors.fill: parent onLoaded: viewManager.allTracksViewIsLoaded(item) sourceComponent: MediaBrowser { id: localTracks focus: true anchors { fill: parent leftMargin: elisaTheme.layoutHorizontalMargin rightMargin: elisaTheme.layoutHorizontalMargin } firstPage: ListBrowserView { id: allTracksView focus: true contentModel: elisa.allTracksProxyModel delegate: MediaTrackDelegate { id: entry width: allTracksView.delegateWidth height: elisaTheme.trackDelegateHeight focus: true trackData: model.containerData isFirstTrackOfDisc: false isSingleDiscAlbum: model.isSingleDiscAlbum onEnqueue: elisa.mediaPlayList.enqueue(data) onReplaceAndPlay: elisa.mediaPlayList.replaceAndPlay(data) onClicked: contentDirectoryView.currentIndex = index } image: elisaTheme.tracksIcon mainTitle: i18nc("Title of the view of all tracks", "Tracks") Binding { target: allTracksView property: 'expandedFilterView' value: persistentSettings.expandedFilterView } onFilterViewChanged: persistentSettings.expandedFilterView = expandedFilterView } } Behavior on opacity { NumberAnimation { easing.type: Easing.InOutQuad duration: 300 } } } Loader { id: localGenresLoader active: opacity > 0 visible: opacity > 0 opacity: 0 anchors.fill: parent onLoaded: viewManager.allGenresViewIsLoaded(item.stackView) sourceComponent: MediaBrowser { id: localGenres focus: true anchors { fill: parent leftMargin: elisaTheme.layoutHorizontalMargin rightMargin: elisaTheme.layoutHorizontalMargin } firstPage: GridBrowserView { id: allGenresView focus: true showRating: false delegateDisplaySecondaryText: false contentModel: elisa.allGenresProxyModel image: elisaTheme.genresIcon mainTitle: i18nc("Title of the view of all genres", "Genres") onOpen: { viewManager.openAllArtistsFromGenre(localGenres.stackView, innerMainTitle) } onGoBack: viewManager.goBack() Binding { target: allGenresView property: 'expandedFilterView' value: persistentSettings.expandedFilterView } onFilterViewChanged: persistentSettings.expandedFilterView = expandedFilterView } } Behavior on opacity { NumberAnimation { easing.type: Easing.InOutQuad duration: 300 } } } Loader { id: localFilesLoader anchors.fill: parent active: opacity > 0 visible: opacity > 0 opacity: 0 anchors { fill: parent leftMargin: elisaTheme.layoutHorizontalMargin rightMargin: elisaTheme.layoutHorizontalMargin } onLoaded: viewManager.filesBrowserViewIsLoaded(item) sourceComponent: FileBrowserView { id: localFiles focus: true contentModel: elisa.fileBrowserProxyModel Binding { target: localFiles property: 'expandedFilterView' value: persistentSettings.expandedFilterView } onFilterViewChanged: persistentSettings.expandedFilterView = expandedFilterView } Behavior on opacity { NumberAnimation { easing.type: Easing.InOutQuad duration: 300 } } } Behavior on border.color { ColorAnimation { duration: 300 } } } } Rectangle { id: firstViewSeparatorItem border.width: 1 border.color: myPalette.mid color: myPalette.mid visible: true Layout.bottomMargin: elisaTheme.layoutVerticalMargin Layout.topMargin: elisaTheme.layoutVerticalMargin Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter Layout.fillHeight: true Layout.preferredWidth: 1 Layout.minimumWidth: 1 Layout.maximumWidth: 1 } MediaPlayListView { id: playList playListModel: elisa.mediaPlayList Layout.fillHeight: true Layout.leftMargin: elisaTheme.layoutHorizontalMargin Layout.rightMargin: elisaTheme.layoutHorizontalMargin Layout.minimumWidth: contentZone.width Layout.maximumWidth: contentZone.width Layout.preferredWidth: contentZone.width onStartPlayback: elisa.audioControl.ensurePlay() onPausePlayback: elisa.audioControl.playPause() onDisplayError: messageNotification.showNotification(errorText) } Rectangle { id: viewSeparatorItem border.width: 1 border.color: myPalette.mid color: myPalette.mid visible: Layout.minimumWidth != 0 Layout.bottomMargin: elisaTheme.layoutVerticalMargin Layout.topMargin: elisaTheme.layoutVerticalMargin Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter Layout.fillHeight: true Layout.preferredWidth: 1 Layout.minimumWidth: 1 Layout.maximumWidth: 1 } ContextView { id: albumContext Layout.fillHeight: true Layout.minimumWidth: contentZone.width Layout.maximumWidth: contentZone.width Layout.preferredWidth: contentZone.width visible: Layout.minimumWidth != 0 artistName: elisa.manageHeaderBar.artist albumName: elisa.manageHeaderBar.album albumArtUrl: elisa.manageHeaderBar.image } } } states: [ State { name: 'playList' when: listViews.currentIndex === 0 PropertyChanges { target: mainContentView Layout.fillWidth: false Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 } PropertyChanges { target: firstViewSeparatorItem Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 } PropertyChanges { target: playList Layout.minimumWidth: contentZone.width / 2 Layout.maximumWidth: contentZone.width / 2 Layout.preferredWidth: contentZone.width / 2 } PropertyChanges { target: viewSeparatorItem Layout.minimumWidth: 1 Layout.maximumWidth: 1 Layout.preferredWidth: 1 } PropertyChanges { target: albumContext Layout.minimumWidth: contentZone.width / 2 Layout.maximumWidth: contentZone.width / 2 Layout.preferredWidth: contentZone.width / 2 } }, State { name: "browsingViewsNoPlaylist" when: listViews.currentIndex !== 0 && contentViewContainer.showPlaylist !== true extend: "browsingViews" PropertyChanges { target: mainContentView Layout.fillWidth: true Layout.minimumWidth: contentZone.width Layout.maximumWidth: contentZone.width Layout.preferredWidth: contentZone.width } PropertyChanges { target: playList Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 } }, State { name: 'browsingViews' when: listViews.currentIndex !== 0 PropertyChanges { target: mainContentView Layout.fillWidth: true Layout.minimumWidth: contentZone.width * 0.66 Layout.maximumWidth: contentZone.width * 0.68 Layout.preferredWidth: contentZone.width * 0.68 } PropertyChanges { target: firstViewSeparatorItem Layout.minimumWidth: 1 Layout.maximumWidth: 1 Layout.preferredWidth: 1 } PropertyChanges { target: playList Layout.minimumWidth: contentZone.width * 0.33 Layout.maximumWidth: contentZone.width * 0.33 Layout.preferredWidth: contentZone.width * 0.33 } PropertyChanges { target: viewSeparatorItem Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 } PropertyChanges { target: albumContext Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 } } ] transitions: Transition { NumberAnimation { properties: "Layout.minimumWidth, Layout.maximumWidth, Layout.preferredWidth, opacity" easing.type: Easing.InOutQuad duration: 300 } } } Component { id: innerAlbumView GridBrowserView { id: innerAlbumGridView contentModel: elisa.singleArtistProxyModel isSubPage: true onOpen: { viewManager.openOneAlbum(stackView, innerMainTitle, innerSecondaryTitle, innerImage, databaseId) } onGoBack: viewManager.goBack() Binding { target: innerAlbumGridView property: 'expandedFilterView' value: persistentSettings.expandedFilterView } onFilterViewChanged: persistentSettings.expandedFilterView = expandedFilterView } } Component { id: innerArtistView GridBrowserView { id: innerAlbumGridView delegateDisplaySecondaryText: false isSubPage: true onOpen: { viewManager.openOneArtist(stackView, innerMainTitle, innerImage, 0) } onGoBack: viewManager.goBack() Binding { target: innerAlbumGridView property: 'expandedFilterView' value: persistentSettings.expandedFilterView } onFilterViewChanged: persistentSettings.expandedFilterView = expandedFilterView } } Component { id: albumView ListBrowserView { id: albumGridView contentModel: elisa.singleAlbumProxyModel isSubPage: true delegate: MediaAlbumTrackDelegate { id: entry width: albumGridView.delegateWidth height: ((model.isFirstTrackOfDisc && !isSingleDiscAlbum) ? elisaTheme.delegateHeight*2 : elisaTheme.delegateHeight) focus: true mediaTrack.trackData: model.containerData mediaTrack.isFirstTrackOfDisc: model.isFirstTrackOfDisc mediaTrack.isSingleDiscAlbum: model.isSingleDiscAlbum mediaTrack.onEnqueue: elisa.mediaPlayList.enqueue(data) mediaTrack.onReplaceAndPlay: elisa.mediaPlayList.replaceAndPlay(data) mediaTrack.isAlternateColor: (index % 2) === 1 mediaTrack.onClicked: albumGridView.currentIndex = index } allowArtistNavigation: true onShowArtist: { viewManager.openOneArtist(stackView, name, elisaTheme.artistIcon, 0) } onGoBack: viewManager.goBack() expandedFilterView: true Binding { target: albumGridView property: 'expandedFilterView' value: persistentSettings.expandedFilterView } onFilterViewChanged: persistentSettings.expandedFilterView = expandedFilterView } } } diff --git a/src/qml/ContextView.qml b/src/qml/ContextView.qml index 09d202b6..c1d2ed80 100644 --- a/src/qml/ContextView.qml +++ b/src/qml/ContextView.qml @@ -1,170 +1,168 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.Window 2.2 import QtQuick.Controls 2.2 import QtQml.Models 2.2 import org.kde.elisa 1.0 import QtQuick.Layouts 1.2 Item { id: topItem property var albumName property var artistName property var tracksCount property var albumArtUrl ColumnLayout { anchors.fill: parent spacing: 0 Item { Layout.fillHeight: true } Image { id: albumIcon source: albumArtUrl.toString() === '' ? Qt.resolvedUrl(elisaTheme.defaultAlbumImage) : albumArtUrl Layout.preferredWidth: elisaTheme.coverImageSize Layout.preferredHeight: elisaTheme.coverImageSize Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter Layout.maximumWidth: elisaTheme.coverImageSize Layout.maximumHeight: elisaTheme.coverImageSize Layout.bottomMargin: elisaTheme.layoutVerticalMargin width: elisaTheme.coverImageSize height: elisaTheme.coverImageSize sourceSize.width: elisaTheme.coverImageSize sourceSize.height: elisaTheme.coverImageSize asynchronous: true fillMode: Image.PreserveAspectFit } LabelWithToolTip { id: titleLabel text: if (albumName !== undefined) albumName else '' font.weight: Font.Bold color: myPalette.text horizontalAlignment: Text.AlignHCenter Layout.fillWidth: true Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom Layout.bottomMargin: elisaTheme.layoutVerticalMargin elide: Text.ElideRight } LabelWithToolTip { id: artistLabel text: if (artistName !== undefined) artistName else '' font.weight: Font.Normal color: myPalette.text horizontalAlignment: Text.AlignHCenter Layout.fillWidth: true Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom elide: Text.ElideRight } LabelWithToolTip { id: numberLabel text: i18np("1 track", "%1 track", tracksCount) visible: tracksCount !== undefined font.weight: Font.Light color: myPalette.text horizontalAlignment: Text.AlignHCenter Layout.fillWidth: true Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom Layout.bottomMargin: elisaTheme.layoutVerticalMargin elide: Text.ElideRight } Item { Layout.fillHeight: true } RowLayout { Layout.fillWidth: true Layout.bottomMargin: elisaTheme.layoutVerticalMargin * 2 spacing: 0 Image { id: artistJumpIcon source: Qt.resolvedUrl(elisaTheme.defaultArtistImage) Layout.preferredWidth: elisaTheme.smallImageSize Layout.preferredHeight: elisaTheme.smallImageSize Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter Layout.maximumWidth: elisaTheme.smallImageSize Layout.maximumHeight: elisaTheme.smallImageSize Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 visible: artistName !== undefined width: elisaTheme.smallImageSize height: elisaTheme.smallImageSize sourceSize.width: elisaTheme.smallImageSize sourceSize.height: elisaTheme.smallImageSize fillMode: Image.PreserveAspectFit } LabelWithToolTip { text: if (artistName !== undefined) artistName else '' font.weight: Font.Normal color: myPalette.text horizontalAlignment: Text.AlignLeft } } } } diff --git a/src/qml/DraggableItem.qml b/src/qml/DraggableItem.qml index 48f92554..69444fa0 100644 --- a/src/qml/DraggableItem.qml +++ b/src/qml/DraggableItem.qml @@ -1,266 +1,264 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ /* * listviewdragitem * * An example of reordering items in a ListView via drag'n'drop. * * Author: Aurélien Gâteau * License: BSD */ import QtQuick 2.7 FocusScope { id: root default property alias contentItem: dragArea.contentItem // This item will become the parent of the dragged item during the drag operation property Item draggedItemParent signal moveItemRequested(int from, int to) // Size of the area at the top and bottom of the list where drag-scrolling happens property int scrollEdgeSize: 6 // Internal: set to -1 when drag-scrolling up and 1 when drag-scrolling down property int _scrollingDirection: 0 // Internal: shortcut to access the attached ListView from everywhere. Shorter than root.ListView.view property ListView _listView: ListView.view property alias containsMouse: dragArea.containsMouse signal clicked() signal doubleClicked() width: contentItem.width height: topPlaceholder.height + wrapperParent.height + bottomPlaceholder.height property int placeholderHeight // Make contentItem a child of contentItemWrapper onContentItemChanged: { contentItem.parent = dragArea; } Rectangle { id: topPlaceholder anchors { left: parent.left right: parent.right top: parent.top } height: 0 color: myPalette.mid } Item { id: wrapperParent anchors { left: parent.left right: parent.right top: topPlaceholder.bottom } height: contentItem.height Rectangle { id: contentItemWrapper anchors.fill: parent Drag.active: dragArea.drag.active Drag.hotSpot { x: contentItem.width / 2 y: contentItem.height / 2 } MouseArea { id: dragArea anchors.fill: parent drag.target: parent // Disable smoothed so that the Item pixel from where we started the drag remains under the mouse cursor drag.smoothed: false property Item contentItem hoverEnabled: true preventStealing: true acceptedButtons: Qt.LeftButton onReleased: { if (drag.active) { emitMoveItemRequested(); } } onClicked: root.clicked() onDoubleClicked: root.doubleClicked() } } } Rectangle { id: bottomPlaceholder anchors { left: parent.left right: parent.right top: wrapperParent.bottom } height: 0 color: myPalette.mid } SmoothedAnimation { id: upAnimation target: _listView property: "contentY" to: 0 running: _scrollingDirection == -1 } SmoothedAnimation { id: downAnimation target: _listView property: "contentY" to: _listView.contentHeight - _listView.height running: _scrollingDirection == 1 } Loader { id: topDropAreaLoader active: model.index === 0 anchors { left: parent.left right: parent.right bottom: wrapperParent.verticalCenter } height: placeholderHeight sourceComponent: Component { DropArea { property int dropIndex: 0 } } } DropArea { id: bottomDropArea anchors { left: parent.left right: parent.right top: wrapperParent.verticalCenter } property bool isLast: model.index === _listView.count - 1 height: isLast ? _listView.contentHeight - y : placeholderHeight property int dropIndex: model.index + 1 } states: [ State { when: dragArea.drag.active name: "dragging" ParentChange { target: contentItemWrapper parent: draggedItemParent } PropertyChanges { target: contentItemWrapper opacity: 0.9 anchors.fill: undefined width: contentItem.width height: contentItem.height } PropertyChanges { target: wrapperParent height: 0 } PropertyChanges { target: root _scrollingDirection: { var yCoord = _listView.mapFromItem(dragArea, 0, dragArea.mouseY).y; if (yCoord < scrollEdgeSize) { -1; } else if (yCoord > _listView.height - scrollEdgeSize) { 1; } else { 0; } } } }, State { when: bottomDropArea.containsDrag name: "droppingBelow" PropertyChanges { target: bottomPlaceholder height: placeholderHeight } PropertyChanges { target: bottomDropArea height: contentItem.height } }, State { when: topDropAreaLoader.item.containsDrag name: "droppingAbove" PropertyChanges { target: topPlaceholder height: placeholderHeight } PropertyChanges { target: topDropAreaLoader height: contentItem.height } } ] function emitMoveItemRequested() { var dropArea = contentItemWrapper.Drag.target; if (!dropArea) { return; } var dropIndex = dropArea.dropIndex; // If the target item is below us, then decrement dropIndex because the target item is going to move up when // our item leaves its place if (model.index < dropIndex) { dropIndex--; } if (model.index === dropIndex) { return; } root.moveItemRequested(model.index, dropIndex); // Scroll the ListView to ensure the dropped item is visible. This is required when dropping an item after the // last item of the view. Delay the scroll using a Timer because we have to wait until the view has moved the // item before we can scroll to it. makeDroppedItemVisibleTimer.start(); } Timer { id: makeDroppedItemVisibleTimer interval: 0 onTriggered: { _listView.positionViewAtIndex(model.index, ListView.Contain); } } } diff --git a/src/qml/ElisaMainWindow.qml b/src/qml/ElisaMainWindow.qml index 3d566362..d268510a 100644 --- a/src/qml/ElisaMainWindow.qml +++ b/src/qml/ElisaMainWindow.qml @@ -1,324 +1,322 @@ /* * Copyright 2016-2018 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.2 import QtQuick.Controls 1.4 as Controls1 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") property var goBackAction: elisa.action("go_back") property var findAction: elisa.action("edit_find") Controls1.Action { shortcut: findAction.shortcut onTriggered: { if ( persistentSettings.expandedFilterView == true) { persistentSettings.expandedFilterView = false } else { persistentSettings.expandedFilterView = true } } } Controls1.Action { shortcut: goBackAction.shortcut onTriggered: contentView.goBack() } Controls1.Action { id: applicationMenuAction text: i18nc("open application menu", "Application Menu") iconName: "application-menu" onTriggered: applicationMenu.popup() } 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 playControlItemRepeat : false property bool playControlItemShuffle : false property bool expandedFilterView: false property bool showPlaylist: true property bool headerBarIsMaximized: false } 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.playControlItemRepeat = headerBar.playerControl.repeat persistentSettings.playControlItemShuffle = headerBar.playerControl.shuffle 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 } Connections { target: elisa.mediaPlayList onPlayListLoadFailed: { messageNotification.showNotification(i18nc("message of passive notification when playlist load failed", "Load of playlist failed"), 3000) } } PassiveNotification { id: messageNotification } Rectangle { color: myPalette.base anchors.fill: parent ColumnLayout { anchors.fill: parent spacing: 0 Item { id: headerBarParent Layout.minimumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight Layout.maximumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight Layout.fillWidth: true HeaderBar { id: headerBar focus: true anchors.fill: parent tracksCount: elisa.manageHeaderBar.remainingTracks album: elisa.manageHeaderBar.album title: elisa.manageHeaderBar.title artist: elisa.manageHeaderBar.artist image: elisa.manageHeaderBar.image 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: persistentSettings.playControlItemRepeat playerControl.shuffle: persistentSettings.playControlItemShuffle 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 TrackImportNotification { id: importedTracksCountNotification anchors { right: headerBar.right top: headerBar.top rightMargin: elisaTheme.layoutHorizontalMargin * 1.75 topMargin: elisaTheme.layoutHorizontalMargin * 3 } } Binding { target: importedTracksCountNotification property: 'musicManager' value: elisa.musicManager when: elisa.musicManager !== undefined } Loader { sourceComponent: Binding { target: importedTracksCountNotification property: 'indexingRunning' value: elisa.musicManager.indexingRunning } active: elisa.musicManager !== undefined } Loader { sourceComponent: Binding { target: importedTracksCountNotification property: 'importedTracksCount' value: elisa.musicManager.importedTracksCount } active: elisa.musicManager !== undefined } } } ContentView { id: contentView Layout.fillHeight: true Layout.fillWidth: true showPlaylist: persistentSettings.showPlaylist } } } StateGroup { id: mainWindowState states: [ State { name: "headerBarIsMaximized" when: headerBar.isMaximized changes: [ PropertyChanges { target: mainWindow minimumHeight: 120 + elisaTheme.mediaPlayerControlHeight explicit: true }, PropertyChanges { target: headerBarParent Layout.minimumHeight: mainWindow.height Layout.maximumHeight: mainWindow.height }, PropertyChanges { target: contentView height: 0 visible: false } ] } ] } Component.onCompleted: { elisa.initialize() 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}) if (persistentSettings.playListState) { elisa.mediaPlayList.persistentState = persistentSettings.playListState } if (persistentSettings.audioPlayerState) { elisa.audioControl.persistentState = persistentSettings.audioPlayerState } elisa.audioPlayer.muted = Qt.binding(function() { return headerBar.playerControl.muted }) elisa.audioPlayer.volume = Qt.binding(function() { return headerBar.playerControl.volume }) mprisloader.active = true } } diff --git a/src/qml/FileBrowserDelegate.qml b/src/qml/FileBrowserDelegate.qml index d21e2733..4913ce8f 100644 --- a/src/qml/FileBrowserDelegate.qml +++ b/src/qml/FileBrowserDelegate.qml @@ -1,283 +1,281 @@ /* * Copyright 2016-2018 Matthieu Gallien * Copyright 2018 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.2 import QtQuick.Controls 1.4 as Controls1 import QtQuick.Layouts 1.2 import org.kde.elisa 1.0 FocusScope { id: fileDelegate property var fileName property var fileUrl property var imageUrl property var contentModel property bool isDirectory signal enqueue(var data) signal replaceAndPlay(var data) signal open(var data) signal selected() Controls1.Action { id: replaceAndPlayAction text: i18nc("Clear play list and enqueue current track", "Play Now and Replace Play List") iconName: "media-playback-start" onTriggered: replaceAndPlay(fileUrl) } Controls1.Action { id: enqueueAction text: i18nc("Enqueue current track", "Enqueue") iconName: "media-track-add-amarok" onTriggered: enqueue(fileUrl) } Controls1.Action { id: openAction text: i18nc("Enqueue current track", "Enqueue") iconName: 'document-open-folder' onTriggered: open(fileUrl) } Controls1.Action { id: viewDetailsAction text: i18nc("Show track metadata", "View Details") iconName: "help-about" onTriggered: { if (metadataLoader.active === false) { metadataLoader.active = true metadataLoader.item.trackDataHelper.trackData = contentModel.loadMetaDataFromUrl(fileUrl) } else { metadataLoader.item.close(); metadataLoader.active = false } } } Loader { id: metadataLoader active: false onLoaded: item.show() sourceComponent: MediaTrackMetadataView { trackDataHelper: TrackDataHelper { id: dataHelper } onRejected: metadataLoader.active = false; } } Keys.onReturnPressed: isDirectory ? fileDelegate.open(fileUrl) : fileDelegate.enqueue(fileUrl) Keys.onEnterPressed: isDirectory ? fileDelegate.open(fileUrl) : fileDelegate.enqueue(fileUrl) ColumnLayout { anchors.fill: parent spacing: 0 MouseArea { id: hoverArea hoverEnabled: true acceptedButtons: Qt.LeftButton Layout.preferredHeight: fileDelegate.width * 0.85 + elisaTheme.layoutVerticalMargin * 0.5 + mainLabelSize.height Layout.fillWidth: true onClicked: fileDelegate.selected() onDoubleClicked: isDirectory ? fileDelegate.open(fileUrl) : fileDelegate.enqueue(fileUrl) TextMetrics { id: mainLabelSize font: mainLabel.font text: mainLabel.text } ColumnLayout { id: mainData spacing: 0 anchors.fill: parent Item { Layout.preferredHeight: fileDelegate.width * 0.85 Layout.preferredWidth: fileDelegate.width * 0.85 Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter Loader { id: hoverLoader active: false anchors.centerIn: parent z: 1 opacity: 0 sourceComponent: Row { Controls1.ToolButton { id: detailsButton Layout.preferredHeight: elisaTheme.delegateHeight Layout.preferredWidth: elisaTheme.delegateHeight action: viewDetailsAction visible: !isDirectory } Controls1.ToolButton { id: enqueueOpenButton Layout.preferredHeight: elisaTheme.delegateHeight Layout.preferredWidth: elisaTheme.delegateHeight action: isDirectory ? openAction : enqueueAction } Controls1.ToolButton { id: replaceAndPlayButton Layout.preferredHeight: elisaTheme.delegateHeight Layout.preferredWidth: elisaTheme.delegateHeight scale: LayoutMirroring.enabled ? -1 : 1 action: replaceAndPlayAction visible: !isDirectory } } } Image { id: icon anchors.fill: parent sourceSize.width: parent.width sourceSize.height: parent.height fillMode: Image.PreserveAspectFit smooth: true source: imageUrl asynchronous: true } } LabelWithToolTip { id: mainLabel font.weight: Font.Bold color: myPalette.text horizontalAlignment: Text.AlignLeft Layout.topMargin: elisaTheme.layoutVerticalMargin * 0.5 Layout.preferredWidth: fileDelegate.width * 0.85 Layout.maximumHeight: mainLabelSize.height * 2 Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom text: fileName wrapMode: Label.Wrap elide: Text.ElideRight } Item { Layout.fillHeight: true } } } Item { Layout.fillHeight: true } } states: [ State { name: 'notSelected' when: !fileDelegate.activeFocus && !hoverArea.containsMouse PropertyChanges { target: hoverLoader active: false } PropertyChanges { target: hoverLoader opacity: 0.0 } PropertyChanges { target: icon opacity: 1 } }, State { name: 'hoveredOrSelected' when: fileDelegate.activeFocus || hoverArea.containsMouse PropertyChanges { target: hoverLoader active: true } PropertyChanges { target: hoverLoader opacity: 1.0 } PropertyChanges { target: icon opacity: 0.2 } } ] transitions: [ Transition { to: 'hoveredOrSelected' SequentialAnimation { PropertyAction { properties: "active" } NumberAnimation { properties: "opacity" easing.type: Easing.InOutQuad duration: 100 } } }, Transition { to: 'notSelected' SequentialAnimation { NumberAnimation { properties: "opacity" easing.type: Easing.InOutQuad duration: 100 } PropertyAction { properties: "active" } } } ] } diff --git a/src/qml/FileBrowserView.qml b/src/qml/FileBrowserView.qml index 0f5e4545..a632e963 100644 --- a/src/qml/FileBrowserView.qml +++ b/src/qml/FileBrowserView.qml @@ -1,157 +1,155 @@ /* * Copyright 2016-2018 Matthieu Gallien * Copyright 2018 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.2 import QtQml.Models 2.2 import QtQuick.Layouts 1.2 import org.kde.elisa 1.0 FocusScope { id: fileView property bool isSubPage: false property alias contentModel: contentDirectoryView.model property alias expandedFilterView: navigationBar.expandedFilterView signal filterViewChanged(bool expandedFilterView) function goBack() { contentModel.openParentFolder() } function loadFolderAndClear(data) { contentModel.openFolder(data) navigationBar.filterText = "" } SystemPalette { id: myPalette colorGroup: SystemPalette.Active } Theme { id: elisaTheme } MouseArea { anchors.fill: parent hoverEnabled: false acceptedButtons: Qt.BackButton onClicked: contentModel.openParentFolder() } ColumnLayout { anchors.fill: parent spacing: 0 NavigationActionBar { id: navigationBar mainTitle: i18nc("Title of the file browser view", "Files") image: elisaTheme.folderIcon secondaryTitle: contentModel.url enableGoBack: contentModel.canGoBack sortOrder: contentModel.sortedAscending showRating: false height: elisaTheme.navigationBarHeight Layout.preferredHeight: height Layout.minimumHeight: height Layout.maximumHeight: height Layout.fillWidth: true Binding { target: contentModel property: 'filterText' value: navigationBar.filterText } onEnqueue: contentModel.enqueueToPlayList() onReplaceAndPlay: contentModel.replaceAndPlayOfPlayList() onGoBack: contentModel.openParentFolder() onFilterViewChanged: fileView.filterViewChanged(expandedFilterView) onSort: contentModel.sortModel(order) } Rectangle { color: myPalette.base Layout.fillHeight: true Layout.fillWidth: true clip: true GridView { id: contentDirectoryView anchors.topMargin: 20 anchors.fill: parent focus: true ScrollBar.vertical: ScrollBar { id: scrollBar } boundsBehavior: Flickable.StopAtBounds add: Transition { PropertyAnimation { property: "opacity" from: 0 to: 1 duration: 100 } } remove: Transition { PropertyAnimation { property: "opacity" from: 0 to: 1 duration: 100 } } cellWidth: elisaTheme.gridDelegateWidth cellHeight:elisaTheme.gridDelegateHeight delegate: FileBrowserDelegate { width: contentDirectoryView.cellWidth height: contentDirectoryView.cellHeight focus: true isDirectory: model.directory fileName: model.name fileUrl: model.containerData imageUrl: model.imageUrl contentModel: fileView.contentModel onEnqueue: elisa.mediaPlayList.enqueue(data) onReplaceAndPlay: elisa.mediaPlayList.replaceAndPlay(data) onSelected: { forceActiveFocus() contentDirectoryView.currentIndex = model.index } onOpen: loadFolderAndClear(data) } } } } } diff --git a/src/qml/GridBrowserDelegate.qml b/src/qml/GridBrowserDelegate.qml index 2b66376f..8a4be4a4 100644 --- a/src/qml/GridBrowserDelegate.qml +++ b/src/qml/GridBrowserDelegate.qml @@ -1,307 +1,305 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.2 import QtQuick.Controls 1.4 as Controls1 import QtQuick.Window 2.2 import QtQml.Models 2.1 import QtQuick.Layouts 1.2 import QtGraphicalEffects 1.0 FocusScope { id: gridEntry property var imageUrl property bool shadowForImage property alias mainText: mainLabel.text property alias secondaryText: secondaryLabel.text property var containerData property bool delegateDisplaySecondaryText: true property bool isPartial signal enqueue(var data) signal replaceAndPlay(var data) signal open() signal selected() Controls1.Action { id: enqueueAction text: i18nc("Add whole container to play list", "Enqueue") iconName: 'media-track-add-amarok' onTriggered: enqueue(containerData) } Controls1.Action { id: openAction text: i18nc("Open view of the container", "Open") iconName: 'document-open-folder' onTriggered: open() } Controls1.Action { id: replaceAndPlayAction text: i18nc("Clear play list and add whole container to play list", "Play Now and Replace Play List") iconName: 'media-playback-start' onTriggered: replaceAndPlay(containerData) } Keys.onReturnPressed: openAction.trigger(this) Keys.onEnterPressed: openAction.trigger(this) ColumnLayout { anchors.fill: parent spacing: 0 MouseArea { id: hoverHandle hoverEnabled: true acceptedButtons: Qt.LeftButton Layout.preferredHeight: gridEntry.width * 0.85 + elisaTheme.layoutVerticalMargin * 0.5 + mainLabelSize.height + secondaryLabelSize.height Layout.fillWidth: true onClicked: { gridEntry.selected() } onDoubleClicked: openAction.trigger(this) TextMetrics { id: mainLabelSize font: mainLabel.font text: mainLabel.text } TextMetrics { id: secondaryLabelSize font: secondaryLabel.font text: secondaryLabel.text } ColumnLayout { id: mainData spacing: 0 anchors.fill: parent Item { Layout.preferredHeight: gridEntry.width * 0.85 Layout.preferredWidth: gridEntry.width * 0.85 Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter Loader { id: hoverLoader active: false anchors.centerIn: parent z: 1 opacity: 0 sourceComponent: Row { Controls1.ToolButton { id: enqueueButton objectName: 'enqueueButton' action: enqueueAction width: elisaTheme.delegateToolButtonSize height: elisaTheme.delegateToolButtonSize } Controls1.ToolButton { id: openButton objectName: 'openButton' action: openAction width: elisaTheme.delegateToolButtonSize height: elisaTheme.delegateToolButtonSize } Controls1.ToolButton { id: replaceAndPlayButton objectName: 'replaceAndPlayButton' scale: LayoutMirroring.enabled ? -1 : 1 action: replaceAndPlayAction width: elisaTheme.delegateToolButtonSize height: elisaTheme.delegateToolButtonSize } } } Loader { id: coverImageLoader active: !isPartial anchors.fill: parent sourceComponent: Image { id: coverImage anchors.fill: parent sourceSize.width: parent.width sourceSize.height: parent.height fillMode: Image.PreserveAspectFit smooth: true source: (gridEntry.imageUrl !== undefined ? gridEntry.imageUrl : "") asynchronous: true layer.enabled: shadowForImage layer.effect: DropShadow { source: coverImage radius: 10 spread: 0.1 samples: 21 color: myPalette.shadow } } } Loader { active: isPartial anchors.fill: parent sourceComponent: BusyIndicator { anchors.fill: parent running: true } } } LabelWithToolTip { id: mainLabel font.weight: Font.Bold color: myPalette.text horizontalAlignment: Text.AlignLeft Layout.topMargin: elisaTheme.layoutVerticalMargin * 0.5 Layout.preferredWidth: gridEntry.width * 0.85 Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom elide: Text.ElideRight } LabelWithToolTip { id: secondaryLabel font.weight: Font.Light color: myPalette.text horizontalAlignment: Text.AlignLeft Layout.preferredWidth: gridEntry.width * 0.85 Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom visible: delegateDisplaySecondaryText elide: Text.ElideRight } } } Item { Layout.fillHeight: true } } states: [ State { name: 'notSelected' when: !gridEntry.activeFocus && !hoverHandle.containsMouse PropertyChanges { target: hoverLoader active: false } PropertyChanges { target: hoverLoader opacity: 0.0 } PropertyChanges { target: coverImageLoader opacity: 1 } }, State { name: 'hoveredOrSelected' when: gridEntry.activeFocus || hoverHandle.containsMouse PropertyChanges { target: hoverLoader active: true } PropertyChanges { target: hoverLoader opacity: 1.0 } PropertyChanges { target: coverImageLoader opacity: 0.2 } } ] transitions: [ Transition { to: 'hoveredOrSelected' SequentialAnimation { PropertyAction { properties: "active" } NumberAnimation { properties: "opacity" easing.type: Easing.InOutQuad duration: 100 } } }, Transition { to: 'notSelected' SequentialAnimation { NumberAnimation { properties: "opacity" easing.type: Easing.InOutQuad duration: 100 } PropertyAction { properties: "active" } } } ] } diff --git a/src/qml/GridBrowserView.qml b/src/qml/GridBrowserView.qml index bd0e012e..01260e0b 100644 --- a/src/qml/GridBrowserView.qml +++ b/src/qml/GridBrowserView.qml @@ -1,159 +1,157 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.2 import QtQuick.Window 2.2 import QtQml.Models 2.1 import QtQuick.Layouts 1.2 import QtGraphicalEffects 1.0 import org.kde.elisa 1.0 FocusScope { id: gridView property bool isSubPage: false property string mainTitle property string secondaryTitle property url image property alias contentModel: contentDirectoryView.model property alias showRating: navigationBar.showRating property bool delegateDisplaySecondaryText: true property alias expandedFilterView: navigationBar.expandedFilterView property var stackView signal open(var innerMainTitle, var innerSecondaryTitle, var innerImage, var databaseId) signal goBack() signal filterViewChanged(bool expandedFilterView) SystemPalette { id: myPalette colorGroup: SystemPalette.Active } Theme { id: elisaTheme } ColumnLayout { anchors.fill: parent spacing: 0 NavigationActionBar { id: navigationBar mainTitle: gridView.mainTitle secondaryTitle: gridView.secondaryTitle image: gridView.image enableGoBack: isSubPage sortOrder: if (contentModel) {contentModel.sortedAscending} else true height: elisaTheme.navigationBarHeight Layout.preferredHeight: height Layout.minimumHeight: height Layout.maximumHeight: height Layout.fillWidth: true Loader { active: contentModel !== undefined sourceComponent: Binding { target: contentModel property: 'filterText' value: navigationBar.filterText } } Loader { active: contentModel sourceComponent: Binding { target: contentModel property: 'filterRating' value: navigationBar.filterRating } } onEnqueue: contentModel.enqueueToPlayList() onReplaceAndPlay:contentModel.replaceAndPlayOfPlayList() onGoBack: gridView.goBack() onFilterViewChanged: gridView.filterViewChanged(expandedFilterView) onSort: contentModel.sortModel(order) } Rectangle { color: myPalette.base Layout.fillHeight: true Layout.fillWidth: true clip: true GridView { id: contentDirectoryView anchors.topMargin: 20 focus: true anchors.fill: parent ScrollBar.vertical: ScrollBar { id: scrollBar } boundsBehavior: Flickable.StopAtBounds TextMetrics { id: secondaryLabelSize text: 'example' } cellWidth: elisaTheme.gridDelegateWidth cellHeight: (delegateDisplaySecondaryText ? elisaTheme.gridDelegateHeight : elisaTheme.gridDelegateHeight - secondaryLabelSize.height) delegate: GridBrowserDelegate { width: contentDirectoryView.cellWidth height: contentDirectoryView.cellHeight focus: true isPartial: false mainText: model.display secondaryText: if (gridView.delegateDisplaySecondaryText) {model.secondaryText} else {""} imageUrl: model.imageUrl shadowForImage: if (model.shadowForImage) {model.shadowForImage} else {false} containerData: model.containerData delegateDisplaySecondaryText: gridView.delegateDisplaySecondaryText onEnqueue: elisa.mediaPlayList.enqueue(data) onReplaceAndPlay: elisa.mediaPlayList.replaceAndPlay(data) onOpen: gridView.open(model.display, model.secondaryText, model.imageUrl, model.databaseId) onSelected: { forceActiveFocus() contentDirectoryView.currentIndex = model.index } } } } } } diff --git a/src/qml/HeaderBar.qml b/src/qml/HeaderBar.qml index 064fa701..24f1b193 100644 --- a/src/qml/HeaderBar.qml +++ b/src/qml/HeaderBar.qml @@ -1,390 +1,388 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.Layouts 1.2 import QtQuick.Controls 2.2 import QtQuick.Window 2.2 import QtGraphicalEffects 1.0 FocusScope { id: headerBar property string title property string artist property string album property string image property string newImage property string oldImage property string tracksCount property int trackRating property bool ratingVisible property alias playerControl: playControlItem property alias isMaximized: playControlItem.isMaximized onImageChanged: { if (changeBackgroundTransition.running) { changeBackgroundTransition.complete() } newImage = image changeBackgroundTransition.start() } Item { id: background anchors.fill: parent Image { id: oldBackground source: (oldImage ? oldImage : Qt.resolvedUrl(elisaTheme.defaultBackgroundImage)) asynchronous: true anchors.fill: parent fillMode: Image.PreserveAspectCrop sourceSize.width: parent.width opacity: 1 layer.enabled: true layer.effect: HueSaturation { cached: true lightness: -0.5 saturation: 0.9 layer.enabled: true layer.effect: GaussianBlur { cached: true radius: 256 deviation: 12 samples: 129 transparentBorder: false } } } Image { id: newBackground source: (newImage ? newImage : Qt.resolvedUrl(elisaTheme.defaultBackgroundImage)) asynchronous: true anchors.fill: parent fillMode: Image.PreserveAspectCrop sourceSize.width: parent.width visible: false opacity: 0 layer.enabled: true layer.effect: HueSaturation { cached: true lightness: -0.5 saturation: 0.9 layer.enabled: true layer.effect: GaussianBlur { cached: true radius: 256 deviation: 12 samples: 129 transparentBorder: false } } } } MediaPlayerControl { id: playControlItem focus: true anchors.left: background.left anchors.right: background.right anchors.bottom: background.bottom height: elisaTheme.mediaPlayerControlHeight } ColumnLayout { id: contentZone anchors.top: parent.top anchors.left: parent.left anchors.right: parent.right anchors.bottom: playControlItem.top spacing: 0 Item { Layout.fillHeight: true Layout.fillWidth: true } RowLayout { spacing: 0 Layout.alignment: Qt.AlignVCenter Layout.fillWidth: true Layout.fillHeight: true Item { Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter Layout.preferredHeight: contentZone.height * 0.9 Layout.minimumHeight: contentZone.height * 0.9 Layout.maximumHeight: contentZone.height * 0.9 Layout.preferredWidth: contentZone.height * 0.9 Layout.minimumWidth: contentZone.height * 0.9 Layout.maximumWidth: contentZone.height * 0.9 Layout.leftMargin: !LayoutMirroring.enabled ? contentZone.width * 0.15 : 0 Layout.rightMargin: LayoutMirroring.enabled ? contentZone.width * 0.15 : 0 Image { id: oldMainIcon anchors.fill: parent asynchronous: true source: (oldImage ? oldImage : Qt.resolvedUrl(elisaTheme.defaultAlbumImage)) sourceSize { width: contentZone.height * 0.9 height: contentZone.height * 0.9 } fillMode: Image.PreserveAspectFit } Image { id: newMainIcon anchors.fill: parent asynchronous: true source: (newImage ? newImage : Qt.resolvedUrl(elisaTheme.defaultAlbumImage)) visible: false opacity: 0 sourceSize { width: contentZone.height * 0.9 height: contentZone.height * 0.9 } fillMode: Image.PreserveAspectFit } } ColumnLayout { spacing: 0 Layout.alignment: Qt.AlignTop | Qt.AlignHCenter Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.fillWidth: true Layout.fillHeight: true TextMetrics { id: titleFontInfo font { bold: albumLabel.font.bold pointSize: albumLabel.font.pointSize } text: albumLabel.text } LabelWithToolTip { id: mainLabel text: title Layout.fillWidth: true Layout.alignment: Qt.AlignLeft elide: Text.ElideRight color: myPalette.highlightedText font.pointSize: elisaTheme.defaultFontPointSize * 2.5 font.bold: true Layout.bottomMargin: titleFontInfo.height * 0.5 } LabelWithToolTip { id: authorLabel text: artist Layout.fillWidth: true Layout.alignment: Qt.AlignLeft elide: Text.ElideRight color: myPalette.highlightedText font.pointSize: elisaTheme.defaultFontPointSize * 1.5 layer.effect: Glow { cached: true color: myPalette.shadow radius: 4.0 samples: 9 } } LabelWithToolTip { id: albumLabel text: album Layout.fillWidth: true Layout.alignment: Qt.AlignLeft elide: Text.ElideRight color: myPalette.highlightedText font.weight: Font.Light font.pointSize: elisaTheme.defaultFontPointSize * 1 layer.effect: Glow { cached: true color: myPalette.shadow radius: 4.0 samples: 9 } } RatingStar { id: mainRating visible: ratingVisible starSize: elisaTheme.ratingStarSize starRating: trackRating Layout.alignment: Qt.AlignLeft } } LabelWithToolTip { id: remainingTracksLabel text: i18np("1 track remaining", "%1 tracks remaining", tracksCount) Layout.alignment: Qt.AlignRight | Qt.AlignBottom Layout.bottomMargin: elisaTheme.layoutVerticalMargin Layout.leftMargin: elisaTheme.layoutHorizontalMargin Layout.rightMargin: elisaTheme.layoutHorizontalMargin * 1.75 elide: Text.ElideRight visible: tracksCount > 0 color: myPalette.highlightedText } } Item { Layout.fillHeight: true Layout.fillWidth: true } } SequentialAnimation { id: changeBackgroundTransition PropertyAction { targets: [newBackground, newMainIcon] property: 'opacity' value: 0 } PropertyAction { targets: [newBackground, newMainIcon] property: 'visible' value: true } PropertyAction { target: newBackground property: "source" value: (newImage ? newImage : Qt.resolvedUrl(elisaTheme.defaultBackgroundImage)) } PropertyAction { target: newMainIcon property: "source" value: (newImage ? newImage : Qt.resolvedUrl(elisaTheme.defaultAlbumImage)) } ParallelAnimation { NumberAnimation { targets: [newBackground, newMainIcon] property: 'opacity' from: 0 to: 1 duration: 250 easing.type: Easing.Linear } NumberAnimation { targets: [oldBackground, oldMainIcon] property: 'opacity' from: 1 to: 0 duration: 250 easing.type: Easing.Linear } } PropertyAction { target: headerBar property: "oldImage" value: image } PropertyAction { target: oldBackground property: 'source' value: (headerBar.oldImage ? headerBar.oldImage : Qt.resolvedUrl(elisaTheme.defaultBackgroundImage)) } PropertyAction { target: oldMainIcon property: 'source' value: (headerBar.oldImage ? headerBar.oldImage : Qt.resolvedUrl(elisaTheme.defaultAlbumImage)) } PropertyAction { targets: [oldBackground, oldMainIcon] property: 'opacity' value: 1 } PropertyAction { targets: [newBackground, newMainIcon] property: 'visible' value: false } onStopped: { oldImage = newImage } } } diff --git a/src/qml/LabelWithToolTip.qml b/src/qml/LabelWithToolTip.qml index 3583733d..34ed4408 100644 --- a/src/qml/LabelWithToolTip.qml +++ b/src/qml/LabelWithToolTip.qml @@ -1,76 +1,74 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.2 import QtGraphicalEffects 1.0 import QtQuick.Window 2.2 Label { id: theLabel horizontalAlignment: Text.AlignLeft Loader { anchors.fill: parent active: theLabel.truncated visible: theLabel.truncated sourceComponent: MouseArea { id: hoverArea anchors.fill: parent hoverEnabled: true acceptedButtons: Qt.NoButton Loader { anchors.fill: parent active: hoverArea && hoverArea.containsMouse sourceComponent: ToolTip { delay: Qt.styleHints.mousePressAndHoldInterval visible: hoverArea && hoverArea.containsMouse && theLabel.truncated text: theLabel.text contentItem: Label { text: theLabel.text color: myPalette.highlightedText } enter: Transition { NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad; from: 0.0; to: 1.0; duration: 300; } } exit: Transition { NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad; from: 1.0; to: 0.0; duration: 300; } } background: Rectangle { color: myPalette.shadow radius: elisaTheme.tooltipRadius layer.enabled: true layer.effect: DropShadow { horizontalOffset: elisaTheme.shadowOffset verticalOffset: elisaTheme.shadowOffset radius: 8 samples: 17 color: myPalette.shadow } } } } } } } diff --git a/src/qml/ListBrowserView.qml b/src/qml/ListBrowserView.qml index 18edb365..03c15c50 100644 --- a/src/qml/ListBrowserView.qml +++ b/src/qml/ListBrowserView.qml @@ -1,121 +1,119 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.2 import QtQuick.Window 2.2 import QtQml.Models 2.2 import QtQuick.Layouts 1.2 import QtGraphicalEffects 1.0 import org.kde.elisa 1.0 FocusScope { id: listView property bool isSubPage: false property alias mainTitle: navigationBar.mainTitle property alias secondaryTitle: navigationBar.secondaryTitle property alias image: navigationBar.image property alias delegate: contentDirectoryView.delegate property alias contentModel: contentDirectoryView.model property alias expandedFilterView: navigationBar.expandedFilterView property alias showRating: navigationBar.showRating property alias allowArtistNavigation: navigationBar.allowArtistNavigation property var delegateWidth: scrollBar.visible ? contentDirectoryView.width - scrollBar.width : contentDirectoryView.width property alias currentIndex: contentDirectoryView.currentIndex property var stackView signal goBack() signal showArtist(var name) signal filterViewChanged(bool expandedFilterView) SystemPalette { id: myPalette colorGroup: SystemPalette.Active } Theme { id: elisaTheme } ColumnLayout { anchors.fill: parent spacing: 0 NavigationActionBar { id: navigationBar enableGoBack: listView.isSubPage sortOrder: contentModel.sortedAscending height: elisaTheme.navigationBarHeight Layout.preferredHeight: height Layout.minimumHeight: height Layout.maximumHeight: height Layout.fillWidth: true Binding { target: contentModel property: 'filterText' value: navigationBar.filterText } Binding { target: contentModel property: 'filterRating' value: navigationBar.filterRating } onEnqueue: contentModel.enqueueToPlayList() onFilterViewChanged: listView.filterViewChanged(expandedFilterView) onReplaceAndPlay: contentModel.replaceAndPlayOfPlayList() onGoBack: listView.goBack() onShowArtist: listView.showArtist(listView.contentModel.sourceModel.author) onSort: contentModel.sortModel(order) } Rectangle { color: myPalette.base Layout.fillHeight: true Layout.fillWidth: true ListView { id: contentDirectoryView anchors.topMargin: 20 anchors.fill: parent focus: true ScrollBar.vertical: ScrollBar { id: scrollBar } boundsBehavior: Flickable.StopAtBounds clip: true } } } } diff --git a/src/qml/MediaAlbumTrackDelegate.qml b/src/qml/MediaAlbumTrackDelegate.qml index 187a9368..3692ab88 100644 --- a/src/qml/MediaAlbumTrackDelegate.qml +++ b/src/qml/MediaAlbumTrackDelegate.qml @@ -1,73 +1,71 @@ /* * Copyright 2016-2017 Matthieu Gallien * Copyright 2017 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.Layouts 1.2 FocusScope { id: albumTrack property alias mediaTrack: mediaTrack ColumnLayout { anchors.fill: parent spacing: 0 Rectangle { Layout.preferredHeight: elisaTheme.delegateHeight Layout.minimumHeight: elisaTheme.delegateHeight Layout.maximumHeight: elisaTheme.delegateHeight Layout.fillWidth: true color: (mediaTrack.isAlternateColor ? myPalette.alternateBase : myPalette.base) visible: mediaTrack.isFirstTrackOfDisc && !mediaTrack.isSingleDiscAlbum LabelWithToolTip { id: discHeaderLabel text: 'CD ' + mediaTrack.discNumber font.weight: Font.Bold font.italic: true color: myPalette.text anchors.fill: parent anchors.topMargin: elisaTheme.layoutVerticalMargin anchors.leftMargin: elisaTheme.layoutHorizontalMargin elide: Text.ElideRight } } MediaTrackDelegate { id: mediaTrack Layout.preferredHeight: elisaTheme.delegateHeight Layout.minimumHeight: elisaTheme.delegateHeight Layout.maximumHeight: elisaTheme.delegateHeight Layout.fillWidth: true focus: true detailedView: false } } } diff --git a/src/qml/MediaBrowser.qml b/src/qml/MediaBrowser.qml index 5651bd68..743a8199 100644 --- a/src/qml/MediaBrowser.qml +++ b/src/qml/MediaBrowser.qml @@ -1,89 +1,87 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.2 import QtQuick.Layouts 1.2 import QtQuick.Window 2.2 import org.kde.elisa 1.0 FocusScope { id: contentDirectoryRoot property alias firstPage: listingView.initialItem property alias stackView: listingView function goBack() { if (listingView.depth > 1) { listingView.pop() } } ColumnLayout { anchors.fill: parent spacing: 0 StackView { id: listingView Layout.fillHeight: true Layout.fillWidth: true focus: true pushEnter: Transition { PropertyAnimation { property: "opacity" from: 0 to: 1 } } pushExit: Transition { PropertyAnimation { property: "opacity" from: 1 to: 0 } } popEnter: Transition { PropertyAnimation { property: "opacity" from: 0 to: 1 } } popExit: Transition { PropertyAnimation { property: "opacity" from: 1 to: 0 } } } } MouseArea { anchors.fill: parent acceptedButtons: Qt.BackButton onClicked: goBack() } } diff --git a/src/qml/MediaPlayListView.qml b/src/qml/MediaPlayListView.qml index 477a5b40..9466c174 100644 --- a/src/qml/MediaPlayListView.qml +++ b/src/qml/MediaPlayListView.qml @@ -1,307 +1,305 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ import QtQuick 2.5 import QtQuick.Controls 2.2 import QtQuick.Controls 1.3 as Controls1 import QtQuick.Layouts 1.1 import QtQuick.Window 2.2 import QtQml.Models 2.1 import Qt.labs.platform 1.0 as PlatformDialog import org.kde.elisa 1.0 FocusScope { property StackView parentStackView property MediaPlayList playListModel property int placeholderHeight: elisaTheme.dragDropPlaceholderHeight signal startPlayback() signal pausePlayback() signal displayError(var errorText) id: topItem Controls1.Action { id: clearPlayList text: i18nc("Remove all tracks from play list", "Clear Playlist") iconName: "list-remove" enabled: playListModelDelegate.items.count > 0 onTriggered: playListModel.clearPlayList() } Controls1.Action { id: showCurrentTrack text: i18nc("Show currently played track inside playlist", "Show Current Track") iconName: 'media-show-active-track-amarok' enabled: playListModelDelegate.items.count > 0 onTriggered: { playListView.positionViewAtIndex(playListModel.currentTrackRow, ListView.Contain) playListView.currentIndex = playListModel.currentTrackRow playListView.currentItem.forceActiveFocus() } } Controls1.Action { id: loadPlaylist text: i18nc("Load a playlist file", "Load Playlist...") iconName: 'document-open' onTriggered: { fileDialog.fileMode = PlatformDialog.FileDialog.OpenFile fileDialog.file = '' fileDialog.open() } } Controls1.Action { id: savePlaylist text: i18nc("Save a playlist file", "Save Playlist...") iconName: 'document-save' enabled: playListModelDelegate.items.count > 0 onTriggered: { fileDialog.fileMode = PlatformDialog.FileDialog.SaveFile fileDialog.file = '' fileDialog.open() } } PlatformDialog.FileDialog { id: fileDialog defaultSuffix: 'm3u' folder: PlatformDialog.StandardPaths.writableLocation(PlatformDialog.StandardPaths.MusicLocation) nameFilters: [i18nc("file type (mime type) for m3u playlist", "Playlist (*.m3u)")] onAccepted: { if (fileMode === PlatformDialog.FileDialog.SaveFile) { if (!playListModel.savePlaylist(fileDialog.file)) { displayError(i18nc("message of passive notification when playlist load failed", "Save of playlist failed")) } } else { playListModel.loadPlaylist(fileDialog.file) } } } ColumnLayout { anchors.fill: parent spacing: 0 ColumnLayout { height: elisaTheme.navigationBarHeight Layout.preferredHeight: elisaTheme.navigationBarHeight Layout.minimumHeight: elisaTheme.navigationBarHeight Layout.maximumHeight: elisaTheme.navigationBarHeight spacing: 0 Layout.leftMargin: elisaTheme.layoutHorizontalMargin Layout.rightMargin: elisaTheme.layoutHorizontalMargin TextMetrics { id: titleHeight text: viewTitleHeight.text font { pointSize: viewTitleHeight.font.pointSize bold: viewTitleHeight.font.bold } } LabelWithToolTip { id: viewTitleHeight text: i18nc("Title of the view of the playlist", "Playlist") color: myPalette.text font.pointSize: elisaTheme.defaultFontPointSize * 2 Layout.alignment: Qt.AlignLeft | Qt.AlignTop Layout.topMargin: elisaTheme.layoutVerticalMargin * 3 } RowLayout { Layout.fillWidth: true LabelWithToolTip { id: playListInfo text: i18np("1 track", "%1 tracks", playListModel.tracksCount) color: myPalette.text Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter } Item { Layout.fillWidth: true } Controls1.ToolButton { action: showCurrentTrack } Controls1.ToolButton { action: savePlaylist } Controls1.ToolButton { action: loadPlaylist } Controls1.ToolButton { action: clearPlayList } } Item { Layout.fillHeight: true } } ListView { id: playListView Layout.fillWidth: true Layout.fillHeight: true Layout.topMargin: elisaTheme.layoutVerticalMargin focus: true ScrollBar.vertical: ScrollBar { id: scrollBar } boundsBehavior: Flickable.StopAtBounds clip: true TextEdit { readOnly: true visible: playListModelDelegate.count === 0 wrapMode: TextEdit.Wrap color: myPalette.text font.weight: Font.ExtraLight font.pixelSize: elisaTheme.defaultFontPixelSize * 1.5 text: i18nc("Text shown when play list is empty", "Your play list is empty.\nIn order to start, you can explore your music library with the views on the left.\nUse the available buttons to add your selection.") anchors.fill: parent anchors.margins: elisaTheme.layoutHorizontalMargin } add: Transition { NumberAnimation { property: "opacity"; from: 0; to: 1; duration: 100 } } populate: Transition { NumberAnimation { property: "opacity"; from: 0; to: 1; duration: 100 } } remove: Transition { NumberAnimation { property: "opacity"; from: 1.0; to: 0; duration: 100 } } displaced: Transition { NumberAnimation { properties: "x,y"; duration: 100; easing.type: Easing.InOutQuad} } model: DelegateModel { id: playListModelDelegate model: playListModel groups: [ DelegateModelGroup { name: "selected" } ] delegate: DraggableItem { id: item placeholderHeight: topItem.placeholderHeight focus: true PlayListEntry { id: entry focus: true width: scrollBar.visible ? (!LayoutMirroring.enabled ? playListView.width - scrollBar.width : playListView.width) : playListView.width scrollBarWidth: scrollBar.visible ? scrollBar.width : 0 index: model.index isAlternateColor: item.DelegateModel.itemsIndex % 2 hasAlbumHeader: model.hasAlbumHeader isSingleDiscAlbum: model.isSingleDiscAlbum trackData: model.trackData titleDisplay: model.title albumDisplay: model.album artistDisplay: model.artist albumArtistDisplay: model.albumArtist isValid: model.isValid isPlaying: model.isPlaying isSelected: playListView.currentIndex === index containsMouse: item.containsMouse onStartPlayback: topItem.startPlayback() onPausePlayback: topItem.pausePlayback() onRemoveFromPlaylist: topItem.playListModel.removeRows(trackIndex, 1) onSwitchToTrack: topItem.playListModel.switchTo(trackIndex) } draggedItemParent: topItem onClicked: { playListView.currentIndex = index entry.forceActiveFocus() } onDoubleClicked: { if (model.isValid) { topItem.playListModel.switchTo(model.index) topItem.startPlayback() } } onMoveItemRequested: { playListModel.move(from, to, 1); } } } } } } diff --git a/src/qml/MediaPlayerControl.qml b/src/qml/MediaPlayerControl.qml index 0af1445e..0c1a54e0 100644 --- a/src/qml/MediaPlayerControl.qml +++ b/src/qml/MediaPlayerControl.qml @@ -1,620 +1,618 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.Layouts 1.2 import QtGraphicalEffects 1.0 import QtQuick.Controls 2.2 import org.kde.elisa 1.0 import QtQuick.Controls 1.4 as Controls1 FocusScope { property double volume property int position property int duration property bool muted property bool isPlaying property bool seekable property bool playEnabled property bool skipForwardEnabled property bool skipBackwardEnabled property bool isMaximized property bool shuffle property bool repeat signal play() signal pause() signal playPrevious() signal playNext() signal seek(int position) signal maximize() signal minimize() id: musicWidget SystemPalette { id: myPalette colorGroup: SystemPalette.Active } Theme { id: elisaTheme } Rectangle { anchors.fill: parent color: myPalette.midlight opacity: elisaTheme.mediaPlayerControlOpacity } RowLayout { anchors.fill: parent spacing: 5 Button { Layout.preferredWidth: elisaTheme.smallControlButtonSize Layout.preferredHeight: elisaTheme.smallControlButtonSize Layout.alignment: Qt.AlignVCenter Layout.maximumWidth: elisaTheme.smallControlButtonSize Layout.maximumHeight: elisaTheme.smallControlButtonSize Layout.minimumWidth: elisaTheme.smallControlButtonSize Layout.minimumHeight: elisaTheme.smallControlButtonSize Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.mediaPlayerHorizontalMargin : 0 Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.mediaPlayerHorizontalMargin : 0 contentItem: Image { anchors.fill: parent source: Qt.resolvedUrl(musicWidget.isMaximized ? elisaTheme.minimizeIcon : elisaTheme.maximizeIcon) width: elisaTheme.smallControlButtonSize height: elisaTheme.smallControlButtonSize sourceSize.width: elisaTheme.smallControlButtonSize sourceSize.height: elisaTheme.smallControlButtonSize fillMode: Image.PreserveAspectFit opacity: 1.0 } background: Rectangle { border.width: 0 opacity: 0.0 } onClicked: { musicWidget.isMaximized = !musicWidget.isMaximized } } RoundButton { focus: skipBackwardEnabled Layout.preferredWidth: elisaTheme.smallControlButtonSize Layout.preferredHeight: elisaTheme.smallControlButtonSize Layout.alignment: Qt.AlignVCenter Layout.maximumWidth: elisaTheme.smallControlButtonSize Layout.maximumHeight: elisaTheme.smallControlButtonSize Layout.minimumWidth: elisaTheme.smallControlButtonSize Layout.minimumHeight: elisaTheme.smallControlButtonSize Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.mediaPlayerHorizontalMargin : 0 Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.mediaPlayerHorizontalMargin : 0 enabled: skipBackwardEnabled hoverEnabled: true onClicked: { musicWidget.playPrevious() } contentItem: Image { anchors.fill: parent source: Qt.resolvedUrl(LayoutMirroring.enabled ? elisaTheme.skipForwardIcon : elisaTheme.skipBackwardIcon) width: elisaTheme.smallControlButtonSize height: elisaTheme.smallControlButtonSize sourceSize.width: elisaTheme.smallControlButtonSize sourceSize.height: elisaTheme.smallControlButtonSize fillMode: Image.PreserveAspectFit opacity: skipBackwardEnabled ? 1.0 : 0.6 } background: Rectangle { color: "transparent" border.color: (parent.hovered || parent.activeFocus) ? myPalette.highlight : "transparent" border.width: 1 radius: elisaTheme.smallControlButtonSize Behavior on border.color { ColorAnimation { duration: 300 } } } } RoundButton { focus: playEnabled Layout.preferredWidth: elisaTheme.smallControlButtonSize Layout.preferredHeight: elisaTheme.smallControlButtonSize Layout.alignment: Qt.AlignVCenter Layout.maximumWidth: elisaTheme.smallControlButtonSize Layout.maximumHeight: elisaTheme.smallControlButtonSize Layout.minimumWidth: elisaTheme.smallControlButtonSize Layout.minimumHeight: elisaTheme.smallControlButtonSize enabled: playEnabled hoverEnabled: true onClicked: { if (musicWidget.isPlaying) { musicWidget.pause() } else { musicWidget.play() } } contentItem: Image { anchors.fill: parent source: { if (musicWidget.isPlaying) Qt.resolvedUrl(elisaTheme.pauseIcon) else Qt.resolvedUrl(elisaTheme.playIcon) } width: elisaTheme.smallControlButtonSize height: elisaTheme.smallControlButtonSize sourceSize.width: elisaTheme.smallControlButtonSize sourceSize.height: elisaTheme.smallControlButtonSize fillMode: Image.PreserveAspectFit mirror: LayoutMirroring.enabled opacity: playEnabled ? 1.0 : 0.6 } background: Rectangle { color: "transparent" border.color: (parent.hovered || parent.activeFocus) ? myPalette.highlight : "transparent" border.width: 1 radius: elisaTheme.smallControlButtonSize Behavior on border.color { ColorAnimation { duration: 300 } } } } RoundButton { focus: skipForwardEnabled Layout.preferredWidth: elisaTheme.smallControlButtonSize Layout.preferredHeight: elisaTheme.smallControlButtonSize Layout.alignment: Qt.AlignVCenter Layout.maximumWidth: elisaTheme.smallControlButtonSize Layout.maximumHeight: elisaTheme.smallControlButtonSize Layout.minimumWidth: elisaTheme.smallControlButtonSize Layout.minimumHeight: elisaTheme.smallControlButtonSize enabled: skipForwardEnabled hoverEnabled: true onClicked: { musicWidget.playNext() } contentItem: Image { anchors.fill: parent source: Qt.resolvedUrl(LayoutMirroring.enabled ? elisaTheme.skipBackwardIcon : elisaTheme.skipForwardIcon) width: elisaTheme.smallControlButtonSize height: elisaTheme.smallControlButtonSize sourceSize.width: elisaTheme.smallControlButtonSize sourceSize.height: elisaTheme.smallControlButtonSize fillMode: Image.PreserveAspectFit opacity: skipForwardEnabled ? 1.0 : 0.6 } background: Rectangle { color: "transparent" border.color: (parent.hovered || parent.activeFocus) ? myPalette.highlight : "transparent" border.width: 1 radius: elisaTheme.smallControlButtonSize Behavior on border.color { ColorAnimation { duration: 300 } } } } TextMetrics { id: durationTextMetrics text: i18nc("This is used to preserve a fixed width for the duration text.", "00:00:00") } LabelWithToolTip { id: positionLabel text: timeIndicator.progressDuration color: myPalette.text Layout.alignment: Qt.AlignVCenter Layout.fillHeight: true Layout.rightMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : elisaTheme.layoutHorizontalMargin * 2 Layout.leftMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : elisaTheme.layoutHorizontalMargin * 2 Layout.preferredWidth: durationTextMetrics.width+5 // be in the safe side verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignRight ProgressIndicator { id: timeIndicator position: musicWidget.position } } Slider { property bool seekStarted: false property int seekValue id: musicProgress from: 0 to: musicWidget.duration Layout.alignment: Qt.AlignVCenter Layout.fillWidth: true Layout.rightMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.leftMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 enabled: musicWidget.seekable && musicWidget.playEnabled live: true onValueChanged: { if (seekStarted) { seekValue = value } } onPressedChanged: { if (pressed) { seekStarted = true; seekValue = value } else { musicWidget.seek(seekValue) seekStarted = false; } } background: Rectangle { x: musicProgress.leftPadding y: musicProgress.topPadding + musicProgress.availableHeight / 2 - height / 2 implicitWidth: 200 implicitHeight: 6 width: musicProgress.availableWidth height: implicitHeight radius: 3 color: myPalette.dark Rectangle { x: (LayoutMirroring.enabled ? musicProgress.visualPosition * parent.width : 0) width: LayoutMirroring.enabled ? parent.width - musicProgress.visualPosition * parent.width: musicProgress.handle.x + radius height: parent.height color: myPalette.text radius: 3 } } handle: Rectangle { x: musicProgress.leftPadding + musicProgress.visualPosition * (musicProgress.availableWidth - width) y: musicProgress.topPadding + musicProgress.availableHeight / 2 - height / 2 implicitWidth: 18 implicitHeight: 18 radius: 9 color: myPalette.base border.width: 1 border.color: musicProgress.pressed ? myPalette.text : myPalette.dark } } LabelWithToolTip { id: durationLabel text: durationIndicator.progressDuration color: myPalette.text Layout.alignment: Qt.AlignVCenter Layout.fillHeight: true Layout.rightMargin: !LayoutMirroring.enabled ? (elisaTheme.layoutHorizontalMargin * 2) : 0 Layout.leftMargin: LayoutMirroring.enabled ? (elisaTheme.layoutHorizontalMargin * 2) : 0 Layout.preferredWidth: durationTextMetrics.width verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignLeft ProgressIndicator { id: durationIndicator position: musicWidget.duration } } Image { id: volumeIcon source: if (musicWidget.muted) Qt.resolvedUrl(elisaTheme.playerVolumeMutedIcon) else Qt.resolvedUrl(elisaTheme.playerVolumeIcon) Layout.preferredWidth: elisaTheme.smallControlButtonSize Layout.preferredHeight: elisaTheme.smallControlButtonSize Layout.alignment: Qt.AlignVCenter Layout.maximumWidth: elisaTheme.smallControlButtonSize Layout.maximumHeight: elisaTheme.smallControlButtonSize Layout.minimumWidth: elisaTheme.smallControlButtonSize Layout.minimumHeight: elisaTheme.smallControlButtonSize Layout.rightMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.leftMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 sourceSize.width: elisaTheme.smallControlButtonSize sourceSize.height: elisaTheme.smallControlButtonSize fillMode: Image.PreserveAspectFit visible: false } RoundButton { focus: true Layout.preferredWidth: elisaTheme.smallControlButtonSize Layout.preferredHeight: elisaTheme.smallControlButtonSize Layout.alignment: Qt.AlignVCenter Layout.maximumWidth: elisaTheme.smallControlButtonSize Layout.maximumHeight: elisaTheme.smallControlButtonSize Layout.minimumWidth: elisaTheme.smallControlButtonSize Layout.minimumHeight: elisaTheme.smallControlButtonSize hoverEnabled: true onClicked: musicWidget.muted = !musicWidget.muted contentItem: Image { anchors.fill: parent source: if (musicWidget.muted) Qt.resolvedUrl(elisaTheme.playerVolumeMutedIcon) else Qt.resolvedUrl(elisaTheme.playerVolumeIcon) width: elisaTheme.smallControlButtonSize height: elisaTheme.smallControlButtonSize sourceSize.width: elisaTheme.smallControlButtonSize sourceSize.height: elisaTheme.smallControlButtonSize fillMode: Image.PreserveAspectFit } background: Rectangle { color: "transparent" border.color: (parent.hovered || parent.activeFocus) ? myPalette.highlight : "transparent" border.width: 1 radius: elisaTheme.smallControlButtonSize Behavior on border.color { ColorAnimation { duration: 300 } } } } Slider { id: volumeSlider from: 0 to: 100 value: musicWidget.volume onValueChanged: musicWidget.volume = value enabled: !muted Layout.alignment: Qt.AlignVCenter Layout.preferredWidth: elisaTheme.volumeSliderWidth Layout.maximumWidth: elisaTheme.volumeSliderWidth Layout.minimumWidth: elisaTheme.volumeSliderWidth Layout.rightMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin * 3 : 0 Layout.leftMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin * 3 : 0 width: elisaTheme.volumeSliderWidth background: Rectangle { x: volumeSlider.leftPadding y: volumeSlider.topPadding + volumeSlider.availableHeight / 2 - height / 2 implicitWidth: 200 implicitHeight: 6 width: volumeSlider.availableWidth height: implicitHeight radius: 3 color: myPalette.dark opacity: muted ? 0.5 : 1 Rectangle { x: (LayoutMirroring.enabled ? volumeSlider.visualPosition * parent.width : 0) width: (LayoutMirroring.enabled ? parent.width - volumeSlider.visualPosition * parent.width : volumeSlider.visualPosition * parent.width) height: parent.height color: myPalette.text radius: 3 opacity: muted ? 0.5 : 1 } } handle: Rectangle { x: volumeSlider.leftPadding + volumeSlider.visualPosition * (volumeSlider.availableWidth - width) y: volumeSlider.topPadding + volumeSlider.availableHeight / 2 - height / 2 implicitWidth: 18 implicitHeight: 18 radius: 9 color: myPalette.base border.width: 1 border.color: volumeSlider.pressed ? myPalette.text : (muted ? myPalette.mid : myPalette.dark) } } RoundButton { focus: true id: shuffleButton Layout.preferredWidth: elisaTheme.smallControlButtonSize Layout.preferredHeight: elisaTheme.smallControlButtonSize Layout.alignment: Qt.AlignCenter Layout.maximumWidth: elisaTheme.smallControlButtonSize Layout.maximumHeight: elisaTheme.smallControlButtonSize Layout.minimumWidth: elisaTheme.smallControlButtonSize Layout.minimumHeight: elisaTheme.smallControlButtonSize hoverEnabled: true onClicked: musicWidget.shuffle = !musicWidget.shuffle contentItem: Image { anchors.fill: parent source: musicWidget.shuffle ? Qt.resolvedUrl(elisaTheme.shuffleIcon) : Qt.resolvedUrl(elisaTheme.noShuffleIcon) width: elisaTheme.smallControlButtonSize height: elisaTheme.smallControlButtonSize sourceSize.width: elisaTheme.smallControlButtonSize sourceSize.height: elisaTheme.smallControlButtonSize fillMode: Image.PreserveAspectFit } background: Rectangle { color: "transparent" } } RoundButton { focus: true id: repeatButton Layout.preferredWidth: elisaTheme.smallControlButtonSize Layout.preferredHeight: elisaTheme.smallControlButtonSize Layout.alignment: Qt.AlignCenter Layout.maximumWidth: elisaTheme.smallControlButtonSize Layout.maximumHeight: elisaTheme.smallControlButtonSize Layout.minimumWidth: elisaTheme.smallControlButtonSize Layout.minimumHeight: elisaTheme.smallControlButtonSize hoverEnabled: true onClicked: musicWidget.repeat = !musicWidget.repeat contentItem: Image { anchors.fill: parent source: musicWidget.repeat ? Qt.resolvedUrl(elisaTheme.repeatIcon) : Qt.resolvedUrl(elisaTheme.noRepeatIcon) width: elisaTheme.smallControlButtonSize height: elisaTheme.smallControlButtonSize sourceSize.width: elisaTheme.smallControlButtonSize sourceSize.height: elisaTheme.smallControlButtonSize fillMode: Image.PreserveAspectFit } background: Rectangle { color: "transparent" } } Controls1.ToolButton { id: menuButton action: applicationMenuAction Layout.preferredWidth: elisaTheme.smallControlButtonSize Layout.preferredHeight: elisaTheme.smallControlButtonSize Layout.alignment: Qt.AlignVCenter Layout.maximumWidth: elisaTheme.smallControlButtonSize Layout.maximumHeight: elisaTheme.smallControlButtonSize Layout.minimumWidth: elisaTheme.smallControlButtonSize Layout.minimumHeight: elisaTheme.smallControlButtonSize Layout.rightMargin: !LayoutMirroring.enabled ? elisaTheme.mediaPlayerHorizontalMargin : elisaTheme.mediaPlayerHorizontalMargin * 1.5 Layout.leftMargin: LayoutMirroring.enabled ? elisaTheme.mediaPlayerHorizontalMargin : elisaTheme.mediaPlayerHorizontalMargin * 1.5 } } onPositionChanged: { if (!musicProgress.seekStarted) { musicProgress.value = position } } onVolumeChanged: { console.log('volume of player controls changed: ' + volume) } onIsMaximizedChanged: { if (musicWidget.isMaximized) { musicWidget.maximize() } else { musicWidget.minimize() } } } diff --git a/src/qml/MediaTrackDelegate.qml b/src/qml/MediaTrackDelegate.qml index 5f273c56..5d6b5c1a 100644 --- a/src/qml/MediaTrackDelegate.qml +++ b/src/qml/MediaTrackDelegate.qml @@ -1,426 +1,424 @@ /* * Copyright 2016-2017 Matthieu Gallien * Copyright 2017 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.Layouts 1.2 import QtQuick.Controls 2.2 import QtQuick.Controls 1.4 as Controls1 import QtQuick.Window 2.2 import QtGraphicalEffects 1.0 import org.kde.elisa 1.0 FocusScope { id: mediaTrack property alias trackData: dataHelper.trackData property alias discNumber: dataHelper.discNumber property bool isFirstTrackOfDisc property bool isSingleDiscAlbum property bool isAlternateColor property bool detailedView: true signal clicked() signal enqueue(var data) signal replaceAndPlay(var data) Controls1.Action { id: replaceAndPlayAction text: i18nc("Clear play list and enqueue current track", "Play Now and Replace Play List") iconName: "media-playback-start" onTriggered: replaceAndPlay(dataHelper.databaseId) } Controls1.Action { id: enqueueAction text: i18nc("Enqueue current track", "Enqueue") iconName: "media-track-add-amarok" onTriggered: enqueue(dataHelper.databaseId) } Controls1.Action { id: viewDetailsAction text: i18nc("Show track metadata", "View Details") iconName: "help-about" onTriggered: { if (metadataLoader.active === false) { metadataLoader.active = true } else { metadataLoader.item.close(); metadataLoader.active = false } } } TrackDataHelper { id: dataHelper } Keys.onReturnPressed: enqueueToPlaylist(trackData) Keys.onEnterPressed: enqueueToPlaylist(trackData) Loader { id: metadataLoader active: false onLoaded: item.show() sourceComponent: MediaTrackMetadataView { trackDataHelper: dataHelper onRejected: metadataLoader.active = false; } } Rectangle { id: rowRoot anchors.fill: parent color: (isAlternateColor ? myPalette.alternateBase : myPalette.base) MouseArea { id: hoverArea anchors.fill: parent hoverEnabled: true focus: true acceptedButtons: Qt.LeftButton onClicked: { hoverArea.forceActiveFocus() mediaTrack.clicked() } onDoubleClicked: enqueue(trackData) RowLayout { anchors.fill: parent spacing: 0 LabelWithToolTip { id: mainLabel visible: !detailedView text: { if (dataHelper.hasValidTrackNumber) { if (artist !== albumArtist) return i18nc("%1: track number. %2: track title. %3: artist name", "%1 - %2 - %3", dataHelper.trackNumber.toLocaleString(Qt.locale(), 'f', 0), dataHelper.title, dataHelper.artist); else return i18nc("%1: track number. %2: track title.", "%1 - %2", dataHelper.trackNumber.toLocaleString(Qt.locale(), 'f', 0), dataHelper.title); } else { if (dataHelper.artist !== dataHelper.albumArtist) return i18nc("%1: track title. %2: artist name", "%1 - %2", dataHelper.title, dataHelper.artist); else return i18nc("%1: track title", "%1", dataHelper.title); } } elide: Text.ElideRight horizontalAlignment: Text.AlignLeft color: myPalette.text Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter Layout.fillWidth: true Layout.leftMargin: { if (!LayoutMirroring.enabled) return (!isSingleDiscAlbum ? elisaTheme.layoutHorizontalMargin * 4 : elisaTheme.layoutHorizontalMargin) else return 0 } Layout.rightMargin: { if (LayoutMirroring.enabled) return (!isSingleDiscAlbum ? elisaTheme.layoutHorizontalMargin * 4 : elisaTheme.layoutHorizontalMargin) else return 0 } } Item { Layout.preferredHeight: mediaTrack.height * 0.9 Layout.preferredWidth: mediaTrack.height * 0.9 Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter visible: detailedView Image { id: coverImageElement anchors.fill: parent sourceSize.width: mediaTrack.height * 0.9 sourceSize.height: mediaTrack.height * 0.9 fillMode: Image.PreserveAspectFit smooth: true source: (dataHelper.hasValidAlbumCover ? dataHelper.albumCover : Qt.resolvedUrl(elisaTheme.defaultAlbumImage)) asynchronous: true layer.enabled: dataHelper.hasValidAlbumCover ? true : false layer.effect: DropShadow { source: coverImageElement radius: 10 spread: 0.1 samples: 21 color: myPalette.shadow } } } ColumnLayout { visible: detailedView Layout.fillWidth: true Layout.fillHeight: true Layout.alignment: Qt.AlignLeft spacing: 0 LabelWithToolTip { id: mainLabelDetailed text: { if (dataHelper.hasValidTrackNumber) { return i18nc("%1: track number. %2: track title", "%1 - %2", dataHelper.trackNumber.toLocaleString(Qt.locale(), 'f', 0), dataHelper.title); } else { return dataHelper.title; } } horizontalAlignment: Text.AlignLeft font.weight: Font.Bold color: myPalette.text Layout.alignment: Qt.AlignLeft | Qt.AlignTop Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.fillWidth: true Layout.topMargin: elisaTheme.layoutVerticalMargin / 2 elide: Text.ElideRight } Item { Layout.fillHeight: true } LabelWithToolTip { id: artistLabel text: (isSingleDiscAlbum ? dataHelper.artist + ' - ' + dataHelper.albumName : dataHelper.artist + ' - ' + dataHelper.albumName + ' - CD ' + dataHelper.discNumber) horizontalAlignment: Text.AlignLeft font.weight: Font.Light font.italic: true color: myPalette.text Layout.alignment: Qt.AlignLeft | Qt.AlignBottom Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.fillWidth: true Layout.bottomMargin: elisaTheme.layoutVerticalMargin / 2 elide: Text.ElideRight } } Loader { id: hoverLoader active: false Layout.alignment: Qt.AlignVCenter | Qt.AlignRight Layout.rightMargin: 10 z: 1 opacity: 0 sourceComponent: Row { anchors.centerIn: parent Controls1.ToolButton { id: detailsButton height: elisaTheme.delegateHeight width: elisaTheme.delegateHeight action: viewDetailsAction } Controls1.ToolButton { id: enqueueButton height: elisaTheme.delegateHeight width: elisaTheme.delegateHeight action: enqueueAction } Controls1.ToolButton { id: clearAndEnqueueButton scale: LayoutMirroring.enabled ? -1 : 1 height: elisaTheme.delegateHeight width: elisaTheme.delegateHeight action: replaceAndPlayAction } } } RatingStar { id: ratingWidget starSize: elisaTheme.ratingStarSize starRating: dataHelper.rating Layout.alignment: Qt.AlignVCenter | Qt.AlignRight Layout.leftMargin: elisaTheme.layoutHorizontalMargin Layout.rightMargin: elisaTheme.layoutHorizontalMargin } TextMetrics { id: durationTextMetrics text: i18nc("This is used to preserve a fixed width for the duration text.", "00:00") } LabelWithToolTip { id: durationLabel text: dataHelper.duration font.weight: Font.Light color: myPalette.text horizontalAlignment: Text.AlignRight Layout.alignment: Qt.AlignVCenter | Qt.AlignRight Layout.rightMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.leftMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.preferredWidth: durationTextMetrics.width + 1 } } } } states: [ State { name: 'notSelected' when: !hoverArea.containsMouse && !mediaTrack.activeFocus PropertyChanges { target: hoverLoader active: false } PropertyChanges { target: hoverLoader opacity: 0.0 } PropertyChanges { target: ratingWidget hoverWidgetOpacity: 0.0 } PropertyChanges { target: rowRoot color: (isAlternateColor ? myPalette.alternateBase : myPalette.base) } }, State { name: 'hoveredOrSelected' when: hoverArea.containsMouse || mediaTrack.activeFocus PropertyChanges { target: hoverLoader active: true } PropertyChanges { target: hoverLoader opacity: 1.0 } PropertyChanges { target: ratingWidget hoverWidgetOpacity: 1.0 } PropertyChanges { target: rowRoot color: myPalette.mid } } ] transitions: [ Transition { to: 'hoveredOrSelected' SequentialAnimation { PropertyAction { properties: "active" } ParallelAnimation { NumberAnimation { properties: "opacity, hoverWidgetOpacity" easing.type: Easing.InOutQuad duration: 250 } ColorAnimation { properties: "color" duration: 250 } } } }, Transition { to: 'notSelected' SequentialAnimation { ParallelAnimation { NumberAnimation { properties: "opacity, hoverWidgetOpacity" easing.type: Easing.InOutQuad duration: 250 } ColorAnimation { properties: "color" duration: 250 } } PropertyAction { properties: "active" } } } ] } diff --git a/src/qml/MediaTrackMetadataView.qml b/src/qml/MediaTrackMetadataView.qml index 32d0c78f..2cc5dad3 100644 --- a/src/qml/MediaTrackMetadataView.qml +++ b/src/qml/MediaTrackMetadataView.qml @@ -1,258 +1,256 @@ /* * Copyright 2017 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.2 import QtQuick.Window 2.2 import QtQml.Models 2.2 import QtQuick.Layouts 1.2 import QtGraphicalEffects 1.0 Window { id: trackMetadata property var trackDataHelper property real labelWidth: trackData.width * 0.33 property real metadataWidth: trackData.width * 0.66 signal rejected() LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft LayoutMirroring.childrenInherit: true title: i18nc("Window title for track metadata", "View Details") function updateData() { trackList.clear() if (trackDataHelper.hasValidTitle) trackList.append({"name": i18nc("Track title for track metadata view", "Title:"), "content": trackDataHelper.title}) if (trackDataHelper.hasValidArtist) trackList.append({"name": i18nc("Track artist for track metadata view", "Artist:"), "content": trackDataHelper.artist}) if (trackDataHelper.hasValidAlbumName) trackList.append({"name": i18nc("Album name for track metadata view", "Album:"), "content": trackDataHelper.albumName}) if (trackDataHelper.hasValidTrackNumber) trackList.append({"name": i18nc("Track number for track metadata view", "Track Number:"), "content": trackDataHelper.trackNumber.toString()}) if (trackDataHelper.hasValidDiscNumber) trackList.append({"name": i18nc("Disc number for track metadata view", "Disc Number:"), "content": trackDataHelper.discNumber.toString()}) if (trackDataHelper.hasValidAlbumArtist) trackList.append({"name": i18nc("Album artist for track metadata view", "Album Artist:"), "content": trackDataHelper.albumArtist}) trackList.append({"name": i18nc("Duration label for track metadata view", "Duration:"), "content": trackDataHelper.duration}) if (trackDataHelper.hasValidYear) trackList.append({"name": i18nc("Year label for track metadata view", "Year:"), "content": trackDataHelper.year.toString()}) if (trackDataHelper.hasValidGenre) trackList.append({"name": i18nc("Genre label for track metadata view", "Genre:"), "content": trackDataHelper.genre}) if (trackDataHelper.hasValidComposer) trackList.append({"name": i18nc("Composer name for track metadata view", "Composer:"), "content": trackDataHelper.composer}) if (trackDataHelper.hasValidLyricist) trackList.append({"name": i18nc("Lyricist label for track metadata view", "Lyricist:"), "content": trackDataHelper.lyricist}) if (trackDataHelper.hasValidBitRate) trackList.append({"name": i18nc("Bit rate label for track metadata view", "Bit Rate:"), "content": (trackDataHelper.bitRate / 1000) + " " + i18nc("Unit of the bit rate in thousand", "kbit/s")}) if (trackDataHelper.hasValidSampleRate) trackList.append({"name": i18nc("Sample Rate label for track metadata view", "Sample Rate:"), "content": trackDataHelper.sampleRate + " " + i18nc("Unit of the sample rate", "Hz")}) if (trackDataHelper.hasValidChannels) trackList.append({"name": i18nc("Channels label for track metadata view", "Channels:"), "content": trackDataHelper.channels.toString()}) if (trackDataHelper.hasValidComment) trackList.append({"name": i18nc("Comment label for track metadata view", "Comment:"), "content": trackDataHelper.comment}) } function resize() { trackData.Layout.preferredHeight = textSize.height * trackData.count trackMetadata.height = textSize.height * (trackData.count + 1 + ( trackDataHelper.hasValidRating ? 1 : 0 )) + buttons.height + elisaTheme.layoutHorizontalMargin * 3 trackMetadata.minimumHeight = trackMetadata.height trackMetadata.maximumHeight = trackMetadata.height trackMetadata.width = (trackDataHelper.hasValidAlbumCover ? elisaTheme.coverImageSize : 0) + labelWidth + metadataWidth + 2 * elisaTheme.layoutHorizontalMargin trackMetadata.minimumWidth = trackMetadata.width } Connections { target: trackDataHelper onTrackDataChanged: { updateData() resize() } } modality: Qt.NonModal flags: Qt.Dialog | Qt.WindowCloseButtonHint Component.onCompleted: { updateData() resize() } Rectangle { anchors.fill: parent color: myPalette.window ColumnLayout { anchors.fill: parent anchors.margins: elisaTheme.layoutHorizontalMargin spacing: 0 RowLayout { Layout.fillHeight: true Layout.fillWidth: true spacing: 0 Image { source: trackDataHelper.albumCover visible: trackDataHelper.hasValidAlbumCover width: elisaTheme.coverImageSize height: elisaTheme.coverImageSize fillMode: Image.PreserveAspectFit Layout.preferredHeight: height Layout.preferredWidth: width Layout.minimumHeight: height Layout.minimumWidth: width Layout.maximumHeight: height Layout.maximumWidth: width } ColumnLayout { Layout.leftMargin: elisaTheme.layoutHorizontalMargin Layout.fillHeight: true Layout.fillWidth: true spacing: 0 ListView { id: trackData interactive: false Layout.fillWidth: true model: ListModel { id: trackList } onCountChanged: resize() delegate: RowLayout { id: delegateRow spacing: 0 Label { id: metaDataLabels text: name color: myPalette.text horizontalAlignment: Text.AlignRight Layout.preferredWidth: labelWidth Layout.minimumHeight: textSize.height Layout.rightMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.leftMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Component.onCompleted: { if(labelWidth < metaDataLabels.implicitWidth) { labelWidth = metaDataLabels.implicitWidth } } } Label { id: metaData text: content color: myPalette.text horizontalAlignment: Text.AlignLeft elide: Text.ElideRight Layout.preferredWidth: trackMetadata.width - labelWidth - 2 * elisaTheme.layoutHorizontalMargin - (trackDataHelper.hasValidAlbumCover ? elisaTheme.coverImageSize : 0) Layout.fillWidth: true Layout.minimumHeight: textSize.height Component.onCompleted: { if(metadataWidth < metaData.implicitWidth) { if (metaData.implicitWidth > elisaTheme.maximumMetadataWidth) { metadataWidth = elisaTheme.maximumMetadataWidth } else { metadataWidth = metaData.implicitWidth + 1 } } } } } } RowLayout { anchors.margins: 0 spacing: 0 visible: trackDataHelper.hasValidRating Layout.minimumHeight: textSize.height Label { id: ratingText text: i18nc("Rating label for information panel", "Rating:") color: myPalette.text horizontalAlignment: Text.AlignRight Layout.preferredWidth: labelWidth Layout.rightMargin: elisaTheme.layoutHorizontalMargin } TextMetrics { id: textSize font: ratingText.font text: ratingText.text } RatingStar { id: ratingWidget starRating: trackDataHelper.rating readOnly: true starSize: elisaTheme.ratingStarSize Layout.fillWidth: true layer.effect: ColorOverlay { source: ratingWidget color: myPalette.text } } } } } LabelWithToolTip { id: trackResource text: trackDataHelper.resourceURI color: myPalette.text font.italic: true elide: Text.ElideLeft horizontalAlignment: implicitWidth > trackMetadata.width ? Text.AlignRight : Text.AlignLeft Layout.minimumHeight: textSize.height Layout.preferredWidth: trackMetadata.width * 0.98 - 2 * elisaTheme.layoutHorizontalMargin Layout.topMargin: elisaTheme.layoutVerticalMargin } DialogButtonBox { id: buttons standardButtons: DialogButtonBox.Close alignment: Qt.AlignRight onRejected: trackMetadata.rejected() Layout.fillWidth: true } } } } diff --git a/src/qml/NavigationActionBar.qml b/src/qml/NavigationActionBar.qml index 2dc1aed3..335f2f5c 100644 --- a/src/qml/NavigationActionBar.qml +++ b/src/qml/NavigationActionBar.qml @@ -1,393 +1,391 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ import QtQml 2.2 import QtQuick 2.7 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.2 import QtQuick.Controls 1.4 as Controls1 FocusScope { id: navigationBar property string mainTitle property string secondaryTitle property url image property bool allowArtistNavigation: false property string labelText property bool showRating: true property alias filterText: filterTextInput.text property alias filterRating: ratingFilter.starRating property bool enableGoBack: true property bool expandedFilterView: false property bool enableSorting: true property bool sortOrder signal enqueue(); signal replaceAndPlay(); signal goBack(); signal showArtist(); signal filterViewChanged(bool expandedFilterView); signal sort(var order); Controls1.Action { id: goPreviousAction text: i18nc("navigate back in the views stack", "Back") iconName: (Qt.application.layoutDirection == Qt.RightToLeft) ? "go-next" : "go-previous" onTriggered: goBack() } Controls1.Action { id: showFilterAction text: !navigationBar.expandedFilterView ? i18nc("Show filters in the navigation bar", "Show Search Options") : i18nc("Hide filters in the navigation bar", "Hide Search Options") iconName: !navigationBar.expandedFilterView ? "go-down-search" : "go-up-search" onTriggered: filterViewChanged(!navigationBar.expandedFilterView) } Controls1.Action { id: sortAction text: i18nc("Toggle between ascending and descending order", "Toggle sort order") iconName: sortOrder ? "view-sort-ascending" : "view-sort-descending" onTriggered: sortOrder ? sort(Qt.DescendingOrder) : sort(Qt.AscendingOrder) } ColumnLayout { anchors.fill: parent spacing: 0 anchors.topMargin: elisaTheme.layoutVerticalMargin anchors.bottomMargin: elisaTheme.layoutVerticalMargin RowLayout { spacing: 0 Layout.alignment: Qt.AlignTop Layout.preferredHeight: elisaTheme.navigationBarHeight Layout.minimumHeight: elisaTheme.navigationBarHeight Layout.maximumHeight: elisaTheme.navigationBarHeight Controls1.ToolButton { action: goPreviousAction objectName: 'goPreviousButton' Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 visible: enableGoBack } Image { id: mainIcon source: image asynchronous: true sourceSize.height: elisaTheme.coverImageSize / 2 sourceSize.width: elisaTheme.coverImageSize / 2 fillMode: Image.PreserveAspectFit Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft Layout.preferredHeight: elisaTheme.coverImageSize / 2 Layout.minimumHeight: elisaTheme.coverImageSize / 2 Layout.maximumHeight: elisaTheme.coverImageSize / 2 Layout.preferredWidth: elisaTheme.coverImageSize / 2 Layout.minimumWidth: elisaTheme.coverImageSize / 2 Layout.maximumWidth: elisaTheme.coverImageSize / 2 Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 } ColumnLayout { Layout.preferredHeight: elisaTheme.coverImageSize / 1.9 Layout.minimumHeight: elisaTheme.coverImageSize / 1.9 Layout.maximumHeight: elisaTheme.coverImageSize / 1.9 spacing: 0 Layout.fillWidth: true Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 TextMetrics { id: albumTextSize text: albumLabel.text font.pointSize: albumLabel.font.pointSize font.bold: albumLabel.font.bold } LabelWithToolTip { id: albumLabel text: mainTitle Layout.fillWidth: true Layout.alignment: Qt.AlignTop | Qt.AlignLeft Layout.topMargin: secondaryTitle !== "" ? 0 : 9 elide: Text.ElideRight fontSizeMode: Text.Fit Layout.preferredHeight: elisaTheme.coverImageSize / 5 Layout.minimumHeight: elisaTheme.coverImageSize / 5 Layout.maximumHeight: elisaTheme.coverImageSize / 5 color: myPalette.text font { pointSize: elisaTheme.defaultFontPointSize * 2 } } TextMetrics { id: authorTextSize text: authorLabel.text font.pointSize: authorLabel.font.pointSize font.bold: authorLabel.font.bold } LabelWithToolTip { id: authorLabel text: secondaryTitle color: myPalette.text Layout.fillWidth: true Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter font { pointSize: elisaTheme.defaultFontPointSize } elide: Text.ElideRight visible: secondaryTitle !== "" } RowLayout { Layout.fillWidth: true spacing: 0 Layout.bottomMargin: secondaryTitle !== "" ? 0 : 14 Controls1.Button { objectName: 'enqueueButton' text: i18nc("Add current list to playlist", "Enqueue") iconName: "media-track-add-amarok" onClicked: enqueue() Layout.leftMargin: 0 Layout.rightMargin: 0 } Controls1.Button { objectName: 'replaceAndPlayButton' text: i18nc("Clear playlist and play", "Replace and Play") tooltip: i18nc("Clear playlist and add current list to it", "Replace PlayList and Play Now") iconName: "media-playback-start" onClicked: replaceAndPlay() Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 } Controls1.Button { objectName: 'showArtistButton' id: showArtistButton visible: allowArtistNavigation text: i18nc("Button to navigate to the artist of the album", "Display Artist") iconName: "view-media-artist" onClicked: showArtist() Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 } Item { Layout.fillWidth: true } Controls1.ToolButton { action: showFilterAction objectName: 'showFilterButton' Layout.alignment: Qt.AlignRight Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 } } } } RowLayout { id: filterRow spacing: 0 visible: opacity > 0.0 opacity: 0 Layout.preferredHeight: elisaTheme.navigationBarFilterHeight Layout.minimumHeight: elisaTheme.navigationBarFilterHeight Layout.maximumHeight: elisaTheme.navigationBarFilterHeight Layout.fillWidth: true Layout.topMargin: elisaTheme.layoutVerticalMargin * 2 Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.alignment: Qt.AlignTop LabelWithToolTip { text: i18nc("before the TextField input of the filter", "Search: ") font.bold: true Layout.bottomMargin: 0 color: myPalette.text } TextField { id: filterTextInput objectName: 'filterTextInput' horizontalAlignment: TextInput.AlignLeft placeholderText: i18nc("Placeholder text in the filter text box", "Album name, artist, etc.") Layout.bottomMargin: 0 Layout.preferredWidth: navigationBar.width / 2 Image { anchors.top: parent.top anchors.bottom: parent.bottom anchors.right: parent.right anchors.margins: elisaTheme.filterClearButtonMargin id: clearText fillMode: Image.PreserveAspectFit smooth: true visible: parent.text source: Qt.resolvedUrl(elisaTheme.clearIcon) height: parent.height width: parent.height sourceSize.width: parent.height sourceSize.height: parent.height mirror: LayoutMirroring.enabled MouseArea { id: clear anchors { horizontalCenter: parent.horizontalCenter; verticalCenter: parent.verticalCenter } height: parent.parent.height width: parent.parent.height onClicked: { parent.parent.text = "" parent.parent.forceActiveFocus() } } } } LabelWithToolTip { text: i18nc("before the Rating widget input of the filter", "Rating: ") visible: showRating font.bold: true color: myPalette.text Layout.bottomMargin: 0 Layout.leftMargin: !LayoutMirroring.enabled ? (elisaTheme.layoutHorizontalMargin * 2) : 0 Layout.rightMargin: LayoutMirroring.enabled ? (elisaTheme.layoutHorizontalMargin * 2) : 0 } RatingStar { id: ratingFilter objectName: 'ratingFilter' visible: showRating hoverWidgetOpacity: 1 readOnly: false starSize: elisaTheme.ratingStarSize Layout.bottomMargin: 0 } Item { Layout.fillWidth: true } Controls1.ToolButton { action: sortAction objectName: 'sortAscendingButton' Layout.alignment: Qt.AlignRight Layout.leftMargin: !LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 Layout.rightMargin: LayoutMirroring.enabled ? elisaTheme.layoutHorizontalMargin : 0 visible: enableSorting } } } states: [ State { name: 'collapsed' when: !expandedFilterView PropertyChanges { target: navigationBar height: elisaTheme.navigationBarHeight + elisaTheme.layoutVerticalMargin * 2 } PropertyChanges { target: filterRow opacity: 0.0 } }, State { name: 'expanded' when: expandedFilterView PropertyChanges { target: navigationBar height: elisaTheme.navigationBarHeight + elisaTheme.navigationBarFilterHeight + elisaTheme.layoutVerticalMargin * 4 } PropertyChanges { target: filterRow opacity: 1.0 } } ] transitions: Transition { from: "expanded,collapsed" PropertyAnimation { properties: "height" easing.type: Easing.Linear duration: 250 } PropertyAnimation { properties: "opacity" easing.type: Easing.Linear duration: 250 } } } diff --git a/src/qml/PlatformIntegration.qml b/src/qml/PlatformIntegration.qml index bab47cae..cc6ef9be 100644 --- a/src/qml/PlatformIntegration.qml +++ b/src/qml/PlatformIntegration.qml @@ -1,44 +1,42 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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 org.kde.elisa 1.0 Item { id: rootItem property alias playListModel: mpris2Interface.playListModel property alias audioPlayerManager: mpris2Interface.audioPlayerManager property alias player: mpris2Interface.audioPlayer property alias headerBarManager: mpris2Interface.headerBarManager property alias manageMediaPlayerControl: mpris2Interface.manageMediaPlayerControl signal raisePlayer() Mpris2 { id: mpris2Interface playerName: 'elisa' onRaisePlayer: { rootItem.raisePlayer() } } } diff --git a/src/qml/PlayListEntry.qml b/src/qml/PlayListEntry.qml index a930451d..f8372ae7 100644 --- a/src/qml/PlayListEntry.qml +++ b/src/qml/PlayListEntry.qml @@ -1,604 +1,602 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.Layouts 1.2 import QtQuick.Controls 2.3 import QtQuick.Controls 1.4 as Controls1 import QtQuick.Window 2.2 import QtGraphicalEffects 1.0 import org.kde.elisa 1.0 FocusScope { id: playListEntry property var index property bool isSingleDiscAlbum property int isPlaying property bool isSelected property bool isValid property bool isAlternateColor property bool containsMouse property bool hasAlbumHeader property string titleDisplay property string albumDisplay property string albumArtistDisplay property string artistDisplay property alias trackData: dataHelper.trackData property int scrollBarWidth signal startPlayback() signal pausePlayback() signal removeFromPlaylist(var trackIndex) signal switchToTrack(var trackIndex) height: (hasAlbumHeader ? elisaTheme.playListDelegateWithHeaderHeight : elisaTheme.playListDelegateHeight) Controls1.Action { id: removeFromPlayList text: i18nc("Remove current track from play list", "Remove") iconName: "error" onTriggered: { playListEntry.removeFromPlaylist(playListEntry.index) } } Controls1.Action { id: playNow text: i18nc("Play now current track from play list", "Play Now") iconName: "media-playback-start" enabled: !(isPlaying === MediaPlayList.IsPlaying) && isValid onTriggered: { if (isPlaying === MediaPlayList.NotPlaying) { playListEntry.switchToTrack(playListEntry.index) } playListEntry.startPlayback() } } Controls1.Action { id: pauseNow text: i18nc("Pause current track from play list", "Pause") iconName: "media-playback-pause" enabled: isPlaying == MediaPlayList.IsPlaying && isValid onTriggered: playListEntry.pausePlayback() } Controls1.Action { id: showInfo text: i18nc("Show track metadata", "View Details") iconName: "help-about" enabled: isValid onTriggered: { if (metadataLoader.active === false) { metadataLoader.active = true } else { metadataLoader.item.close(); metadataLoader.active = false } } } TrackDataHelper { id: dataHelper } Loader { id: metadataLoader active: false onLoaded: item.show() sourceComponent: MediaTrackMetadataView { trackDataHelper: dataHelper onRejected: metadataLoader.active = false; } } Rectangle { id: entryBackground anchors.fill: parent anchors.rightMargin: LayoutMirroring.enabled ? scrollBarWidth : 0 color: (isAlternateColor ? myPalette.alternateBase : myPalette.base) height: (hasAlbumHeader ? elisaTheme.playListDelegateWithHeaderHeight : elisaTheme.playListDelegateHeight) focus: true ColumnLayout { spacing: 0 anchors.fill: parent Loader { Layout.fillWidth: true Layout.preferredHeight: elisaTheme.playListDelegateWithHeaderHeight - elisaTheme.playListDelegateHeight Layout.minimumHeight: elisaTheme.playListDelegateWithHeaderHeight - elisaTheme.playListDelegateHeight Layout.maximumHeight: elisaTheme.playListDelegateWithHeaderHeight - elisaTheme.playListDelegateHeight visible: hasAlbumHeader active: hasAlbumHeader sourceComponent: Rectangle { color: myPalette.midlight anchors.fill: parent RowLayout { id: headerRow spacing: elisaTheme.layoutHorizontalMargin anchors.fill: parent anchors.topMargin: elisaTheme.layoutVerticalMargin * 1.5 anchors.bottomMargin: elisaTheme.layoutVerticalMargin * 1.5 Image { id: mainIcon source: (isValid ? (dataHelper.hasValidAlbumCover ? dataHelper.albumCover : Qt.resolvedUrl(elisaTheme.defaultAlbumImage)) : Qt.resolvedUrl(elisaTheme.errorIcon)) Layout.minimumWidth: headerRow.height Layout.maximumWidth: headerRow.height Layout.preferredWidth: headerRow.height Layout.minimumHeight: headerRow.height Layout.maximumHeight: headerRow.height Layout.preferredHeight: headerRow.height Layout.leftMargin: !LayoutMirroring.enabled ? (elisaTheme.smallDelegateToolButtonSize + trackNumberSize.width + fakeDiscNumberSize.width + (elisaTheme.layoutHorizontalMargin * 3 / 4) - headerRow.height) : 0 Layout.rightMargin: LayoutMirroring.enabled ? (elisaTheme.smallDelegateToolButtonSize + trackNumberSize.width + fakeDiscNumberSize.width + (elisaTheme.layoutHorizontalMargin * 3 / 4) - headerRow.height) : 0 Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter sourceSize.width: headerRow.height sourceSize.height: headerRow.height fillMode: Image.PreserveAspectFit asynchronous: true visible: isValid } BrightnessContrast { source: mainIcon cached: true visible: !isValid contrast: -0.9 Layout.minimumWidth: headerRow.height - 4 Layout.maximumWidth: headerRow.height - 4 Layout.preferredWidth: headerRow.height - 4 Layout.minimumHeight: headerRow.height - 4 Layout.maximumHeight: headerRow.height - 4 Layout.preferredHeight: headerRow.height - 4 Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter } ColumnLayout { id: albumHeaderTextColumn Layout.fillWidth: true Layout.fillHeight: true Layout.leftMargin: !LayoutMirroring.enabled ? - elisaTheme.layoutHorizontalMargin / 4 : 0 Layout.rightMargin: LayoutMirroring.enabled ? - elisaTheme.layoutHorizontalMargin / 4 : 0 spacing: 0 LabelWithToolTip { id: mainLabel text: albumDisplay font.weight: Font.Bold font.pointSize: elisaTheme.defaultFontPointSize * 1.4 color: myPalette.text horizontalAlignment: Text.AlignLeft Layout.fillWidth: true Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft Layout.topMargin: elisaTheme.layoutVerticalMargin elide: Text.ElideRight } Item { Layout.fillHeight: true } LabelWithToolTip { id: authorLabel text: albumArtistDisplay font.weight: Font.Light color: myPalette.text horizontalAlignment: Text.AlignLeft Layout.fillWidth: true Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft Layout.bottomMargin: elisaTheme.layoutVerticalMargin elide: Text.ElideRight } } } } } Item { Layout.fillWidth: true Layout.fillHeight: true RowLayout { id: trackRow anchors.fill: parent spacing: elisaTheme.layoutHorizontalMargin / 4 Item { id: playIconItem implicitHeight: elisaTheme.smallDelegateToolButtonSize implicitWidth: elisaTheme.smallDelegateToolButtonSize Layout.maximumWidth: elisaTheme.smallDelegateToolButtonSize Layout.maximumHeight: elisaTheme.smallDelegateToolButtonSize Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter Image { id: playIcon anchors.fill: parent opacity: 0 source: (isPlaying === MediaPlayList.IsPlaying ? Qt.resolvedUrl(elisaTheme.playingIndicatorIcon) : Qt.resolvedUrl(elisaTheme.pausedIndicatorIcon)) width: parent.height * 1. height: parent.height * 1. sourceSize.width: parent.height * 1. sourceSize.height: parent.height * 1. fillMode: Image.PreserveAspectFit mirror: LayoutMirroring.enabled visible: opacity > 0.0 } } Item { id: fakeDiscNumberItem visible: isValid && (!dataHelper.hasValidDiscNumber || isSingleDiscAlbum) Layout.preferredWidth: fakeDiscNumberSize.width + (elisaTheme.layoutHorizontalMargin / 4) Layout.minimumWidth: fakeDiscNumberSize.width + (elisaTheme.layoutHorizontalMargin / 4) Layout.maximumWidth: fakeDiscNumberSize.width + (elisaTheme.layoutHorizontalMargin / 4) TextMetrics { id: fakeDiscNumberSize text: '/9' } } Label { id: trackNumberLabel horizontalAlignment: Text.AlignRight text: dataHelper.hasValidTrackNumber ? Number(dataHelper.trackNumber).toLocaleString(Qt.locale(), 'f', 0) : '' font.weight: (isPlaying ? Font.Bold : Font.Light) color: myPalette.text Layout.alignment: Qt.AlignVCenter | Qt.AlignRight visible: isValid Layout.preferredWidth: (trackNumberSize.width > realTrackNumberSize.width ? trackNumberSize.width : realTrackNumberSize.width) Layout.minimumWidth: (trackNumberSize.width > realTrackNumberSize.width ? trackNumberSize.width : realTrackNumberSize.width) Layout.maximumWidth: (trackNumberSize.width > realTrackNumberSize.width ? trackNumberSize.width : realTrackNumberSize.width) Layout.rightMargin: !LayoutMirroring.enabled ? (dataHelper.hasValidDiscNumber && !isSingleDiscAlbum ? 0 : elisaTheme.layoutHorizontalMargin / 2) : 0 Layout.leftMargin: LayoutMirroring.enabled ? (dataHelper.hasValidDiscNumber && !isSingleDiscAlbum ? 0 : elisaTheme.layoutHorizontalMargin / 2) : 0 TextMetrics { id: trackNumberSize text: (99).toLocaleString(Qt.locale(), 'f', 0) } TextMetrics { id: realTrackNumberSize text: Number(dataHelper.trackNumber).toLocaleString(Qt.locale(), 'f', 0) } } Label { horizontalAlignment: Text.AlignCenter text: '/' visible: isValid && dataHelper.hasValidDiscNumber && !isSingleDiscAlbum font.weight: (isPlaying ? Font.Bold : Font.Light) color: myPalette.text Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter Layout.preferredWidth: numberSeparatorSize.width Layout.minimumWidth: numberSeparatorSize.width Layout.maximumWidth: numberSeparatorSize.width TextMetrics { id: numberSeparatorSize text: '/' } } Label { horizontalAlignment: Text.AlignRight font.weight: (isPlaying ? Font.Bold : Font.Light) color: myPalette.text text: Number(dataHelper.discNumber).toLocaleString(Qt.locale(), 'f', 0) visible: isValid && dataHelper.hasValidDiscNumber && !isSingleDiscAlbum Layout.alignment: Qt.AlignVCenter | Qt.AlignRight Layout.preferredWidth: (discNumberSize.width > realDiscNumberSize.width ? discNumberSize.width : realDiscNumberSize.width) Layout.minimumWidth: (discNumberSize.width > realDiscNumberSize.width ? discNumberSize.width : realDiscNumberSize.width) Layout.maximumWidth: (discNumberSize.width > realDiscNumberSize.width ? discNumberSize.width : realDiscNumberSize.width) Layout.rightMargin: !LayoutMirroring.enabled ? (elisaTheme.layoutHorizontalMargin / 2) : 0 Layout.leftMargin: LayoutMirroring.enabled ? (elisaTheme.layoutHorizontalMargin / 2) : 0 TextMetrics { id: discNumberSize text: '9' } TextMetrics { id: realDiscNumberSize text: Number(dataHelper.discNumber).toLocaleString(Qt.locale(), 'f', 0) } } LabelWithToolTip { id: mainCompactLabel text: titleDisplay font.weight: (isPlaying ? Font.Bold : Font.Normal) color: myPalette.text Layout.maximumWidth: mainCompactLabel.implicitWidth + 1 Layout.fillWidth: true Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft visible: isValid elide: Text.ElideRight horizontalAlignment: Text.AlignLeft } LabelWithToolTip { id: mainInvalidCompactLabel text: titleDisplay font.weight: Font.Normal color: myPalette.text Layout.fillWidth: true Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft visible: !isValid elide: Text.ElideRight } Item { Layout.fillWidth: true Layout.preferredWidth: 0 } Controls1.ToolButton { id: infoButton objectName: 'infoButton' implicitHeight: elisaTheme.smallDelegateToolButtonSize implicitWidth: elisaTheme.smallDelegateToolButtonSize opacity: 0 visible: opacity > 0.1 action: showInfo Layout.alignment: Qt.AlignVCenter | Qt.AlignRight } Controls1.ToolButton { id: playPauseButton objectName: 'playPauseButton' implicitHeight: elisaTheme.smallDelegateToolButtonSize implicitWidth: elisaTheme.smallDelegateToolButtonSize opacity: 0 scale: LayoutMirroring.enabled ? -1 : 1 // We can mirror the symmetrical pause icon visible: opacity > 0.1 action: !(isPlaying === MediaPlayList.IsPlaying) ? playNow : pauseNow Layout.alignment: Qt.AlignVCenter | Qt.AlignRight } Item { implicitHeight: elisaTheme.smallDelegateToolButtonSize implicitWidth: elisaTheme.smallDelegateToolButtonSize Layout.maximumWidth: elisaTheme.smallDelegateToolButtonSize Layout.maximumHeight: elisaTheme.smallDelegateToolButtonSize Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter Controls1.ToolButton { id: removeButton objectName: 'removeButton' anchors.fill: parent opacity: 0 visible: opacity > 0.1 action: removeFromPlayList } } RatingStar { id: ratingWidget starRating: dataHelper.rating starSize: elisaTheme.ratingStarSize } TextMetrics { id: durationTextMetrics text: i18nc("This is used to preserve a fixed width for the duration text.", "00:00") } LabelWithToolTip { id: durationLabel text: dataHelper.duration font.weight: (isPlaying ? Font.Bold : Font.Normal) color: myPalette.text Layout.alignment: Qt.AlignVCenter | Qt.AlignRight Layout.preferredWidth: durationTextMetrics.width + 1 Layout.leftMargin: elisaTheme.layoutHorizontalMargin / 2 Layout.rightMargin: elisaTheme.layoutHorizontalMargin / 2 horizontalAlignment: Text.AlignRight } } } } } states: [ State { name: 'notSelected' when: !containsMouse && (!playListEntry.activeFocus || !isSelected) PropertyChanges { target: removeButton opacity: 0 } PropertyChanges { target: infoButton opacity: 0 } PropertyChanges { target: playPauseButton opacity: 0 } PropertyChanges { target: playIcon opacity: (isPlaying === MediaPlayList.IsPlaying || isPlaying === MediaPlayList.IsPaused ? 1.0 : 0.0) } PropertyChanges { target: entryBackground color: (isAlternateColor ? myPalette.alternateBase : myPalette.base) } PropertyChanges { target: ratingWidget hoverWidgetOpacity: 0.0 } }, State { name: 'hoveredOrSelected' when: containsMouse || (playListEntry.activeFocus && isSelected) PropertyChanges { target: removeButton opacity: 1 } PropertyChanges { target: playPauseButton opacity: 1 } PropertyChanges { target: infoButton opacity: 1 } PropertyChanges { target: playIcon opacity: (isPlaying === MediaPlayList.IsPlaying || isPlaying === MediaPlayList.IsPaused ? 1.0 : 0.0) } PropertyChanges { target: entryBackground color: myPalette.mid } PropertyChanges { target: ratingWidget hoverWidgetOpacity: 1.0 } } ] transitions: Transition { ParallelAnimation { NumberAnimation { properties: "opacity, hoverWidgetOpacity" easing.type: Easing.InOutQuad duration: 250 } ColorAnimation { properties: "color" duration: 250 } } } } diff --git a/src/qml/RatingStar.qml b/src/qml/RatingStar.qml index 341d1bf1..3bb6140f 100644 --- a/src/qml/RatingStar.qml +++ b/src/qml/RatingStar.qml @@ -1,94 +1,92 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.Layouts 1.2 import QtGraphicalEffects 1.0 RowLayout { property int starSize property int starRating property bool readOnly: true property double hoverBrightness: 0.5 property double hoverContrast: 0.5 property double hoverWidgetOpacity: 0 property int hoveredRating: 0 spacing: 0 opacity: starRating > 0 ? 1 : (readOnly ? 0 : hoverWidgetOpacity) Repeater { model: 5 Item { property int ratingThreshold: 2 + index * 2 Layout.preferredHeight: starSize Layout.preferredWidth: starSize Layout.maximumHeight: starSize Layout.maximumWidth: starSize Layout.minimumHeight: starSize Layout.minimumWidth: starSize Image { width: starSize height: starSize anchors.centerIn: parent sourceSize.width: starSize sourceSize.height: starSize fillMode: Image.PreserveAspectFit layer.enabled: hoveredRating >= ratingThreshold layer.effect: BrightnessContrast { brightness: hoverBrightness contrast: hoverContrast } source: if (starRating >= ratingThreshold || hoveredRating >= ratingThreshold) Qt.resolvedUrl(elisaTheme.ratingIcon) else Qt.resolvedUrl(elisaTheme.ratingUnratedIcon) opacity: if (starRating >= ratingThreshold || hoveredRating >= ratingThreshold) 1 else 0.7 } MouseArea { anchors.fill: parent enabled: !readOnly acceptedButtons: Qt.LeftButton hoverEnabled: true onClicked: if (starRating !== ratingThreshold) { starRating = ratingThreshold } else { starRating = 0 } onEntered: hoveredRating = ratingThreshold onExited: hoveredRating = 0 } } } } diff --git a/src/qml/Theme.qml b/src/qml/Theme.qml index f6fdfb51..f3ec4aac 100644 --- a/src/qml/Theme.qml +++ b/src/qml/Theme.qml @@ -1,24 +1,22 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.2 BaseTheme { } diff --git a/src/qml/TopNotification.qml b/src/qml/TopNotification.qml index c3616c45..a65d8b23 100644 --- a/src/qml/TopNotification.qml +++ b/src/qml/TopNotification.qml @@ -1,342 +1,340 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.Layouts 1.2 import QtQuick.Controls 2.2 import QtQml.Models 2.2 import org.kde.elisa 1.0 FocusScope { id: topItem property var musicManager property bool isViewExpanded: false property int rowHeight: elisaTheme.delegateHeight * 2 visible: Layout.preferredHeight > 0 Rectangle { anchors.fill: parent color: myPalette.mid } Component { id: highlightBar Rectangle { width: notificationColumn.width height: rowHeight color: (topItem.state === 'expanded' ? myPalette.highlight : myPalette.mid) Behavior on color { ColorAnimation { duration: 300 } } } } Rectangle { id: notificationCounter anchors { top: parent.top left: parent.left margins: elisaTheme.layoutVerticalMargin } width: elisaTheme.delegateToolButtonSize height: elisaTheme.delegateToolButtonSize radius: width / 2 color: myPalette.window opacity: 0.0 visible: opacity > 0 z: 3 ToolButton { anchors.centerIn: parent text: manager.countNotifications onClicked: topItem.isViewExpanded = !topItem.isViewExpanded } } ScrollView { id: expandedView ScrollBar.vertical.policy: ScrollBar.AlwaysOff anchors { top: parent.top right: parent.right left: notificationCounter.right bottom: parent.bottom } opacity: 0 visible: opacity > 0 focus: true z: 2 ListView { id: notificationColumn focus: true populate: Transition { NumberAnimation { properties: "opacity"; from: 0; to: 1.0; duration: 300 } } add: Transition { NumberAnimation { properties: "opacity"; from: 0; to: 1.0; duration: 300 } } displaced: Transition { NumberAnimation { properties: "x,y"; duration: 300 } } highlight: highlightBar model: DelegateModel { model: manager delegate: TopNotificationItem { id: currentDelegate focus: true width: ListView.view.width height: rowHeight onEntered: notificationColumn.currentIndex = index onClose: manager.closeNotification(index) onMainButtonClicked: manager.triggerMainButton(index) onSecondaryButtonClicked: manager.triggerSecondaryButton(index) itemMessage: message itemMainButtonText: mainButtonText itemMainButtonIconName: mainButtonIconName itemSecondaryButtonText: secondaryButtonText itemSecondaryButtonIconName: secondaryButtonIconName ListView.onRemove: SequentialAnimation { PropertyAction { target: currentDelegate; property: "ListView.delayRemove"; value: true } ParallelAnimation { NumberAnimation { target: currentDelegate; properties: "height"; from: elisaTheme.delegateHeight * 2; to: 0; duration: 300 } NumberAnimation { target: currentDelegate; properties: "opacity"; from: 1.0; to: 0; duration: 300 } } PropertyAction { target: currentDelegate; property: "ListView.delayRemove"; value: false } } } } function gotoBeginning() { anim.from = notificationColumn.contentY; anim.to = 0; anim.running = true; } NumberAnimation { id: anim; target: notificationColumn; property: "contentY"; duration: 300 } } } TopNotificationManager { id: manager } Connections { target: elisa.musicManager onNewNotification: manager.addNotification(notification) onCloseNotification: manager.closeNotificationById(notificationId) } states: [ State { name: "empty" when: manager.countNotifications === 0 PropertyChanges { target: topItem Layout.preferredHeight: 0 } PropertyChanges { target: notificationCounter opacity: 0.0 } PropertyChanges { target: notificationCounter width: 0 } PropertyChanges { target: notificationColumn interactive: false } PropertyChanges { target: expandedView opacity: 0.0 ScrollBar.vertical.policy: ScrollBar.AlwaysOff } StateChangeScript { script: notificationColumn.gotoBeginning() } }, State { name: "oneNotification" when: manager.countNotifications === 1 PropertyChanges { target: topItem Layout.preferredHeight: elisaTheme.delegateHeight * 2 } PropertyChanges { target: notificationCounter opacity: 0.0 } PropertyChanges { target: notificationCounter width: 0 } PropertyChanges { target: notificationColumn interactive: false } PropertyChanges { target: expandedView opacity: 1.0 ScrollBar.vertical.policy: ScrollBar.AlwaysOff } StateChangeScript { script: notificationColumn.gotoBeginning() } }, State { name: "multipleNotifications" when: manager.countNotifications > 1 && !isViewExpanded PropertyChanges { target: topItem Layout.preferredHeight: elisaTheme.delegateHeight * 2 } PropertyChanges { target: notificationCounter opacity: 1.0 } PropertyChanges { target: notificationCounter width: elisaTheme.delegateToolButtonSize } PropertyChanges { target: notificationColumn interactive: false } PropertyChanges { target: expandedView opacity: 1.0 ScrollBar.vertical.policy: ScrollBar.AsNeeded } StateChangeScript { script: notificationColumn.gotoBeginning() } }, State { name: "expanded" when: manager.countNotifications > 1 && isViewExpanded PropertyChanges { target: topItem Layout.preferredHeight: elisaTheme.delegateHeight * 4 } PropertyChanges { target: notificationCounter opacity: 1.0 } PropertyChanges { target: notificationCounter width: elisaTheme.delegateToolButtonSize } PropertyChanges { target: notificationColumn interactive: true } PropertyChanges { target: expandedView opacity: 1.0 ScrollBar.vertical.policy: ScrollBar.AsNeeded } } ] transitions: [ Transition { SequentialAnimation { PropertyAction { target: expandedView property: "ScrollBar.vertical.policy" value: ScrollBar.AlwaysOff } ParallelAnimation { NumberAnimation { target: topItem duration: 300 property: "Layout.preferredHeight" } NumberAnimation { target: notificationCounter duration: 300 property: "opacity" } NumberAnimation { target: notificationCounter duration: 300 property: "width" } NumberAnimation { target: expandedView duration: 300 property: "opacity" } } } } ] } diff --git a/src/qml/TopNotificationItem.qml b/src/qml/TopNotificationItem.qml index a72ebbd7..cdbca746 100644 --- a/src/qml/TopNotificationItem.qml +++ b/src/qml/TopNotificationItem.qml @@ -1,127 +1,125 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.Layouts 1.2 import QtQuick.Controls 2.2 import QtQuick.Controls 1.4 as Controls1 import org.kde.elisa 1.0 FocusScope { id: topItem signal close() signal mainButtonClicked() signal secondaryButtonClicked() signal entered() property alias itemMessage: notificationText.text property alias itemMainButtonText: mainButton.text property alias itemMainButtonIconName: mainButton.iconName property alias itemSecondaryButtonText: secondaryButton.text property alias itemSecondaryButtonIconName: secondaryButton.iconName property var parentList MouseArea { anchors.fill: parent hoverEnabled: true acceptedButtons: Qt.NoButton onEntered: topItem.entered() } RowLayout { id: content anchors.fill: parent Label { id: notificationText font.pointSize: elisaTheme.defaultFontPoinPoint * 1.5 Layout.leftMargin: elisaTheme.layoutHorizontalMargin Layout.alignment: Qt.AlignHCenter visible: topItem.height > height opacity: (topItem.height - height) / height } Controls1.Button { id: mainButton Layout.leftMargin: elisaTheme.layoutHorizontalMargin Layout.alignment: Qt.AlignHCenter Layout.maximumHeight: elisaTheme.delegateHeight visible: text !== "" && topItem.height > height opacity: (topItem.height - height) / height onClicked: { mainButton.enabled = false enableAgainMainButtonTimer.start() mainButtonClicked() } Timer { id: enableAgainMainButtonTimer interval: 500 onTriggered: mainButton.enabled = true } } Controls1.Button { id: secondaryButton Layout.leftMargin: elisaTheme.layoutHorizontalMargin Layout.alignment: Qt.AlignHCenter Layout.maximumHeight: elisaTheme.delegateHeight visible: text !== "" && topItem.height > height opacity: (topItem.height - height) / height onClicked: { secondaryButton.enabled = false enableAgainSecondaryButtonTimer.start() secondaryButtonClicked() } Timer { id: enableAgainSecondaryButtonTimer interval: 500 onTriggered: secondaryButton.enabled = true } } Item { Layout.fillWidth: true } } Controls1.ToolButton { anchors.top: parent.top anchors.right: parent.right visible: topItem.height > height opacity: (topItem.height - height) / height iconName: 'dialog-close' onClicked: close() } } diff --git a/src/qml/TrackImportNotification.qml b/src/qml/TrackImportNotification.qml index c8fcb319..92cddc4a 100644 --- a/src/qml/TrackImportNotification.qml +++ b/src/qml/TrackImportNotification.qml @@ -1,71 +1,69 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.2 import org.kde.elisa 1.0 Rectangle { id: rootComponent property bool indexingRunning property int importedTracksCount property MusicListenersManager musicManager color: myPalette.highlight width: elisaTheme.gridDelegateWidth * 1.5 height: elisaTheme.smallControlButtonSize * 1.5 visible: opacity > 0 opacity: (indexingRunning ? 1 : 0) Label { anchors.centerIn: parent text: i18ncp("number of imported tracks", "Imported one track", "Imported %1 tracks", importedTracksCount) color: myPalette.highlightedText } Timer { id: hideTimer interval: 6000 repeat: false onTriggered: { rootComponent.opacity = 0 } } Behavior on opacity { NumberAnimation { easing.type: Easing.InOutQuad duration: 300 } } onIndexingRunningChanged: if (indexingRunning) { hideTimer.stop() opacity = 1 } else { hideTimer.start() } } diff --git a/src/qml/ViewManager.qml b/src/qml/ViewManager.qml index d35e04a4..71462d9d 100644 --- a/src/qml/ViewManager.qml +++ b/src/qml/ViewManager.qml @@ -1,264 +1,262 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ import QtQuick 2.7 QtObject { enum ViewsType { NoViews, AllAlbums, OneAlbum, AllArtists, OneArtist, OneAlbumFromArtist, AllTracks, AllGenres, AllArtistsFromGenre, OneArtistFromGenre, OneAlbumFromArtistAndGenre, FilesBrowser } property int currentView: ViewManager.ViewsType.NoViews property string currentAlbumTitle property string currentAlbumAuthor property string currentArtistName property string currentGenreName property var currentStackView property int targetView: ViewManager.ViewsType.NoViews property string targetAlbumTitle property string targetAlbumAuthor property string targetArtistName property string targetGenreName property url targetImageUrl property int targetDatabaseId signal switchAllAlbumsView() signal switchOneAlbumView(var currentStackView, string mainTitle, url imageUrl, string secondaryTitle, int databaseId) signal switchAllArtistsView() signal switchOneArtistView(var currentStackView, string mainTitle, url imageUrl, string secondaryTitle, int databaseId) signal switchAllTracksView() signal switchAllGenresView() signal switchAllArtistsFromGenreView(var currentStackView, string genreName) signal switchOneArtistFromGenreView(var currentStackView, string mainTitle, url imageUrl, string secondaryTitle, int databaseId, string genreName) signal switchFilesBrowserView() signal switchOffAllViews() function closeAllViews() { currentView = ViewManager.ViewsType.NoViews targetView = ViewManager.ViewsType.NoViews switchOffAllViews() } function openAllAlbums() { targetView = ViewManager.ViewsType.AllAlbums if (currentView != targetView) { switchAllAlbumsView() } } function openOneAlbum(stackView, albumTitle, albumAuthor, albumCover, albumDatabaseId) { targetAlbumTitle = albumTitle targetAlbumAuthor = albumAuthor targetDatabaseId = albumDatabaseId targetImageUrl = albumCover currentStackView = stackView if (currentView == ViewManager.ViewsType.AllAlbums) { targetView = ViewManager.ViewsType.OneAlbum switchOneAlbumView(currentStackView, targetAlbumTitle, targetImageUrl, targetAlbumAuthor, targetDatabaseId) } else if (currentView == ViewManager.ViewsType.OneArtist) { targetView = ViewManager.ViewsType.OneAlbumFromArtist switchOneAlbumView(currentStackView, targetAlbumTitle, targetImageUrl, targetAlbumAuthor, targetDatabaseId) } else if (currentView == ViewManager.ViewsType.OneArtistFromGenre) { targetView = ViewManager.ViewsType.OneAlbumFromArtistAndGenre switchOneAlbumView(currentStackView, targetAlbumTitle, targetImageUrl, targetAlbumAuthor, targetDatabaseId) } else { switchAllAlbumsView() } } function openAllArtists() { targetView = ViewManager.ViewsType.AllArtists if (currentView != targetView) { switchAllArtistsView() } } function openOneArtist(stackView, artistName, artistImageUrl, artistDatabaseId) { targetArtistName = artistName targetDatabaseId = artistDatabaseId targetImageUrl = artistImageUrl currentStackView = stackView if (currentView == ViewManager.ViewsType.AllArtistsFromGenre) { targetView = ViewManager.ViewsType.OneArtistFromGenre } else { targetView = ViewManager.ViewsType.OneArtist } if (currentView == ViewManager.ViewsType.AllArtists && targetView == ViewManager.ViewsType.OneArtist) { switchOneArtistView(currentStackView, targetArtistName, targetImageUrl, '', targetDatabaseId) } else if (currentView == ViewManager.ViewsType.OneArtist && currentArtistName != targetArtistName && targetView == ViewManager.ViewsType.OneArtist) { currentStackView.pop() switchOneArtistView(currentStackView, targetArtistName, targetImageUrl, '', targetDatabaseId) } else if (currentView == ViewManager.ViewsType.OneAlbumFromArtist && currentArtistName != targetArtistName && targetView == ViewManager.ViewsType.OneArtist) { currentStackView.pop() currentStackView.pop() switchOneArtistView(currentStackView, targetArtistName, targetImageUrl, '', targetDatabaseId) } else if (currentView == ViewManager.ViewsType.AllArtistsFromGenre && targetView == ViewManager.ViewsType.OneArtistFromGenre) { switchOneArtistFromGenreView(currentStackView, targetArtistName, targetImageUrl, '', targetDatabaseId, targetGenreName) } else { switchAllArtistsView() } } function openAllTracks() { targetView = ViewManager.ViewsType.AllTracks if (currentView != targetView) { switchAllTracksView() } } function openAllGenres() { targetView = ViewManager.ViewsType.AllGenres if (currentView != targetView) { switchAllGenresView() } } function openAllArtistsFromGenre(stackView, genreName) { targetView = ViewManager.ViewsType.AllArtistsFromGenre targetGenreName = genreName currentStackView = stackView if (currentView == ViewManager.ViewsType.AllGenres) { switchAllArtistsFromGenreView(currentStackView, targetGenreName) } else { switchAllGenresView() } } function openFilesBrowser() { targetView = ViewManager.ViewsType.FilesBrowser if (currentView != targetView) { switchFilesBrowserView() } } function allAlbumsViewIsLoaded(stackView) { currentStackView = stackView currentView = ViewManager.ViewsType.AllAlbums if (targetView == ViewManager.ViewsType.OneAlbum) { switchOneAlbumView(currentStackView, targetAlbumTitle, targetImageUrl, targetArtistName, targetDatabaseId) } } function oneAlbumViewIsLoaded() { currentAlbumTitle = targetAlbumTitle currentAlbumAuthor = targetAlbumAuthor if (targetView == ViewManager.ViewsType.OneAlbum) { currentView = ViewManager.ViewsType.OneAlbum } else if (targetView == ViewManager.ViewsType.OneAlbumFromArtist) { currentView = ViewManager.ViewsType.OneAlbumFromArtist } else if (targetView == ViewManager.ViewsType.OneAlbumFromArtistAndGenre) { currentView = ViewManager.ViewsType.OneAlbumFromArtistAndGenre } } function allArtistsViewIsLoaded(stackView) { currentStackView = stackView currentView = ViewManager.ViewsType.AllArtists if (targetView == ViewManager.ViewsType.OneArtist) { switchOneArtistView(currentStackView, targetArtistName, targetImageUrl, '', targetDatabaseId) } } function oneArtistViewIsLoaded() { currentArtistName = targetArtistName if (targetView == ViewManager.ViewsType.OneArtist) { currentView = ViewManager.ViewsType.OneArtist } else { currentGenreName = targetGenreName currentView = ViewManager.ViewsType.OneArtistFromGenre } } function allTracksViewIsLoaded(allTracksView) { currentView = ViewManager.ViewsType.AllTracks } function allGenresViewIsLoaded(stackView) { currentStackView = stackView currentView = ViewManager.ViewsType.AllGenres } function allArtistsFromGenreViewIsLoaded() { currentGenreName = targetGenreName currentView = ViewManager.ViewsType.AllArtistsFromGenre } function filesBrowserViewIsLoaded() { currentView = ViewManager.ViewsType.FilesBrowser } function goBack() { currentStackView.pop() if (currentView == ViewManager.ViewsType.OneAlbum) { currentView = ViewManager.ViewsType.AllAlbums } else if (currentView == ViewManager.ViewsType.OneArtist) { currentView = ViewManager.ViewsType.AllArtists } else if (currentView == ViewManager.ViewsType.OneAlbumFromArtist) { currentView = ViewManager.ViewsType.OneArtist } else if (currentView == ViewManager.ViewsType.AllArtistsFromGenre) { currentView = ViewManager.ViewsType.AllGenres } else if (currentView == ViewManager.ViewsType.OneArtistFromGenre) { currentView = ViewManager.ViewsType.AllArtistsFromGenre } else if (currentView == ViewManager.ViewsType.OneAlbumFromArtistAndGenre) { currentView = ViewManager.ViewsType.OneArtistFromGenre } } } diff --git a/src/qml/ViewSelector.qml b/src/qml/ViewSelector.qml index a3575ef6..f3f5558d 100644 --- a/src/qml/ViewSelector.qml +++ b/src/qml/ViewSelector.qml @@ -1,197 +1,195 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.2 import QtQml.Models 2.2 import QtGraphicalEffects 1.0 FocusScope { id: rootFocusScope property alias currentIndex: viewModeView.currentIndex signal switchView(int index) Rectangle { anchors.fill: parent color: myPalette.base border { color: (rootFocusScope.activeFocus ? myPalette.highlight : "transparent") width: 1 } ScrollView { focus: true anchors.fill: parent clip: true ScrollBar.horizontal.policy: ScrollBar.AlwaysOff ListView { id: viewModeView focus: true z: 2 anchors.topMargin: elisaTheme.layoutHorizontalMargin * 2 model: DelegateModel { id: pageDelegateModel model: ListModel { id: pageModel } delegate: MouseArea { id: item height: elisaTheme.viewSelectorDelegateHeight * 1.4 width: viewModeView.width hoverEnabled: true acceptedButtons: Qt.LeftButton Image { id: viewIcon z: 2 anchors { verticalCenter: parent.verticalCenter leftMargin: elisaTheme.layoutHorizontalMargin left: parent.left } height: elisaTheme.viewSelectorDelegateHeight width: elisaTheme.viewSelectorDelegateHeight sourceSize { width: elisaTheme.viewSelectorDelegateHeight height: elisaTheme.viewSelectorDelegateHeight } source: iconName visible: false } ColorOverlay { source: viewIcon z: 2 anchors { verticalCenter: parent.verticalCenter leftMargin: elisaTheme.layoutHorizontalMargin left: parent.left } height: elisaTheme.viewSelectorDelegateHeight width: elisaTheme.viewSelectorDelegateHeight color: (index === viewModeView.currentIndex || item.containsMouse ? myPalette.highlight : "transparent") Behavior on color { ColorAnimation { duration: 300 } } } LabelWithToolTip { id: nameLabel z: 2 anchors.verticalCenter: parent.verticalCenter anchors.leftMargin: elisaTheme.layoutHorizontalMargin anchors.left: viewIcon.right anchors.right: parent.right anchors.rightMargin: elisaTheme.layoutHorizontalMargin verticalAlignment: "AlignVCenter" font.pointSize: elisaTheme.defaultFontPointSize * 1.4 text: model.name elide: Text.ElideRight color: (viewModeView.currentIndex === index || item.containsMouse ? myPalette.highlight : myPalette.text) Behavior on color { ColorAnimation { duration: 300 } } } onClicked: { viewModeView.currentIndex = index rootFocusScope.focus = true switchView(index) } } } footer: MouseArea { width: viewModeView.width height: viewModeView.height - y acceptedButtons: Qt.LeftButton onClicked: { rootFocusScope.focus = true } } } } Behavior on border.color { ColorAnimation { duration: 300 } } } Connections { target: elisa onInitializationDone: { pageModel.insert(0, {"name": i18nc("Title of the view of the playlist", "Now Playing"), "iconName": elisaTheme.playlistIcon}) pageModel.insert(1, {"name": i18nc("Title of the view of all albums", "Albums"), "iconName": elisaTheme.albumIcon}) pageModel.insert(2, {"name": i18nc("Title of the view of all artists", "Artists"), "iconName": elisaTheme.artistIcon}) pageModel.insert(3, {"name": i18nc("Title of the view of all tracks", "Tracks"), "iconName": elisaTheme.tracksIcon}) pageModel.insert(4, {"name": i18nc("Title of the view of all genres", "Genres"), "iconName": elisaTheme.genresIcon}) console.log(elisa.fileBrowserProxyModel) if (elisa.fileBrowserProxyModel) { pageModel.insert(5, {"name": i18nc("Title of the file browser view", "Files"), "iconName": elisaTheme.folderIcon}) } viewModeView.currentIndex = 1 switchView(1) } } } diff --git a/src/topnotificationmanager.cpp b/src/topnotificationmanager.cpp index e8b29550..20c4e5f2 100644 --- a/src/topnotificationmanager.cpp +++ b/src/topnotificationmanager.cpp @@ -1,203 +1,201 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "topnotificationmanager.h" #include "notificationitem.h" class TopNotificationManagerPrivate { public: QList mNotifications; }; TopNotificationManager::TopNotificationManager(QObject *parent) : QAbstractListModel(parent), d(std::make_unique()) { } TopNotificationManager::~TopNotificationManager() =default; int TopNotificationManager::countNotifications() const { return d->mNotifications.count(); } QModelIndex TopNotificationManager::parent(const QModelIndex &index) const { Q_UNUSED(index); return {}; } void TopNotificationManager::addNotification(NotificationItem notification) { beginInsertRows({}, d->mNotifications.count(), d->mNotifications.count()); d->mNotifications.push_back(notification); endInsertRows(); Q_EMIT countNotificationsChanged(); Q_EMIT notificationMessageChanged(); Q_EMIT notificationMainButtonTextChanged(); Q_EMIT notificationMainButtonIconNameChanged(); Q_EMIT notificationSecondaryButtonTextChanged(); Q_EMIT notificationSecondaryButtonIconNameChanged(); } void TopNotificationManager::closeNotification(int index) { if (index < 0 || index >= d->mNotifications.count()) { return; } beginRemoveRows({}, index, index); d->mNotifications.removeAt(index); endRemoveRows(); Q_EMIT countNotificationsChanged(); Q_EMIT notificationMessageChanged(); Q_EMIT notificationMainButtonTextChanged(); Q_EMIT notificationMainButtonIconNameChanged(); Q_EMIT notificationSecondaryButtonTextChanged(); Q_EMIT notificationSecondaryButtonIconNameChanged(); } void TopNotificationManager::closeNotificationById(const QString ¬ificationId) { for (int i = 0; i < d->mNotifications.size(); ) { if (d->mNotifications.at(i).notificationId() == notificationId) { closeNotification(i); } else { ++i; } } } void TopNotificationManager::triggerMainButton(int index) const { if (index < 0 || index >= d->mNotifications.count()) { return; } d->mNotifications.at(index).triggerMainButton(); } void TopNotificationManager::triggerSecondaryButton(int index) const { if (index < 0 || index >= d->mNotifications.count()) { return; } d->mNotifications.at(index).triggerSecondaryButton(); } int TopNotificationManager::rowCount(const QModelIndex &parent) const { if (parent.isValid()) { return 0; } return d->mNotifications.count(); } QVariant TopNotificationManager::data(const QModelIndex &index, int role) const { auto result = QVariant(); if (!index.isValid()) { return result; } if (index.column() != 0) { return result; } if (index.row() < 0 || index.row() >= d->mNotifications.count()) { return result; } if (role < ColumnsRoles::MessageRole || role > ColumnsRoles::SecondaryButtonIconNameRole) { return result; } auto realRole = static_cast(role); switch(realRole) { case ColumnsRoles::MessageRole: result = d->mNotifications.at(index.row()).message(); break; case ColumnsRoles::MainButtonTextRole: result = d->mNotifications.at(index.row()).mainButtonText(); break; case ColumnsRoles::MainButtonIconNameRole: result = d->mNotifications.at(index.row()).mainButtonIconName(); break; case ColumnsRoles::SecondaryButtonTextRole: result = d->mNotifications.at(index.row()).secondaryButtonText(); break; case ColumnsRoles::SecondaryButtonIconNameRole: result = d->mNotifications.at(index.row()).secondaryButtonIconName(); break; } return result; } QHash TopNotificationManager::roleNames() const { QHash roles; roles[static_cast(ColumnsRoles::MessageRole)] = "message"; roles[static_cast(ColumnsRoles::MainButtonTextRole)] = "mainButtonText"; roles[static_cast(ColumnsRoles::MainButtonIconNameRole)] = "mainButtonIconName"; roles[static_cast(ColumnsRoles::SecondaryButtonTextRole)] = "secondaryButtonText"; roles[static_cast(ColumnsRoles::SecondaryButtonIconNameRole)] = "secondaryButtonIconName"; return roles; } QString TopNotificationManager::notificationMessage() const { return data(index(0, 0, {}), TopNotificationManager::MessageRole).toString(); } QString TopNotificationManager::notificationMainButtonText() const { return data(index(0, 0, {}), TopNotificationManager::MainButtonTextRole).toString(); } QString TopNotificationManager::notificationMainButtonIconName() const { return data(index(0, 0, {}), TopNotificationManager::MainButtonIconNameRole).toString(); } QString TopNotificationManager::notificationSecondaryButtonText() const { return data(index(0, 0, {}), TopNotificationManager::SecondaryButtonTextRole).toString(); } QString TopNotificationManager::notificationSecondaryButtonIconName() const { return data(index(0, 0, {}), TopNotificationManager::SecondaryButtonIconNameRole).toString(); } //#include "moc_topnotificationmanager.cpp" diff --git a/src/topnotificationmanager.h b/src/topnotificationmanager.h index ee0524bc..325efb94 100644 --- a/src/topnotificationmanager.h +++ b/src/topnotificationmanager.h @@ -1,133 +1,131 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef TOPNOTIFICATIONMANAGER_H #define TOPNOTIFICATIONMANAGER_H #include "elisaLib_export.h" #include "notificationitem.h" #include #include #include class TopNotificationManagerPrivate; class ELISALIB_EXPORT TopNotificationManager : public QAbstractListModel { Q_OBJECT Q_PROPERTY(int countNotifications READ countNotifications NOTIFY countNotificationsChanged) Q_PROPERTY(QString notificationMessage READ notificationMessage NOTIFY notificationMessageChanged) Q_PROPERTY(QString notificationMainButtonText READ notificationMainButtonText NOTIFY notificationMainButtonTextChanged) Q_PROPERTY(QString notificationMainButtonIconName READ notificationMainButtonIconName NOTIFY notificationMainButtonIconNameChanged) Q_PROPERTY(QString notificationSecondaryButtonText READ notificationSecondaryButtonText NOTIFY notificationSecondaryButtonTextChanged) Q_PROPERTY(QString notificationSecondaryButtonIconName READ notificationSecondaryButtonIconName NOTIFY notificationSecondaryButtonIconNameChanged) public: enum ColumnsRoles { MessageRole = Qt::UserRole + 1, MainButtonTextRole, MainButtonIconNameRole, SecondaryButtonTextRole, SecondaryButtonIconNameRole, }; Q_ENUM(ColumnsRoles) explicit TopNotificationManager(QObject *parent = nullptr); ~TopNotificationManager(); int countNotifications() const; QModelIndex parent(const QModelIndex &index) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QHash roleNames() const override; QString notificationMessage() const; QString notificationMainButtonText() const; QString notificationMainButtonIconName() const; QString notificationSecondaryButtonText() const; QString notificationSecondaryButtonIconName() const; Q_SIGNALS: void countNotificationsChanged(); void notificationMessageChanged(); void notificationMainButtonTextChanged(); void notificationMainButtonIconNameChanged(); void notificationSecondaryButtonTextChanged(); void notificationSecondaryButtonIconNameChanged(); public Q_SLOTS: void addNotification(NotificationItem notification); void closeNotification(int index); void closeNotificationById(const QString ¬ificationId); void triggerMainButton(int index) const; void triggerSecondaryButton(int index) const; private: std::unique_ptr d; }; #endif // TOPNOTIFICATIONMANAGER_H diff --git a/src/trackdatahelper.cpp b/src/trackdatahelper.cpp index 0d329b0d..eda80fa6 100644 --- a/src/trackdatahelper.cpp +++ b/src/trackdatahelper.cpp @@ -1,153 +1,151 @@ /* * Copyright 2018 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "trackdatahelper.h" TrackDataHelper::TrackDataHelper(QObject *parent) : QObject(parent) { } TrackDataHelper::~TrackDataHelper() = default; const MusicAudioTrack &TrackDataHelper::trackData() const { return *this; } void TrackDataHelper::setTrackData(const MusicAudioTrack &track) { MusicAudioTrack::operator=(track); Q_EMIT trackDataChanged(); } QString TrackDataHelper::title() const { if (MusicAudioTrack::title().isEmpty()) { return fileName(); } else { return MusicAudioTrack::title(); } } QString TrackDataHelper::duration() const { QString result; const QTime &trackDuration = MusicAudioTrack::duration(); if (trackDuration.hour() == 0) { result = trackDuration.toString(QStringLiteral("mm:ss")); } else { result = trackDuration.toString(QStringLiteral("h:mm:ss")); } return result; } QString TrackDataHelper::resourceURI() const { return MusicAudioTrack::resourceURI().toDisplayString(QUrl::PreferLocalFile); } QString TrackDataHelper::fileName() const { return MusicAudioTrack::resourceURI().fileName(); } bool TrackDataHelper::hasValidTrackNumber() const { return trackNumber() > -1; } bool TrackDataHelper::hasValidDiscNumber() const { return discNumber() > -1; } bool TrackDataHelper::hasValidChannels() const { return channels() > -1; } bool TrackDataHelper::hasValidBitRate() const { return bitRate() > -1; } bool TrackDataHelper::hasValidSampleRate() const { return sampleRate() > -1; } bool TrackDataHelper::hasValidYear() const { return MusicAudioTrack::year() != 0; } bool TrackDataHelper::hasValidRating() const { return rating() > -1; } bool TrackDataHelper::hasValidTitle() const { return !title().isEmpty(); } bool TrackDataHelper::hasValidArtist() const { return !artist().isEmpty(); } bool TrackDataHelper::hasValidAlbumArtist() const { return !albumArtist().isEmpty(); } bool TrackDataHelper::hasValidAlbumName() const { return !albumName().isEmpty(); } bool TrackDataHelper::hasValidGenre() const { return !genre().isEmpty(); } bool TrackDataHelper::hasValidComposer() const { return !composer().isEmpty(); } bool TrackDataHelper::hasValidLyricist() const { return !lyricist().isEmpty(); } bool TrackDataHelper::hasValidComment() const { return !comment().isEmpty(); } bool TrackDataHelper::hasValidAlbumCover() const { return !albumCover().isEmpty(); } #include "moc_trackdatahelper.cpp" diff --git a/src/trackdatahelper.h b/src/trackdatahelper.h index ed060b6b..03cbf8c0 100644 --- a/src/trackdatahelper.h +++ b/src/trackdatahelper.h @@ -1,242 +1,240 @@ /* * Copyright 2018 Alexander Stippich * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef TRACKDATAHELPER_H #define TRACKDATAHELPER_H #include "elisaLib_export.h" #include #include "musicaudiotrack.h" class ELISALIB_EXPORT TrackDataHelper : public QObject, public MusicAudioTrack { Q_OBJECT Q_PROPERTY(MusicAudioTrack trackData READ trackData WRITE setTrackData NOTIFY trackDataChanged) Q_PROPERTY(QString title READ title NOTIFY trackDataChanged) Q_PROPERTY(bool hasValidTitle READ hasValidTitle NOTIFY trackDataChanged) Q_PROPERTY(QString artist READ artist NOTIFY trackDataChanged) Q_PROPERTY(bool hasValidArtist READ hasValidArtist NOTIFY trackDataChanged) Q_PROPERTY(QString albumName READ albumName NOTIFY trackDataChanged) Q_PROPERTY(bool hasValidAlbumName READ hasValidAlbumName NOTIFY trackDataChanged) Q_PROPERTY(QString albumArtist READ albumArtist NOTIFY trackDataChanged) Q_PROPERTY(bool hasValidAlbumArtist READ hasValidAlbumArtist NOTIFY trackDataChanged) Q_PROPERTY(QString genre READ genre NOTIFY trackDataChanged) Q_PROPERTY(bool hasValidGenre READ hasValidGenre NOTIFY trackDataChanged) Q_PROPERTY(QString composer READ composer NOTIFY trackDataChanged) Q_PROPERTY(bool hasValidComposer READ hasValidComposer NOTIFY trackDataChanged) Q_PROPERTY(QString lyricist READ lyricist NOTIFY trackDataChanged) Q_PROPERTY(bool hasValidLyricist READ hasValidLyricist NOTIFY trackDataChanged) Q_PROPERTY(QString comment READ comment NOTIFY trackDataChanged) Q_PROPERTY(bool hasValidComment READ hasValidComment NOTIFY trackDataChanged) Q_PROPERTY(int year READ year NOTIFY trackDataChanged) Q_PROPERTY(bool hasValidYear READ hasValidYear NOTIFY trackDataChanged) Q_PROPERTY(int trackNumber READ trackNumber NOTIFY trackDataChanged) Q_PROPERTY(bool hasValidTrackNumber READ hasValidTrackNumber NOTIFY trackDataChanged) Q_PROPERTY(int discNumber READ discNumber NOTIFY trackDataChanged) Q_PROPERTY(bool hasValidDiscNumber READ hasValidDiscNumber NOTIFY trackDataChanged) Q_PROPERTY(int channels READ channels NOTIFY trackDataChanged) Q_PROPERTY(bool hasValidChannels READ hasValidChannels NOTIFY trackDataChanged) Q_PROPERTY(int bitRate READ bitRate NOTIFY trackDataChanged) Q_PROPERTY(bool hasValidBitRate READ hasValidBitRate NOTIFY trackDataChanged) Q_PROPERTY(int sampleRate READ sampleRate NOTIFY trackDataChanged) Q_PROPERTY(bool hasValidSampleRate READ hasValidSampleRate NOTIFY trackDataChanged) Q_PROPERTY(QString resourceURI READ resourceURI NOTIFY trackDataChanged) Q_PROPERTY(QString fileName READ fileName NOTIFY trackDataChanged) Q_PROPERTY(QString duration READ duration NOTIFY trackDataChanged) Q_PROPERTY(int rating READ rating NOTIFY trackDataChanged) Q_PROPERTY(bool hasValidRating READ hasValidRating NOTIFY trackDataChanged) Q_PROPERTY(QUrl albumCover READ albumCover NOTIFY trackDataChanged) Q_PROPERTY(bool hasValidAlbumCover READ hasValidAlbumCover NOTIFY trackDataChanged) Q_PROPERTY(qulonglong databaseId READ databaseId NOTIFY trackDataChanged) public: explicit TrackDataHelper(QObject *parent = nullptr); ~TrackDataHelper() override; QString title() const; QString duration() const; QString resourceURI() const; QString fileName() const; const MusicAudioTrack& trackData() const; void setTrackData(const MusicAudioTrack &track); bool hasValidTitle() const; bool hasValidArtist() const; bool hasValidAlbumName() const; bool hasValidAlbumArtist() const; bool hasValidGenre() const; bool hasValidComposer() const; bool hasValidLyricist() const; bool hasValidComment() const; bool hasValidTrackNumber() const; bool hasValidDiscNumber() const; bool hasValidChannels() const; bool hasValidRating() const; bool hasValidBitRate() const; bool hasValidSampleRate() const; bool hasValidYear() const; bool hasValidAlbumCover() const; Q_SIGNALS: void trackDataChanged(); public: }; #endif // TRACKDATAHELPER_H diff --git a/src/trackslistener.cpp b/src/trackslistener.cpp index 05a6d4f9..0ac54fdf 100644 --- a/src/trackslistener.cpp +++ b/src/trackslistener.cpp @@ -1,201 +1,199 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #include "trackslistener.h" #include "databaseinterface.h" #include "filescanner.h" #include #include #include #include #include #include class TracksListenerPrivate { public: QSet mTracksByIdSet; QList> mTracksByNameSet; QList mTracksByFileNameSet; DatabaseInterface *mDatabase = nullptr; FileScanner mFileScanner; QMimeDatabase mMimeDb; }; TracksListener::TracksListener(DatabaseInterface *database, QObject *parent) : QObject(parent), d(std::make_unique()) { d->mDatabase = database; } TracksListener::~TracksListener() = default; void TracksListener::tracksAdded(const QList &allTracks) { for (const auto &oneTrack : allTracks) { if (d->mTracksByIdSet.contains(oneTrack.databaseId())) { Q_EMIT trackHasChanged(oneTrack); } if (d->mTracksByNameSet.isEmpty()) { return; } for (auto itTrack = d->mTracksByNameSet.begin(); itTrack != d->mTracksByNameSet.end(); ) { if (std::get<0>(*itTrack) != oneTrack.title()) { ++itTrack; continue; } if (std::get<1>(*itTrack) != oneTrack.artist()) { ++itTrack; continue; } if (std::get<2>(*itTrack) != oneTrack.albumName()) { ++itTrack; continue; } if (std::get<3>(*itTrack) != oneTrack.trackNumber()) { ++itTrack; continue; } if (std::get<4>(*itTrack) != oneTrack.discNumber()) { ++itTrack; continue; } Q_EMIT trackHasChanged(oneTrack); d->mTracksByIdSet.insert(oneTrack.databaseId()); itTrack = d->mTracksByNameSet.erase(itTrack); } } } void TracksListener::trackRemoved(qulonglong id) { if (d->mTracksByIdSet.contains(id)) { Q_EMIT trackHasBeenRemoved(id); } } void TracksListener::trackModified(const MusicAudioTrack &modifiedTrack) { if (d->mTracksByIdSet.contains(modifiedTrack.databaseId())) { Q_EMIT trackHasChanged(modifiedTrack); } } void TracksListener::trackByNameInList(const QString &title, const QString &artist, const QString &album, int trackNumber, int discNumber) { auto newTrackId = d->mDatabase->trackIdFromTitleAlbumTrackDiscNumber(title, artist, album, trackNumber, discNumber); if (newTrackId == 0) { auto newTrack = std::tuple(title, artist, album, trackNumber, discNumber); d->mTracksByNameSet.push_back(newTrack); return; } d->mTracksByIdSet.insert(newTrackId); auto newTrack = d->mDatabase->trackFromDatabaseId(newTrackId); if (newTrack.isValid()) { Q_EMIT trackHasChanged(newTrack); } } void TracksListener::trackByFileNameInList(const QUrl &fileName) { qDebug() << "TracksListener::trackByFileNameInList" << fileName; auto newTrackId = d->mDatabase->trackIdFromFileName(fileName); qDebug() << "TracksListener::trackByFileNameInList" << fileName << newTrackId; if (newTrackId == 0) { auto newTrack = scanOneFile(fileName); qDebug() << "TracksListener::trackByFileNameInList" << fileName << newTrack; if (newTrack.isValid()) { qDebug() << "TracksListener::trackByFileNameInList" << "trackHasChanged" << newTrack; Q_EMIT trackHasChanged(newTrack); return; } d->mTracksByFileNameSet.push_back(fileName); return; } d->mTracksByIdSet.insert(newTrackId); auto newTrack = d->mDatabase->trackFromDatabaseId(newTrackId); qDebug() << "TracksListener::trackByFileNameInList" << newTrackId << newTrack; if (newTrack.isValid()) { qDebug() << "TracksListener::trackByFileNameInList" << "trackHasChanged" << newTrack; Q_EMIT trackHasChanged(newTrack); } } void TracksListener::trackByIdInList(qulonglong newTrackId) { d->mTracksByIdSet.insert(newTrackId); auto newTrack = d->mDatabase->trackFromDatabaseId(newTrackId); if (newTrack.isValid()) { Q_EMIT trackHasChanged(newTrack); } } void TracksListener::newArtistInList(const QString &artist) { auto newTracks = d->mDatabase->tracksFromAuthor(artist); if (newTracks.isEmpty()) { return; } for (const auto &oneTrack : newTracks) { d->mTracksByIdSet.insert(oneTrack.databaseId()); } Q_EMIT albumAdded(newTracks); } MusicAudioTrack TracksListener::scanOneFile(const QUrl &scanFile) { return d->mFileScanner.scanOneFile(scanFile, d->mMimeDb); } #include "moc_trackslistener.cpp" diff --git a/src/trackslistener.h b/src/trackslistener.h index 5d0b202b..425c0725 100644 --- a/src/trackslistener.h +++ b/src/trackslistener.h @@ -1,76 +1,74 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef TRACKSLISTENER_H #define TRACKSLISTENER_H #include "elisaLib_export.h" #include #include "musicaudiotrack.h" #include class TracksListenerPrivate; class DatabaseInterface; class ELISALIB_EXPORT TracksListener : public QObject { Q_OBJECT public: explicit TracksListener(DatabaseInterface *database, QObject *parent = nullptr); ~TracksListener() override; Q_SIGNALS: void trackHasChanged(const MusicAudioTrack &audioTrack); void trackHasBeenRemoved(qulonglong id); void albumAdded(const QList &tracks); public Q_SLOTS: void tracksAdded(const QList &allTracks); void trackRemoved(qulonglong id); void trackModified(const MusicAudioTrack &modifiedTrack); void trackByNameInList(const QString &title, const QString &artist, const QString &album, int trackNumber, int discNumber); void trackByFileNameInList(const QUrl &fileName); void trackByIdInList(qulonglong newTrackId); void newArtistInList(const QString &artist); private: MusicAudioTrack scanOneFile(const QUrl &scanFile); std::unique_ptr d; }; #endif // TRACKSLISTENER_H diff --git a/src/upnp/didlparser.h b/src/upnp/didlparser.h index bec36bfe..01c043bd 100644 --- a/src/upnp/didlparser.h +++ b/src/upnp/didlparser.h @@ -1,162 +1,160 @@ /* * Copyright 2015-2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef DIDLPARSER_H #define DIDLPARSER_H #include "musicalbum.h" #include "musicaudiotrack.h" #include #include #include #include #include #include class UpnpControlAbstractServiceReply; class QDomNode; class UpnpControlContentDirectory; class DidlParserPrivate; class DidlParser : public QObject { Q_OBJECT Q_PROPERTY(QString browseFlag READ browseFlag WRITE setBrowseFlag NOTIFY browseFlagChanged) Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged) Q_PROPERTY(QString sortCriteria READ sortCriteria WRITE setSortCriteria NOTIFY sortCriteriaChanged) Q_PROPERTY(QString searchCriteria READ searchCriteria WRITE setSearchCriteria NOTIFY searchCriteriaChanged) Q_PROPERTY(QString parentId READ parentId WRITE setParentId NOTIFY parentIdChanged) Q_PROPERTY(UpnpControlContentDirectory* contentDirectory READ contentDirectory WRITE setContentDirectory NOTIFY contentDirectoryChanged) Q_PROPERTY(bool isDataValid READ isDataValid NOTIFY isDataValidChanged) public: explicit DidlParser(QObject *parent = nullptr); ~DidlParser() override; const QString& browseFlag() const; const QString& filter() const; const QString& sortCriteria() const; const QString& searchCriteria() const; UpnpControlContentDirectory* contentDirectory() const; bool isDataValid() const; void browse(int startIndex = 0, int maximumNmberOfResults = 0); void search(int startIndex = 0, int maximumNumberOfResults = 0); QString parentId() const; const QVector &newAlbumIds() const; const QHash &newAlbums() const; const QVector &newMusicTrackIds() const; const QList &newMusicTracks() const; const QHash& covers() const; Q_SIGNALS: void browseFlagChanged(); void filterChanged(); void sortCriteriaChanged(); void searchCriteriaChanged(); void contentDirectoryChanged(); void isDataValidChanged(const QString &uuid, const QString &parentId); void parentIdChanged(); public Q_SLOTS: void setBrowseFlag(const QString &flag); void setFilter(const QString &flag); void setSortCriteria(const QString &criteria); void setSearchCriteria(const QString &criteria); void setContentDirectory(UpnpControlContentDirectory *directory); void setParentId(QString parentId); void systemUpdateIDChanged(); private Q_SLOTS: void browseFinished(UpnpControlAbstractServiceReply *self); void searchFinished(UpnpControlAbstractServiceReply *self); private: void decodeContainerNode(const QDomNode &containerNode, QHash &newData, QVector &newDataIds); void decodeAudioTrackNode(const QDomNode &itemNode, QHash &newData, QVector &newDataIds); void groupNewTracksByAlbums(); std::unique_ptr d; }; #endif // DIDLPARSER_H diff --git a/src/upnp/upnpcontentdirectorymodel.h b/src/upnp/upnpcontentdirectorymodel.h index 7619e26a..b94d6ad1 100644 --- a/src/upnp/upnpcontentdirectorymodel.h +++ b/src/upnp/upnpcontentdirectorymodel.h @@ -1,169 +1,167 @@ /* * Copyright 2015 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef UPNPCONTENTDIRECTORYMODEL_H #define UPNPCONTENTDIRECTORYMODEL_H #include "upnpQt_export.h" #include #include class UpnpContentDirectoryModelPrivate; class UpnpSsdpEngine; class UpnpControlAbstractDevice; class UpnpControlContentDirectory; class UpnpDiscoveryResult; class UPNPQT_EXPORT UpnpContentDirectoryModel : public QAbstractItemModel { Q_OBJECT Q_PROPERTY(QString browseFlag READ browseFlag WRITE setBrowseFlag NOTIFY browseFlagChanged) Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged) Q_PROPERTY(QString sortCriteria READ sortCriteria WRITE setSortCriteria NOTIFY sortCriteriaChanged) Q_PROPERTY(UpnpControlContentDirectory* contentDirectory READ contentDirectory WRITE setContentDirectory NOTIFY contentDirectoryChanged) Q_PROPERTY(bool useLocalIcons READ useLocalIcons WRITE setUseLocalIcons NOTIFY useLocalIconsChanged) public: enum ItemClass { Container = 0, Album = 1, AudioTrack = 2, }; Q_ENUM(ItemClass) enum ColumnsRoles { TitleRole = Qt::UserRole + 1, DurationRole = TitleRole + 1, CreatorRole = DurationRole + 1, ArtistRole = CreatorRole + 1, AlbumRole = ArtistRole + 1, RatingRole = AlbumRole + 1, ImageRole = RatingRole + 1, ResourceRole = ImageRole + 1, ItemClassRole = ResourceRole + 1, CountRole = ItemClassRole + 1, IdRole = CountRole + 1, ParentIdRole = IdRole + 1, IsPlayingRole = ParentIdRole + 1, }; Q_ENUM(ColumnsRoles) explicit UpnpContentDirectoryModel(QObject *parent = nullptr); ~UpnpContentDirectoryModel() override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; QHash roleNames() const override; Qt::ItemFlags flags(const QModelIndex &index) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; QModelIndex parent(const QModelIndex &child) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; bool canFetchMore(const QModelIndex &parent) const override; void fetchMore(const QModelIndex &parent) override; const QString& browseFlag() const; void setBrowseFlag(const QString &flag); const QString& filter() const; void setFilter(const QString &flag); const QString& sortCriteria() const; void setSortCriteria(const QString &criteria); UpnpControlContentDirectory* contentDirectory() const; void setContentDirectory(UpnpControlContentDirectory *directory); bool useLocalIcons() const; void setUseLocalIcons(bool value); Q_INVOKABLE QString objectIdByIndex(const QModelIndex &index) const; Q_INVOKABLE QVariant getUrl(const QModelIndex &index) const; Q_INVOKABLE QModelIndex indexFromId(const QString &id) const; Q_SIGNALS: void browseFlagChanged(); void filterChanged(); void sortCriteriaChanged(); void contentDirectoryChanged(); void useLocalIconsChanged(); public Q_SLOTS: void browseFinished(const QString &result, int numberReturned, int totalMatches, int systemUpdateID, bool success); private Q_SLOTS: private: QModelIndex indexFromInternalId(quintptr internalId) const; std::unique_ptr d; }; Q_DECLARE_METATYPE(UpnpContentDirectoryModel::ItemClass) #endif // UPNPCONTENTDIRECTORYMODEL_H diff --git a/src/upnp/upnpcontrolconnectionmanager.h b/src/upnp/upnpcontrolconnectionmanager.h index 81e571d0..a1bd36f8 100644 --- a/src/upnp/upnpcontrolconnectionmanager.h +++ b/src/upnp/upnpcontrolconnectionmanager.h @@ -1,110 +1,108 @@ /* * Copyright 2015 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef UPNPCONTROLCONNECTIONMANAGER_H #define UPNPCONTROLCONNECTIONMANAGER_H #include "upnpQt_export.h" #include "upnpcontrolabstractservice.h" #include "upnpbasictypes.h" #include class UpnpControlConnectionManagerPrivate; class UPNPQT_EXPORT UpnpControlConnectionManager : public UpnpControlAbstractService { Q_OBJECT Q_PROPERTY(QString sourceProtocolInfo READ sourceProtocolInfo NOTIFY sourceProtocolInfoChanged) Q_PROPERTY(QString sinkProtocolInfo READ sinkProtocolInfo NOTIFY sinkProtocolInfoChanged) Q_PROPERTY(QString currentConnectionIDs READ currentConnectionIDs NOTIFY currentConnectionIDsChanged) Q_PROPERTY(bool hasPrepareForConnection READ hasPrepareForConnection NOTIFY hasPrepareForConnectionChanged) Q_PROPERTY(bool hasConnectionComplete READ hasConnectionComplete NOTIFY hasConnectionCompleteChanged) public: explicit UpnpControlConnectionManager(QObject *parent = nullptr); ~UpnpControlConnectionManager() override; const QString& sourceProtocolInfo() const; const QString& sinkProtocolInfo() const; const QString& currentConnectionIDs() const; bool hasPrepareForConnection() const; bool hasConnectionComplete() const; public Q_SLOTS: UpnpControlAbstractServiceReply *getProtocolInfo(); UpnpControlAbstractServiceReply *prepareForConnection(const QString &remoteProtocolInfo, const QString &remoteUDN, const QString &remoteServiceID, int remotePeerConnectionID, const QString &connectionDirection); UpnpControlAbstractServiceReply *connectionComplete(int currentConnectionID); UpnpControlAbstractServiceReply *getCurrentConnectionIDs(); UpnpControlAbstractServiceReply *getCurrentConnectionInfo(int currentConnectionID); Q_SIGNALS: void sourceProtocolInfoChanged(const QString &protocolInfo); void sinkProtocolInfoChanged(const QString &protocolInfo); void currentConnectionIDsChanged(const QString &ids); void hasPrepareForConnectionChanged(); void hasConnectionCompleteChanged(); private Q_SLOTS: protected: void parseServiceDescription(QIODevice *serviceDescriptionContent) override; void parseEventNotification(const QString &eventName, const QString &eventValue) Q_DECL_OVERRIDE; private: std::unique_ptr d; }; #endif // UPNPCONTROLCONNECTIONMANAGER_H diff --git a/src/upnp/upnpcontrolcontentdirectory.h b/src/upnp/upnpcontrolcontentdirectory.h index be5065f1..78d53fbc 100644 --- a/src/upnp/upnpcontrolcontentdirectory.h +++ b/src/upnp/upnpcontrolcontentdirectory.h @@ -1,114 +1,112 @@ /* * Copyright 2015-2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef UPNPCONTROLCONTENTDIRECTORY_H #define UPNPCONTROLCONTENTDIRECTORY_H #include "upnpcontrolabstractservice.h" #include "upnpbasictypes.h" #include class UpnpControlContentDirectoryPrivate; class UpnpControlAbstractServiceReply; class UpnpControlContentDirectory : public UpnpControlAbstractService { Q_OBJECT Q_PROPERTY(QString searchCapabilities READ searchCapabilities NOTIFY searchCapabilitiesChanged) Q_PROPERTY(QString transferIDs READ transferIDs NOTIFY transferIDsChanged) Q_PROPERTY(bool hasTransferIDs READ hasTransferIDs NOTIFY hasTransferIDsChanged) Q_PROPERTY(QString sortCapabilities READ sortCapabilities NOTIFY sortCapabilitiesChanged) Q_PROPERTY(int systemUpdateID READ systemUpdateID NOTIFY systemUpdateIDChanged) public: explicit UpnpControlContentDirectory(QObject *parent = nullptr); ~UpnpControlContentDirectory() override; const QString& searchCapabilities() const; const QString& transferIDs() const; bool hasTransferIDs() const; const QString& sortCapabilities() const; int systemUpdateID() const; public Q_SLOTS: UpnpControlAbstractServiceReply* getSearchCapabilities(); UpnpControlAbstractServiceReply* getSortCapabilities(); UpnpControlAbstractServiceReply* getSystemUpdateID(); UpnpControlAbstractServiceReply* search(const QString &objectID, const QString &searchCriteria, const QString &filter, int startingIndex, int requestedCount, const QString &sortCriteria); UpnpControlAbstractServiceReply* browse(const QString &objectID, const QString &browseFlag, const QString &filter, int startingIndex, int requestedCount, const QString &sortCriteria); Q_SIGNALS: void searchCapabilitiesChanged(const QString &capabilities); void transferIDsChanged(const QString &ids); void hasTransferIDsChanged(); void sortCapabilitiesChanged(const QString &capabilities); void systemUpdateIDChanged(int id); private Q_SLOTS: protected: void parseServiceDescription(QIODevice *serviceDescriptionContent) override; void parseEventNotification(const QString &eventName, const QString &eventValue) Q_DECL_OVERRIDE; private: std::unique_ptr d; }; #endif // UPNPCONTROLCONTENTDIRECTORY_H diff --git a/src/upnp/upnpcontrolmediaserver.h b/src/upnp/upnpcontrolmediaserver.h index 53050eac..7be82d14 100644 --- a/src/upnp/upnpcontrolmediaserver.h +++ b/src/upnp/upnpcontrolmediaserver.h @@ -1,61 +1,59 @@ /* * Copyright 2015 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef UPNPCONTROLMEDIASERVER_H #define UPNPCONTROLMEDIASERVER_H #include "upnpcontrolabstractdevice.h" #include class UpnpControlConnectionManager; class UpnpControlMediaServerPrivate; class UpnpControlMediaServer : public UpnpControlAbstractDevice { Q_OBJECT Q_PROPERTY(bool hasAVTransport READ hasAVTransport NOTIFY hasAVTransportChanged) public: explicit UpnpControlMediaServer(QObject *parent = nullptr); ~UpnpControlMediaServer() override; bool hasAVTransport() const; Q_SIGNALS: void hasAVTransportChanged(); protected: //void parseDeviceDescription(QIODevice *deviceDescriptionContent, const QString &fallBackURLBase) override; private: std::unique_ptr d; }; #endif // UPNPCONTROLMEDIASERVER_H diff --git a/src/upnp/upnpdiscoverallmusic.h b/src/upnp/upnpdiscoverallmusic.h index 7260d345..a7c43464 100644 --- a/src/upnp/upnpdiscoverallmusic.h +++ b/src/upnp/upnpdiscoverallmusic.h @@ -1,120 +1,118 @@ /* * Copyright 2016 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef UPNPDISCOVERALLMUSIC_H #define UPNPDISCOVERALLMUSIC_H #include #include #include class DatabaseInterface; class UpnpDiscoveryResult; class UpnpDiscoverAllMusicPrivate; class UpnpDiscoverAllMusic : public QObject { Q_OBJECT Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged) Q_PROPERTY(QString browseFlag READ browseFlag WRITE setBrowseFlag NOTIFY browseFlagChanged) Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged) Q_PROPERTY(QString sortCriteria READ sortCriteria WRITE setSortCriteria NOTIFY sortCriteriaChanged) Q_PROPERTY(DatabaseInterface* albumDatabase READ albumDatabase WRITE setAlbumDatabase NOTIFY albumDatabaseChanged) public: explicit UpnpDiscoverAllMusic(QObject *parent = nullptr); ~UpnpDiscoverAllMusic() override; QString deviceId() const; const QString& browseFlag() const; const QString& filter() const; const QString& sortCriteria() const; DatabaseInterface* albumDatabase() const; Q_SIGNALS: void deviceIdChanged(QString deviceId); void browseFlagChanged(); void filterChanged(); void sortCriteriaChanged(); void albumDatabaseChanged(); public Q_SLOTS: void newDevice(QSharedPointer serviceDiscovery); void removedDevice(QSharedPointer serviceDiscovery); void setDeviceId(QString deviceId); void setBrowseFlag(const QString &flag); void setFilter(const QString &flag); void setSortCriteria(const QString &criteria); void setAlbumDatabase(DatabaseInterface* albumDatabase); private Q_SLOTS: void deviceDescriptionChanged(const QString &uuid); void descriptionParsed(const QString &UDN); void contentChanged(const QString &uuid, const QString &parentId); private: std::unique_ptr d; }; #endif // UPNPDISCOVERALLMUSIC_H diff --git a/src/upnp/upnplistener.h b/src/upnp/upnplistener.h index ffe34b90..a447e50d 100644 --- a/src/upnp/upnplistener.h +++ b/src/upnp/upnplistener.h @@ -1,75 +1,73 @@ /* * Copyright 2016-2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ #ifndef UPNPLISTENER_H #define UPNPLISTENER_H #include #include #include #include class UpnpListenerPrivate; class DatabaseInterface; class UpnpDiscoverAllMusic; class UpnpSsdpEngine; class MusicAudioTrack; class UpnpListener : public QObject { Q_OBJECT Q_PROPERTY(DatabaseInterface* databaseInterface READ databaseInterface WRITE setDatabaseInterface NOTIFY databaseInterfaceChanged) public: explicit UpnpListener(QObject *parent = nullptr); ~UpnpListener() override; DatabaseInterface* databaseInterface() const; Q_SIGNALS: void databaseInterfaceChanged(); void databaseReady(); void initialTracksListRequired(QString musicSource); void initialTracksList(QString musicSource, QList initialList); public Q_SLOTS: void setDatabaseInterface(DatabaseInterface* databaseInterface); void applicationAboutToQuit(); private: std::unique_ptr d; }; #endif // UPNPLISTENER_H diff --git a/src/windows/LabelWithToolTip.qml b/src/windows/LabelWithToolTip.qml index 8adeef77..2670de60 100644 --- a/src/windows/LabelWithToolTip.qml +++ b/src/windows/LabelWithToolTip.qml @@ -1,48 +1,46 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.2 import QtGraphicalEffects 1.0 import QtQuick.Window 2.2 Label { id: theLabel Loader { anchors.fill: parent active: theLabel.truncated visible: theLabel.truncated MouseArea { anchors.fill: parent hoverEnabled: true ToolTip { delay: Qt.styleHints.mousePressAndHoldInterval visible: parent.containsMouse && theLabel.truncated text: theLabel.text enter: Transition { NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad; from: 0.0; to: 1.0; duration: 300; } } exit: Transition { NumberAnimation { properties: "opacity"; easing.type: Easing.InOutQuad; from: 1.0; to: 0.0; duration: 300; } } } } } } diff --git a/src/windows/PlatformIntegration.qml b/src/windows/PlatformIntegration.qml index 6e5ab28d..c186aee3 100644 --- a/src/windows/PlatformIntegration.qml +++ b/src/windows/PlatformIntegration.qml @@ -1,70 +1,68 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . */ import QtQuick 2.0 import org.kde.elisa 1.0 import QtWinExtras 1.0 Item { id: rootItem property var playListModel property var audioPlayerManager property var player property var headerBarManager property var manageMediaPlayerControl signal raisePlayer() Theme { id: elisaTheme } TaskbarButton { progress.minimum: 0 progress.maximum: player.duration progress.value: player.position progress.visible: manageMediaPlayerControl.musicPlaying overlay.iconSource: (manageMediaPlayerControl.musicPlaying ? Qt.resolvedUrl(elisaTheme.playingIndicatorIcon) : Qt.resolvedUrl(elisaTheme.pausedIndicatorIcon)) } ThumbnailToolBar { iconicThumbnailSource: (headerBarManager.image.toString() !== '' ? headerBarManager.image : Qt.resolvedUrl(elisaTheme.albumCover)) ThumbnailToolButton { iconSource: Qt.resolvedUrl(LayoutMirroring.enabled ? elisaTheme.skipForwardIcon : elisaTheme.skipBackwardIcon) onClicked: playListModel.skipPreviousTrack() enabled: manageMediaPlayerControl.skipBackwardControlEnabled } ThumbnailToolButton { iconSource: (manageMediaPlayerControl.musicPlaying ? Qt.resolvedUrl(elisaTheme.pauseIcon) : Qt.resolvedUrl(elisaTheme.playIcon)) onClicked: audioPlayerManager.playPause() enabled: manageMediaPlayerControl.playControlEnabled } ThumbnailToolButton { iconSource: Qt.resolvedUrl(LayoutMirroring.enabled ? elisaTheme.skipBackwardIcon : elisaTheme.skipForwardIcon) onClicked: playListModel.skipNextTrack() enabled: manageMediaPlayerControl.skipForwardControlEnabled } } } diff --git a/src/windows/WindowsTheme.qml b/src/windows/WindowsTheme.qml index ab8a14ba..650ca7d9 100644 --- a/src/windows/WindowsTheme.qml +++ b/src/windows/WindowsTheme.qml @@ -1,25 +1,23 @@ /* * Copyright 2017 Matthieu Gallien * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public + * 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 library is distributed in the hope that it will be useful, + * 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 - * Library General Public License for more details. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * 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.2 BaseTheme { property real mediaPlayerControlOpacity: 0.8 }