Commit 39d128dc authored by Matthieu Gallien's avatar Matthieu Gallien

fix issues when refreshing (i.e. clean reindex) music database

parent 0ff44518
......@@ -276,7 +276,7 @@ public:
QSet<qulonglong> mInsertedAlbums;
QSet<qulonglong> mInsertedArtists;
QSet<QPair<qulonglong, QString>> mInsertedArtists;
qulonglong mAlbumId = 1;
......@@ -1147,8 +1147,10 @@ void DatabaseInterface::insertTracksList(const DataTypes::ListTrackDataType &tra
if (!d->mInsertedArtists.isEmpty()) {
DataTypes::ListArtistDataType newArtists;
for (auto artistId : qAsConst(d->mInsertedArtists)) {
newArtists.push_back({{DataTypes::DatabaseIdRole, artistId}});
for (auto newArtistData : qAsConst(d->mInsertedArtists)) {
newArtists.push_back({{DataTypes::DatabaseIdRole, newArtistData.first},
{DataTypes::TitleRole, newArtistData.second},
{DataTypes::ElementTypeRole, ElisaUtils::Artist}});
}
qCInfo(orgKdeElisaDatabase) << "artistsAdded" << newArtists.size();
Q_EMIT artistsAdded(newArtists);
......@@ -1208,8 +1210,10 @@ void DatabaseInterface::removeTracksList(const QList<QUrl> &removedTracks)
if (!d->mInsertedArtists.isEmpty()) {
DataTypes::ListArtistDataType newArtists;
for (auto artistId : qAsConst(d->mInsertedArtists)) {
newArtists.push_back({{DataTypes::DatabaseIdRole, artistId}});
for (auto newArtistData : qAsConst(d->mInsertedArtists)) {
newArtists.push_back({{DataTypes::DatabaseIdRole, newArtistData.first},
{DataTypes::TitleRole, newArtistData.second},
{DataTypes::ElementTypeRole, ElisaUtils::Artist}});
}
Q_EMIT artistsAdded(newArtists);
}
......@@ -6504,7 +6508,7 @@ qulonglong DatabaseInterface::insertArtist(const QString &name)
++d->mArtistId;
d->mInsertedArtists.insert(result);
d->mInsertedArtists.insert({result, name});
d->mInsertArtistsQuery.finish();
......@@ -6631,7 +6635,9 @@ qulonglong DatabaseInterface::insertGenre(const QString &name)
d->mInsertGenreQuery.finish();
Q_EMIT genresAdded({{{DataTypes::DatabaseIdRole, result}}});
Q_EMIT genresAdded({{{DataTypes::DatabaseIdRole, result},
{DataTypes::TitleRole, name},
{DataTypes::ElementTypeRole, ElisaUtils::Genre}}});
return result;
}
......
......@@ -156,6 +156,10 @@ void ViewsModel::setViewsData(ViewsListData *viewsData)
this, &ViewsModel::dataRemoved);
connect(d->mViewsData, &ViewsListData::dataModified,
this, &ViewsModel::dataModified);
connect(d->mViewsData, &ViewsListData::dataAboutToBeReset,
this, &ViewsModel::dataAboutToBeReset);
connect(d->mViewsData, &ViewsListData::dataReset,
this, &ViewsModel::dataReset);
endResetModel();
}
......@@ -186,5 +190,15 @@ void ViewsModel::dataModified(int currentIndex)
Q_EMIT dataChanged(index(currentIndex, 0), index(currentIndex, 0));
}
void ViewsModel::dataAboutToBeReset()
{
beginResetModel();
}
void ViewsModel::dataReset()
{
endResetModel();
}
#include "moc_viewsmodel.cpp"
......@@ -73,6 +73,10 @@ private Q_SLOTS:
void dataModified(int currentIndex);
void dataAboutToBeReset();
void dataReset();
private:
std::unique_ptr<ViewsModelPrivate> d;
......
......@@ -10,6 +10,8 @@
#include "databaseinterface.h"
#include "musiclistenersmanager.h"
#include "viewsLogging.h"
#include <KI18n/KLocalizedString>
#include <QUrl>
......@@ -266,7 +268,7 @@ void ViewsListData::artistsAdded(DataTypes::ListArtistDataType newData)
oneArtist.databaseId(),
ElisaUtils::Album,
ElisaUtils::Artist,
QUrl{QStringLiteral("image://icon/view-media-artist")},
QUrl{QStringLiteral("image://icon/media-optical-audio")},
ViewManager::DelegateWithSecondaryText,
ViewManager::ViewShowRating});
}
......@@ -372,6 +374,36 @@ void ViewsListData::albumModified(const DataTypes::AlbumDataType &modifiedAlbum)
}
}
void ViewsListData::cleanedDatabase()
{
qCDebug(orgKdeElisaViews) << "ViewsListData::cleanedDatabase" << d->mEmbeddedCategory;
switch (d->mEmbeddedCategory)
{
case ElisaUtils::Album:
case ElisaUtils::Genre:
case ElisaUtils::Artist:
Q_EMIT dataAboutToBeReset();
for (int i = 0; i < d->mViewsParameters.size(); ) {
if (d->mViewsParameters.at(i).mEntryType == d->mEmbeddedCategory) {
d->mViewsParameters.removeAt(i);
} else {
++i;
}
}
Q_EMIT dataReset();
break;
case ElisaUtils::Radio:
case ElisaUtils::Track:
case ElisaUtils::Unknown:
case ElisaUtils::Composer:
case ElisaUtils::FileName:
case ElisaUtils::Lyricist:
case ElisaUtils::Container:
break;
}
}
void ViewsListData::refreshEmbeddedCategory()
{
auto elementsCategoryToRemove = ElisaUtils::Unknown;
......@@ -548,6 +580,8 @@ void ViewsListData::setDatabase(DatabaseInterface *aDatabase)
this, &ViewsListData::albumRemoved);
connect(d->mDatabase, &DatabaseInterface::albumModified,
this, &ViewsListData::albumModified);
connect(d->mDatabase, &DatabaseInterface::cleanedDatabase,
this, &ViewsListData::cleanedDatabase);
connect(this, &ViewsListData::needData,
d->mDataLoader, &ModelDataLoader::loadData);
......
......@@ -325,6 +325,10 @@ Q_SIGNALS:
void dataModified(int index);
void dataAboutToBeReset();
void dataReset();
public Q_SLOTS:
void setEmbeddedCategory(ElisaUtils::PlayListEntryType aEmbeddedView);
......@@ -345,6 +349,8 @@ public Q_SLOTS:
void albumModified(const DataTypes::AlbumDataType &modifiedAlbum);
void cleanedDatabase();
private:
void refreshEmbeddedCategory();
......
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