diff --git a/ChangeLog b/ChangeLog index 48ec27cac..7cb658951 100644 --- a/ChangeLog +++ b/ChangeLog @@ -32,6 +32,8 @@ 16. Use cache by default for devices. 17. Compress cache files. 18. Save remote device library settings on remote device. +19. When using list or icon view, only show genres that are relevant to the + current level. 0.9.2 ----- diff --git a/gui/albumspage.cpp b/gui/albumspage.cpp index 7707ff0d0..61e85d776 100644 --- a/gui/albumspage.cpp +++ b/gui/albumspage.cpp @@ -83,6 +83,7 @@ AlbumsPage::AlbumsPage(MainWindow *p) connect(genreCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(searchItems())); connect(view, SIGNAL(searchItems()), this, SLOT(searchItems())); connect(view, SIGNAL(itemsSelected(bool)), this, SLOT(controlActions())); + connect(view, SIGNAL(rootIndexSet(QModelIndex)), this, SLOT(updateGenres(QModelIndex))); connect(MPDConnection::self(), SIGNAL(updatingLibrary()), view, SLOT(showSpinner())); connect(MPDConnection::self(), SIGNAL(updatedLibrary()), view, SLOT(hideSpinner())); } @@ -205,6 +206,18 @@ void AlbumsPage::searchItems() } } +void AlbumsPage::updateGenres(const QModelIndex &idx) +{ + if (idx.isValid()) { + QModelIndex m=proxy.mapToSource(idx); + if (m.isValid() && static_cast(m.internalPointer())->isAlbum()) { + genreCombo->update(static_cast(m.internalPointer())->genres); + return; + } + } + genreCombo->update(MusicLibraryModel::self()->genres()); +} + void AlbumsPage::controlActions() { QModelIndexList selected=view->selectedIndexes(); diff --git a/gui/albumspage.h b/gui/albumspage.h index 7c2f8ff48..dd9757cfe 100644 --- a/gui/albumspage.h +++ b/gui/albumspage.h @@ -68,6 +68,7 @@ public Q_SLOTS: void itemActivated(const QModelIndex &); void controlActions(); void searchItems(); + void updateGenres(const QModelIndex &); private: AlbumsProxyModel proxy; diff --git a/gui/librarypage.cpp b/gui/librarypage.cpp index c41a2ba13..1e2100327 100644 --- a/gui/librarypage.cpp +++ b/gui/librarypage.cpp @@ -26,6 +26,7 @@ #include "mpdstats.h" #include "covers.h" #include "musiclibrarymodel.h" +#include "musiclibraryitemartist.h" #include "musiclibraryitemalbum.h" #include "musiclibraryitemsong.h" #include "mainwindow.h" @@ -91,6 +92,7 @@ LibraryPage::LibraryPage(MainWindow *p) connect(view, SIGNAL(itemsSelected(bool)), this, SLOT(controlActions())); connect(view, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(itemDoubleClicked(const QModelIndex &))); connect(view, SIGNAL(searchItems()), this, SLOT(searchItems())); + connect(view, SIGNAL(rootIndexSet(QModelIndex)), this, SLOT(updateGenres(QModelIndex))); proxy.setSourceModel(MusicLibraryModel::self()); view->setTopText(i18n("Library")); view->setModel(&proxy); @@ -273,6 +275,24 @@ void LibraryPage::searchItems() } } +void LibraryPage::updateGenres(const QModelIndex &idx) +{ + if (idx.isValid()) { + QModelIndex m=proxy.mapToSource(idx); + if (m.isValid()) { + MusicLibraryItem::Type itemType=static_cast(m.internalPointer())->itemType(); + if (itemType==MusicLibraryItem::Type_Artist) { + genreCombo->update(static_cast(m.internalPointer())->genres()); + return; + } else if (itemType==MusicLibraryItem::Type_Album) { + genreCombo->update(static_cast(m.internalPointer())->genres()); + return; + } + } + } + genreCombo->update(MusicLibraryModel::self()->genres()); +} + void LibraryPage::controlActions() { QModelIndexList selected=view->selectedIndexes(); diff --git a/gui/librarypage.h b/gui/librarypage.h index 81fd5d46b..c8e836c60 100644 --- a/gui/librarypage.h +++ b/gui/librarypage.h @@ -71,6 +71,7 @@ public Q_SLOTS: void searchItems(); void controlActions(); void databaseUpdated(); + void updateGenres(const QModelIndex &); private: MusicLibraryProxyModel proxy; diff --git a/models/musiclibrarymodel.h b/models/musiclibrarymodel.h index 5170151bb..0268dcefc 100644 --- a/models/musiclibrarymodel.h +++ b/models/musiclibrarymodel.h @@ -87,6 +87,7 @@ public: void setLargeImages(bool a) { rootItem->setLargeImages(a); } void setSupportsAlbumArtistTag(bool s) { rootItem->setSupportsAlbumArtistTag(s); } void toggleGrouping(); + const QSet & genres() const { return rootItem->genres(); } public Q_SLOTS: void updateMusicLibrary(MusicLibraryItemRoot * root, QDateTime dbUpdate = QDateTime(), bool fromFile = false); diff --git a/widgets/genrecombo.cpp b/widgets/genrecombo.cpp index c04de58c8..33fb79e74 100644 --- a/widgets/genrecombo.cpp +++ b/widgets/genrecombo.cpp @@ -41,6 +41,19 @@ void GenreCombo::update(const QSet &g) qSort(entries); entries.prepend(i18n("All Genres")); + if (count()==entries.count()) { + bool noChange=true; + for (int i=0; i & entries() const { return genres; } -private Q_SLOTS: +public Q_SLOTS: void update(const QSet &g); private: diff --git a/widgets/itemview.cpp b/widgets/itemview.cpp index 00e1fcdc1..632728e92 100644 --- a/widgets/itemview.cpp +++ b/widgets/itemview.cpp @@ -530,6 +530,7 @@ void ItemView::setMode(Mode m) setLevel(0); listView->setRootIndex(QModelIndex()); itemModel->setRootIndex(QModelIndex()); + emit rootIndexSet(QModelIndex()); if (Mode_IconTop!=mode) { listView->setGridSize(listGridSize); listView->setViewMode(QListView::ListMode); @@ -733,6 +734,7 @@ void ItemView::showIndex(const QModelIndex &idx, bool scrollTo) if (idx.parent().isValid()) { QList indexes; QModelIndex i=idx.parent(); + QModelIndex p=idx; while (i.isValid()) { indexes.prepend(i); i=i.parent(); @@ -741,7 +743,10 @@ void ItemView::showIndex(const QModelIndex &idx, bool scrollTo) listView->setRootIndex(QModelIndex()); itemModel->setRootIndex(QModelIndex()); foreach (const QModelIndex &i, indexes) { - activateItem(i); + activateItem(i, false); + } + if (p.isValid()) { + emit rootIndexSet(p); } if (scrollTo) { listView->scrollTo(idx, QAbstractItemView::PositionAtTop); @@ -827,6 +832,7 @@ void ItemView::backActivated() setLevel(currentLevel-1); itemModel->setRootIndex(listView->rootIndex().parent()); listView->setRootIndex(listView->rootIndex().parent()); + emit rootIndexSet(listView->rootIndex().parent()); if (qobject_cast(listView->model())) { QModelIndex idx=static_cast(listView->model())->mapFromSource(prevTopIndex); @@ -867,7 +873,7 @@ void ItemView::itemActivated(const QModelIndex &index) } } -void ItemView::activateItem(const QModelIndex &index) +void ItemView::activateItem(const QModelIndex &index, bool emitRootSet) { if ((act1 || act2 || toggle) && ActionItemDelegate::hasActions(index, actLevel) && getAction(index)) { return; @@ -892,6 +898,9 @@ void ItemView::activateItem(const QModelIndex &index) listSearch->setPlaceholderText(i18n("Search %1...").arg(text)); listView->setRootIndex(index); itemModel->setRootIndex(index); + if (emitRootSet) { + emit rootIndexSet(index); + } listView->scrollToTop(); } } diff --git a/widgets/itemview.h b/widgets/itemview.h index eb5d1b04e..daf85b8f8 100644 --- a/widgets/itemview.h +++ b/widgets/itemview.h @@ -131,6 +131,7 @@ Q_SIGNALS: void searchItems(); void itemsSelected(bool); void doubleClicked(const QModelIndex &); + void rootIndexSet(const QModelIndex &); private Q_SLOTS: void itemClicked(const QModelIndex &index); @@ -138,7 +139,7 @@ private Q_SLOTS: void delaySearchItems(); private: - void activateItem(const QModelIndex &index); + void activateItem(const QModelIndex &index, bool emitRootSet=true); QAction * getAction(const QModelIndex &index); private: