Skip to content

Commit

Permalink
MythMusic: in the playlist editor tree sort album tracks by track number
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Paul Harrison committed Apr 21, 2013
1 parent b4751aa commit 2c20e71
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 103 deletions.
222 changes: 119 additions & 103 deletions mythplugins/mythmusic/mythmusic/playlisteditorview.cpp
Expand Up @@ -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<MythGenericTree*> *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<MetadataPtrList*> (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;
Expand All @@ -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<MusicGenericTree*>(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<MusicGenericTree*>(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<MythGenericTree*> *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<MetadataPtrList*> (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)
Expand Down Expand Up @@ -584,17 +618,10 @@ void PlaylistEditorView::ShowMenu(void)
else
{
menu = createPlaylistOptionsMenu();

m_songList.clear();
MetadataPtrList *tracks = qVariantValue<MetadataPtrList*> (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());
Expand Down Expand Up @@ -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());
}
}
}
}

Expand Down Expand Up @@ -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<MythGenericTree*> *children = mnode->getAllChildren();
for (int x = 0; x < children->count(); x++)
{
MythGenericTree *childnode = children->at(x);
m_songList.append(childnode->getInt());
}
}
}

Expand Down Expand Up @@ -953,13 +956,28 @@ void PlaylistEditorView::filterTracks(MusicGenericTree *node)
{
QMap<QString, int> map;
QStringList list;
bool isAlbum = false;
MusicGenericTree *parentNode = dynamic_cast<MusicGenericTree*>(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());
}
}

Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -1147,7 +1165,6 @@ void PlaylistEditorView::filterTracks(MusicGenericTree *node)
newnode->SetData(qVariantFromValue(i.value()));
++i;
}

}
else if (node->getAction() == "years")
{
Expand Down Expand Up @@ -1181,7 +1198,6 @@ void PlaylistEditorView::filterTracks(MusicGenericTree *node)
newnode->SetData(qVariantFromValue(i.value()));
++i;
}

}
else if (node->getAction() == "directory")
{
Expand Down
1 change: 1 addition & 0 deletions mythplugins/mythmusic/mythmusic/playlisteditorview.h
Expand Up @@ -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);
Expand Down

0 comments on commit 2c20e71

Please sign in to comment.