------------------------------------------------------------------------
r717679 | mueller | 2007-09-27 11:50:56 +0200 (Thu, 27 Sep 2007) | 2 lines

fix various threading races

------------------------------------------------------------------------
Index: amarok/src/collectiondb.cpp
===================================================================
--- amarok/src/collectiondb.cpp	(revision 717678)
+++ amarok/src/collectiondb.cpp	(revision 717679)
@@ -217,6 +217,7 @@ CollectionDB::CollectionDB()
         : EngineObserver( EngineController::instance() )
         , m_autoScoring( true )
         , m_noCover( locate( "data", "amarok/images/nocover.png" ) )
+        , m_shadowImage( locate( "data", "amarok/images/shadow_albumcover.png" ) )
         , m_scanInProgress( false )
         , m_rescanRequired( false )
         , m_aftEnabledPersistentTables()
@@ -2055,11 +2056,12 @@ CollectionDB::albumImage( const MetaBund
     return s;
 }
 
-
 QString
 CollectionDB::makeShadowedImage( const QString& albumImage, bool cache )
 {
-    const QImage original( albumImage );
+    qApp->lock();
+    const QImage original( albumImage, "PNG" );
+    qApp->unlock();
 
     if( original.hasAlphaBuffer() )
         return albumImage;
@@ -2067,22 +2069,26 @@ CollectionDB::makeShadowedImage( const Q
     const QFileInfo fileInfo( albumImage );
     const uint shadowSize = static_cast<uint>( original.width() / 100.0 * 6.0 );
     const QString cacheFile = fileInfo.fileName() + "@shadow";
-    QImage shadow;
 
     if ( !cache && cacheCoverDir().exists( cacheFile ) )
         return cacheCoverDir().filePath( cacheFile );
 
+    QImage shadow;
+
     const QString folder = Amarok::saveLocation( "covershadow-cache/" );
     const QString file = QString( "shadow_albumcover%1x%2.png" ).arg( original.width() + shadowSize ).arg( original.height() + shadowSize  );
-    if ( QFile::exists( folder + file ) )
-        shadow.load( folder + file );
+    if ( QFile::exists( folder + file ) ) {
+        qApp->lock();
+        shadow.load( folder + file, "PNG" );
+        qApp->unlock();
+    }
     else {
-        shadow.load( locate( "data", "amarok/images/shadow_albumcover.png" ) );
+        shadow = QDeepCopy<QImage>(instance()->m_shadowImage);
         shadow = shadow.smoothScale( original.width() + shadowSize, original.height() + shadowSize );
         shadow.save( folder + file, "PNG" );
     }
 
-    QImage target( shadow );
+    QImage target(shadow);
     bitBlt( &target, 0, 0, &original );
 
     if ( cache ) {
@@ -7834,7 +7840,7 @@ QString
 QueryBuilder::tableName( int table )
 {
     // optimize for 1 table which is by far the most frequent case
-    static const QString tabNames[] = {
+    static const char tabNames[][16] = {
         "album",
         "artist",
         "composer",
Index: amarok/src/collectiondb.h
===================================================================
--- amarok/src/collectiondb.h	(revision 717678)
+++ amarok/src/collectiondb.h	(revision 717679)
@@ -619,7 +619,7 @@ class LIBAMAROK_EXPORT CollectionDB : pu
 
         static QMap<QListViewItem*, CoverFetcher*> *itemCoverMap;
         static QMutex *itemCoverMapMutex;
-        QImage m_noCover;
+        QImage m_noCover, m_shadowImage;
 
         static QMap<QThread *, DbConnection *> *threadConnections;
         static QMutex *connectionMutex;
Index: amarok/src/collectionbrowser.cpp
===================================================================
--- amarok/src/collectionbrowser.cpp	(revision 717678)
+++ amarok/src/collectionbrowser.cpp	(revision 717679)
@@ -63,7 +63,6 @@
 #include <klocale.h>
 #include <kmessagebox.h>
 #include <kpopupmenu.h>
-#include <kstandarddirs.h>   //KGlobal::dirs()
 #include <ktoolbarbutton.h> //ctor
 #include <kurldrag.h>       //dragObject()
 #include <kio/job.h>
Index: amarok/src/contextbrowser.cpp
===================================================================
--- amarok/src/contextbrowser.cpp	(revision 717678)
+++ amarok/src/contextbrowser.cpp	(revision 717679)
@@ -1109,6 +1109,9 @@ public:
 
         m_amarokIconPath = QDeepCopy<QString>(KGlobal::iconLoader()->iconPath( "amarok",
                     -KIcon::SizeEnormous ) );
+        m_musicBrainIconPath = QDeepCopy<QString>(locate( "data", "amarok/images/musicbrainz.png" )
+                );
+        m_lastfmIcon = "file://" + locate( "data","amarok/images/lastfm.png" );
     }
 
 private:
@@ -1151,6 +1154,8 @@ private:
     }
     QString m_HTMLSource;
     QString m_amarokIconPath;
+    QString m_musicBrainIconPath;
+    QString m_lastfmIcon;
 
     ContextBrowser *b;
     MetaBundle m_currentTrack;
@@ -1749,7 +1754,6 @@ void CurrentTrackJob::showLastFm( const 
     const QString albumUrl   = lastFmInfo->albumUrl();
     const QString artistUrl  = lastFmInfo->artistUrl();
     const QString titleUrl   = lastFmInfo->titleUrl();
-    const QString lastfmIcon = "file://" + locate( "data","amarok/images/lastfm.png" );
 
     const QString coverImage = ContextBrowser::getEncodedImage( lastFmInfo->imageUrl() );
 
@@ -1824,7 +1828,7 @@ void CurrentTrackJob::showLastFm( const 
             << escapeHTMLAttr( currentTrack.album() )//10
             << escapeHTMLAttr( userpage ) //11
             << escapeHTMLAttr( userpage ) //12
-            << escapeHTMLAttr( lastfmIcon ) //13
+            << escapeHTMLAttr( m_lastfmIcon ) //13
             << escapeHTML( i18n( "Skip" ) ) //14
             << escapeHTMLAttr( skipIcon ) //15
             << escapeHTML( i18n( "Love" ) ) //16
@@ -2255,7 +2259,7 @@ void CurrentTrackJob::showCurrentArtistH
                         << escapeHTMLAttr( currentTrack.artist() )
                         << escapeHTMLAttr( currentTrack.album() )
                         << escapeHTMLAttr( currentTrack.title() )
-                        << escapeHTML( locate( "data", "amarok/images/musicbrainz.png" ) ) )
+                        << escapeHTML( m_musicBrainIconPath ) )
                 : QString ( //no title
                         "<span id='current_box-header-prettytitle' class='box-header-prettytitle'>%1</span> "
                         "</div>\n"
