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

Don't crash when editing a song that doesn't exist any more, also don't even add deleted songs to the playlist. Fixes issue #253.

This commit is contained in:
David Sansome 2010-04-27 17:37:26 +00:00
parent 0579b18850
commit 48bd5020cd
10 changed files with 20 additions and 10 deletions

View File

@ -906,7 +906,7 @@ PlaylistItemList LibraryBackend::GetPlaylistItems(int playlist) {
if (!item)
continue;
item->InitFromQuery(q);
if (item->InitFromQuery(q))
ret << item;
}

View File

@ -39,9 +39,11 @@ void LibraryPlaylistItem::Reload() {
song_.InitFromFile(song_.filename(), song_.directory_id());
}
void LibraryPlaylistItem::InitFromQuery(const QSqlQuery &query) {
bool LibraryPlaylistItem::InitFromQuery(const QSqlQuery &query) {
// Rows from the songs table come first
song_.InitFromQuery(query);
return song_.is_valid();
}
QVariant LibraryPlaylistItem::DatabaseValue(DatabaseColumn column) const {

View File

@ -25,7 +25,7 @@ class LibraryPlaylistItem : public PlaylistItem {
LibraryPlaylistItem(const QString& type);
LibraryPlaylistItem(const Song& song);
void InitFromQuery(const QSqlQuery &query);
bool InitFromQuery(const QSqlQuery &query);
void BindToQuery(QSqlQuery *query) const;
void Reload();

View File

@ -47,7 +47,7 @@ class PlaylistItem {
virtual Options options() const { return Default; }
virtual void InitFromQuery(const QSqlQuery& query) = 0;
virtual bool InitFromQuery(const QSqlQuery& query) = 0;
void BindToQuery(QSqlQuery* query) const;
virtual void Reload() {}

View File

@ -40,7 +40,7 @@ RadioPlaylistItem::RadioPlaylistItem(RadioService* service, const QUrl& url,
InitMetadata();
}
void RadioPlaylistItem::InitFromQuery(const QSqlQuery &query) {
bool RadioPlaylistItem::InitFromQuery(const QSqlQuery &query) {
// The song table gets joined first, plus one for the song ROWID
const int row = Song::kColumns.count() + 1;
@ -52,6 +52,7 @@ void RadioPlaylistItem::InitFromQuery(const QSqlQuery &query) {
service_ = RadioModel::ServiceByName(service);
InitMetadata();
return true;
}
QVariant RadioPlaylistItem::DatabaseValue(DatabaseColumn column) const {

View File

@ -32,7 +32,7 @@ class RadioPlaylistItem : public PlaylistItem {
Options options() const;
void InitFromQuery(const QSqlQuery &query);
bool InitFromQuery(const QSqlQuery &query);
void BindToQuery(QSqlQuery *query) const;
Song Metadata() const;

View File

@ -490,6 +490,9 @@ bool Song::Save() const {
scoped_ptr<TagLib::FileRef> fileref(factory_->GetFileRef(d->filename_));
if (!fileref || fileref->isNull()) // The file probably doesn't exist
return false;
fileref->tag()->setTitle(QStringToTaglibString(d->title_));
fileref->tag()->setArtist(QStringToTaglibString(d->artist_));
fileref->tag()->setAlbum(QStringToTaglibString(d->album_));

View File

@ -31,7 +31,7 @@ SongPlaylistItem::SongPlaylistItem(const Song& song)
{
}
void SongPlaylistItem::InitFromQuery(const QSqlQuery &query) {
bool SongPlaylistItem::InitFromQuery(const QSqlQuery &query) {
// The song table gets joined first, plus one for the song ROWID
const int row = Song::kColumns.count() + 1;
@ -53,7 +53,11 @@ void SongPlaylistItem::InitFromQuery(const QSqlQuery &query) {
song_.Init(title, artist, album, length);
} else {
song_.InitFromFile(filename, -1);
if (!song_.is_valid())
return false;
}
return true;
}
QVariant SongPlaylistItem::DatabaseValue(DatabaseColumn column) const {

View File

@ -25,7 +25,7 @@ class SongPlaylistItem : public PlaylistItem {
SongPlaylistItem(const QString& type);
SongPlaylistItem(const Song& song);
void InitFromQuery(const QSqlQuery &query);
bool InitFromQuery(const QSqlQuery &query);
void Reload();
Song Metadata() const { return song_; }

View File

@ -30,7 +30,7 @@ class MockPlaylistItem : public PlaylistItem {
MOCK_CONST_METHOD0(options,
Options());
MOCK_METHOD1(InitFromQuery,
void(const QSqlQuery& settings));
bool(const QSqlQuery& settings));
MOCK_METHOD0(Reload,
void());
MOCK_CONST_METHOD0(Metadata,