mpdata/src/mpsongdata.cpp
changeset 32 c163ef0b758d
parent 29 8192e5b5c935
child 43 0f32e550d9d8
equal deleted inserted replaced
29:8192e5b5c935 32:c163ef0b758d
    19 #include <QString>
    19 #include <QString>
    20 #include <QPixmap>
    20 #include <QPixmap>
    21 #include <QPainter>
    21 #include <QPainter>
    22 #include <QBuffer>
    22 #include <QBuffer>
    23 #include <QPixmap>
    23 #include <QPixmap>
       
    24 #include <QTime>
    24 #include <hbicon.h>
    25 #include <hbicon.h>
    25 #include <QIcon>
    26 #include <QIcon>
    26 #include <QFile>
    27 #include <QFile>
    27 
    28 
    28 #include <thumbnailmanager_qt.h>
    29 #include <thumbnailmanager_qt.h>
    87 {
    88 {
    88     TX_ENTRY
    89     TX_ENTRY
    89     if( mThumbnailManager ) {
    90     if( mThumbnailManager ) {
    90         delete mThumbnailManager;
    91         delete mThumbnailManager;
    91     }
    92     }
       
    93     removeAlbumArtFile(); // TODO Remove when base64 is working
    92     TX_EXIT
    94     TX_EXIT
    93 }
    95 }
    94 
    96 
    95 /*!
    97 /*!
    96  Returns the song album art on \a pixmap.
    98  Returns the song album art on \a pixmap.
   731     return result;
   733     return result;
   732     */
   734     */
   733     // TODO: this is temporary solution until base64 defect in QT is fixed.
   735     // TODO: this is temporary solution until base64 defect in QT is fixed.
   734     TX_LOG
   736     TX_LOG
   735     QByteArray array;
   737     QByteArray array;
   736     QFile file( "e:\\album_art.png" );
   738 
       
   739     // Remove old album art in case new one cannot be written.
       
   740     removeAlbumArtFile();
       
   741 
       
   742     QString sTimeStamp = QTime::currentTime().toString( "hhmmsszzz" );
       
   743     QString sTempFileLocation = QString( "e:\\album_art_%1.png" ).arg( sTimeStamp );
       
   744 
       
   745     ( ( MpSongData* ) this )->mTempAlbumArt = sTempFileLocation;
       
   746     TX_LOG_ARGS( "Create album art file " << mTempAlbumArt );
       
   747 
       
   748     QFile file( mTempAlbumArt );
   737     file.open( QIODevice::WriteOnly );
   749     file.open( QIODevice::WriteOnly );
   738     if ( mAlbumArt && !mAlbumArt->isNull() && !mAlbumArt->qicon().isNull() )
   750     if ( mAlbumArt && !mAlbumArt->isNull() && !mAlbumArt->qicon().isNull() )
   739     {
   751     {
   740         QPixmap p = mAlbumArt->qicon().pixmap( QSize( 74, 74 ), QIcon::Normal, QIcon::Off );
   752         QPixmap p = mAlbumArt->qicon().pixmap( QSize( 74, 74 ), QIcon::Normal, QIcon::Off );
   741         p.save( &file, "PNG" );
   753         p.save( &file, "PNG" );
   742         //mAlbumArt->pixmap().save( &file, "PNG" ); // writes pixmap into bytes in PNG format
   754         //mAlbumArt->pixmap().save( &file, "PNG" ); // writes pixmap into bytes in PNG format
   743     }
   755     }
   744     file.close();
   756     file.close();
   745     return "e:\\album_art.png";
   757     return mTempAlbumArt;
   746 }
   758 }
   747 
   759 
       
   760 /*!
       
   761  Delete temporary album art file.
       
   762  */
       
   763 void MpSongData::removeAlbumArtFile() const
       
   764 {
       
   765     TX_ENTRY
       
   766     if ( !mTempAlbumArt.isEmpty() )
       
   767     {
       
   768         TX_LOG_ARGS( "Remove album art file " << mTempAlbumArt );
       
   769         QFile::remove( mTempAlbumArt );
       
   770         ( ( MpSongData* ) this )->mTempAlbumArt = "";
       
   771     }
       
   772     else
       
   773     {
       
   774         TX_LOG_ARGS( "Album art filename is empty" );
       
   775     }
       
   776     TX_EXIT
       
   777 }