mpviewplugins/mpplaybackviewplugin/src/mpplaybackdata.cpp
changeset 19 4e84c994a771
child 20 82baf59ce8dd
equal deleted inserted replaced
5:2a40e88564c8 19:4e84c994a771
       
     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 #include <thumbnailmanager_qt.h>
       
    22 
       
    23 #include "mpplaybackdata.h"
       
    24 #include "mptrace.h"
       
    25 
       
    26 const int KUndefined = -1;
       
    27 
       
    28 /*!
       
    29     \class MpPlaybackData
       
    30     \brief Music Player playback data.
       
    31 
       
    32     Playback data provides access to current playing song data, and playback
       
    33     properties, it is designed as an interface between the playback wrapper
       
    34     and the UI, it also provides album art extraction.
       
    35 */
       
    36 
       
    37 /*!
       
    38     \fn void durationChanged()
       
    39 
       
    40     This signal is emitted when duration changes.
       
    41  */
       
    42 
       
    43 /*!
       
    44     \fn void positionChanged()
       
    45 
       
    46     This signal is emitted when position changes.
       
    47  */
       
    48 
       
    49 /*!
       
    50     \fn void albumArtReady()
       
    51 
       
    52     This signal is emitted when album art is ready.
       
    53  */
       
    54 
       
    55 /*!
       
    56     \fn void playbackStateChanged()
       
    57 
       
    58     This signal is emitted when there is a *transition* on the playback state,
       
    59     this is based on a simple state.
       
    60  */
       
    61 
       
    62 /*!
       
    63     \fn void playbackInfoChanged()
       
    64 
       
    65     This signal is emitted when playback info changes. This includes:
       
    66     title, artist and album name.
       
    67  */
       
    68 
       
    69 
       
    70 
       
    71 /*!
       
    72     Constructs a new MpPlaybackData.
       
    73  */
       
    74 MpPlaybackData::MpPlaybackData( QObject *parent )
       
    75     : QObject(parent),
       
    76       mThumbnailManager(0),
       
    77       mReqId(KUndefined),
       
    78       mDuration(0),
       
    79       mPosition(0),
       
    80       mAlbumArt()
       
    81 {
       
    82     TX_ENTRY
       
    83     mThumbnailManager = new ThumbnailManager(this);
       
    84     mThumbnailManager->setQualityPreference(ThumbnailManager::OptimizeForQuality);
       
    85     mThumbnailManager->setThumbnailSize(ThumbnailManager::ThumbnailLarge);
       
    86     connect( mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void *, int, int)),
       
    87              this, SLOT(thumbnailReady(QPixmap, void *, int, int)) );
       
    88 
       
    89     mDefaultAlbumArt = QPixmap(":/playbackviewicons/defaultalbumart.png");
       
    90     TX_EXIT
       
    91 }
       
    92 
       
    93 /*!
       
    94  Constructs a new MpPlaybackData.
       
    95  */
       
    96 MpPlaybackData::~MpPlaybackData()
       
    97 {
       
    98     TX_ENTRY
       
    99     delete mThumbnailManager;
       
   100     TX_EXIT
       
   101 }
       
   102 
       
   103 /*!
       
   104  Sets the song \a duration.
       
   105 */
       
   106 void MpPlaybackData::setDuration( int duration )
       
   107 {
       
   108     TX_ENTRY_ARGS( "duration = " << duration )
       
   109     mDuration = duration;
       
   110     emit durationChanged();
       
   111     TX_EXIT
       
   112 }
       
   113 
       
   114 /*!
       
   115  Returns the song duration.
       
   116 */
       
   117 int MpPlaybackData::duration() const
       
   118 {
       
   119     TX_LOG_ARGS( "mDuration = " << mDuration )
       
   120     return mDuration;
       
   121 }
       
   122 
       
   123 /*!
       
   124  Sets the song \a position.
       
   125 */
       
   126 void MpPlaybackData::setPosition( int position )
       
   127 {
       
   128     TX_ENTRY_ARGS( "position = " << position )
       
   129     mPosition = position;
       
   130     emit positionChanged();
       
   131     TX_EXIT
       
   132 }
       
   133 
       
   134 /*!
       
   135  Returns the song position.
       
   136 */
       
   137 int MpPlaybackData::position() const
       
   138 {
       
   139     TX_ENTRY_ARGS( "mPosition = " << mPosition )
       
   140     return mPosition;
       
   141 }
       
   142 
       
   143 /*!
       
   144  Sets the song \a title, returns true if the value is new.
       
   145 */
       
   146 bool MpPlaybackData::setTitle( const QString& title )
       
   147 {
       
   148     TX_ENTRY_ARGS( "title = " << title )
       
   149     bool change = false;
       
   150     if ( title != mTitle ) {
       
   151         change = true;
       
   152         mTitle = title;
       
   153     }
       
   154     TX_EXIT
       
   155     return change;
       
   156 }
       
   157 
       
   158 /*!
       
   159  Returns the song title.
       
   160 */
       
   161 const QString& MpPlaybackData::title() const
       
   162 {
       
   163     TX_ENTRY_ARGS( "mTitle = " << mTitle )
       
   164     return mTitle;
       
   165 }
       
   166 
       
   167 /*!
       
   168  Sets the song \a artist, returns true if the value is new.
       
   169 */
       
   170 bool MpPlaybackData::setArtist( const QString& artist )
       
   171 {
       
   172     TX_ENTRY_ARGS( "artist = " << artist )
       
   173     bool change = false;
       
   174     if ( artist != mArtist ) {
       
   175         change = true;
       
   176         mArtist = artist;
       
   177     }
       
   178     TX_EXIT
       
   179     return change;
       
   180 }
       
   181 
       
   182 /*!
       
   183  Returns the song artist.
       
   184 */
       
   185 const QString& MpPlaybackData::artist() const
       
   186 {
       
   187     TX_ENTRY_ARGS( "mArtist = " << mArtist )
       
   188     return mArtist;
       
   189 }
       
   190 
       
   191 /*!
       
   192  Sets the song \a album, returns true if the value is new.
       
   193 */
       
   194 bool MpPlaybackData::setAlbum( const QString& album )
       
   195 {
       
   196     TX_ENTRY_ARGS( "album = " << album )
       
   197     bool change = false;
       
   198     if ( album != mAlbum ) {
       
   199         change = true;
       
   200         mAlbum = album;
       
   201     }
       
   202     TX_EXIT
       
   203     return change;
       
   204 }
       
   205 
       
   206 /*!
       
   207  Returns the song album.
       
   208 */
       
   209 const QString& MpPlaybackData::album() const
       
   210 {
       
   211     TX_ENTRY_ARGS( "mAlbum = " << mAlbum )
       
   212     return mAlbum;
       
   213 }
       
   214 
       
   215 /*!
       
   216  Sets the song \a uri, returns true if the value is new.
       
   217 */
       
   218 bool MpPlaybackData::setUri( const QString& uri )
       
   219 {
       
   220     TX_ENTRY_ARGS( "uri = " << uri )
       
   221     bool change = false;
       
   222     if ( uri != mUri ) {
       
   223         change = true;
       
   224         mUri = uri;
       
   225     }
       
   226     TX_EXIT
       
   227     return change;
       
   228 }
       
   229 
       
   230 /*!
       
   231  Returns the song uri.
       
   232 */
       
   233 const QString& MpPlaybackData::uri() const
       
   234 {
       
   235     TX_ENTRY_ARGS( "mUri = " << mUri )
       
   236     return mUri;
       
   237 }
       
   238 
       
   239 /*!
       
   240  Sets the song \a albumArtUri.
       
   241 */
       
   242 void MpPlaybackData::setAlbumArtUri( const QString& albumArtUri )
       
   243 {
       
   244     TX_ENTRY_ARGS( "albumArtUri = " << albumArtUri )
       
   245     if ( !albumArtUri.isEmpty() ) {
       
   246         bool ok = true;
       
   247         if ( mReqId != KUndefined ) {
       
   248             // There is already an outstanding request. Cancel it first.
       
   249             bool ok = mThumbnailManager->cancelRequest(mReqId);
       
   250         }
       
   251         if ( ok ) {
       
   252             mReqId = mThumbnailManager->getThumbnail( albumArtUri );
       
   253             if ( mReqId == KUndefined ) {
       
   254                 // Request failed. Set default album art.
       
   255                 mAlbumArt = mDefaultAlbumArt;
       
   256                 emit albumArtReady();
       
   257             }
       
   258         }
       
   259     }
       
   260     else {
       
   261         // No album art uri. Set default album art.
       
   262         mAlbumArt = mDefaultAlbumArt;
       
   263         emit albumArtReady();
       
   264     }
       
   265     TX_EXIT
       
   266 }
       
   267 
       
   268 /*!
       
   269  Returns the song album art on \a pixmap.
       
   270 */
       
   271 void MpPlaybackData::albumArt( QPixmap& pixmap ) const
       
   272 {
       
   273     TX_ENTRY
       
   274     if ( mAlbumArt.isNull() ) {
       
   275         pixmap = QPixmap();
       
   276      }
       
   277      else {
       
   278         pixmap = mAlbumArt;
       
   279      }
       
   280     TX_EXIT
       
   281 }
       
   282 
       
   283 /*!
       
   284  Sets the playback \a state.
       
   285 */
       
   286 void MpPlaybackData::setPlaybackState( const SimplifiedState state )
       
   287 {
       
   288     TX_ENTRY_ARGS( "state = " << state )
       
   289     if ( state != mPlaybackState ) {
       
   290         mPlaybackState = state;
       
   291         emit playbackStateChanged();
       
   292     }
       
   293     TX_EXIT
       
   294 }
       
   295 
       
   296 /*!
       
   297  Returns the playback state.
       
   298 */
       
   299 MpPlaybackData::SimplifiedState MpPlaybackData::playbackState() const
       
   300 {
       
   301     TX_LOG_ARGS( "mPlaybackState = " << mPlaybackState )
       
   302     return mPlaybackState;
       
   303 }
       
   304 
       
   305 /*!
       
   306 
       
   307 */
       
   308 void MpPlaybackData::commitPlaybackInfo()
       
   309 {
       
   310     TX_ENTRY
       
   311     emit playbackInfoChanged();
       
   312     TX_EXIT
       
   313 }
       
   314 
       
   315 /*!
       
   316  Slot to handle the album art thumb.
       
   317 */
       
   318 void MpPlaybackData::thumbnailReady(
       
   319     const QPixmap& pixmap, void *data, int id, int error )
       
   320 {
       
   321     TX_LOG_ARGS( "error = " << error << ", id = " << id )
       
   322     Q_UNUSED(data);
       
   323     if ( error == 0 && mReqId == id ) {
       
   324         mReqId = KUndefined;
       
   325         mAlbumArt = pixmap;
       
   326         emit albumArtReady();
       
   327     }
       
   328     else {
       
   329         mReqId = KUndefined;
       
   330         mAlbumArt = mDefaultAlbumArt;
       
   331         emit albumArtReady();
       
   332     }
       
   333     TX_EXIT
       
   334 }
       
   335