fixing a bug where streams were removed from playlist during Clementine's startup

This commit is contained in:
Paweł Bara 2011-03-20 16:07:24 +00:00
parent bfb068a6d1
commit e619d7a280
6 changed files with 22 additions and 11 deletions

View File

@ -154,7 +154,7 @@ void Player::TrackEnded() {
}
if (current_item_ && current_item_->IsLocalLibraryItem() &&
!playlists_->active()->has_scrobbled()) {
current_item_->Metadata().id() != -1 && !playlists_->active()->has_scrobbled()) {
// The track finished before its scrobble point (30 seconds), so increment
// the play count now.
playlists_->library_backend()->IncrementPlayCountAsync(

View File

@ -34,7 +34,7 @@ class LibraryPlaylistItem : public PlaylistItem {
QUrl Url() const;
bool IsLocalLibraryItem() const { return song_.id() != -1; }
bool IsLocalLibraryItem() const { return true; }
protected:
QVariant DatabaseValue(DatabaseColumn column) const;

View File

@ -235,7 +235,8 @@ QVariant Playlist::data(const QModelIndex& index, int role) const {
case Role_CanSetRating:
return index.column() == Column_Rating &&
items_[index.row()]->IsLocalLibraryItem();
items_[index.row()]->IsLocalLibraryItem() &&
items_[index.row()]->Metadata().id() != -1;
case Qt::EditRole:
case Qt::ToolTipRole:
@ -1130,11 +1131,13 @@ void Playlist::ItemsLoaded() {
PlaylistItemList items = watcher->future().results();
// backend returns empty elements for items which it couldn't
// backend returns empty elements for library items which it couldn't
// match (because they got deleted); we don't need those
QMutableListIterator<PlaylistItemPtr> it(items);
while (it.hasNext()) {
if (it.next()->Metadata().filename().isEmpty()) {
PlaylistItemPtr item = it.next();
if (item->IsLocalLibraryItem() && item->Metadata().filename().isEmpty()) {
it.remove();
}
}
@ -1402,7 +1405,7 @@ void Playlist::RateSong(const QModelIndex& index, double rating) {
if(has_item_at(row)) {
PlaylistItemPtr item = item_at(row);
if (item && item->IsLocalLibraryItem()) {
if (item && item->IsLocalLibraryItem() && item->Metadata().id() != -1) {
library_->UpdateSongRatingAsync(item->Metadata().id(), rating);
}
}

View File

@ -130,6 +130,9 @@ class PlaylistItem : public boost::enable_shared_from_this<PlaylistItem> {
// Convenience function to find out whether this item is from the local
// library, as opposed to a device, a file on disk, or a stream.
// Remember that even if this returns true, the library item might be
// invalid so you might want to check that it's id is not equal to -1
// before actually using it.
virtual bool IsLocalLibraryItem() const { return false; }
protected:

View File

@ -177,8 +177,11 @@ Returns true if L{SetTemporaryMetadata()} has been called.
bool IsLocalLibraryItem() const;
%Docstring
IsLocalLibraryItem() -> bool
Convenience function to check whether this item is from the local library (the
list of songs appearing in the Library tab).
Convenience function to check whether this item is from the local
library, as opposed to a device, a file on disk or a stream.
Remember that even if this returns true, the library item might be
invalid so you might want to check that it's id is not equal to -1
before actually using it.
%End
void SetBackgroundColor(short priority, const QColor& color);

View File

@ -847,7 +847,8 @@ void MainWindow::SongChanged(const Song& song) {
void MainWindow::TrackSkipped(PlaylistItemPtr item) {
// If it was a library item then we have to increment its skipped count in
// the database.
if (item && item->IsLocalLibraryItem() && !playlists_->active()->has_scrobbled()) {
if (item && item->IsLocalLibraryItem() &&
item->Metadata().id() != -1 && !playlists_->active()->has_scrobbled()) {
Song song = item->Metadata();
const qint64 position = player_->engine()->position_nanosec();
const qint64 length = player_->engine()->length_nanosec();
@ -989,7 +990,7 @@ void MainWindow::UpdateTrackPosition() {
playlists_->active()->set_scrobbled(true);
// Update the play count for the song if it's from the library
if (item->IsLocalLibraryItem()) {
if (item->IsLocalLibraryItem() && item->Metadata().id() != -1) {
library_->backend()->IncrementPlayCountAsync(item->Metadata().id());
}
}
@ -1191,7 +1192,8 @@ void MainWindow::PlaylistRightClick(const QPoint& global_pos, const QModelIndex&
ui_->action_edit_value->setText(tr("Edit tag \"%1\"...").arg(column_name));
// Is it a library item?
if (playlists_->current()->item_at(source_index.row())->IsLocalLibraryItem()) {
PlaylistItemPtr item = playlists_->current()->item_at(source_index.row());
if (item->IsLocalLibraryItem() && item->Metadata().id() != -1) {
playlist_organise_->setVisible(editable);
} else {
playlist_copy_to_library_->setVisible(editable);