extragear/multimedia/amarok

Seb Ruiz me at sebruiz.net
Wed Jan 17 15:23:45 UTC 2007


I remember that we used to have images embedded into the context
browser pages, and we changed this as one of the optimisations at the
K3M meeting last may.

Perhaps there is a better way to avoid using konqueror caching?

On 17/01/07, Tobias Knieper <tobias.knieper at gmail.com> wrote:
> SVN commit 624268 by tknieper:
>
> Embed album covers in html as encoded strings to get around KHtmlView's
> caching.
>
> BUG: 130518
>
>
>
>  M  +1 -0      ChangeLog
>  M  +20 -11    src/contextbrowser.cpp
>  M  +2 -0      src/contextbrowser.h
>
>
> --- trunk/extragear/multimedia/amarok/ChangeLog #624267:624268
> @@ -97,6 +97,7 @@
>     * Amarok now saves playlists with relative paths by default.
>
>   BUGFIXES:
> +    * Context browser would not display updated covers correctly. (BR 130518)
>     * The select custom cover dialog no longer starts in the wrong directory
>       for compilations. (BR 131776)
>     * Amarok's xine engine would cut off approximately the last second of an
> --- trunk/extragear/multimedia/amarok/src/contextbrowser.cpp #624267:624268
> @@ -1389,7 +1389,7 @@
>
>         QString artistName = albumValues[5].isEmpty() ? i18n( "Unknown artist" ) : albumValues[5];
>
> -        QString albumImage = CollectionDB::instance()->albumImage( albumValues[5], reqResult[ i ], true, 50 );
> +        QString albumImage = ContextBrowser::getEncodedImage( CollectionDB::instance()->albumImage( albumValues[5], reqResult[ i ], true, 50 ) );
>         QString albumImageTitleAttr = albumImageTooltip( albumImage, 50 );
>
>         // Album image
> @@ -1733,13 +1733,7 @@
>     const QString titleUrl   = lastFmInfo->titleUrl();
>     const QString lastfmIcon = "file://" + locate( "data","amarok/images/lastfm.png" );
>
> -    // Embed cover image in html (encoded string), to get around khtml's caching
> -    const QImage img( lastFmInfo->imageUrl() );
> -    QByteArray ba;
> -    QBuffer buffer( ba );
> -    buffer.open( IO_WriteOnly );
> -    img.save( &buffer, "PNG" ); // writes image into ba in PNG format
> -    const QString coverImage = QString( "data:image/png;base64,%1" ).arg( KCodecs::base64Encode( ba ) );
> +    const QString coverImage = ContextBrowser::getEncodedImage( lastFmInfo->imageUrl() );
>
>     QPtrList<QString> newUrls;
>     newUrls.append( &albumUrl  );
> @@ -2194,7 +2188,7 @@
>     usleep( 10000 );
>
>     //making 2 tables is most probably not the cleanest way to do it, but it works.
> -    QString albumImage = CollectionDB::instance()->albumImage( currentTrack, true, 1 );
> +    QString albumImage = ContextBrowser::getEncodedImage( CollectionDB::instance()->albumImage( currentTrack, true, 1 ) );
>     QString albumImageTitleAttr = albumImageTooltip( albumImage, 0 );
>
>     bool isCompilation = false;
> @@ -2660,7 +2654,7 @@
>                 i_albumLength += QString(albumValues[j + 4]).toInt();
>
>             QString albumLength = ( i_albumLength==0 ? i18n( "Unknown" ) : MetaBundle::prettyTime( i_albumLength, true ) );
> -            QString albumImage = CollectionDB::instance()->albumImage( artist, values[ i ], true, 50 );
> +            QString albumImage = ContextBrowser::getEncodedImage( CollectionDB::instance()->albumImage( artist, values[ i ], true, 50 ) );
>             QString albumImageTitleAttr = albumImageTooltip( albumImage, 50 );
>
>             m_HTMLSource.append( QStringx (
> @@ -2823,7 +2817,7 @@
>                 i_albumLength += QString(albumValues[j + 4]).toInt();
>
>             QString albumLength = ( i_albumLength==0 ? i18n( "Unknown" ) : MetaBundle::prettyTime( i_albumLength, true ) );
> -            QString albumImage = CollectionDB::instance()->albumImage( artist, values[ i ], true, 50 );
> +            QString albumImage = ContextBrowser::getEncodedImage( CollectionDB::instance()->albumImage( artist, values[ i ], true, 50 ) );
>             QString albumImageTitleAttr = albumImageTooltip( albumImage, 50 );
>
>             m_HTMLSource.append( QStringx (
> @@ -3157,6 +3151,21 @@
>     saveHtmlData(); // Send html code to file
>  }
>
> +QString
> +ContextBrowser::getEncodedImage( const QString &imageUrl )
> +{
> +    // Embed cover image in html (encoded string), to get around khtml's caching
> +    //debug() << "Encoding imageUrl: " << imageUrl << endl;
> +    const QImage img( imageUrl );
> +    QByteArray ba;
> +    QBuffer buffer( ba );
> +    buffer.open( IO_WriteOnly );
> +    img.save( &buffer, "PNG" ); // writes image into ba in PNG format
> +    const QString coverImage = QString( "data:image/png;base64,%1" ).arg( KCodecs::base64Encode( ba ) );
> +    //debug() << "Encoded imageUrl: " << coverImage << endl;
> +    return coverImage;
> +}
> +
>  //////////////////////////////////////////////////////////////////////////////////////////
>  // Lyrics-Tab
>  //////////////////////////////////////////////////////////////////////////////////////////
> --- trunk/extragear/multimedia/amarok/src/contextbrowser.h #624267:624268
> @@ -134,6 +134,8 @@
>         void saveHtmlData();
>         void showScanning();
>
> +        static QString getEncodedImage( const QString &imageUrl );
> +
>         static QString wikiLocale();
>         static void setWikiLocale( const QString &locale );
>         static QString wikiURL( const QString &item );
>


-- 
http://www.sebruiz.net/



More information about the Amarok mailing list