From fdb24f8e2d0987532fd9263ff5fbb88bb09fcc1a Mon Sep 17 00:00:00 2001 From: "craig.p.drummond" Date: Sun, 6 Oct 2013 18:37:58 +0000 Subject: [PATCH] Add a config item to configure album-view to load all covers immediately. BUG: 312 --- ChangeLog | 3 +++ README | 6 ++++++ gui/albumspage.cpp | 25 +++++++++++++++++++++++++ gui/albumspage.h | 11 +++++++++++ gui/settings.cpp | 5 +++++ gui/settings.h | 1 + models/albumsmodel.cpp | 25 +++++++++++++++++++++++++ models/albumsmodel.h | 5 ++++- 8 files changed, 80 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 77e88ec04..f87876030 100644 --- a/ChangeLog +++ b/ChangeLog @@ -59,6 +59,9 @@ 29. Move media-keys setting into shortcuts page. 30. Add a config item to disable all network access. Needs to be set manually, see README for details. +31. Add a config item to configure album-view to load all covers immediately, + rather than waiting for then to be displayed. Again, no UI for this, and + see README for details. 1.1.3 ----- diff --git a/README b/README index 2e7957652..e9c52ed6a 100644 --- a/README +++ b/README @@ -302,6 +302,11 @@ networkAccessEnabled= Configure whether Cantata should be allowed to make networks requests - for accessing covers, etc. By default this is set to true. +albumViewLoadAll= + If set to true, then when th ealbum view is shown it will request all covers + covers immediately - rather than waiting for the cover to be displayed. + Default is false. + e.g. [General] iconTheme=oxygen @@ -309,6 +314,7 @@ maxCoverFindPerIteration=5 maxCoverUpdatePerIteration=5 cueFileCodecs=GBK, big5-0 networkAccessEnabled=false +albumViewLoadAll=true 7. CUE Files diff --git a/gui/albumspage.cpp b/gui/albumspage.cpp index 4cde9af25..0a5291e43 100644 --- a/gui/albumspage.cpp +++ b/gui/albumspage.cpp @@ -34,6 +34,7 @@ AlbumsPage::AlbumsPage(QWidget *p) : QWidget(p) + , coverLoad(Settings::self()->albumViewLoadAll() ? CL_LoadAll : CL_LoadAsRequired) { setupUi(this); addToPlayQueue->setDefaultAction(StdActions::self()->addToPlayQueueAction); @@ -67,6 +68,7 @@ AlbumsPage::AlbumsPage(QWidget *p) view->setModel(&proxy); connect(MusicLibraryModel::self(), SIGNAL(updateGenres(const QSet &)), genreCombo, SLOT(update(const QSet &))); + connect(AlbumsModel::self(), SIGNAL(updated()), this, SLOT(albumsUpdated())); connect(this, SIGNAL(add(const QStringList &, bool, quint8)), MPDConnection::self(), SLOT(add(const QStringList &, bool, quint8))); connect(this, SIGNAL(addSongsToPlaylist(const QString &, const QStringList &)), MPDConnection::self(), SLOT(addToPlaylist(const QString &, const QStringList &))); connect(genreCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(searchItems())); @@ -87,6 +89,15 @@ void AlbumsPage::setView(int v) view->setMode((ItemView::Mode)v); } +void AlbumsPage::showEvent(QShowEvent *e) +{ + if (CL_LoadAll==coverLoad) { + AlbumsModel::self()->loadAllCovers(); + coverLoad=CL_Loaded; + } + QWidget::showEvent(e); +} + void AlbumsPage::clear() { AlbumsModel::self()->clear(); @@ -107,6 +118,20 @@ void AlbumsPage::setItemSize(int v) } } +void AlbumsPage::albumsUpdated() +{ + if (CL_LoadAsRequired==coverLoad) { + return; + } + + if (isVisible()) { + AlbumsModel::self()->loadAllCovers(); + coverLoad=CL_Loaded; + } else { + coverLoad=CL_LoadAll; + } +} + QStringList AlbumsPage::selectedFiles(bool allowPlaylists) const { QModelIndexList selected = view->selectedIndexes(); diff --git a/gui/albumspage.h b/gui/albumspage.h index 170008782..3099e82b0 100644 --- a/gui/albumspage.h +++ b/gui/albumspage.h @@ -34,6 +34,14 @@ class MusicLibraryItemRoot; class AlbumsPage : public QWidget, public Ui::AlbumsPage { Q_OBJECT + + enum CoverLoad + { + CL_LoadAsRequired, + CL_LoadAll, + CL_Loaded + }; + public: AlbumsPage(QWidget *p); virtual ~AlbumsPage(); @@ -52,6 +60,7 @@ public: void focusSearch() { view->focusSearch(); } void goBack() { view->backActivated(); } void goTop() { view->setLevel(0); } + void showEvent(QShowEvent *e); private: void setItemSize(int v); @@ -69,8 +78,10 @@ public Q_SLOTS: void controlActions(); void searchItems(); void updateGenres(const QModelIndex &); + void albumsUpdated(); private: + CoverLoad coverLoad; AlbumsProxyModel proxy; }; diff --git a/gui/settings.cpp b/gui/settings.cpp index ff8a61497..fb369c828 100644 --- a/gui/settings.cpp +++ b/gui/settings.cpp @@ -753,6 +753,11 @@ bool Settings::networkAccessEnabled() return GET_BOOL("networkAccessEnabled", true); } +bool Settings::albumViewLoadAll() +{ + return GET_BOOL("albumViewLoadAll", false); +} + void Settings::removeConnectionDetails(const QString &v) { if (v==currentConnection()) { diff --git a/gui/settings.h b/gui/settings.h index a69546bef..cc741b433 100644 --- a/gui/settings.h +++ b/gui/settings.h @@ -188,6 +188,7 @@ public: int maxCoverUpdatePerIteration(); QStringList cueFileCodecs(); bool networkAccessEnabled(); + bool albumViewLoadAll(); void removeConnectionDetails(const QString &v); void saveConnectionDetails(const MPDConnectionDetails &v); diff --git a/models/albumsmodel.cpp b/models/albumsmodel.cpp index d5034bec5..2f3c75f36 100644 --- a/models/albumsmodel.cpp +++ b/models/albumsmodel.cpp @@ -373,6 +373,7 @@ void AlbumsModel::update(const MusicLibraryItemRoot *root) return; } + bool changesMade=false; bool resettingModel=items.isEmpty() || 0==root->childCount(); if (resettingModel) { beginResetModel(); @@ -422,6 +423,7 @@ void AlbumsModel::update(const MusicLibraryItemRoot *root) } if (!found) { + changesMade=true; AlbumItem *a=new AlbumItem(artist, album, albumItem->year()); a->setSongs(albumItem); a->genres=albumItem->genres(); @@ -452,6 +454,10 @@ void AlbumsModel::update(const MusicLibraryItemRoot *root) } } } + + if (changesMade) { + emit updated(); + } } void AlbumsModel::setCover(const Song &song, const QImage &img, const QString &file, bool update) @@ -532,6 +538,25 @@ void AlbumsModel::setAlbumSort(int s) } } +void AlbumsModel::loadAllCovers() +{ + if (items.isEmpty()) { + return; + } + int iSize=iconSize(); + if (!iSize) { + return; + } + foreach (AlbumItem *al, items) { + if (!al->coverRequested && Song::SingleTracks!=al->type) { + al->getCover(); + if (!al->cover) { + al->coverRequested=true; + } + } + } +} + AlbumsModel::AlbumItem::AlbumItem(const QString &ar, const QString &al, quint16 y) : artist(ar) , album(al) diff --git a/models/albumsmodel.h b/models/albumsmodel.h index 0dc5bafff..96b61b30c 100644 --- a/models/albumsmodel.h +++ b/models/albumsmodel.h @@ -124,7 +124,10 @@ public: void setEnabled(bool e); int albumSort() const; void setAlbumSort(int s); -// void getCovers(); + void loadAllCovers(); + +Q_SIGNALS: + void updated(); public Q_SLOTS: void setCover(const Song &song, const QImage &img, const QString &file, bool update=false);