From 2c20e711d8337b8db3c6d77b92242933849bd570 Mon Sep 17 00:00:00 2001 From: Paul Harrison Date: Sun, 21 Apr 2013 11:20:35 +0100 Subject: [PATCH] MythMusic: in the playlist editor tree sort album tracks by track number Also now we sort the nodes in the tree make sure the tracks get added to the active playlist in the same order they are displayed in. Fixes #11398. --- .../mythmusic/playlisteditorview.cpp | 222 ++++++++++-------- .../mythmusic/mythmusic/playlisteditorview.h | 1 + 2 files changed, 120 insertions(+), 103 deletions(-) diff --git a/mythplugins/mythmusic/mythmusic/playlisteditorview.cpp b/mythplugins/mythmusic/mythmusic/playlisteditorview.cpp index b5242c33183..efb01417d9e 100644 --- a/mythplugins/mythmusic/mythmusic/playlisteditorview.cpp +++ b/mythplugins/mythmusic/mythmusic/playlisteditorview.cpp @@ -463,69 +463,9 @@ bool PlaylistEditorView::keyPressEvent(QKeyEvent *event) if (mnode) { - if (mnode->getAction() == "trackid") - { - m_songList.clear(); - m_songList.append(node->getInt()); - } - else if ((mnode->getAction() == "playlists") || (mnode->getAction() == "smartplaylists") || (mnode->getAction() == "smartplaylistcategory")) - { - handled = false; - } - else if (mnode->getAction() == "playlist") - { - // get list of tracks to add - int playlistID = mnode->getInt(); - Playlist *playlist = gMusicData->all_playlists->getPlaylist(playlistID); - - if (playlist) - { - SongList songlist = playlist->getSongs(); - if (songlist.count() > 0) - { - m_songList.clear(); - for (int x = 0; x < songlist.count(); x++) - { - m_songList.append(songlist.at(x)->ID()); - } - } - else - { - handled = false; - } - } - } - else if (mnode->getAction() == "smartplaylist") - { - // add the selected smart playlist's tracks to the song list - QList *children = mnode->getAllChildren(); - if (children->count() > 0) - { - m_songList.clear(); - for (int x = 0; x < children->count(); x++) - { - MythGenericTree *childnode = children->at(x); - m_songList.append(childnode->getInt()); - } - } - else - { - handled = false; - } - } - else - { - m_songList.clear(); - MetadataPtrList *tracks = qVariantValue (mnode->GetData()); - for (int x = 0; x < tracks->count(); x++) - { - Metadata *mdata = tracks->at(x); - if (mdata) - m_songList.append((int)mdata->ID()); - } - } + updateSonglist(mnode); - if (handled) + if (m_songList.count() > 0) { m_playlistOptions.playPLOption = PL_FIRST; m_playlistOptions.insertPLOption = PL_REPLACE; @@ -551,6 +491,100 @@ bool PlaylistEditorView::keyPressEvent(QKeyEvent *event) return handled; } +void PlaylistEditorView::updateSonglist(MusicGenericTree *node) +{ + m_songList.clear(); + + if (node->getAction() == "playlists" || + node->getAction() == "smartplaylists" || + node->getAction() == "smartplaylistcategory") + { + } + else if (node->getAction() == "trackid") + { + m_songList.append(node->getInt()); + } + else if (node->getAction() == "all tracks" || + node->getAction() == "albums" || + node->getAction() == "compartists" || + node->getAction() == "artists" || + node->getAction() == "genres" || + node->getAction() == "ratings" || + node->getAction() == "years") + { + // get the list of tracks from the previous 'All Tracks' node + MusicGenericTree *allTracksNode = dynamic_cast(node->getParent()->getChildAt(0)); + if (allTracksNode) + { + for (int x = 0; x < allTracksNode->childCount(); x++) + { + MythGenericTree *trackNode = allTracksNode->getChildAt(x); + if (trackNode) + m_songList.append(trackNode->getInt()); + } + } + } + else if (node->getAction() == "album" || + node->getAction() == "artist" || + node->getAction() == "genre" || + node->getAction() == "rating" || + node->getAction() == "year" || + node->getAction() == "compilations" || + node->getAction() == "compartist") + { + // get the list of tracks from the 'All Tracks' node + MusicGenericTree *allTracksNode = dynamic_cast(node->getChildAt(0)); + if (allTracksNode) + { + filterTracks(allTracksNode); + + for (int x = 0; x < allTracksNode->childCount(); x++) + { + MythGenericTree *trackNode = allTracksNode->getChildAt(x); + if (trackNode) + m_songList.append(trackNode->getInt()); + } + } + } + else if (node->getAction() == "smartplaylist") + { + // add the selected smart playlist's tracks to the song list + QList *children = node->getAllChildren(); + for (int x = 0; x < children->count(); x++) + { + MythGenericTree *childnode = children->at(x); + m_songList.append(childnode->getInt()); + } + } + else if (node->getAction() == "playlist") + { + // get list of tracks to add from the playlist + int playlistID = node->getInt(); + Playlist *playlist = gMusicData->all_playlists->getPlaylist(playlistID); + + if (playlist) + { + SongList songlist = playlist->getSongs(); + + for (int x = 0; x < songlist.count(); x++) + { + m_songList.append(songlist.at(x)->ID()); + } + } + } + else + { + // fall back to getting the tracks from the MetadataPtrList + MetadataPtrList *tracks = qVariantValue (node->GetData()); + for (int x = 0; x < tracks->count(); x++) + { + Metadata *mdata = tracks->at(x); + if (mdata) + m_songList.append((int)mdata->ID()); + } + } +} + void PlaylistEditorView::ShowMenu(void) { if (GetFocusWidget() == m_playlistTree) @@ -584,17 +618,10 @@ void PlaylistEditorView::ShowMenu(void) else { menu = createPlaylistOptionsMenu(); - - m_songList.clear(); - MetadataPtrList *tracks = qVariantValue (mnode->GetData()); - for (int x = 0; x < tracks->count(); x++) - { - Metadata *mdata = tracks->at(x); - if (mdata) - m_songList.append((int)mdata->ID()); - } } + updateSonglist(mnode); + if (menu) { menu->AddItem(tr("More Options"), NULL, createMainMenu()); @@ -632,21 +659,6 @@ MythMenu* PlaylistEditorView::createPlaylistMenu(void) menu->AddItem(tr("Replace Tracks")); menu->AddItem(tr("Add Tracks")); menu->AddItem(tr("Remove Playlist")); - - // get list of tracks to add - m_songList.clear(); - int playlistID = mnode->getInt(); - Playlist *playlist = gMusicData->all_playlists->getPlaylist(playlistID); - - if (playlist) - { - SongList songlist = playlist->getSongs(); - - for (int x = 0; x < songlist.count(); x++) - { - m_songList.append(songlist.at(x)->ID()); - } - } } } @@ -682,15 +694,6 @@ MythMenu* PlaylistEditorView::createSmartPlaylistMenu(void) menu->AddItem(tr("Edit Smart Playlist")); menu->AddItem(tr("New Smart Playlist")); menu->AddItem(tr("Remove Smart Playlist")); - - // add the selected smart playlist's tracks to the song list - m_songList.clear(); - QList *children = mnode->getAllChildren(); - for (int x = 0; x < children->count(); x++) - { - MythGenericTree *childnode = children->at(x); - m_songList.append(childnode->getInt()); - } } } @@ -953,13 +956,28 @@ void PlaylistEditorView::filterTracks(MusicGenericTree *node) { QMap map; QStringList list; + bool isAlbum = false; + MusicGenericTree *parentNode = dynamic_cast(node->getParent()); + + if (parentNode) + isAlbum = parentNode->getAction() == "album"; for (int x = 0; x < tracks->count(); x++) { Metadata *mdata = tracks->at(x); if (mdata) { - map.insertMulti(mdata->Title(), mdata->ID()); + QString key = mdata->Title(); + + // Add the track number if an album is selected + if (isAlbum && mdata->Track() > 0) + { + key.prepend(QString::number(mdata->Track()) + " - "); + if (mdata->Track() < 10) + key.prepend("0"); + } + + map.insertMulti(key, mdata->ID()); } } @@ -973,7 +991,7 @@ void PlaylistEditorView::filterTracks(MusicGenericTree *node) newnode->setCheck( hasTrack ? MythUIButtonListItem::FullChecked : MythUIButtonListItem::NotChecked); ++i; } - + node->sortByString(); // Case-insensitive sort } else if (node->getAction() == "artists") @@ -1007,7 +1025,7 @@ void PlaylistEditorView::filterTracks(MusicGenericTree *node) newnode->SetData(qVariantFromValue(i.value())); ++i; } - + node->sortByString(); // Case-insensitive sort } else if (node->getAction() == "compartists") @@ -1044,7 +1062,7 @@ void PlaylistEditorView::filterTracks(MusicGenericTree *node) newnode->SetData(qVariantFromValue(i.value())); ++i; } - + node->sortByString(); // Case-insensitive sort } else if (node->getAction() == "albums") @@ -1078,7 +1096,7 @@ void PlaylistEditorView::filterTracks(MusicGenericTree *node) newnode->SetData(qVariantFromValue(i.value())); ++i; } - + node->sortByString(); // Case-insensitive sort } else if (node->getAction() == "genres") @@ -1112,7 +1130,7 @@ void PlaylistEditorView::filterTracks(MusicGenericTree *node) newnode->SetData(qVariantFromValue(i.value())); ++i; } - + node->sortByString(); // Case-insensitive sort } else if (node->getAction() == "ratings") @@ -1147,7 +1165,6 @@ void PlaylistEditorView::filterTracks(MusicGenericTree *node) newnode->SetData(qVariantFromValue(i.value())); ++i; } - } else if (node->getAction() == "years") { @@ -1181,7 +1198,6 @@ void PlaylistEditorView::filterTracks(MusicGenericTree *node) newnode->SetData(qVariantFromValue(i.value())); ++i; } - } else if (node->getAction() == "directory") { diff --git a/mythplugins/mythmusic/mythmusic/playlisteditorview.h b/mythplugins/mythmusic/mythmusic/playlisteditorview.h index adda082967d..1972c26a5c7 100644 --- a/mythplugins/mythmusic/mythmusic/playlisteditorview.h +++ b/mythplugins/mythmusic/mythmusic/playlisteditorview.h @@ -96,6 +96,7 @@ class PlaylistEditorView : public MusicCommon void updateSelectedTracks(void); void updateSelectedTracks(MusicGenericTree *node); + void updateSonglist(MusicGenericTree *node); void createRootNode(void); void reloadTree(void);