1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-25 02:09:48 +01:00

* Fixed crash bug caused by cover fetching and a race condition.

This commit is contained in:
Christian Muehlhaeuser 2011-08-31 12:59:44 +02:00
parent 098999ca8c
commit e75e204007
6 changed files with 88 additions and 56 deletions

View File

@ -320,6 +320,30 @@ AlbumModel::clear()
}
bool
AlbumModel::getCover( const QModelIndex& index )
{
AlbumItem* item = itemFromIndex( index );
if ( !item || !item->cover.isNull() )
return false;
Tomahawk::InfoSystem::InfoCriteriaHash trackInfo;
trackInfo["artist"] = item->album()->artist()->name();
trackInfo["album"] = item->album()->name();
trackInfo["pptr"] = QString::number( (qlonglong)item );
m_coverHash.insert( (qlonglong)item, index );
Tomahawk::InfoSystem::InfoRequestData requestData;
requestData.caller = s_tmInfoIdentifier;
requestData.type = Tomahawk::InfoSystem::InfoAlbumCoverArt;
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo );
requestData.customData = QVariantMap();
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
return true;
}
void
AlbumModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
{
@ -348,7 +372,7 @@ AlbumModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, Q
bool ok;
qlonglong p = pptr["pptr"].toLongLong( &ok );
AlbumItem* ai = reinterpret_cast<AlbumItem*>(p);
AlbumItem* ai = itemFromIndex( m_coverHash.take( p ) );
if ( !ai )
return;

View File

@ -63,10 +63,11 @@ public:
virtual QStringList mimeTypes() const;
virtual Qt::ItemFlags flags( const QModelIndex& index ) const;
void clear();
void addCollection( const Tomahawk::collection_ptr& collection, bool overwrite = false );
void addFilteredCollection( const Tomahawk::collection_ptr& collection, unsigned int amount, DatabaseCommand_AllAlbums::SortOrder order, bool overwrite = false );
void clear();
bool getCover( const QModelIndex& index );
virtual QString title() const { return m_title; }
virtual QString description() const { return m_description; }
@ -95,8 +96,6 @@ signals:
void trackCountChanged( unsigned int tracks );
protected:
private slots:
void onDataChanged();
@ -110,6 +109,8 @@ private:
QString m_title;
QString m_description;
bool m_overwriteOnAdd;
QHash<qlonglong, QPersistentModelIndex> m_coverHash;
};
#endif // ALBUMMODEL_H

View File

@ -30,8 +30,6 @@
#include "viewmanager.h"
#include "utils/logger.h"
static QString s_tmInfoIdentifier = QString( "ALBUMMODEL" );
#define SCROLL_TIMEOUT 280
using namespace Tomahawk;
@ -164,25 +162,8 @@ AlbumView::onScrollTimeout()
started = true;
done = false;
AlbumItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( idx ) );
if ( !item )
if ( !m_model->getCover( m_proxyModel->mapToSource( idx ) ) )
break;
if ( !item->cover.isNull() )
break;
// qDebug() << "Need cover for:" << item->album()->artist()->name() << item->album()->name();
Tomahawk::InfoSystem::InfoCriteriaHash trackInfo;
trackInfo["artist"] = item->album()->artist()->name();
trackInfo["album"] = item->album()->name();
trackInfo["pptr"] = QString::number( (qlonglong)item );
Tomahawk::InfoSystem::InfoRequestData requestData;
requestData.caller = s_tmInfoIdentifier;
requestData.type = Tomahawk::InfoSystem::InfoAlbumCoverArt;
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo );
requestData.customData = QVariantMap();
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
}
}
}

View File

@ -32,8 +32,6 @@
#include "viewmanager.h"
#include "utils/logger.h"
static QString s_tmInfoIdentifier = QString( "TREEMODEL" );
#define SCROLL_TIMEOUT 280
using namespace Tomahawk;
@ -265,23 +263,7 @@ ArtistView::onScrollTimeout()
for ( int i = left.row(); i < max; i++ )
{
TreeModelItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( m_proxyModel->index( i, 0 ) ) );
if ( item->artist().isNull() )
continue;
if ( !item->cover.isNull() )
continue;
Tomahawk::InfoSystem::InfoCriteriaHash trackInfo;
trackInfo["artist"] = item->artist()->name();
trackInfo["pptr"] = QString::number( (qlonglong)item );
Tomahawk::InfoSystem::InfoRequestData requestData;
requestData.caller = s_tmInfoIdentifier;
requestData.type = Tomahawk::InfoSystem::InfoArtistImages;
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo );
requestData.customData = QVariantMap();
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
m_model->getCover( m_proxyModel->mapToSource( m_proxyModel->index( i, 0 ) ) );
}
}

View File

@ -57,6 +57,54 @@ TreeModel::~TreeModel()
}
void
TreeModel::clear()
{
if ( rowCount( QModelIndex() ) )
{
emit loadingFinished();
emit beginResetModel();
delete m_rootItem;
m_rootItem = 0;
m_rootItem = new TreeModelItem( 0, this );
emit endResetModel();
}
}
void
TreeModel::getCover( const QModelIndex& index )
{
TreeModelItem* item = itemFromIndex( index );
if ( !item->cover.isNull() )
return;
Tomahawk::InfoSystem::InfoCriteriaHash trackInfo;
Tomahawk::InfoSystem::InfoRequestData requestData;
if ( !item->artist().isNull() )
{
trackInfo["artist"] = item->artist()->name();
requestData.type = Tomahawk::InfoSystem::InfoArtistImages;
}
else if ( !item->album().isNull() )
{
trackInfo["artist"] = item->album()->artist()->name();
trackInfo["album"] = item->album()->name();
requestData.type = Tomahawk::InfoSystem::InfoAlbumCoverArt;
}
trackInfo["pptr"] = QString::number( (qlonglong)item );
m_coverHash.insert( (qlonglong)item, index );
requestData.caller = s_tmInfoIdentifier;
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo );
requestData.customData = QVariantMap();
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
}
void
TreeModel::setCurrentItem( const QModelIndex& index )
{
@ -645,18 +693,7 @@ TreeModel::onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums, const QVaria
albumitem->index = createIndex( parentItem->children.count() - 1, 0, albumitem );
connect( albumitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
Tomahawk::InfoSystem::InfoCriteriaHash trackInfo;
trackInfo["artist"] = album->artist()->name();
trackInfo["album"] = album->name();
trackInfo["pptr"] = QString::number( (qlonglong)albumitem );
Tomahawk::InfoSystem::InfoRequestData requestData;
requestData.caller = s_tmInfoIdentifier;
requestData.type = Tomahawk::InfoSystem::InfoAlbumCoverArt;
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo );
requestData.customData = QVariantMap();
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
getCover( albumitem->index );
}
if ( !parent.isValid() || crows.second > 0 )
@ -732,7 +769,9 @@ TreeModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QV
pm.loadFromData( ba );
bool ok;
qlonglong p = pptr["pptr"].toLongLong( &ok );
TreeModelItem* ai = reinterpret_cast<TreeModelItem*>(p);
TreeModelItem* ai = itemFromIndex( m_coverHash.take( p ) );
if ( !ai )
return;
if ( !pm.isNull() )
ai->cover = pm;

View File

@ -67,6 +67,8 @@ public:
virtual int rowCount( const QModelIndex& parent ) const;
virtual int columnCount( const QModelIndex& parent ) const;
virtual void clear();
virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) const;
@ -87,6 +89,8 @@ public:
void addAlbums( const Tomahawk::artist_ptr& artist, const QModelIndex& parent );
void addTracks( const Tomahawk::album_ptr& album, const QModelIndex& parent );
void getCover( const QModelIndex& index );
void setColumnStyle( ColumnStyle style );
virtual QString title() const { return m_title; }
@ -147,6 +151,7 @@ private:
ColumnStyle m_columnStyle;
Tomahawk::collection_ptr m_collection;
QHash<qlonglong, QPersistentModelIndex> m_coverHash;
};
#endif // ALBUMMODEL_H