mpviewplugins/mpplaybackviewplugin/src/mpplaybackdata.cpp
changeset 22 ecf06a08d4d9
parent 20 82baf59ce8dd
child 23 d45f4c087764
child 25 3ec52facab4d
child 34 2c5162224003
equal deleted inserted replaced
20:82baf59ce8dd 22:ecf06a08d4d9
     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       mPlaybackState(Stopped)
       
    82 {
       
    83     TX_ENTRY
       
    84     mThumbnailManager = new ThumbnailManager(this);
       
    85     mThumbnailManager->setQualityPreference(ThumbnailManager::OptimizeForQuality);
       
    86     mThumbnailManager->setThumbnailSize(ThumbnailManager::ThumbnailLarge);
       
    87     connect( mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void *, int, int)),
       
    88              this, SLOT(thumbnailReady(QPixmap, void *, int, int)) );
       
    89 
       
    90     mDefaultAlbumArt = QPixmap(":/playbackviewicons/defaultalbumart.png");
       
    91     TX_EXIT
       
    92 }
       
    93 
       
    94 /*!
       
    95  Constructs a new MpPlaybackData.
       
    96  */
       
    97 MpPlaybackData::~MpPlaybackData()
       
    98 {
       
    99     TX_ENTRY
       
   100     delete mThumbnailManager;
       
   101     TX_EXIT
       
   102 }
       
   103 
       
   104 /*!
       
   105  Sets the song \a duration.
       
   106 */
       
   107 void MpPlaybackData::setDuration( int duration )
       
   108 {
       
   109     TX_ENTRY_ARGS( "duration = " << duration )
       
   110     mDuration = duration;
       
   111     emit durationChanged();
       
   112     TX_EXIT
       
   113 }
       
   114 
       
   115 /*!
       
   116  Returns the song duration.
       
   117 */
       
   118 int MpPlaybackData::duration() const
       
   119 {
       
   120     TX_LOG_ARGS( "mDuration = " << mDuration )
       
   121     return mDuration;
       
   122 }
       
   123 
       
   124 /*!
       
   125  Sets the song \a position.
       
   126 */
       
   127 void MpPlaybackData::setPosition( int position )
       
   128 {
       
   129     TX_ENTRY_ARGS( "position = " << position )
       
   130     mPosition = position;
       
   131     emit positionChanged();
       
   132     TX_EXIT
       
   133 }
       
   134 
       
   135 /*!
       
   136  Returns the song position.
       
   137 */
       
   138 int MpPlaybackData::position() const
       
   139 {
       
   140     TX_ENTRY_ARGS( "mPosition = " << mPosition )
       
   141     return mPosition;
       
   142 }
       
   143 
       
   144 /*!
       
   145  Sets the song \a title, returns true if the value is new.
       
   146 */
       
   147 bool MpPlaybackData::setTitle( const QString& title )
       
   148 {
       
   149     TX_ENTRY_ARGS( "title = " << title )
       
   150     bool change = false;
       
   151     if ( title != mTitle ) {
       
   152         change = true;
       
   153         mTitle = title;
       
   154     }
       
   155     TX_EXIT
       
   156     return change;
       
   157 }
       
   158 
       
   159 /*!
       
   160  Returns the song title.
       
   161 */
       
   162 const QString& MpPlaybackData::title() const
       
   163 {
       
   164     TX_ENTRY_ARGS( "mTitle = " << mTitle )
       
   165     return mTitle;
       
   166 }
       
   167 
       
   168 /*!
       
   169  Sets the song \a artist, returns true if the value is new.
       
   170 */
       
   171 bool MpPlaybackData::setArtist( const QString& artist )
       
   172 {
       
   173     TX_ENTRY_ARGS( "artist = " << artist )
       
   174     bool change = false;
       
   175     if ( artist != mArtist ) {
       
   176         change = true;
       
   177         mArtist = artist;
       
   178     }
       
   179     TX_EXIT
       
   180     return change;
       
   181 }
       
   182 
       
   183 /*!
       
   184  Returns the song artist.
       
   185 */
       
   186 const QString& MpPlaybackData::artist() const
       
   187 {
       
   188     TX_ENTRY_ARGS( "mArtist = " << mArtist )
       
   189     return mArtist;
       
   190 }
       
   191 
       
   192 /*!
       
   193  Sets the song \a album, returns true if the value is new.
       
   194 */
       
   195 bool MpPlaybackData::setAlbum( const QString& album )
       
   196 {
       
   197     TX_ENTRY_ARGS( "album = " << album )
       
   198     bool change = false;
       
   199     if ( album != mAlbum ) {
       
   200         change = true;
       
   201         mAlbum = album;
       
   202     }
       
   203     TX_EXIT
       
   204     return change;
       
   205 }
       
   206 
       
   207 /*!
       
   208  Returns the song album.
       
   209 */
       
   210 const QString& MpPlaybackData::album() const
       
   211 {
       
   212     TX_ENTRY_ARGS( "mAlbum = " << mAlbum )
       
   213     return mAlbum;
       
   214 }
       
   215 
       
   216 /*!
       
   217  Sets the song \a uri, returns true if the value is new.
       
   218 */
       
   219 bool MpPlaybackData::setUri( const QString& uri )
       
   220 {
       
   221     TX_ENTRY_ARGS( "uri = " << uri )
       
   222     bool change = false;
       
   223     if ( uri != mUri ) {
       
   224         change = true;
       
   225         mUri = uri;
       
   226     }
       
   227     TX_EXIT
       
   228     return change;
       
   229 }
       
   230 
       
   231 /*!
       
   232  Returns the song uri.
       
   233 */
       
   234 const QString& MpPlaybackData::uri() const
       
   235 {
       
   236     TX_ENTRY_ARGS( "mUri = " << mUri )
       
   237     return mUri;
       
   238 }
       
   239 
       
   240 /*!
       
   241  Sets the song \a albumArtUri.
       
   242 */
       
   243 void MpPlaybackData::setAlbumArtUri( const QString& albumArtUri )
       
   244 {
       
   245     TX_ENTRY_ARGS( "albumArtUri = " << albumArtUri )
       
   246     if ( !albumArtUri.isEmpty() ) {
       
   247         bool ok = true;
       
   248         if ( mReqId != KUndefined ) {
       
   249             // There is already an outstanding request. Cancel it first.
       
   250             bool ok = mThumbnailManager->cancelRequest(mReqId);
       
   251         }
       
   252         if ( ok ) {
       
   253             mReqId = mThumbnailManager->getThumbnail( albumArtUri );
       
   254             if ( mReqId == KUndefined ) {
       
   255                 // Request failed. Set default album art.
       
   256                 mAlbumArt = mDefaultAlbumArt;
       
   257                 emit albumArtReady();
       
   258             }
       
   259         }
       
   260     }
       
   261     else {
       
   262         // No album art uri. Set default album art.
       
   263         mAlbumArt = mDefaultAlbumArt;
       
   264         emit albumArtReady();
       
   265     }
       
   266     TX_EXIT
       
   267 }
       
   268 
       
   269 /*!
       
   270  Returns the song album art on \a pixmap.
       
   271 */
       
   272 void MpPlaybackData::albumArt( QPixmap& pixmap ) const
       
   273 {
       
   274     TX_ENTRY
       
   275     if ( mAlbumArt.isNull() ) {
       
   276         pixmap = QPixmap();
       
   277      }
       
   278      else {
       
   279         pixmap = mAlbumArt;
       
   280      }
       
   281     TX_EXIT
       
   282 }
       
   283 
       
   284 /*!
       
   285  Sets the playback \a state.
       
   286 */
       
   287 void MpPlaybackData::setPlaybackState( const SimplifiedState state )
       
   288 {
       
   289     TX_ENTRY_ARGS( "state = " << state )
       
   290     if ( state != mPlaybackState ) {
       
   291         mPlaybackState = state;
       
   292         emit playbackStateChanged();
       
   293     }
       
   294     TX_EXIT
       
   295 }
       
   296 
       
   297 /*!
       
   298  Returns the playback state.
       
   299 */
       
   300 MpPlaybackData::SimplifiedState MpPlaybackData::playbackState() const
       
   301 {
       
   302     TX_LOG_ARGS( "mPlaybackState = " << mPlaybackState )
       
   303     return mPlaybackState;
       
   304 }
       
   305 
       
   306 /*!
       
   307 
       
   308 */
       
   309 void MpPlaybackData::commitPlaybackInfo()
       
   310 {
       
   311     TX_ENTRY
       
   312     emit playbackInfoChanged();
       
   313     TX_EXIT
       
   314 }
       
   315 
       
   316 /*!
       
   317  Slot to handle the album art thumb.
       
   318 */
       
   319 void MpPlaybackData::thumbnailReady(
       
   320     const QPixmap& pixmap, void *data, int id, int error )
       
   321 {
       
   322     TX_LOG_ARGS( "error = " << error << ", id = " << id )
       
   323     Q_UNUSED(data);
       
   324     if ( error == 0 && mReqId == id ) {
       
   325         mReqId = KUndefined;
       
   326         mAlbumArt = pixmap;
       
   327         emit albumArtReady();
       
   328     }
       
   329     else {
       
   330         mReqId = KUndefined;
       
   331         mAlbumArt = mDefaultAlbumArt;
       
   332         emit albumArtReady();
       
   333     }
       
   334     TX_EXIT
       
   335 }
       
   336