Permalink
Browse files

MythMusic: immediately play songs from playlist editor when PLAY is p…

…ressed

When the playlist tree has focus and PLAY is pressed all the tracks below the
current node will be added to playlist and the first track will start playing.

Closes #10710.
  • Loading branch information...
1 parent 798b39e commit fe13684b4d5d635a6fd930ab49358cdf9192c2de @paul-h paul-h committed Apr 7, 2013
@@ -1441,12 +1441,12 @@ void MusicCommon::customEvent(QEvent *event)
if (resulttext == tr("Replace Tracks"))
{
m_playlistOptions.insertPLOption = PL_REPLACE;
- doUpdatePlaylist();
+ doUpdatePlaylist(false);
}
else if (resulttext == tr("Add Tracks"))
{
m_playlistOptions.insertPLOption = PL_INSERTATEND;
- doUpdatePlaylist();
+ doUpdatePlaylist(false);
}
}
else if (resultid == "visualizermenu")
@@ -1615,6 +1615,9 @@ void MusicCommon::customEvent(QEvent *event)
item->SetFontState("normal");
item->DisplayState("default", "playstate");
}
+
+ if (!gPlayer->getCurrentMetadata())
+ gPlayer->changeCurrentTrack(0);
}
if (m_noTracksText)
@@ -2378,7 +2381,7 @@ void MusicCommon::showPlaylistOptionsMenu(bool addMainMenu)
if (gPlayer->getPlaylist()->getSongs().count() == 0)
{
m_playlistOptions.insertPLOption = PL_REPLACE;
- doUpdatePlaylist();
+ doUpdatePlaylist(true);
return;
}
@@ -2397,7 +2400,7 @@ void MusicCommon::showPlaylistOptionsMenu(bool addMainMenu)
delete menu;
}
-void MusicCommon::doUpdatePlaylist(void)
+void MusicCommon::doUpdatePlaylist(bool startPlayback)
{
int curTrackID, trackCount;
int curPos = gPlayer->getCurrentTrackPos();
@@ -2430,46 +2433,90 @@ void MusicCommon::doUpdatePlaylist(void)
updateUIPlaylist();
- switch (m_playlistOptions.playPLOption)
+ if (startPlayback || gPlayer->isPlaying())
{
- case PL_CURRENT:
+ switch (m_playlistOptions.playPLOption)
{
- if (!restorePosition(curTrackID))
- playFirstTrack();
+ case PL_CURRENT:
+ {
+ if (!restorePosition(curTrackID))
+ playFirstTrack();
- break;
- }
+ break;
+ }
- case PL_FIRST:
- playFirstTrack();
- break;
+ case PL_FIRST:
+ playFirstTrack();
+ break;
- case PL_FIRSTNEW:
- {
- switch (m_playlistOptions.insertPLOption)
+ case PL_FIRSTNEW:
{
- case PL_REPLACE:
- playFirstTrack();
- break;
-
- case PL_INSERTATEND:
+ switch (m_playlistOptions.insertPLOption)
{
- pause();
- if (!gPlayer->setCurrentTrackPos(trackCount + 1))
+ case PL_REPLACE:
playFirstTrack();
- break;
- }
+ break;
+
+ case PL_INSERTATEND:
+ {
+ pause();
+ if (!gPlayer->setCurrentTrackPos(trackCount))
+ playFirstTrack();
+ break;
+ }
+
+ case PL_INSERTAFTERCURRENT:
+ if (!gPlayer->setCurrentTrackPos(curPos + 1))
+ playFirstTrack();
+ break;
- case PL_INSERTAFTERCURRENT:
- if (!gPlayer->setCurrentTrackPos(curPos + 1))
+ default:
playFirstTrack();
- break;
+ }
- default:
- playFirstTrack();
+ break;
}
+ }
+ }
+ else
+ {
+ int trackPos = 0;
- break;
+ switch (m_playlistOptions.playPLOption)
+ {
+ case PL_CURRENT:
+ trackPos = curPos;
+ break;
+
+ case PL_FIRST:
+ trackPos = 0;
+ break;
+
+ case PL_FIRSTNEW:
+ {
+ switch (m_playlistOptions.insertPLOption)
+ {
+ case PL_REPLACE:
+ trackPos = 0;
+ break;
+
+ case PL_INSERTATEND:
+ trackPos = 0;
+ break;
+
+ case PL_INSERTAFTERCURRENT:
+ trackPos = curPos + 1;
+ break;
+
+ default:
+ trackPos = 0;
+ }
+
+ break;
+ }
+
+ gPlayer->changeCurrentTrack(trackPos);
+ m_currentTrack = trackPos;
}
}
@@ -96,7 +96,7 @@ class MPUBLIC MusicCommon : public MythScreenType
void byGenre(void);
void byYear(void);
void byTitle(void);
- void doUpdatePlaylist(void);
+ void doUpdatePlaylist(bool startPlayback);
protected:
void showExitMenu(void);
@@ -572,8 +572,6 @@ void Playlist::loadPlaylist(QString a_name, QString a_host)
m_name = query.value(1).toString();
rawSonglist = query.value(2).toString();
}
- if (m_name == "default_playlist_storage")
- m_name = QObject::tr("Default Playlist");
}
else
{
@@ -282,13 +282,15 @@ void PlaylistEditorView::customEvent(QEvent *event)
}
else if (resulttext == tr("Replace Tracks"))
{
+ m_playlistOptions.playPLOption = PL_CURRENT;
m_playlistOptions.insertPLOption = PL_REPLACE;
- doUpdatePlaylist();
+ doUpdatePlaylist(false);
}
else if (resulttext == tr("Add Tracks"))
{
+ m_playlistOptions.playPLOption = PL_CURRENT;
m_playlistOptions.insertPLOption = PL_INSERTATEND;
- doUpdatePlaylist();
+ doUpdatePlaylist(false);
}
}
else if (resultid == "playlistmenu")
@@ -316,12 +318,12 @@ void PlaylistEditorView::customEvent(QEvent *event)
{
m_playlistOptions.playPLOption = PL_CURRENT;
m_playlistOptions.insertPLOption = PL_REPLACE;
- doUpdatePlaylist();
+ doUpdatePlaylist(false);
}
else if (resulttext == tr("Add Tracks"))
{
m_playlistOptions.insertPLOption = PL_INSERTATEND;
- doUpdatePlaylist();
+ doUpdatePlaylist(false);
}
}
}
@@ -451,6 +453,89 @@ bool PlaylistEditorView::keyPressEvent(QKeyEvent *event)
if (item)
treeItemClicked(item);
}
+ else if ((action == "PLAY") && (GetFocusWidget() == m_playlistTree))
+ {
+ MythUIButtonListItem *item = m_playlistTree->GetItemCurrent();
+ if (item)
+ {
+ MythGenericTree *node = qVariantValue<MythGenericTree*> (item->GetData());
+ MusicGenericTree *mnode = dynamic_cast<MusicGenericTree*>(node);
+
+ if (mnode)
+ {
+ if (mnode->getAction() == "trackid")
+ {
+ handled = false;
+ }
+ 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());
+ }
+ }
+ if (handled)
+ {
+ m_playlistOptions.playPLOption = PL_FIRST;
+ m_playlistOptions.insertPLOption = PL_REPLACE;
+ doUpdatePlaylist(true);
+ }
+ else
+ {
+ handled = false;
+ }
+ }
+ }
+ }
else
handled = false;
}
@@ -865,6 +950,7 @@ void PlaylistEditorView::filterTracks(MusicGenericTree *node)
if (node->getAction() == "all tracks")
{
QMap<QString, int> map;
+ QStringList list;
for (int x = 0; x < tracks->count(); x++)
{
@@ -238,7 +238,7 @@ bool SearchView::keyPressEvent(QKeyEvent *event)
else
handled = false;
}
- else if (action == "PLAY" || action == "PAUSE")
+ else if (action == "PLAY")
{
if (GetFocusWidget() == m_tracksList)
{

0 comments on commit fe13684

Please sign in to comment.