From a19eb9c447e7d4ebd1544feb5340b98b36999fa7 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Sun, 16 Oct 2011 14:06:13 -0400 Subject: [PATCH] Be safer and don't create albums in the for charts browsing --- src/libtomahawk/playlist/albumitemdelegate.cpp | 6 +++++- src/libtomahawk/playlist/albummodel.cpp | 3 ++- src/libtomahawk/playlist/albumproxymodel.cpp | 6 ++++++ src/libtomahawk/widgets/whatshotwidget.cpp | 12 ++++++++++-- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/libtomahawk/playlist/albumitemdelegate.cpp b/src/libtomahawk/playlist/albumitemdelegate.cpp index 03e84c365..4758e3c1f 100644 --- a/src/libtomahawk/playlist/albumitemdelegate.cpp +++ b/src/libtomahawk/playlist/albumitemdelegate.cpp @@ -112,7 +112,11 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, QRect textRect = option.rect.adjusted( 0, option.rect.height() - 32, 0, -2 ); - bool oneLiner = ( textRect.height() / 2 < painter->fontMetrics().boundingRect( item->album()->name() ).height() || + bool oneLiner = false; + if ( item->album()->artist().isNull() ) + oneLiner = true; + else + oneLiner = ( textRect.height() / 2 < painter->fontMetrics().boundingRect( item->album()->name() ).height() || textRect.height() / 2 < painter->fontMetrics().boundingRect( item->album()->artist()->name() ).height() ); if ( oneLiner ) diff --git a/src/libtomahawk/playlist/albummodel.cpp b/src/libtomahawk/playlist/albummodel.cpp index a1307ca98..9d4e13ed2 100644 --- a/src/libtomahawk/playlist/albummodel.cpp +++ b/src/libtomahawk/playlist/albummodel.cpp @@ -330,7 +330,8 @@ AlbumModel::getCover( const QModelIndex& index ) return false; Tomahawk::InfoSystem::InfoCriteriaHash trackInfo; - trackInfo["artist"] = item->album()->artist()->name(); + if ( !item->album()->artist().isNull() ) + trackInfo["artist"] = item->album()->artist()->name(); trackInfo["album"] = item->album()->name(); trackInfo["pptr"] = QString::number( (qlonglong)item ); m_coverHash.insert( (qlonglong)item, index ); diff --git a/src/libtomahawk/playlist/albumproxymodel.cpp b/src/libtomahawk/playlist/albumproxymodel.cpp index 08eff9910..e687a693c 100644 --- a/src/libtomahawk/playlist/albumproxymodel.cpp +++ b/src/libtomahawk/playlist/albumproxymodel.cpp @@ -123,6 +123,12 @@ AlbumProxyModel::lessThan( const QModelIndex& left, const QModelIndex& right ) c if ( !p2 ) return false; + if ( p1->album().isNull() || p1->album()->artist().isNull() ) + return true; + + if ( p2->album().isNull() || p2->album()->artist().isNull() ) + return false; + if ( p1->album()->artist()->name() == p2->album()->artist()->name() ) { return QString::localeAwareCompare( p1->album()->name(), p2->album()->name() ) < 0; diff --git a/src/libtomahawk/widgets/whatshotwidget.cpp b/src/libtomahawk/widgets/whatshotwidget.cpp index 509d82c9c..7b04f2f5f 100644 --- a/src/libtomahawk/widgets/whatshotwidget.cpp +++ b/src/libtomahawk/widgets/whatshotwidget.cpp @@ -184,7 +184,12 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat TreeModel* artistsModel = new TreeModel( ui->artistsViewLeft ); artistsModel->setColumnStyle( TreeModel::TrackOnly ); foreach ( const QString& artist, artists ) - artistsModel->addArtists( Artist::get( artist ) ); + { + artist_ptr artistPtr = Artist::get( artist ); + if ( artistPtr.isNull() ) + artistPtr = Artist::get( 0, artist ); + artistsModel->addArtists( artistPtr ); + } const QString chartId = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >().value( "chart_id" ); m_artistModels[ chartId ] = artistsModel; @@ -200,7 +205,10 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat foreach ( const Tomahawk::InfoSystem::ArtistAlbumPair& album, albums ) { qDebug() << "Getting album" << album.album << "By" << album.artist; - album_ptr albumPtr = Album::get( Artist::get( album.artist, true ), album.album ); + artist_ptr artistPtr = Artist::get( album.artist ); + if ( artistPtr.isNull() ) + artistPtr = Artist::get( 0, album.artist ); + album_ptr albumPtr = Album::get( 0, album.album, artistPtr ); if( !albumPtr.isNull() ) al << albumPtr;