Change the data returned from sqlite a bit so the library view can use cover art too. Still a couple of TODOs in here.
This commit is contained in:
parent
235a015a6f
commit
91958d0fd2
|
@ -145,7 +145,8 @@ void AlbumCoverManager::ArtistChanged(QListWidgetItem* current) {
|
|||
ui_.albums->clear();
|
||||
CancelRequests();
|
||||
|
||||
foreach (const LibraryBackend::AlbumArtInfo& info, backend_->GetAlbumArtInfo(artist)) {
|
||||
foreach (const LibraryBackend::Album& info,
|
||||
backend_->GetAlbumsByArtist(artist)) {
|
||||
QListWidgetItem* item = new QListWidgetItem(no_cover_icon_, info.album_name, ui_.albums);
|
||||
item->setData(Role_ArtistName, info.artist);
|
||||
item->setData(Role_AlbumName, info.album_name);
|
||||
|
|
|
@ -17,7 +17,8 @@ Library::Library(EngineBase* engine, QObject* parent)
|
|||
watcher_(new BackgroundThread<LibraryWatcher>(this)),
|
||||
dir_model_(new LibraryDirectoryModel(this)),
|
||||
artist_icon_(":artist.png"),
|
||||
album_icon_(":album.png")
|
||||
album_icon_(":album.png"),
|
||||
no_cover_icon_(":nocover.png")
|
||||
{
|
||||
root_->lazy_loaded = true;
|
||||
|
||||
|
@ -106,7 +107,8 @@ void Library::SongsDiscovered(const SongList& songs) {
|
|||
if (artist->lazy_loaded) {
|
||||
album = artist->ChildByKey(song.album());
|
||||
if (album == NULL)
|
||||
album = CreateAlbumNode(true, song.album(), artist, song.is_compilation());
|
||||
album = CreateAlbumNode(true, song.album(), artist, song.is_compilation(),
|
||||
song.art_automatic(), song.art_manual());
|
||||
|
||||
if (album->lazy_loaded)
|
||||
CreateSongNode(true, song, album);
|
||||
|
@ -170,7 +172,10 @@ LibraryItem* Library::CreateArtistNode(bool signal, const QString& name) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
LibraryItem* Library::CreateAlbumNode(bool signal, const QString& name, LibraryItem* parent, bool compilation) {
|
||||
LibraryItem* Library::CreateAlbumNode(bool signal, const QString& name,
|
||||
LibraryItem* parent, bool compilation,
|
||||
const QString& art_automatic,
|
||||
const QString& art_manual) {
|
||||
if (signal)
|
||||
beginInsertRows(ItemToIndex(parent), parent->children.count(), parent->children.count());
|
||||
|
||||
|
@ -182,6 +187,12 @@ LibraryItem* Library::CreateAlbumNode(bool signal, const QString& name, LibraryI
|
|||
ret->display_text = PrettyAlbum(name);
|
||||
ret->sort_text = SortTextForAlbum(name);
|
||||
|
||||
// TODO: These should be async
|
||||
/*if (!art_manual.isNull())
|
||||
ret->cover_art.load(art_manual);
|
||||
if (!art_automatic.isNull() && ret->cover_art.isNull())
|
||||
ret->cover_art.load(art_automatic);*/
|
||||
|
||||
if (signal)
|
||||
endInsertRows();
|
||||
|
||||
|
@ -306,8 +317,15 @@ QVariant Library::data(const LibraryItem* item, int role) const {
|
|||
case Qt::DecorationRole:
|
||||
switch (item->type) {
|
||||
case LibraryItem::Type_Album:
|
||||
case LibraryItem::Type_CompilationAlbum:
|
||||
case LibraryItem::Type_CompilationAlbum: {
|
||||
// TODO
|
||||
/*if (item->cover_art.isNull())
|
||||
return no_cover_icon_;
|
||||
else
|
||||
return QIcon(item->cover_art);*/
|
||||
|
||||
return album_icon_;
|
||||
}
|
||||
case LibraryItem::Type_Artist:
|
||||
case LibraryItem::Type_CompilationArtist:
|
||||
return artist_icon_;
|
||||
|
@ -336,8 +354,9 @@ void Library::LazyPopulate(LibraryItem* item) {
|
|||
|
||||
switch (item->type) {
|
||||
case LibraryItem::Type_CompilationArtist:
|
||||
foreach (const QString& album, backend_->Worker()->GetCompilationAlbums(query_options_))
|
||||
CreateAlbumNode(false, album, item, true);
|
||||
foreach (const LibraryBackend::Album& album,
|
||||
backend_->Worker()->GetCompilationAlbums(query_options_))
|
||||
CreateAlbumNode(false, album.album_name, item, true, album.art_automatic, album.art_manual);
|
||||
break;
|
||||
|
||||
case LibraryItem::Type_CompilationAlbum:
|
||||
|
@ -346,8 +365,9 @@ void Library::LazyPopulate(LibraryItem* item) {
|
|||
break;
|
||||
|
||||
case LibraryItem::Type_Artist:
|
||||
foreach (const QString& album, backend_->Worker()->GetAlbumsByArtist(item->key, query_options_))
|
||||
CreateAlbumNode(false, album, item, false);
|
||||
foreach (const LibraryBackend::Album& album,
|
||||
backend_->Worker()->GetAlbumsByArtist(item->key, query_options_))
|
||||
CreateAlbumNode(false, album.album_name, item, false, album.art_automatic, album.art_manual);
|
||||
break;
|
||||
|
||||
case LibraryItem::Type_Album:
|
||||
|
|
|
@ -74,7 +74,10 @@ class Library : public SimpleTreeModel<LibraryItem> {
|
|||
|
||||
LibraryItem* CreateCompilationArtistNode(bool signal);
|
||||
LibraryItem* CreateArtistNode(bool signal, const QString& name);
|
||||
LibraryItem* CreateAlbumNode(bool signal, const QString& name, LibraryItem* parent, bool compilation);
|
||||
LibraryItem* CreateAlbumNode(bool signal, const QString& name,
|
||||
LibraryItem* parent, bool compilation,
|
||||
const QString& art_automatic,
|
||||
const QString& art_manual);
|
||||
LibraryItem* CreateSongNode(bool signal, const Song& song, LibraryItem* parent);
|
||||
|
||||
QString PrettyArtist(QString artist) const;
|
||||
|
@ -104,6 +107,7 @@ class Library : public SimpleTreeModel<LibraryItem> {
|
|||
|
||||
QIcon artist_icon_;
|
||||
QIcon album_icon_;
|
||||
QIcon no_cover_icon_;
|
||||
};
|
||||
|
||||
#endif // LIBRARY_H
|
||||
|
|
|
@ -321,27 +321,13 @@ QStringList LibraryBackend::GetAllArtists(const QueryOptions& opt) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
QStringList LibraryBackend::GetAllAlbums(const QueryOptions &opt) {
|
||||
return GetAlbumsByArtist(QString(), opt);
|
||||
LibraryBackend::AlbumList LibraryBackend::GetAllAlbums(const QueryOptions &opt) {
|
||||
return GetAlbums(QString(), false, opt);
|
||||
}
|
||||
|
||||
QStringList LibraryBackend::GetAlbumsByArtist(const QString& artist, const QueryOptions& opt) {
|
||||
LibraryQuery query(opt);
|
||||
query.SetColumnSpec("DISTINCT album");
|
||||
query.AddCompilationRequirement(false);
|
||||
|
||||
if (!artist.isNull())
|
||||
query.AddWhere("artist", artist);
|
||||
|
||||
QSqlQuery q(query.Query(Connect()));
|
||||
q.exec();
|
||||
if (CheckErrors(q.lastError())) return QStringList();
|
||||
|
||||
QStringList ret;
|
||||
while (q.next()) {
|
||||
ret << q.value(0).toString();
|
||||
}
|
||||
return ret;
|
||||
LibraryBackend::AlbumList LibraryBackend::GetAlbumsByArtist(const QString& artist,
|
||||
const QueryOptions& opt) {
|
||||
return GetAlbums(artist, false, opt);
|
||||
}
|
||||
|
||||
SongList LibraryBackend::GetSongs(const QString& artist, const QString& album, const QueryOptions& opt) {
|
||||
|
@ -392,20 +378,8 @@ bool LibraryBackend::HasCompilations(const QueryOptions& opt) {
|
|||
return q.next();
|
||||
}
|
||||
|
||||
QStringList LibraryBackend::GetCompilationAlbums(const QueryOptions& opt) {
|
||||
LibraryQuery query(opt);
|
||||
query.SetColumnSpec("DISTINCT album");
|
||||
query.AddCompilationRequirement(true);
|
||||
|
||||
QSqlQuery q(query.Query(Connect()));
|
||||
q.exec();
|
||||
if (CheckErrors(q.lastError())) return QStringList();
|
||||
|
||||
QStringList ret;
|
||||
while (q.next()) {
|
||||
ret << q.value(0).toString();
|
||||
}
|
||||
return ret;
|
||||
LibraryBackend::AlbumList LibraryBackend::GetCompilationAlbums(const QueryOptions& opt) {
|
||||
return GetAlbums(QString(), true, opt);
|
||||
}
|
||||
|
||||
SongList LibraryBackend::GetCompilationSongs(const QString& album, const QueryOptions& opt) {
|
||||
|
@ -521,16 +495,21 @@ void LibraryBackend::UpdateCompilations(QSqlQuery& find_songs, QSqlQuery& update
|
|||
CheckErrors(update.lastError());
|
||||
}
|
||||
|
||||
QList<LibraryBackend::AlbumArtInfo>
|
||||
LibraryBackend::GetAlbumArtInfo(const QString& artist,
|
||||
const QueryOptions& opt) {
|
||||
QList<AlbumArtInfo> ret;
|
||||
LibraryBackend::AlbumList LibraryBackend::GetAlbums(const QString& artist,
|
||||
bool compilation,
|
||||
const QueryOptions& opt) {
|
||||
AlbumList ret;
|
||||
|
||||
LibraryQuery query(opt);
|
||||
query.SetColumnSpec("album, artist, compilation, sampler, art_automatic, art_manual");
|
||||
query.SetOrderBy("album");
|
||||
|
||||
if (!artist.isNull())
|
||||
if (compilation) {
|
||||
query.AddCompilationRequirement(true);
|
||||
} else if (!artist.isNull()) {
|
||||
query.AddCompilationRequirement(false);
|
||||
query.AddWhere("artist", artist);
|
||||
}
|
||||
|
||||
QSqlQuery q(query.Query(Connect()));
|
||||
q.exec();
|
||||
|
@ -543,7 +522,7 @@ QList<LibraryBackend::AlbumArtInfo>
|
|||
|
||||
bool compilation = q.value(2).toBool() | q.value(3).toBool();
|
||||
|
||||
AlbumArtInfo info;
|
||||
Album info;
|
||||
info.artist = compilation ? QString() : q.value(1).toString();
|
||||
info.album_name = q.value(0).toString();
|
||||
info.art_automatic = q.value(4).toString();
|
||||
|
@ -555,6 +534,28 @@ QList<LibraryBackend::AlbumArtInfo>
|
|||
return ret;
|
||||
}
|
||||
|
||||
LibraryBackend::Album LibraryBackend::GetAlbumArt(const QString& artist, const QString& album) {
|
||||
Album ret;
|
||||
ret.album_name = album;
|
||||
ret.artist = artist;
|
||||
|
||||
LibraryQuery query = LibraryQuery(QueryOptions());
|
||||
query.SetColumnSpec("art_automatic, art_manual");
|
||||
query.AddWhere("artist", artist);
|
||||
query.AddWhere("album", album);
|
||||
|
||||
QSqlQuery q(query.Query(Connect()));
|
||||
q.exec();
|
||||
if (CheckErrors(q.lastError())) return ret;
|
||||
|
||||
if (q.next()) {
|
||||
ret.art_automatic = q.value(0).toString();
|
||||
ret.art_manual = q.value(1).toString();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void LibraryBackend::UpdateManualAlbumArtAsync(const QString &artist,
|
||||
const QString &album,
|
||||
const QString &art) {
|
||||
|
|
|
@ -17,12 +17,14 @@ class LibraryBackend : public QObject {
|
|||
public:
|
||||
LibraryBackend(QObject* parent = 0);
|
||||
|
||||
struct AlbumArtInfo {
|
||||
struct Album {
|
||||
QString artist;
|
||||
QString album_name;
|
||||
|
||||
QString art_automatic;
|
||||
QString art_manual;
|
||||
};
|
||||
typedef QList<Album> AlbumList;
|
||||
|
||||
// This actually refers to the location of the sqlite database
|
||||
static QString DefaultDirectory();
|
||||
|
@ -36,16 +38,17 @@ class LibraryBackend : public QObject {
|
|||
SongList FindSongsInDirectory(int id);
|
||||
|
||||
QStringList GetAllArtists(const QueryOptions& opt = QueryOptions());
|
||||
QStringList GetAllAlbums(const QueryOptions& opt = QueryOptions());
|
||||
QStringList GetAlbumsByArtist(const QString& artist, const QueryOptions& opt = QueryOptions());
|
||||
SongList GetSongs(const QString& artist, const QString& album, const QueryOptions& opt = QueryOptions());
|
||||
|
||||
bool HasCompilations(const QueryOptions& opt = QueryOptions());
|
||||
QStringList GetCompilationAlbums(const QueryOptions& opt = QueryOptions());
|
||||
SongList GetCompilationSongs(const QString& album, const QueryOptions& opt = QueryOptions());
|
||||
|
||||
QList<AlbumArtInfo> GetAlbumArtInfo(const QString& artist = QString(), const QueryOptions& opt = QueryOptions());
|
||||
AlbumList GetAllAlbums(const QueryOptions& opt = QueryOptions());
|
||||
AlbumList GetAlbumsByArtist(const QString& artist, const QueryOptions& opt = QueryOptions());
|
||||
AlbumList GetCompilationAlbums(const QueryOptions& opt = QueryOptions());
|
||||
|
||||
void UpdateManualAlbumArtAsync(const QString& artist, const QString& album, const QString& art);
|
||||
Album GetAlbumArt(const QString& artist, const QString& album);
|
||||
|
||||
Song GetSongById(int id);
|
||||
|
||||
|
@ -94,6 +97,8 @@ class LibraryBackend : public QObject {
|
|||
void UpdateCompilations(QSqlQuery& find_songs, QSqlQuery& update,
|
||||
SongList& updated_songs,
|
||||
const QString& album, int sampler);
|
||||
AlbumList GetAlbums(const QString& artist, bool compilation = false,
|
||||
const QueryOptions& opt = QueryOptions());
|
||||
|
||||
private:
|
||||
static const char* kDatabaseName;
|
||||
|
|
|
@ -25,6 +25,9 @@ class LibraryItem : public SimpleTreeItem<LibraryItem> {
|
|||
: SimpleTreeItem<LibraryItem>(type, key, parent) {}
|
||||
|
||||
Song song;
|
||||
|
||||
// Maybe stores album cover art
|
||||
QPixmap cover_art;
|
||||
};
|
||||
|
||||
#endif // LIBRARYITEM_H
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<string>Clementine</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
|
@ -294,7 +294,7 @@
|
|||
<item>
|
||||
<widget class="QToolButton" name="library_filter_clear">
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/clear.png</normaloff>:/clear.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
|
@ -318,7 +318,7 @@
|
|||
<item>
|
||||
<widget class="QToolButton" name="library_options">
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/configure.png</normaloff>:/configure.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
|
@ -348,9 +348,6 @@
|
|||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="uniformRowHeights">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="allColumnsShowFocus">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
|
@ -499,7 +496,7 @@
|
|||
</widget>
|
||||
<action name="action_previous_track">
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/media-skip-backward.png</normaloff>:/media-skip-backward.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -508,7 +505,7 @@
|
|||
</action>
|
||||
<action name="action_play_pause">
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/media-playback-start.png</normaloff>:/media-playback-start.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -520,7 +517,7 @@
|
|||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/media-playback-stop.png</normaloff>:/media-playback-stop.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -529,7 +526,7 @@
|
|||
</action>
|
||||
<action name="action_next_track">
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/media-skip-forward.png</normaloff>:/media-skip-forward.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -538,7 +535,7 @@
|
|||
</action>
|
||||
<action name="action_quit">
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/exit.png</normaloff>:/exit.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -550,7 +547,7 @@
|
|||
</action>
|
||||
<action name="action_stop_after_this_track">
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/media-playback-stop.png</normaloff>:/media-playback-stop.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -616,7 +613,7 @@
|
|||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/last.fm/love.png</normaloff>:/last.fm/love.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -628,7 +625,7 @@
|
|||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/last.fm/ban.png</normaloff>:/last.fm/ban.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -637,7 +634,7 @@
|
|||
</action>
|
||||
<action name="action_clear_playlist">
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/clear-list.png</normaloff>:/clear-list.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -649,7 +646,7 @@
|
|||
</action>
|
||||
<action name="action_edit_track">
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/edit-track.png</normaloff>:/edit-track.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -658,7 +655,7 @@
|
|||
</action>
|
||||
<action name="action_configure">
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/configure.png</normaloff>:/configure.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -672,7 +669,7 @@
|
|||
</action>
|
||||
<action name="action_shuffle">
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/shuffle.png</normaloff>:/shuffle.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -681,7 +678,7 @@
|
|||
</action>
|
||||
<action name="action_add_media">
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/open_media.png</normaloff>:/open_media.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -690,7 +687,7 @@
|
|||
</action>
|
||||
<action name="action_add_stream">
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/open_stream.png</normaloff>:/open_stream.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -699,7 +696,7 @@
|
|||
</action>
|
||||
<action name="action_open_media">
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/open_media.png</normaloff>:/open_media.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -713,7 +710,7 @@
|
|||
</action>
|
||||
<action name="action_global_shortcuts">
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/configure.png</normaloff>:/configure.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -722,7 +719,7 @@
|
|||
</action>
|
||||
<action name="action_cover_manager">
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/download.png</normaloff>:/download.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -770,8 +767,6 @@
|
|||
<header>radioview.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../data/data.qrc"/>
|
||||
</resources>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
Loading…
Reference in New Issue