Commit 84001921 authored by Jerome Guidon's avatar Jerome Guidon Committed by Matthieu Gallien

Add support for radio streams

Summary:
Add support for radio streams

Steps of development:
  - play a stream and get some information from it
  - Added a table for radios in the database (V13) with some examples in it.
  - Get the examples in the view and add/play them in the playlist.

Test Plan: after the first reviews, add test for the radios view

Reviewers: #elisa, #vdg, mgallien, astippich

Reviewed By: #elisa, mgallien, astippich

Subscribers: astippich, ngraham, mgallien, ndavis

Maniphest Tasks: T7567

Differential Revision: https://phabricator.kde.org/D21525
parent 286e46a8
......@@ -122,6 +122,8 @@ Q_SIGNALS:
void positionChanged(qint64 position);
void currentPlayingForRadiosChanged(QString title, QString nowPlaying);
void seekableChanged(bool seekable);
void playing();
......
......@@ -233,7 +233,15 @@ void AudioWrapper::setVolume(qreal volume)
void AudioWrapper::setSource(const QUrl &source)
{
d->mMedia = libvlc_media_new_path(d->mInstance, QDir::toNativeSeparators(source.toLocalFile()).toUtf8().constData());
if (source.isLocalFile()) {
qCDebug(orgKdeElisaPlayerVlc) << "AudioWrapper::setSource reading local resource";
d->mMedia = libvlc_media_new_path(d->mInstance, QDir::toNativeSeparators(source.toLocalFile()).toUtf8().constData());
} else {
qCDebug(orgKdeElisaPlayerVlc) << "AudioWrapper::setSource reading remote resource";
const char * charUrl = source.url().toUtf8().constData();
d->mMedia = libvlc_media_new_location(d->mInstance, charUrl);
}
if (!d->mMedia) {
qCDebug(orgKdeElisaPlayerVlc) << "AudioWrapper::setSource"
<< "failed creating media"
......@@ -557,6 +565,13 @@ void AudioWrapperPrivate::signalPositionChange(float newPosition)
mParent->playerPositionSignalChanges(mPreviousPosition);
}
if (this->mMedia) {
QString title = QLatin1String(libvlc_media_get_meta(this->mMedia, libvlc_meta_Title));
QString nowPlaying = QLatin1String(libvlc_media_get_meta(this->mMedia, libvlc_meta_NowPlaying));
Q_EMIT mParent->currentPlayingForRadiosChanged(title, nowPlaying);
}
}
void AudioWrapperPrivate::signalSeekableChange(bool isSeekable)
......
This diff is collapsed.
......@@ -246,6 +246,8 @@ public:
using ListTrackDataType = QList<TrackDataType>;
using ListRadioDataType = QList<TrackDataType>;
class AlbumDataType : public DataType
{
public:
......@@ -357,6 +359,8 @@ public:
ListTrackDataType allTracksData();
ListRadioDataType allRadiosData();
ListTrackDataType recentlyPlayedTracksData(int count);
ListTrackDataType frequentlyPlayedTracksData(int count);
......@@ -383,8 +387,9 @@ public:
TrackDataType trackDataFromDatabaseId(qulonglong id);
qulonglong trackIdFromTitleAlbumTrackDiscNumber(const QString &title, const QString &artist, const std::optional<QString> &album,
std::optional<int> trackNumber, std::optional<int> discNumber);
TrackDataType radioDataFromDatabaseId(qulonglong id);
qulonglong trackIdFromTitleAlbumTrackDiscNumber(const QString &title, const QString &artist, const std::optional<QString> &album, std::optional<int> trackNumber, std::optional<int> discNumber);
qulonglong trackIdFromFileName(const QUrl &fileName);
......@@ -426,6 +431,12 @@ Q_SIGNALS:
void finishRemovingTracksList();
void radioAdded(const DatabaseInterface::TrackDataType radio);
void radioModified(const DatabaseInterface::TrackDataType radio);
void radioRemoved(qulonglong radioId);
public Q_SLOTS:
void insertTracksList(const QList<MusicAudioTrack> &tracks, const QHash<QString, QUrl> &covers);
......@@ -438,6 +449,10 @@ public Q_SLOTS:
void clearData();
void insertRadio(const TrackDataType &oneTrack);
void removeRadio(qulonglong radioId);
private:
enum class TrackFileInsertType {
......@@ -472,6 +487,8 @@ private:
qulonglong internalTrackIdFromFileName(const QUrl &fileName);
qulonglong internalRadioIdFromHttpAddress(const QString &httpAddress);
ListTrackDataType internalTracksFromAuthor(const QString &artistName);
QList<qulonglong> internalAlbumIdsFromAuthor(const QString &artistName);
......@@ -515,6 +532,8 @@ private:
TrackDataType buildTrackDataFromDatabaseRecord(const QSqlRecord &trackRecord) const;
TrackDataType buildRadioDataFromDatabaseRecord(const QSqlRecord &trackRecord) const;
void internalRemoveTracksList(const QList<QUrl> &removedTracks);
void internalRemoveTracksList(const QHash<QUrl, QDateTime> &removedTracks, qulonglong sourceId);
......@@ -539,12 +558,16 @@ private:
ListTrackDataType internalAllTracksPartialData();
ListRadioDataType internalAllRadiosPartialData();
ListTrackDataType internalRecentlyPlayedTracksData(int count);
ListTrackDataType internalFrequentlyPlayedTracksData(int count);
TrackDataType internalOneTrackPartialData(qulonglong databaseId);
TrackDataType internalOneRadioPartialData(qulonglong databaseId);
ListGenreDataType internalAllGenresPartialData();
ListArtistDataType internalAllComposersPartialData();
......@@ -570,6 +593,8 @@ private:
void upgradeDatabaseV13();
void upgradeDatabaseV14();
void checkDatabaseSchema();
void checkAlbumsTableSchema();
......
......@@ -361,6 +361,7 @@ void ElisaApplication::initializePlayer()
QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::playerSourceChanged, d->mAudioWrapper.get(), &AudioWrapper::setSource);
QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::startedPlayingTrack,
d->mMusicManager->viewDatabase(), &DatabaseInterface::trackHasStartedPlaying);
QObject::connect(d->mAudioControl.get(), &ManageAudioPlayer::currentPlayingForRadiosChanged, d->mMediaPlayList.get(), &MediaPlayList::updateRadioData);
QObject::connect(d->mMediaPlayList.get(), &MediaPlayList::ensurePlay, d->mAudioControl.get(), &ManageAudioPlayer::ensurePlay);
QObject::connect(d->mMediaPlayList.get(), &MediaPlayList::playListFinished, d->mAudioControl.get(), &ManageAudioPlayer::playListFinished);
......@@ -368,7 +369,6 @@ void ElisaApplication::initializePlayer()
QObject::connect(d->mMediaPlayList.get(), &MediaPlayList::clearPlayListPlayer, d->mAudioControl.get(), &ManageAudioPlayer::saveForUndoClearPlaylist);
QObject::connect(d->mMediaPlayList.get(), &MediaPlayList::undoClearPlayListPlayer, d->mAudioControl.get(), &ManageAudioPlayer::restoreForUndoClearPlaylist);
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::playbackStateChanged,
d->mAudioControl.get(), &ManageAudioPlayer::setPlayerPlaybackState);
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::statusChanged, d->mAudioControl.get(), &ManageAudioPlayer::setPlayerStatus);
......@@ -376,6 +376,7 @@ void ElisaApplication::initializePlayer()
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::durationChanged, d->mAudioControl.get(), &ManageAudioPlayer::setAudioDuration);
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::seekableChanged, d->mAudioControl.get(), &ManageAudioPlayer::setPlayerIsSeekable);
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::positionChanged, d->mAudioControl.get(), &ManageAudioPlayer::setPlayerPosition);
QObject::connect(d->mAudioWrapper.get(), &AudioWrapper::currentPlayingForRadiosChanged, d->mAudioControl.get(), &ManageAudioPlayer::setCurrentPlayingForRadios);
d->mPlayerControl->setPlayListModel(d->mMediaPlayList.get());
QObject::connect(d->mMediaPlayList.get(), &MediaPlayList::currentTrackChanged, d->mPlayerControl.get(), &ManageMediaPlayerControl::setCurrentTrack);
......
......@@ -146,10 +146,12 @@ void ElisaQmlTestPlugin::registerTypes(const char *uri)
qRegisterMetaType<QVector<qulonglong>>("QVector<qulonglong>");
qRegisterMetaType<QHash<qulonglong,int>>("QHash<qulonglong,int>");
qRegisterMetaType<DatabaseInterface::ListTrackDataType>("DatabaseInterface::ListTrackDataType");
qRegisterMetaType<DatabaseInterface::ListRadioDataType>("DatabaseInterface::ListRadioDataType");
qRegisterMetaType<DatabaseInterface::ListAlbumDataType>("DatabaseInterface::ListAlbumDataType");
qRegisterMetaType<DatabaseInterface::ListArtistDataType>("DatabaseInterface::ListArtistDataType");
qRegisterMetaType<DatabaseInterface::ListGenreDataType>("DatabaseInterface::ListGenreDataType");
qRegisterMetaType<ModelDataLoader::ListTrackDataType>("ModelDataLoader::ListTrackDataType");
qRegisterMetaType<ModelDataLoader::ListRadioDataType>("ModelDataLoader::ListRadioDataType");
qRegisterMetaType<ModelDataLoader::ListAlbumDataType>("ModelDataLoader::ListAlbumDataType");
qRegisterMetaType<ModelDataLoader::ListArtistDataType>("ModelDataLoader::ListArtistDataType");
qRegisterMetaType<ModelDataLoader::ListGenreDataType>("ModelDataLoader::ListGenreDataType");
......
......@@ -55,6 +55,7 @@ enum PlayListEntryType {
Track,
FileName,
Unknown,
Radio,
};
Q_ENUM_NS(PlayListEntryType)
......
......@@ -413,6 +413,13 @@ void ManageAudioPlayer::setPlayerPosition(qint64 playerPosition)
QTimer::singleShot(0, [this]() {Q_EMIT playControlPositionChanged();});
}
void ManageAudioPlayer::setCurrentPlayingForRadios(const QString title, const QString nowPlaying){
if (mPlayListModel && mCurrentTrack.isValid()) {
Q_EMIT currentPlayingForRadiosChanged(title, MediaPlayList::TitleRole);
Q_EMIT currentPlayingForRadiosChanged(nowPlaying, MediaPlayList::ArtistRole);
}
}
void ManageAudioPlayer::setPlayControlPosition(int playerPosition)
{
Q_EMIT seek(playerPosition);
......
......@@ -203,6 +203,8 @@ Q_SIGNALS:
void startedPlayingTrack(const QUrl &fileName, const QDateTime &time);
void currentPlayingForRadiosChanged(const QVariant &value, int role);
public Q_SLOTS:
void setCurrentTrack(const QPersistentModelIndex &currentTrack);
......@@ -237,6 +239,8 @@ public Q_SLOTS:
void setPlayerPosition(qint64 playerPosition);
void setCurrentPlayingForRadios(const QString title, const QString nowPlaying);
void setPlayControlPosition(int playerPosition);
void setPersistentState(const QVariantMap &persistentStateValue);
......
......@@ -220,7 +220,8 @@ bool MediaPlayList::setData(const QModelIndex &index, const QVariant &value, int
return modelModified;
}
if (role < ColumnsRoles::IsValidRole || role > ColumnsRoles::IsPlayingRole) {
if ((role != ColumnsRoles::TitleRole && role != ColumnsRoles::ArtistRole) &&
(role < ColumnsRoles::IsValidRole || role > ColumnsRoles::IsPlayingRole)) {
return modelModified;
}
......@@ -241,6 +242,32 @@ bool MediaPlayList::setData(const QModelIndex &index, const QVariant &value, int
break;
}
case ColumnsRoles::TitleRole:
{
modelModified = true;
d->mData[index.row()].mTitle = value;
d->mTrackData[index.row()][static_cast<TrackDataType::key_type>(role)] = value;
Q_EMIT dataChanged(index, index, {role});
if (!d->mCurrentTrack.isValid()) {
resetCurrentTrack();
}
break;
}
case ColumnsRoles::ArtistRole:
{
modelModified = true;
d->mData[index.row()].mArtist = value;
d->mTrackData[index.row()][static_cast<TrackDataType::key_type>(role)] = value;
Q_EMIT dataChanged(index, index, {role});
if (!d->mCurrentTrack.isValid()) {
resetCurrentTrack();
}
break;
}
default:
modelModified = false;
}
......@@ -338,7 +365,9 @@ void MediaPlayList::enqueueRestoredEntry(const MediaPlayListEntry &newEntry)
Q_EMIT persistentStateChanged();
if (!newEntry.mIsValid) {
if (newEntry.mTrackUrl.isValid()) {
if (newEntry.mEntryType == ElisaUtils::Radio) {
Q_EMIT newEntryInList(newEntry.mId, {}, ElisaUtils::Radio);
} else if (newEntry.mTrackUrl.isValid()) {
auto entryURL = newEntry.mTrackUrl.toUrl();
if (entryURL.isLocalFile()) {
auto entryString = entryURL.toLocalFile();
......@@ -425,13 +454,13 @@ void MediaPlayList::enqueueFilesList(const ElisaUtils::EntryDataList &newEntries
Q_EMIT dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), {MediaPlayList::IsPlayingRole});
}
void MediaPlayList::enqueueTracksListById(const ElisaUtils::EntryDataList &newEntries)
void MediaPlayList::enqueueTracksListById(const ElisaUtils::EntryDataList &newEntries, ElisaUtils::PlayListEntryType type)
{
enqueueCommon();
beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size() + newEntries.size() - 1);
for (const auto &newTrack : newEntries) {
auto newMediaPlayListEntry = MediaPlayListEntry{std::get<0>(newTrack), std::get<1>(newTrack), ElisaUtils::Track};
auto newMediaPlayListEntry = MediaPlayListEntry{std::get<0>(newTrack), std::get<1>(newTrack), type};
d->mData.push_back(newMediaPlayListEntry);
d->mTrackData.push_back({});
Q_EMIT newEntryInList(newMediaPlayListEntry.mId, newMediaPlayListEntry.mTitle.toString(), newMediaPlayListEntry.mEntryType);
......@@ -565,6 +594,14 @@ void MediaPlayList::undoClearPlayList()
Q_EMIT undoClearPlayListPlayer();
}
void MediaPlayList::updateRadioData(const QVariant &value, int role)
{
auto convertedRole = static_cast<ColumnsRoles>(role);
if (d->mCurrentTrack.data(convertedRole) != value) {
this->setData(d->mCurrentTrack, value, role);
}
}
void MediaPlayList::enqueueCommon()
{
displayOrHideUndoInline(false);
......@@ -633,6 +670,7 @@ void MediaPlayList::enqueue(const ElisaUtils::EntryData &newEntry,
case ElisaUtils::Artist:
case ElisaUtils::Genre:
case ElisaUtils::Track:
case ElisaUtils::Radio:
enqueueOneEntry(newEntry, databaseIdType);
break;
case ElisaUtils::FileName:
......@@ -674,7 +712,8 @@ void MediaPlayList::enqueue(const ElisaUtils::EntryDataList &newEntries,
switch (databaseIdType)
{
case ElisaUtils::Track:
enqueueTracksListById(newEntries);
case ElisaUtils::Radio:
enqueueTracksListById(newEntries, databaseIdType);
break;
case ElisaUtils::FileName:
enqueueFilesList(newEntries);
......@@ -725,6 +764,7 @@ QVariantMap MediaPlayList::persistentState() const
if (oneEntry.mIsValid) {
const auto &oneTrack = d->mTrackData[trackIndex];
oneData.push_back(QString::number(oneTrack.databaseId()));
oneData.push_back(oneTrack.title());
oneData.push_back(oneTrack.artist());
if (oneTrack.hasAlbum()) {
......@@ -800,19 +840,20 @@ void MediaPlayList::setPersistentState(const QVariantMap &persistentStateValue)
for (auto &oneData : persistentState) {
auto trackData = oneData.toStringList();
if (trackData.size() != 6) {
if (trackData.size() != 7) {
continue;
}
auto restoredTitle = trackData[0];
auto restoredArtist = trackData[1];
auto restoredAlbum = trackData[2];
auto restoredTrackNumber = trackData[3];
auto restoredDiscNumber = trackData[4];
auto restoredId = trackData[0].toULongLong();
auto restoredTitle = trackData[1];
auto restoredArtist = trackData[2];
auto restoredAlbum = trackData[3];
auto restoredTrackNumber = trackData[4];
auto restoredDiscNumber = trackData[5];
auto mEntryType = static_cast<ElisaUtils::PlayListEntryType>(trackData[5].toInt());
auto mEntryType = static_cast<ElisaUtils::PlayListEntryType>(trackData[6].toInt());
enqueueRestoredEntry({restoredTitle, restoredArtist, restoredAlbum, restoredTrackNumber, restoredDiscNumber, mEntryType});
enqueueRestoredEntry({restoredId, restoredTitle, restoredArtist, restoredAlbum, restoredTrackNumber, restoredDiscNumber, mEntryType});
}
restorePlayListPosition();
......@@ -921,6 +962,24 @@ void MediaPlayList::trackChanged(const TrackDataType &track)
resetCurrentTrack();
}
continue;
} else if (oneEntry.mEntryType == ElisaUtils::Radio ) {
if (track.databaseId() != oneEntry.mId) {
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;
} else if (oneEntry.mEntryType != ElisaUtils::Artist && !oneEntry.mIsValid && !oneEntry.mTrackUrl.isValid()) {
if (track.find(TrackDataType::key_type::TitleRole) != track.end() &&
track.title() != oneEntry.mTitle) {
......
......@@ -269,6 +269,8 @@ public Q_SLOTS:
void undoClearPlayList();
void updateRadioData(const QVariant &value, int role);
private Q_SLOTS:
void loadPlayListLoaded();
......@@ -294,7 +296,7 @@ private:
void enqueueFilesList(const ElisaUtils::EntryDataList &newEntries);
void enqueueTracksListById(const ElisaUtils::EntryDataList &newEntries);
void enqueueTracksListById(const ElisaUtils::EntryDataList &newEntries, ElisaUtils::PlayListEntryType type);
void enqueueOneEntry(const ElisaUtils::EntryData &entryData, ElisaUtils::PlayListEntryType type);
......@@ -323,10 +325,9 @@ public:
mTrackNumber(trackNumber), mDiscNumber(discNumber), mEntryType(entryType) {
}
MediaPlayListEntry(QVariant title, QVariant artist, QVariant album, QVariant trackNumber,
QVariant discNumber, ElisaUtils::PlayListEntryType entryType = ElisaUtils::Unknown)
MediaPlayListEntry(qulonglong id, QVariant title, QVariant artist, QVariant album, QVariant trackNumber, QVariant discNumber, ElisaUtils::PlayListEntryType entryType = ElisaUtils::Unknown)
: mTitle(std::move(title)), mAlbum(std::move(album)), mArtist(std::move(artist)),
mTrackNumber(std::move(trackNumber)), mDiscNumber(std::move(discNumber)), mEntryType(entryType) {
mTrackNumber(trackNumber), mDiscNumber(discNumber), mId(id), mEntryType(entryType) {
}
explicit MediaPlayListEntry(const MusicAudioTrack &track)
......
......@@ -75,6 +75,16 @@ void ModelDataLoader::setDatabase(DatabaseInterface *database)
this, &ModelDataLoader::databaseArtistsAdded);
connect(database, &DatabaseInterface::artistRemoved,
this, &ModelDataLoader::databaseArtistRemoved);
connect(this, &ModelDataLoader::saveRadioModified,
database, &DatabaseInterface::insertRadio);
connect(this, &ModelDataLoader::removeRadio,
database, &DatabaseInterface::removeRadio);
connect(database, &DatabaseInterface::radioAdded,
this, &ModelDataLoader::databaseRadioAdded);
connect(database, &DatabaseInterface::radioModified,
this, &ModelDataLoader::databaseRadioModified);
connect(database, &DatabaseInterface::radioRemoved,
this, &ModelDataLoader::databaseRadioRemoved);
}
void ModelDataLoader::loadData(ElisaUtils::PlayListEntryType dataType)
......@@ -106,6 +116,9 @@ void ModelDataLoader::loadData(ElisaUtils::PlayListEntryType dataType)
case ElisaUtils::FileName:
case ElisaUtils::Unknown:
break;
case ElisaUtils::Radio:
Q_EMIT allRadiosData(d->mDatabase->allRadiosData());
break;
}
}
......@@ -135,6 +148,7 @@ void ModelDataLoader::loadDataByAlbumId(ElisaUtils::PlayListEntryType dataType,
break;
case ElisaUtils::FileName:
case ElisaUtils::Unknown:
case ElisaUtils::Radio:
break;
}
}
......@@ -160,6 +174,7 @@ void ModelDataLoader::loadDataByGenre(ElisaUtils::PlayListEntryType dataType, co
case ElisaUtils::Lyricist:
case ElisaUtils::FileName:
case ElisaUtils::Unknown:
case ElisaUtils::Radio:
break;
}
}
......@@ -185,6 +200,7 @@ void ModelDataLoader::loadDataByArtist(ElisaUtils::PlayListEntryType dataType, c
case ElisaUtils::Lyricist:
case ElisaUtils::FileName:
case ElisaUtils::Unknown:
case ElisaUtils::Radio:
break;
}
}
......@@ -211,6 +227,7 @@ void ModelDataLoader::loadDataByGenreAndArtist(ElisaUtils::PlayListEntryType dat
case ElisaUtils::Track:
case ElisaUtils::FileName:
case ElisaUtils::Unknown:
case ElisaUtils::Radio:
break;
}
}
......@@ -229,6 +246,9 @@ void ModelDataLoader::loadDataByDatabaseId(ElisaUtils::PlayListEntryType dataTyp
case ElisaUtils::Track:
Q_EMIT allTrackData(d->mDatabase->trackDataFromDatabaseId(databaseId));
break;
case ElisaUtils::Radio:
Q_EMIT allRadioData(d->mDatabase->radioDataFromDatabaseId(databaseId));
break;
case ElisaUtils::Album:
case ElisaUtils::Artist:
case ElisaUtils::Composer:
......@@ -263,6 +283,7 @@ void ModelDataLoader::loadDataByFileName(ElisaUtils::PlayListEntryType dataType,
case ElisaUtils::Genre:
case ElisaUtils::Lyricist:
case ElisaUtils::Unknown:
case ElisaUtils::Radio:
break;
}
}
......@@ -287,6 +308,7 @@ void ModelDataLoader::loadRecentlyPlayedData(ElisaUtils::PlayListEntryType dataT
case ElisaUtils::Lyricist:
case ElisaUtils::FileName:
case ElisaUtils::Unknown:
case ElisaUtils::Radio:
break;
}
}
......@@ -311,6 +333,7 @@ void ModelDataLoader::loadFrequentlyPlayedData(ElisaUtils::PlayListEntryType dat
case ElisaUtils::Lyricist:
case ElisaUtils::FileName:
case ElisaUtils::Unknown:
case ElisaUtils::Radio:
break;
}
}
......@@ -439,5 +462,29 @@ void ModelDataLoader::databaseAlbumModified(const AlbumDataType &modifiedAlbum)
Q_EMIT albumModified(modifiedAlbum);
}
void ModelDataLoader::updateRadioData(TrackDataType trackDataType)
{
Q_EMIT saveRadioModified(trackDataType);
}
void ModelDataLoader::deleteRadioData(qulonglong radioId)
{
Q_EMIT removeRadio(radioId);
}
void ModelDataLoader::databaseRadioAdded(TrackDataType radio)
{
Q_EMIT radioAdded(radio);
}
void ModelDataLoader::databaseRadioModified(TrackDataType radio)
{
Q_EMIT radioModified(radio);
}
void ModelDataLoader::databaseRadioRemoved(qulonglong radioId)
{
Q_EMIT radioRemoved(radioId);
}
#include "moc_modeldataloader.cpp"
......@@ -41,6 +41,7 @@ public:
using ListArtistDataType = DatabaseInterface::ListArtistDataType;
using ListGenreDataType = DatabaseInterface::ListGenreDataType;
using ListTrackDataType = DatabaseInterface::ListTrackDataType;
using ListRadioDataType = DatabaseInterface::ListRadioDataType;
using TrackDataType = DatabaseInterface::TrackDataType;
using AlbumDataType = DatabaseInterface::AlbumDataType;
......@@ -62,8 +63,16 @@ Q_SIGNALS:
void allTracksData(const ModelDataLoader::ListTrackDataType &allData);
void allRadiosData(const ModelDataLoader::ListRadioDataType &radiosData);
void radioAdded(const ModelDataLoader::TrackDataType radiosData);
void radioModified(const ModelDataLoader::TrackDataType radiosData);
void allTrackData(const ModelDataLoader::TrackDataType &allData);
void allRadioData(const ModelDataLoader::TrackDataType &allData);
void tracksAdded(ModelDataLoader::ListTrackDataType newData);
void trackModified(const ModelDataLoader::TrackDataType &modifiedTrack);
......@@ -82,6 +91,12 @@ Q_SIGNALS:
void albumModified(const ModelDataLoader::AlbumDataType &modifiedAlbum);
void saveRadioModified(const ModelDataLoader::TrackDataType trackDataType);
void removeRadio(qulonglong radioId);
void radioRemoved(qulonglong radioId);
public Q_SLOTS:
void loadData(ElisaUtils::PlayListEntryType dataType);
......@@ -107,6 +122,10 @@ public Q_SLOTS:
void loadFrequentlyPlayedData(ElisaUtils::PlayListEntryType dataType);
void updateRadioData(ModelDataLoader::TrackDataType trackDataType);
void deleteRadioData(qulonglong radioId);
private:
void databaseTracksAdded(const ListTrackDataType &newData);
......@@ -127,6 +146,12 @@ private:
void databaseAlbumModified(const AlbumDataType &modifiedAlbum);
void databaseRadioAdded(const TrackDataType radio);
void databaseRadioModified(const TrackDataType radio);
void databaseRadioRemoved(qulonglong radioId);
private:
std::unique_ptr<ModelDataLoaderPrivate> d;
......
......@@ -34,6 +34,8 @@ public:
DataModel::ListTrackDataType mAllTrackData;
DataModel::ListRadioDataType mAllRadiosData;
DataModel::ListAlbumDataType mAllAlbumData;
DataModel::ListArtistDataType mAllArtistData;
......@@ -123,14 +125,14 @@ QVariant DataModel::data(const QModelIndex &index, int role) const
return result;
}
const auto dataCount = d->mAllTrackData.size() + d->mAllAlbumData.size() + d->mAllArtistData.size() + d->mAllGenreData.size();
const auto dataCount = d->mModelType == ElisaUtils::Radio ? d->mAllRadiosData.size() : d->mAllTrackData.size() + d->mAllAlbumData.size() + d->mAllArtistData.size() + d->mAllGenreData.size();
Q_ASSERT(index.isValid());
Q_ASSERT(index.column() == 0);
Q_ASSERT(index.row() >= 0 && index.row() < dataCount);
Q_ASSERT(!index.parent().isValid());
Q_ASSERT(index.model() == this);