diff options
author | Arno <arno@disconnect.de> | 2017-02-25 06:46:51 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2017-02-25 06:46:51 +0100 |
commit | 25bcad4c8496431f1a5556803eaccea9dddc31e1 (patch) | |
tree | 62b220ecf3b7773f171fc78279f8e53e0ab40cf4 | |
parent | 0e883223783a0e3ee5bc83f4ffeb4acc0beed1aa (diff) | |
download | BeetPlayer-25bcad4c8496431f1a5556803eaccea9dddc31e1.tar.gz BeetPlayer-25bcad4c8496431f1a5556803eaccea9dddc31e1.tar.bz2 BeetPlayer-25bcad4c8496431f1a5556803eaccea9dddc31e1.zip |
Fix Indexer
Well, as it turns out, an artist is not married to an album, but to a
song, and so is the genre. Adjust the database layout, indexer and view
accordingly.
-rw-r--r-- | indexerwidget.cpp | 21 | ||||
-rw-r--r-- | indexerwidget.h | 4 | ||||
-rw-r--r-- | playerwidget.cpp | 7 |
3 files changed, 17 insertions, 15 deletions
diff --git a/indexerwidget.cpp b/indexerwidget.cpp index 84f2598..e1643fa 100644 --- a/indexerwidget.cpp +++ b/indexerwidget.cpp @@ -94,11 +94,11 @@ BeetReader::BeetReader() : mCanceled(false){ mCurGenresQ = new QSqlQuery(mDb); mCurGenresQ->prepare("SELECT currval('genres_igenre_id__seq')"); mInsertAlbumQ = new QSqlQuery(mDb); - mInsertAlbumQ->prepare("INSERT INTO albums(iartists_id, igenres_id, talbum_name, siyear) VALUES(:aid, :genid, :name, :year)"); + mInsertAlbumQ->prepare("INSERT INTO albums(talbum_name, siyear) VALUES(:name, :year)"); mCurAlbumQ = new QSqlQuery(mDb); mCurAlbumQ->prepare("SELECT currval('albums_ialbums_id__seq')"); mInsertSongQ = new QSqlQuery(mDb); - mInsertSongQ->prepare("INSERT INTO songs (ialbums_id, sipos, ttitle, tfullpath) VALUES(:aid, :pos, :title, :tfp)"); + mInsertSongQ->prepare("INSERT INTO songs (ialbums_id, sipos, ttitle, iartists_id, igenres_id, tfullpath) VALUES(:aid, :pos, :title, :iartistid, :igenid, :tfp)"); } void BeetReader::run(){ @@ -136,8 +136,8 @@ void BeetReader::run(){ //write to database int artistId = doArtist(artist); int genreId = doGenre(genre); - int albumId = doAlbum(album, genreId, artistId, year, QString(s).toUtf8()); - doSong(title, track, albumId, s); + int albumId = doAlbum(album, year); + doSong(title, track, albumId, genreId, artistId, s); if(ctr % 100 == 0){ QString msg = QString(tr("Processed %1 files of %2")).arg(QString::number(ctr)).arg(QString::number(totalCount)); @@ -176,6 +176,8 @@ void BeetReader::clearAll(){ mArtistH.clear(); mAlbumH.clear(); mGenreH.clear(); + QSqlQuery q5("INSERT INTO genres VALUES(-1, 'none')", mDb); + q5.exec(); emit cleared(); } @@ -214,16 +216,13 @@ int BeetReader::doGenre(QString name){ return retval; } -int BeetReader::doAlbum(QString name, int genre, int artist, int year, QString fullPath){ - QFileInfo fi(fullPath); - QString key = fi.absolutePath(); +int BeetReader::doAlbum(QString name, int year){ + QString key = name; if(mAlbumH.contains(key)){ return mAlbumH.value(key); } mDb.transaction(); mInsertAlbumQ->bindValue(":name", name); - mInsertAlbumQ->bindValue(":aid", artist); - mInsertAlbumQ->bindValue(":genid", genre); mInsertAlbumQ->bindValue(":year", year); mInsertAlbumQ->exec(); int retval = -1; @@ -236,11 +235,13 @@ int BeetReader::doAlbum(QString name, int genre, int artist, int year, QString f return retval; } -void BeetReader::doSong(QString title, int pos, int album, QString fullpath){ +void BeetReader::doSong(QString title, int pos, int album, int genre, int artist, QString fullpath){ mDb.transaction(); mInsertSongQ->bindValue(":title", title); mInsertSongQ->bindValue(":pos", pos); mInsertSongQ->bindValue(":aid", album); + mInsertSongQ->bindValue(":iartistid", artist); + mInsertSongQ->bindValue(":igenid", genre); mInsertSongQ->bindValue(":tfp", fullpath); mInsertSongQ->exec(); mDb.commit(); diff --git a/indexerwidget.h b/indexerwidget.h index aa3c1d3..64e1343 100644 --- a/indexerwidget.h +++ b/indexerwidget.h @@ -54,8 +54,8 @@ class BeetReader : public QThread { void clearAll(); int doArtist(QString name); int doGenre(QString name); - int doAlbum(QString name, int genre, int artist, int year, QString fullPath); - void doSong(QString title, int pos, int album, QString fullpath); + int doAlbum(QString name, int year); + void doSong(QString title, int pos, int album, int genre, int artist, QString fullpath); QMutex mCancelMx; bool mCanceled; QSqlDatabase mDb; diff --git a/playerwidget.cpp b/playerwidget.cpp index b238f62..36910cc 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -129,9 +129,9 @@ void PlayerWidget::populateByArtist(){ QSqlQuery artistsQ(db); artistsQ.prepare("SELECT iartists_id, tartists_name FROM artists ORDER BY tartists_name ASC"); QSqlQuery albumQ(db); - albumQ.prepare("SELECT ialbums_id, talbum_name, siyear FROM albums WHERE iartists_id = :aid ORDER BY talbum_name ASC"); + albumQ.prepare("SELECT DISTINCT(songs.ialbums_id), talbum_name, siyear FROM songs, albums WHERE songs.iartists_id = :artistid AND songs.ialbums_id = albums.ialbums_id"); QSqlQuery songQ(db); - songQ.prepare("SELECT sipos, ttitle, tfullpath FROM songs WHERE ialbums_id = :alid ORDER BY sipos ASC"); + songQ.prepare("SELECT sipos, ttitle, tfullpath FROM songs WHERE ialbums_id = :alid AND iartists_id = :arid ORDER BY sipos ASC"); //reset view+model mView->setSortingEnabled(false); @@ -148,7 +148,7 @@ void PlayerWidget::populateByArtist(){ curArtist->setData(Artist, TypeRole); curArtist->setData(artistsQ.value(0).toInt(), IdRole); root->appendRow(curArtist); - albumQ.bindValue(":aid", artistsQ.value(0)); + albumQ.bindValue(":artistid", artistsQ.value(0)); albumQ.exec(); while(albumQ.next()){ QStandardItem *curAlbum = new QStandardItem; @@ -158,6 +158,7 @@ void PlayerWidget::populateByArtist(){ curAlbum->setData(albumQ.value(0), IdRole); curArtist->appendRow(curAlbum); songQ.bindValue(":alid", albumQ.value(0)); + songQ.bindValue(":arid", artistsQ.value(0)); songQ.exec(); while(songQ.next()){ QStandardItem *curSong = new QStandardItem; |