Commit 0e7b80af authored by Michael Pyne's avatar Michael Pyne

Implement bug 60108 (Randomly play albums) as suggested by wheels.

This allows you to randomly play every song from one album, followed by every song from the next album, and so on.

I'm not horribly fond of the UI for selecting it at this point (you must enable Random Play, and then enable Album Random Play from the Player menu), so watch out for that to improve.

CCMAIL:wheeler@kde.org
CCMAIL:60108-done@bugs.kde.org

svn path=/trunk/kdemultimedia/juk/; revision=327328
parent 93314762
......@@ -113,6 +113,8 @@ void JuK::setupActions()
new KToolBarPopupAction(i18n("Previous &Track"), "player_start", KShortcut(), m_player, SLOT(back()), actions(), "back");
new KAction(i18n("&Next Track"), "player_end", KShortcut(), m_player, SLOT(forward()), actions(), "forward");
new KToggleAction(i18n("&Loop Playlist"), 0, KShortcut(), actions(), "loopPlaylist");
KToggleAction *ka = new KToggleAction(i18n("Album Random Play"), 0, actions(), "albumRandomPlay");
connect (m_randomPlayAction, SIGNAL(toggled(bool)), ka, SLOT(setEnabled(bool)));
// the following are not visible by default
......@@ -249,6 +251,10 @@ void JuK::readConfig()
bool randomPlay = playerConfig.readBoolEntry("RandomPlay", false);
m_randomPlayAction->setChecked(randomPlay);
ActionCollection::action<KToggleAction>("albumRandomPlay")->setEnabled(randomPlay);
bool albumRandomPlay = playerConfig.readBoolEntry("AlbumRandomPlay", false);
ActionCollection::action<KToggleAction>("albumRandomPlay")->setChecked(albumRandomPlay);
bool loopPlaylist = playerConfig.readBoolEntry("LoopPlaylist", false);
ActionCollection::action<KToggleAction>("loopPlaylist")->setChecked(loopPlaylist);
......@@ -283,6 +289,9 @@ void JuK::saveConfig()
KToggleAction *a = ActionCollection::action<KToggleAction>("loopPlaylist");
playerConfig.writeEntry("LoopPlaylist", a->isChecked());
a = ActionCollection::action<KToggleAction>("albumRandomPlay");
playerConfig.writeEntry("AlbumRandomPlay", a->isChecked() && a->isEnabled());
// general settings
KConfigGroup settingsConfig(KGlobal::config(), "Settings");
......
......@@ -35,6 +35,7 @@
</Menu>
<Menu name="player"><text>&amp;Player</text>
<Action name="randomPlay"/>
<Action name="albumRandomPlay"/>
<Action name="loopPlaylist"/>
<Separator/>
......@@ -42,8 +43,8 @@
<Action name="play"/>
<Action name="pause"/>
<Action name="stop"/>
<Action name="back"/>
<Action name="forward"/>
<Action name="back"/>
</Menu>
<Menu name="playlist"><text>&amp;Tagger</text>
<Action name="saveItem"/>
......
......@@ -397,6 +397,7 @@ void Playlist::playNext()
{
bool random = action("randomPlay") && action<KToggleAction>("randomPlay")->isChecked();
bool loop = action("loopPlaylist") && action<KToggleAction>("loopPlaylist")->isChecked();
bool albumRandom = action("albumRandomPlay") && action<KToggleAction>("albumRandomPlay")->isChecked();
Playlist *list = m_playingItem ? m_playingItem->playlist() : this;
......@@ -412,9 +413,27 @@ void Playlist::playNext()
m_playNextItem = 0;
}
else if(random) {
if(list->m_randomList.isEmpty())
if(list->m_randomList.isEmpty()) {
m_randomAlbum = QString::null;
list->m_randomList = list->visibleItems();
next = list->m_randomList[KApplication::random() % list->m_randomList.count()];
}
if(albumRandom) {
PlaylistItemList albumMatches;
PlaylistItemList::ConstIterator it;
for(it = list->m_randomList.begin(); !m_randomAlbum.isNull() && it != list->m_randomList.end(); ++it)
if((*it) != m_playingItem && (*it)->file().tag()->album() == m_randomAlbum)
albumMatches.append(*it);
if(albumMatches.isEmpty())
next = list->m_randomList[KApplication::random() % list->m_randomList.count()];
else
next = albumMatches[KApplication::random() % albumMatches.count()];
}
else
next = list->m_randomList[KApplication::random() % list->m_randomList.count()];
list->m_randomList.remove(next);
}
else {
......@@ -426,12 +445,17 @@ void Playlist::playNext()
}
}
m_randomAlbum = QString::null;
if(next)
m_randomAlbum = next->file().tag()->album();
setPlaying(next);
}
void Playlist::stop()
{
m_history.clear();
m_randomAlbum = QString::null;
setPlaying(0);
}
......
......@@ -559,6 +559,7 @@ private:
bool m_widthsDirty;
PlaylistItemList m_randomList;
QString m_randomAlbum;
PlaylistItemList m_history;
PlaylistSearch m_search;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment