Make sure song changed is only called once
This commit is contained in:
@@ -134,7 +134,6 @@ Playlist::Playlist(PlaylistBackend *backend, TaskManager *task_manager, Collecti
|
||||
special_type_(special_type),
|
||||
cancel_restore_(false),
|
||||
scrobbled_(false),
|
||||
nowplaying_(false),
|
||||
scrobble_point_(-1),
|
||||
editing_(-1) {
|
||||
|
||||
@@ -599,11 +598,12 @@ void Playlist::set_current_row(const int i, const AutoScroll autoscroll, const b
|
||||
|
||||
if (new_current_item_index != current_item_index_) ClearStreamMetadata();
|
||||
|
||||
if (next_row() != -1 && next_row() != i) {
|
||||
PlaylistItemPtr next_item = item_at(next_row());
|
||||
int nextrow = next_row();
|
||||
if (nextrow != -1 && nextrow != i) {
|
||||
PlaylistItemPtr next_item = item_at(nextrow);
|
||||
if (next_item) {
|
||||
next_item->ClearTemporaryMetadata();
|
||||
emit dataChanged(index(next_row(), 0), index(next_row(), ColumnCount - 1));
|
||||
emit dataChanged(index(nextrow, 0), index(nextrow, ColumnCount - 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -644,7 +644,7 @@ void Playlist::set_current_row(const int i, const AutoScroll autoscroll, const b
|
||||
}
|
||||
|
||||
if (current_item_index_.isValid() && !is_stopping) {
|
||||
InformOfCurrentSongChange(autoscroll);
|
||||
InformOfCurrentSongChange(autoscroll, false);
|
||||
}
|
||||
|
||||
// The structure of a dynamic playlist is as follows:
|
||||
@@ -1596,29 +1596,10 @@ void Playlist::SetStreamMetadata(const QUrl &url, const Song &song, const bool m
|
||||
|
||||
if (!current_item() || current_item()->Url() != url) return;
|
||||
|
||||
//qLog(Debug) << "Setting temporary metadata for" << url;
|
||||
|
||||
bool update_scrobble_point = song.length_nanosec() != current_item_metadata().length_nanosec();
|
||||
|
||||
current_item()->SetTemporaryMetadata(song);
|
||||
|
||||
if (minor) {
|
||||
if (editing_ != current_item_index_.row()) {
|
||||
emit dataChanged(index(current_item_index_.row(), 0), index(current_item_index_.row(), ColumnCount - 1));
|
||||
}
|
||||
// if the song is invalid, we won't play it - there's no point in informing anybody about the change
|
||||
const Song metadata(current_item_metadata());
|
||||
if (metadata.is_valid()) {
|
||||
emit SongMetadataChanged(metadata);
|
||||
}
|
||||
}
|
||||
else {
|
||||
update_scrobble_point = true;
|
||||
nowplaying_ = false;
|
||||
InformOfCurrentSongChange(AutoScroll_Never);
|
||||
}
|
||||
|
||||
if (update_scrobble_point) UpdateScrobblePoint();
|
||||
InformOfCurrentSongChange(AutoScroll_Never, minor);
|
||||
|
||||
}
|
||||
|
||||
@@ -1737,10 +1718,16 @@ void Playlist::ReloadItems(const QList<int> &rows) {
|
||||
for (int row : rows) {
|
||||
PlaylistItemPtr item = item_at(row);
|
||||
|
||||
Song old_metadata = item->Metadata();
|
||||
|
||||
item->Reload();
|
||||
|
||||
if (row == current_row()) {
|
||||
InformOfCurrentSongChange(AutoScroll_Never);
|
||||
const bool minor = old_metadata.title() == item->Metadata().title() &&
|
||||
old_metadata.albumartist() == item->Metadata().albumartist() &&
|
||||
old_metadata.artist() == item->Metadata().artist() &&
|
||||
old_metadata.album() == item->Metadata().album();
|
||||
InformOfCurrentSongChange(AutoScroll_Never, minor);
|
||||
}
|
||||
else {
|
||||
emit dataChanged(index(row, 0), index(row, ColumnCount - 1));
|
||||
@@ -1946,28 +1933,41 @@ void Playlist::QueueLayoutChanged() {
|
||||
|
||||
}
|
||||
|
||||
void Playlist::ItemChanged(const int row) {
|
||||
|
||||
QModelIndex idx = index(row, ColumnCount - 1);
|
||||
if (idx.isValid()) {
|
||||
emit dataChanged(index(row, 0), index(row, ColumnCount - 1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Playlist::ItemChanged(PlaylistItemPtr item) {
|
||||
|
||||
for (int row = 0; row < items_.count(); ++row) {
|
||||
if (items_[row] == item) {
|
||||
QModelIndex idx = index(row, ColumnCount - 1);
|
||||
if (idx.isValid()) {
|
||||
emit dataChanged(index(row, 0), index(row, ColumnCount - 1));
|
||||
}
|
||||
ItemChanged(row);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Playlist::InformOfCurrentSongChange(const AutoScroll autoscroll) {
|
||||
|
||||
emit dataChanged(index(current_item_index_.row(), 0), index(current_item_index_.row(), ColumnCount - 1));
|
||||
void Playlist::InformOfCurrentSongChange(const AutoScroll autoscroll, const bool minor) {
|
||||
|
||||
// if the song is invalid, we won't play it - there's no point in informing anybody about the change
|
||||
const Song metadata(current_item_metadata());
|
||||
if (metadata.is_valid()) {
|
||||
emit CurrentSongChanged(metadata);
|
||||
emit MaybeAutoscroll(autoscroll);
|
||||
if (minor) {
|
||||
emit SongMetadataChanged(metadata);
|
||||
if (editing_ != current_item_index_.row()) {
|
||||
emit dataChanged(index(current_item_index_.row(), 0), index(current_item_index_.row(), ColumnCount - 1));
|
||||
}
|
||||
}
|
||||
else {
|
||||
emit CurrentSongChanged(metadata);
|
||||
emit MaybeAutoscroll(autoscroll);
|
||||
emit dataChanged(index(current_item_index_.row(), 0), index(current_item_index_.row(), ColumnCount - 1));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -232,9 +232,7 @@ class Playlist : public QAbstractListModel {
|
||||
QUndoStack *undo_stack() const { return undo_stack_; }
|
||||
|
||||
bool scrobbled() const { return scrobbled_; }
|
||||
bool nowplaying() const { return nowplaying_; }
|
||||
void set_scrobbled(const bool state) { scrobbled_ = state; }
|
||||
void set_nowplaying(const bool state) { nowplaying_ = state; }
|
||||
void set_editing(const int row) { editing_ = row; }
|
||||
qint64 scrobble_point_nanosec() const { return scrobble_point_; }
|
||||
void UpdateScrobblePoint(const qint64 seek_point_nanosec = 0);
|
||||
@@ -262,7 +260,7 @@ class Playlist : public QAbstractListModel {
|
||||
|
||||
void StopAfter(const int row);
|
||||
void ReloadItems(const QList<int> &rows);
|
||||
void InformOfCurrentSongChange(const AutoScroll autoscroll);
|
||||
void InformOfCurrentSongChange(const AutoScroll autoscroll, const bool minor);
|
||||
|
||||
// Registers an object which will get notifications when new songs are about to be inserted into this playlist.
|
||||
void AddSongInsertVetoListener(SongInsertVetoListener *listener);
|
||||
@@ -290,6 +288,9 @@ class Playlist : public QAbstractListModel {
|
||||
|
||||
static bool ComparePathDepths(Qt::SortOrder, PlaylistItemPtr, PlaylistItemPtr);
|
||||
|
||||
void ItemChanged(PlaylistItemPtr item);
|
||||
void ItemChanged(const int row);
|
||||
|
||||
// Changes rating of a song to the given value asynchronously
|
||||
void RateSong(const QModelIndex &idx, const double rating);
|
||||
void RateSongs(const QModelIndexList &index_list, const double rating);
|
||||
@@ -303,7 +304,6 @@ class Playlist : public QAbstractListModel {
|
||||
|
||||
void ClearStreamMetadata();
|
||||
void SetStreamMetadata(const QUrl &url, const Song &song, const bool minor);
|
||||
void ItemChanged(PlaylistItemPtr item);
|
||||
void UpdateItems(SongList songs);
|
||||
|
||||
void Clear();
|
||||
@@ -424,7 +424,6 @@ class Playlist : public QAbstractListModel {
|
||||
bool cancel_restore_;
|
||||
|
||||
bool scrobbled_;
|
||||
bool nowplaying_;
|
||||
qint64 scrobble_point_;
|
||||
|
||||
int editing_;
|
||||
|
||||
Reference in New Issue
Block a user