mpviewplugins/mpdetailsviewplugin/tsrc/unittest_mpsharedata/stub/src/mpsongdata.cpp
changeset 48 af3740e3753f
parent 42 79c49924ae23
child 54 c5b304f4d89b
equal deleted inserted replaced
42:79c49924ae23 48:af3740e3753f
     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: Playback Data provider for playback view.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <QString>
       
    20 #include <QPixmap>
       
    21 
       
    22 #include "mpsongdata.h"
       
    23 #include "mptrace.h"
       
    24 
       
    25 
       
    26 const int KUndefined = -1;
       
    27 
       
    28 /*!
       
    29     \class MpSongData
       
    30     \brief Music Player song metadata.
       
    31 
       
    32     Song data provide acces to current playing song metadata
       
    33 */
       
    34     
       
    35 /*!
       
    36     \fn void albumArtReady()
       
    37 
       
    38     This signal is albuma alrt is ready.
       
    39  */
       
    40 
       
    41 /*!
       
    42     \fn void playbackInfoChanged()
       
    43 
       
    44     This signal is emitted when basic information is available
       
    45  */
       
    46     
       
    47 /*!
       
    48     \fn void songDetailInfoChanged()
       
    49 
       
    50     This signal is emitted when detail information is available
       
    51  */
       
    52     
       
    53        
       
    54 
       
    55 /*!
       
    56     Constructs a new MpSongData.
       
    57  */
       
    58 MpSongData::MpSongData( QObject *parent )
       
    59     : QObject( parent ),
       
    60       mTitle( NULL ),
       
    61       mAlbum( NULL ),
       
    62       mArtist( NULL ),
       
    63       mComposer( NULL),
       
    64       mGenre( NULL ),
       
    65       mYear( NULL ),
       
    66       mAlbumTrack( NULL ),
       
    67       mAlbumArt(),
       
    68       mReqId( KUndefined )
       
    69 {
       
    70     //TX_ENTRY
       
    71     //TX_EXIT
       
    72 }
       
    73 
       
    74 /*!
       
    75  Constructs a new MpSongData.
       
    76  */
       
    77 MpSongData::~MpSongData()
       
    78 {
       
    79     //TX_ENTRY
       
    80     //TX_EXIT
       
    81 }
       
    82 
       
    83 /*!
       
    84  Returns the song album art on \a pixmap.
       
    85 */
       
    86 void MpSongData::albumArt( QPixmap& pixmap )
       
    87 {
       
    88     //TX_ENTRY
       
    89      if ( !mAlbumArt.isNull() ) {
       
    90         pixmap = mAlbumArt;
       
    91      }
       
    92      else {
       
    93          pixmap = QPixmap();
       
    94      }
       
    95     //TX_EXIT
       
    96 }
       
    97 
       
    98 
       
    99 /*!
       
   100  Returns the song title.
       
   101 */
       
   102 QString MpSongData::title() const
       
   103 {
       
   104     //TX_LOG
       
   105     return mTitle;
       
   106 }
       
   107 
       
   108 /*!
       
   109  Returns the song album.
       
   110 */
       
   111 QString MpSongData::album() const
       
   112 {
       
   113     //TX_LOG
       
   114     return mAlbum;
       
   115 }
       
   116 
       
   117 /*!
       
   118  Returns the song artist.
       
   119 */
       
   120 QString MpSongData::artist() const
       
   121 {
       
   122     //TX_LOG
       
   123     return mArtist;
       
   124 }
       
   125 
       
   126 /*!
       
   127  Returns comment
       
   128 */
       
   129 QString MpSongData::comment() const
       
   130 {
       
   131     //TX_LOG
       
   132     return mComment;
       
   133 }
       
   134 
       
   135 /*!
       
   136  Returns the song composer.
       
   137 */
       
   138 QString MpSongData::composer() const
       
   139 {
       
   140     //TX_LOG
       
   141     return mComposer;
       
   142 }
       
   143 
       
   144 
       
   145 /*!
       
   146  Returns the song genre.
       
   147 */
       
   148 QString MpSongData::genre() const
       
   149 {
       
   150     //TX_LOG
       
   151     return mGenre;
       
   152 }
       
   153 
       
   154 
       
   155 /*!
       
   156  Returns the album track.
       
   157 */
       
   158 QString MpSongData::albumTrack() const
       
   159 {
       
   160     //TX_LOG
       
   161     return mAlbumTrack;
       
   162 }
       
   163 
       
   164 /*!
       
   165  Returns link
       
   166 */
       
   167 QString MpSongData::musicURL() const
       
   168 {
       
   169     //TX_LOG
       
   170     return mMusicURL;
       
   171 }
       
   172 
       
   173 /*!
       
   174  Returns link
       
   175 */
       
   176 QString MpSongData::link() const
       
   177 {
       
   178     //TX_LOG
       
   179     return mLink;
       
   180 }
       
   181 
       
   182 /*!
       
   183  Returns the release date.
       
   184 */
       
   185 QString MpSongData::year() const
       
   186 {
       
   187     //TX_LOG    
       
   188     return mYear;
       
   189 }
       
   190 
       
   191 
       
   192 /*!
       
   193  Sets the song \a title, returns true if the value is new.
       
   194 */
       
   195 bool MpSongData::setTitle( const QString &title )
       
   196 {
       
   197     //TX_ENTRY_ARGS( "title =" << title )
       
   198     bool change = false;
       
   199     if ( title != mTitle ) {
       
   200         change = true;
       
   201         mTitle = title;
       
   202     }
       
   203     //TX_EXIT
       
   204     return change;
       
   205 }
       
   206 
       
   207 /*!
       
   208  Sets the song \a album, returns true if the value is new.
       
   209 */
       
   210 bool MpSongData::setAlbum( const QString &album )
       
   211 {
       
   212     //TX_ENTRY_ARGS( "album =" << album )
       
   213     bool change = false;
       
   214     if ( album != mAlbum ) {
       
   215         change = true;
       
   216         mAlbum = album;
       
   217     }
       
   218     //TX_EXIT
       
   219     return change;
       
   220 }
       
   221 
       
   222 /*!
       
   223  Sets the song \a artist, returns true if the value is new.
       
   224 */
       
   225 bool MpSongData::setArtist( const QString &artist )
       
   226 {
       
   227     //TX_ENTRY_ARGS( "artist =" << artist )
       
   228     bool change = false;
       
   229     if ( artist != mArtist ) {
       
   230         change = true;
       
   231         mArtist = artist;
       
   232     }
       
   233     //TX_EXIT
       
   234     return change;
       
   235 }
       
   236 
       
   237 /*!
       
   238  Sets the song \a comment, returns true if the value is new.
       
   239 */
       
   240 bool MpSongData::setComment( const QString &comment)
       
   241 {
       
   242     //TX_ENTRY_ARGS( "comment =" << comment )
       
   243     bool change = false;
       
   244     if ( comment != mComment ) {
       
   245         change = true;
       
   246         mComment = comment;
       
   247     }
       
   248     //TX_EXIT
       
   249     return change;
       
   250 }
       
   251 
       
   252 
       
   253 /*!
       
   254  Sets the song \a composer, returns true if the value is new.
       
   255 */
       
   256 bool MpSongData::setComposer( const QString &composer )
       
   257 {
       
   258     //TX_ENTRY_ARGS( "composer =" << composer )
       
   259     bool change = false;
       
   260     if ( composer != mComposer ) {
       
   261         change = true;
       
   262         mComposer = composer;
       
   263     }
       
   264     //TX_EXIT
       
   265     return change;
       
   266 }
       
   267 
       
   268 /*!
       
   269  Sets the song \a genre, returns true if the value is new.
       
   270 */
       
   271 bool MpSongData::setGenre( const QString &genre )
       
   272 {
       
   273     //TX_ENTRY_ARGS( "genre =" << genre )
       
   274     bool change = false;
       
   275     if ( genre != mGenre ) {
       
   276         change = true;
       
   277         mGenre = genre;
       
   278     }
       
   279     //TX_EXIT
       
   280     return change;
       
   281 }
       
   282 
       
   283 
       
   284 /*!
       
   285  Sets the song \a date, returns true if the value is new.
       
   286 */
       
   287 bool MpSongData::setYear( int year )
       
   288 {
       
   289     //TX_ENTRY_ARGS( "year =" << year )
       
   290     bool change = false;
       
   291     if ( QString::number(year) != mYear ) {
       
   292         change = true;
       
   293         if ( year >= 0 && year < 9999 ) {
       
   294             mYear = QString::number(year);
       
   295         }
       
   296     }
       
   297     //TX_EXIT
       
   298     return change;
       
   299 }
       
   300 
       
   301 /*!
       
   302  Sets the \a album track, returns true if the value is new.
       
   303 */
       
   304 bool MpSongData::setAlbumTrack( const QString &track )
       
   305 {
       
   306     //TX_ENTRY_ARGS( "track =" << track )
       
   307     bool change = false;
       
   308     if ( track != mAlbumTrack ) {
       
   309         change = true;
       
   310         mAlbumTrack = track;
       
   311     }
       
   312     //TX_EXIT
       
   313     return change;
       
   314 }
       
   315 
       
   316 /*!
       
   317  Sets the \a link
       
   318 */
       
   319 void MpSongData::setLink( const QString &link )
       
   320 {
       
   321     //TX_ENTRY_ARGS( "Link =" << link )
       
   322     mLink = link;
       
   323     //TX_EXIT
       
   324 }
       
   325 
       
   326 /*!
       
   327  Sets the \a Music URL
       
   328 */
       
   329 bool MpSongData::setMusicURL( const QString &link )
       
   330 {
       
   331     //TX_ENTRY_ARGS( "MusicURL =" << link )
       
   332     mMusicURL = link;
       
   333     return true;
       
   334     //TX_EXIT
       
   335 }
       
   336 
       
   337 
       
   338 
       
   339 /*!
       
   340  Sets the song \a albumArtUri.
       
   341 */
       
   342 void MpSongData::setAlbumArtUri( const QString &albumArtUri)
       
   343 {
       
   344     //TX_ENTRY
       
   345     mAlbumArt = mDefaultAlbumArt;
       
   346     emit albumArtReady();
       
   347     //TX_EXIT
       
   348 }
       
   349 
       
   350 
       
   351 /*!
       
   352  Slot to handle the album art thumb.
       
   353 */
       
   354 void MpSongData::thumbnailReady(
       
   355         const QPixmap& pixmap,
       
   356         void *data,
       
   357         int id,
       
   358         int error  )
       
   359 {
       
   360     //TX_ENTRY
       
   361     Q_UNUSED( data );
       
   362 
       
   363     //TX_EXIT
       
   364 }
       
   365 
       
   366 /*!
       
   367  Emit signal when playback information changed, such as artist, track name
       
   368 */
       
   369 void MpSongData::commitPlaybackInfo()
       
   370 {
       
   371     //TX_ENTRY
       
   372     emit playbackInfoChanged();
       
   373     //TX_EXIT
       
   374 }
       
   375 
       
   376 /*!
       
   377  Emit signal when song detail information changed
       
   378 */
       
   379 void MpSongData::commitSongDetailInfo()
       
   380 {
       
   381     //TX_ENTRY
       
   382     emit songDetailInfoChanged();
       
   383     //TX_EXIT
       
   384 }
       
   385 
       
   386 QString MpSongData::albumArtBase64() const
       
   387 {
       
   388     // Converts the current album art pixmap to a base64 string, and return the string.
       
   389 //    TX_ENTRY
       
   390 //    QByteArray array;
       
   391 //    QBuffer buffer(&array);
       
   392 //    buffer.open(QIODevice::WriteOnly);
       
   393 //    mAlbumArt.save(&buffer, "PNG"); // writes pixmap into bytes in PNG format
       
   394 //    buffer.close();
       
   395 //    QByteArray base64 = array.toBase64();
       
   396 //    TX_EXIT
       
   397 //    return base64.constData();
       
   398     return QString("e:\\album_art.png");
       
   399 }