Shuffle playlist

This commit is contained in:
David Sansome 2010-02-03 23:56:41 +00:00
parent b10bf1e40d
commit 8eb42b5ab8
7 changed files with 38 additions and 0 deletions

View File

@ -56,5 +56,6 @@
<file>library.png</file>
<file>media-playback-start-32.png</file>
<file>lightbulb.png</file>
<file>shuffle.png</file>
</qresource>
</RCC>

BIN
data/shuffle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 688 B

View File

@ -103,6 +103,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui_.action_edit_track, SIGNAL(triggered()), SLOT(EditTracks()));
connect(ui_.action_configure, SIGNAL(triggered()), settings_dialog_, SLOT(show()));
connect(ui_.action_about, SIGNAL(triggered()), about_dialog_, SLOT(show()));
connect(ui_.action_shuffle, SIGNAL(triggered()), playlist_, SLOT(Shuffle()));
// Give actions to buttons
ui_.forward_button->setDefaultAction(ui_.action_next_track);
@ -196,6 +197,7 @@ MainWindow::MainWindow(QWidget *parent)
playlist_menu_->addAction(ui_.action_edit_track);
playlist_menu_->addSeparator();
playlist_menu_->addAction(ui_.action_clear_playlist);
playlist_menu_->addAction(ui_.action_shuffle);
// Radio connections
connect(radio_model_, SIGNAL(TaskStarted(QString)), multi_loading_indicator_, SLOT(TaskStarted(QString)));

View File

@ -456,6 +456,7 @@
<string>Playlist</string>
</property>
<addaction name="action_clear_playlist"/>
<addaction name="action_shuffle"/>
</widget>
<widget class="QMenu" name="menuSettings">
<property name="title">
@ -647,6 +648,15 @@
<string>About Clementine...</string>
</property>
</action>
<action name="action_shuffle">
<property name="icon">
<iconset resource="../data/data.qrc">
<normaloff>:/shuffle.png</normaloff>:/shuffle.png</iconset>
</property>
<property name="text">
<string>Shuffle playlist</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>

View File

@ -207,5 +207,9 @@ void Player::EngineMetadataReceived(const Engine::SimpleMetaBundle& bundle) {
Song song;
song.InitFromSimpleMetaBundle(bundle);
// Ignore useless metadata
if (song.title().isEmpty() && song.artist().isEmpty())
return;
playlist_->SetStreamMetadata(item->Url(), song);
}

View File

@ -523,3 +523,23 @@ void Playlist::ReloadItems(const QList<int>& rows) {
emit dataChanged(index(row, 0), index(row, ColumnCount-1));
}
}
void Playlist::Shuffle() {
layoutAboutToBeChanged();
const int count = items_.count();
for (int i=0 ; i < count; ++i) {
int new_pos = i + (rand() % (count - i));
std::swap(items_[i], items_[new_pos]);
foreach (const QModelIndex& pidx, persistentIndexList()) {
if (pidx.row() == i)
changePersistentIndex(pidx, index(new_pos, pidx.column(), QModelIndex()));
else if (pidx.row() == new_pos)
changePersistentIndex(pidx, index(i, pidx.column(), QModelIndex()));
}
}
layoutChanged();
}

View File

@ -101,6 +101,7 @@ class Playlist : public QAbstractListModel {
void SetStreamMetadata(const QUrl& url, const Song& song);
void Clear();
void Shuffle();
signals:
void CurrentSongChanged(const Song& metadata);