minor deleted items handling fixes

This commit is contained in:
Paweł Bara 2011-03-18 21:54:22 +00:00
parent 7705487f96
commit a4bf317f33
4 changed files with 25 additions and 9 deletions

View File

@ -17,7 +17,6 @@
#include "libraryplaylistitem.h"
#include <QtDebug>
#include <QSettings>
LibraryPlaylistItem::LibraryPlaylistItem(const QString& type)

View File

@ -1123,14 +1123,27 @@ void Playlist::ItemsLoaded() {
watcher->deleteLater();
PlaylistItemList items = watcher->future().results();
// backend returns empty elements for 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()) {
it.remove();
}
}
is_loading_ = true;
InsertItems(items, 0);
is_loading_ = false;
PlaylistBackend::Playlist p = backend_->GetPlaylist(id_);
last_played_item_index_ =
p.last_played == -1 ? QModelIndex() : index(p.last_played);
// the newly loaded list of items might be shorter than it was before so
// look out for a bad last_played index
last_played_item_index_ = p.last_played == -1 || p.last_played >= rowCount()
? QModelIndex()
: index(p.last_played);
if (!p.dynamic_type.isEmpty()) {
GeneratorPtr gen = Generator::Create(p.dynamic_type);
@ -1361,9 +1374,11 @@ void Playlist::RemoveItemsNotInQueue() {
void Playlist::ReloadItems(const QList<int>& rows) {
foreach (int row, rows) {
item_at(row)->Reload();
PlaylistItemPtr item = item_at(row);
item->Reload();
InformOfCurrentSongChange(index(row, 0), index(row, ColumnCount-1),
item_at(row)->Metadata());
item->Metadata());
}
}

View File

@ -53,13 +53,14 @@ class PlaylistBackend : public QObject {
PlaylistList GetAllPlaylists();
Playlist GetPlaylist(int id);
PlaylistItemFuture GetPlaylistItems(int playlist);
void SavePlaylistAsync(int playlist, const PlaylistItemList& items,
int last_played, smart_playlists::GeneratorPtr dynamic);
void SetPlaylistOrder(const QList<int>& ids);
int CreatePlaylist(const QString& name);
void RemovePlaylist(int id);
void SavePlaylistAsync(int playlist, const PlaylistItemList& items,
int last_played, smart_playlists::GeneratorPtr dynamic);
void RenamePlaylist(int id, const QString& new_name);
void RemovePlaylist(int id);
void SetLibrary(LibraryBackend* library);

View File

@ -342,7 +342,8 @@ void PlaylistManager::SongChangeRequestProcessed(const QUrl& url, bool valid) {
Song current_song = current->Metadata();
// if validity has changed, reload the item
if(current_song.url() == url && current_song.filetype() != Song::Type_Stream &&
if(current_song.filetype() != Song::Type_Stream &&
current_song.filename() == url.toLocalFile() &&
current_song.is_valid() != QFile::exists(current_song.filename())) {
playlist->ReloadItems(QList<int>() << playlist->current_row());
}