Commit a3d9d08e authored by Ralf Engels's avatar Ralf Engels
Browse files

Prevent crash in case of non-working sql collection

Add some validity checks for the case where a collection is
non-initialized.

BUG: 298425
FIXED-IN: 2.6
parent 1b6b592b
......@@ -37,6 +37,7 @@ VERSION 2.6-RC
244595)
* Provide full-size covers via MPRIS1 if available. (BR 278550)
* Fix serving out of embedded images via MPRIS. (BR 301399)
* Fix problems when sql server is not reachable (BR 298425)
VERSION 2.6-Beta 1
FEATURES:
......
......@@ -374,6 +374,9 @@ SqlRegistry::getArtist( const QString &name )
id = res[0].toInt();
}
if( !id )
return Meta::ArtistPtr();
Meta::ArtistPtr artist( new Meta::SqlArtist( m_collection, id, name ) );
m_artistMap.insert( name, artist );
m_artistIdMap.insert( id, artist );
......@@ -440,6 +443,9 @@ SqlRegistry::getGenre( const QString &name )
id = res[0].toInt();
}
if( !id )
return Meta::GenrePtr();
Meta::GenrePtr genre( new Meta::SqlGenre( m_collection, id, name ) );
m_genreMap.insert( name, genre );
return genre;
......@@ -500,6 +506,9 @@ SqlRegistry::getComposer( const QString &name )
id = res[0].toInt();
}
if( !id )
return Meta::ComposerPtr();
Meta::ComposerPtr composer( new Meta::SqlComposer( m_collection, id, name ) );
m_composerMap.insert( name, composer );
return composer;
......@@ -564,6 +573,10 @@ SqlRegistry::getYear( int year, int yearId )
yearId = res[0].toInt();
}
}
if( !yearId )
return Meta::YearPtr();
Meta::YearPtr yearPtr( new Meta::SqlYear( m_collection, yearId, year ) );
m_yearMap.insert( year, yearPtr );
return yearPtr;
......@@ -595,6 +608,8 @@ SqlRegistry::getAlbum( const QString &name, const QString &artist )
else
{
Meta::ArtistPtr artistPtr = getArtist( albumArtist );
if( !artistPtr )
return Meta::AlbumPtr();
Meta::SqlArtist *sqlArtist = static_cast<Meta::SqlArtist*>(artistPtr.data());
artistId = sqlArtist->id();
......@@ -616,6 +631,9 @@ SqlRegistry::getAlbum( const QString &name, const QString &artist )
albumId = res[0].toInt();
}
if( !albumId )
return Meta::AlbumPtr();
Meta::SqlAlbum *sqlAlbum = new Meta::SqlAlbum( m_collection, albumId, name, artistId );
Meta::AlbumPtr album( sqlAlbum );
m_albumMap.insert( key, album );
......@@ -687,6 +705,9 @@ SqlRegistry::getLabel( const QString &label )
id = res[0].toInt();
}
if( !id )
return Meta::LabelPtr();
Meta::LabelPtr labelPtr( new Meta::SqlLabel( m_collection, id, label ) );
m_labelMap.insert( label, labelPtr );
return labelPtr;
......
......@@ -93,6 +93,8 @@ SqlScanResultProcessor::commitAlbum( CollectionScanner::Album *album )
// --- get or create the album
Meta::SqlAlbumPtr metaAlbum;
metaAlbum = Meta::SqlAlbumPtr::staticCast( m_collection->getAlbum( album->name(), album->artist() ) );
if( !metaAlbum )
return;
m_albumIds.insert( album, metaAlbum->id() );
// --- add all tracks
......@@ -101,25 +103,22 @@ SqlScanResultProcessor::commitAlbum( CollectionScanner::Album *album )
// --- set the cover if we have one
// we need to do this after the tracks are added in case of an embedded cover
if( metaAlbum )
bool suppressAutoFetch = metaAlbum->suppressImageAutoFetch();
metaAlbum->setSuppressImageAutoFetch( true );
if( m_type == FullScan )
{
bool suppressAutoFetch = metaAlbum->suppressImageAutoFetch();
metaAlbum->setSuppressImageAutoFetch( true );
if( m_type == FullScan )
{
if( !album->cover().isEmpty() )
{
metaAlbum->removeImage();
metaAlbum->setImage( album->cover() );
}
}
else
if( !album->cover().isEmpty() )
{
if( !metaAlbum->hasImage() && !album->cover().isEmpty() )
metaAlbum->setImage( album->cover() );
metaAlbum->removeImage();
metaAlbum->setImage( album->cover() );
}
metaAlbum->setSuppressImageAutoFetch( suppressAutoFetch );
}
else
{
if( !metaAlbum->hasImage() && !album->cover().isEmpty() )
metaAlbum->setImage( album->cover() );
}
metaAlbum->setSuppressImageAutoFetch( suppressAutoFetch );
}
void
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment