Commit 7cdadf58 authored by Matthieu Gallien's avatar Matthieu Gallien 🎵

prevent new radio dialog to get data from newly played track

when a create new radio dialog is open and the currently playing track
changes, it will get the data from the newly playing track instead of
being non modified

clean the design of TrackMetadataModel to not have half of the code
needed to build the EditableTrackMetadataModel model. Keep it only on
handling of metadata for tracks.

prepare for proper handling of modifications of metadata of tracks and
not only radios
parent 55aad71d
Pipeline #37963 passed with stage
in 36 minutes and 29 seconds
......@@ -33,6 +33,7 @@ bool EditableTrackMetadataModel::setData(const QModelIndex &index, const QVarian
void EditableTrackMetadataModel::saveData()
{
mIsNewRadio = false;
mIsDirty = false;
Q_EMIT isDirtyChanged();
......@@ -51,6 +52,24 @@ void EditableTrackMetadataModel::saveData()
Q_EMIT saveRadioData(newTrackData);
}
void EditableTrackMetadataModel::deleteRadio()
{
auto &track = displayedTrackData();
if (track[DataTypes::DatabaseIdRole].toULongLong()) {
Q_EMIT deleteRadioData(track[DataTypes::DatabaseIdRole].toULongLong());
}
}
void EditableTrackMetadataModel::fillDataFromTrackData(const TrackMetadataModel::TrackDataType &trackData,
const QList<DataTypes::ColumnsRoles> &fieldsForTrack)
{
if (mIsNewRadio) {
return;
}
TrackMetadataModel::fillDataFromTrackData(trackData, fieldsForTrack);
}
void EditableTrackMetadataModel::filterDataFromTrackData()
{
TrackMetadataModel::filterDataFromTrackData();
......@@ -63,6 +82,22 @@ void EditableTrackMetadataModel::fillLyricsDataFromTrack()
validData();
}
void EditableTrackMetadataModel::fillDataForNewRadio()
{
mIsNewRadio = true;
TrackMetadataModel::fillDataForNewRadio();
}
void EditableTrackMetadataModel::initialize(MusicListenersManager *newManager, DatabaseInterface *trackDatabase)
{
TrackMetadataModel::initialize(newManager, trackDatabase);
connect(this, &EditableTrackMetadataModel::saveRadioData,
&modelDataLoader(), &ModelDataLoader::saveRadioModified);
connect(this, &EditableTrackMetadataModel::deleteRadioData,
&modelDataLoader(), &ModelDataLoader::removeRadio);
}
void EditableTrackMetadataModel::validData()
{
bool newValidState = true;
......
......@@ -55,20 +55,35 @@ Q_SIGNALS:
void errorMessageChanged();
void saveRadioData(const DataTypes::TrackDataType &trackDataType);
void deleteRadioData(qulonglong radioId);
public Q_SLOTS:
void saveData();
void deleteRadio();
protected:
void fillDataFromTrackData(const TrackMetadataModel::TrackDataType &trackData,
const QList<DataTypes::ColumnsRoles> &fieldsForTrack) override;
void filterDataFromTrackData() override;
void fillLyricsDataFromTrack() override;
void fillDataForNewRadio() override;
void initialize(MusicListenersManager *newManager,
DatabaseInterface *trackDatabase) override;
private:
void validData();
bool mIsNewRadio = false;
bool mIsDataValid = false;
bool mIsDirty = false;
......
......@@ -544,10 +544,6 @@ void TrackMetadataModel::initialize(MusicListenersManager *newManager, DatabaseI
&mDataLoader, &ModelDataLoader::loadDataByDatabaseIdAndUrl);
connect(this, &TrackMetadataModel::needDataByUrl,
&mDataLoader, &ModelDataLoader::loadDataByUrl);
connect(this, &TrackMetadataModel::saveRadioData,
&mDataLoader, &ModelDataLoader::saveRadioModified);
connect(this, &TrackMetadataModel::deleteRadioData,
&mDataLoader, &ModelDataLoader::removeRadio);
connect(&mDataLoader, &ModelDataLoader::trackModified,
this, &TrackMetadataModel::trackData);
connect(&mDataLoader, &ModelDataLoader::allTrackData,
......@@ -560,6 +556,16 @@ void TrackMetadataModel::initialize(MusicListenersManager *newManager, DatabaseI
this, &TrackMetadataModel::radioData);
}
ModelDataLoader &TrackMetadataModel::modelDataLoader()
{
return mDataLoader;
}
const TrackMetadataModel::TrackDataType &TrackMetadataModel::displayedTrackData() const
{
return mTrackData;
}
void TrackMetadataModel::fetchLyrics()
{
auto lyricicsValue = QtConcurrent::run(QThreadPool::globalInstance(), [=]() {
......@@ -628,13 +634,6 @@ void TrackMetadataModel::setDatabase(DatabaseInterface *trackDatabase)
initialize(nullptr, trackDatabase);
}
void TrackMetadataModel::deleteRadio()
{
if (mTrackData[DataTypes::DatabaseIdRole].toULongLong()) {
Q_EMIT deleteRadioData(mTrackData[DataTypes::DatabaseIdRole].toULongLong());
}
}
void TrackMetadataModel::radioData(const TrackDataType &radiosData)
{
if (!mFullData.isEmpty() && mFullData[DataTypes::DatabaseIdRole].toInt() != -1 &&
......
......@@ -106,10 +106,6 @@ Q_SIGNALS:
void lyricsChanged();
void saveRadioData(const DataTypes::TrackDataType &trackDataType);
void deleteRadioData(qulonglong radioId);
void databaseIdChanged();
public Q_SLOTS:
......@@ -126,16 +122,14 @@ public Q_SLOTS:
void setDatabase(DatabaseInterface *trackDatabase);
void deleteRadio();
void radioData(const TrackMetadataModel::TrackDataType &radiosData);
protected:
void fillDataFromTrackData(const TrackMetadataModel::TrackDataType &trackData,
const QList<DataTypes::ColumnsRoles> &fieldsForTrack);
virtual void fillDataFromTrackData(const TrackMetadataModel::TrackDataType &trackData,
const QList<DataTypes::ColumnsRoles> &fieldsForTrack);
void fillDataForNewRadio();
virtual void fillDataForNewRadio();
virtual void filterDataFromTrackData();
......@@ -147,15 +141,19 @@ protected:
const TrackDataType& allTrackData() const;
virtual void initialize(MusicListenersManager *newManager,
DatabaseInterface *trackDatabase);
ModelDataLoader& modelDataLoader();
const TrackDataType& displayedTrackData() const;
private Q_SLOTS:
void lyricsValueIsReady();
private:
void initialize(MusicListenersManager *newManager,
DatabaseInterface *trackDatabase);
void fetchLyrics();
TrackDataType mFullData;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment