Commit c6ac1306 authored by Alexander Stippich's avatar Alexander Stippich

Factor out dataTypes from databaseinterface

Summary:
Factor out the type definitions from the
databaseinterface so that the database
is not pulled in everywhere

Reviewers: mgallien

Reviewed By: mgallien

Tags: #elisa

Differential Revision: https://phabricator.kde.org/D23844
parent 2e874214
......@@ -106,7 +106,7 @@ private Q_SLOTS:
auto firstTrack = musicDb.trackDataFromDatabaseId(trackId);
musicDb.removeTracksList({firstTrack[DatabaseInterface::ResourceRole].toUrl()});
musicDb.removeTracksList({firstTrack[DataTypes::ResourceRole].toUrl()});
QCOMPARE(beginInsertRowsSpy.count(), 1);
QCOMPARE(endInsertRowsSpy.count(), 1);
......@@ -175,10 +175,10 @@ private Q_SLOTS:
QStringLiteral("album3"), 3, 1);
auto thirdTrack = musicDb.trackDataFromDatabaseId(thirdTrackId);
musicDb.removeTracksList({firstTrack[DatabaseInterface::ResourceRole].toUrl()
musicDb.removeTracksList({firstTrack[DataTypes::ResourceRole].toUrl()
,
secondTrack[DatabaseInterface::ResourceRole].toUrl(),
thirdTrack[DatabaseInterface::ResourceRole].toUrl()});
secondTrack[DataTypes::ResourceRole].toUrl(),
thirdTrack[DataTypes::ResourceRole].toUrl()});
QCOMPARE(beginInsertRowsSpy.count(), 1);
QCOMPARE(endInsertRowsSpy.count(), 1);
......@@ -412,8 +412,8 @@ private Q_SLOTS:
auto changedIndex = dataChangedSignal.constFirst().toModelIndex();
QCOMPARE(proxyTracksModel.data(changedIndex, DatabaseInterface::ColumnsRoles::RatingRole).isValid(), true);
QCOMPARE(proxyTracksModel.data(changedIndex, DatabaseInterface::ColumnsRoles::RatingRole).toInt(), 5);
QCOMPARE(proxyTracksModel.data(changedIndex, DataTypes::ColumnsRoles::RatingRole).isValid(), true);
QCOMPARE(proxyTracksModel.data(changedIndex, DataTypes::ColumnsRoles::RatingRole).toInt(), 5);
}
void addEmptyTracksList()
......
......@@ -18,6 +18,7 @@
#include "databasetestdata.h"
#include "databaseinterface.h"
#include "datatypes.h"
#include "musicaudiotrack.h"
#include "config-upnp-qt.h"
......@@ -56,14 +57,14 @@ private Q_SLOTS:
qRegisterMetaType<QVector<qlonglong>>("QVector<qlonglong>");
qRegisterMetaType<QHash<qlonglong,int>>("QHash<qlonglong,int>");
qRegisterMetaType<QHash<QUrl,QDateTime>>("QHash<QUrl,QDateTime>");
qRegisterMetaType<DatabaseInterface::ListTrackDataType>("ListTrackDataType");
qRegisterMetaType<DatabaseInterface::ListAlbumDataType>("ListAlbumDataType");
qRegisterMetaType<DatabaseInterface::ListArtistDataType>("ListArtistDataType");
qRegisterMetaType<DatabaseInterface::ListGenreDataType>("ListGenreDataType");
qRegisterMetaType<DatabaseInterface::TrackDataType>("TrackDataType");
qRegisterMetaType<DatabaseInterface::AlbumDataType>("AlbumDataType");
qRegisterMetaType<DatabaseInterface::ArtistDataType>("ArtistDataType");
qRegisterMetaType<DatabaseInterface::GenreDataType>("GenreDataType");
qRegisterMetaType<DataTypes::ListTrackDataType>("ListTrackDataType");
qRegisterMetaType<DataTypes::ListAlbumDataType>("ListAlbumDataType");
qRegisterMetaType<DataTypes::ListArtistDataType>("ListArtistDataType");
qRegisterMetaType<DataTypes::ListGenreDataType>("ListGenreDataType");
qRegisterMetaType<DataTypes::TrackDataType>("TrackDataType");
qRegisterMetaType<DataTypes::AlbumDataType>("AlbumDataType");
qRegisterMetaType<DataTypes::ArtistDataType>("ArtistDataType");
qRegisterMetaType<DataTypes::GenreDataType>("GenreDataType");
}
void avoidCrashInTrackIdFromTitleAlbumArtist()
......@@ -174,7 +175,7 @@ private Q_SLOTS:
QCOMPARE(albumData.count(), 1);
QCOMPARE(album.title(), QStringLiteral("album3"));
QCOMPARE(album.artist(), QStringLiteral("artist2"));
QCOMPARE(album[DatabaseInterface::ColumnsRoles::SecondaryTextRole], QStringLiteral("artist2"));
QCOMPARE(album[DataTypes::ColumnsRoles::SecondaryTextRole], QStringLiteral("artist2"));
QVERIFY(album.isValidArtist());
QCOMPARE(album.albumArtURI(), QUrl::fromLocalFile(QStringLiteral("album3")));
QCOMPARE(album.isSingleDiscAlbum(), true);
......@@ -2215,7 +2216,7 @@ private Q_SLOTS:
QStringLiteral("album1"), 1, 1);
QCOMPARE(removedTrackId, qulonglong(0));
firstTrack[DatabaseInterface::DatabaseIdRole] = 0;
firstTrack[DataTypes::DatabaseIdRole] = 0;
musicDb.insertTracksList({MusicAudioTrack::trackFromData(firstTrack)}, mNewCovers);
......@@ -4291,7 +4292,7 @@ private Q_SLOTS:
const auto &modifiedTrackSignal = musicDbTrackModifiedSpy.at(0);
QCOMPARE(modifiedTrackSignal.count(), 1);
const auto &modifiedTrack = modifiedTrackSignal.at(0).value<DatabaseInterface::TrackDataType>();
const auto &modifiedTrack = modifiedTrackSignal.at(0).value<DataTypes::TrackDataType>();
auto modifiedTrackTitle = modifiedTrack.title();
auto modifiedTrackArtist = modifiedTrack.artist();
......@@ -5163,17 +5164,17 @@ private Q_SLOTS:
const auto newAlbumSignal = musicDbAlbumAddedSpy.at(0);
QCOMPARE(newAlbumSignal.size(), 1);
const auto newAlbums = newAlbumSignal.at(0).value<DatabaseInterface::ListAlbumDataType>();
const auto newAlbums = newAlbumSignal.at(0).value<DataTypes::ListAlbumDataType>();
QCOMPARE(newAlbums.size(), 1);
const auto newAlbum = newAlbums.at(0);
QCOMPARE(newAlbum.title(), QStringLiteral("album3"));
QCOMPARE(newAlbum.artist(), QStringLiteral("Various Artists"));
QCOMPARE(newAlbum[DatabaseInterface::ColumnsRoles::SecondaryTextRole], QStringLiteral("Various Artists"));
QCOMPARE(newAlbum[DataTypes::ColumnsRoles::SecondaryTextRole], QStringLiteral("Various Artists"));
const auto oneAlbum = musicDb.allAlbumsData().at(0);
QCOMPARE(oneAlbum.title(), QStringLiteral("album3"));
QCOMPARE(oneAlbum.artist(), QStringLiteral("Various Artists"));
QCOMPARE(oneAlbum[DatabaseInterface::ColumnsRoles::SecondaryTextRole], QStringLiteral("Various Artists"));
QCOMPARE(oneAlbum[DataTypes::ColumnsRoles::SecondaryTextRole], QStringLiteral("Various Artists"));
}
void testAlbumFromGenreAndArtistWithoutAlbumArtist()
......
......@@ -19,6 +19,7 @@
#include "musicaudiotrack.h"
#include "databaseinterface.h"
#include "datatypes.h"
#include "models/datamodel.h"
#include <QObject>
......@@ -109,7 +110,7 @@ private Q_SLOTS:
auto firstTrack = musicDb.trackDataFromDatabaseId(trackId);
musicDb.removeTracksList({firstTrack[DatabaseInterface::ResourceRole].toUrl()});
musicDb.removeTracksList({firstTrack[DataTypes::ResourceRole].toUrl()});
QCOMPARE(albumsModel.rowCount(), 3);
QCOMPARE(beginInsertRowsSpy.count(), 1);
......@@ -182,9 +183,9 @@ private Q_SLOTS:
QStringLiteral("album3"), 3, 1);
auto thirdTrack = musicDb.trackDataFromDatabaseId(thirdTrackId);
musicDb.removeTracksList({firstTrack[DatabaseInterface::ResourceRole].toUrl(),
secondTrack[DatabaseInterface::ResourceRole].toUrl(),
thirdTrack[DatabaseInterface::ResourceRole].toUrl()});
musicDb.removeTracksList({firstTrack[DataTypes::ResourceRole].toUrl(),
secondTrack[DataTypes::ResourceRole].toUrl(),
thirdTrack[DataTypes::ResourceRole].toUrl()});
QCOMPARE(albumsModel.rowCount(), 0);
QCOMPARE(beginInsertRowsSpy.count(), 1);
......@@ -279,7 +280,7 @@ private Q_SLOTS:
QCOMPARE(beginInsertRowsSpy.at(1).at(1).toInt(), 4);
QCOMPARE(beginInsertRowsSpy.at(1).at(2).toInt(), 4);
QCOMPARE(albumsModel.data(albumsModel.index(4, 0), DatabaseInterface::ColumnsRoles::TitleRole).toString(), QStringLiteral("track6"));
QCOMPARE(albumsModel.data(albumsModel.index(4, 0), DataTypes::ColumnsRoles::TitleRole).toString(), QStringLiteral("track6"));
auto secondNewTrack = MusicAudioTrack{true, QStringLiteral("$24"), QStringLiteral("0"), QStringLiteral("track5"),
QStringLiteral("artist2"), QStringLiteral("album1"), QStringLiteral("Various Artists"), 5, 1,
......@@ -307,7 +308,7 @@ private Q_SLOTS:
QCOMPARE(beginInsertRowsSpy.at(2).at(1).toInt(), 4);
QCOMPARE(beginInsertRowsSpy.at(2).at(2).toInt(), 4);
QCOMPARE(albumsModel.data(albumsModel.index(4, 0), DatabaseInterface::ColumnsRoles::TitleRole).toString(), QStringLiteral("track5"));
QCOMPARE(albumsModel.data(albumsModel.index(4, 0), DataTypes::ColumnsRoles::TitleRole).toString(), QStringLiteral("track5"));
}
void modifyOneTrack()
......@@ -389,7 +390,7 @@ private Q_SLOTS:
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), DatabaseInterface::ColumnsRoles::TrackNumberRole).toInt(), 5);
QCOMPARE(albumsModel.data(albumsModel.index(2, 0), DataTypes::ColumnsRoles::TrackNumberRole).toInt(), 5);
}
......@@ -443,7 +444,7 @@ private Q_SLOTS:
auto firstTrack = musicDb.trackDataFromDatabaseId(trackId);
musicDb.removeTracksList({firstTrack[DatabaseInterface::ResourceRole].toUrl()});
musicDb.removeTracksList({firstTrack[DataTypes::ResourceRole].toUrl()});
QCOMPARE(beginInsertRowsSpy.count(), 1);
QCOMPARE(endInsertRowsSpy.count(), 1);
......@@ -509,9 +510,9 @@ private Q_SLOTS:
QStringLiteral("album3"), 3, 1);
auto thirdTrack = musicDb.trackDataFromDatabaseId(thirdTrackId);
musicDb.removeTracksList({firstTrack[DatabaseInterface::ResourceRole].toUrl(),
secondTrack[DatabaseInterface::ResourceRole].toUrl(),
thirdTrack[DatabaseInterface::ResourceRole].toUrl()});
musicDb.removeTracksList({firstTrack[DataTypes::ResourceRole].toUrl(),
secondTrack[DataTypes::ResourceRole].toUrl(),
thirdTrack[DataTypes::ResourceRole].toUrl()});
QCOMPARE(beginInsertRowsSpy.count(), 1);
QCOMPARE(endInsertRowsSpy.count(), 1);
......@@ -737,8 +738,8 @@ private Q_SLOTS:
auto changedIndex = dataChangedSignal.constFirst().toModelIndex();
QCOMPARE(tracksModel.data(changedIndex, DatabaseInterface::ColumnsRoles::RatingRole).isValid(), true);
QCOMPARE(tracksModel.data(changedIndex, DatabaseInterface::ColumnsRoles::RatingRole).toInt(), 5);
QCOMPARE(tracksModel.data(changedIndex, DataTypes::ColumnsRoles::RatingRole).isValid(), true);
QCOMPARE(tracksModel.data(changedIndex, DataTypes::ColumnsRoles::RatingRole).toInt(), 5);
}
void addEmptyTracksListAllTracks()
......@@ -887,7 +888,7 @@ private Q_SLOTS:
QVERIFY(!firstTrack.isEmpty());
musicDb.removeTracksList({firstTrack[DatabaseInterface::ResourceRole].toUrl()});
musicDb.removeTracksList({firstTrack[DataTypes::ResourceRole].toUrl()});
QCOMPARE(albumsModel.rowCount(), 5);
QCOMPARE(beginInsertRowsSpy.count(), 1);
......@@ -952,9 +953,9 @@ private Q_SLOTS:
QStringLiteral("album3"), 3, 1);
auto thirdTrack = musicDb.trackDataFromDatabaseId(thirdTrackId);
musicDb.removeTracksList({firstTrack[DatabaseInterface::ResourceRole].toUrl(),
secondTrack[DatabaseInterface::ResourceRole].toUrl(),
thirdTrack[DatabaseInterface::ResourceRole].toUrl()});
musicDb.removeTracksList({firstTrack[DataTypes::ResourceRole].toUrl(),
secondTrack[DataTypes::ResourceRole].toUrl(),
thirdTrack[DataTypes::ResourceRole].toUrl()});
QCOMPARE(albumsModel.rowCount(), 4);
QCOMPARE(beginInsertRowsSpy.count(), 1);
......@@ -1145,7 +1146,7 @@ private Q_SLOTS:
auto firstTrack = musicDb.trackDataFromDatabaseId(trackId);
musicDb.removeTracksList({firstTrack[DatabaseInterface::ResourceRole].toUrl()});
musicDb.removeTracksList({firstTrack[DataTypes::ResourceRole].toUrl()});
QCOMPARE(artistsModel.rowCount(), 6);
QCOMPARE(beginInsertRowsSpy.count(), 1);
......
......@@ -4442,7 +4442,7 @@ void MediaPlayListTest::testTrackBeenRemoved()
QVERIFY(!removedTrack.isEmpty());
myPlayList.trackRemoved(removedTrack[DatabaseInterface::DatabaseIdRole].toULongLong());
myPlayList.trackRemoved(removedTrack[DataTypes::DatabaseIdRole].toULongLong());
QCOMPARE(rowsAboutToBeRemovedSpy.count(), 0);
QCOMPARE(rowsAboutToBeMovedSpy.count(), 0);
......
......@@ -56,9 +56,9 @@ private Q_SLOTS:
QCOMPARE(endRemovedRowsSpy.count(), 0);
QCOMPARE(myModel.rowCount(), 0);
auto trackData = TrackMetadataModel::TrackDataType{{DatabaseInterface::DatabaseIdRole, 1},
{DatabaseInterface::TitleRole, QStringLiteral("title")},
{DatabaseInterface::AlbumRole, QStringLiteral("album")}};
auto trackData = TrackMetadataModel::TrackDataType{{DataTypes::DatabaseIdRole, 1},
{DataTypes::TitleRole, QStringLiteral("title")},
{DataTypes::AlbumRole, QStringLiteral("album")}};
myModel.trackData(trackData);
QCOMPARE(beginResetSpy.count(), 1);
......
......@@ -20,6 +20,7 @@
#include "trackslistener.h"
#include "mediaplaylist.h"
#include "databaseinterface.h"
#include "datatypes.h"
#include "config-upnp-qt.h"
......@@ -58,14 +59,14 @@ private Q_SLOTS:
qRegisterMetaType<QVector<qlonglong>>("QVector<qlonglong>");
qRegisterMetaType<QHash<qlonglong,int>>("QHash<qlonglong,int>");
qRegisterMetaType<QList<QUrl>>("QList<QUrl>");
qRegisterMetaType<DatabaseInterface::ListTrackDataType>("ListTrackDataType");
qRegisterMetaType<DatabaseInterface::ListAlbumDataType>("ListAlbumDataType");
qRegisterMetaType<DatabaseInterface::ListArtistDataType>("ListArtistDataType");
qRegisterMetaType<DatabaseInterface::ListGenreDataType>("ListGenreDataType");
qRegisterMetaType<DatabaseInterface::TrackDataType>("TrackDataType");
qRegisterMetaType<DatabaseInterface::AlbumDataType>("AlbumDataType");
qRegisterMetaType<DatabaseInterface::ArtistDataType>("ArtistDataType");
qRegisterMetaType<DatabaseInterface::GenreDataType>("GenreDataType");
qRegisterMetaType<DataTypes::ListTrackDataType>("ListTrackDataType");
qRegisterMetaType<DataTypes::ListAlbumDataType>("ListAlbumDataType");
qRegisterMetaType<DataTypes::ListArtistDataType>("ListArtistDataType");
qRegisterMetaType<DataTypes::ListGenreDataType>("ListGenreDataType");
qRegisterMetaType<DataTypes::TrackDataType>("TrackDataType");
qRegisterMetaType<DataTypes::AlbumDataType>("AlbumDataType");
qRegisterMetaType<DataTypes::ArtistDataType>("ArtistDataType");
qRegisterMetaType<DataTypes::GenreDataType>("GenreDataType");
qRegisterMetaType<ElisaUtils::PlayListEntryType>("PlayListEntryType");
}
......
......@@ -5,6 +5,7 @@ set(elisaLib_SOURCES
musicaudiotrack.cpp
progressindicator.cpp
databaseinterface.cpp
datatypes.cpp
musiclistenersmanager.cpp
managemediaplayercontrol.cpp
manageheaderbar.cpp
......
This diff is collapsed.
......@@ -21,6 +21,7 @@
#include "elisaLib_export.h"
#include "elisautils.h"
#include "datatypes.h"
#include <QObject>
#include <QString>
......@@ -46,309 +47,6 @@ class ELISALIB_EXPORT DatabaseInterface : public QObject
public:
enum ColumnsRoles {
TitleRole = Qt::UserRole + 1,
SecondaryTextRole,
ImageUrlRole,
ShadowForImageRole,
ChildModelRole,
DurationRole,
StringDurationRole,
MilliSecondsDurationRole,
ArtistRole,
AllArtistsRole,
HighestTrackRating,
AlbumRole,
AlbumArtistRole,
IsValidAlbumArtistRole,
TrackNumberRole,
DiscNumberRole,
RatingRole,
GenreRole,
LyricistRole,
ComposerRole,
CommentRole,
YearRole,
ChannelsRole,
BitRateRole,
SampleRateRole,
ResourceRole,
IdRole,
DatabaseIdRole,
IsSingleDiscAlbumRole,
ContainerDataRole,
IsPartialDataRole,
AlbumIdRole,
HasEmbeddedCover,
FileModificationTime,
FirstPlayDate,
LastPlayDate,
PlayCounter,
PlayFrequency,
ElementTypeRole,
LyricsRole,
};
Q_ENUM(ColumnsRoles)
private:
using DataType = QMap<ColumnsRoles, QVariant>;
public:
class TrackDataType : public DataType
{
public:
using DataType::DataType;
bool isValid() const
{
return !isEmpty();
}
qulonglong databaseId() const
{
return operator[](key_type::DatabaseIdRole).toULongLong();
}
QString title() const
{
return operator[](key_type::TitleRole).toString();
}
QString artist() const
{
return operator[](key_type::ArtistRole).toString();
}
qulonglong albumId() const
{
return operator[](key_type::AlbumIdRole).toULongLong();
}
bool hasAlbum() const
{
return find(key_type::AlbumRole) != end();
}
QString album() const
{
return operator[](key_type::AlbumRole).toString();
}
QString albumArtist() const
{
return operator[](key_type::AlbumArtistRole).toString();
}
bool hasTrackNumber() const
{
return find(key_type::TrackNumberRole) != end();
}
int trackNumber() const
{
return operator[](key_type::TrackNumberRole).toInt();
}
bool hasDiscNumber() const
{
return find(key_type::DiscNumberRole) != end();
}
int discNumber() const
{
return operator[](key_type::DiscNumberRole).toInt();
}
QTime duration() const
{
return operator[](key_type::DurationRole).toTime();
}
QUrl resourceURI() const
{
return operator[](key_type::ResourceRole).toUrl();
}
QUrl albumCover() const
{
return operator[](key_type::ImageUrlRole).toUrl();
}
bool isSingleDiscAlbum() const
{
return operator[](key_type::IsSingleDiscAlbumRole).toBool();
}
int rating() const
{
return operator[](key_type::RatingRole).toInt();
}
QString genre() const
{
return operator[](key_type::GenreRole).toString();
}
QString composer() const
{
return operator[](key_type::ComposerRole).toString();
}
QString lyricist() const
{
return operator[](key_type::LyricistRole).toString();
}
QString lyrics() const
{
return operator[](key_type::LyricsRole).toString();
}
QString comment() const
{
return operator[](key_type::CommentRole).toString();
}
int year() const
{
return operator[](key_type::YearRole).toInt();
}
int channels() const
{
return operator[](key_type::ChannelsRole).toInt();
}
int bitRate() const
{
return operator[](key_type::BitRateRole).toInt();
}
int sampleRate() const
{
return operator[](key_type::SampleRateRole).toInt();
}
bool hasEmbeddedCover() const
{
return operator[](key_type::HasEmbeddedCover).toBool();
}
QDateTime fileModificationTime() const
{
return operator[](key_type::FileModificationTime).toDateTime();
}
};
using ListTrackDataType = QList<TrackDataType>;
using ListRadioDataType = QList<TrackDataType>;
class AlbumDataType : public DataType
{
public:
using DataType::DataType;
qulonglong databaseId() const
{
return operator[](key_type::DatabaseIdRole).toULongLong();
}
QString title() const
{
return operator[](key_type::TitleRole).toString();
}
QString artist() const
{
return operator[](key_type::ArtistRole).toString();
}
bool isValidArtist() const
{
const auto &artistData = operator[](key_type::ArtistRole);
return artistData.isValid() && !artistData.toString().isEmpty();
}
QStringList genres() const
{
return operator[](key_type::GenreRole).toStringList();
}
QUrl albumArtURI() const
{
return operator[](key_type::ImageUrlRole).toUrl();
}
bool isSingleDiscAlbum() const
{
return operator[](key_type::IsSingleDiscAlbumRole).toBool();
}
bool isValid() const
{
return !isEmpty();
}
};
using ListAlbumDataType = QList<AlbumDataType>;
class ArtistDataType : public DataType
{
public:
using DataType::DataType;
qulonglong databaseId() const
{
return operator[](key_type::DatabaseIdRole).toULongLong();
}
};
using ListArtistDataType = QList<ArtistDataType>;
class GenreDataType : public DataType
{
public:
using DataType::DataType;
qulonglong databaseId() const
{
return operator[](key_type::DatabaseIdRole).toULongLong();
}
QString title() const
{
return operator[](key_type::TitleRole).toString();
}
};
using ListGenreDataType = QList<GenreDataType>;
enum PropertyType {
DatabaseId,
DisplayRole,
SecondaryRole,
};
Q_ENUM(PropertyType)
enum AlbumDiscsCount {
SingleDiscAlbum,
MultipleDiscsAlbum,
};