When repopulating a dymanic playlist, don't remove items that are queued

This commit is contained in:
David Sansome 2010-11-21 17:48:58 +00:00
parent c9e00f2f22
commit 560d1c5006
4 changed files with 45 additions and 2 deletions

View File

@ -1183,11 +1183,43 @@ void Playlist::RepopulateDynamicPlaylist() {
if (!dynamic_playlist_)
return;
// Can't use Clear() because it turns off dynamic playlist
RemoveItemsWithoutUndo(0, items_.count());
RemoveItemsNotInQueue();
InsertSmartPlaylist(dynamic_playlist_);
}
void Playlist::RemoveItemsNotInQueue() {
if (queue_->is_empty()) {
RemoveItemsWithoutUndo(0, items_.count());
return;
}
int start = 0;
forever {
// Find a place to start - first row that isn't in the queue
forever {
if (start >= rowCount())
return;
if (!queue_->ContainsSourceRow(start))
break;
start ++;
}
// Figure out how many rows to remove - keep going until we find a row
// that is in the queue
int count = 1;
forever {
if (start + count >= rowCount())
break;
if (queue_->ContainsSourceRow(start + count))
break;
count ++;
}
RemoveItemsWithoutUndo(start, count);
start ++;
}
}
void Playlist::ReloadItems(const QList<int>& rows) {
foreach (int row, rows) {
item_at(row)->Reload();

View File

@ -217,6 +217,8 @@ class Playlist : public QAbstractListModel {
void MoveItemsWithoutUndo(const QList<int>& source_rows, int pos);
void MoveItemsWithoutUndo(int start, const QList<int>& dest_rows);
void RemoveItemsNotInQueue();
private slots:
void TracksAboutToBeDequeued(const QModelIndex&, int begin, int end);
void TracksDequeued();

View File

@ -40,6 +40,14 @@ QModelIndex Queue::mapFromSource(const QModelIndex& source_index) const {
return QModelIndex();
}
bool Queue::ContainsSourceRow(int source_row) const {
for (int i=0 ; i<source_indexes_.count() ; ++i) {
if (source_indexes_[i].row() == source_row)
return true;
}
return false;
}
QModelIndex Queue::mapToSource(const QModelIndex& proxy_index) const {
if (!proxy_index.isValid())
return QModelIndex();

View File

@ -33,6 +33,7 @@ public:
// Query the queue
bool is_empty() const;
int PositionOf(const QModelIndex& source_index) const;
bool ContainsSourceRow(int source_row) const;
int PeekNext() const;
// Modify the queue