Sophie

Sophie

distrib > Mandriva > 2009.0 > i586 > by-pkgid > 01dcc30e475c184b57cffdc024fc2ec8 > files > 6

amarok-1.90-0.866096.6mdv2009.0.src.rpm

Index: amarok/src/collection/sqlcollection/SqlMeta.h
===================================================================
--- amarok/src/collection/sqlcollection/SqlMeta.h	(revisão 866606)
+++ amarok/src/collection/sqlcollection/SqlMeta.h	(revisão 866607)
@@ -247,6 +247,8 @@
         QString findCachedImage( int size ) const;
         QString findImage( int size );
         void updateImage( const QString path ) const; // Updates the database to ensure the album has the correct path
+        // Finds or creates a magic value in the database which tells Amarok not to auto fetch an image since it has been explicitly unset.
+        int unsetImageId() const;
 
     private:
         SqlCollection* m_collection;
@@ -255,6 +257,8 @@
         int m_artistId;
         mutable bool m_hasImage;
         mutable bool m_hasImageChecked;
+        mutable int m_unsetImageId;
+        static const QString AMAROK_UNSET_MAGIC;
         mutable QHash<int, QString> m_images; // Cache mapping size -> path. hash used for O(1) insertion and O(1) lookup
         bool m_tracksLoaded;
         Meta::ArtistPtr m_artist;
Index: amarok/src/collection/sqlcollection/SqlMeta.cpp
===================================================================
--- amarok/src/collection/sqlcollection/SqlMeta.cpp	(revisão 866606)
+++ amarok/src/collection/sqlcollection/SqlMeta.cpp	(revisão 866607)
@@ -948,6 +948,7 @@
 
 
 //---------------SqlAlbum---------------------------------
+const QString SqlAlbum::AMAROK_UNSET_MAGIC = QString( "AMAROK_UNSET_MAGIC" );
 
 SqlAlbum::SqlAlbum( SqlCollection* collection, int id, const QString &name, int artist ) : Album()
     , m_collection( QPointer<SqlCollection>( collection ) )
@@ -956,6 +957,7 @@
     , m_artistId( artist )
     , m_hasImage( false )
     , m_hasImageChecked( false )
+    , m_unsetImageId( -1 )
     , m_tracksLoaded( false )
     , m_artist()
     , m_mutex( QMutex::Recursive )
@@ -1033,6 +1035,12 @@
     else
     {
         QString image = findImage( size );
+
+        // If we return this value then we don't need to do anything else
+        // as we know that the user has explicitly set no cover
+        if( image == AMAROK_UNSET_MAGIC )
+            return Meta::Album::image( size, withShadow );
+
         if( !image.isEmpty() && size < 1000 )
             result = image;
     }
@@ -1127,10 +1135,12 @@
         int imageId    = res[0].toInt();
         int references = res[1].toInt();
 
-        // Set the album image to empty
-        query = "UPDATE albums SET image = NULL WHERE id = %1";
-        m_collection->query( query.arg( QString::number( m_id ) ) );
+        // Set the album image to a magic value which will tell Amarok not to fetch it automatically
+        const int unsetId = unsetImageId();
 
+        query = "UPDATE albums SET image = %1 WHERE id = %2";
+        m_collection->query( query.arg( QString::number( unsetId ), QString::number( m_id ) ) );
+
         // We've just removed a references to that imageid
         references--;
 
@@ -1151,10 +1161,36 @@
     }
 
     m_images.clear();
+    m_images.insert( 0, AMAROK_UNSET_MAGIC ); // Set the cached image to be the magic value
 
     notifyObservers();
 }
 
+int
+SqlAlbum::unsetImageId() const
+{
+    // Return the cached value if we have already done the lookup before
+    if( m_unsetImageId >= 0 )
+        return m_unsetImageId;
+
+    QString query = "SELECT id FROM images WHERE path = '%1'";
+    QStringList res = m_collection->query( query.arg( AMAROK_UNSET_MAGIC ) ); 
+
+    // We already have the AMAROK_UNSET_MAGIC variable in the database
+    if( !res.isEmpty() )
+    {
+        m_unsetImageId = res[0].toInt();
+    }
+    else
+    {
+        // We need to create this value
+        query = QString( "INSERT INTO images( path ) VALUES ( '%1' )" )
+                         .arg( m_collection->escape( AMAROK_UNSET_MAGIC ) );
+        m_unsetImageId = m_collection->insert( query, "images" );
+    }
+    return m_unsetImageId;
+}
+
 bool
 SqlAlbum::isCompilation() const
 {
@@ -1265,11 +1301,14 @@
         if( !res.isEmpty() )
         {
             fullsize = res.first();
-            if( !fullsize.isEmpty() )
+            if( !fullsize.isEmpty() ) 
                 m_images.insert( 0, fullsize ); // store the full size version
         }
     }
 
+    if( fullsize == AMAROK_UNSET_MAGIC )
+        return AMAROK_UNSET_MAGIC;
+
     if( QFile::exists( fullsize ) )
     {
         if( size > 1 )