1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-18 20:34:39 +01:00

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>library.png</file>
<file>media-playback-start-32.png</file> <file>media-playback-start-32.png</file>
<file>lightbulb.png</file> <file>lightbulb.png</file>
<file>shuffle.png</file>
</qresource> </qresource>
</RCC> </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_edit_track, SIGNAL(triggered()), SLOT(EditTracks()));
connect(ui_.action_configure, SIGNAL(triggered()), settings_dialog_, SLOT(show())); connect(ui_.action_configure, SIGNAL(triggered()), settings_dialog_, SLOT(show()));
connect(ui_.action_about, SIGNAL(triggered()), about_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 // Give actions to buttons
ui_.forward_button->setDefaultAction(ui_.action_next_track); 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_->addAction(ui_.action_edit_track);
playlist_menu_->addSeparator(); playlist_menu_->addSeparator();
playlist_menu_->addAction(ui_.action_clear_playlist); playlist_menu_->addAction(ui_.action_clear_playlist);
playlist_menu_->addAction(ui_.action_shuffle);
// Radio connections // Radio connections
connect(radio_model_, SIGNAL(TaskStarted(QString)), multi_loading_indicator_, SLOT(TaskStarted(QString))); connect(radio_model_, SIGNAL(TaskStarted(QString)), multi_loading_indicator_, SLOT(TaskStarted(QString)));

View File

@ -456,6 +456,7 @@
<string>Playlist</string> <string>Playlist</string>
</property> </property>
<addaction name="action_clear_playlist"/> <addaction name="action_clear_playlist"/>
<addaction name="action_shuffle"/>
</widget> </widget>
<widget class="QMenu" name="menuSettings"> <widget class="QMenu" name="menuSettings">
<property name="title"> <property name="title">
@ -647,6 +648,15 @@
<string>About Clementine...</string> <string>About Clementine...</string>
</property> </property>
</action> </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> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<customwidgets> <customwidgets>

View File

@ -207,5 +207,9 @@ void Player::EngineMetadataReceived(const Engine::SimpleMetaBundle& bundle) {
Song song; Song song;
song.InitFromSimpleMetaBundle(bundle); song.InitFromSimpleMetaBundle(bundle);
// Ignore useless metadata
if (song.title().isEmpty() && song.artist().isEmpty())
return;
playlist_->SetStreamMetadata(item->Url(), song); 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)); 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 SetStreamMetadata(const QUrl& url, const Song& song);
void Clear(); void Clear();
void Shuffle();
signals: signals:
void CurrentSongChanged(const Song& metadata); void CurrentSongChanged(const Song& metadata);