From 8e73e52986abe7633059a8e2e3d0fe0bde7613e6 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 14 Sep 2012 15:40:58 -0400 Subject: [PATCH] Store QPixmap on the heap in Result, as it's created in a db thread --- src/libtomahawk/Result.cpp | 7 ++++++- src/libtomahawk/Result.h | 9 ++++++--- src/libtomahawk/resolvers/QtScriptResolver.cpp | 2 +- src/libtomahawk/resolvers/ScriptResolver.cpp | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/libtomahawk/Result.cpp b/src/libtomahawk/Result.cpp index 4656f8858..dd6827903 100644 --- a/src/libtomahawk/Result.cpp +++ b/src/libtomahawk/Result.cpp @@ -64,6 +64,7 @@ Result::isCached( const QString& url ) Result::Result( const QString& url ) : QObject() , m_url( url ) + , m_sourceIcon( 0 ) , m_duration( 0 ) , m_bitrate( 0 ) , m_size( 0 ) @@ -81,6 +82,7 @@ Result::Result( const QString& url ) Result::~Result() { + delete m_sourceIcon; } @@ -301,7 +303,10 @@ Result::sourceIcon() const { if ( collection().isNull() ) { - return m_sourceIcon; + if ( !m_sourceIcon ) + return QPixmap(); + else + return *m_sourceIcon; } else { diff --git a/src/libtomahawk/Result.h b/src/libtomahawk/Result.h index 5069c3613..c196a05f3 100644 --- a/src/libtomahawk/Result.h +++ b/src/libtomahawk/Result.h @@ -89,7 +89,6 @@ public: void setRID( RID id ) { m_rid = id; } void setCollection( const Tomahawk::collection_ptr& collection ); void setFriendlySource( const QString& s ) { m_friendlySource = s; } - void setSourceIcon( const QPixmap& i ) { m_sourceIcon = i; } void setPurchaseUrl( const QString& u ) { m_purchaseUrl = u; } void setArtist( const Tomahawk::artist_ptr& artist ); void setAlbum( const Tomahawk::album_ptr& album ); @@ -104,6 +103,9 @@ public: void setYear( unsigned int year ) { m_year = year; } void setDiscNumber( unsigned int discnumber ) { m_discnumber = discnumber; } + // Takes ownership of the pixmap + void setSourceIcon( QPixmap* i ) { m_sourceIcon = i; } + QVariantMap attributes() const { return m_attributes; } void setAttributes( const QVariantMap& map ) { m_attributes = map; updateAttributes(); } @@ -120,7 +122,7 @@ signals: private slots: void onOffline(); void onOnline(); - + void onResolverRemoved( Tomahawk::Resolver* resolver ); private: @@ -143,7 +145,8 @@ private: QString m_purchaseUrl; QString m_mimetype; QString m_friendlySource; - QPixmap m_sourceIcon; + + QPixmap* m_sourceIcon; unsigned int m_duration; unsigned int m_bitrate; diff --git a/src/libtomahawk/resolvers/QtScriptResolver.cpp b/src/libtomahawk/resolvers/QtScriptResolver.cpp index 6f7cb6eac..cea977454 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.cpp +++ b/src/libtomahawk/resolvers/QtScriptResolver.cpp @@ -432,7 +432,7 @@ QtScriptResolver::parseResultVariantList( const QVariantList& reslist ) rp->setSize( m.value( "size" ).toUInt() ); rp->setRID( uuid() ); rp->setFriendlySource( name() ); - rp->setSourceIcon( icon() ); + rp->setSourceIcon( new QPixmap( icon() ) ); rp->setPurchaseUrl( m.value( "purchaseUrl" ).toString() ); rp->setScore( m.value( "score" ).toFloat() ); rp->setDiscNumber( m.value( "discnumber" ).toUInt() ); diff --git a/src/libtomahawk/resolvers/ScriptResolver.cpp b/src/libtomahawk/resolvers/ScriptResolver.cpp index 370a2383f..5c0ca8e86 100644 --- a/src/libtomahawk/resolvers/ScriptResolver.cpp +++ b/src/libtomahawk/resolvers/ScriptResolver.cpp @@ -282,7 +282,7 @@ ScriptResolver::handleMsg( const QByteArray& msg ) rp->setSize( m.value( "size" ).toUInt() ); rp->setRID( uuid() ); rp->setFriendlySource( m_name ); - rp->setSourceIcon( m_icon ); + rp->setSourceIcon( new QPixmap( m_icon ) ); rp->setPurchaseUrl( m.value( "purchaseUrl" ).toString() ); rp->setYear( m.value( "year").toUInt() ); rp->setDiscNumber( m.value( "discnumber" ).toUInt() );