mpdata/src/mpsongdata_p.cpp
changeset 43 0f32e550d9d8
child 45 612c4815aebe
equal deleted inserted replaced
38:b93f525c9244 43:0f32e550d9d8
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Metadata of song for details view - private implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <QString>
       
    20 #include <QPixmap>
       
    21 #include <QPainter>
       
    22 #include <QBuffer>
       
    23 #include <QPixmap>
       
    24 #include <QTime>
       
    25 #include <QIcon>
       
    26 #include <QFile>
       
    27 #include <QRegExp>
       
    28 #include <QFileInfo>
       
    29 #include <QDateTime>
       
    30 #include <QDate>
       
    31 
       
    32 #include <hbicon.h>
       
    33 
       
    34 #include <mpxmedia.h>
       
    35 #include <mpxmediacontainerdefs.h>
       
    36 #include <mpxmediaarray.h>
       
    37 #include <mpxmediageneraldefs.h>
       
    38 #include <mpxmediamusicdefs.h>
       
    39 #include <mpxmediaaudiodefs.h>
       
    40 #include <mpxmediadrmdefs.h>
       
    41 #include <thumbnailmanager_qt.h>
       
    42 
       
    43 #include "mpsongdata_p.h"
       
    44 #include "mptrace.h"
       
    45 
       
    46 const int KUndefined = -1;
       
    47 
       
    48 /*!
       
    49     \class MpSongDataPrivate
       
    50     \brief Music Player song metadata - private implementation.
       
    51 
       
    52     Song data provide access to song metadata.
       
    53 */
       
    54 
       
    55 /*!
       
    56     Constructs a new MpSongDataPrivate.
       
    57  */
       
    58 MpSongDataPrivate::MpSongDataPrivate( MpSongData *wrapper, ThumbnailManager *thumbnailManager )
       
    59     : q_ptr( wrapper ),
       
    60       mThumbnailManager(thumbnailManager),
       
    61       mReqId( KUndefined ),
       
    62       mAlbumArt()
       
    63 {
       
    64     TX_ENTRY
       
    65     mDefaultAlbumArt = new HbIcon( "qtg_large_music_album" );
       
    66     TX_EXIT
       
    67 }
       
    68 
       
    69 /*!
       
    70  Constructs a new MpSongDataPrivate.
       
    71  */
       
    72 MpSongDataPrivate::~MpSongDataPrivate()
       
    73 {
       
    74     TX_ENTRY
       
    75     removeAlbumArtFile(); // TODO Remove when base64 is working
       
    76     TX_EXIT
       
    77 }
       
    78 
       
    79 /*!
       
    80  Returns the song title.
       
    81  */
       
    82 QString MpSongDataPrivate::title() const
       
    83 {
       
    84     TX_LOG
       
    85     return mTitle;
       
    86 }
       
    87 
       
    88 /*!
       
    89  Returns the song album.
       
    90  */
       
    91 QString MpSongDataPrivate::album() const
       
    92 {
       
    93     TX_LOG
       
    94     return mAlbum;
       
    95 }
       
    96 
       
    97 /*!
       
    98  Returns the song artist.
       
    99  */
       
   100 QString MpSongDataPrivate::artist() const
       
   101 {
       
   102     TX_LOG
       
   103     return mArtist;
       
   104 }
       
   105 
       
   106 /*!
       
   107  Returns the comment.
       
   108  */
       
   109 QString MpSongDataPrivate::comment() const
       
   110 {
       
   111     TX_LOG
       
   112     return mComment;
       
   113 }
       
   114 
       
   115 /*!
       
   116  Returns the song album art on \a icon.
       
   117  */
       
   118 void MpSongDataPrivate::albumArt( HbIcon& icon ) const
       
   119 {
       
   120     TX_ENTRY
       
   121      if (  !mAlbumArt || mAlbumArt->isNull() ) {
       
   122          TX_LOG_ARGS( "Album art is NULL." );
       
   123          icon = HbIcon();
       
   124      } else {
       
   125          TX_LOG_ARGS( "Album art is not NULL." );
       
   126          icon = *mAlbumArt ;
       
   127      }
       
   128     TX_EXIT
       
   129 }
       
   130 
       
   131 /*!
       
   132  Returns the release date.
       
   133  */
       
   134 QString MpSongDataPrivate::year() const
       
   135 {
       
   136     TX_LOG
       
   137     return mYear;
       
   138 }
       
   139 
       
   140 /*!
       
   141  Returns the song genre.
       
   142  */
       
   143 QString MpSongDataPrivate::genre() const
       
   144 {
       
   145     TX_LOG
       
   146     return mGenre;
       
   147 }
       
   148 
       
   149 /*!
       
   150  Returns the song composer.
       
   151  */
       
   152 QString MpSongDataPrivate::composer() const
       
   153 {
       
   154     TX_LOG
       
   155     return mComposer;
       
   156 }
       
   157 
       
   158 /*!
       
   159  Returns the album track.
       
   160  */
       
   161 QString MpSongDataPrivate::albumTrack() const
       
   162 {
       
   163     TX_LOG
       
   164     return mAlbumTrack;
       
   165 }
       
   166 
       
   167 /*!
       
   168  Returns link
       
   169  */
       
   170 QString MpSongDataPrivate::link() const
       
   171 {
       
   172     TX_LOG
       
   173     return mLink;
       
   174 }
       
   175 
       
   176 /*!
       
   177  Returns the file name
       
   178  */
       
   179 QString MpSongDataPrivate::fileName() const
       
   180 {
       
   181     TX_LOG
       
   182     return mFileName;
       
   183 }
       
   184 
       
   185 /*!
       
   186  Returns the MIME type
       
   187  */
       
   188 QString MpSongDataPrivate::mimeType() const
       
   189 {
       
   190     TX_LOG
       
   191     return mMimeType;
       
   192 }
       
   193 
       
   194 /*!
       
   195  Returns the duration
       
   196 */
       
   197 QString MpSongDataPrivate::duration() const
       
   198 {
       
   199     TX_LOG
       
   200     return mDuration;
       
   201 }
       
   202 
       
   203 /*!
       
   204  Returns the bit rate
       
   205  */
       
   206 QString MpSongDataPrivate::bitRate() const
       
   207 {
       
   208     TX_LOG
       
   209     return mBitRate;
       
   210 }
       
   211 
       
   212 /*!
       
   213  Returns the sampling rate
       
   214  */
       
   215 QString MpSongDataPrivate::sampleRate() const
       
   216 {
       
   217     TX_LOG
       
   218     return mSampleRate;
       
   219 }
       
   220 
       
   221 /*!
       
   222  Returns the size
       
   223  */
       
   224 QString MpSongDataPrivate::size() const
       
   225 {
       
   226     TX_LOG
       
   227     return mSize;
       
   228 }
       
   229 
       
   230 /*!
       
   231  Returns the modified time
       
   232  */
       
   233 QString MpSongDataPrivate::modified() const
       
   234 {
       
   235     TX_LOG
       
   236     return mModified;
       
   237 }
       
   238 
       
   239 /*!
       
   240  Returns the copyright
       
   241  */
       
   242 QString MpSongDataPrivate::copyright() const
       
   243 {
       
   244     TX_LOG
       
   245     return mCopyright;
       
   246 }
       
   247 
       
   248 /*!
       
   249  Returns the music URL
       
   250  */
       
   251 QString MpSongDataPrivate::musicURL() const
       
   252 {
       
   253     TX_LOG
       
   254     return mMusicURL;
       
   255 }
       
   256 
       
   257 /*!
       
   258  Returns whether the song is protected
       
   259  */
       
   260 bool MpSongDataPrivate::isDrmProtected() const
       
   261 {
       
   262     TX_LOG
       
   263     return mDrmProtected;
       
   264 }
       
   265 
       
   266 /*!
       
   267  Retrieve the album art in base64 encoding suitable for inline HTML display for sharing player.
       
   268  */
       
   269 QString MpSongDataPrivate::albumArtBase64() const
       
   270 {
       
   271     /*
       
   272     // Converts the current album art icon to a base64 string, and return the string.
       
   273     TX_LOG
       
   274     if ( mAlbumArt->isNull() ) {
       
   275         TX_ENTRY_ARGS( "MpSongDataPrivate: album art isNull" )
       
   276         return "nullimgcraptoberemoved";
       
   277     }
       
   278     TX_ENTRY_ARGS("MpSongDataPrivate: album art exists");
       
   279     QByteArray array;
       
   280     QBuffer buffer( &array );
       
   281     buffer.open( QIODevice::WriteOnly );
       
   282     mAlbumArt->pixmap().save( &buffer, "PNG" ); // writes pixmap into bytes in PNG format
       
   283     buffer.close();
       
   284     QString result = array.toBase64().constData();
       
   285     TX_ENTRY_ARGS("MpSongDataPrivate: album art base64 length: " << result.length());
       
   286     return result;
       
   287     */
       
   288     // TODO: this is temporary solution until base64 defect in QT is fixed.
       
   289     TX_LOG
       
   290     QByteArray array;
       
   291 
       
   292     // Remove old album art in case new one cannot be written.
       
   293     removeAlbumArtFile();
       
   294 
       
   295     QString sTimeStamp = QTime::currentTime().toString( "hhmmsszzz" );
       
   296     QString sTempFileLocation = QString( "e:\\album_art_%1.png" ).arg( sTimeStamp );
       
   297 
       
   298     ( ( MpSongDataPrivate* ) this )->mTempAlbumArt = sTempFileLocation;
       
   299     TX_LOG_ARGS( "Create album art file " << mTempAlbumArt );
       
   300 
       
   301     QFile file( mTempAlbumArt );
       
   302     file.open( QIODevice::WriteOnly );
       
   303     if ( mAlbumArt && !mAlbumArt->isNull() && !mAlbumArt->qicon().isNull() )
       
   304     {
       
   305         QPixmap p = mAlbumArt->qicon().pixmap( QSize( 74, 74 ), QIcon::Normal, QIcon::Off );
       
   306         p.save( &file, "PNG" );
       
   307         //mAlbumArt->pixmap().save( &file, "PNG" ); // writes pixmap into bytes in PNG format
       
   308     }
       
   309     file.close();
       
   310     return mTempAlbumArt;
       
   311 }
       
   312 
       
   313 /*!
       
   314  Delete temporary album art file.
       
   315  */
       
   316 void MpSongDataPrivate::removeAlbumArtFile() const
       
   317 {
       
   318     TX_ENTRY
       
   319     if ( !mTempAlbumArt.isEmpty() )
       
   320     {
       
   321         TX_LOG_ARGS( "Remove album art file " << mTempAlbumArt );
       
   322         QFile::remove( mTempAlbumArt );
       
   323         ( ( MpSongDataPrivate* ) this )->mTempAlbumArt = "";
       
   324     }
       
   325     else
       
   326     {
       
   327         TX_LOG_ARGS( "Album art filename is empty" );
       
   328     }
       
   329     TX_EXIT
       
   330 }
       
   331 
       
   332 /*!
       
   333  Sets the \a link
       
   334  */
       
   335 void MpSongDataPrivate::setLink( const QString &link )
       
   336 {
       
   337     TX_ENTRY_ARGS( "Link =" << link )
       
   338     mLink = link;
       
   339     TX_EXIT
       
   340 }
       
   341 
       
   342 /*!
       
   343  \internal
       
   344  New data from MPX collection.
       
   345  */
       
   346 void MpSongDataPrivate::setMpxMedia( const CMPXMedia& aMedia )
       
   347 {
       
   348     TX_ENTRY
       
   349     TRAPD(err, DoSetMpxMediaL(aMedia));
       
   350     if ( err != KErrNone ) {
       
   351         TX_LOG_ARGS("Error: " << err << "; should never get here.");
       
   352     }
       
   353     TX_EXIT
       
   354 }
       
   355 
       
   356 /*!
       
   357  Returns the reserved length.
       
   358  */
       
   359 int MpSongDataPrivate::reservedLength() const
       
   360 {
       
   361     return mLink.length() + mTitle.length() + mArtist.length();
       
   362 }
       
   363 
       
   364 /*!
       
   365  Handles the album art thumbnail.
       
   366  */
       
   367 void MpSongDataPrivate::thumbnailReady( QPixmap pixmap, void *data, int id, int error )
       
   368 {
       
   369     TX_ENTRY
       
   370     Q_UNUSED( data );
       
   371     if ( error == 0 && mReqId == id ) {
       
   372         QIcon qicon;
       
   373         QPixmap mCompositePixmap;
       
   374         mReqId = KUndefined;
       
   375 
       
   376         mCompositePixmap = QPixmap( 360, 360 );
       
   377         mCompositePixmap.fill( Qt::transparent );
       
   378         QPainter painter(&mCompositePixmap);
       
   379         painter.setCompositionMode(QPainter::CompositionMode_Clear);
       
   380         painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
       
   381         painter.fillRect(mCompositePixmap.rect(), Qt::transparent);
       
   382         painter.drawPixmap(QRect(0, 0,360,360), pixmap);
       
   383 
       
   384         if ( !mCompositePixmap.isNull() ) {
       
   385             qicon = QIcon( mCompositePixmap );
       
   386         }
       
   387         else {
       
   388             qicon = QIcon( pixmap );
       
   389         }
       
   390 
       
   391         if ( mAlbumArt == mDefaultAlbumArt ) {
       
   392             TX_LOG_ARGS( "Album art is default album art." )
       
   393             delete mAlbumArt;
       
   394             mAlbumArt = new HbIcon(qicon);
       
   395             mDefaultAlbumArt = new HbIcon( "qtg_large_music_album" );
       
   396         } else {
       
   397             TX_LOG_ARGS( "Album art is NOT default album art." )
       
   398             delete mAlbumArt;
       
   399             mAlbumArt = new HbIcon(qicon);
       
   400         }
       
   401 
       
   402         emit q_ptr->albumArtReady();
       
   403     }
       
   404     else {
       
   405         mReqId = KUndefined;
       
   406         mAlbumArt = mDefaultAlbumArt;
       
   407         emit q_ptr->albumArtReady();
       
   408     }
       
   409 
       
   410     TX_EXIT
       
   411 }
       
   412 
       
   413 /*!
       
   414  \internal
       
   415  */
       
   416 void MpSongDataPrivate::DoSetMpxMediaL( const CMPXMedia& aMedia )
       
   417 {
       
   418     TX_ENTRY
       
   419     bool changed = false;
       
   420     if ( aMedia.IsSupported( KMPXMediaGeneralTitle ) ) {
       
   421         changed |= setTitle(
       
   422             QString::fromUtf16(
       
   423                 aMedia.ValueText( KMPXMediaGeneralTitle ).Ptr(),
       
   424                 aMedia.ValueText( KMPXMediaGeneralTitle ).Length() ) );
       
   425     } else {
       
   426         changed |= setTitle( QString() );
       
   427     }
       
   428 
       
   429     if ( aMedia.IsSupported( KMPXMediaMusicArtist ) ) {
       
   430         changed |= setArtist(
       
   431             QString::fromUtf16(
       
   432                 aMedia.ValueText( KMPXMediaMusicArtist ).Ptr(),
       
   433                 aMedia.ValueText( KMPXMediaMusicArtist ).Length() ) );
       
   434     } else {
       
   435         changed |= setArtist( QString() );
       
   436     }
       
   437 
       
   438     if ( aMedia.IsSupported( KMPXMediaMusicAlbum ) ) {
       
   439         changed |= setAlbum(
       
   440             QString::fromUtf16(
       
   441                 aMedia.ValueText( KMPXMediaMusicAlbum ).Ptr(),
       
   442                 aMedia.ValueText( KMPXMediaMusicAlbum ).Length() ) );
       
   443     } else {
       
   444         changed |= setAlbum( QString() );
       
   445     }
       
   446     if ( changed ) {
       
   447         emit q_ptr->playbackInfoChanged();
       
   448     }
       
   449 
       
   450     // call back will be called when Album art is retrieved
       
   451     if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaMusicAlbumArtFileName ) ) ) {
       
   452         setAlbumArtUri(
       
   453                 QString::fromUtf16(
       
   454                         aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Ptr(),
       
   455                         aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Length() ) );
       
   456     } else {
       
   457         setAlbumArtUri( QString() );
       
   458     }
       
   459 
       
   460     // all following will be for song details
       
   461     changed = false;
       
   462     if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaGeneralUri ) ) ) {
       
   463         QString fullName = QString::fromUtf16(
       
   464                 aMedia.ValueText( KMPXMediaGeneralUri ).Ptr(),
       
   465                 aMedia.ValueText( KMPXMediaGeneralUri ).Length() );
       
   466 
       
   467         TX_LOG_ARGS( "File name with path: " << fullName );
       
   468         // get size & last modifed information from file system
       
   469         QFileInfo info( fullName );
       
   470         changed |= setSize( info.size() );
       
   471 
       
   472         QDateTime lastModified = info.lastModified();
       
   473         QDate date = lastModified.date();
       
   474         int day = date.day();
       
   475         int month = date.month();
       
   476         int year = date.year();
       
   477         QTime time = lastModified.time();
       
   478         int sec = time.second();
       
   479         int min = time.minute();
       
   480         int hr = time.hour();
       
   481 
       
   482         QString lastModifiedStr("%1.%2.%3 %4:%5:%6");
       
   483         lastModifiedStr = lastModifiedStr.arg( day ).arg( month ).arg( year ).arg( hr ).arg( min ).arg( sec );
       
   484         changed |= setModified( lastModifiedStr );
       
   485 
       
   486 
       
   487         // get file name without suffix
       
   488         QString file;
       
   489         QRegExp rx("(.+)\\..+");
       
   490         QString str = info.fileName();
       
   491         TX_LOG_ARGS( "File name with suffix = " << str );
       
   492 
       
   493         int pos = rx.indexIn( str );
       
   494         if( pos > -1 ) {
       
   495             file = rx.cap( 1 );
       
   496             TX_LOG_ARGS( "File = " << file );
       
   497         }
       
   498 
       
   499         changed |= setFileName( file );
       
   500     } else {
       
   501         changed |= setFileName( QString() );
       
   502     }
       
   503 
       
   504     if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaMusicComposer ) ) ) {
       
   505         TX_LOG_ARGS( "Composer is supported " );
       
   506         changed |= setComposer(
       
   507             QString::fromUtf16(
       
   508                 aMedia.ValueText( KMPXMediaMusicComposer ).Ptr(),
       
   509                 aMedia.ValueText( KMPXMediaMusicComposer ).Length() ) );
       
   510     } else {
       
   511         changed |= setComposer( QString() );
       
   512     }
       
   513 
       
   514     if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaMusicYear ) ) ) {
       
   515         TInt64 yearInMicroSeconds = aMedia.ValueTObjectL<TInt64>( KMPXMediaMusicYear );
       
   516         TX_LOG_ARGS( "year = " << yearInMicroSeconds );
       
   517         TTime yearTime( yearInMicroSeconds );
       
   518         changed |= setYear( yearTime.DateTime().Year() );
       
   519     } else {
       
   520         // to clear previous result
       
   521         changed |= setYear( -1 );
       
   522     }
       
   523 
       
   524     if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaMusicAlbumTrack ) ) ) {
       
   525         changed |= setAlbumTrack(
       
   526             QString::fromUtf16(
       
   527                 aMedia.ValueText( KMPXMediaMusicAlbumTrack ).Ptr(),
       
   528                 aMedia.ValueText( KMPXMediaMusicAlbumTrack ).Length() ) );
       
   529     } else {
       
   530         changed |= setAlbumTrack( QString() );
       
   531     }
       
   532 
       
   533     if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaMusicGenre ) ) ) {
       
   534         changed |= setGenre(
       
   535             QString::fromUtf16(
       
   536                 aMedia.ValueText( KMPXMediaMusicGenre ).Ptr(),
       
   537                 aMedia.ValueText( KMPXMediaMusicGenre ).Length() ) );
       
   538     } else {
       
   539         changed |= setGenre( QString() );
       
   540     }
       
   541 
       
   542     if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaGeneralMimeType ) ) ) {
       
   543         QString type = QString::fromUtf16(
       
   544                             aMedia.ValueText( KMPXMediaGeneralMimeType ).Ptr(),
       
   545                             aMedia.ValueText( KMPXMediaGeneralMimeType ).Length() );
       
   546         QString regularExpression(".+/(.+)");
       
   547         QRegExp rx(regularExpression);
       
   548         QString mimeType;
       
   549 
       
   550         int pos = rx.indexIn( type );
       
   551         if( pos > -1 ) {
       
   552             mimeType = rx.cap( 1 );
       
   553             mimeType = mimeType.toUpper();
       
   554             TX_LOG_ARGS( "MIME type =" << mimeType );
       
   555         }
       
   556 
       
   557         changed |= setMimeType( mimeType );
       
   558     } else {
       
   559         changed |= setMimeType( QString() );
       
   560     }
       
   561 
       
   562     if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaGeneralDuration ) ) ) {
       
   563         TInt duration( aMedia.ValueTObjectL<TInt>( KMPXMediaGeneralDuration ) );
       
   564         changed |= setDuration( duration / 1000 );
       
   565     } else {
       
   566         changed |= setDuration( -1 );
       
   567     }
       
   568 
       
   569     if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaAudioBitrate  ) ) ) {
       
   570         TInt bitRate( aMedia.ValueTObjectL<TInt>( KMPXMediaAudioBitrate ) );
       
   571         changed |= setBitRate( bitRate );
       
   572     } else {
       
   573         changed |= setBitRate( -1 );
       
   574     }
       
   575 
       
   576     if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaAudioSamplerate  ) ) ) {
       
   577         TInt sampleRate( aMedia.ValueTObjectL<TInt>( KMPXMediaAudioSamplerate ) );
       
   578         changed |= setSampleRate( sampleRate );
       
   579     } else {
       
   580         changed |= setSampleRate( -1 );
       
   581     }
       
   582 
       
   583 
       
   584     if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaGeneralCopyright ) ) ) {
       
   585         changed |= setCopyright(
       
   586             QString::fromUtf16(
       
   587                 aMedia.ValueText( KMPXMediaGeneralCopyright ).Ptr(),
       
   588                 aMedia.ValueText( KMPXMediaGeneralCopyright ).Length() ) );
       
   589     } else {
       
   590         changed |= setCopyright( QString() );
       
   591     }
       
   592 
       
   593     if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaMusicURL ) ) ) {
       
   594         changed |= setMusicURL(
       
   595             QString::fromUtf16(
       
   596                 aMedia.ValueText( KMPXMediaMusicURL ).Ptr(),
       
   597                 aMedia.ValueText( KMPXMediaMusicURL ).Length() ) );
       
   598     } else {
       
   599         changed |= setMusicURL( QString() );
       
   600     }
       
   601 
       
   602     if ( aMedia.IsSupported( TMPXAttribute( KMPXMediaDrmProtected ) ) ) {
       
   603     TX_LOG_ARGS( "DRM is supported." );
       
   604         changed |= setDrmProtected( aMedia.ValueTObjectL<TBool>( KMPXMediaDrmProtected ) );
       
   605     } else {
       
   606         changed |= setDrmProtected( false );
       
   607     }
       
   608 
       
   609     if ( changed ) {
       
   610         emit q_ptr->songDetailInfoChanged();
       
   611     }
       
   612     TX_EXIT
       
   613 }
       
   614 
       
   615 /*!
       
   616  Sets the song \a title, returns true if the value is new.
       
   617  */
       
   618 bool MpSongDataPrivate::setTitle( const QString &title )
       
   619 {
       
   620     TX_ENTRY_ARGS( "title =" << title )
       
   621     bool change = false;
       
   622     if ( title != mTitle ) {
       
   623         change = true;
       
   624         mTitle = title;
       
   625     }
       
   626     TX_EXIT
       
   627     return change;
       
   628 }
       
   629 
       
   630 /*!
       
   631  Sets the song \a album, returns true if the value is new.
       
   632  */
       
   633 bool MpSongDataPrivate::setAlbum( const QString &album )
       
   634 {
       
   635     TX_ENTRY_ARGS( "album =" << album )
       
   636     bool change = false;
       
   637     if ( album != mAlbum ) {
       
   638         change = true;
       
   639         mAlbum = album;
       
   640     }
       
   641     TX_EXIT
       
   642     return change;
       
   643 }
       
   644 
       
   645 /*!
       
   646  Sets the song \a artist, returns true if the value is new.
       
   647  */
       
   648 bool MpSongDataPrivate::setArtist( const QString &artist )
       
   649 {
       
   650     TX_ENTRY_ARGS( "artist =" << artist )
       
   651     bool change = false;
       
   652     if ( artist != mArtist ) {
       
   653         change = true;
       
   654         mArtist = artist;
       
   655     }
       
   656     TX_EXIT
       
   657     return change;
       
   658 }
       
   659 
       
   660 /*!
       
   661  Sets the song \a comment, returns true if the value is new.
       
   662  */
       
   663 bool MpSongDataPrivate::setComment( const QString &comment)
       
   664 {
       
   665     TX_ENTRY_ARGS( "comment =" << comment )
       
   666     bool change = false;
       
   667     if ( comment != mComment ) {
       
   668         change = true;
       
   669         mComment = comment;
       
   670     }
       
   671     TX_EXIT
       
   672     return change;
       
   673 }
       
   674 
       
   675 /*!
       
   676  Sets the song \a composer, returns true if the value is new.
       
   677  */
       
   678 bool MpSongDataPrivate::setComposer( const QString &composer )
       
   679 {
       
   680     TX_ENTRY_ARGS( "composer =" << composer )
       
   681     bool change = false;
       
   682     if ( composer != mComposer ) {
       
   683         change = true;
       
   684         mComposer = composer;
       
   685     }
       
   686     TX_EXIT
       
   687     return change;
       
   688 }
       
   689 
       
   690 /*!
       
   691  Sets the song \a genre, returns true if the value is new.
       
   692  */
       
   693 bool MpSongDataPrivate::setGenre( const QString &genre )
       
   694 {
       
   695     TX_ENTRY_ARGS( "genre =" << genre )
       
   696     bool change = false;
       
   697     if ( genre != mGenre ) {
       
   698         change = true;
       
   699         mGenre = genre;
       
   700     }
       
   701     TX_EXIT
       
   702     return change;
       
   703 }
       
   704 
       
   705 /*!
       
   706  Sets the song \a date, returns true if the value is new.
       
   707  */
       
   708 bool MpSongDataPrivate::setYear( int year )
       
   709 {
       
   710     TX_ENTRY_ARGS( "year =" << year )
       
   711     bool change = false;
       
   712     if ( QString::number(year) != mYear ) {
       
   713         change = true;
       
   714         if ( year >= 0 && year < 9999 ) {
       
   715             mYear = QString::number(year);
       
   716         } else {
       
   717             mYear = QString();
       
   718         }
       
   719     }
       
   720     TX_EXIT
       
   721     return change;
       
   722 }
       
   723 
       
   724 /*!
       
   725  Sets the \a album track, returns true if the value is new.
       
   726  */
       
   727 bool MpSongDataPrivate::setAlbumTrack( const QString &track )
       
   728 {
       
   729     TX_ENTRY_ARGS( "track =" << track )
       
   730     bool change = false;
       
   731     if ( track != mAlbumTrack ) {
       
   732         change = true;
       
   733         mAlbumTrack = track;
       
   734     }
       
   735     TX_EXIT
       
   736     return change;
       
   737 }
       
   738 
       
   739 /*!
       
   740  Sets the song \a albumArtUri.
       
   741  */
       
   742 void MpSongDataPrivate::setAlbumArtUri( const QString &albumArtUri)
       
   743 {
       
   744     TX_ENTRY_ARGS( "albumArtUri = " << albumArtUri )
       
   745     if ( !albumArtUri.isEmpty() ) {
       
   746         TX_LOG_ARGS( "There is album art" );
       
   747         bool ok = true;
       
   748         if ( mReqId != KUndefined ) {
       
   749             // There is already an outstanding request. Cancel it first.
       
   750             bool ok = mThumbnailManager->cancelRequest( mReqId );
       
   751         }
       
   752         if ( ok ) {
       
   753             mReqId = mThumbnailManager->getThumbnail( albumArtUri );
       
   754             if ( mReqId == KUndefined ) {
       
   755                 // Request failed. Set default album art.
       
   756                 mAlbumArt = mDefaultAlbumArt;
       
   757                 emit q_ptr->albumArtReady();
       
   758             }
       
   759         }
       
   760     }
       
   761     else {
       
   762         // No album art uri. Set default album art.
       
   763         TX_LOG_ARGS( "There is No album art" );
       
   764         mAlbumArt = mDefaultAlbumArt;
       
   765         emit q_ptr->albumArtReady();
       
   766     }
       
   767     TX_EXIT
       
   768 }
       
   769 
       
   770 /*!
       
   771  Sets the \a file name
       
   772  */
       
   773 bool MpSongDataPrivate::setFileName( const QString &fileName )
       
   774 {
       
   775     TX_ENTRY_ARGS( "File name =" << fileName )
       
   776     bool change = false;
       
   777     if ( fileName != mFileName ) {
       
   778         change = true;
       
   779         mFileName = fileName;
       
   780     }
       
   781     TX_EXIT
       
   782     return change;
       
   783 }
       
   784 
       
   785 /*!
       
   786  Sets the \a MIME type
       
   787  */
       
   788 bool MpSongDataPrivate::setMimeType( const QString &mimeType )
       
   789 {
       
   790     TX_ENTRY_ARGS( "Mime =" << mimeType )
       
   791     bool change = false;
       
   792     if ( mimeType != mMimeType ) {
       
   793         change = true;
       
   794         mMimeType = mimeType;
       
   795     }
       
   796     TX_EXIT
       
   797     return change;
       
   798 }
       
   799 
       
   800 /*!
       
   801  Sets the \a duration
       
   802  */
       
   803 bool MpSongDataPrivate::setDuration( int duration )
       
   804 {
       
   805     TX_ENTRY_ARGS( "Duration =" << duration )
       
   806     bool change = false;
       
   807     QString timeFormatOne("%1:%2:%3");
       
   808     QString timeFormatTwo("%1:%2");
       
   809     if ( QString::number( duration ) != mDuration ) {
       
   810         change = true;
       
   811         if ( duration >= 3600 ) {
       
   812             // more than one hours
       
   813             QString hourStr, minStr, secStr;
       
   814             int hour = duration / 3600;
       
   815             int min = duration % 3600 / 60;
       
   816             int sec = duration % 3600 % 60;
       
   817 
       
   818             hourStr = hour >= 10 ? QString::number( hour ) : QString::number( hour ).prepend( "0" );
       
   819             minStr = min >= 10 ? QString::number( min ) : QString::number( min ).prepend( "0" );
       
   820             secStr = sec >= 10 ? QString::number( sec ) : QString::number( sec ).prepend( "0" );
       
   821             mDuration = timeFormatOne.arg( hourStr ).arg( minStr ).arg( secStr );
       
   822         } else if ( duration >= 60 && duration < 3600 ) {
       
   823             // more than one min && less than one hour
       
   824             QString minStr, secStr;
       
   825             int min = duration / 60;
       
   826             int sec = duration % 60;
       
   827 
       
   828             minStr = min >= 10 ? QString::number( min ) : QString::number( min ).prepend( "0" );
       
   829             secStr = sec >= 10 ? QString::number( sec ) : QString::number( sec ).prepend( "0" );
       
   830             mDuration = timeFormatTwo.arg( minStr ).arg( secStr );
       
   831         } else if ( duration > 0 && duration < 60 ) {
       
   832             QString secStr;
       
   833             secStr = duration >= 10 ? QString::number( duration ) : QString::number( duration ).prepend( "0" );
       
   834             mDuration = secStr;
       
   835         } else {
       
   836             mDuration = QString();
       
   837         }
       
   838     }
       
   839     TX_EXIT
       
   840     return change;
       
   841 }
       
   842 
       
   843 /*!
       
   844  Sets bit rate
       
   845  */
       
   846 bool MpSongDataPrivate::setBitRate( int bitRate)
       
   847 {
       
   848     TX_ENTRY_ARGS( "Bit rate =" << bitRate )
       
   849     bool change = false;
       
   850     if ( QString::number( bitRate ) != mBitRate ) {
       
   851         change = true;
       
   852         if ( bitRate > 0 ) {
       
   853             mBitRate = QString::number( bitRate / 1000 );
       
   854         } else {
       
   855             mBitRate = QString();
       
   856         }
       
   857     }
       
   858     TX_EXIT
       
   859     return change;
       
   860 }
       
   861 
       
   862 /*!
       
   863  Sets sample rate
       
   864  */
       
   865 bool MpSongDataPrivate::setSampleRate( int sampleRate )
       
   866 {
       
   867     TX_ENTRY_ARGS( "Sample rate =" << sampleRate )
       
   868     bool change = false;
       
   869     if ( QString::number( sampleRate ) != mSampleRate ) {
       
   870         change = true;
       
   871         if ( sampleRate > 0 ) {
       
   872             mSampleRate = QString::number( sampleRate );
       
   873         } else {
       
   874             mSampleRate = QString();
       
   875         }
       
   876     }
       
   877     TX_EXIT
       
   878     return change;
       
   879 }
       
   880 
       
   881 /*!
       
   882  Sets the \a size
       
   883  */
       
   884 bool MpSongDataPrivate::setSize( int size )
       
   885 {
       
   886     TX_ENTRY_ARGS( "Size =" << size )
       
   887     bool change = false;
       
   888     if ( QString::number( size ) != mSize ) {
       
   889         change = true;
       
   890         mSize = QString::number( size / 1000 );
       
   891     }
       
   892     TX_EXIT
       
   893     return change;
       
   894 }
       
   895 
       
   896 /*!
       
   897  Sets the \a modification information
       
   898  */
       
   899 bool MpSongDataPrivate::setModified( const QString &modified )
       
   900 {
       
   901     TX_ENTRY_ARGS( "Modified =" << modified )
       
   902     bool change = false;
       
   903     if ( modified != mModified ) {
       
   904         change = true;
       
   905         mModified = modified;
       
   906     }
       
   907     TX_EXIT
       
   908     return change;
       
   909 }
       
   910 
       
   911 /*!
       
   912  Sets the \a copyright information
       
   913  */
       
   914 bool MpSongDataPrivate::setCopyright( const QString &copyright )
       
   915 {
       
   916     TX_ENTRY_ARGS( "Copyright =" << copyright )
       
   917     bool change = false;
       
   918     if ( copyright != mCopyright ) {
       
   919         change = true;
       
   920         mCopyright = copyright;
       
   921     }
       
   922     TX_EXIT
       
   923     return change;
       
   924 }
       
   925 
       
   926 /*!
       
   927  Sets the \a music URL
       
   928  */
       
   929 bool MpSongDataPrivate::setMusicURL( const QString &musicURL )
       
   930 {
       
   931     TX_ENTRY_ARGS( "Music URL =" << musicURL )
       
   932     bool change = false;
       
   933     if ( musicURL != mMusicURL ) {
       
   934         change = true;
       
   935         mMusicURL = musicURL;
       
   936     }
       
   937     TX_EXIT
       
   938     return change;
       
   939 }
       
   940 
       
   941 /*!
       
   942  Set whether the song is DRM protected
       
   943  */
       
   944 bool MpSongDataPrivate::setDrmProtected( bool drmProtected )
       
   945 {
       
   946     TX_ENTRY_ARGS( "DRM protected =" << drmProtected )
       
   947     bool change = false;
       
   948     if ( drmProtected != mDrmProtected ) {
       
   949         change = true;
       
   950         mDrmProtected = drmProtected;
       
   951     }
       
   952     TX_EXIT
       
   953     return change;
       
   954 }
       
   955