diff --git a/db/librarydb.cpp b/db/librarydb.cpp index 0e0688cc7..80add280f 100644 --- a/db/librarydb.cpp +++ b/db/librarydb.cpp @@ -680,7 +680,7 @@ QList LibraryDb::getTracks(const QString &artistId, const QString &albumId query.exec(); DBUG << query.executedQuery(); while (query.next()) { - songs.append(getSong(&(query.realQuery()))); + songs.append(getSong(query.realQuery())); } } @@ -705,6 +705,25 @@ QList LibraryDb::getTracks(const QString &artistId, const QString &albumId } #ifndef CANTATA_WEB +QList LibraryDb::songs(const QStringList &files, bool allowPlaylists) const +{ + QList songList; + foreach (const QString &f, files) { + SqlQuery query("*", *db); + query.addWhere("file", f); + query.exec(); + DBUG << query.executedQuery(); + if (query.next()) { + Song song=getSong(query.realQuery()); + if (allowPlaylists || Song::Playlist!=song.type) { + songList.append(song); + } + } + } + + return songList; +} + QList LibraryDb::getAlbumsWithArtist(const QString &artist) { QList albums; @@ -827,30 +846,30 @@ bool LibraryDb::createTable(const QString &q) return true; } -Song LibraryDb::getSong(const QSqlQuery *query) +Song LibraryDb::getSong(const QSqlQuery &query) { Song s; - s.file=query->value(0).toString(); - s.artist=query->value(1).toString(); - s.albumartist=query->value(3).toString(); - s.setComposer(query->value(5).toString()); - s.album=query->value(6).toString(); - QString val=query->value(7).toString(); + s.file=query.value(0).toString(); + s.artist=query.value(1).toString(); + s.albumartist=query.value(3).toString(); + s.setComposer(query.value(5).toString()); + s.album=query.value(6).toString(); + QString val=query.value(7).toString(); if (!val.isEmpty() && val!=s.album) { s.setMbAlbumId(val); } - s.title=query->value(9).toString(); - s.genre=query->value(10).toString(); - s.track=query->value(11).toUInt(); - s.disc=query->value(12).toUInt(); - s.time=query->value(13).toUInt(); - s.year=query->value(14).toUInt(); - s.type=(Song::Type)query->value(15).toUInt(); - val=query->value(4).toString(); + s.title=query.value(9).toString(); + s.genre=query.value(10).toString(); + s.track=query.value(11).toUInt(); + s.disc=query.value(12).toUInt(); + s.time=query.value(13).toUInt(); + s.year=query.value(14).toUInt(); + s.type=(Song::Type)query.value(15).toUInt(); + val=query.value(4).toString(); if (!val.isEmpty() && val!=s.albumArtist()) { s.setArtistSort(val); } - val=query->value(8).toString(); + val=query.value(8).toString(); if (!val.isEmpty() && val!=s.album) { s.setAlbumSort(val); } diff --git a/db/librarydb.h b/db/librarydb.h index 5960e5c4c..0ef345ca0 100644 --- a/db/librarydb.h +++ b/db/librarydb.h @@ -115,6 +115,7 @@ public: QList getAlbums(const QString &artistId=QString(), const QString &genre=QString(), const QString &sort=QString()); QList getTracks(const QString &artistId, const QString &albumId, const QString &genre=QString(), const QString &sort=QString()); #ifndef CANTATA_WEB + QList songs(const QStringList &files, bool allowPlaylists=false) const; QList getAlbumsWithArtist(const QString &artist); QSet get(const QString &type); void getDetails(QSet &artists, QSet &albumArtists, QSet &composers, QSet &albums, QSet &genres); @@ -132,7 +133,7 @@ protected Q_SLOTS: protected: bool createTable(const QString &q); - static Song getSong(const QSqlQuery *query); + static Song getSong(const QSqlQuery &query); protected: virtual void reset(); diff --git a/db/mpdlibrarydb.cpp b/db/mpdlibrarydb.cpp index ecbc3014e..a6362310c 100644 --- a/db/mpdlibrarydb.cpp +++ b/db/mpdlibrarydb.cpp @@ -114,7 +114,7 @@ Song MpdLibraryDb::getCoverSong(const QString &artistId, const QString &albumId) query->exec(); DBUG << "coverquery" << query->executedQuery() << query->size(); while (query->next()) { - return getSong(query); + return getSong(*query); } } return Song(); diff --git a/gui/folderpage.cpp b/gui/folderpage.cpp index a4dc563d6..6845688fc 100644 --- a/gui/folderpage.cpp +++ b/gui/folderpage.cpp @@ -28,6 +28,7 @@ #include "support/messagebox.h" #include "support/action.h" #include "support/utils.h" +#include "models/mpdlibrarymodel.h" #include "stdactions.h" #include #include @@ -190,24 +191,22 @@ void FolderPage::openFileManager() QList FolderPage::selectedSongs(EmptySongMod esMod, bool allowPlaylists) const { -// QList songs=MusicLibraryModel::self()->songs(selectedFiles(allowPlaylists), ES_None!=esMod); + QList songs=MpdLibraryModel::self()->songs(selectedFiles(allowPlaylists), ES_None!=esMod); -// if (ES_None!=esMod) { -// QList::Iterator it(songs.begin()); -// QList::Iterator end(songs.end()); -// for (; it!=end; ++it) { -// if ((*it).isEmpty()) { -// if (ES_GuessTags==esMod) { -// (*it).guessTags(); -// } -// (*it).fillEmptyFields(); -// } -// } -// } + if (ES_None!=esMod) { + QList::Iterator it(songs.begin()); + QList::Iterator end(songs.end()); + for (; it!=end; ++it) { + if ((*it).isEmpty()) { + if (ES_GuessTags==esMod) { + (*it).guessTags(); + } + (*it).fillEmptyFields(); + } + } + } -// return songs; - return QList(); - // TODO!!!! + return songs; } QStringList FolderPage::selectedFiles(bool allowPlaylists) const diff --git a/models/sqllibrarymodel.cpp b/models/sqllibrarymodel.cpp index 4a01e6aa7..b4f40831f 100644 --- a/models/sqllibrarymodel.cpp +++ b/models/sqllibrarymodel.cpp @@ -375,6 +375,11 @@ QList SqlLibraryModel::getAlbumTracks(const Song &song) const return QList(); } +QList SqlLibraryModel::songs(const QStringList &files, bool allowPlaylists) const +{ + return db->songs(files, allowPlaylists); +} + QList SqlLibraryModel::getArtistAlbums(const QString &artist) const { return db->getAlbumsWithArtist(artist); diff --git a/models/sqllibrarymodel.h b/models/sqllibrarymodel.h index c24b0c237..71781eb62 100644 --- a/models/sqllibrarymodel.h +++ b/models/sqllibrarymodel.h @@ -155,6 +155,7 @@ public: QModelIndex findArtistIndex(const QString &artist); QSet getArtists() const; QList getAlbumTracks(const Song &song) const; + QList songs(const QStringList &files, bool allowPlaylists=false) const; QList getArtistAlbums(const QString &artist) const; void getDetails(QSet &artists, QSet &albumArtists, QSet &composers, QSet &albums, QSet &genres);