mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-18 04:19:55 +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:
parent
0579b18850
commit
48bd5020cd
@ -906,8 +906,8 @@ PlaylistItemList LibraryBackend::GetPlaylistItems(int playlist) {
|
||||
if (!item)
|
||||
continue;
|
||||
|
||||
item->InitFromQuery(q);
|
||||
ret << item;
|
||||
if (item->InitFromQuery(q))
|
||||
ret << item;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -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 {
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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() {}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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_));
|
||||
|
@ -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 {
|
||||
|
@ -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_; }
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user