When using list or icon view, only show genres that are relevant to the current level.

BUG:143
This commit is contained in:
craig.p.drummond
2012-12-19 20:04:08 +00:00
committed by craig.p.drummond
parent 5c497b5aa4
commit fa9132627c
10 changed files with 65 additions and 4 deletions

View File

@@ -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
-----

View File

@@ -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<AlbumsModel::Item *>(m.internalPointer())->isAlbum()) {
genreCombo->update(static_cast<AlbumsModel::AlbumItem *>(m.internalPointer())->genres);
return;
}
}
genreCombo->update(MusicLibraryModel::self()->genres());
}
void AlbumsPage::controlActions()
{
QModelIndexList selected=view->selectedIndexes();

View File

@@ -68,6 +68,7 @@ public Q_SLOTS:
void itemActivated(const QModelIndex &);
void controlActions();
void searchItems();
void updateGenres(const QModelIndex &);
private:
AlbumsProxyModel proxy;

View File

@@ -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<MusicLibraryItem *>(m.internalPointer())->itemType();
if (itemType==MusicLibraryItem::Type_Artist) {
genreCombo->update(static_cast<MusicLibraryItemArtist *>(m.internalPointer())->genres());
return;
} else if (itemType==MusicLibraryItem::Type_Album) {
genreCombo->update(static_cast<MusicLibraryItemAlbum *>(m.internalPointer())->genres());
return;
}
}
}
genreCombo->update(MusicLibraryModel::self()->genres());
}
void LibraryPage::controlActions()
{
QModelIndexList selected=view->selectedIndexes();

View File

@@ -71,6 +71,7 @@ public Q_SLOTS:
void searchItems();
void controlActions();
void databaseUpdated();
void updateGenres(const QModelIndex &);
private:
MusicLibraryProxyModel proxy;

View File

@@ -87,6 +87,7 @@ public:
void setLargeImages(bool a) { rootItem->setLargeImages(a); }
void setSupportsAlbumArtistTag(bool s) { rootItem->setSupportsAlbumArtistTag(s); }
void toggleGrouping();
const QSet<QString> & genres() const { return rootItem->genres(); }
public Q_SLOTS:
void updateMusicLibrary(MusicLibraryItemRoot * root, QDateTime dbUpdate = QDateTime(), bool fromFile = false);

View File

@@ -41,6 +41,19 @@ void GenreCombo::update(const QSet<QString> &g)
qSort(entries);
entries.prepend(i18n("All Genres"));
if (count()==entries.count()) {
bool noChange=true;
for (int i=0; i<count(); ++i) {
if (itemText(i)!=entries.at(i)) {
noChange=false;
break;
}
}
if (noChange) {
return;
}
}
QString currentFilter = currentIndex() ? currentText() : QString();
clear();

View File

@@ -36,7 +36,7 @@ public:
const QSet<QString> & entries() const { return genres; }
private Q_SLOTS:
public Q_SLOTS:
void update(const QSet<QString> &g);
private:

View File

@@ -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<QModelIndex> 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<QSortFilterProxyModel *>(listView->model())) {
QModelIndex idx=static_cast<QSortFilterProxyModel *>(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();
}
}

View File

@@ -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: